Moving bottom sheet variables to their own class
Bug: 419264653 Flag: EXEMPT refactor Test: DeviceProfileDumpTest Test: All Image tests Change-Id: Ibaee4e94e54dbeb2f79ea5c1b6e73415ae219251
This commit is contained in:
1 parent
501df2edca
commit
6dcdd67e23
10 files changed
+151
-65
No files matched your search
@@ -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
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ public class AllAppsState extends LauncherState {
|
||||
protected <DEVICE_PROFILE_CONTEXT extends Context & ActivityContext>
|
||||
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()) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -2623,7 +2623,7 @@ public class Launcher extends StatefulActivity<LauncherState>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,7 +113,8 @@ public class AddItemWidgetsBottomSheet extends AbstractSlideInView<AddItemActivi
|
||||
}
|
||||
|
||||
measureChildWithMargins(mContent, widthMeasureSpec,
|
||||
widthUsed, heightMeasureSpec, deviceProfile.bottomSheetTopPadding);
|
||||
widthUsed, heightMeasureSpec,
|
||||
deviceProfile.getBottomSheetProfile().getBottomSheetTopPadding());
|
||||
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),
|
||||
MeasureSpec.getSize(heightMeasureSpec));
|
||||
}
|
||||
|
||||
@@ -344,7 +344,8 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<BaseActivity>
|
||||
|
||||
DeviceProfile deviceProfile = mActivityContext.getDeviceProfile();
|
||||
measureChildWithMargins(mContent, widthMeasureSpec,
|
||||
widthUsed, heightMeasureSpec, deviceProfile.bottomSheetTopPadding);
|
||||
widthUsed, heightMeasureSpec,
|
||||
deviceProfile.getBottomSheetProfile().getBottomSheetTopPadding());
|
||||
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),
|
||||
MeasureSpec.getSize(heightMeasureSpec));
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user