Merge "Force externally injected tiles to use rounded icon."
This commit is contained in:
committed by
Android (Google) Code Review
commit
237f80b0aa
@@ -16,7 +16,6 @@
|
||||
package com.android.settings.dashboard;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Bundle;
|
||||
@@ -51,7 +50,6 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
import com.android.settingslib.drawer.TileUtils;
|
||||
import com.android.settingslib.suggestions.SuggestionControllerMixinCompat;
|
||||
import com.android.settingslib.utils.IconCache;
|
||||
|
||||
@@ -65,7 +63,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
|
||||
@VisibleForTesting
|
||||
static final String STATE_CONDITION_EXPANDED = "condition_expanded";
|
||||
static final String META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB = "com.android.settings.bg.argb";
|
||||
|
||||
private final IconCache mCache;
|
||||
private final Context mContext;
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
@@ -248,10 +246,6 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
return mDashboardData.getItemEntityById(itemId);
|
||||
}
|
||||
|
||||
public Suggestion getSuggestion(int position) {
|
||||
return mSuggestionAdapter.getSuggestion(position);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void notifyDashboardDataChanged(DashboardData prevData) {
|
||||
if (mFirstFrameDrawn && prevData != null) {
|
||||
@@ -322,31 +316,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
if (!TextUtils.equals(tileIcon.getResPackage(), mContext.getPackageName())
|
||||
&& !(icon instanceof RoundedHomepageIcon)) {
|
||||
icon = new RoundedHomepageIcon(mContext, icon);
|
||||
final Bundle metaData = tile.getMetaData();
|
||||
try {
|
||||
if (metaData != null) {
|
||||
// Load from bg.argb first
|
||||
int bgColor = metaData.getInt(META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB,
|
||||
0 /* default */);
|
||||
// Not found, load from bg.hint
|
||||
if (bgColor == 0) {
|
||||
final int colorRes = metaData.getInt(
|
||||
TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_HINT,
|
||||
0 /* default */);
|
||||
if (colorRes != 0) {
|
||||
bgColor = mContext.getPackageManager()
|
||||
.getResourcesForApplication(tileIcon.getResPackage())
|
||||
.getColor(colorRes, null /* theme */);
|
||||
}
|
||||
}
|
||||
// If found anything, use it.
|
||||
if (bgColor != 0) {
|
||||
((RoundedHomepageIcon) icon).setBackgroundColor(bgColor);
|
||||
}
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
Log.e(TAG, "Failed to set background color for " + tile.getPackageName());
|
||||
}
|
||||
((RoundedHomepageIcon) icon).setBackgroundColor(mContext, tile);
|
||||
mCache.updateIcon(tileIcon, icon);
|
||||
}
|
||||
holder.icon.setImageDrawable(icon);
|
||||
|
@@ -25,6 +25,7 @@ import android.content.Context;
|
||||
import android.content.IContentProvider;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
@@ -42,6 +43,7 @@ import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.dashboard.profileselector.ProfileSelectDialog;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.RoundedHomepageIcon;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settingslib.core.instrumentation.VisibilityLoggerMixin;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
@@ -49,7 +51,6 @@ import com.android.settingslib.drawer.Tile;
|
||||
import com.android.settingslib.drawer.TileUtils;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -112,7 +113,7 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
||||
pref.setKey(getDashboardKeyForTile(tile));
|
||||
}
|
||||
bindSummary(pref, tile);
|
||||
bindIcon(pref, tile);
|
||||
bindIcon(pref, tile, forceRoundedIcon);
|
||||
final Bundle metadata = tile.getMetaData();
|
||||
String clsName = null;
|
||||
String action = null;
|
||||
@@ -192,10 +193,16 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void bindIcon(Preference preference, Tile tile) {
|
||||
void bindIcon(Preference preference, Tile tile, boolean forceRoundedIcon) {
|
||||
final Icon tileIcon = tile.getIcon(mContext);
|
||||
if (tileIcon != null) {
|
||||
preference.setIcon(tileIcon.loadDrawable(preference.getContext()));
|
||||
Drawable iconDrawable = tileIcon.loadDrawable(preference.getContext());
|
||||
if (forceRoundedIcon
|
||||
&& !TextUtils.equals(mContext.getPackageName(), tile.getPackageName())) {
|
||||
iconDrawable = new RoundedHomepageIcon(mContext, iconDrawable);
|
||||
((RoundedHomepageIcon) iconDrawable).setBackgroundColor(mContext, tile);
|
||||
}
|
||||
preference.setIcon(iconDrawable);
|
||||
} else if (tile.getMetaData() != null
|
||||
&& tile.getMetaData().containsKey(META_DATA_PREFERENCE_ICON_URI)) {
|
||||
ThreadUtils.postOnBackgroundThread(() -> {
|
||||
|
@@ -62,8 +62,9 @@ public class DashboardFragmentRegistry {
|
||||
|
||||
static {
|
||||
PARENT_TO_CATEGORY_KEY_MAP = new ArrayMap<>();
|
||||
PARENT_TO_CATEGORY_KEY_MAP.put(TopLevelSettings.class.getName(),
|
||||
CategoryKey.CATEGORY_HOMEPAGE);
|
||||
// TODO(b/110405144): Add the mapping when IA.homepage intent-filter is is removed.
|
||||
// PARENT_TO_CATEGORY_KEY_MAP.put(TopLevelSettings.class.getName(),
|
||||
// CategoryKey.CATEGORY_HOMEPAGE);
|
||||
PARENT_TO_CATEGORY_KEY_MAP.put(
|
||||
NetworkDashboardFragment.class.getName(), CategoryKey.CATEGORY_NETWORK);
|
||||
PARENT_TO_CATEGORY_KEY_MAP.put(ConnectedDeviceDashboardFragment.class.getName(),
|
||||
|
Reference in New Issue
Block a user