Merge "Also tint the settings icon in DashboardAdapter.setCategory()."
This commit is contained in:
committed by
Android (Google) Code Review
commit
a1bf76a69d
@@ -146,29 +146,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
|
|
||||||
public void setCategoriesAndSuggestions(List<DashboardCategory> categories,
|
public void setCategoriesAndSuggestions(List<DashboardCategory> categories,
|
||||||
List<Tile> suggestions) {
|
List<Tile> suggestions) {
|
||||||
if (mDashboardFeatureProvider.shouldTintIcon()) {
|
tintIcons(categories, suggestions);
|
||||||
// TODO: Better place for tinting?
|
|
||||||
final TypedArray a = mContext.obtainStyledAttributes(new int[]{
|
|
||||||
android.R.attr.colorControlNormal});
|
|
||||||
final int tintColor = a.getColor(0, mContext.getColor(R.color.fallback_tintColor));
|
|
||||||
a.recycle();
|
|
||||||
for (int i = 0; i < categories.size(); i++) {
|
|
||||||
for (int j = 0; j < categories.get(i).tiles.size(); j++) {
|
|
||||||
final Tile tile = categories.get(i).tiles.get(j);
|
|
||||||
|
|
||||||
if (tile.isIconTintable) {
|
|
||||||
// If this drawable is tintable, tint it to match the color.
|
|
||||||
tile.icon.setTint(tintColor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Tile suggestion : suggestions) {
|
|
||||||
if (suggestion.isIconTintable) {
|
|
||||||
suggestion.icon.setTint(tintColor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final DashboardData prevData = mDashboardData;
|
final DashboardData prevData = mDashboardData;
|
||||||
mDashboardData = new DashboardData.Builder(prevData)
|
mDashboardData = new DashboardData.Builder(prevData)
|
||||||
@@ -196,6 +174,8 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setCategory(List<DashboardCategory> category) {
|
public void setCategory(List<DashboardCategory> category) {
|
||||||
|
tintIcons(category, null);
|
||||||
|
|
||||||
final DashboardData prevData = mDashboardData;
|
final DashboardData prevData = mDashboardData;
|
||||||
Log.d(TAG, "adapter setCategory called");
|
Log.d(TAG, "adapter setCategory called");
|
||||||
mDashboardData = new DashboardData.Builder(prevData)
|
mDashboardData = new DashboardData.Builder(prevData)
|
||||||
@@ -504,6 +484,32 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
holder.title.setText(category.title);
|
holder.title.setText(category.title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void tintIcons(List<DashboardCategory> categories, List<Tile> suggestions) {
|
||||||
|
if (!mDashboardFeatureProvider.shouldTintIcon()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// TODO: Better place for tinting?
|
||||||
|
final TypedArray a = mContext.obtainStyledAttributes(new int[]{
|
||||||
|
android.R.attr.colorControlNormal});
|
||||||
|
final int tintColor = a.getColor(0, mContext.getColor(R.color.fallback_tintColor));
|
||||||
|
a.recycle();
|
||||||
|
for (DashboardCategory category : categories) {
|
||||||
|
for (Tile tile : category.tiles) {
|
||||||
|
if (tile.isIconTintable) {
|
||||||
|
// If this drawable is tintable, tint it to match the color.
|
||||||
|
tile.icon.setTint(tintColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (suggestions != null) {
|
||||||
|
for (Tile suggestion : suggestions) {
|
||||||
|
if (suggestion.isIconTintable) {
|
||||||
|
suggestion.icon.setTint(tintColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void onSaveInstanceState(Bundle outState) {
|
void onSaveInstanceState(Bundle outState) {
|
||||||
final List<Tile> suggestions = mDashboardData.getSuggestions();
|
final List<Tile> suggestions = mDashboardData.getSuggestions();
|
||||||
final List<DashboardCategory> categories = mDashboardData.getCategories();
|
final List<DashboardCategory> categories = mDashboardData.getCategories();
|
||||||
|
@@ -365,6 +365,28 @@ public class DashboardAdapterTest {
|
|||||||
verify(mockIcon).setTint(eq(0x89000000));
|
verify(mockIcon).setTint(eq(0x89000000));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetCategories_iconTinted() {
|
||||||
|
TypedArray mockTypedArray = mock(TypedArray.class);
|
||||||
|
doReturn(mockTypedArray).when(mContext).obtainStyledAttributes(any(int[].class));
|
||||||
|
doReturn(0x89000000).when(mockTypedArray).getColor(anyInt(), anyInt());
|
||||||
|
|
||||||
|
final List<DashboardCategory> categories = new ArrayList<>();
|
||||||
|
final DashboardCategory category = mock(DashboardCategory.class);
|
||||||
|
final List<Tile> tiles = new ArrayList<>();
|
||||||
|
final Icon mockIcon = mock(Icon.class);
|
||||||
|
final Tile tile = new Tile();
|
||||||
|
tile.isIconTintable = true;
|
||||||
|
tile.icon = mockIcon;
|
||||||
|
tiles.add(tile);
|
||||||
|
category.tiles = tiles;
|
||||||
|
categories.add(category);
|
||||||
|
|
||||||
|
mDashboardAdapter.setCategory(categories);
|
||||||
|
|
||||||
|
verify(mockIcon).setTint(eq(0x89000000));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBindConditionAndSuggestion_shouldSetSuggestionAdapterAndNoCrash() {
|
public void testBindConditionAndSuggestion_shouldSetSuggestionAdapterAndNoCrash() {
|
||||||
mDashboardAdapter = new DashboardAdapter(mContext, null, null, null, null);
|
mDashboardAdapter = new DashboardAdapter(mContext, null, null, null, null);
|
||||||
@@ -374,6 +396,7 @@ public class DashboardAdapterTest {
|
|||||||
final List<Tile> tiles = new ArrayList<>();
|
final List<Tile> tiles = new ArrayList<>();
|
||||||
tiles.add(mock(Tile.class));
|
tiles.add(mock(Tile.class));
|
||||||
category.tiles = tiles;
|
category.tiles = tiles;
|
||||||
|
categories.add(category);
|
||||||
mDashboardAdapter.setCategoriesAndSuggestions(categories, suggestions);
|
mDashboardAdapter.setCategoriesAndSuggestions(categories, suggestions);
|
||||||
|
|
||||||
final RecyclerView data = mock(RecyclerView.class);
|
final RecyclerView data = mock(RecyclerView.class);
|
||||||
|
Reference in New Issue
Block a user