Add a config to force rounded icon for DashboardFragment.

And each page has ability to turn on/off rounded icons. This CL only
adds the flag, it doesn't actually change icon shape yet.

- Boolean config in xml
- New protected method for each DashboardFragment to load config
- Plumb the boolean into DashboardFeatureProvider for future use.
- Remove some unused APIs from DashboardFeatureProvider

Bug: 110405144
Fixes: 79748104
Test: robotests
Change-Id: Id34782e75aa7289967e4dd1f4fe2978688092702
This commit is contained in:
Fan Zhang
2018-08-09 17:32:37 -07:00
parent 2d24e8a839
commit 7d5a9eebb8
14 changed files with 102 additions and 150 deletions

View File

@@ -44,6 +44,7 @@ import com.android.settings.dashboard.conditional.Condition;
import com.android.settings.dashboard.conditional.ConditionAdapter;
import com.android.settings.dashboard.suggestions.SuggestionAdapter;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.RoundedHomepageIcon;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;

View File

@@ -15,8 +15,6 @@
*/
package com.android.settings.dashboard;
import android.content.Context;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.Preference;
@@ -35,34 +33,11 @@ public interface DashboardFeatureProvider {
*/
DashboardCategory getTilesForCategory(String key);
/**
* Get tiles (wrapped as a list of Preference) for key defined in CategoryKey.
*
* @param activity Activity hosting the preference
* @param context UI context to inflate preference
* @param sourceMetricsCategory The context (source) from which an action is performed
* @param key Value from CategoryKey
* @deprecated Pages implementing {@code DashboardFragment} should use
* {@link #getTilesForCategory(String)} instead. Using this method will not get the benefit
* of auto-ordering, progressive disclosure, auto-refreshing summary text etc.
*/
@Deprecated
List<Preference> getPreferencesForCategory(FragmentActivity activity, Context context,
int sourceMetricsCategory, String key);
/**
* Get all tiles, grouped by category.
*/
List<DashboardCategory> getAllCategories();
/**
* Whether or not we should tint icons in setting pages.
*
* @deprecated in favor of color icons in homepage
*/
@Deprecated
boolean shouldTintIcon();
/**
* Returns an unique string key for the tile.
*/
@@ -72,6 +47,7 @@ public interface DashboardFeatureProvider {
* Binds preference to data provided by tile.
*
* @param activity If tile contains intent to launch, it will be launched from this activity
* @param forceRoundedIcon Whether or not injected tiles from other packages should be forced to rounded icon.
* @param sourceMetricsCategory The context (source) from which an action is performed
* @param pref The preference to bind data
* @param tile The binding data
@@ -79,8 +55,8 @@ public interface DashboardFeatureProvider {
* @param baseOrder The order offset value. When binding, pref's order is determined by
* both this value and tile's own priority.
*/
void bindPreferenceToTile(FragmentActivity activity, int sourceMetricsCategory, Preference pref,
Tile tile, String key, int baseOrder);
void bindPreferenceToTile(FragmentActivity activity, boolean forceRoundedIcon,
int sourceMetricsCategory, Preference pref, Tile tile, String key, int baseOrder);
/**
* Returns additional intent filter action for dashboard tiles

View File

@@ -80,39 +80,11 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
return mCategoryManager.getTilesByCategory(mContext, key);
}
@Override
public List<Preference> getPreferencesForCategory(FragmentActivity activity, Context context,
int sourceMetricsCategory, String key) {
final DashboardCategory category = getTilesForCategory(key);
if (category == null) {
Log.d(TAG, "NO dashboard tiles for " + TAG);
return null;
}
final List<Tile> tiles = category.getTiles();
if (tiles == null || tiles.isEmpty()) {
Log.d(TAG, "tile list is empty, skipping category " + category.key);
return null;
}
final List<Preference> preferences = new ArrayList<>();
for (Tile tile : tiles) {
final Preference pref = new Preference(context);
bindPreferenceToTile(activity, sourceMetricsCategory, pref, tile, null /* key */,
Preference.DEFAULT_ORDER /* baseOrder */);
preferences.add(pref);
}
return preferences;
}
@Override
public List<DashboardCategory> getAllCategories() {
return mCategoryManager.getCategories(mContext);
}
@Override
public boolean shouldTintIcon() {
return mContext.getResources().getBoolean(R.bool.config_tintSettingIcon);
}
@Override
public String getDashboardKeyForTile(Tile tile) {
if (tile == null) {
@@ -128,8 +100,8 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
}
@Override
public void bindPreferenceToTile(FragmentActivity activity, int sourceMetricsCategory,
Preference pref, Tile tile, String key, int baseOrder) {
public void bindPreferenceToTile(FragmentActivity activity, boolean forceRoundedIcon,
int sourceMetricsCategory, Preference pref, Tile tile, String key, int baseOrder) {
if (pref == null) {
return;
}

View File

@@ -207,6 +207,10 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
@Override
protected abstract int getPreferenceScreenResId();
protected boolean shouldForceRoundedIcon() {
return false;
}
protected <T extends AbstractPreferenceController> T use(Class<T> clazz) {
List<AbstractPreferenceController> controllerList = mPreferenceControllers.get(clazz);
if (controllerList != null) {
@@ -343,6 +347,7 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
final int tintColor = a.getColor(0, context.getColor(android.R.color.white));
a.recycle();
// Install dashboard tiles.
final boolean forceRoundedIcons = shouldForceRoundedIcon();
for (Tile tile : tiles) {
final String key = mDashboardFeatureProvider.getDashboardKeyForTile(tile);
if (TextUtils.isEmpty(key)) {
@@ -361,13 +366,15 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
if (mDashboardTilePrefKeys.contains(key)) {
// Have the key already, will rebind.
final Preference preference = screen.findPreference(key);
mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), getMetricsCategory(),
preference, tile, key, mPlaceholderPreferenceController.getOrder());
mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), forceRoundedIcons,
getMetricsCategory(), preference, tile, key,
mPlaceholderPreferenceController.getOrder());
} else {
// Don't have this key, add it.
final Preference pref = new Preference(getPrefContext());
mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), getMetricsCategory(),
pref, tile, key, mPlaceholderPreferenceController.getOrder());
mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), forceRoundedIcons,
getMetricsCategory(), pref, tile, key,
mPlaceholderPreferenceController.getOrder());
screen.addPreference(pref);
mDashboardTilePrefKeys.add(key);
}

View File

@@ -1,53 +0,0 @@
/*
* 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 static androidx.annotation.VisibleForTesting.NONE;
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.util.Log;
import com.android.settings.R;
import androidx.annotation.VisibleForTesting;
public class RoundedHomepageIcon extends LayerDrawable {
private static final String TAG = "RoundedHomepageIcon";
@VisibleForTesting(otherwise = NONE)
int mBackgroundColor = -1;
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);
}
public void setBackgroundColor(int color) {
mBackgroundColor = color;
getDrawable(0).setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
Log.d(TAG, "Setting background color " + mBackgroundColor);
}
}

View File

@@ -42,12 +42,6 @@ import com.android.settingslib.utils.ThreadUtils;
import java.lang.reflect.Field;
import java.util.List;
/**
* TODO(b/110405144): Remove this when all top level settings are converted to PreferenceControllers
*
* @deprecated
*/
@Deprecated
public class SummaryLoader {
private static final boolean DEBUG = DashboardSummary.DEBUG;
private static final String TAG = "SummaryLoader";