Remove custom tintable check.
Make a bunch keys private in tile and DashboardCategory Bug: 77600770 Test: robotests Change-Id: I4693e6bb71bd50cc664f578c7f8e25e67da20b67
This commit is contained in:
@@ -42,6 +42,16 @@ import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toolbar;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.settings.Settings.WifiSettingsActivity;
|
||||
import com.android.settings.applications.manageapplications.ManageApplications;
|
||||
@@ -65,16 +75,6 @@ import com.android.settingslib.utils.ThreadUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
|
||||
public class SettingsActivity extends SettingsBaseActivity
|
||||
implements PreferenceManager.OnPreferenceTreeClickListener,
|
||||
|
@@ -126,7 +126,7 @@ public class AccountDetailDashboardFragment extends DashboardFragment {
|
||||
if (mAccountType == null) {
|
||||
return false;
|
||||
}
|
||||
final Bundle metadata = tile.metaData;
|
||||
final Bundle metadata = tile.getMetaData();
|
||||
if (metadata == null) {
|
||||
return false;
|
||||
}
|
||||
|
@@ -153,7 +153,7 @@ public class CategoryManager {
|
||||
boolean useNewKey = false;
|
||||
boolean useOldKey = false;
|
||||
for (Tile tile : tiles) {
|
||||
if (CategoryKey.KEY_COMPAT_MAP.containsKey(tile.category)) {
|
||||
if (CategoryKey.KEY_COMPAT_MAP.containsKey(tile.getCategory())) {
|
||||
useOldKey = true;
|
||||
} else {
|
||||
useNewKey = true;
|
||||
@@ -163,12 +163,13 @@ public class CategoryManager {
|
||||
// Uses only old key, map them to new keys one by one.
|
||||
if (useOldKey && !useNewKey) {
|
||||
for (Tile tile : tiles) {
|
||||
final String newCategoryKey = CategoryKey.KEY_COMPAT_MAP.get(tile.category);
|
||||
tile.category = newCategoryKey;
|
||||
final String newCategoryKey =
|
||||
CategoryKey.KEY_COMPAT_MAP.get(tile.getCategory());
|
||||
tile.setCategory(newCategoryKey);
|
||||
// move tile to new category.
|
||||
DashboardCategory newCategory = categoryByKeyMap.get(newCategoryKey);
|
||||
if (newCategory == null) {
|
||||
newCategory = new DashboardCategory();
|
||||
newCategory = new DashboardCategory(newCategoryKey);
|
||||
categoryByKeyMap.put(newCategoryKey, newCategory);
|
||||
}
|
||||
newCategory.addTile(tile);
|
||||
|
@@ -321,8 +321,9 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
&& !(icon instanceof RoundedHomepageIcon)) {
|
||||
icon = new RoundedHomepageIcon(mContext, icon);
|
||||
try {
|
||||
if (tile.metaData != null) {
|
||||
final int colorRes = tile.metaData.getInt(
|
||||
final Bundle metaData = tile.getMetaData();
|
||||
if (metaData != null) {
|
||||
final int colorRes = metaData.getInt(
|
||||
TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_HINT, 0 /* default */);
|
||||
if (colorRes != 0) {
|
||||
final int bgColor = mContext.getPackageManager()
|
||||
|
@@ -143,7 +143,7 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
||||
}
|
||||
bindSummary(pref, tile);
|
||||
bindIcon(pref, tile);
|
||||
final Bundle metadata = tile.metaData;
|
||||
final Bundle metadata = tile.getMetaData();
|
||||
String clsName = null;
|
||||
String action = null;
|
||||
Integer order = null;
|
||||
@@ -218,15 +218,15 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
||||
private void bindSummary(Preference preference, Tile tile) {
|
||||
if (tile.summary != null) {
|
||||
preference.setSummary(tile.summary);
|
||||
} else if (tile.metaData != null
|
||||
&& tile.metaData.containsKey(META_DATA_PREFERENCE_SUMMARY_URI)) {
|
||||
} else if (tile.getMetaData() != null
|
||||
&& tile.getMetaData().containsKey(META_DATA_PREFERENCE_SUMMARY_URI)) {
|
||||
// Set a placeholder summary before starting to fetch real summary, this is necessary
|
||||
// to avoid preference height change.
|
||||
preference.setSummary(R.string.summary_placeholder);
|
||||
|
||||
ThreadUtils.postOnBackgroundThread(() -> {
|
||||
final Map<String, IContentProvider> providerMap = new ArrayMap<>();
|
||||
final String uri = tile.metaData.getString(META_DATA_PREFERENCE_SUMMARY_URI);
|
||||
final String uri = tile.getMetaData().getString(META_DATA_PREFERENCE_SUMMARY_URI);
|
||||
final String summary = TileUtils.getTextFromUri(
|
||||
mContext, uri, providerMap, META_DATA_PREFERENCE_SUMMARY);
|
||||
ThreadUtils.postOnMainThread(() -> preference.setSummary(summary));
|
||||
@@ -241,8 +241,8 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
||||
final Icon tileIcon = tile.getIcon(mContext);
|
||||
if (tileIcon != null) {
|
||||
preference.setIcon(tileIcon.loadDrawable(preference.getContext()));
|
||||
} else if (tile.metaData != null
|
||||
&& tile.metaData.containsKey(META_DATA_PREFERENCE_ICON_URI)) {
|
||||
} else if (tile.getMetaData() != null
|
||||
&& tile.getMetaData().containsKey(META_DATA_PREFERENCE_ICON_URI)) {
|
||||
ThreadUtils.postOnBackgroundThread(() -> {
|
||||
String packageName = null;
|
||||
if (tile.intent != null) {
|
||||
@@ -254,7 +254,7 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
||||
}
|
||||
}
|
||||
final Map<String, IContentProvider> providerMap = new ArrayMap<>();
|
||||
final String uri = tile.metaData.getString(META_DATA_PREFERENCE_ICON_URI);
|
||||
final String uri = tile.getMetaData().getString(META_DATA_PREFERENCE_ICON_URI);
|
||||
final Pair<String, Integer> iconInfo = TileUtils.getIconFromUri(
|
||||
mContext, packageName, uri, providerMap);
|
||||
if (iconInfo == null) {
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.dashboard;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
@@ -40,7 +41,6 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
import com.android.settingslib.drawer.TileUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -254,24 +254,6 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
return true;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean tintTileIcon(Tile tile) {
|
||||
final Context context = getContext();
|
||||
if (tile.getIcon(context) == null) {
|
||||
return false;
|
||||
}
|
||||
// First check if the tile has set the icon tintable metadata.
|
||||
final Bundle metadata = tile.metaData;
|
||||
if (metadata != null
|
||||
&& metadata.containsKey(TileUtils.META_DATA_PREFERENCE_ICON_TINTABLE)) {
|
||||
return metadata.getBoolean(TileUtils.META_DATA_PREFERENCE_ICON_TINTABLE);
|
||||
}
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays resource based tiles.
|
||||
*/
|
||||
@@ -370,8 +352,11 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
if (!displayTile(tile)) {
|
||||
continue;
|
||||
}
|
||||
if (tintTileIcon(tile)) {
|
||||
tile.getIcon(context).setTint(tintColor);
|
||||
if (tile.isIconTintable(context)) {
|
||||
final Icon icon = tile.getIcon(context);
|
||||
if (icon != null) {
|
||||
icon.setTint(tintColor);
|
||||
}
|
||||
}
|
||||
if (mDashboardTilePrefKeys.contains(key)) {
|
||||
// Have the key already, will rebind.
|
||||
|
@@ -30,6 +30,8 @@ import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
@@ -39,8 +41,6 @@ import com.android.settingslib.utils.ThreadUtils;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
public class SummaryLoader {
|
||||
private static final boolean DEBUG = DashboardSummary.DEBUG;
|
||||
private static final String TAG = "SummaryLoader";
|
||||
@@ -160,7 +160,7 @@ public class SummaryLoader {
|
||||
// TODO: Load summary indirectly.
|
||||
return null;
|
||||
}
|
||||
Bundle metaData = getMetaData(tile);
|
||||
final Bundle metaData = tile.getMetaData();
|
||||
if (metaData == null) {
|
||||
if (DEBUG) Log.d(TAG, "No metadata specified for " + tile.intent.getComponent());
|
||||
return null;
|
||||
@@ -187,10 +187,6 @@ public class SummaryLoader {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Bundle getMetaData(Tile tile) {
|
||||
return tile.metaData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a receiver and automatically unregisters it when the activity is stopping.
|
||||
* This ensures that the receivers are unregistered immediately, since most summary loader
|
||||
|
@@ -167,8 +167,8 @@ public class SettingsSearchIndexablesProvider extends SearchIndexablesProvider {
|
||||
// Build parent-child class pairs for all children listed under this key.
|
||||
for (Tile tile : category.getTiles()) {
|
||||
String childClass = null;
|
||||
if (tile.metaData != null) {
|
||||
childClass = tile.metaData.getString(
|
||||
if (tile.getMetaData() != null) {
|
||||
childClass = tile.getMetaData().getString(
|
||||
SettingsActivity.META_DATA_KEY_FRAGMENT_CLASS);
|
||||
}
|
||||
if (childClass == null) {
|
||||
|
Reference in New Issue
Block a user