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

Commit 7a45d741 authored by Kunhung Li's avatar Kunhung Li
Browse files

[1/n] Color picking show up performance

Remove unused color code to reduce the time on getting color resources
for basic colors.

Bug: 229595282
Test: manual
Change-Id: I334f45b379c1a959868ac628ac7881c88049796e
parent a2b70df7
Loading
Loading
Loading
Loading
+5 −45
Original line number Diff line number Diff line
@@ -15,18 +15,11 @@
 */
package com.android.customization.model.color;

import static com.android.customization.model.ResourceConstants.PATH_SIZE;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.PathShape;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

@@ -34,16 +27,13 @@ import androidx.annotation.ColorInt;
import androidx.annotation.Dimension;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.core.graphics.PathParser;

import com.android.customization.model.ResourceConstants;
import com.android.systemui.monet.Style;
import com.android.wallpaper.R;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
@@ -103,8 +93,6 @@ public class ColorBundle extends ColorOption {
        // Monet system palette and accent colors
        @ColorInt public final int primaryColorLight;
        @ColorInt public final int primaryColorDark;
        public final List<Drawable> icons;
        public final Drawable shapeDrawable;
        @Dimension
        public final int bottomSheetCornerRadius;

@@ -115,14 +103,11 @@ public class ColorBundle extends ColorOption {

        private PreviewInfo(
                int secondaryColorLight, int secondaryColorDark, int colorSystemPaletteLight,
                int primaryColorDark, List<Drawable> icons, Drawable shapeDrawable,
                @Dimension int cornerRadius) {
                int primaryColorDark, @Dimension int cornerRadius) {
            this.secondaryColorLight = secondaryColorLight;
            this.secondaryColorDark = secondaryColorDark;
            this.primaryColorLight = colorSystemPaletteLight;
            this.primaryColorDark = primaryColorDark;
            this.icons = icons;
            this.shapeDrawable = shapeDrawable;
            this.bottomSheetCornerRadius = cornerRadius;
        }

@@ -188,7 +173,6 @@ public class ColorBundle extends ColorOption {
        // System and Monet colors
        @ColorInt private int mPrimaryColorLight = Color.TRANSPARENT;
        @ColorInt private int mPrimaryColorDark = Color.TRANSPARENT;
        private List<Drawable> mIcons = new ArrayList<>();
        private boolean mIsDefault;
        private Style mStyle = Style.TONAL_SPOT;
        private int mIndex;
@@ -213,26 +197,12 @@ public class ColorBundle extends ColorOption {
         * @return the {@link PreviewInfo} object
         */
        public PreviewInfo createPreviewInfo(@NonNull Context context) {
            ShapeDrawable shapeDrawable = null;
            Resources system = context.getResources().getSystem();
            String pathString = system.getString(
                    system.getIdentifier(ResourceConstants.CONFIG_ICON_MASK,
                            "string", ResourceConstants.ANDROID_PACKAGE));
            Path path = null;
            if (!TextUtils.isEmpty(pathString)) {
                path = PathParser.createPathFromPathData(pathString);
            }
            if (path != null) {
                PathShape shape = new PathShape(path, PATH_SIZE, PATH_SIZE);
                shapeDrawable = new ShapeDrawable(shape);
                shapeDrawable.setIntrinsicHeight((int) PATH_SIZE);
                shapeDrawable.setIntrinsicWidth((int) PATH_SIZE);
            }
            return new PreviewInfo(mSecondaryColorLight,
                    mSecondaryColorDark, mPrimaryColorLight, mPrimaryColorDark, mIcons,
                    shapeDrawable, system.getDimensionPixelOffset(
                    system.getIdentifier(ResourceConstants.CONFIG_CORNERRADIUS,
                            "dimen", ResourceConstants.ANDROID_PACKAGE)));
                    mSecondaryColorDark, mPrimaryColorLight, mPrimaryColorDark,
                    system.getDimensionPixelOffset(
                            system.getIdentifier(ResourceConstants.CONFIG_CORNERRADIUS, "dimen",
                                    ResourceConstants.ANDROID_PACKAGE)));
        }

        public Map<String, String> getPackages() {
@@ -297,16 +267,6 @@ public class ColorBundle extends ColorOption {
            return this;
        }

        /**
         * Sets icon for bundle
         * @param icon icon in {@link Drawable}
         * @return this of {@link Builder}
         */
        public Builder addIcon(Drawable icon) {
            mIcons.add(icon);
            return this;
        }

        /**
         * Sets overlay package for bundle
         * @param category the category of bundle
+0 −28
Original line number Diff line number Diff line
@@ -15,18 +15,12 @@
 */
package com.android.customization.model.color;

import static com.android.customization.model.ResourceConstants.ANDROID_PACKAGE;
import static com.android.customization.model.ResourceConstants.ICONS_FOR_PREVIEW;
import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_COLOR;
import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_SYSTEM_PALETTE;
import static com.android.customization.model.color.ColorUtils.toColorString;

import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.Log;

@@ -80,26 +74,4 @@ class ColorBundlePreviewExtractor {
        }
        builder.setStyle(s);
    }

    void addAndroidIconOverlay(ColorBundle.Builder builder) throws NameNotFoundException {
        addSystemDefaultIcons(builder, ICONS_FOR_PREVIEW);
    }

    void addSystemDefaultIcons(ColorBundle.Builder builder, String... previewIcons) {
        try {
            for (String iconName : previewIcons) {
                builder.addIcon(loadIconPreviewDrawable(iconName));
            }
        } catch (NameNotFoundException | NotFoundException e) {
            Log.w(TAG, "Didn't find android package icons, will skip preview", e);
        }
    }

    Drawable loadIconPreviewDrawable(String drawableName)
            throws NameNotFoundException, NotFoundException {
        Resources packageRes = mPackageManager.getResourcesForApplication(ANDROID_PACKAGE);
        Resources res = Resources.getSystem();
        return res.getDrawable(packageRes.getIdentifier(drawableName, "drawable",
                        ANDROID_PACKAGE), null);
    }
}
+0 −1
Original line number Diff line number Diff line
@@ -271,7 +271,6 @@ class ColorProvider(context: Context, stubPackageName: String) :
                builder.setColorPrimaryLight(lightColors[0]).setColorSecondaryLight(lightColors[1])
            }

            extractor.addAndroidIconOverlay(builder)
            bundles.add(builder.build(mContext))
            index++
        }