From 0a257ee1ba5de4edc7d161b9062e7fd9fb9a7389 Mon Sep 17 00:00:00 2001 From: Fan Zhang Date: Fri, 28 Apr 2017 09:11:28 -0700 Subject: [PATCH] Add flag to control whether or not we should tint icons Fix: 34365726 Test: robotests Change-Id: Ic08d8590c9867fb0383da03f05237f74644a77ff --- res/values/colors.xml | 2 ++ res/values/config.xml | 3 ++ .../settings/dashboard/DashboardAdapter.java | 28 ++++++++++--------- .../dashboard/DashboardFeatureProvider.java | 5 ++++ .../DashboardFeatureProviderImpl.java | 5 ++++ .../DashboardFeatureProviderImplTest.java | 13 +++++++++ 6 files changed, 43 insertions(+), 13 deletions(-) diff --git a/res/values/colors.xml b/res/values/colors.xml index 4a095949905..449928fe57a 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -113,4 +113,6 @@ #8A000000 + + #89000000 diff --git a/res/values/config.xml b/res/values/config.xml index 5aaf426e4ee..e16ac43ef26 100755 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -102,4 +102,7 @@ false + + true + diff --git a/src/com/android/settings/dashboard/DashboardAdapter.java b/src/com/android/settings/dashboard/DashboardAdapter.java index d9f96cf7a92..2e7b8618def 100644 --- a/src/com/android/settings/dashboard/DashboardAdapter.java +++ b/src/com/android/settings/dashboard/DashboardAdapter.java @@ -137,20 +137,22 @@ public class DashboardAdapter extends RecyclerView.Adapter categories, List suggestions) { - // TODO: Better place for tinting? - final TypedArray a = mContext.obtainStyledAttributes(new int[]{ - android.R.attr.colorControlNormal}); - int tintColor = a.getColor(0, mContext.getColor(android.R.color.white)); - a.recycle(); - for (int i = 0; i < categories.size(); i++) { - for (int j = 0; j < categories.get(i).tiles.size(); j++) { - final Tile tile = categories.get(i).tiles.get(j); + if (mDashboardFeatureProvider.shouldTintIcon()) { + // TODO: Better place for tinting? + final TypedArray a = mContext.obtainStyledAttributes(new int[]{ + android.R.attr.colorControlNormal}); + final int tintColor = a.getColor(0, mContext.getColor(R.color.fallback_tintColor)); + a.recycle(); + for (int i = 0; i < categories.size(); i++) { + for (int j = 0; j < categories.get(i).tiles.size(); j++) { + final Tile tile = categories.get(i).tiles.get(j); - if (!mContext.getPackageName().equals( - tile.intent.getComponent().getPackageName())) { - // If this drawable is coming from outside Settings, tint it to match the - // color. - tile.icon.setTint(tintColor); + if (!mContext.getPackageName().equals( + tile.intent.getComponent().getPackageName())) { + // If this drawable is coming from outside Settings, tint it to match the + // color. + tile.icon.setTint(tintColor); + } } } } diff --git a/src/com/android/settings/dashboard/DashboardFeatureProvider.java b/src/com/android/settings/dashboard/DashboardFeatureProvider.java index 1c55bbbe824..15608a27bee 100644 --- a/src/com/android/settings/dashboard/DashboardFeatureProvider.java +++ b/src/com/android/settings/dashboard/DashboardFeatureProvider.java @@ -55,6 +55,11 @@ public interface DashboardFeatureProvider { */ List getAllCategories(); + /** + * Whether or not we should tint icons in setting pages. + */ + boolean shouldTintIcon(); + /** * Returns an unique string key for the tile. */ diff --git a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java index 342888e24bf..88cf6664297 100644 --- a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java +++ b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java @@ -97,6 +97,11 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider { return mCategoryManager.getCategories(mContext); } + @Override + public boolean shouldTintIcon() { + return mContext.getResources().getBoolean(R.bool.config_tintSettingIcon); + } + @Override public String getDashboardKeyForTile(Tile tile) { if (tile == null || tile.intent == null) { diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java index e7587d58ce7..b78d05cd5d3 100644 --- a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java +++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java @@ -20,6 +20,7 @@ import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.drawable.Icon; import android.os.Bundle; @@ -364,4 +365,16 @@ public class DashboardFeatureProviderImplTest { public void testGetExtraIntentAction_shouldReturnNull() { assertThat(mImpl.getExtraIntentAction()).isNull(); } + + @Test + public void testShouldTintIcon_shouldReturnValueFromResource() { + final Resources res = mActivity.getApplicationContext().getResources(); + when(res.getBoolean(R.bool.config_tintSettingIcon)) + .thenReturn(false); + assertThat(mImpl.shouldTintIcon()).isFalse(); + + when(res.getBoolean(R.bool.config_tintSettingIcon)) + .thenReturn(true); + assertThat(mImpl.shouldTintIcon()).isTrue(); + } }