Skip to content

Commit

Permalink
added canScroll method for imageview
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Termenji committed Sep 25, 2012
1 parent 217766b commit 41a6071
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.content.Context;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
Expand All @@ -14,6 +16,7 @@

public class ImageViewTouch extends ImageViewTouchBase {

private static final float SCROLL_DELTA_THRESHOLD = 1.0f;
static final float MIN_ZOOM = 0.9f;
protected ScaleGestureDetector mScaleDetector;
protected GestureDetector mGestureDetector;
Expand Down Expand Up @@ -124,7 +127,31 @@ protected float onDoubleTapPost( float scale, float maxZoom ) {
return 1f;
}
}


/**
* Determines whether this ImageViewTouch can be scrolled.
* @param direction
* - positive direction value means scroll from right to left,
* negative value means scroll from left to right
*
* @return true if there is some more place to scroll, false - otherwise.
*/
public boolean canScroll(int direction) {
RectF bitmapRect = getBitmapRect();
updateRect(bitmapRect, mScrollRect);
Rect imageViewRect = new Rect();
getGlobalVisibleRect(imageViewRect);

if (bitmapRect.right >= imageViewRect.right) {
if (direction < 0) {
return Math.abs(bitmapRect.right - imageViewRect.right) > SCROLL_DELTA_THRESHOLD;
}
}

double bitmapScrollRectDelta = Math.abs(bitmapRect.left - mScrollRect.left);
return bitmapScrollRectDelta > SCROLL_DELTA_THRESHOLD;
}

public class GestureListener extends GestureDetector.SimpleOnGestureListener {

@Override
Expand Down

0 comments on commit 41a6071

Please sign in to comment.