From 4f38cc1673163848c7b843cb9d23b21945b0bf82 Mon Sep 17 00:00:00 2001 From: Mark Wei Date: Wed, 29 Aug 2012 15:05:38 -0700 Subject: Attachment image viewer should not scale images larger than original size. Bug: 7049410 Change-Id: I1ed2555203e1541f1481cae4f17f532eaa57c1cd --- .../src/com/android/ex/photo/loaders/PhotoBitmapLoader.java | 5 ++++- photoviewer/src/com/android/ex/photo/views/PhotoView.java | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/photoviewer/src/com/android/ex/photo/loaders/PhotoBitmapLoader.java b/photoviewer/src/com/android/ex/photo/loaders/PhotoBitmapLoader.java index f5c5cd0..7049370 100644 --- a/photoviewer/src/com/android/ex/photo/loaders/PhotoBitmapLoader.java +++ b/photoviewer/src/com/android/ex/photo/loaders/PhotoBitmapLoader.java @@ -22,6 +22,7 @@ import android.content.ContentResolver; import android.content.Context; import android.graphics.Bitmap; import android.net.Uri; +import android.util.DisplayMetrics; import com.android.ex.photo.fragments.PhotoViewFragment; import com.android.ex.photo.util.ImageUtils; @@ -49,8 +50,10 @@ public class PhotoBitmapLoader extends AsyncTaskLoader { if (context != null && mPhotoUri != null) { final ContentResolver resolver = context.getContentResolver(); - return ImageUtils.createLocalBitmap(resolver, Uri.parse(mPhotoUri), + Bitmap bitmap = ImageUtils.createLocalBitmap(resolver, Uri.parse(mPhotoUri), PhotoViewFragment.sPhotoSize); + bitmap.setDensity(DisplayMetrics.DENSITY_MEDIUM); + return bitmap; } return null; diff --git a/photoviewer/src/com/android/ex/photo/views/PhotoView.java b/photoviewer/src/com/android/ex/photo/views/PhotoView.java index 647d168..e767cba 100644 --- a/photoviewer/src/com/android/ex/photo/views/PhotoView.java +++ b/photoviewer/src/com/android/ex/photo/views/PhotoView.java @@ -699,7 +699,6 @@ public class PhotoView extends View implements GestureDetector.OnGestureListener final boolean fits = (dwidth < 0 || vwidth == dwidth) && (dheight < 0 || vheight == dheight); - // Set the matrix to fill the screen if (fits && !mAllowCrop) { mMatrix.reset(); } else { @@ -710,7 +709,12 @@ public class PhotoView extends View implements GestureDetector.OnGestureListener } else { mTempDst.set(0, 0, vwidth, vheight); } - mMatrix.setRectToRect(mTempSrc, mTempDst, Matrix.ScaleToFit.CENTER); + + if (dwidth < vwidth && dheight < vheight && !mAllowCrop) { + mMatrix.setTranslate(vwidth / 2 - dwidth / 2, vheight / 2 - dheight / 2); + } else { + mMatrix.setRectToRect(mTempSrc, mTempDst, Matrix.ScaleToFit.CENTER); + } } mOriginalMatrix.set(mMatrix); } -- cgit v1.2.3