Improve gallery
This commit is contained in:
1 parent
8dc9160f21
commit
1097396c52
10 files changed
+475
-39
No files matched your search
@@ -24,6 +24,7 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.hippo.ehviewer.client.EhConfig;
|
||||
import com.hippo.ehviewer.gallery.gl.GalleryView;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.yorozuya.NumberUtils;
|
||||
|
||||
@@ -132,6 +133,21 @@ public class Settings {
|
||||
/********************
|
||||
****** Read
|
||||
********************/
|
||||
private static final String KEY_READING_DIRECTION = "reading_direction";
|
||||
private static final int DEFAULT_READING_DIRECTION = GalleryView.LAYOUT_MODE_RIGHT_TO_LEFT;
|
||||
|
||||
@SuppressWarnings("WrongConstant")
|
||||
@GalleryView.LayoutMode
|
||||
public static int getReadingDirection() {
|
||||
int value = getIntFromStr(KEY_READING_DIRECTION, DEFAULT_READING_DIRECTION);
|
||||
if (value != GalleryView.LAYOUT_MODE_LEFT_TO_RIGHT &&
|
||||
value != GalleryView.LAYOUT_MODE_RIGHT_TO_LEFT &&
|
||||
value != GalleryView.LAYOUT_MODE_TOP_TO_BOTTOM) {
|
||||
value = GalleryView.LAYOUT_MODE_RIGHT_TO_LEFT;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private static final String KEY_VOLUME_PAGE = "volume_page";
|
||||
private static final boolean DEFAULT_VOLUME_PAGE = false;
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
|
||||
@@ -59,7 +60,7 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
|
||||
@IntDef({LAYOUT_MODE_LEFT_TO_RIGHT, LAYOUT_MODE_RIGHT_TO_LEFT, LAYOUT_MODE_TOP_TO_BOTTOM})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
private @interface LayoutMode {}
|
||||
public @interface LayoutMode {}
|
||||
|
||||
public static final int BACKGROUND_COLOR = 0xff212121;
|
||||
private static final int PROGRESS_SIZE_IN_DP = 48;
|
||||
@@ -83,7 +84,8 @@ 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 float[] MENU_AREA = {1.0f / 3.0f, 0.0f, 2.0f / 3.0f, 3.0f / 4.0f};
|
||||
private static final float[] SLIDER_AREA = {1.0f / 3.0f, 3.0f / 4.0f, 2.0f / 3.0f, 1.0f};
|
||||
|
||||
private static final int METHOD_ON_SINGLE_TAP_UP = 0;
|
||||
private static final int METHOD_ON_SINGLE_TAP_CONFIRMED = 1;
|
||||
@@ -99,6 +101,7 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
private static final int METHOD_ON_POINTER_DOWN = 11;
|
||||
private static final int METHOD_ON_POINTER_UP = 12;
|
||||
private static final int METHOD_SET_LAYOUT_MODE = 13;
|
||||
private static final int METHOD_CURRENT_PAGE = 14;
|
||||
|
||||
private final Context mContext;
|
||||
private MovableTextTexture mPageTextTexture;
|
||||
@@ -130,28 +133,32 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
|
||||
private final Rect mLeftArea = new Rect();
|
||||
private final Rect mRightArea = new Rect();
|
||||
private final Rect mCenterArea = new Rect();
|
||||
private final Rect mMenuArea = new Rect();
|
||||
private final Rect mSliderArea = new Rect();
|
||||
|
||||
private final String mDefaultErrorStr;
|
||||
private final String mEmptyStr;
|
||||
|
||||
@LayoutMode
|
||||
private int mLayoutMode = LAYOUT_MODE_RIGHT_TO_LEFT;
|
||||
private int mIndex;
|
||||
|
||||
@Scale
|
||||
private int mScaleMode = SCALE_FIT;
|
||||
@StartPosition
|
||||
private int mStartPosition = START_POSITION_TOP_LEFT;
|
||||
|
||||
private final ActionListener mListener;
|
||||
private final Listener mListener;
|
||||
|
||||
private final List<Integer> mMethodList = new ArrayList<>(5);
|
||||
private final List<Object[]> mArgsList = new ArrayList<>(5);
|
||||
private final List<Integer> mMethodListTemp = new ArrayList<>(5);
|
||||
private final List<Object[]> mArgsListTemp = new ArrayList<>(5);
|
||||
|
||||
private final AtomicInteger mCurrentIndex = new AtomicInteger(GalleryPageView.INVALID_INDEX);
|
||||
|
||||
public GalleryView(@NonNull Context context, @NonNull Adapter adapter,
|
||||
ActionListener listener, @LayoutMode int layoutMode) {
|
||||
Listener listener, @LayoutMode int layoutMode) {
|
||||
mContext = context;
|
||||
mAdapter = adapter;
|
||||
mListener = listener;
|
||||
@@ -200,6 +207,7 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
ensurePagerLayoutManager();
|
||||
mPagerLayoutManager.setMode(PagerLayoutManager.MODE_LEFT_TO_RIGHT);
|
||||
mPagerLayoutManager.onAttach(mAdapter);
|
||||
mPagerLayoutManager.setCurrentIndex(mIndex);
|
||||
mAdapter = null;
|
||||
mLayoutManager = mPagerLayoutManager;
|
||||
break;
|
||||
@@ -207,12 +215,14 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
ensurePagerLayoutManager();
|
||||
mPagerLayoutManager.setMode(PagerLayoutManager.MODE_RIGHT_TO_LEFT);
|
||||
mPagerLayoutManager.onAttach(mAdapter);
|
||||
mPagerLayoutManager.setCurrentIndex(mIndex);
|
||||
mAdapter = null;
|
||||
mLayoutManager = mPagerLayoutManager;
|
||||
break;
|
||||
case LAYOUT_MODE_TOP_TO_BOTTOM:
|
||||
ensureScrollLayoutManager();
|
||||
mScrollLayoutManager.onAttach(mAdapter);
|
||||
mScrollLayoutManager.setCurrentIndex(mIndex);
|
||||
mAdapter = null;
|
||||
mLayoutManager = mScrollLayoutManager;
|
||||
break;
|
||||
@@ -226,6 +236,7 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
super.onDetachFromRoot();
|
||||
mEdgeView.onDetachFromRoot();
|
||||
|
||||
mIndex = mLayoutManager.getInternalCurrentIndex();
|
||||
mAdapter = mLayoutManager.onDetach();
|
||||
mLayoutManager = null;
|
||||
|
||||
@@ -233,6 +244,14 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
mPageTextTexture = null;
|
||||
}
|
||||
|
||||
public int getLayoutMode() {
|
||||
return mLayoutMode;
|
||||
}
|
||||
|
||||
public int getCurrentIndex() {
|
||||
return mCurrentIndex.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestLayout() {
|
||||
// Do not need requestLayout, because the size will not change
|
||||
@@ -285,6 +304,10 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
postMethod(METHOD_SET_LAYOUT_MODE, layoutMode);
|
||||
}
|
||||
|
||||
public void setCurrentPage(int page) {
|
||||
postMethod(METHOD_CURRENT_PAGE, page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSingleTapUp(float x, float y) {
|
||||
postMethod(METHOD_ON_SINGLE_TAP_UP, x, y);
|
||||
@@ -293,7 +316,13 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
|
||||
@Override
|
||||
public boolean onSingleTapConfirmed(float x, float y) {
|
||||
postMethod(METHOD_ON_SINGLE_TAP_CONFIRMED, x, y);
|
||||
if (mSliderArea.contains((int) x, (int) y)) {
|
||||
mListener.onTapSliderArea();
|
||||
} else if (mMenuArea.contains((int) x, (int) y)) {
|
||||
mListener.onTapMenuArea();
|
||||
} else {
|
||||
postMethod(METHOD_ON_SINGLE_TAP_CONFIRMED, x, y);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -371,8 +400,10 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
(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));
|
||||
mMenuArea.set((int) (MENU_AREA[0] * width), (int) (MENU_AREA[1] * height),
|
||||
(int) (MENU_AREA[2] * width), (int) (MENU_AREA[3] * height));
|
||||
mSliderArea.set((int) (SLIDER_AREA[0] * width), (int) (SLIDER_AREA[1] * height),
|
||||
(int) (SLIDER_AREA[2] * width), (int) (SLIDER_AREA[3] * height));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,6 +420,15 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
}
|
||||
|
||||
private void onSingleTapConfirmedInternal(float x, float y) {
|
||||
if (mLayoutManager == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mLeftArea.contains((int) x, (int) y)) {
|
||||
mLayoutManager.onPageLeft();
|
||||
} else if (mRightArea.contains((int) x, (int) y)) {
|
||||
mLayoutManager.onPageRight();
|
||||
}
|
||||
}
|
||||
|
||||
private void onDoubleTapInternal(float x, float y) {
|
||||
@@ -483,7 +523,9 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
} else {
|
||||
ensurePagerLayoutManager();
|
||||
mPagerLayoutManager.setMode(PagerLayoutManager.MODE_LEFT_TO_RIGHT);
|
||||
int index = mLayoutManager.getInternalCurrentIndex();
|
||||
mPagerLayoutManager.onAttach(mLayoutManager.onDetach());
|
||||
mPagerLayoutManager.setCurrentIndex(index);
|
||||
mLayoutManager = mPagerLayoutManager;
|
||||
}
|
||||
break;
|
||||
@@ -494,13 +536,17 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
} else {
|
||||
ensurePagerLayoutManager();
|
||||
mPagerLayoutManager.setMode(PagerLayoutManager.MODE_RIGHT_TO_LEFT);
|
||||
int index = mLayoutManager.getInternalCurrentIndex();
|
||||
mPagerLayoutManager.onAttach(mLayoutManager.onDetach());
|
||||
mPagerLayoutManager.setCurrentIndex(index);
|
||||
mLayoutManager = mPagerLayoutManager;
|
||||
}
|
||||
break;
|
||||
case LAYOUT_MODE_TOP_TO_BOTTOM:
|
||||
ensureScrollLayoutManager();
|
||||
int index = mLayoutManager.getInternalCurrentIndex();
|
||||
mScrollLayoutManager.onAttach(mLayoutManager.onDetach());
|
||||
mScrollLayoutManager.setCurrentIndex(index);
|
||||
mLayoutManager = mScrollLayoutManager;
|
||||
break;
|
||||
}
|
||||
@@ -508,6 +554,14 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
requestFill();
|
||||
}
|
||||
|
||||
private void setCurrentPageInternal(int page) {
|
||||
if (mLayoutManager != null) {
|
||||
mLayoutManager.setCurrentIndex(page);
|
||||
} else {
|
||||
mIndex = page;
|
||||
}
|
||||
}
|
||||
|
||||
@RenderThread
|
||||
void forceFill() {
|
||||
mRequestFill = true;
|
||||
@@ -594,6 +648,8 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
case METHOD_SET_LAYOUT_MODE:
|
||||
setLayoutModeInternal((Integer) args[0]);
|
||||
break;
|
||||
case METHOD_CURRENT_PAGE:
|
||||
setCurrentPageInternal((Integer) args[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -603,6 +659,8 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
|
||||
@Override
|
||||
public void render(GLCanvas canvas) {
|
||||
int oldCurrentIndex = mCurrentIndex.get();
|
||||
|
||||
// Dispatch method
|
||||
dispatchMethod();
|
||||
|
||||
@@ -615,6 +673,18 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
|
||||
super.render(canvas);
|
||||
mEdgeView.render(canvas);
|
||||
|
||||
int newCurrentIndex;
|
||||
if (mLayoutManager != null) {
|
||||
newCurrentIndex = mLayoutManager.getCurrentIndex();
|
||||
} else {
|
||||
newCurrentIndex = GalleryPageView.INVALID_INDEX;
|
||||
}
|
||||
mCurrentIndex.lazySet(newCurrentIndex);
|
||||
|
||||
if (oldCurrentIndex != newCurrentIndex) {
|
||||
mListener.onUpdateCurrentIndex(newCurrentIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@RenderThread
|
||||
@@ -762,6 +832,10 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
|
||||
public abstract void onDataChanged();
|
||||
|
||||
public abstract void onPageLeft();
|
||||
|
||||
public abstract void onPageRight();
|
||||
|
||||
public abstract GalleryPageView findPageByIndex(int index);
|
||||
|
||||
/**
|
||||
@@ -769,6 +843,10 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
*/
|
||||
public abstract int getCurrentIndex();
|
||||
|
||||
public abstract void setCurrentIndex(int index);
|
||||
|
||||
abstract int getInternalCurrentIndex();
|
||||
|
||||
protected void placeCenter(GLView view) {
|
||||
int spec = GLView.MeasureSpec.makeMeasureSpec(GLView.LayoutParams.WRAP_CONTENT,
|
||||
GLView.LayoutParams.WRAP_CONTENT);
|
||||
@@ -781,10 +859,12 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
}
|
||||
}
|
||||
|
||||
public interface ActionListener {
|
||||
public interface Listener {
|
||||
|
||||
void onTapCenter();
|
||||
void onUpdateCurrentIndex(int index);
|
||||
|
||||
void onScrollToPage(int page, boolean internal);
|
||||
void onTapSliderArea();
|
||||
|
||||
void onTapMenuArea();
|
||||
}
|
||||
}
|
||||
@@ -639,6 +639,66 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
|
||||
mGalleryView.requestFill();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageLeft() {
|
||||
int size = mAdapter.size();
|
||||
if (size <= 0 || mCurrent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mMode == MODE_LEFT_TO_RIGHT) {
|
||||
if (mIndex == 0) {
|
||||
GalleryView galleryView = mGalleryView;
|
||||
GLEdgeView edgeView = galleryView.getEdgeView();
|
||||
edgeView.onPull(galleryView.getWidth(),
|
||||
galleryView.getHeight() / 2, GLEdgeView.LEFT);
|
||||
edgeView.onRelease(GLEdgeView.LEFT);
|
||||
} else {
|
||||
setCurrentIndex(mIndex - 1);
|
||||
}
|
||||
} else {
|
||||
if (mIndex >= size - 1) {
|
||||
GalleryView galleryView = mGalleryView;
|
||||
GLEdgeView edgeView = galleryView.getEdgeView();
|
||||
edgeView.onPull(galleryView.getWidth(),
|
||||
galleryView.getHeight() / 2, GLEdgeView.LEFT);
|
||||
edgeView.onRelease(GLEdgeView.LEFT);
|
||||
} else {
|
||||
setCurrentIndex(mIndex + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageRight() {
|
||||
int size = mAdapter.size();
|
||||
if (size <= 0 || mCurrent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mMode == MODE_LEFT_TO_RIGHT) {
|
||||
if (mIndex >= size - 1) {
|
||||
GalleryView galleryView = mGalleryView;
|
||||
GLEdgeView edgeView = galleryView.getEdgeView();
|
||||
edgeView.onPull(galleryView.getWidth(),
|
||||
galleryView.getHeight() / 2, GLEdgeView.RIGHT);
|
||||
edgeView.onRelease(GLEdgeView.RIGHT);
|
||||
} else {
|
||||
setCurrentIndex(mIndex + 1);
|
||||
}
|
||||
} else {
|
||||
if (mIndex == 0) {
|
||||
GalleryView galleryView = mGalleryView;
|
||||
GLEdgeView edgeView = galleryView.getEdgeView();
|
||||
edgeView.onPull(galleryView.getWidth(),
|
||||
galleryView.getHeight() / 2, GLEdgeView.RIGHT);
|
||||
edgeView.onRelease(GLEdgeView.RIGHT);
|
||||
} else {
|
||||
setCurrentIndex(mIndex - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GalleryPageView findPageByIndex(int index) {
|
||||
if (mCurrent != null && mCurrent.getIndex() == index) {
|
||||
@@ -662,6 +722,61 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentIndex(int index) {
|
||||
int size = mAdapter.size();
|
||||
if (size <= 0) {
|
||||
// Can't get size now, assume size is MAX
|
||||
size = Integer.MAX_VALUE;
|
||||
}
|
||||
if (index == mIndex || index < 0 || index >= size) {
|
||||
return;
|
||||
}
|
||||
if (mCurrent == null) {
|
||||
mIndex = index;
|
||||
} else if (index == mIndex - 1) {
|
||||
// Cancel all animations
|
||||
cancelAllAnimations();
|
||||
// Reset parameters
|
||||
resetParameters();
|
||||
// Go to previous
|
||||
pagePrevious();
|
||||
// Request fill
|
||||
mGalleryView.requestFill();
|
||||
} else if (index == mIndex + 1) {
|
||||
// Cancel all animations
|
||||
cancelAllAnimations();
|
||||
// Reset parameters
|
||||
resetParameters();
|
||||
// Go to next
|
||||
pageNext();
|
||||
// Request fill
|
||||
mGalleryView.requestFill();
|
||||
} else {
|
||||
mIndex = index;
|
||||
// It is attached, refill
|
||||
// Cancel all animations
|
||||
cancelAllAnimations();
|
||||
// Remove all view
|
||||
removeProgress();
|
||||
removeErrorView();
|
||||
removeAllPages();
|
||||
// Reset parameters
|
||||
resetParameters();
|
||||
// Request fill
|
||||
mGalleryView.requestFill();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
int getInternalCurrentIndex() {
|
||||
int currentIndex = getCurrentIndex();
|
||||
if (currentIndex == GalleryPageView.INVALID_INDEX) {
|
||||
currentIndex = mIndex;
|
||||
}
|
||||
return currentIndex;
|
||||
}
|
||||
|
||||
class SmoothScroller extends Animation {
|
||||
|
||||
private int mDx;
|
||||
|
||||
@@ -643,6 +643,28 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
|
||||
mGalleryView.requestFill();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageLeft() {
|
||||
/*
|
||||
int size = mAdapter.size();
|
||||
if (size <= 0 || mPages.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
*/
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageRight() {
|
||||
/*
|
||||
int size = mAdapter.size();
|
||||
if (size <= 0 || mPages.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
*/
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public GalleryPageView findPageByIndex(int index) {
|
||||
for (GalleryPageView page : mPages) {
|
||||
@@ -667,6 +689,65 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
|
||||
return GalleryPageView.INVALID_INDEX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentIndex(int index) {
|
||||
int size = mAdapter.size();
|
||||
if (size <= 0) {
|
||||
// Can't get size now, assume size is MAX
|
||||
size = Integer.MAX_VALUE;
|
||||
}
|
||||
if (index == mIndex || index < 0 || index >= size) {
|
||||
return;
|
||||
}
|
||||
if (mPages.isEmpty()) {
|
||||
mIndex = index;
|
||||
} else {
|
||||
mIndex = index;
|
||||
// Fix the index page
|
||||
GalleryPageView targetPage = null;
|
||||
for (GalleryPageView page : mPages) {
|
||||
if (page.getIndex() == index) {
|
||||
targetPage =page;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (targetPage != null) {
|
||||
// Cancel all animations
|
||||
cancelAllAnimations();
|
||||
mOffset -= targetPage.bounds().top;
|
||||
// Backup offset
|
||||
int offset = mOffset;
|
||||
// Reset parameters
|
||||
resetParameters();
|
||||
// Restore offset
|
||||
mOffset = offset;
|
||||
// Request fill
|
||||
mGalleryView.requestFill();
|
||||
} else {
|
||||
// Cancel all animations
|
||||
cancelAllAnimations();
|
||||
// Remove all view
|
||||
removeProgress();
|
||||
removeErrorView();
|
||||
removeAllPages();
|
||||
// Reset parameters
|
||||
resetParameters();
|
||||
// Request fill
|
||||
mGalleryView.requestFill();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
int getInternalCurrentIndex() {
|
||||
int currentIndex = getCurrentIndex();
|
||||
if (currentIndex == GalleryPageView.INVALID_INDEX) {
|
||||
currentIndex = mIndex;
|
||||
}
|
||||
return currentIndex;
|
||||
}
|
||||
|
||||
class PageFling extends Fling {
|
||||
|
||||
private int mVelocityX;
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
@@ -25,6 +27,8 @@ import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.anani.AnimationUtils;
|
||||
import com.hippo.anani.SimpleAnimatorListener;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
@@ -40,11 +44,14 @@ import com.hippo.gl.view.GLRootView;
|
||||
import com.hippo.image.Image;
|
||||
import com.hippo.util.SystemUiHelper;
|
||||
import com.hippo.widget.Slider;
|
||||
import com.hippo.yorozuya.ConcurrentPool;
|
||||
import com.hippo.yorozuya.SimpleHandler;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class GalleryActivity extends AppCompatActivity
|
||||
implements GalleryProviderListener, Slider.OnSetProgressListener {
|
||||
implements GalleryProviderListener, Slider.OnSetProgressListener,
|
||||
GalleryView.Listener {
|
||||
|
||||
public static final String ACTION_DIR = "dir";
|
||||
public static final String ACTION_ZIP = "zip";
|
||||
@@ -80,6 +87,30 @@ public class GalleryActivity extends AppCompatActivity
|
||||
@Nullable
|
||||
private Slider mSlider;
|
||||
|
||||
private int mLayoutMode;
|
||||
private int mSize;
|
||||
private int mCurrentIndex;
|
||||
|
||||
private final ConcurrentPool<NotifyTask> mNotifyTaskPool = new ConcurrentPool<>(3);
|
||||
|
||||
private final Runnable mRequestLayoutSliderTask = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (mSliderPanel != null) {
|
||||
mSliderPanel.requestLayout();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final SimpleAnimatorListener mHideSliderListener = new SimpleAnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
if (mSliderPanel != null) {
|
||||
mSliderPanel.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void buildProvider() {
|
||||
if (mGalleryProvider != null) {
|
||||
return;
|
||||
@@ -153,7 +184,7 @@ public class GalleryActivity extends AppCompatActivity
|
||||
mUploader = new ImageTexture.Uploader(glRootView);
|
||||
|
||||
mGalleryView = new GalleryView(this, new GalleryAdapter(),
|
||||
null, GalleryView.LAYOUT_MODE_TOP_TO_BOTTOM);
|
||||
this, Settings.getReadingDirection());
|
||||
glRootView.setContentPane(mGalleryView);
|
||||
|
||||
// System UI helper
|
||||
@@ -167,13 +198,16 @@ public class GalleryActivity extends AppCompatActivity
|
||||
mSystemUiShowing = true;
|
||||
}
|
||||
|
||||
/*
|
||||
mSliderPanel = findViewById(R.id.slider_panel);
|
||||
mLeftText = (TextView) mSliderPanel.findViewById(R.id.left);
|
||||
mRightText = (TextView) mSliderPanel.findViewById(R.id.right);
|
||||
mSlider = (Slider) mSliderPanel.findViewById(R.id.slider);
|
||||
mSlider.setOnSetProgressListener(this);
|
||||
*/
|
||||
|
||||
mSize = mGalleryProvider.size();
|
||||
mCurrentIndex = mGalleryView.getCurrentIndex();
|
||||
mLayoutMode = mGalleryView.getLayoutMode();
|
||||
updateSlider();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -190,6 +224,7 @@ public class GalleryActivity extends AppCompatActivity
|
||||
mGalleryProvider = null;
|
||||
}
|
||||
|
||||
mSliderPanel = null;
|
||||
mLeftText = null;
|
||||
mRightText = null;
|
||||
mSlider = null;
|
||||
@@ -289,18 +324,27 @@ public class GalleryActivity extends AppCompatActivity
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSlider(int size) {
|
||||
if (mSlider == null) {
|
||||
@SuppressLint("SetTextI18n")
|
||||
private void updateSlider() {
|
||||
if (mSlider == null || mRightText == null || mLeftText == null || mSize <= 0 || mCurrentIndex < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (size >= 0) {
|
||||
mSlider.setRange(1, size);
|
||||
|
||||
|
||||
TextView start;
|
||||
TextView end;
|
||||
if (mLayoutMode == GalleryView.LAYOUT_MODE_RIGHT_TO_LEFT) {
|
||||
start = mRightText;
|
||||
end = mLeftText;
|
||||
mSlider.setReverse(true);
|
||||
} else {
|
||||
// TODO hide slider
|
||||
start = mLeftText;
|
||||
end = mRightText;
|
||||
mSlider.setReverse(false);
|
||||
}
|
||||
start.setText(Integer.toString(mCurrentIndex + 1));
|
||||
end.setText(Integer.toString(mSize));
|
||||
mSlider.setRange(1, mSize);
|
||||
mSlider.setProgress(mCurrentIndex + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -308,16 +352,16 @@ public class GalleryActivity extends AppCompatActivity
|
||||
if (mGalleryView != null) {
|
||||
mGalleryView.onDataChanged();
|
||||
}
|
||||
/*
|
||||
SimpleHandler.getInstance().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (mGalleryProvider != null) {
|
||||
updateSlider(mGalleryProvider.size());
|
||||
}
|
||||
|
||||
if (mGalleryProvider != null) {
|
||||
int size = mGalleryProvider.size();
|
||||
NotifyTask task = mNotifyTaskPool.pop();
|
||||
if (task == null) {
|
||||
task = new NotifyTask();
|
||||
}
|
||||
});
|
||||
*/
|
||||
task.setData(NotifyTask.KEY_SIZE, size);
|
||||
SimpleHandler.getInstance().post(task);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -369,8 +413,76 @@ public class GalleryActivity extends AppCompatActivity
|
||||
@Override
|
||||
public void onSetProgress(Slider slider, int newProgress, int oldProgress,
|
||||
boolean byUser, boolean confirm) {
|
||||
if (confirm && mGalleryView != null) {
|
||||
//mGalleryView.goToPage(newProgress);
|
||||
if (confirm && byUser && mGalleryView != null) {
|
||||
mGalleryView.setCurrentPage(newProgress - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateCurrentIndex(int index) {
|
||||
NotifyTask task = mNotifyTaskPool.pop();
|
||||
if (task == null) {
|
||||
task = new NotifyTask();
|
||||
}
|
||||
task.setData(NotifyTask.KEY_CURRENT_INDEX, index);
|
||||
SimpleHandler.getInstance().post(task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTapSliderArea() {
|
||||
if (mSliderPanel == null || mSize <= 0 || mCurrentIndex < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mSliderPanel.getVisibility() == View.VISIBLE) {
|
||||
mSliderPanel.animate().translationY(mSliderPanel.getHeight()).setDuration(300)
|
||||
.setInterpolator(AnimationUtils.SLOW_FAST_INTERPOLATOR)
|
||||
.setListener(mHideSliderListener).start();
|
||||
} else {
|
||||
mSliderPanel.setTranslationY(mSliderPanel.getHeight());
|
||||
mSliderPanel.setVisibility(View.VISIBLE);
|
||||
mSliderPanel.animate().translationY(0.0f).setDuration(300)
|
||||
.setInterpolator(AnimationUtils.SLOW_FAST_INTERPOLATOR)
|
||||
.setListener(null).start();
|
||||
// Request layout ensure show it
|
||||
SimpleHandler.getInstance().post(mRequestLayoutSliderTask);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTapMenuArea() {
|
||||
|
||||
}
|
||||
|
||||
private class NotifyTask implements Runnable {
|
||||
|
||||
public static final int KEY_LAYOUT_MODE = 0;
|
||||
public static final int KEY_SIZE = 1;
|
||||
public static final int KEY_CURRENT_INDEX = 2;
|
||||
|
||||
private int mKey;
|
||||
private int mValue;
|
||||
|
||||
public void setData(int key, int value) {
|
||||
mKey = key;
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
switch (mKey) {
|
||||
case KEY_LAYOUT_MODE:
|
||||
GalleryActivity.this.mLayoutMode = mValue;
|
||||
break;
|
||||
case KEY_SIZE:
|
||||
GalleryActivity.this.mSize = mValue;
|
||||
break;
|
||||
case KEY_CURRENT_INDEX:
|
||||
GalleryActivity.this.mCurrentIndex = mValue;
|
||||
break;
|
||||
}
|
||||
updateSlider();
|
||||
mNotifyTaskPool.push(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user