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

Commit 01c32a69 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Adding a shared-pref to control icon theming

Bug: 183641907
Test: Manual
Change-Id: I640a8473c9ca4acfded9ebbfa823e437c3a42b45
parent d727db3c
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import static com.android.launcher3.util.SettingsCache.NOTIFICATION_BADGING_URI;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.pm.LauncherApps;
import android.os.UserHandle;
import android.util.Log;
@@ -45,6 +47,7 @@ import com.android.launcher3.util.RunnableList;
import com.android.launcher3.util.SafeCloseable;
import com.android.launcher3.util.SettingsCache;
import com.android.launcher3.util.SimpleBroadcastReceiver;
import com.android.launcher3.util.Themes;
import com.android.launcher3.widget.custom.CustomWidgetManager;

public class LauncherAppState {
@@ -108,6 +111,12 @@ public class LauncherAppState {
                observer, MODEL_EXECUTOR.getHandler());
        mOnTerminateCallback.add(iconChangeTracker::close);
        MODEL_EXECUTOR.execute(observer::verifyIconChanged);
        if (ENABLE_THEMED_ICONS.get()) {
            SharedPreferences prefs = Utilities.getPrefs(mContext);
            prefs.registerOnSharedPreferenceChangeListener(observer);
            mOnTerminateCallback.add(
                    () -> prefs.unregisterOnSharedPreferenceChangeListener(observer));
        }

        InstallSessionTracker installSessionTracker =
                InstallSessionHelper.INSTANCE.get(context).registerInstallTracker(mModel);
@@ -128,7 +137,7 @@ public class LauncherAppState {
        mContext = context;

        mInvariantDeviceProfile = InvariantDeviceProfile.INSTANCE.get(context);
        mIconProvider =  new IconProvider(context, ENABLE_THEMED_ICONS.get());
        mIconProvider =  new IconProvider(context, Themes.isThemedIconEnabled(context));
        mIconCache = new IconCache(mContext, mInvariantDeviceProfile,
                iconCacheFileName, mIconProvider);
        mWidgetCache = new WidgetPreviewLoader(mContext, mIconCache);
@@ -187,7 +196,8 @@ public class LauncherAppState {
        return InvariantDeviceProfile.INSTANCE.get(context);
    }

    private class IconObserver implements IconProvider.IconChangeListener {
    private class IconObserver
            implements IconProvider.IconChangeListener, OnSharedPreferenceChangeListener {

        @Override
        public void onAppIconChanged(String packageName, UserHandle user) {
@@ -207,5 +217,13 @@ public class LauncherAppState {
                onSystemIconStateChanged(iconState);
            }
        }

        @Override
        public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
            if (Themes.KEY_THEMED_ICONS.equals(key)) {
                mIconProvider.setIconThemeSupported(Themes.isThemedIconEnabled(mContext));
                verifyIconChanged();
            }
        }
    }
}
+62 −31
Original line number Diff line number Diff line
package com.android.launcher3.graphics;

import static com.android.launcher3.Utilities.getPrefs;
import static com.android.launcher3.util.Themes.KEY_THEMED_ICONS;
import static com.android.launcher3.util.Themes.isThemedIconEnabled;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.pm.PackageManager;
@@ -15,6 +19,7 @@ import android.util.Xml;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.InvariantDeviceProfile.GridOption;
import com.android.launcher3.R;
import com.android.launcher3.config.FeatureFlags;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -55,6 +60,11 @@ public class GridCustomizationsProvider extends ContentProvider {

    private static final String METHOD_GET_PREVIEW = "get_preview";

    private static final String GET_ICON_THEMED = "/get_icon_themed";
    private static final String SET_ICON_THEMED = "/set_icon_themed";
    private static final String ICON_THEMED = "/icon_themed";
    private static final String BOOLEAN_VALUE = "boolean_value";

    @Override
    public boolean onCreate() {
        return true;
@@ -63,9 +73,8 @@ public class GridCustomizationsProvider extends ContentProvider {
    @Override
    public Cursor query(Uri uri, String[] projection, String selection,
            String[] selectionArgs, String sortOrder) {
        if (!KEY_LIST_OPTIONS.equals(uri.getPath())) {
            return null;
        }
        switch (uri.getPath()) {
            case KEY_LIST_OPTIONS: {
                MatrixCursor cursor = new MatrixCursor(new String[] {
                        KEY_NAME, KEY_ROWS, KEY_COLS, KEY_PREVIEW_COUNT, KEY_IS_DEFAULT});
                InvariantDeviceProfile idp = InvariantDeviceProfile.INSTANCE.get(getContext());
@@ -80,6 +89,16 @@ public class GridCustomizationsProvider extends ContentProvider {
                }
                return cursor;
            }
            case GET_ICON_THEMED:
            case ICON_THEMED: {
                MatrixCursor cursor = new MatrixCursor(new String[] {BOOLEAN_VALUE});
                cursor.newRow().add(BOOLEAN_VALUE, isThemedIconEnabled(getContext()) ? 1 : 0);
                return cursor;
            }
            default:
                return null;
        }
    }

    private List<GridOption> parseAllGridOptions() {
        List<GridOption> result = new ArrayList<>();
@@ -117,10 +136,8 @@ public class GridCustomizationsProvider extends ContentProvider {

    @Override
    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
        if (!KEY_DEFAULT_GRID.equals(uri.getPath())) {
            return 0;
        }

        switch (uri.getPath()) {
            case KEY_DEFAULT_GRID: {
                String gridName = values.getAsString(KEY_NAME);
                // Verify that this is a valid grid option
                GridOption match = null;
@@ -134,9 +151,23 @@ public class GridCustomizationsProvider extends ContentProvider {
                    return 0;
                }

        InvariantDeviceProfile.INSTANCE.get(getContext()).setCurrentGrid(getContext(), gridName);
                InvariantDeviceProfile.INSTANCE.get(getContext())
                        .setCurrentGrid(getContext(), gridName);
                return 1;
            }
            case ICON_THEMED:
            case SET_ICON_THEMED: {
                if (FeatureFlags.ENABLE_THEMED_ICONS.get()) {
                    getPrefs(getContext()).edit()
                            .putBoolean(KEY_THEMED_ICONS, values.getAsBoolean(BOOLEAN_VALUE))
                            .apply();
                }
                return 1;
            }
            default:
                return 0;
        }
    }

    @Override
    public Bundle call(String method, String arg, Bundle extras) {
+10 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.util.TypedValue;

import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.icons.GraphicsUtils;

/**
@@ -40,6 +41,8 @@ import com.android.launcher3.icons.GraphicsUtils;
@SuppressWarnings("NewApi")
public class Themes {

    public static final String KEY_THEMED_ICONS = "themed_icons";

    public static int getActivityThemeRes(Context context) {
        final int colorHints;
        if (Utilities.ATLEAST_P) {
@@ -67,6 +70,13 @@ public class Themes {
        }
    }

    /**
     * Returns true if workspace icon theming is enabled
     */
    public static boolean isThemedIconEnabled(Context context) {
        return FeatureFlags.ENABLE_THEMED_ICONS.get()
                && Utilities.getPrefs(context).getBoolean(KEY_THEMED_ICONS, false);
    }

    public static String getDefaultBodyFont(Context context) {
        TypedArray ta = context.obtainStyledAttributes(android.R.style.TextAppearance_DeviceDefault,