blob: 72d22137eaab0421b3b36c264d764c1c3797ac5f [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,
Thales Limaa25cd902023-11-01 12:00:32 +0000643 DimensionType.HEIGHT, inv.numRows, heightPx - mInsets.top,
Jordan Silva8f7986a2023-11-08 12:11:25 +0000644 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
Jordan Silva3646a1b2023-08-02 13:52:52 +0100991 if (mIsResponsiveGrid) {
Thales Limabba07722023-10-11 18:16:29 +0000992 iconTextSizePx = 0;
993 iconDrawablePaddingPx = 0;
994 int iconSizeWithOverlap = getIconSizeWithOverlap(iconSizePx);
995 cellYPaddingPx = Math.max(0, getCellSize().y - iconSizeWithOverlap) / 2;
996 autoResizeAllAppsCells();
Jordan Silva3646a1b2023-08-02 13:52:52 +0100997
998 return;
999 }
1000
Jon Miranda941375e2021-03-31 13:10:45 -04001001 // We want enough space so that the text is closer to its corresponding icon.
1002 if (workspaceCellPaddingY < iconTextHeight) {
1003 iconTextSizePx = 0;
1004 iconDrawablePaddingPx = 0;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001005 cellHeightPx = getIconSizeWithOverlap(iconSizePx);
Jon Miranda941375e2021-03-31 13:10:45 -04001006 autoResizeAllAppsCells();
1007 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001008 }
Jon Miranda1091e532017-07-21 13:31:50 -07001009
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001010 /**
Jon Miranda228877d2021-02-09 11:05:00 -05001011 * Returns the amount of extra (or unused) vertical space.
1012 */
1013 private int updateAvailableDimensions(Resources res) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001014 iconCenterVertically = mIsScalableGrid || mIsResponsiveGrid;
1015
1016 if (mIsResponsiveGrid) {
Jordan Silva15cacd52023-11-28 14:32:05 +00001017 iconSizePx = mResponsiveWorkspaceCellSpec.getIconSize();
1018 iconTextSizePx = mResponsiveWorkspaceCellSpec.getIconTextSize();
1019 mIconDrawablePaddingOriginalPx = mResponsiveWorkspaceCellSpec.getIconDrawablePadding();
Jordan Silva999dd2a2023-11-17 19:31:43 +00001020 updateIconSize(1f, res);
1021 updateWorkspacePadding();
1022 return 0;
1023 }
1024
Alex Chaua68164d2022-12-15 16:16:03 +00001025 float invIconSizeDp = inv.iconSize[mTypeIndex];
1026 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
1027 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
1028 iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
1029
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001030 updateIconSize(1f, res);
Pat Manning08610ca2022-04-05 21:03:16 +01001031 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -05001032
1033 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +01001034 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +00001035 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -05001036 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -05001037 float scaleY = maxHeight / usedHeight;
1038 boolean shouldScale = scaleY < 1f;
1039
1040 float scaleX = 1f;
Thales Lima79456492023-05-23 11:32:22 +01001041 if (mIsScalableGrid) {
Jon Mirandae126d722021-02-25 10:45:20 -05001042 // We scale to fit the cellWidth and cellHeight in the available space.
1043 // The benefit of scalable grids is that we can get consistent aspect ratios between
1044 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +01001045 float usedWidth =
1046 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -05001047 // We do not subtract padding here, as we also scale the workspace padding if needed.
1048 scaleX = availableWidthPx / usedWidth;
1049 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -07001050 }
Jon Mirandae126d722021-02-25 10:45:20 -05001051
1052 if (shouldScale) {
1053 float scale = Math.min(scaleX, scaleY);
1054 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +01001055 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -05001056 }
1057
Jon Miranda228877d2021-02-09 11:05:00 -05001058 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -07001059 }
1060
Pat Manninga2e14992022-04-22 11:29:17 +01001061 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +01001062 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
1063 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
1064 }
1065
Pat Manninga2e14992022-04-22 11:29:17 +01001066 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +00001067 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +01001068 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
1069 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -05001070 }
1071
Jordan Silva376036a2023-11-08 15:56:40 +00001072 private int getNormalizedIconDrawablePadding(int iconSizePx, int iconDrawablePadding) {
fbarone69b6f42023-12-18 13:20:34 -08001073 return Math.max(0, iconDrawablePadding
1074 - ((iconSizePx - getIconVisibleSizePx(iconSizePx)) / 2));
Jordan Silva376036a2023-11-08 15:56:40 +00001075 }
1076
1077 private int getNormalizedIconDrawablePadding() {
1078 return getNormalizedIconDrawablePadding(iconSizePx, mIconDrawablePaddingOriginalPx);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001079 }
1080
1081 private int getNormalizedFolderChildDrawablePaddingPx(int textHeight) {
1082 // TODO(b/235886078): workaround needed because of this bug
1083 // Icons are 10% larger on XML than their visual size,
1084 // so remove that extra space to get labels closer to the correct padding
1085 int drawablePadding = (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3;
1086
fbarone69b6f42023-12-18 13:20:34 -08001087 int iconSizeDiff = folderChildIconSizePx - getIconVisibleSizePx(folderChildIconSizePx);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001088 return Math.max(0, drawablePadding - iconSizeDiff / 2);
1089 }
1090
Jordan Silva3646a1b2023-08-02 13:52:52 +01001091 private int getIconSizeWithOverlap(int iconSize) {
1092 return (int) Math.ceil(iconSize * ICON_OVERLAP_FACTOR);
1093 }
1094
Jon Miranda6f7e9702019-09-16 14:44:14 -07001095 /**
1096 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
1097 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
1098 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
1099 */
Tony Wickham7ba547c2021-02-02 17:12:08 -08001100 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -07001101 // Icon scale should never exceed 1, otherwise pixellation may occur.
1102 iconScale = Math.min(1f, scale);
1103 cellScaleToFit = scale;
1104
Jon Miranda18751b62017-07-31 17:25:27 -07001105 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -08001106 final boolean isVerticalLayout = isVerticalBarLayout();
Thales Lima080d8902022-03-28 15:30:29 +01001107 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -05001108
Thales Lima79456492023-05-23 11:32:22 +01001109 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001110 cellWidthPx = mResponsiveWorkspaceWidthSpec.getCellSizePx();
1111 cellHeightPx = mResponsiveWorkspaceHeightSpec.getCellSizePx();
Thales Lima79456492023-05-23 11:32:22 +01001112
Thales Lima2759aa32023-06-05 16:25:45 +01001113 if (cellWidthPx < iconSizePx) {
1114 // get a smaller icon size
1115 iconSizePx = mIconSizeSteps.getIconSmallerThan(cellWidthPx);
Thales Lima2759aa32023-06-05 16:25:45 +01001116 }
1117
Thales Lima93ee8fc2023-06-05 17:07:11 +01001118 iconDrawablePaddingPx = getNormalizedIconDrawablePadding();
Thales Lima93ee8fc2023-06-05 17:07:11 +01001119
Thales Lima24ceca62023-09-25 16:21:17 -07001120 CellContentDimensions cellContentDimensions = new CellContentDimensions(iconSizePx,
1121 iconDrawablePaddingPx,
1122 iconTextSizePx);
Thales Limabba07722023-10-11 18:16:29 +00001123 if (isVerticalLayout) {
1124 if (cellHeightPx < iconSizePx) {
1125 cellContentDimensions.setIconSizePx(
1126 mIconSizeSteps.getIconSmallerThan(cellHeightPx));
1127 }
Thales Lima24ceca62023-09-25 16:21:17 -07001128 } else {
1129 cellContentDimensions.resizeToFitCellHeight(cellHeightPx, mIconSizeSteps);
Thales Lima2759aa32023-06-05 16:25:45 +01001130 }
Thales Lima24ceca62023-09-25 16:21:17 -07001131 iconSizePx = cellContentDimensions.getIconSizePx();
1132 iconDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1133 iconTextSizePx = cellContentDimensions.getIconTextSizePx();
1134 int cellContentHeight = cellContentDimensions.getCellContentHeight();
Thales Lima2759aa32023-06-05 16:25:45 +01001135
1136 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Lima79456492023-05-23 11:32:22 +01001137 } else if (mIsScalableGrid) {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001138 iconDrawablePaddingPx = (int) (getNormalizedIconDrawablePadding() * iconScale);
Thales Lima83bedbf2021-10-05 17:47:39 +01001139 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
1140 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001141
1142 if (cellWidthPx < iconSizePx) {
1143 // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger.
1144 int numColumns = getPanelCount() * inv.numColumns;
1145 int numBorders = numColumns - 1;
1146 int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns;
1147 if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) {
1148 cellWidthPx = iconSizePx;
1149 cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders;
1150 } else {
1151 // If it still doesn't fit, set borderSpace to 0 and distribute the space for
1152 // cellWidth, and reduce iconSize.
1153 cellWidthPx = (cellWidthPx * numColumns
1154 + cellLayoutBorderSpacePx.x * numBorders) / numColumns;
1155 iconSizePx = Math.min(iconSizePx, cellWidthPx);
1156 cellLayoutBorderSpacePx.x = 0;
1157 }
1158 }
1159
Thales Lima93ee8fc2023-06-05 17:07:11 +01001160 int cellTextAndPaddingHeight =
1161 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +00001162 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
1163 if (cellHeightPx < cellContentHeight) {
1164 // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight
1165 // bigger.
1166 int numBorders = inv.numRows - 1;
1167 int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows;
1168 if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) {
1169 cellHeightPx = cellContentHeight;
1170 cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders;
1171 } else {
Alex Chau06f36e82023-01-06 10:50:54 +00001172 // If it still doesn't fit, set borderSpace to 0 to recover space.
Alex Chaube753132022-12-09 16:46:54 +00001173 cellHeightPx = (cellHeightPx * inv.numRows
1174 + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows;
Alex Chaube753132022-12-09 16:46:54 +00001175 cellLayoutBorderSpacePx.y = 0;
Alex Chau06f36e82023-01-06 10:50:54 +00001176 // Reduce iconDrawablePaddingPx to make cellContentHeight smaller.
1177 int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx;
1178 if (cellContentWithoutPadding <= cellHeightPx) {
1179 iconDrawablePaddingPx = cellContentHeight - cellHeightPx;
1180 } else {
1181 // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space,
1182 // then proportional reduce iconSizePx and iconTextSizePx to fit.
1183 iconDrawablePaddingPx = 0;
1184 float ratio = cellHeightPx / (float) cellContentWithoutPadding;
1185 iconSizePx = (int) (iconSizePx * ratio);
1186 iconTextSizePx = (int) (iconTextSizePx * ratio);
1187 }
1188 cellTextAndPaddingHeight =
1189 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +00001190 }
1191 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
1192 }
Jon Mirandae126d722021-02-25 10:45:20 -05001193 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +01001194 desiredWorkspaceHorizontalMarginPx =
1195 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -05001196 } else {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001197 iconDrawablePaddingPx = (int) (getNormalizedIconDrawablePadding() * iconScale);
Jon Mirandae126d722021-02-25 10:45:20 -05001198 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001199 cellHeightPx = getIconSizeWithOverlap(iconSizePx)
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001200 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -05001201 + Utilities.calculateTextHeight(iconTextSizePx);
1202 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
1203 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
1204 && !isMultiWindowMode) {
1205 // Ensures that the label is closer to its corresponding icon. This is not an issue
1206 // with vertical bar layout or multi-window mode since the issue is handled
1207 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
1208 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
1209 iconDrawablePaddingPx = cellPaddingY;
1210 }
Jon Miranda846455e2017-10-02 14:58:52 -07001211 }
Jon Miranda18751b62017-07-31 17:25:27 -07001212
Sunny Goyalae190ff2020-04-14 00:19:01 +00001213 // All apps
Thales Limaabfe3642023-05-24 18:08:53 +01001214 if (mIsResponsiveGrid) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001215 updateAllAppsWithResponsiveMeasures();
Thales Limaabfe3642023-05-24 18:08:53 +01001216 } else {
1217 updateAllAppsIconSize(scale, res);
1218 }
1219 updateAllAppsContainerWidth();
1220 if (isVerticalBarLayout()) {
1221 hideWorkspaceLabelsIfNotEnoughSpace();
1222 }
Brandon Dayauon3cdb32c2023-08-22 21:26:37 -07001223 if (FeatureFlags.enableTwolineAllapps()) {
1224 // Add extra textHeight to the existing allAppsCellHeight.
1225 allAppsCellHeightPx += Utilities.calculateTextHeight(allAppsIconTextSizePx);
1226 }
Winson Chungb3800242013-10-24 11:01:54 -07001227
Thales Limab8c05952022-05-23 16:58:38 +01001228 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -07001229
Sunny Goyalbaec6ff2016-09-14 11:26:21 -07001230 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -07001231 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
1232 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Sunny Goyal6c304b12023-04-10 12:03:04 -07001233
1234 // Update widget padding:
1235 float minSpacing = pxFromDp(MIN_WIDGET_PADDING_DP, mMetrics);
1236 if (cellLayoutBorderSpacePx.x < minSpacing
1237 || cellLayoutBorderSpacePx.y < minSpacing) {
1238 widgetPadding.left = widgetPadding.right =
1239 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.x));
1240 widgetPadding.top = widgetPadding.bottom =
1241 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.y));
1242 } else {
1243 widgetPadding.setEmpty();
1244 }
Winson Chung0f785722015-04-08 10:27:49 -07001245 }
1246
Thales Lima425f6822022-05-10 13:44:58 -03001247 /**
Thales Lima6a590062022-11-22 15:52:49 +00001248 * This method calculates the space between the icons to achieve a certain width.
Thales Lima425f6822022-05-10 13:44:58 -03001249 */
Thales Lima6a590062022-11-22 15:52:49 +00001250 private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) {
Jordan Silvad9227182023-08-17 15:53:59 +01001251 int numBorders = (numShownHotseatIcons - 1 + numExtraBorder);
1252 if (numBorders <= 0) return 0;
1253
Thales Lima9938c2f2022-07-25 14:38:16 +01001254 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
Jordan Silvad9227182023-08-17 15:53:59 +01001255 int hotseatBorderSpacePx = (int) (hotseatWidthPx - hotseatIconsTotalPx) / numBorders;
Thales Limaffc68b02023-01-09 16:20:23 +00001256 return Math.min(hotseatBorderSpacePx, mMaxHotseatIconSpacePx);
Thales Lima425f6822022-05-10 13:44:58 -03001257 }
1258
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001259 /**
1260 * Updates the iconSize for allApps* variants.
1261 */
Brian Isganitisa9a78112022-05-23 18:11:47 -07001262 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +01001263 allAppsBorderSpacePx = new Point(
1264 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
1265 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001266 // AllApps cells don't have real space between cells,
1267 // so we add the border space to the cell height
Alex Chaube753132022-12-09 16:46:54 +00001268 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics)
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001269 + allAppsBorderSpacePx.y;
1270 // but width is just the cell,
1271 // the border is added in #updateAllAppsContainerWidth
Thales Lima79456492023-05-23 11:32:22 +01001272 if (mIsScalableGrid) {
Alex Chaube753132022-12-09 16:46:54 +00001273 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1274 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001275 allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding();
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001276 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001277
1278 if (allAppsCellWidthPx < allAppsIconSizePx) {
1279 // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to
1280 // make allAppsCellWidth bigger.
1281 int numBorders = inv.numAllAppsColumns - 1;
1282 int extraWidthRequired =
1283 (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns;
1284 if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) {
1285 allAppsCellWidthPx = allAppsIconSizePx;
1286 allAppsBorderSpacePx.x -= extraWidthRequired / numBorders;
1287 } else {
1288 // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space
1289 // for allAppsCellWidth, and reduce allAppsIconSize.
1290 allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns
1291 + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns;
1292 allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx);
1293 allAppsBorderSpacePx.x = 0;
1294 }
1295 }
1296
1297 int cellContentHeight = allAppsIconSizePx
1298 + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y;
1299 if (allAppsCellHeightPx < cellContentHeight) {
1300 // Increase allAppsCellHeight to fit its content.
1301 allAppsCellHeightPx = cellContentHeight;
1302 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001303 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001304 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
1305 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001306 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1307 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001308 allAppsIconDrawablePaddingPx =
1309 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001310 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001311 }
Thales Limaabfe3642023-05-24 18:08:53 +01001312 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001313
Jordan Silva999dd2a2023-11-17 19:31:43 +00001314 private void updateAllAppsWithResponsiveMeasures() {
1315 allAppsIconSizePx = mResponsiveAllAppsCellSpec.getIconSize();
1316 allAppsIconTextSizePx = mResponsiveAllAppsCellSpec.getIconTextSize();
1317 allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding(allAppsIconSizePx,
1318 mResponsiveAllAppsCellSpec.getIconDrawablePadding());
Thales Limaabfe3642023-05-24 18:08:53 +01001319 allAppsBorderSpacePx = new Point(
Jordan Silva8f7986a2023-11-08 12:11:25 +00001320 mResponsiveAllAppsWidthSpec.getGutterPx(),
1321 mResponsiveAllAppsHeightSpec.getGutterPx()
Thales Limaabfe3642023-05-24 18:08:53 +01001322 );
Jordan Silva999dd2a2023-11-17 19:31:43 +00001323 allAppsCellHeightPx = mResponsiveAllAppsHeightSpec.getCellSizePx();
Jordan Silva8f7986a2023-11-08 12:11:25 +00001324 allAppsCellWidthPx = mResponsiveAllAppsWidthSpec.getCellSizePx();
Thales Limaa25cd902023-11-01 12:00:32 +00001325
1326 // This workaround is needed to align AllApps icons with Workspace icons
1327 // since AllApps doesn't have borders between cells
1328 int halfBorder = allAppsBorderSpacePx.x / 2;
Jordan Silva8f7986a2023-11-08 12:11:25 +00001329 allAppsPadding.left = mResponsiveAllAppsWidthSpec.getStartPaddingPx() - halfBorder;
1330 allAppsPadding.right = mResponsiveAllAppsWidthSpec.getEndPaddingPx() - halfBorder;
Jordan Silva376036a2023-11-08 15:56:40 +00001331
Jordan Silva376036a2023-11-08 15:56:40 +00001332
1333 // Reduce the size of the app icon if it doesn't fit
1334 if (allAppsCellWidthPx < allAppsIconSizePx) {
1335 // get a smaller icon size
1336 allAppsIconSizePx = mIconSizeSteps.getIconSmallerThan(allAppsCellWidthPx);
1337 }
1338
1339 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1340 allAppsIconSizePx, allAppsIconDrawablePaddingPx, (int) allAppsIconTextSizePx);
1341
1342 if (allAppsCellHeightPx < cellContentDimensions.getCellContentHeight()) {
1343 if (isVerticalBarLayout()) {
1344 if (allAppsCellHeightPx < iconSizePx) {
1345 cellContentDimensions.setIconSizePx(
1346 mIconSizeSteps.getIconSmallerThan(allAppsCellHeightPx));
1347 }
1348 } else {
1349 cellContentDimensions.resizeToFitCellHeight(allAppsCellHeightPx,
1350 mIconSizeSteps);
1351 }
1352 allAppsIconSizePx = cellContentDimensions.getIconSizePx();
1353 allAppsIconDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1354 allAppsIconTextSizePx = cellContentDimensions.getIconTextSizePx();
1355 }
Jordan Silva999dd2a2023-11-17 19:31:43 +00001356
1357 allAppsCellHeightPx += mResponsiveAllAppsHeightSpec.getGutterPx();
Thales Limaabfe3642023-05-24 18:08:53 +01001358 }
1359
1360 /**
1361 * Re-computes the all-apps cell size to be independent of workspace
1362 */
1363 public void autoResizeAllAppsCells() {
1364 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
1365 int topBottomPadding = textHeight;
1366 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
1367 + textHeight + (topBottomPadding * 2);
1368 }
1369
1370 private void updateAllAppsContainerWidth() {
1371 int cellLayoutHorizontalPadding =
1372 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
1373 if (isTablet) {
1374 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
1375 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Thales Limab433c9c2023-10-30 12:24:05 +00001376 + allAppsPadding.left + allAppsPadding.right;
Thales Limaabfe3642023-05-24 18:08:53 +01001377 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
Thales Limaa25cd902023-11-01 12:00:32 +00001378 } else if (!mIsResponsiveGrid) {
Thales Limab433c9c2023-10-30 12:24:05 +00001379 allAppsPadding.left = allAppsPadding.right =
Thales Limaabfe3642023-05-24 18:08:53 +01001380 Math.max(0, desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding
1381 - (allAppsBorderSpacePx.x / 2));
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001382 }
1383 }
1384
Thales Limaabfe3642023-05-24 18:08:53 +01001385 private void setupAllAppsStyle(Context context) {
1386 TypedArray allAppsStyle = context.obtainStyledAttributes(
1387 inv.allAppsStyle != INVALID_RESOURCE_HANDLE ? inv.allAppsStyle
1388 : R.style.AllAppsStyleDefault, R.styleable.AllAppsStyle);
1389
Thales Limab433c9c2023-10-30 12:24:05 +00001390 allAppsPadding.left = allAppsPadding.right = allAppsStyle.getDimensionPixelSize(
Thales Limaabfe3642023-05-24 18:08:53 +01001391 R.styleable.AllAppsStyle_horizontalPadding, 0);
1392 allAppsStyle.recycle();
1393 }
1394
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001395 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001396 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001397
Jordan Silva637f4eb2023-06-13 11:21:53 +01001398 // Responsive grid doesn't need to scale the folder
1399 if (mIsResponsiveGrid) return;
1400
Thales Lima7eee74b2023-03-16 16:00:55 -03001401 // For usability we can't have the folder use the whole width of the screen
Sunny Goyal07b69292018-01-08 14:19:34 -08001402 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -08001403
Thales Lima7eee74b2023-03-16 16:00:55 -03001404 // Check if the folder fit within the available height.
Thales Lima1faa4ed2023-12-01 16:48:19 +00001405 float contentUsedHeight = folderCellHeightPx * numFolderRows
1406 + ((numFolderRows - 1) * folderCellLayoutBorderSpacePx.y)
Thales Lima7eee74b2023-03-16 16:00:55 -03001407 + folderFooterHeightPx
1408 + folderContentPaddingTop;
1409 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001410 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -08001411
Thales Lima7eee74b2023-03-16 16:00:55 -03001412 // Check if the folder fit within the available width.
Thales Lima1faa4ed2023-12-01 16:48:19 +00001413 float contentUsedWidth = folderCellWidthPx * numFolderColumns
1414 + ((numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x)
Thales Lima7eee74b2023-03-16 16:00:55 -03001415 + folderContentPaddingLeftRight * 2;
1416 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001417 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -08001418
1419 float scale = Math.min(scaleX, scaleY);
1420 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001421 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001422 }
1423 }
1424
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001425 private void updateFolderCellSize(float scale, Resources res) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001426 int minLabelTextSize = pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001427 if (mIsResponsiveGrid) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001428 folderChildIconSizePx = mResponsiveWorkspaceCellSpec.getIconSize();
1429 folderChildTextSizePx = mResponsiveWorkspaceCellSpec.getIconTextSize();
1430 folderLabelTextSizePx = Math.max(minLabelTextSize,
1431 (int) (folderChildTextSizePx * folderLabelTextScale));
1432 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
1433
Jordan Silva637f4eb2023-06-13 11:21:53 +01001434 folderCellWidthPx = mResponsiveFolderWidthSpec.getCellSizePx();
Jordan Silva637f4eb2023-06-13 11:21:53 +01001435 folderCellHeightPx = mResponsiveFolderHeightSpec.getCellSizePx();
1436 folderContentPaddingTop = mResponsiveFolderHeightSpec.getStartPaddingPx();
1437 folderFooterHeightPx = mResponsiveFolderHeightSpec.getEndPaddingPx();
1438
1439 folderCellLayoutBorderSpacePx = new Point(mResponsiveFolderWidthSpec.getGutterPx(),
Thales Lima4cfd9502023-07-10 14:01:28 +01001440 mResponsiveFolderHeightSpec.getGutterPx());
Jordan Silva637f4eb2023-06-13 11:21:53 +01001441
1442 folderContentPaddingLeftRight = mResponsiveFolderWidthSpec.getStartPaddingPx();
Jordan Silva12fae112023-06-26 12:51:01 +01001443
1444 // Reduce icon width if it's wider than the expected folder cell width
1445 if (folderCellWidthPx < folderChildIconSizePx) {
1446 folderChildIconSizePx = mIconSizeSteps.getIconSmallerThan(folderCellWidthPx);
1447 }
1448
1449 // Recalculating padding and cell height
Jordan Silva3e5688a2023-12-05 15:12:29 -03001450 folderChildDrawablePaddingPx = mResponsiveWorkspaceCellSpec.getIconDrawablePadding();
Jordan Silva12fae112023-06-26 12:51:01 +01001451
Thales Limae9b5e142023-11-04 17:10:13 +00001452 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1453 folderChildIconSizePx,
1454 folderChildDrawablePaddingPx,
1455 folderChildTextSizePx);
1456 cellContentDimensions.resizeToFitCellHeight(folderCellHeightPx, mIconSizeSteps);
1457 folderChildIconSizePx = cellContentDimensions.getIconSizePx();
1458 folderChildDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1459 folderChildTextSizePx = cellContentDimensions.getIconTextSizePx();
Jordan Silva999dd2a2023-11-17 19:31:43 +00001460 folderLabelTextSizePx = Math.max(minLabelTextSize,
Jordan Silva9a3bd8f2023-11-16 18:33:28 +00001461 (int) (folderChildTextSizePx * folderLabelTextScale));
Jordan Silva999dd2a2023-11-17 19:31:43 +00001462 return;
1463 }
1464
1465 float invIconSizeDp = inv.iconSize[mTypeIndex];
1466 float invIconTextSizeDp = inv.iconTextSize[mTypeIndex];
1467 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1468 folderChildTextSizePx = pxFromSp(invIconTextSizeDp, mMetrics, scale);
1469 folderLabelTextSizePx = Math.max(minLabelTextSize,
1470 (int) (folderChildTextSizePx * folderLabelTextScale));
1471 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
1472
1473 if (mIsScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001474 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
Thales Lima7eee74b2023-03-16 16:00:55 -03001475 folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale);
1476 folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale);
1477 } else {
1478 folderCellWidthPx = roundPxValueFromFloat(folderCellWidthPx * scale);
1479 folderCellHeightPx = roundPxValueFromFloat(folderCellHeightPx * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001480 }
Charlie Anderson7bb10972023-11-22 13:35:30 -08001481 // Recalculating padding and cell height
1482 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
1483
1484 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1485 folderChildIconSizePx,
1486 folderChildDrawablePaddingPx,
1487 folderChildTextSizePx);
1488 cellContentDimensions.resizeToFitCellHeight(folderCellHeightPx, mIconSizeSteps);
1489 folderChildIconSizePx = cellContentDimensions.getIconSizePx();
1490 folderChildDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1491 folderChildTextSizePx = cellContentDimensions.getIconTextSizePx();
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001492
Thales Lima7eee74b2023-03-16 16:00:55 -03001493 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001494 folderCellLayoutBorderSpacePx = new Point(
1495 roundPxValueFromFloat(folderCellLayoutBorderSpacePx.x * scale),
1496 roundPxValueFromFloat(folderCellLayoutBorderSpacePx.y * scale)
1497 );
Thales Lima7eee74b2023-03-16 16:00:55 -03001498 folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001499 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx.x;
Jon Miranda823da222021-03-23 08:08:45 -04001500 } else {
1501 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1502 * scale);
1503 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1504 * scale);
1505
1506 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1507 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Lima7eee74b2023-03-16 16:00:55 -03001508 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001509 folderContentPaddingLeftRight =
1510 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1511 folderFooterHeightPx =
Thales Lima7eee74b2023-03-16 16:00:55 -03001512 roundPxValueFromFloat(
1513 res.getDimensionPixelSize(R.dimen.folder_footer_height_default)
1514 * scale);
1515
Jordan Silva12fae112023-06-26 12:51:01 +01001516 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
Jon Miranda823da222021-03-23 08:08:45 -04001517 }
Jon Mirandabf7d8122016-11-03 15:29:29 -07001518 }
1519
Winson1f064272016-07-18 17:18:02 -07001520 public void updateInsets(Rect insets) {
1521 mInsets.set(insets);
1522 }
1523
Sunny Goyalae6e3182019-04-30 12:04:37 -07001524 /**
1525 * The current device insets. This is generally same as the insets being dispatched to
1526 * {@link Insettable} elements, but can differ if the element is using a different profile.
1527 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001528 public Rect getInsets() {
1529 return mInsets;
1530 }
1531
Sunny Goyal756cd262015-08-20 12:33:21 -07001532 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001533 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001534 }
1535
Sunny Goyal19ff7282021-04-22 10:12:54 -07001536 public Point getCellSize(Point result) {
1537 if (result == null) {
1538 result = new Point();
1539 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001540
Pat Manning25d53342022-05-10 09:58:49 +00001541 int shortcutAndWidgetContainerWidth =
1542 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1543 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1544 inv.numColumns);
1545 int shortcutAndWidgetContainerHeight =
1546 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1547 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1548 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001549 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001550 }
1551
1552 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001553 * Returns the left and right space on the cell, which is the cell width - icon size
1554 */
1555 public int getCellHorizontalSpace() {
1556 return getCellSize().x - iconSizePx;
1557 }
1558
1559 /**
Pat Manning25d53342022-05-10 09:58:49 +00001560 * Gets the number of panels within the workspace.
1561 */
1562 public int getPanelCount() {
1563 return isTwoPanels ? 2 : 1;
1564 }
1565
1566 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001567 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1568 * bottom of the screen.
1569 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001570 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1571 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001572 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001573 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001574 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001575 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001576 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001577 }
1578
1579 /**
1580 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1581 */
Pat Manning25d53342022-05-10 09:58:49 +00001582 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001583 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001584 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001585 }
1586
1587 /**
1588 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1589 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001590 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001591 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001592 return heightPx - (isVerticalBarLayout()
1593 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001594 }
1595
Pat Manningea5c1d22022-04-14 10:58:16 +01001596 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001597 * Gets the scale of the workspace for the spring-loaded edit state.
1598 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001599 public float getWorkspaceSpringLoadScale(Context context) {
1600 float scale =
1601 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1602 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001603 scale = Math.min(scale, 1f);
1604
Pat Manninge63dd252022-08-02 16:15:29 +01001605 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001606 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001607 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001608 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001609 if (scaledWorkspaceWidth > maxAvailableWidth) {
1610 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1611 }
1612 return scale;
1613 }
1614
Pat Manning25d53342022-05-10 09:58:49 +00001615 /**
1616 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1617 *
1618 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1619 * layouts have two Cell Layouts per workspace.
1620 */
1621 public int getCellLayoutWidth() {
1622 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001623 }
1624
Pat Manning25d53342022-05-10 09:58:49 +00001625 /**
1626 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1627 *
1628 * <p>This is the height of a Workspace, less its vertical padding.
1629 */
1630 public int getCellLayoutHeight() {
1631 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001632 }
1633
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001634 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001635 return new Point(workspacePadding.left + workspacePadding.right,
1636 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001637 }
1638
1639 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001640 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1641 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001642 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001643 private void updateWorkspacePadding() {
1644 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001645 if (isVerticalBarLayout()) {
Jordan Silva3646a1b2023-08-02 13:52:52 +01001646 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001647 padding.top = mResponsiveWorkspaceHeightSpec.getStartPaddingPx();
Thales Lima8e11d532023-08-31 13:40:26 +00001648 padding.bottom = Math.max(0,
Jordan Silva8f7986a2023-11-08 12:11:25 +00001649 mResponsiveWorkspaceHeightSpec.getEndPaddingPx() - mInsets.bottom);
Jordan Silva3646a1b2023-08-02 13:52:52 +01001650 if (isSeascape()) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001651 padding.left =
1652 hotseatBarSizePx + mResponsiveWorkspaceWidthSpec.getEndPaddingPx();
1653 padding.right = mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
Jordan Silva3646a1b2023-08-02 13:52:52 +01001654 } else {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001655 padding.left = mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
1656 padding.right =
1657 hotseatBarSizePx + mResponsiveWorkspaceWidthSpec.getEndPaddingPx();
Jordan Silva3646a1b2023-08-02 13:52:52 +01001658 }
Winson1f064272016-07-18 17:18:02 -07001659 } else {
Jordan Silva3646a1b2023-08-02 13:52:52 +01001660 padding.top = 0;
1661 padding.bottom = edgeMarginPx;
1662 if (isSeascape()) {
1663 padding.left = hotseatBarSizePx;
Thales Lima8e11d532023-08-31 13:40:26 +00001664 padding.right = mHotseatBarEdgePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001665 } else {
Thales Lima8e11d532023-08-31 13:40:26 +00001666 padding.left = mHotseatBarEdgePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001667 padding.right = hotseatBarSizePx;
1668 }
Winson1f064272016-07-18 17:18:02 -07001669 }
Winson Chungb3800242013-10-24 11:01:54 -07001670 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001671 // Pad the bottom of the workspace with hotseat bar
1672 // and leave a bit of space in case a widget go all the way down
Thales Lima79456492023-05-23 11:32:22 +01001673 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding - mInsets.bottom;
1674 if (!mIsResponsiveGrid) {
1675 paddingBottom +=
1676 workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace;
1677 }
1678 int paddingTop = workspaceTopPadding + (mIsScalableGrid ? 0 : edgeMarginPx);
Pat Manning08610ca2022-04-05 21:03:16 +01001679 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001680
Pat Manning08610ca2022-04-05 21:03:16 +01001681 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001682 }
Pat Manning08610ca2022-04-05 21:03:16 +01001683 insetPadding(workspacePadding, cellLayoutPaddingPx);
1684 }
1685
1686 private void insetPadding(Rect paddings, Rect insets) {
1687 insets.left = Math.min(insets.left, paddings.left);
1688 paddings.left -= insets.left;
1689
1690 insets.top = Math.min(insets.top, paddings.top);
1691 paddings.top -= insets.top;
1692
1693 insets.right = Math.min(insets.right, paddings.right);
1694 paddings.right -= insets.right;
1695
1696 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1697 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001698 }
1699
Liran Binyamina833af32023-08-02 16:30:27 -04001700
1701 /**
1702 * Returns the new border space that should be used between hotseat icons after adjusting it to
1703 * the bubble bar.
1704 *
1705 * <p>If there's no adjustment needed, this method returns {@code 0}.
1706 */
1707 public float getHotseatAdjustedBorderSpaceForBubbleBar(Context context) {
1708 // only need to adjust when QSB is on top of the hotseat.
1709 if (isQsbInline) {
1710 return 0;
1711 }
1712
1713 // no need to adjust if there's enough space for the bubble bar to the right of the hotseat.
1714 if (getHotseatLayoutPadding(context).right > mBubbleBarSpaceThresholdPx) {
1715 return 0;
1716 }
1717
1718 // The adjustment is shrinking the hotseat's width by 1 icon on either side.
1719 int iconsWidth =
1720 iconSizePx * numShownHotseatIcons + hotseatBorderSpace * (numShownHotseatIcons - 1);
1721 int newWidth = iconsWidth - 2 * iconSizePx;
1722 // Evenly space the icons within the boundaries of the new width.
1723 return (float) (newWidth - iconSizePx * numShownHotseatIcons) / (numShownHotseatIcons - 1);
1724 }
1725
Sunny Goyal57b22792021-05-25 14:35:01 -07001726 /**
1727 * Returns the padding for hotseat view
1728 */
1729 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001730 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001731 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001732 // The hotseat icons will be placed in the middle of the hotseat cells.
1733 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1734 // in vertical bar layout.
1735 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1736 // is set to account for that difference.
Jordan Silva3646a1b2023-08-02 13:52:52 +01001737 float diffOverlapFactor = mIsResponsiveGrid ? 0
1738 : iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
1739
Pat Manning08610ca2022-04-05 21:03:16 +01001740 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1741 - diffOverlapFactor), 0);
1742 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001743 + diffOverlapFactor), 0);
1744
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001745 if (isSeascape()) {
Thales Lima8e11d532023-08-31 13:40:26 +00001746 hotseatBarPadding.set(mInsets.left + mHotseatBarEdgePaddingPx, paddingTop,
1747 mHotseatBarWorkspaceSpacePx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001748 } else {
Thales Lima8e11d532023-08-31 13:40:26 +00001749 hotseatBarPadding.set(mHotseatBarWorkspaceSpacePx, paddingTop,
1750 mInsets.right + mHotseatBarEdgePaddingPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001751 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001752 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001753 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001754 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1755 int hotseatBarTopPadding =
1756 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001757
Thales Lima6a590062022-11-22 15:52:49 +00001758 int hotseatWidth = getHotseatRequiredWidth();
Helen Cheuke76291f2023-02-14 17:11:05 +00001759 int startSpacing;
1760 int endSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001761 // Hotseat aligns to the left with nav buttons
1762 if (hotseatBarEndOffset > 0) {
Jon Mirandae17a9492023-03-08 16:42:20 -08001763 startSpacing = inlineNavButtonsEndSpacingPx;
Helen Cheuke76291f2023-02-14 17:11:05 +00001764 endSpacing = availableWidthPx - hotseatWidth - startSpacing + hotseatBorderSpace;
1765 } else {
1766 startSpacing = (availableWidthPx - hotseatWidth) / 2;
1767 endSpacing = startSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001768 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001769 startSpacing += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001770
Helen Cheuke76291f2023-02-14 17:11:05 +00001771 hotseatBarPadding.top = hotseatBarTopPadding;
1772 hotseatBarPadding.bottom = hotseatBarBottomPadding;
Alex Chau51da2192022-05-20 13:32:10 +01001773 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001774 if (isRtl) {
Helen Cheuke76291f2023-02-14 17:11:05 +00001775 hotseatBarPadding.left = endSpacing;
1776 hotseatBarPadding.right = startSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001777 } else {
Helen Cheuke76291f2023-02-14 17:11:05 +00001778 hotseatBarPadding.left = startSpacing;
1779 hotseatBarPadding.right = endSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001780 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001781
Thales Lima79456492023-05-23 11:32:22 +01001782 } else if (mIsScalableGrid) {
fbarone69b6f42023-12-18 13:20:34 -08001783 int iconExtraSpacePx = iconSizePx - getIconVisibleSizePx(iconSizePx);
1784 int sideSpacing = (availableWidthPx - (hotseatQsbWidth + iconExtraSpacePx)) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001785 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001786 0,
Thales Lima425f6822022-05-10 13:44:58 -03001787 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001788 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001789 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001790 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1791 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1792 // for this, we pad the left and right of the hotseat with half of the difference of a
1793 // workspace cell vs a hotseat cell.
1794 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001795 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001796 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001797 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001798 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1799 + mInsets.left,
1800 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001801 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001802 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001803 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001804 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001805 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001806 }
1807
Andy Wickhambd9a1802023-06-08 16:33:15 -07001808 /** The margin between the edge of all apps and the edge of the first icon. */
Thales Limab433c9c2023-10-30 12:24:05 +00001809 public int getAllAppsIconStartMargin(Context context) {
Andy Wickhambd9a1802023-06-08 16:33:15 -07001810 int allAppsSpacing;
1811 if (isVerticalBarLayout()) {
1812 // On phones, the landscape layout uses a different setup.
1813 allAppsSpacing = workspacePadding.left + workspacePadding.right;
1814 } else {
Thales Limab433c9c2023-10-30 12:24:05 +00001815 allAppsSpacing =
1816 allAppsPadding.left + allAppsPadding.right + allAppsLeftRightMargin * 2;
Andy Wickhambd9a1802023-06-08 16:33:15 -07001817 }
1818
1819 int cellWidth = DeviceProfile.calculateCellWidth(
1820 availableWidthPx - allAppsSpacing,
1821 0 /* borderSpace */,
1822 numShownAllAppsColumns);
fbarone69b6f42023-12-18 13:20:34 -08001823 int iconAlignmentMargin = (cellWidth - getIconVisibleSizePx(allAppsIconSizePx)) / 2;
Thales Limab433c9c2023-10-30 12:24:05 +00001824
1825 return (Utilities.isRtl(context.getResources()) ? allAppsPadding.right
1826 : allAppsPadding.left) + iconAlignmentMargin;
Andy Wickhambd9a1802023-06-08 16:33:15 -07001827 }
1828
fbarone69b6f42023-12-18 13:20:34 -08001829 /**
1830 * TODO(b/235886078): workaround needed because of this bug
1831 * Icons are 10% larger on XML than their visual size, so remove that extra space to get
1832 * some dimensions correct.
1833 *
1834 * When this bug is resolved this method will no longer be needed and we would be able to
1835 * replace all instances where this method is called with iconSizePx.
1836 */
1837 private int getIconVisibleSizePx(int iconSizePx) {
1838 return Math.round(ICON_VISIBLE_AREA_FACTOR * iconSizePx);
1839 }
1840
Thales Lima9938c2f2022-07-25 14:38:16 +01001841 private int getAdditionalQsbSpace() {
1842 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1843 }
1844
1845 /**
1846 * Calculate how much space the hotseat needs to be shown completely
1847 */
1848 private int getHotseatRequiredWidth() {
1849 int additionalQsbSpace = getAdditionalQsbSpace();
1850 return iconSizePx * numShownHotseatIcons
Thales Lima6a590062022-11-22 15:52:49 +00001851 + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1))
Thales Lima9938c2f2022-07-25 14:38:16 +01001852 + additionalQsbSpace;
1853 }
1854
Winsonfadbe8f2016-07-22 16:35:37 -07001855 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001856 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1857 */
1858 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001859 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001860 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1861 } else if (isTaskbarPresent) { // QSB on top
1862 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001863 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001864 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001865 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001866 }
1867
Thales Limab8c05952022-05-23 16:58:38 +01001868 /**
1869 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1870 */
1871 private int getHotseatBarBottomPadding() {
1872 if (isTaskbarPresent) { // QSB on top or inline
1873 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001874 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001875 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001876 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001877 }
1878
1879 /**
Alex Chau51da2192022-05-20 13:32:10 +01001880 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1881 */
1882 public int getTaskbarOffsetY() {
Jon Miranda9c478b62023-03-23 21:38:49 -07001883 int taskbarIconBottomSpace = (taskbarHeight - iconSizePx) / 2;
Alex Chau51da2192022-05-20 13:32:10 +01001884 int launcherIconBottomSpace =
1885 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001886 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001887 }
1888
Uwais Ashrafaa7fa882023-10-10 21:36:06 +00001889 /** Returns the number of pixels required below OverviewActions. */
Alex Chaua2fc7642022-04-21 14:20:23 +01001890 public int getOverviewActionsClaimedSpaceBelow() {
Uwais Ashrafaa7fa882023-10-10 21:36:06 +00001891 return isTaskbarPresent ? mTransientTaskbarClaimedSpace : mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001892 }
1893
1894 /** Gets the space that the overview actions will take, including bottom margin. */
1895 public int getOverviewActionsClaimedSpace() {
Alex Chau4989f4f2023-10-11 14:08:22 +00001896 int overviewActionsSpace = isTablet && Flags.enableGridOnlyOverview()
Pat Manning7b8f7662023-01-18 14:48:30 +00001897 ? 0
1898 : (overviewActionsTopMarginPx + overviewActionsHeight);
1899 return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
Alex Chaua2fc7642022-04-21 14:20:23 +01001900 }
1901
1902 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001903 * Takes the View and return the scales of width and height depending on the DeviceProfile
1904 * specifications
1905 *
1906 * @param itemInfo The tag of the widget view
1907 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1908 * height
1909 */
1910 @NonNull
1911 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1912 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1913 }
1914
1915 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001916 * @return the bounds for which the open folders should be contained within
1917 */
1918 public Rect getAbsoluteOpenFolderBounds() {
1919 if (isVerticalBarLayout()) {
1920 // Folders should only appear right of the drop target bar and left of the hotseat
1921 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1922 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001923 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001924 mInsets.top + availableHeightPx);
1925 } else {
1926 // Folders should only appear below the drop target bar and above the hotseat
Jon Miranda9c478b62023-03-23 21:38:49 -07001927 int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001928 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001929 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001930 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001931 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001932 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001933 }
1934 }
1935
Jon Miranda228877d2021-02-09 11:05:00 -05001936 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1937 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001938 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001939
Jon Miranda228877d2021-02-09 11:05:00 -05001940 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1941 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001942 }
1943
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001944 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001945 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1946 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1947 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001948 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001949 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001950 return isLandscape && transposeLayoutWithOrientation;
1951 }
1952
Sunny Goyal59d086c2018-05-07 17:31:40 -07001953 /**
1954 * Updates orientation information and returns true if it has changed from the previous value.
1955 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001956 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001957 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001958 boolean isSeascape = DisplayController.INSTANCE.get(context)
1959 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001960 if (mIsSeascape != isSeascape) {
1961 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001962 // Hotseat changing sides requires updating workspace left/right paddings
1963 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001964 return true;
1965 }
1966 }
1967 return false;
1968 }
1969
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001970 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001971 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001972 }
1973
Sunny Goyal07b69292018-01-08 14:19:34 -08001974 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001975 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001976 }
1977
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001978 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001979 switch (containerType) {
1980 case CellLayout.WORKSPACE:
1981 return cellHeightPx;
1982 case CellLayout.FOLDER:
1983 return folderCellHeightPx;
1984 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001985 // The hotseat is the only container where the cell height is going to be
1986 // different from the content within that cell.
1987 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001988 default:
1989 // ??
1990 return 0;
1991 }
1992 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001993
Jon Miranda58561d42021-03-17 10:51:54 -04001994 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001995 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001996 }
1997
Alex Chaue818bcb2022-09-02 17:27:11 +01001998 private String dpPointFToString(String name, PointF value) {
1999 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
2000 }
2001
Pat Manning5f74bfd2022-07-20 12:08:54 +01002002 /** Dumps various DeviceProfile variables to the specified writer. */
2003 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04002004 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07002005 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04002006
2007 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04002008 writer.println(prefix + "\tisPhone:" + isPhone);
2009 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
2010 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00002011 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04002012
2013 writer.println(prefix + "\tisLandscape:" + isLandscape);
2014 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07002015 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Winson Chung104a4c82023-11-08 18:56:15 +00002016 writer.println(prefix + "\tisLeftRightSplit:" + isLeftRightSplit);
Jon Miranda58561d42021-03-17 10:51:54 -04002017
2018 writer.println(prefix + pxToDpStr("windowX", windowX));
2019 writer.println(prefix + pxToDpStr("windowY", windowY));
2020 writer.println(prefix + pxToDpStr("widthPx", widthPx));
2021 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002022 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
2023 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01002024 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
2025 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
2026 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
2027 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04002028
2029 writer.println(prefix + "\taspectRatio:" + aspectRatio);
2030
Thales Limac98b7812023-04-14 15:04:23 +01002031 writer.println(prefix + "\tisResponsiveGrid:" + mIsResponsiveGrid);
Thales Lima79456492023-05-23 11:32:22 +01002032 writer.println(prefix + "\tisScalableGrid:" + mIsScalableGrid);
Jon Miranda58561d42021-03-17 10:51:54 -04002033
Thales Lima83bedbf2021-10-05 17:47:39 +01002034 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00002035 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
2036 writer.println(prefix + "\tinv.numSearchContainerColumns: "
2037 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04002038
Alex Chaue818bcb2022-09-02 17:27:11 +01002039 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07002040
Jon Miranda58561d42021-03-17 10:51:54 -04002041 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
2042 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
2043
2044 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
2045 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
2046
Thales Lima83bedbf2021-10-05 17:47:39 +01002047 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
2048 cellLayoutBorderSpacePx.x));
2049 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
2050 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002051 writer.println(
2052 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
2053 writer.println(
2054 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
2055 writer.println(
2056 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01002057 writer.println(
2058 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01002059
Jon Miranda58561d42021-03-17 10:51:54 -04002060 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
2061 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
2062 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
2063
Thales Lima1faa4ed2023-12-01 16:48:19 +00002064 writer.println(prefix + "\tnumFolderRows: " + numFolderRows);
2065 writer.println(prefix + "\tnumFolderColumns: " + numFolderColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04002066 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
2067 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
2068 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
2069 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
2070 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
2071 folderChildDrawablePaddingPx));
Jordan Silva637f4eb2023-06-13 11:21:53 +01002072 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.x",
2073 folderCellLayoutBorderSpacePx.x));
2074 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.y",
2075 folderCellLayoutBorderSpacePx.y));
Thales Limaa08a4432022-08-09 09:55:17 +01002076 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
2077 folderContentPaddingLeftRight));
2078 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03002079 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002080
Alex Chaue0227552022-04-06 19:44:43 +01002081 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01002082 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
2083 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
2084 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
2085 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01002086
2087 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
Alex Chau3d2c0622022-09-01 21:28:14 +01002088 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
2089 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04002090 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
2091 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
2092 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
2093 allAppsIconDrawablePaddingPx));
2094 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00002095 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01002096 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
2097 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07002098 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Thales Limab433c9c2023-10-30 12:24:05 +00002099 writer.println(prefix + pxToDpStr("allAppsPadding.top", allAppsPadding.top));
2100 writer.println(prefix + pxToDpStr("allAppsPadding.left", allAppsPadding.left));
2101 writer.println(prefix + pxToDpStr("allAppsPadding.right", allAppsPadding.right));
Alex Chau27b39b92022-01-14 18:02:18 +00002102 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04002103
2104 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03002105 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04002106 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00002107 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Thales Lima8e11d532023-08-31 13:40:26 +00002108 writer.println(prefix + pxToDpStr("mHotseatBarEdgePaddingPx",
2109 mHotseatBarEdgePaddingPx));
2110 writer.println(prefix + pxToDpStr("mHotseatBarWorkspaceSpacePx",
2111 mHotseatBarWorkspaceSpacePx));
Pat Manning26f70f72022-07-07 13:50:39 +01002112 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01002113 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
2114 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01002115 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
2116 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002117 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
2118 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
2119 hotseatLayoutPadding.top));
2120 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
2121 hotseatLayoutPadding.bottom));
2122 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
2123 hotseatLayoutPadding.left));
2124 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
2125 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07002126 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00002127 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00002128 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01002129 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04002130
2131 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10002132 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda9c478b62023-03-23 21:38:49 -07002133 writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight));
2134 writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight));
2135 writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin));
2136 writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize));
Jon Miranda58561d42021-03-17 10:51:54 -04002137
Thales Lima83bedbf2021-10-05 17:47:39 +01002138 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
2139 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002140 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
2141 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
2142 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00002143 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04002144
Jon Mirandaab3c6812021-06-28 15:42:28 -07002145 writer.println(prefix + pxToDpStr("iconScale", iconScale));
2146 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04002147 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00002148 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04002149
Thales Lima171ee662022-11-22 15:52:49 +00002150 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04002151 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
2152 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00002153
2154 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00002155 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
2156 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
2157 overviewTaskIconDrawableSizePx));
2158 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
2159 overviewTaskIconDrawableSizeGridPx));
Pat Manning1695cc72023-07-05 11:45:13 +01002160 writer.println(prefix + pxToDpStr("overviewTaskIconAppChipMenuDrawableSizePx",
2161 overviewTaskIconAppChipMenuDrawableSizePx));
Alex Chau635b3ab2022-01-26 16:49:10 +00002162 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
2163 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01002164 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
2165 overviewActionsTopMarginPx));
2166 writer.println(prefix + pxToDpStr("overviewActionsHeight",
2167 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00002168 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
2169 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00002170 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
2171 overviewActionsButtonSpacing));
2172 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
2173 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
2174 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01002175
Alex Chau62572c02022-07-25 18:36:37 +00002176 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01002177 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00002178 writer.println(
2179 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01002180
Pat Manning5f74bfd2022-07-20 12:08:54 +01002181 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
2182 getCellLayoutSpringLoadShrunkTop()));
2183 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
2184 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01002185 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
2186 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002187 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
2188 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01002189 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
2190 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Thales Lima79456492023-05-23 11:32:22 +01002191 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00002192 writer.println(prefix + "\tmResponsiveWorkspaceHeightSpec:"
2193 + mResponsiveWorkspaceHeightSpec.toString());
2194 writer.println(prefix + "\tmResponsiveWorkspaceWidthSpec:"
2195 + mResponsiveWorkspaceWidthSpec.toString());
2196 writer.println(prefix + "\tmResponsiveAllAppsHeightSpec:"
2197 + mResponsiveAllAppsHeightSpec.toString());
2198 writer.println(prefix + "\tmResponsiveAllAppsWidthSpec:"
2199 + mResponsiveAllAppsWidthSpec.toString());
Jordan Silva637f4eb2023-06-13 11:21:53 +01002200 writer.println(prefix + "\tmResponsiveFolderHeightSpec:" + mResponsiveFolderHeightSpec);
2201 writer.println(prefix + "\tmResponsiveFolderWidthSpec:" + mResponsiveFolderWidthSpec);
Thales Limaf8bfb032023-07-24 15:08:05 +01002202 writer.println(prefix + "\tmResponsiveHotseatSpec:" + mResponsiveHotseatSpec);
Jordan Silva999dd2a2023-11-17 19:31:43 +00002203 writer.println(prefix + "\tmResponsiveWorkspaceCellSpec:"
2204 + mResponsiveWorkspaceCellSpec);
2205 writer.println(prefix + "\tmResponsiveAllAppsCellSpec:" + mResponsiveAllAppsCellSpec);
Thales Lima79456492023-05-23 11:32:22 +01002206 }
Jon Miranda58561d42021-03-17 10:51:54 -04002207 }
2208
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00002209 /** Returns a reduced representation of this DeviceProfile. */
2210 public String toSmallString() {
2211 return "isTablet:" + isTablet + ", "
2212 + "isMultiDisplay:" + isMultiDisplay + ", "
2213 + "widthPx:" + widthPx + ", "
2214 + "heightPx:" + heightPx + ", "
2215 + "insets:" + mInsets + ", "
2216 + "rotationHint:" + rotationHint;
2217 }
2218
Alex Chaua6907dc2022-03-18 15:24:07 +00002219 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07002220 Configuration config = new Configuration(c.getResources().getConfiguration());
2221 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03002222 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00002223 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07002224 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07002225 }
Sunny Goyalfde55052018-02-01 14:46:13 -08002226
2227 /**
2228 * Callback when a component changes the DeviceProfile associated with it, as a result of
2229 * configuration change
2230 */
2231 public interface OnDeviceProfileChangeListener {
2232
2233 /**
2234 * Called when the device profile is reassigned. Note that for layout and measurements, it
2235 * is sufficient to listen for inset changes. Use this callback when you need to perform
2236 * a one time operation.
2237 */
2238 void onDeviceProfileChanged(DeviceProfile dp);
2239 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002240
Sihua Mae04aa202022-07-18 12:43:56 -07002241 /**
2242 * Handler that deals with ItemInfo of the views for the DeviceProfile
2243 */
2244 @FunctionalInterface
2245 public interface ViewScaleProvider {
2246 /**
2247 * Get the scales from the view
2248 *
2249 * @param itemInfo The tag of the widget view
2250 * @return PointF instance containing the scale information, or null if using the default
2251 * app widget scale of this device profile.
2252 */
2253 @NonNull
2254 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
2255 }
2256
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002257 public static class Builder {
2258 private Context mContext;
2259 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07002260 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002261
Sunny Goyal19ff7282021-04-22 10:12:54 -07002262 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00002263 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002264
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002265 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07002266 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00002267 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07002268 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002269
Sunny Goyal65190ae2022-08-02 14:16:26 -07002270 private SparseArray<DotRenderer> mDotRendererCache;
2271
Jon Miranda2b25ded2023-02-02 14:48:45 -08002272 private Consumer<DeviceProfile> mOverrideProvider;
2273
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002274 private boolean mIsTransientTaskbar;
2275
Sunny Goyalfd58da62020-08-11 12:06:49 -07002276 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002277 mContext = context;
2278 mInv = inv;
2279 mInfo = info;
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002280 mIsTransientTaskbar = info.isTransientTaskbar();
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002281 }
2282
2283 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
2284 mIsMultiWindowMode = isMultiWindowMode;
2285 return this;
2286 }
2287
Alex Chauab800f72022-12-13 17:46:06 +00002288 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
2289 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07002290 return this;
2291 }
2292
Sunny Goyal65190ae2022-08-02 14:16:26 -07002293 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
2294 mDotRendererCache = dotRendererCache;
2295 return this;
2296 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07002297
2298 public Builder setWindowBounds(WindowBounds bounds) {
2299 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07002300 return this;
2301 }
2302
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002303 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
2304 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
2305 return this;
2306 }
2307
Alex Chau6ed408f2022-03-04 12:58:05 +00002308 public Builder setGestureMode(boolean isGestureMode) {
2309 mIsGestureMode = isGestureMode;
2310 return this;
2311 }
2312
Jon Miranda2b25ded2023-02-02 14:48:45 -08002313 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
2314 mOverrideProvider = overrideProvider;
2315 return this;
2316 }
2317
Sihua Mae04aa202022-07-18 12:43:56 -07002318 /**
2319 * Set the viewScaleProvider for the builder
2320 *
2321 * @param viewScaleProvider The viewScaleProvider to be set for the
Thales Limae9273ea2023-01-26 12:33:52 +00002322 * DeviceProfile
Sihua Mae04aa202022-07-18 12:43:56 -07002323 * @return This builder
2324 */
2325 @NonNull
2326 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
2327 mViewScaleProvider = viewScaleProvider;
2328 return this;
2329 }
2330
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002331 /**
2332 * Set the isTransientTaskbar for the builder
2333 * @return This Builder
2334 */
2335 public Builder setIsTransientTaskbar(boolean isTransientTaskbar) {
2336 mIsTransientTaskbar = isTransientTaskbar;
2337 return this;
2338 }
2339
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002340 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07002341 if (mWindowBounds == null) {
2342 throw new IllegalArgumentException("Window bounds not set");
2343 }
2344 if (mTransposeLayoutWithOrientation == null) {
2345 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
2346 }
Alex Chau6ed408f2022-03-04 12:58:05 +00002347 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01002348 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00002349 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002350 if (mDotRendererCache == null) {
2351 mDotRendererCache = new SparseArray<>();
2352 }
Sihua Mae04aa202022-07-18 12:43:56 -07002353 if (mViewScaleProvider == null) {
2354 mViewScaleProvider = DEFAULT_PROVIDER;
2355 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08002356 if (mOverrideProvider == null) {
2357 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
2358 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002359 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00002360 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002361 mIsGestureMode, mViewScaleProvider, mOverrideProvider, mIsTransientTaskbar);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002362 }
2363 }
Winson Chungb3800242013-10-24 11:01:54 -07002364}