Merge "Adding a shared-pref to control icon theming" into sc-dev
This commit is contained in:
commit
de94720354
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
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,22 +73,31 @@ 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());
|
||||
for (GridOption gridOption : parseAllGridOptions()) {
|
||||
cursor.newRow()
|
||||
.add(KEY_NAME, gridOption.name)
|
||||
.add(KEY_ROWS, gridOption.numRows)
|
||||
.add(KEY_COLS, gridOption.numColumns)
|
||||
.add(KEY_PREVIEW_COUNT, 1)
|
||||
.add(KEY_IS_DEFAULT, idp.numColumns == gridOption.numColumns
|
||||
&& idp.numRows == gridOption.numRows);
|
||||
}
|
||||
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;
|
||||
}
|
||||
MatrixCursor cursor = new MatrixCursor(new String[] {
|
||||
KEY_NAME, KEY_ROWS, KEY_COLS, KEY_PREVIEW_COUNT, KEY_IS_DEFAULT});
|
||||
InvariantDeviceProfile idp = InvariantDeviceProfile.INSTANCE.get(getContext());
|
||||
for (GridOption gridOption : parseAllGridOptions()) {
|
||||
cursor.newRow()
|
||||
.add(KEY_NAME, gridOption.name)
|
||||
.add(KEY_ROWS, gridOption.numRows)
|
||||
.add(KEY_COLS, gridOption.numColumns)
|
||||
.add(KEY_PREVIEW_COUNT, 1)
|
||||
.add(KEY_IS_DEFAULT, idp.numColumns == gridOption.numColumns
|
||||
&& idp.numRows == gridOption.numRows);
|
||||
}
|
||||
return cursor;
|
||||
}
|
||||
|
||||
private List<GridOption> parseAllGridOptions() {
|
||||
|
@ -117,25 +136,37 @@ 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;
|
||||
for (GridOption option : parseAllGridOptions()) {
|
||||
if (option.name.equals(gridName)) {
|
||||
match = option;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (match == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
String gridName = values.getAsString(KEY_NAME);
|
||||
// Verify that this is a valid grid option
|
||||
GridOption match = null;
|
||||
for (GridOption option : parseAllGridOptions()) {
|
||||
if (option.name.equals(gridName)) {
|
||||
match = option;
|
||||
break;
|
||||
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;
|
||||
}
|
||||
if (match == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
InvariantDeviceProfile.INSTANCE.get(getContext()).setCurrentGrid(getContext(), gridName);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue