From f469c4c0061299e24a5d26419c8abc14011c2a19 Mon Sep 17 00:00:00 2001 From: George Lin Date: Wed, 22 Mar 2023 23:44:15 +0000 Subject: [PATCH] [Launcher] Hide preview bottom components when overlay tabs are shown For deciding show/hide of the bottom components, we need to take care of 2 cases 1. When on color update, we need to set the QSB flag and re-render the surface 2. When show/hide the wallpaper control, we specifically send a message to show/hide the workspace bottom components Test: https://drive.google.com/file/d/1z1EG6KsLKFxAlS8GBLV16GoGvwI72IHc/view?usp=sharing&resourcekey=0-OGzB0RmiK5qvV2rwMYvUHQ Test: https://drive.google.com/file/d/1gK54Y5MuHTt2tAuFDxY7z8RIL22J5c9f/view?usp=sharing&resourcekey=0-jPPC1pl1VkCS_tib2-pVxA Test: https://drive.google.com/file/d/1ntUSgD7KbHPDGNpomQ5zE0D2fsYVeuNA/view?usp=sharing&resourcekey=0-TCuuvL4p022ATzKYuF-Q1A Test: https://drive.google.com/file/d/1yA1K52N-orajamnrxWD17Qg7bCclmq53/view?usp=sharing&resourcekey=0-6LHnZGM5JpFQISNJ6X7jEg Bug: 266618769 Change-Id: I428e6f50dc71369aa8fcdee31629023709e6503f --- .../graphics/GridCustomizationsProvider.java | 16 ++++++++++--- .../graphics/LauncherPreviewRenderer.java | 19 +++++++++++++++ .../graphics/PreviewSurfaceRenderer.java | 24 +++++++++++++++---- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/src/com/android/launcher3/graphics/GridCustomizationsProvider.java b/src/com/android/launcher3/graphics/GridCustomizationsProvider.java index 2c8f1f3a2a..ae5d8d489a 100644 --- a/src/com/android/launcher3/graphics/GridCustomizationsProvider.java +++ b/src/com/android/launcher3/graphics/GridCustomizationsProvider.java @@ -66,6 +66,9 @@ 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"; + + private static final int MESSAGE_ID_UPDATE_PREVIEW = 1337; private final ArrayMap mActivePreviews = new ArrayMap<>(); @@ -79,7 +82,7 @@ public class GridCustomizationsProvider extends ContentProvider { String[] selectionArgs, String sortOrder) { switch (uri.getPath()) { case KEY_LIST_OPTIONS: { - MatrixCursor cursor = new MatrixCursor(new String[] { + 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 : idp.parseAllGridOptions(getContext())) { @@ -95,7 +98,7 @@ public class GridCustomizationsProvider extends ContentProvider { } case GET_ICON_THEMED: case ICON_THEMED: { - MatrixCursor cursor = new MatrixCursor(new String[] {BOOLEAN_VALUE}); + MatrixCursor cursor = new MatrixCursor(new String[]{BOOLEAN_VALUE}); cursor.newRow().add(BOOLEAN_VALUE, isThemedIconEnabled(getContext()) ? 1 : 0); return cursor; } @@ -224,7 +227,14 @@ public class GridCustomizationsProvider extends ContentProvider { @Override public boolean handleMessage(Message message) { - destroyObserver(this); + if (destroyed) { + return true; + } + if (message.what == MESSAGE_ID_UPDATE_PREVIEW) { + renderer.hideBottomRow(message.getData().getBoolean(KEY_HIDE_BOTTOM_ROW)); + } else { + destroyObserver(this); + } return true; } diff --git a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java index b061f8f643..7f49aa9cc1 100644 --- a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java +++ b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java @@ -344,6 +344,25 @@ public class LauncherPreviewRenderer extends ContextWrapper return mHotseat; } + /** + * Hides the components in the bottom row. + * + * @param hide True to hide and false to show. + */ + public void hideBottomRow(boolean hide) { + mUiHandler.post(() -> { + if (mDp.isTaskbarPresent) { + // hotseat icons on bottom + mHotseat.setIconsAlpha(hide ? 0 : 1); + if (mDp.isQsbInline) { + mHotseat.setQsbAlpha(hide ? 0 : 1); + } + } else { + mHotseat.setQsbAlpha(hide ? 0 : 1); + } + }); + } + @Override public CellLayout getScreenWithId(int screenId) { return mWorkspaceScreens.get(screenId); diff --git a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java index 85c0a7a565..0767e69378 100644 --- a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java +++ b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java @@ -87,6 +87,8 @@ public class PreviewSurfaceRenderer { private final SurfaceControlViewHost mSurfaceControlViewHost; private boolean mDestroyed = false; + private LauncherPreviewRenderer mRenderer; + private boolean mHideQsb; public PreviewSurfaceRenderer(Context context, Bundle bundle) throws Exception { mContext = context; @@ -97,6 +99,7 @@ public class PreviewSurfaceRenderer { gridName = InvariantDeviceProfile.getCurrentGridName(context); } mWallpaperColors = bundle.getParcelable(KEY_COLORS); + mHideQsb = bundle.getBoolean(GridCustomizationsProvider.KEY_HIDE_BOTTOM_ROW); mIdp = new InvariantDeviceProfile(context, gridName); mHostToken = bundle.getBinder(KEY_HOST_TOKEN); @@ -174,6 +177,17 @@ public class PreviewSurfaceRenderer { MODEL_EXECUTOR.execute(this::loadModelData); } + /** + * Hides the components in the bottom row. + * + * @param hide True to hide and false to show. + */ + public void hideBottomRow(boolean hide) { + if (mRenderer != null) { + mRenderer.hideBottomRow(hide); + } + } + @WorkerThread private void loadModelData() { final boolean migrated = doGridMigrationIfNecessary(); @@ -209,8 +223,8 @@ public class PreviewSurfaceRenderer { DeviceProfile deviceProfile = mIdp.getDeviceProfile(previewContext); String query = LauncherSettings.Favorites.SCREEN + " = " + Workspace.FIRST_SCREEN_ID - + " or " + LauncherSettings.Favorites.CONTAINER + " = " - + LauncherSettings.Favorites.CONTAINER_HOTSEAT; + + " or " + LauncherSettings.Favorites.CONTAINER + " = " + + LauncherSettings.Favorites.CONTAINER_HOTSEAT; if (deviceProfile.isTwoPanels) { query += " or " + LauncherSettings.Favorites.SCREEN + " = " + Workspace.SECOND_SCREEN_ID; @@ -254,8 +268,10 @@ public class PreviewSurfaceRenderer { if (mDestroyed) { return; } - View view = new LauncherPreviewRenderer(inflationContext, mIdp, mWallpaperColors, - launcherWidgetSpanInfo).getRenderedView(dataModel, widgetProviderInfoMap); + mRenderer = new LauncherPreviewRenderer(inflationContext, mIdp, + mWallpaperColors, launcherWidgetSpanInfo); + mRenderer.hideBottomRow(mHideQsb); + View view = mRenderer.getRenderedView(dataModel, widgetProviderInfoMap); // This aspect scales the view to fit in the surface and centers it final float scale = Math.min(mWidth / (float) view.getMeasuredWidth(), mHeight / (float) view.getMeasuredHeight());