diff options
Diffstat (limited to 'photoviewer/src/com/android/ex/photo/views/PhotoView.java')
-rw-r--r-- | photoviewer/src/com/android/ex/photo/views/PhotoView.java | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/photoviewer/src/com/android/ex/photo/views/PhotoView.java b/photoviewer/src/com/android/ex/photo/views/PhotoView.java index 8575bb1..838a60d 100644 --- a/photoviewer/src/com/android/ex/photo/views/PhotoView.java +++ b/photoviewer/src/com/android/ex/photo/views/PhotoView.java @@ -108,6 +108,8 @@ public class PhotoView extends View implements OnGestureListener, private Rect mCropRect = new Rect(); /** Actual crop size; may differ from {@link #sCropSize} if the screen is smaller */ private int mCropSize; + /** The maximum amount of scaling to apply to images */ + private float mMaxInitialScaleFactor; /** Gesture detector */ private GestureDetectorCompat mGestureDetector; @@ -699,9 +701,13 @@ public class PhotoView extends View implements OnGestureListener, } else { mTempDst.set(0, 0, vwidth, vheight); } - - if (dwidth < vwidth && dheight < vheight && !mAllowCrop) { - mMatrix.setTranslate(vwidth / 2 - dwidth / 2, vheight / 2 - dheight / 2); + RectF scaledDestination = new RectF( + (vwidth / 2) - (dwidth * mMaxInitialScaleFactor / 2), + (vheight / 2) - (dheight * mMaxInitialScaleFactor / 2), + (vwidth / 2) + (dwidth * mMaxInitialScaleFactor / 2), + (vheight / 2) + (dheight * mMaxInitialScaleFactor / 2)); + if(mTempDst.contains(scaledDestination)) { + mMatrix.setRectToRect(mTempSrc, scaledDestination, Matrix.ScaleToFit.CENTER); } else { mMatrix.setRectToRect(mTempSrc, mTempDst, Matrix.ScaleToFit.CENTER); } @@ -1285,4 +1291,8 @@ public class PhotoView extends View implements OnGestureListener, mHeader.post(this); } } + + public void setMaxInitialScale(float f) { + mMaxInitialScaleFactor = f; + } } |