blob: a6ff6c1a898d57857aaaad9eabc461146b325980 [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 Pbe55f822024-01-16 15:07:19 +0000420 // Tablet portrait mode uses a single pane widget picker and extra padding may be applied on
421 // top to avoid making it look too elongated.
422 final boolean applyExtraTopPadding = isTablet
423 && !isLandscape
424 && (aspectRatio > MIN_ASPECT_RATIO_FOR_EXTRA_TOP_PADDING);
Alex Chaue0227552022-04-06 19:44:43 +0100425 bottomSheetTopPadding = mInsets.top // statusbar height
Shamali Pbe55f822024-01-16 15:07:19 +0000426 + (applyExtraTopPadding ? res.getDimensionPixelSize(
427 R.dimen.bottom_sheet_extra_top_padding) : 0)
Andras Kloczl142b0542022-03-09 21:26:02 +0000428 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
Alex Chau3d2c0622022-09-01 21:28:14 +0100429 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
430 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
431 if (isTablet) {
432 bottomSheetWorkspaceScale = workspaceContentScale;
Alex Chauab800f72022-12-13 17:46:06 +0000433 if (isMultiDisplay && !ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH.get()) {
434 // TODO(b/259893832): Revert to use maxWallpaperScale to calculate bottomSheetDepth
435 // when screen recorder bug is fixed.
436 bottomSheetDepth = 1f;
437 } else {
438 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
439 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
440 // When depth is 1, wallpaper zoom is set to 1.
441 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
442 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
443 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
444 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
445 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100446 } else {
447 bottomSheetWorkspaceScale = 1f;
448 bottomSheetDepth = 0f;
449 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000450
Jon Mirandae126d722021-02-25 10:45:20 -0500451 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
Thales Lima1faa4ed2023-12-01 16:48:19 +0000452 numFolderRows = inv.numFolderRows[mTypeIndex];
453 numFolderColumns = inv.numFolderColumns[mTypeIndex];
Thales Limab35faed2022-09-05 16:30:01 -0300454
Thales Lima79456492023-05-23 11:32:22 +0100455 if (mIsScalableGrid && inv.folderStyle != INVALID_RESOURCE_HANDLE) {
Thales Limab35faed2022-09-05 16:30:01 -0300456 TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
Thales Limad852d652023-01-17 14:01:13 +0000457 R.styleable.FolderStyle);
Thales Limab35faed2022-09-05 16:30:01 -0300458 // These are re-set in #updateFolderCellSize if the grid is not scalable
459 folderCellHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000460 R.styleable.FolderStyle_folderCellHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300461 folderCellWidthPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000462 R.styleable.FolderStyle_folderCellWidth, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300463
464 folderContentPaddingTop = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000465 R.styleable.FolderStyle_folderTopPadding, 0);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100466
467 int gutter = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000468 R.styleable.FolderStyle_folderBorderSpace, 0);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100469 folderCellLayoutBorderSpacePx = new Point(gutter, gutter);
Thales Limab35faed2022-09-05 16:30:01 -0300470 folderFooterHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000471 R.styleable.FolderStyle_folderFooterHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300472 folderStyle.recycle();
Jordan Silva637f4eb2023-06-13 11:21:53 +0100473 } else if (!mIsResponsiveGrid) {
474 folderCellLayoutBorderSpacePx = new Point(0, 0);
Thales Lima7eee74b2023-03-16 16:00:55 -0300475 folderFooterHeightPx = res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Thales Limab35faed2022-09-05 16:30:01 -0300476 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
477 }
Jon Mirandae126d722021-02-25 10:45:20 -0500478
Thales Lima85c942f2021-12-31 13:04:20 +0000479 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000480 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
481 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Thales Limae9273ea2023-01-26 12:33:52 +0000482 setupAllAppsStyle(context);
Jon Mirandae126d722021-02-25 10:45:20 -0500483
Tony Wickham5edf9e22020-03-27 20:06:52 -0700484 workspacePageIndicatorHeight = res.getDimensionPixelSize(
485 R.dimen.workspace_page_indicator_height);
486 mWorkspacePageIndicatorOverlapWorkspace =
487 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700488
Jordan Silva999dd2a2023-11-17 19:31:43 +0000489 if (!mIsResponsiveGrid) {
490 TypedArray cellStyle;
491 if (inv.cellStyle != INVALID_RESOURCE_HANDLE) {
492 cellStyle = context.obtainStyledAttributes(inv.cellStyle,
493 R.styleable.CellStyle);
494 } else {
495 cellStyle = context.obtainStyledAttributes(R.style.CellStyleDefault,
496 R.styleable.CellStyle);
497 }
498 mIconDrawablePaddingOriginalPx = cellStyle.getDimensionPixelSize(
499 R.styleable.CellStyle_iconDrawablePadding, 0);
500 cellStyle.recycle();
Thales Limad852d652023-01-17 14:01:13 +0000501 }
Alex Chaua02eddc2021-04-29 00:36:06 +0100502
Sunny Goyal47328fd2016-05-25 18:56:41 -0700503 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
fbaron3bb6d4b2024-02-23 10:54:13 -0800504 // Some foldable portrait modes are too wide in terms of aspect ratio so we need to tweak
505 // the dimensions for edit state.
506 final boolean shouldApplyWidePortraitDimens = isTablet
507 && !isLandscape
508 && aspectRatio < MAX_ASPECT_RATIO_FOR_ALTERNATE_EDIT_STATE;
509 dropTargetBarTopMarginPx = shouldApplyWidePortraitDimens
510 ? 0
511 : res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
512 dropTargetBarBottomMarginPx = shouldApplyWidePortraitDimens
513 ? res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin_wide_portrait)
514 : res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100515 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
516 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100517 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
518 R.dimen.drop_target_button_drawable_horizontal_padding);
519 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
520 R.dimen.drop_target_button_drawable_vertical_padding);
521 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100522 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
523 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100524
Alex Chau906d8822022-05-23 10:42:25 +0100525 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
526 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700527
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700528 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700529
Thales Limaa1012902022-01-13 17:58:42 +0000530 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100531 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
532 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
533
Thales Lima12d0eff2022-03-25 17:06:11 +0000534 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
535 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
536 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
537 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
538 && hotseatQsbHeight > 0;
Thales Lima79456492023-05-23 11:32:22 +0100539 isQsbInline = mIsScalableGrid && inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000540
Thales Lima425f6822022-05-10 13:44:58 -0300541 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100542 numShownHotseatIcons =
543 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000544
Sunny Goyal19ff7282021-04-22 10:12:54 -0700545 numShownAllAppsColumns =
546 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100547
Thales Lima8e11d532023-08-31 13:40:26 +0000548 int hotseatBarBottomSpace;
Thales Limab8c05952022-05-23 16:58:38 +0100549 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
Thales Limaf8bfb032023-07-24 15:08:05 +0100550
551 if (mIsResponsiveGrid) {
Jordan Silvaf2402e22023-10-26 19:53:16 +0100552 float responsiveAspectRatio = (float) widthPx / heightPx;
553 HotseatSpecsProvider hotseatSpecsProvider =
554 HotseatSpecsProvider.create(new ResourceHelper(context,
Thales Limaf8bfb032023-07-24 15:08:05 +0100555 isTwoPanels ? inv.hotseatSpecsTwoPanelId : inv.hotseatSpecsId));
Thales Lima8e11d532023-08-31 13:40:26 +0000556 mResponsiveHotseatSpec =
Jordan Silvaf2402e22023-10-26 19:53:16 +0100557 isVerticalBarLayout() ? hotseatSpecsProvider.getCalculatedSpec(
558 responsiveAspectRatio, DimensionType.WIDTH, widthPx)
559 : hotseatSpecsProvider.getCalculatedSpec(responsiveAspectRatio,
560 DimensionType.HEIGHT, heightPx);
Thales Limaf8bfb032023-07-24 15:08:05 +0100561 hotseatQsbSpace = mResponsiveHotseatSpec.getHotseatQsbSpace();
Thales Lima8e11d532023-08-31 13:40:26 +0000562 hotseatBarBottomSpace =
563 isVerticalBarLayout() ? 0 : mResponsiveHotseatSpec.getEdgePadding();
564 mHotseatBarEdgePaddingPx =
565 isVerticalBarLayout() ? mResponsiveHotseatSpec.getEdgePadding() : 0;
566 mHotseatBarWorkspaceSpacePx = 0;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000567
568 ResponsiveCellSpecsProvider workspaceCellSpecs = ResponsiveCellSpecsProvider.create(
569 new ResourceHelper(context,
570 isTwoPanels ? inv.workspaceCellSpecsTwoPanelId
571 : inv.workspaceCellSpecsId));
572 mResponsiveWorkspaceCellSpec = workspaceCellSpecs.getCalculatedSpec(
573 responsiveAspectRatio, heightPx);
Thales Limaf8bfb032023-07-24 15:08:05 +0100574 } else {
575 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
Thales Lima8e11d532023-08-31 13:40:26 +0000576 hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
577 mHotseatBarEdgePaddingPx =
578 isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
579 mHotseatBarWorkspaceSpacePx =
580 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Thales Limaf8bfb032023-07-24 15:08:05 +0100581 }
582
Thales Lima8e11d532023-08-31 13:40:26 +0000583 if (!isVerticalBarLayout()) {
584 // Have a little space between the inset and the QSB
585 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
586 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
Thales Limab8c05952022-05-23 16:58:38 +0100587
Thales Lima8e11d532023-08-31 13:40:26 +0000588 // Only change the spaces if there is space
589 if (availableSpace > 0) {
590 // Make sure there is enough space between hotseat/QSB and QSB/navBar
591 if (availableSpace < minQsbMargin * 2) {
592 minQsbMargin = availableSpace / 2;
593 hotseatQsbSpace = minQsbMargin;
594 } else {
595 hotseatQsbSpace -= minQsbMargin;
596 }
Thales Limab8c05952022-05-23 16:58:38 +0100597 }
Thales Lima8e11d532023-08-31 13:40:26 +0000598 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
Thales Limab8c05952022-05-23 16:58:38 +0100599
Thales Lima8e11d532023-08-31 13:40:26 +0000600 } else {
601 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
602 }
Thales Limaa1012902022-01-13 17:58:42 +0000603 }
Thales Lima425f6822022-05-10 13:44:58 -0300604
fbaron3bb6d4b2024-02-23 10:54:13 -0800605 springLoadedHotseatBarTopMarginPx = shouldApplyWidePortraitDimens
606 ? res.getDimensionPixelSize(R.dimen.spring_loaded_hotseat_top_margin_wide_portrait)
607 : res.getDimensionPixelSize(R.dimen.spring_loaded_hotseat_top_margin);
Jordan Silva999dd2a2023-11-17 19:31:43 +0000608
609 if (mIsResponsiveGrid) {
610 updateHotseatSizes(mResponsiveWorkspaceCellSpec.getIconSize());
611 } else {
612 updateHotseatSizes(pxFromDp(inv.iconSize[mTypeIndex], mMetrics));
613 }
614
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700615 if (areNavButtonsInline && !isPhone) {
Jon Mirandae17a9492023-03-08 16:42:20 -0800616 inlineNavButtonsEndSpacingPx =
Thales Limaffc68b02023-01-09 16:20:23 +0000617 res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing);
Pat Manning26f70f72022-07-07 13:50:39 +0100618 /*
619 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700620 * Spacing between nav buttons +
Thales Lima6a590062022-11-22 15:52:49 +0000621 * Space at the end for contextual buttons
Pat Manning26f70f72022-07-07 13:50:39 +0100622 */
623 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700624 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
Jon Mirandae17a9492023-03-08 16:42:20 -0800625 + inlineNavButtonsEndSpacingPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100626 } else {
Jon Mirandae17a9492023-03-08 16:42:20 -0800627 inlineNavButtonsEndSpacingPx = 0;
Pat Manning26f70f72022-07-07 13:50:39 +0100628 hotseatBarEndOffset = 0;
629 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700630
Liran Binyamina833af32023-08-02 16:30:27 -0400631 mBubbleBarSpaceThresholdPx =
632 res.getDimensionPixelSize(R.dimen.bubblebar_hotseat_adjustment_threshold);
633
Thales Lima79456492023-05-23 11:32:22 +0100634 // Needs to be calculated after hotseatBarSizePx is correct,
635 // for the available height to be correct
636 if (mIsResponsiveGrid) {
Thales Lima2759aa32023-06-05 16:25:45 +0100637 int availableResponsiveWidth =
638 availableWidthPx - (isVerticalBarLayout() ? hotseatBarSizePx : 0);
Jordan Silva376036a2023-11-08 15:56:40 +0000639 int numWorkspaceColumns = getPanelCount() * inv.numColumns;
Thales Lima8e11d532023-08-31 13:40:26 +0000640 // don't use availableHeightPx because it subtracts mInsets.bottom
641 int availableResponsiveHeight = heightPx - mInsets.top
Jordan Silvaf2402e22023-10-26 19:53:16 +0100642 - (isVerticalBarLayout() ? 0 : hotseatBarSizePx);
643 float responsiveAspectRatio = (float) widthPx / heightPx;
Thales Limaabfe3642023-05-24 18:08:53 +0100644
Jordan Silvaf2402e22023-10-26 19:53:16 +0100645 ResponsiveSpecsProvider workspaceSpecs = ResponsiveSpecsProvider.create(
Jordan Silva575c3bd2023-07-21 12:00:43 +0100646 new ResourceHelper(context,
Jordan Silvaf2402e22023-10-26 19:53:16 +0100647 isTwoPanels ? inv.workspaceSpecsTwoPanelId : inv.workspaceSpecsId),
648 ResponsiveSpecType.Workspace);
Jordan Silva8f7986a2023-11-08 12:11:25 +0000649 mResponsiveWorkspaceWidthSpec = workspaceSpecs.getCalculatedSpec(responsiveAspectRatio,
Jordan Silva376036a2023-11-08 15:56:40 +0000650 DimensionType.WIDTH, numWorkspaceColumns, availableResponsiveWidth);
Jordan Silva8f7986a2023-11-08 12:11:25 +0000651 mResponsiveWorkspaceHeightSpec = workspaceSpecs.getCalculatedSpec(responsiveAspectRatio,
Jordan Silvaf2402e22023-10-26 19:53:16 +0100652 DimensionType.HEIGHT, inv.numRows, availableResponsiveHeight);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100653
Jordan Silvaf2402e22023-10-26 19:53:16 +0100654 ResponsiveSpecsProvider allAppsSpecs = ResponsiveSpecsProvider.create(
Jordan Silva575c3bd2023-07-21 12:00:43 +0100655 new ResourceHelper(context,
Jordan Silvaf2402e22023-10-26 19:53:16 +0100656 isTwoPanels ? inv.allAppsSpecsTwoPanelId : inv.allAppsSpecsId),
657 ResponsiveSpecType.AllApps);
Jordan Silva8f7986a2023-11-08 12:11:25 +0000658 mResponsiveAllAppsWidthSpec = allAppsSpecs.getCalculatedSpec(responsiveAspectRatio,
Jordan Silva8b3fa142023-11-13 21:31:38 +0000659 DimensionType.WIDTH, numShownAllAppsColumns, availableWidthPx,
Jordan Silva8f7986a2023-11-08 12:11:25 +0000660 mResponsiveWorkspaceWidthSpec);
661 mResponsiveAllAppsHeightSpec = allAppsSpecs.getCalculatedSpec(responsiveAspectRatio,
Jordan Silva2de6a272024-01-04 14:44:20 -0300662 DimensionType.HEIGHT, inv.numAllAppsRowsForCellHeightCalculation,
663 heightPx - mInsets.top, mResponsiveWorkspaceHeightSpec);
Jordan Silvaf2402e22023-10-26 19:53:16 +0100664
665 ResponsiveSpecsProvider folderSpecs = ResponsiveSpecsProvider.create(
666 new ResourceHelper(context,
667 isTwoPanels ? inv.folderSpecsTwoPanelId : inv.folderSpecsId),
668 ResponsiveSpecType.Folder);
669 mResponsiveFolderWidthSpec = folderSpecs.getCalculatedSpec(responsiveAspectRatio,
Thales Lima1faa4ed2023-12-01 16:48:19 +0000670 DimensionType.WIDTH, numFolderColumns,
Jordan Silva8f7986a2023-11-08 12:11:25 +0000671 mResponsiveWorkspaceWidthSpec.getAvailableSpace(),
672 mResponsiveWorkspaceWidthSpec);
Jordan Silvaf2402e22023-10-26 19:53:16 +0100673 mResponsiveFolderHeightSpec = folderSpecs.getCalculatedSpec(responsiveAspectRatio,
Thales Lima1faa4ed2023-12-01 16:48:19 +0000674 DimensionType.HEIGHT, numFolderRows,
Jordan Silva8f7986a2023-11-08 12:11:25 +0000675 mResponsiveWorkspaceHeightSpec.getAvailableSpace(),
676 mResponsiveWorkspaceHeightSpec);
Jordan Silva999dd2a2023-11-17 19:31:43 +0000677
678 ResponsiveCellSpecsProvider allAppsCellSpecs = ResponsiveCellSpecsProvider.create(
679 new ResourceHelper(context,
680 isTwoPanels ? inv.allAppsCellSpecsTwoPanelId
681 : inv.allAppsCellSpecsId));
682 mResponsiveAllAppsCellSpec = allAppsCellSpecs.getCalculatedSpec(
683 responsiveAspectRatio,
684 mResponsiveAllAppsHeightSpec.getAvailableSpace(),
685 mResponsiveWorkspaceCellSpec);
Thales Lima79456492023-05-23 11:32:22 +0100686 }
687
688 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
689 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
690
Alex Chau635b3ab2022-01-26 16:49:10 +0000691 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Pat Manning1695cc72023-07-05 11:45:13 +0100692 overviewTaskIconSizePx = enableOverviewIconMenu() ? res.getDimensionPixelSize(
693 R.dimen.task_thumbnail_icon_menu_drawable_touch_size) : res.getDimensionPixelSize(
694 R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100695 overviewTaskIconDrawableSizePx =
696 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
697 overviewTaskIconDrawableSizeGridPx =
698 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Pat Manning1695cc72023-07-05 11:45:13 +0100699 overviewTaskThumbnailTopMarginPx =
700 enableOverviewIconMenu() ? 0 : overviewTaskIconSizePx + overviewTaskMarginPx;
Andy Wickhambc3bac42023-08-07 16:02:23 -0700701 // Don't add margin with floating search bar to minimize risk of overlapping.
702 overviewActionsTopMarginPx = FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get() ? 0
703 : res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000704 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
705 overviewActionsButtonSpacing = res.getDimensionPixelSize(
706 R.dimen.overview_actions_button_spacing);
Andy Wickhambc3bac42023-08-07 16:02:23 -0700707 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700708 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000709 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700710
Jeremy Sim0ac47082022-10-10 13:59:40 -0700711 splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset);
Winson Chung104a4c82023-11-08 18:56:15 +0000712 // We need to use the full window bounds for split determination because on near-square
713 // devices, the available bounds (bounds minus insets) may actually be in landscape while
714 // actually portrait
715 int leftRightSplitPortraitResId = Resources.getSystem().getIdentifier(
716 "config_leftRightSplitInPortrait", "bool", "android");
717 boolean allowLeftRightSplitInPortrait =
718 com.android.wm.shell.Flags.enableLeftRightSplitInPortrait()
719 && leftRightSplitPortraitResId > 0
720 && res.getBoolean(leftRightSplitPortraitResId);
721 if (allowLeftRightSplitInPortrait && isTablet) {
722 isLeftRightSplit = !isLandscape;
723 } else {
724 isLeftRightSplit = isLandscape;
725 }
Jeremy Sim0ac47082022-10-10 13:59:40 -0700726
Jon Miranda2ed276e2017-06-29 11:36:34 -0700727 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400728 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700729
Thales Lima79456492023-05-23 11:32:22 +0100730 calculateAndSetWorkspaceVerticalPadding(context, inv, extraSpace);
Pat Manning08610ca2022-04-05 21:03:16 +0100731
732 int cellLayoutPadding =
733 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
734 R.dimen.cell_layout_padding);
735 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
736 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800737 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800738
Thales Lima7eee74b2023-03-16 16:00:55 -0300739 // Folder scaling requires correct workspace paddings
740 updateAvailableFolderCellDimensions(res);
741
Thales Limaffc68b02023-01-09 16:20:23 +0000742 mMinHotseatIconSpacePx = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
743 mMinHotseatQsbWidthPx = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
744 mMaxHotseatIconSpacePx = areNavButtonsInline
Thales Lima6a590062022-11-22 15:52:49 +0000745 ? res.getDimensionPixelSize(R.dimen.max_hotseat_icon_space) : Integer.MAX_VALUE;
Thales Lima425f6822022-05-10 13:44:58 -0300746 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima6a590062022-11-22 15:52:49 +0000747 recalculateHotseatWidthAndBorderSpace();
Alex Chau206ede92022-08-01 17:46:12 +0100748
Jordan Silva3646a1b2023-08-02 13:52:52 +0100749 if (mIsResponsiveGrid && isVerticalBarLayout()) {
750 hotseatBorderSpace = cellLayoutBorderSpacePx.y;
751 }
752
Alex Chau206ede92022-08-01 17:46:12 +0100753 if (isTablet) {
Andy Wickham99d7d4f2023-11-15 08:09:09 +0000754 allAppsPadding.top = mInsets.top;
755 allAppsShiftRange = heightPx;
Alex Chau206ede92022-08-01 17:46:12 +0100756 } else {
Thales Limab433c9c2023-10-30 12:24:05 +0000757 allAppsPadding.top = 0;
Alex Chau206ede92022-08-01 17:46:12 +0100758 allAppsShiftRange =
759 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
760 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100761 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
762 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300763
Alex Chaua02eddc2021-04-29 00:36:06 +0100764 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
765 R.dimen.drag_flingToDeleteMinVelocity);
766
Sihua Mae04aa202022-07-18 12:43:56 -0700767 mViewScaleProvider = viewScaleProvider;
768
Jon Miranda2b25ded2023-02-02 14:48:45 -0800769 dimensionOverrideProvider.accept(this);
770
Tony Wickham1237df02017-02-24 08:59:36 -0800771 // This is done last, after iconSizePx is calculated above.
Sunny Goyal799e1202023-02-09 10:54:28 -0800772 mDotRendererWorkSpace = createDotRenderer(context, iconSizePx, dotRendererCache);
773 mDotRendererAllApps = createDotRenderer(context, allAppsIconSizePx, dotRendererCache);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700774 }
775
776 private static DotRenderer createDotRenderer(
Sunny Goyal799e1202023-02-09 10:54:28 -0800777 @NonNull Context context, int size, @NonNull SparseArray<DotRenderer> cache) {
Sunny Goyal65190ae2022-08-02 14:16:26 -0700778 DotRenderer renderer = cache.get(size);
779 if (renderer == null) {
Sunny Goyal799e1202023-02-09 10:54:28 -0800780 renderer = new DotRenderer(size, getShapePath(context, DEFAULT_DOT_SIZE),
781 DEFAULT_DOT_SIZE);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700782 cache.put(size, renderer);
783 }
784 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700785 }
786
Thales Lima425f6822022-05-10 13:44:58 -0300787 /**
Fengjiang Li6c590822023-09-25 15:04:57 -0700788 * Return maximum of all apps row count displayed on screen. Note that 1) Partially displayed
789 * row is counted as 1 row, and 2) we don't exclude the space of floating search bar. This
790 * method is used for calculating number of {@link BubbleTextView} we need to pre-inflate. Thus
791 * reasonable over estimation is fine.
792 */
793 public int getMaxAllAppsRowCount() {
Thales Limab433c9c2023-10-30 12:24:05 +0000794 return (int) (Math.ceil((availableHeightPx - allAppsPadding.top)
Fengjiang Li6c590822023-09-25 15:04:57 -0700795 / (float) allAppsCellHeightPx));
796 }
797
798 /**
Thales Lima425f6822022-05-10 13:44:58 -0300799 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
800 * width of the hotseat.
801 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100802 private int calculateQsbWidth(int hotseatBorderSpace) {
fbarone69b6f42023-12-18 13:20:34 -0800803 int iconExtraSpacePx = iconSizePx - getIconVisibleSizePx(iconSizePx);
Thales Lima425f6822022-05-10 13:44:58 -0300804 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100805 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300806 return getIconToIconWidthForColumns(columns)
807 - iconSizePx * numShownHotseatIcons
fbarone69b6f42023-12-18 13:20:34 -0800808 - hotseatBorderSpace * numShownHotseatIcons
809 - iconExtraSpacePx;
Thales Lima425f6822022-05-10 13:44:58 -0300810 } else {
811 int columns = inv.hotseatColumnSpan[mTypeIndex];
fbarone69b6f42023-12-18 13:20:34 -0800812 return getIconToIconWidthForColumns(columns) - iconExtraSpacePx;
Thales Lima425f6822022-05-10 13:44:58 -0300813 }
814 }
Thales Lima2903a622022-03-17 13:52:19 +0000815
Thales Lima425f6822022-05-10 13:44:58 -0300816 private int getIconToIconWidthForColumns(int columns) {
817 return columns * getCellSize().x
818 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400819 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000820 }
821
Thales Limad90faab2021-09-21 17:18:47 +0100822 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
Thales Lima79456492023-05-23 11:32:22 +0100823 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +0000824 return mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
Thales Lima79456492023-05-23 11:32:22 +0100825 }
826
Thales Limad90faab2021-09-21 17:18:47 +0100827 if (isVerticalBarLayout()) {
828 return 0;
829 }
830
Thales Lima79456492023-05-23 11:32:22 +0100831 return mIsScalableGrid
Thales Lima83bedbf2021-10-05 17:47:39 +0100832 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
833 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100834 }
835
Thales Lima79456492023-05-23 11:32:22 +0100836 private void calculateAndSetWorkspaceVerticalPadding(Context context,
837 InvariantDeviceProfile inv,
838 int extraSpace) {
839 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +0000840 workspaceTopPadding = mResponsiveWorkspaceHeightSpec.getStartPaddingPx();
841 workspaceBottomPadding = mResponsiveWorkspaceHeightSpec.getEndPaddingPx();
Thales Lima79456492023-05-23 11:32:22 +0100842 } else if (mIsScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
843 // Paddings were created assuming no scaling, so we first unscale the extra space.
844 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
845 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
846 DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
847 maxEmptySpace = padding.getMaxEmptySpacePx();
848
849 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
850 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
851
852 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
853 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
854 }
855 }
856
Thales Limab8c05952022-05-23 16:58:38 +0100857 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
858 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700859 // Ensure there is enough space for folder icons, which have a slightly larger radius.
Jordan Silva3646a1b2023-08-02 13:52:52 +0100860 hotseatCellHeightPx = getIconSizeWithOverlap(hotseatIconSizePx);
Thales Limab8c05952022-05-23 16:58:38 +0100861
Jon Miranda0d284852021-06-22 14:50:55 -0700862 if (isVerticalBarLayout()) {
Thales Lima8e11d532023-08-31 13:40:26 +0000863 hotseatBarSizePx = hotseatIconSizePx + mHotseatBarEdgePaddingPx
864 + mHotseatBarWorkspaceSpacePx;
Thales Limab8c05952022-05-23 16:58:38 +0100865 } else if (isQsbInline) {
866 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
867 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700868 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100869 hotseatBarSizePx = hotseatIconSizePx
870 + hotseatQsbSpace
871 + hotseatQsbVisualHeight
872 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700873 }
874 }
875
Thales Lima6a590062022-11-22 15:52:49 +0000876 /**
877 * Calculates the width of the hotseat, changing spaces between the icons and removing icons if
878 * necessary.
879 */
880 public void recalculateHotseatWidthAndBorderSpace() {
Thales Lima79456492023-05-23 11:32:22 +0100881 if (!mIsScalableGrid) return;
Thales Lima6a590062022-11-22 15:52:49 +0000882
883 int columns = inv.hotseatColumnSpan[mTypeIndex];
884 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
885 hotseatBorderSpace = calculateHotseatBorderSpace(hotseatWidthPx, /* numExtraBorder= */ 0);
Thales Lima9938c2f2022-07-25 14:38:16 +0100886 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
Thales Lima6a590062022-11-22 15:52:49 +0000887 // Spaces should be correct when the nav buttons are not inline
Thales Lima9938c2f2022-07-25 14:38:16 +0100888 if (!areNavButtonsInline) {
889 return;
890 }
891
Thales Lima6a590062022-11-22 15:52:49 +0000892 // The side space with inline buttons should be what is defined in InvariantDeviceProfile
Jon Mirandae17a9492023-03-08 16:42:20 -0800893 int sideSpacePx = inlineNavButtonsEndSpacingPx;
Thales Limaffc68b02023-01-09 16:20:23 +0000894 int maxHotseatWidthPx = availableWidthPx - sideSpacePx - hotseatBarEndOffset;
895 int maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
896 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000897 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100898
Thales Limaffc68b02023-01-09 16:20:23 +0000899 if (hotseatBorderSpace >= mMinHotseatIconSpacePx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100900 return;
901 }
902
903 // Border space can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000904 hotseatBorderSpace = mMinHotseatIconSpacePx;
Thales Lima6a590062022-11-22 15:52:49 +0000905 int requiredWidth = getHotseatRequiredWidth();
Thales Lima9938c2f2022-07-25 14:38:16 +0100906
907 // If there is an inline qsb, change its size
908 if (isQsbInline) {
Thales Limaffc68b02023-01-09 16:20:23 +0000909 hotseatQsbWidth -= requiredWidth - maxHotseatWidthPx;
910 if (hotseatQsbWidth >= mMinHotseatQsbWidthPx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100911 return;
912 }
913
914 // QSB can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000915 hotseatQsbWidth = mMinHotseatQsbWidthPx;
Thales Lima9938c2f2022-07-25 14:38:16 +0100916 }
917
Thales Limaffc68b02023-01-09 16:20:23 +0000918 maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
Thales Lima6a590062022-11-22 15:52:49 +0000919
Thales Lima9938c2f2022-07-25 14:38:16 +0100920 // If it still doesn't fit, start removing icons
921 do {
922 numShownHotseatIcons--;
Thales Limaffc68b02023-01-09 16:20:23 +0000923 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000924 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Limaffc68b02023-01-09 16:20:23 +0000925 } while (hotseatBorderSpace < mMinHotseatIconSpacePx && numShownHotseatIcons > 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100926 }
927
Thales Lima78d00ad2021-09-30 11:29:06 +0100928 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100929 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100930 }
931
932 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima79456492023-05-23 11:32:22 +0100933 int horizontalSpacePx = 0;
934 int verticalSpacePx = 0;
Thales Lima78d00ad2021-09-30 11:29:06 +0100935
Thales Lima79456492023-05-23 11:32:22 +0100936 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +0000937 horizontalSpacePx = mResponsiveWorkspaceWidthSpec.getGutterPx();
938 verticalSpacePx = mResponsiveWorkspaceHeightSpec.getGutterPx();
Thales Lima79456492023-05-23 11:32:22 +0100939 } else if (mIsScalableGrid) {
940 horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
941 verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
942 }
Thales Lima78d00ad2021-09-30 11:29:06 +0100943
944 return new Point(horizontalSpacePx, verticalSpacePx);
945 }
946
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700947 public Info getDisplayInfo() {
948 return mInfo;
949 }
950
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700951 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800952 WindowBounds bounds = new WindowBounds(
953 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700954 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100955 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700956
957 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
958 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
959 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
960
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700961 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700962 .setWindowBounds(bounds)
Alex Chauab800f72022-12-13 17:46:06 +0000963 .setIsMultiDisplay(isMultiDisplay)
Alex Chau6ed408f2022-03-04 12:58:05 +0000964 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700965 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000966 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800967 }
968
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700969 public DeviceProfile copy(Context context) {
970 return toBuilder(context).build();
971 }
972
973 /**
974 * TODO: Move this to the builder as part of setMultiWindowMode
975 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700976 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700977 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700978 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700979 .setMultiWindowMode(true)
980 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800981
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800982 // We use these scales to measure and layout the widgets using their full invariant profile
983 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
984 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
985 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700986 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
987 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
988 profile = profile.toBuilder(context)
989 .setViewScaleProvider(i -> p)
990 .build();
991 }
992
993 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800994
Jon Miranda93e1f042016-11-11 14:13:04 -0800995 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700996 }
997
Adam Cohen63f1ec02014-08-12 09:23:13 -0700998 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400999 * Checks if there is enough space for labels on the workspace.
1000 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -07001001 * It is important to call this method after the All Apps variables have been set.
1002 */
Jon Miranda941375e2021-03-31 13:10:45 -04001003 private void hideWorkspaceLabelsIfNotEnoughSpace() {
1004 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
1005 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
1006 - iconTextHeight;
1007
1008 // We want enough space so that the text is closer to its corresponding icon.
1009 if (workspaceCellPaddingY < iconTextHeight) {
1010 iconTextSizePx = 0;
1011 iconDrawablePaddingPx = 0;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001012 cellHeightPx = getIconSizeWithOverlap(iconSizePx);
Jon Miranda941375e2021-03-31 13:10:45 -04001013 autoResizeAllAppsCells();
1014 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001015 }
Jon Miranda1091e532017-07-21 13:31:50 -07001016
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001017 /**
Jon Miranda228877d2021-02-09 11:05:00 -05001018 * Returns the amount of extra (or unused) vertical space.
1019 */
1020 private int updateAvailableDimensions(Resources res) {
fbaronfc6bbcf2024-01-29 10:35:17 -08001021 iconCenterVertically = (mIsScalableGrid || mIsResponsiveGrid) && isVerticalBarLayout();
Jordan Silva999dd2a2023-11-17 19:31:43 +00001022
1023 if (mIsResponsiveGrid) {
Jordan Silva15cacd52023-11-28 14:32:05 +00001024 iconSizePx = mResponsiveWorkspaceCellSpec.getIconSize();
1025 iconTextSizePx = mResponsiveWorkspaceCellSpec.getIconTextSize();
1026 mIconDrawablePaddingOriginalPx = mResponsiveWorkspaceCellSpec.getIconDrawablePadding();
Jordan Silva999dd2a2023-11-17 19:31:43 +00001027 updateIconSize(1f, res);
1028 updateWorkspacePadding();
1029 return 0;
1030 }
1031
Alex Chaua68164d2022-12-15 16:16:03 +00001032 float invIconSizeDp = inv.iconSize[mTypeIndex];
1033 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
1034 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
1035 iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
1036
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001037 updateIconSize(1f, res);
Pat Manning08610ca2022-04-05 21:03:16 +01001038 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -05001039
1040 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +01001041 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +00001042 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -05001043 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -05001044 float scaleY = maxHeight / usedHeight;
1045 boolean shouldScale = scaleY < 1f;
1046
1047 float scaleX = 1f;
Thales Lima79456492023-05-23 11:32:22 +01001048 if (mIsScalableGrid) {
Jon Mirandae126d722021-02-25 10:45:20 -05001049 // We scale to fit the cellWidth and cellHeight in the available space.
1050 // The benefit of scalable grids is that we can get consistent aspect ratios between
1051 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +01001052 float usedWidth =
1053 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -05001054 // We do not subtract padding here, as we also scale the workspace padding if needed.
1055 scaleX = availableWidthPx / usedWidth;
1056 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -07001057 }
Jon Mirandae126d722021-02-25 10:45:20 -05001058
1059 if (shouldScale) {
1060 float scale = Math.min(scaleX, scaleY);
1061 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +01001062 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -05001063 }
1064
Jon Miranda228877d2021-02-09 11:05:00 -05001065 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -07001066 }
1067
Pat Manninga2e14992022-04-22 11:29:17 +01001068 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +01001069 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
1070 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
1071 }
1072
Pat Manninga2e14992022-04-22 11:29:17 +01001073 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +00001074 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +01001075 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
1076 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -05001077 }
1078
Jordan Silva376036a2023-11-08 15:56:40 +00001079 private int getNormalizedIconDrawablePadding(int iconSizePx, int iconDrawablePadding) {
fbarone69b6f42023-12-18 13:20:34 -08001080 return Math.max(0, iconDrawablePadding
1081 - ((iconSizePx - getIconVisibleSizePx(iconSizePx)) / 2));
Jordan Silva376036a2023-11-08 15:56:40 +00001082 }
1083
1084 private int getNormalizedIconDrawablePadding() {
1085 return getNormalizedIconDrawablePadding(iconSizePx, mIconDrawablePaddingOriginalPx);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001086 }
1087
1088 private int getNormalizedFolderChildDrawablePaddingPx(int textHeight) {
1089 // TODO(b/235886078): workaround needed because of this bug
1090 // Icons are 10% larger on XML than their visual size,
1091 // so remove that extra space to get labels closer to the correct padding
1092 int drawablePadding = (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3;
1093
fbarone69b6f42023-12-18 13:20:34 -08001094 int iconSizeDiff = folderChildIconSizePx - getIconVisibleSizePx(folderChildIconSizePx);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001095 return Math.max(0, drawablePadding - iconSizeDiff / 2);
1096 }
1097
Jordan Silva3646a1b2023-08-02 13:52:52 +01001098 private int getIconSizeWithOverlap(int iconSize) {
1099 return (int) Math.ceil(iconSize * ICON_OVERLAP_FACTOR);
1100 }
1101
Jon Miranda6f7e9702019-09-16 14:44:14 -07001102 /**
1103 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
1104 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
1105 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
1106 */
Tony Wickham7ba547c2021-02-02 17:12:08 -08001107 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -07001108 // Icon scale should never exceed 1, otherwise pixellation may occur.
1109 iconScale = Math.min(1f, scale);
1110 cellScaleToFit = scale;
1111
Jon Miranda18751b62017-07-31 17:25:27 -07001112 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -08001113 final boolean isVerticalLayout = isVerticalBarLayout();
Thales Lima080d8902022-03-28 15:30:29 +01001114 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -05001115
Thales Lima79456492023-05-23 11:32:22 +01001116 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001117 cellWidthPx = mResponsiveWorkspaceWidthSpec.getCellSizePx();
1118 cellHeightPx = mResponsiveWorkspaceHeightSpec.getCellSizePx();
Thales Lima79456492023-05-23 11:32:22 +01001119
Thales Lima2759aa32023-06-05 16:25:45 +01001120 if (cellWidthPx < iconSizePx) {
1121 // get a smaller icon size
1122 iconSizePx = mIconSizeSteps.getIconSmallerThan(cellWidthPx);
Thales Lima2759aa32023-06-05 16:25:45 +01001123 }
1124
Jordan Silvadd612682024-01-08 11:38:13 -03001125 if (isVerticalLayout) {
1126 iconDrawablePaddingPx = 0;
1127 iconTextSizePx = 0;
1128 } else {
1129 iconDrawablePaddingPx = getNormalizedIconDrawablePadding();
1130 }
Thales Lima93ee8fc2023-06-05 17:07:11 +01001131
Thales Lima24ceca62023-09-25 16:21:17 -07001132 CellContentDimensions cellContentDimensions = new CellContentDimensions(iconSizePx,
1133 iconDrawablePaddingPx,
1134 iconTextSizePx);
Jordan Silvadd612682024-01-08 11:38:13 -03001135 int cellContentHeight = cellContentDimensions.resizeToFitCellHeight(cellHeightPx,
1136 mIconSizeSteps);
Thales Lima24ceca62023-09-25 16:21:17 -07001137 iconSizePx = cellContentDimensions.getIconSizePx();
1138 iconDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1139 iconTextSizePx = cellContentDimensions.getIconTextSizePx();
Thales Lima2759aa32023-06-05 16:25:45 +01001140
Jordan Silvadd612682024-01-08 11:38:13 -03001141 if (isVerticalLayout) {
1142 cellYPaddingPx = Math.max(0, getCellSize().y - getIconSizeWithOverlap(iconSizePx))
1143 / 2;
1144 } else {
1145 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
1146 }
Thales Lima79456492023-05-23 11:32:22 +01001147 } else if (mIsScalableGrid) {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001148 iconDrawablePaddingPx = (int) (getNormalizedIconDrawablePadding() * iconScale);
Thales Lima83bedbf2021-10-05 17:47:39 +01001149 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
1150 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001151
1152 if (cellWidthPx < iconSizePx) {
1153 // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger.
1154 int numColumns = getPanelCount() * inv.numColumns;
1155 int numBorders = numColumns - 1;
1156 int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns;
1157 if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) {
1158 cellWidthPx = iconSizePx;
1159 cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders;
1160 } else {
1161 // If it still doesn't fit, set borderSpace to 0 and distribute the space for
1162 // cellWidth, and reduce iconSize.
1163 cellWidthPx = (cellWidthPx * numColumns
1164 + cellLayoutBorderSpacePx.x * numBorders) / numColumns;
1165 iconSizePx = Math.min(iconSizePx, cellWidthPx);
1166 cellLayoutBorderSpacePx.x = 0;
1167 }
1168 }
1169
Thales Lima93ee8fc2023-06-05 17:07:11 +01001170 int cellTextAndPaddingHeight =
1171 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +00001172 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
1173 if (cellHeightPx < cellContentHeight) {
1174 // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight
1175 // bigger.
1176 int numBorders = inv.numRows - 1;
1177 int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows;
1178 if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) {
1179 cellHeightPx = cellContentHeight;
1180 cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders;
1181 } else {
Alex Chau06f36e82023-01-06 10:50:54 +00001182 // If it still doesn't fit, set borderSpace to 0 to recover space.
Alex Chaube753132022-12-09 16:46:54 +00001183 cellHeightPx = (cellHeightPx * inv.numRows
1184 + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows;
Alex Chaube753132022-12-09 16:46:54 +00001185 cellLayoutBorderSpacePx.y = 0;
Alex Chau06f36e82023-01-06 10:50:54 +00001186 // Reduce iconDrawablePaddingPx to make cellContentHeight smaller.
1187 int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx;
1188 if (cellContentWithoutPadding <= cellHeightPx) {
1189 iconDrawablePaddingPx = cellContentHeight - cellHeightPx;
1190 } else {
1191 // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space,
1192 // then proportional reduce iconSizePx and iconTextSizePx to fit.
1193 iconDrawablePaddingPx = 0;
1194 float ratio = cellHeightPx / (float) cellContentWithoutPadding;
1195 iconSizePx = (int) (iconSizePx * ratio);
1196 iconTextSizePx = (int) (iconTextSizePx * ratio);
1197 }
1198 cellTextAndPaddingHeight =
1199 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +00001200 }
1201 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
1202 }
Jon Mirandae126d722021-02-25 10:45:20 -05001203 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +01001204 desiredWorkspaceHorizontalMarginPx =
1205 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -05001206 } else {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001207 iconDrawablePaddingPx = (int) (getNormalizedIconDrawablePadding() * iconScale);
Jon Mirandae126d722021-02-25 10:45:20 -05001208 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001209 cellHeightPx = getIconSizeWithOverlap(iconSizePx)
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001210 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -05001211 + Utilities.calculateTextHeight(iconTextSizePx);
1212 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
1213 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
1214 && !isMultiWindowMode) {
1215 // Ensures that the label is closer to its corresponding icon. This is not an issue
1216 // with vertical bar layout or multi-window mode since the issue is handled
1217 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
1218 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
1219 iconDrawablePaddingPx = cellPaddingY;
1220 }
Jon Miranda846455e2017-10-02 14:58:52 -07001221 }
Jon Miranda18751b62017-07-31 17:25:27 -07001222
Sunny Goyalae190ff2020-04-14 00:19:01 +00001223 // All apps
Thales Limaabfe3642023-05-24 18:08:53 +01001224 if (mIsResponsiveGrid) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001225 updateAllAppsWithResponsiveMeasures();
Thales Limaabfe3642023-05-24 18:08:53 +01001226 } else {
1227 updateAllAppsIconSize(scale, res);
1228 }
1229 updateAllAppsContainerWidth();
Jordan Silvadd612682024-01-08 11:38:13 -03001230 if (isVerticalLayout && !mIsResponsiveGrid) {
Thales Limaabfe3642023-05-24 18:08:53 +01001231 hideWorkspaceLabelsIfNotEnoughSpace();
1232 }
Brandon Dayauon3cdb32c2023-08-22 21:26:37 -07001233 if (FeatureFlags.enableTwolineAllapps()) {
1234 // Add extra textHeight to the existing allAppsCellHeight.
1235 allAppsCellHeightPx += Utilities.calculateTextHeight(allAppsIconTextSizePx);
1236 }
Winson Chungb3800242013-10-24 11:01:54 -07001237
Thales Limab8c05952022-05-23 16:58:38 +01001238 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -07001239
Sunny Goyalbaec6ff2016-09-14 11:26:21 -07001240 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -07001241 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
1242 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Sunny Goyal6c304b12023-04-10 12:03:04 -07001243
1244 // Update widget padding:
1245 float minSpacing = pxFromDp(MIN_WIDGET_PADDING_DP, mMetrics);
1246 if (cellLayoutBorderSpacePx.x < minSpacing
1247 || cellLayoutBorderSpacePx.y < minSpacing) {
1248 widgetPadding.left = widgetPadding.right =
1249 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.x));
1250 widgetPadding.top = widgetPadding.bottom =
1251 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.y));
1252 } else {
1253 widgetPadding.setEmpty();
1254 }
Winson Chung0f785722015-04-08 10:27:49 -07001255 }
1256
Thales Lima425f6822022-05-10 13:44:58 -03001257 /**
Thales Lima6a590062022-11-22 15:52:49 +00001258 * This method calculates the space between the icons to achieve a certain width.
Thales Lima425f6822022-05-10 13:44:58 -03001259 */
Thales Lima6a590062022-11-22 15:52:49 +00001260 private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) {
Jordan Silvad9227182023-08-17 15:53:59 +01001261 int numBorders = (numShownHotseatIcons - 1 + numExtraBorder);
1262 if (numBorders <= 0) return 0;
1263
Thales Lima9938c2f2022-07-25 14:38:16 +01001264 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
Jordan Silvad9227182023-08-17 15:53:59 +01001265 int hotseatBorderSpacePx = (int) (hotseatWidthPx - hotseatIconsTotalPx) / numBorders;
Thales Limaffc68b02023-01-09 16:20:23 +00001266 return Math.min(hotseatBorderSpacePx, mMaxHotseatIconSpacePx);
Thales Lima425f6822022-05-10 13:44:58 -03001267 }
1268
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001269 /**
1270 * Updates the iconSize for allApps* variants.
1271 */
Brian Isganitisa9a78112022-05-23 18:11:47 -07001272 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +01001273 allAppsBorderSpacePx = new Point(
1274 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
1275 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001276 // AllApps cells don't have real space between cells,
1277 // so we add the border space to the cell height
Alex Chaube753132022-12-09 16:46:54 +00001278 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics)
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001279 + allAppsBorderSpacePx.y;
1280 // but width is just the cell,
1281 // the border is added in #updateAllAppsContainerWidth
Thales Lima79456492023-05-23 11:32:22 +01001282 if (mIsScalableGrid) {
Alex Chaube753132022-12-09 16:46:54 +00001283 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1284 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001285 allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding();
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001286 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001287
1288 if (allAppsCellWidthPx < allAppsIconSizePx) {
1289 // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to
1290 // make allAppsCellWidth bigger.
1291 int numBorders = inv.numAllAppsColumns - 1;
1292 int extraWidthRequired =
1293 (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns;
1294 if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) {
1295 allAppsCellWidthPx = allAppsIconSizePx;
1296 allAppsBorderSpacePx.x -= extraWidthRequired / numBorders;
1297 } else {
1298 // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space
1299 // for allAppsCellWidth, and reduce allAppsIconSize.
1300 allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns
1301 + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns;
1302 allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx);
1303 allAppsBorderSpacePx.x = 0;
1304 }
1305 }
1306
1307 int cellContentHeight = allAppsIconSizePx
1308 + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y;
1309 if (allAppsCellHeightPx < cellContentHeight) {
1310 // Increase allAppsCellHeight to fit its content.
1311 allAppsCellHeightPx = cellContentHeight;
1312 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001313 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001314 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
1315 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001316 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1317 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001318 allAppsIconDrawablePaddingPx =
1319 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001320 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001321 }
Thales Limaabfe3642023-05-24 18:08:53 +01001322 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001323
Jordan Silva999dd2a2023-11-17 19:31:43 +00001324 private void updateAllAppsWithResponsiveMeasures() {
1325 allAppsIconSizePx = mResponsiveAllAppsCellSpec.getIconSize();
1326 allAppsIconTextSizePx = mResponsiveAllAppsCellSpec.getIconTextSize();
1327 allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding(allAppsIconSizePx,
1328 mResponsiveAllAppsCellSpec.getIconDrawablePadding());
Thales Limaabfe3642023-05-24 18:08:53 +01001329 allAppsBorderSpacePx = new Point(
Jordan Silva8f7986a2023-11-08 12:11:25 +00001330 mResponsiveAllAppsWidthSpec.getGutterPx(),
1331 mResponsiveAllAppsHeightSpec.getGutterPx()
Thales Limaabfe3642023-05-24 18:08:53 +01001332 );
Jordan Silva999dd2a2023-11-17 19:31:43 +00001333 allAppsCellHeightPx = mResponsiveAllAppsHeightSpec.getCellSizePx();
Jordan Silva8f7986a2023-11-08 12:11:25 +00001334 allAppsCellWidthPx = mResponsiveAllAppsWidthSpec.getCellSizePx();
Thales Limaa25cd902023-11-01 12:00:32 +00001335
1336 // This workaround is needed to align AllApps icons with Workspace icons
1337 // since AllApps doesn't have borders between cells
1338 int halfBorder = allAppsBorderSpacePx.x / 2;
Jordan Silva8f7986a2023-11-08 12:11:25 +00001339 allAppsPadding.left = mResponsiveAllAppsWidthSpec.getStartPaddingPx() - halfBorder;
1340 allAppsPadding.right = mResponsiveAllAppsWidthSpec.getEndPaddingPx() - halfBorder;
Jordan Silva376036a2023-11-08 15:56:40 +00001341
Jordan Silva376036a2023-11-08 15:56:40 +00001342
1343 // Reduce the size of the app icon if it doesn't fit
1344 if (allAppsCellWidthPx < allAppsIconSizePx) {
1345 // get a smaller icon size
1346 allAppsIconSizePx = mIconSizeSteps.getIconSmallerThan(allAppsCellWidthPx);
1347 }
1348
1349 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1350 allAppsIconSizePx, allAppsIconDrawablePaddingPx, (int) allAppsIconTextSizePx);
1351
1352 if (allAppsCellHeightPx < cellContentDimensions.getCellContentHeight()) {
1353 if (isVerticalBarLayout()) {
Jordan Silva2de6a272024-01-04 14:44:20 -03001354 if (allAppsCellHeightPx < allAppsIconSizePx) {
Jordan Silva376036a2023-11-08 15:56:40 +00001355 cellContentDimensions.setIconSizePx(
1356 mIconSizeSteps.getIconSmallerThan(allAppsCellHeightPx));
1357 }
1358 } else {
1359 cellContentDimensions.resizeToFitCellHeight(allAppsCellHeightPx,
1360 mIconSizeSteps);
1361 }
1362 allAppsIconSizePx = cellContentDimensions.getIconSizePx();
1363 allAppsIconDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1364 allAppsIconTextSizePx = cellContentDimensions.getIconTextSizePx();
1365 }
Jordan Silva999dd2a2023-11-17 19:31:43 +00001366
1367 allAppsCellHeightPx += mResponsiveAllAppsHeightSpec.getGutterPx();
Jordan Silvadd612682024-01-08 11:38:13 -03001368
1369 if (isVerticalBarLayout()) {
1370 autoResizeAllAppsCells();
1371 }
Thales Limaabfe3642023-05-24 18:08:53 +01001372 }
1373
1374 /**
1375 * Re-computes the all-apps cell size to be independent of workspace
1376 */
1377 public void autoResizeAllAppsCells() {
1378 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
1379 int topBottomPadding = textHeight;
1380 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
1381 + textHeight + (topBottomPadding * 2);
1382 }
1383
1384 private void updateAllAppsContainerWidth() {
1385 int cellLayoutHorizontalPadding =
1386 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
1387 if (isTablet) {
1388 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
1389 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Thales Limab433c9c2023-10-30 12:24:05 +00001390 + allAppsPadding.left + allAppsPadding.right;
Thales Limaabfe3642023-05-24 18:08:53 +01001391 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
Thales Limaa25cd902023-11-01 12:00:32 +00001392 } else if (!mIsResponsiveGrid) {
Thales Limab433c9c2023-10-30 12:24:05 +00001393 allAppsPadding.left = allAppsPadding.right =
Thales Limaabfe3642023-05-24 18:08:53 +01001394 Math.max(0, desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding
1395 - (allAppsBorderSpacePx.x / 2));
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001396 }
1397 }
1398
Thales Limaabfe3642023-05-24 18:08:53 +01001399 private void setupAllAppsStyle(Context context) {
1400 TypedArray allAppsStyle = context.obtainStyledAttributes(
1401 inv.allAppsStyle != INVALID_RESOURCE_HANDLE ? inv.allAppsStyle
1402 : R.style.AllAppsStyleDefault, R.styleable.AllAppsStyle);
1403
Thales Limab433c9c2023-10-30 12:24:05 +00001404 allAppsPadding.left = allAppsPadding.right = allAppsStyle.getDimensionPixelSize(
Thales Limaabfe3642023-05-24 18:08:53 +01001405 R.styleable.AllAppsStyle_horizontalPadding, 0);
1406 allAppsStyle.recycle();
1407 }
1408
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001409 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001410 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001411
Jordan Silva637f4eb2023-06-13 11:21:53 +01001412 // Responsive grid doesn't need to scale the folder
1413 if (mIsResponsiveGrid) return;
1414
Thales Lima7eee74b2023-03-16 16:00:55 -03001415 // For usability we can't have the folder use the whole width of the screen
Sunny Goyal07b69292018-01-08 14:19:34 -08001416 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -08001417
Thales Lima7eee74b2023-03-16 16:00:55 -03001418 // Check if the folder fit within the available height.
Thales Lima1faa4ed2023-12-01 16:48:19 +00001419 float contentUsedHeight = folderCellHeightPx * numFolderRows
1420 + ((numFolderRows - 1) * folderCellLayoutBorderSpacePx.y)
Thales Lima7eee74b2023-03-16 16:00:55 -03001421 + folderFooterHeightPx
1422 + folderContentPaddingTop;
1423 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001424 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -08001425
Thales Lima7eee74b2023-03-16 16:00:55 -03001426 // Check if the folder fit within the available width.
Thales Lima1faa4ed2023-12-01 16:48:19 +00001427 float contentUsedWidth = folderCellWidthPx * numFolderColumns
1428 + ((numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x)
Thales Lima7eee74b2023-03-16 16:00:55 -03001429 + folderContentPaddingLeftRight * 2;
1430 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001431 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -08001432
1433 float scale = Math.min(scaleX, scaleY);
1434 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001435 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001436 }
1437 }
1438
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001439 private void updateFolderCellSize(float scale, Resources res) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001440 int minLabelTextSize = pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001441 if (mIsResponsiveGrid) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001442 folderChildIconSizePx = mResponsiveWorkspaceCellSpec.getIconSize();
1443 folderChildTextSizePx = mResponsiveWorkspaceCellSpec.getIconTextSize();
1444 folderLabelTextSizePx = Math.max(minLabelTextSize,
1445 (int) (folderChildTextSizePx * folderLabelTextScale));
1446 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
1447
Jordan Silva637f4eb2023-06-13 11:21:53 +01001448 folderCellWidthPx = mResponsiveFolderWidthSpec.getCellSizePx();
Jordan Silva637f4eb2023-06-13 11:21:53 +01001449 folderCellHeightPx = mResponsiveFolderHeightSpec.getCellSizePx();
1450 folderContentPaddingTop = mResponsiveFolderHeightSpec.getStartPaddingPx();
1451 folderFooterHeightPx = mResponsiveFolderHeightSpec.getEndPaddingPx();
1452
1453 folderCellLayoutBorderSpacePx = new Point(mResponsiveFolderWidthSpec.getGutterPx(),
Thales Lima4cfd9502023-07-10 14:01:28 +01001454 mResponsiveFolderHeightSpec.getGutterPx());
Jordan Silva637f4eb2023-06-13 11:21:53 +01001455
1456 folderContentPaddingLeftRight = mResponsiveFolderWidthSpec.getStartPaddingPx();
Jordan Silva12fae112023-06-26 12:51:01 +01001457
1458 // Reduce icon width if it's wider than the expected folder cell width
1459 if (folderCellWidthPx < folderChildIconSizePx) {
1460 folderChildIconSizePx = mIconSizeSteps.getIconSmallerThan(folderCellWidthPx);
1461 }
1462
1463 // Recalculating padding and cell height
Jordan Silva3e5688a2023-12-05 15:12:29 -03001464 folderChildDrawablePaddingPx = mResponsiveWorkspaceCellSpec.getIconDrawablePadding();
Jordan Silva12fae112023-06-26 12:51:01 +01001465
Thales Limae9b5e142023-11-04 17:10:13 +00001466 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1467 folderChildIconSizePx,
1468 folderChildDrawablePaddingPx,
1469 folderChildTextSizePx);
1470 cellContentDimensions.resizeToFitCellHeight(folderCellHeightPx, mIconSizeSteps);
1471 folderChildIconSizePx = cellContentDimensions.getIconSizePx();
1472 folderChildDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1473 folderChildTextSizePx = cellContentDimensions.getIconTextSizePx();
Jordan Silva999dd2a2023-11-17 19:31:43 +00001474 folderLabelTextSizePx = Math.max(minLabelTextSize,
Jordan Silva9a3bd8f2023-11-16 18:33:28 +00001475 (int) (folderChildTextSizePx * folderLabelTextScale));
Jordan Silva999dd2a2023-11-17 19:31:43 +00001476 return;
1477 }
1478
1479 float invIconSizeDp = inv.iconSize[mTypeIndex];
1480 float invIconTextSizeDp = inv.iconTextSize[mTypeIndex];
1481 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1482 folderChildTextSizePx = pxFromSp(invIconTextSizeDp, mMetrics, scale);
1483 folderLabelTextSizePx = Math.max(minLabelTextSize,
1484 (int) (folderChildTextSizePx * folderLabelTextScale));
1485 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
1486
1487 if (mIsScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001488 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
Thales Lima7eee74b2023-03-16 16:00:55 -03001489 folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale);
1490 folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale);
1491 } else {
1492 folderCellWidthPx = roundPxValueFromFloat(folderCellWidthPx * scale);
1493 folderCellHeightPx = roundPxValueFromFloat(folderCellHeightPx * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001494 }
Charlie Anderson7bb10972023-11-22 13:35:30 -08001495 // Recalculating padding and cell height
1496 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
1497
1498 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1499 folderChildIconSizePx,
1500 folderChildDrawablePaddingPx,
1501 folderChildTextSizePx);
1502 cellContentDimensions.resizeToFitCellHeight(folderCellHeightPx, mIconSizeSteps);
1503 folderChildIconSizePx = cellContentDimensions.getIconSizePx();
1504 folderChildDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1505 folderChildTextSizePx = cellContentDimensions.getIconTextSizePx();
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001506
Thales Lima7eee74b2023-03-16 16:00:55 -03001507 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001508 folderCellLayoutBorderSpacePx = new Point(
1509 roundPxValueFromFloat(folderCellLayoutBorderSpacePx.x * scale),
1510 roundPxValueFromFloat(folderCellLayoutBorderSpacePx.y * scale)
1511 );
Thales Lima7eee74b2023-03-16 16:00:55 -03001512 folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001513 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx.x;
Jon Miranda823da222021-03-23 08:08:45 -04001514 } else {
1515 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1516 * scale);
1517 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1518 * scale);
1519
1520 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1521 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Lima7eee74b2023-03-16 16:00:55 -03001522 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001523 folderContentPaddingLeftRight =
1524 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1525 folderFooterHeightPx =
Thales Lima7eee74b2023-03-16 16:00:55 -03001526 roundPxValueFromFloat(
1527 res.getDimensionPixelSize(R.dimen.folder_footer_height_default)
1528 * scale);
1529
Jordan Silva12fae112023-06-26 12:51:01 +01001530 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
Jon Miranda823da222021-03-23 08:08:45 -04001531 }
Jon Mirandabf7d8122016-11-03 15:29:29 -07001532 }
1533
Winson1f064272016-07-18 17:18:02 -07001534 public void updateInsets(Rect insets) {
1535 mInsets.set(insets);
1536 }
1537
Sunny Goyalae6e3182019-04-30 12:04:37 -07001538 /**
1539 * The current device insets. This is generally same as the insets being dispatched to
1540 * {@link Insettable} elements, but can differ if the element is using a different profile.
1541 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001542 public Rect getInsets() {
1543 return mInsets;
1544 }
1545
Sunny Goyal756cd262015-08-20 12:33:21 -07001546 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001547 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001548 }
1549
Sunny Goyal19ff7282021-04-22 10:12:54 -07001550 public Point getCellSize(Point result) {
1551 if (result == null) {
1552 result = new Point();
1553 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001554
Pat Manning25d53342022-05-10 09:58:49 +00001555 int shortcutAndWidgetContainerWidth =
1556 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1557 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1558 inv.numColumns);
1559 int shortcutAndWidgetContainerHeight =
1560 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1561 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1562 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001563 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001564 }
1565
1566 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001567 * Returns the left and right space on the cell, which is the cell width - icon size
1568 */
1569 public int getCellHorizontalSpace() {
1570 return getCellSize().x - iconSizePx;
1571 }
1572
1573 /**
Pat Manning25d53342022-05-10 09:58:49 +00001574 * Gets the number of panels within the workspace.
1575 */
1576 public int getPanelCount() {
1577 return isTwoPanels ? 2 : 1;
1578 }
1579
1580 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001581 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1582 * bottom of the screen.
1583 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001584 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1585 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001586 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001587 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001588 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001589 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001590 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001591 }
1592
1593 /**
1594 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1595 */
Pat Manning25d53342022-05-10 09:58:49 +00001596 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001597 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001598 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001599 }
1600
1601 /**
1602 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1603 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001604 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001605 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001606 return heightPx - (isVerticalBarLayout()
1607 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001608 }
1609
Pat Manningea5c1d22022-04-14 10:58:16 +01001610 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001611 * Gets the scale of the workspace for the spring-loaded edit state.
1612 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001613 public float getWorkspaceSpringLoadScale(Context context) {
1614 float scale =
1615 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1616 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001617 scale = Math.min(scale, 1f);
1618
Pat Manninge63dd252022-08-02 16:15:29 +01001619 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001620 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001621 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001622 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001623 if (scaledWorkspaceWidth > maxAvailableWidth) {
1624 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1625 }
1626 return scale;
1627 }
1628
Pat Manning25d53342022-05-10 09:58:49 +00001629 /**
1630 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1631 *
1632 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1633 * layouts have two Cell Layouts per workspace.
1634 */
1635 public int getCellLayoutWidth() {
1636 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001637 }
1638
Pat Manning25d53342022-05-10 09:58:49 +00001639 /**
1640 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1641 *
1642 * <p>This is the height of a Workspace, less its vertical padding.
1643 */
1644 public int getCellLayoutHeight() {
1645 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001646 }
1647
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001648 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001649 return new Point(workspacePadding.left + workspacePadding.right,
1650 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001651 }
1652
1653 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001654 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1655 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001656 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001657 private void updateWorkspacePadding() {
1658 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001659 if (isVerticalBarLayout()) {
Jordan Silva3646a1b2023-08-02 13:52:52 +01001660 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001661 padding.top = mResponsiveWorkspaceHeightSpec.getStartPaddingPx();
Thales Lima8e11d532023-08-31 13:40:26 +00001662 padding.bottom = Math.max(0,
Jordan Silva8f7986a2023-11-08 12:11:25 +00001663 mResponsiveWorkspaceHeightSpec.getEndPaddingPx() - mInsets.bottom);
Jordan Silva3646a1b2023-08-02 13:52:52 +01001664 if (isSeascape()) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001665 padding.left =
1666 hotseatBarSizePx + mResponsiveWorkspaceWidthSpec.getEndPaddingPx();
1667 padding.right = mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
Jordan Silva3646a1b2023-08-02 13:52:52 +01001668 } else {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001669 padding.left = mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
1670 padding.right =
1671 hotseatBarSizePx + mResponsiveWorkspaceWidthSpec.getEndPaddingPx();
Jordan Silva3646a1b2023-08-02 13:52:52 +01001672 }
Winson1f064272016-07-18 17:18:02 -07001673 } else {
Jordan Silva3646a1b2023-08-02 13:52:52 +01001674 padding.top = 0;
1675 padding.bottom = edgeMarginPx;
1676 if (isSeascape()) {
1677 padding.left = hotseatBarSizePx;
Thales Lima8e11d532023-08-31 13:40:26 +00001678 padding.right = mHotseatBarEdgePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001679 } else {
Thales Lima8e11d532023-08-31 13:40:26 +00001680 padding.left = mHotseatBarEdgePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001681 padding.right = hotseatBarSizePx;
1682 }
Winson1f064272016-07-18 17:18:02 -07001683 }
Winson Chungb3800242013-10-24 11:01:54 -07001684 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001685 // Pad the bottom of the workspace with hotseat bar
1686 // and leave a bit of space in case a widget go all the way down
Thales Lima79456492023-05-23 11:32:22 +01001687 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding - mInsets.bottom;
1688 if (!mIsResponsiveGrid) {
1689 paddingBottom +=
1690 workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace;
1691 }
1692 int paddingTop = workspaceTopPadding + (mIsScalableGrid ? 0 : edgeMarginPx);
Pat Manning08610ca2022-04-05 21:03:16 +01001693 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001694
Pat Manning08610ca2022-04-05 21:03:16 +01001695 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001696 }
Pat Manning08610ca2022-04-05 21:03:16 +01001697 insetPadding(workspacePadding, cellLayoutPaddingPx);
1698 }
1699
1700 private void insetPadding(Rect paddings, Rect insets) {
1701 insets.left = Math.min(insets.left, paddings.left);
1702 paddings.left -= insets.left;
1703
1704 insets.top = Math.min(insets.top, paddings.top);
1705 paddings.top -= insets.top;
1706
1707 insets.right = Math.min(insets.right, paddings.right);
1708 paddings.right -= insets.right;
1709
1710 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1711 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001712 }
1713
Liran Binyamina833af32023-08-02 16:30:27 -04001714
1715 /**
1716 * Returns the new border space that should be used between hotseat icons after adjusting it to
1717 * the bubble bar.
1718 *
1719 * <p>If there's no adjustment needed, this method returns {@code 0}.
1720 */
1721 public float getHotseatAdjustedBorderSpaceForBubbleBar(Context context) {
1722 // only need to adjust when QSB is on top of the hotseat.
1723 if (isQsbInline) {
1724 return 0;
1725 }
1726
1727 // no need to adjust if there's enough space for the bubble bar to the right of the hotseat.
1728 if (getHotseatLayoutPadding(context).right > mBubbleBarSpaceThresholdPx) {
1729 return 0;
1730 }
1731
1732 // The adjustment is shrinking the hotseat's width by 1 icon on either side.
1733 int iconsWidth =
1734 iconSizePx * numShownHotseatIcons + hotseatBorderSpace * (numShownHotseatIcons - 1);
1735 int newWidth = iconsWidth - 2 * iconSizePx;
1736 // Evenly space the icons within the boundaries of the new width.
1737 return (float) (newWidth - iconSizePx * numShownHotseatIcons) / (numShownHotseatIcons - 1);
1738 }
1739
Sunny Goyal57b22792021-05-25 14:35:01 -07001740 /**
1741 * Returns the padding for hotseat view
1742 */
1743 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001744 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001745 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001746 // The hotseat icons will be placed in the middle of the hotseat cells.
1747 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1748 // in vertical bar layout.
fbaronfc6bbcf2024-01-29 10:35:17 -08001749 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top), 0);
1750 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom), 0);
Sihua Ma38bb3b02022-03-21 22:20:14 -07001751
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001752 if (isSeascape()) {
Thales Lima8e11d532023-08-31 13:40:26 +00001753 hotseatBarPadding.set(mInsets.left + mHotseatBarEdgePaddingPx, paddingTop,
1754 mHotseatBarWorkspaceSpacePx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001755 } else {
Thales Lima8e11d532023-08-31 13:40:26 +00001756 hotseatBarPadding.set(mHotseatBarWorkspaceSpacePx, paddingTop,
1757 mInsets.right + mHotseatBarEdgePaddingPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001758 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001759 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001760 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001761 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1762 int hotseatBarTopPadding =
1763 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001764
Thales Lima6a590062022-11-22 15:52:49 +00001765 int hotseatWidth = getHotseatRequiredWidth();
Helen Cheuke76291f2023-02-14 17:11:05 +00001766 int startSpacing;
1767 int endSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001768 // Hotseat aligns to the left with nav buttons
1769 if (hotseatBarEndOffset > 0) {
Jon Mirandae17a9492023-03-08 16:42:20 -08001770 startSpacing = inlineNavButtonsEndSpacingPx;
Helen Cheuke76291f2023-02-14 17:11:05 +00001771 endSpacing = availableWidthPx - hotseatWidth - startSpacing + hotseatBorderSpace;
1772 } else {
1773 startSpacing = (availableWidthPx - hotseatWidth) / 2;
1774 endSpacing = startSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001775 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001776 startSpacing += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001777
Helen Cheuke76291f2023-02-14 17:11:05 +00001778 hotseatBarPadding.top = hotseatBarTopPadding;
1779 hotseatBarPadding.bottom = hotseatBarBottomPadding;
Alex Chau51da2192022-05-20 13:32:10 +01001780 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001781 if (isRtl) {
Helen Cheuke76291f2023-02-14 17:11:05 +00001782 hotseatBarPadding.left = endSpacing;
1783 hotseatBarPadding.right = startSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001784 } else {
Helen Cheuke76291f2023-02-14 17:11:05 +00001785 hotseatBarPadding.left = startSpacing;
1786 hotseatBarPadding.right = endSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001787 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001788
Thales Lima79456492023-05-23 11:32:22 +01001789 } else if (mIsScalableGrid) {
fbarone69b6f42023-12-18 13:20:34 -08001790 int iconExtraSpacePx = iconSizePx - getIconVisibleSizePx(iconSizePx);
1791 int sideSpacing = (availableWidthPx - (hotseatQsbWidth + iconExtraSpacePx)) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001792 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001793 0,
Thales Lima425f6822022-05-10 13:44:58 -03001794 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001795 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001796 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001797 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1798 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1799 // for this, we pad the left and right of the hotseat with half of the difference of a
1800 // workspace cell vs a hotseat cell.
1801 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001802 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001803 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001804 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001805 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1806 + mInsets.left,
1807 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001808 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001809 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001810 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001811 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001812 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001813 }
1814
Andy Wickhambd9a1802023-06-08 16:33:15 -07001815 /** The margin between the edge of all apps and the edge of the first icon. */
Thales Limab433c9c2023-10-30 12:24:05 +00001816 public int getAllAppsIconStartMargin(Context context) {
Andy Wickhambd9a1802023-06-08 16:33:15 -07001817 int allAppsSpacing;
1818 if (isVerticalBarLayout()) {
1819 // On phones, the landscape layout uses a different setup.
1820 allAppsSpacing = workspacePadding.left + workspacePadding.right;
1821 } else {
Thales Limab433c9c2023-10-30 12:24:05 +00001822 allAppsSpacing =
1823 allAppsPadding.left + allAppsPadding.right + allAppsLeftRightMargin * 2;
Andy Wickhambd9a1802023-06-08 16:33:15 -07001824 }
1825
1826 int cellWidth = DeviceProfile.calculateCellWidth(
1827 availableWidthPx - allAppsSpacing,
1828 0 /* borderSpace */,
1829 numShownAllAppsColumns);
fbarone69b6f42023-12-18 13:20:34 -08001830 int iconAlignmentMargin = (cellWidth - getIconVisibleSizePx(allAppsIconSizePx)) / 2;
Thales Limab433c9c2023-10-30 12:24:05 +00001831
1832 return (Utilities.isRtl(context.getResources()) ? allAppsPadding.right
1833 : allAppsPadding.left) + iconAlignmentMargin;
Andy Wickhambd9a1802023-06-08 16:33:15 -07001834 }
1835
fbarone69b6f42023-12-18 13:20:34 -08001836 /**
1837 * TODO(b/235886078): workaround needed because of this bug
1838 * Icons are 10% larger on XML than their visual size, so remove that extra space to get
1839 * some dimensions correct.
1840 *
1841 * When this bug is resolved this method will no longer be needed and we would be able to
1842 * replace all instances where this method is called with iconSizePx.
1843 */
1844 private int getIconVisibleSizePx(int iconSizePx) {
1845 return Math.round(ICON_VISIBLE_AREA_FACTOR * iconSizePx);
1846 }
1847
Thales Lima9938c2f2022-07-25 14:38:16 +01001848 private int getAdditionalQsbSpace() {
1849 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1850 }
1851
1852 /**
1853 * Calculate how much space the hotseat needs to be shown completely
1854 */
1855 private int getHotseatRequiredWidth() {
1856 int additionalQsbSpace = getAdditionalQsbSpace();
1857 return iconSizePx * numShownHotseatIcons
Thales Lima6a590062022-11-22 15:52:49 +00001858 + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1))
Thales Lima9938c2f2022-07-25 14:38:16 +01001859 + additionalQsbSpace;
1860 }
1861
Winsonfadbe8f2016-07-22 16:35:37 -07001862 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001863 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1864 */
1865 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001866 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001867 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1868 } else if (isTaskbarPresent) { // QSB on top
1869 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001870 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001871 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001872 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001873 }
1874
Thales Limab8c05952022-05-23 16:58:38 +01001875 /**
1876 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1877 */
1878 private int getHotseatBarBottomPadding() {
1879 if (isTaskbarPresent) { // QSB on top or inline
1880 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001881 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001882 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001883 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001884 }
1885
1886 /**
Alex Chau51da2192022-05-20 13:32:10 +01001887 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1888 */
1889 public int getTaskbarOffsetY() {
Jon Miranda9c478b62023-03-23 21:38:49 -07001890 int taskbarIconBottomSpace = (taskbarHeight - iconSizePx) / 2;
Alex Chau51da2192022-05-20 13:32:10 +01001891 int launcherIconBottomSpace =
1892 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001893 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001894 }
1895
Uwais Ashrafaa7fa882023-10-10 21:36:06 +00001896 /** Returns the number of pixels required below OverviewActions. */
Alex Chaua2fc7642022-04-21 14:20:23 +01001897 public int getOverviewActionsClaimedSpaceBelow() {
Uwais Ashrafaa7fa882023-10-10 21:36:06 +00001898 return isTaskbarPresent ? mTransientTaskbarClaimedSpace : mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001899 }
1900
1901 /** Gets the space that the overview actions will take, including bottom margin. */
1902 public int getOverviewActionsClaimedSpace() {
Alex Chau4989f4f2023-10-11 14:08:22 +00001903 int overviewActionsSpace = isTablet && Flags.enableGridOnlyOverview()
Pat Manning7b8f7662023-01-18 14:48:30 +00001904 ? 0
1905 : (overviewActionsTopMarginPx + overviewActionsHeight);
1906 return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
Alex Chaua2fc7642022-04-21 14:20:23 +01001907 }
1908
1909 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001910 * Takes the View and return the scales of width and height depending on the DeviceProfile
1911 * specifications
1912 *
1913 * @param itemInfo The tag of the widget view
1914 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1915 * height
1916 */
1917 @NonNull
1918 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1919 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1920 }
1921
1922 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001923 * @return the bounds for which the open folders should be contained within
1924 */
1925 public Rect getAbsoluteOpenFolderBounds() {
1926 if (isVerticalBarLayout()) {
1927 // Folders should only appear right of the drop target bar and left of the hotseat
1928 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1929 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001930 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001931 mInsets.top + availableHeightPx);
1932 } else {
1933 // Folders should only appear below the drop target bar and above the hotseat
Jon Miranda9c478b62023-03-23 21:38:49 -07001934 int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001935 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001936 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001937 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001938 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001939 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001940 }
1941 }
1942
Jon Miranda228877d2021-02-09 11:05:00 -05001943 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1944 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001945 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001946
Jon Miranda228877d2021-02-09 11:05:00 -05001947 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1948 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001949 }
1950
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001951 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001952 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1953 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1954 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001955 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001956 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001957 return isLandscape && transposeLayoutWithOrientation;
1958 }
1959
Sunny Goyal59d086c2018-05-07 17:31:40 -07001960 /**
1961 * Updates orientation information and returns true if it has changed from the previous value.
1962 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001963 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001964 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001965 boolean isSeascape = DisplayController.INSTANCE.get(context)
1966 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001967 if (mIsSeascape != isSeascape) {
1968 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001969 // Hotseat changing sides requires updating workspace left/right paddings
1970 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001971 return true;
1972 }
1973 }
1974 return false;
1975 }
1976
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001977 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001978 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001979 }
1980
Sunny Goyal07b69292018-01-08 14:19:34 -08001981 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001982 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001983 }
1984
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001985 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001986 switch (containerType) {
1987 case CellLayout.WORKSPACE:
1988 return cellHeightPx;
1989 case CellLayout.FOLDER:
1990 return folderCellHeightPx;
1991 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001992 // The hotseat is the only container where the cell height is going to be
1993 // different from the content within that cell.
1994 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001995 default:
1996 // ??
1997 return 0;
1998 }
1999 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07002000
Jon Miranda58561d42021-03-17 10:51:54 -04002001 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07002002 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04002003 }
2004
Alex Chaue818bcb2022-09-02 17:27:11 +01002005 private String dpPointFToString(String name, PointF value) {
2006 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
2007 }
2008
Pat Manning5f74bfd2022-07-20 12:08:54 +01002009 /** Dumps various DeviceProfile variables to the specified writer. */
2010 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04002011 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07002012 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04002013
2014 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04002015 writer.println(prefix + "\tisPhone:" + isPhone);
2016 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
2017 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00002018 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04002019
2020 writer.println(prefix + "\tisLandscape:" + isLandscape);
2021 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07002022 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Winson Chung104a4c82023-11-08 18:56:15 +00002023 writer.println(prefix + "\tisLeftRightSplit:" + isLeftRightSplit);
Jon Miranda58561d42021-03-17 10:51:54 -04002024
2025 writer.println(prefix + pxToDpStr("windowX", windowX));
2026 writer.println(prefix + pxToDpStr("windowY", windowY));
2027 writer.println(prefix + pxToDpStr("widthPx", widthPx));
2028 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002029 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
2030 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01002031 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
2032 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
2033 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
2034 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04002035
2036 writer.println(prefix + "\taspectRatio:" + aspectRatio);
2037
Thales Limac98b7812023-04-14 15:04:23 +01002038 writer.println(prefix + "\tisResponsiveGrid:" + mIsResponsiveGrid);
Thales Lima79456492023-05-23 11:32:22 +01002039 writer.println(prefix + "\tisScalableGrid:" + mIsScalableGrid);
Jon Miranda58561d42021-03-17 10:51:54 -04002040
Thales Lima83bedbf2021-10-05 17:47:39 +01002041 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00002042 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
2043 writer.println(prefix + "\tinv.numSearchContainerColumns: "
2044 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04002045
Alex Chaue818bcb2022-09-02 17:27:11 +01002046 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07002047
Jon Miranda58561d42021-03-17 10:51:54 -04002048 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
2049 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
2050
2051 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
2052 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
2053
Thales Lima83bedbf2021-10-05 17:47:39 +01002054 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
2055 cellLayoutBorderSpacePx.x));
2056 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
2057 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002058 writer.println(
2059 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
2060 writer.println(
2061 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
2062 writer.println(
2063 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01002064 writer.println(
2065 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01002066
Jon Miranda58561d42021-03-17 10:51:54 -04002067 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
2068 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
2069 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
2070
Thales Lima1faa4ed2023-12-01 16:48:19 +00002071 writer.println(prefix + "\tnumFolderRows: " + numFolderRows);
2072 writer.println(prefix + "\tnumFolderColumns: " + numFolderColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04002073 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
2074 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
2075 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
2076 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
2077 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
2078 folderChildDrawablePaddingPx));
Jordan Silva637f4eb2023-06-13 11:21:53 +01002079 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.x",
2080 folderCellLayoutBorderSpacePx.x));
2081 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.y",
2082 folderCellLayoutBorderSpacePx.y));
Thales Limaa08a4432022-08-09 09:55:17 +01002083 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
2084 folderContentPaddingLeftRight));
2085 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03002086 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002087
Alex Chaue0227552022-04-06 19:44:43 +01002088 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01002089 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
2090 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
2091 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
2092 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01002093
2094 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
Alex Chau3d2c0622022-09-01 21:28:14 +01002095 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
2096 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04002097 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
2098 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
2099 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
2100 allAppsIconDrawablePaddingPx));
2101 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00002102 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01002103 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
2104 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07002105 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Thales Limab433c9c2023-10-30 12:24:05 +00002106 writer.println(prefix + pxToDpStr("allAppsPadding.top", allAppsPadding.top));
2107 writer.println(prefix + pxToDpStr("allAppsPadding.left", allAppsPadding.left));
2108 writer.println(prefix + pxToDpStr("allAppsPadding.right", allAppsPadding.right));
Alex Chau27b39b92022-01-14 18:02:18 +00002109 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04002110
2111 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03002112 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04002113 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00002114 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Thales Lima8e11d532023-08-31 13:40:26 +00002115 writer.println(prefix + pxToDpStr("mHotseatBarEdgePaddingPx",
2116 mHotseatBarEdgePaddingPx));
2117 writer.println(prefix + pxToDpStr("mHotseatBarWorkspaceSpacePx",
2118 mHotseatBarWorkspaceSpacePx));
Pat Manning26f70f72022-07-07 13:50:39 +01002119 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01002120 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
2121 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01002122 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
2123 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002124 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
2125 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
2126 hotseatLayoutPadding.top));
2127 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
2128 hotseatLayoutPadding.bottom));
2129 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
2130 hotseatLayoutPadding.left));
2131 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
2132 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07002133 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00002134 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00002135 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01002136 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04002137
2138 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10002139 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda9c478b62023-03-23 21:38:49 -07002140 writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight));
2141 writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight));
2142 writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin));
2143 writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize));
Jon Miranda58561d42021-03-17 10:51:54 -04002144
Thales Lima83bedbf2021-10-05 17:47:39 +01002145 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
2146 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002147 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
2148 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
2149 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00002150 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04002151
Jon Mirandaab3c6812021-06-28 15:42:28 -07002152 writer.println(prefix + pxToDpStr("iconScale", iconScale));
2153 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04002154 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00002155 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04002156
Thales Lima171ee662022-11-22 15:52:49 +00002157 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04002158 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
2159 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00002160
2161 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00002162 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
2163 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
2164 overviewTaskIconDrawableSizePx));
2165 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
2166 overviewTaskIconDrawableSizeGridPx));
2167 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
2168 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01002169 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
2170 overviewActionsTopMarginPx));
2171 writer.println(prefix + pxToDpStr("overviewActionsHeight",
2172 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00002173 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
2174 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00002175 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
2176 overviewActionsButtonSpacing));
2177 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
2178 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
2179 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01002180
Alex Chau62572c02022-07-25 18:36:37 +00002181 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01002182 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00002183 writer.println(
2184 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01002185
Pat Manning5f74bfd2022-07-20 12:08:54 +01002186 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
2187 getCellLayoutSpringLoadShrunkTop()));
2188 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
2189 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01002190 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
2191 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002192 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
2193 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01002194 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
2195 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Thales Lima79456492023-05-23 11:32:22 +01002196 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00002197 writer.println(prefix + "\tmResponsiveWorkspaceHeightSpec:"
2198 + mResponsiveWorkspaceHeightSpec.toString());
2199 writer.println(prefix + "\tmResponsiveWorkspaceWidthSpec:"
2200 + mResponsiveWorkspaceWidthSpec.toString());
2201 writer.println(prefix + "\tmResponsiveAllAppsHeightSpec:"
2202 + mResponsiveAllAppsHeightSpec.toString());
2203 writer.println(prefix + "\tmResponsiveAllAppsWidthSpec:"
2204 + mResponsiveAllAppsWidthSpec.toString());
Jordan Silva637f4eb2023-06-13 11:21:53 +01002205 writer.println(prefix + "\tmResponsiveFolderHeightSpec:" + mResponsiveFolderHeightSpec);
2206 writer.println(prefix + "\tmResponsiveFolderWidthSpec:" + mResponsiveFolderWidthSpec);
Thales Limaf8bfb032023-07-24 15:08:05 +01002207 writer.println(prefix + "\tmResponsiveHotseatSpec:" + mResponsiveHotseatSpec);
Jordan Silva999dd2a2023-11-17 19:31:43 +00002208 writer.println(prefix + "\tmResponsiveWorkspaceCellSpec:"
2209 + mResponsiveWorkspaceCellSpec);
2210 writer.println(prefix + "\tmResponsiveAllAppsCellSpec:" + mResponsiveAllAppsCellSpec);
Thales Lima79456492023-05-23 11:32:22 +01002211 }
Jon Miranda58561d42021-03-17 10:51:54 -04002212 }
2213
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00002214 /** Returns a reduced representation of this DeviceProfile. */
2215 public String toSmallString() {
2216 return "isTablet:" + isTablet + ", "
2217 + "isMultiDisplay:" + isMultiDisplay + ", "
2218 + "widthPx:" + widthPx + ", "
2219 + "heightPx:" + heightPx + ", "
2220 + "insets:" + mInsets + ", "
2221 + "rotationHint:" + rotationHint;
2222 }
2223
Alex Chaua6907dc2022-03-18 15:24:07 +00002224 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07002225 Configuration config = new Configuration(c.getResources().getConfiguration());
2226 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03002227 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00002228 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07002229 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07002230 }
Sunny Goyalfde55052018-02-01 14:46:13 -08002231
2232 /**
2233 * Callback when a component changes the DeviceProfile associated with it, as a result of
2234 * configuration change
2235 */
2236 public interface OnDeviceProfileChangeListener {
2237
2238 /**
2239 * Called when the device profile is reassigned. Note that for layout and measurements, it
2240 * is sufficient to listen for inset changes. Use this callback when you need to perform
2241 * a one time operation.
2242 */
2243 void onDeviceProfileChanged(DeviceProfile dp);
2244 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002245
Sihua Mae04aa202022-07-18 12:43:56 -07002246 /**
2247 * Handler that deals with ItemInfo of the views for the DeviceProfile
2248 */
2249 @FunctionalInterface
2250 public interface ViewScaleProvider {
2251 /**
2252 * Get the scales from the view
2253 *
2254 * @param itemInfo The tag of the widget view
2255 * @return PointF instance containing the scale information, or null if using the default
2256 * app widget scale of this device profile.
2257 */
2258 @NonNull
2259 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
2260 }
2261
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002262 public static class Builder {
2263 private Context mContext;
2264 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07002265 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002266
Sunny Goyal19ff7282021-04-22 10:12:54 -07002267 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00002268 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002269
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002270 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07002271 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00002272 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07002273 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002274
Sunny Goyal65190ae2022-08-02 14:16:26 -07002275 private SparseArray<DotRenderer> mDotRendererCache;
2276
Jon Miranda2b25ded2023-02-02 14:48:45 -08002277 private Consumer<DeviceProfile> mOverrideProvider;
2278
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002279 private boolean mIsTransientTaskbar;
2280
Sunny Goyalfd58da62020-08-11 12:06:49 -07002281 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002282 mContext = context;
2283 mInv = inv;
2284 mInfo = info;
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002285 mIsTransientTaskbar = info.isTransientTaskbar();
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002286 }
2287
2288 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
2289 mIsMultiWindowMode = isMultiWindowMode;
2290 return this;
2291 }
2292
Alex Chauab800f72022-12-13 17:46:06 +00002293 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
2294 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07002295 return this;
2296 }
2297
Sunny Goyal65190ae2022-08-02 14:16:26 -07002298 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
2299 mDotRendererCache = dotRendererCache;
2300 return this;
2301 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07002302
2303 public Builder setWindowBounds(WindowBounds bounds) {
2304 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07002305 return this;
2306 }
2307
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002308 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
2309 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
2310 return this;
2311 }
2312
Alex Chau6ed408f2022-03-04 12:58:05 +00002313 public Builder setGestureMode(boolean isGestureMode) {
2314 mIsGestureMode = isGestureMode;
2315 return this;
2316 }
2317
Jon Miranda2b25ded2023-02-02 14:48:45 -08002318 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
2319 mOverrideProvider = overrideProvider;
2320 return this;
2321 }
2322
Sihua Mae04aa202022-07-18 12:43:56 -07002323 /**
2324 * Set the viewScaleProvider for the builder
2325 *
2326 * @param viewScaleProvider The viewScaleProvider to be set for the
Thales Limae9273ea2023-01-26 12:33:52 +00002327 * DeviceProfile
Sihua Mae04aa202022-07-18 12:43:56 -07002328 * @return This builder
2329 */
2330 @NonNull
2331 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
2332 mViewScaleProvider = viewScaleProvider;
2333 return this;
2334 }
2335
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002336 /**
2337 * Set the isTransientTaskbar for the builder
2338 * @return This Builder
2339 */
2340 public Builder setIsTransientTaskbar(boolean isTransientTaskbar) {
2341 mIsTransientTaskbar = isTransientTaskbar;
2342 return this;
2343 }
2344
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002345 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07002346 if (mWindowBounds == null) {
2347 throw new IllegalArgumentException("Window bounds not set");
2348 }
2349 if (mTransposeLayoutWithOrientation == null) {
2350 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
2351 }
Alex Chau6ed408f2022-03-04 12:58:05 +00002352 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01002353 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00002354 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002355 if (mDotRendererCache == null) {
2356 mDotRendererCache = new SparseArray<>();
2357 }
Sihua Mae04aa202022-07-18 12:43:56 -07002358 if (mViewScaleProvider == null) {
2359 mViewScaleProvider = DEFAULT_PROVIDER;
2360 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08002361 if (mOverrideProvider == null) {
2362 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
2363 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002364 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00002365 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002366 mIsGestureMode, mViewScaleProvider, mOverrideProvider, mIsTransientTaskbar);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002367 }
2368 }
Winson Chungb3800242013-10-24 11:01:54 -07002369}