OSDN Git Service

Add flag to control whether or not we should tint icons
authorFan Zhang <zhfan@google.com>
Fri, 28 Apr 2017 16:11:28 +0000 (09:11 -0700)
committerFan Zhang <zhfan@google.com>
Fri, 28 Apr 2017 16:54:33 +0000 (09:54 -0700)
Fix: 34365726
Test: robotests
Change-Id: Ic08d8590c9867fb0383da03f05237f74644a77ff

res/values/colors.xml
res/values/config.xml
src/com/android/settings/dashboard/DashboardAdapter.java
src/com/android/settings/dashboard/DashboardFeatureProvider.java
src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java

index 4a09594..449928f 100644 (file)
     <!-- Color for preference icons on the Wifi Network Details page -->
     <color name="wifi_details_icon_color">#8A000000</color>
 
+    <!-- The fallback color for tinting icons. Only used when colorControlNormal is unavailable -->
+    <color name="fallback_tintColor">#89000000</color>
 </resources>
index 5aaf426..e16ac43 100755 (executable)
     <!-- Whether or not the camera lift trigger is available in the moves menu. -->
     <bool name="config_cameraLiftTriggerAvailable">false</bool>
 
+    <!-- Whether or not we should tint the icon color on setting pages. -->
+    <bool name="config_tintSettingIcon">true</bool>
+
 </resources>
index d9f96cf..2e7b861 100644 (file)
@@ -137,20 +137,22 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
 
     public void setCategoriesAndSuggestions(List<DashboardCategory> categories,
             List<Tile> 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 (!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 (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);
+                    }
                 }
             }
         }
index 1c55bbb..15608a2 100644 (file)
@@ -56,6 +56,11 @@ public interface DashboardFeatureProvider {
     List<DashboardCategory> getAllCategories();
 
     /**
+     * Whether or not we should tint icons in setting pages.
+     */
+    boolean shouldTintIcon();
+
+    /**
      * Returns an unique string key for the tile.
      */
     String getDashboardKeyForTile(Tile tile);
index 342888e..88cf666 100644 (file)
@@ -98,6 +98,11 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
     }
 
     @Override
+    public boolean shouldTintIcon() {
+        return mContext.getResources().getBoolean(R.bool.config_tintSettingIcon);
+    }
+
+    @Override
     public String getDashboardKeyForTile(Tile tile) {
         if (tile == null || tile.intent == null) {
             return null;
index e7587d5..b78d05c 100644 (file)
@@ -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();
+    }
 }