blob: 8a6347792505eaca4dc8636d6906c90ec2a0c2e3 [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;
Thales Limaf8bfb032023-07-24 15:08:05 +010057import com.android.launcher3.responsive.CalculatedHotseatSpec;
Jordan Silvaf2402e22023-10-26 19:53:16 +010058import com.android.launcher3.responsive.CalculatedResponsiveSpec;
59import com.android.launcher3.responsive.HotseatSpecsProvider;
60import com.android.launcher3.responsive.ResponsiveSpec.Companion.ResponsiveSpecType;
61import com.android.launcher3.responsive.ResponsiveSpec.DimensionType;
62import com.android.launcher3.responsive.ResponsiveSpecsProvider;
Sunny Goyal57b22792021-05-25 14:35:01 -070063import com.android.launcher3.uioverrides.ApiWrapper;
Thales Lima24ceca62023-09-25 16:21:17 -070064import com.android.launcher3.util.CellContentDimensions;
Sunny Goyalfd58da62020-08-11 12:06:49 -070065import com.android.launcher3.util.DisplayController;
66import com.android.launcher3.util.DisplayController.Info;
Thales Lima2759aa32023-06-05 16:25:45 +010067import com.android.launcher3.util.IconSizeSteps;
Thales Limac98b7812023-04-14 15:04:23 +010068import com.android.launcher3.util.ResourceHelper;
Sunny Goyalb46703d2020-05-27 17:52:03 -070069import com.android.launcher3.util.WindowBounds;
Winson1f064272016-07-18 17:18:02 -070070
Jon Miranda58561d42021-03-17 10:51:54 -040071import java.io.PrintWriter;
Alex Chaue818bcb2022-09-02 17:27:11 +010072import java.util.Locale;
Jon Miranda2b25ded2023-02-02 14:48:45 -080073import java.util.function.Consumer;
Jon Miranda58561d42021-03-17 10:51:54 -040074
Sunny Goyal35c7b192021-04-20 16:51:10 -070075@SuppressLint("NewApi")
Winson Chungb3800242013-10-24 11:01:54 -070076public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070077
Sunny Goyal8b9919d2021-04-07 14:45:17 -070078 private static final int DEFAULT_DOT_SIZE = 100;
Alex Chau206ede92022-08-01 17:46:12 +010079 private static final float ALL_APPS_TABLET_MAX_ROWS = 5.5f;
Thales Limab35faed2022-09-05 16:30:01 -030080 private static final float MIN_FOLDER_TEXT_SIZE_SP = 16f;
Sunny Goyal6c304b12023-04-10 12:03:04 -070081 private static final float MIN_WIDGET_PADDING_DP = 6f;
Alex Chau206ede92022-08-01 17:46:12 +010082
Sihua Mae04aa202022-07-18 12:43:56 -070083 public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f);
84 public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE;
Jordan Silvaf2402e22023-10-26 19:53:16 +010085 public static final Consumer<DeviceProfile> DEFAULT_DIMENSION_PROVIDER = dp -> {
86 };
Sihua Mae04aa202022-07-18 12:43:56 -070087
Adam Cohen2e6da152015-05-06 11:42:25 -070088 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070089 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070090 private final DisplayMetrics mMetrics;
Thales Lima2759aa32023-06-05 16:25:45 +010091 private final IconSizeSteps mIconSizeSteps;
Winson Chungbe876472014-05-14 14:15:20 -070092
Sunny Goyalc6205602015-05-21 20:46:33 -070093 // Device properties
94 public final boolean isTablet;
Sunny Goyalc6205602015-05-21 20:46:33 -070095 public final boolean isPhone;
96 public final boolean transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +000097 public final boolean isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -070098 public final boolean isTwoPanels;
Thales Limaa1012902022-01-13 17:58:42 +000099 public final boolean isQsbInline;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700100
Sunny Goyalc6205602015-05-21 20:46:33 -0700101 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -0700102 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -0800103 public final boolean isMultiWindowMode;
Alex Chau6ed408f2022-03-04 12:58:05 +0000104 public final boolean isGestureMode;
Sunny Goyald70e75a2018-02-22 10:07:32 -0800105
Sunny Goyal0addbf02020-04-28 14:17:35 -0700106 public final int windowX;
107 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -0700108 public final int widthPx;
109 public final int heightPx;
110 public final int availableWidthPx;
111 public final int availableHeightPx;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800112 public final int rotationHint;
Jon Mirandabba64512019-03-27 10:54:17 -0700113
114 public final float aspectRatio;
115
Thales Lima79456492023-05-23 11:32:22 +0100116 private final boolean mIsScalableGrid;
Thales Lima83bedbf2021-10-05 17:47:39 +0100117 private final int mTypeIndex;
Jon Mirandae126d722021-02-25 10:45:20 -0500118
Thales Limac98b7812023-04-14 15:04:23 +0100119 // Responsive grid
120 private final boolean mIsResponsiveGrid;
Jordan Silva8f7986a2023-11-08 12:11:25 +0000121 private CalculatedResponsiveSpec mResponsiveWorkspaceWidthSpec;
122 private CalculatedResponsiveSpec mResponsiveWorkspaceHeightSpec;
123 private CalculatedResponsiveSpec mResponsiveAllAppsWidthSpec;
124 private CalculatedResponsiveSpec mResponsiveAllAppsHeightSpec;
Jordan Silvaf2402e22023-10-26 19:53:16 +0100125 private CalculatedResponsiveSpec mResponsiveFolderWidthSpec;
126 private CalculatedResponsiveSpec mResponsiveFolderHeightSpec;
Thales Limaf8bfb032023-07-24 15:08:05 +0100127 private CalculatedHotseatSpec mResponsiveHotseatSpec;
Thales Limac98b7812023-04-14 15:04:23 +0100128
Tony Wickhamd6b40372015-09-23 18:37:57 -0700129 /**
130 * The maximum amount of left/right workspace padding as a percentage of the screen width.
131 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
132 * 7% of the screen width can be used as right padding.
133 */
134 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -0700135
Jon Miranda3f9bab22017-07-28 14:50:17 -0700136 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700137 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda80dda302021-07-28 14:14:59 -0700138 private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252;
139 private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700140
Sunny Goyalc6205602015-05-21 20:46:33 -0700141 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +0100142 public final int desiredWorkspaceHorizontalMarginOriginalPx;
143 public int desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100144 public int gridVisualizationPaddingX;
145 public int gridVisualizationPaddingY;
Thales Lima78d00ad2021-09-30 11:29:06 +0100146 public Point cellLayoutBorderSpaceOriginalPx;
147 public Point cellLayoutBorderSpacePx;
Pat Manning08610ca2022-04-05 21:03:16 +0100148 public Rect cellLayoutPaddingPx = new Rect();
149
Sunny Goyalc6205602015-05-21 20:46:33 -0700150 public final int edgeMarginPx;
Alex Chau0c4e11b2022-07-08 18:41:36 +0100151 public final float workspaceContentScale;
Alex Chau906d8822022-05-23 10:42:25 +0100152 public final int workspaceSpringLoadedMinNextPageVisiblePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700153
Jon Miranda58561d42021-03-17 10:51:54 -0400154 private final int extraSpace;
Thales Lima171ee662022-11-22 15:52:49 +0000155 private int maxEmptySpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500156 public int workspaceTopPadding;
157 public int workspaceBottomPadding;
158
Tony Wickham5edf9e22020-03-27 20:06:52 -0700159 // Workspace page indicator
160 public final int workspacePageIndicatorHeight;
161 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700162
Sunny Goyalc6205602015-05-21 20:46:33 -0700163 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400164 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700165 public int iconSizePx;
166 public int iconTextSizePx;
167 public int iconDrawablePaddingPx;
Thales Lima93ee8fc2023-06-05 17:07:11 +0100168 private final int mIconDrawablePaddingOriginalPx;
Thales Lima79456492023-05-23 11:32:22 +0100169 public boolean iconCenterVertically;
Winson Chungb3800242013-10-24 11:01:54 -0700170
Jon Mirandaab3c6812021-06-28 15:42:28 -0700171 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800172 public int cellWidthPx;
173 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700174 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800175
Thales Lima79456492023-05-23 11:32:22 +0100176 public int cellYPaddingPx = -1;
Jon Mirandae126d722021-02-25 10:45:20 -0500177
Sunny Goyalc6205602015-05-21 20:46:33 -0700178 // Folder
Thales Lima07c6b8d2023-11-08 18:22:38 +0000179 public final int numFolderRows;
180 public final int numFolderColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500181 public float folderLabelTextScale;
182 public int folderLabelTextSizePx;
Thales Limab35faed2022-09-05 16:30:01 -0300183 public int folderFooterHeightPx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700184 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700185 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700186
Jon Mirandae126d722021-02-25 10:45:20 -0500187 // Folder content
Jordan Silva637f4eb2023-06-13 11:21:53 +0100188 public Point folderCellLayoutBorderSpacePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500189 public int folderContentPaddingLeftRight;
190 public int folderContentPaddingTop;
191
Jon Mirandabf7d8122016-11-03 15:29:29 -0700192 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700193 public int folderCellWidthPx;
194 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700195
196 // Folder child
197 public int folderChildIconSizePx;
198 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700199 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700200
Sunny Goyalc6205602015-05-21 20:46:33 -0700201 // Hotseat
Thales Lima9938c2f2022-07-25 14:38:16 +0100202 public int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700203 public int hotseatCellHeightPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100204 public final boolean areNavButtonsInline;
Jon Miranda18751b62017-07-31 17:25:27 -0700205 // In portrait: size = height, in landscape: size = width
206 public int hotseatBarSizePx;
Thales Limab8c05952022-05-23 16:58:38 +0100207 public int hotseatBarBottomSpacePx;
Pat Manning26f70f72022-07-07 13:50:39 +0100208 public int hotseatBarEndOffset;
Thales Limab8c05952022-05-23 16:58:38 +0100209 public int hotseatQsbSpace;
Pat Manningde25c0d2022-04-05 19:11:26 +0100210 public int springLoadedHotseatBarTopMarginPx;
Thales Lima8e11d532023-08-31 13:40:26 +0000211 // These 2 values are only used for isVerticalBar
212 // Padding between edge of screen and hotseat
213 public final int mHotseatBarEdgePaddingPx;
214 // Space between hotseat and workspace (not used in responsive)
215 public final int mHotseatBarWorkspaceSpacePx;
Alex Chau206ede92022-08-01 17:46:12 +0100216 public int hotseatQsbWidth; // only used when isQsbInline
Sunny Goyal57b22792021-05-25 14:35:01 -0700217 public final int hotseatQsbHeight;
Thales Limab8c05952022-05-23 16:58:38 +0100218 public final int hotseatQsbVisualHeight;
219 private final int hotseatQsbShadowHeight;
Thales Limadd027342022-01-07 12:54:37 +0000220 public int hotseatBorderSpace;
Thales Limaffc68b02023-01-09 16:20:23 +0000221 private final int mMinHotseatIconSpacePx;
222 private final int mMinHotseatQsbWidthPx;
223 private final int mMaxHotseatIconSpacePx;
Jon Mirandae17a9492023-03-08 16:42:20 -0800224 public final int inlineNavButtonsEndSpacingPx;
Liran Binyamina833af32023-08-02 16:30:27 -0400225 // Space required for the bubble bar between the hotseat and the edge of the screen. If there's
226 // not enough space, the hotseat will adjust itself for the bubble bar.
227 private final int mBubbleBarSpaceThresholdPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700228
Alex Chau3d2c0622022-09-01 21:28:14 +0100229 // Bottom sheets
230 public int bottomSheetTopPadding;
231 public int bottomSheetOpenDuration;
232 public int bottomSheetCloseDuration;
233 public float bottomSheetWorkspaceScale;
234 public float bottomSheetDepth;
235
Sunny Goyalc6205602015-05-21 20:46:33 -0700236 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000237 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000238 public int allAppsShiftRange;
Thales Limab433c9c2023-10-30 12:24:05 +0000239 public Rect allAppsPadding = new Rect();
Alex Chau3d2c0622022-09-01 21:28:14 +0100240 public int allAppsOpenDuration;
241 public int allAppsCloseDuration;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700242 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700243 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700244 public int allAppsIconSizePx;
245 public int allAppsIconDrawablePaddingPx;
Alex Chau27b39b92022-01-14 18:02:18 +0000246 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700247 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700248 public float allAppsIconTextSizePx;
249
Zak Cohen334efeb2021-03-19 16:42:07 -0700250 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700251 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000252 public int overviewTaskIconSizePx;
Alex Chauac9df382021-08-02 19:08:41 +0100253 public int overviewTaskIconDrawableSizePx;
254 public int overviewTaskIconDrawableSizeGridPx;
Pat Manning1695cc72023-07-05 11:45:13 +0100255 public int overviewTaskIconAppChipMenuDrawableSizePx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000256 public int overviewTaskThumbnailTopMarginPx;
Alex Chau19c6eca2022-03-10 20:12:56 +0000257 public final int overviewActionsHeight;
Alex Chaua2fc7642022-04-21 14:20:23 +0100258 public final int overviewActionsTopMarginPx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000259 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100260 public int overviewPageSpacing;
261 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000262 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700263
Jeremy Sim0ac47082022-10-10 13:59:40 -0700264 // Split staging
265 public int splitPlaceholderInset;
266
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800267 // Widgets
Sihua Mae04aa202022-07-18 12:43:56 -0700268 private final ViewScaleProvider mViewScaleProvider;
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800269
Sunny Goyal47328fd2016-05-25 18:56:41 -0700270 // Drop Target
271 public int dropTargetBarSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100272 public int dropTargetBarTopMarginPx;
273 public int dropTargetBarBottomMarginPx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100274 public int dropTargetDragPaddingPx;
275 public int dropTargetTextSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100276 public int dropTargetHorizontalPaddingPx;
277 public int dropTargetVerticalPaddingPx;
278 public int dropTargetGapPx;
Alex Chau5b019302022-05-23 10:42:25 +0100279 public int dropTargetButtonWorkspaceEdgeGapPx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700280
Winson1f064272016-07-18 17:18:02 -0700281 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800282 private final Rect mInsets = new Rect();
283 public final Rect workspacePadding = new Rect();
Sunny Goyal6c304b12023-04-10 12:03:04 -0700284 // Additional padding added to the widget inside its cellSpace. It is applied outside
285 // the widgetView, such that the actual view size is same as the widget size.
286 public final Rect widgetPadding = new Rect();
287
Jon Miranda0bd63d12019-03-06 17:29:29 -0800288 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700289 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700290
Tony Wickhamf34bee82018-12-03 18:11:39 -0800291 // Notification dots
Sunny Goyal65190ae2022-08-02 14:16:26 -0700292 public final DotRenderer mDotRendererWorkSpace;
293 public final DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800294
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100295 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800296 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000297 // Whether Taskbar will inset the bottom of apps by taskbarSize.
298 public boolean isTaskbarPresentInApps;
Jon Miranda9c478b62023-03-23 21:38:49 -0700299 public final int taskbarHeight;
300 public final int stashedTaskbarHeight;
301 public final int taskbarBottomMargin;
302 public final int taskbarIconSize;
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000303 private final int mTransientTaskbarClaimedSpace;
Jon Miranda04f05102023-04-04 12:16:31 -0700304 // If true, used to layout taskbar in 3 button navigation mode.
305 public final boolean startAlignTaskbar;
Thales Limae9566402023-08-30 16:35:12 +0100306 public final boolean isTransientTaskbar;
Alex Chaua02eddc2021-04-29 00:36:06 +0100307 // DragController
308 public int flingToDeleteThresholdVelocity;
309
Vinit Nayak17c4b332021-08-05 12:54:58 -0700310 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700311 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal65190ae2022-08-02 14:16:26 -0700312 SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
Alex Chauab800f72022-12-13 17:46:06 +0000313 boolean transposeLayoutWithOrientation, boolean isMultiDisplay, boolean isGestureMode,
Jon Miranda2b25ded2023-02-02 14:48:45 -0800314 @NonNull final ViewScaleProvider viewScaleProvider,
Jagrut Desai3a7d1392023-09-06 15:56:19 -0700315 @NonNull final Consumer<DeviceProfile> dimensionOverrideProvider,
316 boolean isTransientTaskbar) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700317
Adam Cohen2e6da152015-05-06 11:42:25 -0700318 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700319 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800320 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500321 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +0000322 this.isMultiDisplay = isMultiDisplay;
Alex Chau6ed408f2022-03-04 12:58:05 +0000323 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700324 windowX = windowBounds.bounds.left;
325 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800326 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100327 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700328
Thales Limac98b7812023-04-14 15:04:23 +0100329 // TODO(b/241386436): shouldn't change any launcher behaviour
Thales Limaabfe3642023-05-24 18:08:53 +0100330 mIsResponsiveGrid = inv.workspaceSpecsId != INVALID_RESOURCE_HANDLE
Jordan Silva637f4eb2023-06-13 11:21:53 +0100331 && inv.allAppsSpecsId != INVALID_RESOURCE_HANDLE
Thales Limaf8bfb032023-07-24 15:08:05 +0100332 && inv.folderSpecsId != INVALID_RESOURCE_HANDLE
333 && inv.hotseatSpecsId != INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100334
Thales Lima79456492023-05-23 11:32:22 +0100335 mIsScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000336 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700337 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000338 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700339 isPhone = !isTablet;
Alex Chauab800f72022-12-13 17:46:06 +0000340 isTwoPanels = isTablet && isMultiDisplay;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800341 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700342
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000343 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000344 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700345 ? Configuration.ORIENTATION_LANDSCAPE
346 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000347 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700348 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000349 mMetrics = res.getDisplayMetrics();
350
Thales Lima2759aa32023-06-05 16:25:45 +0100351 mIconSizeSteps = mIsResponsiveGrid ? new IconSizeSteps(res) : null;
352
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000353 // Determine sizes.
354 widthPx = windowBounds.bounds.width();
355 heightPx = windowBounds.bounds.height();
356 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100357 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000358
359 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Thales Lima83bedbf2021-10-05 17:47:39 +0100360 if (isTwoPanels) {
361 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000362 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100363 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000364 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100365 }
366 } else {
367 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000368 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100369 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000370 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100371 }
372 }
373
Jagrut Desai3a7d1392023-09-06 15:56:19 -0700374 this.isTransientTaskbar = isTransientTaskbar;
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000375 int transientTaskbarIconSize = pxFromDp(inv.transientTaskbarIconSize[mTypeIndex], mMetrics);
376 int transientTaskbarBottomMargin =
377 res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin);
378 int transientTaskbarHeight =
379 Math.round((transientTaskbarIconSize * ICON_VISIBLE_AREA_FACTOR)
Jordan Silvaf2402e22023-10-26 19:53:16 +0100380 + (2 * res.getDimensionPixelSize(R.dimen.transient_taskbar_padding)));
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000381 mTransientTaskbarClaimedSpace = transientTaskbarHeight + 2 * transientTaskbarBottomMargin;
382
Uwais Ashraf3602d172023-09-15 11:36:32 +0000383 if (!isTaskbarPresent) {
384 taskbarIconSize = taskbarHeight = stashedTaskbarHeight = taskbarBottomMargin = 0;
385 startAlignTaskbar = false;
386 } else if (isTransientTaskbar) {
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000387 taskbarIconSize = transientTaskbarIconSize;
388 taskbarHeight = transientTaskbarHeight;
Jon Miranda9c478b62023-03-23 21:38:49 -0700389 stashedTaskbarHeight =
390 res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_height);
Uwais Ashrafaa7fa882023-10-10 21:36:06 +0000391 taskbarBottomMargin = transientTaskbarBottomMargin;
Jon Miranda04f05102023-04-04 12:16:31 -0700392 startAlignTaskbar = false;
Jon Miranda9c478b62023-03-23 21:38:49 -0700393 } else {
394 taskbarIconSize = pxFromDp(ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size),
395 mMetrics);
396 taskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_size);
397 stashedTaskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
398 taskbarBottomMargin = 0;
Jon Miranda04f05102023-04-04 12:16:31 -0700399 startAlignTaskbar = inv.startAlignTaskbar[mTypeIndex];
Tony Wickham15883892021-02-12 11:24:40 -0800400 }
Tony Wickham15883892021-02-12 11:24:40 -0800401
Winson Chungb3800242013-10-24 11:01:54 -0700402 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100403 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700404
Alex Chau51da2192022-05-20 13:32:10 +0100405 gridVisualizationPaddingX = res.getDimensionPixelSize(
406 R.dimen.grid_visualization_horizontal_cell_spacing);
407 gridVisualizationPaddingY = res.getDimensionPixelSize(
408 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500409
Alex Chaue0227552022-04-06 19:44:43 +0100410 bottomSheetTopPadding = mInsets.top // statusbar height
Andras Kloczl142b0542022-03-09 21:26:02 +0000411 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
412 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
Alex Chau3d2c0622022-09-01 21:28:14 +0100413 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
414 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
415 if (isTablet) {
416 bottomSheetWorkspaceScale = workspaceContentScale;
Alex Chauab800f72022-12-13 17:46:06 +0000417 if (isMultiDisplay && !ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH.get()) {
418 // TODO(b/259893832): Revert to use maxWallpaperScale to calculate bottomSheetDepth
419 // when screen recorder bug is fixed.
420 bottomSheetDepth = 1f;
421 } else {
422 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
423 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
424 // When depth is 1, wallpaper zoom is set to 1.
425 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
426 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
427 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
428 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
429 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100430 } else {
431 bottomSheetWorkspaceScale = 1f;
432 bottomSheetDepth = 0f;
433 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000434
Jon Mirandae126d722021-02-25 10:45:20 -0500435 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
Thales Lima07c6b8d2023-11-08 18:22:38 +0000436 numFolderRows = inv.numFolderRows;
437 numFolderColumns = inv.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300438
Thales Lima79456492023-05-23 11:32:22 +0100439 if (mIsScalableGrid && inv.folderStyle != INVALID_RESOURCE_HANDLE) {
Thales Limab35faed2022-09-05 16:30:01 -0300440 TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
Thales Limad852d652023-01-17 14:01:13 +0000441 R.styleable.FolderStyle);
Thales Limab35faed2022-09-05 16:30:01 -0300442 // These are re-set in #updateFolderCellSize if the grid is not scalable
443 folderCellHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000444 R.styleable.FolderStyle_folderCellHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300445 folderCellWidthPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000446 R.styleable.FolderStyle_folderCellWidth, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300447
448 folderContentPaddingTop = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000449 R.styleable.FolderStyle_folderTopPadding, 0);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100450
451 int gutter = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000452 R.styleable.FolderStyle_folderBorderSpace, 0);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100453 folderCellLayoutBorderSpacePx = new Point(gutter, gutter);
Thales Limab35faed2022-09-05 16:30:01 -0300454 folderFooterHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000455 R.styleable.FolderStyle_folderFooterHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300456 folderStyle.recycle();
Jordan Silva637f4eb2023-06-13 11:21:53 +0100457 } else if (!mIsResponsiveGrid) {
458 folderCellLayoutBorderSpacePx = new Point(0, 0);
Thales Lima7eee74b2023-03-16 16:00:55 -0300459 folderFooterHeightPx = res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Thales Limab35faed2022-09-05 16:30:01 -0300460 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
461 }
Jon Mirandae126d722021-02-25 10:45:20 -0500462
Thales Lima85c942f2021-12-31 13:04:20 +0000463 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000464 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
465 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Thales Limae9273ea2023-01-26 12:33:52 +0000466 setupAllAppsStyle(context);
Jon Mirandae126d722021-02-25 10:45:20 -0500467
Tony Wickham5edf9e22020-03-27 20:06:52 -0700468 workspacePageIndicatorHeight = res.getDimensionPixelSize(
469 R.dimen.workspace_page_indicator_height);
470 mWorkspacePageIndicatorOverlapWorkspace =
471 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700472
Thales Limad852d652023-01-17 14:01:13 +0000473 TypedArray cellStyle;
474 if (inv.cellStyle != INVALID_RESOURCE_HANDLE) {
475 cellStyle = context.obtainStyledAttributes(inv.cellStyle,
476 R.styleable.CellStyle);
477 } else {
478 cellStyle = context.obtainStyledAttributes(R.style.CellStyleDefault,
479 R.styleable.CellStyle);
480 }
Thales Lima93ee8fc2023-06-05 17:07:11 +0100481 mIconDrawablePaddingOriginalPx = cellStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000482 R.styleable.CellStyle_iconDrawablePadding, 0);
483 cellStyle.recycle();
Alex Chaua02eddc2021-04-29 00:36:06 +0100484
Sunny Goyal47328fd2016-05-25 18:56:41 -0700485 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100486 dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
487 dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100488 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
489 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100490 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
491 R.dimen.drop_target_button_drawable_horizontal_padding);
492 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
493 R.dimen.drop_target_button_drawable_vertical_padding);
494 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100495 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
496 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100497
Alex Chau906d8822022-05-23 10:42:25 +0100498 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
499 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700500
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700501 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700502
Thales Limaa1012902022-01-13 17:58:42 +0000503 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100504 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
505 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
506
Thales Lima12d0eff2022-03-25 17:06:11 +0000507 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
508 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
509 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
510 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
511 && hotseatQsbHeight > 0;
Thales Lima79456492023-05-23 11:32:22 +0100512 isQsbInline = mIsScalableGrid && inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000513
Thales Lima425f6822022-05-10 13:44:58 -0300514 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100515 numShownHotseatIcons =
516 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000517
Sunny Goyal19ff7282021-04-22 10:12:54 -0700518 numShownAllAppsColumns =
519 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100520
Thales Lima8e11d532023-08-31 13:40:26 +0000521 int hotseatBarBottomSpace;
Thales Limab8c05952022-05-23 16:58:38 +0100522 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
Thales Limaf8bfb032023-07-24 15:08:05 +0100523
524 if (mIsResponsiveGrid) {
Jordan Silvaf2402e22023-10-26 19:53:16 +0100525 float responsiveAspectRatio = (float) widthPx / heightPx;
526 HotseatSpecsProvider hotseatSpecsProvider =
527 HotseatSpecsProvider.create(new ResourceHelper(context,
Thales Limaf8bfb032023-07-24 15:08:05 +0100528 isTwoPanels ? inv.hotseatSpecsTwoPanelId : inv.hotseatSpecsId));
Thales Lima8e11d532023-08-31 13:40:26 +0000529 mResponsiveHotseatSpec =
Jordan Silvaf2402e22023-10-26 19:53:16 +0100530 isVerticalBarLayout() ? hotseatSpecsProvider.getCalculatedSpec(
531 responsiveAspectRatio, DimensionType.WIDTH, widthPx)
532 : hotseatSpecsProvider.getCalculatedSpec(responsiveAspectRatio,
533 DimensionType.HEIGHT, heightPx);
Thales Limaf8bfb032023-07-24 15:08:05 +0100534 hotseatQsbSpace = mResponsiveHotseatSpec.getHotseatQsbSpace();
Thales Lima8e11d532023-08-31 13:40:26 +0000535 hotseatBarBottomSpace =
536 isVerticalBarLayout() ? 0 : mResponsiveHotseatSpec.getEdgePadding();
537 mHotseatBarEdgePaddingPx =
538 isVerticalBarLayout() ? mResponsiveHotseatSpec.getEdgePadding() : 0;
539 mHotseatBarWorkspaceSpacePx = 0;
Thales Limaf8bfb032023-07-24 15:08:05 +0100540 } else {
541 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
Thales Lima8e11d532023-08-31 13:40:26 +0000542 hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
543 mHotseatBarEdgePaddingPx =
544 isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
545 mHotseatBarWorkspaceSpacePx =
546 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Thales Limaf8bfb032023-07-24 15:08:05 +0100547 }
548
Thales Lima8e11d532023-08-31 13:40:26 +0000549 if (!isVerticalBarLayout()) {
550 // Have a little space between the inset and the QSB
551 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
552 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
Thales Limab8c05952022-05-23 16:58:38 +0100553
Thales Lima8e11d532023-08-31 13:40:26 +0000554 // Only change the spaces if there is space
555 if (availableSpace > 0) {
556 // Make sure there is enough space between hotseat/QSB and QSB/navBar
557 if (availableSpace < minQsbMargin * 2) {
558 minQsbMargin = availableSpace / 2;
559 hotseatQsbSpace = minQsbMargin;
560 } else {
561 hotseatQsbSpace -= minQsbMargin;
562 }
Thales Limab8c05952022-05-23 16:58:38 +0100563 }
Thales Lima8e11d532023-08-31 13:40:26 +0000564 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
Thales Limab8c05952022-05-23 16:58:38 +0100565
Thales Lima8e11d532023-08-31 13:40:26 +0000566 } else {
567 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
568 }
Thales Limaa1012902022-01-13 17:58:42 +0000569 }
Thales Lima425f6822022-05-10 13:44:58 -0300570
Pat Manningde25c0d2022-04-05 19:11:26 +0100571 springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
572 R.dimen.spring_loaded_hotseat_top_margin);
Thales Lima8e11d532023-08-31 13:40:26 +0000573 updateHotseatSizes(pxFromDp(inv.iconSize[mTypeIndex], mMetrics));
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700574 if (areNavButtonsInline && !isPhone) {
Jon Mirandae17a9492023-03-08 16:42:20 -0800575 inlineNavButtonsEndSpacingPx =
Thales Limaffc68b02023-01-09 16:20:23 +0000576 res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing);
Pat Manning26f70f72022-07-07 13:50:39 +0100577 /*
578 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700579 * Spacing between nav buttons +
Thales Lima6a590062022-11-22 15:52:49 +0000580 * Space at the end for contextual buttons
Pat Manning26f70f72022-07-07 13:50:39 +0100581 */
582 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700583 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
Jon Mirandae17a9492023-03-08 16:42:20 -0800584 + inlineNavButtonsEndSpacingPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100585 } else {
Jon Mirandae17a9492023-03-08 16:42:20 -0800586 inlineNavButtonsEndSpacingPx = 0;
Pat Manning26f70f72022-07-07 13:50:39 +0100587 hotseatBarEndOffset = 0;
588 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700589
Liran Binyamina833af32023-08-02 16:30:27 -0400590 mBubbleBarSpaceThresholdPx =
591 res.getDimensionPixelSize(R.dimen.bubblebar_hotseat_adjustment_threshold);
592
Thales Lima79456492023-05-23 11:32:22 +0100593 // Needs to be calculated after hotseatBarSizePx is correct,
594 // for the available height to be correct
595 if (mIsResponsiveGrid) {
Thales Lima2759aa32023-06-05 16:25:45 +0100596 int availableResponsiveWidth =
597 availableWidthPx - (isVerticalBarLayout() ? hotseatBarSizePx : 0);
Jordan Silva376036a2023-11-08 15:56:40 +0000598 int numWorkspaceColumns = getPanelCount() * inv.numColumns;
Thales Lima8e11d532023-08-31 13:40:26 +0000599 // don't use availableHeightPx because it subtracts mInsets.bottom
600 int availableResponsiveHeight = heightPx - mInsets.top
Jordan Silvaf2402e22023-10-26 19:53:16 +0100601 - (isVerticalBarLayout() ? 0 : hotseatBarSizePx);
602 float responsiveAspectRatio = (float) widthPx / heightPx;
Thales Limaabfe3642023-05-24 18:08:53 +0100603
Jordan Silvaf2402e22023-10-26 19:53:16 +0100604 ResponsiveSpecsProvider workspaceSpecs = ResponsiveSpecsProvider.create(
Jordan Silva575c3bd2023-07-21 12:00:43 +0100605 new ResourceHelper(context,
Jordan Silvaf2402e22023-10-26 19:53:16 +0100606 isTwoPanels ? inv.workspaceSpecsTwoPanelId : inv.workspaceSpecsId),
607 ResponsiveSpecType.Workspace);
Jordan Silva8f7986a2023-11-08 12:11:25 +0000608 mResponsiveWorkspaceWidthSpec = workspaceSpecs.getCalculatedSpec(responsiveAspectRatio,
Jordan Silva376036a2023-11-08 15:56:40 +0000609 DimensionType.WIDTH, numWorkspaceColumns, availableResponsiveWidth);
Jordan Silva8f7986a2023-11-08 12:11:25 +0000610 mResponsiveWorkspaceHeightSpec = workspaceSpecs.getCalculatedSpec(responsiveAspectRatio,
Jordan Silvaf2402e22023-10-26 19:53:16 +0100611 DimensionType.HEIGHT, inv.numRows, availableResponsiveHeight);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100612
Jordan Silvaf2402e22023-10-26 19:53:16 +0100613 ResponsiveSpecsProvider allAppsSpecs = ResponsiveSpecsProvider.create(
Jordan Silva575c3bd2023-07-21 12:00:43 +0100614 new ResourceHelper(context,
Jordan Silvaf2402e22023-10-26 19:53:16 +0100615 isTwoPanels ? inv.allAppsSpecsTwoPanelId : inv.allAppsSpecsId),
616 ResponsiveSpecType.AllApps);
Jordan Silva8f7986a2023-11-08 12:11:25 +0000617 mResponsiveAllAppsWidthSpec = allAppsSpecs.getCalculatedSpec(responsiveAspectRatio,
Jordan Silva8b3fa142023-11-13 21:31:38 +0000618 DimensionType.WIDTH, numShownAllAppsColumns, availableWidthPx,
Jordan Silva8f7986a2023-11-08 12:11:25 +0000619 mResponsiveWorkspaceWidthSpec);
620 mResponsiveAllAppsHeightSpec = allAppsSpecs.getCalculatedSpec(responsiveAspectRatio,
Thales Limaa25cd902023-11-01 12:00:32 +0000621 DimensionType.HEIGHT, inv.numRows, heightPx - mInsets.top,
Jordan Silva8f7986a2023-11-08 12:11:25 +0000622 mResponsiveWorkspaceHeightSpec);
Jordan Silvaf2402e22023-10-26 19:53:16 +0100623
624 ResponsiveSpecsProvider folderSpecs = ResponsiveSpecsProvider.create(
625 new ResourceHelper(context,
626 isTwoPanels ? inv.folderSpecsTwoPanelId : inv.folderSpecsId),
627 ResponsiveSpecType.Folder);
628 mResponsiveFolderWidthSpec = folderSpecs.getCalculatedSpec(responsiveAspectRatio,
Thales Lima07c6b8d2023-11-08 18:22:38 +0000629 DimensionType.WIDTH, numFolderColumns,
Jordan Silva8f7986a2023-11-08 12:11:25 +0000630 mResponsiveWorkspaceWidthSpec.getAvailableSpace(),
631 mResponsiveWorkspaceWidthSpec);
Jordan Silvaf2402e22023-10-26 19:53:16 +0100632 mResponsiveFolderHeightSpec = folderSpecs.getCalculatedSpec(responsiveAspectRatio,
Thales Lima07c6b8d2023-11-08 18:22:38 +0000633 DimensionType.HEIGHT, numFolderRows,
Jordan Silva8f7986a2023-11-08 12:11:25 +0000634 mResponsiveWorkspaceHeightSpec.getAvailableSpace(),
635 mResponsiveWorkspaceHeightSpec);
Thales Lima79456492023-05-23 11:32:22 +0100636 }
637
638 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
639 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
640
Alex Chau635b3ab2022-01-26 16:49:10 +0000641 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Pat Manning1695cc72023-07-05 11:45:13 +0100642 overviewTaskIconSizePx = enableOverviewIconMenu() ? res.getDimensionPixelSize(
643 R.dimen.task_thumbnail_icon_menu_drawable_touch_size) : res.getDimensionPixelSize(
644 R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100645 overviewTaskIconDrawableSizePx =
646 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
647 overviewTaskIconDrawableSizeGridPx =
648 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Pat Manning1695cc72023-07-05 11:45:13 +0100649 overviewTaskIconAppChipMenuDrawableSizePx = res.getDimensionPixelSize(
650 R.dimen.task_thumbnail_icon_menu_drawable_size);
651 overviewTaskThumbnailTopMarginPx =
652 enableOverviewIconMenu() ? 0 : overviewTaskIconSizePx + overviewTaskMarginPx;
Andy Wickhambc3bac42023-08-07 16:02:23 -0700653 // Don't add margin with floating search bar to minimize risk of overlapping.
654 overviewActionsTopMarginPx = FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get() ? 0
655 : res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000656 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
657 overviewActionsButtonSpacing = res.getDimensionPixelSize(
658 R.dimen.overview_actions_button_spacing);
Andy Wickhambc3bac42023-08-07 16:02:23 -0700659 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700660 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000661 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700662
Jeremy Sim0ac47082022-10-10 13:59:40 -0700663 splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset);
664
Jon Miranda2ed276e2017-06-29 11:36:34 -0700665 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400666 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700667
Thales Lima79456492023-05-23 11:32:22 +0100668 calculateAndSetWorkspaceVerticalPadding(context, inv, extraSpace);
Pat Manning08610ca2022-04-05 21:03:16 +0100669
670 int cellLayoutPadding =
671 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
672 R.dimen.cell_layout_padding);
673 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
674 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800675 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800676
Thales Lima7eee74b2023-03-16 16:00:55 -0300677 // Folder scaling requires correct workspace paddings
678 updateAvailableFolderCellDimensions(res);
679
Thales Limaffc68b02023-01-09 16:20:23 +0000680 mMinHotseatIconSpacePx = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
681 mMinHotseatQsbWidthPx = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
682 mMaxHotseatIconSpacePx = areNavButtonsInline
Thales Lima6a590062022-11-22 15:52:49 +0000683 ? res.getDimensionPixelSize(R.dimen.max_hotseat_icon_space) : Integer.MAX_VALUE;
Thales Lima425f6822022-05-10 13:44:58 -0300684 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima6a590062022-11-22 15:52:49 +0000685 recalculateHotseatWidthAndBorderSpace();
Alex Chau206ede92022-08-01 17:46:12 +0100686
Jordan Silva3646a1b2023-08-02 13:52:52 +0100687 if (mIsResponsiveGrid && isVerticalBarLayout()) {
688 hotseatBorderSpace = cellLayoutBorderSpacePx.y;
689 }
690
Alex Chau206ede92022-08-01 17:46:12 +0100691 // AllApps height calculation depends on updated cellSize
692 if (isTablet) {
693 int collapseHandleHeight =
694 res.getDimensionPixelOffset(R.dimen.bottom_sheet_handle_area_height);
695 int contentHeight = heightPx - collapseHandleHeight - hotseatQsbHeight;
696 int targetContentHeight = (int) (allAppsCellHeightPx * ALL_APPS_TABLET_MAX_ROWS);
Thales Limab433c9c2023-10-30 12:24:05 +0000697 allAppsPadding.top = Math.max(mInsets.top, contentHeight - targetContentHeight);
698 allAppsShiftRange = heightPx - allAppsPadding.top;
Alex Chau206ede92022-08-01 17:46:12 +0100699 } else {
Thales Limab433c9c2023-10-30 12:24:05 +0000700 allAppsPadding.top = 0;
Alex Chau206ede92022-08-01 17:46:12 +0100701 allAppsShiftRange =
702 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
703 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100704 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
705 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300706
Alex Chaua02eddc2021-04-29 00:36:06 +0100707 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
708 R.dimen.drag_flingToDeleteMinVelocity);
709
Sihua Mae04aa202022-07-18 12:43:56 -0700710 mViewScaleProvider = viewScaleProvider;
711
Jon Miranda2b25ded2023-02-02 14:48:45 -0800712 dimensionOverrideProvider.accept(this);
713
Tony Wickham1237df02017-02-24 08:59:36 -0800714 // This is done last, after iconSizePx is calculated above.
Sunny Goyal799e1202023-02-09 10:54:28 -0800715 mDotRendererWorkSpace = createDotRenderer(context, iconSizePx, dotRendererCache);
716 mDotRendererAllApps = createDotRenderer(context, allAppsIconSizePx, dotRendererCache);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700717 }
718
719 private static DotRenderer createDotRenderer(
Sunny Goyal799e1202023-02-09 10:54:28 -0800720 @NonNull Context context, int size, @NonNull SparseArray<DotRenderer> cache) {
Sunny Goyal65190ae2022-08-02 14:16:26 -0700721 DotRenderer renderer = cache.get(size);
722 if (renderer == null) {
Sunny Goyal799e1202023-02-09 10:54:28 -0800723 renderer = new DotRenderer(size, getShapePath(context, DEFAULT_DOT_SIZE),
724 DEFAULT_DOT_SIZE);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700725 cache.put(size, renderer);
726 }
727 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700728 }
729
Thales Lima425f6822022-05-10 13:44:58 -0300730 /**
Fengjiang Li6c590822023-09-25 15:04:57 -0700731 * Return maximum of all apps row count displayed on screen. Note that 1) Partially displayed
732 * row is counted as 1 row, and 2) we don't exclude the space of floating search bar. This
733 * method is used for calculating number of {@link BubbleTextView} we need to pre-inflate. Thus
734 * reasonable over estimation is fine.
735 */
736 public int getMaxAllAppsRowCount() {
Thales Limab433c9c2023-10-30 12:24:05 +0000737 return (int) (Math.ceil((availableHeightPx - allAppsPadding.top)
Fengjiang Li6c590822023-09-25 15:04:57 -0700738 / (float) allAppsCellHeightPx));
739 }
740
741 /**
Thales Lima425f6822022-05-10 13:44:58 -0300742 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
743 * width of the hotseat.
744 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100745 private int calculateQsbWidth(int hotseatBorderSpace) {
Thales Lima425f6822022-05-10 13:44:58 -0300746 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100747 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300748 return getIconToIconWidthForColumns(columns)
749 - iconSizePx * numShownHotseatIcons
750 - hotseatBorderSpace * numShownHotseatIcons;
751 } else {
752 int columns = inv.hotseatColumnSpan[mTypeIndex];
753 return getIconToIconWidthForColumns(columns);
754 }
755 }
Thales Lima2903a622022-03-17 13:52:19 +0000756
Thales Lima425f6822022-05-10 13:44:58 -0300757 private int getIconToIconWidthForColumns(int columns) {
758 return columns * getCellSize().x
759 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400760 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000761 }
762
Thales Limad90faab2021-09-21 17:18:47 +0100763 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
Thales Lima79456492023-05-23 11:32:22 +0100764 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +0000765 return mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
Thales Lima79456492023-05-23 11:32:22 +0100766 }
767
Thales Limad90faab2021-09-21 17:18:47 +0100768 if (isVerticalBarLayout()) {
769 return 0;
770 }
771
Thales Lima79456492023-05-23 11:32:22 +0100772 return mIsScalableGrid
Thales Lima83bedbf2021-10-05 17:47:39 +0100773 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
774 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100775 }
776
Thales Lima79456492023-05-23 11:32:22 +0100777 private void calculateAndSetWorkspaceVerticalPadding(Context context,
778 InvariantDeviceProfile inv,
779 int extraSpace) {
780 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +0000781 workspaceTopPadding = mResponsiveWorkspaceHeightSpec.getStartPaddingPx();
782 workspaceBottomPadding = mResponsiveWorkspaceHeightSpec.getEndPaddingPx();
Thales Lima79456492023-05-23 11:32:22 +0100783 } else if (mIsScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
784 // Paddings were created assuming no scaling, so we first unscale the extra space.
785 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
786 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
787 DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
788 maxEmptySpace = padding.getMaxEmptySpacePx();
789
790 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
791 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
792
793 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
794 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
795 }
796 }
797
Thales Limab8c05952022-05-23 16:58:38 +0100798 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
799 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700800 // Ensure there is enough space for folder icons, which have a slightly larger radius.
Jordan Silva3646a1b2023-08-02 13:52:52 +0100801 hotseatCellHeightPx = getIconSizeWithOverlap(hotseatIconSizePx);
Thales Limab8c05952022-05-23 16:58:38 +0100802
Jon Miranda0d284852021-06-22 14:50:55 -0700803 if (isVerticalBarLayout()) {
Thales Lima8e11d532023-08-31 13:40:26 +0000804 hotseatBarSizePx = hotseatIconSizePx + mHotseatBarEdgePaddingPx
805 + mHotseatBarWorkspaceSpacePx;
Thales Limab8c05952022-05-23 16:58:38 +0100806 } else if (isQsbInline) {
807 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
808 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700809 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100810 hotseatBarSizePx = hotseatIconSizePx
811 + hotseatQsbSpace
812 + hotseatQsbVisualHeight
813 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700814 }
815 }
816
Thales Lima6a590062022-11-22 15:52:49 +0000817 /**
818 * Calculates the width of the hotseat, changing spaces between the icons and removing icons if
819 * necessary.
820 */
821 public void recalculateHotseatWidthAndBorderSpace() {
Thales Lima79456492023-05-23 11:32:22 +0100822 if (!mIsScalableGrid) return;
Thales Lima6a590062022-11-22 15:52:49 +0000823
824 int columns = inv.hotseatColumnSpan[mTypeIndex];
825 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
826 hotseatBorderSpace = calculateHotseatBorderSpace(hotseatWidthPx, /* numExtraBorder= */ 0);
Thales Lima9938c2f2022-07-25 14:38:16 +0100827 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
Thales Lima6a590062022-11-22 15:52:49 +0000828 // Spaces should be correct when the nav buttons are not inline
Thales Lima9938c2f2022-07-25 14:38:16 +0100829 if (!areNavButtonsInline) {
830 return;
831 }
832
Thales Lima6a590062022-11-22 15:52:49 +0000833 // The side space with inline buttons should be what is defined in InvariantDeviceProfile
Jon Mirandae17a9492023-03-08 16:42:20 -0800834 int sideSpacePx = inlineNavButtonsEndSpacingPx;
Thales Limaffc68b02023-01-09 16:20:23 +0000835 int maxHotseatWidthPx = availableWidthPx - sideSpacePx - hotseatBarEndOffset;
836 int maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
837 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000838 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100839
Thales Limaffc68b02023-01-09 16:20:23 +0000840 if (hotseatBorderSpace >= mMinHotseatIconSpacePx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100841 return;
842 }
843
844 // Border space can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000845 hotseatBorderSpace = mMinHotseatIconSpacePx;
Thales Lima6a590062022-11-22 15:52:49 +0000846 int requiredWidth = getHotseatRequiredWidth();
Thales Lima9938c2f2022-07-25 14:38:16 +0100847
848 // If there is an inline qsb, change its size
849 if (isQsbInline) {
Thales Limaffc68b02023-01-09 16:20:23 +0000850 hotseatQsbWidth -= requiredWidth - maxHotseatWidthPx;
851 if (hotseatQsbWidth >= mMinHotseatQsbWidthPx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100852 return;
853 }
854
855 // QSB can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000856 hotseatQsbWidth = mMinHotseatQsbWidthPx;
Thales Lima9938c2f2022-07-25 14:38:16 +0100857 }
858
Thales Limaffc68b02023-01-09 16:20:23 +0000859 maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
Thales Lima6a590062022-11-22 15:52:49 +0000860
Thales Lima9938c2f2022-07-25 14:38:16 +0100861 // If it still doesn't fit, start removing icons
862 do {
863 numShownHotseatIcons--;
Thales Limaffc68b02023-01-09 16:20:23 +0000864 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000865 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Limaffc68b02023-01-09 16:20:23 +0000866 } while (hotseatBorderSpace < mMinHotseatIconSpacePx && numShownHotseatIcons > 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100867 }
868
Thales Lima78d00ad2021-09-30 11:29:06 +0100869 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100870 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100871 }
872
873 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima79456492023-05-23 11:32:22 +0100874 int horizontalSpacePx = 0;
875 int verticalSpacePx = 0;
Thales Lima78d00ad2021-09-30 11:29:06 +0100876
Thales Lima79456492023-05-23 11:32:22 +0100877 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +0000878 horizontalSpacePx = mResponsiveWorkspaceWidthSpec.getGutterPx();
879 verticalSpacePx = mResponsiveWorkspaceHeightSpec.getGutterPx();
Thales Lima79456492023-05-23 11:32:22 +0100880 } else if (mIsScalableGrid) {
881 horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
882 verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
883 }
Thales Lima78d00ad2021-09-30 11:29:06 +0100884
885 return new Point(horizontalSpacePx, verticalSpacePx);
886 }
887
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700888 public Info getDisplayInfo() {
889 return mInfo;
890 }
891
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700892 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800893 WindowBounds bounds = new WindowBounds(
894 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700895 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100896 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700897
898 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
899 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
900 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
901
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700902 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700903 .setWindowBounds(bounds)
Alex Chauab800f72022-12-13 17:46:06 +0000904 .setIsMultiDisplay(isMultiDisplay)
Alex Chau6ed408f2022-03-04 12:58:05 +0000905 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700906 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000907 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800908 }
909
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700910 public DeviceProfile copy(Context context) {
911 return toBuilder(context).build();
912 }
913
914 /**
915 * TODO: Move this to the builder as part of setMultiWindowMode
916 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700917 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700918 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700919 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700920 .setMultiWindowMode(true)
921 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800922
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800923 // We use these scales to measure and layout the widgets using their full invariant profile
924 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
925 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
926 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700927 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
928 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
929 profile = profile.toBuilder(context)
930 .setViewScaleProvider(i -> p)
931 .build();
932 }
933
934 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800935
Jon Miranda93e1f042016-11-11 14:13:04 -0800936 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700937 }
938
Adam Cohen63f1ec02014-08-12 09:23:13 -0700939 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400940 * Checks if there is enough space for labels on the workspace.
941 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700942 * It is important to call this method after the All Apps variables have been set.
943 */
Jon Miranda941375e2021-03-31 13:10:45 -0400944 private void hideWorkspaceLabelsIfNotEnoughSpace() {
945 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
946 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
947 - iconTextHeight;
948
Jordan Silva3646a1b2023-08-02 13:52:52 +0100949 if (mIsResponsiveGrid) {
Thales Limabba07722023-10-11 18:16:29 +0000950 iconTextSizePx = 0;
951 iconDrawablePaddingPx = 0;
952 int iconSizeWithOverlap = getIconSizeWithOverlap(iconSizePx);
953 cellYPaddingPx = Math.max(0, getCellSize().y - iconSizeWithOverlap) / 2;
954 autoResizeAllAppsCells();
Jordan Silva3646a1b2023-08-02 13:52:52 +0100955
956 return;
957 }
958
Jon Miranda941375e2021-03-31 13:10:45 -0400959 // We want enough space so that the text is closer to its corresponding icon.
960 if (workspaceCellPaddingY < iconTextHeight) {
961 iconTextSizePx = 0;
962 iconDrawablePaddingPx = 0;
Jordan Silva3646a1b2023-08-02 13:52:52 +0100963 cellHeightPx = getIconSizeWithOverlap(iconSizePx);
Jon Miranda941375e2021-03-31 13:10:45 -0400964 autoResizeAllAppsCells();
965 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700966 }
Jon Miranda1091e532017-07-21 13:31:50 -0700967
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700968 /**
Jon Miranda228877d2021-02-09 11:05:00 -0500969 * Returns the amount of extra (or unused) vertical space.
970 */
971 private int updateAvailableDimensions(Resources res) {
Alex Chaua68164d2022-12-15 16:16:03 +0000972 float invIconSizeDp = inv.iconSize[mTypeIndex];
973 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
974 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
975 iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
Thales Lima79456492023-05-23 11:32:22 +0100976 iconCenterVertically = mIsScalableGrid || mIsResponsiveGrid;
Alex Chaua68164d2022-12-15 16:16:03 +0000977
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700978 updateIconSize(1f, res);
Pat Manning08610ca2022-04-05 21:03:16 +0100979 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -0500980
Alex Chau5225e832023-08-01 16:32:15 +0100981 if (mIsResponsiveGrid) {
982 return 0;
983 }
984
Jon Mirandae126d722021-02-25 10:45:20 -0500985 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +0100986 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +0000987 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -0500988 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500989 float scaleY = maxHeight / usedHeight;
990 boolean shouldScale = scaleY < 1f;
991
992 float scaleX = 1f;
Thales Lima79456492023-05-23 11:32:22 +0100993 if (mIsScalableGrid) {
Jon Mirandae126d722021-02-25 10:45:20 -0500994 // We scale to fit the cellWidth and cellHeight in the available space.
995 // The benefit of scalable grids is that we can get consistent aspect ratios between
996 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +0100997 float usedWidth =
998 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500999 // We do not subtract padding here, as we also scale the workspace padding if needed.
1000 scaleX = availableWidthPx / usedWidth;
1001 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -07001002 }
Jon Mirandae126d722021-02-25 10:45:20 -05001003
1004 if (shouldScale) {
1005 float scale = Math.min(scaleX, scaleY);
1006 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +01001007 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -05001008 }
1009
Jon Miranda228877d2021-02-09 11:05:00 -05001010 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -07001011 }
1012
Pat Manninga2e14992022-04-22 11:29:17 +01001013 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +01001014 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
1015 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
1016 }
1017
Pat Manninga2e14992022-04-22 11:29:17 +01001018 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +00001019 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +01001020 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
1021 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -05001022 }
1023
Jordan Silva376036a2023-11-08 15:56:40 +00001024 private int getNormalizedIconDrawablePadding(int iconSizePx, int iconDrawablePadding) {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001025 // TODO(b/235886078): workaround needed because of this bug
1026 // Icons are 10% larger on XML than their visual size,
1027 // so remove that extra space to get labels closer to the correct padding
1028 int iconVisibleSizePx = (int) Math.round(ICON_VISIBLE_AREA_FACTOR * iconSizePx);
Jordan Silva376036a2023-11-08 15:56:40 +00001029 return Math.max(0, iconDrawablePadding - ((iconSizePx - iconVisibleSizePx) / 2));
1030 }
1031
1032 private int getNormalizedIconDrawablePadding() {
1033 return getNormalizedIconDrawablePadding(iconSizePx, mIconDrawablePaddingOriginalPx);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001034 }
1035
1036 private int getNormalizedFolderChildDrawablePaddingPx(int textHeight) {
1037 // TODO(b/235886078): workaround needed because of this bug
1038 // Icons are 10% larger on XML than their visual size,
1039 // so remove that extra space to get labels closer to the correct padding
1040 int drawablePadding = (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3;
1041
1042 int iconVisibleSizePx = Math.round(ICON_VISIBLE_AREA_FACTOR * folderChildIconSizePx);
1043 int iconSizeDiff = folderChildIconSizePx - iconVisibleSizePx;
1044 return Math.max(0, drawablePadding - iconSizeDiff / 2);
1045 }
1046
Jordan Silva3646a1b2023-08-02 13:52:52 +01001047 private int getIconSizeWithOverlap(int iconSize) {
1048 return (int) Math.ceil(iconSize * ICON_OVERLAP_FACTOR);
1049 }
1050
Jon Miranda6f7e9702019-09-16 14:44:14 -07001051 /**
1052 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
1053 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
1054 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
1055 */
Tony Wickham7ba547c2021-02-02 17:12:08 -08001056 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -07001057 // Icon scale should never exceed 1, otherwise pixellation may occur.
1058 iconScale = Math.min(1f, scale);
1059 cellScaleToFit = scale;
1060
Jon Miranda18751b62017-07-31 17:25:27 -07001061 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -08001062 final boolean isVerticalLayout = isVerticalBarLayout();
Thales Lima080d8902022-03-28 15:30:29 +01001063 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -05001064
Thales Lima79456492023-05-23 11:32:22 +01001065 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001066 cellWidthPx = mResponsiveWorkspaceWidthSpec.getCellSizePx();
1067 cellHeightPx = mResponsiveWorkspaceHeightSpec.getCellSizePx();
Thales Lima79456492023-05-23 11:32:22 +01001068
Thales Lima2759aa32023-06-05 16:25:45 +01001069 if (cellWidthPx < iconSizePx) {
1070 // get a smaller icon size
1071 iconSizePx = mIconSizeSteps.getIconSmallerThan(cellWidthPx);
Thales Lima2759aa32023-06-05 16:25:45 +01001072 }
1073
Thales Lima93ee8fc2023-06-05 17:07:11 +01001074 iconDrawablePaddingPx = getNormalizedIconDrawablePadding();
Thales Lima93ee8fc2023-06-05 17:07:11 +01001075
Thales Lima24ceca62023-09-25 16:21:17 -07001076 CellContentDimensions cellContentDimensions = new CellContentDimensions(iconSizePx,
1077 iconDrawablePaddingPx,
1078 iconTextSizePx);
Thales Limabba07722023-10-11 18:16:29 +00001079 if (isVerticalLayout) {
1080 if (cellHeightPx < iconSizePx) {
1081 cellContentDimensions.setIconSizePx(
1082 mIconSizeSteps.getIconSmallerThan(cellHeightPx));
1083 }
Thales Lima24ceca62023-09-25 16:21:17 -07001084 } else {
1085 cellContentDimensions.resizeToFitCellHeight(cellHeightPx, mIconSizeSteps);
Thales Lima2759aa32023-06-05 16:25:45 +01001086 }
Thales Lima24ceca62023-09-25 16:21:17 -07001087 iconSizePx = cellContentDimensions.getIconSizePx();
1088 iconDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1089 iconTextSizePx = cellContentDimensions.getIconTextSizePx();
1090 int cellContentHeight = cellContentDimensions.getCellContentHeight();
Thales Lima2759aa32023-06-05 16:25:45 +01001091
1092 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Lima79456492023-05-23 11:32:22 +01001093 } else if (mIsScalableGrid) {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001094 iconDrawablePaddingPx = (int) (getNormalizedIconDrawablePadding() * iconScale);
Thales Lima83bedbf2021-10-05 17:47:39 +01001095 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
1096 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001097
1098 if (cellWidthPx < iconSizePx) {
1099 // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger.
1100 int numColumns = getPanelCount() * inv.numColumns;
1101 int numBorders = numColumns - 1;
1102 int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns;
1103 if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) {
1104 cellWidthPx = iconSizePx;
1105 cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders;
1106 } else {
1107 // If it still doesn't fit, set borderSpace to 0 and distribute the space for
1108 // cellWidth, and reduce iconSize.
1109 cellWidthPx = (cellWidthPx * numColumns
1110 + cellLayoutBorderSpacePx.x * numBorders) / numColumns;
1111 iconSizePx = Math.min(iconSizePx, cellWidthPx);
1112 cellLayoutBorderSpacePx.x = 0;
1113 }
1114 }
1115
Thales Lima93ee8fc2023-06-05 17:07:11 +01001116 int cellTextAndPaddingHeight =
1117 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +00001118 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
1119 if (cellHeightPx < cellContentHeight) {
1120 // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight
1121 // bigger.
1122 int numBorders = inv.numRows - 1;
1123 int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows;
1124 if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) {
1125 cellHeightPx = cellContentHeight;
1126 cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders;
1127 } else {
Alex Chau06f36e82023-01-06 10:50:54 +00001128 // If it still doesn't fit, set borderSpace to 0 to recover space.
Alex Chaube753132022-12-09 16:46:54 +00001129 cellHeightPx = (cellHeightPx * inv.numRows
1130 + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows;
Alex Chaube753132022-12-09 16:46:54 +00001131 cellLayoutBorderSpacePx.y = 0;
Alex Chau06f36e82023-01-06 10:50:54 +00001132 // Reduce iconDrawablePaddingPx to make cellContentHeight smaller.
1133 int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx;
1134 if (cellContentWithoutPadding <= cellHeightPx) {
1135 iconDrawablePaddingPx = cellContentHeight - cellHeightPx;
1136 } else {
1137 // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space,
1138 // then proportional reduce iconSizePx and iconTextSizePx to fit.
1139 iconDrawablePaddingPx = 0;
1140 float ratio = cellHeightPx / (float) cellContentWithoutPadding;
1141 iconSizePx = (int) (iconSizePx * ratio);
1142 iconTextSizePx = (int) (iconTextSizePx * ratio);
1143 }
1144 cellTextAndPaddingHeight =
1145 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +00001146 }
1147 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
1148 }
Jon Mirandae126d722021-02-25 10:45:20 -05001149 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +01001150 desiredWorkspaceHorizontalMarginPx =
1151 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -05001152 } else {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001153 iconDrawablePaddingPx = (int) (getNormalizedIconDrawablePadding() * iconScale);
Jon Mirandae126d722021-02-25 10:45:20 -05001154 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001155 cellHeightPx = getIconSizeWithOverlap(iconSizePx)
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001156 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -05001157 + Utilities.calculateTextHeight(iconTextSizePx);
1158 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
1159 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
1160 && !isMultiWindowMode) {
1161 // Ensures that the label is closer to its corresponding icon. This is not an issue
1162 // with vertical bar layout or multi-window mode since the issue is handled
1163 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
1164 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
1165 iconDrawablePaddingPx = cellPaddingY;
1166 }
Jon Miranda846455e2017-10-02 14:58:52 -07001167 }
Jon Miranda18751b62017-07-31 17:25:27 -07001168
Sunny Goyalae190ff2020-04-14 00:19:01 +00001169 // All apps
Thales Limaabfe3642023-05-24 18:08:53 +01001170 if (mIsResponsiveGrid) {
Jordan Silva376036a2023-11-08 15:56:40 +00001171 updateAllAppsWithResponsiveMeasures(res);
Thales Limaabfe3642023-05-24 18:08:53 +01001172 } else {
1173 updateAllAppsIconSize(scale, res);
1174 }
1175 updateAllAppsContainerWidth();
1176 if (isVerticalBarLayout()) {
1177 hideWorkspaceLabelsIfNotEnoughSpace();
1178 }
Brandon Dayauon3cdb32c2023-08-22 21:26:37 -07001179 if (FeatureFlags.enableTwolineAllapps()) {
1180 // Add extra textHeight to the existing allAppsCellHeight.
1181 allAppsCellHeightPx += Utilities.calculateTextHeight(allAppsIconTextSizePx);
1182 }
Winson Chungb3800242013-10-24 11:01:54 -07001183
Thales Limab8c05952022-05-23 16:58:38 +01001184 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -07001185
Sunny Goyalbaec6ff2016-09-14 11:26:21 -07001186 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -07001187 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
1188 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Sunny Goyal6c304b12023-04-10 12:03:04 -07001189
1190 // Update widget padding:
1191 float minSpacing = pxFromDp(MIN_WIDGET_PADDING_DP, mMetrics);
1192 if (cellLayoutBorderSpacePx.x < minSpacing
1193 || cellLayoutBorderSpacePx.y < minSpacing) {
1194 widgetPadding.left = widgetPadding.right =
1195 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.x));
1196 widgetPadding.top = widgetPadding.bottom =
1197 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.y));
1198 } else {
1199 widgetPadding.setEmpty();
1200 }
Winson Chung0f785722015-04-08 10:27:49 -07001201 }
1202
Thales Lima425f6822022-05-10 13:44:58 -03001203 /**
Thales Lima6a590062022-11-22 15:52:49 +00001204 * This method calculates the space between the icons to achieve a certain width.
Thales Lima425f6822022-05-10 13:44:58 -03001205 */
Thales Lima6a590062022-11-22 15:52:49 +00001206 private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) {
Jordan Silvad9227182023-08-17 15:53:59 +01001207 int numBorders = (numShownHotseatIcons - 1 + numExtraBorder);
1208 if (numBorders <= 0) return 0;
1209
Thales Lima9938c2f2022-07-25 14:38:16 +01001210 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
Jordan Silvad9227182023-08-17 15:53:59 +01001211 int hotseatBorderSpacePx = (int) (hotseatWidthPx - hotseatIconsTotalPx) / numBorders;
Thales Limaffc68b02023-01-09 16:20:23 +00001212 return Math.min(hotseatBorderSpacePx, mMaxHotseatIconSpacePx);
Thales Lima425f6822022-05-10 13:44:58 -03001213 }
1214
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001215 /**
1216 * Updates the iconSize for allApps* variants.
1217 */
Brian Isganitisa9a78112022-05-23 18:11:47 -07001218 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +01001219 allAppsBorderSpacePx = new Point(
1220 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
1221 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001222 // AllApps cells don't have real space between cells,
1223 // so we add the border space to the cell height
Alex Chaube753132022-12-09 16:46:54 +00001224 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics)
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001225 + allAppsBorderSpacePx.y;
1226 // but width is just the cell,
1227 // the border is added in #updateAllAppsContainerWidth
Thales Lima79456492023-05-23 11:32:22 +01001228 if (mIsScalableGrid) {
Alex Chaube753132022-12-09 16:46:54 +00001229 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1230 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001231 allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding();
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001232 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001233
1234 if (allAppsCellWidthPx < allAppsIconSizePx) {
1235 // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to
1236 // make allAppsCellWidth bigger.
1237 int numBorders = inv.numAllAppsColumns - 1;
1238 int extraWidthRequired =
1239 (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns;
1240 if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) {
1241 allAppsCellWidthPx = allAppsIconSizePx;
1242 allAppsBorderSpacePx.x -= extraWidthRequired / numBorders;
1243 } else {
1244 // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space
1245 // for allAppsCellWidth, and reduce allAppsIconSize.
1246 allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns
1247 + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns;
1248 allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx);
1249 allAppsBorderSpacePx.x = 0;
1250 }
1251 }
1252
1253 int cellContentHeight = allAppsIconSizePx
1254 + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y;
1255 if (allAppsCellHeightPx < cellContentHeight) {
1256 // Increase allAppsCellHeight to fit its content.
1257 allAppsCellHeightPx = cellContentHeight;
1258 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001259 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001260 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
1261 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001262 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1263 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001264 allAppsIconDrawablePaddingPx =
1265 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001266 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001267 }
Thales Limaabfe3642023-05-24 18:08:53 +01001268 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001269
Jordan Silva376036a2023-11-08 15:56:40 +00001270 private void updateAllAppsWithResponsiveMeasures(Resources res) {
Thales Limaabfe3642023-05-24 18:08:53 +01001271 allAppsBorderSpacePx = new Point(
Jordan Silva8f7986a2023-11-08 12:11:25 +00001272 mResponsiveAllAppsWidthSpec.getGutterPx(),
1273 mResponsiveAllAppsHeightSpec.getGutterPx()
Thales Limaabfe3642023-05-24 18:08:53 +01001274 );
Jordan Silva8f7986a2023-11-08 12:11:25 +00001275 allAppsCellHeightPx = mResponsiveAllAppsHeightSpec.getCellSizePx()
1276 + mResponsiveAllAppsHeightSpec.getGutterPx();
1277 allAppsCellWidthPx = mResponsiveAllAppsWidthSpec.getCellSizePx();
Thales Limaa25cd902023-11-01 12:00:32 +00001278
1279 // This workaround is needed to align AllApps icons with Workspace icons
1280 // since AllApps doesn't have borders between cells
1281 int halfBorder = allAppsBorderSpacePx.x / 2;
Jordan Silva8f7986a2023-11-08 12:11:25 +00001282 allAppsPadding.left = mResponsiveAllAppsWidthSpec.getStartPaddingPx() - halfBorder;
1283 allAppsPadding.right = mResponsiveAllAppsWidthSpec.getEndPaddingPx() - halfBorder;
Jordan Silva376036a2023-11-08 15:56:40 +00001284
1285 // TODO(b/287975993): Remove this after icon size is extracted to responsive grid
1286 // Copy icon size from the workspace when spec is matchWorkspace or
1287 // use the default all apps icon size
Jordan Silva8f7986a2023-11-08 12:11:25 +00001288 if (mResponsiveAllAppsHeightSpec.isCellSizeMatchWorkspace()
1289 || mResponsiveAllAppsWidthSpec.isCellSizeMatchWorkspace()) {
Jordan Silva376036a2023-11-08 15:56:40 +00001290 allAppsIconSizePx = iconSizePx;
1291 allAppsIconTextSizePx = iconTextSizePx;
1292 allAppsIconDrawablePaddingPx = iconDrawablePaddingPx;
1293 } else {
1294 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1295 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
1296 allAppsIconDrawablePaddingPx = res.getDimensionPixelSize(
1297 R.dimen.all_apps_icon_drawable_padding);
1298 allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding(allAppsIconSizePx,
1299 allAppsIconDrawablePaddingPx);
1300 }
1301
1302 // Reduce the size of the app icon if it doesn't fit
1303 if (allAppsCellWidthPx < allAppsIconSizePx) {
1304 // get a smaller icon size
1305 allAppsIconSizePx = mIconSizeSteps.getIconSmallerThan(allAppsCellWidthPx);
1306 }
1307
1308 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1309 allAppsIconSizePx, allAppsIconDrawablePaddingPx, (int) allAppsIconTextSizePx);
1310
1311 if (allAppsCellHeightPx < cellContentDimensions.getCellContentHeight()) {
1312 if (isVerticalBarLayout()) {
1313 if (allAppsCellHeightPx < iconSizePx) {
1314 cellContentDimensions.setIconSizePx(
1315 mIconSizeSteps.getIconSmallerThan(allAppsCellHeightPx));
1316 }
1317 } else {
1318 cellContentDimensions.resizeToFitCellHeight(allAppsCellHeightPx,
1319 mIconSizeSteps);
1320 }
1321 allAppsIconSizePx = cellContentDimensions.getIconSizePx();
1322 allAppsIconDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1323 allAppsIconTextSizePx = cellContentDimensions.getIconTextSizePx();
1324 }
Thales Limaabfe3642023-05-24 18:08:53 +01001325 }
1326
1327 /**
1328 * Re-computes the all-apps cell size to be independent of workspace
1329 */
1330 public void autoResizeAllAppsCells() {
1331 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
1332 int topBottomPadding = textHeight;
1333 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
1334 + textHeight + (topBottomPadding * 2);
1335 }
1336
1337 private void updateAllAppsContainerWidth() {
1338 int cellLayoutHorizontalPadding =
1339 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
1340 if (isTablet) {
1341 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
1342 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Thales Limab433c9c2023-10-30 12:24:05 +00001343 + allAppsPadding.left + allAppsPadding.right;
Thales Limaabfe3642023-05-24 18:08:53 +01001344 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
Thales Limaa25cd902023-11-01 12:00:32 +00001345 } else if (!mIsResponsiveGrid) {
Thales Limab433c9c2023-10-30 12:24:05 +00001346 allAppsPadding.left = allAppsPadding.right =
Thales Limaabfe3642023-05-24 18:08:53 +01001347 Math.max(0, desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding
1348 - (allAppsBorderSpacePx.x / 2));
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001349 }
1350 }
1351
Thales Limaabfe3642023-05-24 18:08:53 +01001352 private void setupAllAppsStyle(Context context) {
1353 TypedArray allAppsStyle = context.obtainStyledAttributes(
1354 inv.allAppsStyle != INVALID_RESOURCE_HANDLE ? inv.allAppsStyle
1355 : R.style.AllAppsStyleDefault, R.styleable.AllAppsStyle);
1356
Thales Limab433c9c2023-10-30 12:24:05 +00001357 allAppsPadding.left = allAppsPadding.right = allAppsStyle.getDimensionPixelSize(
Thales Limaabfe3642023-05-24 18:08:53 +01001358 R.styleable.AllAppsStyle_horizontalPadding, 0);
1359 allAppsStyle.recycle();
1360 }
1361
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001362 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001363 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001364
Jordan Silva637f4eb2023-06-13 11:21:53 +01001365 // Responsive grid doesn't need to scale the folder
1366 if (mIsResponsiveGrid) return;
1367
Thales Lima7eee74b2023-03-16 16:00:55 -03001368 // For usability we can't have the folder use the whole width of the screen
Sunny Goyal07b69292018-01-08 14:19:34 -08001369 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -08001370
Thales Lima7eee74b2023-03-16 16:00:55 -03001371 // Check if the folder fit within the available height.
Thales Lima07c6b8d2023-11-08 18:22:38 +00001372 float contentUsedHeight = folderCellHeightPx * numFolderRows
1373 + ((numFolderRows - 1) * folderCellLayoutBorderSpacePx.y)
Thales Lima7eee74b2023-03-16 16:00:55 -03001374 + folderFooterHeightPx
1375 + folderContentPaddingTop;
1376 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001377 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -08001378
Thales Lima7eee74b2023-03-16 16:00:55 -03001379 // Check if the folder fit within the available width.
Thales Lima07c6b8d2023-11-08 18:22:38 +00001380 float contentUsedWidth = folderCellWidthPx * numFolderColumns
1381 + ((numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x)
Thales Lima7eee74b2023-03-16 16:00:55 -03001382 + folderContentPaddingLeftRight * 2;
1383 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001384 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -08001385
1386 float scale = Math.min(scaleX, scaleY);
1387 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001388 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001389 }
1390 }
1391
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001392 private void updateFolderCellSize(float scale, Resources res) {
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001393 float invIconSizeDp = inv.iconSize[mTypeIndex];
Sunny Goyal35c7b192021-04-20 16:51:10 -07001394 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001395 folderChildTextSizePx = pxFromSp(inv.iconTextSize[mTypeIndex], mMetrics, scale);
Thales Lima7eee74b2023-03-16 16:00:55 -03001396 folderLabelTextSizePx = Math.max(pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale),
Thales Limab35faed2022-09-05 16:30:01 -03001397 (int) (folderChildTextSizePx * folderLabelTextScale));
Jon Mirandabf7d8122016-11-03 15:29:29 -07001398
1399 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001400
Jordan Silva637f4eb2023-06-13 11:21:53 +01001401 if (mIsResponsiveGrid) {
1402 folderCellWidthPx = mResponsiveFolderWidthSpec.getCellSizePx();
Jordan Silva637f4eb2023-06-13 11:21:53 +01001403 folderCellHeightPx = mResponsiveFolderHeightSpec.getCellSizePx();
1404 folderContentPaddingTop = mResponsiveFolderHeightSpec.getStartPaddingPx();
1405 folderFooterHeightPx = mResponsiveFolderHeightSpec.getEndPaddingPx();
1406
1407 folderCellLayoutBorderSpacePx = new Point(mResponsiveFolderWidthSpec.getGutterPx(),
Thales Lima4cfd9502023-07-10 14:01:28 +01001408 mResponsiveFolderHeightSpec.getGutterPx());
Jordan Silva637f4eb2023-06-13 11:21:53 +01001409
1410 folderContentPaddingLeftRight = mResponsiveFolderWidthSpec.getStartPaddingPx();
Jordan Silva12fae112023-06-26 12:51:01 +01001411
1412 // Reduce icon width if it's wider than the expected folder cell width
1413 if (folderCellWidthPx < folderChildIconSizePx) {
1414 folderChildIconSizePx = mIconSizeSteps.getIconSmallerThan(folderCellWidthPx);
1415 }
1416
1417 // Recalculating padding and cell height
1418 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
Jordan Silva12fae112023-06-26 12:51:01 +01001419
Thales Limae9b5e142023-11-04 17:10:13 +00001420 CellContentDimensions cellContentDimensions = new CellContentDimensions(
1421 folderChildIconSizePx,
1422 folderChildDrawablePaddingPx,
1423 folderChildTextSizePx);
1424 cellContentDimensions.resizeToFitCellHeight(folderCellHeightPx, mIconSizeSteps);
1425 folderChildIconSizePx = cellContentDimensions.getIconSizePx();
1426 folderChildDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
1427 folderChildTextSizePx = cellContentDimensions.getIconTextSizePx();
Jordan Silva9a3bd8f2023-11-16 18:33:28 +00001428 folderLabelTextSizePx = Math.max(pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale),
1429 (int) (folderChildTextSizePx * folderLabelTextScale));
Jordan Silva637f4eb2023-06-13 11:21:53 +01001430 } else if (mIsScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001431 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
Thales Lima7eee74b2023-03-16 16:00:55 -03001432 folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale);
1433 folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale);
1434 } else {
1435 folderCellWidthPx = roundPxValueFromFloat(folderCellWidthPx * scale);
1436 folderCellHeightPx = roundPxValueFromFloat(folderCellHeightPx * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001437 }
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001438
Thales Lima7eee74b2023-03-16 16:00:55 -03001439 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001440 folderCellLayoutBorderSpacePx = new Point(
1441 roundPxValueFromFloat(folderCellLayoutBorderSpacePx.x * scale),
1442 roundPxValueFromFloat(folderCellLayoutBorderSpacePx.y * scale)
1443 );
Thales Lima7eee74b2023-03-16 16:00:55 -03001444 folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale);
1445
Jordan Silva637f4eb2023-06-13 11:21:53 +01001446 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx.x;
Jordan Silva12fae112023-06-26 12:51:01 +01001447
1448 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
Jon Miranda823da222021-03-23 08:08:45 -04001449 } else {
1450 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1451 * scale);
1452 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1453 * scale);
1454
1455 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1456 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Lima7eee74b2023-03-16 16:00:55 -03001457 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001458 folderContentPaddingLeftRight =
1459 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1460 folderFooterHeightPx =
Thales Lima7eee74b2023-03-16 16:00:55 -03001461 roundPxValueFromFloat(
1462 res.getDimensionPixelSize(R.dimen.folder_footer_height_default)
1463 * scale);
1464
Jordan Silva12fae112023-06-26 12:51:01 +01001465 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
Jon Miranda823da222021-03-23 08:08:45 -04001466 }
Jon Mirandabf7d8122016-11-03 15:29:29 -07001467 }
1468
Winson1f064272016-07-18 17:18:02 -07001469 public void updateInsets(Rect insets) {
1470 mInsets.set(insets);
1471 }
1472
Sunny Goyalae6e3182019-04-30 12:04:37 -07001473 /**
1474 * The current device insets. This is generally same as the insets being dispatched to
1475 * {@link Insettable} elements, but can differ if the element is using a different profile.
1476 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001477 public Rect getInsets() {
1478 return mInsets;
1479 }
1480
Sunny Goyal756cd262015-08-20 12:33:21 -07001481 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001482 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001483 }
1484
Sunny Goyal19ff7282021-04-22 10:12:54 -07001485 public Point getCellSize(Point result) {
1486 if (result == null) {
1487 result = new Point();
1488 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001489
Pat Manning25d53342022-05-10 09:58:49 +00001490 int shortcutAndWidgetContainerWidth =
1491 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1492 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1493 inv.numColumns);
1494 int shortcutAndWidgetContainerHeight =
1495 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1496 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1497 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001498 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001499 }
1500
1501 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001502 * Returns the left and right space on the cell, which is the cell width - icon size
1503 */
1504 public int getCellHorizontalSpace() {
1505 return getCellSize().x - iconSizePx;
1506 }
1507
1508 /**
Pat Manning25d53342022-05-10 09:58:49 +00001509 * Gets the number of panels within the workspace.
1510 */
1511 public int getPanelCount() {
1512 return isTwoPanels ? 2 : 1;
1513 }
1514
1515 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001516 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1517 * bottom of the screen.
1518 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001519 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1520 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001521 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001522 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001523 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001524 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001525 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001526 }
1527
1528 /**
1529 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1530 */
Pat Manning25d53342022-05-10 09:58:49 +00001531 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001532 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001533 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001534 }
1535
1536 /**
1537 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1538 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001539 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001540 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001541 return heightPx - (isVerticalBarLayout()
1542 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001543 }
1544
Pat Manningea5c1d22022-04-14 10:58:16 +01001545 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001546 * Gets the scale of the workspace for the spring-loaded edit state.
1547 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001548 public float getWorkspaceSpringLoadScale(Context context) {
1549 float scale =
1550 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1551 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001552 scale = Math.min(scale, 1f);
1553
Pat Manninge63dd252022-08-02 16:15:29 +01001554 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001555 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001556 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001557 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001558 if (scaledWorkspaceWidth > maxAvailableWidth) {
1559 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1560 }
1561 return scale;
1562 }
1563
Pat Manning25d53342022-05-10 09:58:49 +00001564 /**
1565 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1566 *
1567 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1568 * layouts have two Cell Layouts per workspace.
1569 */
1570 public int getCellLayoutWidth() {
1571 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001572 }
1573
Pat Manning25d53342022-05-10 09:58:49 +00001574 /**
1575 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1576 *
1577 * <p>This is the height of a Workspace, less its vertical padding.
1578 */
1579 public int getCellLayoutHeight() {
1580 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001581 }
1582
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001583 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001584 return new Point(workspacePadding.left + workspacePadding.right,
1585 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001586 }
1587
1588 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001589 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1590 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001591 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001592 private void updateWorkspacePadding() {
1593 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001594 if (isVerticalBarLayout()) {
Jordan Silva3646a1b2023-08-02 13:52:52 +01001595 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001596 padding.top = mResponsiveWorkspaceHeightSpec.getStartPaddingPx();
Thales Lima8e11d532023-08-31 13:40:26 +00001597 padding.bottom = Math.max(0,
Jordan Silva8f7986a2023-11-08 12:11:25 +00001598 mResponsiveWorkspaceHeightSpec.getEndPaddingPx() - mInsets.bottom);
Jordan Silva3646a1b2023-08-02 13:52:52 +01001599 if (isSeascape()) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001600 padding.left =
1601 hotseatBarSizePx + mResponsiveWorkspaceWidthSpec.getEndPaddingPx();
1602 padding.right = mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
Jordan Silva3646a1b2023-08-02 13:52:52 +01001603 } else {
Jordan Silva8f7986a2023-11-08 12:11:25 +00001604 padding.left = mResponsiveWorkspaceWidthSpec.getStartPaddingPx();
1605 padding.right =
1606 hotseatBarSizePx + mResponsiveWorkspaceWidthSpec.getEndPaddingPx();
Jordan Silva3646a1b2023-08-02 13:52:52 +01001607 }
Winson1f064272016-07-18 17:18:02 -07001608 } else {
Jordan Silva3646a1b2023-08-02 13:52:52 +01001609 padding.top = 0;
1610 padding.bottom = edgeMarginPx;
1611 if (isSeascape()) {
1612 padding.left = hotseatBarSizePx;
Thales Lima8e11d532023-08-31 13:40:26 +00001613 padding.right = mHotseatBarEdgePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001614 } else {
Thales Lima8e11d532023-08-31 13:40:26 +00001615 padding.left = mHotseatBarEdgePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001616 padding.right = hotseatBarSizePx;
1617 }
Winson1f064272016-07-18 17:18:02 -07001618 }
Winson Chungb3800242013-10-24 11:01:54 -07001619 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001620 // Pad the bottom of the workspace with hotseat bar
1621 // and leave a bit of space in case a widget go all the way down
Thales Lima79456492023-05-23 11:32:22 +01001622 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding - mInsets.bottom;
1623 if (!mIsResponsiveGrid) {
1624 paddingBottom +=
1625 workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace;
1626 }
1627 int paddingTop = workspaceTopPadding + (mIsScalableGrid ? 0 : edgeMarginPx);
Pat Manning08610ca2022-04-05 21:03:16 +01001628 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001629
Pat Manning08610ca2022-04-05 21:03:16 +01001630 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001631 }
Pat Manning08610ca2022-04-05 21:03:16 +01001632 insetPadding(workspacePadding, cellLayoutPaddingPx);
1633 }
1634
1635 private void insetPadding(Rect paddings, Rect insets) {
1636 insets.left = Math.min(insets.left, paddings.left);
1637 paddings.left -= insets.left;
1638
1639 insets.top = Math.min(insets.top, paddings.top);
1640 paddings.top -= insets.top;
1641
1642 insets.right = Math.min(insets.right, paddings.right);
1643 paddings.right -= insets.right;
1644
1645 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1646 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001647 }
1648
Liran Binyamina833af32023-08-02 16:30:27 -04001649
1650 /**
1651 * Returns the new border space that should be used between hotseat icons after adjusting it to
1652 * the bubble bar.
1653 *
1654 * <p>If there's no adjustment needed, this method returns {@code 0}.
1655 */
1656 public float getHotseatAdjustedBorderSpaceForBubbleBar(Context context) {
1657 // only need to adjust when QSB is on top of the hotseat.
1658 if (isQsbInline) {
1659 return 0;
1660 }
1661
1662 // no need to adjust if there's enough space for the bubble bar to the right of the hotseat.
1663 if (getHotseatLayoutPadding(context).right > mBubbleBarSpaceThresholdPx) {
1664 return 0;
1665 }
1666
1667 // The adjustment is shrinking the hotseat's width by 1 icon on either side.
1668 int iconsWidth =
1669 iconSizePx * numShownHotseatIcons + hotseatBorderSpace * (numShownHotseatIcons - 1);
1670 int newWidth = iconsWidth - 2 * iconSizePx;
1671 // Evenly space the icons within the boundaries of the new width.
1672 return (float) (newWidth - iconSizePx * numShownHotseatIcons) / (numShownHotseatIcons - 1);
1673 }
1674
Sunny Goyal57b22792021-05-25 14:35:01 -07001675 /**
1676 * Returns the padding for hotseat view
1677 */
1678 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001679 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001680 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001681 // The hotseat icons will be placed in the middle of the hotseat cells.
1682 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1683 // in vertical bar layout.
1684 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1685 // is set to account for that difference.
Jordan Silva3646a1b2023-08-02 13:52:52 +01001686 float diffOverlapFactor = mIsResponsiveGrid ? 0
1687 : iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
1688
Pat Manning08610ca2022-04-05 21:03:16 +01001689 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1690 - diffOverlapFactor), 0);
1691 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001692 + diffOverlapFactor), 0);
1693
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001694 if (isSeascape()) {
Thales Lima8e11d532023-08-31 13:40:26 +00001695 hotseatBarPadding.set(mInsets.left + mHotseatBarEdgePaddingPx, paddingTop,
1696 mHotseatBarWorkspaceSpacePx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001697 } else {
Thales Lima8e11d532023-08-31 13:40:26 +00001698 hotseatBarPadding.set(mHotseatBarWorkspaceSpacePx, paddingTop,
1699 mInsets.right + mHotseatBarEdgePaddingPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001700 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001701 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001702 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001703 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1704 int hotseatBarTopPadding =
1705 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001706
Thales Lima6a590062022-11-22 15:52:49 +00001707 int hotseatWidth = getHotseatRequiredWidth();
Helen Cheuke76291f2023-02-14 17:11:05 +00001708 int startSpacing;
1709 int endSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001710 // Hotseat aligns to the left with nav buttons
1711 if (hotseatBarEndOffset > 0) {
Jon Mirandae17a9492023-03-08 16:42:20 -08001712 startSpacing = inlineNavButtonsEndSpacingPx;
Helen Cheuke76291f2023-02-14 17:11:05 +00001713 endSpacing = availableWidthPx - hotseatWidth - startSpacing + hotseatBorderSpace;
1714 } else {
1715 startSpacing = (availableWidthPx - hotseatWidth) / 2;
1716 endSpacing = startSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001717 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001718 startSpacing += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001719
Helen Cheuke76291f2023-02-14 17:11:05 +00001720 hotseatBarPadding.top = hotseatBarTopPadding;
1721 hotseatBarPadding.bottom = hotseatBarBottomPadding;
Alex Chau51da2192022-05-20 13:32:10 +01001722 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001723 if (isRtl) {
Helen Cheuke76291f2023-02-14 17:11:05 +00001724 hotseatBarPadding.left = endSpacing;
1725 hotseatBarPadding.right = startSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001726 } else {
Helen Cheuke76291f2023-02-14 17:11:05 +00001727 hotseatBarPadding.left = startSpacing;
1728 hotseatBarPadding.right = endSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001729 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001730
Thales Lima79456492023-05-23 11:32:22 +01001731 } else if (mIsScalableGrid) {
Alex Chau206ede92022-08-01 17:46:12 +01001732 int sideSpacing = (availableWidthPx - hotseatQsbWidth) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001733 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001734 0,
Thales Lima425f6822022-05-10 13:44:58 -03001735 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001736 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001737 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001738 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1739 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1740 // for this, we pad the left and right of the hotseat with half of the difference of a
1741 // workspace cell vs a hotseat cell.
1742 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001743 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001744 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001745 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001746 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1747 + mInsets.left,
1748 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001749 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001750 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001751 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001752 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001753 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001754 }
1755
Andy Wickhambd9a1802023-06-08 16:33:15 -07001756 /** The margin between the edge of all apps and the edge of the first icon. */
Thales Limab433c9c2023-10-30 12:24:05 +00001757 public int getAllAppsIconStartMargin(Context context) {
Andy Wickhambd9a1802023-06-08 16:33:15 -07001758 int allAppsSpacing;
1759 if (isVerticalBarLayout()) {
1760 // On phones, the landscape layout uses a different setup.
1761 allAppsSpacing = workspacePadding.left + workspacePadding.right;
1762 } else {
Thales Limab433c9c2023-10-30 12:24:05 +00001763 allAppsSpacing =
1764 allAppsPadding.left + allAppsPadding.right + allAppsLeftRightMargin * 2;
Andy Wickhambd9a1802023-06-08 16:33:15 -07001765 }
1766
1767 int cellWidth = DeviceProfile.calculateCellWidth(
1768 availableWidthPx - allAppsSpacing,
1769 0 /* borderSpace */,
1770 numShownAllAppsColumns);
1771 int iconVisibleSize = Math.round(ICON_VISIBLE_AREA_FACTOR * allAppsIconSizePx);
1772 int iconAlignmentMargin = (cellWidth - iconVisibleSize) / 2;
Thales Limab433c9c2023-10-30 12:24:05 +00001773
1774 return (Utilities.isRtl(context.getResources()) ? allAppsPadding.right
1775 : allAppsPadding.left) + iconAlignmentMargin;
Andy Wickhambd9a1802023-06-08 16:33:15 -07001776 }
1777
Thales Lima9938c2f2022-07-25 14:38:16 +01001778 private int getAdditionalQsbSpace() {
1779 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1780 }
1781
1782 /**
1783 * Calculate how much space the hotseat needs to be shown completely
1784 */
1785 private int getHotseatRequiredWidth() {
1786 int additionalQsbSpace = getAdditionalQsbSpace();
1787 return iconSizePx * numShownHotseatIcons
Thales Lima6a590062022-11-22 15:52:49 +00001788 + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1))
Thales Lima9938c2f2022-07-25 14:38:16 +01001789 + additionalQsbSpace;
1790 }
1791
Winsonfadbe8f2016-07-22 16:35:37 -07001792 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001793 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1794 */
1795 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001796 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001797 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1798 } else if (isTaskbarPresent) { // QSB on top
1799 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001800 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001801 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001802 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001803 }
1804
Thales Limab8c05952022-05-23 16:58:38 +01001805 /**
1806 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1807 */
1808 private int getHotseatBarBottomPadding() {
1809 if (isTaskbarPresent) { // QSB on top or inline
1810 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001811 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001812 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001813 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001814 }
1815
1816 /**
Alex Chau51da2192022-05-20 13:32:10 +01001817 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1818 */
1819 public int getTaskbarOffsetY() {
Jon Miranda9c478b62023-03-23 21:38:49 -07001820 int taskbarIconBottomSpace = (taskbarHeight - iconSizePx) / 2;
Alex Chau51da2192022-05-20 13:32:10 +01001821 int launcherIconBottomSpace =
1822 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001823 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001824 }
1825
Uwais Ashrafaa7fa882023-10-10 21:36:06 +00001826 /** Returns the number of pixels required below OverviewActions. */
Alex Chaua2fc7642022-04-21 14:20:23 +01001827 public int getOverviewActionsClaimedSpaceBelow() {
Uwais Ashrafaa7fa882023-10-10 21:36:06 +00001828 return isTaskbarPresent ? mTransientTaskbarClaimedSpace : mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001829 }
1830
1831 /** Gets the space that the overview actions will take, including bottom margin. */
1832 public int getOverviewActionsClaimedSpace() {
Alex Chau4989f4f2023-10-11 14:08:22 +00001833 int overviewActionsSpace = isTablet && Flags.enableGridOnlyOverview()
Pat Manning7b8f7662023-01-18 14:48:30 +00001834 ? 0
1835 : (overviewActionsTopMarginPx + overviewActionsHeight);
1836 return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
Alex Chaua2fc7642022-04-21 14:20:23 +01001837 }
1838
1839 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001840 * Takes the View and return the scales of width and height depending on the DeviceProfile
1841 * specifications
1842 *
1843 * @param itemInfo The tag of the widget view
1844 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1845 * height
1846 */
1847 @NonNull
1848 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1849 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1850 }
1851
1852 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001853 * @return the bounds for which the open folders should be contained within
1854 */
1855 public Rect getAbsoluteOpenFolderBounds() {
1856 if (isVerticalBarLayout()) {
1857 // Folders should only appear right of the drop target bar and left of the hotseat
1858 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1859 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001860 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001861 mInsets.top + availableHeightPx);
1862 } else {
1863 // Folders should only appear below the drop target bar and above the hotseat
Jon Miranda9c478b62023-03-23 21:38:49 -07001864 int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001865 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001866 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001867 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001868 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001869 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001870 }
1871 }
1872
Jon Miranda228877d2021-02-09 11:05:00 -05001873 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1874 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001875 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001876
Jon Miranda228877d2021-02-09 11:05:00 -05001877 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1878 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001879 }
1880
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001881 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001882 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1883 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1884 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001885 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001886 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001887 return isLandscape && transposeLayoutWithOrientation;
1888 }
1889
Sunny Goyal59d086c2018-05-07 17:31:40 -07001890 /**
1891 * Updates orientation information and returns true if it has changed from the previous value.
1892 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001893 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001894 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001895 boolean isSeascape = DisplayController.INSTANCE.get(context)
1896 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001897 if (mIsSeascape != isSeascape) {
1898 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001899 // Hotseat changing sides requires updating workspace left/right paddings
1900 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001901 return true;
1902 }
1903 }
1904 return false;
1905 }
1906
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001907 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001908 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001909 }
1910
Sunny Goyal07b69292018-01-08 14:19:34 -08001911 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001912 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001913 }
1914
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001915 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001916 switch (containerType) {
1917 case CellLayout.WORKSPACE:
1918 return cellHeightPx;
1919 case CellLayout.FOLDER:
1920 return folderCellHeightPx;
1921 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001922 // The hotseat is the only container where the cell height is going to be
1923 // different from the content within that cell.
1924 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001925 default:
1926 // ??
1927 return 0;
1928 }
1929 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001930
Jon Miranda58561d42021-03-17 10:51:54 -04001931 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001932 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001933 }
1934
Alex Chaue818bcb2022-09-02 17:27:11 +01001935 private String dpPointFToString(String name, PointF value) {
1936 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
1937 }
1938
Pat Manning5f74bfd2022-07-20 12:08:54 +01001939 /** Dumps various DeviceProfile variables to the specified writer. */
1940 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04001941 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001942 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001943
1944 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001945 writer.println(prefix + "\tisPhone:" + isPhone);
1946 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1947 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001948 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001949
1950 writer.println(prefix + "\tisLandscape:" + isLandscape);
1951 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001952 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001953
1954 writer.println(prefix + pxToDpStr("windowX", windowX));
1955 writer.println(prefix + pxToDpStr("windowY", windowY));
1956 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1957 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001958 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1959 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001960 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1961 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1962 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1963 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001964
1965 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1966
Thales Limac98b7812023-04-14 15:04:23 +01001967 writer.println(prefix + "\tisResponsiveGrid:" + mIsResponsiveGrid);
Thales Lima79456492023-05-23 11:32:22 +01001968 writer.println(prefix + "\tisScalableGrid:" + mIsScalableGrid);
Jon Miranda58561d42021-03-17 10:51:54 -04001969
Thales Lima83bedbf2021-10-05 17:47:39 +01001970 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001971 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1972 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1973 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001974
Alex Chaue818bcb2022-09-02 17:27:11 +01001975 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07001976
Jon Miranda58561d42021-03-17 10:51:54 -04001977 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1978 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1979
1980 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1981 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1982
Thales Lima83bedbf2021-10-05 17:47:39 +01001983 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1984 cellLayoutBorderSpacePx.x));
1985 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1986 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001987 writer.println(
1988 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
1989 writer.println(
1990 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
1991 writer.println(
1992 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01001993 writer.println(
1994 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01001995
Jon Miranda58561d42021-03-17 10:51:54 -04001996 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1997 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1998 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1999
Thales Lima07c6b8d2023-11-08 18:22:38 +00002000 writer.println(prefix + "\tnumFolderRows: " + numFolderRows);
2001 writer.println(prefix + "\tnumFolderColumns: " + numFolderColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04002002 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
2003 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
2004 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
2005 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
2006 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
2007 folderChildDrawablePaddingPx));
Jordan Silva637f4eb2023-06-13 11:21:53 +01002008 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.x",
2009 folderCellLayoutBorderSpacePx.x));
2010 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.y",
2011 folderCellLayoutBorderSpacePx.y));
Thales Limaa08a4432022-08-09 09:55:17 +01002012 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
2013 folderContentPaddingLeftRight));
2014 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03002015 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002016
Alex Chaue0227552022-04-06 19:44:43 +01002017 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01002018 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
2019 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
2020 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
2021 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01002022
2023 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
Alex Chau3d2c0622022-09-01 21:28:14 +01002024 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
2025 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04002026 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
2027 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
2028 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
2029 allAppsIconDrawablePaddingPx));
2030 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00002031 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01002032 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
2033 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07002034 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Thales Limab433c9c2023-10-30 12:24:05 +00002035 writer.println(prefix + pxToDpStr("allAppsPadding.top", allAppsPadding.top));
2036 writer.println(prefix + pxToDpStr("allAppsPadding.left", allAppsPadding.left));
2037 writer.println(prefix + pxToDpStr("allAppsPadding.right", allAppsPadding.right));
Alex Chau27b39b92022-01-14 18:02:18 +00002038 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04002039
2040 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03002041 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04002042 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00002043 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Thales Lima8e11d532023-08-31 13:40:26 +00002044 writer.println(prefix + pxToDpStr("mHotseatBarEdgePaddingPx",
2045 mHotseatBarEdgePaddingPx));
2046 writer.println(prefix + pxToDpStr("mHotseatBarWorkspaceSpacePx",
2047 mHotseatBarWorkspaceSpacePx));
Pat Manning26f70f72022-07-07 13:50:39 +01002048 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01002049 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
2050 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01002051 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
2052 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002053 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
2054 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
2055 hotseatLayoutPadding.top));
2056 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
2057 hotseatLayoutPadding.bottom));
2058 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
2059 hotseatLayoutPadding.left));
2060 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
2061 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07002062 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00002063 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00002064 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01002065 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04002066
2067 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10002068 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda9c478b62023-03-23 21:38:49 -07002069 writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight));
2070 writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight));
2071 writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin));
2072 writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize));
Jon Miranda58561d42021-03-17 10:51:54 -04002073
Thales Lima83bedbf2021-10-05 17:47:39 +01002074 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
2075 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04002076 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
2077 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
2078 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00002079 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04002080
Jon Mirandaab3c6812021-06-28 15:42:28 -07002081 writer.println(prefix + pxToDpStr("iconScale", iconScale));
2082 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04002083 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00002084 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04002085
Thales Lima171ee662022-11-22 15:52:49 +00002086 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04002087 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
2088 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00002089
2090 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00002091 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
2092 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
2093 overviewTaskIconDrawableSizePx));
2094 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
2095 overviewTaskIconDrawableSizeGridPx));
Pat Manning1695cc72023-07-05 11:45:13 +01002096 writer.println(prefix + pxToDpStr("overviewTaskIconAppChipMenuDrawableSizePx",
2097 overviewTaskIconAppChipMenuDrawableSizePx));
Alex Chau635b3ab2022-01-26 16:49:10 +00002098 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
2099 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01002100 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
2101 overviewActionsTopMarginPx));
2102 writer.println(prefix + pxToDpStr("overviewActionsHeight",
2103 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00002104 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
2105 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00002106 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
2107 overviewActionsButtonSpacing));
2108 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
2109 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
2110 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01002111
Alex Chau62572c02022-07-25 18:36:37 +00002112 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01002113 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00002114 writer.println(
2115 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01002116
Pat Manning5f74bfd2022-07-20 12:08:54 +01002117 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
2118 getCellLayoutSpringLoadShrunkTop()));
2119 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
2120 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01002121 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
2122 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002123 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
2124 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01002125 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
2126 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Thales Lima79456492023-05-23 11:32:22 +01002127 if (mIsResponsiveGrid) {
Jordan Silva8f7986a2023-11-08 12:11:25 +00002128 writer.println(prefix + "\tmResponsiveWorkspaceHeightSpec:"
2129 + mResponsiveWorkspaceHeightSpec.toString());
2130 writer.println(prefix + "\tmResponsiveWorkspaceWidthSpec:"
2131 + mResponsiveWorkspaceWidthSpec.toString());
2132 writer.println(prefix + "\tmResponsiveAllAppsHeightSpec:"
2133 + mResponsiveAllAppsHeightSpec.toString());
2134 writer.println(prefix + "\tmResponsiveAllAppsWidthSpec:"
2135 + mResponsiveAllAppsWidthSpec.toString());
Jordan Silva637f4eb2023-06-13 11:21:53 +01002136 writer.println(prefix + "\tmResponsiveFolderHeightSpec:" + mResponsiveFolderHeightSpec);
2137 writer.println(prefix + "\tmResponsiveFolderWidthSpec:" + mResponsiveFolderWidthSpec);
Thales Limaf8bfb032023-07-24 15:08:05 +01002138 writer.println(prefix + "\tmResponsiveHotseatSpec:" + mResponsiveHotseatSpec);
Thales Lima79456492023-05-23 11:32:22 +01002139 }
Jon Miranda58561d42021-03-17 10:51:54 -04002140 }
2141
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00002142 /** Returns a reduced representation of this DeviceProfile. */
2143 public String toSmallString() {
2144 return "isTablet:" + isTablet + ", "
2145 + "isMultiDisplay:" + isMultiDisplay + ", "
2146 + "widthPx:" + widthPx + ", "
2147 + "heightPx:" + heightPx + ", "
2148 + "insets:" + mInsets + ", "
2149 + "rotationHint:" + rotationHint;
2150 }
2151
Alex Chaua6907dc2022-03-18 15:24:07 +00002152 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07002153 Configuration config = new Configuration(c.getResources().getConfiguration());
2154 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03002155 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00002156 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07002157 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07002158 }
Sunny Goyalfde55052018-02-01 14:46:13 -08002159
2160 /**
2161 * Callback when a component changes the DeviceProfile associated with it, as a result of
2162 * configuration change
2163 */
2164 public interface OnDeviceProfileChangeListener {
2165
2166 /**
2167 * Called when the device profile is reassigned. Note that for layout and measurements, it
2168 * is sufficient to listen for inset changes. Use this callback when you need to perform
2169 * a one time operation.
2170 */
2171 void onDeviceProfileChanged(DeviceProfile dp);
2172 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002173
Sihua Mae04aa202022-07-18 12:43:56 -07002174 /**
2175 * Handler that deals with ItemInfo of the views for the DeviceProfile
2176 */
2177 @FunctionalInterface
2178 public interface ViewScaleProvider {
2179 /**
2180 * Get the scales from the view
2181 *
2182 * @param itemInfo The tag of the widget view
2183 * @return PointF instance containing the scale information, or null if using the default
2184 * app widget scale of this device profile.
2185 */
2186 @NonNull
2187 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
2188 }
2189
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002190 public static class Builder {
2191 private Context mContext;
2192 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07002193 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002194
Sunny Goyal19ff7282021-04-22 10:12:54 -07002195 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00002196 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002197
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002198 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07002199 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00002200 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07002201 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002202
Sunny Goyal65190ae2022-08-02 14:16:26 -07002203 private SparseArray<DotRenderer> mDotRendererCache;
2204
Jon Miranda2b25ded2023-02-02 14:48:45 -08002205 private Consumer<DeviceProfile> mOverrideProvider;
2206
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002207 private boolean mIsTransientTaskbar;
2208
Sunny Goyalfd58da62020-08-11 12:06:49 -07002209 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002210 mContext = context;
2211 mInv = inv;
2212 mInfo = info;
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002213 mIsTransientTaskbar = info.isTransientTaskbar();
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002214 }
2215
2216 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
2217 mIsMultiWindowMode = isMultiWindowMode;
2218 return this;
2219 }
2220
Alex Chauab800f72022-12-13 17:46:06 +00002221 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
2222 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07002223 return this;
2224 }
2225
Sunny Goyal65190ae2022-08-02 14:16:26 -07002226 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
2227 mDotRendererCache = dotRendererCache;
2228 return this;
2229 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07002230
2231 public Builder setWindowBounds(WindowBounds bounds) {
2232 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07002233 return this;
2234 }
2235
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002236 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
2237 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
2238 return this;
2239 }
2240
Alex Chau6ed408f2022-03-04 12:58:05 +00002241 public Builder setGestureMode(boolean isGestureMode) {
2242 mIsGestureMode = isGestureMode;
2243 return this;
2244 }
2245
Jon Miranda2b25ded2023-02-02 14:48:45 -08002246 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
2247 mOverrideProvider = overrideProvider;
2248 return this;
2249 }
2250
Sihua Mae04aa202022-07-18 12:43:56 -07002251 /**
2252 * Set the viewScaleProvider for the builder
2253 *
2254 * @param viewScaleProvider The viewScaleProvider to be set for the
Thales Limae9273ea2023-01-26 12:33:52 +00002255 * DeviceProfile
Sihua Mae04aa202022-07-18 12:43:56 -07002256 * @return This builder
2257 */
2258 @NonNull
2259 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
2260 mViewScaleProvider = viewScaleProvider;
2261 return this;
2262 }
2263
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002264 /**
2265 * Set the isTransientTaskbar for the builder
2266 * @return This Builder
2267 */
2268 public Builder setIsTransientTaskbar(boolean isTransientTaskbar) {
2269 mIsTransientTaskbar = isTransientTaskbar;
2270 return this;
2271 }
2272
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002273 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07002274 if (mWindowBounds == null) {
2275 throw new IllegalArgumentException("Window bounds not set");
2276 }
2277 if (mTransposeLayoutWithOrientation == null) {
2278 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
2279 }
Alex Chau6ed408f2022-03-04 12:58:05 +00002280 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01002281 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00002282 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002283 if (mDotRendererCache == null) {
2284 mDotRendererCache = new SparseArray<>();
2285 }
Sihua Mae04aa202022-07-18 12:43:56 -07002286 if (mViewScaleProvider == null) {
2287 mViewScaleProvider = DEFAULT_PROVIDER;
2288 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08002289 if (mOverrideProvider == null) {
2290 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
2291 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002292 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00002293 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jagrut Desai3a7d1392023-09-06 15:56:19 -07002294 mIsGestureMode, mViewScaleProvider, mOverrideProvider, mIsTransientTaskbar);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002295 }
2296 }
Winson Chungb3800242013-10-24 11:01:54 -07002297}