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

Commit f9f63355 authored by Daniel Sandler's avatar Daniel Sandler
Browse files

Put DessertCase on a diet.

- store desserts as ALPHA_8, saving 75% of bitmap memory
- run DessertCase in its own process, avoiding bloating
  systemui every time the daydream or platlogo activity run
- lock orientation in DessertCase to stop thrashing around
  when the device is rotated

Bug: 10918599
Change-Id: Ia2fb0696b903ae355c75b53d3a0c45b70784d00c
parent dd73ee4d
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -200,7 +200,8 @@
            android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
            android:hardwareAccelerated="true"
            android:launchMode="singleInstance"
            android:configChanges="orientation|screenSize"
            android:screenOrientation="locked"
            android:process=":sweetsweetdesserts"
            android:excludeFromRecents="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
@@ -215,6 +216,7 @@
            android:exported="true"
            android:label="@string/dessert_case"
            android:enabled="false"
            android:process=":sweetsweetdesserts"
            >
            <intent-filter>
                <action android:name="android.service.dreams.DreamService" />
+21 −6
Original line number Diff line number Diff line
@@ -96,6 +96,13 @@ public class DessertCaseView extends FrameLayout {
            1f,  0f,  0f,  0f, 0f
    };

    private static final float[] ALPHA_MASK = {
            0f,  0f,  0f,  0f, 255f,
            0f,  0f,  0f,  0f, 255f,
            0f,  0f,  0f,  0f, 255f,
            0f,  0f,  0f,  1f, 0f
    };

    private static final float[] WHITE_MASK = {
            0f,  0f,  0f,  0f, 255f,
            0f,  0f,  0f,  0f, 255f,
@@ -162,8 +169,8 @@ public class DessertCaseView extends FrameLayout {
        for (int[] list : new int[][] { PASTRIES, RARE_PASTRIES, XRARE_PASTRIES, XXRARE_PASTRIES }) {
            for (int resid : list) {
                final BitmapDrawable d = new BitmapDrawable(res,
                        BitmapFactory.decodeResource(res, resid, opts));
                d.setColorFilter(new ColorMatrixColorFilter(MASK));
                        convertToAlphaMask(BitmapFactory.decodeResource(res, resid, opts)));
                d.setColorFilter(new ColorMatrixColorFilter(ALPHA_MASK));
                d.setBounds(0, 0, mCellSize, mCellSize);
                mDrawables.append(resid, d);
            }
@@ -171,6 +178,15 @@ public class DessertCaseView extends FrameLayout {
        if (DEBUG) setWillNotDraw(false);
    }

    private static Bitmap convertToAlphaMask(Bitmap b) {
        Bitmap a = Bitmap.createBitmap(b.getWidth(), b.getHeight(), Bitmap.Config.ALPHA_8);
        Canvas c = new Canvas(a);
        Paint pt = new Paint();
        pt.setColorFilter(new ColorMatrixColorFilter(MASK));
        c.drawBitmap(b, 0.0f, 0.0f, pt);
        return a;
    }

    public void start() {
        if (!mStarted) {
            mStarted = true;
@@ -273,9 +289,9 @@ public class DessertCaseView extends FrameLayout {

            final float which = frand();
            final Drawable d;
            if (which < 0.001f) {
            if (which < 0.0005f) {
                d = mDrawables.get(pick(XXRARE_PASTRIES));
            } else if (which < 0.01f) {
            } else if (which < 0.005f) {
                d = mDrawables.get(pick(XRARE_PASTRIES));
            } else if (which < 0.5f) {
                d = mDrawables.get(pick(RARE_PASTRIES));
@@ -288,8 +304,7 @@ public class DessertCaseView extends FrameLayout {
                v.getOverlay().add(d);
            }

            final Paint paint = new Paint();
            v.setLayerType(View.LAYER_TYPE_HARDWARE, paint);
            v.setLayerType(View.LAYER_TYPE_HARDWARE, null);

            lp.width = lp.height = mCellSize;
            addView(v, lp);