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 | |
parent | c33c13cdf43f37141a525d96abd915328a537c1d (diff) |
add option to fit comics to width by default
Diffstat (limited to 'src')
-rw-r--r-- | src/it/sephiroth/android/library/imagezoom/ImageViewTouchBase.java | 30 | ||||
-rw-r--r-- | src/org/fox/ttcomics/ComicFragment.java | 6 |
2 files changed, 34 insertions, 2 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); + } + } } diff --git a/src/org/fox/ttcomics/ComicFragment.java b/src/org/fox/ttcomics/ComicFragment.java index 09c9659..4c5ce9c 100644 --- a/src/org/fox/ttcomics/ComicFragment.java +++ b/src/org/fox/ttcomics/ComicFragment.java @@ -84,7 +84,11 @@ public class ComicFragment extends Fragment implements GestureDetector.OnDoubleT image.setBackgroundColor(0xff000000);
}
- image.setFitToScreen(true);
+ if (m_prefs.getBoolean("fit_to_width", false)) {
+ image.setFitToWidth(true);
+ } else {
+ image.setFitToScreen(true);
+ }
AsyncTask<ComicArchive, Void, Bitmap> loadTask = new AsyncTask<ComicArchive, Void, Bitmap>() {
@Override
|