blob: f96d59ebbaed5a4172a6f94dfca41600284b7dfd [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;
Thales Lima12d0eff2022-03-25 17:06:11 +000021import static com.android.launcher3.InvariantDeviceProfile.INDEX_DEFAULT;
22import static com.android.launcher3.InvariantDeviceProfile.INDEX_LANDSCAPE;
23import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_LANDSCAPE;
24import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_PORTRAIT;
Jon Miranda58561d42021-03-17 10:51:54 -040025import static com.android.launcher3.Utilities.dpiFromPx;
Jon Mirandaaf3aed02021-05-06 18:28:45 -070026import static com.android.launcher3.Utilities.pxFromSp;
Alex Chauab800f72022-12-13 17:46:06 +000027import static com.android.launcher3.config.FeatureFlags.ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH;
Jon Miranda92c1b5d2021-07-20 13:57:16 -070028import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.ICON_OVERLAP_FACTOR;
Sunny Goyal65190ae2022-08-02 14:16:26 -070029import static com.android.launcher3.icons.GraphicsUtils.getShapePath;
Jon Miranda95f44722023-06-06 19:48:19 -070030import static com.android.launcher3.icons.IconNormalizer.ICON_VISIBLE_AREA_FACTOR;
Thales Limab35faed2022-09-05 16:30:01 -030031import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURCE_HANDLE;
Pat Manning5f74bfd2022-07-20 12:08:54 +010032import static com.android.launcher3.testing.shared.ResourceUtils.pxFromDp;
Thales Lima7eee74b2023-03-16 16:00:55 -030033import static com.android.launcher3.testing.shared.ResourceUtils.roundPxValueFromFloat;
Jon Miranda228877d2021-02-09 11:05:00 -050034
Sunny Goyal35c7b192021-04-20 16:51:10 -070035import android.annotation.SuppressLint;
Winson Chungb3800242013-10-24 11:01:54 -070036import android.content.Context;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070037import android.content.res.Configuration;
Winson Chungb3800242013-10-24 11:01:54 -070038import android.content.res.Resources;
Thales Limab35faed2022-09-05 16:30:01 -030039import android.content.res.TypedArray;
Winson Chungb3800242013-10-24 11:01:54 -070040import android.graphics.Point;
Jon Miranda7ae64ff2016-11-21 16:18:46 -080041import android.graphics.PointF;
Winson Chungb3800242013-10-24 11:01:54 -070042import android.graphics.Rect;
Sunny Goyal35c7b192021-04-20 16:51:10 -070043import android.util.DisplayMetrics;
Sunny Goyal65190ae2022-08-02 14:16:26 -070044import android.util.SparseArray;
Sunny Goyal59d086c2018-05-07 17:31:40 -070045import android.view.Surface;
Winson Chungb3800242013-10-24 11:01:54 -070046
Sunny Goyal65190ae2022-08-02 14:16:26 -070047import androidx.annotation.NonNull;
Sihua Mae04aa202022-07-18 12:43:56 -070048import androidx.annotation.Nullable;
Jon Miranda9c478b62023-03-23 21:38:49 -070049import androidx.core.content.res.ResourcesCompat;
Sunny Goyal65190ae2022-08-02 14:16:26 -070050
Sunny Goyalc13403c2016-11-18 23:44:48 -080051import com.android.launcher3.CellLayout.ContainerType;
Jon Miranda228877d2021-02-09 11:05:00 -050052import com.android.launcher3.DevicePaddings.DevicePadding;
Alex Chaud67ddc42022-09-30 18:15:56 +010053import com.android.launcher3.config.FeatureFlags;
Tony Wickham8912b042018-11-29 15:28:53 -080054import com.android.launcher3.icons.DotRenderer;
Hyunyoung Song48cb7bc2018-09-25 17:03:34 -070055import com.android.launcher3.icons.IconNormalizer;
Sihua Mae04aa202022-07-18 12:43:56 -070056import com.android.launcher3.model.data.ItemInfo;
Jordan Silva999dd2a2023-11-17 19:31:43 +000057import com.android.launcher3.responsive.CalculatedCellSpec;
Thales Limaf8bfb032023-07-24 15:08:05 +010058import com.android.launcher3.responsive.CalculatedHotseatSpec;
Jordan Silvaf2402e22023-10-26 19:53:16 +010059import com.android.launcher3.responsive.CalculatedResponsiveSpec;
60import com.android.launcher3.responsive.HotseatSpecsProvider;
Jordan Silva999dd2a2023-11-17 19:31:43 +000061import com.android.launcher3.responsive.ResponsiveCellSpecsProvider;
Jordan Silvaf2402e22023-10-26 19:53:16 +010062import com.android.launcher3.responsive.ResponsiveSpec.Companion.ResponsiveSpecType;
63import com.android.launcher3.responsive.ResponsiveSpec.DimensionType;
64import com.android.launcher3.responsive.ResponsiveSpecsProvider;
Sunny Goyal57b22792021-05-25 14:35:01 -070065import com.android.launcher3.uioverrides.ApiWrapper;
Thales Lima24ceca62023-09-25 16:21:17 -070066import com.android.launcher3.util.CellContentDimensions;
Sunny Goyalfd58da62020-08-11 12:06:49 -070067import com.android.launcher3.util.DisplayController;
68import com.android.launcher3.util.DisplayController.Info;
Thales Lima2759aa32023-06-05 16:25:45 +010069import com.android.launcher3.util.IconSizeSteps;
Thales Limac98b7812023-04-14 15:04:23 +010070import com.android.launcher3.util.ResourceHelper;
Sunny Goyalb46703d2020-05-27 17:52:03 -070071import com.android.launcher3.util.WindowBounds;
Winson1f064272016-07-18 17:18:02 -070072
Jon Miranda58561d42021-03-17 10:51:54 -040073import java.io.PrintWriter;
Alex Chaue818bcb2022-09-02 17:27:11 +010074import java.util.Locale;
Jon Miranda2b25ded2023-02-02 14:48:45 -080075import java.util.function.Consumer;
Jon Miranda58561d42021-03-17 10:51:54 -040076
Sunny Goyal35c7b192021-04-20 16:51:10 -070077@SuppressLint("NewApi")
Winson Chungb3800242013-10-24 11:01:54 -070078public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070079
Sunny Goyal8b9919d2021-04-07 14:45:17 -070080 private static final int DEFAULT_DOT_SIZE = 100;
Thales Limab35faed2022-09-05 16:30:01 -030081 private static final float MIN_FOLDER_TEXT_SIZE_SP = 16f;
Sunny Goyal6c304b12023-04-10 12:03:04 -070082 private static final float MIN_WIDGET_PADDING_DP = 6f;
Alex Chau206ede92022-08-01 17:46:12 +010083
Shamali Pbe55f822024-01-16 15:07:19 +000084 // Minimum aspect ratio beyond which an extra top padding may be applied to a bottom sheet.
85 private static final float MIN_ASPECT_RATIO_FOR_EXTRA_TOP_PADDING = 1.5f;
fbaron3bb6d4b2024-02-23 10:54:13 -080086 private static final float MAX_ASPECT_RATIO_FOR_ALTERNATE_EDIT_STATE = 1.5f;
Shamali Pbe55f822024-01-16 15:07:19 +000087
Sihua Mae04aa202022-07-18 12:43:56 -070088 public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f);
89 public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE;
Jordan Silvaf2402e22023-10-26 19:53:16 +010090 public static final Consumer<DeviceProfile> DEFAULT_DIMENSION_PROVIDER = dp -> {
91 };
Sihua Mae04aa202022-07-18 12:43:56 -070092
Adam Cohen2e6da152015-05-06 11:42:25 -070093 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070094 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070095 private final DisplayMetrics mMetrics;
Thales Lima2759aa32023-06-05 16:25:45 +010096 private final IconSizeSteps mIconSizeSteps;
Winson Chungbe876472014-05-14 14:15:20 -070097
Sunny Goyalc6205602015-05-21 20:46:33 -070098 // Device properties
99 public final boolean isTablet;
Sunny Goyalc6205602015-05-21 20:46:33 -0700100 public final boolean isPhone;
101 public final boolean transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +0000102 public final boolean isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700103 public final boolean isTwoPanels;
Thales Limaa1012902022-01-13 17:58:42 +0000104 public final boolean isQsbInline;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700105
Sunny Goyalc6205602015-05-21 20:46:33 -0700106 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -0700107 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -0800108 public final boolean isMultiWindowMode;
Alex Chau6ed408f2022-03-04 12:58:05 +0000109 public final boolean isGestureMode;
Sunny Goyald70e75a2018-02-22 10:07:32 -0800110
Winson Chung104a4c82023-11-08 18:56:15 +0000111 public final boolean isLeftRightSplit;
112
Sunny Goyal0addbf02020-04-28 14:17:35 -0700113 public final int windowX;
114 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -0700115 public final int widthPx;
116 public final int heightPx;
117 public final int availableWidthPx;
118 public final int availableHeightPx;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800119 public final int rotationHint;
Jon Mirandabba64512019-03-27 10:54:17 -0700120
121 public final float aspectRatio;
122
Thales Lima79456492023-05-23 11:32:22 +0100123 private final boolean mIsScalableGrid;
Thales Lima83bedbf2021-10-05 17:47:39 +0100124 private final int mTypeIndex;
Jon Mirandae126d722021-02-25 10:45:20 -0500125
Thales Limac98b7812023-04-14 15:04:23 +0100126 // Responsive grid
127 private final boolean mIsResponsiveGrid;
Jordan Silva8f7986a2023-11-08 12:11:25 +0000128 private CalculatedResponsiveSpec mResponsiveWorkspaceWidthSpec;
129 private CalculatedResponsiveSpec mResponsiveWorkspaceHeightSpec;
130 private CalculatedResponsiveSpec mResponsiveAllAppsWidthSpec;
131 private CalculatedResponsiveSpec mResponsiveAllAppsHeightSpec;
Jordan Silvaf2402e22023-10-26 19:53:16 +0100132 private CalculatedResponsiveSpec mResponsiveFolderWidthSpec;
133 private CalculatedResponsiveSpec mResponsiveFolderHeightSpec;
Thales Limaf8bfb032023-07-24 15:08:05 +0100134 private CalculatedHotseatSpec mResponsiveHotseatSpec;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000135 private CalculatedCellSpec mResponsiveWorkspaceCellSpec;
136 private CalculatedCellSpec mResponsiveAllAppsCellSpec;
Thales Limac98b7812023-04-14 15:04:23 +0100137
Tony Wickhamd6b40372015-09-23 18:37:57 -0700138 /**
139 * The maximum amount of left/right workspace padding as a percentage of the screen width.
140 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
141 * 7% of the screen width can be used as right padding.
142 */
143 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -0700144
Jon Miranda3f9bab22017-07-28 14:50:17 -0700145 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700146 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda80dda302021-07-28 14:14:59 -0700147 private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252;
148 private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700149
Sunny Goyalc6205602015-05-21 20:46:33 -0700150 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +0100151 public final int desiredWorkspaceHorizontalMarginOriginalPx;
152 public int desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100153 public int gridVisualizationPaddingX;
154 public int gridVisualizationPaddingY;
Thales Lima78d00ad2021-09-30 11:29:06 +0100155 public Point cellLayoutBorderSpaceOriginalPx;
156 public Point cellLayoutBorderSpacePx;
Pat Manning08610ca2022-04-05 21:03:16 +0100157 public Rect cellLayoutPaddingPx = new Rect();
158
Sunny Goyalc6205602015-05-21 20:46:33 -0700159 public final int edgeMarginPx;
Alex Chau0c4e11b2022-07-08 18:41:36 +0100160 public final float workspaceContentScale;
Alex Chau906d8822022-05-23 10:42:25 +0100161 public final int workspaceSpringLoadedMinNextPageVisiblePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700162
Jon Miranda58561d42021-03-17 10:51:54 -0400163 private final int extraSpace;
Thales Lima171ee662022-11-22 15:52:49 +0000164 private int maxEmptySpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500165 public int workspaceTopPadding;
166 public int workspaceBottomPadding;
167
Tony Wickham5edf9e22020-03-27 20:06:52 -0700168 // Workspace page indicator
169 public final int workspacePageIndicatorHeight;
170 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700171
Sunny Goyalc6205602015-05-21 20:46:33 -0700172 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400173 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700174 public int iconSizePx;
175 public int iconTextSizePx;
176 public int iconDrawablePaddingPx;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000177 private int mIconDrawablePaddingOriginalPx;
Thales Lima79456492023-05-23 11:32:22 +0100178 public boolean iconCenterVertically;
Winson Chungb3800242013-10-24 11:01:54 -0700179
Jon Mirandaab3c6812021-06-28 15:42:28 -0700180 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800181 public int cellWidthPx;
182 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700183 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800184
Thales Lima79456492023-05-23 11:32:22 +0100185 public int cellYPaddingPx = -1;
Jon Mirandae126d722021-02-25 10:45:20 -0500186
Sunny Goyalc6205602015-05-21 20:46:33 -0700187 // Folder
Thales Lima1faa4ed2023-12-01 16:48:19 +0000188 public final int numFolderRows;
189 public final int numFolderColumns;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000190 public final float folderLabelTextScale;
Jon Mirandae126d722021-02-25 10:45:20 -0500191 public int folderLabelTextSizePx;
Thales Limab35faed2022-09-05 16:30:01 -0300192 public int folderFooterHeightPx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700193 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700194 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700195
Jon Mirandae126d722021-02-25 10:45:20 -0500196 // Folder content
Jordan Silva637f4eb2023-06-13 11:21:53 +0100197 public Point folderCellLayoutBorderSpacePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500198 public int folderContentPaddingLeftRight;
199 public int folderContentPaddingTop;
200
Jon Mirandabf7d8122016-11-03 15:29:29 -0700201 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700202 public int folderCellWidthPx;
203 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700204
205 // Folder child
206 public int folderChildIconSizePx;
207 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700208 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700209
Sunny Goyalc6205602015-05-21 20:46:33 -0700210 // Hotseat
Thales Lima9938c2f2022-07-25 14:38:16 +0100211 public int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700212 public int hotseatCellHeightPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100213 public final boolean areNavButtonsInline;
Jon Miranda18751b62017-07-31 17:25:27 -0700214 // In portrait: size = height, in landscape: size = width
215 public int hotseatBarSizePx;
Thales Limab8c05952022-05-23 16:58:38 +0100216 public int hotseatBarBottomSpacePx;
Pat Manning26f70f72022-07-07 13:50:39 +0100217 public int hotseatBarEndOffset;
Thales Limab8c05952022-05-23 16:58:38 +0100218 public int hotseatQsbSpace;
Pat Manningde25c0d2022-04-05 19:11:26 +0100219 public int springLoadedHotseatBarTopMarginPx;
Thales Lima8e11d532023-08-31 13:40:26 +0000220 // These 2 values are only used for isVerticalBar
221 // Padding between edge of screen and hotseat
222 public final int mHotseatBarEdgePaddingPx;
223 // Space between hotseat and workspace (not used in responsive)
224 public final int mHotseatBarWorkspaceSpacePx;
Alex Chau206ede92022-08-01 17:46:12 +0100225 public int hotseatQsbWidth; // only used when isQsbInline
Sunny Goyal57b22792021-05-25 14:35:01 -0700226 public final int hotseatQsbHeight;
Thales Limab8c05952022-05-23 16:58:38 +0100227 public final int hotseatQsbVisualHeight;
228 private final int hotseatQsbShadowHeight;
Thales Limadd027342022-01-07 12:54:37 +0000229 public int hotseatBorderSpace;
Thales Limaffc68b02023-01-09 16:20:23 +0000230 private final int mMinHotseatIconSpacePx;
231 private final int mMinHotseatQsbWidthPx;
232 private final int mMaxHotseatIconSpacePx;
Jon Mirandae17a9492023-03-08 16:42:20 -0800233 public final int inlineNavButtonsEndSpacingPx;
Liran Binyamina833af32023-08-02 16:30:27 -0400234 // Space required for the bubble bar between the hotseat and the edge of the screen. If there's
235 // not enough space, the hotseat will adjust itself for the bubble bar.
236 private final int mBubbleBarSpaceThresholdPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700237
Alex Chau3d2c0622022-09-01 21:28:14 +0100238 // Bottom sheets
239 public int bottomSheetTopPadding;
240 public int bottomSheetOpenDuration;
241 public int bottomSheetCloseDuration;
242 public float bottomSheetWorkspaceScale;
243 public float bottomSheetDepth;
244
Sunny Goyalc6205602015-05-21 20:46:33 -0700245 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000246 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000247 public int allAppsShiftRange;
Thales Limab433c9c2023-10-30 12:24:05 +0000248 public Rect allAppsPadding = new Rect();
Alex Chau3d2c0622022-09-01 21:28:14 +0100249 public int allAppsOpenDuration;
250 public int allAppsCloseDuration;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700251 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700252 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700253 public int allAppsIconSizePx;
254 public int allAppsIconDrawablePaddingPx;
Alex Chau27b39b92022-01-14 18:02:18 +0000255 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700256 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700257 public float allAppsIconTextSizePx;
258
Zak Cohen334efeb2021-03-19 16:42:07 -0700259 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700260 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000261 public int overviewTaskIconSizePx;
Alex Chauac9df382021-08-02 19:08:41 +0100262 public int overviewTaskIconDrawableSizePx;
263 public int overviewTaskIconDrawableSizeGridPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000264 public int overviewTaskThumbnailTopMarginPx;
Alex Chau19c6eca2022-03-10 20:12:56 +0000265 public final int overviewActionsHeight;
Alex Chaua2fc7642022-04-21 14:20:23 +0100266 public final int overviewActionsTopMarginPx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000267 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100268 public int overviewPageSpacing;
269 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000270 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700271
Jeremy Sim0ac47082022-10-10 13:59:40 -0700272 // Split staging
273 public int splitPlaceholderInset;
274
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800275 // Widgets
Sihua Mae04aa202022-07-18 12:43:56 -0700276 private final ViewScaleProvider mViewScaleProvider;
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800277
Sunny Goyal47328fd2016-05-25 18:56:41 -0700278 // Drop Target
279 public int dropTargetBarSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100280 public int dropTargetBarTopMarginPx;
281 public int dropTargetBarBottomMarginPx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100282 public int dropTargetDragPaddingPx;
283 public int dropTargetTextSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100284 public int dropTargetHorizontalPaddingPx;
285 public int dropTargetVerticalPaddingPx;
286 public int dropTargetGapPx;
Alex Chau5b019302022-05-23 10:42:25 +0100287 public int dropTargetButtonWorkspaceEdgeGapPx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700288
Winson1f064272016-07-18 17:18:02 -0700289 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800290 private final Rect mInsets = new Rect();
291 public final Rect workspacePadding = new Rect();
Sunny Goyal6c304b12023-04-10 12:03:04 -0700292 // Additional padding added to the widget inside its cellSpace. It is applied outside
293 // the widgetView, such that the actual view size is same as the widget size.
294 public final Rect widgetPadding = new Rect();
295
Jon Miranda0bd63d12019-03-06 17:29:29 -0800296 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700297 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700298
Tony Wickhamf34bee82018-12-03 18:11:39 -0800299 // Notification dots
Sunny Goyal65190ae2022-08-02 14:16:26 -0700300 public final DotRenderer mDotRendererWorkSpace;
301 public final DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800302
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100303 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800304 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000305 // Whether Taskbar will inset the bottom of apps by taskbarSize.
306 public boolean isTaskbarPresentInApps;
Jon Miranda9c478b62023-03-23 21:38:49 -0700307 public final int taskbarHeight;
308 public final int stashedTaskbarHeight;
309 public final int taskbarBottomMargin;
310 public final int taskbarIconSize;
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000311 private final int mTransientTaskbarClaimedSpace;
Jon Miranda04f05102023-04-04 12:16:31 -0700312 // If true, used to layout taskbar in 3 button navigation mode.
313 public final boolean startAlignTaskbar;
Thales Limae9566402023-08-30 16:35:12 +0100314 public final boolean isTransientTaskbar;
Alex Chaua02eddc2021-04-29 00:36:06 +0100315 // DragController
316 public int flingToDeleteThresholdVelocity;
317
Vinit Nayak17c4b332021-08-05 12:54:58 -0700318 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700319 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal65190ae2022-08-02 14:16:26 -0700320 SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
Alex Chauab800f72022-12-13 17:46:06 +0000321 boolean transposeLayoutWithOrientation, boolean isMultiDisplay, boolean isGestureMode,
Jon Miranda2b25ded2023-02-02 14:48:45 -0800322 @NonNull final ViewScaleProvider viewScaleProvider,
Jagrut Desai3a7d1392023-09-06 15:56:19 -0700323 @NonNull final Consumer<DeviceProfile> dimensionOverrideProvider,
324 boolean isTransientTaskbar) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700325
Adam Cohen2e6da152015-05-06 11:42:25 -0700326 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700327 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800328 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500329 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +0000330 this.isMultiDisplay = isMultiDisplay;
Alex Chau6ed408f2022-03-04 12:58:05 +0000331 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700332 windowX = windowBounds.bounds.left;
333 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800334 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100335 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700336
Thales Limac98b7812023-04-14 15:04:23 +0100337 // TODO(b/241386436): shouldn't change any launcher behaviour
Thales Limaabfe3642023-05-24 18:08:53 +0100338 mIsResponsiveGrid = inv.workspaceSpecsId != INVALID_RESOURCE_HANDLE
Jordan Silva637f4eb2023-06-13 11:21:53 +0100339 && inv.allAppsSpecsId != INVALID_RESOURCE_HANDLE
Thales Limaf8bfb032023-07-24 15:08:05 +0100340 && inv.folderSpecsId != INVALID_RESOURCE_HANDLE
Jordan Silva999dd2a2023-11-17 19:31:43 +0000341 && inv.hotseatSpecsId != INVALID_RESOURCE_HANDLE
342 && inv.workspaceCellSpecsId != INVALID_RESOURCE_HANDLE
343 && inv.allAppsCellSpecsId != INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100344
Thales Lima79456492023-05-23 11:32:22 +0100345 mIsScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000346 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700347 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000348 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700349 isPhone = !isTablet;
Alex Chauab800f72022-12-13 17:46:06 +0000350 isTwoPanels = isTablet && isMultiDisplay;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800351 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700352
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000353 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000354 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700355 ? Configuration.ORIENTATION_LANDSCAPE
356 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000357 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700358 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000359 mMetrics = res.getDisplayMetrics();
360
Charlie Anderson7bb10972023-11-22 13:35:30 -0800361 mIconSizeSteps = new IconSizeSteps(res);
Thales Lima2759aa32023-06-05 16:25:45 +0100362
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000363 // Determine sizes.
364 widthPx = windowBounds.bounds.width();
365 heightPx = windowBounds.bounds.height();
366 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100367 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000368
369 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Thales Lima83bedbf2021-10-05 17:47:39 +0100370 if (isTwoPanels) {
371 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000372 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100373 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000374 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100375 }
376 } else {
377 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000378 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100379 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000380 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100381 }
382 }
383
Jagrut Desai3a7d1392023-09-06 15:56:19 -0700384 this.isTransientTaskbar = isTransientTaskbar;
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000385 int transientTaskbarIconSize = pxFromDp(inv.transientTaskbarIconSize[mTypeIndex], mMetrics);
386 int transientTaskbarBottomMargin =
387 res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin);
388 int transientTaskbarHeight =
389 Math.round((transientTaskbarIconSize * ICON_VISIBLE_AREA_FACTOR)
Jordan Silvaf2402e22023-10-26 19:53:16 +0100390 + (2 * res.getDimensionPixelSize(R.dimen.transient_taskbar_padding)));
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000391 mTransientTaskbarClaimedSpace = transientTaskbarHeight + 2 * transientTaskbarBottomMargin;
392
Uwais Ashraf3602d172023-09-15 11:36:32 +0000393 if (!isTaskbarPresent) {
394 taskbarIconSize = taskbarHeight = stashedTaskbarHeight = taskbarBottomMargin = 0;
395 startAlignTaskbar = false;
396 } else if (isTransientTaskbar) {
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000397 taskbarIconSize = transientTaskbarIconSize;
398 taskbarHeight = transientTaskbarHeight;
Jon Miranda9c478b62023-03-23 21:38:49 -0700399 stashedTaskbarHeight =
400 res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_height);
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000401 taskbarBottomMargin = transientTaskbarBottomMargin;
Jon Miranda04f05102023-04-04 12:16:31 -0700402 startAlignTaskbar = false;
Jon Miranda9c478b62023-03-23 21:38:49 -0700403 } else {
404 taskbarIconSize = pxFromDp(ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size),
405 mMetrics);
406 taskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_size);
407 stashedTaskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
408 taskbarBottomMargin = 0;
Jon Miranda04f05102023-04-04 12:16:31 -0700409 startAlignTaskbar = inv.startAlignTaskbar[mTypeIndex];
Tony Wickham15883892021-02-12 11:24:40 -0800410 }
Tony Wickham15883892021-02-12 11:24:40 -0800411
Winson Chungb3800242013-10-24 11:01:54 -0700412 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100413 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700414
Alex Chau51da2192022-05-20 13:32:10 +0100415 gridVisualizationPaddingX = res.getDimensionPixelSize(
416 R.dimen.grid_visualization_horizontal_cell_spacing);
417 gridVisualizationPaddingY = res.getDimensionPixelSize(
418 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500419
Shamali P5fbb0cc2024-02-06 23:05:35 +0000420 {
421 // In large screens, in portrait mode, a bottom sheet can appear too elongated, so, we
422 // apply additional padding.
423 final boolean applyExtraTopPadding = isTablet
424 && !isLandscape
425 && (aspectRatio > MIN_ASPECT_RATIO_FOR_EXTRA_TOP_PADDING);
426 final int derivedTopPadding = heightPx / 6;
427 bottomSheetTopPadding = mInsets.top // statusbar height
428 + (applyExtraTopPadding ? derivedTopPadding : 0)
429 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
430 }
431
Alex Chau3d2c0622022-09-01 21:28:14 +0100432 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
433 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
434 if (isTablet) {
435 bottomSheetWorkspaceScale = workspaceContentScale;
Alex Chauab800f72022-12-13 17:46:06 +0000436 if (isMultiDisplay && !ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH.get()) {
437 // TODO(b/259893832): Revert to use maxWallpaperScale to calculate bottomSheetDepth
438 // when screen recorder bug is fixed.
439 bottomSheetDepth = 1f;
440 } else {
441 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
442 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
443 // When depth is 1, wallpaper zoom is set to 1.
444 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
445 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
446 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
447 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
448 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100449 } else {
450 bottomSheetWorkspaceScale = 1f;
451 bottomSheetDepth = 0f;
452 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000453
Jon Mirandae126d722021-02-25 10:45:20 -0500454 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
Thales Lima1faa4ed2023-12-01 16:48:19 +0000455 numFolderRows = inv.numFolderRows[mTypeIndex];
456 numFolderColumns = inv.numFolderColumns[mTypeIndex];
Thales Limab35faed2022-09-05 16:30:01 -0300457
Thales Lima79456492023-05-23 11:32:22 +0100458 if (mIsScalableGrid && inv.folderStyle != INVALID_RESOURCE_HANDLE) {
Thales Limab35faed2022-09-05 16:30:01 -0300459 TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
Thales Limad852d652023-01-17 14:01:13 +0000460 R.styleable.FolderStyle);
Thales Limab35faed2022-09-05 16:30:01 -0300461 // These are re-set in #updateFolderCellSize if the grid is not scalable
462 folderCellHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000463 R.styleable.FolderStyle_folderCellHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300464 folderCellWidthPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000465 R.styleable.FolderStyle_folderCellWidth, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300466
467 folderContentPaddingTop = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000468 R.styleable.FolderStyle_folderTopPadding, 0);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100469
470 int gutter = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000471 R.styleable.FolderStyle_folderBorderSpace, 0);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100472 folderCellLayoutBorderSpacePx = new Point(gutter, gutter);
Thales Limab35faed2022-09-05 16:30:01 -0300473 folderFooterHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000474 R.styleable.FolderStyle_folderFooterHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300475 folderStyle.recycle();
Jordan Silva637f4eb2023-06-13 11:21:53 +0100476 } else if (!mIsResponsiveGrid) {
477 folderCellLayoutBorderSpacePx = new Point(0, 0);
Thales Lima7eee74b2023-03-16 16:00:55 -0300478 folderFooterHeightPx = res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Thales Limab35faed2022-09-05 16:30:01 -0300479 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
480 }
Jon Mirandae126d722021-02-25 10:45:20 -0500481
Thales Lima85c942f2021-12-31 13:04:20 +0000482 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000483 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
484 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Thales Limae9273ea2023-01-26 12:33:52 +0000485 setupAllAppsStyle(context);
Jon Mirandae126d722021-02-25 10:45:20 -0500486
Tony Wickham5edf9e22020-03-27 20:06:52 -0700487 workspacePageIndicatorHeight = res.getDimensionPixelSize(
488 R.dimen.workspace_page_indicator_height);
489 mWorkspacePageIndicatorOverlapWorkspace =
490 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700491
Jordan Silva999dd2a2023-11-17 19:31:43 +0000492 if (!mIsResponsiveGrid) {
493 TypedArray cellStyle;
494 if (inv.cellStyle != INVALID_RESOURCE_HANDLE) {
495 cellStyle = context.obtainStyledAttributes(inv.cellStyle,
496 R.styleable.CellStyle);
497 } else {
498 cellStyle = context.obtainStyledAttributes(R.style.CellStyleDefault,
499 R.styleable.CellStyle);
500 }
501 mIconDrawablePaddingOriginalPx = cellStyle.getDimensionPixelSize(
502 R.styleable.CellStyle_iconDrawablePadding, 0);
503 cellStyle.recycle();
Thales Limad852d652023-01-17 14:01:13 +0000504 }
Alex Chaua02eddc2021-04-29 00:36:06 +0100505
Sunny Goyal47328fd2016-05-25 18:56:41 -0700506 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
fbaron3bb6d4b2024-02-23 10:54:13 -0800507 // Some foldable portrait modes are too wide in terms of aspect ratio so we need to tweak
508 // the dimensions for edit state.
509 final boolean shouldApplyWidePortraitDimens = isTablet
510 && !isLandscape
511 && aspectRatio < MAX_ASPECT_RATIO_FOR_ALTERNATE_EDIT_STATE;
512 dropTargetBarTopMarginPx = shouldApplyWidePortraitDimens
513 ? 0
514 : res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
515 dropTargetBarBottomMarginPx = shouldApplyWidePortraitDimens
516 ? res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin_wide_portrait)
517 : res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100518 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
519 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100520 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
521 R.dimen.drop_target_button_drawable_horizontal_padding);
522 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
523 R.dimen.drop_target_button_drawable_vertical_padding);
524 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100525 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
526 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100527
Alex Chau906d8822022-05-23 10:42:25 +0100528 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
529 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700530
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700531 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700532
Thales Limaa1012902022-01-13 17:58:42 +0000533 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100534 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
535 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
536
Thales Lima12d0eff2022-03-25 17:06:11 +0000537 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
538 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
539 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
540 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
541 && hotseatQsbHeight > 0;
Thales Lima79456492023-05-23 11:32:22 +0100542 isQsbInline = mIsScalableGrid && inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000543
Thales Lima425f6822022-05-10 13:44:58 -0300544 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100545 numShownHotseatIcons =
546 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000547
Sunny Goyal19ff7282021-04-22 10:12:54 -0700548 numShownAllAppsColumns =
549 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100550
Thales Lima8e11d532023-08-31 13:40:26 +0000551 int hotseatBarBottomSpace;
Thales Limab8c05952022-05-23 16:58:38 +0100552 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
Thales Limaf8bfb032023-07-24 15:08:05 +0100553
554 if (mIsResponsiveGrid) {
Jordan Silvaf2402e22023-10-26 19:53:16 +0100555 float responsiveAspectRatio = (float) widthPx / heightPx;
556 HotseatSpecsProvider hotseatSpecsProvider =
557 HotseatSpecsProvider.create(new ResourceHelper(context,
Thales Limaf8bfb032023-07-24 15:08:05 +0100558 isTwoPanels ? inv.hotseatSpecsTwoPanelId : inv.hotseatSpecsId));
Thales Lima8e11d532023-08-31 13:40:26 +0000559 mResponsiveHotseatSpec =
Jordan Silvaf2402e22023-10-26 19:53:16 +0100560 isVerticalBarLayout() ? hotseatSpecsProvider.getCalculatedSpec(
561 responsiveAspectRatio, DimensionType.WIDTH, widthPx)
562 : hotseatSpecsProvider.getCalculatedSpec(responsiveAspectRatio,
563 DimensionType.HEIGHT, heightPx);
Thales Limaf8bfb032023-07-24 15:08:05 +0100564 hotseatQsbSpace = mResponsiveHotseatSpec.getHotseatQsbSpace();
Thales Lima8e11d532023-08-31 13:40:26 +0000565 hotseatBarBottomSpace =
566 isVerticalBarLayout() ? 0 : mResponsiveHotseatSpec.getEdgePadding();
567 mHotseatBarEdgePaddingPx =
568 isVerticalBarLayout() ? mResponsiveHotseatSpec.getEdgePadding() : 0;
569 mHotseatBarWorkspaceSpacePx = 0;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000570
571 ResponsiveCellSpecsProvider workspaceCellSpecs = ResponsiveCellSpecsProvider.create(
572 new ResourceHelper(context,
573 isTwoPanels ? inv.workspaceCellSpecsTwoPanelId
574 : inv.workspaceCellSpecsId));
575 mResponsiveWorkspaceCellSpec = workspaceCellSpecs.getCalculatedSpec(
576 responsiveAspectRatio, heightPx);
Thales Limaf8bfb032023-07-24 15:08:05 +0100577 } else {
578 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
Thales Lima8e11d532023-08-31 13:40:26 +0000579 hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
580 mHotseatBarEdgePaddingPx =
581 isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
582 mHotseatBarWorkspaceSpacePx =
583 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Thales Limaf8bfb032023-07-24 15:08:05 +0100584 }
585
Thales Lima8e11d532023-08-31 13:40:26 +0000586 if (!isVerticalBarLayout()) {
587 // Have a little space between the inset and the QSB
588 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
589 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
Thales Limab8c05952022-05-23 16:58:38 +0100590
Thales Lima8e11d532023-08-31 13:40:26 +0000591 // Only change the spaces if there is space
592 if (availableSpace > 0) {
593 // Make sure there is enough space between hotseat/QSB and QSB/navBar
594 if (availableSpace < minQsbMargin * 2) {
595 minQsbMargin = availableSpace / 2;
596 hotseatQsbSpace = minQsbMargin;
597 } else {
598 hotseatQsbSpace -= minQsbMargin;
599 }
Thales Limab8c05952022-05-23 16:58:38 +0100600 }
Thales Lima8e11d532023-08-31 13:40:26 +0000601 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
Thales Limab8c05952022-05-23 16:58:38 +0100602
Thales Lima8e11d532023-08-31 13:40:26 +0000603 } else {
604 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
605 }
Thales Limaa1012902022-01-13 17:58:42 +0000606 }
Thales Lima425f6822022-05-10 13:44:58 -0300607
fbaron3bb6d4b2024-02-23 10:54:13 -0800608 springLoadedHotseatBarTopMarginPx = shouldApplyWidePortraitDimens
609 ? res.getDimensionPixelSize(R.dimen.spring_loaded_hotseat_top_margin_wide_portrait)
610 : res.getDimensionPixelSize(R.dimen.spring_loaded_hotseat_top_margin);
Jordan Silva999dd2a2023-11-17 19:31:43 +0000611
612 if (mIsResponsiveGrid) {
613 updateHotseatSizes(mResponsiveWorkspaceCellSpec.getIconSize());
614 } else {
615 updateHotseatSizes(pxFromDp(inv.iconSize[mTypeIndex], mMetrics));
616 }
617
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700618 if (areNavButtonsInline && !isPhone) {
Jon Mirandae17a9492023-03-08 16:42:20 -0800619 inlineNavButtonsEndSpacingPx =
Thales Limaffc68b02023-01-09 16:20:23 +0000620 res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing);
Pat Manning26f70f72022-07-07 13:50:39 +0100621 /*
622 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700623 * Spacing between nav buttons +
Thales Lima6a590062022-11-22 15:52:49 +0000624 * Space at the end for contextual buttons
Pat Manning26f70f72022-07-07 13:50:39 +0100625 */
626 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700627 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
Jon Mirandae17a9492023-03-08 16:42:20 -0800628 + inlineNavButtonsEndSpacingPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100629 } else {
Jon Mirandae17a9492023-03-08 16:42:20 -0800630 inlineNavButtonsEndSpacingPx = 0;
Pat Manning26f70f72022-07-07 13:50:39 +0100631 hotseatBarEndOffset = 0;
632 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700633
Liran Binyamina833af32023-08-02 16:30:27 -0400634 mBubbleBarSpaceThresholdPx =
635 res.getDimensionPixelSize(R.dimen.bubblebar_hotseat_adjustment_threshold);
636
Thales Lima79456492023-05-23 11:32:22 +0100637 // Needs to be calculated after hotseatBarSizePx is correct,
638 // for the available height to be correct
639 if (mIsResponsiveGrid) {
Thales Lima2759aa32023-06-05 16:25:45 +0100640 int availableResponsiveWidth =
641 availableWidthPx - (isVerticalBarLayout() ? hotseatBarSizePx : 0);
Jordan Silva376036a2023-11-08 15:56:40 +0000642 int numWorkspaceColumns = getPanelCount() * inv.numColumns;
Thales Lima8e11d532023-08-31 13:40:26 +0000643 // don't use availableHeightPx because it subtracts mInsets.bottom
644 int availableResponsiveHeight = heightPx - mInsets.top
Jordan Silvaf2402e22023-10-26 19:53:16 +0100645 - (isVerticalBarLayout() ? 0 : hotseatBarSizePx);
646 float responsiveAspectRatio = (float) widthPx / heightPx;
Thales Limaabfe3642023-05-24 18:08:53 +0100647
Jordan Silvaf2402e22023-10-26 19:53:16 +0100648 ResponsiveSpecsProvider workspaceSpecs = ResponsiveSpecsProvider.create(
Jordan Silva575c3bd2023-07-21 12:00:43 +0100649 new ResourceHelper(context,
Jordan Silvaf2402e22023-10-26 19:53:16 +0100650 isTwoPanels ? inv.workspaceSpecsTwoPanelId : inv.workspaceSpecsId),
651 ResponsiveSpecType.Workspace);
Jordan Silva8f7986a2023-11-08 12:11:25 +0000652 mResponsiveWorkspaceWidthSpec = workspaceSpecs.getCalculatedSpec(responsiveAspectRatio,
Jordan Silva376036a2023-11-08 15:56:40 +0000653 DimensionType.WIDTH, numWorkspaceColumns, availableResponsiveWidth);
Jordan Silva8f7986a2023-11-08 12:11:25 +0000654 mResponsiveWorkspaceHeightSpec = workspaceSpecs.getCalculatedSpec(responsiveAspectRatio,
Jordan Silvaf2402e22023-10-26 19:53:16 +0100655 DimensionType.HEIGHT, inv.numRows, availableResponsiveHeight);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100656
Jordan Silvaf2402e22023-10-26 19:53:16 +0100657 ResponsiveSpecsProvider allAppsSpecs = ResponsiveSpecsProvider.create(
Jordan Silva575c3bd2023-07-21 12:00:43 +0100658 new ResourceHelper(context,
Jordan Silvaf2402e22023-10-26 19:53:16 +0100659 isTwoPanels ? inv.allAppsSpecsTwoPanelId : inv.allAppsSpecsId),
660 ResponsiveSpecType.AllApps);
Jordan Silva8f7986a2023-11-08 12:11:25 +0000661 mResponsiveAllAppsWidthSpec = allAppsSpecs.getCalculatedSpec(responsiveAspectRatio,
Jordan Silva8b3fa142023-11-13 21:31:38 +0000662 DimensionType.WIDTH, numShownAllAppsColumns, availableWidthPx,
Jordan Silva8f7986a2023-11-08 12:11:25 +0000663 mResponsiveWorkspaceWidthSpec);
664 mResponsiveAllAppsHeightSpec = allAppsSpecs.getCalculatedSpec(responsiveAspectRatio,
Jordan Silva2de6a272024-01-04 14:44:20 -0300665 DimensionType.HEIGHT, inv.numAllAppsRowsForCellHeightCalculation,
666 heightPx - mInsets.top, mResponsiveWorkspaceHeightSpec);
Jordan Silvaf2402e22023-10-26 19:53:16 +0100667
668 ResponsiveSpecsProvider folderSpecs = ResponsiveSpecsProvider.create(
669 new ResourceHelper(context,
670 isTwoPanels ? inv.folderSpecsTwoPanelId : inv.folderSpecsId),
671 ResponsiveSpecType.Folder);
672 mResponsiveFolderWidthSpec = folderSpecs.getCalculatedSpec(responsiveAspectRatio,
Thales Lima1faa4ed2023-12-01 16:48:19 +0000673 DimensionType.WIDTH, numFolderColumns,
Jordan Silva8f7986a2023-11-08 12:11:25 +0000674 mResponsiveWorkspaceWidthSpec.getAvailableSpace(),
675 mResponsiveWorkspaceWidthSpec);
Jordan Silvaf2402e22023-10-26 19:53:16 +0100676 mResponsiveFolderHeightSpec = folderSpecs.getCalculatedSpec(responsiveAspectRatio,
Thales Lima1faa4ed2023-12-01 16:48:19 +0000677 DimensionType.HEIGHT, numFolderRows,
Jordan Silva8f7986a2023-11-08 12:11:25 +0000678 mResponsiveWorkspaceHeightSpec.getAvailableSpace(),
679 mResponsiveWorkspaceHeightSpec);
Jordan Silva999dd2a2023-11-17 19:31:43 +0000680
681 ResponsiveCellSpecsProvider allAppsCellSpecs = ResponsiveCellSpecsProvider.create(
682 new ResourceHelper(context,
683 isTwoPanels ? inv.allAppsCellSpecsTwoPanelId
684 : inv.allAppsCellSpecsId));
685 mResponsiveAllAppsCellSpec = allAppsCellSpecs.getCalculatedSpec(
686 responsiveAspectRatio,
687 mResponsiveAllAppsHeightSpec.getAvailableSpace(),
688 mResponsiveWorkspaceCellSpec);
Thales Lima79456492023-05-23 11:32:22 +0100689 }
690
691 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
692 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
693
Alex Chau635b3ab2022-01-26 16:49:10 +0000694 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Pat Manning1695cc72023-07-05 11:45:13 +0100695 overviewTaskIconSizePx = enableOverviewIconMenu() ? res.getDimensionPixelSize(
696 R.dimen.task_thumbnail_icon_menu_drawable_touch_size) : res.getDimensionPixelSize(
697 R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100698 overviewTaskIconDrawableSizePx =
699 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
700 overviewTaskIconDrawableSizeGridPx =
701 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Pat Manning1695cc72023-07-05 11:45:13 +0100702 overviewTaskThumbnailTopMarginPx =
703 enableOverviewIconMenu() ? 0 : overviewTaskIconSizePx + overviewTaskMarginPx;
Andy Wickhambc3bac42023-08-07 16:02:23 -0700704 // Don't add margin with floating search bar to minimize risk of overlapping.
705 overviewActionsTopMarginPx = FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get() ? 0
706 : res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000707 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
708 overviewActionsButtonSpacing = res.getDimensionPixelSize(
709 R.dimen.overview_actions_button_spacing);
Andy Wickhambc3bac42023-08-07 16:02:23 -0700710 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700711 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000712 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700713
Jeremy Sim0ac47082022-10-10 13:59:40 -0700714 splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset);
Winson Chung104a4c82023-11-08 18:56:15 +0000715 // We need to use the full window bounds for split determination because on near-square
716 // devices, the available bounds (bounds minus insets) may actually be in landscape while
717 // actually portrait
718 int leftRightSplitPortraitResId = Resources.getSystem().getIdentifier(
719 "config_leftRightSplitInPortrait", "bool", "android");
720 boolean allowLeftRightSplitInPortrait =
721 com.android.wm.shell.Flags.enableLeftRightSplitInPortrait()
722 && leftRightSplitPortraitResId > 0
723 && res.getBoolean(leftRightSplitPortraitResId);
724 if (allowLeftRightSplitInPortrait && isTablet) {
725 isLeftRightSplit = !isLandscape;
726 } else {
727 isLeftRightSplit = isLandscape;
728 }
Jeremy Sim0ac47082022-10-10 13:59:40 -0700729
Jon Miranda2ed276e2017-06-29 11:36:34 -0700730 // Calculate all of the remaining variables.
Brandon Dayauon5787a272023-12-14 13:47:17 -0800731 extraSpace = updateAvailableDimensions(context);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700732
Thales Lima79456492023-05-23 11:32:22 +0100733 calculateAndSetWorkspaceVerticalPadding(context, inv, extraSpace);
Pat Manning08610ca2022-04-05 21:03:16 +0100734
735 int cellLayoutPadding =
736 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
737 R.dimen.cell_layout_padding);
738 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
739 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800740 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800741
Thales Lima7eee74b2023-03-16 16:00:55 -0300742 // Folder scaling requires correct workspace paddings
743 updateAvailableFolderCellDimensions(res);
744
Thales Limaffc68b02023-01-09 16:20:23 +0000745 mMinHotseatIconSpacePx = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
746 mMinHotseatQsbWidthPx = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
747 mMaxHotseatIconSpacePx = areNavButtonsInline
Thales Lima6a590062022-11-22 15:52:49 +0000748 ? res.getDimensionPixelSize(R.dimen.max_hotseat_icon_space) : Integer.MAX_VALUE;
Thales Lima425f6822022-05-10 13:44:58 -0300749 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima6a590062022-11-22 15:52:49 +0000750 recalculateHotseatWidthAndBorderSpace();
Alex Chau206ede92022-08-01 17:46:12 +0100751
Jordan Silva3646a1b2023-08-02 13:52:52 +0100752 if (mIsResponsiveGrid && isVerticalBarLayout()) {
753 hotseatBorderSpace = cellLayoutBorderSpacePx.y;
754 }
755
Alex Chau206ede92022-08-01 17:46:12 +0100756 if (isTablet) {
Andy Wickham99d7d4f2023-11-15 08:09:09 +0000757 allAppsPadding.top = mInsets.top;
758 allAppsShiftRange = heightPx;
Alex Chau206ede92022-08-01 17:46:12 +0100759 } else {
Thales Limab433c9c2023-10-30 12:24:05 +0000760 allAppsPadding.top = 0;
Alex Chau206ede92022-08-01 17:46:12 +0100761 allAppsShiftRange =
762 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
763 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100764 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
765 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300766
Alex Chaua02eddc2021-04-29 00:36:06 +0100767 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
768 R.dimen.drag_flingToDeleteMinVelocity);
769
Sihua Mae04aa202022-07-18 12:43:56 -0700770 mViewScaleProvider = viewScaleProvider;
771
Jon Miranda2b25ded2023-02-02 14:48:45 -0800772 dimensionOverrideProvider.accept(this);
773
Tony Wickham1237df02017-02-24 08:59:36 -0800774 // This is done last, after iconSizePx is calculated above.
Sunny Goyal799e1202023-02-09 10:54:28 -0800775 mDotRendererWorkSpace = createDotRenderer(context, iconSizePx, dotRendererCache);
776 mDotRendererAllApps = createDotRenderer(context, allAppsIconSizePx, dotRendererCache);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700777 }
778
779 private static DotRenderer createDotRenderer(
Sunny Goyal799e1202023-02-09 10:54:28 -0800780 @NonNull Context context, int size, @NonNull SparseArray<DotRenderer> cache) {
Sunny Goyal65190ae2022-08-02 14:16:26 -0700781 DotRenderer renderer = cache.get(size);
782 if (renderer == null) {
Sunny Goyal799e1202023-02-09 10:54:28 -0800783 renderer = new DotRenderer(size, getShapePath(context, DEFAULT_DOT_SIZE),
784 DEFAULT_DOT_SIZE);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700785 cache.put(size, renderer);
786 }
787 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700788 }
789
Thales Lima425f6822022-05-10 13:44:58 -0300790 /**
Fengjiang Li6c590822023-09-25 15:04:57 -0700791 * Return maximum of all apps row count displayed on screen. Note that 1) Partially displayed
792 * row is counted as 1 row, and 2) we don't exclude the space of floating search bar. This
793 * method is used for calculating number of {@link BubbleTextView} we need to pre-inflate. Thus
794 * reasonable over estimation is fine.
795 */
796 public int getMaxAllAppsRowCount() {
Thales Limab433c9c2023-10-30 12:24:05 +0000797 return (int) (Math.ceil((availableHeightPx - allAppsPadding.top)
Fengjiang Li6c590822023-09-25 15:04:57 -0700798 / (float) allAppsCellHeightPx));
799 }
800
801 /**
Thales Lima425f6822022-05-10 13:44:58 -0300802 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
803 * width of the hotseat.
804 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100805 private int calculateQsbWidth(int hotseatBorderSpace) {
fbarone69b6f42023-12-18 13:20:34 -0800806 int iconExtraSpacePx = iconSizePx - getIconVisibleSizePx(iconSizePx);
Thales Lima425f6822022-05-10 13:44:58 -0300807 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100808 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300809 return getIconToIconWidthForColumns(columns)
810 - iconSizePx * numShownHotseatIcons
fbarone69b6f42023-12-18 13:20:34 -0800811 - hotseatBorderSpace * numShownHotseatIcons
812 - iconExtraSpacePx;
Thales Lima425f6822022-05-10 13:44:58 -0300813 } else {
814 int columns = inv.hotseatColumnSpan[mTypeIndex];
fbarone69b6f42023-12-18 13:20:34 -0800815 return getIconToIconWidthForColumns(columns) - iconExtraSpacePx;
Thales Lima425f6822022-05-10 13:44:58 -0300816 }
817 }
Thales Lima2903a622022-03-17 13:52:19 +0000818
Thales Lima425f6822022-05-10 13:44:58 -0300819 private int getIconToIconWidthForColumns(int columns) {
820 return columns * getCellSize().x
821 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400822 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000823 }
824
Thales Limad90faab2021-09-21 17:18:47 +0100825 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
Thales Lima79456492023-05-23 11:32:22 +0100826 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +0000827 return mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
Thales Lima79456492023-05-23 11:32:22 +0100828 }
829
Thales Limad90faab2021-09-21 17:18:47 +0100830 if (isVerticalBarLayout()) {
831 return 0;
832 }
833
Thales Lima79456492023-05-23 11:32:22 +0100834 return mIsScalableGrid
Thales Lima83bedbf2021-10-05 17:47:39 +0100835 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
836 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100837 }
838
Thales Lima79456492023-05-23 11:32:22 +0100839 private void calculateAndSetWorkspaceVerticalPadding(Context context,
840 InvariantDeviceProfile inv,
841 int extraSpace) {
842 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +0000843 workspaceTopPadding = mResponsiveWorkspaceHeightSpec.getStartPaddingPx();
844 workspaceBottomPadding = mResponsiveWorkspaceHeightSpec.getEndPaddingPx();
Thales Lima79456492023-05-23 11:32:22 +0100845 } else if (mIsScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
846 // Paddings were created assuming no scaling, so we first unscale the extra space.
847 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
848 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
849 DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
850 maxEmptySpace = padding.getMaxEmptySpacePx();
851
852 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
853 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
854
855 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
856 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
857 }
858 }
859
Thales Limab8c05952022-05-23 16:58:38 +0100860 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
861 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700862 // Ensure there is enough space for folder icons, which have a slightly larger radius.
Jordan Silva3646a1b2023-08-02 13:52:52 +0100863 hotseatCellHeightPx = getIconSizeWithOverlap(hotseatIconSizePx);
Thales Limab8c05952022-05-23 16:58:38 +0100864
Jon Miranda0d284852021-06-22 14:50:55 -0700865 if (isVerticalBarLayout()) {
Thales Lima8e11d532023-08-31 13:40:26 +0000866 hotseatBarSizePx = hotseatIconSizePx + mHotseatBarEdgePaddingPx
867 + mHotseatBarWorkspaceSpacePx;
Thales Limab8c05952022-05-23 16:58:38 +0100868 } else if (isQsbInline) {
869 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
870 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700871 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100872 hotseatBarSizePx = hotseatIconSizePx
873 + hotseatQsbSpace
874 + hotseatQsbVisualHeight
875 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700876 }
877 }
878
Thales Lima6a590062022-11-22 15:52:49 +0000879 /**
880 * Calculates the width of the hotseat, changing spaces between the icons and removing icons if
881 * necessary.
882 */
883 public void recalculateHotseatWidthAndBorderSpace() {
Thales Lima79456492023-05-23 11:32:22 +0100884 if (!mIsScalableGrid) return;
Thales Lima6a590062022-11-22 15:52:49 +0000885
886 int columns = inv.hotseatColumnSpan[mTypeIndex];
887 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
888 hotseatBorderSpace = calculateHotseatBorderSpace(hotseatWidthPx, /* numExtraBorder= */ 0);
Thales Lima9938c2f2022-07-25 14:38:16 +0100889 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
Thales Lima6a590062022-11-22 15:52:49 +0000890 // Spaces should be correct when the nav buttons are not inline
Thales Lima9938c2f2022-07-25 14:38:16 +0100891 if (!areNavButtonsInline) {
892 return;
893 }
894
Thales Lima6a590062022-11-22 15:52:49 +0000895 // The side space with inline buttons should be what is defined in InvariantDeviceProfile
Jon Mirandae17a9492023-03-08 16:42:20 -0800896 int sideSpacePx = inlineNavButtonsEndSpacingPx;
Thales Limaffc68b02023-01-09 16:20:23 +0000897 int maxHotseatWidthPx = availableWidthPx - sideSpacePx - hotseatBarEndOffset;
898 int maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
899 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000900 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100901
Thales Limaffc68b02023-01-09 16:20:23 +0000902 if (hotseatBorderSpace >= mMinHotseatIconSpacePx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100903 return;
904 }
905
906 // Border space can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000907 hotseatBorderSpace = mMinHotseatIconSpacePx;
Thales Lima6a590062022-11-22 15:52:49 +0000908 int requiredWidth = getHotseatRequiredWidth();
Thales Lima9938c2f2022-07-25 14:38:16 +0100909
910 // If there is an inline qsb, change its size
911 if (isQsbInline) {
Thales Limaffc68b02023-01-09 16:20:23 +0000912 hotseatQsbWidth -= requiredWidth - maxHotseatWidthPx;
913 if (hotseatQsbWidth >= mMinHotseatQsbWidthPx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100914 return;
915 }
916
917 // QSB can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000918 hotseatQsbWidth = mMinHotseatQsbWidthPx;
Thales Lima9938c2f2022-07-25 14:38:16 +0100919 }
920
Thales Limaffc68b02023-01-09 16:20:23 +0000921 maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
Thales Lima6a590062022-11-22 15:52:49 +0000922
Thales Lima9938c2f2022-07-25 14:38:16 +0100923 // If it still doesn't fit, start removing icons
924 do {
925 numShownHotseatIcons--;
Thales Limaffc68b02023-01-09 16:20:23 +0000926 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000927 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Limaffc68b02023-01-09 16:20:23 +0000928 } while (hotseatBorderSpace < mMinHotseatIconSpacePx && numShownHotseatIcons > 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100929 }
930
Thales Lima78d00ad2021-09-30 11:29:06 +0100931 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100932 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100933 }
934
935 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima79456492023-05-23 11:32:22 +0100936 int horizontalSpacePx = 0;
937 int verticalSpacePx = 0;
Thales Lima78d00ad2021-09-30 11:29:06 +0100938
Thales Lima79456492023-05-23 11:32:22 +0100939 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +0000940 horizontalSpacePx = mResponsiveWorkspaceWidthSpec.getGutterPx();
941 verticalSpacePx = mResponsiveWorkspaceHeightSpec.getGutterPx();
Thales Lima79456492023-05-23 11:32:22 +0100942 } else if (mIsScalableGrid) {
943 horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
944 verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
945 }
Thales Lima78d00ad2021-09-30 11:29:06 +0100946
947 return new Point(horizontalSpacePx, verticalSpacePx);
948 }
949
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700950 public Info getDisplayInfo() {
951 return mInfo;
952 }
953
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700954 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800955 WindowBounds bounds = new WindowBounds(
956 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700957 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100958 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700959
960 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
961 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
962 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
963
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700964 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700965 .setWindowBounds(bounds)
Alex Chauab800f72022-12-13 17:46:06 +0000966 .setIsMultiDisplay(isMultiDisplay)
Alex Chau6ed408f2022-03-04 12:58:05 +0000967 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700968 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000969 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800970 }
971
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700972 public DeviceProfile copy(Context context) {
973 return toBuilder(context).build();
974 }
975
976 /**
977 * TODO: Move this to the builder as part of setMultiWindowMode
978 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700979 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700980 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700981 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700982 .setMultiWindowMode(true)
983 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800984
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800985 // We use these scales to measure and layout the widgets using their full invariant profile
986 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
987 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
988 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700989 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
990 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
991 profile = profile.toBuilder(context)
992 .setViewScaleProvider(i -> p)
993 .build();
994 }
995
996 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800997
Jon Miranda93e1f042016-11-11 14:13:04 -0800998 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700999 }
1000
Adam Cohen63f1ec02014-08-12 09:23:13 -07001001 /**
Jon Miranda941375e2021-03-31 13:10:45 -04001002 * Checks if there is enough space for labels on the workspace.
1003 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -07001004 * It is important to call this method after the All Apps variables have been set.
1005 */
Jon Miranda941375e2021-03-31 13:10:45 -04001006 private void hideWorkspaceLabelsIfNotEnoughSpace() {
1007 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
1008 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
1009 - iconTextHeight;
1010
1011 // We want enough space so that the text is closer to its corresponding icon.
1012 if (workspaceCellPaddingY < iconTextHeight) {
1013 iconTextSizePx = 0;
1014 iconDrawablePaddingPx = 0;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001015 cellHeightPx = getIconSizeWithOverlap(iconSizePx);
Jon Miranda941375e2021-03-31 13:10:45 -04001016 autoResizeAllAppsCells();
1017 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001018 }
Jon Miranda1091e532017-07-21 13:31:50 -07001019
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001020 /**
Jon Miranda228877d2021-02-09 11:05:00 -05001021 * Returns the amount of extra (or unused) vertical space.
1022 */
Brandon Dayauon5787a272023-12-14 13:47:17 -08001023 private int updateAvailableDimensions(Context context) {
fbaronfc6bbcf2024-01-29 10:35:17 -08001024 iconCenterVertically = (mIsScalableGrid || mIsResponsiveGrid) && isVerticalBarLayout();
Jordan Silva999dd2a2023-11-17 19:31:43 +00001025
1026 if (mIsResponsiveGrid) {
Jordan Silva15cacd52023-11-28 14:32:05 +00001027 iconSizePx = mResponsiveWorkspaceCellSpec.getIconSize();
1028 iconTextSizePx = mResponsiveWorkspaceCellSpec.getIconTextSize();
1029 mIconDrawablePaddingOriginalPx = mResponsiveWorkspaceCellSpec.getIconDrawablePadding();
Brandon Dayauon5787a272023-12-14 13:47:17 -08001030 updateIconSize(1f, context);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001031 updateWorkspacePadding();
1032 return 0;
1033 }
1034
Alex Chaua68164d2022-12-15 16:16:03 +00001035 float invIconSizeDp = inv.iconSize[mTypeIndex];
1036 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
1037 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
1038 iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
1039
Brandon Dayauon5787a272023-12-14 13:47:17 -08001040 updateIconSize(1f, context);
Pat Manning08610ca2022-04-05 21:03:16 +01001041 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -05001042
1043 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +01001044 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +00001045 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -05001046 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -05001047 float scaleY = maxHeight / usedHeight;
1048 boolean shouldScale = scaleY < 1f;
1049
1050 float scaleX = 1f;
Thales Lima79456492023-05-23 11:32:22 +01001051 if (mIsScalableGrid) {
Jon Mirandae126d722021-02-25 10:45:20 -05001052 // We scale to fit the cellWidth and cellHeight in the available space.
1053 // The benefit of scalable grids is that we can get consistent aspect ratios between
1054 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +01001055 float usedWidth =
1056 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -05001057 // We do not subtract padding here, as we also scale the workspace padding if needed.
1058 scaleX = availableWidthPx / usedWidth;
1059 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -07001060 }
Jon Mirandae126d722021-02-25 10:45:20 -05001061
1062 if (shouldScale) {
1063 float scale = Math.min(scaleX, scaleY);
Brandon Dayauon5787a272023-12-14 13:47:17 -08001064 updateIconSize(scale, context);
Pat Manninga2e14992022-04-22 11:29:17 +01001065 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -05001066 }
1067
Jon Miranda228877d2021-02-09 11:05:00 -05001068 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -07001069 }
1070
Pat Manninga2e14992022-04-22 11:29:17 +01001071 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +01001072 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
1073 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
1074 }
1075
Pat Manninga2e14992022-04-22 11:29:17 +01001076 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +00001077 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +01001078 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
1079 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -05001080 }
1081
Jordan Silva376036a2023-11-08 15:56:40 +00001082 private int getNormalizedIconDrawablePadding(int iconSizePx, int iconDrawablePadding) {
fbarone69b6f42023-12-18 13:20:34 -08001083 return Math.max(0, iconDrawablePadding
1084 - ((iconSizePx - getIconVisibleSizePx(iconSizePx)) / 2));
Jordan Silva376036a2023-11-08 15:56:40 +00001085 }
1086
1087 private int getNormalizedIconDrawablePadding() {
1088 return getNormalizedIconDrawablePadding(iconSizePx, mIconDrawablePaddingOriginalPx);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001089 }
1090
1091 private int getNormalizedFolderChildDrawablePaddingPx(int textHeight) {
1092 // TODO(b/235886078): workaround needed because of this bug
1093 // Icons are 10% larger on XML than their visual size,
1094 // so remove that extra space to get labels closer to the correct padding
1095 int drawablePadding = (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3;
1096
fbarone69b6f42023-12-18 13:20:34 -08001097 int iconSizeDiff = folderChildIconSizePx - getIconVisibleSizePx(folderChildIconSizePx);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001098 return Math.max(0, drawablePadding - iconSizeDiff / 2);
1099 }
1100
Jordan Silva3646a1b2023-08-02 13:52:52 +01001101 private int getIconSizeWithOverlap(int iconSize) {
1102 return (int) Math.ceil(iconSize * ICON_OVERLAP_FACTOR);
1103 }
1104
Jon Miranda6f7e9702019-09-16 14:44:14 -07001105 /**
1106 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
1107 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
1108 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
1109 */
Brandon Dayauon5787a272023-12-14 13:47:17 -08001110 public void updateIconSize(float scale, Context context) {
Jon Mirandaab3c6812021-06-28 15:42:28 -07001111 // Icon scale should never exceed 1, otherwise pixellation may occur.
1112 iconScale = Math.min(1f, scale);
1113 cellScaleToFit = scale;
1114
Jon Miranda18751b62017-07-31 17:25:27 -07001115 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -08001116 final boolean isVerticalLayout = isVerticalBarLayout();
Thales Lima080d8902022-03-28 15:30:29 +01001117 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -05001118
Thales Lima79456492023-05-23 11:32:22 +01001119 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001120 cellWidthPx = mResponsiveWorkspaceWidthSpec.getCellSizePx();
1121 cellHeightPx = mResponsiveWorkspaceHeightSpec.getCellSizePx();
Thales Lima79456492023-05-23 11:32:22 +01001122
Thales Lima2759aa32023-06-05 16:25:45 +01001123 if (cellWidthPx < iconSizePx) {
1124 // get a smaller icon size
1125 iconSizePx = mIconSizeSteps.getIconSmallerThan(cellWidthPx);
Thales Lima2759aa32023-06-05 16:25:45 +01001126 }
1127
Jordan Silvadd612682024-01-08 11:38:13 -03001128 if (isVerticalLayout) {
1129 iconDrawablePaddingPx = 0;
1130 iconTextSizePx = 0;
1131 } else {
1132 iconDrawablePaddingPx = getNormalizedIconDrawablePadding();
1133 }
Thales Lima93ee8fc2023-06-05 17:07:11 +01001134
Thales Lima24ceca62023-09-25 16:21:17 -07001135 CellContentDimensions cellContentDimensions = new CellContentDimensions(iconSizePx,
1136 iconDrawablePaddingPx,
1137 iconTextSizePx);
Jordan Silvadd612682024-01-08 11:38:13 -03001138 int cellContentHeight = cellContentDimensions.resizeToFitCellHeight(cellHeightPx,
1139 mIconSizeSteps);
Thales Lima24ceca62023-09-25 16:21:17 -07001140 iconSizePx = cellContentDimensions.getIconSizePx();
1141 iconDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1142 iconTextSizePx = cellContentDimensions.getIconTextSizePx();
Thales Lima2759aa32023-06-05 16:25:45 +01001143
Jordan Silvadd612682024-01-08 11:38:13 -03001144 if (isVerticalLayout) {
1145 cellYPaddingPx = Math.max(0, getCellSize().y - getIconSizeWithOverlap(iconSizePx))
1146 / 2;
1147 } else {
1148 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
1149 }
Thales Lima79456492023-05-23 11:32:22 +01001150 } else if (mIsScalableGrid) {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001151 iconDrawablePaddingPx = (int) (getNormalizedIconDrawablePadding() * iconScale);
Thales Lima83bedbf2021-10-05 17:47:39 +01001152 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
1153 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001154
1155 if (cellWidthPx < iconSizePx) {
1156 // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger.
1157 int numColumns = getPanelCount() * inv.numColumns;
1158 int numBorders = numColumns - 1;
1159 int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns;
1160 if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) {
1161 cellWidthPx = iconSizePx;
1162 cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders;
1163 } else {
1164 // If it still doesn't fit, set borderSpace to 0 and distribute the space for
1165 // cellWidth, and reduce iconSize.
1166 cellWidthPx = (cellWidthPx * numColumns
1167 + cellLayoutBorderSpacePx.x * numBorders) / numColumns;
1168 iconSizePx = Math.min(iconSizePx, cellWidthPx);
1169 cellLayoutBorderSpacePx.x = 0;
1170 }
1171 }
1172
Thales Lima93ee8fc2023-06-05 17:07:11 +01001173 int cellTextAndPaddingHeight =
1174 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +00001175 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
1176 if (cellHeightPx < cellContentHeight) {
1177 // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight
1178 // bigger.
1179 int numBorders = inv.numRows - 1;
1180 int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows;
1181 if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) {
1182 cellHeightPx = cellContentHeight;
1183 cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders;
1184 } else {
Alex Chau06f36e82023-01-06 10:50:54 +00001185 // If it still doesn't fit, set borderSpace to 0 to recover space.
Alex Chaube753132022-12-09 16:46:54 +00001186 cellHeightPx = (cellHeightPx * inv.numRows
1187 + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows;
Alex Chaube753132022-12-09 16:46:54 +00001188 cellLayoutBorderSpacePx.y = 0;
Alex Chau06f36e82023-01-06 10:50:54 +00001189 // Reduce iconDrawablePaddingPx to make cellContentHeight smaller.
1190 int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx;
1191 if (cellContentWithoutPadding <= cellHeightPx) {
1192 iconDrawablePaddingPx = cellContentHeight - cellHeightPx;
1193 } else {
1194 // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space,
1195 // then proportional reduce iconSizePx and iconTextSizePx to fit.
1196 iconDrawablePaddingPx = 0;
1197 float ratio = cellHeightPx / (float) cellContentWithoutPadding;
1198 iconSizePx = (int) (iconSizePx * ratio);
1199 iconTextSizePx = (int) (iconTextSizePx * ratio);
1200 }
1201 cellTextAndPaddingHeight =
1202 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +00001203 }
1204 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
1205 }
Jon Mirandae126d722021-02-25 10:45:20 -05001206 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +01001207 desiredWorkspaceHorizontalMarginPx =
1208 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -05001209 } else {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001210 iconDrawablePaddingPx = (int) (getNormalizedIconDrawablePadding() * iconScale);
Jon Mirandae126d722021-02-25 10:45:20 -05001211 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001212 cellHeightPx = getIconSizeWithOverlap(iconSizePx)
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001213 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -05001214 + Utilities.calculateTextHeight(iconTextSizePx);
1215 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
1216 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
1217 && !isMultiWindowMode) {
1218 // Ensures that the label is closer to its corresponding icon. This is not an issue
1219 // with vertical bar layout or multi-window mode since the issue is handled
1220 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
1221 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
1222 iconDrawablePaddingPx = cellPaddingY;
1223 }
Jon Miranda846455e2017-10-02 14:58:52 -07001224 }
Jon Miranda18751b62017-07-31 17:25:27 -07001225
Sunny Goyalae190ff2020-04-14 00:19:01 +00001226 // All apps
Thales Limaabfe3642023-05-24 18:08:53 +01001227 if (mIsResponsiveGrid) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001228 updateAllAppsWithResponsiveMeasures();
Thales Limaabfe3642023-05-24 18:08:53 +01001229 } else {
Brandon Dayauon5787a272023-12-14 13:47:17 -08001230 updateAllAppsIconSize(scale, context.getResources());
Thales Limaabfe3642023-05-24 18:08:53 +01001231 }
1232 updateAllAppsContainerWidth();
Jordan Silvadd612682024-01-08 11:38:13 -03001233 if (isVerticalLayout && !mIsResponsiveGrid) {
Thales Limaabfe3642023-05-24 18:08:53 +01001234 hideWorkspaceLabelsIfNotEnoughSpace();
1235 }
Brandon Dayauon68c18232024-03-07 10:14:44 -08001236 if ((Flags.enableTwolineToggle()
1237 && LauncherPrefs.ENABLE_TWOLINE_ALLAPPS_TOGGLE.get(context))) {
Brandon Dayauon3cdb32c2023-08-22 21:26:37 -07001238 // Add extra textHeight to the existing allAppsCellHeight.
1239 allAppsCellHeightPx += Utilities.calculateTextHeight(allAppsIconTextSizePx);
1240 }
Winson Chungb3800242013-10-24 11:01:54 -07001241
Thales Limab8c05952022-05-23 16:58:38 +01001242 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -07001243
Sunny Goyalbaec6ff2016-09-14 11:26:21 -07001244 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -07001245 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
1246 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Sunny Goyal6c304b12023-04-10 12:03:04 -07001247
1248 // Update widget padding:
1249 float minSpacing = pxFromDp(MIN_WIDGET_PADDING_DP, mMetrics);
1250 if (cellLayoutBorderSpacePx.x < minSpacing
1251 || cellLayoutBorderSpacePx.y < minSpacing) {
1252 widgetPadding.left = widgetPadding.right =
1253 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.x));
1254 widgetPadding.top = widgetPadding.bottom =
1255 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.y));
1256 } else {
1257 widgetPadding.setEmpty();
1258 }
Winson Chung0f785722015-04-08 10:27:49 -07001259 }
1260
Thales Lima425f6822022-05-10 13:44:58 -03001261 /**
Thales Lima6a590062022-11-22 15:52:49 +00001262 * This method calculates the space between the icons to achieve a certain width.
Thales Lima425f6822022-05-10 13:44:58 -03001263 */
Thales Lima6a590062022-11-22 15:52:49 +00001264 private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) {
Jordan Silvad9227182023-08-17 15:53:59 +01001265 int numBorders = (numShownHotseatIcons - 1 + numExtraBorder);
1266 if (numBorders <= 0) return 0;
1267
Thales Lima9938c2f2022-07-25 14:38:16 +01001268 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
Jordan Silvad9227182023-08-17 15:53:59 +01001269 int hotseatBorderSpacePx = (int) (hotseatWidthPx - hotseatIconsTotalPx) / numBorders;
Thales Limaffc68b02023-01-09 16:20:23 +00001270 return Math.min(hotseatBorderSpacePx, mMaxHotseatIconSpacePx);
Thales Lima425f6822022-05-10 13:44:58 -03001271 }
1272
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001273 /**
1274 * Updates the iconSize for allApps* variants.
1275 */
Brian Isganitisa9a78112022-05-23 18:11:47 -07001276 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +01001277 allAppsBorderSpacePx = new Point(
1278 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
1279 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001280 // AllApps cells don't have real space between cells,
1281 // so we add the border space to the cell height
Alex Chaube753132022-12-09 16:46:54 +00001282 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics)
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001283 + allAppsBorderSpacePx.y;
1284 // but width is just the cell,
1285 // the border is added in #updateAllAppsContainerWidth
Thales Lima79456492023-05-23 11:32:22 +01001286 if (mIsScalableGrid) {
Alex Chaube753132022-12-09 16:46:54 +00001287 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1288 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001289 allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding();
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001290 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001291
1292 if (allAppsCellWidthPx < allAppsIconSizePx) {
1293 // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to
1294 // make allAppsCellWidth bigger.
1295 int numBorders = inv.numAllAppsColumns - 1;
1296 int extraWidthRequired =
1297 (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns;
1298 if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) {
1299 allAppsCellWidthPx = allAppsIconSizePx;
1300 allAppsBorderSpacePx.x -= extraWidthRequired / numBorders;
1301 } else {
1302 // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space
1303 // for allAppsCellWidth, and reduce allAppsIconSize.
1304 allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns
1305 + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns;
1306 allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx);
1307 allAppsBorderSpacePx.x = 0;
1308 }
1309 }
1310
1311 int cellContentHeight = allAppsIconSizePx
1312 + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y;
1313 if (allAppsCellHeightPx < cellContentHeight) {
1314 // Increase allAppsCellHeight to fit its content.
1315 allAppsCellHeightPx = cellContentHeight;
1316 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001317 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001318 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
1319 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001320 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1321 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001322 allAppsIconDrawablePaddingPx =
1323 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001324 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001325 }
Thales Limaabfe3642023-05-24 18:08:53 +01001326 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001327
Jordan Silva999dd2a2023-11-17 19:31:43 +00001328 private void updateAllAppsWithResponsiveMeasures() {
1329 allAppsIconSizePx = mResponsiveAllAppsCellSpec.getIconSize();
1330 allAppsIconTextSizePx = mResponsiveAllAppsCellSpec.getIconTextSize();
1331 allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding(allAppsIconSizePx,
1332 mResponsiveAllAppsCellSpec.getIconDrawablePadding());
Thales Limaabfe3642023-05-24 18:08:53 +01001333 allAppsBorderSpacePx = new Point(
Jordan Silva8f7986a2023-11-08 12:11:25 +00001334 mResponsiveAllAppsWidthSpec.getGutterPx(),
1335 mResponsiveAllAppsHeightSpec.getGutterPx()
Thales Limaabfe3642023-05-24 18:08:53 +01001336 );
Jordan Silva999dd2a2023-11-17 19:31:43 +00001337 allAppsCellHeightPx = mResponsiveAllAppsHeightSpec.getCellSizePx();
Jordan Silva8f7986a2023-11-08 12:11:25 +00001338 allAppsCellWidthPx = mResponsiveAllAppsWidthSpec.getCellSizePx();
Thales Limaa25cd902023-11-01 12:00:32 +00001339
1340 // This workaround is needed to align AllApps icons with Workspace icons
1341 // since AllApps doesn't have borders between cells
1342 int halfBorder = allAppsBorderSpacePx.x / 2;
Jordan Silva8f7986a2023-11-08 12:11:25 +00001343 allAppsPadding.left = mResponsiveAllAppsWidthSpec.getStartPaddingPx() - halfBorder;
1344 allAppsPadding.right = mResponsiveAllAppsWidthSpec.getEndPaddingPx() - halfBorder;
Jordan Silva376036a2023-11-08 15:56:40 +00001345
Jordan Silva376036a2023-11-08 15:56:40 +00001346
1347 // Reduce the size of the app icon if it doesn't fit
1348 if (allAppsCellWidthPx < allAppsIconSizePx) {
1349 // get a smaller icon size
1350 allAppsIconSizePx = mIconSizeSteps.getIconSmallerThan(allAppsCellWidthPx);
1351 }
1352
1353 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1354 allAppsIconSizePx, allAppsIconDrawablePaddingPx, (int) allAppsIconTextSizePx);
1355
1356 if (allAppsCellHeightPx < cellContentDimensions.getCellContentHeight()) {
1357 if (isVerticalBarLayout()) {
Jordan Silva2de6a272024-01-04 14:44:20 -03001358 if (allAppsCellHeightPx < allAppsIconSizePx) {
Jordan Silva376036a2023-11-08 15:56:40 +00001359 cellContentDimensions.setIconSizePx(
1360 mIconSizeSteps.getIconSmallerThan(allAppsCellHeightPx));
1361 }
1362 } else {
1363 cellContentDimensions.resizeToFitCellHeight(allAppsCellHeightPx,
1364 mIconSizeSteps);
1365 }
1366 allAppsIconSizePx = cellContentDimensions.getIconSizePx();
1367 allAppsIconDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1368 allAppsIconTextSizePx = cellContentDimensions.getIconTextSizePx();
1369 }
Jordan Silva999dd2a2023-11-17 19:31:43 +00001370
1371 allAppsCellHeightPx += mResponsiveAllAppsHeightSpec.getGutterPx();
Jordan Silvadd612682024-01-08 11:38:13 -03001372
1373 if (isVerticalBarLayout()) {
1374 autoResizeAllAppsCells();
1375 }
Thales Limaabfe3642023-05-24 18:08:53 +01001376 }
1377
1378 /**
1379 * Re-computes the all-apps cell size to be independent of workspace
1380 */
1381 public void autoResizeAllAppsCells() {
1382 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
1383 int topBottomPadding = textHeight;
1384 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
1385 + textHeight + (topBottomPadding * 2);
1386 }
1387
1388 private void updateAllAppsContainerWidth() {
1389 int cellLayoutHorizontalPadding =
1390 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
1391 if (isTablet) {
1392 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
1393 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Thales Limab433c9c2023-10-30 12:24:05 +00001394 + allAppsPadding.left + allAppsPadding.right;
Thales Limaabfe3642023-05-24 18:08:53 +01001395 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
Thales Limaa25cd902023-11-01 12:00:32 +00001396 } else if (!mIsResponsiveGrid) {
Thales Limab433c9c2023-10-30 12:24:05 +00001397 allAppsPadding.left = allAppsPadding.right =
Thales Limaabfe3642023-05-24 18:08:53 +01001398 Math.max(0, desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding
1399 - (allAppsBorderSpacePx.x / 2));
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001400 }
1401 }
1402
Thales Limaabfe3642023-05-24 18:08:53 +01001403 private void setupAllAppsStyle(Context context) {
1404 TypedArray allAppsStyle = context.obtainStyledAttributes(
1405 inv.allAppsStyle != INVALID_RESOURCE_HANDLE ? inv.allAppsStyle
1406 : R.style.AllAppsStyleDefault, R.styleable.AllAppsStyle);
1407
Thales Limab433c9c2023-10-30 12:24:05 +00001408 allAppsPadding.left = allAppsPadding.right = allAppsStyle.getDimensionPixelSize(
Thales Limaabfe3642023-05-24 18:08:53 +01001409 R.styleable.AllAppsStyle_horizontalPadding, 0);
1410 allAppsStyle.recycle();
1411 }
1412
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001413 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001414 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001415
Jordan Silva637f4eb2023-06-13 11:21:53 +01001416 // Responsive grid doesn't need to scale the folder
1417 if (mIsResponsiveGrid) return;
1418
Thales Lima7eee74b2023-03-16 16:00:55 -03001419 // For usability we can't have the folder use the whole width of the screen
Sunny Goyal07b69292018-01-08 14:19:34 -08001420 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -08001421
Thales Lima7eee74b2023-03-16 16:00:55 -03001422 // Check if the folder fit within the available height.
Thales Lima1faa4ed2023-12-01 16:48:19 +00001423 float contentUsedHeight = folderCellHeightPx * numFolderRows
1424 + ((numFolderRows - 1) * folderCellLayoutBorderSpacePx.y)
Thales Lima7eee74b2023-03-16 16:00:55 -03001425 + folderFooterHeightPx
1426 + folderContentPaddingTop;
1427 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001428 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -08001429
Thales Lima7eee74b2023-03-16 16:00:55 -03001430 // Check if the folder fit within the available width.
Thales Lima1faa4ed2023-12-01 16:48:19 +00001431 float contentUsedWidth = folderCellWidthPx * numFolderColumns
1432 + ((numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x)
Thales Lima7eee74b2023-03-16 16:00:55 -03001433 + folderContentPaddingLeftRight * 2;
1434 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001435 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -08001436
1437 float scale = Math.min(scaleX, scaleY);
1438 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001439 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001440 }
1441 }
1442
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001443 private void updateFolderCellSize(float scale, Resources res) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001444 int minLabelTextSize = pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001445 if (mIsResponsiveGrid) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001446 folderChildIconSizePx = mResponsiveWorkspaceCellSpec.getIconSize();
1447 folderChildTextSizePx = mResponsiveWorkspaceCellSpec.getIconTextSize();
1448 folderLabelTextSizePx = Math.max(minLabelTextSize,
1449 (int) (folderChildTextSizePx * folderLabelTextScale));
1450 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
1451
Jordan Silva637f4eb2023-06-13 11:21:53 +01001452 folderCellWidthPx = mResponsiveFolderWidthSpec.getCellSizePx();
Jordan Silva637f4eb2023-06-13 11:21:53 +01001453 folderCellHeightPx = mResponsiveFolderHeightSpec.getCellSizePx();
1454 folderContentPaddingTop = mResponsiveFolderHeightSpec.getStartPaddingPx();
1455 folderFooterHeightPx = mResponsiveFolderHeightSpec.getEndPaddingPx();
1456
1457 folderCellLayoutBorderSpacePx = new Point(mResponsiveFolderWidthSpec.getGutterPx(),
Thales Lima4cfd9502023-07-10 14:01:28 +01001458 mResponsiveFolderHeightSpec.getGutterPx());
Jordan Silva637f4eb2023-06-13 11:21:53 +01001459
1460 folderContentPaddingLeftRight = mResponsiveFolderWidthSpec.getStartPaddingPx();
Jordan Silva12fae112023-06-26 12:51:01 +01001461
1462 // Reduce icon width if it's wider than the expected folder cell width
1463 if (folderCellWidthPx < folderChildIconSizePx) {
1464 folderChildIconSizePx = mIconSizeSteps.getIconSmallerThan(folderCellWidthPx);
1465 }
1466
1467 // Recalculating padding and cell height
Jordan Silva3e5688a2023-12-05 15:12:29 -03001468 folderChildDrawablePaddingPx = mResponsiveWorkspaceCellSpec.getIconDrawablePadding();
Jordan Silva12fae112023-06-26 12:51:01 +01001469
Thales Limae9b5e142023-11-04 17:10:13 +00001470 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1471 folderChildIconSizePx,
1472 folderChildDrawablePaddingPx,
1473 folderChildTextSizePx);
1474 cellContentDimensions.resizeToFitCellHeight(folderCellHeightPx, mIconSizeSteps);
1475 folderChildIconSizePx = cellContentDimensions.getIconSizePx();
1476 folderChildDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1477 folderChildTextSizePx = cellContentDimensions.getIconTextSizePx();
Jordan Silva999dd2a2023-11-17 19:31:43 +00001478 folderLabelTextSizePx = Math.max(minLabelTextSize,
Jordan Silva9a3bd8f2023-11-16 18:33:28 +00001479 (int) (folderChildTextSizePx * folderLabelTextScale));
Jordan Silva999dd2a2023-11-17 19:31:43 +00001480 return;
1481 }
1482
1483 float invIconSizeDp = inv.iconSize[mTypeIndex];
1484 float invIconTextSizeDp = inv.iconTextSize[mTypeIndex];
1485 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1486 folderChildTextSizePx = pxFromSp(invIconTextSizeDp, mMetrics, scale);
1487 folderLabelTextSizePx = Math.max(minLabelTextSize,
1488 (int) (folderChildTextSizePx * folderLabelTextScale));
1489 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
1490
1491 if (mIsScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001492 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
Thales Lima7eee74b2023-03-16 16:00:55 -03001493 folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale);
1494 folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale);
1495 } else {
1496 folderCellWidthPx = roundPxValueFromFloat(folderCellWidthPx * scale);
1497 folderCellHeightPx = roundPxValueFromFloat(folderCellHeightPx * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001498 }
Charlie Anderson7bb10972023-11-22 13:35:30 -08001499 // Recalculating padding and cell height
1500 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
1501
1502 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1503 folderChildIconSizePx,
1504 folderChildDrawablePaddingPx,
1505 folderChildTextSizePx);
1506 cellContentDimensions.resizeToFitCellHeight(folderCellHeightPx, mIconSizeSteps);
1507 folderChildIconSizePx = cellContentDimensions.getIconSizePx();
1508 folderChildDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1509 folderChildTextSizePx = cellContentDimensions.getIconTextSizePx();
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001510
Thales Lima7eee74b2023-03-16 16:00:55 -03001511 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001512 folderCellLayoutBorderSpacePx = new Point(
1513 roundPxValueFromFloat(folderCellLayoutBorderSpacePx.x * scale),
1514 roundPxValueFromFloat(folderCellLayoutBorderSpacePx.y * scale)
1515 );
Thales Lima7eee74b2023-03-16 16:00:55 -03001516 folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001517 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx.x;
Jon Miranda823da222021-03-23 08:08:45 -04001518 } else {
1519 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1520 * scale);
1521 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1522 * scale);
1523
1524 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1525 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Lima7eee74b2023-03-16 16:00:55 -03001526 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001527 folderContentPaddingLeftRight =
1528 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1529 folderFooterHeightPx =
Thales Lima7eee74b2023-03-16 16:00:55 -03001530 roundPxValueFromFloat(
1531 res.getDimensionPixelSize(R.dimen.folder_footer_height_default)
1532 * scale);
1533
Jordan Silva12fae112023-06-26 12:51:01 +01001534 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
Jon Miranda823da222021-03-23 08:08:45 -04001535 }
Jon Mirandabf7d8122016-11-03 15:29:29 -07001536 }
1537
Winson1f064272016-07-18 17:18:02 -07001538 public void updateInsets(Rect insets) {
1539 mInsets.set(insets);
1540 }
1541
Sunny Goyalae6e3182019-04-30 12:04:37 -07001542 /**
1543 * The current device insets. This is generally same as the insets being dispatched to
1544 * {@link Insettable} elements, but can differ if the element is using a different profile.
1545 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001546 public Rect getInsets() {
1547 return mInsets;
1548 }
1549
Sunny Goyal756cd262015-08-20 12:33:21 -07001550 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001551 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001552 }
1553
Sunny Goyal19ff7282021-04-22 10:12:54 -07001554 public Point getCellSize(Point result) {
1555 if (result == null) {
1556 result = new Point();
1557 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001558
Pat Manning25d53342022-05-10 09:58:49 +00001559 int shortcutAndWidgetContainerWidth =
1560 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1561 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1562 inv.numColumns);
1563 int shortcutAndWidgetContainerHeight =
1564 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1565 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1566 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001567 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001568 }
1569
1570 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001571 * Returns the left and right space on the cell, which is the cell width - icon size
1572 */
1573 public int getCellHorizontalSpace() {
1574 return getCellSize().x - iconSizePx;
1575 }
1576
1577 /**
Pat Manning25d53342022-05-10 09:58:49 +00001578 * Gets the number of panels within the workspace.
1579 */
1580 public int getPanelCount() {
1581 return isTwoPanels ? 2 : 1;
1582 }
1583
1584 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001585 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1586 * bottom of the screen.
1587 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001588 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1589 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001590 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001591 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001592 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001593 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001594 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001595 }
1596
1597 /**
1598 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1599 */
Pat Manning25d53342022-05-10 09:58:49 +00001600 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001601 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001602 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001603 }
1604
1605 /**
1606 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1607 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001608 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001609 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001610 return heightPx - (isVerticalBarLayout()
1611 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001612 }
1613
Pat Manningea5c1d22022-04-14 10:58:16 +01001614 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001615 * Gets the scale of the workspace for the spring-loaded edit state.
1616 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001617 public float getWorkspaceSpringLoadScale(Context context) {
1618 float scale =
1619 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1620 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001621 scale = Math.min(scale, 1f);
1622
Pat Manninge63dd252022-08-02 16:15:29 +01001623 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001624 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001625 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001626 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001627 if (scaledWorkspaceWidth > maxAvailableWidth) {
1628 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1629 }
1630 return scale;
1631 }
1632
Pat Manning25d53342022-05-10 09:58:49 +00001633 /**
1634 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1635 *
1636 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1637 * layouts have two Cell Layouts per workspace.
1638 */
1639 public int getCellLayoutWidth() {
1640 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001641 }
1642
Pat Manning25d53342022-05-10 09:58:49 +00001643 /**
1644 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1645 *
1646 * <p>This is the height of a Workspace, less its vertical padding.
1647 */
1648 public int getCellLayoutHeight() {
1649 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001650 }
1651
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001652 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001653 return new Point(workspacePadding.left + workspacePadding.right,
1654 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001655 }
1656
1657 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001658 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1659 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001660 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001661 private void updateWorkspacePadding() {
1662 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001663 if (isVerticalBarLayout()) {
Jordan Silva3646a1b2023-08-02 13:52:52 +01001664 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001665 padding.top = mResponsiveWorkspaceHeightSpec.getStartPaddingPx();
Thales Lima8e11d532023-08-31 13:40:26 +00001666 padding.bottom = Math.max(0,
Jordan Silva8f7986a2023-11-08 12:11:25 +00001667 mResponsiveWorkspaceHeightSpec.getEndPaddingPx() - mInsets.bottom);
Jordan Silva3646a1b2023-08-02 13:52:52 +01001668 if (isSeascape()) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001669 padding.left =
1670 hotseatBarSizePx + mResponsiveWorkspaceWidthSpec.getEndPaddingPx();
1671 padding.right = mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
Jordan Silva3646a1b2023-08-02 13:52:52 +01001672 } else {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001673 padding.left = mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
1674 padding.right =
1675 hotseatBarSizePx + mResponsiveWorkspaceWidthSpec.getEndPaddingPx();
Jordan Silva3646a1b2023-08-02 13:52:52 +01001676 }
Winson1f064272016-07-18 17:18:02 -07001677 } else {
Jordan Silva3646a1b2023-08-02 13:52:52 +01001678 padding.top = 0;
1679 padding.bottom = edgeMarginPx;
1680 if (isSeascape()) {
1681 padding.left = hotseatBarSizePx;
Thales Lima8e11d532023-08-31 13:40:26 +00001682 padding.right = mHotseatBarEdgePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001683 } else {
Thales Lima8e11d532023-08-31 13:40:26 +00001684 padding.left = mHotseatBarEdgePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001685 padding.right = hotseatBarSizePx;
1686 }
Winson1f064272016-07-18 17:18:02 -07001687 }
Winson Chungb3800242013-10-24 11:01:54 -07001688 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001689 // Pad the bottom of the workspace with hotseat bar
1690 // and leave a bit of space in case a widget go all the way down
Thales Lima79456492023-05-23 11:32:22 +01001691 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding - mInsets.bottom;
1692 if (!mIsResponsiveGrid) {
1693 paddingBottom +=
1694 workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace;
1695 }
1696 int paddingTop = workspaceTopPadding + (mIsScalableGrid ? 0 : edgeMarginPx);
Pat Manning08610ca2022-04-05 21:03:16 +01001697 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001698
Pat Manning08610ca2022-04-05 21:03:16 +01001699 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001700 }
Pat Manning08610ca2022-04-05 21:03:16 +01001701 insetPadding(workspacePadding, cellLayoutPaddingPx);
1702 }
1703
1704 private void insetPadding(Rect paddings, Rect insets) {
1705 insets.left = Math.min(insets.left, paddings.left);
1706 paddings.left -= insets.left;
1707
1708 insets.top = Math.min(insets.top, paddings.top);
1709 paddings.top -= insets.top;
1710
1711 insets.right = Math.min(insets.right, paddings.right);
1712 paddings.right -= insets.right;
1713
1714 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1715 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001716 }
1717
Liran Binyamina833af32023-08-02 16:30:27 -04001718
1719 /**
1720 * Returns the new border space that should be used between hotseat icons after adjusting it to
1721 * the bubble bar.
1722 *
1723 * <p>If there's no adjustment needed, this method returns {@code 0}.
1724 */
1725 public float getHotseatAdjustedBorderSpaceForBubbleBar(Context context) {
1726 // only need to adjust when QSB is on top of the hotseat.
1727 if (isQsbInline) {
1728 return 0;
1729 }
1730
1731 // no need to adjust if there's enough space for the bubble bar to the right of the hotseat.
1732 if (getHotseatLayoutPadding(context).right > mBubbleBarSpaceThresholdPx) {
1733 return 0;
1734 }
1735
1736 // The adjustment is shrinking the hotseat's width by 1 icon on either side.
1737 int iconsWidth =
1738 iconSizePx * numShownHotseatIcons + hotseatBorderSpace * (numShownHotseatIcons - 1);
1739 int newWidth = iconsWidth - 2 * iconSizePx;
1740 // Evenly space the icons within the boundaries of the new width.
1741 return (float) (newWidth - iconSizePx * numShownHotseatIcons) / (numShownHotseatIcons - 1);
1742 }
1743
Sunny Goyal57b22792021-05-25 14:35:01 -07001744 /**
1745 * Returns the padding for hotseat view
1746 */
1747 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001748 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001749 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001750 // The hotseat icons will be placed in the middle of the hotseat cells.
1751 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1752 // in vertical bar layout.
fbaronfc6bbcf2024-01-29 10:35:17 -08001753 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top), 0);
1754 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom), 0);
Sihua Ma38bb3b02022-03-21 22:20:14 -07001755
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001756 if (isSeascape()) {
Thales Lima8e11d532023-08-31 13:40:26 +00001757 hotseatBarPadding.set(mInsets.left + mHotseatBarEdgePaddingPx, paddingTop,
1758 mHotseatBarWorkspaceSpacePx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001759 } else {
Thales Lima8e11d532023-08-31 13:40:26 +00001760 hotseatBarPadding.set(mHotseatBarWorkspaceSpacePx, paddingTop,
1761 mInsets.right + mHotseatBarEdgePaddingPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001762 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001763 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001764 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001765 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1766 int hotseatBarTopPadding =
1767 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001768
Thales Lima6a590062022-11-22 15:52:49 +00001769 int hotseatWidth = getHotseatRequiredWidth();
Helen Cheuke76291f2023-02-14 17:11:05 +00001770 int startSpacing;
1771 int endSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001772 // Hotseat aligns to the left with nav buttons
1773 if (hotseatBarEndOffset > 0) {
Jon Mirandae17a9492023-03-08 16:42:20 -08001774 startSpacing = inlineNavButtonsEndSpacingPx;
Helen Cheuke76291f2023-02-14 17:11:05 +00001775 endSpacing = availableWidthPx - hotseatWidth - startSpacing + hotseatBorderSpace;
1776 } else {
1777 startSpacing = (availableWidthPx - hotseatWidth) / 2;
1778 endSpacing = startSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001779 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001780 startSpacing += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001781
Helen Cheuke76291f2023-02-14 17:11:05 +00001782 hotseatBarPadding.top = hotseatBarTopPadding;
1783 hotseatBarPadding.bottom = hotseatBarBottomPadding;
Alex Chau51da2192022-05-20 13:32:10 +01001784 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001785 if (isRtl) {
Helen Cheuke76291f2023-02-14 17:11:05 +00001786 hotseatBarPadding.left = endSpacing;
1787 hotseatBarPadding.right = startSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001788 } else {
Helen Cheuke76291f2023-02-14 17:11:05 +00001789 hotseatBarPadding.left = startSpacing;
1790 hotseatBarPadding.right = endSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001791 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001792
Thales Lima79456492023-05-23 11:32:22 +01001793 } else if (mIsScalableGrid) {
fbarone69b6f42023-12-18 13:20:34 -08001794 int iconExtraSpacePx = iconSizePx - getIconVisibleSizePx(iconSizePx);
1795 int sideSpacing = (availableWidthPx - (hotseatQsbWidth + iconExtraSpacePx)) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001796 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001797 0,
Thales Lima425f6822022-05-10 13:44:58 -03001798 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001799 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001800 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001801 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1802 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1803 // for this, we pad the left and right of the hotseat with half of the difference of a
1804 // workspace cell vs a hotseat cell.
1805 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001806 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001807 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001808 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001809 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1810 + mInsets.left,
1811 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001812 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001813 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001814 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001815 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001816 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001817 }
1818
Andy Wickhambd9a1802023-06-08 16:33:15 -07001819 /** The margin between the edge of all apps and the edge of the first icon. */
Thales Limab433c9c2023-10-30 12:24:05 +00001820 public int getAllAppsIconStartMargin(Context context) {
Andy Wickhambd9a1802023-06-08 16:33:15 -07001821 int allAppsSpacing;
1822 if (isVerticalBarLayout()) {
1823 // On phones, the landscape layout uses a different setup.
1824 allAppsSpacing = workspacePadding.left + workspacePadding.right;
1825 } else {
Thales Limab433c9c2023-10-30 12:24:05 +00001826 allAppsSpacing =
1827 allAppsPadding.left + allAppsPadding.right + allAppsLeftRightMargin * 2;
Andy Wickhambd9a1802023-06-08 16:33:15 -07001828 }
1829
1830 int cellWidth = DeviceProfile.calculateCellWidth(
1831 availableWidthPx - allAppsSpacing,
1832 0 /* borderSpace */,
1833 numShownAllAppsColumns);
fbarone69b6f42023-12-18 13:20:34 -08001834 int iconAlignmentMargin = (cellWidth - getIconVisibleSizePx(allAppsIconSizePx)) / 2;
Thales Limab433c9c2023-10-30 12:24:05 +00001835
1836 return (Utilities.isRtl(context.getResources()) ? allAppsPadding.right
1837 : allAppsPadding.left) + iconAlignmentMargin;
Andy Wickhambd9a1802023-06-08 16:33:15 -07001838 }
1839
fbarone69b6f42023-12-18 13:20:34 -08001840 /**
1841 * TODO(b/235886078): workaround needed because of this bug
1842 * Icons are 10% larger on XML than their visual size, so remove that extra space to get
1843 * some dimensions correct.
1844 *
1845 * When this bug is resolved this method will no longer be needed and we would be able to
1846 * replace all instances where this method is called with iconSizePx.
1847 */
1848 private int getIconVisibleSizePx(int iconSizePx) {
1849 return Math.round(ICON_VISIBLE_AREA_FACTOR * iconSizePx);
1850 }
1851
Thales Lima9938c2f2022-07-25 14:38:16 +01001852 private int getAdditionalQsbSpace() {
1853 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1854 }
1855
1856 /**
1857 * Calculate how much space the hotseat needs to be shown completely
1858 */
1859 private int getHotseatRequiredWidth() {
1860 int additionalQsbSpace = getAdditionalQsbSpace();
1861 return iconSizePx * numShownHotseatIcons
Thales Lima6a590062022-11-22 15:52:49 +00001862 + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1))
Thales Lima9938c2f2022-07-25 14:38:16 +01001863 + additionalQsbSpace;
1864 }
1865
Winsonfadbe8f2016-07-22 16:35:37 -07001866 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001867 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1868 */
1869 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001870 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001871 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1872 } else if (isTaskbarPresent) { // QSB on top
1873 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001874 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001875 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001876 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001877 }
1878
Thales Limab8c05952022-05-23 16:58:38 +01001879 /**
1880 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1881 */
1882 private int getHotseatBarBottomPadding() {
1883 if (isTaskbarPresent) { // QSB on top or inline
1884 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001885 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001886 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001887 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001888 }
1889
1890 /**
Alex Chau51da2192022-05-20 13:32:10 +01001891 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1892 */
1893 public int getTaskbarOffsetY() {
Jon Miranda9c478b62023-03-23 21:38:49 -07001894 int taskbarIconBottomSpace = (taskbarHeight - iconSizePx) / 2;
Alex Chau51da2192022-05-20 13:32:10 +01001895 int launcherIconBottomSpace =
1896 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001897 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001898 }
1899
Uwais Ashrafaa7fa882023-10-10 21:36:06 +00001900 /** Returns the number of pixels required below OverviewActions. */
Alex Chaua2fc7642022-04-21 14:20:23 +01001901 public int getOverviewActionsClaimedSpaceBelow() {
Uwais Ashrafaa7fa882023-10-10 21:36:06 +00001902 return isTaskbarPresent ? mTransientTaskbarClaimedSpace : mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001903 }
1904
1905 /** Gets the space that the overview actions will take, including bottom margin. */
1906 public int getOverviewActionsClaimedSpace() {
Alex Chau4989f4f2023-10-11 14:08:22 +00001907 int overviewActionsSpace = isTablet && Flags.enableGridOnlyOverview()
Pat Manning7b8f7662023-01-18 14:48:30 +00001908 ? 0
1909 : (overviewActionsTopMarginPx + overviewActionsHeight);
1910 return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
Alex Chaua2fc7642022-04-21 14:20:23 +01001911 }
1912
1913 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001914 * Takes the View and return the scales of width and height depending on the DeviceProfile
1915 * specifications
1916 *
1917 * @param itemInfo The tag of the widget view
1918 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1919 * height
1920 */
1921 @NonNull
1922 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1923 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1924 }
1925
1926 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001927 * @return the bounds for which the open folders should be contained within
1928 */
1929 public Rect getAbsoluteOpenFolderBounds() {
1930 if (isVerticalBarLayout()) {
1931 // Folders should only appear right of the drop target bar and left of the hotseat
1932 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1933 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001934 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001935 mInsets.top + availableHeightPx);
1936 } else {
1937 // Folders should only appear below the drop target bar and above the hotseat
Jon Miranda9c478b62023-03-23 21:38:49 -07001938 int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001939 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001940 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001941 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001942 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001943 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001944 }
1945 }
1946
Jon Miranda228877d2021-02-09 11:05:00 -05001947 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1948 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001949 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001950
Jon Miranda228877d2021-02-09 11:05:00 -05001951 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1952 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001953 }
1954
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001955 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001956 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1957 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1958 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001959 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001960 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001961 return isLandscape && transposeLayoutWithOrientation;
1962 }
1963
Sunny Goyal59d086c2018-05-07 17:31:40 -07001964 /**
1965 * Updates orientation information and returns true if it has changed from the previous value.
1966 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001967 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001968 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001969 boolean isSeascape = DisplayController.INSTANCE.get(context)
1970 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001971 if (mIsSeascape != isSeascape) {
1972 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001973 // Hotseat changing sides requires updating workspace left/right paddings
1974 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001975 return true;
1976 }
1977 }
1978 return false;
1979 }
1980
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001981 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001982 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001983 }
1984
Sunny Goyal07b69292018-01-08 14:19:34 -08001985 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001986 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001987 }
1988
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001989 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001990 switch (containerType) {
1991 case CellLayout.WORKSPACE:
1992 return cellHeightPx;
1993 case CellLayout.FOLDER:
1994 return folderCellHeightPx;
1995 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001996 // The hotseat is the only container where the cell height is going to be
1997 // different from the content within that cell.
1998 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001999 default:
2000 // ??
2001 return 0;
2002 }
2003 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07002004
Jon Miranda58561d42021-03-17 10:51:54 -04002005 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07002006 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04002007 }
2008
Alex Chaue818bcb2022-09-02 17:27:11 +01002009 private String dpPointFToString(String name, PointF value) {
2010 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
2011 }
2012
Pat Manning5f74bfd2022-07-20 12:08:54 +01002013 /** Dumps various DeviceProfile variables to the specified writer. */
2014 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04002015 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07002016 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04002017
2018 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04002019 writer.println(prefix + "\tisPhone:" + isPhone);
2020 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
2021 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00002022 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04002023
2024 writer.println(prefix + "\tisLandscape:" + isLandscape);
2025 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07002026 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Winson Chung104a4c82023-11-08 18:56:15 +00002027 writer.println(prefix + "\tisLeftRightSplit:" + isLeftRightSplit);
Jon Miranda58561d42021-03-17 10:51:54 -04002028
2029 writer.println(prefix + pxToDpStr("windowX", windowX));
2030 writer.println(prefix + pxToDpStr("windowY", windowY));
2031 writer.println(prefix + pxToDpStr("widthPx", widthPx));
2032 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002033 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
2034 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01002035 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
2036 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
2037 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
2038 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04002039
2040 writer.println(prefix + "\taspectRatio:" + aspectRatio);
2041
Thales Limac98b7812023-04-14 15:04:23 +01002042 writer.println(prefix + "\tisResponsiveGrid:" + mIsResponsiveGrid);
Thales Lima79456492023-05-23 11:32:22 +01002043 writer.println(prefix + "\tisScalableGrid:" + mIsScalableGrid);
Jon Miranda58561d42021-03-17 10:51:54 -04002044
Thales Lima83bedbf2021-10-05 17:47:39 +01002045 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00002046 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
2047 writer.println(prefix + "\tinv.numSearchContainerColumns: "
2048 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04002049
Alex Chaue818bcb2022-09-02 17:27:11 +01002050 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07002051
Jon Miranda58561d42021-03-17 10:51:54 -04002052 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
2053 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
2054
2055 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
2056 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
2057
Thales Lima83bedbf2021-10-05 17:47:39 +01002058 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
2059 cellLayoutBorderSpacePx.x));
2060 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
2061 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002062 writer.println(
2063 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
2064 writer.println(
2065 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
2066 writer.println(
2067 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01002068 writer.println(
2069 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01002070
Jon Miranda58561d42021-03-17 10:51:54 -04002071 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
2072 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
2073 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
2074
Thales Lima1faa4ed2023-12-01 16:48:19 +00002075 writer.println(prefix + "\tnumFolderRows: " + numFolderRows);
2076 writer.println(prefix + "\tnumFolderColumns: " + numFolderColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04002077 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
2078 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
2079 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
2080 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
2081 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
2082 folderChildDrawablePaddingPx));
Jordan Silva637f4eb2023-06-13 11:21:53 +01002083 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.x",
2084 folderCellLayoutBorderSpacePx.x));
2085 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.y",
2086 folderCellLayoutBorderSpacePx.y));
Thales Limaa08a4432022-08-09 09:55:17 +01002087 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
2088 folderContentPaddingLeftRight));
2089 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03002090 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002091
Alex Chaue0227552022-04-06 19:44:43 +01002092 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01002093 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
2094 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
2095 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
2096 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01002097
2098 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
Alex Chau3d2c0622022-09-01 21:28:14 +01002099 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
2100 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04002101 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
2102 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
2103 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
2104 allAppsIconDrawablePaddingPx));
2105 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00002106 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01002107 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
2108 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07002109 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Thales Limab433c9c2023-10-30 12:24:05 +00002110 writer.println(prefix + pxToDpStr("allAppsPadding.top", allAppsPadding.top));
2111 writer.println(prefix + pxToDpStr("allAppsPadding.left", allAppsPadding.left));
2112 writer.println(prefix + pxToDpStr("allAppsPadding.right", allAppsPadding.right));
Alex Chau27b39b92022-01-14 18:02:18 +00002113 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04002114
2115 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03002116 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04002117 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00002118 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Thales Lima8e11d532023-08-31 13:40:26 +00002119 writer.println(prefix + pxToDpStr("mHotseatBarEdgePaddingPx",
2120 mHotseatBarEdgePaddingPx));
2121 writer.println(prefix + pxToDpStr("mHotseatBarWorkspaceSpacePx",
2122 mHotseatBarWorkspaceSpacePx));
Pat Manning26f70f72022-07-07 13:50:39 +01002123 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01002124 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
2125 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01002126 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
2127 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002128 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
2129 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
2130 hotseatLayoutPadding.top));
2131 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
2132 hotseatLayoutPadding.bottom));
2133 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
2134 hotseatLayoutPadding.left));
2135 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
2136 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07002137 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00002138 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00002139 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01002140 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04002141
2142 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10002143 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda9c478b62023-03-23 21:38:49 -07002144 writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight));
2145 writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight));
2146 writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin));
2147 writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize));
Jon Miranda58561d42021-03-17 10:51:54 -04002148
Thales Lima83bedbf2021-10-05 17:47:39 +01002149 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
2150 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002151 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
2152 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
2153 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00002154 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04002155
Jon Mirandaab3c6812021-06-28 15:42:28 -07002156 writer.println(prefix + pxToDpStr("iconScale", iconScale));
2157 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04002158 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00002159 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04002160
Thales Lima171ee662022-11-22 15:52:49 +00002161 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04002162 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
2163 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00002164
2165 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00002166 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
2167 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
2168 overviewTaskIconDrawableSizePx));
2169 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
2170 overviewTaskIconDrawableSizeGridPx));
2171 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
2172 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01002173 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
2174 overviewActionsTopMarginPx));
2175 writer.println(prefix + pxToDpStr("overviewActionsHeight",
2176 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00002177 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
2178 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00002179 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
2180 overviewActionsButtonSpacing));
2181 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
2182 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
2183 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01002184
Alex Chau62572c02022-07-25 18:36:37 +00002185 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01002186 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00002187 writer.println(
2188 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01002189
Pat Manning5f74bfd2022-07-20 12:08:54 +01002190 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
2191 getCellLayoutSpringLoadShrunkTop()));
2192 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
2193 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01002194 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
2195 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002196 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
2197 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01002198 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
2199 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Thales Lima79456492023-05-23 11:32:22 +01002200 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00002201 writer.println(prefix + "\tmResponsiveWorkspaceHeightSpec:"
2202 + mResponsiveWorkspaceHeightSpec.toString());
2203 writer.println(prefix + "\tmResponsiveWorkspaceWidthSpec:"
2204 + mResponsiveWorkspaceWidthSpec.toString());
2205 writer.println(prefix + "\tmResponsiveAllAppsHeightSpec:"
2206 + mResponsiveAllAppsHeightSpec.toString());
2207 writer.println(prefix + "\tmResponsiveAllAppsWidthSpec:"
2208 + mResponsiveAllAppsWidthSpec.toString());
Jordan Silva637f4eb2023-06-13 11:21:53 +01002209 writer.println(prefix + "\tmResponsiveFolderHeightSpec:" + mResponsiveFolderHeightSpec);
2210 writer.println(prefix + "\tmResponsiveFolderWidthSpec:" + mResponsiveFolderWidthSpec);
Thales Limaf8bfb032023-07-24 15:08:05 +01002211 writer.println(prefix + "\tmResponsiveHotseatSpec:" + mResponsiveHotseatSpec);
Jordan Silva999dd2a2023-11-17 19:31:43 +00002212 writer.println(prefix + "\tmResponsiveWorkspaceCellSpec:"
2213 + mResponsiveWorkspaceCellSpec);
2214 writer.println(prefix + "\tmResponsiveAllAppsCellSpec:" + mResponsiveAllAppsCellSpec);
Thales Lima79456492023-05-23 11:32:22 +01002215 }
Jon Miranda58561d42021-03-17 10:51:54 -04002216 }
2217
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00002218 /** Returns a reduced representation of this DeviceProfile. */
2219 public String toSmallString() {
2220 return "isTablet:" + isTablet + ", "
2221 + "isMultiDisplay:" + isMultiDisplay + ", "
2222 + "widthPx:" + widthPx + ", "
2223 + "heightPx:" + heightPx + ", "
2224 + "insets:" + mInsets + ", "
2225 + "rotationHint:" + rotationHint;
2226 }
2227
Alex Chaua6907dc2022-03-18 15:24:07 +00002228 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07002229 Configuration config = new Configuration(c.getResources().getConfiguration());
2230 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03002231 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00002232 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07002233 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07002234 }
Sunny Goyalfde55052018-02-01 14:46:13 -08002235
2236 /**
2237 * Callback when a component changes the DeviceProfile associated with it, as a result of
2238 * configuration change
2239 */
2240 public interface OnDeviceProfileChangeListener {
2241
2242 /**
2243 * Called when the device profile is reassigned. Note that for layout and measurements, it
2244 * is sufficient to listen for inset changes. Use this callback when you need to perform
2245 * a one time operation.
2246 */
2247 void onDeviceProfileChanged(DeviceProfile dp);
2248 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002249
Sihua Mae04aa202022-07-18 12:43:56 -07002250 /**
2251 * Handler that deals with ItemInfo of the views for the DeviceProfile
2252 */
2253 @FunctionalInterface
2254 public interface ViewScaleProvider {
2255 /**
2256 * Get the scales from the view
2257 *
2258 * @param itemInfo The tag of the widget view
2259 * @return PointF instance containing the scale information, or null if using the default
2260 * app widget scale of this device profile.
2261 */
2262 @NonNull
2263 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
2264 }
2265
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002266 public static class Builder {
2267 private Context mContext;
2268 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07002269 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002270
Sunny Goyal19ff7282021-04-22 10:12:54 -07002271 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00002272 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002273
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002274 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07002275 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00002276 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07002277 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002278
Sunny Goyal65190ae2022-08-02 14:16:26 -07002279 private SparseArray<DotRenderer> mDotRendererCache;
2280
Jon Miranda2b25ded2023-02-02 14:48:45 -08002281 private Consumer<DeviceProfile> mOverrideProvider;
2282
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002283 private boolean mIsTransientTaskbar;
2284
Sunny Goyalfd58da62020-08-11 12:06:49 -07002285 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002286 mContext = context;
2287 mInv = inv;
2288 mInfo = info;
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002289 mIsTransientTaskbar = info.isTransientTaskbar();
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002290 }
2291
2292 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
2293 mIsMultiWindowMode = isMultiWindowMode;
2294 return this;
2295 }
2296
Alex Chauab800f72022-12-13 17:46:06 +00002297 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
2298 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07002299 return this;
2300 }
2301
Sunny Goyal65190ae2022-08-02 14:16:26 -07002302 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
2303 mDotRendererCache = dotRendererCache;
2304 return this;
2305 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07002306
2307 public Builder setWindowBounds(WindowBounds bounds) {
2308 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07002309 return this;
2310 }
2311
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002312 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
2313 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
2314 return this;
2315 }
2316
Alex Chau6ed408f2022-03-04 12:58:05 +00002317 public Builder setGestureMode(boolean isGestureMode) {
2318 mIsGestureMode = isGestureMode;
2319 return this;
2320 }
2321
Jon Miranda2b25ded2023-02-02 14:48:45 -08002322 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
2323 mOverrideProvider = overrideProvider;
2324 return this;
2325 }
2326
Sihua Mae04aa202022-07-18 12:43:56 -07002327 /**
2328 * Set the viewScaleProvider for the builder
2329 *
2330 * @param viewScaleProvider The viewScaleProvider to be set for the
Thales Limae9273ea2023-01-26 12:33:52 +00002331 * DeviceProfile
Sihua Mae04aa202022-07-18 12:43:56 -07002332 * @return This builder
2333 */
2334 @NonNull
2335 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
2336 mViewScaleProvider = viewScaleProvider;
2337 return this;
2338 }
2339
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002340 /**
2341 * Set the isTransientTaskbar for the builder
2342 * @return This Builder
2343 */
2344 public Builder setIsTransientTaskbar(boolean isTransientTaskbar) {
2345 mIsTransientTaskbar = isTransientTaskbar;
2346 return this;
2347 }
2348
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002349 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07002350 if (mWindowBounds == null) {
2351 throw new IllegalArgumentException("Window bounds not set");
2352 }
2353 if (mTransposeLayoutWithOrientation == null) {
2354 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
2355 }
Alex Chau6ed408f2022-03-04 12:58:05 +00002356 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01002357 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00002358 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002359 if (mDotRendererCache == null) {
2360 mDotRendererCache = new SparseArray<>();
2361 }
Sihua Mae04aa202022-07-18 12:43:56 -07002362 if (mViewScaleProvider == null) {
2363 mViewScaleProvider = DEFAULT_PROVIDER;
2364 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08002365 if (mOverrideProvider == null) {
2366 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
2367 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002368 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00002369 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002370 mIsGestureMode, mViewScaleProvider, mOverrideProvider, mIsTransientTaskbar);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002371 }
2372 }
Winson Chungb3800242013-10-24 11:01:54 -07002373}