From a23b53f496e75771e6ed2ac5dfcac1ff0d826c7f Mon Sep 17 00:00:00 2001 From: Krzysztof Bielicki Date: Mon, 17 Feb 2014 11:45:30 +0100 Subject: [PATCH] Added canScrollVertically, canScrollHorizontally to behave properly in ViewPager --- .../library/imagezoom/ImageViewTouch.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/library/src/it/sephiroth/android/library/imagezoom/ImageViewTouch.java b/library/src/it/sephiroth/android/library/imagezoom/ImageViewTouch.java index 750f936..9841560 100644 --- a/library/src/it/sephiroth/android/library/imagezoom/ImageViewTouch.java +++ b/library/src/it/sephiroth/android/library/imagezoom/ImageViewTouch.java @@ -176,6 +176,11 @@ public boolean onSingleTapUp( MotionEvent e ) { return true; } + @Override + public boolean canScrollHorizontally(int direction) { + return canScroll(-direction); + } + /** * Determines whether this ImageViewTouch can be scrolled. * @@ -205,7 +210,28 @@ public boolean canScroll( int direction ) { return bitmapScrollRectDelta > SCROLL_DELTA_THRESHOLD; } - public class GestureListener extends GestureDetector.SimpleOnGestureListener { + @Override + public boolean canScrollVertically(int direction) { + RectF bitmapRect = getBitmapRect(); + updateRect( bitmapRect, mScrollRect ); + Rect imageViewRect = new Rect(); + getGlobalVisibleRect( imageViewRect ); + + if( null == bitmapRect ) { + return false; + } + + if ( bitmapRect.bottom >= imageViewRect.bottom ) { + if ( direction < 0 ) { + return Math.abs( bitmapRect.bottom - imageViewRect.bottom ) > SCROLL_DELTA_THRESHOLD; + } + } + + double bitmapScrollRectDelta = Math.abs( bitmapRect.top - mScrollRect.top ); + return bitmapScrollRectDelta > SCROLL_DELTA_THRESHOLD; + } + + public class GestureListener extends GestureDetector.SimpleOnGestureListener { @Override public boolean onSingleTapConfirmed( MotionEvent e ) {