diff options
author | Michael Jurka <mikejurka@google.com> | 2013-12-02 15:05:44 -0800 |
---|---|---|
committer | Adam Cohen <adamcohen@google.com> | 2014-03-19 17:56:55 +0000 |
commit | c82618c660bbb76df05c11c548cc01724f5e5fc9 (patch) | |
tree | f0fe46dc29e50c29140400bb653b2f16f2e37704 /packages | |
parent | 5d3d4ee3005e910dce780074d3f68d594aa12070 (diff) | |
download | frameworks_base-c82618c660bbb76df05c11c548cc01724f5e5fc9.zip frameworks_base-c82618c660bbb76df05c11c548cc01724f5e5fc9.tar.gz frameworks_base-c82618c660bbb76df05c11c548cc01724f5e5fc9.tar.bz2 |
[DO NOT MERGE] Fix wallpaper cropping bugs
- take into account that image decoder might not
respect inSampleSize
- check rounded values so we don't have crop rects
that lie outside a bitmap's dimensions
- correctly set initial scale on bitmaps that are
larger than the screen size
- switch to using asynctask when setting wallpaper
dimensions
(cherry picked from commit e39c9a953ca11319b747b3aa79f4ccd082b775b7)
Change-Id: I43372f0bff37f139c8bc83f9956a967d0b4a8708
Diffstat (limited to 'packages')
-rw-r--r-- | packages/WallpaperCropper/src/com/android/wallpapercropper/CropView.java | 3 | ||||
-rw-r--r-- | packages/WallpaperCropper/src/com/android/wallpapercropper/WallpaperCropActivity.java | 36 |
2 files changed, 34 insertions, 5 deletions
diff --git a/packages/WallpaperCropper/src/com/android/wallpapercropper/CropView.java b/packages/WallpaperCropper/src/com/android/wallpapercropper/CropView.java index 14f7c1d..c3ef302 100644 --- a/packages/WallpaperCropper/src/com/android/wallpapercropper/CropView.java +++ b/packages/WallpaperCropper/src/com/android/wallpapercropper/CropView.java @@ -165,7 +165,8 @@ public class CropView extends TiledImageView implements OnScaleGestureListener { final float imageWidth = imageDims[0]; final float imageHeight = imageDims[1]; mMinScale = Math.max(w / imageWidth, h / imageHeight); - mRenderer.scale = Math.max(mMinScale, mRenderer.scale); + mRenderer.scale = + Math.max(mMinScale, resetScale ? Float.MIN_VALUE : mRenderer.scale); } } } diff --git a/packages/WallpaperCropper/src/com/android/wallpapercropper/WallpaperCropActivity.java b/packages/WallpaperCropper/src/com/android/wallpapercropper/WallpaperCropActivity.java index 7b3f112..04963d4 100644 --- a/packages/WallpaperCropper/src/com/android/wallpapercropper/WallpaperCropActivity.java +++ b/packages/WallpaperCropper/src/com/android/wallpapercropper/WallpaperCropActivity.java @@ -557,6 +557,8 @@ public class WallpaperCropActivity extends Activity { Rect roundedTrueCrop = new Rect(); Matrix rotateMatrix = new Matrix(); Matrix inverseRotateMatrix = new Matrix(); + + Point bounds = getImageBounds(); if (mRotation > 0) { rotateMatrix.setRotate(mRotation); inverseRotateMatrix.setRotate(-mRotation); @@ -564,7 +566,6 @@ public class WallpaperCropActivity extends Activity { mCropBounds.roundOut(roundedTrueCrop); mCropBounds = new RectF(roundedTrueCrop); - Point bounds = getImageBounds(); if (bounds == null) { Log.w(LOGTAG, "cannot get bounds for image"); failure = true; @@ -636,12 +637,38 @@ public class WallpaperCropActivity extends Activity { Utils.closeSilently(is); } if (fullSize != null) { + // Find out the true sample size that was used by the decoder + scaleDownSampleSize = bounds.x / fullSize.getWidth(); mCropBounds.left /= scaleDownSampleSize; mCropBounds.top /= scaleDownSampleSize; mCropBounds.bottom /= scaleDownSampleSize; mCropBounds.right /= scaleDownSampleSize; mCropBounds.roundOut(roundedTrueCrop); + // Adjust values to account for issues related to rounding + if (roundedTrueCrop.width() > fullSize.getWidth()) { + // Adjust the width + roundedTrueCrop.right = roundedTrueCrop.left + fullSize.getWidth(); + } + if (roundedTrueCrop.right > fullSize.getWidth()) { + // Adjust the left value + int adjustment = roundedTrueCrop.left - + Math.max(0, roundedTrueCrop.right - roundedTrueCrop.width()); + roundedTrueCrop.left -= adjustment; + roundedTrueCrop.right -= adjustment; + } + if (roundedTrueCrop.height() > fullSize.getHeight()) { + // Adjust the height + roundedTrueCrop.bottom = roundedTrueCrop.top + fullSize.getHeight(); + } + if (roundedTrueCrop.bottom > fullSize.getHeight()) { + // Adjust the top value + int adjustment = roundedTrueCrop.top - + Math.max(0, roundedTrueCrop.bottom - roundedTrueCrop.height()); + roundedTrueCrop.top -= adjustment; + roundedTrueCrop.bottom -= adjustment; + } + crop = Bitmap.createBitmap(fullSize, roundedTrueCrop.left, roundedTrueCrop.top, roundedTrueCrop.width(), roundedTrueCrop.height()); @@ -766,14 +793,15 @@ public class WallpaperCropActivity extends Activity { final WallpaperManager wallpaperManager) { final Point defaultWallpaperSize = getDefaultWallpaperSize(res, windowManager); - new Thread("suggestWallpaperDimension") { - public void run() { + new AsyncTask<Void, Void, Void>() { + public Void doInBackground(Void ... args) { // If we have saved a wallpaper width/height, use that instead int savedWidth = sharedPrefs.getInt(WALLPAPER_WIDTH_KEY, defaultWallpaperSize.x); int savedHeight = sharedPrefs.getInt(WALLPAPER_HEIGHT_KEY, defaultWallpaperSize.y); wallpaperManager.suggestDesiredDimensions(savedWidth, savedHeight); + return null; } - }.start(); + }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); } protected static RectF getMaxCropRect( |