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

Commit eb2196f9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[Expressive design] Update homepage injection icons" into main

parents c7949125 b84b3005
Loading
Loading
Loading
Loading
+43 −6
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.graphics.drawable.LayerDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.UserHandle;
@@ -77,6 +78,7 @@ import com.android.settingslib.drawer.Tile;
import com.android.settingslib.drawer.TileUtils;
import com.android.settingslib.utils.ThreadUtils;
import com.android.settingslib.widget.AdaptiveIcon;
import com.android.settingslib.widget.SettingsThemeHelper;

import com.google.common.collect.Iterables;

@@ -92,6 +94,7 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
    private static final String TAG = "DashboardFeatureImpl";
    private static final String DASHBOARD_TILE_PREF_KEY_PREFIX = "dashboard_tile_pref_";
    private static final String META_DATA_KEY_INTENT_ACTION = "com.android.settings.intent.action";
    private static final String TOP_LEVEL_ACCOUNT_CATEGORY = "top_level_account_category";

    protected final Context mContext;

@@ -454,14 +457,20 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
            preference.setIcon(null);
            return;
        }
        // Tint homepage icons
        // Handle homepage icons
        if (TextUtils.equals(tile.getCategory(), CategoryKey.CATEGORY_HOMEPAGE)) {
            if (Flags.homepageRevamp()) {
                if (SettingsThemeHelper.isExpressiveTheme(mContext)) {
                    preference.setIcon(getExpressiveHomepageIcon(tile, iconDrawable, iconPackage));
                    return;
                }
                // Skip tinting and Adaptive Icon transformation for homepage account type raw icons
            if (TextUtils.equals(tile.getGroupKey(), "top_level_account_category")
                if (TextUtils.equals(tile.getGroupKey(), TOP_LEVEL_ACCOUNT_CATEGORY)
                        && iconPackage == null) {
                    preference.setIcon(iconDrawable);
                    return;
                }
            }
            iconDrawable.setTint(Utils.getHomepageIconColor(preference.getContext()));
        }

@@ -473,6 +482,34 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
        preference.setIcon(iconDrawable);
    }

    private Drawable getExpressiveHomepageIcon(Tile tile, Drawable iconDrawable,
            @Nullable String iconPackage) {
        if (TextUtils.equals(tile.getGroupKey(), TOP_LEVEL_ACCOUNT_CATEGORY)
                && iconPackage == null) {
            // Normalize size for homepage account type raw icons
            LayerDrawable drawable = new LayerDrawable(new Drawable[] {iconDrawable});
            int size = mContext.getResources().getDimensionPixelSize(
                    R.dimen.dashboard_tile_image_size);
            drawable.setLayerSize(0, size, size);
            return drawable;
        } else if (TextUtils.equals(tile.getPackageName(),
                mPackageManager.getWellbeingPackageName())) {
            return getRoundedIcon(iconDrawable,
                    R.color.homepage_wellbeing_foreground, R.color.homepage_wellbeing_background);
        }
        // For future injections, please add the package name and color resources here.

        iconDrawable.setTint(Utils.getHomepageIconColor(mContext));
        return iconDrawable;
    }

    private Drawable getRoundedIcon(Drawable iconDrawable, int fgColorId, int bgColorId) {
        iconDrawable.setTint(mContext.getColor(fgColorId));
        AdaptiveIcon roundedIcon = new AdaptiveIcon(mContext, iconDrawable);
        roundedIcon.setBackgroundColor(mContext.getColor(bgColorId));
        return roundedIcon;
    }

    private void launchPendingIntentOrSelectProfile(FragmentActivity activity, Tile tile,
            int sourceMetricCategory) {
        ProfileSelectDialog.updatePendingIntentsIfNeeded(mContext, tile);