Merge "Check icon tintable flag of the Suggestion."
This commit is contained in:
committed by
Android (Google) Code Review
commit
0186c9d223
@@ -116,7 +116,7 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
|||||||
mConfig.setCardLayout(holder, suggestionCount, position);
|
mConfig.setCardLayout(holder, suggestionCount, position);
|
||||||
final Icon icon = suggestion.getIcon();
|
final Icon icon = suggestion.getIcon();
|
||||||
final Drawable drawable = mCache.getIcon(icon);
|
final Drawable drawable = mCache.getIcon(icon);
|
||||||
if (drawable != null && TextUtils.equals(icon.getResPackage(), mContext.getPackageName())) {
|
if ((suggestion.getFlags() & Suggestion.FLAG_ICON_TINTABLE) != 0) {
|
||||||
drawable.setTint(Utils.getColorAccent(mContext));
|
drawable.setTint(Utils.getColorAccent(mContext));
|
||||||
}
|
}
|
||||||
holder.icon.setImageDrawable(drawable);
|
holder.icon.setImageDrawable(drawable);
|
||||||
|
@@ -215,11 +215,9 @@ public class SuggestionAdapterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onBindViewHolder_differentPackage_shouldNotTintIcon()
|
public void onBindViewHolder_iconNotTintable_shouldNotTintIcon()
|
||||||
throws PendingIntent.CanceledException {
|
throws PendingIntent.CanceledException {
|
||||||
final Icon icon = mock(Icon.class);
|
final Icon icon = mock(Icon.class);
|
||||||
when(icon.getResPackage()).thenReturn("pkg1");
|
|
||||||
when(mActivity.getPackageName()).thenReturn("pkg2");
|
|
||||||
final Suggestion suggestion = new Suggestion.Builder("pkg1")
|
final Suggestion suggestion = new Suggestion.Builder("pkg1")
|
||||||
.setPendingIntent(mock(PendingIntent.class))
|
.setPendingIntent(mock(PendingIntent.class))
|
||||||
.setIcon(icon)
|
.setIcon(icon)
|
||||||
@@ -243,15 +241,14 @@ public class SuggestionAdapterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onBindViewHolder_samePackage_shouldTintIcon()
|
public void onBindViewHolder_iconTintable_shouldTintIcon()
|
||||||
throws PendingIntent.CanceledException {
|
throws PendingIntent.CanceledException {
|
||||||
final Icon icon = mock(Icon.class);
|
final Icon icon = mock(Icon.class);
|
||||||
final String packageName = "pkg1";
|
final int FLAG_ICON_TINTABLE = 1 << 1;
|
||||||
when(icon.getResPackage()).thenReturn(packageName);
|
final Suggestion suggestion = new Suggestion.Builder("pkg1")
|
||||||
when(mActivity.getPackageName()).thenReturn(packageName);
|
|
||||||
final Suggestion suggestion = new Suggestion.Builder(packageName)
|
|
||||||
.setPendingIntent(mock(PendingIntent.class))
|
.setPendingIntent(mock(PendingIntent.class))
|
||||||
.setIcon(icon)
|
.setIcon(icon)
|
||||||
|
.setFlags(FLAG_ICON_TINTABLE)
|
||||||
.build();
|
.build();
|
||||||
final List<Suggestion> suggestions = new ArrayList<>();
|
final List<Suggestion> suggestions = new ArrayList<>();
|
||||||
suggestions.add(suggestion);
|
suggestions.add(suggestion);
|
||||||
|
Reference in New Issue
Block a user