Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7d5a9eeb authored by Fan Zhang's avatar Fan Zhang
Browse files

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
parent 2d24e8a8
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -106,9 +106,6 @@
        -->
    </string-array>

    <!-- Whether or not we should tint the icon color on setting pages. -->
    <bool name="config_tintSettingIcon">true</bool>

    <!-- Whether or not App & Notification screen should display recently used apps -->
    <bool name="config_display_recent_apps">true</bool>

@@ -133,4 +130,7 @@
         devices will be able to vary their amplitude but do not possess enough dynamic range to
         have distinct intensity levels -->
    <bool name="config_vibration_supports_multiple_intensities">false</bool>

    <!-- Whether or not TopLevelSettings should force rounded icon for injected tiles -->
    <bool name="config_force_rounded_icon_TopLevelSettings">true</bool>
</resources>
+1 −0
Original line number Diff line number Diff line
@@ -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;
+3 −27
Original line number Diff line number Diff line
@@ -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
+2 −30
Original line number Diff line number Diff line
@@ -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;
        }
+11 −4
Original line number Diff line number Diff line
@@ -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);
            }
Loading