Improve gallery activity

This commit is contained in:
seven332 committed 2015-08-09 00:11:51 +08:00
1 parent b6c726162d
commit 36424b11a9
36 files changed
+1492 -364

No files matched your search

@@ -16,6 +16,8 @@
package com.hippo.ehviewer.gallery;
import android.util.Log;
import com.hippo.ehviewer.client.EhConfig;
import com.hippo.ehviewer.client.data.GalleryBase;
import com.hippo.yorozuya.AssertUtils;
@@ -31,6 +33,8 @@ import java.io.OutputStreamWriter;
public class SpiderInfo {
private static final String TAG = SpiderInfo.class.getSimpleName();
private static final int VERSION = 1;
public GalleryBase galleryBase;
@@ -137,7 +141,8 @@ public class SpiderInfo {
for (;;) {
String line = IOUtils.readAsciiLine(is);
int pos = line.indexOf(":");
if (pos == -1) {
if (pos < 0) {
Log.e(TAG, "Can't parse line " + line);
continue;
}
try {
@@ -146,6 +151,7 @@ public class SpiderInfo {
tokens.set(index, token);
} catch (NumberFormatException e) {
// Empty
Log.e(TAG, "Can't parse line " + line);
}
}
} catch (EOFException e) {
@@ -655,6 +655,7 @@ public class SpiderQueen implements Runnable {
}
}
// TODO request index may
private int getRequestIndex() {
synchronized (mNextIndexLock) {
int length = mSpiderInfo.pages;
@@ -747,8 +748,6 @@ public class SpiderQueen implements Runnable {
imageUrl = result.imageUrl;
skipHathKey = result.skipHathKey;
Log.d("TAG", "index = " + index + ", imageUrl = " + imageUrl + ", skipHathKey = " + skipHathKey);
// Download image
try {
mCurrentSaveHelper = new ImageHandler.SaveHelper() {
@@ -90,8 +90,10 @@ abstract public class Animation {
}
public void start() {
mStartTime = ANIMATION_START;
mRunnedCount = 0;
if (mStartTime == NO_ANIMATION) {
mStartTime = ANIMATION_START;
mRunnedCount = 0;
}
}
public void setStartTime(long time) {
@@ -106,6 +108,11 @@ abstract public class Animation {
mStartTime = NO_ANIMATION;
}
public void forceReset() {
mStartTime = ANIMATION_START;
mRunnedCount = 0;
}
// TODO mRepeatMode
public boolean calculate(long currentTimeMillis) {
if (mStartTime == NO_ANIMATION) {
@@ -116,7 +123,7 @@ abstract public class Animation {
}
long elapse = currentTimeMillis - mStartTime;
float x = MathUtils.clamp((float) elapse / mDuration, 0f, 1f);
float x = MathUtils.clamp(mDuration == 0.0f ? 1.0f : (float) elapse / mDuration, 0.0f, 1.0f); // Avoid NaN
Interpolator i = mInterpolator;
onCalculate(i != null ? i.getInterpolation(x) : x);
@@ -16,21 +16,22 @@
package com.hippo.ehviewer.gallery.anim;
import com.hippo.yorozuya.MathUtils;
public class FloatAnimation extends Animation {
private final float mFrom;
private final float mTo;
private float mFrom;
private float mTo;
private float mCurrent;
public FloatAnimation(float from, float to) {
public void setRange(float from, float to) {
mFrom = from;
mTo = to;
mCurrent = from;
}
@Override
protected void onCalculate(float progress) {
mCurrent = mFrom + (mTo - mFrom) * progress;
mCurrent = MathUtils.lerp(mFrom, mTo, progress);
}
public float get() {
@@ -1,176 +0,0 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* 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.hippo.ehviewer.gallery.anim;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import com.hippo.ehviewer.gallery.glrenderer.GLCanvas;
import com.hippo.ehviewer.gallery.glrenderer.RawTexture;
import com.hippo.ehviewer.gallery.ui.GLView;
public class StateTransitionAnimation extends Animation {
public static class Spec {
public static final Spec OUTGOING;
public static final Spec INCOMING;
public static final Spec PHOTO_INCOMING;
private static final Interpolator DEFAULT_INTERPOLATOR =
new DecelerateInterpolator();
public int duration = 330;
public float backgroundAlphaFrom = 0;
public float backgroundAlphaTo = 0;
public float backgroundScaleFrom = 0;
public float backgroundScaleTo = 0;
public float contentAlphaFrom = 1;
public float contentAlphaTo = 1;
public float contentScaleFrom = 1;
public float contentScaleTo = 1;
public float overlayAlphaFrom = 0;
public float overlayAlphaTo = 0;
public float overlayScaleFrom = 0;
public float overlayScaleTo = 0;
public Interpolator interpolator = DEFAULT_INTERPOLATOR;
static {
OUTGOING = new Spec();
OUTGOING.backgroundAlphaFrom = 0.5f;
OUTGOING.backgroundAlphaTo = 0f;
OUTGOING.backgroundScaleFrom = 1f;
OUTGOING.backgroundScaleTo = 0f;
OUTGOING.contentAlphaFrom = 0.5f;
OUTGOING.contentAlphaTo = 1f;
OUTGOING.contentScaleFrom = 3f;
OUTGOING.contentScaleTo = 1f;
INCOMING = new Spec();
INCOMING.overlayAlphaFrom = 1f;
INCOMING.overlayAlphaTo = 0f;
INCOMING.overlayScaleFrom = 1f;
INCOMING.overlayScaleTo = 3f;
INCOMING.contentAlphaFrom = 0f;
INCOMING.contentAlphaTo = 1f;
INCOMING.contentScaleFrom = 0.25f;
INCOMING.contentScaleTo = 1f;
PHOTO_INCOMING = INCOMING;
}
private static Spec specForTransition(Transition t) {
switch (t) {
case Outgoing:
return Spec.OUTGOING;
case Incoming:
return Spec.INCOMING;
case PhotoIncoming:
return Spec.PHOTO_INCOMING;
case None:
default:
return null;
}
}
}
public static enum Transition { None, Outgoing, Incoming, PhotoIncoming }
private final Spec mTransitionSpec;
private float mCurrentContentScale;
private float mCurrentContentAlpha;
private float mCurrentBackgroundScale;
private float mCurrentBackgroundAlpha;
private float mCurrentOverlayScale;
private float mCurrentOverlayAlpha;
private RawTexture mOldScreenTexture;
public StateTransitionAnimation(Transition t, RawTexture oldScreen) {
this(Spec.specForTransition(t), oldScreen);
}
public StateTransitionAnimation(Spec spec, RawTexture oldScreen) {
mTransitionSpec = spec != null ? spec : Spec.OUTGOING;
setDuration(mTransitionSpec.duration);
setInterpolator(mTransitionSpec.interpolator);
mOldScreenTexture = oldScreen;
}
@Override
public boolean calculate(long currentTimeMillis) {
boolean retval = super.calculate(currentTimeMillis);
if (!isActive()) {
if (mOldScreenTexture != null) {
mOldScreenTexture.recycle();
mOldScreenTexture = null;
}
}
return retval;
}
@Override
protected void onCalculate(float progress) {
mCurrentContentScale = mTransitionSpec.contentScaleFrom
+ (mTransitionSpec.contentScaleTo - mTransitionSpec.contentScaleFrom) * progress;
mCurrentContentAlpha = mTransitionSpec.contentAlphaFrom
+ (mTransitionSpec.contentAlphaTo - mTransitionSpec.contentAlphaFrom) * progress;
mCurrentBackgroundAlpha = mTransitionSpec.backgroundAlphaFrom
+ (mTransitionSpec.backgroundAlphaTo - mTransitionSpec.backgroundAlphaFrom)
* progress;
mCurrentBackgroundScale = mTransitionSpec.backgroundScaleFrom
+ (mTransitionSpec.backgroundScaleTo - mTransitionSpec.backgroundScaleFrom)
* progress;
mCurrentOverlayScale = mTransitionSpec.overlayScaleFrom
+ (mTransitionSpec.overlayScaleTo - mTransitionSpec.overlayScaleFrom) * progress;
mCurrentOverlayAlpha = mTransitionSpec.overlayAlphaFrom
+ (mTransitionSpec.overlayAlphaTo - mTransitionSpec.overlayAlphaFrom) * progress;
}
private void applyOldTexture(GLView view, GLCanvas canvas, float alpha, float scale, boolean clear) {
if (mOldScreenTexture == null)
return;
if (clear) canvas.clearBuffer(view.getBackgroundColor());
canvas.save();
canvas.setAlpha(alpha);
int xOffset = view.getWidth() / 2;
int yOffset = view.getHeight() / 2;
canvas.translate(xOffset, yOffset);
canvas.scale(scale, scale, 1);
mOldScreenTexture.draw(canvas, -xOffset, -yOffset);
canvas.restore();
}
public void applyBackground(GLView view, GLCanvas canvas) {
if (mCurrentBackgroundAlpha > 0f) {
applyOldTexture(view, canvas, mCurrentBackgroundAlpha, mCurrentBackgroundScale, true);
}
}
public void applyContentTransform(GLView view, GLCanvas canvas) {
int xOffset = view.getWidth() / 2;
int yOffset = view.getHeight() / 2;
canvas.translate(xOffset, yOffset);
canvas.scale(mCurrentContentScale, mCurrentContentScale, 1);
canvas.translate(-xOffset, -yOffset);
canvas.setAlpha(mCurrentContentAlpha);
}
public void applyOverlay(GLView view, GLCanvas canvas) {
if (mCurrentOverlayAlpha > 0f) {
applyOldTexture(view, canvas, mCurrentOverlayAlpha, mCurrentOverlayScale, false);
}
}
}
@@ -24,7 +24,6 @@ import android.graphics.Canvas;
// The subclasses should override onDraw() to draw on the bitmap.
// By default CanvasTexture is not opaque.
abstract class CanvasTexture extends UploadedTexture {
protected Canvas mCanvas;
private final Config mConfig;
public CanvasTexture(int width, int height) {
@@ -36,8 +35,8 @@ abstract class CanvasTexture extends UploadedTexture {
@Override
protected Bitmap onGetBitmap() {
Bitmap bitmap = Bitmap.createBitmap(mWidth, mHeight, mConfig);
mCanvas = new Canvas(bitmap);
onDraw(mCanvas, bitmap);
Canvas canvas = new Canvas(bitmap);
onDraw(canvas, bitmap);
return bitmap;
}
@@ -23,6 +23,19 @@ public class TextTexture extends SpriteTexture {
mMaxWidth = maxWidth;
}
public int[] getTextIndexes(String text) {
char[] characters = mCharacters;
int length = text.length();
int[] indexes = new int[length];
for (int i = 0; i < length; i++) {
char ch = text.charAt(i);
indexes[i] = Arrays.binarySearch(characters, ch);
}
return indexes;
}
public float getTextWidth(String text) {
char[] characters = mCharacters;
float[] widths = mWidths;
@@ -41,7 +54,27 @@ public class TextTexture extends SpriteTexture {
return width;
}
public float getTextHeight(String text) {
public float getTextWidth(int[] indexes) {
float[] widths = mWidths;
float width = 0.0f;
int length = indexes.length;
for (int i = 0; i < length; i++) {
int index = indexes[i];
if (index >= 0) {
width += widths[index];
} else {
width += mMaxWidth;
}
}
return width;
}
public float getMaxWidth() {
return mMaxWidth;
}
public float getTextHeight() {
return mHeight;
}
@@ -61,6 +94,20 @@ public class TextTexture extends SpriteTexture {
}
}
public void drawText(GLCanvas canvas, int[] indexes, int x, int y) {
float[] widths = mWidths;
for (int i = 0, n = indexes.length; i < n; i++) {
int index = indexes[i];
if (index >= 0) {
drawSprite(canvas, index, x, y);
x += widths[index];
} else {
x += mMaxWidth;
}
}
}
/**
* Create a TextTexture to draw text
*
@@ -0,0 +1,79 @@
/*
* Copyright 2015 Hippo Seven
*
* 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.hippo.ehviewer.gallery.glrenderer;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.support.annotation.DrawableRes;
import android.support.v4.content.ContextCompat;
public class XmlResourceTexture extends UploadedTexture {
private Context mContext;
private int mResId;
private int mWidth;
private int mHeight;
public XmlResourceTexture(Context context, @DrawableRes int resId) {
mContext = context;
mResId = resId;
setOpaque(false);
}
public void setBound(int width, int height) {
mWidth = width;
mHeight = height;
invalidateContent();
}
@Override
protected Bitmap onGetBitmap() {
Drawable drawable = ContextCompat.getDrawable(mContext, mResId);
int width = mWidth;
int height = mHeight;
if (mWidth <= 0) {
width = drawable.getIntrinsicWidth();
}
if (mHeight <= 0) {
height = drawable.getIntrinsicHeight();
}
if (mWidth <= 0) {
width = 1;
}
if (mHeight <= 0) {
height = 1;
}
drawable.setBounds(0, 0, width, height);
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.draw(canvas);
return bitmap;
}
@Override
protected void onFreeBitmap(Bitmap bitmap) {
if (!inFinalizer()) {
bitmap.recycle();
}
}
}
@@ -1,6 +1,6 @@
package com.hippo.ehviewer.gallery.ui;
public class FrameView extends GLView {
public class FrameLayout extends GLView {
@Override
protected void onMeasure(int widthSpec, int heightSpec) {
@@ -19,10 +19,12 @@ package com.hippo.ehviewer.gallery.ui;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.opengl.GLSurfaceView;
import android.os.Build;
import android.os.Process;
import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
@@ -36,6 +38,7 @@ import com.hippo.ehviewer.gallery.glrenderer.UploadedTexture;
import com.hippo.ehviewer.gallery.util.ApiHelper;
import com.hippo.ehviewer.gallery.util.GalleryUtils;
import com.hippo.ehviewer.gallery.util.MotionEventHelper;
import com.hippo.widget.FitPaddingImpl;
import com.hippo.yorozuya.AssertUtils;
import java.util.ArrayDeque;
@@ -609,6 +612,33 @@ public class GLRootView extends GLSurfaceView
}
}
@SuppressWarnings("deprecation")
@Override
protected boolean fitSystemWindows(@NonNull Rect insets) {
int fitPaddingLeft = insets.left;
int fitPaddingTop = insets.top;
int fitPaddingRight = insets.right;
int fitPaddingBottom = insets.bottom;
GLView contentView = mContentView;
if (contentView != null) {
for (int i = 0, n = contentView.getComponentCount(); i < n; i++) {
GLView component = contentView.getComponent(i);
if (component instanceof FitPaddingImpl) {
((FitPaddingImpl) component).onFitPadding(fitPaddingLeft ,fitPaddingTop,
fitPaddingRight, fitPaddingBottom);
}
}
}
insets.left = 0;
insets.top = 0;
insets.right = 0;
insets.bottom = 0;
return super.fitSystemWindows(insets);
}
private static abstract class BaseConfigChooser implements EGLConfigChooser {
public BaseConfigChooser(int[] configSpec) {
@@ -23,7 +23,6 @@ import android.util.Log;
import android.view.MotionEvent;
import com.hippo.ehviewer.gallery.anim.CanvasAnimation;
import com.hippo.ehviewer.gallery.anim.StateTransitionAnimation;
import com.hippo.ehviewer.gallery.glrenderer.GLCanvas;
import com.hippo.ehviewer.gallery.glrenderer.GLPaint;
import com.hippo.yorozuya.AssertUtils;
@@ -45,10 +44,12 @@ import java.util.ArrayList;
// from main thread (like a Handler) in your GLView, you need to call
// lockRendering() if the rendering thread should not run at the same time.
//
// TODO Add store state
// TODO Add click listener
public class GLView {
private static final String TAG = "GLView";
private static final boolean DEBUG_DRAW_BOUNDS = false;
private static final boolean DEBUG_DRAW_BOUNDS = true;
public static final int VISIBLE = 0;
public static final int INVISIBLE = 1;
@@ -107,8 +108,7 @@ public class GLView {
private LayoutParams mLayoutParams;
private float [] mBackgroundColor;
private StateTransitionAnimation mTransition;
private int mBackgroundColor = Color.TRANSPARENT;
public void startAnimation(CanvasAnimation animation) {
GLRoot root = getGLRoot();
@@ -195,7 +195,9 @@ public class GLView {
}
// Ensure params is valid
if (!checkLayoutParams(params)) {
if (params == null) {
params = generateDefaultLayoutParams();
} else if (!checkLayoutParams(params)) {
params = generateLayoutParams(params);
}
@@ -319,17 +321,16 @@ public class GLView {
}
protected void render(GLCanvas canvas) {
boolean transitionActive = false;
if (mTransition != null && mTransition.calculate(AnimationTime.get())) {
invalidate();
transitionActive = mTransition.isActive();
// render background color
if (Color.alpha(mBackgroundColor) != 0) {
canvas.fillRect(0, 0, getWidth(), getHeight(), mBackgroundColor);
}
renderBackground(canvas);
// render content
onRender(canvas);
// render child
canvas.save();
if (transitionActive) {
mTransition.applyContentTransform(this, canvas);
}
for (int i = 0, n = getComponentCount(); i < n; ++i) {
GLView component = getComponent(i);
if (Rect.intersects(mRenderCheckBounds, component.mBounds)) {
@@ -338,40 +339,19 @@ public class GLView {
}
canvas.restore();
// render bounds
if (DEBUG_DRAW_BOUNDS) {
canvas.drawRect(0, 0, getWidth(), getHeight(), mDrawBoundsPaint);
}
if (transitionActive) {
mTransition.applyOverlay(this, canvas);
}
}
protected void onRender(GLCanvas canvas) {
}
public void setIntroAnimation(StateTransitionAnimation intro) {
mTransition = intro;
if (mTransition != null) mTransition.start();
}
public float [] getBackgroundColor() {
return mBackgroundColor;
}
public void setBackgroundColor(float [] color) {
public void setBackgroundColor(int color) {
mBackgroundColor = color;
}
protected void renderBackground(GLCanvas view) {
if (mBackgroundColor != null) {
view.clearBuffer(mBackgroundColor);
}
if (mTransition != null && mTransition.isActive()) {
mTransition.applyBackground(this, view);
}
}
protected void renderChild(GLCanvas canvas, GLView component) {
if (component.getVisibility() != GLView.VISIBLE
&& component.mAnimation == null) return;
@@ -449,6 +429,26 @@ public class GLView {
return onTouch(event);
}
public void setPaddings(int paddingLeft, int paddingTop, int paddingRight, int paddingBottom) {
mPaddings.set(paddingLeft, paddingTop, paddingRight, paddingBottom);
}
public void setPaddingLeft(int paddingLeft) {
mPaddings.left = paddingLeft;
}
public void setPaddingTop(int paddingTop) {
mPaddings.top = paddingTop;
}
public void setPaddingRight(int paddingRight) {
mPaddings.right = paddingRight;
}
public void setPaddingBottom(int paddingBottom) {
mPaddings.bottom = paddingBottom;
}
public Rect getPaddings() {
return mPaddings;
}
@@ -498,11 +498,11 @@ public class GLView {
}
protected int getSuggestedMinimumHeight() {
return getMinimumHeight();
return getMinimumHeight() + mPaddings.top + mPaddings.bottom;
}
protected int getSuggestedMinimumWidth() {
return getMinimumWidth();
return getMinimumWidth() + mPaddings.left + mPaddings.right;
}
/**
@@ -574,6 +574,28 @@ public class GLView {
boolean changeSize, int left, int top, int right, int bottom) {
}
/**
* Utility to return a default begin. Uses the supplied number as left or top.
*
* @param size the parent size
* @param specSize the child size
* @param paddingBeign the padding begin
* @param paddingFinish the padding finish
* @param position the {@link Gravity#POSITION_BEGIN} or {@link Gravity#POSITION_CENTER} or
* {@link Gravity#POSITION_FINISH}
* @return the begin size
*/
public static int getDefaultBegin(int size, int specSize, int paddingBeign, int paddingFinish,
@Gravity.PositionMode int position) {
if (position == Gravity.POSITION_FINISH) {
return size - paddingFinish - specSize;
} else if (position == Gravity.POSITION_CENTER) {
return ((size - paddingBeign - paddingFinish) / 2) - (specSize / 2) + paddingBeign;
} else {
return paddingBeign;
}
}
/**
* Utility to return a default size. Uses the supplied size if the
* MeasureSpec imposed no constraints. Will get larger if allowed
@@ -601,6 +623,32 @@ public class GLView {
return result;
}
/**
* Utility to return a max size. Uses the supplied size if the
* MeasureSpec imposed no constraints. Will get larger if allowed
* by the MeasureSpec.
*
* @param size Default size for this view
* @param measureSpec Constraints imposed by the parent
* @return The size this view should be.
*/
public static int getMaxSize(int size, int measureSpec) {
int result = size;
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
switch (specMode) {
case MeasureSpec.UNSPECIFIED:
result = size;
break;
case MeasureSpec.EXACTLY:
case MeasureSpec.AT_MOST:
result = specSize;
break;
}
return result;
}
public static int getComponentSpec(int spec, int childSize) {
int specMode = MeasureSpec.getMode(spec);
int specSize = MeasureSpec.getSize(spec);
@@ -969,6 +1017,10 @@ public class GLView {
public GravityLayoutParams(GLView.LayoutParams source) {
super(source);
if (source instanceof GravityLayoutParams) {
gravity = ((GravityLayoutParams) source).gravity;
}
}
public GravityLayoutParams(int width, int height) {
@@ -0,0 +1,89 @@
/*
* Copyright 2015 Hippo Seven
*
* 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.hippo.ehviewer.gallery.ui;
import android.content.Context;
import com.hippo.ehviewer.R;
import com.hippo.yorozuya.LayoutUtils;
public class GalleryLayout extends FrameLayout implements GalleryView.ActionListener, GalleryPanel.ActionListener {
private GalleryView mGalleryView;
private GalleryPanel mGalleryPanel;
private ActionListener mActionListener;
public GalleryLayout(Context context, ActionListener listener) {
mActionListener = listener;
setBackgroundColor(context.getResources().getColor(R.color.gallery_background));
mGalleryView = new GalleryView(context, 0, this);
mGalleryView.setProgressSize(LayoutUtils.dp2pix(context, 56));
mGalleryView.setInterval(LayoutUtils.dp2pix(context, 48));
mGalleryPanel = new GalleryPanel(context, this);
addComponent(mGalleryView, new GravityLayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
addComponent(mGalleryPanel, new GravityLayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}
public GalleryView getGalleryView() {
return mGalleryView;
}
public GalleryPanel getGalleryPanel() {
return mGalleryPanel;
}
@Override
public void onTapCenter() {
mGalleryPanel.setShown(true);
mActionListener.onShowGalleryPanel();
}
@Override
public void onSetMode(GalleryView.Mode mode) {
mGalleryPanel.setRange(1, mGalleryView.getPages());
}
@Override
public void onScrollToPage(int page, boolean internal) {
if (internal) {
mGalleryPanel.setProgress(page + 1);
}
}
@Override
public void onSetProgress(int newProgress, int oldProgress, boolean byUser) {
if (byUser) {
mGalleryView.scrollToPage(newProgress - 1);
}
}
@Override
public void onHide() {
mActionListener.onHideGalleryPanel();
}
public interface ActionListener {
void onShowGalleryPanel();
void onHideGalleryPanel();
}
}
@@ -6,10 +6,10 @@ import android.graphics.Rect;
import com.hippo.ehviewer.gallery.glrenderer.TextTexture;
import com.hippo.yorozuya.LayoutUtils;
public class GalleryPageView extends FrameView {
public class GalleryPageView extends FrameLayout {
public ScaledImageView mImageView;
public LinearView mLinearView;
public LinearLayout mLinearLayout;
public TextView mIndexView;
public ProgressView mProgressView;
@@ -23,8 +23,8 @@ public class GalleryPageView extends FrameView {
public GalleryPageView(Context context) {
mImageView = new ScaledImageView();
mLinearView = new LinearView();
mLinearView.setInterval(LayoutUtils.dp2pix(context, 24)); // 12dp
mLinearLayout = new LinearLayout();
mLinearLayout.setInterval(LayoutUtils.dp2pix(context, 24)); // 12dp
mIndexView = new TextView(sTextTexture);
mProgressView = new ProgressView();
mProgressView.setMinimumWidth(LayoutUtils.dp2pix(context, 56)); // 56dp
@@ -33,11 +33,11 @@ public class GalleryPageView extends FrameView {
GravityLayoutParams lp = new GravityLayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.CENTER_HORIZONTAL;
mLinearView.addComponent(mIndexView, lp);
mLinearLayout.addComponent(mIndexView, lp);
lp = new GravityLayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.CENTER_HORIZONTAL;
mLinearView.addComponent(mProgressView, lp);
mLinearLayout.addComponent(mProgressView, lp);
lp = new GravityLayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
@@ -46,7 +46,7 @@ public class GalleryPageView extends FrameView {
lp = new GravityLayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.CENTER;
addComponent(mLinearView, lp);
addComponent(mLinearLayout, lp);
}
private void updateSeen() {
@@ -0,0 +1,228 @@
/*
* Copyright 2015 Hippo Seven
*
* 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.hippo.ehviewer.gallery.ui;
import android.content.Context;
import android.view.MotionEvent;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.gallery.anim.FloatAnimation;
import com.hippo.ehviewer.gallery.glrenderer.GLCanvas;
import com.hippo.ehviewer.gallery.glrenderer.TextTexture;
import com.hippo.ehviewer.gallery.glrenderer.XmlResourceTexture;
import com.hippo.util.AnimationUtils;
import com.hippo.widget.FitPaddingImpl;
import com.hippo.yorozuya.LayoutUtils;
public class GalleryPanel extends GLView implements FitPaddingImpl, Slider.OnSetProgressListener {
private Context mContext;
private LinearLayout mRightView;
private XmlResourceView mScreenRotation;
private XmlResourceView mRefresh;
private XmlResourceView mShare;
private LinearLayout mBottomView;
private TextView mProgressTextView;
private TextView mPagesTextView;
private Slider mSlider;
private float mShowPercent = 0.0f;
private int mEnd = 0;
private ActionListener mListener;
private FloatAnimation mAnimation;
private boolean mShown = false;
private static TextTexture sTextTexture;
public static void setTextTexture(TextTexture textTexture) {
sTextTexture = textTexture;
}
public GalleryPanel(Context context, ActionListener listener) {
mContext = context;
mListener = listener;
int background = context.getResources().getColor(R.color.gallery_panel_background);
LinearLayout.LayoutParams lp;
int dp8 = LayoutUtils.dp2pix(context, 8);
mRightView = new LinearLayout();
mRightView.setOrientation(LinearLayout.VERTICAL);
mRightView.setBackgroundColor(background);
mRightView.setInterval(dp8);
mRightView.setPaddings(dp8, dp8, dp8, dp8);
mScreenRotation = new XmlResourceView();
XmlResourceTexture screenRotationTexture = new XmlResourceTexture(context, R.drawable.ic_screen_rotation_dark_x48);
mScreenRotation.setTexture(screenRotationTexture);
mRefresh = new XmlResourceView();
XmlResourceTexture refreshTexture = new XmlResourceTexture(context, R.drawable.ic_refresh_dark_x48);
mRefresh.setTexture(refreshTexture);
mShare = new XmlResourceView();
XmlResourceTexture shareTexture = new XmlResourceTexture(context, R.drawable.ic_share_dark_x48);
mShare.setTexture(shareTexture);
int actionSize = LayoutUtils.dp2pix(context, 48);
lp = new LinearLayout.LayoutParams(
actionSize, actionSize);
mRightView.addComponent(mScreenRotation, lp);
lp = new LinearLayout.LayoutParams(
actionSize, actionSize);
mRightView.addComponent(mRefresh, lp);
lp = new LinearLayout.LayoutParams(
actionSize, actionSize);
mRightView.addComponent(mShare, lp);
mBottomView = new LinearLayout();
mBottomView.setOrientation(LinearLayout.HORIZONTAL);
mBottomView.setBackgroundColor(background);
mBottomView.setPaddingLeft(LayoutUtils.dp2pix(context, 8));
mBottomView.setPaddingRight(LayoutUtils.dp2pix(context, 8));
mProgressTextView = new TextView(sTextTexture);
mProgressTextView.setGravity(Gravity.CENTER);
mPagesTextView = new TextView(sTextTexture);
mPagesTextView.setGravity(Gravity.CENTER);
mSlider = new Slider(context);
mSlider.setPaddings(LayoutUtils.dp2pix(context, 8), LayoutUtils.dp2pix(context, 18),
LayoutUtils.dp2pix(context, 8), LayoutUtils.dp2pix(context, 18));
mSlider.setColor(context.getResources().getColor(R.color.theme_primary));
mSlider.setOnSetProgressListener(this);
lp = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.CENTER_VERTICAL;
mBottomView.addComponent(mProgressTextView, lp);
lp = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.CENTER_VERTICAL;
lp.weight = 1;
mBottomView.addComponent(mSlider, lp);
lp = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.CENTER_VERTICAL;
mBottomView.addComponent(mPagesTextView, lp);
addComponent(mRightView, new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
addComponent(mBottomView, new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
mAnimation = new FloatAnimation() {
@Override
protected void onCalculate(float progress) {
super.onCalculate(progress);
mShowPercent = get();
mRightView.offsetLeftAndRight(getWidth() - (int) (mRightView.getWidth() * mShowPercent) - mRightView.bounds().left);
mBottomView.offsetTopAndBottom(getHeight() - (int) (mBottomView.getMeasuredHeight() * mShowPercent) - mBottomView.bounds().top);
}
};
mAnimation.setInterpolator(AnimationUtils.FAST_SLOW_INTERPOLATOR);
}
protected void setShown(boolean shown) {
if (mShown != shown) {
mShown = shown;
mAnimation.setRange(mShowPercent, shown ? 1.0f : 0.0f);
mAnimation.setDuration(300); // TODO
mAnimation.forceReset();
invalidate();
if (!shown) {
mListener.onHide();
}
}
}
@Override
protected boolean onTouch(MotionEvent event) {
if (mShown && event.getAction() == MotionEvent.ACTION_UP) {
setShown(false);
}
return mShown;
}
@Override
protected void onMeasure(int widthSpec, int heightSpec) {
measureComponent(mRightView, widthSpec, heightSpec);
measureComponent(mBottomView, widthSpec, heightSpec);
super.onMeasure(widthSpec, heightSpec);
}
@Override
protected void onLayout(
boolean changeSize, int left, int top, int right, int bottom) {
if (changeSize) {
int width = getWidth();
int height = getHeight();
int l = width - (int) (mRightView.getMeasuredWidth() * mShowPercent);
mRightView.layout(l, height / 2 - mRightView.getMeasuredHeight() / 2,
l + mRightView.getMeasuredWidth(), height / 2 + mRightView.getMeasuredHeight() / 2);
int t = height - (int) (mBottomView.getMeasuredHeight() * mShowPercent);
mBottomView.layout(0, t, width, t + mBottomView.getMeasuredHeight());
}
}
public void setRange(int start, int end) {
mSlider.setRange(start, end);
mEnd = end;
String pages = Integer.toString(end);
mProgressTextView.setMinimumWidth((int) (sTextTexture.getMaxWidth() * pages.length()));
mPagesTextView.setMinimumWidth((int) (sTextTexture.getMaxWidth() * pages.length()));
mPagesTextView.setText(pages);
}
public void setProgress(int progress) {
mSlider.setProgress(progress);
mProgressTextView.setText(Integer.toString(progress));
}
@Override
public void onFitPadding(int left, int top, int right, int bottom) {
mRightView.setPaddingRight(LayoutUtils.dp2pix(mContext, 8) + right);
mBottomView.setPaddingBottom(bottom);
mBottomView.setPaddingRight(LayoutUtils.dp2pix(mContext, 8) + right);
}
@Override
public void onSetProgress(int newProgress, int oldProgress, boolean byUser) {
mListener.onSetProgress(newProgress, oldProgress, byUser);
mProgressTextView.setText(Integer.toString(newProgress));
}
@Override
protected void onRender(GLCanvas canvas) {
if (mAnimation.calculate(AnimationTime.get())) {
invalidate();
}
super.onRender(canvas);
}
public interface ActionListener {
void onSetProgress(int newProgress, int oldProgress, boolean byUser);
void onHide();
}
}
@@ -1,12 +1,12 @@
package com.hippo.ehviewer.gallery.ui;
import android.content.Context;
import android.graphics.Rect;
import android.util.SparseArray;
import android.view.MotionEvent;
import android.view.animation.Interpolator;
import android.view.animation.OvershootInterpolator;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.gallery.anim.Animation;
import com.hippo.ehviewer.gallery.glrenderer.GLCanvas;
import com.hippo.ehviewer.gallery.util.GalleryUtils;
@@ -40,6 +40,10 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
}
};
private static final float[] LEFT_AREA = {0.0f, 0.0f, 1.0f / 3.0f, 1f};
private static final float[] RIGHT_AREA = {2.0f / 3.0f, 0.0f, 1.0f, 1f};
private static final float[] CENTER_AREA = {1.0f / 3.0f, 2.0f / 5.0f, 2.0f / 3.0f, 3.0f / 5.0f};
private static final Interpolator SMOOTH_SCALER_INTERPOLATOR = new OvershootInterpolator();
private boolean mEnableRequestLayout = true;
@@ -63,6 +67,10 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
private boolean mScroll = false;
private boolean mTouched = false;
private Rect mLeftArea = new Rect();
private Rect mRightArea = new Rect();
private Rect mCenterArea = new Rect();
private int mDeltaX;
private int[] mScrollRemain = new int[2];
@@ -84,6 +92,8 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
private boolean mRequestFill = false;
private ActionListener mListener;
public enum Mode {
NONE, // Just a progress view
LEFT_TO_RIGHT,
@@ -107,7 +117,9 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
CENTER
}
public GalleryView(Context context) {
public GalleryView(Context context, int firstShownIndex, ActionListener listener) {
mFirstShownIndex = firstShownIndex;
mListener = listener;
mEdgeView = new EdgeView(context);
mGestureRecognizer = new GestureRecognizer(context, this);
mSmoothScroller = new SmoothScroller();
@@ -115,8 +127,6 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
mSmoothScaler = new SmoothScaler();
mSmoothScaler.setInterpolator(SMOOTH_SCALER_INTERPOLATOR);
mRecycler = new Recycler();
setBackgroundColor(GalleryUtils.intColorToFloatARGBArray(context.getResources().getColor(R.color.gallery_background)));
}
@Override
@@ -135,8 +145,15 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
public void setMode(Mode mode) {
if (mMode != mode) {
Mode oldMode = mMode;
mMode = mode;
superRequestLayout();
mListener.onSetMode(mode);
if (oldMode == Mode.NONE) {
mFirstShownIndex = MathUtils.clamp(mFirstShownIndex, 0, mAdapter.getPages() - 1);
mListener.onScrollToPage(mFirstShownIndex, true);
}
}
}
@@ -154,6 +171,10 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
superRequestLayout();
}
public int getPages() {
return mAdapter.getPages();
}
public void superRequestLayout() {
super.requestLayout();
}
@@ -168,6 +189,10 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
}
public void scrollToPage(int page) {
scrollToPageInternal(page, false);
}
private void scrollToPageInternal(int page, boolean internal) {
mSmoothScroller.forceStop();
mSmoothScaler.forceStop();
@@ -178,6 +203,8 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
mFirstShownIndex = page;
mLayoutOffset = 0;
requestFill();
mListener.onScrollToPage(page, internal);
}
public void smoothScrollToPage(int page) {
@@ -196,6 +223,7 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
boolean reverse = mMode == Mode.RIGHT_TO_LEFT;
// Fix TODO What if offset is very large
int oldFirstShownIndex = mFirstShownIndex;
int width = getWidth();
if (!mHaveChangePage) {
if (mLayoutOffset > mInterval) {
@@ -221,6 +249,10 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
}
}
if (mFirstShownIndex != oldFirstShownIndex) {
mListener.onScrollToPage(mFirstShownIndex, true);
}
requestFill();
}
@@ -238,21 +270,37 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
@Override
public boolean onSingleTapConfirmed(float x, float y) {
if ((mMode == Mode.LEFT_TO_RIGHT || mMode == Mode.RIGHT_TO_LEFT) && mLayoutOffset == 0) {
if (x < getWidth() / 2) {
if (mFirstShownIndex > 0) {
scrollToPage(mFirstShownIndex - 1);
if (mLeftArea.contains((int) x, (int) y)) {
if (mMode == Mode.LEFT_TO_RIGHT) {
if (mFirstShownIndex > 0) {
scrollToPageInternal(mFirstShownIndex - 1, true);
} else {
mEdgeView.onPull(getWidth() * 2, (int) y, EdgeView.LEFT);
}
} else {
mEdgeView.onPull(getWidth() * 2, (int) y, EdgeView.LEFT);
if (mFirstShownIndex < mAdapter.getPages() - 1) {
scrollToPageInternal(mFirstShownIndex + 1, true);
} else {
mEdgeView.onPull(getWidth() * 2, (int) y, EdgeView.LEFT);
}
}
} else {
if (mFirstShownIndex < mAdapter.getPages() - 1) {
scrollToPage(mFirstShownIndex + 1);
} else if (mRightArea.contains((int) x, (int) y)) {
if (mMode == Mode.LEFT_TO_RIGHT) {
if (mFirstShownIndex < mAdapter.getPages() - 1) {
scrollToPageInternal(mFirstShownIndex + 1, true);
} else {
mEdgeView.onPull(getWidth() * 2, (int) y, EdgeView.RIGHT);
}
} else {
mEdgeView.onPull(getWidth() * 2, (int) y, EdgeView.RIGHT);
if (mFirstShownIndex > 0) {
scrollToPageInternal(mFirstShownIndex - 1, true);
} else {
mEdgeView.onPull(getWidth() * 2, (int) y, EdgeView.RIGHT);
}
}
} else if (mCenterArea.contains((int) x, (int) y)) {
mListener.onTapCenter();
}
}
@@ -533,6 +581,17 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
mLayoutOffset = 0;
mHaveChangePage = false;
fill();
if (changeSize) {
int width = right - left;
int height = bottom - top;
mLeftArea.set((int) (LEFT_AREA[0] * width), (int) (LEFT_AREA[1] * height),
(int) (LEFT_AREA[2] * width), (int) (LEFT_AREA[3] * height));
mRightArea.set((int) (RIGHT_AREA[0] * width), (int) (RIGHT_AREA[1] * height),
(int) (RIGHT_AREA[2] * width), (int) (RIGHT_AREA[3] * height));
mCenterArea.set((int) (CENTER_AREA[0] * width), (int) (CENTER_AREA[1] * height),
(int) (CENTER_AREA[2] * width), (int) (CENTER_AREA[3] * height));
}
}
public GalleryPageView getPage(int index) {
@@ -922,4 +981,13 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
}
}
}
public interface ActionListener {
void onTapCenter();
void onSetMode(Mode mode);
void onScrollToPage(int page, boolean internal);
}
}
@@ -1,7 +1,20 @@
package com.hippo.ehviewer.gallery.ui;
import android.support.annotation.IntDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
public class Gravity {
@IntDef({POSITION_BEGIN, POSITION_CENTER, POSITION_FINISH})
@Retention(RetentionPolicy.SOURCE)
public @interface PositionMode {}
@IntDef({HORIZONTAL, VERTICAL})
@Retention(RetentionPolicy.SOURCE)
public @interface DirectionMode {}
public static final int NO_GRAVITY = 0x0000;
public static final int LEFT = 0x0001;
@@ -16,6 +29,13 @@ public class Gravity {
public static final int HORIZONTAL_MASK = CENTER_HORIZONTAL;
public static final int VERTICAL_MASK = CENTER_VERTICAL;
public static final int POSITION_BEGIN = 0;
public static final int POSITION_CENTER = 1;
public static final int POSITION_FINISH = 2;
public static final int HORIZONTAL = 0;
public static final int VERTICAL = 1;
public static boolean centerHorizontal(int gravity) {
return (gravity & HORIZONTAL_MASK) == CENTER_HORIZONTAL;
}
@@ -39,4 +59,24 @@ public class Gravity {
public static boolean bottom(int gravity) {
return (gravity & VERTICAL_MASK) == BOTTOM;
}
public static @PositionMode int getPosition(int gravity, @DirectionMode int direction) {
if (direction == HORIZONTAL) {
if (right(gravity)) {
return POSITION_FINISH;
} else if (centerHorizontal(gravity)) {
return POSITION_CENTER;
} else {
return POSITION_BEGIN;
}
} else {
if (bottom(gravity)) {
return POSITION_FINISH;
} else if (centerVertical(gravity)) {
return POSITION_CENTER;
} else {
return POSITION_BEGIN;
}
}
}
}
@@ -0,0 +1,208 @@
package com.hippo.ehviewer.gallery.ui;
import android.graphics.Rect;
import android.support.annotation.IntDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
public class LinearLayout extends GLView {
@IntDef({HORIZONTAL, VERTICAL})
@Retention(RetentionPolicy.SOURCE)
public @interface OrientationMode {}
public static final int HORIZONTAL = 0;
public static final int VERTICAL = 1;
private int mInterval = 0;
private int mOrientation = VERTICAL;
private List<GLView> mTempList = new ArrayList<>();
public void setInterval(int interval) {
if (mInterval != interval) {
mInterval = interval;
requestLayout();
}
}
/**
* Should the layout be a column or a row.
* @param orientation Pass {@link #HORIZONTAL} or {@link #VERTICAL}. Default
* value is {@link #HORIZONTAL}.
*/
public void setOrientation(@OrientationMode int orientation) {
if (mOrientation != orientation) {
mOrientation = orientation;
requestLayout();
}
}
@Override
protected void onMeasure(int widthSpec, int heightSpec) {
int layoutWidthSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthSpec) - mPaddings.left - mPaddings.right,
MeasureSpec.getMode(widthSpec));
int layoutHeightSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightSpec) - mPaddings.top - mPaddings.bottom,
MeasureSpec.getMode(heightSpec));
if (mOrientation == HORIZONTAL && MeasureSpec.getMode(widthSpec) == MeasureSpec.EXACTLY) {
int width = MeasureSpec.getSize(layoutWidthSpec);
float sumWeight = 0.0f;
for (int i = 0, n = getComponentCount(); i < n; i++) {
final GLView component = getComponent(i);
final LayoutParams lp = (LayoutParams) component.getLayoutParams();
if (lp.weight > 0.0f) {
sumWeight += lp.weight;
mTempList.add(component);
} else {
measureComponent(component, layoutWidthSpec, layoutHeightSpec);
width -= component.getMeasuredWidth();
}
}
for (GLView component : mTempList) {
final LayoutParams lp = (LayoutParams) component.getLayoutParams();
final int componentWidthSpec = MeasureSpec.makeMeasureSpec(
(int) (width * lp.weight / sumWeight), MeasureSpec.EXACTLY);
final int componentHeightSpec = getComponentSpec(layoutHeightSpec, lp.height);
component.measure(componentWidthSpec, componentHeightSpec);
}
mTempList.clear();
} else if (mOrientation == VERTICAL && MeasureSpec.getMode(heightSpec) == MeasureSpec.EXACTLY) {
int height = MeasureSpec.getSize(layoutHeightSpec);
float sumWeight = 0.0f;
for (int i = 0, n = getComponentCount(); i < n; i++) {
final GLView component = getComponent(i);
final LayoutParams lp = (LayoutParams) component.getLayoutParams();
if (lp.weight > 0.0f) {
sumWeight += lp.weight;
mTempList.add(component);
} else {
measureComponent(component, layoutWidthSpec, layoutHeightSpec);
height -= component.getMeasuredHeight();
}
}
for (GLView component : mTempList) {
final LayoutParams lp = (LayoutParams) component.getLayoutParams();
final int componentWidthSpec = getComponentSpec(layoutWidthSpec, lp.width);
final int componentHeightSpec = MeasureSpec.makeMeasureSpec(
(int) (height * lp.weight / sumWeight), MeasureSpec.EXACTLY);
component.measure(componentWidthSpec, componentHeightSpec);
}
mTempList.clear();
} else {
measureAllComponents(this, layoutWidthSpec, layoutHeightSpec);
}
int maxWidth = 0;
int maxHeight = 0;
for (int i = 0, n = getComponentCount(); i < n; i++) {
GLView component = getComponent(i);
if (mOrientation == VERTICAL) {
maxWidth = Math.max(maxWidth, component.getMeasuredWidth());
if (i != 0) {
maxHeight += mInterval;
}
maxHeight += component.getMeasuredHeight();
} else if (mOrientation == HORIZONTAL) {
maxHeight = Math.max(maxHeight, component.getMeasuredHeight());
if (i != 0) {
maxWidth += mInterval;
}
maxWidth += component.getMeasuredWidth();
}
}
Rect paddings = getPaddings();
maxWidth = maxWidth + paddings.left + paddings.right;
maxHeight = maxHeight + paddings.top + paddings.bottom;
setMeasuredSize(getDefaultSize(maxWidth, widthSpec), getDefaultSize(maxHeight, heightSpec));
}
@Override
protected void onLayout(boolean changeSize, int left, int top, int right, int bottom) {
int width = getWidth();
int height = getHeight();
Rect paddings = getPaddings();
int componentLeft;
int componentTop;
if (mOrientation == VERTICAL) {
componentTop = paddings.top;
for (int i = 0, n = getComponentCount(); i < n; i++) {
GLView component = getComponent(i);
int measureWidth = component.getMeasuredWidth();
int measureHeight = component.getMeasuredHeight();
LayoutParams lp = (LayoutParams) component.getLayoutParams();
componentLeft = getDefaultBegin(width, measureWidth, paddings.left, paddings.right,
Gravity.getPosition(lp.gravity, Gravity.HORIZONTAL));
component.layout(componentLeft, componentTop,
componentLeft + measureWidth, componentTop + measureHeight);
componentTop += measureHeight + mInterval;
}
} else if (mOrientation == HORIZONTAL) {
componentLeft = paddings.left;
for (int i = 0, n = getComponentCount(); i < n; i++) {
GLView component = getComponent(i);
int measureWidth = component.getMeasuredWidth();
int measureHeight = component.getMeasuredHeight();
LayoutParams lp = (LayoutParams) component.getLayoutParams();
componentTop = getDefaultBegin(height, measureHeight, paddings.top, paddings.bottom,
Gravity.getPosition(lp.gravity, Gravity.VERTICAL));
component.layout(componentLeft, componentTop,
componentLeft + measureWidth, componentTop + measureHeight);
componentLeft += measureWidth + mInterval;
}
}
}
@Override
protected boolean checkLayoutParams(GLView.LayoutParams p) {
return p instanceof LayoutParams;
}
@Override
protected GLView.LayoutParams generateDefaultLayoutParams() {
return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
}
@Override
protected GLView.LayoutParams generateLayoutParams(GLView.LayoutParams p) {
return p == null ? generateDefaultLayoutParams() : new LayoutParams(p);
}
public static class LayoutParams extends GravityLayoutParams {
public float weight = 0.0f;
public LayoutParams(GLView.LayoutParams source) {
super(source);
if (source instanceof LayoutParams) {
weight = ((LayoutParams) source).weight;
}
}
public LayoutParams(int width, int height) {
super(width, height);
}
}
}
@@ -1,74 +0,0 @@
package com.hippo.ehviewer.gallery.ui;
public class LinearView extends GLView {
public int mInterval;
public void setInterval(int interval) {
mInterval = interval;
requestLayout();
}
// TODO
@Override
protected void onMeasure(int widthSpec, int heightSpec) {
measureAllComponents(this, widthSpec, heightSpec);
int maxWidth = 0;
int maxHeight = 0;
int n = getComponentCount();
for (int i = 0; i < n; i++) {
GLView component = getComponent(i);
maxWidth = Math.max(maxWidth, component.getMeasuredWidth());
if (i != 0) {
maxHeight += mInterval;
}
maxHeight += component.getMeasuredHeight();
}
setMeasuredSize(getDefaultSize(maxWidth, widthSpec), getDefaultSize(maxHeight, heightSpec));
}
@Override
protected void onLayout(boolean changeSize, int left, int top, int right, int bottom) {
int width = getWidth();
int componentLeft;
int componentTop = 0;
for (int i = 0, n = getComponentCount(); i < n; i++) {
GLView component = getComponent(i);
int measureWidth = component.getMeasuredWidth();
int measureHeight = component.getMeasuredHeight();
GravityLayoutParams lp = (GravityLayoutParams) component.getLayoutParams();
int gravity = lp.gravity;
if (Gravity.centerHorizontal(gravity)) {
componentLeft = (width / 2) - (measureWidth / 2);
} else if (Gravity.right(gravity)) {
componentLeft = width - measureWidth;
} else {
componentLeft = 0;
}
component.layout(componentLeft, componentTop,
componentLeft + measureWidth, componentTop + measureHeight);
componentTop += measureHeight + mInterval;
}
}
@Override
protected boolean checkLayoutParams(GLView.LayoutParams p) {
return p instanceof GravityLayoutParams;
}
@Override
protected LayoutParams generateDefaultLayoutParams() {
return new GravityLayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
}
@Override
protected LayoutParams generateLayoutParams(GLView.LayoutParams p) {
return p == null ? generateDefaultLayoutParams() : new GravityLayoutParams(p);
}
}
@@ -22,10 +22,10 @@ import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import com.hippo.ehviewer.gallery.anim.Animation;
import com.hippo.ehviewer.gallery.anim.FloatAnimation;
import com.hippo.ehviewer.gallery.glrenderer.GLCanvas;
import com.hippo.ehviewer.gallery.glrenderer.GLPaint;
import com.hippo.vectorold.animation.PathInterpolator;
import com.hippo.yorozuya.MathUtils;
import java.util.ArrayList;
import java.util.List;
@@ -76,42 +76,50 @@ public class ProgressView extends GLView {
}
public void setupAnimations() {
Animation trimStart = new Animation() {
FloatAnimation trimStart = new FloatAnimation() {
@Override
protected void onCalculate(float progress) {
mTrimStart = MathUtils.lerp(0.0f, 0.75f, progress);
super.onCalculate(progress);
mTrimStart = get();
}
};
trimStart.setRange(0.0f, 0.75f);
trimStart.setDuration(1333L);
trimStart.setInterpolator(TRIM_START_INTERPOLATOR);
trimStart.setRepeatCount(Animation.INFINITE);
Animation trimEnd = new Animation() {
FloatAnimation trimEnd = new FloatAnimation() {
@Override
protected void onCalculate(float progress) {
mTrimEnd = MathUtils.lerp(0.0f, 0.75f, progress);
super.onCalculate(progress);
mTrimEnd = get();
}
};
trimEnd.setRange(0.0f, 0.75f);
trimEnd.setDuration(1333L);
trimEnd.setInterpolator(TRIM_END_INTERPOLATOR);
trimEnd.setRepeatCount(Animation.INFINITE);
Animation trimOffset = new Animation() {
FloatAnimation trimOffset = new FloatAnimation() {
@Override
protected void onCalculate(float progress) {
mTrimOffset = MathUtils.lerp(0.0f, 0.25f, progress);
super.onCalculate(progress);
mTrimOffset = get();
}
};
trimOffset.setRange(0.0f, 0.25f);
trimOffset.setDuration(1333L);
trimOffset.setInterpolator(LINEAR_INTERPOLATOR);
trimOffset.setRepeatCount(Animation.INFINITE);
Animation trimRotation = new Animation() {
FloatAnimation trimRotation = new FloatAnimation() {
@Override
protected void onCalculate(float progress) {
mTrimRotation = MathUtils.lerp(0.0f, 720.0f, progress);
super.onCalculate(progress);
mTrimRotation = get();
}
};
trimRotation.setRange(0.0f, 720.0f);
trimRotation.setDuration(6665L);
trimRotation.setInterpolator(LINEAR_INTERPOLATOR);
trimRotation.setRepeatCount(Animation.INFINITE);
@@ -125,7 +133,7 @@ public class ProgressView extends GLView {
private void startAnimations() {
List<Animation> animations = mAnimations;
for (int i = 0, n = animations.size(); i < n; i++) {
animations.get(i).start();
animations.get(i).forceReset();
}
}
@@ -191,7 +199,7 @@ public class ProgressView extends GLView {
int cy = height / 2;
float startAngle = (mTrimStart + mTrimOffset) * 360.0f - 90;
float sweepAngle = (mTrimEnd - mTrimStart) * 360.0f;
float sweepAngle = Math.max(6.0f, (mTrimEnd - mTrimStart) * 360.0f);
float rotation = mTrimRotation + startAngle;
canvas.save();
@@ -0,0 +1,144 @@
/*
* Copyright 2015 Hippo Seven
*
* 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.hippo.ehviewer.gallery.ui;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.view.MotionEvent;
import com.hippo.ehviewer.gallery.glrenderer.GLCanvas;
import com.hippo.yorozuya.LayoutUtils;
import com.hippo.yorozuya.MathUtils;
public class Slider extends GLView {
private int mStart;
private int mEnd;
private int mProgress;
// 0.0f to 1.0f
private float mDrawProgress = 0.0f;
private int m2dp;
private int m5dp;
private int m6dp;
private int m12dp;
private int mColor = Color.WHITE;
private OnSetProgressListener mListener;
public Slider(Context context) {
m2dp = LayoutUtils.dp2pix(context, 2);
m5dp = LayoutUtils.dp2pix(context, 5);
m6dp = LayoutUtils.dp2pix(context, 6);
m12dp = LayoutUtils.dp2pix(context, 12);
setMinimumHeight(m12dp);
setMinimumWidth(512);
}
public void setColor(int color) {
mColor = color;
}
public void setRange(int start, int end) {
mStart = start;
mEnd = end;
setProgress(mProgress);
}
public void setProgress(int progress) {
progress = MathUtils.clamp(progress, mStart, mEnd);
if (mProgress != progress) {
int oldProgress = mProgress;
mProgress = progress;
mDrawProgress = MathUtils.delerp(mStart, mEnd, mProgress);
if (mListener != null) {
mListener.onSetProgress(progress, oldProgress, false);
}
invalidate();
}
}
public void setOnSetProgressListener(OnSetProgressListener listener) {
mListener = listener;
}
@Override
protected void onMeasure(int widthSpec, int heightSpec) {
setMeasuredSize(getMaxSize(getSuggestedMinimumWidth(), widthSpec),
getDefaultSize(getSuggestedMinimumHeight(), heightSpec));
}
@Override
protected void onRender(GLCanvas canvas) {
super.onRender(canvas);
int width = getWidth();
if (width < m12dp * 2) {
canvas.fillRect(0, 0, width, getHeight(), mColor);
} else {
Rect padding = mPaddings;
int dp6 = m6dp;
// Draw bar
canvas.fillRect(padding.left + dp6, padding.top + m5dp,
width - dp6 - dp6 - padding.left - padding.right, m2dp, mColor);
// Draw controllor
canvas.fillOval(padding.left + dp6 + (width - dp6 - dp6 - padding.left - padding.right) * mDrawProgress,
padding.top + dp6, dp6, dp6, mColor);
}
}
@Override
protected boolean onTouch(MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
float x = event.getX();
int progress = Math.round(MathUtils.lerp((float) mStart, (float) mEnd,
MathUtils.clamp((x - m6dp) / (getWidth() - m6dp - m6dp), 0.0f, 1.0f)));
if (progress != mProgress) {
mDrawProgress = MathUtils.delerp(mStart, mEnd, progress);
invalidate();
}
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
if (progress != mProgress) {
int oldProgress = mProgress;
mProgress = progress;
if (mListener != null) {
mListener.onSetProgress(progress, oldProgress, true);
}
}
}
break;
}
return true;
}
public interface OnSetProgressListener {
void onSetProgress(int newProgress, int oldProgress, boolean byUser);
}
}
@@ -1,13 +1,19 @@
package com.hippo.ehviewer.gallery.ui;
import android.graphics.Rect;
import com.hippo.ehviewer.gallery.glrenderer.GLCanvas;
import com.hippo.ehviewer.gallery.glrenderer.TextTexture;
import com.hippo.yorozuya.ArrayUtils;
public class TextView extends GLView {
TextTexture mTextTexture;
private String mText = "";
private int[] mIndexes = ArrayUtils.EMPTY_INT_ARRAY;
private int mGravity = Gravity.NO_GRAVITY;
public TextView(TextTexture textTexture) {
mTextTexture = textTexture;
@@ -19,18 +25,26 @@ public class TextView extends GLView {
}
if (!text.equals(mText)) {
mText = text;
mIndexes = mTextTexture.getTextIndexes(text);
requestLayout();
}
}
public void setGravity(int gravity) {
if (mGravity != gravity) {
mGravity = gravity;
invalidate();
}
}
@Override
protected void onMeasure(int widthSpec, int heightSpec) {
int textWidth = 0;
int textHight = 0;
if (mTextTexture != null) {
textWidth = (int) mTextTexture.getTextWidth(mText);
textHight = (int) mTextTexture.getTextHeight(mText);
textWidth = (int) mTextTexture.getTextWidth(mIndexes);
textHight = (int) mTextTexture.getTextHeight();
}
setMeasuredSize(getDefaultSize(Math.max(getSuggestedMinimumWidth(), textWidth), widthSpec),
@@ -39,6 +53,11 @@ public class TextView extends GLView {
@Override
protected void onRender(GLCanvas canvas) {
mTextTexture.drawText(canvas, mText, 0, 0);
Rect paddings = getPaddings();
int x = getDefaultBegin(getWidth(), (int) mTextTexture.getTextWidth(mIndexes),
paddings.left, paddings.right, Gravity.getPosition(mGravity, Gravity.HORIZONTAL));
int y = getDefaultBegin(getHeight(), (int) mTextTexture.getTextHeight(),
paddings.top, paddings.bottom, Gravity.getPosition(mGravity, Gravity.VERTICAL));
mTextTexture.drawText(canvas, mIndexes, x, y);
}
}
@@ -0,0 +1,56 @@
/*
* Copyright 2015 Hippo Seven
*
* 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.hippo.ehviewer.gallery.ui;
import com.hippo.ehviewer.gallery.glrenderer.GLCanvas;
import com.hippo.ehviewer.gallery.glrenderer.XmlResourceTexture;
public class XmlResourceView extends GLView {
private XmlResourceTexture mTexture;
public void setTexture(XmlResourceTexture texture) {
mTexture = texture;
if (texture != null) {
int width = getWidth();
int height = getHeight();
if (width > 0 && height > 0) {
texture.setBound(width, height);
invalidate();
}
}
}
@Override
protected void onLayout(boolean changeSize, int left, int top, int right, int bottom) {
super.onLayout(changeSize, left, top, right, bottom);
if (changeSize && mTexture != null) {
mTexture.setBound(right - left, bottom - top);
}
}
@Override
protected void onRender(GLCanvas canvas) {
super.onRender(canvas);
if (mTexture != null) {
canvas.drawTexture(mTexture, 0, 0, getWidth(), getHeight());
}
}
}
@@ -33,6 +33,10 @@ public class GalleryUtils {
};
}
public static int floatARGBArrayTointColor(float[] from) {
return Color.argb((int) (from[0] * 255), (int) (from[1] * 255), (int) (from[2] * 255), (int) (from[3] * 255));
}
// Below are used the detect using database in the render thread. It only
// works most of the time, but that's ok because it's for debugging only.
@@ -25,6 +25,7 @@ import android.os.Bundle;
import android.os.Process;
import android.support.annotation.Nullable;
import android.util.Pair;
import android.util.SparseArray;
import com.hippo.app.StatsActivity;
import com.hippo.conaco.BitmapPool;
@@ -43,17 +44,20 @@ import com.hippo.ehviewer.gallery.glrenderer.TextTexture;
import com.hippo.ehviewer.gallery.glrenderer.TiledTexture;
import com.hippo.ehviewer.gallery.ui.GLRootView;
import com.hippo.ehviewer.gallery.ui.GLView;
import com.hippo.ehviewer.gallery.ui.GalleryLayout;
import com.hippo.ehviewer.gallery.ui.GalleryPageView;
import com.hippo.ehviewer.gallery.ui.GalleryPanel;
import com.hippo.ehviewer.gallery.ui.GalleryView;
import com.hippo.util.SystemUiHelper;
import com.hippo.yorozuya.LayoutUtils;
import com.hippo.yorozuya.PriorityThreadFactory;
import com.hippo.yorozuya.SimpleHandler;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.LinkedBlockingQueue;
public class GalleryActivity extends StatsActivity implements TiledTexture.OnFreeBitmapListener, GalleryProviderListener {
public class GalleryActivity extends StatsActivity implements TiledTexture.OnFreeBitmapListener,
GalleryProviderListener, GalleryLayout.ActionListener {
public static final String ACTION_GALLERY_FROM_GALLERY_BASE = "com.hippo.ehviewer.gallery.action.GALLERY_FROM_GALLERY_BASE";
public static final String ACTION_GALLERY_FROM_ARCHIVE = "com.hippo.ehviewer.gallery.action.GALLERY_FROM_ARCHIVE";
@@ -61,6 +65,10 @@ public class GalleryActivity extends StatsActivity implements TiledTexture.OnFre
public static final String KEY_GALLERY_BASE = "gallery_base";
public static final String KEY_ARCHIVE_URI = "archive_uri";
public static final String KEY_HASH_CODE = "hash_code";
public static final SparseArray<GalleryProvider> sGalleryProviderMap = new SparseArray<>();
public static final SparseArray<CloseGalleryProviderTask> sCloseGalleryProviderTaskMap = new SparseArray<>();
private SystemUiHelper mSystemUiHelper;
private Resources mResources;
@@ -70,10 +78,12 @@ public class GalleryActivity extends StatsActivity implements TiledTexture.OnFre
private GLRootView mGLRootView;
private GalleryView mGalleryView;
private GalleryPanel mGalleryPanel;
private GalleryAdapter mAdapter;
private TextTexture mTextTexture;
private TextTexture mGalleryIndexTextTexture;
private TextTexture mGalleryProgressTextTexture;
private GalleryProvider mGalleryProvider;
@@ -120,7 +130,20 @@ public class GalleryActivity extends StatsActivity implements TiledTexture.OnFre
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!getGalleryProvider(getIntent())) {
if (savedInstanceState != null) {
int hashCode = savedInstanceState.getInt(KEY_HASH_CODE, 0);
if (hashCode != 0) {
mGalleryProvider = sGalleryProviderMap.get(hashCode);
sGalleryProviderMap.remove(hashCode);
Runnable runnable = sCloseGalleryProviderTaskMap.get(hashCode);
sCloseGalleryProviderTaskMap.remove(hashCode);
if (runnable != null) {
SimpleHandler.getInstance().removeCallbacks(runnable);
}
}
}
if (mGalleryProvider == null && !getGalleryProvider(getIntent())) {
mDieYoung = true;
finish();
return;
@@ -130,9 +153,26 @@ public class GalleryActivity extends StatsActivity implements TiledTexture.OnFre
SystemUiHelper.FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES | SystemUiHelper.FLAG_IMMERSIVE_STICKY);
mSystemUiHelper.hide();
mResources = getResources();
// Gallery index typeface
Typeface galleryIndexTf = Typeface.createFromAsset(mResources.getAssets(), "fonts/gallery_index.ttf");
mGalleryIndexTextTexture = TextTexture.create(galleryIndexTf,
mResources.getDimensionPixelSize(R.dimen.gallery_index_text),
mResources.getColor(R.color.secondary_text_dark),
new char[]{'.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'});
GalleryPageView.setTextTexture(mGalleryIndexTextTexture);
// Gallery progress typeface
Typeface galleryProgressTf = Typeface.createFromAsset(mResources.getAssets(), "fonts/gallery_progress.ttf");
mGalleryProgressTextTexture = TextTexture.create(galleryProgressTf,
mResources.getDimensionPixelSize(R.dimen.text_little_small),
mResources.getColor(R.color.primary_text_dark),
new char[]{'/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'});
GalleryPanel.setTextTexture(mGalleryProgressTextTexture);
setContentView(R.layout.activity_gallery);
mGLRootView = (GLRootView) findViewById(R.id.gl_root_view);
mResources = getResources();
// Prepare
TiledTexture.prepareResources();
TiledTexture.setOnFreeBitmapListener(this);
@@ -142,19 +182,15 @@ public class GalleryActivity extends StatsActivity implements TiledTexture.OnFre
GifTexture.initialize(mUploader, mThreadExecutor);
mGifBitmapPool = new BitmapPool();
GifDecoder.setBitmapPool(mGifBitmapPool);
Typeface tf = Typeface.createFromAsset(mResources.getAssets(), "fonts/number.ttf");
mTextTexture = TextTexture.create(tf,
mResources.getDimensionPixelSize(R.dimen.gallery_index_text),
mResources.getColor(R.color.secondary_text_dark),
new char[]{'.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'});
mUploader.addTexture(mTextTexture);
GalleryPageView.setTextTexture(mTextTexture);
mGalleryView = new GalleryView(this);
mUploader.addTexture(mGalleryIndexTextTexture);
mUploader.addTexture(mGalleryProgressTextTexture);
GalleryLayout galleryLayout = new GalleryLayout(this, this);
mGalleryView = galleryLayout.getGalleryView();
mGalleryPanel = galleryLayout.getGalleryPanel();
mAdapter = new GalleryAdapter();
mGalleryView.setAdapter(mAdapter);
mGalleryView.setProgressSize(LayoutUtils.dp2pix(this, 56));
mGalleryView.setInterval(LayoutUtils.dp2pix(this, 48));
mSize = mGalleryProvider.size();
if (mSize <= 0) {
@@ -164,7 +200,7 @@ public class GalleryActivity extends StatsActivity implements TiledTexture.OnFre
}
mGalleryProvider.addGalleryProviderListener(this);
mGLRootView.setContentPane(mGalleryView);
mGLRootView.setContentPane(galleryLayout);
}
private void setMode(GalleryView.Mode mode) {
@@ -172,6 +208,25 @@ public class GalleryActivity extends StatsActivity implements TiledTexture.OnFre
mGalleryView.setMode(mode);
}
@Override
public void finish() {
super.finish();
}
private static void closeGalleryProvider(GalleryProvider galleryProvider) {
if (galleryProvider instanceof GallerySpider) {
GallerySpider.release((GallerySpider) galleryProvider);
} else if (galleryProvider instanceof ZipGalleryProvider) {
((ZipGalleryProvider) galleryProvider).stop();
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(KEY_HASH_CODE, hashCode());
}
@Override
protected void onDestroy() {
super.onDestroy();
@@ -179,18 +234,21 @@ public class GalleryActivity extends StatsActivity implements TiledTexture.OnFre
if (!mDieYoung) {
GalleryPageView.setTextTexture(null);
mUploader.clear();
mTextTexture.recycle();
mGalleryIndexTextTexture.recycle();
mGalleryProgressTextTexture.recycle();
GifDecoder.setBitmapPool(null);
GifTexture.uninitialize();
TiledTexture.setOnFreeBitmapListener(null);
TiledTexture.freeResources();
mGalleryProvider.removeGalleryProviderListener(this);
if (mGalleryProvider instanceof GallerySpider) {
GallerySpider.release((GallerySpider) mGalleryProvider);
} else if (mGalleryProvider instanceof ZipGalleryProvider) {
((ZipGalleryProvider) mGalleryProvider).stop();
}
// Post close task
int hashCode = hashCode();
CloseGalleryProviderTask task = new CloseGalleryProviderTask(mGalleryProvider, hashCode);
sGalleryProviderMap.put(hashCode, mGalleryProvider);
sCloseGalleryProviderTaskMap.put(hashCode, task);
SimpleHandler.getInstance().postDelayed(task, 3000);
mGalleryProvider = null;
@@ -382,6 +440,16 @@ public class GalleryActivity extends StatsActivity implements TiledTexture.OnFre
}
}
@Override
public void onShowGalleryPanel() {
mSystemUiHelper.show();
}
@Override
public void onHideGalleryPanel() {
mSystemUiHelper.hide();
}
class GalleryAdapter extends GalleryView.Adapter {
@Override
@@ -407,4 +475,23 @@ public class GalleryActivity extends StatsActivity implements TiledTexture.OnFre
clearTiledTextureInPage(view);
}
}
static class CloseGalleryProviderTask implements Runnable {
private GalleryProvider mGalleryProvider;
private int mHashCode;
public CloseGalleryProviderTask(GalleryProvider galleryProvider, int hashCode) {
mGalleryProvider = galleryProvider;
mHashCode = hashCode;
}
@Override
public void run() {
closeGalleryProvider(mGalleryProvider);
mGalleryProvider = null;
sGalleryProviderMap.remove(mHashCode);
sCloseGalleryProviderTaskMap.remove(mHashCode);
}
}
}
@@ -250,7 +250,7 @@ public class ElementsSharedCurtain extends Curtain {
View sceneContentView = exit.getSceneView().getChildAt(0);
if (sceneContentView == null) {
Say.w(TAG, "Can't get exit scene content view");
dispatchOpenFinished(enter, exit);
dispatchCloseFinished(enter, exit);
return;
}
@@ -202,6 +202,7 @@ public class SceneManager {
}
if (previousState != null) {
previousState.endCurtainAnimation();
previousState.pause();
previousState.setState(Scene.SCENE_STATE_PAUSE);
}
@@ -319,7 +320,7 @@ public class SceneManager {
}
private void checkSceneState(Scene scene, int expected) {
AssertUtils.assertEquals("The scene state is " + scene.getState() + ", but it should be " + expected,
AssertUtils.assertEquals(this + " state is " + scene.getState() + ", but it should be " + expected,
expected, scene.getState());
}