blob: 78a3eedb4773770b5aa3aae5e1e22ec395990f9c [file] [log] [blame]
Winson Chungb3800242013-10-24 11:01:54 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.launcher3;
18
Kateryna Ivanova71203732023-05-24 15:09:00 +000019import static com.android.app.animation.Interpolators.LINEAR;
Jordan Silvaf2402e22023-10-26 19:53:16 +010020import static com.android.launcher3.Flags.enableOverviewIconMenu;
Luca Zuccarinic9cbc9d2024-03-11 14:29:48 +000021import static com.android.launcher3.Flags.enableScalingRevealHomeAnimation;
Thales Lima12d0eff2022-03-25 17:06:11 +000022import static com.android.launcher3.InvariantDeviceProfile.INDEX_DEFAULT;
23import static com.android.launcher3.InvariantDeviceProfile.INDEX_LANDSCAPE;
24import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_LANDSCAPE;
25import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_PORTRAIT;
Jon Miranda58561d42021-03-17 10:51:54 -040026import static com.android.launcher3.Utilities.dpiFromPx;
Jon Mirandaaf3aed02021-05-06 18:28:45 -070027import static com.android.launcher3.Utilities.pxFromSp;
Alex Chauab800f72022-12-13 17:46:06 +000028import static com.android.launcher3.config.FeatureFlags.ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH;
Jon Miranda92c1b5d2021-07-20 13:57:16 -070029import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.ICON_OVERLAP_FACTOR;
Sunny Goyal65190ae2022-08-02 14:16:26 -070030import static com.android.launcher3.icons.GraphicsUtils.getShapePath;
Jon Miranda95f44722023-06-06 19:48:19 -070031import static com.android.launcher3.icons.IconNormalizer.ICON_VISIBLE_AREA_FACTOR;
Thales Limab35faed2022-09-05 16:30:01 -030032import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURCE_HANDLE;
Pat Manning5f74bfd2022-07-20 12:08:54 +010033import static com.android.launcher3.testing.shared.ResourceUtils.pxFromDp;
Thales Lima7eee74b2023-03-16 16:00:55 -030034import static com.android.launcher3.testing.shared.ResourceUtils.roundPxValueFromFloat;
Brian Isganitise1eaefd2024-05-21 15:38:08 -040035import static com.android.wm.shell.Flags.enableTinyTaskbar;
Jon Miranda228877d2021-02-09 11:05:00 -050036
Sunny Goyal35c7b192021-04-20 16:51:10 -070037import android.annotation.SuppressLint;
Winson Chungb3800242013-10-24 11:01:54 -070038import android.content.Context;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070039import android.content.res.Configuration;
Winson Chungb3800242013-10-24 11:01:54 -070040import android.content.res.Resources;
Thales Limab35faed2022-09-05 16:30:01 -030041import android.content.res.TypedArray;
Winson Chungb3800242013-10-24 11:01:54 -070042import android.graphics.Point;
Jon Miranda7ae64ff2016-11-21 16:18:46 -080043import android.graphics.PointF;
Winson Chungb3800242013-10-24 11:01:54 -070044import android.graphics.Rect;
Sunny Goyal35c7b192021-04-20 16:51:10 -070045import android.util.DisplayMetrics;
Sunny Goyal65190ae2022-08-02 14:16:26 -070046import android.util.SparseArray;
Sunny Goyal59d086c2018-05-07 17:31:40 -070047import android.view.Surface;
Winson Chungb3800242013-10-24 11:01:54 -070048
Sunny Goyal65190ae2022-08-02 14:16:26 -070049import androidx.annotation.NonNull;
Sihua Mae04aa202022-07-18 12:43:56 -070050import androidx.annotation.Nullable;
fbarone4b0b712024-03-29 14:31:17 -070051import androidx.annotation.VisibleForTesting;
Jon Miranda9c478b62023-03-23 21:38:49 -070052import androidx.core.content.res.ResourcesCompat;
Sunny Goyal65190ae2022-08-02 14:16:26 -070053
Sunny Goyalc13403c2016-11-18 23:44:48 -080054import com.android.launcher3.CellLayout.ContainerType;
Jon Miranda228877d2021-02-09 11:05:00 -050055import com.android.launcher3.DevicePaddings.DevicePadding;
Alex Chaud67ddc42022-09-30 18:15:56 +010056import com.android.launcher3.config.FeatureFlags;
Tony Wickham8912b042018-11-29 15:28:53 -080057import com.android.launcher3.icons.DotRenderer;
Hyunyoung Song48cb7bc2018-09-25 17:03:34 -070058import com.android.launcher3.icons.IconNormalizer;
Sihua Mae04aa202022-07-18 12:43:56 -070059import com.android.launcher3.model.data.ItemInfo;
Jordan Silva999dd2a2023-11-17 19:31:43 +000060import com.android.launcher3.responsive.CalculatedCellSpec;
Thales Limaf8bfb032023-07-24 15:08:05 +010061import com.android.launcher3.responsive.CalculatedHotseatSpec;
Jordan Silvaf2402e22023-10-26 19:53:16 +010062import com.android.launcher3.responsive.CalculatedResponsiveSpec;
63import com.android.launcher3.responsive.HotseatSpecsProvider;
Jordan Silva999dd2a2023-11-17 19:31:43 +000064import com.android.launcher3.responsive.ResponsiveCellSpecsProvider;
Jordan Silvaf2402e22023-10-26 19:53:16 +010065import com.android.launcher3.responsive.ResponsiveSpec.Companion.ResponsiveSpecType;
66import com.android.launcher3.responsive.ResponsiveSpec.DimensionType;
67import com.android.launcher3.responsive.ResponsiveSpecsProvider;
Thales Lima24ceca62023-09-25 16:21:17 -070068import com.android.launcher3.util.CellContentDimensions;
Sunny Goyalfd58da62020-08-11 12:06:49 -070069import com.android.launcher3.util.DisplayController;
70import com.android.launcher3.util.DisplayController.Info;
Thales Lima2759aa32023-06-05 16:25:45 +010071import com.android.launcher3.util.IconSizeSteps;
Thales Limac98b7812023-04-14 15:04:23 +010072import com.android.launcher3.util.ResourceHelper;
Sunny Goyalb46703d2020-05-27 17:52:03 -070073import com.android.launcher3.util.WindowBounds;
Sunny Goyal11117d92024-03-25 16:12:10 -070074import com.android.launcher3.util.window.WindowManagerProxy;
Winson1f064272016-07-18 17:18:02 -070075
Jon Miranda58561d42021-03-17 10:51:54 -040076import java.io.PrintWriter;
Alex Chaue818bcb2022-09-02 17:27:11 +010077import java.util.Locale;
Jon Miranda2b25ded2023-02-02 14:48:45 -080078import java.util.function.Consumer;
Jon Miranda58561d42021-03-17 10:51:54 -040079
Sunny Goyal35c7b192021-04-20 16:51:10 -070080@SuppressLint("NewApi")
Winson Chungb3800242013-10-24 11:01:54 -070081public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070082
Sunny Goyal8b9919d2021-04-07 14:45:17 -070083 private static final int DEFAULT_DOT_SIZE = 100;
Thales Limab35faed2022-09-05 16:30:01 -030084 private static final float MIN_FOLDER_TEXT_SIZE_SP = 16f;
Sunny Goyal6c304b12023-04-10 12:03:04 -070085 private static final float MIN_WIDGET_PADDING_DP = 6f;
Alex Chau206ede92022-08-01 17:46:12 +010086
Shamali Pbe55f822024-01-16 15:07:19 +000087 // Minimum aspect ratio beyond which an extra top padding may be applied to a bottom sheet.
88 private static final float MIN_ASPECT_RATIO_FOR_EXTRA_TOP_PADDING = 1.5f;
fbaron3bb6d4b2024-02-23 10:54:13 -080089 private static final float MAX_ASPECT_RATIO_FOR_ALTERNATE_EDIT_STATE = 1.5f;
Shamali Pbe55f822024-01-16 15:07:19 +000090
Sihua Mae04aa202022-07-18 12:43:56 -070091 public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f);
92 public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE;
Jordan Silvaf2402e22023-10-26 19:53:16 +010093 public static final Consumer<DeviceProfile> DEFAULT_DIMENSION_PROVIDER = dp -> {
94 };
Sihua Mae04aa202022-07-18 12:43:56 -070095
Adam Cohen2e6da152015-05-06 11:42:25 -070096 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070097 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070098 private final DisplayMetrics mMetrics;
Thales Lima2759aa32023-06-05 16:25:45 +010099 private final IconSizeSteps mIconSizeSteps;
Winson Chungbe876472014-05-14 14:15:20 -0700100
Sunny Goyalc6205602015-05-21 20:46:33 -0700101 // Device properties
102 public final boolean isTablet;
Sunny Goyalc6205602015-05-21 20:46:33 -0700103 public final boolean isPhone;
104 public final boolean transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +0000105 public final boolean isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700106 public final boolean isTwoPanels;
Fengjiang Lie90f0982024-03-12 09:36:54 -0700107 public boolean isPredictiveBackSwipe;
Thales Limaa1012902022-01-13 17:58:42 +0000108 public final boolean isQsbInline;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700109
Sunny Goyalc6205602015-05-21 20:46:33 -0700110 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -0700111 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -0800112 public final boolean isMultiWindowMode;
Alex Chau6ed408f2022-03-04 12:58:05 +0000113 public final boolean isGestureMode;
Sunny Goyald70e75a2018-02-22 10:07:32 -0800114
Winson Chung104a4c82023-11-08 18:56:15 +0000115 public final boolean isLeftRightSplit;
116
Sunny Goyal0addbf02020-04-28 14:17:35 -0700117 public final int windowX;
118 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -0700119 public final int widthPx;
120 public final int heightPx;
121 public final int availableWidthPx;
122 public final int availableHeightPx;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800123 public final int rotationHint;
Jon Mirandabba64512019-03-27 10:54:17 -0700124
125 public final float aspectRatio;
126
Thales Lima79456492023-05-23 11:32:22 +0100127 private final boolean mIsScalableGrid;
Thales Lima83bedbf2021-10-05 17:47:39 +0100128 private final int mTypeIndex;
Jon Mirandae126d722021-02-25 10:45:20 -0500129
Thales Limac98b7812023-04-14 15:04:23 +0100130 // Responsive grid
131 private final boolean mIsResponsiveGrid;
Jordan Silva8f7986a2023-11-08 12:11:25 +0000132 private CalculatedResponsiveSpec mResponsiveWorkspaceWidthSpec;
133 private CalculatedResponsiveSpec mResponsiveWorkspaceHeightSpec;
134 private CalculatedResponsiveSpec mResponsiveAllAppsWidthSpec;
135 private CalculatedResponsiveSpec mResponsiveAllAppsHeightSpec;
Jordan Silvaf2402e22023-10-26 19:53:16 +0100136 private CalculatedResponsiveSpec mResponsiveFolderWidthSpec;
137 private CalculatedResponsiveSpec mResponsiveFolderHeightSpec;
Thales Limaf8bfb032023-07-24 15:08:05 +0100138 private CalculatedHotseatSpec mResponsiveHotseatSpec;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000139 private CalculatedCellSpec mResponsiveWorkspaceCellSpec;
140 private CalculatedCellSpec mResponsiveAllAppsCellSpec;
Thales Limac98b7812023-04-14 15:04:23 +0100141
Tony Wickhamd6b40372015-09-23 18:37:57 -0700142 /**
143 * The maximum amount of left/right workspace padding as a percentage of the screen width.
144 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
145 * 7% of the screen width can be used as right padding.
146 */
147 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -0700148
Jon Miranda3f9bab22017-07-28 14:50:17 -0700149 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700150 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda80dda302021-07-28 14:14:59 -0700151 private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252;
152 private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700153
Sunny Goyalc6205602015-05-21 20:46:33 -0700154 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +0100155 public final int desiredWorkspaceHorizontalMarginOriginalPx;
156 public int desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100157 public int gridVisualizationPaddingX;
158 public int gridVisualizationPaddingY;
Thales Lima78d00ad2021-09-30 11:29:06 +0100159 public Point cellLayoutBorderSpaceOriginalPx;
160 public Point cellLayoutBorderSpacePx;
Pat Manning08610ca2022-04-05 21:03:16 +0100161 public Rect cellLayoutPaddingPx = new Rect();
162
Sunny Goyalc6205602015-05-21 20:46:33 -0700163 public final int edgeMarginPx;
Alex Chau0c4e11b2022-07-08 18:41:36 +0100164 public final float workspaceContentScale;
Alex Chau906d8822022-05-23 10:42:25 +0100165 public final int workspaceSpringLoadedMinNextPageVisiblePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700166
Jon Miranda58561d42021-03-17 10:51:54 -0400167 private final int extraSpace;
Thales Lima171ee662022-11-22 15:52:49 +0000168 private int maxEmptySpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500169 public int workspaceTopPadding;
170 public int workspaceBottomPadding;
171
Tony Wickham5edf9e22020-03-27 20:06:52 -0700172 // Workspace page indicator
173 public final int workspacePageIndicatorHeight;
174 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700175
Sunny Goyalc6205602015-05-21 20:46:33 -0700176 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400177 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700178 public int iconSizePx;
179 public int iconTextSizePx;
180 public int iconDrawablePaddingPx;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000181 private int mIconDrawablePaddingOriginalPx;
Thales Lima79456492023-05-23 11:32:22 +0100182 public boolean iconCenterVertically;
Winson Chungb3800242013-10-24 11:01:54 -0700183
Jon Mirandaab3c6812021-06-28 15:42:28 -0700184 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800185 public int cellWidthPx;
186 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700187 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800188
Thales Lima79456492023-05-23 11:32:22 +0100189 public int cellYPaddingPx = -1;
Jon Mirandae126d722021-02-25 10:45:20 -0500190
Sunny Goyalc6205602015-05-21 20:46:33 -0700191 // Folder
Thales Lima1faa4ed2023-12-01 16:48:19 +0000192 public final int numFolderRows;
193 public final int numFolderColumns;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000194 public final float folderLabelTextScale;
Jon Mirandae126d722021-02-25 10:45:20 -0500195 public int folderLabelTextSizePx;
Thales Limab35faed2022-09-05 16:30:01 -0300196 public int folderFooterHeightPx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700197 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700198 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700199
Jon Mirandae126d722021-02-25 10:45:20 -0500200 // Folder content
Jordan Silva637f4eb2023-06-13 11:21:53 +0100201 public Point folderCellLayoutBorderSpacePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500202 public int folderContentPaddingLeftRight;
203 public int folderContentPaddingTop;
204
Jon Mirandabf7d8122016-11-03 15:29:29 -0700205 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700206 public int folderCellWidthPx;
207 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700208
209 // Folder child
210 public int folderChildIconSizePx;
211 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700212 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700213
Sunny Goyalc6205602015-05-21 20:46:33 -0700214 // Hotseat
Thales Lima9938c2f2022-07-25 14:38:16 +0100215 public int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700216 public int hotseatCellHeightPx;
fbarone4b0b712024-03-29 14:31:17 -0700217 private int mHotseatColumnSpan;
218 private int mHotseatWidthPx; // not used in vertical bar layout
Pat Manning26f70f72022-07-07 13:50:39 +0100219 public final boolean areNavButtonsInline;
Jon Miranda18751b62017-07-31 17:25:27 -0700220 // In portrait: size = height, in landscape: size = width
221 public int hotseatBarSizePx;
Thales Limab8c05952022-05-23 16:58:38 +0100222 public int hotseatBarBottomSpacePx;
Pat Manning26f70f72022-07-07 13:50:39 +0100223 public int hotseatBarEndOffset;
Thales Limab8c05952022-05-23 16:58:38 +0100224 public int hotseatQsbSpace;
Pat Manningde25c0d2022-04-05 19:11:26 +0100225 public int springLoadedHotseatBarTopMarginPx;
Thales Lima8e11d532023-08-31 13:40:26 +0000226 // These 2 values are only used for isVerticalBar
227 // Padding between edge of screen and hotseat
228 public final int mHotseatBarEdgePaddingPx;
229 // Space between hotseat and workspace (not used in responsive)
230 public final int mHotseatBarWorkspaceSpacePx;
Alex Chau206ede92022-08-01 17:46:12 +0100231 public int hotseatQsbWidth; // only used when isQsbInline
Sunny Goyal57b22792021-05-25 14:35:01 -0700232 public final int hotseatQsbHeight;
Thales Limab8c05952022-05-23 16:58:38 +0100233 public final int hotseatQsbVisualHeight;
234 private final int hotseatQsbShadowHeight;
Thales Limadd027342022-01-07 12:54:37 +0000235 public int hotseatBorderSpace;
Thales Limaffc68b02023-01-09 16:20:23 +0000236 private final int mMinHotseatIconSpacePx;
237 private final int mMinHotseatQsbWidthPx;
238 private final int mMaxHotseatIconSpacePx;
Jon Mirandae17a9492023-03-08 16:42:20 -0800239 public final int inlineNavButtonsEndSpacingPx;
Liran Binyamina833af32023-08-02 16:30:27 -0400240 // Space required for the bubble bar between the hotseat and the edge of the screen. If there's
241 // not enough space, the hotseat will adjust itself for the bubble bar.
242 private final int mBubbleBarSpaceThresholdPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700243
Alex Chau3d2c0622022-09-01 21:28:14 +0100244 // Bottom sheets
245 public int bottomSheetTopPadding;
246 public int bottomSheetOpenDuration;
247 public int bottomSheetCloseDuration;
248 public float bottomSheetWorkspaceScale;
249 public float bottomSheetDepth;
250
Sunny Goyalc6205602015-05-21 20:46:33 -0700251 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000252 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000253 public int allAppsShiftRange;
Thales Limab433c9c2023-10-30 12:24:05 +0000254 public Rect allAppsPadding = new Rect();
Alex Chau3d2c0622022-09-01 21:28:14 +0100255 public int allAppsOpenDuration;
256 public int allAppsCloseDuration;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700257 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700258 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700259 public int allAppsIconSizePx;
260 public int allAppsIconDrawablePaddingPx;
Alex Chau27b39b92022-01-14 18:02:18 +0000261 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700262 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700263 public float allAppsIconTextSizePx;
264
Zak Cohen334efeb2021-03-19 16:42:07 -0700265 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700266 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000267 public int overviewTaskIconSizePx;
Alex Chauac9df382021-08-02 19:08:41 +0100268 public int overviewTaskIconDrawableSizePx;
269 public int overviewTaskIconDrawableSizeGridPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000270 public int overviewTaskThumbnailTopMarginPx;
Alex Chau19c6eca2022-03-10 20:12:56 +0000271 public final int overviewActionsHeight;
Alex Chaua2fc7642022-04-21 14:20:23 +0100272 public final int overviewActionsTopMarginPx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000273 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100274 public int overviewPageSpacing;
275 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000276 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700277
Jeremy Sim0ac47082022-10-10 13:59:40 -0700278 // Split staging
279 public int splitPlaceholderInset;
280
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800281 // Widgets
Sihua Mae04aa202022-07-18 12:43:56 -0700282 private final ViewScaleProvider mViewScaleProvider;
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800283
Sunny Goyal47328fd2016-05-25 18:56:41 -0700284 // Drop Target
285 public int dropTargetBarSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100286 public int dropTargetBarTopMarginPx;
287 public int dropTargetBarBottomMarginPx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100288 public int dropTargetDragPaddingPx;
289 public int dropTargetTextSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100290 public int dropTargetHorizontalPaddingPx;
291 public int dropTargetVerticalPaddingPx;
292 public int dropTargetGapPx;
Alex Chau5b019302022-05-23 10:42:25 +0100293 public int dropTargetButtonWorkspaceEdgeGapPx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700294
Winson1f064272016-07-18 17:18:02 -0700295 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800296 private final Rect mInsets = new Rect();
297 public final Rect workspacePadding = new Rect();
Sunny Goyal6c304b12023-04-10 12:03:04 -0700298 // Additional padding added to the widget inside its cellSpace. It is applied outside
299 // the widgetView, such that the actual view size is same as the widget size.
300 public final Rect widgetPadding = new Rect();
301
Jon Miranda0bd63d12019-03-06 17:29:29 -0800302 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700303 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700304
Tony Wickhamf34bee82018-12-03 18:11:39 -0800305 // Notification dots
Sunny Goyal65190ae2022-08-02 14:16:26 -0700306 public final DotRenderer mDotRendererWorkSpace;
307 public final DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800308
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100309 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800310 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000311 // Whether Taskbar will inset the bottom of apps by taskbarSize.
312 public boolean isTaskbarPresentInApps;
Jon Miranda9c478b62023-03-23 21:38:49 -0700313 public final int taskbarHeight;
314 public final int stashedTaskbarHeight;
315 public final int taskbarBottomMargin;
316 public final int taskbarIconSize;
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000317 private final int mTransientTaskbarClaimedSpace;
Jon Miranda04f05102023-04-04 12:16:31 -0700318 // If true, used to layout taskbar in 3 button navigation mode.
319 public final boolean startAlignTaskbar;
Thales Limae9566402023-08-30 16:35:12 +0100320 public final boolean isTransientTaskbar;
Alex Chaua02eddc2021-04-29 00:36:06 +0100321 // DragController
322 public int flingToDeleteThresholdVelocity;
323
Vinit Nayak17c4b332021-08-05 12:54:58 -0700324 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700325 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal65190ae2022-08-02 14:16:26 -0700326 SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
Alex Chauab800f72022-12-13 17:46:06 +0000327 boolean transposeLayoutWithOrientation, boolean isMultiDisplay, boolean isGestureMode,
Jon Miranda2b25ded2023-02-02 14:48:45 -0800328 @NonNull final ViewScaleProvider viewScaleProvider,
Jagrut Desai3a7d1392023-09-06 15:56:19 -0700329 @NonNull final Consumer<DeviceProfile> dimensionOverrideProvider,
330 boolean isTransientTaskbar) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700331
Adam Cohen2e6da152015-05-06 11:42:25 -0700332 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700333 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800334 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500335 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +0000336 this.isMultiDisplay = isMultiDisplay;
Alex Chau6ed408f2022-03-04 12:58:05 +0000337 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700338 windowX = windowBounds.bounds.left;
339 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800340 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100341 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700342
Thales Limac98b7812023-04-14 15:04:23 +0100343 // TODO(b/241386436): shouldn't change any launcher behaviour
Thales Limaabfe3642023-05-24 18:08:53 +0100344 mIsResponsiveGrid = inv.workspaceSpecsId != INVALID_RESOURCE_HANDLE
Jordan Silva637f4eb2023-06-13 11:21:53 +0100345 && inv.allAppsSpecsId != INVALID_RESOURCE_HANDLE
Thales Limaf8bfb032023-07-24 15:08:05 +0100346 && inv.folderSpecsId != INVALID_RESOURCE_HANDLE
Jordan Silva999dd2a2023-11-17 19:31:43 +0000347 && inv.hotseatSpecsId != INVALID_RESOURCE_HANDLE
348 && inv.workspaceCellSpecsId != INVALID_RESOURCE_HANDLE
349 && inv.allAppsCellSpecsId != INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100350
Thales Lima79456492023-05-23 11:32:22 +0100351 mIsScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000352 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700353 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000354 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700355 isPhone = !isTablet;
Alex Chauab800f72022-12-13 17:46:06 +0000356 isTwoPanels = isTablet && isMultiDisplay;
Brian Isganitise1eaefd2024-05-21 15:38:08 -0400357 isTaskbarPresent = (isTablet || (enableTinyTaskbar() && isGestureMode))
Sunny Goyal11117d92024-03-25 16:12:10 -0700358 && WindowManagerProxy.INSTANCE.get(context).isTaskbarDrawnInProcess();
Adam Cohen2e6da152015-05-06 11:42:25 -0700359
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000360 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000361 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700362 ? Configuration.ORIENTATION_LANDSCAPE
363 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000364 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700365 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000366 mMetrics = res.getDisplayMetrics();
367
Charlie Anderson7bb10972023-11-22 13:35:30 -0800368 mIconSizeSteps = new IconSizeSteps(res);
Thales Lima2759aa32023-06-05 16:25:45 +0100369
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000370 // Determine sizes.
371 widthPx = windowBounds.bounds.width();
372 heightPx = windowBounds.bounds.height();
373 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100374 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000375
376 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Thales Lima83bedbf2021-10-05 17:47:39 +0100377 if (isTwoPanels) {
378 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000379 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100380 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000381 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100382 }
383 } else {
384 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000385 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100386 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000387 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100388 }
389 }
390
Jagrut Desai3a7d1392023-09-06 15:56:19 -0700391 this.isTransientTaskbar = isTransientTaskbar;
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000392 int transientTaskbarIconSize = pxFromDp(inv.transientTaskbarIconSize[mTypeIndex], mMetrics);
393 int transientTaskbarBottomMargin =
394 res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin);
395 int transientTaskbarHeight =
396 Math.round((transientTaskbarIconSize * ICON_VISIBLE_AREA_FACTOR)
Jordan Silvaf2402e22023-10-26 19:53:16 +0100397 + (2 * res.getDimensionPixelSize(R.dimen.transient_taskbar_padding)));
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000398 mTransientTaskbarClaimedSpace = transientTaskbarHeight + 2 * transientTaskbarBottomMargin;
399
Uwais Ashraf3602d172023-09-15 11:36:32 +0000400 if (!isTaskbarPresent) {
401 taskbarIconSize = taskbarHeight = stashedTaskbarHeight = taskbarBottomMargin = 0;
402 startAlignTaskbar = false;
403 } else if (isTransientTaskbar) {
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000404 taskbarIconSize = transientTaskbarIconSize;
405 taskbarHeight = transientTaskbarHeight;
Jon Miranda9c478b62023-03-23 21:38:49 -0700406 stashedTaskbarHeight =
407 res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_height);
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000408 taskbarBottomMargin = transientTaskbarBottomMargin;
Jon Miranda04f05102023-04-04 12:16:31 -0700409 startAlignTaskbar = false;
Jon Miranda9c478b62023-03-23 21:38:49 -0700410 } else {
411 taskbarIconSize = pxFromDp(ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size),
412 mMetrics);
413 taskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_size);
414 stashedTaskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
415 taskbarBottomMargin = 0;
Jon Miranda04f05102023-04-04 12:16:31 -0700416 startAlignTaskbar = inv.startAlignTaskbar[mTypeIndex];
Tony Wickham15883892021-02-12 11:24:40 -0800417 }
Tony Wickham15883892021-02-12 11:24:40 -0800418
Winson Chungb3800242013-10-24 11:01:54 -0700419 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100420 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700421
Alex Chau51da2192022-05-20 13:32:10 +0100422 gridVisualizationPaddingX = res.getDimensionPixelSize(
423 R.dimen.grid_visualization_horizontal_cell_spacing);
424 gridVisualizationPaddingY = res.getDimensionPixelSize(
425 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500426
Shamali P5fbb0cc2024-02-06 23:05:35 +0000427 {
428 // In large screens, in portrait mode, a bottom sheet can appear too elongated, so, we
429 // apply additional padding.
430 final boolean applyExtraTopPadding = isTablet
431 && !isLandscape
432 && (aspectRatio > MIN_ASPECT_RATIO_FOR_EXTRA_TOP_PADDING);
433 final int derivedTopPadding = heightPx / 6;
434 bottomSheetTopPadding = mInsets.top // statusbar height
435 + (applyExtraTopPadding ? derivedTopPadding : 0)
436 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
437 }
438
Alex Chau3d2c0622022-09-01 21:28:14 +0100439 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
440 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
441 if (isTablet) {
442 bottomSheetWorkspaceScale = workspaceContentScale;
Alex Chauab800f72022-12-13 17:46:06 +0000443 if (isMultiDisplay && !ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH.get()) {
444 // TODO(b/259893832): Revert to use maxWallpaperScale to calculate bottomSheetDepth
445 // when screen recorder bug is fixed.
Luca Zuccarinic9cbc9d2024-03-11 14:29:48 +0000446 if (enableScalingRevealHomeAnimation()) {
447 bottomSheetDepth = 0.3f;
448 } else {
449 bottomSheetDepth = 1f;
450 }
Alex Chauab800f72022-12-13 17:46:06 +0000451 } else {
452 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
453 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
454 // When depth is 1, wallpaper zoom is set to 1.
455 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
456 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
457 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
458 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
459 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100460 } else {
461 bottomSheetWorkspaceScale = 1f;
462 bottomSheetDepth = 0f;
463 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000464
Jon Mirandae126d722021-02-25 10:45:20 -0500465 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
Thales Lima1faa4ed2023-12-01 16:48:19 +0000466 numFolderRows = inv.numFolderRows[mTypeIndex];
467 numFolderColumns = inv.numFolderColumns[mTypeIndex];
Thales Limab35faed2022-09-05 16:30:01 -0300468
Thales Lima79456492023-05-23 11:32:22 +0100469 if (mIsScalableGrid && inv.folderStyle != INVALID_RESOURCE_HANDLE) {
Thales Limab35faed2022-09-05 16:30:01 -0300470 TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
Thales Limad852d652023-01-17 14:01:13 +0000471 R.styleable.FolderStyle);
Thales Limab35faed2022-09-05 16:30:01 -0300472 // These are re-set in #updateFolderCellSize if the grid is not scalable
473 folderCellHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000474 R.styleable.FolderStyle_folderCellHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300475 folderCellWidthPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000476 R.styleable.FolderStyle_folderCellWidth, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300477
478 folderContentPaddingTop = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000479 R.styleable.FolderStyle_folderTopPadding, 0);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100480
481 int gutter = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000482 R.styleable.FolderStyle_folderBorderSpace, 0);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100483 folderCellLayoutBorderSpacePx = new Point(gutter, gutter);
Thales Limab35faed2022-09-05 16:30:01 -0300484 folderFooterHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000485 R.styleable.FolderStyle_folderFooterHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300486 folderStyle.recycle();
Jordan Silva637f4eb2023-06-13 11:21:53 +0100487 } else if (!mIsResponsiveGrid) {
488 folderCellLayoutBorderSpacePx = new Point(0, 0);
Thales Lima7eee74b2023-03-16 16:00:55 -0300489 folderFooterHeightPx = res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Thales Limab35faed2022-09-05 16:30:01 -0300490 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
491 }
Jon Mirandae126d722021-02-25 10:45:20 -0500492
Thales Lima85c942f2021-12-31 13:04:20 +0000493 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000494 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
495 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Thales Limae9273ea2023-01-26 12:33:52 +0000496 setupAllAppsStyle(context);
Jon Mirandae126d722021-02-25 10:45:20 -0500497
Tony Wickham5edf9e22020-03-27 20:06:52 -0700498 workspacePageIndicatorHeight = res.getDimensionPixelSize(
499 R.dimen.workspace_page_indicator_height);
500 mWorkspacePageIndicatorOverlapWorkspace =
501 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700502
Jordan Silva999dd2a2023-11-17 19:31:43 +0000503 if (!mIsResponsiveGrid) {
504 TypedArray cellStyle;
505 if (inv.cellStyle != INVALID_RESOURCE_HANDLE) {
506 cellStyle = context.obtainStyledAttributes(inv.cellStyle,
507 R.styleable.CellStyle);
508 } else {
509 cellStyle = context.obtainStyledAttributes(R.style.CellStyleDefault,
510 R.styleable.CellStyle);
511 }
512 mIconDrawablePaddingOriginalPx = cellStyle.getDimensionPixelSize(
513 R.styleable.CellStyle_iconDrawablePadding, 0);
514 cellStyle.recycle();
Thales Limad852d652023-01-17 14:01:13 +0000515 }
Alex Chaua02eddc2021-04-29 00:36:06 +0100516
Sunny Goyal47328fd2016-05-25 18:56:41 -0700517 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
fbaron3bb6d4b2024-02-23 10:54:13 -0800518 // Some foldable portrait modes are too wide in terms of aspect ratio so we need to tweak
519 // the dimensions for edit state.
520 final boolean shouldApplyWidePortraitDimens = isTablet
521 && !isLandscape
522 && aspectRatio < MAX_ASPECT_RATIO_FOR_ALTERNATE_EDIT_STATE;
523 dropTargetBarTopMarginPx = shouldApplyWidePortraitDimens
524 ? 0
525 : res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
526 dropTargetBarBottomMarginPx = shouldApplyWidePortraitDimens
527 ? res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin_wide_portrait)
528 : res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100529 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
530 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100531 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
532 R.dimen.drop_target_button_drawable_horizontal_padding);
533 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
534 R.dimen.drop_target_button_drawable_vertical_padding);
535 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100536 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
537 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100538
Alex Chau906d8822022-05-23 10:42:25 +0100539 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
540 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700541
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700542 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700543
Thales Limaa1012902022-01-13 17:58:42 +0000544 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100545 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
546 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
547
Thales Lima12d0eff2022-03-25 17:06:11 +0000548 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
549 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
550 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
551 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
552 && hotseatQsbHeight > 0;
Thales Lima79456492023-05-23 11:32:22 +0100553 isQsbInline = mIsScalableGrid && inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000554
Thales Lima425f6822022-05-10 13:44:58 -0300555 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100556 numShownHotseatIcons =
557 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
fbarone4b0b712024-03-29 14:31:17 -0700558 mHotseatColumnSpan = inv.numColumns;
Alex Chau6ed408f2022-03-04 12:58:05 +0000559
Sunny Goyal19ff7282021-04-22 10:12:54 -0700560 numShownAllAppsColumns =
561 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100562
Thales Lima8e11d532023-08-31 13:40:26 +0000563 int hotseatBarBottomSpace;
Thales Limab8c05952022-05-23 16:58:38 +0100564 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
Thales Limaf8bfb032023-07-24 15:08:05 +0100565
566 if (mIsResponsiveGrid) {
Jordan Silvaf2402e22023-10-26 19:53:16 +0100567 float responsiveAspectRatio = (float) widthPx / heightPx;
568 HotseatSpecsProvider hotseatSpecsProvider =
569 HotseatSpecsProvider.create(new ResourceHelper(context,
Thales Limaf8bfb032023-07-24 15:08:05 +0100570 isTwoPanels ? inv.hotseatSpecsTwoPanelId : inv.hotseatSpecsId));
Thales Lima8e11d532023-08-31 13:40:26 +0000571 mResponsiveHotseatSpec =
Jordan Silvaf2402e22023-10-26 19:53:16 +0100572 isVerticalBarLayout() ? hotseatSpecsProvider.getCalculatedSpec(
573 responsiveAspectRatio, DimensionType.WIDTH, widthPx)
574 : hotseatSpecsProvider.getCalculatedSpec(responsiveAspectRatio,
575 DimensionType.HEIGHT, heightPx);
Thales Limaf8bfb032023-07-24 15:08:05 +0100576 hotseatQsbSpace = mResponsiveHotseatSpec.getHotseatQsbSpace();
Thales Lima8e11d532023-08-31 13:40:26 +0000577 hotseatBarBottomSpace =
578 isVerticalBarLayout() ? 0 : mResponsiveHotseatSpec.getEdgePadding();
579 mHotseatBarEdgePaddingPx =
580 isVerticalBarLayout() ? mResponsiveHotseatSpec.getEdgePadding() : 0;
581 mHotseatBarWorkspaceSpacePx = 0;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000582
583 ResponsiveCellSpecsProvider workspaceCellSpecs = ResponsiveCellSpecsProvider.create(
584 new ResourceHelper(context,
585 isTwoPanels ? inv.workspaceCellSpecsTwoPanelId
586 : inv.workspaceCellSpecsId));
587 mResponsiveWorkspaceCellSpec = workspaceCellSpecs.getCalculatedSpec(
588 responsiveAspectRatio, heightPx);
Thales Limaf8bfb032023-07-24 15:08:05 +0100589 } else {
590 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
Thales Lima8e11d532023-08-31 13:40:26 +0000591 hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
592 mHotseatBarEdgePaddingPx =
593 isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
594 mHotseatBarWorkspaceSpacePx =
595 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Thales Limaf8bfb032023-07-24 15:08:05 +0100596 }
597
Thales Lima8e11d532023-08-31 13:40:26 +0000598 if (!isVerticalBarLayout()) {
599 // Have a little space between the inset and the QSB
600 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
601 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
Thales Limab8c05952022-05-23 16:58:38 +0100602
Thales Lima8e11d532023-08-31 13:40:26 +0000603 // Only change the spaces if there is space
604 if (availableSpace > 0) {
605 // Make sure there is enough space between hotseat/QSB and QSB/navBar
606 if (availableSpace < minQsbMargin * 2) {
607 minQsbMargin = availableSpace / 2;
608 hotseatQsbSpace = minQsbMargin;
609 } else {
610 hotseatQsbSpace -= minQsbMargin;
611 }
Thales Limab8c05952022-05-23 16:58:38 +0100612 }
Thales Lima8e11d532023-08-31 13:40:26 +0000613 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
Thales Limab8c05952022-05-23 16:58:38 +0100614
Thales Lima8e11d532023-08-31 13:40:26 +0000615 } else {
616 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
617 }
Thales Limaa1012902022-01-13 17:58:42 +0000618 }
Thales Lima425f6822022-05-10 13:44:58 -0300619
fbaron3bb6d4b2024-02-23 10:54:13 -0800620 springLoadedHotseatBarTopMarginPx = shouldApplyWidePortraitDimens
621 ? res.getDimensionPixelSize(R.dimen.spring_loaded_hotseat_top_margin_wide_portrait)
622 : res.getDimensionPixelSize(R.dimen.spring_loaded_hotseat_top_margin);
Jordan Silva999dd2a2023-11-17 19:31:43 +0000623
624 if (mIsResponsiveGrid) {
625 updateHotseatSizes(mResponsiveWorkspaceCellSpec.getIconSize());
626 } else {
627 updateHotseatSizes(pxFromDp(inv.iconSize[mTypeIndex], mMetrics));
628 }
629
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700630 if (areNavButtonsInline && !isPhone) {
Jon Mirandae17a9492023-03-08 16:42:20 -0800631 inlineNavButtonsEndSpacingPx =
Thales Limaffc68b02023-01-09 16:20:23 +0000632 res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing);
Pat Manning26f70f72022-07-07 13:50:39 +0100633 /*
634 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700635 * Spacing between nav buttons +
Thales Lima6a590062022-11-22 15:52:49 +0000636 * Space at the end for contextual buttons
Pat Manning26f70f72022-07-07 13:50:39 +0100637 */
638 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700639 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
Jon Mirandae17a9492023-03-08 16:42:20 -0800640 + inlineNavButtonsEndSpacingPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100641 } else {
Jon Mirandae17a9492023-03-08 16:42:20 -0800642 inlineNavButtonsEndSpacingPx = 0;
Pat Manning26f70f72022-07-07 13:50:39 +0100643 hotseatBarEndOffset = 0;
644 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700645
Liran Binyamina833af32023-08-02 16:30:27 -0400646 mBubbleBarSpaceThresholdPx =
647 res.getDimensionPixelSize(R.dimen.bubblebar_hotseat_adjustment_threshold);
648
Thales Lima79456492023-05-23 11:32:22 +0100649 // Needs to be calculated after hotseatBarSizePx is correct,
650 // for the available height to be correct
651 if (mIsResponsiveGrid) {
Thales Lima2759aa32023-06-05 16:25:45 +0100652 int availableResponsiveWidth =
653 availableWidthPx - (isVerticalBarLayout() ? hotseatBarSizePx : 0);
Jordan Silva376036a2023-11-08 15:56:40 +0000654 int numWorkspaceColumns = getPanelCount() * inv.numColumns;
Thales Lima8e11d532023-08-31 13:40:26 +0000655 // don't use availableHeightPx because it subtracts mInsets.bottom
656 int availableResponsiveHeight = heightPx - mInsets.top
Jordan Silvaf2402e22023-10-26 19:53:16 +0100657 - (isVerticalBarLayout() ? 0 : hotseatBarSizePx);
658 float responsiveAspectRatio = (float) widthPx / heightPx;
Thales Limaabfe3642023-05-24 18:08:53 +0100659
Jordan Silvaf2402e22023-10-26 19:53:16 +0100660 ResponsiveSpecsProvider workspaceSpecs = ResponsiveSpecsProvider.create(
Jordan Silva575c3bd2023-07-21 12:00:43 +0100661 new ResourceHelper(context,
Jordan Silvaf2402e22023-10-26 19:53:16 +0100662 isTwoPanels ? inv.workspaceSpecsTwoPanelId : inv.workspaceSpecsId),
663 ResponsiveSpecType.Workspace);
Jordan Silva8f7986a2023-11-08 12:11:25 +0000664 mResponsiveWorkspaceWidthSpec = workspaceSpecs.getCalculatedSpec(responsiveAspectRatio,
Jordan Silva376036a2023-11-08 15:56:40 +0000665 DimensionType.WIDTH, numWorkspaceColumns, availableResponsiveWidth);
Jordan Silva8f7986a2023-11-08 12:11:25 +0000666 mResponsiveWorkspaceHeightSpec = workspaceSpecs.getCalculatedSpec(responsiveAspectRatio,
Jordan Silvaf2402e22023-10-26 19:53:16 +0100667 DimensionType.HEIGHT, inv.numRows, availableResponsiveHeight);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100668
Jordan Silvaf2402e22023-10-26 19:53:16 +0100669 ResponsiveSpecsProvider allAppsSpecs = ResponsiveSpecsProvider.create(
Jordan Silva575c3bd2023-07-21 12:00:43 +0100670 new ResourceHelper(context,
Jordan Silvaf2402e22023-10-26 19:53:16 +0100671 isTwoPanels ? inv.allAppsSpecsTwoPanelId : inv.allAppsSpecsId),
672 ResponsiveSpecType.AllApps);
Jordan Silva8f7986a2023-11-08 12:11:25 +0000673 mResponsiveAllAppsWidthSpec = allAppsSpecs.getCalculatedSpec(responsiveAspectRatio,
Jordan Silva8b3fa142023-11-13 21:31:38 +0000674 DimensionType.WIDTH, numShownAllAppsColumns, availableWidthPx,
Jordan Silva8f7986a2023-11-08 12:11:25 +0000675 mResponsiveWorkspaceWidthSpec);
676 mResponsiveAllAppsHeightSpec = allAppsSpecs.getCalculatedSpec(responsiveAspectRatio,
Jordan Silva2de6a272024-01-04 14:44:20 -0300677 DimensionType.HEIGHT, inv.numAllAppsRowsForCellHeightCalculation,
678 heightPx - mInsets.top, mResponsiveWorkspaceHeightSpec);
Jordan Silvaf2402e22023-10-26 19:53:16 +0100679
680 ResponsiveSpecsProvider folderSpecs = ResponsiveSpecsProvider.create(
681 new ResourceHelper(context,
682 isTwoPanels ? inv.folderSpecsTwoPanelId : inv.folderSpecsId),
683 ResponsiveSpecType.Folder);
684 mResponsiveFolderWidthSpec = folderSpecs.getCalculatedSpec(responsiveAspectRatio,
Thales Lima1faa4ed2023-12-01 16:48:19 +0000685 DimensionType.WIDTH, numFolderColumns,
Jordan Silva8f7986a2023-11-08 12:11:25 +0000686 mResponsiveWorkspaceWidthSpec.getAvailableSpace(),
687 mResponsiveWorkspaceWidthSpec);
Jordan Silvaf2402e22023-10-26 19:53:16 +0100688 mResponsiveFolderHeightSpec = folderSpecs.getCalculatedSpec(responsiveAspectRatio,
Thales Lima1faa4ed2023-12-01 16:48:19 +0000689 DimensionType.HEIGHT, numFolderRows,
Jordan Silva8f7986a2023-11-08 12:11:25 +0000690 mResponsiveWorkspaceHeightSpec.getAvailableSpace(),
691 mResponsiveWorkspaceHeightSpec);
Jordan Silva999dd2a2023-11-17 19:31:43 +0000692
693 ResponsiveCellSpecsProvider allAppsCellSpecs = ResponsiveCellSpecsProvider.create(
694 new ResourceHelper(context,
695 isTwoPanels ? inv.allAppsCellSpecsTwoPanelId
696 : inv.allAppsCellSpecsId));
697 mResponsiveAllAppsCellSpec = allAppsCellSpecs.getCalculatedSpec(
698 responsiveAspectRatio,
699 mResponsiveAllAppsHeightSpec.getAvailableSpace(),
700 mResponsiveWorkspaceCellSpec);
Thales Lima79456492023-05-23 11:32:22 +0100701 }
702
703 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
704 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
705
Alex Chau635b3ab2022-01-26 16:49:10 +0000706 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Pat Manning1695cc72023-07-05 11:45:13 +0100707 overviewTaskIconSizePx = enableOverviewIconMenu() ? res.getDimensionPixelSize(
708 R.dimen.task_thumbnail_icon_menu_drawable_touch_size) : res.getDimensionPixelSize(
709 R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100710 overviewTaskIconDrawableSizePx =
711 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
712 overviewTaskIconDrawableSizeGridPx =
713 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Pat Manning1695cc72023-07-05 11:45:13 +0100714 overviewTaskThumbnailTopMarginPx =
715 enableOverviewIconMenu() ? 0 : overviewTaskIconSizePx + overviewTaskMarginPx;
Andy Wickhambc3bac42023-08-07 16:02:23 -0700716 // Don't add margin with floating search bar to minimize risk of overlapping.
717 overviewActionsTopMarginPx = FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get() ? 0
718 : res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000719 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
720 overviewActionsButtonSpacing = res.getDimensionPixelSize(
721 R.dimen.overview_actions_button_spacing);
Andy Wickhambc3bac42023-08-07 16:02:23 -0700722 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700723 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000724 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700725
Jeremy Sim0ac47082022-10-10 13:59:40 -0700726 splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset);
Winson Chung104a4c82023-11-08 18:56:15 +0000727 // We need to use the full window bounds for split determination because on near-square
728 // devices, the available bounds (bounds minus insets) may actually be in landscape while
729 // actually portrait
730 int leftRightSplitPortraitResId = Resources.getSystem().getIdentifier(
731 "config_leftRightSplitInPortrait", "bool", "android");
732 boolean allowLeftRightSplitInPortrait =
733 com.android.wm.shell.Flags.enableLeftRightSplitInPortrait()
734 && leftRightSplitPortraitResId > 0
735 && res.getBoolean(leftRightSplitPortraitResId);
736 if (allowLeftRightSplitInPortrait && isTablet) {
737 isLeftRightSplit = !isLandscape;
738 } else {
739 isLeftRightSplit = isLandscape;
740 }
Jeremy Sim0ac47082022-10-10 13:59:40 -0700741
Jon Miranda2ed276e2017-06-29 11:36:34 -0700742 // Calculate all of the remaining variables.
Brandon Dayauon5787a272023-12-14 13:47:17 -0800743 extraSpace = updateAvailableDimensions(context);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700744
Thales Lima79456492023-05-23 11:32:22 +0100745 calculateAndSetWorkspaceVerticalPadding(context, inv, extraSpace);
Pat Manning08610ca2022-04-05 21:03:16 +0100746
747 int cellLayoutPadding =
748 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
749 R.dimen.cell_layout_padding);
750 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
751 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800752 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800753
Thales Lima7eee74b2023-03-16 16:00:55 -0300754 // Folder scaling requires correct workspace paddings
755 updateAvailableFolderCellDimensions(res);
756
Thales Limaffc68b02023-01-09 16:20:23 +0000757 mMinHotseatIconSpacePx = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
758 mMinHotseatQsbWidthPx = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
759 mMaxHotseatIconSpacePx = areNavButtonsInline
Thales Lima6a590062022-11-22 15:52:49 +0000760 ? res.getDimensionPixelSize(R.dimen.max_hotseat_icon_space) : Integer.MAX_VALUE;
Thales Lima425f6822022-05-10 13:44:58 -0300761 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima6a590062022-11-22 15:52:49 +0000762 recalculateHotseatWidthAndBorderSpace();
Alex Chau206ede92022-08-01 17:46:12 +0100763
Jordan Silva3646a1b2023-08-02 13:52:52 +0100764 if (mIsResponsiveGrid && isVerticalBarLayout()) {
765 hotseatBorderSpace = cellLayoutBorderSpacePx.y;
766 }
767
Alex Chau206ede92022-08-01 17:46:12 +0100768 if (isTablet) {
Andy Wickham99d7d4f2023-11-15 08:09:09 +0000769 allAppsPadding.top = mInsets.top;
770 allAppsShiftRange = heightPx;
Alex Chau206ede92022-08-01 17:46:12 +0100771 } else {
Thales Limab433c9c2023-10-30 12:24:05 +0000772 allAppsPadding.top = 0;
Alex Chau206ede92022-08-01 17:46:12 +0100773 allAppsShiftRange =
774 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
775 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100776 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
777 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300778
Alex Chaua02eddc2021-04-29 00:36:06 +0100779 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
780 R.dimen.drag_flingToDeleteMinVelocity);
781
Sihua Mae04aa202022-07-18 12:43:56 -0700782 mViewScaleProvider = viewScaleProvider;
783
Jon Miranda2b25ded2023-02-02 14:48:45 -0800784 dimensionOverrideProvider.accept(this);
785
Tony Wickham1237df02017-02-24 08:59:36 -0800786 // This is done last, after iconSizePx is calculated above.
Sunny Goyal799e1202023-02-09 10:54:28 -0800787 mDotRendererWorkSpace = createDotRenderer(context, iconSizePx, dotRendererCache);
788 mDotRendererAllApps = createDotRenderer(context, allAppsIconSizePx, dotRendererCache);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700789 }
790
791 private static DotRenderer createDotRenderer(
Sunny Goyal799e1202023-02-09 10:54:28 -0800792 @NonNull Context context, int size, @NonNull SparseArray<DotRenderer> cache) {
Sunny Goyal65190ae2022-08-02 14:16:26 -0700793 DotRenderer renderer = cache.get(size);
794 if (renderer == null) {
Sunny Goyal799e1202023-02-09 10:54:28 -0800795 renderer = new DotRenderer(size, getShapePath(context, DEFAULT_DOT_SIZE),
796 DEFAULT_DOT_SIZE);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700797 cache.put(size, renderer);
798 }
799 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700800 }
801
Thales Lima425f6822022-05-10 13:44:58 -0300802 /**
Fengjiang Li6c590822023-09-25 15:04:57 -0700803 * Return maximum of all apps row count displayed on screen. Note that 1) Partially displayed
804 * row is counted as 1 row, and 2) we don't exclude the space of floating search bar. This
805 * method is used for calculating number of {@link BubbleTextView} we need to pre-inflate. Thus
806 * reasonable over estimation is fine.
807 */
808 public int getMaxAllAppsRowCount() {
Thales Limab433c9c2023-10-30 12:24:05 +0000809 return (int) (Math.ceil((availableHeightPx - allAppsPadding.top)
Fengjiang Li6c590822023-09-25 15:04:57 -0700810 / (float) allAppsCellHeightPx));
811 }
812
813 /**
Thales Lima425f6822022-05-10 13:44:58 -0300814 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
815 * width of the hotseat.
816 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100817 private int calculateQsbWidth(int hotseatBorderSpace) {
fbarone69b6f42023-12-18 13:20:34 -0800818 int iconExtraSpacePx = iconSizePx - getIconVisibleSizePx(iconSizePx);
Thales Lima425f6822022-05-10 13:44:58 -0300819 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100820 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300821 return getIconToIconWidthForColumns(columns)
822 - iconSizePx * numShownHotseatIcons
fbarone69b6f42023-12-18 13:20:34 -0800823 - hotseatBorderSpace * numShownHotseatIcons
824 - iconExtraSpacePx;
Thales Lima425f6822022-05-10 13:44:58 -0300825 } else {
fbarone4b0b712024-03-29 14:31:17 -0700826 return getIconToIconWidthForColumns(mHotseatColumnSpan) - iconExtraSpacePx;
Thales Lima425f6822022-05-10 13:44:58 -0300827 }
828 }
Thales Lima2903a622022-03-17 13:52:19 +0000829
Thales Lima425f6822022-05-10 13:44:58 -0300830 private int getIconToIconWidthForColumns(int columns) {
831 return columns * getCellSize().x
832 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400833 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000834 }
835
Thales Limad90faab2021-09-21 17:18:47 +0100836 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
Thales Lima79456492023-05-23 11:32:22 +0100837 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +0000838 return mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
Thales Lima79456492023-05-23 11:32:22 +0100839 }
840
Thales Limad90faab2021-09-21 17:18:47 +0100841 if (isVerticalBarLayout()) {
842 return 0;
843 }
844
Thales Lima79456492023-05-23 11:32:22 +0100845 return mIsScalableGrid
Thales Lima83bedbf2021-10-05 17:47:39 +0100846 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
847 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100848 }
849
Thales Lima79456492023-05-23 11:32:22 +0100850 private void calculateAndSetWorkspaceVerticalPadding(Context context,
851 InvariantDeviceProfile inv,
852 int extraSpace) {
853 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +0000854 workspaceTopPadding = mResponsiveWorkspaceHeightSpec.getStartPaddingPx();
855 workspaceBottomPadding = mResponsiveWorkspaceHeightSpec.getEndPaddingPx();
Thales Lima79456492023-05-23 11:32:22 +0100856 } else if (mIsScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
857 // Paddings were created assuming no scaling, so we first unscale the extra space.
858 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
859 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
860 DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
861 maxEmptySpace = padding.getMaxEmptySpacePx();
862
863 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
864 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
865
866 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
867 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
868 }
869 }
870
Thales Limab8c05952022-05-23 16:58:38 +0100871 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
872 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700873 // Ensure there is enough space for folder icons, which have a slightly larger radius.
Jordan Silva3646a1b2023-08-02 13:52:52 +0100874 hotseatCellHeightPx = getIconSizeWithOverlap(hotseatIconSizePx);
Thales Limab8c05952022-05-23 16:58:38 +0100875
Jon Miranda0d284852021-06-22 14:50:55 -0700876 if (isVerticalBarLayout()) {
Thales Lima8e11d532023-08-31 13:40:26 +0000877 hotseatBarSizePx = hotseatIconSizePx + mHotseatBarEdgePaddingPx
878 + mHotseatBarWorkspaceSpacePx;
Thales Limab8c05952022-05-23 16:58:38 +0100879 } else if (isQsbInline) {
880 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
881 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700882 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100883 hotseatBarSizePx = hotseatIconSizePx
884 + hotseatQsbSpace
885 + hotseatQsbVisualHeight
886 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700887 }
888 }
889
Thales Lima6a590062022-11-22 15:52:49 +0000890 /**
891 * Calculates the width of the hotseat, changing spaces between the icons and removing icons if
892 * necessary.
893 */
894 public void recalculateHotseatWidthAndBorderSpace() {
Thales Lima79456492023-05-23 11:32:22 +0100895 if (!mIsScalableGrid) return;
Thales Lima6a590062022-11-22 15:52:49 +0000896
fbarone4b0b712024-03-29 14:31:17 -0700897 updateHotseatWidthAndBorderSpace(inv.numColumns);
898 int numWorkspaceColumns = getPanelCount() * inv.numColumns;
899 if (isTwoPanels) {
900 updateHotseatWidthAndBorderSpace(inv.numDatabaseHotseatIcons);
901 // If hotseat doesn't fit with current width, increase column span to fit by multiple
902 // of 2.
903 while (hotseatBorderSpace < mMinHotseatIconSpacePx
904 && mHotseatColumnSpan < numWorkspaceColumns) {
905 updateHotseatWidthAndBorderSpace(mHotseatColumnSpan + 2);
906 }
907 }
908 if (isQsbInline) {
909 // If QSB is inline, reduce column span until it fits.
910 int maxHotseatWidthAllowedPx = getIconToIconWidthForColumns(numWorkspaceColumns);
911 int minHotseatWidthRequiredPx =
912 mMinHotseatQsbWidthPx + hotseatBorderSpace + mHotseatWidthPx;
913 while (minHotseatWidthRequiredPx > maxHotseatWidthAllowedPx
914 && mHotseatColumnSpan > 1) {
915 updateHotseatWidthAndBorderSpace(mHotseatColumnSpan - 1);
916 minHotseatWidthRequiredPx =
917 mMinHotseatQsbWidthPx + hotseatBorderSpace + mHotseatWidthPx;
918 }
919 }
Thales Lima9938c2f2022-07-25 14:38:16 +0100920 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
fbarone4b0b712024-03-29 14:31:17 -0700921
Thales Lima6a590062022-11-22 15:52:49 +0000922 // Spaces should be correct when the nav buttons are not inline
Thales Lima9938c2f2022-07-25 14:38:16 +0100923 if (!areNavButtonsInline) {
924 return;
925 }
926
Thales Lima6a590062022-11-22 15:52:49 +0000927 // The side space with inline buttons should be what is defined in InvariantDeviceProfile
Jon Mirandae17a9492023-03-08 16:42:20 -0800928 int sideSpacePx = inlineNavButtonsEndSpacingPx;
Thales Limaffc68b02023-01-09 16:20:23 +0000929 int maxHotseatWidthPx = availableWidthPx - sideSpacePx - hotseatBarEndOffset;
930 int maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
931 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000932 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100933
Thales Limaffc68b02023-01-09 16:20:23 +0000934 if (hotseatBorderSpace >= mMinHotseatIconSpacePx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100935 return;
936 }
937
938 // Border space can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000939 hotseatBorderSpace = mMinHotseatIconSpacePx;
Thales Lima6a590062022-11-22 15:52:49 +0000940 int requiredWidth = getHotseatRequiredWidth();
Thales Lima9938c2f2022-07-25 14:38:16 +0100941
942 // If there is an inline qsb, change its size
943 if (isQsbInline) {
Thales Limaffc68b02023-01-09 16:20:23 +0000944 hotseatQsbWidth -= requiredWidth - maxHotseatWidthPx;
945 if (hotseatQsbWidth >= mMinHotseatQsbWidthPx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100946 return;
947 }
948
949 // QSB can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000950 hotseatQsbWidth = mMinHotseatQsbWidthPx;
Thales Lima9938c2f2022-07-25 14:38:16 +0100951 }
952
Thales Limaffc68b02023-01-09 16:20:23 +0000953 maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
Thales Lima6a590062022-11-22 15:52:49 +0000954
Thales Lima9938c2f2022-07-25 14:38:16 +0100955 // If it still doesn't fit, start removing icons
956 do {
957 numShownHotseatIcons--;
Thales Limaffc68b02023-01-09 16:20:23 +0000958 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000959 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Limaffc68b02023-01-09 16:20:23 +0000960 } while (hotseatBorderSpace < mMinHotseatIconSpacePx && numShownHotseatIcons > 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100961 }
962
fbarone4b0b712024-03-29 14:31:17 -0700963 private void updateHotseatWidthAndBorderSpace(int columns) {
964 mHotseatColumnSpan = columns;
965 mHotseatWidthPx = getIconToIconWidthForColumns(mHotseatColumnSpan);
966 hotseatBorderSpace = calculateHotseatBorderSpace(mHotseatWidthPx, /* numExtraBorder= */ 0);
967 }
968
Thales Lima78d00ad2021-09-30 11:29:06 +0100969 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100970 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100971 }
972
973 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima79456492023-05-23 11:32:22 +0100974 int horizontalSpacePx = 0;
975 int verticalSpacePx = 0;
Thales Lima78d00ad2021-09-30 11:29:06 +0100976
Thales Lima79456492023-05-23 11:32:22 +0100977 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +0000978 horizontalSpacePx = mResponsiveWorkspaceWidthSpec.getGutterPx();
979 verticalSpacePx = mResponsiveWorkspaceHeightSpec.getGutterPx();
Thales Lima79456492023-05-23 11:32:22 +0100980 } else if (mIsScalableGrid) {
981 horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
982 verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
983 }
Thales Lima78d00ad2021-09-30 11:29:06 +0100984
985 return new Point(horizontalSpacePx, verticalSpacePx);
986 }
987
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700988 public Info getDisplayInfo() {
989 return mInfo;
990 }
991
fbarone4b0b712024-03-29 14:31:17 -0700992 @VisibleForTesting
993 public int getHotseatColumnSpan() {
994 return mHotseatColumnSpan;
995 }
996
997 @VisibleForTesting
998 public int getHotseatWidthPx() {
999 return mHotseatWidthPx;
1000 }
1001
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001002 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -08001003 WindowBounds bounds = new WindowBounds(
1004 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001005 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +01001006 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -07001007
1008 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
1009 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
1010 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
1011
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001012 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -07001013 .setWindowBounds(bounds)
Alex Chauab800f72022-12-13 17:46:06 +00001014 .setIsMultiDisplay(isMultiDisplay)
Alex Chau6ed408f2022-03-04 12:58:05 +00001015 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -07001016 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +00001017 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001018 }
1019
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001020 public DeviceProfile copy(Context context) {
1021 return toBuilder(context).build();
1022 }
1023
1024 /**
1025 * TODO: Move this to the builder as part of setMultiWindowMode
1026 */
Sunny Goyalb46703d2020-05-27 17:52:03 -07001027 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001028 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -07001029 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001030 .setMultiWindowMode(true)
1031 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -08001032
Jon Miranda7ae64ff2016-11-21 16:18:46 -08001033 // We use these scales to measure and layout the widgets using their full invariant profile
1034 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
1035 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
1036 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -07001037 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
1038 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
1039 profile = profile.toBuilder(context)
1040 .setViewScaleProvider(i -> p)
1041 .build();
1042 }
1043
1044 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -08001045
Jon Miranda93e1f042016-11-11 14:13:04 -08001046 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -07001047 }
1048
Adam Cohen63f1ec02014-08-12 09:23:13 -07001049 /**
Jon Miranda941375e2021-03-31 13:10:45 -04001050 * Checks if there is enough space for labels on the workspace.
1051 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -07001052 * It is important to call this method after the All Apps variables have been set.
1053 */
Jon Miranda941375e2021-03-31 13:10:45 -04001054 private void hideWorkspaceLabelsIfNotEnoughSpace() {
1055 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
1056 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
1057 - iconTextHeight;
1058
1059 // We want enough space so that the text is closer to its corresponding icon.
1060 if (workspaceCellPaddingY < iconTextHeight) {
1061 iconTextSizePx = 0;
1062 iconDrawablePaddingPx = 0;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001063 cellHeightPx = getIconSizeWithOverlap(iconSizePx);
Jon Miranda941375e2021-03-31 13:10:45 -04001064 autoResizeAllAppsCells();
1065 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001066 }
Jon Miranda1091e532017-07-21 13:31:50 -07001067
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001068 /**
Jon Miranda228877d2021-02-09 11:05:00 -05001069 * Returns the amount of extra (or unused) vertical space.
1070 */
Brandon Dayauon5787a272023-12-14 13:47:17 -08001071 private int updateAvailableDimensions(Context context) {
fbaronfc6bbcf2024-01-29 10:35:17 -08001072 iconCenterVertically = (mIsScalableGrid || mIsResponsiveGrid) && isVerticalBarLayout();
Jordan Silva999dd2a2023-11-17 19:31:43 +00001073
1074 if (mIsResponsiveGrid) {
Jordan Silva15cacd52023-11-28 14:32:05 +00001075 iconSizePx = mResponsiveWorkspaceCellSpec.getIconSize();
1076 iconTextSizePx = mResponsiveWorkspaceCellSpec.getIconTextSize();
1077 mIconDrawablePaddingOriginalPx = mResponsiveWorkspaceCellSpec.getIconDrawablePadding();
Brandon Dayauon5787a272023-12-14 13:47:17 -08001078 updateIconSize(1f, context);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001079 updateWorkspacePadding();
1080 return 0;
1081 }
1082
Alex Chaua68164d2022-12-15 16:16:03 +00001083 float invIconSizeDp = inv.iconSize[mTypeIndex];
1084 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
1085 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
1086 iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
1087
Brandon Dayauon5787a272023-12-14 13:47:17 -08001088 updateIconSize(1f, context);
Pat Manning08610ca2022-04-05 21:03:16 +01001089 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -05001090
1091 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +01001092 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +00001093 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -05001094 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -05001095 float scaleY = maxHeight / usedHeight;
1096 boolean shouldScale = scaleY < 1f;
1097
1098 float scaleX = 1f;
Thales Lima79456492023-05-23 11:32:22 +01001099 if (mIsScalableGrid) {
Jon Mirandae126d722021-02-25 10:45:20 -05001100 // We scale to fit the cellWidth and cellHeight in the available space.
1101 // The benefit of scalable grids is that we can get consistent aspect ratios between
1102 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +01001103 float usedWidth =
1104 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -05001105 // We do not subtract padding here, as we also scale the workspace padding if needed.
1106 scaleX = availableWidthPx / usedWidth;
1107 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -07001108 }
Jon Mirandae126d722021-02-25 10:45:20 -05001109
1110 if (shouldScale) {
1111 float scale = Math.min(scaleX, scaleY);
Brandon Dayauon5787a272023-12-14 13:47:17 -08001112 updateIconSize(scale, context);
Pat Manninga2e14992022-04-22 11:29:17 +01001113 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -05001114 }
1115
Jon Miranda228877d2021-02-09 11:05:00 -05001116 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -07001117 }
1118
Pat Manninga2e14992022-04-22 11:29:17 +01001119 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +01001120 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
1121 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
1122 }
1123
Pat Manninga2e14992022-04-22 11:29:17 +01001124 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +00001125 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +01001126 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
1127 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -05001128 }
1129
Jordan Silva376036a2023-11-08 15:56:40 +00001130 private int getNormalizedIconDrawablePadding(int iconSizePx, int iconDrawablePadding) {
fbarone69b6f42023-12-18 13:20:34 -08001131 return Math.max(0, iconDrawablePadding
1132 - ((iconSizePx - getIconVisibleSizePx(iconSizePx)) / 2));
Jordan Silva376036a2023-11-08 15:56:40 +00001133 }
1134
1135 private int getNormalizedIconDrawablePadding() {
1136 return getNormalizedIconDrawablePadding(iconSizePx, mIconDrawablePaddingOriginalPx);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001137 }
1138
1139 private int getNormalizedFolderChildDrawablePaddingPx(int textHeight) {
1140 // TODO(b/235886078): workaround needed because of this bug
1141 // Icons are 10% larger on XML than their visual size,
1142 // so remove that extra space to get labels closer to the correct padding
1143 int drawablePadding = (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3;
1144
fbarone69b6f42023-12-18 13:20:34 -08001145 int iconSizeDiff = folderChildIconSizePx - getIconVisibleSizePx(folderChildIconSizePx);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001146 return Math.max(0, drawablePadding - iconSizeDiff / 2);
1147 }
1148
Jordan Silva3646a1b2023-08-02 13:52:52 +01001149 private int getIconSizeWithOverlap(int iconSize) {
1150 return (int) Math.ceil(iconSize * ICON_OVERLAP_FACTOR);
1151 }
1152
Jon Miranda6f7e9702019-09-16 14:44:14 -07001153 /**
1154 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
1155 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
1156 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
1157 */
Brandon Dayauon5787a272023-12-14 13:47:17 -08001158 public void updateIconSize(float scale, Context context) {
Jon Mirandaab3c6812021-06-28 15:42:28 -07001159 // Icon scale should never exceed 1, otherwise pixellation may occur.
1160 iconScale = Math.min(1f, scale);
1161 cellScaleToFit = scale;
1162
Jon Miranda18751b62017-07-31 17:25:27 -07001163 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -08001164 final boolean isVerticalLayout = isVerticalBarLayout();
Thales Lima080d8902022-03-28 15:30:29 +01001165 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -05001166
Thales Lima79456492023-05-23 11:32:22 +01001167 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001168 cellWidthPx = mResponsiveWorkspaceWidthSpec.getCellSizePx();
1169 cellHeightPx = mResponsiveWorkspaceHeightSpec.getCellSizePx();
Thales Lima79456492023-05-23 11:32:22 +01001170
Thales Lima2759aa32023-06-05 16:25:45 +01001171 if (cellWidthPx < iconSizePx) {
1172 // get a smaller icon size
1173 iconSizePx = mIconSizeSteps.getIconSmallerThan(cellWidthPx);
Thales Lima2759aa32023-06-05 16:25:45 +01001174 }
1175
Jordan Silvadd612682024-01-08 11:38:13 -03001176 if (isVerticalLayout) {
1177 iconDrawablePaddingPx = 0;
1178 iconTextSizePx = 0;
1179 } else {
1180 iconDrawablePaddingPx = getNormalizedIconDrawablePadding();
1181 }
Thales Lima93ee8fc2023-06-05 17:07:11 +01001182
Thales Lima24ceca62023-09-25 16:21:17 -07001183 CellContentDimensions cellContentDimensions = new CellContentDimensions(iconSizePx,
1184 iconDrawablePaddingPx,
1185 iconTextSizePx);
Jordan Silvadd612682024-01-08 11:38:13 -03001186 int cellContentHeight = cellContentDimensions.resizeToFitCellHeight(cellHeightPx,
1187 mIconSizeSteps);
Thales Lima24ceca62023-09-25 16:21:17 -07001188 iconSizePx = cellContentDimensions.getIconSizePx();
1189 iconDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1190 iconTextSizePx = cellContentDimensions.getIconTextSizePx();
Thales Lima2759aa32023-06-05 16:25:45 +01001191
Jordan Silvadd612682024-01-08 11:38:13 -03001192 if (isVerticalLayout) {
1193 cellYPaddingPx = Math.max(0, getCellSize().y - getIconSizeWithOverlap(iconSizePx))
1194 / 2;
1195 } else {
1196 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
1197 }
Thales Lima79456492023-05-23 11:32:22 +01001198 } else if (mIsScalableGrid) {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001199 iconDrawablePaddingPx = (int) (getNormalizedIconDrawablePadding() * iconScale);
Thales Lima83bedbf2021-10-05 17:47:39 +01001200 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
1201 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001202
1203 if (cellWidthPx < iconSizePx) {
1204 // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger.
1205 int numColumns = getPanelCount() * inv.numColumns;
1206 int numBorders = numColumns - 1;
1207 int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns;
1208 if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) {
1209 cellWidthPx = iconSizePx;
1210 cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders;
1211 } else {
1212 // If it still doesn't fit, set borderSpace to 0 and distribute the space for
1213 // cellWidth, and reduce iconSize.
1214 cellWidthPx = (cellWidthPx * numColumns
1215 + cellLayoutBorderSpacePx.x * numBorders) / numColumns;
1216 iconSizePx = Math.min(iconSizePx, cellWidthPx);
1217 cellLayoutBorderSpacePx.x = 0;
1218 }
1219 }
1220
Thales Lima93ee8fc2023-06-05 17:07:11 +01001221 int cellTextAndPaddingHeight =
1222 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +00001223 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
1224 if (cellHeightPx < cellContentHeight) {
1225 // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight
1226 // bigger.
1227 int numBorders = inv.numRows - 1;
1228 int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows;
1229 if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) {
1230 cellHeightPx = cellContentHeight;
1231 cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders;
1232 } else {
Alex Chau06f36e82023-01-06 10:50:54 +00001233 // If it still doesn't fit, set borderSpace to 0 to recover space.
Alex Chaube753132022-12-09 16:46:54 +00001234 cellHeightPx = (cellHeightPx * inv.numRows
1235 + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows;
Alex Chaube753132022-12-09 16:46:54 +00001236 cellLayoutBorderSpacePx.y = 0;
Alex Chau06f36e82023-01-06 10:50:54 +00001237 // Reduce iconDrawablePaddingPx to make cellContentHeight smaller.
1238 int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx;
1239 if (cellContentWithoutPadding <= cellHeightPx) {
1240 iconDrawablePaddingPx = cellContentHeight - cellHeightPx;
1241 } else {
1242 // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space,
1243 // then proportional reduce iconSizePx and iconTextSizePx to fit.
1244 iconDrawablePaddingPx = 0;
1245 float ratio = cellHeightPx / (float) cellContentWithoutPadding;
1246 iconSizePx = (int) (iconSizePx * ratio);
1247 iconTextSizePx = (int) (iconTextSizePx * ratio);
1248 }
1249 cellTextAndPaddingHeight =
1250 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +00001251 }
1252 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
1253 }
Jon Mirandae126d722021-02-25 10:45:20 -05001254 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +01001255 desiredWorkspaceHorizontalMarginPx =
1256 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -05001257 } else {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001258 iconDrawablePaddingPx = (int) (getNormalizedIconDrawablePadding() * iconScale);
Jon Mirandae126d722021-02-25 10:45:20 -05001259 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001260 cellHeightPx = getIconSizeWithOverlap(iconSizePx)
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001261 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -05001262 + Utilities.calculateTextHeight(iconTextSizePx);
1263 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
1264 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
1265 && !isMultiWindowMode) {
1266 // Ensures that the label is closer to its corresponding icon. This is not an issue
1267 // with vertical bar layout or multi-window mode since the issue is handled
1268 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
1269 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
1270 iconDrawablePaddingPx = cellPaddingY;
1271 }
Jon Miranda846455e2017-10-02 14:58:52 -07001272 }
Jon Miranda18751b62017-07-31 17:25:27 -07001273
Sunny Goyalae190ff2020-04-14 00:19:01 +00001274 // All apps
Thales Limaabfe3642023-05-24 18:08:53 +01001275 if (mIsResponsiveGrid) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001276 updateAllAppsWithResponsiveMeasures();
Thales Limaabfe3642023-05-24 18:08:53 +01001277 } else {
Brandon Dayauon5787a272023-12-14 13:47:17 -08001278 updateAllAppsIconSize(scale, context.getResources());
Thales Limaabfe3642023-05-24 18:08:53 +01001279 }
1280 updateAllAppsContainerWidth();
Jordan Silvadd612682024-01-08 11:38:13 -03001281 if (isVerticalLayout && !mIsResponsiveGrid) {
Thales Limaabfe3642023-05-24 18:08:53 +01001282 hideWorkspaceLabelsIfNotEnoughSpace();
1283 }
Brandon Dayauon68c18232024-03-07 10:14:44 -08001284 if ((Flags.enableTwolineToggle()
1285 && LauncherPrefs.ENABLE_TWOLINE_ALLAPPS_TOGGLE.get(context))) {
Brandon Dayauon3cdb32c2023-08-22 21:26:37 -07001286 // Add extra textHeight to the existing allAppsCellHeight.
1287 allAppsCellHeightPx += Utilities.calculateTextHeight(allAppsIconTextSizePx);
1288 }
Winson Chungb3800242013-10-24 11:01:54 -07001289
Thales Limab8c05952022-05-23 16:58:38 +01001290 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -07001291
Sunny Goyalbaec6ff2016-09-14 11:26:21 -07001292 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -07001293 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
1294 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Sunny Goyal6c304b12023-04-10 12:03:04 -07001295
1296 // Update widget padding:
1297 float minSpacing = pxFromDp(MIN_WIDGET_PADDING_DP, mMetrics);
1298 if (cellLayoutBorderSpacePx.x < minSpacing
1299 || cellLayoutBorderSpacePx.y < minSpacing) {
1300 widgetPadding.left = widgetPadding.right =
1301 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.x));
1302 widgetPadding.top = widgetPadding.bottom =
1303 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.y));
1304 } else {
1305 widgetPadding.setEmpty();
1306 }
Winson Chung0f785722015-04-08 10:27:49 -07001307 }
1308
Thales Lima425f6822022-05-10 13:44:58 -03001309 /**
Thales Lima6a590062022-11-22 15:52:49 +00001310 * This method calculates the space between the icons to achieve a certain width.
Thales Lima425f6822022-05-10 13:44:58 -03001311 */
Thales Lima6a590062022-11-22 15:52:49 +00001312 private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) {
Jordan Silvad9227182023-08-17 15:53:59 +01001313 int numBorders = (numShownHotseatIcons - 1 + numExtraBorder);
1314 if (numBorders <= 0) return 0;
1315
Thales Lima9938c2f2022-07-25 14:38:16 +01001316 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
Jordan Silvad9227182023-08-17 15:53:59 +01001317 int hotseatBorderSpacePx = (int) (hotseatWidthPx - hotseatIconsTotalPx) / numBorders;
Thales Limaffc68b02023-01-09 16:20:23 +00001318 return Math.min(hotseatBorderSpacePx, mMaxHotseatIconSpacePx);
Thales Lima425f6822022-05-10 13:44:58 -03001319 }
1320
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001321 /**
1322 * Updates the iconSize for allApps* variants.
1323 */
Brian Isganitisa9a78112022-05-23 18:11:47 -07001324 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +01001325 allAppsBorderSpacePx = new Point(
1326 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
1327 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001328 // AllApps cells don't have real space between cells,
1329 // so we add the border space to the cell height
Alex Chaube753132022-12-09 16:46:54 +00001330 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics)
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001331 + allAppsBorderSpacePx.y;
1332 // but width is just the cell,
1333 // the border is added in #updateAllAppsContainerWidth
Thales Lima79456492023-05-23 11:32:22 +01001334 if (mIsScalableGrid) {
Alex Chaube753132022-12-09 16:46:54 +00001335 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1336 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001337 allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding();
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001338 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001339
1340 if (allAppsCellWidthPx < allAppsIconSizePx) {
1341 // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to
1342 // make allAppsCellWidth bigger.
1343 int numBorders = inv.numAllAppsColumns - 1;
1344 int extraWidthRequired =
1345 (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns;
1346 if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) {
1347 allAppsCellWidthPx = allAppsIconSizePx;
1348 allAppsBorderSpacePx.x -= extraWidthRequired / numBorders;
1349 } else {
1350 // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space
1351 // for allAppsCellWidth, and reduce allAppsIconSize.
1352 allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns
1353 + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns;
1354 allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx);
1355 allAppsBorderSpacePx.x = 0;
1356 }
1357 }
1358
1359 int cellContentHeight = allAppsIconSizePx
1360 + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y;
1361 if (allAppsCellHeightPx < cellContentHeight) {
1362 // Increase allAppsCellHeight to fit its content.
1363 allAppsCellHeightPx = cellContentHeight;
1364 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001365 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001366 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
1367 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001368 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1369 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001370 allAppsIconDrawablePaddingPx =
1371 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001372 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001373 }
Thales Limaabfe3642023-05-24 18:08:53 +01001374 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001375
Jordan Silva999dd2a2023-11-17 19:31:43 +00001376 private void updateAllAppsWithResponsiveMeasures() {
1377 allAppsIconSizePx = mResponsiveAllAppsCellSpec.getIconSize();
1378 allAppsIconTextSizePx = mResponsiveAllAppsCellSpec.getIconTextSize();
1379 allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding(allAppsIconSizePx,
1380 mResponsiveAllAppsCellSpec.getIconDrawablePadding());
Thales Limaabfe3642023-05-24 18:08:53 +01001381 allAppsBorderSpacePx = new Point(
Jordan Silva8f7986a2023-11-08 12:11:25 +00001382 mResponsiveAllAppsWidthSpec.getGutterPx(),
1383 mResponsiveAllAppsHeightSpec.getGutterPx()
Thales Limaabfe3642023-05-24 18:08:53 +01001384 );
Jordan Silva999dd2a2023-11-17 19:31:43 +00001385 allAppsCellHeightPx = mResponsiveAllAppsHeightSpec.getCellSizePx();
Jordan Silva8f7986a2023-11-08 12:11:25 +00001386 allAppsCellWidthPx = mResponsiveAllAppsWidthSpec.getCellSizePx();
Thales Limaa25cd902023-11-01 12:00:32 +00001387
1388 // This workaround is needed to align AllApps icons with Workspace icons
1389 // since AllApps doesn't have borders between cells
1390 int halfBorder = allAppsBorderSpacePx.x / 2;
Jordan Silva8f7986a2023-11-08 12:11:25 +00001391 allAppsPadding.left = mResponsiveAllAppsWidthSpec.getStartPaddingPx() - halfBorder;
1392 allAppsPadding.right = mResponsiveAllAppsWidthSpec.getEndPaddingPx() - halfBorder;
Jordan Silva376036a2023-11-08 15:56:40 +00001393
Jordan Silva376036a2023-11-08 15:56:40 +00001394
1395 // Reduce the size of the app icon if it doesn't fit
1396 if (allAppsCellWidthPx < allAppsIconSizePx) {
1397 // get a smaller icon size
1398 allAppsIconSizePx = mIconSizeSteps.getIconSmallerThan(allAppsCellWidthPx);
1399 }
1400
1401 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1402 allAppsIconSizePx, allAppsIconDrawablePaddingPx, (int) allAppsIconTextSizePx);
1403
1404 if (allAppsCellHeightPx < cellContentDimensions.getCellContentHeight()) {
1405 if (isVerticalBarLayout()) {
Jordan Silva2de6a272024-01-04 14:44:20 -03001406 if (allAppsCellHeightPx < allAppsIconSizePx) {
Jordan Silva376036a2023-11-08 15:56:40 +00001407 cellContentDimensions.setIconSizePx(
1408 mIconSizeSteps.getIconSmallerThan(allAppsCellHeightPx));
1409 }
1410 } else {
1411 cellContentDimensions.resizeToFitCellHeight(allAppsCellHeightPx,
1412 mIconSizeSteps);
1413 }
1414 allAppsIconSizePx = cellContentDimensions.getIconSizePx();
1415 allAppsIconDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1416 allAppsIconTextSizePx = cellContentDimensions.getIconTextSizePx();
1417 }
Jordan Silva999dd2a2023-11-17 19:31:43 +00001418
1419 allAppsCellHeightPx += mResponsiveAllAppsHeightSpec.getGutterPx();
Jordan Silvadd612682024-01-08 11:38:13 -03001420
1421 if (isVerticalBarLayout()) {
1422 autoResizeAllAppsCells();
1423 }
Thales Limaabfe3642023-05-24 18:08:53 +01001424 }
1425
1426 /**
1427 * Re-computes the all-apps cell size to be independent of workspace
1428 */
1429 public void autoResizeAllAppsCells() {
1430 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
1431 int topBottomPadding = textHeight;
1432 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
1433 + textHeight + (topBottomPadding * 2);
1434 }
1435
1436 private void updateAllAppsContainerWidth() {
1437 int cellLayoutHorizontalPadding =
1438 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
1439 if (isTablet) {
1440 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
1441 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Thales Limab433c9c2023-10-30 12:24:05 +00001442 + allAppsPadding.left + allAppsPadding.right;
Thales Limaabfe3642023-05-24 18:08:53 +01001443 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
Thales Limaa25cd902023-11-01 12:00:32 +00001444 } else if (!mIsResponsiveGrid) {
Thales Limab433c9c2023-10-30 12:24:05 +00001445 allAppsPadding.left = allAppsPadding.right =
Thales Limaabfe3642023-05-24 18:08:53 +01001446 Math.max(0, desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding
1447 - (allAppsBorderSpacePx.x / 2));
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001448 }
1449 }
1450
Thales Limaabfe3642023-05-24 18:08:53 +01001451 private void setupAllAppsStyle(Context context) {
1452 TypedArray allAppsStyle = context.obtainStyledAttributes(
1453 inv.allAppsStyle != INVALID_RESOURCE_HANDLE ? inv.allAppsStyle
1454 : R.style.AllAppsStyleDefault, R.styleable.AllAppsStyle);
1455
Thales Limab433c9c2023-10-30 12:24:05 +00001456 allAppsPadding.left = allAppsPadding.right = allAppsStyle.getDimensionPixelSize(
Thales Limaabfe3642023-05-24 18:08:53 +01001457 R.styleable.AllAppsStyle_horizontalPadding, 0);
1458 allAppsStyle.recycle();
1459 }
1460
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001461 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001462 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001463
Jordan Silva637f4eb2023-06-13 11:21:53 +01001464 // Responsive grid doesn't need to scale the folder
1465 if (mIsResponsiveGrid) return;
1466
Thales Lima7eee74b2023-03-16 16:00:55 -03001467 // For usability we can't have the folder use the whole width of the screen
Sunny Goyal07b69292018-01-08 14:19:34 -08001468 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -08001469
Thales Lima7eee74b2023-03-16 16:00:55 -03001470 // Check if the folder fit within the available height.
Thales Lima1faa4ed2023-12-01 16:48:19 +00001471 float contentUsedHeight = folderCellHeightPx * numFolderRows
1472 + ((numFolderRows - 1) * folderCellLayoutBorderSpacePx.y)
Thales Lima7eee74b2023-03-16 16:00:55 -03001473 + folderFooterHeightPx
1474 + folderContentPaddingTop;
1475 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001476 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -08001477
Thales Lima7eee74b2023-03-16 16:00:55 -03001478 // Check if the folder fit within the available width.
Thales Lima1faa4ed2023-12-01 16:48:19 +00001479 float contentUsedWidth = folderCellWidthPx * numFolderColumns
1480 + ((numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x)
Thales Lima7eee74b2023-03-16 16:00:55 -03001481 + folderContentPaddingLeftRight * 2;
1482 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001483 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -08001484
1485 float scale = Math.min(scaleX, scaleY);
1486 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001487 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001488 }
1489 }
1490
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001491 private void updateFolderCellSize(float scale, Resources res) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001492 int minLabelTextSize = pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001493 if (mIsResponsiveGrid) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001494 folderChildIconSizePx = mResponsiveWorkspaceCellSpec.getIconSize();
1495 folderChildTextSizePx = mResponsiveWorkspaceCellSpec.getIconTextSize();
1496 folderLabelTextSizePx = Math.max(minLabelTextSize,
1497 (int) (folderChildTextSizePx * folderLabelTextScale));
1498 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
1499
Jordan Silva637f4eb2023-06-13 11:21:53 +01001500 folderCellWidthPx = mResponsiveFolderWidthSpec.getCellSizePx();
Jordan Silva637f4eb2023-06-13 11:21:53 +01001501 folderCellHeightPx = mResponsiveFolderHeightSpec.getCellSizePx();
1502 folderContentPaddingTop = mResponsiveFolderHeightSpec.getStartPaddingPx();
1503 folderFooterHeightPx = mResponsiveFolderHeightSpec.getEndPaddingPx();
1504
1505 folderCellLayoutBorderSpacePx = new Point(mResponsiveFolderWidthSpec.getGutterPx(),
Thales Lima4cfd9502023-07-10 14:01:28 +01001506 mResponsiveFolderHeightSpec.getGutterPx());
Jordan Silva637f4eb2023-06-13 11:21:53 +01001507
1508 folderContentPaddingLeftRight = mResponsiveFolderWidthSpec.getStartPaddingPx();
Jordan Silva12fae112023-06-26 12:51:01 +01001509
1510 // Reduce icon width if it's wider than the expected folder cell width
1511 if (folderCellWidthPx < folderChildIconSizePx) {
1512 folderChildIconSizePx = mIconSizeSteps.getIconSmallerThan(folderCellWidthPx);
1513 }
1514
1515 // Recalculating padding and cell height
Jordan Silva3e5688a2023-12-05 15:12:29 -03001516 folderChildDrawablePaddingPx = mResponsiveWorkspaceCellSpec.getIconDrawablePadding();
Jordan Silva12fae112023-06-26 12:51:01 +01001517
Thales Limae9b5e142023-11-04 17:10:13 +00001518 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1519 folderChildIconSizePx,
1520 folderChildDrawablePaddingPx,
1521 folderChildTextSizePx);
1522 cellContentDimensions.resizeToFitCellHeight(folderCellHeightPx, mIconSizeSteps);
1523 folderChildIconSizePx = cellContentDimensions.getIconSizePx();
1524 folderChildDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1525 folderChildTextSizePx = cellContentDimensions.getIconTextSizePx();
Jordan Silva999dd2a2023-11-17 19:31:43 +00001526 folderLabelTextSizePx = Math.max(minLabelTextSize,
Jordan Silva9a3bd8f2023-11-16 18:33:28 +00001527 (int) (folderChildTextSizePx * folderLabelTextScale));
Jordan Silva999dd2a2023-11-17 19:31:43 +00001528 return;
1529 }
1530
1531 float invIconSizeDp = inv.iconSize[mTypeIndex];
1532 float invIconTextSizeDp = inv.iconTextSize[mTypeIndex];
1533 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1534 folderChildTextSizePx = pxFromSp(invIconTextSizeDp, mMetrics, scale);
1535 folderLabelTextSizePx = Math.max(minLabelTextSize,
1536 (int) (folderChildTextSizePx * folderLabelTextScale));
1537 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
1538
1539 if (mIsScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001540 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
Thales Lima7eee74b2023-03-16 16:00:55 -03001541 folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale);
1542 folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale);
1543 } else {
1544 folderCellWidthPx = roundPxValueFromFloat(folderCellWidthPx * scale);
1545 folderCellHeightPx = roundPxValueFromFloat(folderCellHeightPx * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001546 }
Charlie Anderson7bb10972023-11-22 13:35:30 -08001547 // Recalculating padding and cell height
1548 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
1549
1550 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1551 folderChildIconSizePx,
1552 folderChildDrawablePaddingPx,
1553 folderChildTextSizePx);
1554 cellContentDimensions.resizeToFitCellHeight(folderCellHeightPx, mIconSizeSteps);
1555 folderChildIconSizePx = cellContentDimensions.getIconSizePx();
1556 folderChildDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1557 folderChildTextSizePx = cellContentDimensions.getIconTextSizePx();
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001558
Thales Lima7eee74b2023-03-16 16:00:55 -03001559 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001560 folderCellLayoutBorderSpacePx = new Point(
1561 roundPxValueFromFloat(folderCellLayoutBorderSpacePx.x * scale),
1562 roundPxValueFromFloat(folderCellLayoutBorderSpacePx.y * scale)
1563 );
Thales Lima7eee74b2023-03-16 16:00:55 -03001564 folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001565 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx.x;
Jon Miranda823da222021-03-23 08:08:45 -04001566 } else {
1567 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1568 * scale);
1569 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1570 * scale);
1571
1572 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1573 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Lima7eee74b2023-03-16 16:00:55 -03001574 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001575 folderContentPaddingLeftRight =
1576 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1577 folderFooterHeightPx =
Thales Lima7eee74b2023-03-16 16:00:55 -03001578 roundPxValueFromFloat(
1579 res.getDimensionPixelSize(R.dimen.folder_footer_height_default)
1580 * scale);
1581
Jordan Silva12fae112023-06-26 12:51:01 +01001582 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
Jon Miranda823da222021-03-23 08:08:45 -04001583 }
Jon Mirandabf7d8122016-11-03 15:29:29 -07001584 }
1585
Winson1f064272016-07-18 17:18:02 -07001586 public void updateInsets(Rect insets) {
1587 mInsets.set(insets);
1588 }
1589
Sunny Goyalae6e3182019-04-30 12:04:37 -07001590 /**
1591 * The current device insets. This is generally same as the insets being dispatched to
1592 * {@link Insettable} elements, but can differ if the element is using a different profile.
1593 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001594 public Rect getInsets() {
1595 return mInsets;
1596 }
1597
Sunny Goyal756cd262015-08-20 12:33:21 -07001598 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001599 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001600 }
1601
Sunny Goyal19ff7282021-04-22 10:12:54 -07001602 public Point getCellSize(Point result) {
1603 if (result == null) {
1604 result = new Point();
1605 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001606
Pat Manning25d53342022-05-10 09:58:49 +00001607 int shortcutAndWidgetContainerWidth =
1608 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1609 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1610 inv.numColumns);
1611 int shortcutAndWidgetContainerHeight =
1612 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1613 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1614 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001615 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001616 }
1617
1618 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001619 * Returns the left and right space on the cell, which is the cell width - icon size
1620 */
1621 public int getCellHorizontalSpace() {
1622 return getCellSize().x - iconSizePx;
1623 }
1624
1625 /**
Pat Manning25d53342022-05-10 09:58:49 +00001626 * Gets the number of panels within the workspace.
1627 */
1628 public int getPanelCount() {
1629 return isTwoPanels ? 2 : 1;
1630 }
1631
1632 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001633 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1634 * bottom of the screen.
1635 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001636 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1637 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001638 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001639 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001640 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001641 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001642 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001643 }
1644
1645 /**
1646 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1647 */
Pat Manning25d53342022-05-10 09:58:49 +00001648 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001649 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001650 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001651 }
1652
1653 /**
1654 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1655 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001656 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001657 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001658 return heightPx - (isVerticalBarLayout()
1659 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001660 }
1661
Pat Manningea5c1d22022-04-14 10:58:16 +01001662 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001663 * Gets the scale of the workspace for the spring-loaded edit state.
1664 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001665 public float getWorkspaceSpringLoadScale(Context context) {
1666 float scale =
1667 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1668 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001669 scale = Math.min(scale, 1f);
1670
Pat Manninge63dd252022-08-02 16:15:29 +01001671 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001672 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001673 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001674 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001675 if (scaledWorkspaceWidth > maxAvailableWidth) {
1676 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1677 }
1678 return scale;
1679 }
1680
Pat Manning25d53342022-05-10 09:58:49 +00001681 /**
1682 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1683 *
1684 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1685 * layouts have two Cell Layouts per workspace.
1686 */
1687 public int getCellLayoutWidth() {
1688 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001689 }
1690
Pat Manning25d53342022-05-10 09:58:49 +00001691 /**
1692 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1693 *
1694 * <p>This is the height of a Workspace, less its vertical padding.
1695 */
1696 public int getCellLayoutHeight() {
1697 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001698 }
1699
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001700 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001701 return new Point(workspacePadding.left + workspacePadding.right,
1702 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001703 }
1704
1705 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001706 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1707 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001708 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001709 private void updateWorkspacePadding() {
1710 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001711 if (isVerticalBarLayout()) {
Jordan Silva3646a1b2023-08-02 13:52:52 +01001712 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001713 padding.top = mResponsiveWorkspaceHeightSpec.getStartPaddingPx();
Thales Lima8e11d532023-08-31 13:40:26 +00001714 padding.bottom = Math.max(0,
Jordan Silva8f7986a2023-11-08 12:11:25 +00001715 mResponsiveWorkspaceHeightSpec.getEndPaddingPx() - mInsets.bottom);
Jordan Silva3646a1b2023-08-02 13:52:52 +01001716 if (isSeascape()) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001717 padding.left =
1718 hotseatBarSizePx + mResponsiveWorkspaceWidthSpec.getEndPaddingPx();
1719 padding.right = mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
Jordan Silva3646a1b2023-08-02 13:52:52 +01001720 } else {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001721 padding.left = mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
1722 padding.right =
1723 hotseatBarSizePx + mResponsiveWorkspaceWidthSpec.getEndPaddingPx();
Jordan Silva3646a1b2023-08-02 13:52:52 +01001724 }
Winson1f064272016-07-18 17:18:02 -07001725 } else {
Jordan Silva3646a1b2023-08-02 13:52:52 +01001726 padding.top = 0;
1727 padding.bottom = edgeMarginPx;
1728 if (isSeascape()) {
1729 padding.left = hotseatBarSizePx;
Thales Lima8e11d532023-08-31 13:40:26 +00001730 padding.right = mHotseatBarEdgePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001731 } else {
Thales Lima8e11d532023-08-31 13:40:26 +00001732 padding.left = mHotseatBarEdgePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001733 padding.right = hotseatBarSizePx;
1734 }
Winson1f064272016-07-18 17:18:02 -07001735 }
Winson Chungb3800242013-10-24 11:01:54 -07001736 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001737 // Pad the bottom of the workspace with hotseat bar
1738 // and leave a bit of space in case a widget go all the way down
Thales Lima79456492023-05-23 11:32:22 +01001739 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding - mInsets.bottom;
1740 if (!mIsResponsiveGrid) {
1741 paddingBottom +=
1742 workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace;
1743 }
1744 int paddingTop = workspaceTopPadding + (mIsScalableGrid ? 0 : edgeMarginPx);
Pat Manning08610ca2022-04-05 21:03:16 +01001745 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001746
Pat Manning08610ca2022-04-05 21:03:16 +01001747 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001748 }
Pat Manning08610ca2022-04-05 21:03:16 +01001749 insetPadding(workspacePadding, cellLayoutPaddingPx);
1750 }
1751
1752 private void insetPadding(Rect paddings, Rect insets) {
1753 insets.left = Math.min(insets.left, paddings.left);
1754 paddings.left -= insets.left;
1755
1756 insets.top = Math.min(insets.top, paddings.top);
1757 paddings.top -= insets.top;
1758
1759 insets.right = Math.min(insets.right, paddings.right);
1760 paddings.right -= insets.right;
1761
1762 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1763 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001764 }
1765
Liran Binyamina833af32023-08-02 16:30:27 -04001766
1767 /**
1768 * Returns the new border space that should be used between hotseat icons after adjusting it to
1769 * the bubble bar.
1770 *
1771 * <p>If there's no adjustment needed, this method returns {@code 0}.
1772 */
1773 public float getHotseatAdjustedBorderSpaceForBubbleBar(Context context) {
1774 // only need to adjust when QSB is on top of the hotseat.
1775 if (isQsbInline) {
1776 return 0;
1777 }
1778
1779 // no need to adjust if there's enough space for the bubble bar to the right of the hotseat.
1780 if (getHotseatLayoutPadding(context).right > mBubbleBarSpaceThresholdPx) {
1781 return 0;
1782 }
1783
1784 // The adjustment is shrinking the hotseat's width by 1 icon on either side.
1785 int iconsWidth =
1786 iconSizePx * numShownHotseatIcons + hotseatBorderSpace * (numShownHotseatIcons - 1);
1787 int newWidth = iconsWidth - 2 * iconSizePx;
1788 // Evenly space the icons within the boundaries of the new width.
1789 return (float) (newWidth - iconSizePx * numShownHotseatIcons) / (numShownHotseatIcons - 1);
1790 }
1791
Sunny Goyal57b22792021-05-25 14:35:01 -07001792 /**
1793 * Returns the padding for hotseat view
1794 */
1795 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001796 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001797 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001798 // The hotseat icons will be placed in the middle of the hotseat cells.
1799 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1800 // in vertical bar layout.
fbaronfc6bbcf2024-01-29 10:35:17 -08001801 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top), 0);
1802 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom), 0);
Sihua Ma38bb3b02022-03-21 22:20:14 -07001803
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001804 if (isSeascape()) {
Thales Lima8e11d532023-08-31 13:40:26 +00001805 hotseatBarPadding.set(mInsets.left + mHotseatBarEdgePaddingPx, paddingTop,
1806 mHotseatBarWorkspaceSpacePx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001807 } else {
Thales Lima8e11d532023-08-31 13:40:26 +00001808 hotseatBarPadding.set(mHotseatBarWorkspaceSpacePx, paddingTop,
1809 mInsets.right + mHotseatBarEdgePaddingPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001810 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001811 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001812 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001813 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1814 int hotseatBarTopPadding =
1815 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001816
Thales Lima6a590062022-11-22 15:52:49 +00001817 int hotseatWidth = getHotseatRequiredWidth();
Helen Cheuke76291f2023-02-14 17:11:05 +00001818 int startSpacing;
1819 int endSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001820 // Hotseat aligns to the left with nav buttons
1821 if (hotseatBarEndOffset > 0) {
Jon Mirandae17a9492023-03-08 16:42:20 -08001822 startSpacing = inlineNavButtonsEndSpacingPx;
Helen Cheuke76291f2023-02-14 17:11:05 +00001823 endSpacing = availableWidthPx - hotseatWidth - startSpacing + hotseatBorderSpace;
1824 } else {
1825 startSpacing = (availableWidthPx - hotseatWidth) / 2;
1826 endSpacing = startSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001827 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001828 startSpacing += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001829
Helen Cheuke76291f2023-02-14 17:11:05 +00001830 hotseatBarPadding.top = hotseatBarTopPadding;
1831 hotseatBarPadding.bottom = hotseatBarBottomPadding;
Alex Chau51da2192022-05-20 13:32:10 +01001832 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001833 if (isRtl) {
Helen Cheuke76291f2023-02-14 17:11:05 +00001834 hotseatBarPadding.left = endSpacing;
1835 hotseatBarPadding.right = startSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001836 } else {
Helen Cheuke76291f2023-02-14 17:11:05 +00001837 hotseatBarPadding.left = startSpacing;
1838 hotseatBarPadding.right = endSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001839 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001840
Thales Lima79456492023-05-23 11:32:22 +01001841 } else if (mIsScalableGrid) {
fbarone69b6f42023-12-18 13:20:34 -08001842 int iconExtraSpacePx = iconSizePx - getIconVisibleSizePx(iconSizePx);
1843 int sideSpacing = (availableWidthPx - (hotseatQsbWidth + iconExtraSpacePx)) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001844 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001845 0,
Thales Lima425f6822022-05-10 13:44:58 -03001846 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001847 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001848 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001849 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1850 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1851 // for this, we pad the left and right of the hotseat with half of the difference of a
1852 // workspace cell vs a hotseat cell.
1853 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001854 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001855 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001856 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001857 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1858 + mInsets.left,
1859 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001860 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001861 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001862 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001863 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001864 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001865 }
1866
Andy Wickhambd9a1802023-06-08 16:33:15 -07001867 /** The margin between the edge of all apps and the edge of the first icon. */
Thales Limab433c9c2023-10-30 12:24:05 +00001868 public int getAllAppsIconStartMargin(Context context) {
Andy Wickhambd9a1802023-06-08 16:33:15 -07001869 int allAppsSpacing;
1870 if (isVerticalBarLayout()) {
1871 // On phones, the landscape layout uses a different setup.
1872 allAppsSpacing = workspacePadding.left + workspacePadding.right;
1873 } else {
Thales Limab433c9c2023-10-30 12:24:05 +00001874 allAppsSpacing =
1875 allAppsPadding.left + allAppsPadding.right + allAppsLeftRightMargin * 2;
Andy Wickhambd9a1802023-06-08 16:33:15 -07001876 }
1877
1878 int cellWidth = DeviceProfile.calculateCellWidth(
1879 availableWidthPx - allAppsSpacing,
1880 0 /* borderSpace */,
1881 numShownAllAppsColumns);
fbarone69b6f42023-12-18 13:20:34 -08001882 int iconAlignmentMargin = (cellWidth - getIconVisibleSizePx(allAppsIconSizePx)) / 2;
Thales Limab433c9c2023-10-30 12:24:05 +00001883
1884 return (Utilities.isRtl(context.getResources()) ? allAppsPadding.right
1885 : allAppsPadding.left) + iconAlignmentMargin;
Andy Wickhambd9a1802023-06-08 16:33:15 -07001886 }
1887
fbarone69b6f42023-12-18 13:20:34 -08001888 /**
1889 * TODO(b/235886078): workaround needed because of this bug
1890 * Icons are 10% larger on XML than their visual size, so remove that extra space to get
1891 * some dimensions correct.
1892 *
1893 * When this bug is resolved this method will no longer be needed and we would be able to
1894 * replace all instances where this method is called with iconSizePx.
1895 */
1896 private int getIconVisibleSizePx(int iconSizePx) {
1897 return Math.round(ICON_VISIBLE_AREA_FACTOR * iconSizePx);
1898 }
1899
Thales Lima9938c2f2022-07-25 14:38:16 +01001900 private int getAdditionalQsbSpace() {
1901 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1902 }
1903
1904 /**
1905 * Calculate how much space the hotseat needs to be shown completely
1906 */
1907 private int getHotseatRequiredWidth() {
1908 int additionalQsbSpace = getAdditionalQsbSpace();
1909 return iconSizePx * numShownHotseatIcons
Thales Lima6a590062022-11-22 15:52:49 +00001910 + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1))
Thales Lima9938c2f2022-07-25 14:38:16 +01001911 + additionalQsbSpace;
1912 }
1913
Winsonfadbe8f2016-07-22 16:35:37 -07001914 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001915 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1916 */
1917 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001918 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001919 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1920 } else if (isTaskbarPresent) { // QSB on top
1921 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001922 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001923 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001924 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001925 }
1926
Thales Limab8c05952022-05-23 16:58:38 +01001927 /**
1928 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1929 */
1930 private int getHotseatBarBottomPadding() {
1931 if (isTaskbarPresent) { // QSB on top or inline
1932 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001933 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001934 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001935 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001936 }
1937
1938 /**
Alex Chau51da2192022-05-20 13:32:10 +01001939 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1940 */
1941 public int getTaskbarOffsetY() {
Jon Miranda9c478b62023-03-23 21:38:49 -07001942 int taskbarIconBottomSpace = (taskbarHeight - iconSizePx) / 2;
Alex Chau51da2192022-05-20 13:32:10 +01001943 int launcherIconBottomSpace =
1944 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001945 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001946 }
1947
Uwais Ashrafaa7fa882023-10-10 21:36:06 +00001948 /** Returns the number of pixels required below OverviewActions. */
Alex Chaua2fc7642022-04-21 14:20:23 +01001949 public int getOverviewActionsClaimedSpaceBelow() {
Uwais Ashrafaa7fa882023-10-10 21:36:06 +00001950 return isTaskbarPresent ? mTransientTaskbarClaimedSpace : mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001951 }
1952
1953 /** Gets the space that the overview actions will take, including bottom margin. */
1954 public int getOverviewActionsClaimedSpace() {
Alex Chau4989f4f2023-10-11 14:08:22 +00001955 int overviewActionsSpace = isTablet && Flags.enableGridOnlyOverview()
Pat Manning7b8f7662023-01-18 14:48:30 +00001956 ? 0
1957 : (overviewActionsTopMarginPx + overviewActionsHeight);
1958 return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
Alex Chaua2fc7642022-04-21 14:20:23 +01001959 }
1960
1961 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001962 * Takes the View and return the scales of width and height depending on the DeviceProfile
1963 * specifications
1964 *
1965 * @param itemInfo The tag of the widget view
1966 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1967 * height
1968 */
1969 @NonNull
1970 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1971 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1972 }
1973
1974 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001975 * @return the bounds for which the open folders should be contained within
1976 */
1977 public Rect getAbsoluteOpenFolderBounds() {
1978 if (isVerticalBarLayout()) {
1979 // Folders should only appear right of the drop target bar and left of the hotseat
1980 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1981 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001982 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001983 mInsets.top + availableHeightPx);
1984 } else {
1985 // Folders should only appear below the drop target bar and above the hotseat
Jon Miranda9c478b62023-03-23 21:38:49 -07001986 int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001987 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001988 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001989 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001990 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001991 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001992 }
1993 }
1994
Jon Miranda228877d2021-02-09 11:05:00 -05001995 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1996 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001997 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001998
Jon Miranda228877d2021-02-09 11:05:00 -05001999 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
2000 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07002001 }
2002
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07002003 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07002004 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
2005 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
2006 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07002007 */
Tony Wickhamab946a12015-09-16 15:38:16 -07002008 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07002009 return isLandscape && transposeLayoutWithOrientation;
2010 }
2011
Sunny Goyal59d086c2018-05-07 17:31:40 -07002012 /**
2013 * Updates orientation information and returns true if it has changed from the previous value.
2014 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07002015 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07002016 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07002017 boolean isSeascape = DisplayController.INSTANCE.get(context)
2018 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07002019 if (mIsSeascape != isSeascape) {
2020 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01002021 // Hotseat changing sides requires updating workspace left/right paddings
2022 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07002023 return true;
2024 }
2025 }
2026 return false;
2027 }
2028
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08002029 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07002030 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08002031 }
2032
Sunny Goyal07b69292018-01-08 14:19:34 -08002033 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07002034 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07002035 }
2036
Jon Miranda92c1b5d2021-07-20 13:57:16 -07002037 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08002038 switch (containerType) {
2039 case CellLayout.WORKSPACE:
2040 return cellHeightPx;
2041 case CellLayout.FOLDER:
2042 return folderCellHeightPx;
2043 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07002044 // The hotseat is the only container where the cell height is going to be
2045 // different from the content within that cell.
2046 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08002047 default:
2048 // ??
2049 return 0;
2050 }
2051 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07002052
Jon Miranda58561d42021-03-17 10:51:54 -04002053 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07002054 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04002055 }
2056
Alex Chaue818bcb2022-09-02 17:27:11 +01002057 private String dpPointFToString(String name, PointF value) {
2058 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
2059 }
2060
Pat Manning5f74bfd2022-07-20 12:08:54 +01002061 /** Dumps various DeviceProfile variables to the specified writer. */
2062 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04002063 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07002064 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04002065
2066 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04002067 writer.println(prefix + "\tisPhone:" + isPhone);
2068 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
2069 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00002070 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04002071
2072 writer.println(prefix + "\tisLandscape:" + isLandscape);
2073 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07002074 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Winson Chung104a4c82023-11-08 18:56:15 +00002075 writer.println(prefix + "\tisLeftRightSplit:" + isLeftRightSplit);
Jon Miranda58561d42021-03-17 10:51:54 -04002076
2077 writer.println(prefix + pxToDpStr("windowX", windowX));
2078 writer.println(prefix + pxToDpStr("windowY", windowY));
2079 writer.println(prefix + pxToDpStr("widthPx", widthPx));
2080 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002081 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
2082 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01002083 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
2084 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
2085 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
2086 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04002087
2088 writer.println(prefix + "\taspectRatio:" + aspectRatio);
2089
Thales Limac98b7812023-04-14 15:04:23 +01002090 writer.println(prefix + "\tisResponsiveGrid:" + mIsResponsiveGrid);
Thales Lima79456492023-05-23 11:32:22 +01002091 writer.println(prefix + "\tisScalableGrid:" + mIsScalableGrid);
Jon Miranda58561d42021-03-17 10:51:54 -04002092
Thales Lima83bedbf2021-10-05 17:47:39 +01002093 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00002094 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
2095 writer.println(prefix + "\tinv.numSearchContainerColumns: "
2096 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04002097
Alex Chaue818bcb2022-09-02 17:27:11 +01002098 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07002099
Jon Miranda58561d42021-03-17 10:51:54 -04002100 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
2101 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
2102
2103 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
2104 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
2105
Thales Lima83bedbf2021-10-05 17:47:39 +01002106 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
2107 cellLayoutBorderSpacePx.x));
2108 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
2109 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002110 writer.println(
2111 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
2112 writer.println(
2113 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
2114 writer.println(
2115 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01002116 writer.println(
2117 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01002118
Jon Miranda58561d42021-03-17 10:51:54 -04002119 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
2120 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
2121 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
2122
Thales Lima1faa4ed2023-12-01 16:48:19 +00002123 writer.println(prefix + "\tnumFolderRows: " + numFolderRows);
2124 writer.println(prefix + "\tnumFolderColumns: " + numFolderColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04002125 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
2126 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
2127 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
2128 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
2129 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
2130 folderChildDrawablePaddingPx));
Jordan Silva637f4eb2023-06-13 11:21:53 +01002131 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.x",
2132 folderCellLayoutBorderSpacePx.x));
2133 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.y",
2134 folderCellLayoutBorderSpacePx.y));
Thales Limaa08a4432022-08-09 09:55:17 +01002135 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
2136 folderContentPaddingLeftRight));
2137 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03002138 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002139
Alex Chaue0227552022-04-06 19:44:43 +01002140 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01002141 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
2142 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
2143 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
2144 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01002145
2146 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
Alex Chau3d2c0622022-09-01 21:28:14 +01002147 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
2148 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04002149 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
2150 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
2151 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
2152 allAppsIconDrawablePaddingPx));
2153 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00002154 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01002155 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
2156 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07002157 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Thales Limab433c9c2023-10-30 12:24:05 +00002158 writer.println(prefix + pxToDpStr("allAppsPadding.top", allAppsPadding.top));
2159 writer.println(prefix + pxToDpStr("allAppsPadding.left", allAppsPadding.left));
2160 writer.println(prefix + pxToDpStr("allAppsPadding.right", allAppsPadding.right));
Alex Chau27b39b92022-01-14 18:02:18 +00002161 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04002162
2163 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
fbarone4b0b712024-03-29 14:31:17 -07002164 writer.println(prefix + "\tmHotseatColumnSpan: " + mHotseatColumnSpan);
2165 writer.println(prefix + pxToDpStr("mHotseatWidthPx", mHotseatWidthPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002166 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00002167 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Thales Lima8e11d532023-08-31 13:40:26 +00002168 writer.println(prefix + pxToDpStr("mHotseatBarEdgePaddingPx",
2169 mHotseatBarEdgePaddingPx));
2170 writer.println(prefix + pxToDpStr("mHotseatBarWorkspaceSpacePx",
2171 mHotseatBarWorkspaceSpacePx));
Pat Manning26f70f72022-07-07 13:50:39 +01002172 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01002173 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
2174 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01002175 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
2176 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002177 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
2178 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
2179 hotseatLayoutPadding.top));
2180 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
2181 hotseatLayoutPadding.bottom));
2182 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
2183 hotseatLayoutPadding.left));
2184 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
2185 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07002186 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00002187 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00002188 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01002189 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04002190
2191 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10002192 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda9c478b62023-03-23 21:38:49 -07002193 writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight));
2194 writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight));
2195 writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin));
2196 writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize));
Jon Miranda58561d42021-03-17 10:51:54 -04002197
Thales Lima83bedbf2021-10-05 17:47:39 +01002198 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
2199 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002200 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
2201 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
2202 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00002203 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04002204
Jon Mirandaab3c6812021-06-28 15:42:28 -07002205 writer.println(prefix + pxToDpStr("iconScale", iconScale));
2206 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04002207 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00002208 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04002209
Thales Lima171ee662022-11-22 15:52:49 +00002210 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04002211 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
2212 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00002213
2214 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00002215 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
2216 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
2217 overviewTaskIconDrawableSizePx));
2218 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
2219 overviewTaskIconDrawableSizeGridPx));
2220 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
2221 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01002222 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
2223 overviewActionsTopMarginPx));
2224 writer.println(prefix + pxToDpStr("overviewActionsHeight",
2225 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00002226 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
2227 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00002228 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
2229 overviewActionsButtonSpacing));
2230 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
2231 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
2232 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01002233
Alex Chau62572c02022-07-25 18:36:37 +00002234 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01002235 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00002236 writer.println(
2237 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01002238
Pat Manning5f74bfd2022-07-20 12:08:54 +01002239 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
2240 getCellLayoutSpringLoadShrunkTop()));
2241 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
2242 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01002243 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
2244 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002245 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
2246 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01002247 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
2248 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Thales Lima79456492023-05-23 11:32:22 +01002249 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00002250 writer.println(prefix + "\tmResponsiveWorkspaceHeightSpec:"
2251 + mResponsiveWorkspaceHeightSpec.toString());
2252 writer.println(prefix + "\tmResponsiveWorkspaceWidthSpec:"
2253 + mResponsiveWorkspaceWidthSpec.toString());
2254 writer.println(prefix + "\tmResponsiveAllAppsHeightSpec:"
2255 + mResponsiveAllAppsHeightSpec.toString());
2256 writer.println(prefix + "\tmResponsiveAllAppsWidthSpec:"
2257 + mResponsiveAllAppsWidthSpec.toString());
Jordan Silva637f4eb2023-06-13 11:21:53 +01002258 writer.println(prefix + "\tmResponsiveFolderHeightSpec:" + mResponsiveFolderHeightSpec);
2259 writer.println(prefix + "\tmResponsiveFolderWidthSpec:" + mResponsiveFolderWidthSpec);
Thales Limaf8bfb032023-07-24 15:08:05 +01002260 writer.println(prefix + "\tmResponsiveHotseatSpec:" + mResponsiveHotseatSpec);
Jordan Silva999dd2a2023-11-17 19:31:43 +00002261 writer.println(prefix + "\tmResponsiveWorkspaceCellSpec:"
2262 + mResponsiveWorkspaceCellSpec);
2263 writer.println(prefix + "\tmResponsiveAllAppsCellSpec:" + mResponsiveAllAppsCellSpec);
Thales Lima79456492023-05-23 11:32:22 +01002264 }
Jon Miranda58561d42021-03-17 10:51:54 -04002265 }
2266
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00002267 /** Returns a reduced representation of this DeviceProfile. */
2268 public String toSmallString() {
2269 return "isTablet:" + isTablet + ", "
2270 + "isMultiDisplay:" + isMultiDisplay + ", "
2271 + "widthPx:" + widthPx + ", "
2272 + "heightPx:" + heightPx + ", "
2273 + "insets:" + mInsets + ", "
2274 + "rotationHint:" + rotationHint;
2275 }
2276
Alex Chaua6907dc2022-03-18 15:24:07 +00002277 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07002278 Configuration config = new Configuration(c.getResources().getConfiguration());
2279 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03002280 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00002281 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07002282 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07002283 }
Sunny Goyalfde55052018-02-01 14:46:13 -08002284
2285 /**
2286 * Callback when a component changes the DeviceProfile associated with it, as a result of
2287 * configuration change
2288 */
2289 public interface OnDeviceProfileChangeListener {
2290
2291 /**
2292 * Called when the device profile is reassigned. Note that for layout and measurements, it
2293 * is sufficient to listen for inset changes. Use this callback when you need to perform
2294 * a one time operation.
2295 */
2296 void onDeviceProfileChanged(DeviceProfile dp);
2297 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002298
Sihua Mae04aa202022-07-18 12:43:56 -07002299 /**
2300 * Handler that deals with ItemInfo of the views for the DeviceProfile
2301 */
2302 @FunctionalInterface
2303 public interface ViewScaleProvider {
2304 /**
2305 * Get the scales from the view
2306 *
2307 * @param itemInfo The tag of the widget view
2308 * @return PointF instance containing the scale information, or null if using the default
2309 * app widget scale of this device profile.
2310 */
2311 @NonNull
2312 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
2313 }
2314
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002315 public static class Builder {
2316 private Context mContext;
2317 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07002318 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002319
Sunny Goyal19ff7282021-04-22 10:12:54 -07002320 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00002321 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002322
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002323 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07002324 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00002325 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07002326 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002327
Sunny Goyal65190ae2022-08-02 14:16:26 -07002328 private SparseArray<DotRenderer> mDotRendererCache;
2329
Jon Miranda2b25ded2023-02-02 14:48:45 -08002330 private Consumer<DeviceProfile> mOverrideProvider;
2331
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002332 private boolean mIsTransientTaskbar;
2333
Sunny Goyalfd58da62020-08-11 12:06:49 -07002334 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002335 mContext = context;
2336 mInv = inv;
2337 mInfo = info;
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002338 mIsTransientTaskbar = info.isTransientTaskbar();
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002339 }
2340
2341 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
2342 mIsMultiWindowMode = isMultiWindowMode;
2343 return this;
2344 }
2345
Alex Chauab800f72022-12-13 17:46:06 +00002346 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
2347 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07002348 return this;
2349 }
2350
Sunny Goyal65190ae2022-08-02 14:16:26 -07002351 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
2352 mDotRendererCache = dotRendererCache;
2353 return this;
2354 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07002355
2356 public Builder setWindowBounds(WindowBounds bounds) {
2357 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07002358 return this;
2359 }
2360
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002361 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
2362 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
2363 return this;
2364 }
2365
Alex Chau6ed408f2022-03-04 12:58:05 +00002366 public Builder setGestureMode(boolean isGestureMode) {
2367 mIsGestureMode = isGestureMode;
2368 return this;
2369 }
2370
Jon Miranda2b25ded2023-02-02 14:48:45 -08002371 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
2372 mOverrideProvider = overrideProvider;
2373 return this;
2374 }
2375
Sihua Mae04aa202022-07-18 12:43:56 -07002376 /**
2377 * Set the viewScaleProvider for the builder
2378 *
2379 * @param viewScaleProvider The viewScaleProvider to be set for the
Thales Limae9273ea2023-01-26 12:33:52 +00002380 * DeviceProfile
Sihua Mae04aa202022-07-18 12:43:56 -07002381 * @return This builder
2382 */
2383 @NonNull
2384 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
2385 mViewScaleProvider = viewScaleProvider;
2386 return this;
2387 }
2388
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002389 /**
2390 * Set the isTransientTaskbar for the builder
2391 * @return This Builder
2392 */
2393 public Builder setIsTransientTaskbar(boolean isTransientTaskbar) {
2394 mIsTransientTaskbar = isTransientTaskbar;
2395 return this;
2396 }
2397
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002398 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07002399 if (mWindowBounds == null) {
2400 throw new IllegalArgumentException("Window bounds not set");
2401 }
2402 if (mTransposeLayoutWithOrientation == null) {
2403 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
2404 }
Alex Chau6ed408f2022-03-04 12:58:05 +00002405 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01002406 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00002407 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002408 if (mDotRendererCache == null) {
2409 mDotRendererCache = new SparseArray<>();
2410 }
Sihua Mae04aa202022-07-18 12:43:56 -07002411 if (mViewScaleProvider == null) {
2412 mViewScaleProvider = DEFAULT_PROVIDER;
2413 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08002414 if (mOverrideProvider == null) {
2415 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
2416 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002417 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00002418 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002419 mIsGestureMode, mViewScaleProvider, mOverrideProvider, mIsTransientTaskbar);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002420 }
2421 }
Winson Chungb3800242013-10-24 11:01:54 -07002422}