diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2015-02-26 18:22:34 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-02-26 18:22:34 +0000 |
commit | 748909e5329ea79e6f65fc4b64f2d43e8fad15d5 (patch) | |
tree | 32efe4ac95ff3aeca1f712a80127256fda8e34cd /WallpaperPicker | |
parent | 8ed75e5c1606d4bd1218e2e3975527e1719d9be6 (diff) | |
parent | 9f9d0a59c4dab713b6cd8f5a29ea20f646bc5ac0 (diff) | |
download | android_packages_apps_Trebuchet-748909e5329ea79e6f65fc4b64f2d43e8fad15d5.tar.gz android_packages_apps_Trebuchet-748909e5329ea79e6f65fc4b64f2d43e8fad15d5.tar.bz2 android_packages_apps_Trebuchet-748909e5329ea79e6f65fc4b64f2d43e8fad15d5.zip |
Merge "Picking a bitmap to reuse where least pixels are wasted" into ub-launcher3-burnaby
Diffstat (limited to 'WallpaperPicker')
-rw-r--r-- | WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java index 0ddb79e4f..a3a3c537b 100644 --- a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java +++ b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java @@ -50,7 +50,6 @@ import com.android.photos.BitmapRegionTileSource.BitmapSource.InBitmapProvider; import com.android.photos.views.TiledImageRenderer.TileSource; import java.util.Collections; -import java.util.Iterator; import java.util.Set; import java.util.WeakHashMap; @@ -170,17 +169,23 @@ public class WallpaperCropActivity extends Activity implements Handler.Callback @Override public Bitmap forPixelCount(int count) { + Bitmap bitmapToReuse = null; + // Find the smallest bitmap that satisfies the pixel count limit synchronized (mReusableBitmaps) { - Iterator<Bitmap> itr = mReusableBitmaps.iterator(); - while (itr.hasNext()) { - Bitmap b = itr.next(); - if (b.getWidth() * b.getHeight() >= count) { - itr.remove(); - return b; + int currentBitmapSize = Integer.MAX_VALUE; + for (Bitmap b : mReusableBitmaps) { + int bitmapSize = b.getWidth() * b.getHeight(); + if ((bitmapSize >= count) && (bitmapSize < currentBitmapSize)) { + bitmapToReuse = b; + currentBitmapSize = bitmapSize; } } + + if (bitmapToReuse != null) { + mReusableBitmaps.remove(bitmapToReuse); + } } - return null; + return bitmapToReuse; } }); } catch (SecurityException securityException) { |