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:
@@ -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);
|
||||
|
@@ -22,6 +22,7 @@ import static com.android.settingslib.drawer.SwitchesProvider.EXTRA_SWITCH_SET_C
|
||||
import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_ORDER;
|
||||
import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_PROFILE;
|
||||
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON;
|
||||
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON_COLOR_SCHEME;
|
||||
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON_URI;
|
||||
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_KEYHINT;
|
||||
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_SUMMARY;
|
||||
@@ -822,6 +823,135 @@ public class DashboardFeatureProviderImplTest {
|
||||
verify(mActivity, never()).getSupportFragmentManager();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSchemedColors_schemeNotSpecified_returnNull() {
|
||||
Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
|
||||
Pair<Integer, Integer> colors = mImpl.getSchemedColors(tile);
|
||||
|
||||
assertThat(colors).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSchemedColors_undefinedScheme_returnNull() {
|
||||
Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_COLOR_SCHEME, "abc");
|
||||
|
||||
Pair<Integer, Integer> colors = mImpl.getSchemedColors(tile);
|
||||
|
||||
assertThat(colors).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSchemedColors_blueVariantScheme_returnCorrectColors() {
|
||||
Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_COLOR_SCHEME, "blue_variant");
|
||||
|
||||
Pair<Integer, Integer> colors = mImpl.getSchemedColors(tile);
|
||||
|
||||
assertThat(colors.first).isEqualTo(R.color.homepage_blue_variant_fg);
|
||||
assertThat(colors.second).isEqualTo(R.color.homepage_blue_variant_bg);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSchemedColors_blueScheme_returnCorrectColors() {
|
||||
Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_COLOR_SCHEME, "blue");
|
||||
|
||||
Pair<Integer, Integer> colors = mImpl.getSchemedColors(tile);
|
||||
|
||||
assertThat(colors.first).isEqualTo(R.color.homepage_blue_fg);
|
||||
assertThat(colors.second).isEqualTo(R.color.homepage_blue_bg);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSchemedColors_pinkScheme_returnCorrectColors() {
|
||||
Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_COLOR_SCHEME, "pink");
|
||||
|
||||
Pair<Integer, Integer> colors = mImpl.getSchemedColors(tile);
|
||||
|
||||
assertThat(colors.first).isEqualTo(R.color.homepage_pink_fg);
|
||||
assertThat(colors.second).isEqualTo(R.color.homepage_pink_bg);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSchemedColors_orangeScheme_returnCorrectColors() {
|
||||
Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_COLOR_SCHEME, "orange");
|
||||
|
||||
Pair<Integer, Integer> colors = mImpl.getSchemedColors(tile);
|
||||
|
||||
assertThat(colors.first).isEqualTo(R.color.homepage_orange_fg);
|
||||
assertThat(colors.second).isEqualTo(R.color.homepage_orange_bg);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSchemedColors_yellowScheme_returnCorrectColors() {
|
||||
Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_COLOR_SCHEME, "yellow");
|
||||
|
||||
Pair<Integer, Integer> colors = mImpl.getSchemedColors(tile);
|
||||
|
||||
assertThat(colors.first).isEqualTo(R.color.homepage_yellow_fg);
|
||||
assertThat(colors.second).isEqualTo(R.color.homepage_yellow_bg);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSchemedColors_greenScheme_returnCorrectColors() {
|
||||
Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_COLOR_SCHEME, "green");
|
||||
|
||||
Pair<Integer, Integer> colors = mImpl.getSchemedColors(tile);
|
||||
|
||||
assertThat(colors.first).isEqualTo(R.color.homepage_green_fg);
|
||||
assertThat(colors.second).isEqualTo(R.color.homepage_green_bg);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSchemedColors_greyScheme_returnCorrectColors() {
|
||||
Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_COLOR_SCHEME, "grey");
|
||||
|
||||
Pair<Integer, Integer> colors = mImpl.getSchemedColors(tile);
|
||||
|
||||
assertThat(colors.first).isEqualTo(R.color.homepage_grey_fg);
|
||||
assertThat(colors.second).isEqualTo(R.color.homepage_grey_bg);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSchemedColors_cyanScheme_returnCorrectColors() {
|
||||
Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_COLOR_SCHEME, "cyan");
|
||||
|
||||
Pair<Integer, Integer> colors = mImpl.getSchemedColors(tile);
|
||||
|
||||
assertThat(colors.first).isEqualTo(R.color.homepage_cyan_fg);
|
||||
assertThat(colors.second).isEqualTo(R.color.homepage_cyan_bg);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSchemedColors_redScheme_returnCorrectColors() {
|
||||
Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_COLOR_SCHEME, "red");
|
||||
|
||||
Pair<Integer, Integer> colors = mImpl.getSchemedColors(tile);
|
||||
|
||||
assertThat(colors.first).isEqualTo(R.color.homepage_red_fg);
|
||||
assertThat(colors.second).isEqualTo(R.color.homepage_red_bg);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSchemedColors_purpleScheme_returnCorrectColors() {
|
||||
Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_COLOR_SCHEME, "purple");
|
||||
|
||||
Pair<Integer, Integer> colors = mImpl.getSchemedColors(tile);
|
||||
|
||||
assertThat(colors.first).isEqualTo(R.color.homepage_purple_fg);
|
||||
assertThat(colors.second).isEqualTo(R.color.homepage_purple_bg);
|
||||
}
|
||||
|
||||
private static class TestFragment extends DashboardFragment {
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user