From 3179f6a49516833761be5155c4e1244ac0aa17fe Mon Sep 17 00:00:00 2001 From: Doris Liu Date: Tue, 8 Oct 2013 16:54:22 -0700 Subject: [PATCH] Allow scaling beyond 1:1 in zoom view Bug: 10950226 Change-Id: I38828edaf4010170f6c6db18b8c5fdeef91b4f11 --- src/com/android/camera/ui/FilmStripView.java | 28 ++++++++++++++++++++++++---- src/com/android/camera/ui/ZoomView.java | 2 +- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/com/android/camera/ui/FilmStripView.java b/src/com/android/camera/ui/FilmStripView.java index 21f2fc864..2e3193c73 100644 --- a/src/com/android/camera/ui/FilmStripView.java +++ b/src/com/android/camera/ui/FilmStripView.java @@ -25,9 +25,11 @@ import android.content.res.Configuration; import android.graphics.Canvas; import android.graphics.Rect; import android.graphics.RectF; +import android.hardware.display.DisplayManager; import android.net.Uri; import android.os.Handler; import android.util.AttributeSet; +import android.util.DisplayMetrics; import android.util.Log; import android.view.MotionEvent; import android.view.View; @@ -96,6 +98,7 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener { private boolean mIsUserScrolling; private int mDataIdOnUserScrolling; private ValueAnimator.AnimatorUpdateListener mViewItemUpdateListener; + private float mOverScaleFactor = 1f; /** * Common interface for all images in the filmstrip. @@ -657,6 +660,16 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener { invalidate(); } }; + DisplayMetrics metrics = new DisplayMetrics(); + mActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics); + // Allow over scaling because on high density screens, pixels are too + // tiny to clearly see the details at 1:1 zoom. We should not scale + // beyond what 1:1 would look like on a medium density screen, as + // scaling beyond that would only yield blur. + mOverScaleFactor = (float) metrics.densityDpi / (float) DisplayMetrics.DENSITY_MEDIUM; + if (mOverScaleFactor < 1f) { + mOverScaleFactor = 1f; + } } /** @@ -1917,7 +1930,7 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener { mZoomAnimator.end(); } // Calculate end scale - final float maxScale = getCurrentDataMaxScale(); + final float maxScale = getCurrentDataMaxScale(false); final float endScale = mScale < maxScale - maxScale * TOLERANCE ? maxScale : FULL_SCREEN_SCALE; @@ -2132,7 +2145,7 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener { * actual pixels). The max scale that we can apply on the view should * make the view same size as the image, in pixels. */ - private float getCurrentDataMaxScale() { + private float getCurrentDataMaxScale(boolean allowOverScale) { ViewItem curr = mViewItem[mCurrentItem]; ImageData imageData = mDataAdapter.getImageData(curr.getId()); if (curr == null || !imageData @@ -2143,7 +2156,14 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener { if (imageData.getOrientation() == 90 || imageData.getOrientation() == 270) { imageWidth = imageData.getHeight(); } - return imageWidth / curr.getWidth(); + float scale = imageWidth / curr.getWidth(); + if (allowOverScale) { + // In addition to the scale we apply to the view for 100% view + // (i.e. each pixel on screen corresponds to a pixel in image) + // we allow scaling beyond that for better detail viewing. + scale *= mOverScaleFactor; + } + return scale; } private void loadZoomedImage() { @@ -2558,7 +2578,7 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener { mScaleTrend = 1f; // If the image is smaller than screen size, we should allow to zoom // in to full screen size - mMaxScale = Math.max(mController.getCurrentDataMaxScale(), FULL_SCREEN_SCALE); + mMaxScale = Math.max(mController.getCurrentDataMaxScale(true), FULL_SCREEN_SCALE); return true; } diff --git a/src/com/android/camera/ui/ZoomView.java b/src/com/android/camera/ui/ZoomView.java index f7b645341..e8154dec4 100644 --- a/src/com/android/camera/ui/ZoomView.java +++ b/src/com/android/camera/ui/ZoomView.java @@ -148,7 +148,7 @@ public class ZoomView extends ImageView { public ZoomView(Context context) { super(context); - setScaleType(ScaleType.CENTER_INSIDE); + setScaleType(ScaleType.FIT_CENTER); addOnLayoutChangeListener(new OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, -- 2.11.0