From 6dcdd67e233a0c894724d3e4df2eed499e4b5374 Mon Sep 17 00:00:00 2001 From: Sebastian Franco Date: Tue, 27 May 2025 11:53:29 -0700 Subject: [PATCH] Moving bottom sheet variables to their own class Bug: 419264653 Flag: EXEMPT refactor Test: DeviceProfileDumpTest Test: All Image tests Change-Id: Ibaee4e94e54dbeb2f79ea5c1b6e73415ae219251 --- .../QuickstepWidgetPickerActivity.java | 2 +- .../uioverrides/QuickstepLauncher.java | 3 +- .../uioverrides/states/AllAppsState.java | 2 +- src/com/android/launcher3/DeviceProfile.java | 78 +++++---------- src/com/android/launcher3/Launcher.java | 2 +- .../deviceprofile/BottomSheetProfile.kt | 94 +++++++++++++++++++ .../widget/AddItemWidgetsBottomSheet.java | 3 +- .../launcher3/widget/BaseWidgetSheet.java | 3 +- .../widget/picker/WidgetsFullSheet.java | 26 ++++- .../widget/picker/WidgetsTwoPaneSheet.java | 3 +- 10 files changed, 151 insertions(+), 65 deletions(-) create mode 100644 src/com/android/launcher3/deviceprofile/BottomSheetProfile.kt diff --git a/quickstep/src/com/android/launcher3/QuickstepWidgetPickerActivity.java b/quickstep/src/com/android/launcher3/QuickstepWidgetPickerActivity.java index d4853bb21d..07a492710f 100644 --- a/quickstep/src/com/android/launcher3/QuickstepWidgetPickerActivity.java +++ b/quickstep/src/com/android/launcher3/QuickstepWidgetPickerActivity.java @@ -355,7 +355,7 @@ public class QuickstepWidgetPickerActivity extends // Bind recommendations once picker has finished open animation. MAIN_EXECUTOR.getHandler().postDelayed( () -> mWidgetPickerDataProvider.setWidgetRecommendations(recommendedWidgets), - mDeviceProfile.bottomSheetOpenDuration); + mDeviceProfile.getBottomSheetProfile().getBottomSheetOpenDuration()); } @Override diff --git a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java index f8a9feffad..8303308a9d 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java +++ b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java @@ -950,7 +950,8 @@ public class QuickstepLauncher extends Launcher implements RecentsViewContainer, onTaskbarInAppDisplayProgressUpdate(progress, WIDGETS_PAGE_PROGRESS_INDEX); if (mEnableWidgetDepth) { getDepthController().widgetDepth.setValue(Utilities.mapToRange( - progress, 0f, 1f, 0f, getDeviceProfile().bottomSheetDepth, EMPHASIZED)); + progress, 0f, 1f, 0f, + getDeviceProfile().getBottomSheetProfile().getBottomSheetDepth(), EMPHASIZED)); } } diff --git a/quickstep/src/com/android/launcher3/uioverrides/states/AllAppsState.java b/quickstep/src/com/android/launcher3/uioverrides/states/AllAppsState.java index d6b7c3dd74..95a43f7d8e 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/states/AllAppsState.java +++ b/quickstep/src/com/android/launcher3/uioverrides/states/AllAppsState.java @@ -134,7 +134,7 @@ public class AllAppsState extends LauncherState { protected float getDepthUnchecked(DEVICE_PROFILE_CONTEXT context) { if (context.getDeviceProfile().shouldShowAllAppsOnSheet()) { - return context.getDeviceProfile().bottomSheetDepth; + return context.getDeviceProfile().getBottomSheetProfile().getBottomSheetDepth(); } else { // The scrim fades in at approximately 50% of the swipe gesture. if (enableScalingRevealHomeAnimation()) { diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index eddbce41b7..4d2552d37b 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -16,8 +16,6 @@ package com.android.launcher3; -import static com.android.app.animation.Interpolators.LINEAR; -import static com.android.launcher3.Flags.enableScalingRevealHomeAnimation; import static com.android.launcher3.InvariantDeviceProfile.INDEX_DEFAULT; import static com.android.launcher3.InvariantDeviceProfile.INDEX_LANDSCAPE; import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_LANDSCAPE; @@ -55,6 +53,7 @@ import androidx.core.content.res.ResourcesCompat; import com.android.launcher3.CellLayout.ContainerType; import com.android.launcher3.DevicePaddings.DevicePadding; import com.android.launcher3.InvariantDeviceProfile.DisplayOptionSpec; +import com.android.launcher3.deviceprofile.BottomSheetProfile; import com.android.launcher3.deviceprofile.DeviceProperties; import com.android.launcher3.deviceprofile.DropTargetProfile; import com.android.launcher3.deviceprofile.OverviewProfile; @@ -88,8 +87,6 @@ public class DeviceProfile { private static final float MIN_FOLDER_TEXT_SIZE_SP = 16f; private static final float MIN_WIDGET_PADDING_DP = 6f; - // Minimum aspect ratio beyond which an extra top padding may be applied to a bottom sheet. - private static final float MIN_ASPECT_RATIO_FOR_EXTRA_TOP_PADDING = 1.5f; private static final float MAX_ASPECT_RATIO_FOR_ALTERNATE_EDIT_STATE = 1.5f; public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f); @@ -98,6 +95,7 @@ public class DeviceProfile { }; public final InvariantDeviceProfile inv; + private final BottomSheetProfile mBottomSheetProfile; private final DisplayOptionSpec mDisplayOptionSpec; private final Info mInfo; private final DisplayMetrics mMetrics; @@ -233,13 +231,6 @@ public class DeviceProfile { // not enough space, the hotseat will adjust itself for the bubble bar. private final int mBubbleBarSpaceThresholdPx; - // Bottom sheets - public int bottomSheetTopPadding; - public int bottomSheetOpenDuration; - public int bottomSheetCloseDuration; - public float bottomSheetWorkspaceScale; - public float bottomSheetDepth; - // All apps public Point allAppsBorderSpacePx; public int allAppsShiftRange; @@ -309,6 +300,7 @@ public class DeviceProfile { false, false ); + mBottomSheetProfile = new BottomSheetProfile(0, 0, 0, 0f, 0f); overviewProfile = new OverviewProfile( 0, 0, @@ -461,43 +453,14 @@ public class DeviceProfile { gridVisualizationPaddingY = res.getDimensionPixelSize( R.dimen.grid_visualization_vertical_cell_spacing); - { - // In large screens, in portrait mode, a bottom sheet can appear too elongated, so, we - // apply additional padding. - final boolean applyExtraTopPadding = mDeviceProperties.isTablet() - && !mDeviceProperties.isLandscape() - && (mDeviceProperties.getAspectRatio() > MIN_ASPECT_RATIO_FOR_EXTRA_TOP_PADDING); - final int derivedTopPadding = mDeviceProperties.getHeightPx() / 6; - bottomSheetTopPadding = mInsets.top // statusbar height - + (applyExtraTopPadding ? derivedTopPadding : 0) - + (mDeviceProperties.isTablet() ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding - } - - bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration); - bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration); - if (shouldShowAllAppsOnSheet()) { - bottomSheetWorkspaceScale = workspaceContentScale; - if (isMultiDisplay) { - // TODO(b/259893832): Revert to use maxWallpaperScale to calculate bottomSheetDepth - // when screen recorder bug is fixed. - if (enableScalingRevealHomeAnimation()) { - bottomSheetDepth = 0.3f; - } else { - bottomSheetDepth = 1f; - } - } else { - // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps. - // When depth is 0, wallpaper zoom is set to maxWallpaperScale. - // When depth is 1, wallpaper zoom is set to 1. - // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale: - float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale); - bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale, - maxWallpaperScale, 1f, 0f, 1f, LINEAR); - } - } else { - bottomSheetWorkspaceScale = 1f; - bottomSheetDepth = 0f; - } + mBottomSheetProfile = BottomSheetProfile.Factory.createBottomSheetProfile( + getDeviceProperties(), + mInsets, + res, + edgeMarginPx, + shouldShowAllAppsOnSheet(), + workspaceContentScale + ); folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale); numFolderRows = inv.numFolderRows[mTypeIndex]; @@ -2267,11 +2230,16 @@ public class DeviceProfile { writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop)); writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx)); - writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding)); - writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration); - writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration); - writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale); - writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth); + writer.println(prefix + pxToDpStr("bottomSheetTopPadding", + getBottomSheetProfile().getBottomSheetTopPadding())); + writer.println(prefix + "\tbottomSheetOpenDuration: " + + getBottomSheetProfile().getBottomSheetOpenDuration()); + writer.println(prefix + "\tbottomSheetCloseDuration: " + + getBottomSheetProfile().getBottomSheetCloseDuration()); + writer.println(prefix + "\tbottomSheetWorkspaceScale: " + + getBottomSheetProfile().getBottomSheetWorkspaceScale()); + writer.println(prefix + "\tbottomSheetDepth: " + + getBottomSheetProfile().getBottomSheetDepth()); writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange)); writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration); @@ -2448,6 +2416,10 @@ public class DeviceProfile { return mDropTargetProfile; } + public BottomSheetProfile getBottomSheetProfile() { + return mBottomSheetProfile; + } + /** * Callback when a component changes the DeviceProfile associated with it, as a result of * configuration change diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 29da72dbaa..8d9dea2de8 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -2623,7 +2623,7 @@ public class Launcher extends StatefulActivity */ public void onWidgetsTransition(float progress) { float scale = Utilities.mapToRange(progress, 0f, 1f, 1f, - mDeviceProfile.bottomSheetWorkspaceScale, EMPHASIZED); + mDeviceProfile.getBottomSheetProfile().getBottomSheetWorkspaceScale(), EMPHASIZED); WORKSPACE_WIDGET_SCALE.set(getWorkspace(), scale); HOTSEAT_WIDGET_SCALE.set(getHotseat(), scale); } diff --git a/src/com/android/launcher3/deviceprofile/BottomSheetProfile.kt b/src/com/android/launcher3/deviceprofile/BottomSheetProfile.kt new file mode 100644 index 0000000000..05c5308deb --- /dev/null +++ b/src/com/android/launcher3/deviceprofile/BottomSheetProfile.kt @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2025 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.deviceprofile + +import android.content.res.Resources +import android.graphics.Rect +import com.android.app.animation.Interpolators.LINEAR +import com.android.launcher3.Flags.enableScalingRevealHomeAnimation +import com.android.launcher3.R +import com.android.launcher3.Utilities + +data class BottomSheetProfile( + val bottomSheetTopPadding: Int, + val bottomSheetOpenDuration: Int, + val bottomSheetCloseDuration: Int, + val bottomSheetWorkspaceScale: Float, + val bottomSheetDepth: Float, +) { + companion object Factory { + + // Minimum aspect ratio beyond which an extra top padding may be applied to a bottom sheet. + private const val MIN_ASPECT_RATIO_FOR_EXTRA_TOP_PADDING: Float = 1.5f + + fun createBottomSheetProfile( + deviceProperties: DeviceProperties, + insets: Rect, + res: Resources, + edgeMarginPx: Int, + shouldShowAllAppsOnSheet: Boolean, + workspaceContentScale: Float, + ): BottomSheetProfile { + + // In large screens, in portrait mode, a bottom sheet can appear too elongated, so, we + // apply additional padding. + val applyExtraTopPadding = + deviceProperties.isTablet && + !deviceProperties.isLandscape && + (deviceProperties.aspectRatio > MIN_ASPECT_RATIO_FOR_EXTRA_TOP_PADDING) + val derivedTopPadding: Int = deviceProperties.heightPx / 6 + val bottomSheetDepth = + when { + !shouldShowAllAppsOnSheet -> 0f + // TODO(b/259893832): Revert to use maxWallpaperScale to calculate + // bottomSheetDepth when screen recorder bug is fixed. + deviceProperties.isMultiDisplay -> + if (enableScalingRevealHomeAnimation()) 0.3f else 1f + // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps + // When depth is 0, wallpaper zoom is set to maxWallpaperScale. + // When depth is 1, wallpaper zoom is set to 1. + // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale: + // TODO(b/420688601) We shouldn't use Interpolator to calculate static variables + else -> { + val maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale) + Utilities.mapToRange( + maxWallpaperScale * workspaceContentScale, + maxWallpaperScale, + 1f, + 0f, + 1f, + LINEAR, + ) + } + } + val bottomSheetTopPadding = + insets.top + // statusbar height + (if (applyExtraTopPadding) derivedTopPadding else 0) + + // phones need edgeMarginPx additional padding + (if (deviceProperties.isTablet) 0 else edgeMarginPx).toInt() + return BottomSheetProfile( + bottomSheetTopPadding = bottomSheetTopPadding, + bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration), + bottomSheetCloseDuration = + res.getInteger(R.integer.config_bottomSheetCloseDuration), + bottomSheetWorkspaceScale = + if (shouldShowAllAppsOnSheet) workspaceContentScale else 1f, + bottomSheetDepth = bottomSheetDepth, + ) + } + } +} diff --git a/src/com/android/launcher3/widget/AddItemWidgetsBottomSheet.java b/src/com/android/launcher3/widget/AddItemWidgetsBottomSheet.java index a6deee5340..cde4001791 100644 --- a/src/com/android/launcher3/widget/AddItemWidgetsBottomSheet.java +++ b/src/com/android/launcher3/widget/AddItemWidgetsBottomSheet.java @@ -113,7 +113,8 @@ public class AddItemWidgetsBottomSheet extends AbstractSlideInView DeviceProfile deviceProfile = mActivityContext.getDeviceProfile(); measureChildWithMargins(mContent, widthMeasureSpec, - widthUsed, heightMeasureSpec, deviceProfile.bottomSheetTopPadding); + widthUsed, heightMeasureSpec, + deviceProfile.getBottomSheetProfile().getBottomSheetTopPadding()); setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize(heightMeasureSpec)); } diff --git a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java index 77efe5e495..99c10b2616 100644 --- a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java +++ b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java @@ -657,7 +657,8 @@ public class WidgetsFullSheet extends BaseWidgetSheet return 0f; } - return (mDeviceProfile.getDeviceProperties().getHeightPx() - mDeviceProfile.bottomSheetTopPadding) + return (mDeviceProfile.getDeviceProperties().getHeightPx() + - mDeviceProfile.getBottomSheetProfile().getBottomSheetTopPadding()) * RECOMMENDATION_TABLE_HEIGHT_RATIO; } @@ -672,13 +673,22 @@ public class WidgetsFullSheet extends BaseWidgetSheet if (getPopupContainer().getInsets().bottom > 0) { mContent.setAlpha(0); } - setUpOpenAnimation(mActivityContext.getDeviceProfile().bottomSheetOpenDuration); + setUpOpenAnimation( + mActivityContext + .getDeviceProfile() + .getBottomSheetProfile() + .getBottomSheetOpenDuration() + ); Animator animator = mOpenCloseAnimation.getAnimationPlayer(); animator.setInterpolator(AnimationUtils.loadInterpolator( getContext(), android.R.interpolator.linear_out_slow_in)); post(() -> { - animator.setDuration(mActivityContext.getDeviceProfile().bottomSheetOpenDuration) - .start(); + animator.setDuration( + mActivityContext + .getDeviceProfile() + .getBottomSheetProfile() + .getBottomSheetOpenDuration() + ).start(); mContent.animate().alpha(1).setDuration(FADE_IN_DURATION); }); } else { @@ -689,7 +699,13 @@ public class WidgetsFullSheet extends BaseWidgetSheet @Override protected void handleClose(boolean animate) { - handleClose(animate, mActivityContext.getDeviceProfile().bottomSheetCloseDuration); + handleClose( + animate, + mActivityContext + .getDeviceProfile() + .getBottomSheetProfile() + .getBottomSheetCloseDuration() + ); } @Override diff --git a/src/com/android/launcher3/widget/picker/WidgetsTwoPaneSheet.java b/src/com/android/launcher3/widget/picker/WidgetsTwoPaneSheet.java index 113d9c0632..460a9aa758 100644 --- a/src/com/android/launcher3/widget/picker/WidgetsTwoPaneSheet.java +++ b/src/com/android/launcher3/widget/picker/WidgetsTwoPaneSheet.java @@ -403,7 +403,8 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet { return Float.MAX_VALUE; } - return (mDeviceProfile.getDeviceProperties().getHeightPx() - mDeviceProfile.bottomSheetTopPadding) + return (mDeviceProfile.getDeviceProperties().getHeightPx() + - mDeviceProfile.getBottomSheetProfile().getBottomSheetTopPadding()) * RECOMMENDATION_SECTION_HEIGHT_RATIO_TWO_PANE; }