Merge "Changing status bar color extraction to use region decoder" into ub-launcher3-master

This commit is contained in:
Sunny Goyal 2016-11-08 21:53:33 +00:00 committed by Android (Google) Code Review
commit 0d547bfd57
1 changed files with 33 additions and 10 deletions

View File

@ -64,17 +64,10 @@ public class ColorExtractionService extends IntentService {
} else {
// We extract colors for the hotseat and status bar separately,
// since they only consider part of the wallpaper.
extractedColors.updateHotseatPalette(getHotseatPallete());
extractedColors.updateHotseatPalette(getHotseatPalette());
if (FeatureFlags.LIGHT_STATUS_BAR) {
int statusBarHeight = getResources()
.getDimensionPixelSize(R.dimen.status_bar_height);
Bitmap wallpaper = ((BitmapDrawable) wallpaperManager.getDrawable()).getBitmap();
Palette statusBarPalette = Palette.from(wallpaper)
.setRegion(0, 0, wallpaper.getWidth(), statusBarHeight)
.clearFilters()
.generate();
extractedColors.updateStatusBarPalette(statusBarPalette);
extractedColors.updateStatusBarPalette(getStatusBarPalette());
}
}
@ -90,7 +83,7 @@ public class ColorExtractionService extends IntentService {
}
@TargetApi(Build.VERSION_CODES.N)
private Palette getHotseatPallete() {
private Palette getHotseatPalette() {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
if (Utilities.ATLEAST_NOUGAT) {
try (ParcelFileDescriptor fd = wallpaperManager
@ -117,4 +110,34 @@ public class ColorExtractionService extends IntentService {
.clearFilters()
.generate();
}
@TargetApi(Build.VERSION_CODES.N)
private Palette getStatusBarPalette() {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
int statusBarHeight = getResources()
.getDimensionPixelSize(R.dimen.status_bar_height);
if (Utilities.ATLEAST_NOUGAT) {
try (ParcelFileDescriptor fd = wallpaperManager
.getWallpaperFile(WallpaperManager.FLAG_SYSTEM)) {
BitmapRegionDecoder decoder = BitmapRegionDecoder
.newInstance(fd.getFileDescriptor(), false);
Rect decodeRegion = new Rect(0, 0,
decoder.getWidth(), statusBarHeight);
Bitmap bitmap = decoder.decodeRegion(decodeRegion, null);
decoder.recycle();
if (bitmap != null) {
return Palette.from(bitmap).clearFilters().generate();
}
} catch (IOException e) {
Log.e(TAG, "Fetching partial bitmap failed, trying old method", e);
}
}
Bitmap wallpaper = ((BitmapDrawable) wallpaperManager.getDrawable()).getBitmap();
return Palette.from(wallpaper)
.setRegion(0, 0, wallpaper.getWidth(), statusBarHeight)
.clearFilters()
.generate();
}
}