blob: 7ca8b82270d278218ffcf1d32fac210ba203e9fb [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 Lima07c6b8d2023-11-08 18:22:38 +0000442 numFolderRows = inv.numFolderRows;
443 numFolderColumns = inv.numFolderColumns;
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) {
1005 updateIconSize(1f, res);
1006 updateWorkspacePadding();
1007 return 0;
1008 }
1009
Alex Chaua68164d2022-12-15 16:16:03 +00001010 float invIconSizeDp = inv.iconSize[mTypeIndex];
1011 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
1012 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
1013 iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
1014
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001015 updateIconSize(1f, res);
Pat Manning08610ca2022-04-05 21:03:16 +01001016 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -05001017
1018 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +01001019 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +00001020 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -05001021 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -05001022 float scaleY = maxHeight / usedHeight;
1023 boolean shouldScale = scaleY < 1f;
1024
1025 float scaleX = 1f;
Thales Lima79456492023-05-23 11:32:22 +01001026 if (mIsScalableGrid) {
Jon Mirandae126d722021-02-25 10:45:20 -05001027 // We scale to fit the cellWidth and cellHeight in the available space.
1028 // The benefit of scalable grids is that we can get consistent aspect ratios between
1029 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +01001030 float usedWidth =
1031 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -05001032 // We do not subtract padding here, as we also scale the workspace padding if needed.
1033 scaleX = availableWidthPx / usedWidth;
1034 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -07001035 }
Jon Mirandae126d722021-02-25 10:45:20 -05001036
1037 if (shouldScale) {
1038 float scale = Math.min(scaleX, scaleY);
1039 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +01001040 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -05001041 }
1042
Jon Miranda228877d2021-02-09 11:05:00 -05001043 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -07001044 }
1045
Pat Manninga2e14992022-04-22 11:29:17 +01001046 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +01001047 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
1048 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
1049 }
1050
Pat Manninga2e14992022-04-22 11:29:17 +01001051 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +00001052 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +01001053 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
1054 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -05001055 }
1056
Jordan Silva376036a2023-11-08 15:56:40 +00001057 private int getNormalizedIconDrawablePadding(int iconSizePx, int iconDrawablePadding) {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001058 // TODO(b/235886078): workaround needed because of this bug
1059 // Icons are 10% larger on XML than their visual size,
1060 // so remove that extra space to get labels closer to the correct padding
Jordan Silva999dd2a2023-11-17 19:31:43 +00001061 int iconVisibleSizePx = Math.round(ICON_VISIBLE_AREA_FACTOR * iconSizePx);
Jordan Silva376036a2023-11-08 15:56:40 +00001062 return Math.max(0, iconDrawablePadding - ((iconSizePx - iconVisibleSizePx) / 2));
1063 }
1064
1065 private int getNormalizedIconDrawablePadding() {
1066 return getNormalizedIconDrawablePadding(iconSizePx, mIconDrawablePaddingOriginalPx);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001067 }
1068
1069 private int getNormalizedFolderChildDrawablePaddingPx(int textHeight) {
1070 // TODO(b/235886078): workaround needed because of this bug
1071 // Icons are 10% larger on XML than their visual size,
1072 // so remove that extra space to get labels closer to the correct padding
1073 int drawablePadding = (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3;
1074
1075 int iconVisibleSizePx = Math.round(ICON_VISIBLE_AREA_FACTOR * folderChildIconSizePx);
1076 int iconSizeDiff = folderChildIconSizePx - iconVisibleSizePx;
1077 return Math.max(0, drawablePadding - iconSizeDiff / 2);
1078 }
1079
Jordan Silva3646a1b2023-08-02 13:52:52 +01001080 private int getIconSizeWithOverlap(int iconSize) {
1081 return (int) Math.ceil(iconSize * ICON_OVERLAP_FACTOR);
1082 }
1083
Jon Miranda6f7e9702019-09-16 14:44:14 -07001084 /**
1085 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
1086 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
1087 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
1088 */
Tony Wickham7ba547c2021-02-02 17:12:08 -08001089 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -07001090 // Icon scale should never exceed 1, otherwise pixellation may occur.
1091 iconScale = Math.min(1f, scale);
1092 cellScaleToFit = scale;
1093
Jon Miranda18751b62017-07-31 17:25:27 -07001094 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -08001095 final boolean isVerticalLayout = isVerticalBarLayout();
Thales Lima080d8902022-03-28 15:30:29 +01001096 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -05001097
Thales Lima79456492023-05-23 11:32:22 +01001098 if (mIsResponsiveGrid) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001099 iconSizePx = mResponsiveWorkspaceCellSpec.getIconSize();
1100 iconTextSizePx = mResponsiveWorkspaceCellSpec.getIconTextSize();
1101 mIconDrawablePaddingOriginalPx = mResponsiveWorkspaceCellSpec.getIconDrawablePadding();
1102
Jordan Silva8f7986a2023-11-08 12:11:25 +00001103 cellWidthPx = mResponsiveWorkspaceWidthSpec.getCellSizePx();
1104 cellHeightPx = mResponsiveWorkspaceHeightSpec.getCellSizePx();
Thales Lima79456492023-05-23 11:32:22 +01001105
Thales Lima2759aa32023-06-05 16:25:45 +01001106 if (cellWidthPx < iconSizePx) {
1107 // get a smaller icon size
1108 iconSizePx = mIconSizeSteps.getIconSmallerThan(cellWidthPx);
Thales Lima2759aa32023-06-05 16:25:45 +01001109 }
1110
Thales Lima93ee8fc2023-06-05 17:07:11 +01001111 iconDrawablePaddingPx = getNormalizedIconDrawablePadding();
Thales Lima93ee8fc2023-06-05 17:07:11 +01001112
Thales Lima24ceca62023-09-25 16:21:17 -07001113 CellContentDimensions cellContentDimensions = new CellContentDimensions(iconSizePx,
1114 iconDrawablePaddingPx,
1115 iconTextSizePx);
Thales Limabba07722023-10-11 18:16:29 +00001116 if (isVerticalLayout) {
1117 if (cellHeightPx < iconSizePx) {
1118 cellContentDimensions.setIconSizePx(
1119 mIconSizeSteps.getIconSmallerThan(cellHeightPx));
1120 }
Thales Lima24ceca62023-09-25 16:21:17 -07001121 } else {
1122 cellContentDimensions.resizeToFitCellHeight(cellHeightPx, mIconSizeSteps);
Thales Lima2759aa32023-06-05 16:25:45 +01001123 }
Thales Lima24ceca62023-09-25 16:21:17 -07001124 iconSizePx = cellContentDimensions.getIconSizePx();
1125 iconDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1126 iconTextSizePx = cellContentDimensions.getIconTextSizePx();
1127 int cellContentHeight = cellContentDimensions.getCellContentHeight();
Thales Lima2759aa32023-06-05 16:25:45 +01001128
1129 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Lima79456492023-05-23 11:32:22 +01001130 } else if (mIsScalableGrid) {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001131 iconDrawablePaddingPx = (int) (getNormalizedIconDrawablePadding() * iconScale);
Thales Lima83bedbf2021-10-05 17:47:39 +01001132 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
1133 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001134
1135 if (cellWidthPx < iconSizePx) {
1136 // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger.
1137 int numColumns = getPanelCount() * inv.numColumns;
1138 int numBorders = numColumns - 1;
1139 int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns;
1140 if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) {
1141 cellWidthPx = iconSizePx;
1142 cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders;
1143 } else {
1144 // If it still doesn't fit, set borderSpace to 0 and distribute the space for
1145 // cellWidth, and reduce iconSize.
1146 cellWidthPx = (cellWidthPx * numColumns
1147 + cellLayoutBorderSpacePx.x * numBorders) / numColumns;
1148 iconSizePx = Math.min(iconSizePx, cellWidthPx);
1149 cellLayoutBorderSpacePx.x = 0;
1150 }
1151 }
1152
Thales Lima93ee8fc2023-06-05 17:07:11 +01001153 int cellTextAndPaddingHeight =
1154 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +00001155 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
1156 if (cellHeightPx < cellContentHeight) {
1157 // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight
1158 // bigger.
1159 int numBorders = inv.numRows - 1;
1160 int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows;
1161 if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) {
1162 cellHeightPx = cellContentHeight;
1163 cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders;
1164 } else {
Alex Chau06f36e82023-01-06 10:50:54 +00001165 // If it still doesn't fit, set borderSpace to 0 to recover space.
Alex Chaube753132022-12-09 16:46:54 +00001166 cellHeightPx = (cellHeightPx * inv.numRows
1167 + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows;
Alex Chaube753132022-12-09 16:46:54 +00001168 cellLayoutBorderSpacePx.y = 0;
Alex Chau06f36e82023-01-06 10:50:54 +00001169 // Reduce iconDrawablePaddingPx to make cellContentHeight smaller.
1170 int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx;
1171 if (cellContentWithoutPadding <= cellHeightPx) {
1172 iconDrawablePaddingPx = cellContentHeight - cellHeightPx;
1173 } else {
1174 // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space,
1175 // then proportional reduce iconSizePx and iconTextSizePx to fit.
1176 iconDrawablePaddingPx = 0;
1177 float ratio = cellHeightPx / (float) cellContentWithoutPadding;
1178 iconSizePx = (int) (iconSizePx * ratio);
1179 iconTextSizePx = (int) (iconTextSizePx * ratio);
1180 }
1181 cellTextAndPaddingHeight =
1182 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +00001183 }
1184 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
1185 }
Jon Mirandae126d722021-02-25 10:45:20 -05001186 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +01001187 desiredWorkspaceHorizontalMarginPx =
1188 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -05001189 } else {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001190 iconDrawablePaddingPx = (int) (getNormalizedIconDrawablePadding() * iconScale);
Jon Mirandae126d722021-02-25 10:45:20 -05001191 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001192 cellHeightPx = getIconSizeWithOverlap(iconSizePx)
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001193 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -05001194 + Utilities.calculateTextHeight(iconTextSizePx);
1195 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
1196 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
1197 && !isMultiWindowMode) {
1198 // Ensures that the label is closer to its corresponding icon. This is not an issue
1199 // with vertical bar layout or multi-window mode since the issue is handled
1200 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
1201 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
1202 iconDrawablePaddingPx = cellPaddingY;
1203 }
Jon Miranda846455e2017-10-02 14:58:52 -07001204 }
Jon Miranda18751b62017-07-31 17:25:27 -07001205
Sunny Goyalae190ff2020-04-14 00:19:01 +00001206 // All apps
Thales Limaabfe3642023-05-24 18:08:53 +01001207 if (mIsResponsiveGrid) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001208 updateAllAppsWithResponsiveMeasures();
Thales Limaabfe3642023-05-24 18:08:53 +01001209 } else {
1210 updateAllAppsIconSize(scale, res);
1211 }
1212 updateAllAppsContainerWidth();
1213 if (isVerticalBarLayout()) {
1214 hideWorkspaceLabelsIfNotEnoughSpace();
1215 }
Brandon Dayauon3cdb32c2023-08-22 21:26:37 -07001216 if (FeatureFlags.enableTwolineAllapps()) {
1217 // Add extra textHeight to the existing allAppsCellHeight.
1218 allAppsCellHeightPx += Utilities.calculateTextHeight(allAppsIconTextSizePx);
1219 }
Winson Chungb3800242013-10-24 11:01:54 -07001220
Thales Limab8c05952022-05-23 16:58:38 +01001221 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -07001222
Sunny Goyalbaec6ff2016-09-14 11:26:21 -07001223 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -07001224 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
1225 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Sunny Goyal6c304b12023-04-10 12:03:04 -07001226
1227 // Update widget padding:
1228 float minSpacing = pxFromDp(MIN_WIDGET_PADDING_DP, mMetrics);
1229 if (cellLayoutBorderSpacePx.x < minSpacing
1230 || cellLayoutBorderSpacePx.y < minSpacing) {
1231 widgetPadding.left = widgetPadding.right =
1232 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.x));
1233 widgetPadding.top = widgetPadding.bottom =
1234 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.y));
1235 } else {
1236 widgetPadding.setEmpty();
1237 }
Winson Chung0f785722015-04-08 10:27:49 -07001238 }
1239
Thales Lima425f6822022-05-10 13:44:58 -03001240 /**
Thales Lima6a590062022-11-22 15:52:49 +00001241 * This method calculates the space between the icons to achieve a certain width.
Thales Lima425f6822022-05-10 13:44:58 -03001242 */
Thales Lima6a590062022-11-22 15:52:49 +00001243 private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) {
Jordan Silvad9227182023-08-17 15:53:59 +01001244 int numBorders = (numShownHotseatIcons - 1 + numExtraBorder);
1245 if (numBorders <= 0) return 0;
1246
Thales Lima9938c2f2022-07-25 14:38:16 +01001247 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
Jordan Silvad9227182023-08-17 15:53:59 +01001248 int hotseatBorderSpacePx = (int) (hotseatWidthPx - hotseatIconsTotalPx) / numBorders;
Thales Limaffc68b02023-01-09 16:20:23 +00001249 return Math.min(hotseatBorderSpacePx, mMaxHotseatIconSpacePx);
Thales Lima425f6822022-05-10 13:44:58 -03001250 }
1251
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001252 /**
1253 * Updates the iconSize for allApps* variants.
1254 */
Brian Isganitisa9a78112022-05-23 18:11:47 -07001255 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +01001256 allAppsBorderSpacePx = new Point(
1257 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
1258 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001259 // AllApps cells don't have real space between cells,
1260 // so we add the border space to the cell height
Alex Chaube753132022-12-09 16:46:54 +00001261 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics)
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001262 + allAppsBorderSpacePx.y;
1263 // but width is just the cell,
1264 // the border is added in #updateAllAppsContainerWidth
Thales Lima79456492023-05-23 11:32:22 +01001265 if (mIsScalableGrid) {
Alex Chaube753132022-12-09 16:46:54 +00001266 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1267 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001268 allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding();
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001269 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001270
1271 if (allAppsCellWidthPx < allAppsIconSizePx) {
1272 // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to
1273 // make allAppsCellWidth bigger.
1274 int numBorders = inv.numAllAppsColumns - 1;
1275 int extraWidthRequired =
1276 (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns;
1277 if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) {
1278 allAppsCellWidthPx = allAppsIconSizePx;
1279 allAppsBorderSpacePx.x -= extraWidthRequired / numBorders;
1280 } else {
1281 // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space
1282 // for allAppsCellWidth, and reduce allAppsIconSize.
1283 allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns
1284 + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns;
1285 allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx);
1286 allAppsBorderSpacePx.x = 0;
1287 }
1288 }
1289
1290 int cellContentHeight = allAppsIconSizePx
1291 + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y;
1292 if (allAppsCellHeightPx < cellContentHeight) {
1293 // Increase allAppsCellHeight to fit its content.
1294 allAppsCellHeightPx = cellContentHeight;
1295 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001296 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001297 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
1298 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001299 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1300 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001301 allAppsIconDrawablePaddingPx =
1302 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001303 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001304 }
Thales Limaabfe3642023-05-24 18:08:53 +01001305 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001306
Jordan Silva999dd2a2023-11-17 19:31:43 +00001307 private void updateAllAppsWithResponsiveMeasures() {
1308 allAppsIconSizePx = mResponsiveAllAppsCellSpec.getIconSize();
1309 allAppsIconTextSizePx = mResponsiveAllAppsCellSpec.getIconTextSize();
1310 allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding(allAppsIconSizePx,
1311 mResponsiveAllAppsCellSpec.getIconDrawablePadding());
Thales Limaabfe3642023-05-24 18:08:53 +01001312 allAppsBorderSpacePx = new Point(
Jordan Silva8f7986a2023-11-08 12:11:25 +00001313 mResponsiveAllAppsWidthSpec.getGutterPx(),
1314 mResponsiveAllAppsHeightSpec.getGutterPx()
Thales Limaabfe3642023-05-24 18:08:53 +01001315 );
Jordan Silva999dd2a2023-11-17 19:31:43 +00001316 allAppsCellHeightPx = mResponsiveAllAppsHeightSpec.getCellSizePx();
Jordan Silva8f7986a2023-11-08 12:11:25 +00001317 allAppsCellWidthPx = mResponsiveAllAppsWidthSpec.getCellSizePx();
Thales Limaa25cd902023-11-01 12:00:32 +00001318
1319 // This workaround is needed to align AllApps icons with Workspace icons
1320 // since AllApps doesn't have borders between cells
1321 int halfBorder = allAppsBorderSpacePx.x / 2;
Jordan Silva8f7986a2023-11-08 12:11:25 +00001322 allAppsPadding.left = mResponsiveAllAppsWidthSpec.getStartPaddingPx() - halfBorder;
1323 allAppsPadding.right = mResponsiveAllAppsWidthSpec.getEndPaddingPx() - halfBorder;
Jordan Silva376036a2023-11-08 15:56:40 +00001324
Jordan Silva376036a2023-11-08 15:56:40 +00001325
1326 // Reduce the size of the app icon if it doesn't fit
1327 if (allAppsCellWidthPx < allAppsIconSizePx) {
1328 // get a smaller icon size
1329 allAppsIconSizePx = mIconSizeSteps.getIconSmallerThan(allAppsCellWidthPx);
1330 }
1331
1332 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1333 allAppsIconSizePx, allAppsIconDrawablePaddingPx, (int) allAppsIconTextSizePx);
1334
1335 if (allAppsCellHeightPx < cellContentDimensions.getCellContentHeight()) {
1336 if (isVerticalBarLayout()) {
1337 if (allAppsCellHeightPx < iconSizePx) {
1338 cellContentDimensions.setIconSizePx(
1339 mIconSizeSteps.getIconSmallerThan(allAppsCellHeightPx));
1340 }
1341 } else {
1342 cellContentDimensions.resizeToFitCellHeight(allAppsCellHeightPx,
1343 mIconSizeSteps);
1344 }
1345 allAppsIconSizePx = cellContentDimensions.getIconSizePx();
1346 allAppsIconDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1347 allAppsIconTextSizePx = cellContentDimensions.getIconTextSizePx();
1348 }
Jordan Silva999dd2a2023-11-17 19:31:43 +00001349
1350 allAppsCellHeightPx += mResponsiveAllAppsHeightSpec.getGutterPx();
Thales Limaabfe3642023-05-24 18:08:53 +01001351 }
1352
1353 /**
1354 * Re-computes the all-apps cell size to be independent of workspace
1355 */
1356 public void autoResizeAllAppsCells() {
1357 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
1358 int topBottomPadding = textHeight;
1359 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
1360 + textHeight + (topBottomPadding * 2);
1361 }
1362
1363 private void updateAllAppsContainerWidth() {
1364 int cellLayoutHorizontalPadding =
1365 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
1366 if (isTablet) {
1367 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
1368 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Thales Limab433c9c2023-10-30 12:24:05 +00001369 + allAppsPadding.left + allAppsPadding.right;
Thales Limaabfe3642023-05-24 18:08:53 +01001370 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
Thales Limaa25cd902023-11-01 12:00:32 +00001371 } else if (!mIsResponsiveGrid) {
Thales Limab433c9c2023-10-30 12:24:05 +00001372 allAppsPadding.left = allAppsPadding.right =
Thales Limaabfe3642023-05-24 18:08:53 +01001373 Math.max(0, desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding
1374 - (allAppsBorderSpacePx.x / 2));
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001375 }
1376 }
1377
Thales Limaabfe3642023-05-24 18:08:53 +01001378 private void setupAllAppsStyle(Context context) {
1379 TypedArray allAppsStyle = context.obtainStyledAttributes(
1380 inv.allAppsStyle != INVALID_RESOURCE_HANDLE ? inv.allAppsStyle
1381 : R.style.AllAppsStyleDefault, R.styleable.AllAppsStyle);
1382
Thales Limab433c9c2023-10-30 12:24:05 +00001383 allAppsPadding.left = allAppsPadding.right = allAppsStyle.getDimensionPixelSize(
Thales Limaabfe3642023-05-24 18:08:53 +01001384 R.styleable.AllAppsStyle_horizontalPadding, 0);
1385 allAppsStyle.recycle();
1386 }
1387
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001388 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001389 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001390
Jordan Silva637f4eb2023-06-13 11:21:53 +01001391 // Responsive grid doesn't need to scale the folder
1392 if (mIsResponsiveGrid) return;
1393
Thales Lima7eee74b2023-03-16 16:00:55 -03001394 // For usability we can't have the folder use the whole width of the screen
Sunny Goyal07b69292018-01-08 14:19:34 -08001395 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -08001396
Thales Lima7eee74b2023-03-16 16:00:55 -03001397 // Check if the folder fit within the available height.
Thales Lima07c6b8d2023-11-08 18:22:38 +00001398 float contentUsedHeight = folderCellHeightPx * numFolderRows
1399 + ((numFolderRows - 1) * folderCellLayoutBorderSpacePx.y)
Thales Lima7eee74b2023-03-16 16:00:55 -03001400 + folderFooterHeightPx
1401 + folderContentPaddingTop;
1402 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001403 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -08001404
Thales Lima7eee74b2023-03-16 16:00:55 -03001405 // Check if the folder fit within the available width.
Thales Lima07c6b8d2023-11-08 18:22:38 +00001406 float contentUsedWidth = folderCellWidthPx * numFolderColumns
1407 + ((numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x)
Thales Lima7eee74b2023-03-16 16:00:55 -03001408 + folderContentPaddingLeftRight * 2;
1409 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001410 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -08001411
1412 float scale = Math.min(scaleX, scaleY);
1413 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001414 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001415 }
1416 }
1417
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001418 private void updateFolderCellSize(float scale, Resources res) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001419 int minLabelTextSize = pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001420 if (mIsResponsiveGrid) {
Jordan Silva999dd2a2023-11-17 19:31:43 +00001421 folderChildIconSizePx = mResponsiveWorkspaceCellSpec.getIconSize();
1422 folderChildTextSizePx = mResponsiveWorkspaceCellSpec.getIconTextSize();
1423 folderLabelTextSizePx = Math.max(minLabelTextSize,
1424 (int) (folderChildTextSizePx * folderLabelTextScale));
1425 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
1426
Jordan Silva637f4eb2023-06-13 11:21:53 +01001427 folderCellWidthPx = mResponsiveFolderWidthSpec.getCellSizePx();
Jordan Silva637f4eb2023-06-13 11:21:53 +01001428 folderCellHeightPx = mResponsiveFolderHeightSpec.getCellSizePx();
1429 folderContentPaddingTop = mResponsiveFolderHeightSpec.getStartPaddingPx();
1430 folderFooterHeightPx = mResponsiveFolderHeightSpec.getEndPaddingPx();
1431
1432 folderCellLayoutBorderSpacePx = new Point(mResponsiveFolderWidthSpec.getGutterPx(),
Thales Lima4cfd9502023-07-10 14:01:28 +01001433 mResponsiveFolderHeightSpec.getGutterPx());
Jordan Silva637f4eb2023-06-13 11:21:53 +01001434
1435 folderContentPaddingLeftRight = mResponsiveFolderWidthSpec.getStartPaddingPx();
Jordan Silva12fae112023-06-26 12:51:01 +01001436
1437 // Reduce icon width if it's wider than the expected folder cell width
1438 if (folderCellWidthPx < folderChildIconSizePx) {
1439 folderChildIconSizePx = mIconSizeSteps.getIconSmallerThan(folderCellWidthPx);
1440 }
1441
1442 // Recalculating padding and cell height
1443 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
Jordan Silva12fae112023-06-26 12:51:01 +01001444
Thales Limae9b5e142023-11-04 17:10:13 +00001445 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1446 folderChildIconSizePx,
1447 folderChildDrawablePaddingPx,
1448 folderChildTextSizePx);
1449 cellContentDimensions.resizeToFitCellHeight(folderCellHeightPx, mIconSizeSteps);
1450 folderChildIconSizePx = cellContentDimensions.getIconSizePx();
1451 folderChildDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1452 folderChildTextSizePx = cellContentDimensions.getIconTextSizePx();
Jordan Silva999dd2a2023-11-17 19:31:43 +00001453 folderLabelTextSizePx = Math.max(minLabelTextSize,
Jordan Silva9a3bd8f2023-11-16 18:33:28 +00001454 (int) (folderChildTextSizePx * folderLabelTextScale));
Jordan Silva999dd2a2023-11-17 19:31:43 +00001455 return;
1456 }
1457
1458 float invIconSizeDp = inv.iconSize[mTypeIndex];
1459 float invIconTextSizeDp = inv.iconTextSize[mTypeIndex];
1460 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1461 folderChildTextSizePx = pxFromSp(invIconTextSizeDp, mMetrics, scale);
1462 folderLabelTextSizePx = Math.max(minLabelTextSize,
1463 (int) (folderChildTextSizePx * folderLabelTextScale));
1464 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
1465
1466 if (mIsScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001467 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
Thales Lima7eee74b2023-03-16 16:00:55 -03001468 folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale);
1469 folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale);
1470 } else {
1471 folderCellWidthPx = roundPxValueFromFloat(folderCellWidthPx * scale);
1472 folderCellHeightPx = roundPxValueFromFloat(folderCellHeightPx * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001473 }
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001474
Thales Lima7eee74b2023-03-16 16:00:55 -03001475 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001476 folderCellLayoutBorderSpacePx = new Point(
1477 roundPxValueFromFloat(folderCellLayoutBorderSpacePx.x * scale),
1478 roundPxValueFromFloat(folderCellLayoutBorderSpacePx.y * scale)
1479 );
Thales Lima7eee74b2023-03-16 16:00:55 -03001480 folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale);
1481
Jordan Silva637f4eb2023-06-13 11:21:53 +01001482 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx.x;
Jordan Silva12fae112023-06-26 12:51:01 +01001483
1484 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
Jon Miranda823da222021-03-23 08:08:45 -04001485 } else {
1486 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1487 * scale);
1488 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1489 * scale);
1490
1491 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1492 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Lima7eee74b2023-03-16 16:00:55 -03001493 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001494 folderContentPaddingLeftRight =
1495 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1496 folderFooterHeightPx =
Thales Lima7eee74b2023-03-16 16:00:55 -03001497 roundPxValueFromFloat(
1498 res.getDimensionPixelSize(R.dimen.folder_footer_height_default)
1499 * scale);
1500
Jordan Silva12fae112023-06-26 12:51:01 +01001501 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
Jon Miranda823da222021-03-23 08:08:45 -04001502 }
Jon Mirandabf7d8122016-11-03 15:29:29 -07001503 }
1504
Winson1f064272016-07-18 17:18:02 -07001505 public void updateInsets(Rect insets) {
1506 mInsets.set(insets);
1507 }
1508
Sunny Goyalae6e3182019-04-30 12:04:37 -07001509 /**
1510 * The current device insets. This is generally same as the insets being dispatched to
1511 * {@link Insettable} elements, but can differ if the element is using a different profile.
1512 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001513 public Rect getInsets() {
1514 return mInsets;
1515 }
1516
Sunny Goyal756cd262015-08-20 12:33:21 -07001517 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001518 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001519 }
1520
Sunny Goyal19ff7282021-04-22 10:12:54 -07001521 public Point getCellSize(Point result) {
1522 if (result == null) {
1523 result = new Point();
1524 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001525
Pat Manning25d53342022-05-10 09:58:49 +00001526 int shortcutAndWidgetContainerWidth =
1527 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1528 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1529 inv.numColumns);
1530 int shortcutAndWidgetContainerHeight =
1531 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1532 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1533 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001534 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001535 }
1536
1537 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001538 * Returns the left and right space on the cell, which is the cell width - icon size
1539 */
1540 public int getCellHorizontalSpace() {
1541 return getCellSize().x - iconSizePx;
1542 }
1543
1544 /**
Pat Manning25d53342022-05-10 09:58:49 +00001545 * Gets the number of panels within the workspace.
1546 */
1547 public int getPanelCount() {
1548 return isTwoPanels ? 2 : 1;
1549 }
1550
1551 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001552 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1553 * bottom of the screen.
1554 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001555 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1556 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001557 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001558 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001559 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001560 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001561 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001562 }
1563
1564 /**
1565 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1566 */
Pat Manning25d53342022-05-10 09:58:49 +00001567 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001568 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001569 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001570 }
1571
1572 /**
1573 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1574 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001575 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001576 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001577 return heightPx - (isVerticalBarLayout()
1578 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001579 }
1580
Pat Manningea5c1d22022-04-14 10:58:16 +01001581 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001582 * Gets the scale of the workspace for the spring-loaded edit state.
1583 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001584 public float getWorkspaceSpringLoadScale(Context context) {
1585 float scale =
1586 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1587 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001588 scale = Math.min(scale, 1f);
1589
Pat Manninge63dd252022-08-02 16:15:29 +01001590 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001591 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001592 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001593 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001594 if (scaledWorkspaceWidth > maxAvailableWidth) {
1595 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1596 }
1597 return scale;
1598 }
1599
Pat Manning25d53342022-05-10 09:58:49 +00001600 /**
1601 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1602 *
1603 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1604 * layouts have two Cell Layouts per workspace.
1605 */
1606 public int getCellLayoutWidth() {
1607 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001608 }
1609
Pat Manning25d53342022-05-10 09:58:49 +00001610 /**
1611 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1612 *
1613 * <p>This is the height of a Workspace, less its vertical padding.
1614 */
1615 public int getCellLayoutHeight() {
1616 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001617 }
1618
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001619 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001620 return new Point(workspacePadding.left + workspacePadding.right,
1621 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001622 }
1623
1624 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001625 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1626 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001627 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001628 private void updateWorkspacePadding() {
1629 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001630 if (isVerticalBarLayout()) {
Jordan Silva3646a1b2023-08-02 13:52:52 +01001631 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001632 padding.top = mResponsiveWorkspaceHeightSpec.getStartPaddingPx();
Thales Lima8e11d532023-08-31 13:40:26 +00001633 padding.bottom = Math.max(0,
Jordan Silva8f7986a2023-11-08 12:11:25 +00001634 mResponsiveWorkspaceHeightSpec.getEndPaddingPx() - mInsets.bottom);
Jordan Silva3646a1b2023-08-02 13:52:52 +01001635 if (isSeascape()) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001636 padding.left =
1637 hotseatBarSizePx + mResponsiveWorkspaceWidthSpec.getEndPaddingPx();
1638 padding.right = mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
Jordan Silva3646a1b2023-08-02 13:52:52 +01001639 } else {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001640 padding.left = mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
1641 padding.right =
1642 hotseatBarSizePx + mResponsiveWorkspaceWidthSpec.getEndPaddingPx();
Jordan Silva3646a1b2023-08-02 13:52:52 +01001643 }
Winson1f064272016-07-18 17:18:02 -07001644 } else {
Jordan Silva3646a1b2023-08-02 13:52:52 +01001645 padding.top = 0;
1646 padding.bottom = edgeMarginPx;
1647 if (isSeascape()) {
1648 padding.left = hotseatBarSizePx;
Thales Lima8e11d532023-08-31 13:40:26 +00001649 padding.right = mHotseatBarEdgePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001650 } else {
Thales Lima8e11d532023-08-31 13:40:26 +00001651 padding.left = mHotseatBarEdgePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001652 padding.right = hotseatBarSizePx;
1653 }
Winson1f064272016-07-18 17:18:02 -07001654 }
Winson Chungb3800242013-10-24 11:01:54 -07001655 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001656 // Pad the bottom of the workspace with hotseat bar
1657 // and leave a bit of space in case a widget go all the way down
Thales Lima79456492023-05-23 11:32:22 +01001658 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding - mInsets.bottom;
1659 if (!mIsResponsiveGrid) {
1660 paddingBottom +=
1661 workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace;
1662 }
1663 int paddingTop = workspaceTopPadding + (mIsScalableGrid ? 0 : edgeMarginPx);
Pat Manning08610ca2022-04-05 21:03:16 +01001664 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001665
Pat Manning08610ca2022-04-05 21:03:16 +01001666 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001667 }
Pat Manning08610ca2022-04-05 21:03:16 +01001668 insetPadding(workspacePadding, cellLayoutPaddingPx);
1669 }
1670
1671 private void insetPadding(Rect paddings, Rect insets) {
1672 insets.left = Math.min(insets.left, paddings.left);
1673 paddings.left -= insets.left;
1674
1675 insets.top = Math.min(insets.top, paddings.top);
1676 paddings.top -= insets.top;
1677
1678 insets.right = Math.min(insets.right, paddings.right);
1679 paddings.right -= insets.right;
1680
1681 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1682 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001683 }
1684
Liran Binyamina833af32023-08-02 16:30:27 -04001685
1686 /**
1687 * Returns the new border space that should be used between hotseat icons after adjusting it to
1688 * the bubble bar.
1689 *
1690 * <p>If there's no adjustment needed, this method returns {@code 0}.
1691 */
1692 public float getHotseatAdjustedBorderSpaceForBubbleBar(Context context) {
1693 // only need to adjust when QSB is on top of the hotseat.
1694 if (isQsbInline) {
1695 return 0;
1696 }
1697
1698 // no need to adjust if there's enough space for the bubble bar to the right of the hotseat.
1699 if (getHotseatLayoutPadding(context).right > mBubbleBarSpaceThresholdPx) {
1700 return 0;
1701 }
1702
1703 // The adjustment is shrinking the hotseat's width by 1 icon on either side.
1704 int iconsWidth =
1705 iconSizePx * numShownHotseatIcons + hotseatBorderSpace * (numShownHotseatIcons - 1);
1706 int newWidth = iconsWidth - 2 * iconSizePx;
1707 // Evenly space the icons within the boundaries of the new width.
1708 return (float) (newWidth - iconSizePx * numShownHotseatIcons) / (numShownHotseatIcons - 1);
1709 }
1710
Sunny Goyal57b22792021-05-25 14:35:01 -07001711 /**
1712 * Returns the padding for hotseat view
1713 */
1714 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001715 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001716 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001717 // The hotseat icons will be placed in the middle of the hotseat cells.
1718 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1719 // in vertical bar layout.
1720 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1721 // is set to account for that difference.
Jordan Silva3646a1b2023-08-02 13:52:52 +01001722 float diffOverlapFactor = mIsResponsiveGrid ? 0
1723 : iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
1724
Pat Manning08610ca2022-04-05 21:03:16 +01001725 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1726 - diffOverlapFactor), 0);
1727 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001728 + diffOverlapFactor), 0);
1729
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001730 if (isSeascape()) {
Thales Lima8e11d532023-08-31 13:40:26 +00001731 hotseatBarPadding.set(mInsets.left + mHotseatBarEdgePaddingPx, paddingTop,
1732 mHotseatBarWorkspaceSpacePx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001733 } else {
Thales Lima8e11d532023-08-31 13:40:26 +00001734 hotseatBarPadding.set(mHotseatBarWorkspaceSpacePx, paddingTop,
1735 mInsets.right + mHotseatBarEdgePaddingPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001736 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001737 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001738 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001739 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1740 int hotseatBarTopPadding =
1741 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001742
Thales Lima6a590062022-11-22 15:52:49 +00001743 int hotseatWidth = getHotseatRequiredWidth();
Helen Cheuke76291f2023-02-14 17:11:05 +00001744 int startSpacing;
1745 int endSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001746 // Hotseat aligns to the left with nav buttons
1747 if (hotseatBarEndOffset > 0) {
Jon Mirandae17a9492023-03-08 16:42:20 -08001748 startSpacing = inlineNavButtonsEndSpacingPx;
Helen Cheuke76291f2023-02-14 17:11:05 +00001749 endSpacing = availableWidthPx - hotseatWidth - startSpacing + hotseatBorderSpace;
1750 } else {
1751 startSpacing = (availableWidthPx - hotseatWidth) / 2;
1752 endSpacing = startSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001753 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001754 startSpacing += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001755
Helen Cheuke76291f2023-02-14 17:11:05 +00001756 hotseatBarPadding.top = hotseatBarTopPadding;
1757 hotseatBarPadding.bottom = hotseatBarBottomPadding;
Alex Chau51da2192022-05-20 13:32:10 +01001758 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001759 if (isRtl) {
Helen Cheuke76291f2023-02-14 17:11:05 +00001760 hotseatBarPadding.left = endSpacing;
1761 hotseatBarPadding.right = startSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001762 } else {
Helen Cheuke76291f2023-02-14 17:11:05 +00001763 hotseatBarPadding.left = startSpacing;
1764 hotseatBarPadding.right = endSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001765 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001766
Thales Lima79456492023-05-23 11:32:22 +01001767 } else if (mIsScalableGrid) {
Alex Chau206ede92022-08-01 17:46:12 +01001768 int sideSpacing = (availableWidthPx - hotseatQsbWidth) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001769 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001770 0,
Thales Lima425f6822022-05-10 13:44:58 -03001771 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001772 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001773 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001774 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1775 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1776 // for this, we pad the left and right of the hotseat with half of the difference of a
1777 // workspace cell vs a hotseat cell.
1778 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001779 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001780 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001781 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001782 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1783 + mInsets.left,
1784 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001785 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001786 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001787 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001788 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001789 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001790 }
1791
Andy Wickhambd9a1802023-06-08 16:33:15 -07001792 /** The margin between the edge of all apps and the edge of the first icon. */
Thales Limab433c9c2023-10-30 12:24:05 +00001793 public int getAllAppsIconStartMargin(Context context) {
Andy Wickhambd9a1802023-06-08 16:33:15 -07001794 int allAppsSpacing;
1795 if (isVerticalBarLayout()) {
1796 // On phones, the landscape layout uses a different setup.
1797 allAppsSpacing = workspacePadding.left + workspacePadding.right;
1798 } else {
Thales Limab433c9c2023-10-30 12:24:05 +00001799 allAppsSpacing =
1800 allAppsPadding.left + allAppsPadding.right + allAppsLeftRightMargin * 2;
Andy Wickhambd9a1802023-06-08 16:33:15 -07001801 }
1802
1803 int cellWidth = DeviceProfile.calculateCellWidth(
1804 availableWidthPx - allAppsSpacing,
1805 0 /* borderSpace */,
1806 numShownAllAppsColumns);
1807 int iconVisibleSize = Math.round(ICON_VISIBLE_AREA_FACTOR * allAppsIconSizePx);
1808 int iconAlignmentMargin = (cellWidth - iconVisibleSize) / 2;
Thales Limab433c9c2023-10-30 12:24:05 +00001809
1810 return (Utilities.isRtl(context.getResources()) ? allAppsPadding.right
1811 : allAppsPadding.left) + iconAlignmentMargin;
Andy Wickhambd9a1802023-06-08 16:33:15 -07001812 }
1813
Thales Lima9938c2f2022-07-25 14:38:16 +01001814 private int getAdditionalQsbSpace() {
1815 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1816 }
1817
1818 /**
1819 * Calculate how much space the hotseat needs to be shown completely
1820 */
1821 private int getHotseatRequiredWidth() {
1822 int additionalQsbSpace = getAdditionalQsbSpace();
1823 return iconSizePx * numShownHotseatIcons
Thales Lima6a590062022-11-22 15:52:49 +00001824 + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1))
Thales Lima9938c2f2022-07-25 14:38:16 +01001825 + additionalQsbSpace;
1826 }
1827
Winsonfadbe8f2016-07-22 16:35:37 -07001828 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001829 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1830 */
1831 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001832 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001833 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1834 } else if (isTaskbarPresent) { // QSB on top
1835 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001836 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001837 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001838 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001839 }
1840
Thales Limab8c05952022-05-23 16:58:38 +01001841 /**
1842 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1843 */
1844 private int getHotseatBarBottomPadding() {
1845 if (isTaskbarPresent) { // QSB on top or inline
1846 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001847 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001848 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001849 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001850 }
1851
1852 /**
Alex Chau51da2192022-05-20 13:32:10 +01001853 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1854 */
1855 public int getTaskbarOffsetY() {
Jon Miranda9c478b62023-03-23 21:38:49 -07001856 int taskbarIconBottomSpace = (taskbarHeight - iconSizePx) / 2;
Alex Chau51da2192022-05-20 13:32:10 +01001857 int launcherIconBottomSpace =
1858 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001859 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001860 }
1861
Uwais Ashrafaa7fa882023-10-10 21:36:06 +00001862 /** Returns the number of pixels required below OverviewActions. */
Alex Chaua2fc7642022-04-21 14:20:23 +01001863 public int getOverviewActionsClaimedSpaceBelow() {
Uwais Ashrafaa7fa882023-10-10 21:36:06 +00001864 return isTaskbarPresent ? mTransientTaskbarClaimedSpace : mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001865 }
1866
1867 /** Gets the space that the overview actions will take, including bottom margin. */
1868 public int getOverviewActionsClaimedSpace() {
Alex Chau4989f4f2023-10-11 14:08:22 +00001869 int overviewActionsSpace = isTablet && Flags.enableGridOnlyOverview()
Pat Manning7b8f7662023-01-18 14:48:30 +00001870 ? 0
1871 : (overviewActionsTopMarginPx + overviewActionsHeight);
1872 return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
Alex Chaua2fc7642022-04-21 14:20:23 +01001873 }
1874
1875 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001876 * Takes the View and return the scales of width and height depending on the DeviceProfile
1877 * specifications
1878 *
1879 * @param itemInfo The tag of the widget view
1880 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1881 * height
1882 */
1883 @NonNull
1884 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1885 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1886 }
1887
1888 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001889 * @return the bounds for which the open folders should be contained within
1890 */
1891 public Rect getAbsoluteOpenFolderBounds() {
1892 if (isVerticalBarLayout()) {
1893 // Folders should only appear right of the drop target bar and left of the hotseat
1894 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1895 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001896 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001897 mInsets.top + availableHeightPx);
1898 } else {
1899 // Folders should only appear below the drop target bar and above the hotseat
Jon Miranda9c478b62023-03-23 21:38:49 -07001900 int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001901 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001902 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001903 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001904 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001905 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001906 }
1907 }
1908
Jon Miranda228877d2021-02-09 11:05:00 -05001909 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1910 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001911 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001912
Jon Miranda228877d2021-02-09 11:05:00 -05001913 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1914 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001915 }
1916
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001917 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001918 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1919 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1920 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001921 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001922 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001923 return isLandscape && transposeLayoutWithOrientation;
1924 }
1925
Sunny Goyal59d086c2018-05-07 17:31:40 -07001926 /**
1927 * Updates orientation information and returns true if it has changed from the previous value.
1928 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001929 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001930 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001931 boolean isSeascape = DisplayController.INSTANCE.get(context)
1932 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001933 if (mIsSeascape != isSeascape) {
1934 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001935 // Hotseat changing sides requires updating workspace left/right paddings
1936 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001937 return true;
1938 }
1939 }
1940 return false;
1941 }
1942
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001943 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001944 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001945 }
1946
Sunny Goyal07b69292018-01-08 14:19:34 -08001947 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001948 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001949 }
1950
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001951 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001952 switch (containerType) {
1953 case CellLayout.WORKSPACE:
1954 return cellHeightPx;
1955 case CellLayout.FOLDER:
1956 return folderCellHeightPx;
1957 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001958 // The hotseat is the only container where the cell height is going to be
1959 // different from the content within that cell.
1960 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001961 default:
1962 // ??
1963 return 0;
1964 }
1965 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001966
Jon Miranda58561d42021-03-17 10:51:54 -04001967 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001968 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001969 }
1970
Alex Chaue818bcb2022-09-02 17:27:11 +01001971 private String dpPointFToString(String name, PointF value) {
1972 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
1973 }
1974
Pat Manning5f74bfd2022-07-20 12:08:54 +01001975 /** Dumps various DeviceProfile variables to the specified writer. */
1976 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04001977 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001978 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001979
1980 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001981 writer.println(prefix + "\tisPhone:" + isPhone);
1982 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1983 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001984 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001985
1986 writer.println(prefix + "\tisLandscape:" + isLandscape);
1987 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001988 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001989
1990 writer.println(prefix + pxToDpStr("windowX", windowX));
1991 writer.println(prefix + pxToDpStr("windowY", windowY));
1992 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1993 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001994 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1995 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001996 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1997 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1998 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1999 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04002000
2001 writer.println(prefix + "\taspectRatio:" + aspectRatio);
2002
Thales Limac98b7812023-04-14 15:04:23 +01002003 writer.println(prefix + "\tisResponsiveGrid:" + mIsResponsiveGrid);
Thales Lima79456492023-05-23 11:32:22 +01002004 writer.println(prefix + "\tisScalableGrid:" + mIsScalableGrid);
Jon Miranda58561d42021-03-17 10:51:54 -04002005
Thales Lima83bedbf2021-10-05 17:47:39 +01002006 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00002007 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
2008 writer.println(prefix + "\tinv.numSearchContainerColumns: "
2009 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04002010
Alex Chaue818bcb2022-09-02 17:27:11 +01002011 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07002012
Jon Miranda58561d42021-03-17 10:51:54 -04002013 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
2014 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
2015
2016 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
2017 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
2018
Thales Lima83bedbf2021-10-05 17:47:39 +01002019 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
2020 cellLayoutBorderSpacePx.x));
2021 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
2022 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002023 writer.println(
2024 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
2025 writer.println(
2026 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
2027 writer.println(
2028 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01002029 writer.println(
2030 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01002031
Jon Miranda58561d42021-03-17 10:51:54 -04002032 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
2033 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
2034 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
2035
Thales Lima07c6b8d2023-11-08 18:22:38 +00002036 writer.println(prefix + "\tnumFolderRows: " + numFolderRows);
2037 writer.println(prefix + "\tnumFolderColumns: " + numFolderColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04002038 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
2039 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
2040 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
2041 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
2042 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
2043 folderChildDrawablePaddingPx));
Jordan Silva637f4eb2023-06-13 11:21:53 +01002044 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.x",
2045 folderCellLayoutBorderSpacePx.x));
2046 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.y",
2047 folderCellLayoutBorderSpacePx.y));
Thales Limaa08a4432022-08-09 09:55:17 +01002048 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
2049 folderContentPaddingLeftRight));
2050 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03002051 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002052
Alex Chaue0227552022-04-06 19:44:43 +01002053 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01002054 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
2055 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
2056 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
2057 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01002058
2059 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
Alex Chau3d2c0622022-09-01 21:28:14 +01002060 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
2061 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04002062 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
2063 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
2064 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
2065 allAppsIconDrawablePaddingPx));
2066 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00002067 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01002068 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
2069 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07002070 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Thales Limab433c9c2023-10-30 12:24:05 +00002071 writer.println(prefix + pxToDpStr("allAppsPadding.top", allAppsPadding.top));
2072 writer.println(prefix + pxToDpStr("allAppsPadding.left", allAppsPadding.left));
2073 writer.println(prefix + pxToDpStr("allAppsPadding.right", allAppsPadding.right));
Alex Chau27b39b92022-01-14 18:02:18 +00002074 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04002075
2076 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03002077 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04002078 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00002079 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Thales Lima8e11d532023-08-31 13:40:26 +00002080 writer.println(prefix + pxToDpStr("mHotseatBarEdgePaddingPx",
2081 mHotseatBarEdgePaddingPx));
2082 writer.println(prefix + pxToDpStr("mHotseatBarWorkspaceSpacePx",
2083 mHotseatBarWorkspaceSpacePx));
Pat Manning26f70f72022-07-07 13:50:39 +01002084 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01002085 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
2086 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01002087 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
2088 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002089 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
2090 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
2091 hotseatLayoutPadding.top));
2092 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
2093 hotseatLayoutPadding.bottom));
2094 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
2095 hotseatLayoutPadding.left));
2096 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
2097 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07002098 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00002099 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00002100 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01002101 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04002102
2103 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10002104 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda9c478b62023-03-23 21:38:49 -07002105 writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight));
2106 writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight));
2107 writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin));
2108 writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize));
Jon Miranda58561d42021-03-17 10:51:54 -04002109
Thales Lima83bedbf2021-10-05 17:47:39 +01002110 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
2111 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002112 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
2113 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
2114 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00002115 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04002116
Jon Mirandaab3c6812021-06-28 15:42:28 -07002117 writer.println(prefix + pxToDpStr("iconScale", iconScale));
2118 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04002119 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00002120 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04002121
Thales Lima171ee662022-11-22 15:52:49 +00002122 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04002123 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
2124 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00002125
2126 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00002127 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
2128 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
2129 overviewTaskIconDrawableSizePx));
2130 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
2131 overviewTaskIconDrawableSizeGridPx));
Pat Manning1695cc72023-07-05 11:45:13 +01002132 writer.println(prefix + pxToDpStr("overviewTaskIconAppChipMenuDrawableSizePx",
2133 overviewTaskIconAppChipMenuDrawableSizePx));
Alex Chau635b3ab2022-01-26 16:49:10 +00002134 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
2135 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01002136 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
2137 overviewActionsTopMarginPx));
2138 writer.println(prefix + pxToDpStr("overviewActionsHeight",
2139 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00002140 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
2141 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00002142 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
2143 overviewActionsButtonSpacing));
2144 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
2145 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
2146 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01002147
Alex Chau62572c02022-07-25 18:36:37 +00002148 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01002149 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00002150 writer.println(
2151 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01002152
Pat Manning5f74bfd2022-07-20 12:08:54 +01002153 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
2154 getCellLayoutSpringLoadShrunkTop()));
2155 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
2156 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01002157 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
2158 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002159 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
2160 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01002161 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
2162 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Thales Lima79456492023-05-23 11:32:22 +01002163 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00002164 writer.println(prefix + "\tmResponsiveWorkspaceHeightSpec:"
2165 + mResponsiveWorkspaceHeightSpec.toString());
2166 writer.println(prefix + "\tmResponsiveWorkspaceWidthSpec:"
2167 + mResponsiveWorkspaceWidthSpec.toString());
2168 writer.println(prefix + "\tmResponsiveAllAppsHeightSpec:"
2169 + mResponsiveAllAppsHeightSpec.toString());
2170 writer.println(prefix + "\tmResponsiveAllAppsWidthSpec:"
2171 + mResponsiveAllAppsWidthSpec.toString());
Jordan Silva637f4eb2023-06-13 11:21:53 +01002172 writer.println(prefix + "\tmResponsiveFolderHeightSpec:" + mResponsiveFolderHeightSpec);
2173 writer.println(prefix + "\tmResponsiveFolderWidthSpec:" + mResponsiveFolderWidthSpec);
Thales Limaf8bfb032023-07-24 15:08:05 +01002174 writer.println(prefix + "\tmResponsiveHotseatSpec:" + mResponsiveHotseatSpec);
Jordan Silva999dd2a2023-11-17 19:31:43 +00002175 writer.println(prefix + "\tmResponsiveWorkspaceCellSpec:"
2176 + mResponsiveWorkspaceCellSpec);
2177 writer.println(prefix + "\tmResponsiveAllAppsCellSpec:" + mResponsiveAllAppsCellSpec);
Thales Lima79456492023-05-23 11:32:22 +01002178 }
Jon Miranda58561d42021-03-17 10:51:54 -04002179 }
2180
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00002181 /** Returns a reduced representation of this DeviceProfile. */
2182 public String toSmallString() {
2183 return "isTablet:" + isTablet + ", "
2184 + "isMultiDisplay:" + isMultiDisplay + ", "
2185 + "widthPx:" + widthPx + ", "
2186 + "heightPx:" + heightPx + ", "
2187 + "insets:" + mInsets + ", "
2188 + "rotationHint:" + rotationHint;
2189 }
2190
Alex Chaua6907dc2022-03-18 15:24:07 +00002191 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07002192 Configuration config = new Configuration(c.getResources().getConfiguration());
2193 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03002194 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00002195 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07002196 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07002197 }
Sunny Goyalfde55052018-02-01 14:46:13 -08002198
2199 /**
2200 * Callback when a component changes the DeviceProfile associated with it, as a result of
2201 * configuration change
2202 */
2203 public interface OnDeviceProfileChangeListener {
2204
2205 /**
2206 * Called when the device profile is reassigned. Note that for layout and measurements, it
2207 * is sufficient to listen for inset changes. Use this callback when you need to perform
2208 * a one time operation.
2209 */
2210 void onDeviceProfileChanged(DeviceProfile dp);
2211 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002212
Sihua Mae04aa202022-07-18 12:43:56 -07002213 /**
2214 * Handler that deals with ItemInfo of the views for the DeviceProfile
2215 */
2216 @FunctionalInterface
2217 public interface ViewScaleProvider {
2218 /**
2219 * Get the scales from the view
2220 *
2221 * @param itemInfo The tag of the widget view
2222 * @return PointF instance containing the scale information, or null if using the default
2223 * app widget scale of this device profile.
2224 */
2225 @NonNull
2226 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
2227 }
2228
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002229 public static class Builder {
2230 private Context mContext;
2231 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07002232 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002233
Sunny Goyal19ff7282021-04-22 10:12:54 -07002234 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00002235 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002236
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002237 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07002238 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00002239 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07002240 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002241
Sunny Goyal65190ae2022-08-02 14:16:26 -07002242 private SparseArray<DotRenderer> mDotRendererCache;
2243
Jon Miranda2b25ded2023-02-02 14:48:45 -08002244 private Consumer<DeviceProfile> mOverrideProvider;
2245
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002246 private boolean mIsTransientTaskbar;
2247
Sunny Goyalfd58da62020-08-11 12:06:49 -07002248 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002249 mContext = context;
2250 mInv = inv;
2251 mInfo = info;
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002252 mIsTransientTaskbar = info.isTransientTaskbar();
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002253 }
2254
2255 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
2256 mIsMultiWindowMode = isMultiWindowMode;
2257 return this;
2258 }
2259
Alex Chauab800f72022-12-13 17:46:06 +00002260 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
2261 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07002262 return this;
2263 }
2264
Sunny Goyal65190ae2022-08-02 14:16:26 -07002265 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
2266 mDotRendererCache = dotRendererCache;
2267 return this;
2268 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07002269
2270 public Builder setWindowBounds(WindowBounds bounds) {
2271 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07002272 return this;
2273 }
2274
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002275 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
2276 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
2277 return this;
2278 }
2279
Alex Chau6ed408f2022-03-04 12:58:05 +00002280 public Builder setGestureMode(boolean isGestureMode) {
2281 mIsGestureMode = isGestureMode;
2282 return this;
2283 }
2284
Jon Miranda2b25ded2023-02-02 14:48:45 -08002285 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
2286 mOverrideProvider = overrideProvider;
2287 return this;
2288 }
2289
Sihua Mae04aa202022-07-18 12:43:56 -07002290 /**
2291 * Set the viewScaleProvider for the builder
2292 *
2293 * @param viewScaleProvider The viewScaleProvider to be set for the
Thales Limae9273ea2023-01-26 12:33:52 +00002294 * DeviceProfile
Sihua Mae04aa202022-07-18 12:43:56 -07002295 * @return This builder
2296 */
2297 @NonNull
2298 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
2299 mViewScaleProvider = viewScaleProvider;
2300 return this;
2301 }
2302
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002303 /**
2304 * Set the isTransientTaskbar for the builder
2305 * @return This Builder
2306 */
2307 public Builder setIsTransientTaskbar(boolean isTransientTaskbar) {
2308 mIsTransientTaskbar = isTransientTaskbar;
2309 return this;
2310 }
2311
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002312 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07002313 if (mWindowBounds == null) {
2314 throw new IllegalArgumentException("Window bounds not set");
2315 }
2316 if (mTransposeLayoutWithOrientation == null) {
2317 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
2318 }
Alex Chau6ed408f2022-03-04 12:58:05 +00002319 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01002320 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00002321 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002322 if (mDotRendererCache == null) {
2323 mDotRendererCache = new SparseArray<>();
2324 }
Sihua Mae04aa202022-07-18 12:43:56 -07002325 if (mViewScaleProvider == null) {
2326 mViewScaleProvider = DEFAULT_PROVIDER;
2327 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08002328 if (mOverrideProvider == null) {
2329 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
2330 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002331 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00002332 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002333 mIsGestureMode, mViewScaleProvider, mOverrideProvider, mIsTransientTaskbar);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002334 }
2335 }
Winson Chungb3800242013-10-24 11:01:54 -07002336}