Skip to content

Commit

Permalink
Moved htmlwidget from lib to src, modified to display placeholder img
Browse files Browse the repository at this point in the history
  • Loading branch information
dbjorge authored and scottferg committed Feb 28, 2011
1 parent c7ea5c5 commit 436d7a8
Show file tree
Hide file tree
Showing 13 changed files with 1,969 additions and 3 deletions.
Binary file removed libs/htmlwidget.jar
Binary file not shown.
Binary file added libs/tagsoup-1.2.jar
Binary file not shown.
Binary file added res/drawable-hdpi/loading_image.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/loading_image.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion res/layout/main.xml
Expand Up @@ -15,7 +15,7 @@
android:layout_height="fill_parent"
android:cacheColorHint="#f4f4f4"
android:scrollingCache="true"
android:smoothScrollbar="true"
android:smoothScrollbar="false"
android:fastScrollEnabled="true"
/>
</LinearLayout>
3 changes: 1 addition & 2 deletions src/com/ferg/awful/ThreadDisplayActivity.java
Expand Up @@ -63,13 +63,12 @@
import com.commonsware.cwac.adapter.AdapterWrapper;
import com.ferg.awful.async.DrawableManager;
import com.ferg.awful.constants.Constants;
import com.ferg.awful.htmlwidget.HtmlView;
import com.ferg.awful.reply.Reply;
import com.ferg.awful.thread.AwfulPost;
import com.ferg.awful.thread.AwfulThread;
import com.ferg.awful.thumbnail.ThumbnailAdapter;

import com.google.android.htmlwidget.HtmlView;

public class ThreadDisplayActivity extends Activity {
private static final String TAG = "ThreadDisplayActivity";

Expand Down
82 changes: 82 additions & 0 deletions src/com/ferg/awful/htmlwidget/BlockingFilterInputStream.java
@@ -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;
}
}
111 changes: 111 additions & 0 deletions src/com/ferg/awful/htmlwidget/HorizontalScroller.java
@@ -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);
}
}
}
}
}

0 comments on commit 436d7a8

Please sign in to comment.