Skip to content

Commit

Permalink
fixed first scale, removed unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
sephiroth74 committed Mar 18, 2013
1 parent 1ab26ca commit 16ccac1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,7 +44,6 @@ protected void init() {
mScaleDetector = new ScaleGestureDetector( getContext(), mScaleListener );
mGestureDetector = new GestureDetector( getContext(), mGestureListener, null, true );

mCurrentScaleFactor = 1f;
mDoubleTapDirection = 1;
}

Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
Expand All @@ -278,7 +262,7 @@ public boolean onScale( ScaleGestureDetector detector ) {
// image is scaled.
if( !mScaled ) mScaled = true;
}
return false;
return true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 16ccac1

Please sign in to comment.