blob: 834ba043c510cbd4066b482022d9f599837839bb [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
Sihua Mae04aa202022-07-18 12:43:56 -070084 public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f);
85 public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE;
Jordan Silvaf2402e22023-10-26 19:53:16 +010086 public static final Consumer<DeviceProfile> DEFAULT_DIMENSION_PROVIDER = dp -> {
87 };
Sihua Mae04aa202022-07-18 12:43:56 -070088
Adam Cohen2e6da152015-05-06 11:42:25 -070089 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070090 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070091 private final DisplayMetrics mMetrics;
Thales Lima2759aa32023-06-05 16:25:45 +010092 private final IconSizeSteps mIconSizeSteps;
Winson Chungbe876472014-05-14 14:15:20 -070093
Sunny Goyalc6205602015-05-21 20:46:33 -070094 // Device properties
95 public final boolean isTablet;
Sunny Goyalc6205602015-05-21 20:46:33 -070096 public final boolean isPhone;
97 public final boolean transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +000098 public final boolean isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -070099 public final boolean isTwoPanels;
Thales Limaa1012902022-01-13 17:58:42 +0000100 public final boolean isQsbInline;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700101
Sunny Goyalc6205602015-05-21 20:46:33 -0700102 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -0700103 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -0800104 public final boolean isMultiWindowMode;
Alex Chau6ed408f2022-03-04 12:58:05 +0000105 public final boolean isGestureMode;
Sunny Goyald70e75a2018-02-22 10:07:32 -0800106
Winson Chung104a4c82023-11-08 18:56:15 +0000107 public final boolean isLeftRightSplit;
108
Sunny Goyal0addbf02020-04-28 14:17:35 -0700109 public final int windowX;
110 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -0700111 public final int widthPx;
112 public final int heightPx;
113 public final int availableWidthPx;
114 public final int availableHeightPx;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800115 public final int rotationHint;
Jon Mirandabba64512019-03-27 10:54:17 -0700116
117 public final float aspectRatio;
118
Thales Lima79456492023-05-23 11:32:22 +0100119 private final boolean mIsScalableGrid;
Thales Lima83bedbf2021-10-05 17:47:39 +0100120 private final int mTypeIndex;
Jon Mirandae126d722021-02-25 10:45:20 -0500121
Thales Limac98b7812023-04-14 15:04:23 +0100122 // Responsive grid
123 private final boolean mIsResponsiveGrid;
Jordan Silva8f7986a2023-11-08 12:11:25 +0000124 private CalculatedResponsiveSpec mResponsiveWorkspaceWidthSpec;
125 private CalculatedResponsiveSpec mResponsiveWorkspaceHeightSpec;
126 private CalculatedResponsiveSpec mResponsiveAllAppsWidthSpec;
127 private CalculatedResponsiveSpec mResponsiveAllAppsHeightSpec;
Jordan Silvaf2402e22023-10-26 19:53:16 +0100128 private CalculatedResponsiveSpec mResponsiveFolderWidthSpec;
129 private CalculatedResponsiveSpec mResponsiveFolderHeightSpec;
Thales Limaf8bfb032023-07-24 15:08:05 +0100130 private CalculatedHotseatSpec mResponsiveHotseatSpec;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000131 private CalculatedCellSpec mResponsiveWorkspaceCellSpec;
132 private CalculatedCellSpec mResponsiveAllAppsCellSpec;
Thales Limac98b7812023-04-14 15:04:23 +0100133
Tony Wickhamd6b40372015-09-23 18:37:57 -0700134 /**
135 * The maximum amount of left/right workspace padding as a percentage of the screen width.
136 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
137 * 7% of the screen width can be used as right padding.
138 */
139 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -0700140
Jon Miranda3f9bab22017-07-28 14:50:17 -0700141 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700142 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda80dda302021-07-28 14:14:59 -0700143 private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252;
144 private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700145
Sunny Goyalc6205602015-05-21 20:46:33 -0700146 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +0100147 public final int desiredWorkspaceHorizontalMarginOriginalPx;
148 public int desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100149 public int gridVisualizationPaddingX;
150 public int gridVisualizationPaddingY;
Thales Lima78d00ad2021-09-30 11:29:06 +0100151 public Point cellLayoutBorderSpaceOriginalPx;
152 public Point cellLayoutBorderSpacePx;
Pat Manning08610ca2022-04-05 21:03:16 +0100153 public Rect cellLayoutPaddingPx = new Rect();
154
Sunny Goyalc6205602015-05-21 20:46:33 -0700155 public final int edgeMarginPx;
Alex Chau0c4e11b2022-07-08 18:41:36 +0100156 public final float workspaceContentScale;
Alex Chau906d8822022-05-23 10:42:25 +0100157 public final int workspaceSpringLoadedMinNextPageVisiblePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700158
Jon Miranda58561d42021-03-17 10:51:54 -0400159 private final int extraSpace;
Thales Lima171ee662022-11-22 15:52:49 +0000160 private int maxEmptySpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500161 public int workspaceTopPadding;
162 public int workspaceBottomPadding;
163
Tony Wickham5edf9e22020-03-27 20:06:52 -0700164 // Workspace page indicator
165 public final int workspacePageIndicatorHeight;
166 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700167
Sunny Goyalc6205602015-05-21 20:46:33 -0700168 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400169 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700170 public int iconSizePx;
171 public int iconTextSizePx;
172 public int iconDrawablePaddingPx;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000173 private int mIconDrawablePaddingOriginalPx;
Thales Lima79456492023-05-23 11:32:22 +0100174 public boolean iconCenterVertically;
Winson Chungb3800242013-10-24 11:01:54 -0700175
Jon Mirandaab3c6812021-06-28 15:42:28 -0700176 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800177 public int cellWidthPx;
178 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700179 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800180
Thales Lima79456492023-05-23 11:32:22 +0100181 public int cellYPaddingPx = -1;
Jon Mirandae126d722021-02-25 10:45:20 -0500182
Sunny Goyalc6205602015-05-21 20:46:33 -0700183 // Folder
Thales Lima1faa4ed2023-12-01 16:48:19 +0000184 public final int numFolderRows;
185 public final int numFolderColumns;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000186 public final float folderLabelTextScale;
Jon Mirandae126d722021-02-25 10:45:20 -0500187 public int folderLabelTextSizePx;
Thales Limab35faed2022-09-05 16:30:01 -0300188 public int folderFooterHeightPx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700189 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700190 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700191
Jon Mirandae126d722021-02-25 10:45:20 -0500192 // Folder content
Jordan Silva637f4eb2023-06-13 11:21:53 +0100193 public Point folderCellLayoutBorderSpacePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500194 public int folderContentPaddingLeftRight;
195 public int folderContentPaddingTop;
196
Jon Mirandabf7d8122016-11-03 15:29:29 -0700197 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700198 public int folderCellWidthPx;
199 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700200
201 // Folder child
202 public int folderChildIconSizePx;
203 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700204 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700205
Sunny Goyalc6205602015-05-21 20:46:33 -0700206 // Hotseat
Thales Lima9938c2f2022-07-25 14:38:16 +0100207 public int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700208 public int hotseatCellHeightPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100209 public final boolean areNavButtonsInline;
Jon Miranda18751b62017-07-31 17:25:27 -0700210 // In portrait: size = height, in landscape: size = width
211 public int hotseatBarSizePx;
Thales Limab8c05952022-05-23 16:58:38 +0100212 public int hotseatBarBottomSpacePx;
Pat Manning26f70f72022-07-07 13:50:39 +0100213 public int hotseatBarEndOffset;
Thales Limab8c05952022-05-23 16:58:38 +0100214 public int hotseatQsbSpace;
Pat Manningde25c0d2022-04-05 19:11:26 +0100215 public int springLoadedHotseatBarTopMarginPx;
Thales Lima8e11d532023-08-31 13:40:26 +0000216 // These 2 values are only used for isVerticalBar
217 // Padding between edge of screen and hotseat
218 public final int mHotseatBarEdgePaddingPx;
219 // Space between hotseat and workspace (not used in responsive)
220 public final int mHotseatBarWorkspaceSpacePx;
Alex Chau206ede92022-08-01 17:46:12 +0100221 public int hotseatQsbWidth; // only used when isQsbInline
Sunny Goyal57b22792021-05-25 14:35:01 -0700222 public final int hotseatQsbHeight;
Thales Limab8c05952022-05-23 16:58:38 +0100223 public final int hotseatQsbVisualHeight;
224 private final int hotseatQsbShadowHeight;
Thales Limadd027342022-01-07 12:54:37 +0000225 public int hotseatBorderSpace;
Thales Limaffc68b02023-01-09 16:20:23 +0000226 private final int mMinHotseatIconSpacePx;
227 private final int mMinHotseatQsbWidthPx;
228 private final int mMaxHotseatIconSpacePx;
Jon Mirandae17a9492023-03-08 16:42:20 -0800229 public final int inlineNavButtonsEndSpacingPx;
Liran Binyamina833af32023-08-02 16:30:27 -0400230 // Space required for the bubble bar between the hotseat and the edge of the screen. If there's
231 // not enough space, the hotseat will adjust itself for the bubble bar.
232 private final int mBubbleBarSpaceThresholdPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700233
Alex Chau3d2c0622022-09-01 21:28:14 +0100234 // Bottom sheets
235 public int bottomSheetTopPadding;
236 public int bottomSheetOpenDuration;
237 public int bottomSheetCloseDuration;
238 public float bottomSheetWorkspaceScale;
239 public float bottomSheetDepth;
240
Sunny Goyalc6205602015-05-21 20:46:33 -0700241 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000242 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000243 public int allAppsShiftRange;
Thales Limab433c9c2023-10-30 12:24:05 +0000244 public Rect allAppsPadding = new Rect();
Alex Chau3d2c0622022-09-01 21:28:14 +0100245 public int allAppsOpenDuration;
246 public int allAppsCloseDuration;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700247 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700248 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700249 public int allAppsIconSizePx;
250 public int allAppsIconDrawablePaddingPx;
Alex Chau27b39b92022-01-14 18:02:18 +0000251 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700252 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700253 public float allAppsIconTextSizePx;
254
Zak Cohen334efeb2021-03-19 16:42:07 -0700255 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700256 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000257 public int overviewTaskIconSizePx;
Alex Chauac9df382021-08-02 19:08:41 +0100258 public int overviewTaskIconDrawableSizePx;
259 public int overviewTaskIconDrawableSizeGridPx;
Pat Manning1695cc72023-07-05 11:45:13 +0100260 public int overviewTaskIconAppChipMenuDrawableSizePx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000261 public int overviewTaskThumbnailTopMarginPx;
Alex Chau19c6eca2022-03-10 20:12:56 +0000262 public final int overviewActionsHeight;
Alex Chaua2fc7642022-04-21 14:20:23 +0100263 public final int overviewActionsTopMarginPx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000264 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100265 public int overviewPageSpacing;
266 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000267 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700268
Jeremy Sim0ac47082022-10-10 13:59:40 -0700269 // Split staging
270 public int splitPlaceholderInset;
271
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800272 // Widgets
Sihua Mae04aa202022-07-18 12:43:56 -0700273 private final ViewScaleProvider mViewScaleProvider;
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800274
Sunny Goyal47328fd2016-05-25 18:56:41 -0700275 // Drop Target
276 public int dropTargetBarSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100277 public int dropTargetBarTopMarginPx;
278 public int dropTargetBarBottomMarginPx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100279 public int dropTargetDragPaddingPx;
280 public int dropTargetTextSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100281 public int dropTargetHorizontalPaddingPx;
282 public int dropTargetVerticalPaddingPx;
283 public int dropTargetGapPx;
Alex Chau5b019302022-05-23 10:42:25 +0100284 public int dropTargetButtonWorkspaceEdgeGapPx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700285
Winson1f064272016-07-18 17:18:02 -0700286 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800287 private final Rect mInsets = new Rect();
288 public final Rect workspacePadding = new Rect();
Sunny Goyal6c304b12023-04-10 12:03:04 -0700289 // Additional padding added to the widget inside its cellSpace. It is applied outside
290 // the widgetView, such that the actual view size is same as the widget size.
291 public final Rect widgetPadding = new Rect();
292
Jon Miranda0bd63d12019-03-06 17:29:29 -0800293 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700294 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700295
Tony Wickhamf34bee82018-12-03 18:11:39 -0800296 // Notification dots
Sunny Goyal65190ae2022-08-02 14:16:26 -0700297 public final DotRenderer mDotRendererWorkSpace;
298 public final DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800299
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100300 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800301 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000302 // Whether Taskbar will inset the bottom of apps by taskbarSize.
303 public boolean isTaskbarPresentInApps;
Jon Miranda9c478b62023-03-23 21:38:49 -0700304 public final int taskbarHeight;
305 public final int stashedTaskbarHeight;
306 public final int taskbarBottomMargin;
307 public final int taskbarIconSize;
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000308 private final int mTransientTaskbarClaimedSpace;
Jon Miranda04f05102023-04-04 12:16:31 -0700309 // If true, used to layout taskbar in 3 button navigation mode.
310 public final boolean startAlignTaskbar;
Thales Limae9566402023-08-30 16:35:12 +0100311 public final boolean isTransientTaskbar;
Alex Chaua02eddc2021-04-29 00:36:06 +0100312 // DragController
313 public int flingToDeleteThresholdVelocity;
314
Vinit Nayak17c4b332021-08-05 12:54:58 -0700315 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700316 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal65190ae2022-08-02 14:16:26 -0700317 SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
Alex Chauab800f72022-12-13 17:46:06 +0000318 boolean transposeLayoutWithOrientation, boolean isMultiDisplay, boolean isGestureMode,
Jon Miranda2b25ded2023-02-02 14:48:45 -0800319 @NonNull final ViewScaleProvider viewScaleProvider,
Jagrut Desai3a7d1392023-09-06 15:56:19 -0700320 @NonNull final Consumer<DeviceProfile> dimensionOverrideProvider,
321 boolean isTransientTaskbar) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700322
Adam Cohen2e6da152015-05-06 11:42:25 -0700323 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700324 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800325 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500326 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +0000327 this.isMultiDisplay = isMultiDisplay;
Alex Chau6ed408f2022-03-04 12:58:05 +0000328 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700329 windowX = windowBounds.bounds.left;
330 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800331 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100332 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700333
Thales Limac98b7812023-04-14 15:04:23 +0100334 // TODO(b/241386436): shouldn't change any launcher behaviour
Thales Limaabfe3642023-05-24 18:08:53 +0100335 mIsResponsiveGrid = inv.workspaceSpecsId != INVALID_RESOURCE_HANDLE
Jordan Silva637f4eb2023-06-13 11:21:53 +0100336 && inv.allAppsSpecsId != INVALID_RESOURCE_HANDLE
Thales Limaf8bfb032023-07-24 15:08:05 +0100337 && inv.folderSpecsId != INVALID_RESOURCE_HANDLE
Jordan Silva999dd2a2023-11-17 19:31:43 +0000338 && inv.hotseatSpecsId != INVALID_RESOURCE_HANDLE
339 && inv.workspaceCellSpecsId != INVALID_RESOURCE_HANDLE
340 && inv.allAppsCellSpecsId != INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100341
Thales Lima79456492023-05-23 11:32:22 +0100342 mIsScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000343 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700344 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000345 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700346 isPhone = !isTablet;
Alex Chauab800f72022-12-13 17:46:06 +0000347 isTwoPanels = isTablet && isMultiDisplay;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800348 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700349
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000350 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000351 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700352 ? Configuration.ORIENTATION_LANDSCAPE
353 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000354 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700355 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000356 mMetrics = res.getDisplayMetrics();
357
Charlie Anderson7bb10972023-11-22 13:35:30 -0800358 mIconSizeSteps = new IconSizeSteps(res);
Thales Lima2759aa32023-06-05 16:25:45 +0100359
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000360 // Determine sizes.
361 widthPx = windowBounds.bounds.width();
362 heightPx = windowBounds.bounds.height();
363 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100364 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000365
366 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Thales Lima83bedbf2021-10-05 17:47:39 +0100367 if (isTwoPanels) {
368 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000369 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100370 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000371 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100372 }
373 } else {
374 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000375 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100376 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000377 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100378 }
379 }
380
Jagrut Desai3a7d1392023-09-06 15:56:19 -0700381 this.isTransientTaskbar = isTransientTaskbar;
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000382 int transientTaskbarIconSize = pxFromDp(inv.transientTaskbarIconSize[mTypeIndex], mMetrics);
383 int transientTaskbarBottomMargin =
384 res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin);
385 int transientTaskbarHeight =
386 Math.round((transientTaskbarIconSize * ICON_VISIBLE_AREA_FACTOR)
Jordan Silvaf2402e22023-10-26 19:53:16 +0100387 + (2 * res.getDimensionPixelSize(R.dimen.transient_taskbar_padding)));
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000388 mTransientTaskbarClaimedSpace = transientTaskbarHeight + 2 * transientTaskbarBottomMargin;
389
Uwais Ashraf3602d172023-09-15 11:36:32 +0000390 if (!isTaskbarPresent) {
391 taskbarIconSize = taskbarHeight = stashedTaskbarHeight = taskbarBottomMargin = 0;
392 startAlignTaskbar = false;
393 } else if (isTransientTaskbar) {
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000394 taskbarIconSize = transientTaskbarIconSize;
395 taskbarHeight = transientTaskbarHeight;
Jon Miranda9c478b62023-03-23 21:38:49 -0700396 stashedTaskbarHeight =
397 res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_height);
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000398 taskbarBottomMargin = transientTaskbarBottomMargin;
Jon Miranda04f05102023-04-04 12:16:31 -0700399 startAlignTaskbar = false;
Jon Miranda9c478b62023-03-23 21:38:49 -0700400 } else {
401 taskbarIconSize = pxFromDp(ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size),
402 mMetrics);
403 taskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_size);
404 stashedTaskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
405 taskbarBottomMargin = 0;
Jon Miranda04f05102023-04-04 12:16:31 -0700406 startAlignTaskbar = inv.startAlignTaskbar[mTypeIndex];
Tony Wickham15883892021-02-12 11:24:40 -0800407 }
Tony Wickham15883892021-02-12 11:24:40 -0800408
Winson Chungb3800242013-10-24 11:01:54 -0700409 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100410 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700411
Alex Chau51da2192022-05-20 13:32:10 +0100412 gridVisualizationPaddingX = res.getDimensionPixelSize(
413 R.dimen.grid_visualization_horizontal_cell_spacing);
414 gridVisualizationPaddingY = res.getDimensionPixelSize(
415 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500416
Alex Chaue0227552022-04-06 19:44:43 +0100417 bottomSheetTopPadding = mInsets.top // statusbar height
Andras Kloczl142b0542022-03-09 21:26:02 +0000418 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
419 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
Alex Chau3d2c0622022-09-01 21:28:14 +0100420 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
421 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
422 if (isTablet) {
423 bottomSheetWorkspaceScale = workspaceContentScale;
Alex Chauab800f72022-12-13 17:46:06 +0000424 if (isMultiDisplay && !ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH.get()) {
425 // TODO(b/259893832): Revert to use maxWallpaperScale to calculate bottomSheetDepth
426 // when screen recorder bug is fixed.
427 bottomSheetDepth = 1f;
428 } else {
429 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
430 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
431 // When depth is 1, wallpaper zoom is set to 1.
432 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
433 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
434 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
435 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
436 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100437 } else {
438 bottomSheetWorkspaceScale = 1f;
439 bottomSheetDepth = 0f;
440 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000441
Jon Mirandae126d722021-02-25 10:45:20 -0500442 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
Thales Lima1faa4ed2023-12-01 16:48:19 +0000443 numFolderRows = inv.numFolderRows[mTypeIndex];
444 numFolderColumns = inv.numFolderColumns[mTypeIndex];
Thales Limab35faed2022-09-05 16:30:01 -0300445
Thales Lima79456492023-05-23 11:32:22 +0100446 if (mIsScalableGrid && inv.folderStyle != INVALID_RESOURCE_HANDLE) {
Thales Limab35faed2022-09-05 16:30:01 -0300447 TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
Thales Limad852d652023-01-17 14:01:13 +0000448 R.styleable.FolderStyle);
Thales Limab35faed2022-09-05 16:30:01 -0300449 // These are re-set in #updateFolderCellSize if the grid is not scalable
450 folderCellHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000451 R.styleable.FolderStyle_folderCellHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300452 folderCellWidthPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000453 R.styleable.FolderStyle_folderCellWidth, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300454
455 folderContentPaddingTop = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000456 R.styleable.FolderStyle_folderTopPadding, 0);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100457
458 int gutter = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000459 R.styleable.FolderStyle_folderBorderSpace, 0);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100460 folderCellLayoutBorderSpacePx = new Point(gutter, gutter);
Thales Limab35faed2022-09-05 16:30:01 -0300461 folderFooterHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000462 R.styleable.FolderStyle_folderFooterHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300463 folderStyle.recycle();
Jordan Silva637f4eb2023-06-13 11:21:53 +0100464 } else if (!mIsResponsiveGrid) {
465 folderCellLayoutBorderSpacePx = new Point(0, 0);
Thales Lima7eee74b2023-03-16 16:00:55 -0300466 folderFooterHeightPx = res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Thales Limab35faed2022-09-05 16:30:01 -0300467 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
468 }
Jon Mirandae126d722021-02-25 10:45:20 -0500469
Thales Lima85c942f2021-12-31 13:04:20 +0000470 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000471 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
472 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Thales Limae9273ea2023-01-26 12:33:52 +0000473 setupAllAppsStyle(context);
Jon Mirandae126d722021-02-25 10:45:20 -0500474
Tony Wickham5edf9e22020-03-27 20:06:52 -0700475 workspacePageIndicatorHeight = res.getDimensionPixelSize(
476 R.dimen.workspace_page_indicator_height);
477 mWorkspacePageIndicatorOverlapWorkspace =
478 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700479
Jordan Silva999dd2a2023-11-17 19:31:43 +0000480 if (!mIsResponsiveGrid) {
481 TypedArray cellStyle;
482 if (inv.cellStyle != INVALID_RESOURCE_HANDLE) {
483 cellStyle = context.obtainStyledAttributes(inv.cellStyle,
484 R.styleable.CellStyle);
485 } else {
486 cellStyle = context.obtainStyledAttributes(R.style.CellStyleDefault,
487 R.styleable.CellStyle);
488 }
489 mIconDrawablePaddingOriginalPx = cellStyle.getDimensionPixelSize(
490 R.styleable.CellStyle_iconDrawablePadding, 0);
491 cellStyle.recycle();
Thales Limad852d652023-01-17 14:01:13 +0000492 }
Alex Chaua02eddc2021-04-29 00:36:06 +0100493
Sunny Goyal47328fd2016-05-25 18:56:41 -0700494 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100495 dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
496 dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100497 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
498 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100499 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
500 R.dimen.drop_target_button_drawable_horizontal_padding);
501 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
502 R.dimen.drop_target_button_drawable_vertical_padding);
503 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100504 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
505 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100506
Alex Chau906d8822022-05-23 10:42:25 +0100507 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
508 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700509
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700510 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700511
Thales Limaa1012902022-01-13 17:58:42 +0000512 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100513 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
514 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
515
Thales Lima12d0eff2022-03-25 17:06:11 +0000516 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
517 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
518 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
519 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
520 && hotseatQsbHeight > 0;
Thales Lima79456492023-05-23 11:32:22 +0100521 isQsbInline = mIsScalableGrid && inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000522
Thales Lima425f6822022-05-10 13:44:58 -0300523 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100524 numShownHotseatIcons =
525 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000526
Sunny Goyal19ff7282021-04-22 10:12:54 -0700527 numShownAllAppsColumns =
528 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100529
Thales Lima8e11d532023-08-31 13:40:26 +0000530 int hotseatBarBottomSpace;
Thales Limab8c05952022-05-23 16:58:38 +0100531 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
Thales Limaf8bfb032023-07-24 15:08:05 +0100532
533 if (mIsResponsiveGrid) {
Jordan Silvaf2402e22023-10-26 19:53:16 +0100534 float responsiveAspectRatio = (float) widthPx / heightPx;
535 HotseatSpecsProvider hotseatSpecsProvider =
536 HotseatSpecsProvider.create(new ResourceHelper(context,
Thales Limaf8bfb032023-07-24 15:08:05 +0100537 isTwoPanels ? inv.hotseatSpecsTwoPanelId : inv.hotseatSpecsId));
Thales Lima8e11d532023-08-31 13:40:26 +0000538 mResponsiveHotseatSpec =
Jordan Silvaf2402e22023-10-26 19:53:16 +0100539 isVerticalBarLayout() ? hotseatSpecsProvider.getCalculatedSpec(
540 responsiveAspectRatio, DimensionType.WIDTH, widthPx)
541 : hotseatSpecsProvider.getCalculatedSpec(responsiveAspectRatio,
542 DimensionType.HEIGHT, heightPx);
Thales Limaf8bfb032023-07-24 15:08:05 +0100543 hotseatQsbSpace = mResponsiveHotseatSpec.getHotseatQsbSpace();
Thales Lima8e11d532023-08-31 13:40:26 +0000544 hotseatBarBottomSpace =
545 isVerticalBarLayout() ? 0 : mResponsiveHotseatSpec.getEdgePadding();
546 mHotseatBarEdgePaddingPx =
547 isVerticalBarLayout() ? mResponsiveHotseatSpec.getEdgePadding() : 0;
548 mHotseatBarWorkspaceSpacePx = 0;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000549
550 ResponsiveCellSpecsProvider workspaceCellSpecs = ResponsiveCellSpecsProvider.create(
551 new ResourceHelper(context,
552 isTwoPanels ? inv.workspaceCellSpecsTwoPanelId
553 : inv.workspaceCellSpecsId));
554 mResponsiveWorkspaceCellSpec = workspaceCellSpecs.getCalculatedSpec(
555 responsiveAspectRatio, heightPx);
Thales Limaf8bfb032023-07-24 15:08:05 +0100556 } else {
557 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
Thales Lima8e11d532023-08-31 13:40:26 +0000558 hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
559 mHotseatBarEdgePaddingPx =
560 isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
561 mHotseatBarWorkspaceSpacePx =
562 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Thales Limaf8bfb032023-07-24 15:08:05 +0100563 }
564
Thales Lima8e11d532023-08-31 13:40:26 +0000565 if (!isVerticalBarLayout()) {
566 // Have a little space between the inset and the QSB
567 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
568 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
Thales Limab8c05952022-05-23 16:58:38 +0100569
Thales Lima8e11d532023-08-31 13:40:26 +0000570 // Only change the spaces if there is space
571 if (availableSpace > 0) {
572 // Make sure there is enough space between hotseat/QSB and QSB/navBar
573 if (availableSpace < minQsbMargin * 2) {
574 minQsbMargin = availableSpace / 2;
575 hotseatQsbSpace = minQsbMargin;
576 } else {
577 hotseatQsbSpace -= minQsbMargin;
578 }
Thales Limab8c05952022-05-23 16:58:38 +0100579 }
Thales Lima8e11d532023-08-31 13:40:26 +0000580 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
Thales Limab8c05952022-05-23 16:58:38 +0100581
Thales Lima8e11d532023-08-31 13:40:26 +0000582 } else {
583 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
584 }
Thales Limaa1012902022-01-13 17:58:42 +0000585 }
Thales Lima425f6822022-05-10 13:44:58 -0300586
Pat Manningde25c0d2022-04-05 19:11:26 +0100587 springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
588 R.dimen.spring_loaded_hotseat_top_margin);
Jordan Silva999dd2a2023-11-17 19:31:43 +0000589
590 if (mIsResponsiveGrid) {
591 updateHotseatSizes(mResponsiveWorkspaceCellSpec.getIconSize());
592 } else {
593 updateHotseatSizes(pxFromDp(inv.iconSize[mTypeIndex], mMetrics));
594 }
595
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700596 if (areNavButtonsInline && !isPhone) {
Jon Mirandae17a9492023-03-08 16:42:20 -0800597 inlineNavButtonsEndSpacingPx =
Thales Limaffc68b02023-01-09 16:20:23 +0000598 res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing);
Pat Manning26f70f72022-07-07 13:50:39 +0100599 /*
600 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700601 * Spacing between nav buttons +
Thales Lima6a590062022-11-22 15:52:49 +0000602 * Space at the end for contextual buttons
Pat Manning26f70f72022-07-07 13:50:39 +0100603 */
604 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700605 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
Jon Mirandae17a9492023-03-08 16:42:20 -0800606 + inlineNavButtonsEndSpacingPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100607 } else {
Jon Mirandae17a9492023-03-08 16:42:20 -0800608 inlineNavButtonsEndSpacingPx = 0;
Pat Manning26f70f72022-07-07 13:50:39 +0100609 hotseatBarEndOffset = 0;
610 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700611
Liran Binyamina833af32023-08-02 16:30:27 -0400612 mBubbleBarSpaceThresholdPx =
613 res.getDimensionPixelSize(R.dimen.bubblebar_hotseat_adjustment_threshold);
614
Thales Lima79456492023-05-23 11:32:22 +0100615 // Needs to be calculated after hotseatBarSizePx is correct,
616 // for the available height to be correct
617 if (mIsResponsiveGrid) {
Thales Lima2759aa32023-06-05 16:25:45 +0100618 int availableResponsiveWidth =
619 availableWidthPx - (isVerticalBarLayout() ? hotseatBarSizePx : 0);
Jordan Silva376036a2023-11-08 15:56:40 +0000620 int numWorkspaceColumns = getPanelCount() * inv.numColumns;
Thales Lima8e11d532023-08-31 13:40:26 +0000621 // don't use availableHeightPx because it subtracts mInsets.bottom
622 int availableResponsiveHeight = heightPx - mInsets.top
Jordan Silvaf2402e22023-10-26 19:53:16 +0100623 - (isVerticalBarLayout() ? 0 : hotseatBarSizePx);
624 float responsiveAspectRatio = (float) widthPx / heightPx;
Thales Limaabfe3642023-05-24 18:08:53 +0100625
Jordan Silvaf2402e22023-10-26 19:53:16 +0100626 ResponsiveSpecsProvider workspaceSpecs = ResponsiveSpecsProvider.create(
Jordan Silva575c3bd2023-07-21 12:00:43 +0100627 new ResourceHelper(context,
Jordan Silvaf2402e22023-10-26 19:53:16 +0100628 isTwoPanels ? inv.workspaceSpecsTwoPanelId : inv.workspaceSpecsId),
629 ResponsiveSpecType.Workspace);
Jordan Silva8f7986a2023-11-08 12:11:25 +0000630 mResponsiveWorkspaceWidthSpec = workspaceSpecs.getCalculatedSpec(responsiveAspectRatio,
Jordan Silva376036a2023-11-08 15:56:40 +0000631 DimensionType.WIDTH, numWorkspaceColumns, availableResponsiveWidth);
Jordan Silva8f7986a2023-11-08 12:11:25 +0000632 mResponsiveWorkspaceHeightSpec = workspaceSpecs.getCalculatedSpec(responsiveAspectRatio,
Jordan Silvaf2402e22023-10-26 19:53:16 +0100633 DimensionType.HEIGHT, inv.numRows, availableResponsiveHeight);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100634
Jordan Silvaf2402e22023-10-26 19:53:16 +0100635 ResponsiveSpecsProvider allAppsSpecs = ResponsiveSpecsProvider.create(
Jordan Silva575c3bd2023-07-21 12:00:43 +0100636 new ResourceHelper(context,
Jordan Silvaf2402e22023-10-26 19:53:16 +0100637 isTwoPanels ? inv.allAppsSpecsTwoPanelId : inv.allAppsSpecsId),
638 ResponsiveSpecType.AllApps);
Jordan Silva8f7986a2023-11-08 12:11:25 +0000639 mResponsiveAllAppsWidthSpec = allAppsSpecs.getCalculatedSpec(responsiveAspectRatio,
Jordan Silva8b3fa142023-11-13 21:31:38 +0000640 DimensionType.WIDTH, numShownAllAppsColumns, availableWidthPx,
Jordan Silva8f7986a2023-11-08 12:11:25 +0000641 mResponsiveWorkspaceWidthSpec);
642 mResponsiveAllAppsHeightSpec = allAppsSpecs.getCalculatedSpec(responsiveAspectRatio,
Jordan Silva2de6a272024-01-04 14:44:20 -0300643 DimensionType.HEIGHT, inv.numAllAppsRowsForCellHeightCalculation,
644 heightPx - mInsets.top, mResponsiveWorkspaceHeightSpec);
Jordan Silvaf2402e22023-10-26 19:53:16 +0100645
646 ResponsiveSpecsProvider folderSpecs = ResponsiveSpecsProvider.create(
647 new ResourceHelper(context,
648 isTwoPanels ? inv.folderSpecsTwoPanelId : inv.folderSpecsId),
649 ResponsiveSpecType.Folder);
650 mResponsiveFolderWidthSpec = folderSpecs.getCalculatedSpec(responsiveAspectRatio,
Thales Lima1faa4ed2023-12-01 16:48:19 +0000651 DimensionType.WIDTH, numFolderColumns,
Jordan Silva8f7986a2023-11-08 12:11:25 +0000652 mResponsiveWorkspaceWidthSpec.getAvailableSpace(),
653 mResponsiveWorkspaceWidthSpec);
Jordan Silvaf2402e22023-10-26 19:53:16 +0100654 mResponsiveFolderHeightSpec = folderSpecs.getCalculatedSpec(responsiveAspectRatio,
Thales Lima1faa4ed2023-12-01 16:48:19 +0000655 DimensionType.HEIGHT, numFolderRows,
Jordan Silva8f7986a2023-11-08 12:11:25 +0000656 mResponsiveWorkspaceHeightSpec.getAvailableSpace(),
657 mResponsiveWorkspaceHeightSpec);
Jordan Silva999dd2a2023-11-17 19:31:43 +0000658
659 ResponsiveCellSpecsProvider allAppsCellSpecs = ResponsiveCellSpecsProvider.create(
660 new ResourceHelper(context,
661 isTwoPanels ? inv.allAppsCellSpecsTwoPanelId
662 : inv.allAppsCellSpecsId));
663 mResponsiveAllAppsCellSpec = allAppsCellSpecs.getCalculatedSpec(
664 responsiveAspectRatio,
665 mResponsiveAllAppsHeightSpec.getAvailableSpace(),
666 mResponsiveWorkspaceCellSpec);
Thales Lima79456492023-05-23 11:32:22 +0100667 }
668
669 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
670 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
671
Alex Chau635b3ab2022-01-26 16:49:10 +0000672 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Pat Manning1695cc72023-07-05 11:45:13 +0100673 overviewTaskIconSizePx = enableOverviewIconMenu() ? res.getDimensionPixelSize(
674 R.dimen.task_thumbnail_icon_menu_drawable_touch_size) : res.getDimensionPixelSize(
675 R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100676 overviewTaskIconDrawableSizePx =
677 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
678 overviewTaskIconDrawableSizeGridPx =
679 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Pat Manning1695cc72023-07-05 11:45:13 +0100680 overviewTaskIconAppChipMenuDrawableSizePx = res.getDimensionPixelSize(
681 R.dimen.task_thumbnail_icon_menu_drawable_size);
682 overviewTaskThumbnailTopMarginPx =
683 enableOverviewIconMenu() ? 0 : overviewTaskIconSizePx + overviewTaskMarginPx;
Andy Wickhambc3bac42023-08-07 16:02:23 -0700684 // Don't add margin with floating search bar to minimize risk of overlapping.
685 overviewActionsTopMarginPx = FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get() ? 0
686 : res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000687 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
688 overviewActionsButtonSpacing = res.getDimensionPixelSize(
689 R.dimen.overview_actions_button_spacing);
Andy Wickhambc3bac42023-08-07 16:02:23 -0700690 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700691 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000692 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700693
Jeremy Sim0ac47082022-10-10 13:59:40 -0700694 splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset);
Winson Chung104a4c82023-11-08 18:56:15 +0000695 // We need to use the full window bounds for split determination because on near-square
696 // devices, the available bounds (bounds minus insets) may actually be in landscape while
697 // actually portrait
698 int leftRightSplitPortraitResId = Resources.getSystem().getIdentifier(
699 "config_leftRightSplitInPortrait", "bool", "android");
700 boolean allowLeftRightSplitInPortrait =
701 com.android.wm.shell.Flags.enableLeftRightSplitInPortrait()
702 && leftRightSplitPortraitResId > 0
703 && res.getBoolean(leftRightSplitPortraitResId);
704 if (allowLeftRightSplitInPortrait && isTablet) {
705 isLeftRightSplit = !isLandscape;
706 } else {
707 isLeftRightSplit = isLandscape;
708 }
Jeremy Sim0ac47082022-10-10 13:59:40 -0700709
Jon Miranda2ed276e2017-06-29 11:36:34 -0700710 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400711 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700712
Thales Lima79456492023-05-23 11:32:22 +0100713 calculateAndSetWorkspaceVerticalPadding(context, inv, extraSpace);
Pat Manning08610ca2022-04-05 21:03:16 +0100714
715 int cellLayoutPadding =
716 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
717 R.dimen.cell_layout_padding);
718 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
719 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800720 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800721
Thales Lima7eee74b2023-03-16 16:00:55 -0300722 // Folder scaling requires correct workspace paddings
723 updateAvailableFolderCellDimensions(res);
724
Thales Limaffc68b02023-01-09 16:20:23 +0000725 mMinHotseatIconSpacePx = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
726 mMinHotseatQsbWidthPx = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
727 mMaxHotseatIconSpacePx = areNavButtonsInline
Thales Lima6a590062022-11-22 15:52:49 +0000728 ? res.getDimensionPixelSize(R.dimen.max_hotseat_icon_space) : Integer.MAX_VALUE;
Thales Lima425f6822022-05-10 13:44:58 -0300729 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima6a590062022-11-22 15:52:49 +0000730 recalculateHotseatWidthAndBorderSpace();
Alex Chau206ede92022-08-01 17:46:12 +0100731
Jordan Silva3646a1b2023-08-02 13:52:52 +0100732 if (mIsResponsiveGrid && isVerticalBarLayout()) {
733 hotseatBorderSpace = cellLayoutBorderSpacePx.y;
734 }
735
Alex Chau206ede92022-08-01 17:46:12 +0100736 if (isTablet) {
Andy Wickham99d7d4f2023-11-15 08:09:09 +0000737 allAppsPadding.top = mInsets.top;
738 allAppsShiftRange = heightPx;
Alex Chau206ede92022-08-01 17:46:12 +0100739 } else {
Thales Limab433c9c2023-10-30 12:24:05 +0000740 allAppsPadding.top = 0;
Alex Chau206ede92022-08-01 17:46:12 +0100741 allAppsShiftRange =
742 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
743 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100744 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
745 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300746
Alex Chaua02eddc2021-04-29 00:36:06 +0100747 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
748 R.dimen.drag_flingToDeleteMinVelocity);
749
Sihua Mae04aa202022-07-18 12:43:56 -0700750 mViewScaleProvider = viewScaleProvider;
751
Jon Miranda2b25ded2023-02-02 14:48:45 -0800752 dimensionOverrideProvider.accept(this);
753
Tony Wickham1237df02017-02-24 08:59:36 -0800754 // This is done last, after iconSizePx is calculated above.
Sunny Goyal799e1202023-02-09 10:54:28 -0800755 mDotRendererWorkSpace = createDotRenderer(context, iconSizePx, dotRendererCache);
756 mDotRendererAllApps = createDotRenderer(context, allAppsIconSizePx, dotRendererCache);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700757 }
758
759 private static DotRenderer createDotRenderer(
Sunny Goyal799e1202023-02-09 10:54:28 -0800760 @NonNull Context context, int size, @NonNull SparseArray<DotRenderer> cache) {
Sunny Goyal65190ae2022-08-02 14:16:26 -0700761 DotRenderer renderer = cache.get(size);
762 if (renderer == null) {
Sunny Goyal799e1202023-02-09 10:54:28 -0800763 renderer = new DotRenderer(size, getShapePath(context, DEFAULT_DOT_SIZE),
764 DEFAULT_DOT_SIZE);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700765 cache.put(size, renderer);
766 }
767 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700768 }
769
Thales Lima425f6822022-05-10 13:44:58 -0300770 /**
Fengjiang Li6c590822023-09-25 15:04:57 -0700771 * Return maximum of all apps row count displayed on screen. Note that 1) Partially displayed
772 * row is counted as 1 row, and 2) we don't exclude the space of floating search bar. This
773 * method is used for calculating number of {@link BubbleTextView} we need to pre-inflate. Thus
774 * reasonable over estimation is fine.
775 */
776 public int getMaxAllAppsRowCount() {
Thales Limab433c9c2023-10-30 12:24:05 +0000777 return (int) (Math.ceil((availableHeightPx - allAppsPadding.top)
Fengjiang Li6c590822023-09-25 15:04:57 -0700778 / (float) allAppsCellHeightPx));
779 }
780
781 /**
Thales Lima425f6822022-05-10 13:44:58 -0300782 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
783 * width of the hotseat.
784 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100785 private int calculateQsbWidth(int hotseatBorderSpace) {
fbarone69b6f42023-12-18 13:20:34 -0800786 int iconExtraSpacePx = iconSizePx - getIconVisibleSizePx(iconSizePx);
Thales Lima425f6822022-05-10 13:44:58 -0300787 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100788 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300789 return getIconToIconWidthForColumns(columns)
790 - iconSizePx * numShownHotseatIcons
fbarone69b6f42023-12-18 13:20:34 -0800791 - hotseatBorderSpace * numShownHotseatIcons
792 - iconExtraSpacePx;
Thales Lima425f6822022-05-10 13:44:58 -0300793 } else {
794 int columns = inv.hotseatColumnSpan[mTypeIndex];
fbarone69b6f42023-12-18 13:20:34 -0800795 return getIconToIconWidthForColumns(columns) - iconExtraSpacePx;
Thales Lima425f6822022-05-10 13:44:58 -0300796 }
797 }
Thales Lima2903a622022-03-17 13:52:19 +0000798
Thales Lima425f6822022-05-10 13:44:58 -0300799 private int getIconToIconWidthForColumns(int columns) {
800 return columns * getCellSize().x
801 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400802 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000803 }
804
Thales Limad90faab2021-09-21 17:18:47 +0100805 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
Thales Lima79456492023-05-23 11:32:22 +0100806 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +0000807 return mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
Thales Lima79456492023-05-23 11:32:22 +0100808 }
809
Thales Limad90faab2021-09-21 17:18:47 +0100810 if (isVerticalBarLayout()) {
811 return 0;
812 }
813
Thales Lima79456492023-05-23 11:32:22 +0100814 return mIsScalableGrid
Thales Lima83bedbf2021-10-05 17:47:39 +0100815 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
816 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100817 }
818
Thales Lima79456492023-05-23 11:32:22 +0100819 private void calculateAndSetWorkspaceVerticalPadding(Context context,
820 InvariantDeviceProfile inv,
821 int extraSpace) {
822 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +0000823 workspaceTopPadding = mResponsiveWorkspaceHeightSpec.getStartPaddingPx();
824 workspaceBottomPadding = mResponsiveWorkspaceHeightSpec.getEndPaddingPx();
Thales Lima79456492023-05-23 11:32:22 +0100825 } else if (mIsScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
826 // Paddings were created assuming no scaling, so we first unscale the extra space.
827 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
828 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
829 DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
830 maxEmptySpace = padding.getMaxEmptySpacePx();
831
832 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
833 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
834
835 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
836 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
837 }
838 }
839
Thales Limab8c05952022-05-23 16:58:38 +0100840 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
841 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700842 // Ensure there is enough space for folder icons, which have a slightly larger radius.
Jordan Silva3646a1b2023-08-02 13:52:52 +0100843 hotseatCellHeightPx = getIconSizeWithOverlap(hotseatIconSizePx);
Thales Limab8c05952022-05-23 16:58:38 +0100844
Jon Miranda0d284852021-06-22 14:50:55 -0700845 if (isVerticalBarLayout()) {
Thales Lima8e11d532023-08-31 13:40:26 +0000846 hotseatBarSizePx = hotseatIconSizePx + mHotseatBarEdgePaddingPx
847 + mHotseatBarWorkspaceSpacePx;
Thales Limab8c05952022-05-23 16:58:38 +0100848 } else if (isQsbInline) {
849 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
850 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700851 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100852 hotseatBarSizePx = hotseatIconSizePx
853 + hotseatQsbSpace
854 + hotseatQsbVisualHeight
855 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700856 }
857 }
858
Thales Lima6a590062022-11-22 15:52:49 +0000859 /**
860 * Calculates the width of the hotseat, changing spaces between the icons and removing icons if
861 * necessary.
862 */
863 public void recalculateHotseatWidthAndBorderSpace() {
Thales Lima79456492023-05-23 11:32:22 +0100864 if (!mIsScalableGrid) return;
Thales Lima6a590062022-11-22 15:52:49 +0000865
866 int columns = inv.hotseatColumnSpan[mTypeIndex];
867 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
868 hotseatBorderSpace = calculateHotseatBorderSpace(hotseatWidthPx, /* numExtraBorder= */ 0);
Thales Lima9938c2f2022-07-25 14:38:16 +0100869 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
Thales Lima6a590062022-11-22 15:52:49 +0000870 // Spaces should be correct when the nav buttons are not inline
Thales Lima9938c2f2022-07-25 14:38:16 +0100871 if (!areNavButtonsInline) {
872 return;
873 }
874
Thales Lima6a590062022-11-22 15:52:49 +0000875 // The side space with inline buttons should be what is defined in InvariantDeviceProfile
Jon Mirandae17a9492023-03-08 16:42:20 -0800876 int sideSpacePx = inlineNavButtonsEndSpacingPx;
Thales Limaffc68b02023-01-09 16:20:23 +0000877 int maxHotseatWidthPx = availableWidthPx - sideSpacePx - hotseatBarEndOffset;
878 int maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
879 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000880 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100881
Thales Limaffc68b02023-01-09 16:20:23 +0000882 if (hotseatBorderSpace >= mMinHotseatIconSpacePx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100883 return;
884 }
885
886 // Border space can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000887 hotseatBorderSpace = mMinHotseatIconSpacePx;
Thales Lima6a590062022-11-22 15:52:49 +0000888 int requiredWidth = getHotseatRequiredWidth();
Thales Lima9938c2f2022-07-25 14:38:16 +0100889
890 // If there is an inline qsb, change its size
891 if (isQsbInline) {
Thales Limaffc68b02023-01-09 16:20:23 +0000892 hotseatQsbWidth -= requiredWidth - maxHotseatWidthPx;
893 if (hotseatQsbWidth >= mMinHotseatQsbWidthPx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100894 return;
895 }
896
897 // QSB can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000898 hotseatQsbWidth = mMinHotseatQsbWidthPx;
Thales Lima9938c2f2022-07-25 14:38:16 +0100899 }
900
Thales Limaffc68b02023-01-09 16:20:23 +0000901 maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
Thales Lima6a590062022-11-22 15:52:49 +0000902
Thales Lima9938c2f2022-07-25 14:38:16 +0100903 // If it still doesn't fit, start removing icons
904 do {
905 numShownHotseatIcons--;
Thales Limaffc68b02023-01-09 16:20:23 +0000906 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000907 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Limaffc68b02023-01-09 16:20:23 +0000908 } while (hotseatBorderSpace < mMinHotseatIconSpacePx && numShownHotseatIcons > 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100909 }
910
Thales Lima78d00ad2021-09-30 11:29:06 +0100911 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100912 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100913 }
914
915 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima79456492023-05-23 11:32:22 +0100916 int horizontalSpacePx = 0;
917 int verticalSpacePx = 0;
Thales Lima78d00ad2021-09-30 11:29:06 +0100918
Thales Lima79456492023-05-23 11:32:22 +0100919 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +0000920 horizontalSpacePx = mResponsiveWorkspaceWidthSpec.getGutterPx();
921 verticalSpacePx = mResponsiveWorkspaceHeightSpec.getGutterPx();
Thales Lima79456492023-05-23 11:32:22 +0100922 } else if (mIsScalableGrid) {
923 horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
924 verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
925 }
Thales Lima78d00ad2021-09-30 11:29:06 +0100926
927 return new Point(horizontalSpacePx, verticalSpacePx);
928 }
929
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700930 public Info getDisplayInfo() {
931 return mInfo;
932 }
933
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700934 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800935 WindowBounds bounds = new WindowBounds(
936 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700937 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100938 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700939
940 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
941 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
942 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
943
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700944 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700945 .setWindowBounds(bounds)
Alex Chauab800f72022-12-13 17:46:06 +0000946 .setIsMultiDisplay(isMultiDisplay)
Alex Chau6ed408f2022-03-04 12:58:05 +0000947 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700948 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000949 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800950 }
951
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700952 public DeviceProfile copy(Context context) {
953 return toBuilder(context).build();
954 }
955
956 /**
957 * TODO: Move this to the builder as part of setMultiWindowMode
958 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700959 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700960 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700961 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700962 .setMultiWindowMode(true)
963 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800964
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800965 // We use these scales to measure and layout the widgets using their full invariant profile
966 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
967 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
968 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700969 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
970 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
971 profile = profile.toBuilder(context)
972 .setViewScaleProvider(i -> p)
973 .build();
974 }
975
976 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800977
Jon Miranda93e1f042016-11-11 14:13:04 -0800978 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700979 }
980
Adam Cohen63f1ec02014-08-12 09:23:13 -0700981 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400982 * Checks if there is enough space for labels on the workspace.
983 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700984 * It is important to call this method after the All Apps variables have been set.
985 */
Jon Miranda941375e2021-03-31 13:10:45 -0400986 private void hideWorkspaceLabelsIfNotEnoughSpace() {
987 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
988 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
989 - iconTextHeight;
990
991 // We want enough space so that the text is closer to its corresponding icon.
992 if (workspaceCellPaddingY < iconTextHeight) {
993 iconTextSizePx = 0;
994 iconDrawablePaddingPx = 0;
Jordan Silva3646a1b2023-08-02 13:52:52 +0100995 cellHeightPx = getIconSizeWithOverlap(iconSizePx);
Jon Miranda941375e2021-03-31 13:10:45 -0400996 autoResizeAllAppsCells();
997 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700998 }
Jon Miranda1091e532017-07-21 13:31:50 -0700999
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001000 /**
Jon Miranda228877d2021-02-09 11:05:00 -05001001 * Returns the amount of extra (or unused) vertical space.
1002 */
1003 private int updateAvailableDimensions(Resources res) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001004 iconCenterVertically = mIsScalableGrid || mIsResponsiveGrid;
1005
1006 if (mIsResponsiveGrid) {
Jordan Silva15cacd52023-11-28 14:32:05 +00001007 iconSizePx = mResponsiveWorkspaceCellSpec.getIconSize();
1008 iconTextSizePx = mResponsiveWorkspaceCellSpec.getIconTextSize();
1009 mIconDrawablePaddingOriginalPx = mResponsiveWorkspaceCellSpec.getIconDrawablePadding();
Jordan Silva999dd2a2023-11-17 19:31:43 +00001010 updateIconSize(1f, res);
1011 updateWorkspacePadding();
1012 return 0;
1013 }
1014
Alex Chaua68164d2022-12-15 16:16:03 +00001015 float invIconSizeDp = inv.iconSize[mTypeIndex];
1016 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
1017 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
1018 iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
1019
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001020 updateIconSize(1f, res);
Pat Manning08610ca2022-04-05 21:03:16 +01001021 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -05001022
1023 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +01001024 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +00001025 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -05001026 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -05001027 float scaleY = maxHeight / usedHeight;
1028 boolean shouldScale = scaleY < 1f;
1029
1030 float scaleX = 1f;
Thales Lima79456492023-05-23 11:32:22 +01001031 if (mIsScalableGrid) {
Jon Mirandae126d722021-02-25 10:45:20 -05001032 // We scale to fit the cellWidth and cellHeight in the available space.
1033 // The benefit of scalable grids is that we can get consistent aspect ratios between
1034 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +01001035 float usedWidth =
1036 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -05001037 // We do not subtract padding here, as we also scale the workspace padding if needed.
1038 scaleX = availableWidthPx / usedWidth;
1039 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -07001040 }
Jon Mirandae126d722021-02-25 10:45:20 -05001041
1042 if (shouldScale) {
1043 float scale = Math.min(scaleX, scaleY);
1044 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +01001045 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -05001046 }
1047
Jon Miranda228877d2021-02-09 11:05:00 -05001048 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -07001049 }
1050
Pat Manninga2e14992022-04-22 11:29:17 +01001051 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +01001052 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
1053 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
1054 }
1055
Pat Manninga2e14992022-04-22 11:29:17 +01001056 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +00001057 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +01001058 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
1059 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -05001060 }
1061
Jordan Silva376036a2023-11-08 15:56:40 +00001062 private int getNormalizedIconDrawablePadding(int iconSizePx, int iconDrawablePadding) {
fbarone69b6f42023-12-18 13:20:34 -08001063 return Math.max(0, iconDrawablePadding
1064 - ((iconSizePx - getIconVisibleSizePx(iconSizePx)) / 2));
Jordan Silva376036a2023-11-08 15:56:40 +00001065 }
1066
1067 private int getNormalizedIconDrawablePadding() {
1068 return getNormalizedIconDrawablePadding(iconSizePx, mIconDrawablePaddingOriginalPx);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001069 }
1070
1071 private int getNormalizedFolderChildDrawablePaddingPx(int textHeight) {
1072 // TODO(b/235886078): workaround needed because of this bug
1073 // Icons are 10% larger on XML than their visual size,
1074 // so remove that extra space to get labels closer to the correct padding
1075 int drawablePadding = (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3;
1076
fbarone69b6f42023-12-18 13:20:34 -08001077 int iconSizeDiff = folderChildIconSizePx - getIconVisibleSizePx(folderChildIconSizePx);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001078 return Math.max(0, drawablePadding - iconSizeDiff / 2);
1079 }
1080
Jordan Silva3646a1b2023-08-02 13:52:52 +01001081 private int getIconSizeWithOverlap(int iconSize) {
1082 return (int) Math.ceil(iconSize * ICON_OVERLAP_FACTOR);
1083 }
1084
Jon Miranda6f7e9702019-09-16 14:44:14 -07001085 /**
1086 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
1087 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
1088 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
1089 */
Tony Wickham7ba547c2021-02-02 17:12:08 -08001090 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -07001091 // Icon scale should never exceed 1, otherwise pixellation may occur.
1092 iconScale = Math.min(1f, scale);
1093 cellScaleToFit = scale;
1094
Jon Miranda18751b62017-07-31 17:25:27 -07001095 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -08001096 final boolean isVerticalLayout = isVerticalBarLayout();
Thales Lima080d8902022-03-28 15:30:29 +01001097 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -05001098
Thales Lima79456492023-05-23 11:32:22 +01001099 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001100 cellWidthPx = mResponsiveWorkspaceWidthSpec.getCellSizePx();
1101 cellHeightPx = mResponsiveWorkspaceHeightSpec.getCellSizePx();
Thales Lima79456492023-05-23 11:32:22 +01001102
Thales Lima2759aa32023-06-05 16:25:45 +01001103 if (cellWidthPx < iconSizePx) {
1104 // get a smaller icon size
1105 iconSizePx = mIconSizeSteps.getIconSmallerThan(cellWidthPx);
Thales Lima2759aa32023-06-05 16:25:45 +01001106 }
1107
Jordan Silvadd612682024-01-08 11:38:13 -03001108 if (isVerticalLayout) {
1109 iconDrawablePaddingPx = 0;
1110 iconTextSizePx = 0;
1111 } else {
1112 iconDrawablePaddingPx = getNormalizedIconDrawablePadding();
1113 }
Thales Lima93ee8fc2023-06-05 17:07:11 +01001114
Thales Lima24ceca62023-09-25 16:21:17 -07001115 CellContentDimensions cellContentDimensions = new CellContentDimensions(iconSizePx,
1116 iconDrawablePaddingPx,
1117 iconTextSizePx);
Jordan Silvadd612682024-01-08 11:38:13 -03001118 int cellContentHeight = cellContentDimensions.resizeToFitCellHeight(cellHeightPx,
1119 mIconSizeSteps);
Thales Lima24ceca62023-09-25 16:21:17 -07001120 iconSizePx = cellContentDimensions.getIconSizePx();
1121 iconDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1122 iconTextSizePx = cellContentDimensions.getIconTextSizePx();
Thales Lima2759aa32023-06-05 16:25:45 +01001123
Jordan Silvadd612682024-01-08 11:38:13 -03001124 if (isVerticalLayout) {
1125 cellYPaddingPx = Math.max(0, getCellSize().y - getIconSizeWithOverlap(iconSizePx))
1126 / 2;
1127 } else {
1128 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
1129 }
Thales Lima79456492023-05-23 11:32:22 +01001130 } else if (mIsScalableGrid) {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001131 iconDrawablePaddingPx = (int) (getNormalizedIconDrawablePadding() * iconScale);
Thales Lima83bedbf2021-10-05 17:47:39 +01001132 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
1133 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001134
1135 if (cellWidthPx < iconSizePx) {
1136 // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger.
1137 int numColumns = getPanelCount() * inv.numColumns;
1138 int numBorders = numColumns - 1;
1139 int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns;
1140 if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) {
1141 cellWidthPx = iconSizePx;
1142 cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders;
1143 } else {
1144 // If it still doesn't fit, set borderSpace to 0 and distribute the space for
1145 // cellWidth, and reduce iconSize.
1146 cellWidthPx = (cellWidthPx * numColumns
1147 + cellLayoutBorderSpacePx.x * numBorders) / numColumns;
1148 iconSizePx = Math.min(iconSizePx, cellWidthPx);
1149 cellLayoutBorderSpacePx.x = 0;
1150 }
1151 }
1152
Thales Lima93ee8fc2023-06-05 17:07:11 +01001153 int cellTextAndPaddingHeight =
1154 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +00001155 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
1156 if (cellHeightPx < cellContentHeight) {
1157 // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight
1158 // bigger.
1159 int numBorders = inv.numRows - 1;
1160 int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows;
1161 if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) {
1162 cellHeightPx = cellContentHeight;
1163 cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders;
1164 } else {
Alex Chau06f36e82023-01-06 10:50:54 +00001165 // If it still doesn't fit, set borderSpace to 0 to recover space.
Alex Chaube753132022-12-09 16:46:54 +00001166 cellHeightPx = (cellHeightPx * inv.numRows
1167 + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows;
Alex Chaube753132022-12-09 16:46:54 +00001168 cellLayoutBorderSpacePx.y = 0;
Alex Chau06f36e82023-01-06 10:50:54 +00001169 // Reduce iconDrawablePaddingPx to make cellContentHeight smaller.
1170 int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx;
1171 if (cellContentWithoutPadding <= cellHeightPx) {
1172 iconDrawablePaddingPx = cellContentHeight - cellHeightPx;
1173 } else {
1174 // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space,
1175 // then proportional reduce iconSizePx and iconTextSizePx to fit.
1176 iconDrawablePaddingPx = 0;
1177 float ratio = cellHeightPx / (float) cellContentWithoutPadding;
1178 iconSizePx = (int) (iconSizePx * ratio);
1179 iconTextSizePx = (int) (iconTextSizePx * ratio);
1180 }
1181 cellTextAndPaddingHeight =
1182 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +00001183 }
1184 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
1185 }
Jon Mirandae126d722021-02-25 10:45:20 -05001186 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +01001187 desiredWorkspaceHorizontalMarginPx =
1188 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -05001189 } else {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001190 iconDrawablePaddingPx = (int) (getNormalizedIconDrawablePadding() * iconScale);
Jon Mirandae126d722021-02-25 10:45:20 -05001191 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001192 cellHeightPx = getIconSizeWithOverlap(iconSizePx)
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001193 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -05001194 + Utilities.calculateTextHeight(iconTextSizePx);
1195 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
1196 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
1197 && !isMultiWindowMode) {
1198 // Ensures that the label is closer to its corresponding icon. This is not an issue
1199 // with vertical bar layout or multi-window mode since the issue is handled
1200 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
1201 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
1202 iconDrawablePaddingPx = cellPaddingY;
1203 }
Jon Miranda846455e2017-10-02 14:58:52 -07001204 }
Jon Miranda18751b62017-07-31 17:25:27 -07001205
Sunny Goyalae190ff2020-04-14 00:19:01 +00001206 // All apps
Thales Limaabfe3642023-05-24 18:08:53 +01001207 if (mIsResponsiveGrid) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001208 updateAllAppsWithResponsiveMeasures();
Thales Limaabfe3642023-05-24 18:08:53 +01001209 } else {
1210 updateAllAppsIconSize(scale, res);
1211 }
1212 updateAllAppsContainerWidth();
Jordan Silvadd612682024-01-08 11:38:13 -03001213 if (isVerticalLayout && !mIsResponsiveGrid) {
Thales Limaabfe3642023-05-24 18:08:53 +01001214 hideWorkspaceLabelsIfNotEnoughSpace();
1215 }
Brandon Dayauon3cdb32c2023-08-22 21:26:37 -07001216 if (FeatureFlags.enableTwolineAllapps()) {
1217 // Add extra textHeight to the existing allAppsCellHeight.
1218 allAppsCellHeightPx += Utilities.calculateTextHeight(allAppsIconTextSizePx);
1219 }
Winson Chungb3800242013-10-24 11:01:54 -07001220
Thales Limab8c05952022-05-23 16:58:38 +01001221 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -07001222
Sunny Goyalbaec6ff2016-09-14 11:26:21 -07001223 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -07001224 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
1225 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Sunny Goyal6c304b12023-04-10 12:03:04 -07001226
1227 // Update widget padding:
1228 float minSpacing = pxFromDp(MIN_WIDGET_PADDING_DP, mMetrics);
1229 if (cellLayoutBorderSpacePx.x < minSpacing
1230 || cellLayoutBorderSpacePx.y < minSpacing) {
1231 widgetPadding.left = widgetPadding.right =
1232 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.x));
1233 widgetPadding.top = widgetPadding.bottom =
1234 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.y));
1235 } else {
1236 widgetPadding.setEmpty();
1237 }
Winson Chung0f785722015-04-08 10:27:49 -07001238 }
1239
Thales Lima425f6822022-05-10 13:44:58 -03001240 /**
Thales Lima6a590062022-11-22 15:52:49 +00001241 * This method calculates the space between the icons to achieve a certain width.
Thales Lima425f6822022-05-10 13:44:58 -03001242 */
Thales Lima6a590062022-11-22 15:52:49 +00001243 private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) {
Jordan Silvad9227182023-08-17 15:53:59 +01001244 int numBorders = (numShownHotseatIcons - 1 + numExtraBorder);
1245 if (numBorders <= 0) return 0;
1246
Thales Lima9938c2f2022-07-25 14:38:16 +01001247 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
Jordan Silvad9227182023-08-17 15:53:59 +01001248 int hotseatBorderSpacePx = (int) (hotseatWidthPx - hotseatIconsTotalPx) / numBorders;
Thales Limaffc68b02023-01-09 16:20:23 +00001249 return Math.min(hotseatBorderSpacePx, mMaxHotseatIconSpacePx);
Thales Lima425f6822022-05-10 13:44:58 -03001250 }
1251
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001252 /**
1253 * Updates the iconSize for allApps* variants.
1254 */
Brian Isganitisa9a78112022-05-23 18:11:47 -07001255 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +01001256 allAppsBorderSpacePx = new Point(
1257 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
1258 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001259 // AllApps cells don't have real space between cells,
1260 // so we add the border space to the cell height
Alex Chaube753132022-12-09 16:46:54 +00001261 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics)
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001262 + allAppsBorderSpacePx.y;
1263 // but width is just the cell,
1264 // the border is added in #updateAllAppsContainerWidth
Thales Lima79456492023-05-23 11:32:22 +01001265 if (mIsScalableGrid) {
Alex Chaube753132022-12-09 16:46:54 +00001266 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1267 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001268 allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding();
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001269 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001270
1271 if (allAppsCellWidthPx < allAppsIconSizePx) {
1272 // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to
1273 // make allAppsCellWidth bigger.
1274 int numBorders = inv.numAllAppsColumns - 1;
1275 int extraWidthRequired =
1276 (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns;
1277 if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) {
1278 allAppsCellWidthPx = allAppsIconSizePx;
1279 allAppsBorderSpacePx.x -= extraWidthRequired / numBorders;
1280 } else {
1281 // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space
1282 // for allAppsCellWidth, and reduce allAppsIconSize.
1283 allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns
1284 + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns;
1285 allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx);
1286 allAppsBorderSpacePx.x = 0;
1287 }
1288 }
1289
1290 int cellContentHeight = allAppsIconSizePx
1291 + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y;
1292 if (allAppsCellHeightPx < cellContentHeight) {
1293 // Increase allAppsCellHeight to fit its content.
1294 allAppsCellHeightPx = cellContentHeight;
1295 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001296 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001297 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
1298 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001299 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1300 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001301 allAppsIconDrawablePaddingPx =
1302 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001303 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001304 }
Thales Limaabfe3642023-05-24 18:08:53 +01001305 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001306
Jordan Silva999dd2a2023-11-17 19:31:43 +00001307 private void updateAllAppsWithResponsiveMeasures() {
1308 allAppsIconSizePx = mResponsiveAllAppsCellSpec.getIconSize();
1309 allAppsIconTextSizePx = mResponsiveAllAppsCellSpec.getIconTextSize();
1310 allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding(allAppsIconSizePx,
1311 mResponsiveAllAppsCellSpec.getIconDrawablePadding());
Thales Limaabfe3642023-05-24 18:08:53 +01001312 allAppsBorderSpacePx = new Point(
Jordan Silva8f7986a2023-11-08 12:11:25 +00001313 mResponsiveAllAppsWidthSpec.getGutterPx(),
1314 mResponsiveAllAppsHeightSpec.getGutterPx()
Thales Limaabfe3642023-05-24 18:08:53 +01001315 );
Jordan Silva999dd2a2023-11-17 19:31:43 +00001316 allAppsCellHeightPx = mResponsiveAllAppsHeightSpec.getCellSizePx();
Jordan Silva8f7986a2023-11-08 12:11:25 +00001317 allAppsCellWidthPx = mResponsiveAllAppsWidthSpec.getCellSizePx();
Thales Limaa25cd902023-11-01 12:00:32 +00001318
1319 // This workaround is needed to align AllApps icons with Workspace icons
1320 // since AllApps doesn't have borders between cells
1321 int halfBorder = allAppsBorderSpacePx.x / 2;
Jordan Silva8f7986a2023-11-08 12:11:25 +00001322 allAppsPadding.left = mResponsiveAllAppsWidthSpec.getStartPaddingPx() - halfBorder;
1323 allAppsPadding.right = mResponsiveAllAppsWidthSpec.getEndPaddingPx() - halfBorder;
Jordan Silva376036a2023-11-08 15:56:40 +00001324
Jordan Silva376036a2023-11-08 15:56:40 +00001325
1326 // Reduce the size of the app icon if it doesn't fit
1327 if (allAppsCellWidthPx < allAppsIconSizePx) {
1328 // get a smaller icon size
1329 allAppsIconSizePx = mIconSizeSteps.getIconSmallerThan(allAppsCellWidthPx);
1330 }
1331
1332 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1333 allAppsIconSizePx, allAppsIconDrawablePaddingPx, (int) allAppsIconTextSizePx);
1334
1335 if (allAppsCellHeightPx < cellContentDimensions.getCellContentHeight()) {
1336 if (isVerticalBarLayout()) {
Jordan Silva2de6a272024-01-04 14:44:20 -03001337 if (allAppsCellHeightPx < allAppsIconSizePx) {
Jordan Silva376036a2023-11-08 15:56:40 +00001338 cellContentDimensions.setIconSizePx(
1339 mIconSizeSteps.getIconSmallerThan(allAppsCellHeightPx));
1340 }
1341 } else {
1342 cellContentDimensions.resizeToFitCellHeight(allAppsCellHeightPx,
1343 mIconSizeSteps);
1344 }
1345 allAppsIconSizePx = cellContentDimensions.getIconSizePx();
1346 allAppsIconDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1347 allAppsIconTextSizePx = cellContentDimensions.getIconTextSizePx();
1348 }
Jordan Silva999dd2a2023-11-17 19:31:43 +00001349
1350 allAppsCellHeightPx += mResponsiveAllAppsHeightSpec.getGutterPx();
Jordan Silvadd612682024-01-08 11:38:13 -03001351
1352 if (isVerticalBarLayout()) {
1353 autoResizeAllAppsCells();
1354 }
Thales Limaabfe3642023-05-24 18:08:53 +01001355 }
1356
1357 /**
1358 * Re-computes the all-apps cell size to be independent of workspace
1359 */
1360 public void autoResizeAllAppsCells() {
1361 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
1362 int topBottomPadding = textHeight;
1363 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
1364 + textHeight + (topBottomPadding * 2);
1365 }
1366
1367 private void updateAllAppsContainerWidth() {
1368 int cellLayoutHorizontalPadding =
1369 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
1370 if (isTablet) {
1371 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
1372 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Thales Limab433c9c2023-10-30 12:24:05 +00001373 + allAppsPadding.left + allAppsPadding.right;
Thales Limaabfe3642023-05-24 18:08:53 +01001374 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
Thales Limaa25cd902023-11-01 12:00:32 +00001375 } else if (!mIsResponsiveGrid) {
Thales Limab433c9c2023-10-30 12:24:05 +00001376 allAppsPadding.left = allAppsPadding.right =
Thales Limaabfe3642023-05-24 18:08:53 +01001377 Math.max(0, desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding
1378 - (allAppsBorderSpacePx.x / 2));
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001379 }
1380 }
1381
Thales Limaabfe3642023-05-24 18:08:53 +01001382 private void setupAllAppsStyle(Context context) {
1383 TypedArray allAppsStyle = context.obtainStyledAttributes(
1384 inv.allAppsStyle != INVALID_RESOURCE_HANDLE ? inv.allAppsStyle
1385 : R.style.AllAppsStyleDefault, R.styleable.AllAppsStyle);
1386
Thales Limab433c9c2023-10-30 12:24:05 +00001387 allAppsPadding.left = allAppsPadding.right = allAppsStyle.getDimensionPixelSize(
Thales Limaabfe3642023-05-24 18:08:53 +01001388 R.styleable.AllAppsStyle_horizontalPadding, 0);
1389 allAppsStyle.recycle();
1390 }
1391
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001392 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001393 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001394
Jordan Silva637f4eb2023-06-13 11:21:53 +01001395 // Responsive grid doesn't need to scale the folder
1396 if (mIsResponsiveGrid) return;
1397
Thales Lima7eee74b2023-03-16 16:00:55 -03001398 // For usability we can't have the folder use the whole width of the screen
Sunny Goyal07b69292018-01-08 14:19:34 -08001399 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -08001400
Thales Lima7eee74b2023-03-16 16:00:55 -03001401 // Check if the folder fit within the available height.
Thales Lima1faa4ed2023-12-01 16:48:19 +00001402 float contentUsedHeight = folderCellHeightPx * numFolderRows
1403 + ((numFolderRows - 1) * folderCellLayoutBorderSpacePx.y)
Thales Lima7eee74b2023-03-16 16:00:55 -03001404 + folderFooterHeightPx
1405 + folderContentPaddingTop;
1406 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001407 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -08001408
Thales Lima7eee74b2023-03-16 16:00:55 -03001409 // Check if the folder fit within the available width.
Thales Lima1faa4ed2023-12-01 16:48:19 +00001410 float contentUsedWidth = folderCellWidthPx * numFolderColumns
1411 + ((numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x)
Thales Lima7eee74b2023-03-16 16:00:55 -03001412 + folderContentPaddingLeftRight * 2;
1413 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001414 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -08001415
1416 float scale = Math.min(scaleX, scaleY);
1417 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001418 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001419 }
1420 }
1421
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001422 private void updateFolderCellSize(float scale, Resources res) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001423 int minLabelTextSize = pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001424 if (mIsResponsiveGrid) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001425 folderChildIconSizePx = mResponsiveWorkspaceCellSpec.getIconSize();
1426 folderChildTextSizePx = mResponsiveWorkspaceCellSpec.getIconTextSize();
1427 folderLabelTextSizePx = Math.max(minLabelTextSize,
1428 (int) (folderChildTextSizePx * folderLabelTextScale));
1429 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
1430
Jordan Silva637f4eb2023-06-13 11:21:53 +01001431 folderCellWidthPx = mResponsiveFolderWidthSpec.getCellSizePx();
Jordan Silva637f4eb2023-06-13 11:21:53 +01001432 folderCellHeightPx = mResponsiveFolderHeightSpec.getCellSizePx();
1433 folderContentPaddingTop = mResponsiveFolderHeightSpec.getStartPaddingPx();
1434 folderFooterHeightPx = mResponsiveFolderHeightSpec.getEndPaddingPx();
1435
1436 folderCellLayoutBorderSpacePx = new Point(mResponsiveFolderWidthSpec.getGutterPx(),
Thales Lima4cfd9502023-07-10 14:01:28 +01001437 mResponsiveFolderHeightSpec.getGutterPx());
Jordan Silva637f4eb2023-06-13 11:21:53 +01001438
1439 folderContentPaddingLeftRight = mResponsiveFolderWidthSpec.getStartPaddingPx();
Jordan Silva12fae112023-06-26 12:51:01 +01001440
1441 // Reduce icon width if it's wider than the expected folder cell width
1442 if (folderCellWidthPx < folderChildIconSizePx) {
1443 folderChildIconSizePx = mIconSizeSteps.getIconSmallerThan(folderCellWidthPx);
1444 }
1445
1446 // Recalculating padding and cell height
Jordan Silva3e5688a2023-12-05 15:12:29 -03001447 folderChildDrawablePaddingPx = mResponsiveWorkspaceCellSpec.getIconDrawablePadding();
Jordan Silva12fae112023-06-26 12:51:01 +01001448
Thales Limae9b5e142023-11-04 17:10:13 +00001449 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1450 folderChildIconSizePx,
1451 folderChildDrawablePaddingPx,
1452 folderChildTextSizePx);
1453 cellContentDimensions.resizeToFitCellHeight(folderCellHeightPx, mIconSizeSteps);
1454 folderChildIconSizePx = cellContentDimensions.getIconSizePx();
1455 folderChildDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1456 folderChildTextSizePx = cellContentDimensions.getIconTextSizePx();
Jordan Silva999dd2a2023-11-17 19:31:43 +00001457 folderLabelTextSizePx = Math.max(minLabelTextSize,
Jordan Silva9a3bd8f2023-11-16 18:33:28 +00001458 (int) (folderChildTextSizePx * folderLabelTextScale));
Jordan Silva999dd2a2023-11-17 19:31:43 +00001459 return;
1460 }
1461
1462 float invIconSizeDp = inv.iconSize[mTypeIndex];
1463 float invIconTextSizeDp = inv.iconTextSize[mTypeIndex];
1464 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1465 folderChildTextSizePx = pxFromSp(invIconTextSizeDp, mMetrics, scale);
1466 folderLabelTextSizePx = Math.max(minLabelTextSize,
1467 (int) (folderChildTextSizePx * folderLabelTextScale));
1468 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
1469
1470 if (mIsScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001471 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
Thales Lima7eee74b2023-03-16 16:00:55 -03001472 folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale);
1473 folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale);
1474 } else {
1475 folderCellWidthPx = roundPxValueFromFloat(folderCellWidthPx * scale);
1476 folderCellHeightPx = roundPxValueFromFloat(folderCellHeightPx * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001477 }
Charlie Anderson7bb10972023-11-22 13:35:30 -08001478 // Recalculating padding and cell height
1479 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
1480
1481 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1482 folderChildIconSizePx,
1483 folderChildDrawablePaddingPx,
1484 folderChildTextSizePx);
1485 cellContentDimensions.resizeToFitCellHeight(folderCellHeightPx, mIconSizeSteps);
1486 folderChildIconSizePx = cellContentDimensions.getIconSizePx();
1487 folderChildDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1488 folderChildTextSizePx = cellContentDimensions.getIconTextSizePx();
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001489
Thales Lima7eee74b2023-03-16 16:00:55 -03001490 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001491 folderCellLayoutBorderSpacePx = new Point(
1492 roundPxValueFromFloat(folderCellLayoutBorderSpacePx.x * scale),
1493 roundPxValueFromFloat(folderCellLayoutBorderSpacePx.y * scale)
1494 );
Thales Lima7eee74b2023-03-16 16:00:55 -03001495 folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001496 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx.x;
Jon Miranda823da222021-03-23 08:08:45 -04001497 } else {
1498 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1499 * scale);
1500 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1501 * scale);
1502
1503 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1504 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Lima7eee74b2023-03-16 16:00:55 -03001505 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001506 folderContentPaddingLeftRight =
1507 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1508 folderFooterHeightPx =
Thales Lima7eee74b2023-03-16 16:00:55 -03001509 roundPxValueFromFloat(
1510 res.getDimensionPixelSize(R.dimen.folder_footer_height_default)
1511 * scale);
1512
Jordan Silva12fae112023-06-26 12:51:01 +01001513 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
Jon Miranda823da222021-03-23 08:08:45 -04001514 }
Jon Mirandabf7d8122016-11-03 15:29:29 -07001515 }
1516
Winson1f064272016-07-18 17:18:02 -07001517 public void updateInsets(Rect insets) {
1518 mInsets.set(insets);
1519 }
1520
Sunny Goyalae6e3182019-04-30 12:04:37 -07001521 /**
1522 * The current device insets. This is generally same as the insets being dispatched to
1523 * {@link Insettable} elements, but can differ if the element is using a different profile.
1524 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001525 public Rect getInsets() {
1526 return mInsets;
1527 }
1528
Sunny Goyal756cd262015-08-20 12:33:21 -07001529 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001530 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001531 }
1532
Sunny Goyal19ff7282021-04-22 10:12:54 -07001533 public Point getCellSize(Point result) {
1534 if (result == null) {
1535 result = new Point();
1536 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001537
Pat Manning25d53342022-05-10 09:58:49 +00001538 int shortcutAndWidgetContainerWidth =
1539 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1540 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1541 inv.numColumns);
1542 int shortcutAndWidgetContainerHeight =
1543 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1544 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1545 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001546 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001547 }
1548
1549 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001550 * Returns the left and right space on the cell, which is the cell width - icon size
1551 */
1552 public int getCellHorizontalSpace() {
1553 return getCellSize().x - iconSizePx;
1554 }
1555
1556 /**
Pat Manning25d53342022-05-10 09:58:49 +00001557 * Gets the number of panels within the workspace.
1558 */
1559 public int getPanelCount() {
1560 return isTwoPanels ? 2 : 1;
1561 }
1562
1563 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001564 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1565 * bottom of the screen.
1566 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001567 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1568 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001569 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001570 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001571 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001572 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001573 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001574 }
1575
1576 /**
1577 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1578 */
Pat Manning25d53342022-05-10 09:58:49 +00001579 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001580 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001581 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001582 }
1583
1584 /**
1585 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1586 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001587 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001588 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001589 return heightPx - (isVerticalBarLayout()
1590 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001591 }
1592
Pat Manningea5c1d22022-04-14 10:58:16 +01001593 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001594 * Gets the scale of the workspace for the spring-loaded edit state.
1595 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001596 public float getWorkspaceSpringLoadScale(Context context) {
1597 float scale =
1598 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1599 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001600 scale = Math.min(scale, 1f);
1601
Pat Manninge63dd252022-08-02 16:15:29 +01001602 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001603 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001604 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001605 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001606 if (scaledWorkspaceWidth > maxAvailableWidth) {
1607 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1608 }
1609 return scale;
1610 }
1611
Pat Manning25d53342022-05-10 09:58:49 +00001612 /**
1613 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1614 *
1615 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1616 * layouts have two Cell Layouts per workspace.
1617 */
1618 public int getCellLayoutWidth() {
1619 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001620 }
1621
Pat Manning25d53342022-05-10 09:58:49 +00001622 /**
1623 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1624 *
1625 * <p>This is the height of a Workspace, less its vertical padding.
1626 */
1627 public int getCellLayoutHeight() {
1628 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001629 }
1630
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001631 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001632 return new Point(workspacePadding.left + workspacePadding.right,
1633 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001634 }
1635
1636 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001637 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1638 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001639 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001640 private void updateWorkspacePadding() {
1641 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001642 if (isVerticalBarLayout()) {
Jordan Silva3646a1b2023-08-02 13:52:52 +01001643 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001644 padding.top = mResponsiveWorkspaceHeightSpec.getStartPaddingPx();
Thales Lima8e11d532023-08-31 13:40:26 +00001645 padding.bottom = Math.max(0,
Jordan Silva8f7986a2023-11-08 12:11:25 +00001646 mResponsiveWorkspaceHeightSpec.getEndPaddingPx() - mInsets.bottom);
Jordan Silva3646a1b2023-08-02 13:52:52 +01001647 if (isSeascape()) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001648 padding.left =
1649 hotseatBarSizePx + mResponsiveWorkspaceWidthSpec.getEndPaddingPx();
1650 padding.right = mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
Jordan Silva3646a1b2023-08-02 13:52:52 +01001651 } else {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001652 padding.left = mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
1653 padding.right =
1654 hotseatBarSizePx + mResponsiveWorkspaceWidthSpec.getEndPaddingPx();
Jordan Silva3646a1b2023-08-02 13:52:52 +01001655 }
Winson1f064272016-07-18 17:18:02 -07001656 } else {
Jordan Silva3646a1b2023-08-02 13:52:52 +01001657 padding.top = 0;
1658 padding.bottom = edgeMarginPx;
1659 if (isSeascape()) {
1660 padding.left = hotseatBarSizePx;
Thales Lima8e11d532023-08-31 13:40:26 +00001661 padding.right = mHotseatBarEdgePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001662 } else {
Thales Lima8e11d532023-08-31 13:40:26 +00001663 padding.left = mHotseatBarEdgePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001664 padding.right = hotseatBarSizePx;
1665 }
Winson1f064272016-07-18 17:18:02 -07001666 }
Winson Chungb3800242013-10-24 11:01:54 -07001667 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001668 // Pad the bottom of the workspace with hotseat bar
1669 // and leave a bit of space in case a widget go all the way down
Thales Lima79456492023-05-23 11:32:22 +01001670 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding - mInsets.bottom;
1671 if (!mIsResponsiveGrid) {
1672 paddingBottom +=
1673 workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace;
1674 }
1675 int paddingTop = workspaceTopPadding + (mIsScalableGrid ? 0 : edgeMarginPx);
Pat Manning08610ca2022-04-05 21:03:16 +01001676 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001677
Pat Manning08610ca2022-04-05 21:03:16 +01001678 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001679 }
Pat Manning08610ca2022-04-05 21:03:16 +01001680 insetPadding(workspacePadding, cellLayoutPaddingPx);
1681 }
1682
1683 private void insetPadding(Rect paddings, Rect insets) {
1684 insets.left = Math.min(insets.left, paddings.left);
1685 paddings.left -= insets.left;
1686
1687 insets.top = Math.min(insets.top, paddings.top);
1688 paddings.top -= insets.top;
1689
1690 insets.right = Math.min(insets.right, paddings.right);
1691 paddings.right -= insets.right;
1692
1693 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1694 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001695 }
1696
Liran Binyamina833af32023-08-02 16:30:27 -04001697
1698 /**
1699 * Returns the new border space that should be used between hotseat icons after adjusting it to
1700 * the bubble bar.
1701 *
1702 * <p>If there's no adjustment needed, this method returns {@code 0}.
1703 */
1704 public float getHotseatAdjustedBorderSpaceForBubbleBar(Context context) {
1705 // only need to adjust when QSB is on top of the hotseat.
1706 if (isQsbInline) {
1707 return 0;
1708 }
1709
1710 // no need to adjust if there's enough space for the bubble bar to the right of the hotseat.
1711 if (getHotseatLayoutPadding(context).right > mBubbleBarSpaceThresholdPx) {
1712 return 0;
1713 }
1714
1715 // The adjustment is shrinking the hotseat's width by 1 icon on either side.
1716 int iconsWidth =
1717 iconSizePx * numShownHotseatIcons + hotseatBorderSpace * (numShownHotseatIcons - 1);
1718 int newWidth = iconsWidth - 2 * iconSizePx;
1719 // Evenly space the icons within the boundaries of the new width.
1720 return (float) (newWidth - iconSizePx * numShownHotseatIcons) / (numShownHotseatIcons - 1);
1721 }
1722
Sunny Goyal57b22792021-05-25 14:35:01 -07001723 /**
1724 * Returns the padding for hotseat view
1725 */
1726 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001727 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001728 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001729 // The hotseat icons will be placed in the middle of the hotseat cells.
1730 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1731 // in vertical bar layout.
1732 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1733 // is set to account for that difference.
Jordan Silva3646a1b2023-08-02 13:52:52 +01001734 float diffOverlapFactor = mIsResponsiveGrid ? 0
1735 : iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
1736
Pat Manning08610ca2022-04-05 21:03:16 +01001737 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1738 - diffOverlapFactor), 0);
1739 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001740 + diffOverlapFactor), 0);
1741
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001742 if (isSeascape()) {
Thales Lima8e11d532023-08-31 13:40:26 +00001743 hotseatBarPadding.set(mInsets.left + mHotseatBarEdgePaddingPx, paddingTop,
1744 mHotseatBarWorkspaceSpacePx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001745 } else {
Thales Lima8e11d532023-08-31 13:40:26 +00001746 hotseatBarPadding.set(mHotseatBarWorkspaceSpacePx, paddingTop,
1747 mInsets.right + mHotseatBarEdgePaddingPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001748 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001749 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001750 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001751 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1752 int hotseatBarTopPadding =
1753 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001754
Thales Lima6a590062022-11-22 15:52:49 +00001755 int hotseatWidth = getHotseatRequiredWidth();
Helen Cheuke76291f2023-02-14 17:11:05 +00001756 int startSpacing;
1757 int endSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001758 // Hotseat aligns to the left with nav buttons
1759 if (hotseatBarEndOffset > 0) {
Jon Mirandae17a9492023-03-08 16:42:20 -08001760 startSpacing = inlineNavButtonsEndSpacingPx;
Helen Cheuke76291f2023-02-14 17:11:05 +00001761 endSpacing = availableWidthPx - hotseatWidth - startSpacing + hotseatBorderSpace;
1762 } else {
1763 startSpacing = (availableWidthPx - hotseatWidth) / 2;
1764 endSpacing = startSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001765 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001766 startSpacing += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001767
Helen Cheuke76291f2023-02-14 17:11:05 +00001768 hotseatBarPadding.top = hotseatBarTopPadding;
1769 hotseatBarPadding.bottom = hotseatBarBottomPadding;
Alex Chau51da2192022-05-20 13:32:10 +01001770 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001771 if (isRtl) {
Helen Cheuke76291f2023-02-14 17:11:05 +00001772 hotseatBarPadding.left = endSpacing;
1773 hotseatBarPadding.right = startSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001774 } else {
Helen Cheuke76291f2023-02-14 17:11:05 +00001775 hotseatBarPadding.left = startSpacing;
1776 hotseatBarPadding.right = endSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001777 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001778
Thales Lima79456492023-05-23 11:32:22 +01001779 } else if (mIsScalableGrid) {
fbarone69b6f42023-12-18 13:20:34 -08001780 int iconExtraSpacePx = iconSizePx - getIconVisibleSizePx(iconSizePx);
1781 int sideSpacing = (availableWidthPx - (hotseatQsbWidth + iconExtraSpacePx)) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001782 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001783 0,
Thales Lima425f6822022-05-10 13:44:58 -03001784 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001785 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001786 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001787 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1788 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1789 // for this, we pad the left and right of the hotseat with half of the difference of a
1790 // workspace cell vs a hotseat cell.
1791 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001792 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001793 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001794 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001795 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1796 + mInsets.left,
1797 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001798 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001799 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001800 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001801 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001802 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001803 }
1804
Andy Wickhambd9a1802023-06-08 16:33:15 -07001805 /** The margin between the edge of all apps and the edge of the first icon. */
Thales Limab433c9c2023-10-30 12:24:05 +00001806 public int getAllAppsIconStartMargin(Context context) {
Andy Wickhambd9a1802023-06-08 16:33:15 -07001807 int allAppsSpacing;
1808 if (isVerticalBarLayout()) {
1809 // On phones, the landscape layout uses a different setup.
1810 allAppsSpacing = workspacePadding.left + workspacePadding.right;
1811 } else {
Thales Limab433c9c2023-10-30 12:24:05 +00001812 allAppsSpacing =
1813 allAppsPadding.left + allAppsPadding.right + allAppsLeftRightMargin * 2;
Andy Wickhambd9a1802023-06-08 16:33:15 -07001814 }
1815
1816 int cellWidth = DeviceProfile.calculateCellWidth(
1817 availableWidthPx - allAppsSpacing,
1818 0 /* borderSpace */,
1819 numShownAllAppsColumns);
fbarone69b6f42023-12-18 13:20:34 -08001820 int iconAlignmentMargin = (cellWidth - getIconVisibleSizePx(allAppsIconSizePx)) / 2;
Thales Limab433c9c2023-10-30 12:24:05 +00001821
1822 return (Utilities.isRtl(context.getResources()) ? allAppsPadding.right
1823 : allAppsPadding.left) + iconAlignmentMargin;
Andy Wickhambd9a1802023-06-08 16:33:15 -07001824 }
1825
fbarone69b6f42023-12-18 13:20:34 -08001826 /**
1827 * TODO(b/235886078): workaround needed because of this bug
1828 * Icons are 10% larger on XML than their visual size, so remove that extra space to get
1829 * some dimensions correct.
1830 *
1831 * When this bug is resolved this method will no longer be needed and we would be able to
1832 * replace all instances where this method is called with iconSizePx.
1833 */
1834 private int getIconVisibleSizePx(int iconSizePx) {
1835 return Math.round(ICON_VISIBLE_AREA_FACTOR * iconSizePx);
1836 }
1837
Thales Lima9938c2f2022-07-25 14:38:16 +01001838 private int getAdditionalQsbSpace() {
1839 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1840 }
1841
1842 /**
1843 * Calculate how much space the hotseat needs to be shown completely
1844 */
1845 private int getHotseatRequiredWidth() {
1846 int additionalQsbSpace = getAdditionalQsbSpace();
1847 return iconSizePx * numShownHotseatIcons
Thales Lima6a590062022-11-22 15:52:49 +00001848 + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1))
Thales Lima9938c2f2022-07-25 14:38:16 +01001849 + additionalQsbSpace;
1850 }
1851
Winsonfadbe8f2016-07-22 16:35:37 -07001852 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001853 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1854 */
1855 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001856 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001857 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1858 } else if (isTaskbarPresent) { // QSB on top
1859 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001860 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001861 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001862 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001863 }
1864
Thales Limab8c05952022-05-23 16:58:38 +01001865 /**
1866 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1867 */
1868 private int getHotseatBarBottomPadding() {
1869 if (isTaskbarPresent) { // QSB on top or inline
1870 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001871 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001872 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001873 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001874 }
1875
1876 /**
Alex Chau51da2192022-05-20 13:32:10 +01001877 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1878 */
1879 public int getTaskbarOffsetY() {
Jon Miranda9c478b62023-03-23 21:38:49 -07001880 int taskbarIconBottomSpace = (taskbarHeight - iconSizePx) / 2;
Alex Chau51da2192022-05-20 13:32:10 +01001881 int launcherIconBottomSpace =
1882 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001883 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001884 }
1885
Uwais Ashrafaa7fa882023-10-10 21:36:06 +00001886 /** Returns the number of pixels required below OverviewActions. */
Alex Chaua2fc7642022-04-21 14:20:23 +01001887 public int getOverviewActionsClaimedSpaceBelow() {
Uwais Ashrafaa7fa882023-10-10 21:36:06 +00001888 return isTaskbarPresent ? mTransientTaskbarClaimedSpace : mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001889 }
1890
1891 /** Gets the space that the overview actions will take, including bottom margin. */
1892 public int getOverviewActionsClaimedSpace() {
Alex Chau4989f4f2023-10-11 14:08:22 +00001893 int overviewActionsSpace = isTablet && Flags.enableGridOnlyOverview()
Pat Manning7b8f7662023-01-18 14:48:30 +00001894 ? 0
1895 : (overviewActionsTopMarginPx + overviewActionsHeight);
1896 return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
Alex Chaua2fc7642022-04-21 14:20:23 +01001897 }
1898
1899 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001900 * Takes the View and return the scales of width and height depending on the DeviceProfile
1901 * specifications
1902 *
1903 * @param itemInfo The tag of the widget view
1904 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1905 * height
1906 */
1907 @NonNull
1908 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1909 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1910 }
1911
1912 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001913 * @return the bounds for which the open folders should be contained within
1914 */
1915 public Rect getAbsoluteOpenFolderBounds() {
1916 if (isVerticalBarLayout()) {
1917 // Folders should only appear right of the drop target bar and left of the hotseat
1918 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1919 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001920 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001921 mInsets.top + availableHeightPx);
1922 } else {
1923 // Folders should only appear below the drop target bar and above the hotseat
Jon Miranda9c478b62023-03-23 21:38:49 -07001924 int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001925 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001926 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001927 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001928 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001929 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001930 }
1931 }
1932
Jon Miranda228877d2021-02-09 11:05:00 -05001933 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1934 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001935 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001936
Jon Miranda228877d2021-02-09 11:05:00 -05001937 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1938 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001939 }
1940
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001941 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001942 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1943 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1944 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001945 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001946 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001947 return isLandscape && transposeLayoutWithOrientation;
1948 }
1949
Sunny Goyal59d086c2018-05-07 17:31:40 -07001950 /**
1951 * Updates orientation information and returns true if it has changed from the previous value.
1952 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001953 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001954 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001955 boolean isSeascape = DisplayController.INSTANCE.get(context)
1956 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001957 if (mIsSeascape != isSeascape) {
1958 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001959 // Hotseat changing sides requires updating workspace left/right paddings
1960 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001961 return true;
1962 }
1963 }
1964 return false;
1965 }
1966
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001967 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001968 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001969 }
1970
Sunny Goyal07b69292018-01-08 14:19:34 -08001971 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001972 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001973 }
1974
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001975 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001976 switch (containerType) {
1977 case CellLayout.WORKSPACE:
1978 return cellHeightPx;
1979 case CellLayout.FOLDER:
1980 return folderCellHeightPx;
1981 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001982 // The hotseat is the only container where the cell height is going to be
1983 // different from the content within that cell.
1984 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001985 default:
1986 // ??
1987 return 0;
1988 }
1989 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001990
Jon Miranda58561d42021-03-17 10:51:54 -04001991 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001992 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001993 }
1994
Alex Chaue818bcb2022-09-02 17:27:11 +01001995 private String dpPointFToString(String name, PointF value) {
1996 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
1997 }
1998
Pat Manning5f74bfd2022-07-20 12:08:54 +01001999 /** Dumps various DeviceProfile variables to the specified writer. */
2000 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04002001 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07002002 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04002003
2004 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04002005 writer.println(prefix + "\tisPhone:" + isPhone);
2006 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
2007 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00002008 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04002009
2010 writer.println(prefix + "\tisLandscape:" + isLandscape);
2011 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07002012 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Winson Chung104a4c82023-11-08 18:56:15 +00002013 writer.println(prefix + "\tisLeftRightSplit:" + isLeftRightSplit);
Jon Miranda58561d42021-03-17 10:51:54 -04002014
2015 writer.println(prefix + pxToDpStr("windowX", windowX));
2016 writer.println(prefix + pxToDpStr("windowY", windowY));
2017 writer.println(prefix + pxToDpStr("widthPx", widthPx));
2018 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002019 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
2020 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01002021 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
2022 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
2023 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
2024 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04002025
2026 writer.println(prefix + "\taspectRatio:" + aspectRatio);
2027
Thales Limac98b7812023-04-14 15:04:23 +01002028 writer.println(prefix + "\tisResponsiveGrid:" + mIsResponsiveGrid);
Thales Lima79456492023-05-23 11:32:22 +01002029 writer.println(prefix + "\tisScalableGrid:" + mIsScalableGrid);
Jon Miranda58561d42021-03-17 10:51:54 -04002030
Thales Lima83bedbf2021-10-05 17:47:39 +01002031 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00002032 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
2033 writer.println(prefix + "\tinv.numSearchContainerColumns: "
2034 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04002035
Alex Chaue818bcb2022-09-02 17:27:11 +01002036 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07002037
Jon Miranda58561d42021-03-17 10:51:54 -04002038 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
2039 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
2040
2041 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
2042 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
2043
Thales Lima83bedbf2021-10-05 17:47:39 +01002044 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
2045 cellLayoutBorderSpacePx.x));
2046 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
2047 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002048 writer.println(
2049 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
2050 writer.println(
2051 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
2052 writer.println(
2053 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01002054 writer.println(
2055 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01002056
Jon Miranda58561d42021-03-17 10:51:54 -04002057 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
2058 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
2059 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
2060
Thales Lima1faa4ed2023-12-01 16:48:19 +00002061 writer.println(prefix + "\tnumFolderRows: " + numFolderRows);
2062 writer.println(prefix + "\tnumFolderColumns: " + numFolderColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04002063 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
2064 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
2065 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
2066 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
2067 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
2068 folderChildDrawablePaddingPx));
Jordan Silva637f4eb2023-06-13 11:21:53 +01002069 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.x",
2070 folderCellLayoutBorderSpacePx.x));
2071 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.y",
2072 folderCellLayoutBorderSpacePx.y));
Thales Limaa08a4432022-08-09 09:55:17 +01002073 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
2074 folderContentPaddingLeftRight));
2075 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03002076 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002077
Alex Chaue0227552022-04-06 19:44:43 +01002078 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01002079 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
2080 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
2081 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
2082 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01002083
2084 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
Alex Chau3d2c0622022-09-01 21:28:14 +01002085 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
2086 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04002087 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
2088 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
2089 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
2090 allAppsIconDrawablePaddingPx));
2091 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00002092 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01002093 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
2094 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07002095 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Thales Limab433c9c2023-10-30 12:24:05 +00002096 writer.println(prefix + pxToDpStr("allAppsPadding.top", allAppsPadding.top));
2097 writer.println(prefix + pxToDpStr("allAppsPadding.left", allAppsPadding.left));
2098 writer.println(prefix + pxToDpStr("allAppsPadding.right", allAppsPadding.right));
Alex Chau27b39b92022-01-14 18:02:18 +00002099 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04002100
2101 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03002102 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04002103 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00002104 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Thales Lima8e11d532023-08-31 13:40:26 +00002105 writer.println(prefix + pxToDpStr("mHotseatBarEdgePaddingPx",
2106 mHotseatBarEdgePaddingPx));
2107 writer.println(prefix + pxToDpStr("mHotseatBarWorkspaceSpacePx",
2108 mHotseatBarWorkspaceSpacePx));
Pat Manning26f70f72022-07-07 13:50:39 +01002109 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01002110 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
2111 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01002112 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
2113 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002114 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
2115 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
2116 hotseatLayoutPadding.top));
2117 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
2118 hotseatLayoutPadding.bottom));
2119 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
2120 hotseatLayoutPadding.left));
2121 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
2122 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07002123 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00002124 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00002125 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01002126 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04002127
2128 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10002129 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda9c478b62023-03-23 21:38:49 -07002130 writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight));
2131 writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight));
2132 writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin));
2133 writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize));
Jon Miranda58561d42021-03-17 10:51:54 -04002134
Thales Lima83bedbf2021-10-05 17:47:39 +01002135 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
2136 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002137 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
2138 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
2139 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00002140 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04002141
Jon Mirandaab3c6812021-06-28 15:42:28 -07002142 writer.println(prefix + pxToDpStr("iconScale", iconScale));
2143 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04002144 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00002145 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04002146
Thales Lima171ee662022-11-22 15:52:49 +00002147 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04002148 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
2149 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00002150
2151 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00002152 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
2153 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
2154 overviewTaskIconDrawableSizePx));
2155 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
2156 overviewTaskIconDrawableSizeGridPx));
Pat Manning1695cc72023-07-05 11:45:13 +01002157 writer.println(prefix + pxToDpStr("overviewTaskIconAppChipMenuDrawableSizePx",
2158 overviewTaskIconAppChipMenuDrawableSizePx));
Alex Chau635b3ab2022-01-26 16:49:10 +00002159 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
2160 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01002161 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
2162 overviewActionsTopMarginPx));
2163 writer.println(prefix + pxToDpStr("overviewActionsHeight",
2164 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00002165 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
2166 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00002167 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
2168 overviewActionsButtonSpacing));
2169 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
2170 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
2171 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01002172
Alex Chau62572c02022-07-25 18:36:37 +00002173 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01002174 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00002175 writer.println(
2176 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01002177
Pat Manning5f74bfd2022-07-20 12:08:54 +01002178 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
2179 getCellLayoutSpringLoadShrunkTop()));
2180 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
2181 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01002182 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
2183 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002184 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
2185 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01002186 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
2187 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Thales Lima79456492023-05-23 11:32:22 +01002188 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00002189 writer.println(prefix + "\tmResponsiveWorkspaceHeightSpec:"
2190 + mResponsiveWorkspaceHeightSpec.toString());
2191 writer.println(prefix + "\tmResponsiveWorkspaceWidthSpec:"
2192 + mResponsiveWorkspaceWidthSpec.toString());
2193 writer.println(prefix + "\tmResponsiveAllAppsHeightSpec:"
2194 + mResponsiveAllAppsHeightSpec.toString());
2195 writer.println(prefix + "\tmResponsiveAllAppsWidthSpec:"
2196 + mResponsiveAllAppsWidthSpec.toString());
Jordan Silva637f4eb2023-06-13 11:21:53 +01002197 writer.println(prefix + "\tmResponsiveFolderHeightSpec:" + mResponsiveFolderHeightSpec);
2198 writer.println(prefix + "\tmResponsiveFolderWidthSpec:" + mResponsiveFolderWidthSpec);
Thales Limaf8bfb032023-07-24 15:08:05 +01002199 writer.println(prefix + "\tmResponsiveHotseatSpec:" + mResponsiveHotseatSpec);
Jordan Silva999dd2a2023-11-17 19:31:43 +00002200 writer.println(prefix + "\tmResponsiveWorkspaceCellSpec:"
2201 + mResponsiveWorkspaceCellSpec);
2202 writer.println(prefix + "\tmResponsiveAllAppsCellSpec:" + mResponsiveAllAppsCellSpec);
Thales Lima79456492023-05-23 11:32:22 +01002203 }
Jon Miranda58561d42021-03-17 10:51:54 -04002204 }
2205
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00002206 /** Returns a reduced representation of this DeviceProfile. */
2207 public String toSmallString() {
2208 return "isTablet:" + isTablet + ", "
2209 + "isMultiDisplay:" + isMultiDisplay + ", "
2210 + "widthPx:" + widthPx + ", "
2211 + "heightPx:" + heightPx + ", "
2212 + "insets:" + mInsets + ", "
2213 + "rotationHint:" + rotationHint;
2214 }
2215
Alex Chaua6907dc2022-03-18 15:24:07 +00002216 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07002217 Configuration config = new Configuration(c.getResources().getConfiguration());
2218 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03002219 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00002220 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07002221 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07002222 }
Sunny Goyalfde55052018-02-01 14:46:13 -08002223
2224 /**
2225 * Callback when a component changes the DeviceProfile associated with it, as a result of
2226 * configuration change
2227 */
2228 public interface OnDeviceProfileChangeListener {
2229
2230 /**
2231 * Called when the device profile is reassigned. Note that for layout and measurements, it
2232 * is sufficient to listen for inset changes. Use this callback when you need to perform
2233 * a one time operation.
2234 */
2235 void onDeviceProfileChanged(DeviceProfile dp);
2236 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002237
Sihua Mae04aa202022-07-18 12:43:56 -07002238 /**
2239 * Handler that deals with ItemInfo of the views for the DeviceProfile
2240 */
2241 @FunctionalInterface
2242 public interface ViewScaleProvider {
2243 /**
2244 * Get the scales from the view
2245 *
2246 * @param itemInfo The tag of the widget view
2247 * @return PointF instance containing the scale information, or null if using the default
2248 * app widget scale of this device profile.
2249 */
2250 @NonNull
2251 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
2252 }
2253
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002254 public static class Builder {
2255 private Context mContext;
2256 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07002257 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002258
Sunny Goyal19ff7282021-04-22 10:12:54 -07002259 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00002260 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002261
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002262 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07002263 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00002264 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07002265 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002266
Sunny Goyal65190ae2022-08-02 14:16:26 -07002267 private SparseArray<DotRenderer> mDotRendererCache;
2268
Jon Miranda2b25ded2023-02-02 14:48:45 -08002269 private Consumer<DeviceProfile> mOverrideProvider;
2270
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002271 private boolean mIsTransientTaskbar;
2272
Sunny Goyalfd58da62020-08-11 12:06:49 -07002273 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002274 mContext = context;
2275 mInv = inv;
2276 mInfo = info;
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002277 mIsTransientTaskbar = info.isTransientTaskbar();
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002278 }
2279
2280 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
2281 mIsMultiWindowMode = isMultiWindowMode;
2282 return this;
2283 }
2284
Alex Chauab800f72022-12-13 17:46:06 +00002285 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
2286 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07002287 return this;
2288 }
2289
Sunny Goyal65190ae2022-08-02 14:16:26 -07002290 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
2291 mDotRendererCache = dotRendererCache;
2292 return this;
2293 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07002294
2295 public Builder setWindowBounds(WindowBounds bounds) {
2296 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07002297 return this;
2298 }
2299
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002300 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
2301 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
2302 return this;
2303 }
2304
Alex Chau6ed408f2022-03-04 12:58:05 +00002305 public Builder setGestureMode(boolean isGestureMode) {
2306 mIsGestureMode = isGestureMode;
2307 return this;
2308 }
2309
Jon Miranda2b25ded2023-02-02 14:48:45 -08002310 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
2311 mOverrideProvider = overrideProvider;
2312 return this;
2313 }
2314
Sihua Mae04aa202022-07-18 12:43:56 -07002315 /**
2316 * Set the viewScaleProvider for the builder
2317 *
2318 * @param viewScaleProvider The viewScaleProvider to be set for the
Thales Limae9273ea2023-01-26 12:33:52 +00002319 * DeviceProfile
Sihua Mae04aa202022-07-18 12:43:56 -07002320 * @return This builder
2321 */
2322 @NonNull
2323 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
2324 mViewScaleProvider = viewScaleProvider;
2325 return this;
2326 }
2327
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002328 /**
2329 * Set the isTransientTaskbar for the builder
2330 * @return This Builder
2331 */
2332 public Builder setIsTransientTaskbar(boolean isTransientTaskbar) {
2333 mIsTransientTaskbar = isTransientTaskbar;
2334 return this;
2335 }
2336
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002337 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07002338 if (mWindowBounds == null) {
2339 throw new IllegalArgumentException("Window bounds not set");
2340 }
2341 if (mTransposeLayoutWithOrientation == null) {
2342 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
2343 }
Alex Chau6ed408f2022-03-04 12:58:05 +00002344 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01002345 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00002346 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002347 if (mDotRendererCache == null) {
2348 mDotRendererCache = new SparseArray<>();
2349 }
Sihua Mae04aa202022-07-18 12:43:56 -07002350 if (mViewScaleProvider == null) {
2351 mViewScaleProvider = DEFAULT_PROVIDER;
2352 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08002353 if (mOverrideProvider == null) {
2354 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
2355 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002356 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00002357 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002358 mIsGestureMode, mViewScaleProvider, mOverrideProvider, mIsTransientTaskbar);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002359 }
2360 }
Winson Chungb3800242013-10-24 11:01:54 -07002361}