From de4d7457a884d8bbf19d3a5f1eb902832ed62fdb Mon Sep 17 00:00:00 2001 From: George Lin Date: Tue, 27 Aug 2024 16:57:32 +0000 Subject: [PATCH] Send message to launcher renderer to update grid (3/3) This CL supports external surface view callbacks to send messages to update the launcher's preview grid. Bug: 348664593 Test: Manually tested. See bug. Flag: com.android.systemui.shared.new_customization_picker_ui Change-Id: I8108ae2c49af6b4fc1a207c6ece23e82616baa61 --- Android.bp | 2 +- .../graphics/GridCustomizationsProvider.java | 22 +++++-- .../graphics/PreviewSurfaceRenderer.java | 58 +++++++++++++++++-- 3 files changed, 71 insertions(+), 11 deletions(-) diff --git a/Android.bp b/Android.bp index a0187e36ca..bcbd3626e9 100644 --- a/Android.bp +++ b/Android.bp @@ -333,7 +333,7 @@ android_library { "com_android_wm_shell_flags_lib", "dagger2", "jsr330", - + "com_android_systemui_shared_flags_lib", ], manifest: "AndroidManifest-common.xml", sdk_version: "current", diff --git a/src/com/android/launcher3/graphics/GridCustomizationsProvider.java b/src/com/android/launcher3/graphics/GridCustomizationsProvider.java index dc8694d2f6..374c07b6eb 100644 --- a/src/com/android/launcher3/graphics/GridCustomizationsProvider.java +++ b/src/com/android/launcher3/graphics/GridCustomizationsProvider.java @@ -32,6 +32,7 @@ import android.os.IBinder; import android.os.IBinder.DeathRecipient; import android.os.Message; import android.os.Messenger; +import android.text.TextUtils; import android.util.ArrayMap; import android.util.Log; import android.util.Pair; @@ -80,8 +81,10 @@ public class GridCustomizationsProvider extends ContentProvider { private static final String KEY_SURFACE_PACKAGE = "surface_package"; private static final String KEY_CALLBACK = "callback"; public static final String KEY_HIDE_BOTTOM_ROW = "hide_bottom_row"; + public static final String KEY_GRID_NAME = "grid_name"; private static final int MESSAGE_ID_UPDATE_PREVIEW = 1337; + private static final int MESSAGE_ID_UPDATE_GRID = 7414; /** * Here we use the IBinder and the screen ID as the key of the active previews. @@ -245,11 +248,22 @@ public class GridCustomizationsProvider extends ContentProvider { if (destroyed) { return true; } - if (message.what == MESSAGE_ID_UPDATE_PREVIEW) { - renderer.hideBottomRow(message.getData().getBoolean(KEY_HIDE_BOTTOM_ROW)); - } else { - destroyObserver(this); + + switch (message.what) { + case MESSAGE_ID_UPDATE_PREVIEW: + renderer.hideBottomRow(message.getData().getBoolean(KEY_HIDE_BOTTOM_ROW)); + break; + case MESSAGE_ID_UPDATE_GRID: + String gridName = message.getData().getString(KEY_GRID_NAME); + if (!TextUtils.isEmpty(gridName)) { + renderer.updateGrid(gridName); + } + break; + default: + destroyObserver(this); + break; } + return true; } diff --git a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java index addd0727e8..56c4ca4b37 100644 --- a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java +++ b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java @@ -38,6 +38,7 @@ import android.view.SurfaceControlViewHost; import android.view.SurfaceControlViewHost.SurfacePackage; import android.view.View; import android.view.animation.AccelerateDecelerateInterpolator; +import android.widget.FrameLayout; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -61,6 +62,7 @@ import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.RunnableList; import com.android.launcher3.util.Themes; import com.android.launcher3.widget.LocalColorExtractor; +import com.android.systemui.shared.Flags; import java.util.ArrayList; import java.util.Map; @@ -96,6 +98,7 @@ public class PreviewSurfaceRenderer { private boolean mDestroyed = false; private LauncherPreviewRenderer mRenderer; private boolean mHideQsb; + @Nullable private FrameLayout mViewRoot = null; public PreviewSurfaceRenderer(Context context, Bundle bundle) throws Exception { mContext = context; @@ -193,6 +196,19 @@ public class PreviewSurfaceRenderer { MODEL_EXECUTOR.execute(this::loadModelData); } + /** + * Update the grid of the launcher preview + * + * @param gridName Name of the grid, e.g. normal, practical + */ + public void updateGrid(@NonNull String gridName) { + if (gridName.equals(mGridName)) { + return; + } + mGridName = gridName; + loadAsync(); + } + /** * Hides the components in the bottom row. * @@ -302,11 +318,41 @@ public class PreviewSurfaceRenderer { view.setPivotY(0); view.setTranslationX((mWidth - scale * view.getWidth()) / 2); view.setTranslationY((mHeight - scale * view.getHeight()) / 2); - view.setAlpha(0); - view.animate().alpha(1) - .setInterpolator(new AccelerateDecelerateInterpolator()) - .setDuration(FADE_IN_ANIMATION_DURATION) - .start(); - mSurfaceControlViewHost.setView(view, view.getMeasuredWidth(), view.getMeasuredHeight()); + if (!Flags.newCustomizationPickerUi()) { + view.setAlpha(0); + view.animate().alpha(1) + .setInterpolator(new AccelerateDecelerateInterpolator()) + .setDuration(FADE_IN_ANIMATION_DURATION) + .start(); + mSurfaceControlViewHost.setView( + view, + view.getMeasuredWidth(), + view.getMeasuredHeight() + ); + return; + } + + if (mViewRoot == null) { + mViewRoot = new FrameLayout(inflationContext); + FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams( + FrameLayout.LayoutParams.WRAP_CONTENT, // Width + FrameLayout.LayoutParams.WRAP_CONTENT // Height + ); + mViewRoot.setLayoutParams(layoutParams); + mViewRoot.addView(view); + mViewRoot.setAlpha(0); + mViewRoot.animate().alpha(1) + .setInterpolator(new AccelerateDecelerateInterpolator()) + .setDuration(FADE_IN_ANIMATION_DURATION) + .start(); + mSurfaceControlViewHost.setView( + mViewRoot, + view.getMeasuredWidth(), + view.getMeasuredHeight() + ); + } else { + mViewRoot.removeAllViews(); + mViewRoot.addView(view); + } } }