blob: a16627154bc3312873ff44d7ff9db8c3ba65e76f [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 Lima2759aa32023-06-05 16:25:45 +010061import com.android.launcher3.util.IconSizeSteps;
Thales Limac98b7812023-04-14 15:04:23 +010062import com.android.launcher3.util.ResourceHelper;
Sunny Goyalb46703d2020-05-27 17:52:03 -070063import com.android.launcher3.util.WindowBounds;
Thales Limac98b7812023-04-14 15:04:23 +010064import com.android.launcher3.workspace.CalculatedWorkspaceSpec;
65import com.android.launcher3.workspace.WorkspaceSpecs;
Winson1f064272016-07-18 17:18:02 -070066
Jon Miranda58561d42021-03-17 10:51:54 -040067import java.io.PrintWriter;
Alex Chaue818bcb2022-09-02 17:27:11 +010068import java.util.Locale;
Jon Miranda2b25ded2023-02-02 14:48:45 -080069import java.util.function.Consumer;
Jon Miranda58561d42021-03-17 10:51:54 -040070
Sunny Goyal35c7b192021-04-20 16:51:10 -070071@SuppressLint("NewApi")
Winson Chungb3800242013-10-24 11:01:54 -070072public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070073
Sunny Goyal8b9919d2021-04-07 14:45:17 -070074 private static final int DEFAULT_DOT_SIZE = 100;
Alex Chau206ede92022-08-01 17:46:12 +010075 private static final float ALL_APPS_TABLET_MAX_ROWS = 5.5f;
Thales Limab35faed2022-09-05 16:30:01 -030076 private static final float MIN_FOLDER_TEXT_SIZE_SP = 16f;
Sunny Goyal6c304b12023-04-10 12:03:04 -070077 private static final float MIN_WIDGET_PADDING_DP = 6f;
Alex Chau206ede92022-08-01 17:46:12 +010078
Sihua Mae04aa202022-07-18 12:43:56 -070079 public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f);
80 public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE;
Thales Limaabfe3642023-05-24 18:08:53 +010081 public static final Consumer<DeviceProfile> DEFAULT_DIMENSION_PROVIDER = dp -> {
82 };
Sihua Mae04aa202022-07-18 12:43:56 -070083
Adam Cohen2e6da152015-05-06 11:42:25 -070084 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070085 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070086 private final DisplayMetrics mMetrics;
Thales Lima2759aa32023-06-05 16:25:45 +010087 private final IconSizeSteps mIconSizeSteps;
Winson Chungbe876472014-05-14 14:15:20 -070088
Sunny Goyalc6205602015-05-21 20:46:33 -070089 // Device properties
90 public final boolean isTablet;
Sunny Goyalc6205602015-05-21 20:46:33 -070091 public final boolean isPhone;
92 public final boolean transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +000093 public final boolean isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -070094 public final boolean isTwoPanels;
Thales Limaa1012902022-01-13 17:58:42 +000095 public final boolean isQsbInline;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -070096
Sunny Goyalc6205602015-05-21 20:46:33 -070097 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -070098 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -080099 public final boolean isMultiWindowMode;
Alex Chau6ed408f2022-03-04 12:58:05 +0000100 public final boolean isGestureMode;
Sunny Goyald70e75a2018-02-22 10:07:32 -0800101
Sunny Goyal0addbf02020-04-28 14:17:35 -0700102 public final int windowX;
103 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -0700104 public final int widthPx;
105 public final int heightPx;
106 public final int availableWidthPx;
107 public final int availableHeightPx;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800108 public final int rotationHint;
Jon Mirandabba64512019-03-27 10:54:17 -0700109
110 public final float aspectRatio;
111
Thales Lima79456492023-05-23 11:32:22 +0100112 private final boolean mIsScalableGrid;
Thales Lima83bedbf2021-10-05 17:47:39 +0100113 private final int mTypeIndex;
Jon Mirandae126d722021-02-25 10:45:20 -0500114
Thales Limac98b7812023-04-14 15:04:23 +0100115 // Responsive grid
116 private final boolean mIsResponsiveGrid;
117 private WorkspaceSpecs mWorkspaceSpecs;
118 private CalculatedWorkspaceSpec mResponsiveWidthSpec;
119 private CalculatedWorkspaceSpec mResponsiveHeightSpec;
Thales Limaabfe3642023-05-24 18:08:53 +0100120 private AllAppsSpecs mAllAppsSpecs;
121 private CalculatedAllAppsSpec mAllAppsResponsiveWidthSpec;
122 private CalculatedAllAppsSpec mAllAppsResponsiveHeightSpec;
Thales Limac98b7812023-04-14 15:04:23 +0100123
Tony Wickhamd6b40372015-09-23 18:37:57 -0700124 /**
125 * The maximum amount of left/right workspace padding as a percentage of the screen width.
126 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
127 * 7% of the screen width can be used as right padding.
128 */
129 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -0700130
Jon Miranda3f9bab22017-07-28 14:50:17 -0700131 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700132 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda80dda302021-07-28 14:14:59 -0700133 private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252;
134 private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700135
Sunny Goyalc6205602015-05-21 20:46:33 -0700136 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +0100137 public final int desiredWorkspaceHorizontalMarginOriginalPx;
138 public int desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100139 public int gridVisualizationPaddingX;
140 public int gridVisualizationPaddingY;
Thales Lima78d00ad2021-09-30 11:29:06 +0100141 public Point cellLayoutBorderSpaceOriginalPx;
142 public Point cellLayoutBorderSpacePx;
Pat Manning08610ca2022-04-05 21:03:16 +0100143 public Rect cellLayoutPaddingPx = new Rect();
144
Sunny Goyalc6205602015-05-21 20:46:33 -0700145 public final int edgeMarginPx;
Alex Chau0c4e11b2022-07-08 18:41:36 +0100146 public final float workspaceContentScale;
Alex Chau906d8822022-05-23 10:42:25 +0100147 public final int workspaceSpringLoadedMinNextPageVisiblePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700148
Jon Miranda58561d42021-03-17 10:51:54 -0400149 private final int extraSpace;
Thales Lima171ee662022-11-22 15:52:49 +0000150 private int maxEmptySpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500151 public int workspaceTopPadding;
152 public int workspaceBottomPadding;
153
Tony Wickham5edf9e22020-03-27 20:06:52 -0700154 // Workspace page indicator
155 public final int workspacePageIndicatorHeight;
156 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700157
Sunny Goyalc6205602015-05-21 20:46:33 -0700158 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400159 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700160 public int iconSizePx;
161 public int iconTextSizePx;
162 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700163 public int iconDrawablePaddingOriginalPx;
Thales Lima79456492023-05-23 11:32:22 +0100164 public boolean iconCenterVertically;
Winson Chungb3800242013-10-24 11:01:54 -0700165
Jon Mirandaab3c6812021-06-28 15:42:28 -0700166 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800167 public int cellWidthPx;
168 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700169 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800170
Thales Lima79456492023-05-23 11:32:22 +0100171 public int cellYPaddingPx = -1;
Jon Mirandae126d722021-02-25 10:45:20 -0500172
Sunny Goyalc6205602015-05-21 20:46:33 -0700173 // Folder
Jon Mirandae126d722021-02-25 10:45:20 -0500174 public float folderLabelTextScale;
175 public int folderLabelTextSizePx;
Thales Limab35faed2022-09-05 16:30:01 -0300176 public int folderFooterHeightPx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700177 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700178 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700179
Jon Mirandae126d722021-02-25 10:45:20 -0500180 // Folder content
Thales Limab35faed2022-09-05 16:30:01 -0300181 public int folderCellLayoutBorderSpacePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500182 public int folderContentPaddingLeftRight;
183 public int folderContentPaddingTop;
184
Jon Mirandabf7d8122016-11-03 15:29:29 -0700185 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700186 public int folderCellWidthPx;
187 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700188
189 // Folder child
190 public int folderChildIconSizePx;
191 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700192 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700193
Sunny Goyalc6205602015-05-21 20:46:33 -0700194 // Hotseat
Thales Lima9938c2f2022-07-25 14:38:16 +0100195 public int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700196 public int hotseatCellHeightPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100197 public final boolean areNavButtonsInline;
Jon Miranda18751b62017-07-31 17:25:27 -0700198 // In portrait: size = height, in landscape: size = width
199 public int hotseatBarSizePx;
Thales Limab8c05952022-05-23 16:58:38 +0100200 public int hotseatBarBottomSpacePx;
Pat Manning26f70f72022-07-07 13:50:39 +0100201 public int hotseatBarEndOffset;
Thales Limab8c05952022-05-23 16:58:38 +0100202 public int hotseatQsbSpace;
Pat Manningde25c0d2022-04-05 19:11:26 +0100203 public int springLoadedHotseatBarTopMarginPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700204 // Start is the side next to the nav bar, end is the side next to the workspace
205 public final int hotseatBarSidePaddingStartPx;
206 public final int hotseatBarSidePaddingEndPx;
Alex Chau206ede92022-08-01 17:46:12 +0100207 public int hotseatQsbWidth; // only used when isQsbInline
Sunny Goyal57b22792021-05-25 14:35:01 -0700208 public final int hotseatQsbHeight;
Thales Limab8c05952022-05-23 16:58:38 +0100209 public final int hotseatQsbVisualHeight;
210 private final int hotseatQsbShadowHeight;
Thales Limadd027342022-01-07 12:54:37 +0000211 public int hotseatBorderSpace;
Thales Limaffc68b02023-01-09 16:20:23 +0000212 private final int mMinHotseatIconSpacePx;
213 private final int mMinHotseatQsbWidthPx;
214 private final int mMaxHotseatIconSpacePx;
Jon Mirandae17a9492023-03-08 16:42:20 -0800215 public final int inlineNavButtonsEndSpacingPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700216
Alex Chau3d2c0622022-09-01 21:28:14 +0100217 // Bottom sheets
218 public int bottomSheetTopPadding;
219 public int bottomSheetOpenDuration;
220 public int bottomSheetCloseDuration;
221 public float bottomSheetWorkspaceScale;
222 public float bottomSheetDepth;
223
Sunny Goyalc6205602015-05-21 20:46:33 -0700224 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000225 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000226 public int allAppsShiftRange;
227 public int allAppsTopPadding;
Alex Chau3d2c0622022-09-01 21:28:14 +0100228 public int allAppsOpenDuration;
229 public int allAppsCloseDuration;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700230 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700231 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700232 public int allAppsIconSizePx;
233 public int allAppsIconDrawablePaddingPx;
sfufa@google.comde013292021-09-21 18:22:44 -0700234 public int allAppsLeftRightPadding;
Alex Chau27b39b92022-01-14 18:02:18 +0000235 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700236 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700237 public float allAppsIconTextSizePx;
238
Zak Cohen334efeb2021-03-19 16:42:07 -0700239 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700240 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000241 public int overviewTaskIconSizePx;
Alex Chauac9df382021-08-02 19:08:41 +0100242 public int overviewTaskIconDrawableSizePx;
243 public int overviewTaskIconDrawableSizeGridPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000244 public int overviewTaskThumbnailTopMarginPx;
Alex Chau19c6eca2022-03-10 20:12:56 +0000245 public final int overviewActionsHeight;
Alex Chaua2fc7642022-04-21 14:20:23 +0100246 public final int overviewActionsTopMarginPx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000247 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100248 public int overviewPageSpacing;
249 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000250 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700251
Jeremy Sim0ac47082022-10-10 13:59:40 -0700252 // Split staging
253 public int splitPlaceholderInset;
254
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800255 // Widgets
Sihua Mae04aa202022-07-18 12:43:56 -0700256 private final ViewScaleProvider mViewScaleProvider;
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800257
Sunny Goyal47328fd2016-05-25 18:56:41 -0700258 // Drop Target
259 public int dropTargetBarSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100260 public int dropTargetBarTopMarginPx;
261 public int dropTargetBarBottomMarginPx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100262 public int dropTargetDragPaddingPx;
263 public int dropTargetTextSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100264 public int dropTargetHorizontalPaddingPx;
265 public int dropTargetVerticalPaddingPx;
266 public int dropTargetGapPx;
Alex Chau5b019302022-05-23 10:42:25 +0100267 public int dropTargetButtonWorkspaceEdgeGapPx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700268
Winson1f064272016-07-18 17:18:02 -0700269 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800270 private final Rect mInsets = new Rect();
271 public final Rect workspacePadding = new Rect();
Sunny Goyal6c304b12023-04-10 12:03:04 -0700272 // Additional padding added to the widget inside its cellSpace. It is applied outside
273 // the widgetView, such that the actual view size is same as the widget size.
274 public final Rect widgetPadding = new Rect();
275
Jon Miranda0bd63d12019-03-06 17:29:29 -0800276 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700277 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700278
Tony Wickhamf34bee82018-12-03 18:11:39 -0800279 // Notification dots
Sunny Goyal65190ae2022-08-02 14:16:26 -0700280 public final DotRenderer mDotRendererWorkSpace;
281 public final DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800282
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100283 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800284 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000285 // Whether Taskbar will inset the bottom of apps by taskbarSize.
286 public boolean isTaskbarPresentInApps;
Jon Miranda9c478b62023-03-23 21:38:49 -0700287 public final int taskbarHeight;
288 public final int stashedTaskbarHeight;
289 public final int taskbarBottomMargin;
290 public final int taskbarIconSize;
Jon Miranda04f05102023-04-04 12:16:31 -0700291 // If true, used to layout taskbar in 3 button navigation mode.
292 public final boolean startAlignTaskbar;
Tony Wickham15883892021-02-12 11:24:40 -0800293
Alex Chaua02eddc2021-04-29 00:36:06 +0100294 // DragController
295 public int flingToDeleteThresholdVelocity;
296
Vinit Nayak17c4b332021-08-05 12:54:58 -0700297 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700298 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal65190ae2022-08-02 14:16:26 -0700299 SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
Alex Chauab800f72022-12-13 17:46:06 +0000300 boolean transposeLayoutWithOrientation, boolean isMultiDisplay, boolean isGestureMode,
Jon Miranda2b25ded2023-02-02 14:48:45 -0800301 @NonNull final ViewScaleProvider viewScaleProvider,
302 @NonNull final Consumer<DeviceProfile> dimensionOverrideProvider) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700303
Adam Cohen2e6da152015-05-06 11:42:25 -0700304 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700305 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800306 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500307 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +0000308 this.isMultiDisplay = isMultiDisplay;
Alex Chau6ed408f2022-03-04 12:58:05 +0000309 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700310 windowX = windowBounds.bounds.left;
311 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800312 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100313 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700314
Thales Limac98b7812023-04-14 15:04:23 +0100315 // TODO(b/241386436): shouldn't change any launcher behaviour
Thales Limaabfe3642023-05-24 18:08:53 +0100316 mIsResponsiveGrid = inv.workspaceSpecsId != INVALID_RESOURCE_HANDLE
317 && inv.allAppsSpecsId != INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100318
Thales Lima79456492023-05-23 11:32:22 +0100319 mIsScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000320 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700321 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000322 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700323 isPhone = !isTablet;
Alex Chauab800f72022-12-13 17:46:06 +0000324 isTwoPanels = isTablet && isMultiDisplay;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800325 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700326
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000327 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000328 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700329 ? Configuration.ORIENTATION_LANDSCAPE
330 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000331 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700332 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000333 mMetrics = res.getDisplayMetrics();
334
Thales Lima2759aa32023-06-05 16:25:45 +0100335 mIconSizeSteps = mIsResponsiveGrid ? new IconSizeSteps(res) : null;
336
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000337 // Determine sizes.
338 widthPx = windowBounds.bounds.width();
339 heightPx = windowBounds.bounds.height();
340 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100341 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000342
343 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Thales Lima83bedbf2021-10-05 17:47:39 +0100344 if (isTwoPanels) {
345 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000346 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100347 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000348 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100349 }
350 } else {
351 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000352 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100353 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000354 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100355 }
356 }
357
Jon Miranda9c478b62023-03-23 21:38:49 -0700358 if (DisplayController.isTransientTaskbar(context)) {
359 float invTransientIconSizeDp = inv.transientTaskbarIconSize[mTypeIndex];
360 taskbarIconSize = pxFromDp(invTransientIconSizeDp, mMetrics);
Jon Miranda95f44722023-06-06 19:48:19 -0700361 taskbarHeight = Math.round((taskbarIconSize * ICON_VISIBLE_AREA_FACTOR)
362 + (2 * res.getDimensionPixelSize(R.dimen.transient_taskbar_padding)));
Jon Miranda9c478b62023-03-23 21:38:49 -0700363 stashedTaskbarHeight =
364 res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_height);
365 taskbarBottomMargin =
366 res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin);
Jon Miranda04f05102023-04-04 12:16:31 -0700367 startAlignTaskbar = false;
Jon Miranda9c478b62023-03-23 21:38:49 -0700368 } else {
369 taskbarIconSize = pxFromDp(ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size),
370 mMetrics);
371 taskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_size);
372 stashedTaskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
373 taskbarBottomMargin = 0;
Jon Miranda04f05102023-04-04 12:16:31 -0700374 startAlignTaskbar = inv.startAlignTaskbar[mTypeIndex];
Tony Wickham15883892021-02-12 11:24:40 -0800375 }
Tony Wickham15883892021-02-12 11:24:40 -0800376
Winson Chungb3800242013-10-24 11:01:54 -0700377 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100378 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700379
Alex Chau51da2192022-05-20 13:32:10 +0100380 gridVisualizationPaddingX = res.getDimensionPixelSize(
381 R.dimen.grid_visualization_horizontal_cell_spacing);
382 gridVisualizationPaddingY = res.getDimensionPixelSize(
383 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500384
Alex Chaue0227552022-04-06 19:44:43 +0100385 bottomSheetTopPadding = mInsets.top // statusbar height
Andras Kloczl142b0542022-03-09 21:26:02 +0000386 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
387 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
Alex Chau3d2c0622022-09-01 21:28:14 +0100388 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
389 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
390 if (isTablet) {
391 bottomSheetWorkspaceScale = workspaceContentScale;
Alex Chauab800f72022-12-13 17:46:06 +0000392 if (isMultiDisplay && !ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH.get()) {
393 // TODO(b/259893832): Revert to use maxWallpaperScale to calculate bottomSheetDepth
394 // when screen recorder bug is fixed.
395 bottomSheetDepth = 1f;
396 } else {
397 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
398 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
399 // When depth is 1, wallpaper zoom is set to 1.
400 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
401 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
402 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
403 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
404 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100405 } else {
406 bottomSheetWorkspaceScale = 1f;
407 bottomSheetDepth = 0f;
408 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000409
Jon Mirandae126d722021-02-25 10:45:20 -0500410 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
Thales Limab35faed2022-09-05 16:30:01 -0300411
Thales Lima79456492023-05-23 11:32:22 +0100412 if (mIsScalableGrid && inv.folderStyle != INVALID_RESOURCE_HANDLE) {
Thales Limab35faed2022-09-05 16:30:01 -0300413 TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
Thales Limad852d652023-01-17 14:01:13 +0000414 R.styleable.FolderStyle);
Thales Limab35faed2022-09-05 16:30:01 -0300415 // These are re-set in #updateFolderCellSize if the grid is not scalable
416 folderCellHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000417 R.styleable.FolderStyle_folderCellHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300418 folderCellWidthPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000419 R.styleable.FolderStyle_folderCellWidth, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300420
421 folderContentPaddingTop = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000422 R.styleable.FolderStyle_folderTopPadding, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300423 folderCellLayoutBorderSpacePx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000424 R.styleable.FolderStyle_folderBorderSpace, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300425 folderFooterHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000426 R.styleable.FolderStyle_folderFooterHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300427 folderStyle.recycle();
428 } else {
429 folderCellLayoutBorderSpacePx = 0;
Thales Lima7eee74b2023-03-16 16:00:55 -0300430 folderFooterHeightPx = res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Thales Limab35faed2022-09-05 16:30:01 -0300431 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
432 }
Jon Mirandae126d722021-02-25 10:45:20 -0500433
Thales Lima85c942f2021-12-31 13:04:20 +0000434 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000435 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
436 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Thales Limae9273ea2023-01-26 12:33:52 +0000437 setupAllAppsStyle(context);
Jon Mirandae126d722021-02-25 10:45:20 -0500438
Tony Wickham5edf9e22020-03-27 20:06:52 -0700439 workspacePageIndicatorHeight = res.getDimensionPixelSize(
440 R.dimen.workspace_page_indicator_height);
441 mWorkspacePageIndicatorOverlapWorkspace =
442 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700443
Thales Limad852d652023-01-17 14:01:13 +0000444 TypedArray cellStyle;
445 if (inv.cellStyle != INVALID_RESOURCE_HANDLE) {
446 cellStyle = context.obtainStyledAttributes(inv.cellStyle,
447 R.styleable.CellStyle);
448 } else {
449 cellStyle = context.obtainStyledAttributes(R.style.CellStyleDefault,
450 R.styleable.CellStyle);
451 }
452 iconDrawablePaddingOriginalPx = cellStyle.getDimensionPixelSize(
453 R.styleable.CellStyle_iconDrawablePadding, 0);
454 cellStyle.recycle();
Alex Chaua02eddc2021-04-29 00:36:06 +0100455
Sunny Goyal47328fd2016-05-25 18:56:41 -0700456 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100457 dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
458 dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100459 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
460 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100461 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
462 R.dimen.drop_target_button_drawable_horizontal_padding);
463 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
464 R.dimen.drop_target_button_drawable_vertical_padding);
465 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100466 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
467 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100468
Alex Chau906d8822022-05-23 10:42:25 +0100469 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
470 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700471
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700472 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700473
Thales Limaa1012902022-01-13 17:58:42 +0000474 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100475 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
476 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
477
Thales Lima12d0eff2022-03-25 17:06:11 +0000478 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
479 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
480 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
481 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
482 && hotseatQsbHeight > 0;
Thales Lima79456492023-05-23 11:32:22 +0100483 isQsbInline = mIsScalableGrid && inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000484
Thales Lima425f6822022-05-10 13:44:58 -0300485 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100486 numShownHotseatIcons =
487 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000488
Sunny Goyal19ff7282021-04-22 10:12:54 -0700489 numShownAllAppsColumns =
490 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100491
492 int hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
493 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
494 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
495 // Have a little space between the inset and the QSB
496 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
497 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
498
499 // Only change the spaces if there is space
500 if (availableSpace > 0) {
501 // Make sure there is enough space between hotseat/QSB and QSB/navBar
502 if (availableSpace < minQsbMargin * 2) {
503 minQsbMargin = availableSpace / 2;
504 hotseatQsbSpace = minQsbMargin;
505 } else {
506 hotseatQsbSpace -= minQsbMargin;
507 }
508 }
509 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
510
Thales Limaa1012902022-01-13 17:58:42 +0000511 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100512 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
Thales Limaa1012902022-01-13 17:58:42 +0000513 }
Thales Lima425f6822022-05-10 13:44:58 -0300514
Pat Manningde25c0d2022-04-05 19:11:26 +0100515 springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
516 R.dimen.spring_loaded_hotseat_top_margin);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700517 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800518 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700519 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700520 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Thales Limab8c05952022-05-23 16:58:38 +0100521 updateHotseatSizes(pxFromDp(inv.iconSize[INDEX_DEFAULT], mMetrics));
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700522 if (areNavButtonsInline && !isPhone) {
Jon Mirandae17a9492023-03-08 16:42:20 -0800523 inlineNavButtonsEndSpacingPx =
Thales Limaffc68b02023-01-09 16:20:23 +0000524 res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing);
Pat Manning26f70f72022-07-07 13:50:39 +0100525 /*
526 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700527 * Spacing between nav buttons +
Thales Lima6a590062022-11-22 15:52:49 +0000528 * Space at the end for contextual buttons
Pat Manning26f70f72022-07-07 13:50:39 +0100529 */
530 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700531 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
Jon Mirandae17a9492023-03-08 16:42:20 -0800532 + inlineNavButtonsEndSpacingPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100533 } else {
Jon Mirandae17a9492023-03-08 16:42:20 -0800534 inlineNavButtonsEndSpacingPx = 0;
Pat Manning26f70f72022-07-07 13:50:39 +0100535 hotseatBarEndOffset = 0;
536 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700537
Thales Lima79456492023-05-23 11:32:22 +0100538 // Needs to be calculated after hotseatBarSizePx is correct,
539 // for the available height to be correct
540 if (mIsResponsiveGrid) {
541 mWorkspaceSpecs = new WorkspaceSpecs(new ResourceHelper(context, inv.workspaceSpecsId));
Thales Lima2759aa32023-06-05 16:25:45 +0100542 int availableResponsiveWidth =
543 availableWidthPx - (isVerticalBarLayout() ? hotseatBarSizePx : 0);
544 // don't use availableHeightPx because it subtracts bottom padding,
545 // but the workspace go behind it
546 int availableResponsiveHeight =
547 heightPx - mInsets.top - (isVerticalBarLayout() ? 0 : hotseatBarSizePx);
Thales Lima79456492023-05-23 11:32:22 +0100548 mResponsiveWidthSpec = mWorkspaceSpecs.getCalculatedWidthSpec(inv.numColumns,
Thales Lima2759aa32023-06-05 16:25:45 +0100549 availableResponsiveWidth);
Thales Lima79456492023-05-23 11:32:22 +0100550 mResponsiveHeightSpec = mWorkspaceSpecs.getCalculatedHeightSpec(inv.numRows,
Thales Lima2759aa32023-06-05 16:25:45 +0100551 availableResponsiveHeight);
Thales Limaabfe3642023-05-24 18:08:53 +0100552
553 mAllAppsSpecs = new AllAppsSpecs(new ResourceHelper(context, inv.allAppsSpecsId));
554 mAllAppsResponsiveWidthSpec = mAllAppsSpecs.getCalculatedWidthSpec(inv.numColumns,
555 mResponsiveWidthSpec.getAvailableSpace(), mResponsiveWidthSpec);
556 mAllAppsResponsiveHeightSpec = mAllAppsSpecs.getCalculatedHeightSpec(inv.numRows,
557 mResponsiveHeightSpec.getAvailableSpace(),
558 mResponsiveHeightSpec);
Thales Lima79456492023-05-23 11:32:22 +0100559 }
560
561 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
562 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
563
Alex Chau635b3ab2022-01-26 16:49:10 +0000564 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chau5fd9d492021-07-22 17:27:11 +0100565 overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100566 overviewTaskIconDrawableSizePx =
567 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
568 overviewTaskIconDrawableSizeGridPx =
569 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700570 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx;
Andy Wickham64896f32023-05-30 21:46:24 -0700571 // Don't add margin with floating search bar to minimize risk of overlapping.
572 overviewActionsTopMarginPx = FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get() ? 0
573 : res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000574 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
575 overviewActionsButtonSpacing = res.getDimensionPixelSize(
576 R.dimen.overview_actions_button_spacing);
Alex Chau19c6eca2022-03-10 20:12:56 +0000577 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700578 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000579 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700580
Jeremy Sim0ac47082022-10-10 13:59:40 -0700581 splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset);
582
Jon Miranda2ed276e2017-06-29 11:36:34 -0700583 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400584 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700585
Thales Lima79456492023-05-23 11:32:22 +0100586 calculateAndSetWorkspaceVerticalPadding(context, inv, extraSpace);
Pat Manning08610ca2022-04-05 21:03:16 +0100587
588 int cellLayoutPadding =
589 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
590 R.dimen.cell_layout_padding);
591 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
592 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800593 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800594
Thales Lima7eee74b2023-03-16 16:00:55 -0300595 // Folder scaling requires correct workspace paddings
596 updateAvailableFolderCellDimensions(res);
597
Thales Limaffc68b02023-01-09 16:20:23 +0000598 mMinHotseatIconSpacePx = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
599 mMinHotseatQsbWidthPx = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
600 mMaxHotseatIconSpacePx = areNavButtonsInline
Thales Lima6a590062022-11-22 15:52:49 +0000601 ? res.getDimensionPixelSize(R.dimen.max_hotseat_icon_space) : Integer.MAX_VALUE;
Thales Lima425f6822022-05-10 13:44:58 -0300602 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima6a590062022-11-22 15:52:49 +0000603 recalculateHotseatWidthAndBorderSpace();
Alex Chau206ede92022-08-01 17:46:12 +0100604
605 // AllApps height calculation depends on updated cellSize
606 if (isTablet) {
607 int collapseHandleHeight =
608 res.getDimensionPixelOffset(R.dimen.bottom_sheet_handle_area_height);
609 int contentHeight = heightPx - collapseHandleHeight - hotseatQsbHeight;
610 int targetContentHeight = (int) (allAppsCellHeightPx * ALL_APPS_TABLET_MAX_ROWS);
611 allAppsTopPadding = Math.max(mInsets.top, contentHeight - targetContentHeight);
612 allAppsShiftRange = heightPx - allAppsTopPadding;
613 } else {
614 allAppsTopPadding = 0;
615 allAppsShiftRange =
616 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
617 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100618 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
619 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300620
Alex Chaua02eddc2021-04-29 00:36:06 +0100621 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
622 R.dimen.drag_flingToDeleteMinVelocity);
623
Sihua Mae04aa202022-07-18 12:43:56 -0700624 mViewScaleProvider = viewScaleProvider;
625
Jon Miranda2b25ded2023-02-02 14:48:45 -0800626 dimensionOverrideProvider.accept(this);
627
Tony Wickham1237df02017-02-24 08:59:36 -0800628 // This is done last, after iconSizePx is calculated above.
Sunny Goyal799e1202023-02-09 10:54:28 -0800629 mDotRendererWorkSpace = createDotRenderer(context, iconSizePx, dotRendererCache);
630 mDotRendererAllApps = createDotRenderer(context, allAppsIconSizePx, dotRendererCache);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700631 }
632
633 private static DotRenderer createDotRenderer(
Sunny Goyal799e1202023-02-09 10:54:28 -0800634 @NonNull Context context, int size, @NonNull SparseArray<DotRenderer> cache) {
Sunny Goyal65190ae2022-08-02 14:16:26 -0700635 DotRenderer renderer = cache.get(size);
636 if (renderer == null) {
Sunny Goyal799e1202023-02-09 10:54:28 -0800637 renderer = new DotRenderer(size, getShapePath(context, DEFAULT_DOT_SIZE),
638 DEFAULT_DOT_SIZE);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700639 cache.put(size, renderer);
640 }
641 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700642 }
643
Thales Lima425f6822022-05-10 13:44:58 -0300644 /**
645 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
646 * width of the hotseat.
647 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100648 private int calculateQsbWidth(int hotseatBorderSpace) {
Thales Lima425f6822022-05-10 13:44:58 -0300649 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100650 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300651 return getIconToIconWidthForColumns(columns)
652 - iconSizePx * numShownHotseatIcons
653 - hotseatBorderSpace * numShownHotseatIcons;
654 } else {
655 int columns = inv.hotseatColumnSpan[mTypeIndex];
656 return getIconToIconWidthForColumns(columns);
657 }
658 }
Thales Lima2903a622022-03-17 13:52:19 +0000659
Thales Lima425f6822022-05-10 13:44:58 -0300660 private int getIconToIconWidthForColumns(int columns) {
661 return columns * getCellSize().x
662 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400663 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000664 }
665
Thales Limad90faab2021-09-21 17:18:47 +0100666 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
Thales Lima79456492023-05-23 11:32:22 +0100667 if (mIsResponsiveGrid) {
668 return mResponsiveWidthSpec.getStartPaddingPx();
669 }
670
Thales Limad90faab2021-09-21 17:18:47 +0100671 if (isVerticalBarLayout()) {
672 return 0;
673 }
674
Thales Lima79456492023-05-23 11:32:22 +0100675 return mIsScalableGrid
Thales Lima83bedbf2021-10-05 17:47:39 +0100676 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
677 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100678 }
679
Thales Lima79456492023-05-23 11:32:22 +0100680 private void calculateAndSetWorkspaceVerticalPadding(Context context,
681 InvariantDeviceProfile inv,
682 int extraSpace) {
683 if (mIsResponsiveGrid) {
684 workspaceTopPadding = mResponsiveHeightSpec.getStartPaddingPx();
685 workspaceBottomPadding = mResponsiveHeightSpec.getEndPaddingPx();
686 } else if (mIsScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
687 // Paddings were created assuming no scaling, so we first unscale the extra space.
688 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
689 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
690 DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
691 maxEmptySpace = padding.getMaxEmptySpacePx();
692
693 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
694 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
695
696 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
697 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
698 }
699 }
700
Thales Limab8c05952022-05-23 16:58:38 +0100701 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
702 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700703 // Ensure there is enough space for folder icons, which have a slightly larger radius.
704 hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR);
Thales Limab8c05952022-05-23 16:58:38 +0100705
Jon Miranda0d284852021-06-22 14:50:55 -0700706 if (isVerticalBarLayout()) {
707 hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
708 + hotseatBarSidePaddingEndPx;
Thales Limab8c05952022-05-23 16:58:38 +0100709 } else if (isQsbInline) {
710 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
711 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700712 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100713 hotseatBarSizePx = hotseatIconSizePx
714 + hotseatQsbSpace
715 + hotseatQsbVisualHeight
716 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700717 }
718 }
719
Thales Lima6a590062022-11-22 15:52:49 +0000720 /**
721 * Calculates the width of the hotseat, changing spaces between the icons and removing icons if
722 * necessary.
723 */
724 public void recalculateHotseatWidthAndBorderSpace() {
Thales Lima79456492023-05-23 11:32:22 +0100725 if (!mIsScalableGrid) return;
Thales Lima6a590062022-11-22 15:52:49 +0000726
727 int columns = inv.hotseatColumnSpan[mTypeIndex];
728 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
729 hotseatBorderSpace = calculateHotseatBorderSpace(hotseatWidthPx, /* numExtraBorder= */ 0);
Thales Lima9938c2f2022-07-25 14:38:16 +0100730 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
Thales Lima6a590062022-11-22 15:52:49 +0000731 // Spaces should be correct when the nav buttons are not inline
Thales Lima9938c2f2022-07-25 14:38:16 +0100732 if (!areNavButtonsInline) {
733 return;
734 }
735
Thales Lima6a590062022-11-22 15:52:49 +0000736 // The side space with inline buttons should be what is defined in InvariantDeviceProfile
Jon Mirandae17a9492023-03-08 16:42:20 -0800737 int sideSpacePx = inlineNavButtonsEndSpacingPx;
Thales Limaffc68b02023-01-09 16:20:23 +0000738 int maxHotseatWidthPx = availableWidthPx - sideSpacePx - hotseatBarEndOffset;
739 int maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
740 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000741 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100742
Thales Limaffc68b02023-01-09 16:20:23 +0000743 if (hotseatBorderSpace >= mMinHotseatIconSpacePx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100744 return;
745 }
746
747 // Border space can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000748 hotseatBorderSpace = mMinHotseatIconSpacePx;
Thales Lima6a590062022-11-22 15:52:49 +0000749 int requiredWidth = getHotseatRequiredWidth();
Thales Lima9938c2f2022-07-25 14:38:16 +0100750
751 // If there is an inline qsb, change its size
752 if (isQsbInline) {
Thales Limaffc68b02023-01-09 16:20:23 +0000753 hotseatQsbWidth -= requiredWidth - maxHotseatWidthPx;
754 if (hotseatQsbWidth >= mMinHotseatQsbWidthPx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100755 return;
756 }
757
758 // QSB can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000759 hotseatQsbWidth = mMinHotseatQsbWidthPx;
Thales Lima9938c2f2022-07-25 14:38:16 +0100760 }
761
Thales Limaffc68b02023-01-09 16:20:23 +0000762 maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
Thales Lima6a590062022-11-22 15:52:49 +0000763
Thales Lima9938c2f2022-07-25 14:38:16 +0100764 // If it still doesn't fit, start removing icons
765 do {
766 numShownHotseatIcons--;
Thales Limaffc68b02023-01-09 16:20:23 +0000767 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000768 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Limaffc68b02023-01-09 16:20:23 +0000769 } while (hotseatBorderSpace < mMinHotseatIconSpacePx && numShownHotseatIcons > 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100770
Thales Lima9938c2f2022-07-25 14:38:16 +0100771 }
772
Thales Lima78d00ad2021-09-30 11:29:06 +0100773 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100774 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100775 }
776
777 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima79456492023-05-23 11:32:22 +0100778 int horizontalSpacePx = 0;
779 int verticalSpacePx = 0;
Thales Lima78d00ad2021-09-30 11:29:06 +0100780
Thales Lima79456492023-05-23 11:32:22 +0100781 if (mIsResponsiveGrid) {
782 horizontalSpacePx = mResponsiveWidthSpec.getGutterPx();
783 verticalSpacePx = mResponsiveHeightSpec.getGutterPx();
784 } else if (mIsScalableGrid) {
785 horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
786 verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
787 }
Thales Lima78d00ad2021-09-30 11:29:06 +0100788
789 return new Point(horizontalSpacePx, verticalSpacePx);
790 }
791
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700792 public Info getDisplayInfo() {
793 return mInfo;
794 }
795
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700796 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800797 WindowBounds bounds = new WindowBounds(
798 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700799 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100800 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700801
802 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
803 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
804 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
805
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700806 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700807 .setWindowBounds(bounds)
Alex Chauab800f72022-12-13 17:46:06 +0000808 .setIsMultiDisplay(isMultiDisplay)
Alex Chau6ed408f2022-03-04 12:58:05 +0000809 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700810 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000811 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800812 }
813
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700814 public DeviceProfile copy(Context context) {
815 return toBuilder(context).build();
816 }
817
818 /**
819 * TODO: Move this to the builder as part of setMultiWindowMode
820 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700821 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700822 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700823 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700824 .setMultiWindowMode(true)
825 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800826
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800827 // We use these scales to measure and layout the widgets using their full invariant profile
828 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
829 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
830 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700831 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
832 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
833 profile = profile.toBuilder(context)
834 .setViewScaleProvider(i -> p)
835 .build();
836 }
837
838 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800839
Jon Miranda93e1f042016-11-11 14:13:04 -0800840 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700841 }
842
Adam Cohen63f1ec02014-08-12 09:23:13 -0700843 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400844 * Checks if there is enough space for labels on the workspace.
845 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700846 * It is important to call this method after the All Apps variables have been set.
847 */
Jon Miranda941375e2021-03-31 13:10:45 -0400848 private void hideWorkspaceLabelsIfNotEnoughSpace() {
849 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
850 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
851 - iconTextHeight;
852
853 // We want enough space so that the text is closer to its corresponding icon.
854 if (workspaceCellPaddingY < iconTextHeight) {
855 iconTextSizePx = 0;
856 iconDrawablePaddingPx = 0;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700857 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda941375e2021-03-31 13:10:45 -0400858 autoResizeAllAppsCells();
859 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700860 }
Jon Miranda1091e532017-07-21 13:31:50 -0700861
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700862 /**
Jon Miranda228877d2021-02-09 11:05:00 -0500863 * Returns the amount of extra (or unused) vertical space.
864 */
865 private int updateAvailableDimensions(Resources res) {
Alex Chaua68164d2022-12-15 16:16:03 +0000866 float invIconSizeDp = inv.iconSize[mTypeIndex];
867 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
868 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
869 iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
Thales Lima79456492023-05-23 11:32:22 +0100870 iconCenterVertically = mIsScalableGrid || mIsResponsiveGrid;
Alex Chaua68164d2022-12-15 16:16:03 +0000871
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700872 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800873
Pat Manning08610ca2022-04-05 21:03:16 +0100874 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -0500875
876 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +0100877 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +0000878 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -0500879 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500880 float scaleY = maxHeight / usedHeight;
881 boolean shouldScale = scaleY < 1f;
882
883 float scaleX = 1f;
Thales Lima79456492023-05-23 11:32:22 +0100884 if (mIsScalableGrid) {
Jon Mirandae126d722021-02-25 10:45:20 -0500885 // We scale to fit the cellWidth and cellHeight in the available space.
886 // The benefit of scalable grids is that we can get consistent aspect ratios between
887 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +0100888 float usedWidth =
889 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500890 // We do not subtract padding here, as we also scale the workspace padding if needed.
891 scaleX = availableWidthPx / usedWidth;
892 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700893 }
Jon Mirandae126d722021-02-25 10:45:20 -0500894
895 if (shouldScale) {
896 float scale = Math.min(scaleX, scaleY);
897 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +0100898 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -0500899 }
900
Jon Miranda228877d2021-02-09 11:05:00 -0500901 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700902 }
903
Pat Manninga2e14992022-04-22 11:29:17 +0100904 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +0100905 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
906 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
907 }
908
Pat Manninga2e14992022-04-22 11:29:17 +0100909 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +0000910 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +0100911 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
912 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -0500913 }
914
Jon Miranda6f7e9702019-09-16 14:44:14 -0700915 /**
916 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
917 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
918 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
919 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800920 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -0700921 // Icon scale should never exceed 1, otherwise pixellation may occur.
922 iconScale = Math.min(1f, scale);
923 cellScaleToFit = scale;
924
Jon Miranda18751b62017-07-31 17:25:27 -0700925 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800926 final boolean isVerticalLayout = isVerticalBarLayout();
Jon Mirandaab3c6812021-06-28 15:42:28 -0700927 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);
Thales Lima080d8902022-03-28 15:30:29 +0100928 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Thales Lima79456492023-05-23 11:32:22 +0100929 int cellTextAndPaddingHeight =
930 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Jon Mirandae126d722021-02-25 10:45:20 -0500931
Thales Lima79456492023-05-23 11:32:22 +0100932 if (mIsResponsiveGrid) {
933 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
934
935 cellWidthPx = mResponsiveWidthSpec.getCellSizePx();
936 cellHeightPx = mResponsiveHeightSpec.getCellSizePx();
Thales Lima79456492023-05-23 11:32:22 +0100937
Thales Lima2759aa32023-06-05 16:25:45 +0100938 if (cellWidthPx < iconSizePx) {
939 // get a smaller icon size
940 iconSizePx = mIconSizeSteps.getIconSmallerThan(cellWidthPx);
941 // calculate new cellContentHeight
942 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
943 }
944
945 while (iconSizePx > mIconSizeSteps.minimumIconSize()
946 && cellContentHeight > cellHeightPx) {
947 int extraHeightRequired = cellContentHeight - cellHeightPx;
948 int newPadding = iconDrawablePaddingPx - extraHeightRequired;
949 if (newPadding >= 0) {
950 // Responsive uses the padding without scaling
951 iconDrawablePaddingPx = iconDrawablePaddingOriginalPx = newPadding;
952 cellTextAndPaddingHeight =
953 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
954 } else {
955 // get a smaller icon size
956 iconSizePx = mIconSizeSteps.getNextLowerIconSize(iconSizePx);
957 }
958 // calculate new cellContentHeight
959 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
960 }
961
962 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Lima79456492023-05-23 11:32:22 +0100963 } else if (mIsScalableGrid) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100964 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
965 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +0000966
967 if (cellWidthPx < iconSizePx) {
968 // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger.
969 int numColumns = getPanelCount() * inv.numColumns;
970 int numBorders = numColumns - 1;
971 int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns;
972 if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) {
973 cellWidthPx = iconSizePx;
974 cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders;
975 } else {
976 // If it still doesn't fit, set borderSpace to 0 and distribute the space for
977 // cellWidth, and reduce iconSize.
978 cellWidthPx = (cellWidthPx * numColumns
979 + cellLayoutBorderSpacePx.x * numBorders) / numColumns;
980 iconSizePx = Math.min(iconSizePx, cellWidthPx);
981 cellLayoutBorderSpacePx.x = 0;
982 }
983 }
984
Alex Chaube753132022-12-09 16:46:54 +0000985 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
986 if (cellHeightPx < cellContentHeight) {
987 // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight
988 // bigger.
989 int numBorders = inv.numRows - 1;
990 int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows;
991 if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) {
992 cellHeightPx = cellContentHeight;
993 cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders;
994 } else {
Alex Chau06f36e82023-01-06 10:50:54 +0000995 // If it still doesn't fit, set borderSpace to 0 to recover space.
Alex Chaube753132022-12-09 16:46:54 +0000996 cellHeightPx = (cellHeightPx * inv.numRows
997 + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows;
Alex Chaube753132022-12-09 16:46:54 +0000998 cellLayoutBorderSpacePx.y = 0;
Alex Chau06f36e82023-01-06 10:50:54 +0000999 // Reduce iconDrawablePaddingPx to make cellContentHeight smaller.
1000 int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx;
1001 if (cellContentWithoutPadding <= cellHeightPx) {
1002 iconDrawablePaddingPx = cellContentHeight - cellHeightPx;
1003 } else {
1004 // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space,
1005 // then proportional reduce iconSizePx and iconTextSizePx to fit.
1006 iconDrawablePaddingPx = 0;
1007 float ratio = cellHeightPx / (float) cellContentWithoutPadding;
1008 iconSizePx = (int) (iconSizePx * ratio);
1009 iconTextSizePx = (int) (iconTextSizePx * ratio);
1010 }
1011 cellTextAndPaddingHeight =
1012 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +00001013 }
1014 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
1015 }
Jon Mirandae126d722021-02-25 10:45:20 -05001016 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +01001017 desiredWorkspaceHorizontalMarginPx =
1018 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -05001019 } else {
Jon Mirandae126d722021-02-25 10:45:20 -05001020 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001021 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR)
1022 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -05001023 + Utilities.calculateTextHeight(iconTextSizePx);
1024 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
1025 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
1026 && !isMultiWindowMode) {
1027 // Ensures that the label is closer to its corresponding icon. This is not an issue
1028 // with vertical bar layout or multi-window mode since the issue is handled
1029 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
1030 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
1031 iconDrawablePaddingPx = cellPaddingY;
1032 }
Jon Miranda846455e2017-10-02 14:58:52 -07001033 }
Jon Miranda18751b62017-07-31 17:25:27 -07001034
Sunny Goyalae190ff2020-04-14 00:19:01 +00001035 // All apps
Thales Limaabfe3642023-05-24 18:08:53 +01001036 if (mIsResponsiveGrid) {
1037 updateAllAppsWithResponsiveMeasures();
1038 } else {
1039 updateAllAppsIconSize(scale, res);
1040 }
1041 updateAllAppsContainerWidth();
1042 if (isVerticalBarLayout()) {
1043 hideWorkspaceLabelsIfNotEnoughSpace();
1044 }
Winson Chungb3800242013-10-24 11:01:54 -07001045
Thales Limab8c05952022-05-23 16:58:38 +01001046 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -07001047
Sunny Goyalbaec6ff2016-09-14 11:26:21 -07001048 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -07001049 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
1050 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Sunny Goyal6c304b12023-04-10 12:03:04 -07001051
1052 // Update widget padding:
1053 float minSpacing = pxFromDp(MIN_WIDGET_PADDING_DP, mMetrics);
1054 if (cellLayoutBorderSpacePx.x < minSpacing
1055 || cellLayoutBorderSpacePx.y < minSpacing) {
1056 widgetPadding.left = widgetPadding.right =
1057 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.x));
1058 widgetPadding.top = widgetPadding.bottom =
1059 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.y));
1060 } else {
1061 widgetPadding.setEmpty();
1062 }
Winson Chung0f785722015-04-08 10:27:49 -07001063 }
1064
Thales Lima425f6822022-05-10 13:44:58 -03001065 /**
Thales Lima6a590062022-11-22 15:52:49 +00001066 * This method calculates the space between the icons to achieve a certain width.
Thales Lima425f6822022-05-10 13:44:58 -03001067 */
Thales Lima6a590062022-11-22 15:52:49 +00001068 private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) {
Thales Lima9938c2f2022-07-25 14:38:16 +01001069 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
Thales Limaffc68b02023-01-09 16:20:23 +00001070 int hotseatBorderSpacePx =
Thales Lima6a590062022-11-22 15:52:49 +00001071 (int) (hotseatWidthPx - hotseatIconsTotalPx)
1072 / (numShownHotseatIcons - 1 + numExtraBorder);
Thales Limaffc68b02023-01-09 16:20:23 +00001073 return Math.min(hotseatBorderSpacePx, mMaxHotseatIconSpacePx);
Thales Lima425f6822022-05-10 13:44:58 -03001074 }
1075
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001076
1077 /**
1078 * Updates the iconSize for allApps* variants.
1079 */
Brian Isganitisa9a78112022-05-23 18:11:47 -07001080 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +01001081 allAppsBorderSpacePx = new Point(
1082 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
1083 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001084 // AllApps cells don't have real space between cells,
1085 // so we add the border space to the cell height
Alex Chaube753132022-12-09 16:46:54 +00001086 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics)
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001087 + allAppsBorderSpacePx.y;
1088 // but width is just the cell,
1089 // the border is added in #updateAllAppsContainerWidth
Thales Lima79456492023-05-23 11:32:22 +01001090 if (mIsScalableGrid) {
Alex Chaube753132022-12-09 16:46:54 +00001091 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1092 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001093 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001094 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001095
1096 if (allAppsCellWidthPx < allAppsIconSizePx) {
1097 // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to
1098 // make allAppsCellWidth bigger.
1099 int numBorders = inv.numAllAppsColumns - 1;
1100 int extraWidthRequired =
1101 (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns;
1102 if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) {
1103 allAppsCellWidthPx = allAppsIconSizePx;
1104 allAppsBorderSpacePx.x -= extraWidthRequired / numBorders;
1105 } else {
1106 // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space
1107 // for allAppsCellWidth, and reduce allAppsIconSize.
1108 allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns
1109 + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns;
1110 allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx);
1111 allAppsBorderSpacePx.x = 0;
1112 }
1113 }
1114
1115 int cellContentHeight = allAppsIconSizePx
1116 + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y;
1117 if (allAppsCellHeightPx < cellContentHeight) {
1118 // Increase allAppsCellHeight to fit its content.
1119 allAppsCellHeightPx = cellContentHeight;
1120 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001121 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001122 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
1123 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001124 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1125 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001126 allAppsIconDrawablePaddingPx =
1127 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001128 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001129 }
Thales Limaabfe3642023-05-24 18:08:53 +01001130 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001131
Thales Limaabfe3642023-05-24 18:08:53 +01001132 private void updateAllAppsWithResponsiveMeasures() {
1133 allAppsIconSizePx = iconSizePx;
1134 allAppsIconTextSizePx = iconTextSizePx;
1135 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
1136
1137 allAppsBorderSpacePx = new Point(
1138 mAllAppsResponsiveWidthSpec.getGutterPx(),
1139 mAllAppsResponsiveHeightSpec.getGutterPx()
1140 );
1141 allAppsCellHeightPx = mAllAppsResponsiveHeightSpec.getCellSizePx()
1142 + mAllAppsResponsiveHeightSpec.getGutterPx();
1143 allAppsCellWidthPx = mAllAppsResponsiveWidthSpec.getCellSizePx();
1144 allAppsLeftRightPadding = mAllAppsResponsiveWidthSpec.getStartPaddingPx();
1145 }
1146
1147 /**
1148 * Re-computes the all-apps cell size to be independent of workspace
1149 */
1150 public void autoResizeAllAppsCells() {
1151 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
1152 int topBottomPadding = textHeight;
1153 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
1154 + textHeight + (topBottomPadding * 2);
1155 }
1156
1157 private void updateAllAppsContainerWidth() {
1158 int cellLayoutHorizontalPadding =
1159 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
1160 if (isTablet) {
1161 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
1162 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
1163 + allAppsLeftRightPadding * 2;
1164 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
1165 } else {
1166 allAppsLeftRightPadding =
1167 Math.max(0, desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding
1168 - (allAppsBorderSpacePx.x / 2));
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001169 }
1170 }
1171
Thales Limaabfe3642023-05-24 18:08:53 +01001172 private void setupAllAppsStyle(Context context) {
1173 TypedArray allAppsStyle = context.obtainStyledAttributes(
1174 inv.allAppsStyle != INVALID_RESOURCE_HANDLE ? inv.allAppsStyle
1175 : R.style.AllAppsStyleDefault, R.styleable.AllAppsStyle);
1176
1177 allAppsLeftRightPadding = allAppsStyle.getDimensionPixelSize(
1178 R.styleable.AllAppsStyle_horizontalPadding, 0);
1179 allAppsStyle.recycle();
1180 }
1181
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001182 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001183 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001184
Thales Lima7eee74b2023-03-16 16:00:55 -03001185 // For usability we can't have the folder use the whole width of the screen
Sunny Goyal07b69292018-01-08 14:19:34 -08001186 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -08001187
Thales Lima7eee74b2023-03-16 16:00:55 -03001188 // Check if the folder fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -05001189 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Thales Lima7eee74b2023-03-16 16:00:55 -03001190 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx)
1191 + folderFooterHeightPx
1192 + folderContentPaddingTop;
1193 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001194 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -08001195
Thales Lima7eee74b2023-03-16 16:00:55 -03001196 // Check if the folder fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -05001197 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Thales Lima7eee74b2023-03-16 16:00:55 -03001198 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx)
1199 + folderContentPaddingLeftRight * 2;
1200 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001201 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -08001202
1203 float scale = Math.min(scaleX, scaleY);
1204 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001205 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001206 }
1207 }
1208
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001209 private void updateFolderCellSize(float scale, Resources res) {
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001210 float invIconSizeDp = inv.iconSize[mTypeIndex];
Sunny Goyal35c7b192021-04-20 16:51:10 -07001211 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001212 folderChildTextSizePx = pxFromSp(inv.iconTextSize[mTypeIndex], mMetrics, scale);
Thales Lima7eee74b2023-03-16 16:00:55 -03001213 folderLabelTextSizePx = Math.max(pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale),
Thales Limab35faed2022-09-05 16:30:01 -03001214 (int) (folderChildTextSizePx * folderLabelTextScale));
Jon Mirandabf7d8122016-11-03 15:29:29 -07001215
1216 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001217
Thales Lima79456492023-05-23 11:32:22 +01001218 if (mIsScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001219 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
Thales Lima7eee74b2023-03-16 16:00:55 -03001220 folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale);
1221 folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale);
1222 } else {
1223 folderCellWidthPx = roundPxValueFromFloat(folderCellWidthPx * scale);
1224 folderCellHeightPx = roundPxValueFromFloat(folderCellHeightPx * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001225 }
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001226
Thales Lima7eee74b2023-03-16 16:00:55 -03001227 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
1228 folderCellLayoutBorderSpacePx = roundPxValueFromFloat(
1229 folderCellLayoutBorderSpacePx * scale);
1230 folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale);
1231
Thales Limab35faed2022-09-05 16:30:01 -03001232 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx;
Jon Miranda823da222021-03-23 08:08:45 -04001233 } else {
1234 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1235 * scale);
1236 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1237 * scale);
1238
1239 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1240 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Lima7eee74b2023-03-16 16:00:55 -03001241 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001242 folderContentPaddingLeftRight =
1243 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1244 folderFooterHeightPx =
Thales Lima7eee74b2023-03-16 16:00:55 -03001245 roundPxValueFromFloat(
1246 res.getDimensionPixelSize(R.dimen.folder_footer_height_default)
1247 * scale);
1248
Jon Miranda823da222021-03-23 08:08:45 -04001249 }
1250
Jonathan Miranda9ad87462017-07-26 17:41:02 +00001251 folderChildDrawablePaddingPx = Math.max(0,
1252 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001253 }
1254
Winson1f064272016-07-18 17:18:02 -07001255 public void updateInsets(Rect insets) {
1256 mInsets.set(insets);
1257 }
1258
Sunny Goyalae6e3182019-04-30 12:04:37 -07001259 /**
1260 * The current device insets. This is generally same as the insets being dispatched to
1261 * {@link Insettable} elements, but can differ if the element is using a different profile.
1262 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001263 public Rect getInsets() {
1264 return mInsets;
1265 }
1266
Sunny Goyal756cd262015-08-20 12:33:21 -07001267 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001268 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001269 }
1270
Sunny Goyal19ff7282021-04-22 10:12:54 -07001271 public Point getCellSize(Point result) {
1272 if (result == null) {
1273 result = new Point();
1274 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001275
Pat Manning25d53342022-05-10 09:58:49 +00001276 int shortcutAndWidgetContainerWidth =
1277 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1278 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1279 inv.numColumns);
1280 int shortcutAndWidgetContainerHeight =
1281 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1282 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1283 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001284 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001285 }
1286
1287 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001288 * Returns the left and right space on the cell, which is the cell width - icon size
1289 */
1290 public int getCellHorizontalSpace() {
1291 return getCellSize().x - iconSizePx;
1292 }
1293
1294 /**
Pat Manning25d53342022-05-10 09:58:49 +00001295 * Gets the number of panels within the workspace.
1296 */
1297 public int getPanelCount() {
1298 return isTwoPanels ? 2 : 1;
1299 }
1300
1301 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001302 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1303 * bottom of the screen.
1304 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001305 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1306 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001307 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001308 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001309 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001310 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001311 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001312 }
1313
1314 /**
1315 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1316 */
Pat Manning25d53342022-05-10 09:58:49 +00001317 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001318 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001319 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001320 }
1321
1322 /**
1323 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1324 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001325 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001326 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001327 return heightPx - (isVerticalBarLayout()
1328 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001329 }
1330
Pat Manningea5c1d22022-04-14 10:58:16 +01001331 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001332 * Gets the scale of the workspace for the spring-loaded edit state.
1333 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001334 public float getWorkspaceSpringLoadScale(Context context) {
1335 float scale =
1336 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1337 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001338 scale = Math.min(scale, 1f);
1339
Pat Manninge63dd252022-08-02 16:15:29 +01001340 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001341 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001342 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001343 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001344 if (scaledWorkspaceWidth > maxAvailableWidth) {
1345 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1346 }
1347 return scale;
1348 }
1349
Pat Manning25d53342022-05-10 09:58:49 +00001350 /**
1351 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1352 *
1353 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1354 * layouts have two Cell Layouts per workspace.
1355 */
1356 public int getCellLayoutWidth() {
1357 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001358 }
1359
Pat Manning25d53342022-05-10 09:58:49 +00001360 /**
1361 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1362 *
1363 * <p>This is the height of a Workspace, less its vertical padding.
1364 */
1365 public int getCellLayoutHeight() {
1366 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001367 }
1368
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001369 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001370 return new Point(workspacePadding.left + workspacePadding.right,
1371 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001372 }
1373
1374 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001375 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1376 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001377 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001378 private void updateWorkspacePadding() {
1379 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001380 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -08001381 padding.top = 0;
1382 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001383 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001384 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -07001385 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -07001386 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -07001387 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001388 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -07001389 }
Winson Chungb3800242013-10-24 11:01:54 -07001390 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001391 // Pad the bottom of the workspace with hotseat bar
1392 // and leave a bit of space in case a widget go all the way down
Thales Lima79456492023-05-23 11:32:22 +01001393 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding - mInsets.bottom;
1394 if (!mIsResponsiveGrid) {
1395 paddingBottom +=
1396 workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace;
1397 }
1398 int paddingTop = workspaceTopPadding + (mIsScalableGrid ? 0 : edgeMarginPx);
Pat Manning08610ca2022-04-05 21:03:16 +01001399 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001400
Pat Manning08610ca2022-04-05 21:03:16 +01001401 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001402 }
Pat Manning08610ca2022-04-05 21:03:16 +01001403 insetPadding(workspacePadding, cellLayoutPaddingPx);
1404 }
1405
1406 private void insetPadding(Rect paddings, Rect insets) {
1407 insets.left = Math.min(insets.left, paddings.left);
1408 paddings.left -= insets.left;
1409
1410 insets.top = Math.min(insets.top, paddings.top);
1411 paddings.top -= insets.top;
1412
1413 insets.right = Math.min(insets.right, paddings.right);
1414 paddings.right -= insets.right;
1415
1416 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1417 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001418 }
1419
Sunny Goyal57b22792021-05-25 14:35:01 -07001420 /**
1421 * Returns the padding for hotseat view
1422 */
1423 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001424 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001425 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001426 // The hotseat icons will be placed in the middle of the hotseat cells.
1427 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1428 // in vertical bar layout.
1429 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1430 // is set to account for that difference.
1431 float diffOverlapFactor = iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
Pat Manning08610ca2022-04-05 21:03:16 +01001432 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1433 - diffOverlapFactor), 0);
1434 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001435 + diffOverlapFactor), 0);
1436
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001437 if (isSeascape()) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001438 hotseatBarPadding.set(mInsets.left + hotseatBarSidePaddingStartPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001439 hotseatBarSidePaddingEndPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001440 } else {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001441 hotseatBarPadding.set(hotseatBarSidePaddingEndPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001442 mInsets.right + hotseatBarSidePaddingStartPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001443 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001444 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001445 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001446 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1447 int hotseatBarTopPadding =
1448 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001449
Thales Lima6a590062022-11-22 15:52:49 +00001450 int hotseatWidth = getHotseatRequiredWidth();
Helen Cheuke76291f2023-02-14 17:11:05 +00001451 int startSpacing;
1452 int endSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001453 // Hotseat aligns to the left with nav buttons
1454 if (hotseatBarEndOffset > 0) {
Jon Mirandae17a9492023-03-08 16:42:20 -08001455 startSpacing = inlineNavButtonsEndSpacingPx;
Helen Cheuke76291f2023-02-14 17:11:05 +00001456 endSpacing = availableWidthPx - hotseatWidth - startSpacing + hotseatBorderSpace;
1457 } else {
1458 startSpacing = (availableWidthPx - hotseatWidth) / 2;
1459 endSpacing = startSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001460 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001461 startSpacing += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001462
Helen Cheuke76291f2023-02-14 17:11:05 +00001463 hotseatBarPadding.top = hotseatBarTopPadding;
1464 hotseatBarPadding.bottom = hotseatBarBottomPadding;
Alex Chau51da2192022-05-20 13:32:10 +01001465 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001466 if (isRtl) {
Helen Cheuke76291f2023-02-14 17:11:05 +00001467 hotseatBarPadding.left = endSpacing;
1468 hotseatBarPadding.right = startSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001469 } else {
Helen Cheuke76291f2023-02-14 17:11:05 +00001470 hotseatBarPadding.left = startSpacing;
1471 hotseatBarPadding.right = endSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001472 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001473
Thales Lima79456492023-05-23 11:32:22 +01001474 } else if (mIsScalableGrid) {
Alex Chau206ede92022-08-01 17:46:12 +01001475 int sideSpacing = (availableWidthPx - hotseatQsbWidth) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001476 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001477 0,
Thales Lima425f6822022-05-10 13:44:58 -03001478 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001479 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001480 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001481 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1482 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1483 // for this, we pad the left and right of the hotseat with half of the difference of a
1484 // workspace cell vs a hotseat cell.
1485 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001486 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001487 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001488 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001489 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1490 + mInsets.left,
1491 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001492 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001493 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001494 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001495 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001496 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001497 }
1498
Andy Wickhambd9a1802023-06-08 16:33:15 -07001499 /** The margin between the edge of all apps and the edge of the first icon. */
1500 public int getAllAppsIconStartMargin() {
1501 int allAppsSpacing;
1502 if (isVerticalBarLayout()) {
1503 // On phones, the landscape layout uses a different setup.
1504 allAppsSpacing = workspacePadding.left + workspacePadding.right;
1505 } else {
1506 allAppsSpacing = allAppsLeftRightPadding * 2 + allAppsLeftRightMargin * 2;
1507 }
1508
1509 int cellWidth = DeviceProfile.calculateCellWidth(
1510 availableWidthPx - allAppsSpacing,
1511 0 /* borderSpace */,
1512 numShownAllAppsColumns);
1513 int iconVisibleSize = Math.round(ICON_VISIBLE_AREA_FACTOR * allAppsIconSizePx);
1514 int iconAlignmentMargin = (cellWidth - iconVisibleSize) / 2;
1515 return allAppsLeftRightPadding + iconAlignmentMargin;
1516 }
1517
Thales Lima9938c2f2022-07-25 14:38:16 +01001518 private int getAdditionalQsbSpace() {
1519 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1520 }
1521
1522 /**
1523 * Calculate how much space the hotseat needs to be shown completely
1524 */
1525 private int getHotseatRequiredWidth() {
1526 int additionalQsbSpace = getAdditionalQsbSpace();
1527 return iconSizePx * numShownHotseatIcons
Thales Lima6a590062022-11-22 15:52:49 +00001528 + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1))
Thales Lima9938c2f2022-07-25 14:38:16 +01001529 + additionalQsbSpace;
1530 }
1531
Winsonfadbe8f2016-07-22 16:35:37 -07001532 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001533 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1534 */
1535 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001536 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001537 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1538 } else if (isTaskbarPresent) { // QSB on top
1539 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001540 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001541 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001542 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001543 }
1544
Thales Limab8c05952022-05-23 16:58:38 +01001545 /**
1546 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1547 */
1548 private int getHotseatBarBottomPadding() {
1549 if (isTaskbarPresent) { // QSB on top or inline
1550 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001551 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001552 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001553 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001554 }
1555
1556 /**
Alex Chau51da2192022-05-20 13:32:10 +01001557 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1558 */
1559 public int getTaskbarOffsetY() {
Jon Miranda9c478b62023-03-23 21:38:49 -07001560 int taskbarIconBottomSpace = (taskbarHeight - iconSizePx) / 2;
Alex Chau51da2192022-05-20 13:32:10 +01001561 int launcherIconBottomSpace =
1562 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001563 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001564 }
1565
1566 /**
Alex Chaua2fc7642022-04-21 14:20:23 +01001567 * Returns the number of pixels required below OverviewActions excluding insets.
1568 */
1569 public int getOverviewActionsClaimedSpaceBelow() {
Alex Chaud67ddc42022-09-30 18:15:56 +01001570 if (isTaskbarPresent) {
Jon Miranda9c478b62023-03-23 21:38:49 -07001571 return taskbarHeight + taskbarBottomMargin * 2;
Alex Chaud67ddc42022-09-30 18:15:56 +01001572 }
1573 return mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001574 }
1575
1576 /** Gets the space that the overview actions will take, including bottom margin. */
1577 public int getOverviewActionsClaimedSpace() {
Pat Manning7b8f7662023-01-18 14:48:30 +00001578 int overviewActionsSpace = isTablet && FeatureFlags.ENABLE_GRID_ONLY_OVERVIEW.get()
1579 ? 0
1580 : (overviewActionsTopMarginPx + overviewActionsHeight);
1581 return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
Alex Chaua2fc7642022-04-21 14:20:23 +01001582 }
1583
1584 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001585 * Takes the View and return the scales of width and height depending on the DeviceProfile
1586 * specifications
1587 *
1588 * @param itemInfo The tag of the widget view
1589 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1590 * height
1591 */
1592 @NonNull
1593 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1594 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1595 }
1596
1597 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001598 * @return the bounds for which the open folders should be contained within
1599 */
1600 public Rect getAbsoluteOpenFolderBounds() {
1601 if (isVerticalBarLayout()) {
1602 // Folders should only appear right of the drop target bar and left of the hotseat
1603 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1604 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001605 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001606 mInsets.top + availableHeightPx);
1607 } else {
1608 // Folders should only appear below the drop target bar and above the hotseat
Jon Miranda9c478b62023-03-23 21:38:49 -07001609 int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001610 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001611 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001612 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001613 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001614 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001615 }
1616 }
1617
Jon Miranda228877d2021-02-09 11:05:00 -05001618 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1619 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001620 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001621
Jon Miranda228877d2021-02-09 11:05:00 -05001622 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1623 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001624 }
1625
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001626 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001627 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1628 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1629 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001630 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001631 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001632 return isLandscape && transposeLayoutWithOrientation;
1633 }
1634
Sunny Goyal59d086c2018-05-07 17:31:40 -07001635 /**
1636 * Updates orientation information and returns true if it has changed from the previous value.
1637 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001638 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001639 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001640 boolean isSeascape = DisplayController.INSTANCE.get(context)
1641 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001642 if (mIsSeascape != isSeascape) {
1643 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001644 // Hotseat changing sides requires updating workspace left/right paddings
1645 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001646 return true;
1647 }
1648 }
1649 return false;
1650 }
1651
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001652 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001653 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001654 }
1655
Sunny Goyal07b69292018-01-08 14:19:34 -08001656 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001657 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001658 }
1659
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001660 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001661 switch (containerType) {
1662 case CellLayout.WORKSPACE:
1663 return cellHeightPx;
1664 case CellLayout.FOLDER:
1665 return folderCellHeightPx;
1666 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001667 // The hotseat is the only container where the cell height is going to be
1668 // different from the content within that cell.
1669 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001670 default:
1671 // ??
1672 return 0;
1673 }
1674 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001675
Jon Miranda58561d42021-03-17 10:51:54 -04001676 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001677 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001678 }
1679
Alex Chaue818bcb2022-09-02 17:27:11 +01001680 private String dpPointFToString(String name, PointF value) {
1681 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
1682 }
1683
Pat Manning5f74bfd2022-07-20 12:08:54 +01001684 /** Dumps various DeviceProfile variables to the specified writer. */
1685 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04001686 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001687 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001688
1689 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001690 writer.println(prefix + "\tisPhone:" + isPhone);
1691 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1692 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001693 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001694
1695 writer.println(prefix + "\tisLandscape:" + isLandscape);
1696 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001697 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001698
1699 writer.println(prefix + pxToDpStr("windowX", windowX));
1700 writer.println(prefix + pxToDpStr("windowY", windowY));
1701 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1702 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001703 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1704 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001705 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1706 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1707 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1708 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001709
1710 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1711
Thales Limac98b7812023-04-14 15:04:23 +01001712 writer.println(prefix + "\tisResponsiveGrid:" + mIsResponsiveGrid);
Thales Lima79456492023-05-23 11:32:22 +01001713 writer.println(prefix + "\tisScalableGrid:" + mIsScalableGrid);
Jon Miranda58561d42021-03-17 10:51:54 -04001714
Thales Lima83bedbf2021-10-05 17:47:39 +01001715 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001716 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1717 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1718 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001719
Alex Chaue818bcb2022-09-02 17:27:11 +01001720 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07001721
Jon Miranda58561d42021-03-17 10:51:54 -04001722 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1723 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1724
1725 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1726 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1727
Thales Lima83bedbf2021-10-05 17:47:39 +01001728 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1729 cellLayoutBorderSpacePx.x));
1730 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1731 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001732 writer.println(
1733 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
1734 writer.println(
1735 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
1736 writer.println(
1737 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01001738 writer.println(
1739 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01001740
Jon Miranda58561d42021-03-17 10:51:54 -04001741 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1742 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1743 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1744
Helen Cheuk599109b2023-02-23 17:15:39 +00001745 writer.println(prefix + "\tinv.numFolderRows: " + inv.numFolderRows);
1746 writer.println(prefix + "\tinv.numFolderColumns: " + inv.numFolderColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001747 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1748 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1749 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1750 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1751 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1752 folderChildDrawablePaddingPx));
Thales Limab35faed2022-09-05 16:30:01 -03001753 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx",
1754 folderCellLayoutBorderSpacePx));
Thales Limaa08a4432022-08-09 09:55:17 +01001755 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
1756 folderContentPaddingLeftRight));
1757 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03001758 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001759
Alex Chaue0227552022-04-06 19:44:43 +01001760 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001761 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
1762 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
1763 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
1764 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01001765
1766 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
1767 writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001768 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
1769 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04001770 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1771 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1772 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1773 allAppsIconDrawablePaddingPx));
1774 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001775 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001776 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
1777 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001778 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau62572c02022-07-25 18:36:37 +00001779 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
Alex Chau27b39b92022-01-14 18:02:18 +00001780 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001781
1782 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03001783 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04001784 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00001785 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Jon Miranda58561d42021-03-17 10:51:54 -04001786 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
1787 hotseatBarSidePaddingStartPx));
1788 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
1789 hotseatBarSidePaddingEndPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001790 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01001791 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
1792 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01001793 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
1794 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001795 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
1796 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
1797 hotseatLayoutPadding.top));
1798 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
1799 hotseatLayoutPadding.bottom));
1800 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
1801 hotseatLayoutPadding.left));
1802 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
1803 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001804 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001805 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001806 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01001807 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001808
1809 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001810 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda9c478b62023-03-23 21:38:49 -07001811 writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight));
1812 writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight));
1813 writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin));
1814 writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001815
Thales Lima83bedbf2021-10-05 17:47:39 +01001816 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1817 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001818 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
1819 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
1820 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00001821 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001822
Jon Mirandaab3c6812021-06-28 15:42:28 -07001823 writer.println(prefix + pxToDpStr("iconScale", iconScale));
1824 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04001825 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00001826 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001827
Thales Lima171ee662022-11-22 15:52:49 +00001828 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04001829 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
1830 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00001831
1832 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00001833 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
1834 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
1835 overviewTaskIconDrawableSizePx));
1836 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
1837 overviewTaskIconDrawableSizeGridPx));
1838 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
1839 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01001840 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
1841 overviewActionsTopMarginPx));
1842 writer.println(prefix + pxToDpStr("overviewActionsHeight",
1843 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00001844 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
1845 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00001846 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
1847 overviewActionsButtonSpacing));
1848 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
1849 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
1850 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01001851
Alex Chau62572c02022-07-25 18:36:37 +00001852 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001853 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00001854 writer.println(
1855 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001856
Pat Manning5f74bfd2022-07-20 12:08:54 +01001857 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
1858 getCellLayoutSpringLoadShrunkTop()));
1859 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
1860 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01001861 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
1862 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001863 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
1864 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01001865 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
1866 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Thales Lima79456492023-05-23 11:32:22 +01001867 if (mIsResponsiveGrid) {
1868 writer.println(prefix + "\tmResponsiveHeightSpec:" + mResponsiveHeightSpec.toString());
1869 writer.println(prefix + "\tmResponsiveWidthSpec:" + mResponsiveWidthSpec.toString());
Thales Limaabfe3642023-05-24 18:08:53 +01001870 writer.println(prefix + "\tmAllAppsResponsiveHeightSpec:"
1871 + mAllAppsResponsiveHeightSpec.toString());
1872 writer.println(prefix + "\tmAllAppsResponsiveWidthSpec:"
1873 + mAllAppsResponsiveWidthSpec.toString());
Thales Lima79456492023-05-23 11:32:22 +01001874 }
Jon Miranda58561d42021-03-17 10:51:54 -04001875 }
1876
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00001877 /** Returns a reduced representation of this DeviceProfile. */
1878 public String toSmallString() {
1879 return "isTablet:" + isTablet + ", "
1880 + "isMultiDisplay:" + isMultiDisplay + ", "
1881 + "widthPx:" + widthPx + ", "
1882 + "heightPx:" + heightPx + ", "
1883 + "insets:" + mInsets + ", "
1884 + "rotationHint:" + rotationHint;
1885 }
1886
Alex Chaua6907dc2022-03-18 15:24:07 +00001887 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07001888 Configuration config = new Configuration(c.getResources().getConfiguration());
1889 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03001890 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00001891 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07001892 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07001893 }
Sunny Goyalfde55052018-02-01 14:46:13 -08001894
1895 /**
1896 * Callback when a component changes the DeviceProfile associated with it, as a result of
1897 * configuration change
1898 */
1899 public interface OnDeviceProfileChangeListener {
1900
1901 /**
1902 * Called when the device profile is reassigned. Note that for layout and measurements, it
1903 * is sufficient to listen for inset changes. Use this callback when you need to perform
1904 * a one time operation.
1905 */
1906 void onDeviceProfileChanged(DeviceProfile dp);
1907 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001908
Sihua Mae04aa202022-07-18 12:43:56 -07001909 /**
1910 * Handler that deals with ItemInfo of the views for the DeviceProfile
1911 */
1912 @FunctionalInterface
1913 public interface ViewScaleProvider {
1914 /**
1915 * Get the scales from the view
1916 *
1917 * @param itemInfo The tag of the widget view
1918 * @return PointF instance containing the scale information, or null if using the default
1919 * app widget scale of this device profile.
1920 */
1921 @NonNull
1922 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
1923 }
1924
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001925 public static class Builder {
1926 private Context mContext;
1927 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07001928 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001929
Sunny Goyal19ff7282021-04-22 10:12:54 -07001930 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00001931 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001932
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001933 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001934 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00001935 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07001936 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001937
Sunny Goyal65190ae2022-08-02 14:16:26 -07001938 private SparseArray<DotRenderer> mDotRendererCache;
1939
Jon Miranda2b25ded2023-02-02 14:48:45 -08001940 private Consumer<DeviceProfile> mOverrideProvider;
1941
Sunny Goyalfd58da62020-08-11 12:06:49 -07001942 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001943 mContext = context;
1944 mInv = inv;
1945 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001946 }
1947
1948 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1949 mIsMultiWindowMode = isMultiWindowMode;
1950 return this;
1951 }
1952
Alex Chauab800f72022-12-13 17:46:06 +00001953 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
1954 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001955 return this;
1956 }
1957
Sunny Goyal65190ae2022-08-02 14:16:26 -07001958 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
1959 mDotRendererCache = dotRendererCache;
1960 return this;
1961 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07001962
1963 public Builder setWindowBounds(WindowBounds bounds) {
1964 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07001965 return this;
1966 }
1967
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001968 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1969 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1970 return this;
1971 }
1972
Alex Chau6ed408f2022-03-04 12:58:05 +00001973 public Builder setGestureMode(boolean isGestureMode) {
1974 mIsGestureMode = isGestureMode;
1975 return this;
1976 }
1977
Jon Miranda2b25ded2023-02-02 14:48:45 -08001978 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
1979 mOverrideProvider = overrideProvider;
1980 return this;
1981 }
1982
Sihua Mae04aa202022-07-18 12:43:56 -07001983 /**
1984 * Set the viewScaleProvider for the builder
1985 *
1986 * @param viewScaleProvider The viewScaleProvider to be set for the
Thales Limae9273ea2023-01-26 12:33:52 +00001987 * DeviceProfile
Sihua Mae04aa202022-07-18 12:43:56 -07001988 * @return This builder
1989 */
1990 @NonNull
1991 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
1992 mViewScaleProvider = viewScaleProvider;
1993 return this;
1994 }
1995
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001996 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001997 if (mWindowBounds == null) {
1998 throw new IllegalArgumentException("Window bounds not set");
1999 }
2000 if (mTransposeLayoutWithOrientation == null) {
2001 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
2002 }
Alex Chau6ed408f2022-03-04 12:58:05 +00002003 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01002004 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00002005 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002006 if (mDotRendererCache == null) {
2007 mDotRendererCache = new SparseArray<>();
2008 }
Sihua Mae04aa202022-07-18 12:43:56 -07002009 if (mViewScaleProvider == null) {
2010 mViewScaleProvider = DEFAULT_PROVIDER;
2011 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08002012 if (mOverrideProvider == null) {
2013 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
2014 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002015 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00002016 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jon Miranda2b25ded2023-02-02 14:48:45 -08002017 mIsGestureMode, mViewScaleProvider, mOverrideProvider);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002018 }
2019 }
2020
Winson Chungb3800242013-10-24 11:01:54 -07002021}