diff options
author | Bobby Georgescu <georgescu@google.com> | 2013-04-10 19:39:42 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-04-10 19:39:42 +0000 |
commit | 7f8e138c86f77e64df7d85ab5d51148418c56ca1 (patch) | |
tree | 7c1823a867ff62dfe52c55cc574763b69e360056 | |
parent | 97963eb474d44d7c0e059f5c0d1f0564c79d4f06 (diff) | |
parent | f7ed2bba1b549c4cced8b5b762aa12b5d52012ea (diff) | |
download | android_packages_apps_Snap-7f8e138c86f77e64df7d85ab5d51148418c56ca1.tar.gz android_packages_apps_Snap-7f8e138c86f77e64df7d85ab5d51148418c56ca1.tar.bz2 android_packages_apps_Snap-7f8e138c86f77e64df7d85ab5d51148418c56ca1.zip |
Merge "Correctly scale images in MTP importer" into gb-ub-photos-bryce
-rw-r--r-- | src/com/android/gallery3d/ingest/ui/MtpImageView.java | 61 |
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 |