Add a generic blue background on some homepage tiles
If a homepage tile is injected from external packages, we can't control what their icons look like, so we put a generic blue circular background to make it consistent with the other icons. Change-Id: I2a935db37fff097ae15540262bff94efea55179a Fixes: 69314641 Test: robotests
This commit is contained in:
@@ -17,7 +17,6 @@ package com.android.settings.dashboard;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Bundle;
|
||||
@@ -95,7 +94,7 @@ public class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
mDashboardFeatureProvider = factory.getDashboardFeatureProvider(context);
|
||||
mCache = new IconCache(context);
|
||||
mSuggestionAdapter = new SuggestionAdapterV2(mContext, suggestionControllerMixin,
|
||||
savedInstanceState, this /* callback */, lifecycle);
|
||||
savedInstanceState, this /* callback */, lifecycle);
|
||||
|
||||
setHasStableIds(true);
|
||||
|
||||
@@ -110,11 +109,11 @@ public class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
}
|
||||
|
||||
mDashboardData = new DashboardDataV2.Builder()
|
||||
.setConditions(conditions)
|
||||
.setSuggestions(mSuggestionAdapter.getSuggestions())
|
||||
.setCategory(category)
|
||||
.setConditionExpanded(conditionExpanded)
|
||||
.build();
|
||||
.setConditions(conditions)
|
||||
.setSuggestions(mSuggestionAdapter.getSuggestions())
|
||||
.setCategory(category)
|
||||
.setConditionExpanded(conditionExpanded)
|
||||
.build();
|
||||
}
|
||||
|
||||
public void setSuggestions(List<Suggestion> data) {
|
||||
@@ -126,7 +125,6 @@ public class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
}
|
||||
|
||||
public void setCategory(DashboardCategory category) {
|
||||
tintIcons(category);
|
||||
final DashboardDataV2 prevData = mDashboardData;
|
||||
Log.d(TAG, "adapter setCategory called");
|
||||
mDashboardData = new DashboardDataV2.Builder(prevData)
|
||||
@@ -155,8 +153,8 @@ public class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
// remain as the dashboard item. Need to refresh the dashboard list.
|
||||
final DashboardDataV2 prevData = mDashboardData;
|
||||
mDashboardData = new DashboardDataV2.Builder(prevData)
|
||||
.setSuggestions(null)
|
||||
.build();
|
||||
.setSuggestions(null)
|
||||
.build();
|
||||
notifyDashboardDataChanged(prevData);
|
||||
} else {
|
||||
mSuggestionAdapter.removeSuggestion(suggestion);
|
||||
@@ -194,7 +192,7 @@ public class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
switch (type) {
|
||||
case R.layout.dashboard_tile:
|
||||
final Tile tile = (Tile) mDashboardData.getItemEntityByPosition(position);
|
||||
onBindTile((DashboardItemHolder) holder, tile);
|
||||
onBindTile(holder, tile);
|
||||
holder.itemView.setTag(tile);
|
||||
holder.itemView.setOnClickListener(mTileClickListener);
|
||||
break;
|
||||
@@ -214,7 +212,7 @@ public class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
MetricsEvent.ACTION_SETTINGS_CONDITION_EXPAND, false);
|
||||
DashboardDataV2 prevData = mDashboardData;
|
||||
mDashboardData = new DashboardDataV2.Builder(prevData).
|
||||
setConditionExpanded(false).build();
|
||||
setConditionExpanded(false).build();
|
||||
notifyDashboardDataChanged(prevData);
|
||||
scrollToTopOfConditions();
|
||||
});
|
||||
@@ -275,14 +273,14 @@ public class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
} else {
|
||||
holder.title.setText(null);
|
||||
holder.summary.setText(
|
||||
mContext.getString(R.string.condition_summary, data.conditionCount));
|
||||
mContext.getString(R.string.condition_summary, data.conditionCount));
|
||||
updateConditionIcons(data.conditionIcons, holder.icons);
|
||||
holder.icons.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
holder.itemView.setOnClickListener(v -> {
|
||||
mMetricsFeatureProvider.action(mContext,
|
||||
MetricsEvent.ACTION_SETTINGS_CONDITION_EXPAND, true);
|
||||
MetricsEvent.ACTION_SETTINGS_CONDITION_EXPAND, true);
|
||||
final DashboardDataV2 prevData = mDashboardData;
|
||||
mDashboardData = new DashboardDataV2.Builder(prevData)
|
||||
.setConditionExpanded(true).build();
|
||||
@@ -294,8 +292,8 @@ public class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
@VisibleForTesting
|
||||
void onBindCondition(final ConditionContainerHolder holder, int position) {
|
||||
final ConditionAdapterV2 adapter = new ConditionAdapterV2(mContext,
|
||||
(List<Condition>) mDashboardData.getItemEntityByPosition(position),
|
||||
mDashboardData.isConditionExpanded());
|
||||
(List<Condition>) mDashboardData.getItemEntityByPosition(position),
|
||||
mDashboardData.isConditionExpanded());
|
||||
adapter.addDismissHandling(holder.data);
|
||||
holder.data.setAdapter(adapter);
|
||||
holder.data.setLayoutManager(new LinearLayoutManager(mContext));
|
||||
@@ -306,10 +304,10 @@ public class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
// If there is suggestions to show, it will be at position 0 as we don't show the suggestion
|
||||
// header anymore.
|
||||
final List<Suggestion> suggestions =
|
||||
(List<Suggestion>) mDashboardData.getItemEntityByPosition(position);
|
||||
(List<Suggestion>) mDashboardData.getItemEntityByPosition(position);
|
||||
final int suggestionCount = suggestions.size();
|
||||
if (suggestions != null && suggestionCount > 0) {
|
||||
holder.summary.setText(""+suggestionCount);
|
||||
holder.summary.setText("" + suggestionCount);
|
||||
mSuggestionAdapter.setSuggestions(suggestions);
|
||||
holder.data.setAdapter(mSuggestionAdapter);
|
||||
}
|
||||
@@ -318,8 +316,14 @@ public class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
holder.data.setLayoutManager(layoutManager);
|
||||
}
|
||||
|
||||
private void onBindTile(DashboardItemHolder holder, Tile tile) {
|
||||
holder.icon.setImageDrawable(mCache.getIcon(tile.icon));
|
||||
@VisibleForTesting
|
||||
void onBindTile(DashboardItemHolder holder, Tile tile) {
|
||||
Drawable icon = mCache.getIcon(tile.icon);
|
||||
if (!TextUtils.equals(tile.icon.getResPackage(), mContext.getPackageName())) {
|
||||
icon = new RoundedHomepageIcon(mContext, icon);
|
||||
mCache.updateIcon(tile.icon, icon);
|
||||
}
|
||||
holder.icon.setImageDrawable(icon);
|
||||
holder.title.setText(tile.title);
|
||||
if (!TextUtils.isEmpty(tile.summary)) {
|
||||
holder.summary.setText(tile.summary);
|
||||
@@ -329,25 +333,6 @@ public class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
}
|
||||
}
|
||||
|
||||
private void tintIcons(DashboardCategory category) {
|
||||
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();
|
||||
if (category != null) {
|
||||
for (Tile tile : category.getTiles()) {
|
||||
if (tile.isIconTintable) {
|
||||
// If this drawable is tintable, tint it to match the color.
|
||||
tile.icon.setTint(tintColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
final DashboardCategory category = mDashboardData.getCategory();
|
||||
@@ -392,10 +377,14 @@ public class DashboardAdapterV2 extends RecyclerView.Adapter<DashboardAdapterV2.
|
||||
Drawable drawable = mMap.get(icon);
|
||||
if (drawable == null) {
|
||||
drawable = icon.loadDrawable(mContext);
|
||||
mMap.put(icon, drawable);
|
||||
updateIcon(icon, drawable);
|
||||
}
|
||||
return drawable;
|
||||
}
|
||||
|
||||
public void updateIcon(Icon icon, Drawable drawable) {
|
||||
mMap.put(icon, drawable);
|
||||
}
|
||||
}
|
||||
|
||||
public static class DashboardItemHolder extends RecyclerView.ViewHolder {
|
||||
|
@@ -56,7 +56,9 @@ public interface DashboardFeatureProvider {
|
||||
|
||||
/**
|
||||
* Whether or not we should tint icons in setting pages.
|
||||
* @deprecated in favor of color icons in homepage
|
||||
*/
|
||||
@Deprecated
|
||||
boolean shouldTintIcon();
|
||||
|
||||
/**
|
||||
|
36
src/com/android/settings/dashboard/RoundedHomepageIcon.java
Normal file
36
src/com/android/settings/dashboard/RoundedHomepageIcon.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.dashboard;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
public class RoundedHomepageIcon extends LayerDrawable {
|
||||
|
||||
public RoundedHomepageIcon(Context context, Drawable foreground) {
|
||||
super(new Drawable[] {
|
||||
context.getDrawable(R.drawable.ic_homepage_generic_background),
|
||||
foreground
|
||||
});
|
||||
final int insetPx = context.getResources()
|
||||
.getDimensionPixelSize(R.dimen.dashboard_tile_foreground_image_inset);
|
||||
setLayerInset(1 /* index */, insetPx, insetPx, insetPx, insetPx);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user