diff --git a/src/com/android/settings/dashboard/DashboardAdapter.java b/src/com/android/settings/dashboard/DashboardAdapter.java index 6a7950415f7..950b664a793 100644 --- a/src/com/android/settings/dashboard/DashboardAdapter.java +++ b/src/com/android/settings/dashboard/DashboardAdapter.java @@ -146,29 +146,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) @@ -196,6 +174,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) @@ -504,6 +484,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 55bc4caf849..e17effe7b5d 100644 --- a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java +++ b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java @@ -365,6 +365,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() { mDashboardAdapter = new DashboardAdapter(mContext, null, null, null, null); @@ -374,6 +396,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);