@VisibleForTesting
void onBindTile(DashboardItemHolder holder, Tile tile) {
- Icon tileIcon = tile.getIcon();
+ Icon tileIcon = tile.getIcon(mContext);
Drawable icon = mCache.getIcon(tileIcon);
if (!TextUtils.equals(tileIcon.getResPackage(), mContext.getPackageName())
&& !(icon instanceof RoundedHomepageIcon)) {
import android.util.Log;
import android.util.Pair;
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.Preference;
+
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import java.util.List;
import java.util.Map;
-import androidx.annotation.VisibleForTesting;
-import androidx.preference.Preference;
-
/**
* Impl for {@code DashboardFeatureProvider}.
*/
@VisibleForTesting
void bindIcon(Preference preference, Tile tile) {
- final Icon tileIcon = tile.getIcon();
+ final Icon tileIcon = tile.getIcon(mContext);
if (tileIcon != null) {
preference.setIcon(tileIcon.loadDrawable(preference.getContext()));
} else if (tile.metaData != null
import android.util.ArraySet;
import android.util.Log;
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceManager;
+import androidx.preference.PreferenceScreen;
+
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.PreferenceControllerListHelper;
import java.util.Map;
import java.util.Set;
-import androidx.annotation.VisibleForTesting;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceManager;
-import androidx.preference.PreferenceScreen;
-
/**
* Base fragment for dashboard style UI containing a list of static and dynamic setting items.
*/
@VisibleForTesting
boolean tintTileIcon(Tile tile) {
- if (tile.getIcon() == null) {
+ final Context context = getContext();
+ if (tile.getIcon(context) == null) {
return false;
}
// First check if the tile has set the icon tintable metadata.
&& metadata.containsKey(TileUtils.META_DATA_PREFERENCE_ICON_TINTABLE)) {
return metadata.getBoolean(TileUtils.META_DATA_PREFERENCE_ICON_TINTABLE);
}
- final String pkgName = getContext().getPackageName();
+ final String pkgName = context.getPackageName();
// If this drawable is coming from outside Settings, tint it to match the color.
return pkgName != null && tile.intent != null
&& !pkgName.equals(tile.intent.getComponent().getPackageName());
continue;
}
if (tintTileIcon(tile)) {
- tile.getIcon().setTint(tintColor);
+ tile.getIcon(context).setTint(tintColor);
}
if (mDashboardTilePrefKeys.contains(key)) {
// Have the key already, will rebind.
new DashboardAdapter.DashboardItemHolder(view);
final Tile tile = spy(new Tile(mActivityInfo));
doReturn(Icon.createWithResource(context, R.drawable.ic_settings))
- .when(tile).getIcon();
+ .when(tile).getIcon(context);
final IconCache iconCache = mock(IconCache.class);
- when(iconCache.getIcon(tile.getIcon()))
+ when(iconCache.getIcon(tile.getIcon(context)))
.thenReturn(context.getDrawable(R.drawable.ic_settings));
mDashboardAdapter = new DashboardAdapter(context, null /* savedInstanceState */,
new DashboardAdapter.DashboardItemHolder(view);
final Tile tile = spy(new Tile(mActivityInfo));
final Icon icon = Icon.createWithResource(context, R.drawable.ic_settings);
- doReturn(icon).when(tile).getIcon();
+ doReturn(icon).when(tile).getIcon(context);
final IconCache iconCache = new IconCache(context);
doReturn("another.package").when(context).getPackageName();
mDashboardAdapter.onBindTile(holder, tile);
- assertThat(iconCache.getIcon(tile.getIcon())).isInstanceOf(RoundedHomepageIcon.class);
+ assertThat(iconCache.getIcon(tile.getIcon(context)))
+ .isInstanceOf(RoundedHomepageIcon.class);
}
@Test
tile.metaData.putInt(TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_HINT,
R.color.memory_critical);
doReturn(Icon.createWithResource(context, R.drawable.ic_settings))
- .when(tile).getIcon();
+ .when(tile).getIcon(context);
final IconCache iconCache = new IconCache(context);
mDashboardAdapter = new DashboardAdapter(context, null /* savedInstanceState */,
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
mDashboardAdapter.onBindTile(holder, tile);
final RoundedHomepageIcon homepageIcon = (RoundedHomepageIcon) iconCache.getIcon(
- tile.getIcon());
+ tile.getIcon(context));
assertThat(homepageIcon.mBackgroundColor)
.isEqualTo(RuntimeEnvironment.application.getColor(R.color.memory_critical));
}
final DashboardAdapter.DashboardItemHolder holder =
new DashboardAdapter.DashboardItemHolder(view);
final Tile tile = spy(new Tile(mActivityInfo));
- doReturn(mock(Icon.class)).when(tile).getIcon();
- when(tile.getIcon().getResPackage()).thenReturn("another.package");
+ doReturn(mock(Icon.class)).when(tile).getIcon(context);
+ when(tile.getIcon(context).getResPackage()).thenReturn("another.package");
final IconCache iconCache = mock(IconCache.class);
- when(iconCache.getIcon(tile.getIcon())).thenReturn(mock(RoundedHomepageIcon.class));
+ when(iconCache.getIcon(tile.getIcon(context))).thenReturn(mock(RoundedHomepageIcon.class));
mDashboardAdapter = new DashboardAdapter(context, null /* savedInstanceState */,
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
mDashboardAdapter.onBindTile(holder, tile);
- verify(iconCache, never()).updateIcon(eq(tile.getIcon()), any(RoundedHomepageIcon.class));
+ verify(iconCache, never()).updateIcon(eq(tile.getIcon(context)),
+ any(RoundedHomepageIcon.class));
}
private List<Suggestion> makeSuggestionsV2(String... pkgNames) {
tile.title = "title";
tile.summary = "summary";
doReturn(Icon.createWithBitmap(Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565)))
- .when(tile).getIcon();
+ .when(tile).getIcon(any(Context.class));
tile.metaData = new Bundle();
tile.metaData.putString(SettingsActivity.META_DATA_KEY_FRAGMENT_CLASS, "HI");
tile.priority = 10;
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@Test
public void tintTileIcon_hasMetadata_shouldReturnIconTintableMetadata() {
final Tile tile = spy(new Tile(mActivityInfo));
- doReturn(mock(Icon.class)).when(tile).getIcon();
+ doReturn(mock(Icon.class)).when(tile).getIcon(any(Context.class));
final Bundle metaData = new Bundle();
tile.metaData = metaData;
@Test
public void tintTileIcon_noMetadata_shouldReturnPackageNameCheck() {
final Tile tile = spy(new Tile(mActivityInfo));
- doReturn(mock(Icon.class)).when(tile).getIcon();
+ doReturn(mock(Icon.class)).when(tile).getIcon(any(Context.class));
final Intent intent = new Intent();
tile.intent = intent;
intent.setComponent(