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

Commit 1c35ac84 authored by chihhangchuang's avatar chihhangchuang
Browse files

Add app name for shape app icons in the themepicker preview

Screenshot:
    Default theme: https://screenshot.googleplex.com/WxJjBCQKkS0.png
    Non-default theme: https://screenshot.googleplex.com/tzk0gwM3GMd.png

Test: Manually
Bug: 146475648
Change-Id: I5b8ee1e0c25a60ae910794c100d0e370c41fc7eb
parent c862c981
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY
import static com.android.customization.model.ResourceConstants.SYSUI_PACKAGE;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources.NotFoundException;
import android.text.TextUtils;
@@ -212,6 +213,11 @@ public class DefaultThemeProvider extends ResourcesApkProvider implements ThemeB
            try {
                builder.addShapePreviewIcon(
                        mContext.getPackageManager().getApplicationIcon(packageName));
                // Add the shape icon app name.
                ApplicationInfo appInfo = mContext.getPackageManager()
                        .getApplicationInfo(packageName, /* flag= */ 0);
                builder.addShapePreviewIconName(
                        String.valueOf(mContext.getPackageManager().getApplicationLabel(appInfo)));
            } catch (NameNotFoundException e) {
                Log.d(TAG, "Couldn't find app " + packageName + ", won't use it for icon shape"
                        + "preview");
+6 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ import static com.android.customization.model.ResourceConstants.SYSUI_PACKAGE;
import android.content.Context;
import android.content.om.OverlayInfo;
import android.content.om.OverlayManager;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
@@ -102,6 +103,11 @@ class OverlayThemeExtractor {
                builder.addShapePreviewIcon(
                        mContext.getPackageManager().getApplicationIcon(
                                packageName));
                // Add the shape icon app name.
                ApplicationInfo appInfo = mContext.getPackageManager()
                        .getApplicationInfo(packageName, /* flag= */ 0);
                builder.addShapePreviewIconName(
                        String.valueOf(mContext.getPackageManager().getApplicationLabel(appInfo)));
            } catch (NameNotFoundException e) {
                Log.d(TAG, "Couldn't find app " + packageName
                        + ", won't use it for icon shape preview");
+11 −2
Original line number Diff line number Diff line
@@ -251,12 +251,13 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
        public final List<Drawable> icons;
        public final Drawable shapeDrawable;
        public final List<Drawable> shapeAppIcons;
        public final List<String> shapeAppIconNames;
        @Dimension public final int bottomSheeetCornerRadius;

        private PreviewInfo(Context context, Typeface bodyFontFamily, Typeface headlineFontFamily,
                int colorAccentLight, int colorAccentDark, List<Drawable> icons,
                Drawable shapeDrawable, @Dimension int cornerRadius,
                List<Drawable> shapeAppIcons) {
                List<Drawable> shapeAppIcons, List<String> shapeAppIconNames) {
            this.bodyFontFamily = bodyFontFamily;
            this.headlineFontFamily = headlineFontFamily;
            this.colorAccentLight = colorAccentLight;
@@ -265,6 +266,7 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
            this.shapeDrawable = shapeDrawable;
            this.bottomSheeetCornerRadius = cornerRadius;
            this.shapeAppIcons = shapeAppIcons;
            this.shapeAppIconNames = shapeAppIconNames;
        }

        /**
@@ -292,6 +294,7 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
        @Dimension private int mCornerRadius;
        protected Map<String, String> mPackages = new HashMap<>();
        private List<Drawable> mAppIcons = new ArrayList<>();
        private List<String> mAppIconNames = new ArrayList<>();

        public ThemeBundle build(Context context) {
            return new ThemeBundle(mTitle, mPackages, mIsDefault, createPreviewInfo(context));
@@ -322,7 +325,8 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
                }
            }
            return new PreviewInfo(context, mBodyFontFamily, mHeadlineFontFamily, mColorAccentLight,
                    mColorAccentDark, mIcons, shapeDrawable, mCornerRadius, shapeIcons);
                    mColorAccentDark, mIcons, shapeDrawable, mCornerRadius, shapeIcons,
                    mAppIconNames);
        }

        public Map<String, String> getPackages() {
@@ -388,6 +392,11 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
            return this;
        }

        public Builder addShapePreviewIconName(String appIconName) {
            mAppIconNames.add(appIconName);
            return this;
        }

        public Builder setBottomSheetCornerRadius(@Dimension int radius) {
            mCornerRadius = radius;
            return this;
+12 −2
Original line number Diff line number Diff line
@@ -150,6 +150,7 @@ class ThemeOptionPreviewer implements LifecycleObserver {
        setHeadlineFont(previewInfo.headlineFontFamily);
        setTopBarIcons(previewInfo.icons);
        setAppIconShape(previewInfo.shapeAppIcons);
        setAppIconName(previewInfo.shapeAppIconNames);
        setColorAndIconsSection(previewInfo.icons, previewInfo.shapeDrawable,
                previewInfo.resolveAccentColor(mContext.getResources()));
        setColorAndIconsBoxRadius(previewInfo.bottomSheeetCornerRadius);
@@ -172,20 +173,22 @@ class ThemeOptionPreviewer implements LifecycleObserver {
    }

    private void setHeadlineFont(Typeface headlineFont) {
        // Update font of status bar clock.
        mClock.setTypeface(headlineFont);

        // Update font of the smart space date.
        TextView date = mContentView.findViewById(R.id.smart_space_date);
        date.setTypeface(headlineFont);
        // TODO(chihhangchuang): Use real date.
        date.setText("Friday, Nov 12");

        // TODO(chihhangchuang): Query the app name for icon shapes, we can get package name from
        // res/values/override.xml to query the app name.
        // Update font of app names.
        for (int id : mShapeIconAppNameIds) {
            TextView appName = mContentView.findViewById(id);
            appName.setTypeface(headlineFont);
        }

        // Update font of color/icons section title.
        TextView colorIconsSectionTitle = mContentView.findViewById(R.id.color_icons_section_title);
        colorIconsSectionTitle.setTypeface(headlineFont);
    }
@@ -211,6 +214,13 @@ class ThemeOptionPreviewer implements LifecycleObserver {
        }
    }

    private void setAppIconName(List<String> appIconNames) {
        for (int i = 0; i < mShapeIconAppNameIds.length && i < appIconNames.size(); i++) {
            TextView appName = mContentView.findViewById(mShapeIconAppNameIds[i]);
            appName.setText(appIconNames.get(i));
        }
    }

    private void setColorAndIconsSection(List<Drawable> icons, Drawable shapeDrawable,
                                         int accentColor) {
        // Set QS icons and background.