Add PagerLayoutManager.onDoubleTapConfirmed(float, float)
This commit is contained in:
1 parent
293ada12c6
commit
9e6895b775
4 files changed
+104
-36
No files matched your search
@@ -214,6 +214,8 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
if (mScale) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mLayoutManager.onDoubleTapConfirmed(x, y);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -424,6 +426,8 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
|
||||
public abstract void onUp();
|
||||
|
||||
public abstract void onDoubleTapConfirmed(float x, float y);
|
||||
|
||||
public abstract void onScroll(float dx, float dy, float totalX, float totalY, float x, float y);
|
||||
|
||||
public abstract void onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY);
|
||||
@@ -435,41 +439,6 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
public abstract boolean onUpdateAnimation(long time);
|
||||
}
|
||||
|
||||
/*
|
||||
class SmoothScaler extends Animation {
|
||||
|
||||
private GalleryPageView mPage;
|
||||
private float mFocusX;
|
||||
private float mFocusY;
|
||||
private float mStartScale;
|
||||
private float mEndScale;
|
||||
private float mLastScale;
|
||||
|
||||
public void startSmoothScaler(GalleryPageView page, float focusX, float focusY,
|
||||
float startScale, float endScale, int duration) {
|
||||
mPage = page;
|
||||
mFocusX = focusX;
|
||||
mFocusY = focusY;
|
||||
mStartScale = startScale;
|
||||
mEndScale = endScale;
|
||||
mLastScale = startScale;
|
||||
setDuration(duration);
|
||||
start();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCalculate(float progress) {
|
||||
float scale = MathUtils.lerp(mStartScale, mEndScale, progress);
|
||||
mPage.scale(mFocusX, mFocusY, scale / mLastScale);
|
||||
mLastScale = scale;
|
||||
if (progress == 1.0f) {
|
||||
mPage = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
private static class Recycler {
|
||||
|
||||
private static final int MAX_SIZE = 3;
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.hippo.yorozuya.MathUtils;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ImageView extends GLView {
|
||||
|
||||
@@ -94,6 +95,26 @@ public class ImageView extends GLView {
|
||||
mPositionInRootDirty = true;
|
||||
}
|
||||
|
||||
public void getScaleDefault(float[] scaleDefault) {
|
||||
if (mTexture == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
scaleDefault[0] = 1.0f;
|
||||
|
||||
float scaleX = (float) getWidth() / mTexture.getWidth();
|
||||
float scaleY = (float) getHeight() / mTexture.getHeight();
|
||||
if (scaleX < scaleY) {
|
||||
scaleDefault[1] = scaleX;
|
||||
} else {
|
||||
scaleDefault[1] = scaleY;
|
||||
}
|
||||
|
||||
scaleDefault[2] = scaleDefault[1] * 1.5f;
|
||||
|
||||
Arrays.sort(scaleDefault);
|
||||
}
|
||||
|
||||
public void setTexture(Texture texture) {
|
||||
mTexture = texture;
|
||||
mScaleOffsetDirty = true;
|
||||
@@ -177,6 +198,10 @@ public class ImageView extends GLView {
|
||||
return Math.min(0, getHeight() - (int) mDst.bottom);
|
||||
}
|
||||
|
||||
public float getScale() {
|
||||
return mScale;
|
||||
}
|
||||
|
||||
/**
|
||||
* If target is shorter then screen, make it in screen center. If target is
|
||||
* longer then parent, make sure target fill parent over
|
||||
|
||||
@@ -22,11 +22,13 @@ import android.support.annotation.NonNull;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.animation.Interpolator;
|
||||
|
||||
import com.hippo.anani.AnimationUtils;
|
||||
import com.hippo.gl.anim.Animation;
|
||||
import com.hippo.gl.view.GLView;
|
||||
import com.hippo.gl.widget.GLEdgeView;
|
||||
import com.hippo.gl.widget.GLProgressView;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -64,6 +66,7 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
|
||||
private int mProgressSpec;
|
||||
|
||||
private int[] mScrollRemain = new int[2];
|
||||
private float[] mScaleDefault = new float[3];
|
||||
|
||||
private boolean mCanScrollBetweenPages = false;
|
||||
|
||||
@@ -72,6 +75,7 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
|
||||
|
||||
private PageFling mPageFling;
|
||||
private SmoothScroller mSmoothScroller;
|
||||
private SmoothScaler mSmoothScaler;
|
||||
|
||||
public PagerLayoutManager(Context context, @NonNull GalleryView galleryView,
|
||||
int interval, int progressSize) {
|
||||
@@ -81,6 +85,7 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
|
||||
|
||||
mPageFling = new PageFling(context);
|
||||
mSmoothScroller = new SmoothScroller();
|
||||
mSmoothScaler = new SmoothScaler();
|
||||
}
|
||||
|
||||
public void setMode(@Mode int mode) {
|
||||
@@ -265,10 +270,15 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
|
||||
|
||||
mSmoothScroller.cancel();
|
||||
mPageFling.cancel();
|
||||
mSmoothScaler.cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUp() {
|
||||
if (mCurrent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
mGalleryView.getEdgeView().onRelease();
|
||||
|
||||
// Scroll
|
||||
@@ -288,6 +298,28 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDoubleTapConfirmed(float x, float y) {
|
||||
if (mCurrent == null || !mCurrent.getImageView().isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
float[] scales = mScaleDefault;
|
||||
ImageView image = mCurrent.getImageView();
|
||||
image.getScaleDefault(scales);
|
||||
float scale = image.getScale();
|
||||
float endScale = scales[0];
|
||||
for (int i = 0, size = scales.length; i < size; i++) {
|
||||
float value = scales[i];
|
||||
if (scale < value) {
|
||||
endScale = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mSmoothScaler.startSmoothScaler(x, y, scale, endScale, 300);
|
||||
}
|
||||
|
||||
private void pagePrevious() {
|
||||
GalleryView.PageIterator iterator = mIterator;
|
||||
if (!iterator.hasPrevious()) {
|
||||
@@ -515,7 +547,7 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
|
||||
|
||||
@Override
|
||||
public void onScale(float focusX, float focusY, float scale) {
|
||||
if (mCurrent == null) {
|
||||
if (mCurrent == null || !mCurrent.getImageView().isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -527,6 +559,7 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
|
||||
public boolean onUpdateAnimation(long time) {
|
||||
boolean invalidate = mSmoothScroller.calculate(time);
|
||||
invalidate |= mPageFling.calculate(time);
|
||||
invalidate |= mSmoothScaler.calculate(time);
|
||||
return invalidate;
|
||||
}
|
||||
|
||||
@@ -659,4 +692,40 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SmoothScaler extends Animation {
|
||||
|
||||
private float mFocusX;
|
||||
private float mFocusY;
|
||||
private float mStartScale;
|
||||
private float mEndScale;
|
||||
private float mLastScale;
|
||||
|
||||
public SmoothScaler() {
|
||||
setInterpolator(AnimationUtils.FAST_SLOW_INTERPOLATOR);
|
||||
}
|
||||
|
||||
public void startSmoothScaler(float focusX, float focusY,
|
||||
float startScale, float endScale, int duration) {
|
||||
mFocusX = focusX;
|
||||
mFocusY = focusY;
|
||||
mStartScale = startScale;
|
||||
mEndScale = endScale;
|
||||
mLastScale = startScale;
|
||||
setDuration(duration);
|
||||
start();
|
||||
mGalleryView.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCalculate(float progress) {
|
||||
if (mCurrent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
float scale = MathUtils.lerp(mStartScale, mEndScale, progress);
|
||||
mCurrent.getImageView().scale(mFocusX, mFocusY, scale / mLastScale);
|
||||
mLastScale = scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,11 @@ public class ScrollLayoutManager extends GalleryView.LayoutManager {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDoubleTapConfirmed(float x, float y) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScroll(float dx, float dy, float totalX, float totalY, float x, float y) {
|
||||
|
||||
|
||||
Reference in new issue
Block a user