blob: 04980321088d8aa70bcfbd248a6eeaef897e95f9 [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;
Thales Lima12d0eff2022-03-25 17:06:11 +000020import static com.android.launcher3.InvariantDeviceProfile.INDEX_DEFAULT;
21import static com.android.launcher3.InvariantDeviceProfile.INDEX_LANDSCAPE;
22import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_LANDSCAPE;
23import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_PORTRAIT;
Jon Miranda58561d42021-03-17 10:51:54 -040024import static com.android.launcher3.Utilities.dpiFromPx;
Jon Mirandaaf3aed02021-05-06 18:28:45 -070025import static com.android.launcher3.Utilities.pxFromSp;
Alex Chauab800f72022-12-13 17:46:06 +000026import static com.android.launcher3.config.FeatureFlags.ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH;
Jon Miranda92c1b5d2021-07-20 13:57:16 -070027import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.ICON_OVERLAP_FACTOR;
Sunny Goyal65190ae2022-08-02 14:16:26 -070028import static com.android.launcher3.icons.GraphicsUtils.getShapePath;
Jon Miranda95f44722023-06-06 19:48:19 -070029import static com.android.launcher3.icons.IconNormalizer.ICON_VISIBLE_AREA_FACTOR;
Thales Limab35faed2022-09-05 16:30:01 -030030import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURCE_HANDLE;
Pat Manning5f74bfd2022-07-20 12:08:54 +010031import static com.android.launcher3.testing.shared.ResourceUtils.pxFromDp;
Thales Lima7eee74b2023-03-16 16:00:55 -030032import static com.android.launcher3.testing.shared.ResourceUtils.roundPxValueFromFloat;
Jon Miranda228877d2021-02-09 11:05:00 -050033
Sunny Goyal35c7b192021-04-20 16:51:10 -070034import android.annotation.SuppressLint;
Winson Chungb3800242013-10-24 11:01:54 -070035import android.content.Context;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070036import android.content.res.Configuration;
Winson Chungb3800242013-10-24 11:01:54 -070037import android.content.res.Resources;
Thales Limab35faed2022-09-05 16:30:01 -030038import android.content.res.TypedArray;
Winson Chungb3800242013-10-24 11:01:54 -070039import android.graphics.Point;
Jon Miranda7ae64ff2016-11-21 16:18:46 -080040import android.graphics.PointF;
Winson Chungb3800242013-10-24 11:01:54 -070041import android.graphics.Rect;
Sunny Goyal35c7b192021-04-20 16:51:10 -070042import android.util.DisplayMetrics;
Sunny Goyal65190ae2022-08-02 14:16:26 -070043import android.util.SparseArray;
Sunny Goyal59d086c2018-05-07 17:31:40 -070044import android.view.Surface;
Winson Chungb3800242013-10-24 11:01:54 -070045
Sunny Goyal65190ae2022-08-02 14:16:26 -070046import androidx.annotation.NonNull;
Sihua Mae04aa202022-07-18 12:43:56 -070047import androidx.annotation.Nullable;
Jon Miranda9c478b62023-03-23 21:38:49 -070048import androidx.core.content.res.ResourcesCompat;
Sunny Goyal65190ae2022-08-02 14:16:26 -070049
Sunny Goyalc13403c2016-11-18 23:44:48 -080050import com.android.launcher3.CellLayout.ContainerType;
Jon Miranda228877d2021-02-09 11:05:00 -050051import com.android.launcher3.DevicePaddings.DevicePadding;
Alex Chaud67ddc42022-09-30 18:15:56 +010052import com.android.launcher3.config.FeatureFlags;
Tony Wickham8912b042018-11-29 15:28:53 -080053import com.android.launcher3.icons.DotRenderer;
Hyunyoung Song48cb7bc2018-09-25 17:03:34 -070054import com.android.launcher3.icons.IconNormalizer;
Sihua Mae04aa202022-07-18 12:43:56 -070055import com.android.launcher3.model.data.ItemInfo;
Thales Limaabfe3642023-05-24 18:08:53 +010056import com.android.launcher3.responsive.AllAppsSpecs;
57import com.android.launcher3.responsive.CalculatedAllAppsSpec;
Sunny Goyal57b22792021-05-25 14:35:01 -070058import com.android.launcher3.uioverrides.ApiWrapper;
Sunny Goyalfd58da62020-08-11 12:06:49 -070059import com.android.launcher3.util.DisplayController;
60import com.android.launcher3.util.DisplayController.Info;
Thales Limac98b7812023-04-14 15:04:23 +010061import com.android.launcher3.util.ResourceHelper;
Sunny Goyalb46703d2020-05-27 17:52:03 -070062import com.android.launcher3.util.WindowBounds;
Thales Limac98b7812023-04-14 15:04:23 +010063import com.android.launcher3.workspace.CalculatedWorkspaceSpec;
64import com.android.launcher3.workspace.WorkspaceSpecs;
Winson1f064272016-07-18 17:18:02 -070065
Jon Miranda58561d42021-03-17 10:51:54 -040066import java.io.PrintWriter;
Alex Chaue818bcb2022-09-02 17:27:11 +010067import java.util.Locale;
Jon Miranda2b25ded2023-02-02 14:48:45 -080068import java.util.function.Consumer;
Jon Miranda58561d42021-03-17 10:51:54 -040069
Sunny Goyal35c7b192021-04-20 16:51:10 -070070@SuppressLint("NewApi")
Winson Chungb3800242013-10-24 11:01:54 -070071public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070072
Sunny Goyal8b9919d2021-04-07 14:45:17 -070073 private static final int DEFAULT_DOT_SIZE = 100;
Alex Chau206ede92022-08-01 17:46:12 +010074 private static final float ALL_APPS_TABLET_MAX_ROWS = 5.5f;
Thales Limab35faed2022-09-05 16:30:01 -030075 private static final float MIN_FOLDER_TEXT_SIZE_SP = 16f;
Sunny Goyal6c304b12023-04-10 12:03:04 -070076 private static final float MIN_WIDGET_PADDING_DP = 6f;
Alex Chau206ede92022-08-01 17:46:12 +010077
Sihua Mae04aa202022-07-18 12:43:56 -070078 public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f);
79 public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE;
Thales Limaabfe3642023-05-24 18:08:53 +010080 public static final Consumer<DeviceProfile> DEFAULT_DIMENSION_PROVIDER = dp -> {
81 };
Sihua Mae04aa202022-07-18 12:43:56 -070082
Adam Cohen2e6da152015-05-06 11:42:25 -070083 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070084 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070085 private final DisplayMetrics mMetrics;
Winson Chungbe876472014-05-14 14:15:20 -070086
Sunny Goyalc6205602015-05-21 20:46:33 -070087 // Device properties
88 public final boolean isTablet;
Sunny Goyalc6205602015-05-21 20:46:33 -070089 public final boolean isPhone;
90 public final boolean transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +000091 public final boolean isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -070092 public final boolean isTwoPanels;
Thales Limaa1012902022-01-13 17:58:42 +000093 public final boolean isQsbInline;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -070094
Sunny Goyalc6205602015-05-21 20:46:33 -070095 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -070096 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -080097 public final boolean isMultiWindowMode;
Alex Chau6ed408f2022-03-04 12:58:05 +000098 public final boolean isGestureMode;
Sunny Goyald70e75a2018-02-22 10:07:32 -080099
Sunny Goyal0addbf02020-04-28 14:17:35 -0700100 public final int windowX;
101 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -0700102 public final int widthPx;
103 public final int heightPx;
104 public final int availableWidthPx;
105 public final int availableHeightPx;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800106 public final int rotationHint;
Jon Mirandabba64512019-03-27 10:54:17 -0700107
108 public final float aspectRatio;
109
Thales Lima79456492023-05-23 11:32:22 +0100110 private final boolean mIsScalableGrid;
Thales Lima83bedbf2021-10-05 17:47:39 +0100111 private final int mTypeIndex;
Jon Mirandae126d722021-02-25 10:45:20 -0500112
Thales Limac98b7812023-04-14 15:04:23 +0100113 // Responsive grid
114 private final boolean mIsResponsiveGrid;
115 private WorkspaceSpecs mWorkspaceSpecs;
116 private CalculatedWorkspaceSpec mResponsiveWidthSpec;
117 private CalculatedWorkspaceSpec mResponsiveHeightSpec;
Thales Limaabfe3642023-05-24 18:08:53 +0100118 private AllAppsSpecs mAllAppsSpecs;
119 private CalculatedAllAppsSpec mAllAppsResponsiveWidthSpec;
120 private CalculatedAllAppsSpec mAllAppsResponsiveHeightSpec;
Thales Limac98b7812023-04-14 15:04:23 +0100121
Tony Wickhamd6b40372015-09-23 18:37:57 -0700122 /**
123 * The maximum amount of left/right workspace padding as a percentage of the screen width.
124 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
125 * 7% of the screen width can be used as right padding.
126 */
127 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -0700128
Jon Miranda3f9bab22017-07-28 14:50:17 -0700129 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700130 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda80dda302021-07-28 14:14:59 -0700131 private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252;
132 private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700133
Sunny Goyalc6205602015-05-21 20:46:33 -0700134 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +0100135 public final int desiredWorkspaceHorizontalMarginOriginalPx;
136 public int desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100137 public int gridVisualizationPaddingX;
138 public int gridVisualizationPaddingY;
Thales Lima78d00ad2021-09-30 11:29:06 +0100139 public Point cellLayoutBorderSpaceOriginalPx;
140 public Point cellLayoutBorderSpacePx;
Pat Manning08610ca2022-04-05 21:03:16 +0100141 public Rect cellLayoutPaddingPx = new Rect();
142
Sunny Goyalc6205602015-05-21 20:46:33 -0700143 public final int edgeMarginPx;
Alex Chau0c4e11b2022-07-08 18:41:36 +0100144 public final float workspaceContentScale;
Alex Chau906d8822022-05-23 10:42:25 +0100145 public final int workspaceSpringLoadedMinNextPageVisiblePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700146
Jon Miranda58561d42021-03-17 10:51:54 -0400147 private final int extraSpace;
Thales Lima171ee662022-11-22 15:52:49 +0000148 private int maxEmptySpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500149 public int workspaceTopPadding;
150 public int workspaceBottomPadding;
151
Tony Wickham5edf9e22020-03-27 20:06:52 -0700152 // Workspace page indicator
153 public final int workspacePageIndicatorHeight;
154 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700155
Sunny Goyalc6205602015-05-21 20:46:33 -0700156 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400157 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700158 public int iconSizePx;
159 public int iconTextSizePx;
160 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700161 public int iconDrawablePaddingOriginalPx;
Thales Lima79456492023-05-23 11:32:22 +0100162 public boolean iconCenterVertically;
Winson Chungb3800242013-10-24 11:01:54 -0700163
Jon Mirandaab3c6812021-06-28 15:42:28 -0700164 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800165 public int cellWidthPx;
166 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700167 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800168
Thales Lima79456492023-05-23 11:32:22 +0100169 public int cellYPaddingPx = -1;
Jon Mirandae126d722021-02-25 10:45:20 -0500170
Sunny Goyalc6205602015-05-21 20:46:33 -0700171 // Folder
Jon Mirandae126d722021-02-25 10:45:20 -0500172 public float folderLabelTextScale;
173 public int folderLabelTextSizePx;
Thales Limab35faed2022-09-05 16:30:01 -0300174 public int folderFooterHeightPx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700175 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700176 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700177
Jon Mirandae126d722021-02-25 10:45:20 -0500178 // Folder content
Thales Limab35faed2022-09-05 16:30:01 -0300179 public int folderCellLayoutBorderSpacePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500180 public int folderContentPaddingLeftRight;
181 public int folderContentPaddingTop;
182
Jon Mirandabf7d8122016-11-03 15:29:29 -0700183 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700184 public int folderCellWidthPx;
185 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700186
187 // Folder child
188 public int folderChildIconSizePx;
189 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700190 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700191
Sunny Goyalc6205602015-05-21 20:46:33 -0700192 // Hotseat
Thales Lima9938c2f2022-07-25 14:38:16 +0100193 public int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700194 public int hotseatCellHeightPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100195 public final boolean areNavButtonsInline;
Jon Miranda18751b62017-07-31 17:25:27 -0700196 // In portrait: size = height, in landscape: size = width
197 public int hotseatBarSizePx;
Thales Limab8c05952022-05-23 16:58:38 +0100198 public int hotseatBarBottomSpacePx;
Pat Manning26f70f72022-07-07 13:50:39 +0100199 public int hotseatBarEndOffset;
Thales Limab8c05952022-05-23 16:58:38 +0100200 public int hotseatQsbSpace;
Pat Manningde25c0d2022-04-05 19:11:26 +0100201 public int springLoadedHotseatBarTopMarginPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700202 // Start is the side next to the nav bar, end is the side next to the workspace
203 public final int hotseatBarSidePaddingStartPx;
204 public final int hotseatBarSidePaddingEndPx;
Alex Chau206ede92022-08-01 17:46:12 +0100205 public int hotseatQsbWidth; // only used when isQsbInline
Sunny Goyal57b22792021-05-25 14:35:01 -0700206 public final int hotseatQsbHeight;
Thales Limab8c05952022-05-23 16:58:38 +0100207 public final int hotseatQsbVisualHeight;
208 private final int hotseatQsbShadowHeight;
Thales Limadd027342022-01-07 12:54:37 +0000209 public int hotseatBorderSpace;
Thales Limaffc68b02023-01-09 16:20:23 +0000210 private final int mMinHotseatIconSpacePx;
211 private final int mMinHotseatQsbWidthPx;
212 private final int mMaxHotseatIconSpacePx;
Jon Mirandae17a9492023-03-08 16:42:20 -0800213 public final int inlineNavButtonsEndSpacingPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700214
Alex Chau3d2c0622022-09-01 21:28:14 +0100215 // Bottom sheets
216 public int bottomSheetTopPadding;
217 public int bottomSheetOpenDuration;
218 public int bottomSheetCloseDuration;
219 public float bottomSheetWorkspaceScale;
220 public float bottomSheetDepth;
221
Sunny Goyalc6205602015-05-21 20:46:33 -0700222 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000223 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000224 public int allAppsShiftRange;
225 public int allAppsTopPadding;
Alex Chau3d2c0622022-09-01 21:28:14 +0100226 public int allAppsOpenDuration;
227 public int allAppsCloseDuration;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700228 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700229 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700230 public int allAppsIconSizePx;
231 public int allAppsIconDrawablePaddingPx;
sfufa@google.comde013292021-09-21 18:22:44 -0700232 public int allAppsLeftRightPadding;
Alex Chau27b39b92022-01-14 18:02:18 +0000233 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700234 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700235 public float allAppsIconTextSizePx;
236
Zak Cohen334efeb2021-03-19 16:42:07 -0700237 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700238 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000239 public int overviewTaskIconSizePx;
Alex Chauac9df382021-08-02 19:08:41 +0100240 public int overviewTaskIconDrawableSizePx;
241 public int overviewTaskIconDrawableSizeGridPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000242 public int overviewTaskThumbnailTopMarginPx;
Alex Chau19c6eca2022-03-10 20:12:56 +0000243 public final int overviewActionsHeight;
Alex Chaua2fc7642022-04-21 14:20:23 +0100244 public final int overviewActionsTopMarginPx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000245 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100246 public int overviewPageSpacing;
247 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000248 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700249
Jeremy Sim0ac47082022-10-10 13:59:40 -0700250 // Split staging
251 public int splitPlaceholderInset;
252
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800253 // Widgets
Sihua Mae04aa202022-07-18 12:43:56 -0700254 private final ViewScaleProvider mViewScaleProvider;
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800255
Sunny Goyal47328fd2016-05-25 18:56:41 -0700256 // Drop Target
257 public int dropTargetBarSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100258 public int dropTargetBarTopMarginPx;
259 public int dropTargetBarBottomMarginPx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100260 public int dropTargetDragPaddingPx;
261 public int dropTargetTextSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100262 public int dropTargetHorizontalPaddingPx;
263 public int dropTargetVerticalPaddingPx;
264 public int dropTargetGapPx;
Alex Chau5b019302022-05-23 10:42:25 +0100265 public int dropTargetButtonWorkspaceEdgeGapPx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700266
Winson1f064272016-07-18 17:18:02 -0700267 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800268 private final Rect mInsets = new Rect();
269 public final Rect workspacePadding = new Rect();
Sunny Goyal6c304b12023-04-10 12:03:04 -0700270 // Additional padding added to the widget inside its cellSpace. It is applied outside
271 // the widgetView, such that the actual view size is same as the widget size.
272 public final Rect widgetPadding = new Rect();
273
Jon Miranda0bd63d12019-03-06 17:29:29 -0800274 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700275 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700276
Tony Wickhamf34bee82018-12-03 18:11:39 -0800277 // Notification dots
Sunny Goyal65190ae2022-08-02 14:16:26 -0700278 public final DotRenderer mDotRendererWorkSpace;
279 public final DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800280
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100281 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800282 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000283 // Whether Taskbar will inset the bottom of apps by taskbarSize.
284 public boolean isTaskbarPresentInApps;
Jon Miranda9c478b62023-03-23 21:38:49 -0700285 public final int taskbarHeight;
286 public final int stashedTaskbarHeight;
287 public final int taskbarBottomMargin;
288 public final int taskbarIconSize;
Jon Miranda04f05102023-04-04 12:16:31 -0700289 // If true, used to layout taskbar in 3 button navigation mode.
290 public final boolean startAlignTaskbar;
Tony Wickham15883892021-02-12 11:24:40 -0800291
Alex Chaua02eddc2021-04-29 00:36:06 +0100292 // DragController
293 public int flingToDeleteThresholdVelocity;
294
Vinit Nayak17c4b332021-08-05 12:54:58 -0700295 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700296 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal65190ae2022-08-02 14:16:26 -0700297 SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
Alex Chauab800f72022-12-13 17:46:06 +0000298 boolean transposeLayoutWithOrientation, boolean isMultiDisplay, boolean isGestureMode,
Jon Miranda2b25ded2023-02-02 14:48:45 -0800299 @NonNull final ViewScaleProvider viewScaleProvider,
300 @NonNull final Consumer<DeviceProfile> dimensionOverrideProvider) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700301
Adam Cohen2e6da152015-05-06 11:42:25 -0700302 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700303 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800304 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500305 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +0000306 this.isMultiDisplay = isMultiDisplay;
Alex Chau6ed408f2022-03-04 12:58:05 +0000307 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700308 windowX = windowBounds.bounds.left;
309 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800310 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100311 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700312
Thales Limac98b7812023-04-14 15:04:23 +0100313 // TODO(b/241386436): shouldn't change any launcher behaviour
Thales Limaabfe3642023-05-24 18:08:53 +0100314 mIsResponsiveGrid = inv.workspaceSpecsId != INVALID_RESOURCE_HANDLE
315 && inv.allAppsSpecsId != INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100316
Thales Lima79456492023-05-23 11:32:22 +0100317 mIsScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000318 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700319 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000320 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700321 isPhone = !isTablet;
Alex Chauab800f72022-12-13 17:46:06 +0000322 isTwoPanels = isTablet && isMultiDisplay;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800323 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700324
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000325 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000326 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700327 ? Configuration.ORIENTATION_LANDSCAPE
328 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000329 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700330 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000331 mMetrics = res.getDisplayMetrics();
332
333 // Determine sizes.
334 widthPx = windowBounds.bounds.width();
335 heightPx = windowBounds.bounds.height();
336 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100337 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000338
339 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Thales Lima83bedbf2021-10-05 17:47:39 +0100340 if (isTwoPanels) {
341 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000342 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100343 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000344 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100345 }
346 } else {
347 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000348 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100349 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000350 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100351 }
352 }
353
Jon Miranda9c478b62023-03-23 21:38:49 -0700354 if (DisplayController.isTransientTaskbar(context)) {
355 float invTransientIconSizeDp = inv.transientTaskbarIconSize[mTypeIndex];
356 taskbarIconSize = pxFromDp(invTransientIconSizeDp, mMetrics);
Jon Miranda95f44722023-06-06 19:48:19 -0700357 taskbarHeight = Math.round((taskbarIconSize * ICON_VISIBLE_AREA_FACTOR)
358 + (2 * res.getDimensionPixelSize(R.dimen.transient_taskbar_padding)));
Jon Miranda9c478b62023-03-23 21:38:49 -0700359 stashedTaskbarHeight =
360 res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_height);
361 taskbarBottomMargin =
362 res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin);
Jon Miranda04f05102023-04-04 12:16:31 -0700363 startAlignTaskbar = false;
Jon Miranda9c478b62023-03-23 21:38:49 -0700364 } else {
365 taskbarIconSize = pxFromDp(ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size),
366 mMetrics);
367 taskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_size);
368 stashedTaskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
369 taskbarBottomMargin = 0;
Jon Miranda04f05102023-04-04 12:16:31 -0700370 startAlignTaskbar = inv.startAlignTaskbar[mTypeIndex];
Tony Wickham15883892021-02-12 11:24:40 -0800371 }
Tony Wickham15883892021-02-12 11:24:40 -0800372
Winson Chungb3800242013-10-24 11:01:54 -0700373 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100374 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700375
Alex Chau51da2192022-05-20 13:32:10 +0100376 gridVisualizationPaddingX = res.getDimensionPixelSize(
377 R.dimen.grid_visualization_horizontal_cell_spacing);
378 gridVisualizationPaddingY = res.getDimensionPixelSize(
379 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500380
Alex Chaue0227552022-04-06 19:44:43 +0100381 bottomSheetTopPadding = mInsets.top // statusbar height
Andras Kloczl142b0542022-03-09 21:26:02 +0000382 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
383 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
Alex Chau3d2c0622022-09-01 21:28:14 +0100384 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
385 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
386 if (isTablet) {
387 bottomSheetWorkspaceScale = workspaceContentScale;
Alex Chauab800f72022-12-13 17:46:06 +0000388 if (isMultiDisplay && !ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH.get()) {
389 // TODO(b/259893832): Revert to use maxWallpaperScale to calculate bottomSheetDepth
390 // when screen recorder bug is fixed.
391 bottomSheetDepth = 1f;
392 } else {
393 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
394 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
395 // When depth is 1, wallpaper zoom is set to 1.
396 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
397 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
398 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
399 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
400 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100401 } else {
402 bottomSheetWorkspaceScale = 1f;
403 bottomSheetDepth = 0f;
404 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000405
Jon Mirandae126d722021-02-25 10:45:20 -0500406 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
Thales Limab35faed2022-09-05 16:30:01 -0300407
Thales Lima79456492023-05-23 11:32:22 +0100408 if (mIsScalableGrid && inv.folderStyle != INVALID_RESOURCE_HANDLE) {
Thales Limab35faed2022-09-05 16:30:01 -0300409 TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
Thales Limad852d652023-01-17 14:01:13 +0000410 R.styleable.FolderStyle);
Thales Limab35faed2022-09-05 16:30:01 -0300411 // These are re-set in #updateFolderCellSize if the grid is not scalable
412 folderCellHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000413 R.styleable.FolderStyle_folderCellHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300414 folderCellWidthPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000415 R.styleable.FolderStyle_folderCellWidth, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300416
417 folderContentPaddingTop = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000418 R.styleable.FolderStyle_folderTopPadding, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300419 folderCellLayoutBorderSpacePx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000420 R.styleable.FolderStyle_folderBorderSpace, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300421 folderFooterHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000422 R.styleable.FolderStyle_folderFooterHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300423 folderStyle.recycle();
424 } else {
425 folderCellLayoutBorderSpacePx = 0;
Thales Lima7eee74b2023-03-16 16:00:55 -0300426 folderFooterHeightPx = res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Thales Limab35faed2022-09-05 16:30:01 -0300427 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
428 }
Jon Mirandae126d722021-02-25 10:45:20 -0500429
Thales Lima85c942f2021-12-31 13:04:20 +0000430 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000431 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
432 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Thales Limae9273ea2023-01-26 12:33:52 +0000433 setupAllAppsStyle(context);
Jon Mirandae126d722021-02-25 10:45:20 -0500434
Tony Wickham5edf9e22020-03-27 20:06:52 -0700435 workspacePageIndicatorHeight = res.getDimensionPixelSize(
436 R.dimen.workspace_page_indicator_height);
437 mWorkspacePageIndicatorOverlapWorkspace =
438 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700439
Thales Limad852d652023-01-17 14:01:13 +0000440 TypedArray cellStyle;
441 if (inv.cellStyle != INVALID_RESOURCE_HANDLE) {
442 cellStyle = context.obtainStyledAttributes(inv.cellStyle,
443 R.styleable.CellStyle);
444 } else {
445 cellStyle = context.obtainStyledAttributes(R.style.CellStyleDefault,
446 R.styleable.CellStyle);
447 }
448 iconDrawablePaddingOriginalPx = cellStyle.getDimensionPixelSize(
449 R.styleable.CellStyle_iconDrawablePadding, 0);
450 cellStyle.recycle();
Alex Chaua02eddc2021-04-29 00:36:06 +0100451
Sunny Goyal47328fd2016-05-25 18:56:41 -0700452 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100453 dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
454 dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100455 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
456 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100457 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
458 R.dimen.drop_target_button_drawable_horizontal_padding);
459 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
460 R.dimen.drop_target_button_drawable_vertical_padding);
461 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100462 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
463 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100464
Alex Chau906d8822022-05-23 10:42:25 +0100465 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
466 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700467
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700468 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700469
Thales Limaa1012902022-01-13 17:58:42 +0000470 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100471 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
472 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
473
Thales Lima12d0eff2022-03-25 17:06:11 +0000474 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
475 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
476 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
477 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
478 && hotseatQsbHeight > 0;
Thales Lima79456492023-05-23 11:32:22 +0100479 isQsbInline = mIsScalableGrid && inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000480
Thales Lima425f6822022-05-10 13:44:58 -0300481 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100482 numShownHotseatIcons =
483 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000484
Sunny Goyal19ff7282021-04-22 10:12:54 -0700485 numShownAllAppsColumns =
486 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100487
488 int hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
489 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
490 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
491 // Have a little space between the inset and the QSB
492 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
493 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
494
495 // Only change the spaces if there is space
496 if (availableSpace > 0) {
497 // Make sure there is enough space between hotseat/QSB and QSB/navBar
498 if (availableSpace < minQsbMargin * 2) {
499 minQsbMargin = availableSpace / 2;
500 hotseatQsbSpace = minQsbMargin;
501 } else {
502 hotseatQsbSpace -= minQsbMargin;
503 }
504 }
505 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
506
Thales Limaa1012902022-01-13 17:58:42 +0000507 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100508 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
Thales Limaa1012902022-01-13 17:58:42 +0000509 }
Thales Lima425f6822022-05-10 13:44:58 -0300510
Pat Manningde25c0d2022-04-05 19:11:26 +0100511 springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
512 R.dimen.spring_loaded_hotseat_top_margin);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700513 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800514 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700515 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700516 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Thales Limab8c05952022-05-23 16:58:38 +0100517 updateHotseatSizes(pxFromDp(inv.iconSize[INDEX_DEFAULT], mMetrics));
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700518 if (areNavButtonsInline && !isPhone) {
Jon Mirandae17a9492023-03-08 16:42:20 -0800519 inlineNavButtonsEndSpacingPx =
Thales Limaffc68b02023-01-09 16:20:23 +0000520 res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing);
Pat Manning26f70f72022-07-07 13:50:39 +0100521 /*
522 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700523 * Spacing between nav buttons +
Thales Lima6a590062022-11-22 15:52:49 +0000524 * Space at the end for contextual buttons
Pat Manning26f70f72022-07-07 13:50:39 +0100525 */
526 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700527 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
Jon Mirandae17a9492023-03-08 16:42:20 -0800528 + inlineNavButtonsEndSpacingPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100529 } else {
Jon Mirandae17a9492023-03-08 16:42:20 -0800530 inlineNavButtonsEndSpacingPx = 0;
Pat Manning26f70f72022-07-07 13:50:39 +0100531 hotseatBarEndOffset = 0;
532 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700533
Thales Lima79456492023-05-23 11:32:22 +0100534 // Needs to be calculated after hotseatBarSizePx is correct,
535 // for the available height to be correct
536 if (mIsResponsiveGrid) {
537 mWorkspaceSpecs = new WorkspaceSpecs(new ResourceHelper(context, inv.workspaceSpecsId));
538 mResponsiveWidthSpec = mWorkspaceSpecs.getCalculatedWidthSpec(inv.numColumns,
539 availableWidthPx);
540 mResponsiveHeightSpec = mWorkspaceSpecs.getCalculatedHeightSpec(inv.numRows,
541 // don't use availableHeightPx because it subtracts bottom padding,
542 // but the hotseat go behind it
543 heightPx - mInsets.top - hotseatBarSizePx);
Thales Limaabfe3642023-05-24 18:08:53 +0100544
545 mAllAppsSpecs = new AllAppsSpecs(new ResourceHelper(context, inv.allAppsSpecsId));
546 mAllAppsResponsiveWidthSpec = mAllAppsSpecs.getCalculatedWidthSpec(inv.numColumns,
547 mResponsiveWidthSpec.getAvailableSpace(), mResponsiveWidthSpec);
548 mAllAppsResponsiveHeightSpec = mAllAppsSpecs.getCalculatedHeightSpec(inv.numRows,
549 mResponsiveHeightSpec.getAvailableSpace(),
550 mResponsiveHeightSpec);
Thales Lima79456492023-05-23 11:32:22 +0100551 }
552
553 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
554 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
555
Alex Chau635b3ab2022-01-26 16:49:10 +0000556 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chau5fd9d492021-07-22 17:27:11 +0100557 overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100558 overviewTaskIconDrawableSizePx =
559 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
560 overviewTaskIconDrawableSizeGridPx =
561 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700562 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx;
Andy Wickham64896f32023-05-30 21:46:24 -0700563 // Don't add margin with floating search bar to minimize risk of overlapping.
564 overviewActionsTopMarginPx = FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get() ? 0
565 : res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000566 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
567 overviewActionsButtonSpacing = res.getDimensionPixelSize(
568 R.dimen.overview_actions_button_spacing);
Alex Chau19c6eca2022-03-10 20:12:56 +0000569 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700570 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000571 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700572
Jeremy Sim0ac47082022-10-10 13:59:40 -0700573 splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset);
574
Jon Miranda2ed276e2017-06-29 11:36:34 -0700575 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400576 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700577
Thales Lima79456492023-05-23 11:32:22 +0100578 calculateAndSetWorkspaceVerticalPadding(context, inv, extraSpace);
Pat Manning08610ca2022-04-05 21:03:16 +0100579
580 int cellLayoutPadding =
581 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
582 R.dimen.cell_layout_padding);
583 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
584 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800585 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800586
Thales Lima7eee74b2023-03-16 16:00:55 -0300587 // Folder scaling requires correct workspace paddings
588 updateAvailableFolderCellDimensions(res);
589
Thales Limaffc68b02023-01-09 16:20:23 +0000590 mMinHotseatIconSpacePx = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
591 mMinHotseatQsbWidthPx = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
592 mMaxHotseatIconSpacePx = areNavButtonsInline
Thales Lima6a590062022-11-22 15:52:49 +0000593 ? res.getDimensionPixelSize(R.dimen.max_hotseat_icon_space) : Integer.MAX_VALUE;
Thales Lima425f6822022-05-10 13:44:58 -0300594 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima6a590062022-11-22 15:52:49 +0000595 recalculateHotseatWidthAndBorderSpace();
Alex Chau206ede92022-08-01 17:46:12 +0100596
597 // AllApps height calculation depends on updated cellSize
598 if (isTablet) {
599 int collapseHandleHeight =
600 res.getDimensionPixelOffset(R.dimen.bottom_sheet_handle_area_height);
601 int contentHeight = heightPx - collapseHandleHeight - hotseatQsbHeight;
602 int targetContentHeight = (int) (allAppsCellHeightPx * ALL_APPS_TABLET_MAX_ROWS);
603 allAppsTopPadding = Math.max(mInsets.top, contentHeight - targetContentHeight);
604 allAppsShiftRange = heightPx - allAppsTopPadding;
605 } else {
606 allAppsTopPadding = 0;
607 allAppsShiftRange =
608 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
609 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100610 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
611 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300612
Alex Chaua02eddc2021-04-29 00:36:06 +0100613 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
614 R.dimen.drag_flingToDeleteMinVelocity);
615
Sihua Mae04aa202022-07-18 12:43:56 -0700616 mViewScaleProvider = viewScaleProvider;
617
Jon Miranda2b25ded2023-02-02 14:48:45 -0800618 dimensionOverrideProvider.accept(this);
619
Tony Wickham1237df02017-02-24 08:59:36 -0800620 // This is done last, after iconSizePx is calculated above.
Sunny Goyal799e1202023-02-09 10:54:28 -0800621 mDotRendererWorkSpace = createDotRenderer(context, iconSizePx, dotRendererCache);
622 mDotRendererAllApps = createDotRenderer(context, allAppsIconSizePx, dotRendererCache);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700623 }
624
625 private static DotRenderer createDotRenderer(
Sunny Goyal799e1202023-02-09 10:54:28 -0800626 @NonNull Context context, int size, @NonNull SparseArray<DotRenderer> cache) {
Sunny Goyal65190ae2022-08-02 14:16:26 -0700627 DotRenderer renderer = cache.get(size);
628 if (renderer == null) {
Sunny Goyal799e1202023-02-09 10:54:28 -0800629 renderer = new DotRenderer(size, getShapePath(context, DEFAULT_DOT_SIZE),
630 DEFAULT_DOT_SIZE);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700631 cache.put(size, renderer);
632 }
633 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700634 }
635
Thales Lima425f6822022-05-10 13:44:58 -0300636 /**
637 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
638 * width of the hotseat.
639 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100640 private int calculateQsbWidth(int hotseatBorderSpace) {
Thales Lima425f6822022-05-10 13:44:58 -0300641 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100642 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300643 return getIconToIconWidthForColumns(columns)
644 - iconSizePx * numShownHotseatIcons
645 - hotseatBorderSpace * numShownHotseatIcons;
646 } else {
647 int columns = inv.hotseatColumnSpan[mTypeIndex];
648 return getIconToIconWidthForColumns(columns);
649 }
650 }
Thales Lima2903a622022-03-17 13:52:19 +0000651
Thales Lima425f6822022-05-10 13:44:58 -0300652 private int getIconToIconWidthForColumns(int columns) {
653 return columns * getCellSize().x
654 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400655 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000656 }
657
Thales Limad90faab2021-09-21 17:18:47 +0100658 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
Thales Lima79456492023-05-23 11:32:22 +0100659 if (mIsResponsiveGrid) {
660 return mResponsiveWidthSpec.getStartPaddingPx();
661 }
662
Thales Limad90faab2021-09-21 17:18:47 +0100663 if (isVerticalBarLayout()) {
664 return 0;
665 }
666
Thales Lima79456492023-05-23 11:32:22 +0100667 return mIsScalableGrid
Thales Lima83bedbf2021-10-05 17:47:39 +0100668 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
669 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100670 }
671
Thales Lima79456492023-05-23 11:32:22 +0100672 private void calculateAndSetWorkspaceVerticalPadding(Context context,
673 InvariantDeviceProfile inv,
674 int extraSpace) {
675 if (mIsResponsiveGrid) {
676 workspaceTopPadding = mResponsiveHeightSpec.getStartPaddingPx();
677 workspaceBottomPadding = mResponsiveHeightSpec.getEndPaddingPx();
678 } else if (mIsScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
679 // Paddings were created assuming no scaling, so we first unscale the extra space.
680 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
681 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
682 DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
683 maxEmptySpace = padding.getMaxEmptySpacePx();
684
685 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
686 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
687
688 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
689 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
690 }
691 }
692
Thales Limab8c05952022-05-23 16:58:38 +0100693 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
694 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700695 // Ensure there is enough space for folder icons, which have a slightly larger radius.
696 hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR);
Thales Limab8c05952022-05-23 16:58:38 +0100697
Jon Miranda0d284852021-06-22 14:50:55 -0700698 if (isVerticalBarLayout()) {
699 hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
700 + hotseatBarSidePaddingEndPx;
Thales Limab8c05952022-05-23 16:58:38 +0100701 } else if (isQsbInline) {
702 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
703 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700704 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100705 hotseatBarSizePx = hotseatIconSizePx
706 + hotseatQsbSpace
707 + hotseatQsbVisualHeight
708 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700709 }
710 }
711
Thales Lima6a590062022-11-22 15:52:49 +0000712 /**
713 * Calculates the width of the hotseat, changing spaces between the icons and removing icons if
714 * necessary.
715 */
716 public void recalculateHotseatWidthAndBorderSpace() {
Thales Lima79456492023-05-23 11:32:22 +0100717 if (!mIsScalableGrid) return;
Thales Lima6a590062022-11-22 15:52:49 +0000718
719 int columns = inv.hotseatColumnSpan[mTypeIndex];
720 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
721 hotseatBorderSpace = calculateHotseatBorderSpace(hotseatWidthPx, /* numExtraBorder= */ 0);
Thales Lima9938c2f2022-07-25 14:38:16 +0100722 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
Thales Lima6a590062022-11-22 15:52:49 +0000723 // Spaces should be correct when the nav buttons are not inline
Thales Lima9938c2f2022-07-25 14:38:16 +0100724 if (!areNavButtonsInline) {
725 return;
726 }
727
Thales Lima6a590062022-11-22 15:52:49 +0000728 // The side space with inline buttons should be what is defined in InvariantDeviceProfile
Jon Mirandae17a9492023-03-08 16:42:20 -0800729 int sideSpacePx = inlineNavButtonsEndSpacingPx;
Thales Limaffc68b02023-01-09 16:20:23 +0000730 int maxHotseatWidthPx = availableWidthPx - sideSpacePx - hotseatBarEndOffset;
731 int maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
732 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000733 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100734
Thales Limaffc68b02023-01-09 16:20:23 +0000735 if (hotseatBorderSpace >= mMinHotseatIconSpacePx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100736 return;
737 }
738
739 // Border space can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000740 hotseatBorderSpace = mMinHotseatIconSpacePx;
Thales Lima6a590062022-11-22 15:52:49 +0000741 int requiredWidth = getHotseatRequiredWidth();
Thales Lima9938c2f2022-07-25 14:38:16 +0100742
743 // If there is an inline qsb, change its size
744 if (isQsbInline) {
Thales Limaffc68b02023-01-09 16:20:23 +0000745 hotseatQsbWidth -= requiredWidth - maxHotseatWidthPx;
746 if (hotseatQsbWidth >= mMinHotseatQsbWidthPx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100747 return;
748 }
749
750 // QSB can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000751 hotseatQsbWidth = mMinHotseatQsbWidthPx;
Thales Lima9938c2f2022-07-25 14:38:16 +0100752 }
753
Thales Limaffc68b02023-01-09 16:20:23 +0000754 maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
Thales Lima6a590062022-11-22 15:52:49 +0000755
Thales Lima9938c2f2022-07-25 14:38:16 +0100756 // If it still doesn't fit, start removing icons
757 do {
758 numShownHotseatIcons--;
Thales Limaffc68b02023-01-09 16:20:23 +0000759 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000760 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Limaffc68b02023-01-09 16:20:23 +0000761 } while (hotseatBorderSpace < mMinHotseatIconSpacePx && numShownHotseatIcons > 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100762
Thales Lima9938c2f2022-07-25 14:38:16 +0100763 }
764
Thales Lima78d00ad2021-09-30 11:29:06 +0100765 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100766 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100767 }
768
769 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima79456492023-05-23 11:32:22 +0100770 int horizontalSpacePx = 0;
771 int verticalSpacePx = 0;
Thales Lima78d00ad2021-09-30 11:29:06 +0100772
Thales Lima79456492023-05-23 11:32:22 +0100773 if (mIsResponsiveGrid) {
774 horizontalSpacePx = mResponsiveWidthSpec.getGutterPx();
775 verticalSpacePx = mResponsiveHeightSpec.getGutterPx();
776 } else if (mIsScalableGrid) {
777 horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
778 verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
779 }
Thales Lima78d00ad2021-09-30 11:29:06 +0100780
781 return new Point(horizontalSpacePx, verticalSpacePx);
782 }
783
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700784 public Info getDisplayInfo() {
785 return mInfo;
786 }
787
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700788 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800789 WindowBounds bounds = new WindowBounds(
790 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700791 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100792 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700793
794 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
795 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
796 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
797
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700798 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700799 .setWindowBounds(bounds)
Alex Chauab800f72022-12-13 17:46:06 +0000800 .setIsMultiDisplay(isMultiDisplay)
Alex Chau6ed408f2022-03-04 12:58:05 +0000801 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700802 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000803 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800804 }
805
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700806 public DeviceProfile copy(Context context) {
807 return toBuilder(context).build();
808 }
809
810 /**
811 * TODO: Move this to the builder as part of setMultiWindowMode
812 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700813 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700814 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700815 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700816 .setMultiWindowMode(true)
817 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800818
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800819 // We use these scales to measure and layout the widgets using their full invariant profile
820 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
821 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
822 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700823 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
824 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
825 profile = profile.toBuilder(context)
826 .setViewScaleProvider(i -> p)
827 .build();
828 }
829
830 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800831
Jon Miranda93e1f042016-11-11 14:13:04 -0800832 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700833 }
834
Adam Cohen63f1ec02014-08-12 09:23:13 -0700835 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400836 * Checks if there is enough space for labels on the workspace.
837 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700838 * It is important to call this method after the All Apps variables have been set.
839 */
Jon Miranda941375e2021-03-31 13:10:45 -0400840 private void hideWorkspaceLabelsIfNotEnoughSpace() {
841 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
842 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
843 - iconTextHeight;
844
845 // We want enough space so that the text is closer to its corresponding icon.
846 if (workspaceCellPaddingY < iconTextHeight) {
847 iconTextSizePx = 0;
848 iconDrawablePaddingPx = 0;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700849 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda941375e2021-03-31 13:10:45 -0400850 autoResizeAllAppsCells();
851 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700852 }
Jon Miranda1091e532017-07-21 13:31:50 -0700853
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700854 /**
Jon Miranda228877d2021-02-09 11:05:00 -0500855 * Returns the amount of extra (or unused) vertical space.
856 */
857 private int updateAvailableDimensions(Resources res) {
Alex Chaua68164d2022-12-15 16:16:03 +0000858 float invIconSizeDp = inv.iconSize[mTypeIndex];
859 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
860 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
861 iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
Thales Lima79456492023-05-23 11:32:22 +0100862 iconCenterVertically = mIsScalableGrid || mIsResponsiveGrid;
Alex Chaua68164d2022-12-15 16:16:03 +0000863
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700864 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800865
Pat Manning08610ca2022-04-05 21:03:16 +0100866 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -0500867
868 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +0100869 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +0000870 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -0500871 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500872 float scaleY = maxHeight / usedHeight;
873 boolean shouldScale = scaleY < 1f;
874
875 float scaleX = 1f;
Thales Lima79456492023-05-23 11:32:22 +0100876 if (mIsScalableGrid) {
Jon Mirandae126d722021-02-25 10:45:20 -0500877 // We scale to fit the cellWidth and cellHeight in the available space.
878 // The benefit of scalable grids is that we can get consistent aspect ratios between
879 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +0100880 float usedWidth =
881 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500882 // We do not subtract padding here, as we also scale the workspace padding if needed.
883 scaleX = availableWidthPx / usedWidth;
884 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700885 }
Jon Mirandae126d722021-02-25 10:45:20 -0500886
887 if (shouldScale) {
888 float scale = Math.min(scaleX, scaleY);
889 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +0100890 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -0500891 }
892
Jon Miranda228877d2021-02-09 11:05:00 -0500893 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700894 }
895
Pat Manninga2e14992022-04-22 11:29:17 +0100896 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +0100897 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
898 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
899 }
900
Pat Manninga2e14992022-04-22 11:29:17 +0100901 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +0000902 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +0100903 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
904 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -0500905 }
906
Jon Miranda6f7e9702019-09-16 14:44:14 -0700907 /**
908 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
909 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
910 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
911 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800912 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -0700913 // Icon scale should never exceed 1, otherwise pixellation may occur.
914 iconScale = Math.min(1f, scale);
915 cellScaleToFit = scale;
916
Jon Miranda18751b62017-07-31 17:25:27 -0700917 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800918 final boolean isVerticalLayout = isVerticalBarLayout();
Jon Mirandaab3c6812021-06-28 15:42:28 -0700919 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);
Thales Lima080d8902022-03-28 15:30:29 +0100920 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Thales Lima79456492023-05-23 11:32:22 +0100921 int cellTextAndPaddingHeight =
922 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Jon Mirandae126d722021-02-25 10:45:20 -0500923
Thales Lima79456492023-05-23 11:32:22 +0100924 if (mIsResponsiveGrid) {
925 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
926
927 cellWidthPx = mResponsiveWidthSpec.getCellSizePx();
928 cellHeightPx = mResponsiveHeightSpec.getCellSizePx();
929 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
930
931 // TODO(b/283929701): decrease icon size if content doesn't fit on cell
932 } else if (mIsScalableGrid) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100933 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
934 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +0000935
936 if (cellWidthPx < iconSizePx) {
937 // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger.
938 int numColumns = getPanelCount() * inv.numColumns;
939 int numBorders = numColumns - 1;
940 int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns;
941 if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) {
942 cellWidthPx = iconSizePx;
943 cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders;
944 } else {
945 // If it still doesn't fit, set borderSpace to 0 and distribute the space for
946 // cellWidth, and reduce iconSize.
947 cellWidthPx = (cellWidthPx * numColumns
948 + cellLayoutBorderSpacePx.x * numBorders) / numColumns;
949 iconSizePx = Math.min(iconSizePx, cellWidthPx);
950 cellLayoutBorderSpacePx.x = 0;
951 }
952 }
953
Alex Chaube753132022-12-09 16:46:54 +0000954 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
955 if (cellHeightPx < cellContentHeight) {
956 // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight
957 // bigger.
958 int numBorders = inv.numRows - 1;
959 int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows;
960 if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) {
961 cellHeightPx = cellContentHeight;
962 cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders;
963 } else {
Alex Chau06f36e82023-01-06 10:50:54 +0000964 // If it still doesn't fit, set borderSpace to 0 to recover space.
Alex Chaube753132022-12-09 16:46:54 +0000965 cellHeightPx = (cellHeightPx * inv.numRows
966 + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows;
Alex Chaube753132022-12-09 16:46:54 +0000967 cellLayoutBorderSpacePx.y = 0;
Alex Chau06f36e82023-01-06 10:50:54 +0000968 // Reduce iconDrawablePaddingPx to make cellContentHeight smaller.
969 int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx;
970 if (cellContentWithoutPadding <= cellHeightPx) {
971 iconDrawablePaddingPx = cellContentHeight - cellHeightPx;
972 } else {
973 // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space,
974 // then proportional reduce iconSizePx and iconTextSizePx to fit.
975 iconDrawablePaddingPx = 0;
976 float ratio = cellHeightPx / (float) cellContentWithoutPadding;
977 iconSizePx = (int) (iconSizePx * ratio);
978 iconTextSizePx = (int) (iconTextSizePx * ratio);
979 }
980 cellTextAndPaddingHeight =
981 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +0000982 }
983 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
984 }
Jon Mirandae126d722021-02-25 10:45:20 -0500985 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +0100986 desiredWorkspaceHorizontalMarginPx =
987 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -0500988 } else {
Jon Mirandae126d722021-02-25 10:45:20 -0500989 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700990 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR)
991 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -0500992 + Utilities.calculateTextHeight(iconTextSizePx);
993 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
994 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
995 && !isMultiWindowMode) {
996 // Ensures that the label is closer to its corresponding icon. This is not an issue
997 // with vertical bar layout or multi-window mode since the issue is handled
998 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
999 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
1000 iconDrawablePaddingPx = cellPaddingY;
1001 }
Jon Miranda846455e2017-10-02 14:58:52 -07001002 }
Jon Miranda18751b62017-07-31 17:25:27 -07001003
Sunny Goyalae190ff2020-04-14 00:19:01 +00001004 // All apps
Thales Limaabfe3642023-05-24 18:08:53 +01001005 if (mIsResponsiveGrid) {
1006 updateAllAppsWithResponsiveMeasures();
1007 } else {
1008 updateAllAppsIconSize(scale, res);
1009 }
1010 updateAllAppsContainerWidth();
1011 if (isVerticalBarLayout()) {
1012 hideWorkspaceLabelsIfNotEnoughSpace();
1013 }
Winson Chungb3800242013-10-24 11:01:54 -07001014
Thales Limab8c05952022-05-23 16:58:38 +01001015 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -07001016
Sunny Goyalbaec6ff2016-09-14 11:26:21 -07001017 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -07001018 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
1019 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Sunny Goyal6c304b12023-04-10 12:03:04 -07001020
1021 // Update widget padding:
1022 float minSpacing = pxFromDp(MIN_WIDGET_PADDING_DP, mMetrics);
1023 if (cellLayoutBorderSpacePx.x < minSpacing
1024 || cellLayoutBorderSpacePx.y < minSpacing) {
1025 widgetPadding.left = widgetPadding.right =
1026 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.x));
1027 widgetPadding.top = widgetPadding.bottom =
1028 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.y));
1029 } else {
1030 widgetPadding.setEmpty();
1031 }
Winson Chung0f785722015-04-08 10:27:49 -07001032 }
1033
Thales Lima425f6822022-05-10 13:44:58 -03001034 /**
Thales Lima6a590062022-11-22 15:52:49 +00001035 * This method calculates the space between the icons to achieve a certain width.
Thales Lima425f6822022-05-10 13:44:58 -03001036 */
Thales Lima6a590062022-11-22 15:52:49 +00001037 private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) {
Thales Lima9938c2f2022-07-25 14:38:16 +01001038 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
Thales Limaffc68b02023-01-09 16:20:23 +00001039 int hotseatBorderSpacePx =
Thales Lima6a590062022-11-22 15:52:49 +00001040 (int) (hotseatWidthPx - hotseatIconsTotalPx)
1041 / (numShownHotseatIcons - 1 + numExtraBorder);
Thales Limaffc68b02023-01-09 16:20:23 +00001042 return Math.min(hotseatBorderSpacePx, mMaxHotseatIconSpacePx);
Thales Lima425f6822022-05-10 13:44:58 -03001043 }
1044
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001045
1046 /**
1047 * Updates the iconSize for allApps* variants.
1048 */
Brian Isganitisa9a78112022-05-23 18:11:47 -07001049 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +01001050 allAppsBorderSpacePx = new Point(
1051 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
1052 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001053 // AllApps cells don't have real space between cells,
1054 // so we add the border space to the cell height
Alex Chaube753132022-12-09 16:46:54 +00001055 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics)
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001056 + allAppsBorderSpacePx.y;
1057 // but width is just the cell,
1058 // the border is added in #updateAllAppsContainerWidth
Thales Lima79456492023-05-23 11:32:22 +01001059 if (mIsScalableGrid) {
Alex Chaube753132022-12-09 16:46:54 +00001060 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1061 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001062 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001063 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001064
1065 if (allAppsCellWidthPx < allAppsIconSizePx) {
1066 // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to
1067 // make allAppsCellWidth bigger.
1068 int numBorders = inv.numAllAppsColumns - 1;
1069 int extraWidthRequired =
1070 (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns;
1071 if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) {
1072 allAppsCellWidthPx = allAppsIconSizePx;
1073 allAppsBorderSpacePx.x -= extraWidthRequired / numBorders;
1074 } else {
1075 // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space
1076 // for allAppsCellWidth, and reduce allAppsIconSize.
1077 allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns
1078 + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns;
1079 allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx);
1080 allAppsBorderSpacePx.x = 0;
1081 }
1082 }
1083
1084 int cellContentHeight = allAppsIconSizePx
1085 + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y;
1086 if (allAppsCellHeightPx < cellContentHeight) {
1087 // Increase allAppsCellHeight to fit its content.
1088 allAppsCellHeightPx = cellContentHeight;
1089 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001090 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001091 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
1092 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001093 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1094 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001095 allAppsIconDrawablePaddingPx =
1096 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001097 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001098 }
Thales Limaabfe3642023-05-24 18:08:53 +01001099 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001100
Thales Limaabfe3642023-05-24 18:08:53 +01001101 private void updateAllAppsWithResponsiveMeasures() {
1102 allAppsIconSizePx = iconSizePx;
1103 allAppsIconTextSizePx = iconTextSizePx;
1104 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
1105
1106 allAppsBorderSpacePx = new Point(
1107 mAllAppsResponsiveWidthSpec.getGutterPx(),
1108 mAllAppsResponsiveHeightSpec.getGutterPx()
1109 );
1110 allAppsCellHeightPx = mAllAppsResponsiveHeightSpec.getCellSizePx()
1111 + mAllAppsResponsiveHeightSpec.getGutterPx();
1112 allAppsCellWidthPx = mAllAppsResponsiveWidthSpec.getCellSizePx();
1113 allAppsLeftRightPadding = mAllAppsResponsiveWidthSpec.getStartPaddingPx();
1114 }
1115
1116 /**
1117 * Re-computes the all-apps cell size to be independent of workspace
1118 */
1119 public void autoResizeAllAppsCells() {
1120 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
1121 int topBottomPadding = textHeight;
1122 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
1123 + textHeight + (topBottomPadding * 2);
1124 }
1125
1126 private void updateAllAppsContainerWidth() {
1127 int cellLayoutHorizontalPadding =
1128 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
1129 if (isTablet) {
1130 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
1131 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
1132 + allAppsLeftRightPadding * 2;
1133 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
1134 } else {
1135 allAppsLeftRightPadding =
1136 Math.max(0, desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding
1137 - (allAppsBorderSpacePx.x / 2));
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001138 }
1139 }
1140
Thales Limaabfe3642023-05-24 18:08:53 +01001141 private void setupAllAppsStyle(Context context) {
1142 TypedArray allAppsStyle = context.obtainStyledAttributes(
1143 inv.allAppsStyle != INVALID_RESOURCE_HANDLE ? inv.allAppsStyle
1144 : R.style.AllAppsStyleDefault, R.styleable.AllAppsStyle);
1145
1146 allAppsLeftRightPadding = allAppsStyle.getDimensionPixelSize(
1147 R.styleable.AllAppsStyle_horizontalPadding, 0);
1148 allAppsStyle.recycle();
1149 }
1150
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001151 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001152 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001153
Thales Lima7eee74b2023-03-16 16:00:55 -03001154 // For usability we can't have the folder use the whole width of the screen
Sunny Goyal07b69292018-01-08 14:19:34 -08001155 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -08001156
Thales Lima7eee74b2023-03-16 16:00:55 -03001157 // Check if the folder fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -05001158 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Thales Lima7eee74b2023-03-16 16:00:55 -03001159 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx)
1160 + folderFooterHeightPx
1161 + folderContentPaddingTop;
1162 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001163 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -08001164
Thales Lima7eee74b2023-03-16 16:00:55 -03001165 // Check if the folder fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -05001166 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Thales Lima7eee74b2023-03-16 16:00:55 -03001167 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx)
1168 + folderContentPaddingLeftRight * 2;
1169 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001170 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -08001171
1172 float scale = Math.min(scaleX, scaleY);
1173 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001174 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001175 }
1176 }
1177
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001178 private void updateFolderCellSize(float scale, Resources res) {
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001179 float invIconSizeDp = inv.iconSize[mTypeIndex];
Sunny Goyal35c7b192021-04-20 16:51:10 -07001180 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001181 folderChildTextSizePx = pxFromSp(inv.iconTextSize[mTypeIndex], mMetrics, scale);
Thales Lima7eee74b2023-03-16 16:00:55 -03001182 folderLabelTextSizePx = Math.max(pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale),
Thales Limab35faed2022-09-05 16:30:01 -03001183 (int) (folderChildTextSizePx * folderLabelTextScale));
Jon Mirandabf7d8122016-11-03 15:29:29 -07001184
1185 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001186
Thales Lima79456492023-05-23 11:32:22 +01001187 if (mIsScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001188 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
Thales Lima7eee74b2023-03-16 16:00:55 -03001189 folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale);
1190 folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale);
1191 } else {
1192 folderCellWidthPx = roundPxValueFromFloat(folderCellWidthPx * scale);
1193 folderCellHeightPx = roundPxValueFromFloat(folderCellHeightPx * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001194 }
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001195
Thales Lima7eee74b2023-03-16 16:00:55 -03001196 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
1197 folderCellLayoutBorderSpacePx = roundPxValueFromFloat(
1198 folderCellLayoutBorderSpacePx * scale);
1199 folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale);
1200
Thales Limab35faed2022-09-05 16:30:01 -03001201 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx;
Jon Miranda823da222021-03-23 08:08:45 -04001202 } else {
1203 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1204 * scale);
1205 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1206 * scale);
1207
1208 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1209 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Lima7eee74b2023-03-16 16:00:55 -03001210 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001211 folderContentPaddingLeftRight =
1212 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1213 folderFooterHeightPx =
Thales Lima7eee74b2023-03-16 16:00:55 -03001214 roundPxValueFromFloat(
1215 res.getDimensionPixelSize(R.dimen.folder_footer_height_default)
1216 * scale);
1217
Jon Miranda823da222021-03-23 08:08:45 -04001218 }
1219
Jonathan Miranda9ad87462017-07-26 17:41:02 +00001220 folderChildDrawablePaddingPx = Math.max(0,
1221 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001222 }
1223
Winson1f064272016-07-18 17:18:02 -07001224 public void updateInsets(Rect insets) {
1225 mInsets.set(insets);
1226 }
1227
Sunny Goyalae6e3182019-04-30 12:04:37 -07001228 /**
1229 * The current device insets. This is generally same as the insets being dispatched to
1230 * {@link Insettable} elements, but can differ if the element is using a different profile.
1231 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001232 public Rect getInsets() {
1233 return mInsets;
1234 }
1235
Sunny Goyal756cd262015-08-20 12:33:21 -07001236 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001237 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001238 }
1239
Sunny Goyal19ff7282021-04-22 10:12:54 -07001240 public Point getCellSize(Point result) {
1241 if (result == null) {
1242 result = new Point();
1243 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001244
Pat Manning25d53342022-05-10 09:58:49 +00001245 int shortcutAndWidgetContainerWidth =
1246 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1247 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1248 inv.numColumns);
1249 int shortcutAndWidgetContainerHeight =
1250 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1251 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1252 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001253 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001254 }
1255
1256 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001257 * Returns the left and right space on the cell, which is the cell width - icon size
1258 */
1259 public int getCellHorizontalSpace() {
1260 return getCellSize().x - iconSizePx;
1261 }
1262
1263 /**
Pat Manning25d53342022-05-10 09:58:49 +00001264 * Gets the number of panels within the workspace.
1265 */
1266 public int getPanelCount() {
1267 return isTwoPanels ? 2 : 1;
1268 }
1269
1270 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001271 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1272 * bottom of the screen.
1273 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001274 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1275 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001276 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001277 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001278 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001279 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001280 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001281 }
1282
1283 /**
1284 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1285 */
Pat Manning25d53342022-05-10 09:58:49 +00001286 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001287 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001288 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001289 }
1290
1291 /**
1292 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1293 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001294 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001295 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001296 return heightPx - (isVerticalBarLayout()
1297 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001298 }
1299
Pat Manningea5c1d22022-04-14 10:58:16 +01001300 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001301 * Gets the scale of the workspace for the spring-loaded edit state.
1302 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001303 public float getWorkspaceSpringLoadScale(Context context) {
1304 float scale =
1305 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1306 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001307 scale = Math.min(scale, 1f);
1308
Pat Manninge63dd252022-08-02 16:15:29 +01001309 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001310 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001311 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001312 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001313 if (scaledWorkspaceWidth > maxAvailableWidth) {
1314 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1315 }
1316 return scale;
1317 }
1318
Pat Manning25d53342022-05-10 09:58:49 +00001319 /**
1320 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1321 *
1322 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1323 * layouts have two Cell Layouts per workspace.
1324 */
1325 public int getCellLayoutWidth() {
1326 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001327 }
1328
Pat Manning25d53342022-05-10 09:58:49 +00001329 /**
1330 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1331 *
1332 * <p>This is the height of a Workspace, less its vertical padding.
1333 */
1334 public int getCellLayoutHeight() {
1335 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001336 }
1337
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001338 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001339 return new Point(workspacePadding.left + workspacePadding.right,
1340 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001341 }
1342
1343 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001344 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1345 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001346 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001347 private void updateWorkspacePadding() {
1348 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001349 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -08001350 padding.top = 0;
1351 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001352 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001353 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -07001354 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -07001355 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -07001356 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001357 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -07001358 }
Winson Chungb3800242013-10-24 11:01:54 -07001359 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001360 // Pad the bottom of the workspace with hotseat bar
1361 // and leave a bit of space in case a widget go all the way down
Thales Lima79456492023-05-23 11:32:22 +01001362 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding - mInsets.bottom;
1363 if (!mIsResponsiveGrid) {
1364 paddingBottom +=
1365 workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace;
1366 }
1367 int paddingTop = workspaceTopPadding + (mIsScalableGrid ? 0 : edgeMarginPx);
Pat Manning08610ca2022-04-05 21:03:16 +01001368 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001369
Pat Manning08610ca2022-04-05 21:03:16 +01001370 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001371 }
Pat Manning08610ca2022-04-05 21:03:16 +01001372 insetPadding(workspacePadding, cellLayoutPaddingPx);
1373 }
1374
1375 private void insetPadding(Rect paddings, Rect insets) {
1376 insets.left = Math.min(insets.left, paddings.left);
1377 paddings.left -= insets.left;
1378
1379 insets.top = Math.min(insets.top, paddings.top);
1380 paddings.top -= insets.top;
1381
1382 insets.right = Math.min(insets.right, paddings.right);
1383 paddings.right -= insets.right;
1384
1385 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1386 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001387 }
1388
Sunny Goyal57b22792021-05-25 14:35:01 -07001389 /**
1390 * Returns the padding for hotseat view
1391 */
1392 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001393 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001394 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001395 // The hotseat icons will be placed in the middle of the hotseat cells.
1396 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1397 // in vertical bar layout.
1398 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1399 // is set to account for that difference.
1400 float diffOverlapFactor = iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
Pat Manning08610ca2022-04-05 21:03:16 +01001401 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1402 - diffOverlapFactor), 0);
1403 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001404 + diffOverlapFactor), 0);
1405
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001406 if (isSeascape()) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001407 hotseatBarPadding.set(mInsets.left + hotseatBarSidePaddingStartPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001408 hotseatBarSidePaddingEndPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001409 } else {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001410 hotseatBarPadding.set(hotseatBarSidePaddingEndPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001411 mInsets.right + hotseatBarSidePaddingStartPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001412 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001413 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001414 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001415 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1416 int hotseatBarTopPadding =
1417 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001418
Thales Lima6a590062022-11-22 15:52:49 +00001419 int hotseatWidth = getHotseatRequiredWidth();
Helen Cheuke76291f2023-02-14 17:11:05 +00001420 int startSpacing;
1421 int endSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001422 // Hotseat aligns to the left with nav buttons
1423 if (hotseatBarEndOffset > 0) {
Jon Mirandae17a9492023-03-08 16:42:20 -08001424 startSpacing = inlineNavButtonsEndSpacingPx;
Helen Cheuke76291f2023-02-14 17:11:05 +00001425 endSpacing = availableWidthPx - hotseatWidth - startSpacing + hotseatBorderSpace;
1426 } else {
1427 startSpacing = (availableWidthPx - hotseatWidth) / 2;
1428 endSpacing = startSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001429 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001430 startSpacing += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001431
Helen Cheuke76291f2023-02-14 17:11:05 +00001432 hotseatBarPadding.top = hotseatBarTopPadding;
1433 hotseatBarPadding.bottom = hotseatBarBottomPadding;
Alex Chau51da2192022-05-20 13:32:10 +01001434 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001435 if (isRtl) {
Helen Cheuke76291f2023-02-14 17:11:05 +00001436 hotseatBarPadding.left = endSpacing;
1437 hotseatBarPadding.right = startSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001438 } else {
Helen Cheuke76291f2023-02-14 17:11:05 +00001439 hotseatBarPadding.left = startSpacing;
1440 hotseatBarPadding.right = endSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001441 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001442
Thales Lima79456492023-05-23 11:32:22 +01001443 } else if (mIsScalableGrid) {
Alex Chau206ede92022-08-01 17:46:12 +01001444 int sideSpacing = (availableWidthPx - hotseatQsbWidth) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001445 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001446 0,
Thales Lima425f6822022-05-10 13:44:58 -03001447 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001448 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001449 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001450 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1451 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1452 // for this, we pad the left and right of the hotseat with half of the difference of a
1453 // workspace cell vs a hotseat cell.
1454 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001455 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001456 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001457 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001458 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1459 + mInsets.left,
1460 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001461 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001462 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001463 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001464 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001465 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001466 }
1467
Andy Wickhambd9a1802023-06-08 16:33:15 -07001468 /** The margin between the edge of all apps and the edge of the first icon. */
1469 public int getAllAppsIconStartMargin() {
1470 int allAppsSpacing;
1471 if (isVerticalBarLayout()) {
1472 // On phones, the landscape layout uses a different setup.
1473 allAppsSpacing = workspacePadding.left + workspacePadding.right;
1474 } else {
1475 allAppsSpacing = allAppsLeftRightPadding * 2 + allAppsLeftRightMargin * 2;
1476 }
1477
1478 int cellWidth = DeviceProfile.calculateCellWidth(
1479 availableWidthPx - allAppsSpacing,
1480 0 /* borderSpace */,
1481 numShownAllAppsColumns);
1482 int iconVisibleSize = Math.round(ICON_VISIBLE_AREA_FACTOR * allAppsIconSizePx);
1483 int iconAlignmentMargin = (cellWidth - iconVisibleSize) / 2;
1484 return allAppsLeftRightPadding + iconAlignmentMargin;
1485 }
1486
Thales Lima9938c2f2022-07-25 14:38:16 +01001487 private int getAdditionalQsbSpace() {
1488 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1489 }
1490
1491 /**
1492 * Calculate how much space the hotseat needs to be shown completely
1493 */
1494 private int getHotseatRequiredWidth() {
1495 int additionalQsbSpace = getAdditionalQsbSpace();
1496 return iconSizePx * numShownHotseatIcons
Thales Lima6a590062022-11-22 15:52:49 +00001497 + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1))
Thales Lima9938c2f2022-07-25 14:38:16 +01001498 + additionalQsbSpace;
1499 }
1500
Winsonfadbe8f2016-07-22 16:35:37 -07001501 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001502 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1503 */
1504 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001505 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001506 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1507 } else if (isTaskbarPresent) { // QSB on top
1508 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001509 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001510 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001511 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001512 }
1513
Thales Limab8c05952022-05-23 16:58:38 +01001514 /**
1515 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1516 */
1517 private int getHotseatBarBottomPadding() {
1518 if (isTaskbarPresent) { // QSB on top or inline
1519 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001520 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001521 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001522 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001523 }
1524
1525 /**
Alex Chau51da2192022-05-20 13:32:10 +01001526 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1527 */
1528 public int getTaskbarOffsetY() {
Jon Miranda9c478b62023-03-23 21:38:49 -07001529 int taskbarIconBottomSpace = (taskbarHeight - iconSizePx) / 2;
Alex Chau51da2192022-05-20 13:32:10 +01001530 int launcherIconBottomSpace =
1531 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001532 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001533 }
1534
1535 /**
Alex Chaua2fc7642022-04-21 14:20:23 +01001536 * Returns the number of pixels required below OverviewActions excluding insets.
1537 */
1538 public int getOverviewActionsClaimedSpaceBelow() {
Alex Chaud67ddc42022-09-30 18:15:56 +01001539 if (isTaskbarPresent) {
Jon Miranda9c478b62023-03-23 21:38:49 -07001540 return taskbarHeight + taskbarBottomMargin * 2;
Alex Chaud67ddc42022-09-30 18:15:56 +01001541 }
1542 return mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001543 }
1544
1545 /** Gets the space that the overview actions will take, including bottom margin. */
1546 public int getOverviewActionsClaimedSpace() {
Pat Manning7b8f7662023-01-18 14:48:30 +00001547 int overviewActionsSpace = isTablet && FeatureFlags.ENABLE_GRID_ONLY_OVERVIEW.get()
1548 ? 0
1549 : (overviewActionsTopMarginPx + overviewActionsHeight);
1550 return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
Alex Chaua2fc7642022-04-21 14:20:23 +01001551 }
1552
1553 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001554 * Takes the View and return the scales of width and height depending on the DeviceProfile
1555 * specifications
1556 *
1557 * @param itemInfo The tag of the widget view
1558 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1559 * height
1560 */
1561 @NonNull
1562 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1563 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1564 }
1565
1566 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001567 * @return the bounds for which the open folders should be contained within
1568 */
1569 public Rect getAbsoluteOpenFolderBounds() {
1570 if (isVerticalBarLayout()) {
1571 // Folders should only appear right of the drop target bar and left of the hotseat
1572 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1573 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001574 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001575 mInsets.top + availableHeightPx);
1576 } else {
1577 // Folders should only appear below the drop target bar and above the hotseat
Jon Miranda9c478b62023-03-23 21:38:49 -07001578 int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001579 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001580 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001581 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001582 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001583 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001584 }
1585 }
1586
Jon Miranda228877d2021-02-09 11:05:00 -05001587 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1588 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001589 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001590
Jon Miranda228877d2021-02-09 11:05:00 -05001591 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1592 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001593 }
1594
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001595 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001596 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1597 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1598 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001599 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001600 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001601 return isLandscape && transposeLayoutWithOrientation;
1602 }
1603
Sunny Goyal59d086c2018-05-07 17:31:40 -07001604 /**
1605 * Updates orientation information and returns true if it has changed from the previous value.
1606 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001607 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001608 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001609 boolean isSeascape = DisplayController.INSTANCE.get(context)
1610 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001611 if (mIsSeascape != isSeascape) {
1612 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001613 // Hotseat changing sides requires updating workspace left/right paddings
1614 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001615 return true;
1616 }
1617 }
1618 return false;
1619 }
1620
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001621 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001622 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001623 }
1624
Sunny Goyal07b69292018-01-08 14:19:34 -08001625 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001626 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001627 }
1628
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001629 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001630 switch (containerType) {
1631 case CellLayout.WORKSPACE:
1632 return cellHeightPx;
1633 case CellLayout.FOLDER:
1634 return folderCellHeightPx;
1635 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001636 // The hotseat is the only container where the cell height is going to be
1637 // different from the content within that cell.
1638 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001639 default:
1640 // ??
1641 return 0;
1642 }
1643 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001644
Jon Miranda58561d42021-03-17 10:51:54 -04001645 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001646 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001647 }
1648
Alex Chaue818bcb2022-09-02 17:27:11 +01001649 private String dpPointFToString(String name, PointF value) {
1650 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
1651 }
1652
Pat Manning5f74bfd2022-07-20 12:08:54 +01001653 /** Dumps various DeviceProfile variables to the specified writer. */
1654 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04001655 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001656 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001657
1658 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001659 writer.println(prefix + "\tisPhone:" + isPhone);
1660 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1661 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001662 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001663
1664 writer.println(prefix + "\tisLandscape:" + isLandscape);
1665 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001666 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001667
1668 writer.println(prefix + pxToDpStr("windowX", windowX));
1669 writer.println(prefix + pxToDpStr("windowY", windowY));
1670 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1671 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001672 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1673 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001674 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1675 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1676 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1677 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001678
1679 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1680
Thales Limac98b7812023-04-14 15:04:23 +01001681 writer.println(prefix + "\tisResponsiveGrid:" + mIsResponsiveGrid);
Thales Lima79456492023-05-23 11:32:22 +01001682 writer.println(prefix + "\tisScalableGrid:" + mIsScalableGrid);
Jon Miranda58561d42021-03-17 10:51:54 -04001683
Thales Lima83bedbf2021-10-05 17:47:39 +01001684 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001685 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1686 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1687 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001688
Alex Chaue818bcb2022-09-02 17:27:11 +01001689 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07001690
Jon Miranda58561d42021-03-17 10:51:54 -04001691 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1692 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1693
1694 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1695 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1696
Thales Lima83bedbf2021-10-05 17:47:39 +01001697 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1698 cellLayoutBorderSpacePx.x));
1699 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1700 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001701 writer.println(
1702 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
1703 writer.println(
1704 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
1705 writer.println(
1706 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01001707 writer.println(
1708 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01001709
Jon Miranda58561d42021-03-17 10:51:54 -04001710 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1711 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1712 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1713
Helen Cheuk599109b2023-02-23 17:15:39 +00001714 writer.println(prefix + "\tinv.numFolderRows: " + inv.numFolderRows);
1715 writer.println(prefix + "\tinv.numFolderColumns: " + inv.numFolderColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001716 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1717 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1718 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1719 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1720 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1721 folderChildDrawablePaddingPx));
Thales Limab35faed2022-09-05 16:30:01 -03001722 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx",
1723 folderCellLayoutBorderSpacePx));
Thales Limaa08a4432022-08-09 09:55:17 +01001724 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
1725 folderContentPaddingLeftRight));
1726 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03001727 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001728
Alex Chaue0227552022-04-06 19:44:43 +01001729 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001730 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
1731 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
1732 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
1733 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01001734
1735 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
1736 writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001737 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
1738 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04001739 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1740 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1741 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1742 allAppsIconDrawablePaddingPx));
1743 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001744 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001745 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
1746 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001747 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau62572c02022-07-25 18:36:37 +00001748 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
Alex Chau27b39b92022-01-14 18:02:18 +00001749 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001750
1751 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03001752 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04001753 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00001754 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Jon Miranda58561d42021-03-17 10:51:54 -04001755 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
1756 hotseatBarSidePaddingStartPx));
1757 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
1758 hotseatBarSidePaddingEndPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001759 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01001760 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
1761 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01001762 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
1763 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001764 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
1765 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
1766 hotseatLayoutPadding.top));
1767 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
1768 hotseatLayoutPadding.bottom));
1769 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
1770 hotseatLayoutPadding.left));
1771 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
1772 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001773 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001774 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001775 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01001776 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001777
1778 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001779 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda9c478b62023-03-23 21:38:49 -07001780 writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight));
1781 writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight));
1782 writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin));
1783 writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001784
Thales Lima83bedbf2021-10-05 17:47:39 +01001785 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1786 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001787 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
1788 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
1789 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00001790 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001791
Jon Mirandaab3c6812021-06-28 15:42:28 -07001792 writer.println(prefix + pxToDpStr("iconScale", iconScale));
1793 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04001794 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00001795 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001796
Thales Lima171ee662022-11-22 15:52:49 +00001797 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04001798 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
1799 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00001800
1801 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00001802 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
1803 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
1804 overviewTaskIconDrawableSizePx));
1805 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
1806 overviewTaskIconDrawableSizeGridPx));
1807 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
1808 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01001809 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
1810 overviewActionsTopMarginPx));
1811 writer.println(prefix + pxToDpStr("overviewActionsHeight",
1812 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00001813 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
1814 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00001815 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
1816 overviewActionsButtonSpacing));
1817 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
1818 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
1819 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01001820
Alex Chau62572c02022-07-25 18:36:37 +00001821 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001822 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00001823 writer.println(
1824 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001825
Pat Manning5f74bfd2022-07-20 12:08:54 +01001826 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
1827 getCellLayoutSpringLoadShrunkTop()));
1828 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
1829 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01001830 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
1831 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001832 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
1833 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01001834 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
1835 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Thales Lima79456492023-05-23 11:32:22 +01001836 if (mIsResponsiveGrid) {
1837 writer.println(prefix + "\tmResponsiveHeightSpec:" + mResponsiveHeightSpec.toString());
1838 writer.println(prefix + "\tmResponsiveWidthSpec:" + mResponsiveWidthSpec.toString());
Thales Limaabfe3642023-05-24 18:08:53 +01001839 writer.println(prefix + "\tmAllAppsResponsiveHeightSpec:"
1840 + mAllAppsResponsiveHeightSpec.toString());
1841 writer.println(prefix + "\tmAllAppsResponsiveWidthSpec:"
1842 + mAllAppsResponsiveWidthSpec.toString());
Thales Lima79456492023-05-23 11:32:22 +01001843 }
Jon Miranda58561d42021-03-17 10:51:54 -04001844 }
1845
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00001846 /** Returns a reduced representation of this DeviceProfile. */
1847 public String toSmallString() {
1848 return "isTablet:" + isTablet + ", "
1849 + "isMultiDisplay:" + isMultiDisplay + ", "
1850 + "widthPx:" + widthPx + ", "
1851 + "heightPx:" + heightPx + ", "
1852 + "insets:" + mInsets + ", "
1853 + "rotationHint:" + rotationHint;
1854 }
1855
Alex Chaua6907dc2022-03-18 15:24:07 +00001856 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07001857 Configuration config = new Configuration(c.getResources().getConfiguration());
1858 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03001859 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00001860 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07001861 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07001862 }
Sunny Goyalfde55052018-02-01 14:46:13 -08001863
1864 /**
1865 * Callback when a component changes the DeviceProfile associated with it, as a result of
1866 * configuration change
1867 */
1868 public interface OnDeviceProfileChangeListener {
1869
1870 /**
1871 * Called when the device profile is reassigned. Note that for layout and measurements, it
1872 * is sufficient to listen for inset changes. Use this callback when you need to perform
1873 * a one time operation.
1874 */
1875 void onDeviceProfileChanged(DeviceProfile dp);
1876 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001877
Sihua Mae04aa202022-07-18 12:43:56 -07001878 /**
1879 * Handler that deals with ItemInfo of the views for the DeviceProfile
1880 */
1881 @FunctionalInterface
1882 public interface ViewScaleProvider {
1883 /**
1884 * Get the scales from the view
1885 *
1886 * @param itemInfo The tag of the widget view
1887 * @return PointF instance containing the scale information, or null if using the default
1888 * app widget scale of this device profile.
1889 */
1890 @NonNull
1891 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
1892 }
1893
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001894 public static class Builder {
1895 private Context mContext;
1896 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07001897 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001898
Sunny Goyal19ff7282021-04-22 10:12:54 -07001899 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00001900 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001901
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001902 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001903 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00001904 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07001905 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001906
Sunny Goyal65190ae2022-08-02 14:16:26 -07001907 private SparseArray<DotRenderer> mDotRendererCache;
1908
Jon Miranda2b25ded2023-02-02 14:48:45 -08001909 private Consumer<DeviceProfile> mOverrideProvider;
1910
Sunny Goyalfd58da62020-08-11 12:06:49 -07001911 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001912 mContext = context;
1913 mInv = inv;
1914 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001915 }
1916
1917 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1918 mIsMultiWindowMode = isMultiWindowMode;
1919 return this;
1920 }
1921
Alex Chauab800f72022-12-13 17:46:06 +00001922 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
1923 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001924 return this;
1925 }
1926
Sunny Goyal65190ae2022-08-02 14:16:26 -07001927 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
1928 mDotRendererCache = dotRendererCache;
1929 return this;
1930 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07001931
1932 public Builder setWindowBounds(WindowBounds bounds) {
1933 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07001934 return this;
1935 }
1936
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001937 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1938 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1939 return this;
1940 }
1941
Alex Chau6ed408f2022-03-04 12:58:05 +00001942 public Builder setGestureMode(boolean isGestureMode) {
1943 mIsGestureMode = isGestureMode;
1944 return this;
1945 }
1946
Jon Miranda2b25ded2023-02-02 14:48:45 -08001947 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
1948 mOverrideProvider = overrideProvider;
1949 return this;
1950 }
1951
Sihua Mae04aa202022-07-18 12:43:56 -07001952 /**
1953 * Set the viewScaleProvider for the builder
1954 *
1955 * @param viewScaleProvider The viewScaleProvider to be set for the
Thales Limae9273ea2023-01-26 12:33:52 +00001956 * DeviceProfile
Sihua Mae04aa202022-07-18 12:43:56 -07001957 * @return This builder
1958 */
1959 @NonNull
1960 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
1961 mViewScaleProvider = viewScaleProvider;
1962 return this;
1963 }
1964
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001965 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001966 if (mWindowBounds == null) {
1967 throw new IllegalArgumentException("Window bounds not set");
1968 }
1969 if (mTransposeLayoutWithOrientation == null) {
1970 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
1971 }
Alex Chau6ed408f2022-03-04 12:58:05 +00001972 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01001973 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00001974 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001975 if (mDotRendererCache == null) {
1976 mDotRendererCache = new SparseArray<>();
1977 }
Sihua Mae04aa202022-07-18 12:43:56 -07001978 if (mViewScaleProvider == null) {
1979 mViewScaleProvider = DEFAULT_PROVIDER;
1980 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08001981 if (mOverrideProvider == null) {
1982 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
1983 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001984 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00001985 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jon Miranda2b25ded2023-02-02 14:48:45 -08001986 mIsGestureMode, mViewScaleProvider, mOverrideProvider);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001987 }
1988 }
1989
Winson Chungb3800242013-10-24 11:01:54 -07001990}