From 067122a8e4eaf7942835b07c2838b356142bb886 Mon Sep 17 00:00:00 2001 From: Doris Ling Date: Wed, 28 Jun 2017 16:12:38 -0700 Subject: [PATCH] Also tint the settings icon in DashboardAdapter.setCategory(). 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 --- .../settings/dashboard/DashboardAdapter.java | 52 +++++++++++-------- .../dashboard/DashboardAdapterTest.java | 23 ++++++++ 2 files changed, 52 insertions(+), 23 deletions(-) diff --git a/src/com/android/settings/dashboard/DashboardAdapter.java b/src/com/android/settings/dashboard/DashboardAdapter.java index 1d24c198129..958e3656f69 100644 --- a/src/com/android/settings/dashboard/DashboardAdapter.java +++ b/src/com/android/settings/dashboard/DashboardAdapter.java @@ -182,29 +182,7 @@ public class DashboardAdapter extends RecyclerView.Adapter categories, List 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 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 categories, List 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 suggestions = mDashboardData.getSuggestions(); final List categories = mDashboardData.getCategories(); diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java index 66706cc9da3..3971e53e660 100644 --- a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java +++ b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java @@ -448,6 +448,28 @@ public class DashboardAdapterTest { verify(mockIcon).setTint(eq(0x89000000)); } + @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 categories = new ArrayList<>(); + final DashboardCategory category = mock(DashboardCategory.class); + final List 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); @@ -458,6 +480,7 @@ public class DashboardAdapterTest { final List tiles = new ArrayList<>(); tiles.add(mock(Tile.class)); category.tiles = tiles; + categories.add(category); mDashboardAdapter.setCategoriesAndSuggestions(categories, suggestions); final RecyclerView data = mock(RecyclerView.class);