Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a9f1e720 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Changing status bar color extraction to use region decoder

Change-Id: Ie9913a9cb28948128e6624dc3a335c790fa5a11a
parent 99014e5c
Loading
Loading
Loading
Loading
+33 −10
Original line number Diff line number Diff line
@@ -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();
    }
}