blob: 4b4bdc2ecf0596ea31d157c28fd8691d6c35119c [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 Dayauon5787a272023-12-14 13:47:17 -08001236 if (FeatureFlags.enableTwolineAllapps()
1237 && (!Flags.enableTwolineToggle() || (Flags.enableTwolineToggle()
1238 && LauncherPrefs.ENABLE_TWOLINE_ALLAPPS_TOGGLE.get(context)))) {
Brandon Dayauon3cdb32c2023-08-22 21:26:37 -07001239 // Add extra textHeight to the existing allAppsCellHeight.
1240 allAppsCellHeightPx += Utilities.calculateTextHeight(allAppsIconTextSizePx);
1241 }
Winson Chungb3800242013-10-24 11:01:54 -07001242
Thales Limab8c05952022-05-23 16:58:38 +01001243 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -07001244
Sunny Goyalbaec6ff2016-09-14 11:26:21 -07001245 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -07001246 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
1247 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Sunny Goyal6c304b12023-04-10 12:03:04 -07001248
1249 // Update widget padding:
1250 float minSpacing = pxFromDp(MIN_WIDGET_PADDING_DP, mMetrics);
1251 if (cellLayoutBorderSpacePx.x < minSpacing
1252 || cellLayoutBorderSpacePx.y < minSpacing) {
1253 widgetPadding.left = widgetPadding.right =
1254 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.x));
1255 widgetPadding.top = widgetPadding.bottom =
1256 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.y));
1257 } else {
1258 widgetPadding.setEmpty();
1259 }
Winson Chung0f785722015-04-08 10:27:49 -07001260 }
1261
Thales Lima425f6822022-05-10 13:44:58 -03001262 /**
Thales Lima6a590062022-11-22 15:52:49 +00001263 * This method calculates the space between the icons to achieve a certain width.
Thales Lima425f6822022-05-10 13:44:58 -03001264 */
Thales Lima6a590062022-11-22 15:52:49 +00001265 private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) {
Jordan Silvad9227182023-08-17 15:53:59 +01001266 int numBorders = (numShownHotseatIcons - 1 + numExtraBorder);
1267 if (numBorders <= 0) return 0;
1268
Thales Lima9938c2f2022-07-25 14:38:16 +01001269 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
Jordan Silvad9227182023-08-17 15:53:59 +01001270 int hotseatBorderSpacePx = (int) (hotseatWidthPx - hotseatIconsTotalPx) / numBorders;
Thales Limaffc68b02023-01-09 16:20:23 +00001271 return Math.min(hotseatBorderSpacePx, mMaxHotseatIconSpacePx);
Thales Lima425f6822022-05-10 13:44:58 -03001272 }
1273
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001274 /**
1275 * Updates the iconSize for allApps* variants.
1276 */
Brian Isganitisa9a78112022-05-23 18:11:47 -07001277 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +01001278 allAppsBorderSpacePx = new Point(
1279 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
1280 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001281 // AllApps cells don't have real space between cells,
1282 // so we add the border space to the cell height
Alex Chaube753132022-12-09 16:46:54 +00001283 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics)
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001284 + allAppsBorderSpacePx.y;
1285 // but width is just the cell,
1286 // the border is added in #updateAllAppsContainerWidth
Thales Lima79456492023-05-23 11:32:22 +01001287 if (mIsScalableGrid) {
Alex Chaube753132022-12-09 16:46:54 +00001288 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1289 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001290 allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding();
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001291 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001292
1293 if (allAppsCellWidthPx < allAppsIconSizePx) {
1294 // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to
1295 // make allAppsCellWidth bigger.
1296 int numBorders = inv.numAllAppsColumns - 1;
1297 int extraWidthRequired =
1298 (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns;
1299 if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) {
1300 allAppsCellWidthPx = allAppsIconSizePx;
1301 allAppsBorderSpacePx.x -= extraWidthRequired / numBorders;
1302 } else {
1303 // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space
1304 // for allAppsCellWidth, and reduce allAppsIconSize.
1305 allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns
1306 + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns;
1307 allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx);
1308 allAppsBorderSpacePx.x = 0;
1309 }
1310 }
1311
1312 int cellContentHeight = allAppsIconSizePx
1313 + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y;
1314 if (allAppsCellHeightPx < cellContentHeight) {
1315 // Increase allAppsCellHeight to fit its content.
1316 allAppsCellHeightPx = cellContentHeight;
1317 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001318 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001319 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
1320 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001321 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1322 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001323 allAppsIconDrawablePaddingPx =
1324 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001325 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001326 }
Thales Limaabfe3642023-05-24 18:08:53 +01001327 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001328
Jordan Silva999dd2a2023-11-17 19:31:43 +00001329 private void updateAllAppsWithResponsiveMeasures() {
1330 allAppsIconSizePx = mResponsiveAllAppsCellSpec.getIconSize();
1331 allAppsIconTextSizePx = mResponsiveAllAppsCellSpec.getIconTextSize();
1332 allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding(allAppsIconSizePx,
1333 mResponsiveAllAppsCellSpec.getIconDrawablePadding());
Thales Limaabfe3642023-05-24 18:08:53 +01001334 allAppsBorderSpacePx = new Point(
Jordan Silva8f7986a2023-11-08 12:11:25 +00001335 mResponsiveAllAppsWidthSpec.getGutterPx(),
1336 mResponsiveAllAppsHeightSpec.getGutterPx()
Thales Limaabfe3642023-05-24 18:08:53 +01001337 );
Jordan Silva999dd2a2023-11-17 19:31:43 +00001338 allAppsCellHeightPx = mResponsiveAllAppsHeightSpec.getCellSizePx();
Jordan Silva8f7986a2023-11-08 12:11:25 +00001339 allAppsCellWidthPx = mResponsiveAllAppsWidthSpec.getCellSizePx();
Thales Limaa25cd902023-11-01 12:00:32 +00001340
1341 // This workaround is needed to align AllApps icons with Workspace icons
1342 // since AllApps doesn't have borders between cells
1343 int halfBorder = allAppsBorderSpacePx.x / 2;
Jordan Silva8f7986a2023-11-08 12:11:25 +00001344 allAppsPadding.left = mResponsiveAllAppsWidthSpec.getStartPaddingPx() - halfBorder;
1345 allAppsPadding.right = mResponsiveAllAppsWidthSpec.getEndPaddingPx() - halfBorder;
Jordan Silva376036a2023-11-08 15:56:40 +00001346
Jordan Silva376036a2023-11-08 15:56:40 +00001347
1348 // Reduce the size of the app icon if it doesn't fit
1349 if (allAppsCellWidthPx < allAppsIconSizePx) {
1350 // get a smaller icon size
1351 allAppsIconSizePx = mIconSizeSteps.getIconSmallerThan(allAppsCellWidthPx);
1352 }
1353
1354 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1355 allAppsIconSizePx, allAppsIconDrawablePaddingPx, (int) allAppsIconTextSizePx);
1356
1357 if (allAppsCellHeightPx < cellContentDimensions.getCellContentHeight()) {
1358 if (isVerticalBarLayout()) {
Jordan Silva2de6a272024-01-04 14:44:20 -03001359 if (allAppsCellHeightPx < allAppsIconSizePx) {
Jordan Silva376036a2023-11-08 15:56:40 +00001360 cellContentDimensions.setIconSizePx(
1361 mIconSizeSteps.getIconSmallerThan(allAppsCellHeightPx));
1362 }
1363 } else {
1364 cellContentDimensions.resizeToFitCellHeight(allAppsCellHeightPx,
1365 mIconSizeSteps);
1366 }
1367 allAppsIconSizePx = cellContentDimensions.getIconSizePx();
1368 allAppsIconDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1369 allAppsIconTextSizePx = cellContentDimensions.getIconTextSizePx();
1370 }
Jordan Silva999dd2a2023-11-17 19:31:43 +00001371
1372 allAppsCellHeightPx += mResponsiveAllAppsHeightSpec.getGutterPx();
Jordan Silvadd612682024-01-08 11:38:13 -03001373
1374 if (isVerticalBarLayout()) {
1375 autoResizeAllAppsCells();
1376 }
Thales Limaabfe3642023-05-24 18:08:53 +01001377 }
1378
1379 /**
1380 * Re-computes the all-apps cell size to be independent of workspace
1381 */
1382 public void autoResizeAllAppsCells() {
1383 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
1384 int topBottomPadding = textHeight;
1385 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
1386 + textHeight + (topBottomPadding * 2);
1387 }
1388
1389 private void updateAllAppsContainerWidth() {
1390 int cellLayoutHorizontalPadding =
1391 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
1392 if (isTablet) {
1393 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
1394 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Thales Limab433c9c2023-10-30 12:24:05 +00001395 + allAppsPadding.left + allAppsPadding.right;
Thales Limaabfe3642023-05-24 18:08:53 +01001396 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
Thales Limaa25cd902023-11-01 12:00:32 +00001397 } else if (!mIsResponsiveGrid) {
Thales Limab433c9c2023-10-30 12:24:05 +00001398 allAppsPadding.left = allAppsPadding.right =
Thales Limaabfe3642023-05-24 18:08:53 +01001399 Math.max(0, desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding
1400 - (allAppsBorderSpacePx.x / 2));
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001401 }
1402 }
1403
Thales Limaabfe3642023-05-24 18:08:53 +01001404 private void setupAllAppsStyle(Context context) {
1405 TypedArray allAppsStyle = context.obtainStyledAttributes(
1406 inv.allAppsStyle != INVALID_RESOURCE_HANDLE ? inv.allAppsStyle
1407 : R.style.AllAppsStyleDefault, R.styleable.AllAppsStyle);
1408
Thales Limab433c9c2023-10-30 12:24:05 +00001409 allAppsPadding.left = allAppsPadding.right = allAppsStyle.getDimensionPixelSize(
Thales Limaabfe3642023-05-24 18:08:53 +01001410 R.styleable.AllAppsStyle_horizontalPadding, 0);
1411 allAppsStyle.recycle();
1412 }
1413
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001414 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001415 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001416
Jordan Silva637f4eb2023-06-13 11:21:53 +01001417 // Responsive grid doesn't need to scale the folder
1418 if (mIsResponsiveGrid) return;
1419
Thales Lima7eee74b2023-03-16 16:00:55 -03001420 // For usability we can't have the folder use the whole width of the screen
Sunny Goyal07b69292018-01-08 14:19:34 -08001421 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -08001422
Thales Lima7eee74b2023-03-16 16:00:55 -03001423 // Check if the folder fit within the available height.
Thales Lima1faa4ed2023-12-01 16:48:19 +00001424 float contentUsedHeight = folderCellHeightPx * numFolderRows
1425 + ((numFolderRows - 1) * folderCellLayoutBorderSpacePx.y)
Thales Lima7eee74b2023-03-16 16:00:55 -03001426 + folderFooterHeightPx
1427 + folderContentPaddingTop;
1428 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001429 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -08001430
Thales Lima7eee74b2023-03-16 16:00:55 -03001431 // Check if the folder fit within the available width.
Thales Lima1faa4ed2023-12-01 16:48:19 +00001432 float contentUsedWidth = folderCellWidthPx * numFolderColumns
1433 + ((numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x)
Thales Lima7eee74b2023-03-16 16:00:55 -03001434 + folderContentPaddingLeftRight * 2;
1435 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001436 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -08001437
1438 float scale = Math.min(scaleX, scaleY);
1439 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001440 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001441 }
1442 }
1443
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001444 private void updateFolderCellSize(float scale, Resources res) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001445 int minLabelTextSize = pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001446 if (mIsResponsiveGrid) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001447 folderChildIconSizePx = mResponsiveWorkspaceCellSpec.getIconSize();
1448 folderChildTextSizePx = mResponsiveWorkspaceCellSpec.getIconTextSize();
1449 folderLabelTextSizePx = Math.max(minLabelTextSize,
1450 (int) (folderChildTextSizePx * folderLabelTextScale));
1451 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
1452
Jordan Silva637f4eb2023-06-13 11:21:53 +01001453 folderCellWidthPx = mResponsiveFolderWidthSpec.getCellSizePx();
Jordan Silva637f4eb2023-06-13 11:21:53 +01001454 folderCellHeightPx = mResponsiveFolderHeightSpec.getCellSizePx();
1455 folderContentPaddingTop = mResponsiveFolderHeightSpec.getStartPaddingPx();
1456 folderFooterHeightPx = mResponsiveFolderHeightSpec.getEndPaddingPx();
1457
1458 folderCellLayoutBorderSpacePx = new Point(mResponsiveFolderWidthSpec.getGutterPx(),
Thales Lima4cfd9502023-07-10 14:01:28 +01001459 mResponsiveFolderHeightSpec.getGutterPx());
Jordan Silva637f4eb2023-06-13 11:21:53 +01001460
1461 folderContentPaddingLeftRight = mResponsiveFolderWidthSpec.getStartPaddingPx();
Jordan Silva12fae112023-06-26 12:51:01 +01001462
1463 // Reduce icon width if it's wider than the expected folder cell width
1464 if (folderCellWidthPx < folderChildIconSizePx) {
1465 folderChildIconSizePx = mIconSizeSteps.getIconSmallerThan(folderCellWidthPx);
1466 }
1467
1468 // Recalculating padding and cell height
Jordan Silva3e5688a2023-12-05 15:12:29 -03001469 folderChildDrawablePaddingPx = mResponsiveWorkspaceCellSpec.getIconDrawablePadding();
Jordan Silva12fae112023-06-26 12:51:01 +01001470
Thales Limae9b5e142023-11-04 17:10:13 +00001471 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1472 folderChildIconSizePx,
1473 folderChildDrawablePaddingPx,
1474 folderChildTextSizePx);
1475 cellContentDimensions.resizeToFitCellHeight(folderCellHeightPx, mIconSizeSteps);
1476 folderChildIconSizePx = cellContentDimensions.getIconSizePx();
1477 folderChildDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1478 folderChildTextSizePx = cellContentDimensions.getIconTextSizePx();
Jordan Silva999dd2a2023-11-17 19:31:43 +00001479 folderLabelTextSizePx = Math.max(minLabelTextSize,
Jordan Silva9a3bd8f2023-11-16 18:33:28 +00001480 (int) (folderChildTextSizePx * folderLabelTextScale));
Jordan Silva999dd2a2023-11-17 19:31:43 +00001481 return;
1482 }
1483
1484 float invIconSizeDp = inv.iconSize[mTypeIndex];
1485 float invIconTextSizeDp = inv.iconTextSize[mTypeIndex];
1486 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1487 folderChildTextSizePx = pxFromSp(invIconTextSizeDp, mMetrics, scale);
1488 folderLabelTextSizePx = Math.max(minLabelTextSize,
1489 (int) (folderChildTextSizePx * folderLabelTextScale));
1490 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
1491
1492 if (mIsScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001493 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
Thales Lima7eee74b2023-03-16 16:00:55 -03001494 folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale);
1495 folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale);
1496 } else {
1497 folderCellWidthPx = roundPxValueFromFloat(folderCellWidthPx * scale);
1498 folderCellHeightPx = roundPxValueFromFloat(folderCellHeightPx * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001499 }
Charlie Anderson7bb10972023-11-22 13:35:30 -08001500 // Recalculating padding and cell height
1501 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
1502
1503 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1504 folderChildIconSizePx,
1505 folderChildDrawablePaddingPx,
1506 folderChildTextSizePx);
1507 cellContentDimensions.resizeToFitCellHeight(folderCellHeightPx, mIconSizeSteps);
1508 folderChildIconSizePx = cellContentDimensions.getIconSizePx();
1509 folderChildDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1510 folderChildTextSizePx = cellContentDimensions.getIconTextSizePx();
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001511
Thales Lima7eee74b2023-03-16 16:00:55 -03001512 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001513 folderCellLayoutBorderSpacePx = new Point(
1514 roundPxValueFromFloat(folderCellLayoutBorderSpacePx.x * scale),
1515 roundPxValueFromFloat(folderCellLayoutBorderSpacePx.y * scale)
1516 );
Thales Lima7eee74b2023-03-16 16:00:55 -03001517 folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001518 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx.x;
Jon Miranda823da222021-03-23 08:08:45 -04001519 } else {
1520 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1521 * scale);
1522 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1523 * scale);
1524
1525 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1526 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Lima7eee74b2023-03-16 16:00:55 -03001527 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001528 folderContentPaddingLeftRight =
1529 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1530 folderFooterHeightPx =
Thales Lima7eee74b2023-03-16 16:00:55 -03001531 roundPxValueFromFloat(
1532 res.getDimensionPixelSize(R.dimen.folder_footer_height_default)
1533 * scale);
1534
Jordan Silva12fae112023-06-26 12:51:01 +01001535 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
Jon Miranda823da222021-03-23 08:08:45 -04001536 }
Jon Mirandabf7d8122016-11-03 15:29:29 -07001537 }
1538
Winson1f064272016-07-18 17:18:02 -07001539 public void updateInsets(Rect insets) {
1540 mInsets.set(insets);
1541 }
1542
Sunny Goyalae6e3182019-04-30 12:04:37 -07001543 /**
1544 * The current device insets. This is generally same as the insets being dispatched to
1545 * {@link Insettable} elements, but can differ if the element is using a different profile.
1546 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001547 public Rect getInsets() {
1548 return mInsets;
1549 }
1550
Sunny Goyal756cd262015-08-20 12:33:21 -07001551 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001552 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001553 }
1554
Sunny Goyal19ff7282021-04-22 10:12:54 -07001555 public Point getCellSize(Point result) {
1556 if (result == null) {
1557 result = new Point();
1558 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001559
Pat Manning25d53342022-05-10 09:58:49 +00001560 int shortcutAndWidgetContainerWidth =
1561 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1562 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1563 inv.numColumns);
1564 int shortcutAndWidgetContainerHeight =
1565 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1566 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1567 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001568 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001569 }
1570
1571 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001572 * Returns the left and right space on the cell, which is the cell width - icon size
1573 */
1574 public int getCellHorizontalSpace() {
1575 return getCellSize().x - iconSizePx;
1576 }
1577
1578 /**
Pat Manning25d53342022-05-10 09:58:49 +00001579 * Gets the number of panels within the workspace.
1580 */
1581 public int getPanelCount() {
1582 return isTwoPanels ? 2 : 1;
1583 }
1584
1585 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001586 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1587 * bottom of the screen.
1588 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001589 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1590 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001591 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001592 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001593 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001594 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001595 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001596 }
1597
1598 /**
1599 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1600 */
Pat Manning25d53342022-05-10 09:58:49 +00001601 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001602 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001603 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001604 }
1605
1606 /**
1607 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1608 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001609 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001610 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001611 return heightPx - (isVerticalBarLayout()
1612 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001613 }
1614
Pat Manningea5c1d22022-04-14 10:58:16 +01001615 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001616 * Gets the scale of the workspace for the spring-loaded edit state.
1617 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001618 public float getWorkspaceSpringLoadScale(Context context) {
1619 float scale =
1620 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1621 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001622 scale = Math.min(scale, 1f);
1623
Pat Manninge63dd252022-08-02 16:15:29 +01001624 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001625 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001626 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001627 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001628 if (scaledWorkspaceWidth > maxAvailableWidth) {
1629 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1630 }
1631 return scale;
1632 }
1633
Pat Manning25d53342022-05-10 09:58:49 +00001634 /**
1635 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1636 *
1637 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1638 * layouts have two Cell Layouts per workspace.
1639 */
1640 public int getCellLayoutWidth() {
1641 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001642 }
1643
Pat Manning25d53342022-05-10 09:58:49 +00001644 /**
1645 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1646 *
1647 * <p>This is the height of a Workspace, less its vertical padding.
1648 */
1649 public int getCellLayoutHeight() {
1650 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001651 }
1652
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001653 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001654 return new Point(workspacePadding.left + workspacePadding.right,
1655 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001656 }
1657
1658 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001659 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1660 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001661 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001662 private void updateWorkspacePadding() {
1663 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001664 if (isVerticalBarLayout()) {
Jordan Silva3646a1b2023-08-02 13:52:52 +01001665 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001666 padding.top = mResponsiveWorkspaceHeightSpec.getStartPaddingPx();
Thales Lima8e11d532023-08-31 13:40:26 +00001667 padding.bottom = Math.max(0,
Jordan Silva8f7986a2023-11-08 12:11:25 +00001668 mResponsiveWorkspaceHeightSpec.getEndPaddingPx() - mInsets.bottom);
Jordan Silva3646a1b2023-08-02 13:52:52 +01001669 if (isSeascape()) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001670 padding.left =
1671 hotseatBarSizePx + mResponsiveWorkspaceWidthSpec.getEndPaddingPx();
1672 padding.right = mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
Jordan Silva3646a1b2023-08-02 13:52:52 +01001673 } else {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001674 padding.left = mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
1675 padding.right =
1676 hotseatBarSizePx + mResponsiveWorkspaceWidthSpec.getEndPaddingPx();
Jordan Silva3646a1b2023-08-02 13:52:52 +01001677 }
Winson1f064272016-07-18 17:18:02 -07001678 } else {
Jordan Silva3646a1b2023-08-02 13:52:52 +01001679 padding.top = 0;
1680 padding.bottom = edgeMarginPx;
1681 if (isSeascape()) {
1682 padding.left = hotseatBarSizePx;
Thales Lima8e11d532023-08-31 13:40:26 +00001683 padding.right = mHotseatBarEdgePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001684 } else {
Thales Lima8e11d532023-08-31 13:40:26 +00001685 padding.left = mHotseatBarEdgePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001686 padding.right = hotseatBarSizePx;
1687 }
Winson1f064272016-07-18 17:18:02 -07001688 }
Winson Chungb3800242013-10-24 11:01:54 -07001689 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001690 // Pad the bottom of the workspace with hotseat bar
1691 // and leave a bit of space in case a widget go all the way down
Thales Lima79456492023-05-23 11:32:22 +01001692 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding - mInsets.bottom;
1693 if (!mIsResponsiveGrid) {
1694 paddingBottom +=
1695 workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace;
1696 }
1697 int paddingTop = workspaceTopPadding + (mIsScalableGrid ? 0 : edgeMarginPx);
Pat Manning08610ca2022-04-05 21:03:16 +01001698 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001699
Pat Manning08610ca2022-04-05 21:03:16 +01001700 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001701 }
Pat Manning08610ca2022-04-05 21:03:16 +01001702 insetPadding(workspacePadding, cellLayoutPaddingPx);
1703 }
1704
1705 private void insetPadding(Rect paddings, Rect insets) {
1706 insets.left = Math.min(insets.left, paddings.left);
1707 paddings.left -= insets.left;
1708
1709 insets.top = Math.min(insets.top, paddings.top);
1710 paddings.top -= insets.top;
1711
1712 insets.right = Math.min(insets.right, paddings.right);
1713 paddings.right -= insets.right;
1714
1715 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1716 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001717 }
1718
Liran Binyamina833af32023-08-02 16:30:27 -04001719
1720 /**
1721 * Returns the new border space that should be used between hotseat icons after adjusting it to
1722 * the bubble bar.
1723 *
1724 * <p>If there's no adjustment needed, this method returns {@code 0}.
1725 */
1726 public float getHotseatAdjustedBorderSpaceForBubbleBar(Context context) {
1727 // only need to adjust when QSB is on top of the hotseat.
1728 if (isQsbInline) {
1729 return 0;
1730 }
1731
1732 // no need to adjust if there's enough space for the bubble bar to the right of the hotseat.
1733 if (getHotseatLayoutPadding(context).right > mBubbleBarSpaceThresholdPx) {
1734 return 0;
1735 }
1736
1737 // The adjustment is shrinking the hotseat's width by 1 icon on either side.
1738 int iconsWidth =
1739 iconSizePx * numShownHotseatIcons + hotseatBorderSpace * (numShownHotseatIcons - 1);
1740 int newWidth = iconsWidth - 2 * iconSizePx;
1741 // Evenly space the icons within the boundaries of the new width.
1742 return (float) (newWidth - iconSizePx * numShownHotseatIcons) / (numShownHotseatIcons - 1);
1743 }
1744
Sunny Goyal57b22792021-05-25 14:35:01 -07001745 /**
1746 * Returns the padding for hotseat view
1747 */
1748 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001749 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001750 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001751 // The hotseat icons will be placed in the middle of the hotseat cells.
1752 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1753 // in vertical bar layout.
fbaronfc6bbcf2024-01-29 10:35:17 -08001754 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top), 0);
1755 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom), 0);
Sihua Ma38bb3b02022-03-21 22:20:14 -07001756
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001757 if (isSeascape()) {
Thales Lima8e11d532023-08-31 13:40:26 +00001758 hotseatBarPadding.set(mInsets.left + mHotseatBarEdgePaddingPx, paddingTop,
1759 mHotseatBarWorkspaceSpacePx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001760 } else {
Thales Lima8e11d532023-08-31 13:40:26 +00001761 hotseatBarPadding.set(mHotseatBarWorkspaceSpacePx, paddingTop,
1762 mInsets.right + mHotseatBarEdgePaddingPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001763 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001764 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001765 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001766 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1767 int hotseatBarTopPadding =
1768 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001769
Thales Lima6a590062022-11-22 15:52:49 +00001770 int hotseatWidth = getHotseatRequiredWidth();
Helen Cheuke76291f2023-02-14 17:11:05 +00001771 int startSpacing;
1772 int endSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001773 // Hotseat aligns to the left with nav buttons
1774 if (hotseatBarEndOffset > 0) {
Jon Mirandae17a9492023-03-08 16:42:20 -08001775 startSpacing = inlineNavButtonsEndSpacingPx;
Helen Cheuke76291f2023-02-14 17:11:05 +00001776 endSpacing = availableWidthPx - hotseatWidth - startSpacing + hotseatBorderSpace;
1777 } else {
1778 startSpacing = (availableWidthPx - hotseatWidth) / 2;
1779 endSpacing = startSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001780 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001781 startSpacing += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001782
Helen Cheuke76291f2023-02-14 17:11:05 +00001783 hotseatBarPadding.top = hotseatBarTopPadding;
1784 hotseatBarPadding.bottom = hotseatBarBottomPadding;
Alex Chau51da2192022-05-20 13:32:10 +01001785 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001786 if (isRtl) {
Helen Cheuke76291f2023-02-14 17:11:05 +00001787 hotseatBarPadding.left = endSpacing;
1788 hotseatBarPadding.right = startSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001789 } else {
Helen Cheuke76291f2023-02-14 17:11:05 +00001790 hotseatBarPadding.left = startSpacing;
1791 hotseatBarPadding.right = endSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001792 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001793
Thales Lima79456492023-05-23 11:32:22 +01001794 } else if (mIsScalableGrid) {
fbarone69b6f42023-12-18 13:20:34 -08001795 int iconExtraSpacePx = iconSizePx - getIconVisibleSizePx(iconSizePx);
1796 int sideSpacing = (availableWidthPx - (hotseatQsbWidth + iconExtraSpacePx)) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001797 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001798 0,
Thales Lima425f6822022-05-10 13:44:58 -03001799 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001800 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001801 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001802 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1803 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1804 // for this, we pad the left and right of the hotseat with half of the difference of a
1805 // workspace cell vs a hotseat cell.
1806 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001807 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001808 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001809 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001810 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1811 + mInsets.left,
1812 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001813 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001814 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001815 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001816 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001817 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001818 }
1819
Andy Wickhambd9a1802023-06-08 16:33:15 -07001820 /** The margin between the edge of all apps and the edge of the first icon. */
Thales Limab433c9c2023-10-30 12:24:05 +00001821 public int getAllAppsIconStartMargin(Context context) {
Andy Wickhambd9a1802023-06-08 16:33:15 -07001822 int allAppsSpacing;
1823 if (isVerticalBarLayout()) {
1824 // On phones, the landscape layout uses a different setup.
1825 allAppsSpacing = workspacePadding.left + workspacePadding.right;
1826 } else {
Thales Limab433c9c2023-10-30 12:24:05 +00001827 allAppsSpacing =
1828 allAppsPadding.left + allAppsPadding.right + allAppsLeftRightMargin * 2;
Andy Wickhambd9a1802023-06-08 16:33:15 -07001829 }
1830
1831 int cellWidth = DeviceProfile.calculateCellWidth(
1832 availableWidthPx - allAppsSpacing,
1833 0 /* borderSpace */,
1834 numShownAllAppsColumns);
fbarone69b6f42023-12-18 13:20:34 -08001835 int iconAlignmentMargin = (cellWidth - getIconVisibleSizePx(allAppsIconSizePx)) / 2;
Thales Limab433c9c2023-10-30 12:24:05 +00001836
1837 return (Utilities.isRtl(context.getResources()) ? allAppsPadding.right
1838 : allAppsPadding.left) + iconAlignmentMargin;
Andy Wickhambd9a1802023-06-08 16:33:15 -07001839 }
1840
fbarone69b6f42023-12-18 13:20:34 -08001841 /**
1842 * TODO(b/235886078): workaround needed because of this bug
1843 * Icons are 10% larger on XML than their visual size, so remove that extra space to get
1844 * some dimensions correct.
1845 *
1846 * When this bug is resolved this method will no longer be needed and we would be able to
1847 * replace all instances where this method is called with iconSizePx.
1848 */
1849 private int getIconVisibleSizePx(int iconSizePx) {
1850 return Math.round(ICON_VISIBLE_AREA_FACTOR * iconSizePx);
1851 }
1852
Thales Lima9938c2f2022-07-25 14:38:16 +01001853 private int getAdditionalQsbSpace() {
1854 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1855 }
1856
1857 /**
1858 * Calculate how much space the hotseat needs to be shown completely
1859 */
1860 private int getHotseatRequiredWidth() {
1861 int additionalQsbSpace = getAdditionalQsbSpace();
1862 return iconSizePx * numShownHotseatIcons
Thales Lima6a590062022-11-22 15:52:49 +00001863 + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1))
Thales Lima9938c2f2022-07-25 14:38:16 +01001864 + additionalQsbSpace;
1865 }
1866
Winsonfadbe8f2016-07-22 16:35:37 -07001867 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001868 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1869 */
1870 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001871 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001872 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1873 } else if (isTaskbarPresent) { // QSB on top
1874 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001875 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001876 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001877 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001878 }
1879
Thales Limab8c05952022-05-23 16:58:38 +01001880 /**
1881 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1882 */
1883 private int getHotseatBarBottomPadding() {
1884 if (isTaskbarPresent) { // QSB on top or inline
1885 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001886 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001887 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001888 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001889 }
1890
1891 /**
Alex Chau51da2192022-05-20 13:32:10 +01001892 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1893 */
1894 public int getTaskbarOffsetY() {
Jon Miranda9c478b62023-03-23 21:38:49 -07001895 int taskbarIconBottomSpace = (taskbarHeight - iconSizePx) / 2;
Alex Chau51da2192022-05-20 13:32:10 +01001896 int launcherIconBottomSpace =
1897 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001898 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001899 }
1900
Uwais Ashrafaa7fa882023-10-10 21:36:06 +00001901 /** Returns the number of pixels required below OverviewActions. */
Alex Chaua2fc7642022-04-21 14:20:23 +01001902 public int getOverviewActionsClaimedSpaceBelow() {
Uwais Ashrafaa7fa882023-10-10 21:36:06 +00001903 return isTaskbarPresent ? mTransientTaskbarClaimedSpace : mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001904 }
1905
1906 /** Gets the space that the overview actions will take, including bottom margin. */
1907 public int getOverviewActionsClaimedSpace() {
Alex Chau4989f4f2023-10-11 14:08:22 +00001908 int overviewActionsSpace = isTablet && Flags.enableGridOnlyOverview()
Pat Manning7b8f7662023-01-18 14:48:30 +00001909 ? 0
1910 : (overviewActionsTopMarginPx + overviewActionsHeight);
1911 return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
Alex Chaua2fc7642022-04-21 14:20:23 +01001912 }
1913
1914 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001915 * Takes the View and return the scales of width and height depending on the DeviceProfile
1916 * specifications
1917 *
1918 * @param itemInfo The tag of the widget view
1919 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1920 * height
1921 */
1922 @NonNull
1923 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1924 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1925 }
1926
1927 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001928 * @return the bounds for which the open folders should be contained within
1929 */
1930 public Rect getAbsoluteOpenFolderBounds() {
1931 if (isVerticalBarLayout()) {
1932 // Folders should only appear right of the drop target bar and left of the hotseat
1933 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1934 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001935 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001936 mInsets.top + availableHeightPx);
1937 } else {
1938 // Folders should only appear below the drop target bar and above the hotseat
Jon Miranda9c478b62023-03-23 21:38:49 -07001939 int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001940 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001941 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001942 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001943 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001944 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001945 }
1946 }
1947
Jon Miranda228877d2021-02-09 11:05:00 -05001948 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1949 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001950 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001951
Jon Miranda228877d2021-02-09 11:05:00 -05001952 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1953 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001954 }
1955
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001956 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001957 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1958 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1959 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001960 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001961 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001962 return isLandscape && transposeLayoutWithOrientation;
1963 }
1964
Sunny Goyal59d086c2018-05-07 17:31:40 -07001965 /**
1966 * Updates orientation information and returns true if it has changed from the previous value.
1967 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001968 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001969 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001970 boolean isSeascape = DisplayController.INSTANCE.get(context)
1971 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001972 if (mIsSeascape != isSeascape) {
1973 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001974 // Hotseat changing sides requires updating workspace left/right paddings
1975 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001976 return true;
1977 }
1978 }
1979 return false;
1980 }
1981
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001982 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001983 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001984 }
1985
Sunny Goyal07b69292018-01-08 14:19:34 -08001986 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001987 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001988 }
1989
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001990 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001991 switch (containerType) {
1992 case CellLayout.WORKSPACE:
1993 return cellHeightPx;
1994 case CellLayout.FOLDER:
1995 return folderCellHeightPx;
1996 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001997 // The hotseat is the only container where the cell height is going to be
1998 // different from the content within that cell.
1999 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08002000 default:
2001 // ??
2002 return 0;
2003 }
2004 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07002005
Jon Miranda58561d42021-03-17 10:51:54 -04002006 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07002007 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04002008 }
2009
Alex Chaue818bcb2022-09-02 17:27:11 +01002010 private String dpPointFToString(String name, PointF value) {
2011 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
2012 }
2013
Pat Manning5f74bfd2022-07-20 12:08:54 +01002014 /** Dumps various DeviceProfile variables to the specified writer. */
2015 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04002016 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07002017 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04002018
2019 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04002020 writer.println(prefix + "\tisPhone:" + isPhone);
2021 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
2022 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00002023 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04002024
2025 writer.println(prefix + "\tisLandscape:" + isLandscape);
2026 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07002027 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Winson Chung104a4c82023-11-08 18:56:15 +00002028 writer.println(prefix + "\tisLeftRightSplit:" + isLeftRightSplit);
Jon Miranda58561d42021-03-17 10:51:54 -04002029
2030 writer.println(prefix + pxToDpStr("windowX", windowX));
2031 writer.println(prefix + pxToDpStr("windowY", windowY));
2032 writer.println(prefix + pxToDpStr("widthPx", widthPx));
2033 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002034 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
2035 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01002036 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
2037 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
2038 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
2039 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04002040
2041 writer.println(prefix + "\taspectRatio:" + aspectRatio);
2042
Thales Limac98b7812023-04-14 15:04:23 +01002043 writer.println(prefix + "\tisResponsiveGrid:" + mIsResponsiveGrid);
Thales Lima79456492023-05-23 11:32:22 +01002044 writer.println(prefix + "\tisScalableGrid:" + mIsScalableGrid);
Jon Miranda58561d42021-03-17 10:51:54 -04002045
Thales Lima83bedbf2021-10-05 17:47:39 +01002046 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00002047 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
2048 writer.println(prefix + "\tinv.numSearchContainerColumns: "
2049 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04002050
Alex Chaue818bcb2022-09-02 17:27:11 +01002051 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07002052
Jon Miranda58561d42021-03-17 10:51:54 -04002053 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
2054 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
2055
2056 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
2057 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
2058
Thales Lima83bedbf2021-10-05 17:47:39 +01002059 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
2060 cellLayoutBorderSpacePx.x));
2061 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
2062 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002063 writer.println(
2064 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
2065 writer.println(
2066 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
2067 writer.println(
2068 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01002069 writer.println(
2070 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01002071
Jon Miranda58561d42021-03-17 10:51:54 -04002072 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
2073 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
2074 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
2075
Thales Lima1faa4ed2023-12-01 16:48:19 +00002076 writer.println(prefix + "\tnumFolderRows: " + numFolderRows);
2077 writer.println(prefix + "\tnumFolderColumns: " + numFolderColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04002078 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
2079 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
2080 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
2081 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
2082 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
2083 folderChildDrawablePaddingPx));
Jordan Silva637f4eb2023-06-13 11:21:53 +01002084 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.x",
2085 folderCellLayoutBorderSpacePx.x));
2086 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.y",
2087 folderCellLayoutBorderSpacePx.y));
Thales Limaa08a4432022-08-09 09:55:17 +01002088 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
2089 folderContentPaddingLeftRight));
2090 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03002091 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002092
Alex Chaue0227552022-04-06 19:44:43 +01002093 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01002094 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
2095 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
2096 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
2097 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01002098
2099 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
Alex Chau3d2c0622022-09-01 21:28:14 +01002100 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
2101 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04002102 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
2103 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
2104 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
2105 allAppsIconDrawablePaddingPx));
2106 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00002107 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01002108 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
2109 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07002110 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Thales Limab433c9c2023-10-30 12:24:05 +00002111 writer.println(prefix + pxToDpStr("allAppsPadding.top", allAppsPadding.top));
2112 writer.println(prefix + pxToDpStr("allAppsPadding.left", allAppsPadding.left));
2113 writer.println(prefix + pxToDpStr("allAppsPadding.right", allAppsPadding.right));
Alex Chau27b39b92022-01-14 18:02:18 +00002114 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04002115
2116 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03002117 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04002118 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00002119 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Thales Lima8e11d532023-08-31 13:40:26 +00002120 writer.println(prefix + pxToDpStr("mHotseatBarEdgePaddingPx",
2121 mHotseatBarEdgePaddingPx));
2122 writer.println(prefix + pxToDpStr("mHotseatBarWorkspaceSpacePx",
2123 mHotseatBarWorkspaceSpacePx));
Pat Manning26f70f72022-07-07 13:50:39 +01002124 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01002125 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
2126 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01002127 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
2128 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002129 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
2130 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
2131 hotseatLayoutPadding.top));
2132 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
2133 hotseatLayoutPadding.bottom));
2134 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
2135 hotseatLayoutPadding.left));
2136 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
2137 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07002138 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00002139 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00002140 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01002141 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04002142
2143 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10002144 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda9c478b62023-03-23 21:38:49 -07002145 writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight));
2146 writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight));
2147 writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin));
2148 writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize));
Jon Miranda58561d42021-03-17 10:51:54 -04002149
Thales Lima83bedbf2021-10-05 17:47:39 +01002150 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
2151 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002152 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
2153 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
2154 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00002155 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04002156
Jon Mirandaab3c6812021-06-28 15:42:28 -07002157 writer.println(prefix + pxToDpStr("iconScale", iconScale));
2158 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04002159 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00002160 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04002161
Thales Lima171ee662022-11-22 15:52:49 +00002162 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04002163 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
2164 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00002165
2166 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00002167 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
2168 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
2169 overviewTaskIconDrawableSizePx));
2170 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
2171 overviewTaskIconDrawableSizeGridPx));
2172 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
2173 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01002174 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
2175 overviewActionsTopMarginPx));
2176 writer.println(prefix + pxToDpStr("overviewActionsHeight",
2177 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00002178 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
2179 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00002180 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
2181 overviewActionsButtonSpacing));
2182 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
2183 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
2184 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01002185
Alex Chau62572c02022-07-25 18:36:37 +00002186 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01002187 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00002188 writer.println(
2189 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01002190
Pat Manning5f74bfd2022-07-20 12:08:54 +01002191 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
2192 getCellLayoutSpringLoadShrunkTop()));
2193 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
2194 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01002195 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
2196 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002197 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
2198 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01002199 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
2200 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Thales Lima79456492023-05-23 11:32:22 +01002201 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00002202 writer.println(prefix + "\tmResponsiveWorkspaceHeightSpec:"
2203 + mResponsiveWorkspaceHeightSpec.toString());
2204 writer.println(prefix + "\tmResponsiveWorkspaceWidthSpec:"
2205 + mResponsiveWorkspaceWidthSpec.toString());
2206 writer.println(prefix + "\tmResponsiveAllAppsHeightSpec:"
2207 + mResponsiveAllAppsHeightSpec.toString());
2208 writer.println(prefix + "\tmResponsiveAllAppsWidthSpec:"
2209 + mResponsiveAllAppsWidthSpec.toString());
Jordan Silva637f4eb2023-06-13 11:21:53 +01002210 writer.println(prefix + "\tmResponsiveFolderHeightSpec:" + mResponsiveFolderHeightSpec);
2211 writer.println(prefix + "\tmResponsiveFolderWidthSpec:" + mResponsiveFolderWidthSpec);
Thales Limaf8bfb032023-07-24 15:08:05 +01002212 writer.println(prefix + "\tmResponsiveHotseatSpec:" + mResponsiveHotseatSpec);
Jordan Silva999dd2a2023-11-17 19:31:43 +00002213 writer.println(prefix + "\tmResponsiveWorkspaceCellSpec:"
2214 + mResponsiveWorkspaceCellSpec);
2215 writer.println(prefix + "\tmResponsiveAllAppsCellSpec:" + mResponsiveAllAppsCellSpec);
Thales Lima79456492023-05-23 11:32:22 +01002216 }
Jon Miranda58561d42021-03-17 10:51:54 -04002217 }
2218
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00002219 /** Returns a reduced representation of this DeviceProfile. */
2220 public String toSmallString() {
2221 return "isTablet:" + isTablet + ", "
2222 + "isMultiDisplay:" + isMultiDisplay + ", "
2223 + "widthPx:" + widthPx + ", "
2224 + "heightPx:" + heightPx + ", "
2225 + "insets:" + mInsets + ", "
2226 + "rotationHint:" + rotationHint;
2227 }
2228
Alex Chaua6907dc2022-03-18 15:24:07 +00002229 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07002230 Configuration config = new Configuration(c.getResources().getConfiguration());
2231 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03002232 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00002233 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07002234 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07002235 }
Sunny Goyalfde55052018-02-01 14:46:13 -08002236
2237 /**
2238 * Callback when a component changes the DeviceProfile associated with it, as a result of
2239 * configuration change
2240 */
2241 public interface OnDeviceProfileChangeListener {
2242
2243 /**
2244 * Called when the device profile is reassigned. Note that for layout and measurements, it
2245 * is sufficient to listen for inset changes. Use this callback when you need to perform
2246 * a one time operation.
2247 */
2248 void onDeviceProfileChanged(DeviceProfile dp);
2249 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002250
Sihua Mae04aa202022-07-18 12:43:56 -07002251 /**
2252 * Handler that deals with ItemInfo of the views for the DeviceProfile
2253 */
2254 @FunctionalInterface
2255 public interface ViewScaleProvider {
2256 /**
2257 * Get the scales from the view
2258 *
2259 * @param itemInfo The tag of the widget view
2260 * @return PointF instance containing the scale information, or null if using the default
2261 * app widget scale of this device profile.
2262 */
2263 @NonNull
2264 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
2265 }
2266
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002267 public static class Builder {
2268 private Context mContext;
2269 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07002270 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002271
Sunny Goyal19ff7282021-04-22 10:12:54 -07002272 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00002273 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002274
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002275 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07002276 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00002277 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07002278 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002279
Sunny Goyal65190ae2022-08-02 14:16:26 -07002280 private SparseArray<DotRenderer> mDotRendererCache;
2281
Jon Miranda2b25ded2023-02-02 14:48:45 -08002282 private Consumer<DeviceProfile> mOverrideProvider;
2283
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002284 private boolean mIsTransientTaskbar;
2285
Sunny Goyalfd58da62020-08-11 12:06:49 -07002286 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002287 mContext = context;
2288 mInv = inv;
2289 mInfo = info;
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002290 mIsTransientTaskbar = info.isTransientTaskbar();
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002291 }
2292
2293 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
2294 mIsMultiWindowMode = isMultiWindowMode;
2295 return this;
2296 }
2297
Alex Chauab800f72022-12-13 17:46:06 +00002298 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
2299 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07002300 return this;
2301 }
2302
Sunny Goyal65190ae2022-08-02 14:16:26 -07002303 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
2304 mDotRendererCache = dotRendererCache;
2305 return this;
2306 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07002307
2308 public Builder setWindowBounds(WindowBounds bounds) {
2309 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07002310 return this;
2311 }
2312
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002313 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
2314 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
2315 return this;
2316 }
2317
Alex Chau6ed408f2022-03-04 12:58:05 +00002318 public Builder setGestureMode(boolean isGestureMode) {
2319 mIsGestureMode = isGestureMode;
2320 return this;
2321 }
2322
Jon Miranda2b25ded2023-02-02 14:48:45 -08002323 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
2324 mOverrideProvider = overrideProvider;
2325 return this;
2326 }
2327
Sihua Mae04aa202022-07-18 12:43:56 -07002328 /**
2329 * Set the viewScaleProvider for the builder
2330 *
2331 * @param viewScaleProvider The viewScaleProvider to be set for the
Thales Limae9273ea2023-01-26 12:33:52 +00002332 * DeviceProfile
Sihua Mae04aa202022-07-18 12:43:56 -07002333 * @return This builder
2334 */
2335 @NonNull
2336 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
2337 mViewScaleProvider = viewScaleProvider;
2338 return this;
2339 }
2340
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002341 /**
2342 * Set the isTransientTaskbar for the builder
2343 * @return This Builder
2344 */
2345 public Builder setIsTransientTaskbar(boolean isTransientTaskbar) {
2346 mIsTransientTaskbar = isTransientTaskbar;
2347 return this;
2348 }
2349
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002350 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07002351 if (mWindowBounds == null) {
2352 throw new IllegalArgumentException("Window bounds not set");
2353 }
2354 if (mTransposeLayoutWithOrientation == null) {
2355 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
2356 }
Alex Chau6ed408f2022-03-04 12:58:05 +00002357 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01002358 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00002359 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002360 if (mDotRendererCache == null) {
2361 mDotRendererCache = new SparseArray<>();
2362 }
Sihua Mae04aa202022-07-18 12:43:56 -07002363 if (mViewScaleProvider == null) {
2364 mViewScaleProvider = DEFAULT_PROVIDER;
2365 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08002366 if (mOverrideProvider == null) {
2367 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
2368 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002369 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00002370 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002371 mIsGestureMode, mViewScaleProvider, mOverrideProvider, mIsTransientTaskbar);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002372 }
2373 }
Winson Chungb3800242013-10-24 11:01:54 -07002374}