Stop wrapping RoundedHomepageIcon if it's already wrapped.
On homepage, if an icon is already wrapped in RoundedHomepageIcon, we shouldn't wrap it more. Otherwise each time we do this it will add a few dp padding around the bitmap. Change-Id: I5313a38f4bd128272d7b4e05209aaee72c690c55 Fixes: 73295342 Test: robotest
This commit is contained in:
@@ -16,8 +16,8 @@
|
||||
package com.android.settings.dashboard;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.reset;
|
||||
@@ -93,15 +93,16 @@ public class DashboardAdapterTest {
|
||||
mConditionList.add(mCondition);
|
||||
when(mCondition.shouldShow()).thenReturn(true);
|
||||
mDashboardAdapter = new DashboardAdapter(mContext, null /* savedInstanceState */,
|
||||
mConditionList, null /* suggestionControllerMixin */, null /* lifecycle */);
|
||||
mConditionList, null /* suggestionControllerMixin */, null /* lifecycle */);
|
||||
when(mView.getTag()).thenReturn(mCondition);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuggestionDismissed_notOnlySuggestion_updateSuggestionOnly() {
|
||||
final DashboardAdapter adapter =
|
||||
spy(new DashboardAdapter(mContext, null /* savedInstanceState */,
|
||||
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */));
|
||||
spy(new DashboardAdapter(mContext, null /* savedInstanceState */,
|
||||
null /* conditions */, null /* suggestionControllerMixin */,
|
||||
null /* lifecycle */));
|
||||
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1", "pkg2", "pkg3");
|
||||
adapter.setSuggestions(suggestions);
|
||||
|
||||
@@ -114,7 +115,7 @@ public class DashboardAdapterTest {
|
||||
when(itemView.findViewById(android.R.id.summary)).thenReturn(mock(TextView.class));
|
||||
when(itemView.findViewById(android.R.id.title)).thenReturn(mock(TextView.class));
|
||||
final DashboardAdapter.SuggestionContainerHolder holder =
|
||||
new DashboardAdapter.SuggestionContainerHolder(itemView);
|
||||
new DashboardAdapter.SuggestionContainerHolder(itemView);
|
||||
|
||||
adapter.onBindSuggestion(holder, 0);
|
||||
|
||||
@@ -133,8 +134,9 @@ public class DashboardAdapterTest {
|
||||
@Test
|
||||
public void testSuggestionDismissed_onlySuggestion_updateDashboardData() {
|
||||
DashboardAdapter adapter =
|
||||
spy(new DashboardAdapter(mContext, null /* savedInstanceState */,
|
||||
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */));
|
||||
spy(new DashboardAdapter(mContext, null /* savedInstanceState */,
|
||||
null /* conditions */, null /* suggestionControllerMixin */,
|
||||
null /* lifecycle */));
|
||||
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1");
|
||||
adapter.setSuggestions(suggestions);
|
||||
final DashboardData dashboardData = adapter.mDashboardData;
|
||||
@@ -149,7 +151,7 @@ public class DashboardAdapterTest {
|
||||
@Test
|
||||
public void testBindSuggestion_shouldSetSuggestionAdapterAndNoCrash() {
|
||||
mDashboardAdapter = new DashboardAdapter(mContext, null /* savedInstanceState */,
|
||||
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
|
||||
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
|
||||
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1");
|
||||
|
||||
mDashboardAdapter.setSuggestions(suggestions);
|
||||
@@ -163,7 +165,7 @@ public class DashboardAdapterTest {
|
||||
when(itemView.findViewById(android.R.id.summary)).thenReturn(mock(TextView.class));
|
||||
when(itemView.findViewById(android.R.id.title)).thenReturn(mock(TextView.class));
|
||||
final DashboardAdapter.SuggestionContainerHolder holder =
|
||||
new DashboardAdapter.SuggestionContainerHolder(itemView);
|
||||
new DashboardAdapter.SuggestionContainerHolder(itemView);
|
||||
|
||||
mDashboardAdapter.onBindSuggestion(holder, 0);
|
||||
|
||||
@@ -176,14 +178,14 @@ public class DashboardAdapterTest {
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
final View view = LayoutInflater.from(context).inflate(R.layout.dashboard_tile, null);
|
||||
final DashboardAdapter.DashboardItemHolder holder =
|
||||
new DashboardAdapter.DashboardItemHolder(view);
|
||||
new DashboardAdapter.DashboardItemHolder(view);
|
||||
final Tile tile = new Tile();
|
||||
tile.icon = Icon.createWithResource(context, R.drawable.ic_settings);
|
||||
final IconCache iconCache = mock(IconCache.class);
|
||||
when(iconCache.getIcon(tile.icon)).thenReturn(context.getDrawable(R.drawable.ic_settings));
|
||||
|
||||
mDashboardAdapter = new DashboardAdapter(context, null /* savedInstanceState */,
|
||||
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
|
||||
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
|
||||
ReflectionHelpers.setField(mDashboardAdapter, "mCache", iconCache);
|
||||
mDashboardAdapter.onBindTile(holder, tile);
|
||||
|
||||
@@ -191,11 +193,11 @@ public class DashboardAdapterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindTile_externalTile_shouldNotUseGenericBackgroundIcon() {
|
||||
public void onBindTile_externalTile_shouldUpdateIcon() {
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
final View view = LayoutInflater.from(context).inflate(R.layout.dashboard_tile, null);
|
||||
final DashboardAdapter.DashboardItemHolder holder =
|
||||
new DashboardAdapter.DashboardItemHolder(view);
|
||||
new DashboardAdapter.DashboardItemHolder(view);
|
||||
final Tile tile = new Tile();
|
||||
tile.icon = mock(Icon.class);
|
||||
when(tile.icon.getResPackage()).thenReturn("another.package");
|
||||
@@ -204,13 +206,36 @@ public class DashboardAdapterTest {
|
||||
when(iconCache.getIcon(tile.icon)).thenReturn(context.getDrawable(R.drawable.ic_settings));
|
||||
|
||||
mDashboardAdapter = new DashboardAdapter(context, null /* savedInstanceState */,
|
||||
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
|
||||
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
|
||||
ReflectionHelpers.setField(mDashboardAdapter, "mCache", iconCache);
|
||||
|
||||
mDashboardAdapter.onBindTile(holder, tile);
|
||||
|
||||
verify(iconCache).updateIcon(eq(tile.icon), any(RoundedHomepageIcon.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindTile_externalTile_usingRoundedHomepageIcon_shouldNotUpdateIcon() {
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
final View view = LayoutInflater.from(context).inflate(R.layout.dashboard_tile, null);
|
||||
final DashboardAdapter.DashboardItemHolder holder =
|
||||
new DashboardAdapter.DashboardItemHolder(view);
|
||||
final Tile tile = new Tile();
|
||||
tile.icon = mock(Icon.class);
|
||||
when(tile.icon.getResPackage()).thenReturn("another.package");
|
||||
|
||||
final IconCache iconCache = mock(IconCache.class);
|
||||
when(iconCache.getIcon(tile.icon)).thenReturn(mock(RoundedHomepageIcon.class));
|
||||
|
||||
mDashboardAdapter = new DashboardAdapter(context, null /* savedInstanceState */,
|
||||
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
|
||||
ReflectionHelpers.setField(mDashboardAdapter, "mCache", iconCache);
|
||||
|
||||
mDashboardAdapter.onBindTile(holder, tile);
|
||||
|
||||
verify(iconCache, never()).updateIcon(eq(tile.icon), any(RoundedHomepageIcon.class));
|
||||
}
|
||||
|
||||
private List<Suggestion> makeSuggestionsV2(String... pkgNames) {
|
||||
final List<Suggestion> suggestions = new ArrayList<>();
|
||||
for (String pkgName : pkgNames) {
|
||||
|
Reference in New Issue
Block a user