Support icon color scheme for homepage injections

Bug: 402607181
Test: visual, atest SettingsRoboTests:DashboardFeatureProviderImplTest
Flag: com.android.settingslib.widget.theme.flags.is_expressive_design_enabled
Change-Id: Iac6434864c38b08e2a35cc58f910a3cf1a6dc113
This commit is contained in:
Jason Chiu
2025-03-12 14:54:44 +08:00
parent de3ec7e343
commit 3e064619ec
2 changed files with 166 additions and 2 deletions

View File

@@ -80,6 +80,7 @@ import com.android.settingslib.utils.ThreadUtils;
import com.android.settingslib.widget.AdaptiveIcon;
import com.android.settingslib.widget.SettingsThemeHelper;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import java.util.ArrayList;
@@ -96,6 +97,20 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
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";
private static final Map<String, Pair<Integer, Integer>> COLOR_SCHEMES = ImmutableMap.of(
"blue_variant", new Pair<>(
R.color.homepage_blue_variant_fg, R.color.homepage_blue_variant_bg),
"blue", new Pair<>(R.color.homepage_blue_fg, R.color.homepage_blue_bg),
"pink", new Pair<>(R.color.homepage_pink_fg, R.color.homepage_pink_bg),
"orange", new Pair<>(R.color.homepage_orange_fg, R.color.homepage_orange_bg),
"yellow", new Pair<>(R.color.homepage_yellow_fg, R.color.homepage_yellow_bg),
"green", new Pair<>(R.color.homepage_green_fg, R.color.homepage_green_bg),
"grey", new Pair<>(R.color.homepage_grey_fg, R.color.homepage_grey_bg),
"cyan", new Pair<>(R.color.homepage_cyan_fg, R.color.homepage_cyan_bg),
"red", new Pair<>(R.color.homepage_red_fg, R.color.homepage_red_bg),
"purple", new Pair<>(R.color.homepage_purple_fg, R.color.homepage_purple_bg)
);
protected final Context mContext;
private final MetricsFeatureProvider mMetricsFeatureProvider;
@@ -486,7 +501,7 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
@Nullable String iconPackage) {
if (TextUtils.equals(tile.getGroupKey(), TOP_LEVEL_ACCOUNT_CATEGORY)
&& iconPackage == null) {
// Normalize size for homepage account type raw icons
// Normalize size for homepage account type raw image
LayerDrawable drawable = new LayerDrawable(new Drawable[] {iconDrawable});
int size = mContext.getResources().getDimensionPixelSize(
R.dimen.dashboard_tile_image_size);
@@ -497,7 +512,11 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
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.
Pair<Integer, Integer> colors = getSchemedColors(tile);
if (colors != null) {
return getRoundedIcon(iconDrawable, colors.first, colors.second);
}
iconDrawable.setTint(Utils.getHomepageIconColor(mContext));
return iconDrawable;
@@ -510,6 +529,21 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
return roundedIcon;
}
@VisibleForTesting
@Nullable
Pair<Integer, Integer> getSchemedColors(Tile tile) {
String scheme = tile.getIconColorScheme(mContext);
if (TextUtils.isEmpty(scheme)) {
return null;
}
Pair<Integer, Integer> colors = COLOR_SCHEMES.get(scheme);
if (colors == null) {
Log.w(TAG, "Invalid color scheme: " + scheme);
}
return colors;
}
private void launchPendingIntentOrSelectProfile(FragmentActivity activity, Tile tile,
int sourceMetricCategory) {
ProfileSelectDialog.updatePendingIntentsIfNeeded(mContext, tile);