diff --git a/bin/EhViewer.apk b/bin/EhViewer.apk index 1c5c569fd..c9391faf1 100644 Binary files a/bin/EhViewer.apk and b/bin/EhViewer.apk differ diff --git a/bin/classes.dex b/bin/classes.dex index 394510bb7..05a78057b 100644 Binary files a/bin/classes.dex and b/bin/classes.dex differ diff --git a/bin/resources.ap_ b/bin/resources.ap_ index 97e6ee349..e9668afd5 100644 Binary files a/bin/resources.ap_ and b/bin/resources.ap_ differ diff --git a/src/com/hippo/ehviewer/util/Cache.java b/src/com/hippo/ehviewer/util/Cache.java index 49ea4b3b5..1423410c5 100644 --- a/src/com/hippo/ehviewer/util/Cache.java +++ b/src/com/hippo/ehviewer/util/Cache.java @@ -62,16 +62,16 @@ public class Cache { } } - final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); - final int cacheSize = maxMemory / 24; + //final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); + final int cacheSize = 8 * 1024 * 1024; // 8MB, can store 80 thumb memoryCache = new LruCache(cacheSize) { @SuppressLint("NewApi") @Override protected int sizeOf(String key, Bitmap bitmap) { if (Build.VERSION.SDK_INT < 19) - return bitmap.getByteCount() / 1024; + return bitmap.getByteCount(); else - return bitmap.getAllocationByteCount() / 1024; + return bitmap.getAllocationByteCount(); } }; diff --git a/src/com/hippo/ehviewer/widget/AutoWrapLayout.java b/src/com/hippo/ehviewer/widget/AutoWrapLayout.java index b7821c05f..ca042f39b 100644 --- a/src/com/hippo/ehviewer/widget/AutoWrapLayout.java +++ b/src/com/hippo/ehviewer/widget/AutoWrapLayout.java @@ -3,17 +3,23 @@ package com.hippo.ehviewer.widget; import java.util.ArrayList; import java.util.List; +import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Rect; import android.util.AttributeSet; +import android.util.Log; import android.view.View; import android.view.ViewGroup; -import android.view.ViewGroup.LayoutParams; +/** + * A ViewGroup that can layout views in line and auto wrap + * + * @author Hippo + * + */ public class AutoWrapLayout extends ViewGroup { @SuppressWarnings("unused") private final static String TAG = "AutoWrapLayout"; - private List rectList = new ArrayList(); public AutoWrapLayout(Context context) { @@ -26,59 +32,90 @@ public class AutoWrapLayout extends ViewGroup { super(context, attrs, defStyle); } - static int adjust(int measureSpec, int delta) { - return MeasureSpec.makeMeasureSpec( - MeasureSpec.getSize(measureSpec + delta), MeasureSpec.getMode(measureSpec)); - } - + // TODO Take vertical mode + /** + * each row or line at least show one child + * + * horizontal only show child can show or partly show in parent + */ + @SuppressLint("DrawAllocation") @Override - protected void onMeasure(int widthMeasureSpec, int heightSpec) { - final int mWidth = MeasureSpec.getSize(widthMeasureSpec) - getPaddingLeft() - getPaddingRight(); - final int childCount = getChildCount(); + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + int widthMode = MeasureSpec.getMode(widthMeasureSpec); + int heightMode = MeasureSpec.getMode(heightMeasureSpec); + + int maxWidth = MeasureSpec.getSize(widthMeasureSpec); + int maxHeight = MeasureSpec.getSize(heightMeasureSpec); + + + Log.d(TAG, "widthMode = " + widthMode); + Log.d(TAG, "heightMode = " + heightMode); + Log.d(TAG, "maxWidth = " + maxWidth); + Log.d(TAG, "maxHeight = " + maxHeight); + + Log.d(TAG, "getChildCount() = " + getChildCount()); + + if (widthMode == MeasureSpec.UNSPECIFIED) + maxWidth = Integer.MAX_VALUE; + if (heightMode == MeasureSpec.UNSPECIFIED) + maxHeight = Integer.MAX_VALUE; + + int paddingLeft = getPaddingLeft(); + int paddingTop = getPaddingTop(); + int paddingRight = getPaddingRight(); + int paddingBottom = getPaddingBottom(); + + int maxRightBound = maxWidth - paddingRight; + int maxBottomBound = maxWidth - paddingBottom; int left; int top; int right; int bottom; - int rightBound = 0; + int rightBound = paddingLeft; + int maxRightNoPadding = rightBound; int bottomBound; - int lastMaxBottom = 0; - int maxBottom = lastMaxBottom; - int width; - int height; + int lastMaxBottom = paddingTop; + int maxBottom = lastMaxBottom; // maxBottom is maxBottomNoPadding + //int maxBottomNoPadding = maxBottom; + int childWidth; + int childHeight; rectList.clear(); - - for(int i = 0; i < childCount; i++){ - final View child = this.getChildAt(i); + int childCount = getChildCount(); + for (int index = 0; index < childCount; index++) { + final View child = getChildAt(index); child.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); + if (child.getVisibility() == View.GONE) + continue; final AutoWrapLayout.LayoutParams lp = (AutoWrapLayout.LayoutParams)child.getLayoutParams(); - width = child.getMeasuredWidth(); - height = child.getMeasuredHeight(); + childWidth = child.getMeasuredWidth(); + childHeight = child.getMeasuredHeight(); left = rightBound + lp.leftMargin; - right = left + width; + right = left + childWidth; rightBound = right + lp.rightMargin; - //if it can't drawing on a same line , skip to next line - if(rightBound > mWidth) { - left = 0 + lp.leftMargin; - right = left + width; + if (rightBound > maxRightBound) { // Go to next row + // If child can't show in parent + if (maxBottom >= maxBottomBound) + break; + left = paddingLeft + lp.leftMargin; + right = left + childWidth; rightBound = right + lp.rightMargin; lastMaxBottom = maxBottom; - top = lastMaxBottom + lp.topMargin; - bottom = top + height; + bottom = top + childHeight; bottomBound = bottom + lp.bottomMargin; - - maxBottom = bottomBound; } else { top = lastMaxBottom + lp.topMargin; - bottom = top + height; + bottom = top + childHeight; bottomBound = bottom + lp.bottomMargin; } - // Update max bottom + // Update max + if (rightBound > maxRightNoPadding) + maxRightNoPadding = rightBound; if (bottomBound > maxBottom) maxBottom = bottomBound; Rect rect = new Rect(); @@ -88,15 +125,38 @@ public class AutoWrapLayout extends ViewGroup { rect.bottom = bottom; rectList.add(rect); } - setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), maxBottom + getPaddingTop() + getPaddingBottom()); + + int measuredWidth; + int measuredHeight; + + if (widthMode == MeasureSpec.EXACTLY) + measuredWidth = maxWidth; + else { + measuredWidth = maxRightNoPadding + paddingRight; + if (widthMode == MeasureSpec.AT_MOST) + measuredWidth = measuredWidth > maxWidth ? maxWidth : measuredWidth; + } + if (heightMode == MeasureSpec.EXACTLY) + measuredHeight = maxHeight; + else { + measuredHeight = maxBottom + paddingBottom; + if (heightMode == MeasureSpec.AT_MOST) + measuredHeight = measuredHeight > maxHeight ? maxHeight : measuredHeight; + } + + Log.d(TAG, "measuredWidth = " + measuredWidth); + Log.d(TAG, "measuredHeight = " + measuredHeight); + + setMeasuredDimension(measuredWidth, measuredHeight); } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { - final int count = getChildCount() > rectList.size() ? rectList.size() : getChildCount(); - + final int count = rectList.size(); for(int i = 0; i < count; i++){ final View child = this.getChildAt(i); + if (child.getVisibility() == View.GONE) + continue; Rect rect = rectList.get(i); child.layout(rect.left, rect.top, rect.right, rect.bottom); }