diff options
author | Tony Wickham <twickham@google.com> | 2015-09-09 18:21:49 -0700 |
---|---|---|
committer | Tony Wickham <twickham@google.com> | 2015-09-10 11:56:54 -0700 |
commit | 3e776a87dc5178ab7d2c31a8db06fe5657db4e4a (patch) | |
tree | 4eb42d1e367620c45a53b0817e5600a22f2dbfef /WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java | |
parent | 01251b0dc4c302a8b9eb6ef6797c8e33eebab139 (diff) | |
download | android_packages_apps_Trebuchet-3e776a87dc5178ab7d2c31a8db06fe5657db4e4a.tar.gz android_packages_apps_Trebuchet-3e776a87dc5178ab7d2c31a8db06fe5657db4e4a.tar.bz2 android_packages_apps_Trebuchet-3e776a87dc5178ab7d2c31a8db06fe5657db4e4a.zip |
Wallpaper preview parallax matches the actual wallpaper's.
Cherry picking the following changes from ub-launcher3-master:
Change-Id: I41c5bbbfdabfeb4e20d77e9b5804842a03211edf
Change-Id: I69afa3f8cc59c77e9c4c25e29e8db8c4beb87462
Change-Id: I82b7ba506d51ee4b3812af5fbdf95d3303b37aef
Change-Id: Id7c2b5483c5535d59be2f8a459ce7788e3c8318a
Bug: 23568800
Change-Id: I343169b9fdc5ceaab3d4b39044627d78b7267868
Diffstat (limited to 'WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java')
-rw-r--r-- | WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java | 58 |
1 files changed, 40 insertions, 18 deletions
diff --git a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java index f2459dd3e..0dbd3578a 100644 --- a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java +++ b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java @@ -124,7 +124,11 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb @Override public void onClick(View v) { boolean finishActivityWhenDone = true; - cropImageAndSetWallpaper(imageUri, null, finishActivityWhenDone); + // Never fade on finish because we return to the app that started us (e.g. + // Photos), not the home screen. + boolean shouldFadeOutOnFinish = false; + cropImageAndSetWallpaper(imageUri, null, finishActivityWhenDone, + shouldFadeOutOnFinish); } }); mSetWallpaperButton = findViewById(R.id.set_wallpaper_button); @@ -246,8 +250,14 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb if (req.moveToLeft) { mCropView.moveToLeft(); } - if (req.scaleProvider != null) { - mCropView.setScale(req.scaleProvider.getScale(req.result)); + if (req.scaleAndOffsetProvider != null) { + TileSource src = req.result; + Point wallpaperSize = WallpaperUtils.getDefaultWallpaperSize( + getResources(), getWindowManager()); + RectF crop = Utils.getMaxCropRect(src.getImageWidth(), src.getImageHeight(), + wallpaperSize.x, wallpaperSize.y, false /* leftAligned */); + mCropView.setScale(req.scaleAndOffsetProvider.getScale(wallpaperSize, crop)); + mCropView.setParallaxOffset(req.scaleAndOffsetProvider.getParallaxOffset(), crop); } // Free last image @@ -265,13 +275,13 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb } public final void setCropViewTileSource(BitmapSource bitmapSource, boolean touchEnabled, - boolean moveToLeft, CropViewScaleProvider scaleProvider, Runnable postExecute) { + boolean moveToLeft, CropViewScaleAndOffsetProvider scaleProvider, Runnable postExecute) { final LoadRequest req = new LoadRequest(); req.moveToLeft = moveToLeft; req.src = bitmapSource; req.touchEnabled = touchEnabled; req.postExecute = postExecute; - req.scaleProvider = scaleProvider; + req.scaleAndOffsetProvider = scaleProvider; mCurrentLoadRequest = req; // Remove any pending requests @@ -295,17 +305,21 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb return getResources().getBoolean(R.bool.allow_rotation); } - protected void setWallpaper(Uri uri, final boolean finishActivityWhenDone) { + protected void setWallpaper(Uri uri, final boolean finishActivityWhenDone, + final boolean shouldFadeOutOnFinish) { int rotation = BitmapUtils.getRotationFromExif(getContext(), uri); BitmapCropTask cropTask = new BitmapCropTask( getContext(), uri, null, rotation, 0, 0, true, false, null); final Point bounds = cropTask.getImageBounds(); - Runnable onEndCrop = new Runnable() { - public void run() { + BitmapCropTask.OnEndCropHandler onEndCrop = new BitmapCropTask.OnEndCropHandler() { + public void run(boolean cropSucceeded) { updateWallpaperDimensions(bounds.x, bounds.y); if (finishActivityWhenDone) { setResult(Activity.RESULT_OK); finish(); + if (cropSucceeded && shouldFadeOutOnFinish) { + overridePendingTransition(0, R.anim.fade_out); + } } } }; @@ -314,8 +328,8 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb cropTask.execute(); } - protected void cropImageAndSetWallpaper( - Resources res, int resId, final boolean finishActivityWhenDone) { + protected void cropImageAndSetWallpaper(Resources res, int resId, + final boolean finishActivityWhenDone, final boolean shouldFadeOutOnFinish) { // crop this image and scale it down to the default wallpaper size for // this device int rotation = BitmapUtils.getRotationFromExif(res, resId); @@ -324,14 +338,17 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb getWindowManager()); RectF crop = Utils.getMaxCropRect( inSize.x, inSize.y, outSize.x, outSize.y, false); - Runnable onEndCrop = new Runnable() { - public void run() { + BitmapCropTask.OnEndCropHandler onEndCrop = new BitmapCropTask.OnEndCropHandler() { + public void run(boolean cropSucceeded) { // Passing 0, 0 will cause launcher to revert to using the // default wallpaper size updateWallpaperDimensions(0, 0); if (finishActivityWhenDone) { setResult(Activity.RESULT_OK); finish(); + if (cropSucceeded && shouldFadeOutOnFinish) { + overridePendingTransition(0, R.anim.fade_out); + } } } }; @@ -342,7 +359,8 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) protected void cropImageAndSetWallpaper(Uri uri, - BitmapCropTask.OnBitmapCroppedHandler onBitmapCroppedHandler, final boolean finishActivityWhenDone) { + BitmapCropTask.OnBitmapCroppedHandler onBitmapCroppedHandler, + final boolean finishActivityWhenDone, final boolean shouldFadeOutOnFinish) { boolean centerCrop = getResources().getBoolean(R.bool.center_crop); // Get the crop boolean ltr = mCropView.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR; @@ -418,13 +436,16 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb final int outWidth = (int) Math.round(cropRect.width() * cropScale); final int outHeight = (int) Math.round(cropRect.height() * cropScale); - Runnable onEndCrop = new Runnable() { - public void run() { + BitmapCropTask.OnEndCropHandler onEndCrop = new BitmapCropTask.OnEndCropHandler() { + public void run(boolean cropSucceeded) { updateWallpaperDimensions(outWidth, outHeight); if (finishActivityWhenDone) { setResult(Activity.RESULT_OK); finish(); } + if (cropSucceeded && shouldFadeOutOnFinish) { + overridePendingTransition(0, R.anim.fade_out); + } } }; BitmapCropTask cropTask = new BitmapCropTask(getContext(), uri, @@ -456,12 +477,13 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb boolean touchEnabled; boolean moveToLeft; Runnable postExecute; - CropViewScaleProvider scaleProvider; + CropViewScaleAndOffsetProvider scaleAndOffsetProvider; TileSource result; } - interface CropViewScaleProvider { - float getScale(TileSource src); + interface CropViewScaleAndOffsetProvider { + float getScale(Point wallpaperSize, RectF crop); + float getParallaxOffset(); } } |