forked from Awful/Awful.apk
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved htmlwidget from lib to src, modified to display placeholder img
- Loading branch information
Showing
13 changed files
with
1,969 additions
and
3 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/com/ferg/awful/htmlwidget/BlockingFilterInputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/*- | ||
* Copyright (C) 2010 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.ferg.awful.htmlwidget; | ||
|
||
import java.io.FilterInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
/** | ||
* A {@link FilterInputStream} that blocks until the requested number of bytes | ||
* have been read/skipped, or the end of the stream is reached. | ||
* <p> | ||
* This filter can be used as a work-around for <a | ||
* href="http://code.google.com/p/android/issues/detail?id=6066">Issue | ||
* #6066</a>. | ||
*/ | ||
class BlockingFilterInputStream extends FilterInputStream { | ||
|
||
public BlockingFilterInputStream(InputStream input) { | ||
super(input); | ||
} | ||
|
||
@Override | ||
public int read(byte[] buffer, int offset, int count) throws IOException { | ||
int total = 0; | ||
while (total < count) { | ||
int read = super.read(buffer, offset + total, count - total); | ||
if (read == -1) { | ||
return (total != 0) ? total : -1; | ||
} | ||
total += read; | ||
} | ||
return total; | ||
} | ||
|
||
@Override | ||
public int read(byte[] buffer) throws IOException { | ||
int total = 0; | ||
while (total < buffer.length) { | ||
int offset = total; | ||
int count = buffer.length - total; | ||
int read = super.read(buffer, offset, count); | ||
if (read == -1) { | ||
return (total != 0) ? total : -1; | ||
} | ||
total += read; | ||
} | ||
return total; | ||
} | ||
|
||
@Override | ||
public long skip(long count) throws IOException { | ||
long total = 0L; | ||
while (total < count) { | ||
long skipped = super.skip(count - total); | ||
if (skipped == 0L) { | ||
int b = super.read(); | ||
if (b < 0) { | ||
break; | ||
} else { | ||
skipped += 1; | ||
} | ||
} | ||
total += skipped; | ||
} | ||
return total; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/*- | ||
* Copyright (C) 2010 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.ferg.awful.htmlwidget; | ||
|
||
import android.content.Context; | ||
import android.text.Layout; | ||
import android.util.AttributeSet; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.HorizontalScrollView; | ||
import android.widget.TextView; | ||
|
||
/** | ||
* Provides smooth horizontal scrolling for {@link TextView TextViews} that | ||
* extend past the edge of the screen. | ||
* <p> | ||
* TODO: Replace this class by implementing smooth scrolling in {@link HtmlView}? | ||
*/ | ||
public class HorizontalScroller extends HorizontalScrollView { | ||
|
||
private static final int getMaxLineWidth(TextView textView) { | ||
Layout layout = textView.getLayout(); | ||
if (layout != null) { | ||
int lineCount = layout.getLineCount(); | ||
float max = 0; | ||
for (int i = 0; i < lineCount; i++) { | ||
float lineWidth = layout.getLineWidth(i); | ||
max = Math.max(max, lineWidth); | ||
} | ||
return (int) max; | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
public HorizontalScroller(Context context, AttributeSet attrs, int defStyle) { | ||
super(context, attrs, defStyle); | ||
} | ||
|
||
public HorizontalScroller(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
public HorizontalScroller(Context context) { | ||
super(context); | ||
} | ||
|
||
@Override | ||
protected void measureChild(View child, int parentWidthMeasureSpec, int parentHeightMeasureSpec) { | ||
ViewGroup.LayoutParams lp = child.getLayoutParams(); | ||
|
||
int childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec, getPaddingLeft() | ||
+ getPaddingRight(), lp.width); | ||
int childHeightMeasureSpec = getChildMeasureSpec(parentHeightMeasureSpec, getPaddingTop() | ||
+ getPaddingBottom(), lp.height); | ||
|
||
child.measure(childWidthMeasureSpec, childHeightMeasureSpec); | ||
} | ||
|
||
@Override | ||
protected void measureChildWithMargins(View child, int parentWidthMeasureSpec, int widthUsed, | ||
int parentHeightMeasureSpec, int heightUsed) { | ||
MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams(); | ||
|
||
int childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec, getPaddingLeft() | ||
+ getPaddingRight() + lp.leftMargin + lp.rightMargin + widthUsed, lp.width); | ||
int childHeightMeasureSpec = getChildMeasureSpec(parentHeightMeasureSpec, getPaddingTop() | ||
+ getPaddingBottom() + lp.topMargin + lp.bottomMargin + heightUsed, lp.height); | ||
|
||
child.measure(childWidthMeasureSpec, childHeightMeasureSpec); | ||
} | ||
|
||
@Override | ||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) { | ||
super.onLayout(changed, left, top, right, bottom); | ||
|
||
int count = getChildCount(); | ||
for (int i = 0; i < count; i++) { | ||
View child = getChildAt(i); | ||
int visibility = child.getVisibility(); | ||
if (visibility != GONE && child instanceof TextView) { | ||
int childLeft = child.getLeft(); | ||
int childTop = child.getTop(); | ||
int childRight = child.getRight(); | ||
int childBottom = child.getBottom(); | ||
|
||
int padding = child.getPaddingLeft() + child.getPaddingRight(); | ||
int maxLineWidth = getMaxLineWidth((TextView) child); | ||
int preferredRight = childLeft + maxLineWidth + padding; | ||
|
||
if (childRight < preferredRight) { | ||
child.layout(childLeft, childTop, preferredRight, childBottom); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.