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

Commit fca3d58d authored by chihhangchuang's avatar chihhangchuang
Browse files

New drawable of shaped app icon for using

Because there are two different size ImageViews using the same drawable instance, the bound size was updated to break one of the ImageView displaying.

Video: https://drive.google.com/file/d/1eVzxyn1ojbWanUg47yHXA9AoKZTjXWzp/view?usp=sharing

Test: Manually
Fixes: 160695343
Change-Id: I27f843d21f268e5c82e9682f6af7e0aa907e00eb
parent 031d8dd5
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -272,9 +272,9 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
                mAppName = appName;
            }

            /** Returns the app icon drawable. */
            public Drawable getDrawable() {
                return mIconDrawable;
            /** Returns a copy of app icon drawable. */
            public Drawable getDrawableCopy() {
                return mIconDrawable.getConstantState().newDrawable().mutate();
            }

            /** Returns the app name. */
@@ -340,7 +340,7 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
                shapeDrawable.setIntrinsicHeight((int) PATH_SIZE);
                shapeDrawable.setIntrinsicWidth((int) PATH_SIZE);
                for (ShapeAppIcon icon : mAppIcons) {
                    Drawable drawable = icon.getDrawable();
                    Drawable drawable = icon.mIconDrawable;
                    if (drawable instanceof AdaptiveIconDrawable) {
                        AdaptiveIconDrawable adaptiveIcon = (AdaptiveIconDrawable) drawable;
                        shapeIcons.add(new ShapeAppIcon(
+1 −1
Original line number Diff line number Diff line
@@ -504,7 +504,7 @@ public abstract class ThemeComponentOption implements CustomizationOption<ThemeC
            }
            for (int i = 0; i < mShapeIconIds.length && i < mAppIcons.size(); i++) {
                ImageView iconView = cardBody.findViewById(mShapeIconIds[i]);
                iconView.setBackground(mAppIcons.get(i).getDrawable());
                iconView.setBackground(mAppIcons.get(i).getDrawableCopy());
            }
        }

+1 −1
Original line number Diff line number Diff line
@@ -288,7 +288,7 @@ class ThemeOptionPreviewer implements LifecycleObserver {
            ShapeAppIcon icon = appIcons.get(i);
            // Set app icon.
            ImageView iconView = mContentView.findViewById(mShapeAppIconIds[i]);
            iconView.setBackground(icon.getDrawable());
            iconView.setBackground(icon.getDrawableCopy());
            // Set app name.
            TextView appName = mContentView.findViewById(mShapeIconAppNameIds[i]);
            appName.setText(icon.getAppName());
+7 −6
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@ package com.android.customization.widget;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
@@ -27,8 +26,6 @@ import android.util.DisplayMetrics;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.wallpaper.R;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

@@ -765,6 +762,8 @@ public class DynamicAdaptiveIconDrawable extends Drawable implements Drawable.Ca
    }

    static class LayerState extends ConstantState {
        private final DynamicAdaptiveIconDrawable mOwner;

        private int[] mThemeAttrs;

        final static int N_CHILDREN = 2;
@@ -791,6 +790,7 @@ public class DynamicAdaptiveIconDrawable extends Drawable implements Drawable.Ca

        LayerState(@Nullable LayerState orig, @NonNull DynamicAdaptiveIconDrawable owner,
                @Nullable Resources res) {
            mOwner = owner;
            mChildren = new ChildDrawable[N_CHILDREN];
            if (orig != null) {
                final ChildDrawable[] origChildDrawable = orig.mChildren;
@@ -800,7 +800,7 @@ public class DynamicAdaptiveIconDrawable extends Drawable implements Drawable.Ca

                for (int i = 0; i < N_CHILDREN; i++) {
                    final ChildDrawable or = origChildDrawable[i];
                    mChildren[i] = new ChildDrawable(or, owner, res);
                    mChildren[i] = new ChildDrawable(or, mOwner, res);
                }

                mCheckedOpacity = orig.mCheckedOpacity;
@@ -842,12 +842,13 @@ public class DynamicAdaptiveIconDrawable extends Drawable implements Drawable.Ca

        @Override
        public Drawable newDrawable() {
            return new DynamicAdaptiveIconDrawable(this, null, null);
            return new DynamicAdaptiveIconDrawable(mOwner.getBackground(), mOwner.getForeground(),
                    mOwner.mOriginalMask);
        }

        @Override
        public Drawable newDrawable(@Nullable Resources res) {
            return new DynamicAdaptiveIconDrawable(this, res, null);
            return newDrawable();
        }

        @Override
+1 −1
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ public class ThemeInfoView extends LinearLayout {

            if (previewInfo.shapeAppIcons.get(SHAPE_PREVIEW_INDEX) != null) {
                mAppPreviewImageView.setBackground(
                        previewInfo.shapeAppIcons.get(SHAPE_PREVIEW_INDEX).getDrawable());
                        previewInfo.shapeAppIcons.get(SHAPE_PREVIEW_INDEX).getDrawableCopy());
            }

            if (previewInfo.shapeDrawable != null) {