From 16ccac1a9155b80b6b4a5f9245573fa982cc6ac2 Mon Sep 17 00:00:00 2001 From: Alessandro Crugnola Date: Sun, 17 Mar 2013 20:24:11 -0400 Subject: [PATCH] fixed first scale, removed unused code --- .../library/imagezoom/ImageViewTouch.java | 30 +++++-------------- .../library/imagezoom/ImageViewTouchBase.java | 8 ++--- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/ImageViewTouch/src/it/sephiroth/android/library/imagezoom/ImageViewTouch.java b/ImageViewTouch/src/it/sephiroth/android/library/imagezoom/ImageViewTouch.java index 6728061..e023039 100644 --- a/ImageViewTouch/src/it/sephiroth/android/library/imagezoom/ImageViewTouch.java +++ b/ImageViewTouch/src/it/sephiroth/android/library/imagezoom/ImageViewTouch.java @@ -20,7 +20,6 @@ public class ImageViewTouch extends ImageViewTouchBase { protected ScaleGestureDetector mScaleDetector; protected GestureDetector mGestureDetector; protected int mTouchSlop; - protected float mCurrentScaleFactor; protected float mScaleFactor; protected int mDoubleTapDirection; protected OnGestureListener mGestureListener; @@ -45,7 +44,6 @@ protected void init() { mScaleDetector = new ScaleGestureDetector( getContext(), mScaleListener ); mGestureDetector = new GestureDetector( getContext(), mGestureListener, null, true ); - mCurrentScaleFactor = 1f; mDoubleTapDirection = 1; } @@ -81,15 +79,6 @@ protected OnScaleGestureListener getScaleListener() { return new ScaleListener(); } - @Override - protected void onLayoutChanged( int left, int top, int right, int bottom ) { - super.onLayoutChanged( left, top, right, bottom ); - - float v[] = new float[9]; - mSuppMatrix.getValues( v ); - mCurrentScaleFactor = v[Matrix.MSCALE_X]; - } - @Override protected void _setImageDrawable( final Drawable drawable, final Matrix initial_matrix, float min_zoom, float max_zoom ) { super._setImageDrawable( drawable, initial_matrix, min_zoom, max_zoom ); @@ -115,16 +104,13 @@ public boolean onTouchEvent( MotionEvent event ) { return true; } - @Override - protected void onZoom( float scale ) { - if ( !mScaleDetector.isInProgress() ) mCurrentScaleFactor = scale; - } @Override protected void onZoomAnimationCompleted( float scale ) { - if ( !mScaleDetector.isInProgress() ) mCurrentScaleFactor = scale; - Log.d( LOG_TAG, "onZoomAnimationCompleted. scale: " + scale + ", minZoom: " + getMinScale() ); + if( LOG_ENABLED ) { + Log.d( LOG_TAG, "onZoomAnimationCompleted. scale: " + scale + ", minZoom: " + getMinScale() ); + } if ( scale < getMinScale() ) { zoomTo( getMinScale(), 50 ); @@ -220,7 +206,6 @@ public boolean onDoubleTap( MotionEvent e ) { float targetScale = scale; targetScale = onDoubleTapPost( scale, getMaxScale() ); targetScale = Math.min( getMaxScale(), Math.max( targetScale, getMinScale() ) ); - mCurrentScaleFactor = targetScale; zoomTo( targetScale, e.getX(), e.getY(), DEFAULT_ANIMATION_DURATION ); invalidate(); } @@ -257,18 +242,17 @@ public boolean onFling( MotionEvent e1, MotionEvent e2, float velocityX, float v public class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener { - protected boolean mScaled; + protected boolean mScaled = false; @Override public boolean onScale( ScaleGestureDetector detector ) { float span = detector.getCurrentSpan() - detector.getPreviousSpan(); - float targetScale = mCurrentScaleFactor * detector.getScaleFactor(); - + float targetScale = getScale() * detector.getScaleFactor(); + if ( mScaleEnabled ) { if( mScaled && span != 0 ) { targetScale = Math.min( getMaxScale(), Math.max( targetScale, getMinScale() - 0.1f ) ); zoomTo( targetScale, detector.getFocusX(), detector.getFocusY() ); - mCurrentScaleFactor = Math.min( getMaxScale(), Math.max( targetScale, getMinScale() - 1.0f ) ); mDoubleTapDirection = 1; invalidate(); return true; @@ -278,7 +262,7 @@ public boolean onScale( ScaleGestureDetector detector ) { // image is scaled. if( !mScaled ) mScaled = true; } - return false; + return true; } } diff --git a/ImageViewTouch/src/it/sephiroth/android/library/imagezoom/ImageViewTouchBase.java b/ImageViewTouch/src/it/sephiroth/android/library/imagezoom/ImageViewTouchBase.java index c49fdc1..f3549ca 100644 --- a/ImageViewTouch/src/it/sephiroth/android/library/imagezoom/ImageViewTouchBase.java +++ b/ImageViewTouch/src/it/sephiroth/android/library/imagezoom/ImageViewTouchBase.java @@ -51,8 +51,8 @@ public enum DisplayType { }; - public static final String LOG_TAG = "image"; - protected static final boolean LOG_ENABLED = true; + public static final String LOG_TAG = "ImageViewTouchBase"; + protected static final boolean LOG_ENABLED = false; public static final float ZOOM_INVALID = -1f; @@ -761,9 +761,9 @@ protected void zoomTo( float scale, float centerX, float centerY ) { center( true, true ); } - protected abstract void onZoom( float scale ); + protected void onZoom( float scale ){} - protected abstract void onZoomAnimationCompleted( float scale ); + protected void onZoomAnimationCompleted( float scale ){} /** * Scrolls the view by the x and y amount