blob: f277926580a2789d21e5631a39ba8bb2eeb6b5ef [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;
Alex Chau206ede92022-08-01 17:46:12 +010081 private static final float ALL_APPS_TABLET_MAX_ROWS = 5.5f;
Thales Limab35faed2022-09-05 16:30:01 -030082 private static final float MIN_FOLDER_TEXT_SIZE_SP = 16f;
Sunny Goyal6c304b12023-04-10 12:03:04 -070083 private static final float MIN_WIDGET_PADDING_DP = 6f;
Alex Chau206ede92022-08-01 17:46:12 +010084
Sihua Mae04aa202022-07-18 12:43:56 -070085 public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f);
86 public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE;
Jordan Silvaf2402e22023-10-26 19:53:16 +010087 public static final Consumer<DeviceProfile> DEFAULT_DIMENSION_PROVIDER = dp -> {
88 };
Sihua Mae04aa202022-07-18 12:43:56 -070089
Adam Cohen2e6da152015-05-06 11:42:25 -070090 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070091 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070092 private final DisplayMetrics mMetrics;
Thales Lima2759aa32023-06-05 16:25:45 +010093 private final IconSizeSteps mIconSizeSteps;
Winson Chungbe876472014-05-14 14:15:20 -070094
Sunny Goyalc6205602015-05-21 20:46:33 -070095 // Device properties
96 public final boolean isTablet;
Sunny Goyalc6205602015-05-21 20:46:33 -070097 public final boolean isPhone;
98 public final boolean transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +000099 public final boolean isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700100 public final boolean isTwoPanels;
Thales Limaa1012902022-01-13 17:58:42 +0000101 public final boolean isQsbInline;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700102
Sunny Goyalc6205602015-05-21 20:46:33 -0700103 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -0700104 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -0800105 public final boolean isMultiWindowMode;
Alex Chau6ed408f2022-03-04 12:58:05 +0000106 public final boolean isGestureMode;
Sunny Goyald70e75a2018-02-22 10:07:32 -0800107
Sunny Goyal0addbf02020-04-28 14:17:35 -0700108 public final int windowX;
109 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -0700110 public final int widthPx;
111 public final int heightPx;
112 public final int availableWidthPx;
113 public final int availableHeightPx;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800114 public final int rotationHint;
Jon Mirandabba64512019-03-27 10:54:17 -0700115
116 public final float aspectRatio;
117
Thales Lima79456492023-05-23 11:32:22 +0100118 private final boolean mIsScalableGrid;
Thales Lima83bedbf2021-10-05 17:47:39 +0100119 private final int mTypeIndex;
Jon Mirandae126d722021-02-25 10:45:20 -0500120
Thales Limac98b7812023-04-14 15:04:23 +0100121 // Responsive grid
122 private final boolean mIsResponsiveGrid;
Jordan Silva8f7986a2023-11-08 12:11:25 +0000123 private CalculatedResponsiveSpec mResponsiveWorkspaceWidthSpec;
124 private CalculatedResponsiveSpec mResponsiveWorkspaceHeightSpec;
125 private CalculatedResponsiveSpec mResponsiveAllAppsWidthSpec;
126 private CalculatedResponsiveSpec mResponsiveAllAppsHeightSpec;
Jordan Silvaf2402e22023-10-26 19:53:16 +0100127 private CalculatedResponsiveSpec mResponsiveFolderWidthSpec;
128 private CalculatedResponsiveSpec mResponsiveFolderHeightSpec;
Thales Limaf8bfb032023-07-24 15:08:05 +0100129 private CalculatedHotseatSpec mResponsiveHotseatSpec;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000130 private CalculatedCellSpec mResponsiveWorkspaceCellSpec;
131 private CalculatedCellSpec mResponsiveAllAppsCellSpec;
Thales Limac98b7812023-04-14 15:04:23 +0100132
Tony Wickhamd6b40372015-09-23 18:37:57 -0700133 /**
134 * The maximum amount of left/right workspace padding as a percentage of the screen width.
135 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
136 * 7% of the screen width can be used as right padding.
137 */
138 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -0700139
Jon Miranda3f9bab22017-07-28 14:50:17 -0700140 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700141 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda80dda302021-07-28 14:14:59 -0700142 private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252;
143 private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700144
Sunny Goyalc6205602015-05-21 20:46:33 -0700145 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +0100146 public final int desiredWorkspaceHorizontalMarginOriginalPx;
147 public int desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100148 public int gridVisualizationPaddingX;
149 public int gridVisualizationPaddingY;
Thales Lima78d00ad2021-09-30 11:29:06 +0100150 public Point cellLayoutBorderSpaceOriginalPx;
151 public Point cellLayoutBorderSpacePx;
Pat Manning08610ca2022-04-05 21:03:16 +0100152 public Rect cellLayoutPaddingPx = new Rect();
153
Sunny Goyalc6205602015-05-21 20:46:33 -0700154 public final int edgeMarginPx;
Alex Chau0c4e11b2022-07-08 18:41:36 +0100155 public final float workspaceContentScale;
Alex Chau906d8822022-05-23 10:42:25 +0100156 public final int workspaceSpringLoadedMinNextPageVisiblePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700157
Jon Miranda58561d42021-03-17 10:51:54 -0400158 private final int extraSpace;
Thales Lima171ee662022-11-22 15:52:49 +0000159 private int maxEmptySpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500160 public int workspaceTopPadding;
161 public int workspaceBottomPadding;
162
Tony Wickham5edf9e22020-03-27 20:06:52 -0700163 // Workspace page indicator
164 public final int workspacePageIndicatorHeight;
165 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700166
Sunny Goyalc6205602015-05-21 20:46:33 -0700167 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400168 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700169 public int iconSizePx;
170 public int iconTextSizePx;
171 public int iconDrawablePaddingPx;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000172 private int mIconDrawablePaddingOriginalPx;
Thales Lima79456492023-05-23 11:32:22 +0100173 public boolean iconCenterVertically;
Winson Chungb3800242013-10-24 11:01:54 -0700174
Jon Mirandaab3c6812021-06-28 15:42:28 -0700175 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800176 public int cellWidthPx;
177 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700178 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800179
Thales Lima79456492023-05-23 11:32:22 +0100180 public int cellYPaddingPx = -1;
Jon Mirandae126d722021-02-25 10:45:20 -0500181
Sunny Goyalc6205602015-05-21 20:46:33 -0700182 // Folder
Thales Lima07c6b8d2023-11-08 18:22:38 +0000183 public final int numFolderRows;
184 public final int numFolderColumns;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000185 public final float folderLabelTextScale;
Jon Mirandae126d722021-02-25 10:45:20 -0500186 public int folderLabelTextSizePx;
Thales Limab35faed2022-09-05 16:30:01 -0300187 public int folderFooterHeightPx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700188 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700189 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700190
Jon Mirandae126d722021-02-25 10:45:20 -0500191 // Folder content
Jordan Silva637f4eb2023-06-13 11:21:53 +0100192 public Point folderCellLayoutBorderSpacePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500193 public int folderContentPaddingLeftRight;
194 public int folderContentPaddingTop;
195
Jon Mirandabf7d8122016-11-03 15:29:29 -0700196 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700197 public int folderCellWidthPx;
198 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700199
200 // Folder child
201 public int folderChildIconSizePx;
202 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700203 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700204
Sunny Goyalc6205602015-05-21 20:46:33 -0700205 // Hotseat
Thales Lima9938c2f2022-07-25 14:38:16 +0100206 public int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700207 public int hotseatCellHeightPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100208 public final boolean areNavButtonsInline;
Jon Miranda18751b62017-07-31 17:25:27 -0700209 // In portrait: size = height, in landscape: size = width
210 public int hotseatBarSizePx;
Thales Limab8c05952022-05-23 16:58:38 +0100211 public int hotseatBarBottomSpacePx;
Pat Manning26f70f72022-07-07 13:50:39 +0100212 public int hotseatBarEndOffset;
Thales Limab8c05952022-05-23 16:58:38 +0100213 public int hotseatQsbSpace;
Pat Manningde25c0d2022-04-05 19:11:26 +0100214 public int springLoadedHotseatBarTopMarginPx;
Thales Lima8e11d532023-08-31 13:40:26 +0000215 // These 2 values are only used for isVerticalBar
216 // Padding between edge of screen and hotseat
217 public final int mHotseatBarEdgePaddingPx;
218 // Space between hotseat and workspace (not used in responsive)
219 public final int mHotseatBarWorkspaceSpacePx;
Alex Chau206ede92022-08-01 17:46:12 +0100220 public int hotseatQsbWidth; // only used when isQsbInline
Sunny Goyal57b22792021-05-25 14:35:01 -0700221 public final int hotseatQsbHeight;
Thales Limab8c05952022-05-23 16:58:38 +0100222 public final int hotseatQsbVisualHeight;
223 private final int hotseatQsbShadowHeight;
Thales Limadd027342022-01-07 12:54:37 +0000224 public int hotseatBorderSpace;
Thales Limaffc68b02023-01-09 16:20:23 +0000225 private final int mMinHotseatIconSpacePx;
226 private final int mMinHotseatQsbWidthPx;
227 private final int mMaxHotseatIconSpacePx;
Jon Mirandae17a9492023-03-08 16:42:20 -0800228 public final int inlineNavButtonsEndSpacingPx;
Liran Binyamina833af32023-08-02 16:30:27 -0400229 // Space required for the bubble bar between the hotseat and the edge of the screen. If there's
230 // not enough space, the hotseat will adjust itself for the bubble bar.
231 private final int mBubbleBarSpaceThresholdPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700232
Alex Chau3d2c0622022-09-01 21:28:14 +0100233 // Bottom sheets
234 public int bottomSheetTopPadding;
235 public int bottomSheetOpenDuration;
236 public int bottomSheetCloseDuration;
237 public float bottomSheetWorkspaceScale;
238 public float bottomSheetDepth;
239
Sunny Goyalc6205602015-05-21 20:46:33 -0700240 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000241 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000242 public int allAppsShiftRange;
Thales Limab433c9c2023-10-30 12:24:05 +0000243 public Rect allAppsPadding = new Rect();
Alex Chau3d2c0622022-09-01 21:28:14 +0100244 public int allAppsOpenDuration;
245 public int allAppsCloseDuration;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700246 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700247 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700248 public int allAppsIconSizePx;
249 public int allAppsIconDrawablePaddingPx;
Alex Chau27b39b92022-01-14 18:02:18 +0000250 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700251 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700252 public float allAppsIconTextSizePx;
253
Zak Cohen334efeb2021-03-19 16:42:07 -0700254 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700255 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000256 public int overviewTaskIconSizePx;
Alex Chauac9df382021-08-02 19:08:41 +0100257 public int overviewTaskIconDrawableSizePx;
258 public int overviewTaskIconDrawableSizeGridPx;
Pat Manning1695cc72023-07-05 11:45:13 +0100259 public int overviewTaskIconAppChipMenuDrawableSizePx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000260 public int overviewTaskThumbnailTopMarginPx;
Alex Chau19c6eca2022-03-10 20:12:56 +0000261 public final int overviewActionsHeight;
Alex Chaua2fc7642022-04-21 14:20:23 +0100262 public final int overviewActionsTopMarginPx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000263 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100264 public int overviewPageSpacing;
265 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000266 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700267
Jeremy Sim0ac47082022-10-10 13:59:40 -0700268 // Split staging
269 public int splitPlaceholderInset;
270
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800271 // Widgets
Sihua Mae04aa202022-07-18 12:43:56 -0700272 private final ViewScaleProvider mViewScaleProvider;
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800273
Sunny Goyal47328fd2016-05-25 18:56:41 -0700274 // Drop Target
275 public int dropTargetBarSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100276 public int dropTargetBarTopMarginPx;
277 public int dropTargetBarBottomMarginPx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100278 public int dropTargetDragPaddingPx;
279 public int dropTargetTextSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100280 public int dropTargetHorizontalPaddingPx;
281 public int dropTargetVerticalPaddingPx;
282 public int dropTargetGapPx;
Alex Chau5b019302022-05-23 10:42:25 +0100283 public int dropTargetButtonWorkspaceEdgeGapPx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700284
Winson1f064272016-07-18 17:18:02 -0700285 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800286 private final Rect mInsets = new Rect();
287 public final Rect workspacePadding = new Rect();
Sunny Goyal6c304b12023-04-10 12:03:04 -0700288 // Additional padding added to the widget inside its cellSpace. It is applied outside
289 // the widgetView, such that the actual view size is same as the widget size.
290 public final Rect widgetPadding = new Rect();
291
Jon Miranda0bd63d12019-03-06 17:29:29 -0800292 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700293 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700294
Tony Wickhamf34bee82018-12-03 18:11:39 -0800295 // Notification dots
Sunny Goyal65190ae2022-08-02 14:16:26 -0700296 public final DotRenderer mDotRendererWorkSpace;
297 public final DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800298
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100299 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800300 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000301 // Whether Taskbar will inset the bottom of apps by taskbarSize.
302 public boolean isTaskbarPresentInApps;
Jon Miranda9c478b62023-03-23 21:38:49 -0700303 public final int taskbarHeight;
304 public final int stashedTaskbarHeight;
305 public final int taskbarBottomMargin;
306 public final int taskbarIconSize;
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000307 private final int mTransientTaskbarClaimedSpace;
Jon Miranda04f05102023-04-04 12:16:31 -0700308 // If true, used to layout taskbar in 3 button navigation mode.
309 public final boolean startAlignTaskbar;
Thales Limae9566402023-08-30 16:35:12 +0100310 public final boolean isTransientTaskbar;
Alex Chaua02eddc2021-04-29 00:36:06 +0100311 // DragController
312 public int flingToDeleteThresholdVelocity;
313
Vinit Nayak17c4b332021-08-05 12:54:58 -0700314 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700315 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal65190ae2022-08-02 14:16:26 -0700316 SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
Alex Chauab800f72022-12-13 17:46:06 +0000317 boolean transposeLayoutWithOrientation, boolean isMultiDisplay, boolean isGestureMode,
Jon Miranda2b25ded2023-02-02 14:48:45 -0800318 @NonNull final ViewScaleProvider viewScaleProvider,
Jagrut Desai3a7d1392023-09-06 15:56:19 -0700319 @NonNull final Consumer<DeviceProfile> dimensionOverrideProvider,
320 boolean isTransientTaskbar) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700321
Adam Cohen2e6da152015-05-06 11:42:25 -0700322 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700323 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800324 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500325 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +0000326 this.isMultiDisplay = isMultiDisplay;
Alex Chau6ed408f2022-03-04 12:58:05 +0000327 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700328 windowX = windowBounds.bounds.left;
329 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800330 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100331 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700332
Thales Limac98b7812023-04-14 15:04:23 +0100333 // TODO(b/241386436): shouldn't change any launcher behaviour
Thales Limaabfe3642023-05-24 18:08:53 +0100334 mIsResponsiveGrid = inv.workspaceSpecsId != INVALID_RESOURCE_HANDLE
Jordan Silva637f4eb2023-06-13 11:21:53 +0100335 && inv.allAppsSpecsId != INVALID_RESOURCE_HANDLE
Thales Limaf8bfb032023-07-24 15:08:05 +0100336 && inv.folderSpecsId != INVALID_RESOURCE_HANDLE
Jordan Silva999dd2a2023-11-17 19:31:43 +0000337 && inv.hotseatSpecsId != INVALID_RESOURCE_HANDLE
338 && inv.workspaceCellSpecsId != INVALID_RESOURCE_HANDLE
339 && inv.allAppsCellSpecsId != INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100340
Thales Lima79456492023-05-23 11:32:22 +0100341 mIsScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000342 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700343 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000344 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700345 isPhone = !isTablet;
Alex Chauab800f72022-12-13 17:46:06 +0000346 isTwoPanels = isTablet && isMultiDisplay;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800347 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700348
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000349 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000350 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700351 ? Configuration.ORIENTATION_LANDSCAPE
352 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000353 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700354 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000355 mMetrics = res.getDisplayMetrics();
356
Thales Lima2759aa32023-06-05 16:25:45 +0100357 mIconSizeSteps = mIsResponsiveGrid ? new IconSizeSteps(res) : null;
358
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000359 // Determine sizes.
360 widthPx = windowBounds.bounds.width();
361 heightPx = windowBounds.bounds.height();
362 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100363 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000364
365 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Thales Lima83bedbf2021-10-05 17:47:39 +0100366 if (isTwoPanels) {
367 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000368 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100369 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000370 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100371 }
372 } else {
373 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000374 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100375 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000376 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100377 }
378 }
379
Jagrut Desai3a7d1392023-09-06 15:56:19 -0700380 this.isTransientTaskbar = isTransientTaskbar;
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000381 int transientTaskbarIconSize = pxFromDp(inv.transientTaskbarIconSize[mTypeIndex], mMetrics);
382 int transientTaskbarBottomMargin =
383 res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin);
384 int transientTaskbarHeight =
385 Math.round((transientTaskbarIconSize * ICON_VISIBLE_AREA_FACTOR)
Jordan Silvaf2402e22023-10-26 19:53:16 +0100386 + (2 * res.getDimensionPixelSize(R.dimen.transient_taskbar_padding)));
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000387 mTransientTaskbarClaimedSpace = transientTaskbarHeight + 2 * transientTaskbarBottomMargin;
388
Uwais Ashraf3602d172023-09-15 11:36:32 +0000389 if (!isTaskbarPresent) {
390 taskbarIconSize = taskbarHeight = stashedTaskbarHeight = taskbarBottomMargin = 0;
391 startAlignTaskbar = false;
392 } else if (isTransientTaskbar) {
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000393 taskbarIconSize = transientTaskbarIconSize;
394 taskbarHeight = transientTaskbarHeight;
Jon Miranda9c478b62023-03-23 21:38:49 -0700395 stashedTaskbarHeight =
396 res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_height);
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000397 taskbarBottomMargin = transientTaskbarBottomMargin;
Jon Miranda04f05102023-04-04 12:16:31 -0700398 startAlignTaskbar = false;
Jon Miranda9c478b62023-03-23 21:38:49 -0700399 } else {
400 taskbarIconSize = pxFromDp(ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size),
401 mMetrics);
402 taskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_size);
403 stashedTaskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
404 taskbarBottomMargin = 0;
Jon Miranda04f05102023-04-04 12:16:31 -0700405 startAlignTaskbar = inv.startAlignTaskbar[mTypeIndex];
Tony Wickham15883892021-02-12 11:24:40 -0800406 }
Tony Wickham15883892021-02-12 11:24:40 -0800407
Winson Chungb3800242013-10-24 11:01:54 -0700408 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100409 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700410
Alex Chau51da2192022-05-20 13:32:10 +0100411 gridVisualizationPaddingX = res.getDimensionPixelSize(
412 R.dimen.grid_visualization_horizontal_cell_spacing);
413 gridVisualizationPaddingY = res.getDimensionPixelSize(
414 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500415
Alex Chaue0227552022-04-06 19:44:43 +0100416 bottomSheetTopPadding = mInsets.top // statusbar height
Andras Kloczl142b0542022-03-09 21:26:02 +0000417 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
418 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
Alex Chau3d2c0622022-09-01 21:28:14 +0100419 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
420 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
421 if (isTablet) {
422 bottomSheetWorkspaceScale = workspaceContentScale;
Alex Chauab800f72022-12-13 17:46:06 +0000423 if (isMultiDisplay && !ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH.get()) {
424 // TODO(b/259893832): Revert to use maxWallpaperScale to calculate bottomSheetDepth
425 // when screen recorder bug is fixed.
426 bottomSheetDepth = 1f;
427 } else {
428 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
429 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
430 // When depth is 1, wallpaper zoom is set to 1.
431 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
432 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
433 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
434 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
435 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100436 } else {
437 bottomSheetWorkspaceScale = 1f;
438 bottomSheetDepth = 0f;
439 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000440
Jon Mirandae126d722021-02-25 10:45:20 -0500441 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
Thales Lima24051842023-11-21 23:00:20 +0000442 numFolderRows = inv.numFolderRows[mTypeIndex];
443 numFolderColumns = inv.numFolderColumns[mTypeIndex];
Thales Limab35faed2022-09-05 16:30:01 -0300444
Thales Lima79456492023-05-23 11:32:22 +0100445 if (mIsScalableGrid && inv.folderStyle != INVALID_RESOURCE_HANDLE) {
Thales Limab35faed2022-09-05 16:30:01 -0300446 TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
Thales Limad852d652023-01-17 14:01:13 +0000447 R.styleable.FolderStyle);
Thales Limab35faed2022-09-05 16:30:01 -0300448 // These are re-set in #updateFolderCellSize if the grid is not scalable
449 folderCellHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000450 R.styleable.FolderStyle_folderCellHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300451 folderCellWidthPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000452 R.styleable.FolderStyle_folderCellWidth, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300453
454 folderContentPaddingTop = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000455 R.styleable.FolderStyle_folderTopPadding, 0);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100456
457 int gutter = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000458 R.styleable.FolderStyle_folderBorderSpace, 0);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100459 folderCellLayoutBorderSpacePx = new Point(gutter, gutter);
Thales Limab35faed2022-09-05 16:30:01 -0300460 folderFooterHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000461 R.styleable.FolderStyle_folderFooterHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300462 folderStyle.recycle();
Jordan Silva637f4eb2023-06-13 11:21:53 +0100463 } else if (!mIsResponsiveGrid) {
464 folderCellLayoutBorderSpacePx = new Point(0, 0);
Thales Lima7eee74b2023-03-16 16:00:55 -0300465 folderFooterHeightPx = res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Thales Limab35faed2022-09-05 16:30:01 -0300466 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
467 }
Jon Mirandae126d722021-02-25 10:45:20 -0500468
Thales Lima85c942f2021-12-31 13:04:20 +0000469 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000470 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
471 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Thales Limae9273ea2023-01-26 12:33:52 +0000472 setupAllAppsStyle(context);
Jon Mirandae126d722021-02-25 10:45:20 -0500473
Tony Wickham5edf9e22020-03-27 20:06:52 -0700474 workspacePageIndicatorHeight = res.getDimensionPixelSize(
475 R.dimen.workspace_page_indicator_height);
476 mWorkspacePageIndicatorOverlapWorkspace =
477 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700478
Jordan Silva999dd2a2023-11-17 19:31:43 +0000479 if (!mIsResponsiveGrid) {
480 TypedArray cellStyle;
481 if (inv.cellStyle != INVALID_RESOURCE_HANDLE) {
482 cellStyle = context.obtainStyledAttributes(inv.cellStyle,
483 R.styleable.CellStyle);
484 } else {
485 cellStyle = context.obtainStyledAttributes(R.style.CellStyleDefault,
486 R.styleable.CellStyle);
487 }
488 mIconDrawablePaddingOriginalPx = cellStyle.getDimensionPixelSize(
489 R.styleable.CellStyle_iconDrawablePadding, 0);
490 cellStyle.recycle();
Thales Limad852d652023-01-17 14:01:13 +0000491 }
Alex Chaua02eddc2021-04-29 00:36:06 +0100492
Sunny Goyal47328fd2016-05-25 18:56:41 -0700493 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100494 dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
495 dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100496 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
497 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100498 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
499 R.dimen.drop_target_button_drawable_horizontal_padding);
500 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
501 R.dimen.drop_target_button_drawable_vertical_padding);
502 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100503 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
504 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100505
Alex Chau906d8822022-05-23 10:42:25 +0100506 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
507 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700508
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700509 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700510
Thales Limaa1012902022-01-13 17:58:42 +0000511 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100512 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
513 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
514
Thales Lima12d0eff2022-03-25 17:06:11 +0000515 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
516 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
517 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
518 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
519 && hotseatQsbHeight > 0;
Thales Lima79456492023-05-23 11:32:22 +0100520 isQsbInline = mIsScalableGrid && inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000521
Thales Lima425f6822022-05-10 13:44:58 -0300522 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100523 numShownHotseatIcons =
524 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000525
Sunny Goyal19ff7282021-04-22 10:12:54 -0700526 numShownAllAppsColumns =
527 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100528
Thales Lima8e11d532023-08-31 13:40:26 +0000529 int hotseatBarBottomSpace;
Thales Limab8c05952022-05-23 16:58:38 +0100530 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
Thales Limaf8bfb032023-07-24 15:08:05 +0100531
532 if (mIsResponsiveGrid) {
Jordan Silvaf2402e22023-10-26 19:53:16 +0100533 float responsiveAspectRatio = (float) widthPx / heightPx;
534 HotseatSpecsProvider hotseatSpecsProvider =
535 HotseatSpecsProvider.create(new ResourceHelper(context,
Thales Limaf8bfb032023-07-24 15:08:05 +0100536 isTwoPanels ? inv.hotseatSpecsTwoPanelId : inv.hotseatSpecsId));
Thales Lima8e11d532023-08-31 13:40:26 +0000537 mResponsiveHotseatSpec =
Jordan Silvaf2402e22023-10-26 19:53:16 +0100538 isVerticalBarLayout() ? hotseatSpecsProvider.getCalculatedSpec(
539 responsiveAspectRatio, DimensionType.WIDTH, widthPx)
540 : hotseatSpecsProvider.getCalculatedSpec(responsiveAspectRatio,
541 DimensionType.HEIGHT, heightPx);
Thales Limaf8bfb032023-07-24 15:08:05 +0100542 hotseatQsbSpace = mResponsiveHotseatSpec.getHotseatQsbSpace();
Thales Lima8e11d532023-08-31 13:40:26 +0000543 hotseatBarBottomSpace =
544 isVerticalBarLayout() ? 0 : mResponsiveHotseatSpec.getEdgePadding();
545 mHotseatBarEdgePaddingPx =
546 isVerticalBarLayout() ? mResponsiveHotseatSpec.getEdgePadding() : 0;
547 mHotseatBarWorkspaceSpacePx = 0;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000548
549 ResponsiveCellSpecsProvider workspaceCellSpecs = ResponsiveCellSpecsProvider.create(
550 new ResourceHelper(context,
551 isTwoPanels ? inv.workspaceCellSpecsTwoPanelId
552 : inv.workspaceCellSpecsId));
553 mResponsiveWorkspaceCellSpec = workspaceCellSpecs.getCalculatedSpec(
554 responsiveAspectRatio, heightPx);
Thales Limaf8bfb032023-07-24 15:08:05 +0100555 } else {
556 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
Thales Lima8e11d532023-08-31 13:40:26 +0000557 hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
558 mHotseatBarEdgePaddingPx =
559 isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
560 mHotseatBarWorkspaceSpacePx =
561 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Thales Limaf8bfb032023-07-24 15:08:05 +0100562 }
563
Thales Lima8e11d532023-08-31 13:40:26 +0000564 if (!isVerticalBarLayout()) {
565 // Have a little space between the inset and the QSB
566 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
567 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
Thales Limab8c05952022-05-23 16:58:38 +0100568
Thales Lima8e11d532023-08-31 13:40:26 +0000569 // Only change the spaces if there is space
570 if (availableSpace > 0) {
571 // Make sure there is enough space between hotseat/QSB and QSB/navBar
572 if (availableSpace < minQsbMargin * 2) {
573 minQsbMargin = availableSpace / 2;
574 hotseatQsbSpace = minQsbMargin;
575 } else {
576 hotseatQsbSpace -= minQsbMargin;
577 }
Thales Limab8c05952022-05-23 16:58:38 +0100578 }
Thales Lima8e11d532023-08-31 13:40:26 +0000579 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
Thales Limab8c05952022-05-23 16:58:38 +0100580
Thales Lima8e11d532023-08-31 13:40:26 +0000581 } else {
582 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
583 }
Thales Limaa1012902022-01-13 17:58:42 +0000584 }
Thales Lima425f6822022-05-10 13:44:58 -0300585
Pat Manningde25c0d2022-04-05 19:11:26 +0100586 springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
587 R.dimen.spring_loaded_hotseat_top_margin);
Jordan Silva999dd2a2023-11-17 19:31:43 +0000588
589 if (mIsResponsiveGrid) {
590 updateHotseatSizes(mResponsiveWorkspaceCellSpec.getIconSize());
591 } else {
592 updateHotseatSizes(pxFromDp(inv.iconSize[mTypeIndex], mMetrics));
593 }
594
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700595 if (areNavButtonsInline && !isPhone) {
Jon Mirandae17a9492023-03-08 16:42:20 -0800596 inlineNavButtonsEndSpacingPx =
Thales Limaffc68b02023-01-09 16:20:23 +0000597 res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing);
Pat Manning26f70f72022-07-07 13:50:39 +0100598 /*
599 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700600 * Spacing between nav buttons +
Thales Lima6a590062022-11-22 15:52:49 +0000601 * Space at the end for contextual buttons
Pat Manning26f70f72022-07-07 13:50:39 +0100602 */
603 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700604 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
Jon Mirandae17a9492023-03-08 16:42:20 -0800605 + inlineNavButtonsEndSpacingPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100606 } else {
Jon Mirandae17a9492023-03-08 16:42:20 -0800607 inlineNavButtonsEndSpacingPx = 0;
Pat Manning26f70f72022-07-07 13:50:39 +0100608 hotseatBarEndOffset = 0;
609 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700610
Liran Binyamina833af32023-08-02 16:30:27 -0400611 mBubbleBarSpaceThresholdPx =
612 res.getDimensionPixelSize(R.dimen.bubblebar_hotseat_adjustment_threshold);
613
Thales Lima79456492023-05-23 11:32:22 +0100614 // Needs to be calculated after hotseatBarSizePx is correct,
615 // for the available height to be correct
616 if (mIsResponsiveGrid) {
Thales Lima2759aa32023-06-05 16:25:45 +0100617 int availableResponsiveWidth =
618 availableWidthPx - (isVerticalBarLayout() ? hotseatBarSizePx : 0);
Jordan Silva376036a2023-11-08 15:56:40 +0000619 int numWorkspaceColumns = getPanelCount() * inv.numColumns;
Thales Lima8e11d532023-08-31 13:40:26 +0000620 // don't use availableHeightPx because it subtracts mInsets.bottom
621 int availableResponsiveHeight = heightPx - mInsets.top
Jordan Silvaf2402e22023-10-26 19:53:16 +0100622 - (isVerticalBarLayout() ? 0 : hotseatBarSizePx);
623 float responsiveAspectRatio = (float) widthPx / heightPx;
Thales Limaabfe3642023-05-24 18:08:53 +0100624
Jordan Silvaf2402e22023-10-26 19:53:16 +0100625 ResponsiveSpecsProvider workspaceSpecs = ResponsiveSpecsProvider.create(
Jordan Silva575c3bd2023-07-21 12:00:43 +0100626 new ResourceHelper(context,
Jordan Silvaf2402e22023-10-26 19:53:16 +0100627 isTwoPanels ? inv.workspaceSpecsTwoPanelId : inv.workspaceSpecsId),
628 ResponsiveSpecType.Workspace);
Jordan Silva8f7986a2023-11-08 12:11:25 +0000629 mResponsiveWorkspaceWidthSpec = workspaceSpecs.getCalculatedSpec(responsiveAspectRatio,
Jordan Silva376036a2023-11-08 15:56:40 +0000630 DimensionType.WIDTH, numWorkspaceColumns, availableResponsiveWidth);
Jordan Silva8f7986a2023-11-08 12:11:25 +0000631 mResponsiveWorkspaceHeightSpec = workspaceSpecs.getCalculatedSpec(responsiveAspectRatio,
Jordan Silvaf2402e22023-10-26 19:53:16 +0100632 DimensionType.HEIGHT, inv.numRows, availableResponsiveHeight);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100633
Jordan Silvaf2402e22023-10-26 19:53:16 +0100634 ResponsiveSpecsProvider allAppsSpecs = ResponsiveSpecsProvider.create(
Jordan Silva575c3bd2023-07-21 12:00:43 +0100635 new ResourceHelper(context,
Jordan Silvaf2402e22023-10-26 19:53:16 +0100636 isTwoPanels ? inv.allAppsSpecsTwoPanelId : inv.allAppsSpecsId),
637 ResponsiveSpecType.AllApps);
Jordan Silva8f7986a2023-11-08 12:11:25 +0000638 mResponsiveAllAppsWidthSpec = allAppsSpecs.getCalculatedSpec(responsiveAspectRatio,
Jordan Silva8b3fa142023-11-13 21:31:38 +0000639 DimensionType.WIDTH, numShownAllAppsColumns, availableWidthPx,
Jordan Silva8f7986a2023-11-08 12:11:25 +0000640 mResponsiveWorkspaceWidthSpec);
641 mResponsiveAllAppsHeightSpec = allAppsSpecs.getCalculatedSpec(responsiveAspectRatio,
Thales Limaa25cd902023-11-01 12:00:32 +0000642 DimensionType.HEIGHT, inv.numRows, heightPx - mInsets.top,
Jordan Silva8f7986a2023-11-08 12:11:25 +0000643 mResponsiveWorkspaceHeightSpec);
Jordan Silvaf2402e22023-10-26 19:53:16 +0100644
645 ResponsiveSpecsProvider folderSpecs = ResponsiveSpecsProvider.create(
646 new ResourceHelper(context,
647 isTwoPanels ? inv.folderSpecsTwoPanelId : inv.folderSpecsId),
648 ResponsiveSpecType.Folder);
649 mResponsiveFolderWidthSpec = folderSpecs.getCalculatedSpec(responsiveAspectRatio,
Thales Lima07c6b8d2023-11-08 18:22:38 +0000650 DimensionType.WIDTH, numFolderColumns,
Jordan Silva8f7986a2023-11-08 12:11:25 +0000651 mResponsiveWorkspaceWidthSpec.getAvailableSpace(),
652 mResponsiveWorkspaceWidthSpec);
Jordan Silvaf2402e22023-10-26 19:53:16 +0100653 mResponsiveFolderHeightSpec = folderSpecs.getCalculatedSpec(responsiveAspectRatio,
Thales Lima07c6b8d2023-11-08 18:22:38 +0000654 DimensionType.HEIGHT, numFolderRows,
Jordan Silva8f7986a2023-11-08 12:11:25 +0000655 mResponsiveWorkspaceHeightSpec.getAvailableSpace(),
656 mResponsiveWorkspaceHeightSpec);
Jordan Silva999dd2a2023-11-17 19:31:43 +0000657
658 ResponsiveCellSpecsProvider allAppsCellSpecs = ResponsiveCellSpecsProvider.create(
659 new ResourceHelper(context,
660 isTwoPanels ? inv.allAppsCellSpecsTwoPanelId
661 : inv.allAppsCellSpecsId));
662 mResponsiveAllAppsCellSpec = allAppsCellSpecs.getCalculatedSpec(
663 responsiveAspectRatio,
664 mResponsiveAllAppsHeightSpec.getAvailableSpace(),
665 mResponsiveWorkspaceCellSpec);
Thales Lima79456492023-05-23 11:32:22 +0100666 }
667
668 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
669 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
670
Alex Chau635b3ab2022-01-26 16:49:10 +0000671 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Pat Manning1695cc72023-07-05 11:45:13 +0100672 overviewTaskIconSizePx = enableOverviewIconMenu() ? res.getDimensionPixelSize(
673 R.dimen.task_thumbnail_icon_menu_drawable_touch_size) : res.getDimensionPixelSize(
674 R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100675 overviewTaskIconDrawableSizePx =
676 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
677 overviewTaskIconDrawableSizeGridPx =
678 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Pat Manning1695cc72023-07-05 11:45:13 +0100679 overviewTaskIconAppChipMenuDrawableSizePx = res.getDimensionPixelSize(
680 R.dimen.task_thumbnail_icon_menu_drawable_size);
681 overviewTaskThumbnailTopMarginPx =
682 enableOverviewIconMenu() ? 0 : overviewTaskIconSizePx + overviewTaskMarginPx;
Andy Wickhambc3bac42023-08-07 16:02:23 -0700683 // Don't add margin with floating search bar to minimize risk of overlapping.
684 overviewActionsTopMarginPx = FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get() ? 0
685 : res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000686 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
687 overviewActionsButtonSpacing = res.getDimensionPixelSize(
688 R.dimen.overview_actions_button_spacing);
Andy Wickhambc3bac42023-08-07 16:02:23 -0700689 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700690 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000691 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700692
Jeremy Sim0ac47082022-10-10 13:59:40 -0700693 splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset);
694
Jon Miranda2ed276e2017-06-29 11:36:34 -0700695 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400696 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700697
Thales Lima79456492023-05-23 11:32:22 +0100698 calculateAndSetWorkspaceVerticalPadding(context, inv, extraSpace);
Pat Manning08610ca2022-04-05 21:03:16 +0100699
700 int cellLayoutPadding =
701 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
702 R.dimen.cell_layout_padding);
703 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
704 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800705 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800706
Thales Lima7eee74b2023-03-16 16:00:55 -0300707 // Folder scaling requires correct workspace paddings
708 updateAvailableFolderCellDimensions(res);
709
Thales Limaffc68b02023-01-09 16:20:23 +0000710 mMinHotseatIconSpacePx = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
711 mMinHotseatQsbWidthPx = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
712 mMaxHotseatIconSpacePx = areNavButtonsInline
Thales Lima6a590062022-11-22 15:52:49 +0000713 ? res.getDimensionPixelSize(R.dimen.max_hotseat_icon_space) : Integer.MAX_VALUE;
Thales Lima425f6822022-05-10 13:44:58 -0300714 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima6a590062022-11-22 15:52:49 +0000715 recalculateHotseatWidthAndBorderSpace();
Alex Chau206ede92022-08-01 17:46:12 +0100716
Jordan Silva3646a1b2023-08-02 13:52:52 +0100717 if (mIsResponsiveGrid && isVerticalBarLayout()) {
718 hotseatBorderSpace = cellLayoutBorderSpacePx.y;
719 }
720
Alex Chau206ede92022-08-01 17:46:12 +0100721 // AllApps height calculation depends on updated cellSize
722 if (isTablet) {
723 int collapseHandleHeight =
724 res.getDimensionPixelOffset(R.dimen.bottom_sheet_handle_area_height);
725 int contentHeight = heightPx - collapseHandleHeight - hotseatQsbHeight;
726 int targetContentHeight = (int) (allAppsCellHeightPx * ALL_APPS_TABLET_MAX_ROWS);
Thales Limab433c9c2023-10-30 12:24:05 +0000727 allAppsPadding.top = Math.max(mInsets.top, contentHeight - targetContentHeight);
728 allAppsShiftRange = heightPx - allAppsPadding.top;
Alex Chau206ede92022-08-01 17:46:12 +0100729 } else {
Thales Limab433c9c2023-10-30 12:24:05 +0000730 allAppsPadding.top = 0;
Alex Chau206ede92022-08-01 17:46:12 +0100731 allAppsShiftRange =
732 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
733 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100734 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
735 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300736
Alex Chaua02eddc2021-04-29 00:36:06 +0100737 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
738 R.dimen.drag_flingToDeleteMinVelocity);
739
Sihua Mae04aa202022-07-18 12:43:56 -0700740 mViewScaleProvider = viewScaleProvider;
741
Jon Miranda2b25ded2023-02-02 14:48:45 -0800742 dimensionOverrideProvider.accept(this);
743
Tony Wickham1237df02017-02-24 08:59:36 -0800744 // This is done last, after iconSizePx is calculated above.
Sunny Goyal799e1202023-02-09 10:54:28 -0800745 mDotRendererWorkSpace = createDotRenderer(context, iconSizePx, dotRendererCache);
746 mDotRendererAllApps = createDotRenderer(context, allAppsIconSizePx, dotRendererCache);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700747 }
748
749 private static DotRenderer createDotRenderer(
Sunny Goyal799e1202023-02-09 10:54:28 -0800750 @NonNull Context context, int size, @NonNull SparseArray<DotRenderer> cache) {
Sunny Goyal65190ae2022-08-02 14:16:26 -0700751 DotRenderer renderer = cache.get(size);
752 if (renderer == null) {
Sunny Goyal799e1202023-02-09 10:54:28 -0800753 renderer = new DotRenderer(size, getShapePath(context, DEFAULT_DOT_SIZE),
754 DEFAULT_DOT_SIZE);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700755 cache.put(size, renderer);
756 }
757 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700758 }
759
Thales Lima425f6822022-05-10 13:44:58 -0300760 /**
Fengjiang Li6c590822023-09-25 15:04:57 -0700761 * Return maximum of all apps row count displayed on screen. Note that 1) Partially displayed
762 * row is counted as 1 row, and 2) we don't exclude the space of floating search bar. This
763 * method is used for calculating number of {@link BubbleTextView} we need to pre-inflate. Thus
764 * reasonable over estimation is fine.
765 */
766 public int getMaxAllAppsRowCount() {
Thales Limab433c9c2023-10-30 12:24:05 +0000767 return (int) (Math.ceil((availableHeightPx - allAppsPadding.top)
Fengjiang Li6c590822023-09-25 15:04:57 -0700768 / (float) allAppsCellHeightPx));
769 }
770
771 /**
Thales Lima425f6822022-05-10 13:44:58 -0300772 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
773 * width of the hotseat.
774 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100775 private int calculateQsbWidth(int hotseatBorderSpace) {
Thales Lima425f6822022-05-10 13:44:58 -0300776 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100777 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300778 return getIconToIconWidthForColumns(columns)
779 - iconSizePx * numShownHotseatIcons
780 - hotseatBorderSpace * numShownHotseatIcons;
781 } else {
782 int columns = inv.hotseatColumnSpan[mTypeIndex];
783 return getIconToIconWidthForColumns(columns);
784 }
785 }
Thales Lima2903a622022-03-17 13:52:19 +0000786
Thales Lima425f6822022-05-10 13:44:58 -0300787 private int getIconToIconWidthForColumns(int columns) {
788 return columns * getCellSize().x
789 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400790 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000791 }
792
Thales Limad90faab2021-09-21 17:18:47 +0100793 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
Thales Lima79456492023-05-23 11:32:22 +0100794 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +0000795 return mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
Thales Lima79456492023-05-23 11:32:22 +0100796 }
797
Thales Limad90faab2021-09-21 17:18:47 +0100798 if (isVerticalBarLayout()) {
799 return 0;
800 }
801
Thales Lima79456492023-05-23 11:32:22 +0100802 return mIsScalableGrid
Thales Lima83bedbf2021-10-05 17:47:39 +0100803 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
804 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100805 }
806
Thales Lima79456492023-05-23 11:32:22 +0100807 private void calculateAndSetWorkspaceVerticalPadding(Context context,
808 InvariantDeviceProfile inv,
809 int extraSpace) {
810 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +0000811 workspaceTopPadding = mResponsiveWorkspaceHeightSpec.getStartPaddingPx();
812 workspaceBottomPadding = mResponsiveWorkspaceHeightSpec.getEndPaddingPx();
Thales Lima79456492023-05-23 11:32:22 +0100813 } else if (mIsScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
814 // Paddings were created assuming no scaling, so we first unscale the extra space.
815 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
816 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
817 DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
818 maxEmptySpace = padding.getMaxEmptySpacePx();
819
820 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
821 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
822
823 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
824 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
825 }
826 }
827
Thales Limab8c05952022-05-23 16:58:38 +0100828 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
829 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700830 // Ensure there is enough space for folder icons, which have a slightly larger radius.
Jordan Silva3646a1b2023-08-02 13:52:52 +0100831 hotseatCellHeightPx = getIconSizeWithOverlap(hotseatIconSizePx);
Thales Limab8c05952022-05-23 16:58:38 +0100832
Jon Miranda0d284852021-06-22 14:50:55 -0700833 if (isVerticalBarLayout()) {
Thales Lima8e11d532023-08-31 13:40:26 +0000834 hotseatBarSizePx = hotseatIconSizePx + mHotseatBarEdgePaddingPx
835 + mHotseatBarWorkspaceSpacePx;
Thales Limab8c05952022-05-23 16:58:38 +0100836 } else if (isQsbInline) {
837 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
838 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700839 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100840 hotseatBarSizePx = hotseatIconSizePx
841 + hotseatQsbSpace
842 + hotseatQsbVisualHeight
843 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700844 }
845 }
846
Thales Lima6a590062022-11-22 15:52:49 +0000847 /**
848 * Calculates the width of the hotseat, changing spaces between the icons and removing icons if
849 * necessary.
850 */
851 public void recalculateHotseatWidthAndBorderSpace() {
Thales Lima79456492023-05-23 11:32:22 +0100852 if (!mIsScalableGrid) return;
Thales Lima6a590062022-11-22 15:52:49 +0000853
854 int columns = inv.hotseatColumnSpan[mTypeIndex];
855 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
856 hotseatBorderSpace = calculateHotseatBorderSpace(hotseatWidthPx, /* numExtraBorder= */ 0);
Thales Lima9938c2f2022-07-25 14:38:16 +0100857 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
Thales Lima6a590062022-11-22 15:52:49 +0000858 // Spaces should be correct when the nav buttons are not inline
Thales Lima9938c2f2022-07-25 14:38:16 +0100859 if (!areNavButtonsInline) {
860 return;
861 }
862
Thales Lima6a590062022-11-22 15:52:49 +0000863 // The side space with inline buttons should be what is defined in InvariantDeviceProfile
Jon Mirandae17a9492023-03-08 16:42:20 -0800864 int sideSpacePx = inlineNavButtonsEndSpacingPx;
Thales Limaffc68b02023-01-09 16:20:23 +0000865 int maxHotseatWidthPx = availableWidthPx - sideSpacePx - hotseatBarEndOffset;
866 int maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
867 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000868 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100869
Thales Limaffc68b02023-01-09 16:20:23 +0000870 if (hotseatBorderSpace >= mMinHotseatIconSpacePx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100871 return;
872 }
873
874 // Border space can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000875 hotseatBorderSpace = mMinHotseatIconSpacePx;
Thales Lima6a590062022-11-22 15:52:49 +0000876 int requiredWidth = getHotseatRequiredWidth();
Thales Lima9938c2f2022-07-25 14:38:16 +0100877
878 // If there is an inline qsb, change its size
879 if (isQsbInline) {
Thales Limaffc68b02023-01-09 16:20:23 +0000880 hotseatQsbWidth -= requiredWidth - maxHotseatWidthPx;
881 if (hotseatQsbWidth >= mMinHotseatQsbWidthPx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100882 return;
883 }
884
885 // QSB can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000886 hotseatQsbWidth = mMinHotseatQsbWidthPx;
Thales Lima9938c2f2022-07-25 14:38:16 +0100887 }
888
Thales Limaffc68b02023-01-09 16:20:23 +0000889 maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
Thales Lima6a590062022-11-22 15:52:49 +0000890
Thales Lima9938c2f2022-07-25 14:38:16 +0100891 // If it still doesn't fit, start removing icons
892 do {
893 numShownHotseatIcons--;
Thales Limaffc68b02023-01-09 16:20:23 +0000894 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000895 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Limaffc68b02023-01-09 16:20:23 +0000896 } while (hotseatBorderSpace < mMinHotseatIconSpacePx && numShownHotseatIcons > 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100897 }
898
Thales Lima78d00ad2021-09-30 11:29:06 +0100899 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100900 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100901 }
902
903 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima79456492023-05-23 11:32:22 +0100904 int horizontalSpacePx = 0;
905 int verticalSpacePx = 0;
Thales Lima78d00ad2021-09-30 11:29:06 +0100906
Thales Lima79456492023-05-23 11:32:22 +0100907 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +0000908 horizontalSpacePx = mResponsiveWorkspaceWidthSpec.getGutterPx();
909 verticalSpacePx = mResponsiveWorkspaceHeightSpec.getGutterPx();
Thales Lima79456492023-05-23 11:32:22 +0100910 } else if (mIsScalableGrid) {
911 horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
912 verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
913 }
Thales Lima78d00ad2021-09-30 11:29:06 +0100914
915 return new Point(horizontalSpacePx, verticalSpacePx);
916 }
917
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700918 public Info getDisplayInfo() {
919 return mInfo;
920 }
921
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700922 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800923 WindowBounds bounds = new WindowBounds(
924 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700925 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100926 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700927
928 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
929 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
930 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
931
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700932 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700933 .setWindowBounds(bounds)
Alex Chauab800f72022-12-13 17:46:06 +0000934 .setIsMultiDisplay(isMultiDisplay)
Alex Chau6ed408f2022-03-04 12:58:05 +0000935 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700936 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000937 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800938 }
939
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700940 public DeviceProfile copy(Context context) {
941 return toBuilder(context).build();
942 }
943
944 /**
945 * TODO: Move this to the builder as part of setMultiWindowMode
946 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700947 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700948 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700949 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700950 .setMultiWindowMode(true)
951 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800952
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800953 // We use these scales to measure and layout the widgets using their full invariant profile
954 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
955 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
956 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700957 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
958 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
959 profile = profile.toBuilder(context)
960 .setViewScaleProvider(i -> p)
961 .build();
962 }
963
964 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800965
Jon Miranda93e1f042016-11-11 14:13:04 -0800966 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700967 }
968
Adam Cohen63f1ec02014-08-12 09:23:13 -0700969 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400970 * Checks if there is enough space for labels on the workspace.
971 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700972 * It is important to call this method after the All Apps variables have been set.
973 */
Jon Miranda941375e2021-03-31 13:10:45 -0400974 private void hideWorkspaceLabelsIfNotEnoughSpace() {
975 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
976 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
977 - iconTextHeight;
978
Jordan Silva3646a1b2023-08-02 13:52:52 +0100979 if (mIsResponsiveGrid) {
Thales Limabba07722023-10-11 18:16:29 +0000980 iconTextSizePx = 0;
981 iconDrawablePaddingPx = 0;
982 int iconSizeWithOverlap = getIconSizeWithOverlap(iconSizePx);
983 cellYPaddingPx = Math.max(0, getCellSize().y - iconSizeWithOverlap) / 2;
984 autoResizeAllAppsCells();
Jordan Silva3646a1b2023-08-02 13:52:52 +0100985
986 return;
987 }
988
Jon Miranda941375e2021-03-31 13:10:45 -0400989 // We want enough space so that the text is closer to its corresponding icon.
990 if (workspaceCellPaddingY < iconTextHeight) {
991 iconTextSizePx = 0;
992 iconDrawablePaddingPx = 0;
Jordan Silva3646a1b2023-08-02 13:52:52 +0100993 cellHeightPx = getIconSizeWithOverlap(iconSizePx);
Jon Miranda941375e2021-03-31 13:10:45 -0400994 autoResizeAllAppsCells();
995 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700996 }
Jon Miranda1091e532017-07-21 13:31:50 -0700997
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700998 /**
Jon Miranda228877d2021-02-09 11:05:00 -0500999 * Returns the amount of extra (or unused) vertical space.
1000 */
1001 private int updateAvailableDimensions(Resources res) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001002 iconCenterVertically = mIsScalableGrid || mIsResponsiveGrid;
1003
1004 if (mIsResponsiveGrid) {
Jordan Silva15cacd52023-11-28 14:32:05 +00001005 iconSizePx = mResponsiveWorkspaceCellSpec.getIconSize();
1006 iconTextSizePx = mResponsiveWorkspaceCellSpec.getIconTextSize();
1007 mIconDrawablePaddingOriginalPx = mResponsiveWorkspaceCellSpec.getIconDrawablePadding();
Jordan Silva999dd2a2023-11-17 19:31:43 +00001008 updateIconSize(1f, res);
1009 updateWorkspacePadding();
1010 return 0;
1011 }
1012
Alex Chaua68164d2022-12-15 16:16:03 +00001013 float invIconSizeDp = inv.iconSize[mTypeIndex];
1014 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
1015 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
1016 iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
1017
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001018 updateIconSize(1f, res);
Pat Manning08610ca2022-04-05 21:03:16 +01001019 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -05001020
1021 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +01001022 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +00001023 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -05001024 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -05001025 float scaleY = maxHeight / usedHeight;
1026 boolean shouldScale = scaleY < 1f;
1027
1028 float scaleX = 1f;
Thales Lima79456492023-05-23 11:32:22 +01001029 if (mIsScalableGrid) {
Jon Mirandae126d722021-02-25 10:45:20 -05001030 // We scale to fit the cellWidth and cellHeight in the available space.
1031 // The benefit of scalable grids is that we can get consistent aspect ratios between
1032 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +01001033 float usedWidth =
1034 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -05001035 // We do not subtract padding here, as we also scale the workspace padding if needed.
1036 scaleX = availableWidthPx / usedWidth;
1037 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -07001038 }
Jon Mirandae126d722021-02-25 10:45:20 -05001039
1040 if (shouldScale) {
1041 float scale = Math.min(scaleX, scaleY);
1042 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +01001043 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -05001044 }
1045
Jon Miranda228877d2021-02-09 11:05:00 -05001046 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -07001047 }
1048
Pat Manninga2e14992022-04-22 11:29:17 +01001049 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +01001050 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
1051 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
1052 }
1053
Pat Manninga2e14992022-04-22 11:29:17 +01001054 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +00001055 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +01001056 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
1057 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -05001058 }
1059
Jordan Silva376036a2023-11-08 15:56:40 +00001060 private int getNormalizedIconDrawablePadding(int iconSizePx, int iconDrawablePadding) {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001061 // TODO(b/235886078): workaround needed because of this bug
1062 // Icons are 10% larger on XML than their visual size,
1063 // so remove that extra space to get labels closer to the correct padding
Jordan Silva999dd2a2023-11-17 19:31:43 +00001064 int iconVisibleSizePx = Math.round(ICON_VISIBLE_AREA_FACTOR * iconSizePx);
Jordan Silva376036a2023-11-08 15:56:40 +00001065 return Math.max(0, iconDrawablePadding - ((iconSizePx - iconVisibleSizePx) / 2));
1066 }
1067
1068 private int getNormalizedIconDrawablePadding() {
1069 return getNormalizedIconDrawablePadding(iconSizePx, mIconDrawablePaddingOriginalPx);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001070 }
1071
1072 private int getNormalizedFolderChildDrawablePaddingPx(int textHeight) {
1073 // TODO(b/235886078): workaround needed because of this bug
1074 // Icons are 10% larger on XML than their visual size,
1075 // so remove that extra space to get labels closer to the correct padding
1076 int drawablePadding = (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3;
1077
1078 int iconVisibleSizePx = Math.round(ICON_VISIBLE_AREA_FACTOR * folderChildIconSizePx);
1079 int iconSizeDiff = folderChildIconSizePx - iconVisibleSizePx;
1080 return Math.max(0, drawablePadding - iconSizeDiff / 2);
1081 }
1082
Jordan Silva3646a1b2023-08-02 13:52:52 +01001083 private int getIconSizeWithOverlap(int iconSize) {
1084 return (int) Math.ceil(iconSize * ICON_OVERLAP_FACTOR);
1085 }
1086
Jon Miranda6f7e9702019-09-16 14:44:14 -07001087 /**
1088 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
1089 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
1090 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
1091 */
Tony Wickham7ba547c2021-02-02 17:12:08 -08001092 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -07001093 // Icon scale should never exceed 1, otherwise pixellation may occur.
1094 iconScale = Math.min(1f, scale);
1095 cellScaleToFit = scale;
1096
Jon Miranda18751b62017-07-31 17:25:27 -07001097 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -08001098 final boolean isVerticalLayout = isVerticalBarLayout();
Thales Lima080d8902022-03-28 15:30:29 +01001099 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -05001100
Thales Lima79456492023-05-23 11:32:22 +01001101 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001102 cellWidthPx = mResponsiveWorkspaceWidthSpec.getCellSizePx();
1103 cellHeightPx = mResponsiveWorkspaceHeightSpec.getCellSizePx();
Thales Lima79456492023-05-23 11:32:22 +01001104
Thales Lima2759aa32023-06-05 16:25:45 +01001105 if (cellWidthPx < iconSizePx) {
1106 // get a smaller icon size
1107 iconSizePx = mIconSizeSteps.getIconSmallerThan(cellWidthPx);
Thales Lima2759aa32023-06-05 16:25:45 +01001108 }
1109
Thales Lima93ee8fc2023-06-05 17:07:11 +01001110 iconDrawablePaddingPx = getNormalizedIconDrawablePadding();
Thales Lima93ee8fc2023-06-05 17:07:11 +01001111
Thales Lima24ceca62023-09-25 16:21:17 -07001112 CellContentDimensions cellContentDimensions = new CellContentDimensions(iconSizePx,
1113 iconDrawablePaddingPx,
1114 iconTextSizePx);
Thales Limabba07722023-10-11 18:16:29 +00001115 if (isVerticalLayout) {
1116 if (cellHeightPx < iconSizePx) {
1117 cellContentDimensions.setIconSizePx(
1118 mIconSizeSteps.getIconSmallerThan(cellHeightPx));
1119 }
Thales Lima24ceca62023-09-25 16:21:17 -07001120 } else {
1121 cellContentDimensions.resizeToFitCellHeight(cellHeightPx, mIconSizeSteps);
Thales Lima2759aa32023-06-05 16:25:45 +01001122 }
Thales Lima24ceca62023-09-25 16:21:17 -07001123 iconSizePx = cellContentDimensions.getIconSizePx();
1124 iconDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1125 iconTextSizePx = cellContentDimensions.getIconTextSizePx();
1126 int cellContentHeight = cellContentDimensions.getCellContentHeight();
Thales Lima2759aa32023-06-05 16:25:45 +01001127
1128 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Lima79456492023-05-23 11:32:22 +01001129 } else if (mIsScalableGrid) {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001130 iconDrawablePaddingPx = (int) (getNormalizedIconDrawablePadding() * iconScale);
Thales Lima83bedbf2021-10-05 17:47:39 +01001131 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
1132 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001133
1134 if (cellWidthPx < iconSizePx) {
1135 // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger.
1136 int numColumns = getPanelCount() * inv.numColumns;
1137 int numBorders = numColumns - 1;
1138 int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns;
1139 if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) {
1140 cellWidthPx = iconSizePx;
1141 cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders;
1142 } else {
1143 // If it still doesn't fit, set borderSpace to 0 and distribute the space for
1144 // cellWidth, and reduce iconSize.
1145 cellWidthPx = (cellWidthPx * numColumns
1146 + cellLayoutBorderSpacePx.x * numBorders) / numColumns;
1147 iconSizePx = Math.min(iconSizePx, cellWidthPx);
1148 cellLayoutBorderSpacePx.x = 0;
1149 }
1150 }
1151
Thales Lima93ee8fc2023-06-05 17:07:11 +01001152 int cellTextAndPaddingHeight =
1153 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +00001154 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
1155 if (cellHeightPx < cellContentHeight) {
1156 // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight
1157 // bigger.
1158 int numBorders = inv.numRows - 1;
1159 int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows;
1160 if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) {
1161 cellHeightPx = cellContentHeight;
1162 cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders;
1163 } else {
Alex Chau06f36e82023-01-06 10:50:54 +00001164 // If it still doesn't fit, set borderSpace to 0 to recover space.
Alex Chaube753132022-12-09 16:46:54 +00001165 cellHeightPx = (cellHeightPx * inv.numRows
1166 + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows;
Alex Chaube753132022-12-09 16:46:54 +00001167 cellLayoutBorderSpacePx.y = 0;
Alex Chau06f36e82023-01-06 10:50:54 +00001168 // Reduce iconDrawablePaddingPx to make cellContentHeight smaller.
1169 int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx;
1170 if (cellContentWithoutPadding <= cellHeightPx) {
1171 iconDrawablePaddingPx = cellContentHeight - cellHeightPx;
1172 } else {
1173 // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space,
1174 // then proportional reduce iconSizePx and iconTextSizePx to fit.
1175 iconDrawablePaddingPx = 0;
1176 float ratio = cellHeightPx / (float) cellContentWithoutPadding;
1177 iconSizePx = (int) (iconSizePx * ratio);
1178 iconTextSizePx = (int) (iconTextSizePx * ratio);
1179 }
1180 cellTextAndPaddingHeight =
1181 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +00001182 }
1183 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
1184 }
Jon Mirandae126d722021-02-25 10:45:20 -05001185 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +01001186 desiredWorkspaceHorizontalMarginPx =
1187 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -05001188 } else {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001189 iconDrawablePaddingPx = (int) (getNormalizedIconDrawablePadding() * iconScale);
Jon Mirandae126d722021-02-25 10:45:20 -05001190 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001191 cellHeightPx = getIconSizeWithOverlap(iconSizePx)
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001192 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -05001193 + Utilities.calculateTextHeight(iconTextSizePx);
1194 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
1195 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
1196 && !isMultiWindowMode) {
1197 // Ensures that the label is closer to its corresponding icon. This is not an issue
1198 // with vertical bar layout or multi-window mode since the issue is handled
1199 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
1200 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
1201 iconDrawablePaddingPx = cellPaddingY;
1202 }
Jon Miranda846455e2017-10-02 14:58:52 -07001203 }
Jon Miranda18751b62017-07-31 17:25:27 -07001204
Sunny Goyalae190ff2020-04-14 00:19:01 +00001205 // All apps
Thales Limaabfe3642023-05-24 18:08:53 +01001206 if (mIsResponsiveGrid) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001207 updateAllAppsWithResponsiveMeasures();
Thales Limaabfe3642023-05-24 18:08:53 +01001208 } else {
1209 updateAllAppsIconSize(scale, res);
1210 }
1211 updateAllAppsContainerWidth();
1212 if (isVerticalBarLayout()) {
1213 hideWorkspaceLabelsIfNotEnoughSpace();
1214 }
Brandon Dayauon3cdb32c2023-08-22 21:26:37 -07001215 if (FeatureFlags.enableTwolineAllapps()) {
1216 // Add extra textHeight to the existing allAppsCellHeight.
1217 allAppsCellHeightPx += Utilities.calculateTextHeight(allAppsIconTextSizePx);
1218 }
Winson Chungb3800242013-10-24 11:01:54 -07001219
Thales Limab8c05952022-05-23 16:58:38 +01001220 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -07001221
Sunny Goyalbaec6ff2016-09-14 11:26:21 -07001222 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -07001223 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
1224 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Sunny Goyal6c304b12023-04-10 12:03:04 -07001225
1226 // Update widget padding:
1227 float minSpacing = pxFromDp(MIN_WIDGET_PADDING_DP, mMetrics);
1228 if (cellLayoutBorderSpacePx.x < minSpacing
1229 || cellLayoutBorderSpacePx.y < minSpacing) {
1230 widgetPadding.left = widgetPadding.right =
1231 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.x));
1232 widgetPadding.top = widgetPadding.bottom =
1233 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.y));
1234 } else {
1235 widgetPadding.setEmpty();
1236 }
Winson Chung0f785722015-04-08 10:27:49 -07001237 }
1238
Thales Lima425f6822022-05-10 13:44:58 -03001239 /**
Thales Lima6a590062022-11-22 15:52:49 +00001240 * This method calculates the space between the icons to achieve a certain width.
Thales Lima425f6822022-05-10 13:44:58 -03001241 */
Thales Lima6a590062022-11-22 15:52:49 +00001242 private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) {
Jordan Silvad9227182023-08-17 15:53:59 +01001243 int numBorders = (numShownHotseatIcons - 1 + numExtraBorder);
1244 if (numBorders <= 0) return 0;
1245
Thales Lima9938c2f2022-07-25 14:38:16 +01001246 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
Jordan Silvad9227182023-08-17 15:53:59 +01001247 int hotseatBorderSpacePx = (int) (hotseatWidthPx - hotseatIconsTotalPx) / numBorders;
Thales Limaffc68b02023-01-09 16:20:23 +00001248 return Math.min(hotseatBorderSpacePx, mMaxHotseatIconSpacePx);
Thales Lima425f6822022-05-10 13:44:58 -03001249 }
1250
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001251 /**
1252 * Updates the iconSize for allApps* variants.
1253 */
Brian Isganitisa9a78112022-05-23 18:11:47 -07001254 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +01001255 allAppsBorderSpacePx = new Point(
1256 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
1257 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001258 // AllApps cells don't have real space between cells,
1259 // so we add the border space to the cell height
Alex Chaube753132022-12-09 16:46:54 +00001260 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics)
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001261 + allAppsBorderSpacePx.y;
1262 // but width is just the cell,
1263 // the border is added in #updateAllAppsContainerWidth
Thales Lima79456492023-05-23 11:32:22 +01001264 if (mIsScalableGrid) {
Alex Chaube753132022-12-09 16:46:54 +00001265 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1266 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001267 allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding();
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001268 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001269
1270 if (allAppsCellWidthPx < allAppsIconSizePx) {
1271 // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to
1272 // make allAppsCellWidth bigger.
1273 int numBorders = inv.numAllAppsColumns - 1;
1274 int extraWidthRequired =
1275 (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns;
1276 if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) {
1277 allAppsCellWidthPx = allAppsIconSizePx;
1278 allAppsBorderSpacePx.x -= extraWidthRequired / numBorders;
1279 } else {
1280 // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space
1281 // for allAppsCellWidth, and reduce allAppsIconSize.
1282 allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns
1283 + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns;
1284 allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx);
1285 allAppsBorderSpacePx.x = 0;
1286 }
1287 }
1288
1289 int cellContentHeight = allAppsIconSizePx
1290 + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y;
1291 if (allAppsCellHeightPx < cellContentHeight) {
1292 // Increase allAppsCellHeight to fit its content.
1293 allAppsCellHeightPx = cellContentHeight;
1294 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001295 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001296 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
1297 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001298 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1299 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001300 allAppsIconDrawablePaddingPx =
1301 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001302 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001303 }
Thales Limaabfe3642023-05-24 18:08:53 +01001304 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001305
Jordan Silva999dd2a2023-11-17 19:31:43 +00001306 private void updateAllAppsWithResponsiveMeasures() {
1307 allAppsIconSizePx = mResponsiveAllAppsCellSpec.getIconSize();
1308 allAppsIconTextSizePx = mResponsiveAllAppsCellSpec.getIconTextSize();
1309 allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding(allAppsIconSizePx,
1310 mResponsiveAllAppsCellSpec.getIconDrawablePadding());
Thales Limaabfe3642023-05-24 18:08:53 +01001311 allAppsBorderSpacePx = new Point(
Jordan Silva8f7986a2023-11-08 12:11:25 +00001312 mResponsiveAllAppsWidthSpec.getGutterPx(),
1313 mResponsiveAllAppsHeightSpec.getGutterPx()
Thales Limaabfe3642023-05-24 18:08:53 +01001314 );
Jordan Silva999dd2a2023-11-17 19:31:43 +00001315 allAppsCellHeightPx = mResponsiveAllAppsHeightSpec.getCellSizePx();
Jordan Silva8f7986a2023-11-08 12:11:25 +00001316 allAppsCellWidthPx = mResponsiveAllAppsWidthSpec.getCellSizePx();
Thales Limaa25cd902023-11-01 12:00:32 +00001317
1318 // This workaround is needed to align AllApps icons with Workspace icons
1319 // since AllApps doesn't have borders between cells
1320 int halfBorder = allAppsBorderSpacePx.x / 2;
Jordan Silva8f7986a2023-11-08 12:11:25 +00001321 allAppsPadding.left = mResponsiveAllAppsWidthSpec.getStartPaddingPx() - halfBorder;
1322 allAppsPadding.right = mResponsiveAllAppsWidthSpec.getEndPaddingPx() - halfBorder;
Jordan Silva376036a2023-11-08 15:56:40 +00001323
Jordan Silva376036a2023-11-08 15:56:40 +00001324
1325 // Reduce the size of the app icon if it doesn't fit
1326 if (allAppsCellWidthPx < allAppsIconSizePx) {
1327 // get a smaller icon size
1328 allAppsIconSizePx = mIconSizeSteps.getIconSmallerThan(allAppsCellWidthPx);
1329 }
1330
1331 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1332 allAppsIconSizePx, allAppsIconDrawablePaddingPx, (int) allAppsIconTextSizePx);
1333
1334 if (allAppsCellHeightPx < cellContentDimensions.getCellContentHeight()) {
1335 if (isVerticalBarLayout()) {
1336 if (allAppsCellHeightPx < iconSizePx) {
1337 cellContentDimensions.setIconSizePx(
1338 mIconSizeSteps.getIconSmallerThan(allAppsCellHeightPx));
1339 }
1340 } else {
1341 cellContentDimensions.resizeToFitCellHeight(allAppsCellHeightPx,
1342 mIconSizeSteps);
1343 }
1344 allAppsIconSizePx = cellContentDimensions.getIconSizePx();
1345 allAppsIconDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1346 allAppsIconTextSizePx = cellContentDimensions.getIconTextSizePx();
1347 }
Jordan Silva999dd2a2023-11-17 19:31:43 +00001348
1349 allAppsCellHeightPx += mResponsiveAllAppsHeightSpec.getGutterPx();
Thales Limaabfe3642023-05-24 18:08:53 +01001350 }
1351
1352 /**
1353 * Re-computes the all-apps cell size to be independent of workspace
1354 */
1355 public void autoResizeAllAppsCells() {
1356 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
1357 int topBottomPadding = textHeight;
1358 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
1359 + textHeight + (topBottomPadding * 2);
1360 }
1361
1362 private void updateAllAppsContainerWidth() {
1363 int cellLayoutHorizontalPadding =
1364 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
1365 if (isTablet) {
1366 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
1367 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Thales Limab433c9c2023-10-30 12:24:05 +00001368 + allAppsPadding.left + allAppsPadding.right;
Thales Limaabfe3642023-05-24 18:08:53 +01001369 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
Thales Limaa25cd902023-11-01 12:00:32 +00001370 } else if (!mIsResponsiveGrid) {
Thales Limab433c9c2023-10-30 12:24:05 +00001371 allAppsPadding.left = allAppsPadding.right =
Thales Limaabfe3642023-05-24 18:08:53 +01001372 Math.max(0, desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding
1373 - (allAppsBorderSpacePx.x / 2));
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001374 }
1375 }
1376
Thales Limaabfe3642023-05-24 18:08:53 +01001377 private void setupAllAppsStyle(Context context) {
1378 TypedArray allAppsStyle = context.obtainStyledAttributes(
1379 inv.allAppsStyle != INVALID_RESOURCE_HANDLE ? inv.allAppsStyle
1380 : R.style.AllAppsStyleDefault, R.styleable.AllAppsStyle);
1381
Thales Limab433c9c2023-10-30 12:24:05 +00001382 allAppsPadding.left = allAppsPadding.right = allAppsStyle.getDimensionPixelSize(
Thales Limaabfe3642023-05-24 18:08:53 +01001383 R.styleable.AllAppsStyle_horizontalPadding, 0);
1384 allAppsStyle.recycle();
1385 }
1386
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001387 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001388 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001389
Jordan Silva637f4eb2023-06-13 11:21:53 +01001390 // Responsive grid doesn't need to scale the folder
1391 if (mIsResponsiveGrid) return;
1392
Thales Lima7eee74b2023-03-16 16:00:55 -03001393 // For usability we can't have the folder use the whole width of the screen
Sunny Goyal07b69292018-01-08 14:19:34 -08001394 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -08001395
Thales Lima7eee74b2023-03-16 16:00:55 -03001396 // Check if the folder fit within the available height.
Thales Lima07c6b8d2023-11-08 18:22:38 +00001397 float contentUsedHeight = folderCellHeightPx * numFolderRows
1398 + ((numFolderRows - 1) * folderCellLayoutBorderSpacePx.y)
Thales Lima7eee74b2023-03-16 16:00:55 -03001399 + folderFooterHeightPx
1400 + folderContentPaddingTop;
1401 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001402 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -08001403
Thales Lima7eee74b2023-03-16 16:00:55 -03001404 // Check if the folder fit within the available width.
Thales Lima07c6b8d2023-11-08 18:22:38 +00001405 float contentUsedWidth = folderCellWidthPx * numFolderColumns
1406 + ((numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x)
Thales Lima7eee74b2023-03-16 16:00:55 -03001407 + folderContentPaddingLeftRight * 2;
1408 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001409 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -08001410
1411 float scale = Math.min(scaleX, scaleY);
1412 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001413 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001414 }
1415 }
1416
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001417 private void updateFolderCellSize(float scale, Resources res) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001418 int minLabelTextSize = pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001419 if (mIsResponsiveGrid) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001420 folderChildIconSizePx = mResponsiveWorkspaceCellSpec.getIconSize();
1421 folderChildTextSizePx = mResponsiveWorkspaceCellSpec.getIconTextSize();
1422 folderLabelTextSizePx = Math.max(minLabelTextSize,
1423 (int) (folderChildTextSizePx * folderLabelTextScale));
1424 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
1425
Jordan Silva637f4eb2023-06-13 11:21:53 +01001426 folderCellWidthPx = mResponsiveFolderWidthSpec.getCellSizePx();
Jordan Silva637f4eb2023-06-13 11:21:53 +01001427 folderCellHeightPx = mResponsiveFolderHeightSpec.getCellSizePx();
1428 folderContentPaddingTop = mResponsiveFolderHeightSpec.getStartPaddingPx();
1429 folderFooterHeightPx = mResponsiveFolderHeightSpec.getEndPaddingPx();
1430
1431 folderCellLayoutBorderSpacePx = new Point(mResponsiveFolderWidthSpec.getGutterPx(),
Thales Lima4cfd9502023-07-10 14:01:28 +01001432 mResponsiveFolderHeightSpec.getGutterPx());
Jordan Silva637f4eb2023-06-13 11:21:53 +01001433
1434 folderContentPaddingLeftRight = mResponsiveFolderWidthSpec.getStartPaddingPx();
Jordan Silva12fae112023-06-26 12:51:01 +01001435
1436 // Reduce icon width if it's wider than the expected folder cell width
1437 if (folderCellWidthPx < folderChildIconSizePx) {
1438 folderChildIconSizePx = mIconSizeSteps.getIconSmallerThan(folderCellWidthPx);
1439 }
1440
1441 // Recalculating padding and cell height
1442 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
Jordan Silva12fae112023-06-26 12:51:01 +01001443
Thales Limae9b5e142023-11-04 17:10:13 +00001444 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1445 folderChildIconSizePx,
1446 folderChildDrawablePaddingPx,
1447 folderChildTextSizePx);
1448 cellContentDimensions.resizeToFitCellHeight(folderCellHeightPx, mIconSizeSteps);
1449 folderChildIconSizePx = cellContentDimensions.getIconSizePx();
1450 folderChildDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1451 folderChildTextSizePx = cellContentDimensions.getIconTextSizePx();
Jordan Silva999dd2a2023-11-17 19:31:43 +00001452 folderLabelTextSizePx = Math.max(minLabelTextSize,
Jordan Silva9a3bd8f2023-11-16 18:33:28 +00001453 (int) (folderChildTextSizePx * folderLabelTextScale));
Jordan Silva999dd2a2023-11-17 19:31:43 +00001454 return;
1455 }
1456
1457 float invIconSizeDp = inv.iconSize[mTypeIndex];
1458 float invIconTextSizeDp = inv.iconTextSize[mTypeIndex];
1459 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1460 folderChildTextSizePx = pxFromSp(invIconTextSizeDp, mMetrics, scale);
1461 folderLabelTextSizePx = Math.max(minLabelTextSize,
1462 (int) (folderChildTextSizePx * folderLabelTextScale));
1463 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
1464
1465 if (mIsScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001466 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
Thales Lima7eee74b2023-03-16 16:00:55 -03001467 folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale);
1468 folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale);
1469 } else {
1470 folderCellWidthPx = roundPxValueFromFloat(folderCellWidthPx * scale);
1471 folderCellHeightPx = roundPxValueFromFloat(folderCellHeightPx * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001472 }
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001473
Thales Lima7eee74b2023-03-16 16:00:55 -03001474 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001475 folderCellLayoutBorderSpacePx = new Point(
1476 roundPxValueFromFloat(folderCellLayoutBorderSpacePx.x * scale),
1477 roundPxValueFromFloat(folderCellLayoutBorderSpacePx.y * scale)
1478 );
Thales Lima7eee74b2023-03-16 16:00:55 -03001479 folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale);
1480
Jordan Silva637f4eb2023-06-13 11:21:53 +01001481 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx.x;
Jordan Silva12fae112023-06-26 12:51:01 +01001482
1483 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
Jon Miranda823da222021-03-23 08:08:45 -04001484 } else {
1485 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1486 * scale);
1487 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1488 * scale);
1489
1490 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1491 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Lima7eee74b2023-03-16 16:00:55 -03001492 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001493 folderContentPaddingLeftRight =
1494 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1495 folderFooterHeightPx =
Thales Lima7eee74b2023-03-16 16:00:55 -03001496 roundPxValueFromFloat(
1497 res.getDimensionPixelSize(R.dimen.folder_footer_height_default)
1498 * scale);
1499
Jordan Silva12fae112023-06-26 12:51:01 +01001500 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
Jon Miranda823da222021-03-23 08:08:45 -04001501 }
Jon Mirandabf7d8122016-11-03 15:29:29 -07001502 }
1503
Winson1f064272016-07-18 17:18:02 -07001504 public void updateInsets(Rect insets) {
1505 mInsets.set(insets);
1506 }
1507
Sunny Goyalae6e3182019-04-30 12:04:37 -07001508 /**
1509 * The current device insets. This is generally same as the insets being dispatched to
1510 * {@link Insettable} elements, but can differ if the element is using a different profile.
1511 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001512 public Rect getInsets() {
1513 return mInsets;
1514 }
1515
Sunny Goyal756cd262015-08-20 12:33:21 -07001516 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001517 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001518 }
1519
Sunny Goyal19ff7282021-04-22 10:12:54 -07001520 public Point getCellSize(Point result) {
1521 if (result == null) {
1522 result = new Point();
1523 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001524
Pat Manning25d53342022-05-10 09:58:49 +00001525 int shortcutAndWidgetContainerWidth =
1526 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1527 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1528 inv.numColumns);
1529 int shortcutAndWidgetContainerHeight =
1530 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1531 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1532 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001533 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001534 }
1535
1536 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001537 * Returns the left and right space on the cell, which is the cell width - icon size
1538 */
1539 public int getCellHorizontalSpace() {
1540 return getCellSize().x - iconSizePx;
1541 }
1542
1543 /**
Pat Manning25d53342022-05-10 09:58:49 +00001544 * Gets the number of panels within the workspace.
1545 */
1546 public int getPanelCount() {
1547 return isTwoPanels ? 2 : 1;
1548 }
1549
1550 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001551 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1552 * bottom of the screen.
1553 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001554 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1555 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001556 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001557 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001558 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001559 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001560 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001561 }
1562
1563 /**
1564 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1565 */
Pat Manning25d53342022-05-10 09:58:49 +00001566 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001567 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001568 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001569 }
1570
1571 /**
1572 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1573 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001574 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001575 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001576 return heightPx - (isVerticalBarLayout()
1577 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001578 }
1579
Pat Manningea5c1d22022-04-14 10:58:16 +01001580 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001581 * Gets the scale of the workspace for the spring-loaded edit state.
1582 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001583 public float getWorkspaceSpringLoadScale(Context context) {
1584 float scale =
1585 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1586 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001587 scale = Math.min(scale, 1f);
1588
Pat Manninge63dd252022-08-02 16:15:29 +01001589 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001590 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001591 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001592 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001593 if (scaledWorkspaceWidth > maxAvailableWidth) {
1594 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1595 }
1596 return scale;
1597 }
1598
Pat Manning25d53342022-05-10 09:58:49 +00001599 /**
1600 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1601 *
1602 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1603 * layouts have two Cell Layouts per workspace.
1604 */
1605 public int getCellLayoutWidth() {
1606 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001607 }
1608
Pat Manning25d53342022-05-10 09:58:49 +00001609 /**
1610 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1611 *
1612 * <p>This is the height of a Workspace, less its vertical padding.
1613 */
1614 public int getCellLayoutHeight() {
1615 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001616 }
1617
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001618 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001619 return new Point(workspacePadding.left + workspacePadding.right,
1620 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001621 }
1622
1623 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001624 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1625 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001626 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001627 private void updateWorkspacePadding() {
1628 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001629 if (isVerticalBarLayout()) {
Jordan Silva3646a1b2023-08-02 13:52:52 +01001630 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001631 padding.top = mResponsiveWorkspaceHeightSpec.getStartPaddingPx();
Thales Lima8e11d532023-08-31 13:40:26 +00001632 padding.bottom = Math.max(0,
Jordan Silva8f7986a2023-11-08 12:11:25 +00001633 mResponsiveWorkspaceHeightSpec.getEndPaddingPx() - mInsets.bottom);
Jordan Silva3646a1b2023-08-02 13:52:52 +01001634 if (isSeascape()) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001635 padding.left =
1636 hotseatBarSizePx + mResponsiveWorkspaceWidthSpec.getEndPaddingPx();
1637 padding.right = mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
Jordan Silva3646a1b2023-08-02 13:52:52 +01001638 } else {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001639 padding.left = mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
1640 padding.right =
1641 hotseatBarSizePx + mResponsiveWorkspaceWidthSpec.getEndPaddingPx();
Jordan Silva3646a1b2023-08-02 13:52:52 +01001642 }
Winson1f064272016-07-18 17:18:02 -07001643 } else {
Jordan Silva3646a1b2023-08-02 13:52:52 +01001644 padding.top = 0;
1645 padding.bottom = edgeMarginPx;
1646 if (isSeascape()) {
1647 padding.left = hotseatBarSizePx;
Thales Lima8e11d532023-08-31 13:40:26 +00001648 padding.right = mHotseatBarEdgePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001649 } else {
Thales Lima8e11d532023-08-31 13:40:26 +00001650 padding.left = mHotseatBarEdgePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001651 padding.right = hotseatBarSizePx;
1652 }
Winson1f064272016-07-18 17:18:02 -07001653 }
Winson Chungb3800242013-10-24 11:01:54 -07001654 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001655 // Pad the bottom of the workspace with hotseat bar
1656 // and leave a bit of space in case a widget go all the way down
Thales Lima79456492023-05-23 11:32:22 +01001657 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding - mInsets.bottom;
1658 if (!mIsResponsiveGrid) {
1659 paddingBottom +=
1660 workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace;
1661 }
1662 int paddingTop = workspaceTopPadding + (mIsScalableGrid ? 0 : edgeMarginPx);
Pat Manning08610ca2022-04-05 21:03:16 +01001663 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001664
Pat Manning08610ca2022-04-05 21:03:16 +01001665 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001666 }
Pat Manning08610ca2022-04-05 21:03:16 +01001667 insetPadding(workspacePadding, cellLayoutPaddingPx);
1668 }
1669
1670 private void insetPadding(Rect paddings, Rect insets) {
1671 insets.left = Math.min(insets.left, paddings.left);
1672 paddings.left -= insets.left;
1673
1674 insets.top = Math.min(insets.top, paddings.top);
1675 paddings.top -= insets.top;
1676
1677 insets.right = Math.min(insets.right, paddings.right);
1678 paddings.right -= insets.right;
1679
1680 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1681 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001682 }
1683
Liran Binyamina833af32023-08-02 16:30:27 -04001684
1685 /**
1686 * Returns the new border space that should be used between hotseat icons after adjusting it to
1687 * the bubble bar.
1688 *
1689 * <p>If there's no adjustment needed, this method returns {@code 0}.
1690 */
1691 public float getHotseatAdjustedBorderSpaceForBubbleBar(Context context) {
1692 // only need to adjust when QSB is on top of the hotseat.
1693 if (isQsbInline) {
1694 return 0;
1695 }
1696
1697 // no need to adjust if there's enough space for the bubble bar to the right of the hotseat.
1698 if (getHotseatLayoutPadding(context).right > mBubbleBarSpaceThresholdPx) {
1699 return 0;
1700 }
1701
1702 // The adjustment is shrinking the hotseat's width by 1 icon on either side.
1703 int iconsWidth =
1704 iconSizePx * numShownHotseatIcons + hotseatBorderSpace * (numShownHotseatIcons - 1);
1705 int newWidth = iconsWidth - 2 * iconSizePx;
1706 // Evenly space the icons within the boundaries of the new width.
1707 return (float) (newWidth - iconSizePx * numShownHotseatIcons) / (numShownHotseatIcons - 1);
1708 }
1709
Sunny Goyal57b22792021-05-25 14:35:01 -07001710 /**
1711 * Returns the padding for hotseat view
1712 */
1713 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001714 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001715 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001716 // The hotseat icons will be placed in the middle of the hotseat cells.
1717 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1718 // in vertical bar layout.
1719 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1720 // is set to account for that difference.
Jordan Silva3646a1b2023-08-02 13:52:52 +01001721 float diffOverlapFactor = mIsResponsiveGrid ? 0
1722 : iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
1723
Pat Manning08610ca2022-04-05 21:03:16 +01001724 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1725 - diffOverlapFactor), 0);
1726 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001727 + diffOverlapFactor), 0);
1728
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001729 if (isSeascape()) {
Thales Lima8e11d532023-08-31 13:40:26 +00001730 hotseatBarPadding.set(mInsets.left + mHotseatBarEdgePaddingPx, paddingTop,
1731 mHotseatBarWorkspaceSpacePx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001732 } else {
Thales Lima8e11d532023-08-31 13:40:26 +00001733 hotseatBarPadding.set(mHotseatBarWorkspaceSpacePx, paddingTop,
1734 mInsets.right + mHotseatBarEdgePaddingPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001735 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001736 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001737 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001738 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1739 int hotseatBarTopPadding =
1740 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001741
Thales Lima6a590062022-11-22 15:52:49 +00001742 int hotseatWidth = getHotseatRequiredWidth();
Helen Cheuke76291f2023-02-14 17:11:05 +00001743 int startSpacing;
1744 int endSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001745 // Hotseat aligns to the left with nav buttons
1746 if (hotseatBarEndOffset > 0) {
Jon Mirandae17a9492023-03-08 16:42:20 -08001747 startSpacing = inlineNavButtonsEndSpacingPx;
Helen Cheuke76291f2023-02-14 17:11:05 +00001748 endSpacing = availableWidthPx - hotseatWidth - startSpacing + hotseatBorderSpace;
1749 } else {
1750 startSpacing = (availableWidthPx - hotseatWidth) / 2;
1751 endSpacing = startSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001752 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001753 startSpacing += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001754
Helen Cheuke76291f2023-02-14 17:11:05 +00001755 hotseatBarPadding.top = hotseatBarTopPadding;
1756 hotseatBarPadding.bottom = hotseatBarBottomPadding;
Alex Chau51da2192022-05-20 13:32:10 +01001757 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001758 if (isRtl) {
Helen Cheuke76291f2023-02-14 17:11:05 +00001759 hotseatBarPadding.left = endSpacing;
1760 hotseatBarPadding.right = startSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001761 } else {
Helen Cheuke76291f2023-02-14 17:11:05 +00001762 hotseatBarPadding.left = startSpacing;
1763 hotseatBarPadding.right = endSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001764 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001765
Thales Lima79456492023-05-23 11:32:22 +01001766 } else if (mIsScalableGrid) {
Alex Chau206ede92022-08-01 17:46:12 +01001767 int sideSpacing = (availableWidthPx - hotseatQsbWidth) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001768 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001769 0,
Thales Lima425f6822022-05-10 13:44:58 -03001770 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001771 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001772 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001773 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1774 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1775 // for this, we pad the left and right of the hotseat with half of the difference of a
1776 // workspace cell vs a hotseat cell.
1777 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001778 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001779 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001780 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001781 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1782 + mInsets.left,
1783 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001784 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001785 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001786 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001787 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001788 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001789 }
1790
Andy Wickhambd9a1802023-06-08 16:33:15 -07001791 /** The margin between the edge of all apps and the edge of the first icon. */
Thales Limab433c9c2023-10-30 12:24:05 +00001792 public int getAllAppsIconStartMargin(Context context) {
Andy Wickhambd9a1802023-06-08 16:33:15 -07001793 int allAppsSpacing;
1794 if (isVerticalBarLayout()) {
1795 // On phones, the landscape layout uses a different setup.
1796 allAppsSpacing = workspacePadding.left + workspacePadding.right;
1797 } else {
Thales Limab433c9c2023-10-30 12:24:05 +00001798 allAppsSpacing =
1799 allAppsPadding.left + allAppsPadding.right + allAppsLeftRightMargin * 2;
Andy Wickhambd9a1802023-06-08 16:33:15 -07001800 }
1801
1802 int cellWidth = DeviceProfile.calculateCellWidth(
1803 availableWidthPx - allAppsSpacing,
1804 0 /* borderSpace */,
1805 numShownAllAppsColumns);
1806 int iconVisibleSize = Math.round(ICON_VISIBLE_AREA_FACTOR * allAppsIconSizePx);
1807 int iconAlignmentMargin = (cellWidth - iconVisibleSize) / 2;
Thales Limab433c9c2023-10-30 12:24:05 +00001808
1809 return (Utilities.isRtl(context.getResources()) ? allAppsPadding.right
1810 : allAppsPadding.left) + iconAlignmentMargin;
Andy Wickhambd9a1802023-06-08 16:33:15 -07001811 }
1812
Thales Lima9938c2f2022-07-25 14:38:16 +01001813 private int getAdditionalQsbSpace() {
1814 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1815 }
1816
1817 /**
1818 * Calculate how much space the hotseat needs to be shown completely
1819 */
1820 private int getHotseatRequiredWidth() {
1821 int additionalQsbSpace = getAdditionalQsbSpace();
1822 return iconSizePx * numShownHotseatIcons
Thales Lima6a590062022-11-22 15:52:49 +00001823 + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1))
Thales Lima9938c2f2022-07-25 14:38:16 +01001824 + additionalQsbSpace;
1825 }
1826
Winsonfadbe8f2016-07-22 16:35:37 -07001827 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001828 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1829 */
1830 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001831 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001832 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1833 } else if (isTaskbarPresent) { // QSB on top
1834 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001835 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001836 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001837 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001838 }
1839
Thales Limab8c05952022-05-23 16:58:38 +01001840 /**
1841 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1842 */
1843 private int getHotseatBarBottomPadding() {
1844 if (isTaskbarPresent) { // QSB on top or inline
1845 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001846 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001847 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001848 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001849 }
1850
1851 /**
Alex Chau51da2192022-05-20 13:32:10 +01001852 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1853 */
1854 public int getTaskbarOffsetY() {
Jon Miranda9c478b62023-03-23 21:38:49 -07001855 int taskbarIconBottomSpace = (taskbarHeight - iconSizePx) / 2;
Alex Chau51da2192022-05-20 13:32:10 +01001856 int launcherIconBottomSpace =
1857 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001858 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001859 }
1860
Uwais Ashrafaa7fa882023-10-10 21:36:06 +00001861 /** Returns the number of pixels required below OverviewActions. */
Alex Chaua2fc7642022-04-21 14:20:23 +01001862 public int getOverviewActionsClaimedSpaceBelow() {
Uwais Ashrafaa7fa882023-10-10 21:36:06 +00001863 return isTaskbarPresent ? mTransientTaskbarClaimedSpace : mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001864 }
1865
1866 /** Gets the space that the overview actions will take, including bottom margin. */
1867 public int getOverviewActionsClaimedSpace() {
Alex Chau4989f4f2023-10-11 14:08:22 +00001868 int overviewActionsSpace = isTablet && Flags.enableGridOnlyOverview()
Pat Manning7b8f7662023-01-18 14:48:30 +00001869 ? 0
1870 : (overviewActionsTopMarginPx + overviewActionsHeight);
1871 return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
Alex Chaua2fc7642022-04-21 14:20:23 +01001872 }
1873
1874 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001875 * Takes the View and return the scales of width and height depending on the DeviceProfile
1876 * specifications
1877 *
1878 * @param itemInfo The tag of the widget view
1879 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1880 * height
1881 */
1882 @NonNull
1883 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1884 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1885 }
1886
1887 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001888 * @return the bounds for which the open folders should be contained within
1889 */
1890 public Rect getAbsoluteOpenFolderBounds() {
1891 if (isVerticalBarLayout()) {
1892 // Folders should only appear right of the drop target bar and left of the hotseat
1893 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1894 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001895 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001896 mInsets.top + availableHeightPx);
1897 } else {
1898 // Folders should only appear below the drop target bar and above the hotseat
Jon Miranda9c478b62023-03-23 21:38:49 -07001899 int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001900 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001901 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001902 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001903 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001904 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001905 }
1906 }
1907
Jon Miranda228877d2021-02-09 11:05:00 -05001908 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1909 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001910 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001911
Jon Miranda228877d2021-02-09 11:05:00 -05001912 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1913 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001914 }
1915
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001916 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001917 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1918 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1919 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001920 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001921 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001922 return isLandscape && transposeLayoutWithOrientation;
1923 }
1924
Sunny Goyal59d086c2018-05-07 17:31:40 -07001925 /**
1926 * Updates orientation information and returns true if it has changed from the previous value.
1927 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001928 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001929 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001930 boolean isSeascape = DisplayController.INSTANCE.get(context)
1931 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001932 if (mIsSeascape != isSeascape) {
1933 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001934 // Hotseat changing sides requires updating workspace left/right paddings
1935 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001936 return true;
1937 }
1938 }
1939 return false;
1940 }
1941
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001942 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001943 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001944 }
1945
Sunny Goyal07b69292018-01-08 14:19:34 -08001946 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001947 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001948 }
1949
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001950 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001951 switch (containerType) {
1952 case CellLayout.WORKSPACE:
1953 return cellHeightPx;
1954 case CellLayout.FOLDER:
1955 return folderCellHeightPx;
1956 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001957 // The hotseat is the only container where the cell height is going to be
1958 // different from the content within that cell.
1959 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001960 default:
1961 // ??
1962 return 0;
1963 }
1964 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001965
Jon Miranda58561d42021-03-17 10:51:54 -04001966 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001967 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001968 }
1969
Alex Chaue818bcb2022-09-02 17:27:11 +01001970 private String dpPointFToString(String name, PointF value) {
1971 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
1972 }
1973
Pat Manning5f74bfd2022-07-20 12:08:54 +01001974 /** Dumps various DeviceProfile variables to the specified writer. */
1975 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04001976 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001977 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001978
1979 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001980 writer.println(prefix + "\tisPhone:" + isPhone);
1981 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1982 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001983 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001984
1985 writer.println(prefix + "\tisLandscape:" + isLandscape);
1986 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001987 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001988
1989 writer.println(prefix + pxToDpStr("windowX", windowX));
1990 writer.println(prefix + pxToDpStr("windowY", windowY));
1991 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1992 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001993 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1994 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001995 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1996 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1997 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1998 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001999
2000 writer.println(prefix + "\taspectRatio:" + aspectRatio);
2001
Thales Limac98b7812023-04-14 15:04:23 +01002002 writer.println(prefix + "\tisResponsiveGrid:" + mIsResponsiveGrid);
Thales Lima79456492023-05-23 11:32:22 +01002003 writer.println(prefix + "\tisScalableGrid:" + mIsScalableGrid);
Jon Miranda58561d42021-03-17 10:51:54 -04002004
Thales Lima83bedbf2021-10-05 17:47:39 +01002005 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00002006 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
2007 writer.println(prefix + "\tinv.numSearchContainerColumns: "
2008 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04002009
Alex Chaue818bcb2022-09-02 17:27:11 +01002010 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07002011
Jon Miranda58561d42021-03-17 10:51:54 -04002012 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
2013 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
2014
2015 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
2016 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
2017
Thales Lima83bedbf2021-10-05 17:47:39 +01002018 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
2019 cellLayoutBorderSpacePx.x));
2020 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
2021 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002022 writer.println(
2023 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
2024 writer.println(
2025 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
2026 writer.println(
2027 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01002028 writer.println(
2029 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01002030
Jon Miranda58561d42021-03-17 10:51:54 -04002031 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
2032 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
2033 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
2034
Thales Lima07c6b8d2023-11-08 18:22:38 +00002035 writer.println(prefix + "\tnumFolderRows: " + numFolderRows);
2036 writer.println(prefix + "\tnumFolderColumns: " + numFolderColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04002037 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
2038 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
2039 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
2040 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
2041 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
2042 folderChildDrawablePaddingPx));
Jordan Silva637f4eb2023-06-13 11:21:53 +01002043 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.x",
2044 folderCellLayoutBorderSpacePx.x));
2045 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.y",
2046 folderCellLayoutBorderSpacePx.y));
Thales Limaa08a4432022-08-09 09:55:17 +01002047 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
2048 folderContentPaddingLeftRight));
2049 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03002050 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002051
Alex Chaue0227552022-04-06 19:44:43 +01002052 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01002053 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
2054 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
2055 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
2056 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01002057
2058 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
Alex Chau3d2c0622022-09-01 21:28:14 +01002059 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
2060 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04002061 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
2062 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
2063 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
2064 allAppsIconDrawablePaddingPx));
2065 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00002066 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01002067 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
2068 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07002069 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Thales Limab433c9c2023-10-30 12:24:05 +00002070 writer.println(prefix + pxToDpStr("allAppsPadding.top", allAppsPadding.top));
2071 writer.println(prefix + pxToDpStr("allAppsPadding.left", allAppsPadding.left));
2072 writer.println(prefix + pxToDpStr("allAppsPadding.right", allAppsPadding.right));
Alex Chau27b39b92022-01-14 18:02:18 +00002073 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04002074
2075 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03002076 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04002077 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00002078 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Thales Lima8e11d532023-08-31 13:40:26 +00002079 writer.println(prefix + pxToDpStr("mHotseatBarEdgePaddingPx",
2080 mHotseatBarEdgePaddingPx));
2081 writer.println(prefix + pxToDpStr("mHotseatBarWorkspaceSpacePx",
2082 mHotseatBarWorkspaceSpacePx));
Pat Manning26f70f72022-07-07 13:50:39 +01002083 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01002084 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
2085 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01002086 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
2087 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002088 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
2089 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
2090 hotseatLayoutPadding.top));
2091 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
2092 hotseatLayoutPadding.bottom));
2093 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
2094 hotseatLayoutPadding.left));
2095 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
2096 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07002097 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00002098 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00002099 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01002100 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04002101
2102 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10002103 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda9c478b62023-03-23 21:38:49 -07002104 writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight));
2105 writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight));
2106 writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin));
2107 writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize));
Jon Miranda58561d42021-03-17 10:51:54 -04002108
Thales Lima83bedbf2021-10-05 17:47:39 +01002109 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
2110 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002111 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
2112 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
2113 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00002114 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04002115
Jon Mirandaab3c6812021-06-28 15:42:28 -07002116 writer.println(prefix + pxToDpStr("iconScale", iconScale));
2117 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04002118 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00002119 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04002120
Thales Lima171ee662022-11-22 15:52:49 +00002121 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04002122 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
2123 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00002124
2125 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00002126 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
2127 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
2128 overviewTaskIconDrawableSizePx));
2129 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
2130 overviewTaskIconDrawableSizeGridPx));
Pat Manning1695cc72023-07-05 11:45:13 +01002131 writer.println(prefix + pxToDpStr("overviewTaskIconAppChipMenuDrawableSizePx",
2132 overviewTaskIconAppChipMenuDrawableSizePx));
Alex Chau635b3ab2022-01-26 16:49:10 +00002133 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
2134 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01002135 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
2136 overviewActionsTopMarginPx));
2137 writer.println(prefix + pxToDpStr("overviewActionsHeight",
2138 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00002139 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
2140 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00002141 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
2142 overviewActionsButtonSpacing));
2143 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
2144 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
2145 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01002146
Alex Chau62572c02022-07-25 18:36:37 +00002147 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01002148 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00002149 writer.println(
2150 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01002151
Pat Manning5f74bfd2022-07-20 12:08:54 +01002152 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
2153 getCellLayoutSpringLoadShrunkTop()));
2154 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
2155 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01002156 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
2157 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002158 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
2159 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01002160 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
2161 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Thales Lima79456492023-05-23 11:32:22 +01002162 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00002163 writer.println(prefix + "\tmResponsiveWorkspaceHeightSpec:"
2164 + mResponsiveWorkspaceHeightSpec.toString());
2165 writer.println(prefix + "\tmResponsiveWorkspaceWidthSpec:"
2166 + mResponsiveWorkspaceWidthSpec.toString());
2167 writer.println(prefix + "\tmResponsiveAllAppsHeightSpec:"
2168 + mResponsiveAllAppsHeightSpec.toString());
2169 writer.println(prefix + "\tmResponsiveAllAppsWidthSpec:"
2170 + mResponsiveAllAppsWidthSpec.toString());
Jordan Silva637f4eb2023-06-13 11:21:53 +01002171 writer.println(prefix + "\tmResponsiveFolderHeightSpec:" + mResponsiveFolderHeightSpec);
2172 writer.println(prefix + "\tmResponsiveFolderWidthSpec:" + mResponsiveFolderWidthSpec);
Thales Limaf8bfb032023-07-24 15:08:05 +01002173 writer.println(prefix + "\tmResponsiveHotseatSpec:" + mResponsiveHotseatSpec);
Jordan Silva999dd2a2023-11-17 19:31:43 +00002174 writer.println(prefix + "\tmResponsiveWorkspaceCellSpec:"
2175 + mResponsiveWorkspaceCellSpec);
2176 writer.println(prefix + "\tmResponsiveAllAppsCellSpec:" + mResponsiveAllAppsCellSpec);
Thales Lima79456492023-05-23 11:32:22 +01002177 }
Jon Miranda58561d42021-03-17 10:51:54 -04002178 }
2179
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00002180 /** Returns a reduced representation of this DeviceProfile. */
2181 public String toSmallString() {
2182 return "isTablet:" + isTablet + ", "
2183 + "isMultiDisplay:" + isMultiDisplay + ", "
2184 + "widthPx:" + widthPx + ", "
2185 + "heightPx:" + heightPx + ", "
2186 + "insets:" + mInsets + ", "
2187 + "rotationHint:" + rotationHint;
2188 }
2189
Alex Chaua6907dc2022-03-18 15:24:07 +00002190 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07002191 Configuration config = new Configuration(c.getResources().getConfiguration());
2192 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03002193 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00002194 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07002195 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07002196 }
Sunny Goyalfde55052018-02-01 14:46:13 -08002197
2198 /**
2199 * Callback when a component changes the DeviceProfile associated with it, as a result of
2200 * configuration change
2201 */
2202 public interface OnDeviceProfileChangeListener {
2203
2204 /**
2205 * Called when the device profile is reassigned. Note that for layout and measurements, it
2206 * is sufficient to listen for inset changes. Use this callback when you need to perform
2207 * a one time operation.
2208 */
2209 void onDeviceProfileChanged(DeviceProfile dp);
2210 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002211
Sihua Mae04aa202022-07-18 12:43:56 -07002212 /**
2213 * Handler that deals with ItemInfo of the views for the DeviceProfile
2214 */
2215 @FunctionalInterface
2216 public interface ViewScaleProvider {
2217 /**
2218 * Get the scales from the view
2219 *
2220 * @param itemInfo The tag of the widget view
2221 * @return PointF instance containing the scale information, or null if using the default
2222 * app widget scale of this device profile.
2223 */
2224 @NonNull
2225 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
2226 }
2227
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002228 public static class Builder {
2229 private Context mContext;
2230 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07002231 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002232
Sunny Goyal19ff7282021-04-22 10:12:54 -07002233 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00002234 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002235
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002236 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07002237 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00002238 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07002239 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002240
Sunny Goyal65190ae2022-08-02 14:16:26 -07002241 private SparseArray<DotRenderer> mDotRendererCache;
2242
Jon Miranda2b25ded2023-02-02 14:48:45 -08002243 private Consumer<DeviceProfile> mOverrideProvider;
2244
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002245 private boolean mIsTransientTaskbar;
2246
Sunny Goyalfd58da62020-08-11 12:06:49 -07002247 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002248 mContext = context;
2249 mInv = inv;
2250 mInfo = info;
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002251 mIsTransientTaskbar = info.isTransientTaskbar();
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002252 }
2253
2254 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
2255 mIsMultiWindowMode = isMultiWindowMode;
2256 return this;
2257 }
2258
Alex Chauab800f72022-12-13 17:46:06 +00002259 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
2260 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07002261 return this;
2262 }
2263
Sunny Goyal65190ae2022-08-02 14:16:26 -07002264 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
2265 mDotRendererCache = dotRendererCache;
2266 return this;
2267 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07002268
2269 public Builder setWindowBounds(WindowBounds bounds) {
2270 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07002271 return this;
2272 }
2273
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002274 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
2275 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
2276 return this;
2277 }
2278
Alex Chau6ed408f2022-03-04 12:58:05 +00002279 public Builder setGestureMode(boolean isGestureMode) {
2280 mIsGestureMode = isGestureMode;
2281 return this;
2282 }
2283
Jon Miranda2b25ded2023-02-02 14:48:45 -08002284 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
2285 mOverrideProvider = overrideProvider;
2286 return this;
2287 }
2288
Sihua Mae04aa202022-07-18 12:43:56 -07002289 /**
2290 * Set the viewScaleProvider for the builder
2291 *
2292 * @param viewScaleProvider The viewScaleProvider to be set for the
Thales Limae9273ea2023-01-26 12:33:52 +00002293 * DeviceProfile
Sihua Mae04aa202022-07-18 12:43:56 -07002294 * @return This builder
2295 */
2296 @NonNull
2297 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
2298 mViewScaleProvider = viewScaleProvider;
2299 return this;
2300 }
2301
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002302 /**
2303 * Set the isTransientTaskbar for the builder
2304 * @return This Builder
2305 */
2306 public Builder setIsTransientTaskbar(boolean isTransientTaskbar) {
2307 mIsTransientTaskbar = isTransientTaskbar;
2308 return this;
2309 }
2310
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002311 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07002312 if (mWindowBounds == null) {
2313 throw new IllegalArgumentException("Window bounds not set");
2314 }
2315 if (mTransposeLayoutWithOrientation == null) {
2316 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
2317 }
Alex Chau6ed408f2022-03-04 12:58:05 +00002318 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01002319 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00002320 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002321 if (mDotRendererCache == null) {
2322 mDotRendererCache = new SparseArray<>();
2323 }
Sihua Mae04aa202022-07-18 12:43:56 -07002324 if (mViewScaleProvider == null) {
2325 mViewScaleProvider = DEFAULT_PROVIDER;
2326 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08002327 if (mOverrideProvider == null) {
2328 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
2329 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002330 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00002331 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002332 mIsGestureMode, mViewScaleProvider, mOverrideProvider, mIsTransientTaskbar);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002333 }
2334 }
Winson Chungb3800242013-10-24 11:01:54 -07002335}