summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBobby Georgescu <georgescu@google.com>2013-04-10 11:46:56 -0700
committerBobby Georgescu <georgescu@google.com>2013-04-10 11:49:28 -0700
commitf7ed2bba1b549c4cced8b5b762aa12b5d52012ea (patch)
tree8e5ad6f9e06534c6ab87d01878ecca194a55ab5e
parent753bb8aa56fff425fe16b93be368b9b236e4751f (diff)
downloadandroid_packages_apps_Snap-f7ed2bba1b549c4cced8b5b762aa12b5d52012ea.tar.gz
android_packages_apps_Snap-f7ed2bba1b549c4cced8b5b762aa12b5d52012ea.tar.bz2
android_packages_apps_Snap-f7ed2bba1b549c4cced8b5b762aa12b5d52012ea.zip
Correctly scale images in MTP importer
Bug: 8293048 Change-Id: Ib46a6ce13aeea6a59706790b69be29215be7ebc4
-rw-r--r--src/com/android/gallery3d/ingest/ui/MtpImageView.java61
1 files changed, 59 insertions, 2 deletions
diff --git a/src/com/android/gallery3d/ingest/ui/MtpImageView.java b/src/com/android/gallery3d/ingest/ui/MtpImageView.java
index 5664d8a34..9ab78628d 100644
--- a/src/com/android/gallery3d/ingest/ui/MtpImageView.java
+++ b/src/com/android/gallery3d/ingest/ui/MtpImageView.java
@@ -17,6 +17,7 @@
package com.android.gallery3d.ingest.ui;
import android.content.Context;
+import android.graphics.Matrix;
import android.mtp.MtpDevice;
import android.mtp.MtpObjectInfo;
import android.os.Handler;
@@ -91,10 +92,67 @@ public class MtpImageView extends ImageView {
return MtpBitmapFetch.getFullsize(device, info);
}
+ private float mLastBitmapWidth;
+ private float mLastBitmapHeight;
+ private int mLastRotationDegrees;
+ private Matrix mDrawMatrix = new Matrix();
+
+ private void updateDrawMatrix() {
+ mDrawMatrix.reset();
+ float dwidth;
+ float dheight;
+ float vheight = getHeight();
+ float vwidth = getWidth();
+ float scale;
+ boolean rotated90 = (mLastRotationDegrees % 180 != 0);
+ if (rotated90) {
+ dwidth = mLastBitmapHeight;
+ dheight = mLastBitmapWidth;
+ } else {
+ dwidth = mLastBitmapWidth;
+ dheight = mLastBitmapHeight;
+ }
+ if (dwidth <= vwidth && dheight <= vheight) {
+ scale = 1.0f;
+ } else {
+ scale = Math.min(vwidth / dwidth, vheight / dheight);
+ }
+ mDrawMatrix.setScale(scale, scale);
+ if (rotated90) {
+ mDrawMatrix.postTranslate(-dheight * scale * 0.5f,
+ -dwidth * scale * 0.5f);
+ mDrawMatrix.postRotate(mLastRotationDegrees);
+ mDrawMatrix.postTranslate(dwidth * scale * 0.5f,
+ dheight * scale * 0.5f);
+ }
+ mDrawMatrix.postTranslate((vwidth - dwidth * scale) * 0.5f,
+ (vheight - dheight * scale) * 0.5f);
+ if (!rotated90 && mLastRotationDegrees > 0) {
+ // rotated by a multiple of 180
+ mDrawMatrix.postRotate(mLastRotationDegrees, vwidth / 2, vheight / 2);
+ }
+ setImageMatrix(mDrawMatrix);
+ }
+
+ @Override
+ protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+ super.onLayout(changed, left, top, right, bottom);
+ if (changed && getScaleType() == ScaleType.MATRIX) {
+ updateDrawMatrix();
+ }
+ }
+
protected void onMtpImageDataFetchedFromDevice(Object result) {
BitmapWithMetadata bitmapWithMetadata = (BitmapWithMetadata)result;
+ if (getScaleType() == ScaleType.MATRIX) {
+ mLastBitmapHeight = bitmapWithMetadata.bitmap.getHeight();
+ mLastBitmapWidth = bitmapWithMetadata.bitmap.getWidth();
+ mLastRotationDegrees = bitmapWithMetadata.rotationDegrees;
+ updateDrawMatrix();
+ } else {
+ setRotation(bitmapWithMetadata.rotationDegrees);
+ }
setImageBitmap(bitmapWithMetadata.bitmap);
- setRotation(bitmapWithMetadata.rotationDegrees);
}
protected void cancelLoadingAndClear() {
@@ -104,7 +162,6 @@ public class MtpImageView extends ImageView {
mFetchResult = null;
}
setImageResource(android.R.color.transparent);
- setRotation(0);
}
@Override