diff options
author | Tony Wickham <twickham@google.com> | 2015-08-28 12:26:08 -0700 |
---|---|---|
committer | Tony Wickham <twickham@google.com> | 2015-08-28 23:06:01 +0000 |
commit | f970ee5cdc0185fa5003ded178ef680813d8a259 (patch) | |
tree | a2d1de896ac6300309c648f784b39806448dc2a8 /WallpaperPicker/src | |
parent | fafd4c276e1a1db8449d1feb46800351adbc3ad6 (diff) | |
download | android_packages_apps_Trebuchet-f970ee5cdc0185fa5003ded178ef680813d8a259.tar.gz android_packages_apps_Trebuchet-f970ee5cdc0185fa5003ded178ef680813d8a259.tar.bz2 android_packages_apps_Trebuchet-f970ee5cdc0185fa5003ded178ef680813d8a259.zip |
Reuse existing temporary wallpaper tiles when selecting same photo.
Previously, if you selected a photo to set as the wallpaper multiple times, it
kept adding temporary wallpaper tiles that were all identical. Now it reuses the
same tile, updating the thumbnail and wallpaper if the Uri happens to point to a
new image (such as if a photo is renamed).
Change-Id: Ib05c9db4e1fd17226b503174f25add3368158b11
Diffstat (limited to 'WallpaperPicker/src')
-rw-r--r-- | WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java b/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java index e05115a10..63986b4b1 100644 --- a/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java +++ b/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java @@ -841,12 +841,31 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { } private void addTemporaryWallpaperTile(final Uri uri, boolean fromRestore) { - mTempWallpaperTiles.add(uri); - // Add a tile for the image picked from Gallery - final FrameLayout pickedImageThumbnail = (FrameLayout) getLayoutInflater(). - inflate(R.layout.wallpaper_picker_item, mWallpapersView, false); - pickedImageThumbnail.setVisibility(View.GONE); - mWallpapersView.addView(pickedImageThumbnail, 0); + // Add a tile for the image picked from Gallery, reusing the existing tile if there is one. + FrameLayout existingImageThumbnail = null; + int indexOfExistingTile = 0; + for (; indexOfExistingTile < mWallpapersView.getChildCount(); indexOfExistingTile++) { + FrameLayout thumbnail = (FrameLayout) mWallpapersView.getChildAt(indexOfExistingTile); + Object tag = thumbNail.getTag(); + if (tag instanceof UriWallpaperInfo && ((UriWallpaperInfo) tag).mUri.equals(uri)) { + existingImageThumbnail = thumbNail; + break; + } + } + final FrameLayout pickedImageThumbnail; + if (existingImageThumbnail != null) { + pickedImageThumbnail = existingImageThumbnail; + // Always move the existing wallpaper to the front so user can see it without scrolling. + mWallpapersView.removeViewAt(indexOfExistingTile); + mWallpapersView.addView(existingImageThumbnail, 0); + } else { + // This is the first time this temporary wallpaper has been added + pickedImageThumbnail = (FrameLayout) getLayoutInflater() + .inflate(R.layout.wallpaper_picker_item, mWallpapersView, false); + pickedImageThumbnail.setVisibility(View.GONE); + mWallpapersView.addView(pickedImageThumbnail, 0); + mTempWallpaperTiles.add(uri); + } // Load the thumbnail final ImageView image = (ImageView) pickedImageThumbnail.findViewById(R.id.wallpaper_image); @@ -856,7 +875,8 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { protected Bitmap doInBackground(Void...args) { try { int rotation = BitmapUtils.getRotationFromExif(context, uri); - return createThumbnail(defaultSize, context, uri, null, null, 0, rotation, false); + return createThumbnail(defaultSize, context, uri, null, null, 0, rotation, + false); } catch (SecurityException securityException) { if (isActivityDestroyed()) { // Temporarily granted permissions are revoked when the activity |