From de15672e6fea7adeb2cfe2f50678ba0bf9b2177e Mon Sep 17 00:00:00 2001 From: Charlie Anderson Date: Fri, 21 Feb 2025 20:04:34 +0000 Subject: [PATCH] Initialize shape with PreviewContext init and remove nullability Bug: 372887760 Bug: 348664593 Flag: com.android.launcher3.enable_launcher_icon_shapes Test: previewing shapes with flag on/off Change-Id: I4d7278c54a0d69e38142d31dd7a9605a74db3348 --- .../graphics/GridCustomizationsProxy.java | 4 +++- .../graphics/LauncherPreviewRenderer.java | 4 +++- .../launcher3/graphics/PreviewSurfaceRenderer.java | 14 ++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/com/android/launcher3/graphics/GridCustomizationsProxy.java b/src/com/android/launcher3/graphics/GridCustomizationsProxy.java index 01c9d7ec4f..062c753758 100644 --- a/src/com/android/launcher3/graphics/GridCustomizationsProxy.java +++ b/src/com/android/launcher3/graphics/GridCustomizationsProxy.java @@ -377,7 +377,9 @@ public class GridCustomizationsProxy implements ProxyProvider { if (Flags.newCustomizationPickerUi() && com.android.launcher3.Flags.enableLauncherIconShapes()) { String shapeKey = message.getData().getString(KEY_SHAPE_KEY); - renderer.updateShape(shapeKey); + if (!TextUtils.isEmpty(shapeKey)) { + renderer.updateShape(shapeKey); + } } break; case MESSAGE_ID_UPDATE_GRID: diff --git a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java index 332a6bbc36..740b87b02e 100644 --- a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java +++ b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java @@ -28,6 +28,7 @@ import static com.android.launcher3.LauncherPrefs.GRID_NAME; import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT; import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION; import static com.android.launcher3.Utilities.SHOULD_SHOW_FIRST_PAGE_WIDGET; +import static com.android.launcher3.graphics.ThemeManager.PREF_ICON_SHAPE; import static com.android.launcher3.model.ModelUtils.currentScreenContentFilter; import android.app.Fragment; @@ -137,12 +138,13 @@ public class LauncherPreviewRenderer extends ContextWrapper private final String mPrefName; - public PreviewContext(Context base, String gridName) { + public PreviewContext(Context base, String gridName, String shapeKey) { super(base); mPrefName = "preview-" + UUID.randomUUID().toString(); LauncherPrefs prefs = new ProxyPrefs(this, getSharedPreferences(mPrefName, MODE_PRIVATE)); prefs.put(GRID_NAME, gridName); + prefs.put(PREF_ICON_SHAPE, shapeKey); initDaggerComponent( DaggerLauncherPreviewRenderer_PreviewAppComponent.builder().bindPrefs(prefs)); } diff --git a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java index 6fe5804da6..4dd9c5bea5 100644 --- a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java +++ b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java @@ -73,7 +73,6 @@ import com.android.systemui.shared.Flags; import java.util.ArrayList; import java.util.Map; -import java.util.Objects; import java.util.concurrent.TimeUnit; /** Render preview using surface view. */ @@ -120,6 +119,7 @@ public class PreviewSurfaceRenderer { if (mGridName == null) { mGridName = LauncherPrefs.get(context).get(GRID_NAME); } + mShapeKey = LauncherPrefs.get(context).get(PREF_ICON_SHAPE); mWallpaperColors = bundle.getParcelable(KEY_COLORS); if (Flags.newCustomizationPickerUi()) { updateColorOverrides(bundle); @@ -225,8 +225,8 @@ public class PreviewSurfaceRenderer { * * @param shapeKey key for the IconShape model */ - public void updateShape(@Nullable String shapeKey) { - if (Objects.equals(mShapeKey, shapeKey)) { + public void updateShape(String shapeKey) { + if (shapeKey.equals(mShapeKey)) { Log.w(TAG, "Preview shape already set, skipping. shape=" + mShapeKey); return; } @@ -332,12 +332,10 @@ public class PreviewSurfaceRenderer { private void loadModelData() { final Context inflationContext = getPreviewContext(); if (!mGridName.equals(LauncherPrefs.INSTANCE.get(mContext).get(GRID_NAME)) - || mShapeKey != null) { + || !mShapeKey.equals(LauncherPrefs.INSTANCE.get(mContext).get(PREF_ICON_SHAPE))) { // Start the migration - PreviewContext previewContext = new PreviewContext(inflationContext, mGridName); - if (mShapeKey != null) { - LauncherPrefs.INSTANCE.get(previewContext).put(PREF_ICON_SHAPE, mShapeKey); - } + PreviewContext previewContext = + new PreviewContext(inflationContext, mGridName, mShapeKey); // Copy existing data to preview DB LauncherDbUtils.copyTable(LauncherAppState.getInstance(mContext) .getModel().getModelDbController().getDb(),