diff options
author | Andrew Dolgov <[email protected]> | 2012-12-03 12:12:08 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2012-12-03 12:12:08 +0300 |
commit | df1fc6033a7997e49f4cf284b122641352c1e5ae (patch) | |
tree | 9e1fe4090b3b4ffb75902fb560a88109c341f049 /src/it/sephiroth | |
parent | c33c13cdf43f37141a525d96abd915328a537c1d (diff) |
add option to fit comics to width by default
Diffstat (limited to 'src/it/sephiroth')
-rw-r--r-- | src/it/sephiroth/android/library/imagezoom/ImageViewTouchBase.java | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/it/sephiroth/android/library/imagezoom/ImageViewTouchBase.java b/src/it/sephiroth/android/library/imagezoom/ImageViewTouchBase.java index a0e1a3b..95d6333 100644 --- a/src/it/sephiroth/android/library/imagezoom/ImageViewTouchBase.java +++ b/src/it/sephiroth/android/library/imagezoom/ImageViewTouchBase.java @@ -39,6 +39,7 @@ public class ImageViewTouchBase extends ImageView implements IDisposable { protected final float[] mMatrixValues = new float[9]; protected int mThisWidth = -1, mThisHeight = -1; protected boolean mFitToScreen = false; + protected boolean mFitToWidth = false; final protected float MAX_ZOOM = 2.0f; protected RectF mBitmapRect = new RectF(); @@ -76,6 +77,13 @@ public class ImageViewTouchBase extends ImageView implements IDisposable { } } + public void setFitToWidth( boolean value ) { + if ( value != mFitToWidth ) { + mFitToWidth = value; + requestLayout(); + } + } + @Override protected void onLayout( boolean changed, int left, int top, int right, int bottom ) { super.onLayout( changed, left, top, right, bottom ); @@ -92,6 +100,9 @@ public class ImageViewTouchBase extends ImageView implements IDisposable { else getProperBaseMatrix( getDrawable(), mBaseMatrix ); setImageMatrix( getImageViewMatrix() ); + + if (mFitToWidth && getScale() - 1f <= 0.01) + zoomToWidth(); } } @@ -182,13 +193,17 @@ public class ImageViewTouchBase extends ImageView implements IDisposable { } protected void _setImageDrawable( final Drawable drawable, final boolean reset, final Matrix initial_matrix, final float maxZoom ) { - + if ( drawable != null ) { if ( mFitToScreen ) getProperBaseMatrix2( drawable, mBaseMatrix ); else getProperBaseMatrix( drawable, mBaseMatrix ); super.setImageDrawable( drawable ); + + if (mFitToWidth && getScale() - 1f <= 0.01) + zoomToWidth(); + } else { mBaseMatrix.reset(); super.setImageDrawable( null ); @@ -483,4 +498,17 @@ public class ImageViewTouchBase extends ImageView implements IDisposable { public void dispose() { clear(); } + + protected void zoomToWidth() { + RectF bitmapRect = getBitmapRect(); + + float w = bitmapRect.right - bitmapRect.left; + + float scale = 1f; + + if (w < getWidth()) { + scale = (float)getWidth() / w; + zoomTo(scale, 0f, 0f); + } + } } |