mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-20 03:08:19 +00:00
Handle messages to update Launcher preview color
Receive color update messages with a list of color resource ids and a corresponding list of color overrides, and adjust the preview accordingly. Flag: com.android.systemui.shared.new_customization_picker_ui Test: manually verified that the selected colors are previewed Bug: 350718581 Change-Id: Ibcde0575416df00b76627ac1004f21f5f9af1196
This commit is contained in:
@@ -95,6 +95,7 @@ public class GridCustomizationsProvider extends ContentProvider {
|
||||
|
||||
private static final int MESSAGE_ID_UPDATE_PREVIEW = 1337;
|
||||
private static final int MESSAGE_ID_UPDATE_GRID = 7414;
|
||||
private static final int MESSAGE_ID_UPDATE_COLOR = 856;
|
||||
|
||||
// Set of all active previews used to track duplicate memory allocations
|
||||
private final Set<PreviewLifecycleObserver> mActivePreviews =
|
||||
@@ -289,6 +290,11 @@ public class GridCustomizationsProvider extends ContentProvider {
|
||||
renderer.updateGrid(gridName);
|
||||
}
|
||||
break;
|
||||
case MESSAGE_ID_UPDATE_COLOR:
|
||||
if (Flags.newCustomizationPickerUi()) {
|
||||
renderer.previewColor(message.getData());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// Unknown command, destroy lifecycle
|
||||
Log.d(TAG, "Unknown preview command: " + message.what + ", destroying preview");
|
||||
|
||||
@@ -98,6 +98,7 @@ import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
|
||||
import com.android.launcher3.widget.LauncherWidgetHolder;
|
||||
import com.android.launcher3.widget.LocalColorExtractor;
|
||||
import com.android.launcher3.widget.util.WidgetSizes;
|
||||
import com.android.systemui.shared.Flags;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -150,6 +151,14 @@ public class LauncherPreviewRenderer extends ContextWrapper
|
||||
InvariantDeviceProfile idp,
|
||||
WallpaperColors wallpaperColorsOverride,
|
||||
@Nullable final SparseArray<Size> launcherWidgetSpanInfo) {
|
||||
this(context, idp, null, wallpaperColorsOverride, launcherWidgetSpanInfo);
|
||||
}
|
||||
|
||||
public LauncherPreviewRenderer(Context context,
|
||||
InvariantDeviceProfile idp,
|
||||
SparseIntArray previewColorOverride,
|
||||
WallpaperColors wallpaperColorsOverride,
|
||||
@Nullable final SparseArray<Size> launcherWidgetSpanInfo) {
|
||||
|
||||
super(context);
|
||||
mUiHandler = new Handler(Looper.getMainLooper());
|
||||
@@ -206,12 +215,29 @@ public class LauncherPreviewRenderer extends ContextWrapper
|
||||
mWorkspaceScreens.put(Workspace.SECOND_SCREEN_ID, rightPanel);
|
||||
}
|
||||
|
||||
WallpaperColors wallpaperColors = wallpaperColorsOverride != null
|
||||
? wallpaperColorsOverride
|
||||
: WallpaperManager.getInstance(context).getWallpaperColors(FLAG_SYSTEM);
|
||||
mWallpaperColorResources = wallpaperColors != null
|
||||
? LocalColorExtractor.newInstance(context).generateColorsOverride(wallpaperColors)
|
||||
: null;
|
||||
if (Flags.newCustomizationPickerUi()) {
|
||||
if (previewColorOverride != null) {
|
||||
mWallpaperColorResources = previewColorOverride;
|
||||
} else if (wallpaperColorsOverride != null) {
|
||||
mWallpaperColorResources = LocalColorExtractor.newInstance(
|
||||
context).generateColorsOverride(wallpaperColorsOverride);
|
||||
} else {
|
||||
WallpaperColors wallpaperColors = WallpaperManager.getInstance(
|
||||
context).getWallpaperColors(FLAG_SYSTEM);
|
||||
mWallpaperColorResources = wallpaperColors != null
|
||||
? LocalColorExtractor.newInstance(context).generateColorsOverride(
|
||||
wallpaperColors)
|
||||
: null;
|
||||
}
|
||||
} else {
|
||||
WallpaperColors wallpaperColors = wallpaperColorsOverride != null
|
||||
? wallpaperColorsOverride
|
||||
: WallpaperManager.getInstance(context).getWallpaperColors(FLAG_SYSTEM);
|
||||
mWallpaperColorResources = wallpaperColors != null
|
||||
? LocalColorExtractor.newInstance(context).generateColorsOverride(
|
||||
wallpaperColors)
|
||||
: null;
|
||||
}
|
||||
mAppWidgetHost = new LauncherPreviewAppWidgetHost(context);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
import android.util.Size;
|
||||
import android.util.SparseArray;
|
||||
import android.util.SparseIntArray;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.Display;
|
||||
import android.view.SurfaceControlViewHost;
|
||||
@@ -81,6 +82,8 @@ public class PreviewSurfaceRenderer {
|
||||
private static final String KEY_VIEW_HEIGHT = "height";
|
||||
private static final String KEY_DISPLAY_ID = "display_id";
|
||||
private static final String KEY_COLORS = "wallpaper_colors";
|
||||
private static final String KEY_COLOR_RESOURCE_IDS = "color_resource_ids";
|
||||
private static final String KEY_COLOR_VALUES = "color_values";
|
||||
|
||||
private Context mContext;
|
||||
private final IBinder mHostToken;
|
||||
@@ -91,6 +94,7 @@ public class PreviewSurfaceRenderer {
|
||||
private final int mDisplayId;
|
||||
private final Display mDisplay;
|
||||
private final WallpaperColors mWallpaperColors;
|
||||
private SparseIntArray mPreviewColorOverride;
|
||||
private final RunnableList mLifeCycleTracker;
|
||||
|
||||
private final SurfaceControlViewHost mSurfaceControlViewHost;
|
||||
@@ -110,6 +114,9 @@ public class PreviewSurfaceRenderer {
|
||||
mGridName = InvariantDeviceProfile.getCurrentGridName(context);
|
||||
}
|
||||
mWallpaperColors = bundle.getParcelable(KEY_COLORS);
|
||||
if (Flags.newCustomizationPickerUi()) {
|
||||
updateColorOverrides(bundle);
|
||||
}
|
||||
mHideQsb = bundle.getBoolean(GridCustomizationsProvider.KEY_HIDE_BOTTOM_ROW);
|
||||
|
||||
mHostToken = bundle.getBinder(KEY_HOST_TOKEN);
|
||||
@@ -217,20 +224,60 @@ public class PreviewSurfaceRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the colors of the preview.
|
||||
*
|
||||
* @param bundle Bundle with an int array of color ids and an int array of overriding colors.
|
||||
*/
|
||||
public void previewColor(Bundle bundle) {
|
||||
updateColorOverrides(bundle);
|
||||
loadAsync();
|
||||
}
|
||||
|
||||
private void updateColorOverrides(Bundle bundle) {
|
||||
int[] ids = bundle.getIntArray(KEY_COLOR_RESOURCE_IDS);
|
||||
int[] colors = bundle.getIntArray(KEY_COLOR_VALUES);
|
||||
if (ids != null && colors != null) {
|
||||
mPreviewColorOverride = new SparseIntArray();
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
mPreviewColorOverride.put(ids[i], colors[i]);
|
||||
}
|
||||
} else {
|
||||
mPreviewColorOverride = null;
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* Generates a new context overriding the theme color and the display size without affecting the
|
||||
* main application context
|
||||
*/
|
||||
private Context getPreviewContext() {
|
||||
Context context = mContext.createDisplayContext(mDisplay);
|
||||
if (mWallpaperColors == null) {
|
||||
if (Flags.newCustomizationPickerUi()) {
|
||||
if (mPreviewColorOverride != null) {
|
||||
LocalColorExtractor.newInstance(context)
|
||||
.applyColorsOverride(context, mPreviewColorOverride);
|
||||
} else if (mWallpaperColors != null) {
|
||||
LocalColorExtractor.newInstance(context)
|
||||
.applyColorsOverride(context, mWallpaperColors);
|
||||
}
|
||||
if (mWallpaperColors != null) {
|
||||
return new ContextThemeWrapper(context,
|
||||
Themes.getActivityThemeRes(context, mWallpaperColors.getColorHints()));
|
||||
} else {
|
||||
return new ContextThemeWrapper(context,
|
||||
Themes.getActivityThemeRes(context));
|
||||
}
|
||||
} else {
|
||||
if (mWallpaperColors == null) {
|
||||
return new ContextThemeWrapper(context,
|
||||
Themes.getActivityThemeRes(context));
|
||||
}
|
||||
LocalColorExtractor.newInstance(context)
|
||||
.applyColorsOverride(context, mWallpaperColors);
|
||||
return new ContextThemeWrapper(context,
|
||||
Themes.getActivityThemeRes(context));
|
||||
Themes.getActivityThemeRes(context, mWallpaperColors.getColorHints()));
|
||||
}
|
||||
LocalColorExtractor.newInstance(context)
|
||||
.applyColorsOverride(context, mWallpaperColors);
|
||||
return new ContextThemeWrapper(context,
|
||||
Themes.getActivityThemeRes(context, mWallpaperColors.getColorHints()));
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
@@ -300,8 +347,13 @@ public class PreviewSurfaceRenderer {
|
||||
if (mDestroyed) {
|
||||
return;
|
||||
}
|
||||
mRenderer = new LauncherPreviewRenderer(inflationContext, idp,
|
||||
mWallpaperColors, launcherWidgetSpanInfo);
|
||||
if (Flags.newCustomizationPickerUi()) {
|
||||
mRenderer = new LauncherPreviewRenderer(inflationContext, idp, mPreviewColorOverride,
|
||||
mWallpaperColors, launcherWidgetSpanInfo);
|
||||
} else {
|
||||
mRenderer = new LauncherPreviewRenderer(inflationContext, idp,
|
||||
mWallpaperColors, launcherWidgetSpanInfo);
|
||||
}
|
||||
mRenderer.hideBottomRow(mHideQsb);
|
||||
View view = mRenderer.getRenderedView(dataModel, widgetProviderInfoMap);
|
||||
// This aspect scales the view to fit in the surface and centers it
|
||||
|
||||
@@ -48,4 +48,9 @@ public class LocalColorExtractor implements ResourceBasedOverride {
|
||||
public SparseIntArray generateColorsOverride(WallpaperColors colors) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the base context to contain the colors override
|
||||
*/
|
||||
public void applyColorsOverride(Context base, SparseIntArray override) { }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user