OSDN Git Service

Also tint the settings icon in DashboardAdapter.setCategory().
authorDoris Ling <dling@google.com>
Wed, 28 Jun 2017 23:12:38 +0000 (16:12 -0700)
committerDoris Ling <dling@google.com>
Wed, 28 Jun 2017 23:12:38 +0000 (16:12 -0700)
When suggestion loader takes longer time to complete, we will first show
the dashboard with just the categories, and refresh the UI when the
suggestion is ready. However, we only tint the icon when we update both
the categories and suggestions, and hence in some case, some tile
results with icon not being tinted.

Change-Id: I023d50655349731b03c7d7aff153d2cbbd8c63e0
Fix: 37456962
Test: make RunSettingsRoboTests

src/com/android/settings/dashboard/DashboardAdapter.java
tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java

index 1d24c19..958e365 100644 (file)
@@ -182,29 +182,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
 
     public void setCategoriesAndSuggestions(List<DashboardCategory> categories,
             List<Tile> suggestions) {
-        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 (tile.isIconTintable) {
-                        // If this drawable is tintable, tint it to match the color.
-                        tile.icon.setTint(tintColor);
-                    }
-                }
-            }
-
-            for (Tile suggestion : suggestions) {
-                if (suggestion.isIconTintable) {
-                    suggestion.icon.setTint(tintColor);
-                }
-            }
-        }
+        tintIcons(categories, suggestions);
 
         final DashboardData prevData = mDashboardData;
         mDashboardData = new DashboardData.Builder(prevData)
@@ -244,6 +222,8 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
     }
 
     public void setCategory(List<DashboardCategory> category) {
+        tintIcons(category, null);
+
         final DashboardData prevData = mDashboardData;
         Log.d(TAG, "adapter setCategory called");
         mDashboardData = new DashboardData.Builder(prevData)
@@ -669,6 +649,32 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
         holder.title.setText(category.title);
     }
 
+    private void tintIcons(List<DashboardCategory> categories, List<Tile> suggestions) {
+        if (!mDashboardFeatureProvider.shouldTintIcon()) {
+            return;
+        }
+        // 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 (DashboardCategory category : categories) {
+            for (Tile tile : category.tiles) {
+                if (tile.isIconTintable) {
+                    // If this drawable is tintable, tint it to match the color.
+                    tile.icon.setTint(tintColor);
+                }
+            }
+        }
+        if (suggestions != null) {
+            for (Tile suggestion : suggestions) {
+                if (suggestion.isIconTintable) {
+                    suggestion.icon.setTint(tintColor);
+                }
+            }
+        }
+    }
+
     void onSaveInstanceState(Bundle outState) {
         final List<Tile> suggestions = mDashboardData.getSuggestions();
         final List<DashboardCategory> categories = mDashboardData.getCategories();
index 66706cc..3971e53 100644 (file)
@@ -449,6 +449,28 @@ public class DashboardAdapterTest {
     }
 
     @Test
+    public void testSetCategories_iconTinted() {
+        TypedArray mockTypedArray = mock(TypedArray.class);
+        doReturn(mockTypedArray).when(mContext).obtainStyledAttributes(any(int[].class));
+        doReturn(0x89000000).when(mockTypedArray).getColor(anyInt(), anyInt());
+
+        final List<DashboardCategory> categories = new ArrayList<>();
+        final DashboardCategory category = mock(DashboardCategory.class);
+        final List<Tile> tiles = new ArrayList<>();
+        final Icon mockIcon = mock(Icon.class);
+        final Tile tile = new Tile();
+        tile.isIconTintable = true;
+        tile.icon = mockIcon;
+        tiles.add(tile);
+        category.tiles = tiles;
+        categories.add(category);
+
+        mDashboardAdapter.setCategory(categories);
+
+        verify(mockIcon).setTint(eq(0x89000000));
+    }
+
+    @Test
     public void testBindConditionAndSuggestion_shouldSetSuggestionAdapterAndNoCrash() {
         when(mFactory.dashboardFeatureProvider.combineSuggestionAndCondition()).thenReturn(true);
         mDashboardAdapter = new DashboardAdapter(mContext, null, null);
@@ -458,6 +480,7 @@ public class DashboardAdapterTest {
         final List<Tile> tiles = new ArrayList<>();
         tiles.add(mock(Tile.class));
         category.tiles = tiles;
+        categories.add(category);
         mDashboardAdapter.setCategoriesAndSuggestions(categories, suggestions);
 
         final RecyclerView data = mock(RecyclerView.class);