From 8f5773b8340efee5fdadd020ae01c54f04593a80 Mon Sep 17 00:00:00 2001 From: Doris Ling Date: Wed, 7 Mar 2018 15:04:11 -0800 Subject: [PATCH] Fix layout height for suggestion tile. - set minHeight instead of using a fix height, so that when the font/display size is set to larger, the height will expand accordingly to fit all elements in the suggestion card. - revert the change that tint all suggestion icons. The previous logic should be used to determine if we should tint the icon or not. Change-Id: I2451490130cee216ff65301a600eb91d2e65c321 Fixes: 74261827 Test: visual and make RunSettingsRoboTests --- res/layout/suggestion_tile.xml | 3 +- res/layout/suggestion_tile_with_button.xml | 3 +- .../suggestions/SuggestionAdapter.java | 2 +- .../suggestions/SuggestionAdapterTest.java | 30 ++++++++++++++++++- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/res/layout/suggestion_tile.xml b/res/layout/suggestion_tile.xml index 9493e2d5f80..0465b1976b5 100644 --- a/res/layout/suggestion_tile.xml +++ b/res/layout/suggestion_tile.xml @@ -29,7 +29,8 @@ diff --git a/res/layout/suggestion_tile_with_button.xml b/res/layout/suggestion_tile_with_button.xml index 7b9ddf92989..7cb834a8a46 100644 --- a/res/layout/suggestion_tile_with_button.xml +++ b/res/layout/suggestion_tile_with_button.xml @@ -29,7 +29,8 @@ } final Icon icon = suggestion.getIcon(); final Drawable drawable = mCache.getIcon(icon); - if (drawable != null) { + if (drawable != null && (suggestion.getFlags() & Suggestion.FLAG_ICON_TINTABLE) != 0) { drawable.setTint(Utils.getColorAccent(mContext)); } holder.icon.setImageDrawable(drawable); diff --git a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java index fc347245530..533d4e95ad6 100644 --- a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java +++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionAdapterTest.java @@ -231,12 +231,40 @@ public class SuggestionAdapterTest { } @Test - public void onBindViewHolder_shouldTintIcon() throws PendingIntent.CanceledException { + public void onBindViewHolder_iconNotTintable_shouldNotTintIcon() + throws PendingIntent.CanceledException { + final Icon icon = mock(Icon.class); + final Suggestion suggestion = new Suggestion.Builder("pkg1") + .setPendingIntent(mock(PendingIntent.class)) + .setIcon(icon) + .build(); + final List suggestions = new ArrayList<>(); + suggestions.add(suggestion); + mSuggestionAdapter = new SuggestionAdapter(mActivity, mSuggestionControllerMixin, + null /* savedInstanceState */, null /* callback */, null /* lifecycle */); + mSuggestionAdapter.setSuggestions(suggestions); + mSuggestionHolder = mSuggestionAdapter.onCreateViewHolder( + new FrameLayout(RuntimeEnvironment.application), + mSuggestionAdapter.getItemViewType(0)); + IconCache cache = mock(IconCache.class); + final Drawable drawable = mock(Drawable.class); + when(cache.getIcon(icon)).thenReturn(drawable); + ReflectionHelpers.setField(mSuggestionAdapter, "mCache", cache); + + mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0); + + verify(drawable, never()).setTint(anyInt()); + } + + @Test + public void onBindViewHolder_iconTintable_shouldTintIcon() + throws PendingIntent.CanceledException { final Icon icon = mock(Icon.class); final int FLAG_ICON_TINTABLE = 1 << 1; final Suggestion suggestion = new Suggestion.Builder("pkg1") .setPendingIntent(mock(PendingIntent.class)) .setIcon(icon) + .setFlags(FLAG_ICON_TINTABLE) .build(); final List suggestions = new ArrayList<>(); suggestions.add(suggestion);