Merge "Force externally injected tiles to use rounded icon."
This commit is contained in:
committed by
Android (Google) Code Review
commit
237f80b0aa
@@ -53,7 +53,6 @@ import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.widget.RoundedHomepageIcon;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
import com.android.settingslib.drawer.TileUtils;
|
||||
import com.android.settingslib.utils.IconCache;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -115,7 +114,7 @@ public class DashboardAdapterTest {
|
||||
spy(new DashboardAdapter(mContext, null /* savedInstanceState */,
|
||||
null /* conditions */, null /* suggestionControllerMixin */,
|
||||
null /* lifecycle */));
|
||||
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1", "pkg2", "pkg3");
|
||||
final List<Suggestion> suggestions = makeSuggestions("pkg1", "pkg2", "pkg3");
|
||||
adapter.setSuggestions(suggestions);
|
||||
|
||||
final RecyclerView data = mock(RecyclerView.class);
|
||||
@@ -147,7 +146,7 @@ public class DashboardAdapterTest {
|
||||
spy(new DashboardAdapter(mContext, null /* savedInstanceState */,
|
||||
null /* conditions */, null /* suggestionControllerMixin */,
|
||||
null /* lifecycle */));
|
||||
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1");
|
||||
final List<Suggestion> suggestions = makeSuggestions("pkg1");
|
||||
adapter.setSuggestions(suggestions);
|
||||
final DashboardData dashboardData = adapter.mDashboardData;
|
||||
reset(adapter); // clear interactions tracking
|
||||
@@ -164,7 +163,7 @@ public class DashboardAdapterTest {
|
||||
spy(new DashboardAdapter(mContext, null /* savedInstanceState */,
|
||||
null /* conditions */, null /* suggestionControllerMixin */,
|
||||
null /* lifecycle */));
|
||||
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1");
|
||||
final List<Suggestion> suggestions = makeSuggestions("pkg1");
|
||||
adapter.setSuggestions(suggestions);
|
||||
|
||||
reset(adapter); // clear interactions tracking
|
||||
@@ -178,7 +177,7 @@ public class DashboardAdapterTest {
|
||||
public void onBindSuggestion_shouldSetSuggestionAdapterAndNoCrash() {
|
||||
mDashboardAdapter = new DashboardAdapter(mContext, null /* savedInstanceState */,
|
||||
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
|
||||
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1");
|
||||
final List<Suggestion> suggestions = makeSuggestions("pkg1");
|
||||
|
||||
mDashboardAdapter.setSuggestions(suggestions);
|
||||
|
||||
@@ -243,55 +242,6 @@ public class DashboardAdapterTest {
|
||||
.isInstanceOf(RoundedHomepageIcon.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindTile_externalTileWithBackgroundColorRawValue_shouldUpdateIcon() {
|
||||
final Context context = spy(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 = spy(new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE));
|
||||
tile.getMetaData().putInt(DashboardAdapter.META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB,
|
||||
0xff0000);
|
||||
doReturn(Icon.createWithResource(context, R.drawable.ic_settings))
|
||||
.when(tile).getIcon(context);
|
||||
final IconCache iconCache = new IconCache(context);
|
||||
mDashboardAdapter = new DashboardAdapter(context, null /* savedInstanceState */,
|
||||
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
|
||||
ReflectionHelpers.setField(mDashboardAdapter, "mCache", iconCache);
|
||||
|
||||
doReturn("another.package").when(context).getPackageName();
|
||||
mDashboardAdapter.onBindTile(holder, tile);
|
||||
|
||||
final RoundedHomepageIcon homepageIcon = (RoundedHomepageIcon) iconCache.getIcon(
|
||||
tile.getIcon(context));
|
||||
assertThat(homepageIcon.mBackgroundColor).isEqualTo(0xff0000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindTile_externalTileWithBackgroundColorHint_shouldUpdateIcon() {
|
||||
final Context context = spy(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 = spy(new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE));
|
||||
tile.getMetaData().putInt(TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_HINT,
|
||||
R.color.memory_critical);
|
||||
doReturn(Icon.createWithResource(context, R.drawable.ic_settings))
|
||||
.when(tile).getIcon(context);
|
||||
final IconCache iconCache = new IconCache(context);
|
||||
mDashboardAdapter = new DashboardAdapter(context, null /* savedInstanceState */,
|
||||
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
|
||||
ReflectionHelpers.setField(mDashboardAdapter, "mCache", iconCache);
|
||||
|
||||
doReturn("another.package").when(context).getPackageName();
|
||||
mDashboardAdapter.onBindTile(holder, tile);
|
||||
|
||||
final RoundedHomepageIcon homepageIcon = (RoundedHomepageIcon) iconCache.getIcon(
|
||||
tile.getIcon(context));
|
||||
assertThat(homepageIcon.mBackgroundColor)
|
||||
.isEqualTo(RuntimeEnvironment.application.getColor(R.color.memory_critical));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindTile_externalTile_usingRoundedHomepageIcon_shouldNotUpdateIcon() {
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
@@ -315,7 +265,7 @@ public class DashboardAdapterTest {
|
||||
any(RoundedHomepageIcon.class));
|
||||
}
|
||||
|
||||
private List<Suggestion> makeSuggestionsV2(String... pkgNames) {
|
||||
private List<Suggestion> makeSuggestions(String... pkgNames) {
|
||||
final List<Suggestion> suggestions = new ArrayList<>();
|
||||
for (String pkgName : pkgNames) {
|
||||
final Suggestion suggestion = new Suggestion.Builder(pkgName)
|
||||
|
@@ -291,7 +291,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key");
|
||||
mActivityInfo.metaData.putString(TileUtils.META_DATA_PREFERENCE_ICON_URI,
|
||||
"content://com.android.settings/tile_icon");
|
||||
mImpl.bindIcon(preference, tile);
|
||||
mImpl.bindIcon(preference, tile, false /* forceRoundedIcon */);
|
||||
|
||||
assertThat(preference.getIcon()).isNotNull();
|
||||
}
|
||||
|
@@ -16,21 +16,30 @@
|
||||
|
||||
package com.android.settings.widget;
|
||||
|
||||
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB;
|
||||
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_HINT;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.graphics.drawable.ShapeDrawable;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -41,10 +50,15 @@ import org.robolectric.RuntimeEnvironment;
|
||||
public class RoundedHomepageIconTest {
|
||||
|
||||
private Context mContext;
|
||||
private ActivityInfo mActivityInfo;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mActivityInfo = new ActivityInfo();
|
||||
mActivityInfo.packageName = mContext.getPackageName();
|
||||
mActivityInfo.name = "class";
|
||||
mActivityInfo.metaData = new Bundle();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,4 +82,34 @@ public class RoundedHomepageIconTest {
|
||||
|
||||
verify(background).setColorFilter(Color.BLUE, PorterDuff.Mode.SRC_ATOP);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setBackgroundColor_externalTileWithBackgroundColorRawValue_shouldUpdateIcon() {
|
||||
final Tile tile = spy(new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE));
|
||||
mActivityInfo.metaData.putInt(META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB, 0xff0000);
|
||||
doReturn(Icon.createWithResource(mContext, R.drawable.ic_settings))
|
||||
.when(tile).getIcon(mContext);
|
||||
final RoundedHomepageIcon icon =
|
||||
new RoundedHomepageIcon(mContext, new ColorDrawable(Color.BLACK));
|
||||
|
||||
icon.setBackgroundColor(mContext, tile);
|
||||
assertThat(icon.mBackgroundColor).isEqualTo(0xff0000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindTile_externalTileWithBackgroundColorHint_shouldUpdateIcon() {
|
||||
final Tile tile = spy(new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE));
|
||||
mActivityInfo.metaData.putInt(META_DATA_PREFERENCE_ICON_BACKGROUND_HINT,
|
||||
R.color.memory_critical);
|
||||
doReturn(Icon.createWithResource(mContext, R.drawable.ic_settings))
|
||||
.when(tile).getIcon(mContext);
|
||||
|
||||
final RoundedHomepageIcon icon =
|
||||
new RoundedHomepageIcon(mContext, new ColorDrawable(Color.BLACK));
|
||||
icon.setBackgroundColor(mContext, tile);
|
||||
|
||||
assertThat(icon.mBackgroundColor)
|
||||
.isEqualTo(mContext.getColor(R.color.memory_critical));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user