blob: fa1cbd60db112245348d3145d0e11fd124237b9d [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
Thales Lima12d0eff2022-03-25 17:06:11 +000019import static com.android.launcher3.InvariantDeviceProfile.INDEX_DEFAULT;
20import static com.android.launcher3.InvariantDeviceProfile.INDEX_LANDSCAPE;
21import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_LANDSCAPE;
22import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_PORTRAIT;
Jon Miranda58561d42021-03-17 10:51:54 -040023import static com.android.launcher3.Utilities.dpiFromPx;
Jon Mirandaaf3aed02021-05-06 18:28:45 -070024import static com.android.launcher3.Utilities.pxFromSp;
Alex Chau3d2c0622022-09-01 21:28:14 +010025import static com.android.launcher3.anim.Interpolators.LINEAR;
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;
Sunny Goyal57b22792021-05-25 14:35:01 -070056import com.android.launcher3.uioverrides.ApiWrapper;
Sunny Goyalfd58da62020-08-11 12:06:49 -070057import com.android.launcher3.util.DisplayController;
58import com.android.launcher3.util.DisplayController.Info;
Thales Limac98b7812023-04-14 15:04:23 +010059import com.android.launcher3.util.ResourceHelper;
Sunny Goyalb46703d2020-05-27 17:52:03 -070060import com.android.launcher3.util.WindowBounds;
Thales Limac98b7812023-04-14 15:04:23 +010061import com.android.launcher3.workspace.CalculatedWorkspaceSpec;
62import com.android.launcher3.workspace.WorkspaceSpecs;
Winson1f064272016-07-18 17:18:02 -070063
Jon Miranda58561d42021-03-17 10:51:54 -040064import java.io.PrintWriter;
Alex Chaue818bcb2022-09-02 17:27:11 +010065import java.util.Locale;
Jon Miranda2b25ded2023-02-02 14:48:45 -080066import java.util.function.Consumer;
Jon Miranda58561d42021-03-17 10:51:54 -040067
Sunny Goyal35c7b192021-04-20 16:51:10 -070068@SuppressLint("NewApi")
Winson Chungb3800242013-10-24 11:01:54 -070069public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070070
Sunny Goyal8b9919d2021-04-07 14:45:17 -070071 private static final int DEFAULT_DOT_SIZE = 100;
Alex Chau206ede92022-08-01 17:46:12 +010072 private static final float ALL_APPS_TABLET_MAX_ROWS = 5.5f;
Thales Limab35faed2022-09-05 16:30:01 -030073 private static final float MIN_FOLDER_TEXT_SIZE_SP = 16f;
Sunny Goyal6c304b12023-04-10 12:03:04 -070074 private static final float MIN_WIDGET_PADDING_DP = 6f;
Alex Chau206ede92022-08-01 17:46:12 +010075
Sihua Mae04aa202022-07-18 12:43:56 -070076 public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f);
77 public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE;
Jon Miranda2b25ded2023-02-02 14:48:45 -080078 public static final Consumer<DeviceProfile> DEFAULT_DIMENSION_PROVIDER = dp -> {};
Sihua Mae04aa202022-07-18 12:43:56 -070079
Adam Cohen2e6da152015-05-06 11:42:25 -070080 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070081 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070082 private final DisplayMetrics mMetrics;
Winson Chungbe876472014-05-14 14:15:20 -070083
Sunny Goyalc6205602015-05-21 20:46:33 -070084 // Device properties
85 public final boolean isTablet;
Sunny Goyalc6205602015-05-21 20:46:33 -070086 public final boolean isPhone;
87 public final boolean transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +000088 public final boolean isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -070089 public final boolean isTwoPanels;
Thales Limaa1012902022-01-13 17:58:42 +000090 public final boolean isQsbInline;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -070091
Sunny Goyalc6205602015-05-21 20:46:33 -070092 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -070093 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -080094 public final boolean isMultiWindowMode;
Alex Chau6ed408f2022-03-04 12:58:05 +000095 public final boolean isGestureMode;
Sunny Goyald70e75a2018-02-22 10:07:32 -080096
Sunny Goyal0addbf02020-04-28 14:17:35 -070097 public final int windowX;
98 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -070099 public final int widthPx;
100 public final int heightPx;
101 public final int availableWidthPx;
102 public final int availableHeightPx;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800103 public final int rotationHint;
Jon Mirandabba64512019-03-27 10:54:17 -0700104
105 public final float aspectRatio;
106
Jon Mirandae126d722021-02-25 10:45:20 -0500107 public final boolean isScalableGrid;
Thales Lima83bedbf2021-10-05 17:47:39 +0100108 private final int mTypeIndex;
Jon Mirandae126d722021-02-25 10:45:20 -0500109
Thales Limac98b7812023-04-14 15:04:23 +0100110 // Responsive grid
111 private final boolean mIsResponsiveGrid;
112 private WorkspaceSpecs mWorkspaceSpecs;
113 private CalculatedWorkspaceSpec mResponsiveWidthSpec;
114 private CalculatedWorkspaceSpec mResponsiveHeightSpec;
115
Tony Wickhamd6b40372015-09-23 18:37:57 -0700116 /**
117 * The maximum amount of left/right workspace padding as a percentage of the screen width.
118 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
119 * 7% of the screen width can be used as right padding.
120 */
121 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -0700122
Jon Miranda3f9bab22017-07-28 14:50:17 -0700123 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700124 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda80dda302021-07-28 14:14:59 -0700125 private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252;
126 private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700127
Sunny Goyalc6205602015-05-21 20:46:33 -0700128 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +0100129 public final int desiredWorkspaceHorizontalMarginOriginalPx;
130 public int desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100131 public int gridVisualizationPaddingX;
132 public int gridVisualizationPaddingY;
Thales Lima78d00ad2021-09-30 11:29:06 +0100133 public Point cellLayoutBorderSpaceOriginalPx;
134 public Point cellLayoutBorderSpacePx;
Pat Manning08610ca2022-04-05 21:03:16 +0100135 public Rect cellLayoutPaddingPx = new Rect();
136
Sunny Goyalc6205602015-05-21 20:46:33 -0700137 public final int edgeMarginPx;
Alex Chau0c4e11b2022-07-08 18:41:36 +0100138 public final float workspaceContentScale;
Alex Chau906d8822022-05-23 10:42:25 +0100139 public final int workspaceSpringLoadedMinNextPageVisiblePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700140
Jon Miranda58561d42021-03-17 10:51:54 -0400141 private final int extraSpace;
Thales Lima171ee662022-11-22 15:52:49 +0000142 private int maxEmptySpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500143 public int workspaceTopPadding;
144 public int workspaceBottomPadding;
145
Tony Wickham5edf9e22020-03-27 20:06:52 -0700146 // Workspace page indicator
147 public final int workspacePageIndicatorHeight;
148 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700149
Sunny Goyalc6205602015-05-21 20:46:33 -0700150 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400151 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700152 public int iconSizePx;
153 public int iconTextSizePx;
154 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700155 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -0700156
Jon Mirandaab3c6812021-06-28 15:42:28 -0700157 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800158 public int cellWidthPx;
159 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700160 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800161
Jon Mirandae126d722021-02-25 10:45:20 -0500162 public int cellYPaddingPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500163
Sunny Goyalc6205602015-05-21 20:46:33 -0700164 // Folder
Jon Mirandae126d722021-02-25 10:45:20 -0500165 public float folderLabelTextScale;
166 public int folderLabelTextSizePx;
Thales Limab35faed2022-09-05 16:30:01 -0300167 public int folderFooterHeightPx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700168 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700169 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700170
Jon Mirandae126d722021-02-25 10:45:20 -0500171 // Folder content
Thales Limab35faed2022-09-05 16:30:01 -0300172 public int folderCellLayoutBorderSpacePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500173 public int folderContentPaddingLeftRight;
174 public int folderContentPaddingTop;
175
Jon Mirandabf7d8122016-11-03 15:29:29 -0700176 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700177 public int folderCellWidthPx;
178 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700179
180 // Folder child
181 public int folderChildIconSizePx;
182 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700183 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700184
Sunny Goyalc6205602015-05-21 20:46:33 -0700185 // Hotseat
Thales Lima9938c2f2022-07-25 14:38:16 +0100186 public int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700187 public int hotseatCellHeightPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100188 public final boolean areNavButtonsInline;
Jon Miranda18751b62017-07-31 17:25:27 -0700189 // In portrait: size = height, in landscape: size = width
190 public int hotseatBarSizePx;
Thales Limab8c05952022-05-23 16:58:38 +0100191 public int hotseatBarBottomSpacePx;
Pat Manning26f70f72022-07-07 13:50:39 +0100192 public int hotseatBarEndOffset;
Thales Limab8c05952022-05-23 16:58:38 +0100193 public int hotseatQsbSpace;
Pat Manningde25c0d2022-04-05 19:11:26 +0100194 public int springLoadedHotseatBarTopMarginPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700195 // Start is the side next to the nav bar, end is the side next to the workspace
196 public final int hotseatBarSidePaddingStartPx;
197 public final int hotseatBarSidePaddingEndPx;
Alex Chau206ede92022-08-01 17:46:12 +0100198 public int hotseatQsbWidth; // only used when isQsbInline
Sunny Goyal57b22792021-05-25 14:35:01 -0700199 public final int hotseatQsbHeight;
Thales Limab8c05952022-05-23 16:58:38 +0100200 public final int hotseatQsbVisualHeight;
201 private final int hotseatQsbShadowHeight;
Thales Limadd027342022-01-07 12:54:37 +0000202 public int hotseatBorderSpace;
Thales Limaffc68b02023-01-09 16:20:23 +0000203 private final int mMinHotseatIconSpacePx;
204 private final int mMinHotseatQsbWidthPx;
205 private final int mMaxHotseatIconSpacePx;
Jon Mirandae17a9492023-03-08 16:42:20 -0800206 public final int inlineNavButtonsEndSpacingPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700207
Alex Chau3d2c0622022-09-01 21:28:14 +0100208 // Bottom sheets
209 public int bottomSheetTopPadding;
210 public int bottomSheetOpenDuration;
211 public int bottomSheetCloseDuration;
212 public float bottomSheetWorkspaceScale;
213 public float bottomSheetDepth;
214
Sunny Goyalc6205602015-05-21 20:46:33 -0700215 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000216 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000217 public int allAppsShiftRange;
218 public int allAppsTopPadding;
Alex Chau3d2c0622022-09-01 21:28:14 +0100219 public int allAppsOpenDuration;
220 public int allAppsCloseDuration;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700221 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700222 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700223 public int allAppsIconSizePx;
224 public int allAppsIconDrawablePaddingPx;
sfufa@google.comde013292021-09-21 18:22:44 -0700225 public int allAppsLeftRightPadding;
Alex Chau27b39b92022-01-14 18:02:18 +0000226 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700227 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700228 public float allAppsIconTextSizePx;
229
Zak Cohen334efeb2021-03-19 16:42:07 -0700230 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700231 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000232 public int overviewTaskIconSizePx;
Alex Chauac9df382021-08-02 19:08:41 +0100233 public int overviewTaskIconDrawableSizePx;
234 public int overviewTaskIconDrawableSizeGridPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000235 public int overviewTaskThumbnailTopMarginPx;
Alex Chau19c6eca2022-03-10 20:12:56 +0000236 public final int overviewActionsHeight;
Alex Chaua2fc7642022-04-21 14:20:23 +0100237 public final int overviewActionsTopMarginPx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000238 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100239 public int overviewPageSpacing;
240 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000241 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700242
Jeremy Sim0ac47082022-10-10 13:59:40 -0700243 // Split staging
244 public int splitPlaceholderInset;
245
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800246 // Widgets
Sihua Mae04aa202022-07-18 12:43:56 -0700247 private final ViewScaleProvider mViewScaleProvider;
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800248
Sunny Goyal47328fd2016-05-25 18:56:41 -0700249 // Drop Target
250 public int dropTargetBarSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100251 public int dropTargetBarTopMarginPx;
252 public int dropTargetBarBottomMarginPx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100253 public int dropTargetDragPaddingPx;
254 public int dropTargetTextSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100255 public int dropTargetHorizontalPaddingPx;
256 public int dropTargetVerticalPaddingPx;
257 public int dropTargetGapPx;
Alex Chau5b019302022-05-23 10:42:25 +0100258 public int dropTargetButtonWorkspaceEdgeGapPx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700259
Winson1f064272016-07-18 17:18:02 -0700260 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800261 private final Rect mInsets = new Rect();
262 public final Rect workspacePadding = new Rect();
Sunny Goyal6c304b12023-04-10 12:03:04 -0700263 // Additional padding added to the widget inside its cellSpace. It is applied outside
264 // the widgetView, such that the actual view size is same as the widget size.
265 public final Rect widgetPadding = new Rect();
266
Jon Miranda0bd63d12019-03-06 17:29:29 -0800267 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700268 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700269
Tony Wickhamf34bee82018-12-03 18:11:39 -0800270 // Notification dots
Sunny Goyal65190ae2022-08-02 14:16:26 -0700271 public final DotRenderer mDotRendererWorkSpace;
272 public final DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800273
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100274 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800275 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000276 // Whether Taskbar will inset the bottom of apps by taskbarSize.
277 public boolean isTaskbarPresentInApps;
Jon Miranda9c478b62023-03-23 21:38:49 -0700278 public final int taskbarHeight;
279 public final int stashedTaskbarHeight;
280 public final int taskbarBottomMargin;
281 public final int taskbarIconSize;
Jon Miranda04f05102023-04-04 12:16:31 -0700282 // If true, used to layout taskbar in 3 button navigation mode.
283 public final boolean startAlignTaskbar;
Tony Wickham15883892021-02-12 11:24:40 -0800284
Alex Chaua02eddc2021-04-29 00:36:06 +0100285 // DragController
286 public int flingToDeleteThresholdVelocity;
287
Vinit Nayak17c4b332021-08-05 12:54:58 -0700288 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700289 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal65190ae2022-08-02 14:16:26 -0700290 SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
Alex Chauab800f72022-12-13 17:46:06 +0000291 boolean transposeLayoutWithOrientation, boolean isMultiDisplay, boolean isGestureMode,
Jon Miranda2b25ded2023-02-02 14:48:45 -0800292 @NonNull final ViewScaleProvider viewScaleProvider,
293 @NonNull final Consumer<DeviceProfile> dimensionOverrideProvider) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700294
Adam Cohen2e6da152015-05-06 11:42:25 -0700295 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700296 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800297 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500298 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +0000299 this.isMultiDisplay = isMultiDisplay;
Alex Chau6ed408f2022-03-04 12:58:05 +0000300 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700301 windowX = windowBounds.bounds.left;
302 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800303 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100304 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700305
Thales Limac98b7812023-04-14 15:04:23 +0100306 // TODO(b/241386436): shouldn't change any launcher behaviour
307 mIsResponsiveGrid = inv.workspaceSpecsId != INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100308
Jon Mirandae126d722021-02-25 10:45:20 -0500309 isScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000310 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700311 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000312 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700313 isPhone = !isTablet;
Alex Chauab800f72022-12-13 17:46:06 +0000314 isTwoPanels = isTablet && isMultiDisplay;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800315 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700316
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000317 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000318 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700319 ? Configuration.ORIENTATION_LANDSCAPE
320 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000321 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700322 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000323 mMetrics = res.getDisplayMetrics();
324
325 // Determine sizes.
326 widthPx = windowBounds.bounds.width();
327 heightPx = windowBounds.bounds.height();
328 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100329 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000330
331 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Thales Lima83bedbf2021-10-05 17:47:39 +0100332 if (isTwoPanels) {
333 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000334 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100335 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000336 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100337 }
338 } else {
339 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000340 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100341 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000342 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100343 }
344 }
345
Thales Limac98b7812023-04-14 15:04:23 +0100346 if (mIsResponsiveGrid) {
347 mWorkspaceSpecs = new WorkspaceSpecs(new ResourceHelper(context, inv.workspaceSpecsId));
348 mResponsiveWidthSpec = mWorkspaceSpecs.getCalculatedWidthSpec(inv.numColumns,
349 availableWidthPx);
350 mResponsiveHeightSpec = mWorkspaceSpecs.getCalculatedHeightSpec(inv.numRows,
351 availableHeightPx);
352 }
353
Jon Miranda9c478b62023-03-23 21:38:49 -0700354 if (DisplayController.isTransientTaskbar(context)) {
355 float invTransientIconSizeDp = inv.transientTaskbarIconSize[mTypeIndex];
356 taskbarIconSize = pxFromDp(invTransientIconSizeDp, mMetrics);
Jon Miranda95f44722023-06-06 19:48:19 -0700357 taskbarHeight = Math.round((taskbarIconSize * ICON_VISIBLE_AREA_FACTOR)
358 + (2 * res.getDimensionPixelSize(R.dimen.transient_taskbar_padding)));
Jon Miranda9c478b62023-03-23 21:38:49 -0700359 stashedTaskbarHeight =
360 res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_height);
361 taskbarBottomMargin =
362 res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin);
Jon Miranda04f05102023-04-04 12:16:31 -0700363 startAlignTaskbar = false;
Jon Miranda9c478b62023-03-23 21:38:49 -0700364 } else {
365 taskbarIconSize = pxFromDp(ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size),
366 mMetrics);
367 taskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_size);
368 stashedTaskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
369 taskbarBottomMargin = 0;
Jon Miranda04f05102023-04-04 12:16:31 -0700370 startAlignTaskbar = inv.startAlignTaskbar[mTypeIndex];
Tony Wickham15883892021-02-12 11:24:40 -0800371 }
Tony Wickham15883892021-02-12 11:24:40 -0800372
Winson Chungb3800242013-10-24 11:01:54 -0700373 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100374 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700375
Thales Limad90faab2021-09-21 17:18:47 +0100376 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
377 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100378 gridVisualizationPaddingX = res.getDimensionPixelSize(
379 R.dimen.grid_visualization_horizontal_cell_spacing);
380 gridVisualizationPaddingY = res.getDimensionPixelSize(
381 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500382
Alex Chaue0227552022-04-06 19:44:43 +0100383 bottomSheetTopPadding = mInsets.top // statusbar height
Andras Kloczl142b0542022-03-09 21:26:02 +0000384 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
385 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
Alex Chau3d2c0622022-09-01 21:28:14 +0100386 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
387 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
388 if (isTablet) {
389 bottomSheetWorkspaceScale = workspaceContentScale;
Alex Chauab800f72022-12-13 17:46:06 +0000390 if (isMultiDisplay && !ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH.get()) {
391 // TODO(b/259893832): Revert to use maxWallpaperScale to calculate bottomSheetDepth
392 // when screen recorder bug is fixed.
393 bottomSheetDepth = 1f;
394 } else {
395 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
396 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
397 // When depth is 1, wallpaper zoom is set to 1.
398 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
399 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
400 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
401 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
402 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100403 } else {
404 bottomSheetWorkspaceScale = 1f;
405 bottomSheetDepth = 0f;
406 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000407
Jon Mirandae126d722021-02-25 10:45:20 -0500408 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
Thales Limab35faed2022-09-05 16:30:01 -0300409
Thales Lima7eee74b2023-03-16 16:00:55 -0300410 if (isScalableGrid && inv.folderStyle != INVALID_RESOURCE_HANDLE) {
Thales Limab35faed2022-09-05 16:30:01 -0300411 TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
Thales Limad852d652023-01-17 14:01:13 +0000412 R.styleable.FolderStyle);
Thales Limab35faed2022-09-05 16:30:01 -0300413 // These are re-set in #updateFolderCellSize if the grid is not scalable
414 folderCellHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000415 R.styleable.FolderStyle_folderCellHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300416 folderCellWidthPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000417 R.styleable.FolderStyle_folderCellWidth, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300418
419 folderContentPaddingTop = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000420 R.styleable.FolderStyle_folderTopPadding, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300421 folderCellLayoutBorderSpacePx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000422 R.styleable.FolderStyle_folderBorderSpace, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300423 folderFooterHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000424 R.styleable.FolderStyle_folderFooterHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300425 folderStyle.recycle();
426 } else {
427 folderCellLayoutBorderSpacePx = 0;
Thales Lima7eee74b2023-03-16 16:00:55 -0300428 folderFooterHeightPx = res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Thales Limab35faed2022-09-05 16:30:01 -0300429 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
430 }
Jon Mirandae126d722021-02-25 10:45:20 -0500431
Thales Lima78d00ad2021-09-30 11:29:06 +0100432 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv);
Thales Limab35faed2022-09-05 16:30:01 -0300433 cellLayoutBorderSpaceOriginalPx = new Point(cellLayoutBorderSpacePx);
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 Lima6a590062022-11-22 15:52:49 +0000483 isQsbInline = isScalableGrid && 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
Alex Chau635b3ab2022-01-26 16:49:10 +0000538 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chau5fd9d492021-07-22 17:27:11 +0100539 overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100540 overviewTaskIconDrawableSizePx =
541 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
542 overviewTaskIconDrawableSizeGridPx =
543 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700544 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx;
Jeremy Sim3c2c3f12022-05-16 20:37:43 -0700545 overviewActionsTopMarginPx = res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000546 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
547 overviewActionsButtonSpacing = res.getDimensionPixelSize(
548 R.dimen.overview_actions_button_spacing);
Alex Chau19c6eca2022-03-10 20:12:56 +0000549 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700550 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000551 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700552
Jeremy Sim0ac47082022-10-10 13:59:40 -0700553 splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset);
554
Jon Miranda2ed276e2017-06-29 11:36:34 -0700555 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400556 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700557
Jon Miranda2ed276e2017-06-29 11:36:34 -0700558 // Now that we have all of the variables calculated, we can tune certain sizes.
Thales Limaae0d7ef2022-11-16 15:53:43 +0000559 if (isScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400560 // Paddings were created assuming no scaling, so we first unscale the extra space.
Jon Mirandaab3c6812021-06-28 15:42:28 -0700561 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
Thales Limaae0d7ef2022-11-16 15:53:43 +0000562 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
563 DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
Thales Lima171ee662022-11-22 15:52:49 +0000564 maxEmptySpace = padding.getMaxEmptySpacePx();
Jon Miranda228877d2021-02-09 11:05:00 -0500565
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400566 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
567 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
568 int paddingHotseatBottom = padding.getHotseatBottomPadding(unscaledExtraSpace);
569
Jon Mirandaab3c6812021-06-28 15:42:28 -0700570 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
571 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700572 }
Pat Manning08610ca2022-04-05 21:03:16 +0100573
574 int cellLayoutPadding =
575 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
576 R.dimen.cell_layout_padding);
577 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
578 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800579 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800580
Thales Lima7eee74b2023-03-16 16:00:55 -0300581 // Folder scaling requires correct workspace paddings
582 updateAvailableFolderCellDimensions(res);
583
Thales Limaffc68b02023-01-09 16:20:23 +0000584 mMinHotseatIconSpacePx = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
585 mMinHotseatQsbWidthPx = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
586 mMaxHotseatIconSpacePx = areNavButtonsInline
Thales Lima6a590062022-11-22 15:52:49 +0000587 ? res.getDimensionPixelSize(R.dimen.max_hotseat_icon_space) : Integer.MAX_VALUE;
Thales Lima425f6822022-05-10 13:44:58 -0300588 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima6a590062022-11-22 15:52:49 +0000589 recalculateHotseatWidthAndBorderSpace();
Alex Chau206ede92022-08-01 17:46:12 +0100590
591 // AllApps height calculation depends on updated cellSize
592 if (isTablet) {
593 int collapseHandleHeight =
594 res.getDimensionPixelOffset(R.dimen.bottom_sheet_handle_area_height);
595 int contentHeight = heightPx - collapseHandleHeight - hotseatQsbHeight;
596 int targetContentHeight = (int) (allAppsCellHeightPx * ALL_APPS_TABLET_MAX_ROWS);
597 allAppsTopPadding = Math.max(mInsets.top, contentHeight - targetContentHeight);
598 allAppsShiftRange = heightPx - allAppsTopPadding;
599 } else {
600 allAppsTopPadding = 0;
601 allAppsShiftRange =
602 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
603 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100604 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
605 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300606
Alex Chaua02eddc2021-04-29 00:36:06 +0100607 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
608 R.dimen.drag_flingToDeleteMinVelocity);
609
Sihua Mae04aa202022-07-18 12:43:56 -0700610 mViewScaleProvider = viewScaleProvider;
611
Jon Miranda2b25ded2023-02-02 14:48:45 -0800612 dimensionOverrideProvider.accept(this);
613
Tony Wickham1237df02017-02-24 08:59:36 -0800614 // This is done last, after iconSizePx is calculated above.
Sunny Goyal799e1202023-02-09 10:54:28 -0800615 mDotRendererWorkSpace = createDotRenderer(context, iconSizePx, dotRendererCache);
616 mDotRendererAllApps = createDotRenderer(context, allAppsIconSizePx, dotRendererCache);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700617 }
618
619 private static DotRenderer createDotRenderer(
Sunny Goyal799e1202023-02-09 10:54:28 -0800620 @NonNull Context context, int size, @NonNull SparseArray<DotRenderer> cache) {
Sunny Goyal65190ae2022-08-02 14:16:26 -0700621 DotRenderer renderer = cache.get(size);
622 if (renderer == null) {
Sunny Goyal799e1202023-02-09 10:54:28 -0800623 renderer = new DotRenderer(size, getShapePath(context, DEFAULT_DOT_SIZE),
624 DEFAULT_DOT_SIZE);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700625 cache.put(size, renderer);
626 }
627 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700628 }
629
Thales Lima425f6822022-05-10 13:44:58 -0300630 /**
631 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
632 * width of the hotseat.
633 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100634 private int calculateQsbWidth(int hotseatBorderSpace) {
Thales Lima425f6822022-05-10 13:44:58 -0300635 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100636 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300637 return getIconToIconWidthForColumns(columns)
638 - iconSizePx * numShownHotseatIcons
639 - hotseatBorderSpace * numShownHotseatIcons;
640 } else {
641 int columns = inv.hotseatColumnSpan[mTypeIndex];
642 return getIconToIconWidthForColumns(columns);
643 }
644 }
Thales Lima2903a622022-03-17 13:52:19 +0000645
Thales Lima425f6822022-05-10 13:44:58 -0300646 private int getIconToIconWidthForColumns(int columns) {
647 return columns * getCellSize().x
648 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400649 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000650 }
651
Thales Limad90faab2021-09-21 17:18:47 +0100652 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
653 if (isVerticalBarLayout()) {
654 return 0;
655 }
656
Thales Lima83bedbf2021-10-05 17:47:39 +0100657 return isScalableGrid
658 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
659 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100660 }
661
Thales Limab8c05952022-05-23 16:58:38 +0100662 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
663 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700664 // Ensure there is enough space for folder icons, which have a slightly larger radius.
665 hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR);
Thales Limab8c05952022-05-23 16:58:38 +0100666
Jon Miranda0d284852021-06-22 14:50:55 -0700667 if (isVerticalBarLayout()) {
668 hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
669 + hotseatBarSidePaddingEndPx;
Thales Limab8c05952022-05-23 16:58:38 +0100670 } else if (isQsbInline) {
671 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
672 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700673 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100674 hotseatBarSizePx = hotseatIconSizePx
675 + hotseatQsbSpace
676 + hotseatQsbVisualHeight
677 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700678 }
679 }
680
Thales Lima6a590062022-11-22 15:52:49 +0000681 /**
682 * Calculates the width of the hotseat, changing spaces between the icons and removing icons if
683 * necessary.
684 */
685 public void recalculateHotseatWidthAndBorderSpace() {
686 if (!isScalableGrid) return;
687
688 int columns = inv.hotseatColumnSpan[mTypeIndex];
689 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
690 hotseatBorderSpace = calculateHotseatBorderSpace(hotseatWidthPx, /* numExtraBorder= */ 0);
Thales Lima9938c2f2022-07-25 14:38:16 +0100691 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
Thales Lima6a590062022-11-22 15:52:49 +0000692 // Spaces should be correct when the nav buttons are not inline
Thales Lima9938c2f2022-07-25 14:38:16 +0100693 if (!areNavButtonsInline) {
694 return;
695 }
696
Thales Lima6a590062022-11-22 15:52:49 +0000697 // The side space with inline buttons should be what is defined in InvariantDeviceProfile
Jon Mirandae17a9492023-03-08 16:42:20 -0800698 int sideSpacePx = inlineNavButtonsEndSpacingPx;
Thales Limaffc68b02023-01-09 16:20:23 +0000699 int maxHotseatWidthPx = availableWidthPx - sideSpacePx - hotseatBarEndOffset;
700 int maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
701 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000702 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100703
Thales Limaffc68b02023-01-09 16:20:23 +0000704 if (hotseatBorderSpace >= mMinHotseatIconSpacePx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100705 return;
706 }
707
708 // Border space can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000709 hotseatBorderSpace = mMinHotseatIconSpacePx;
Thales Lima6a590062022-11-22 15:52:49 +0000710 int requiredWidth = getHotseatRequiredWidth();
Thales Lima9938c2f2022-07-25 14:38:16 +0100711
712 // If there is an inline qsb, change its size
713 if (isQsbInline) {
Thales Limaffc68b02023-01-09 16:20:23 +0000714 hotseatQsbWidth -= requiredWidth - maxHotseatWidthPx;
715 if (hotseatQsbWidth >= mMinHotseatQsbWidthPx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100716 return;
717 }
718
719 // QSB can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000720 hotseatQsbWidth = mMinHotseatQsbWidthPx;
Thales Lima9938c2f2022-07-25 14:38:16 +0100721 }
722
Thales Limaffc68b02023-01-09 16:20:23 +0000723 maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
Thales Lima6a590062022-11-22 15:52:49 +0000724
Thales Lima9938c2f2022-07-25 14:38:16 +0100725 // If it still doesn't fit, start removing icons
726 do {
727 numShownHotseatIcons--;
Thales Limaffc68b02023-01-09 16:20:23 +0000728 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000729 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Limaffc68b02023-01-09 16:20:23 +0000730 } while (hotseatBorderSpace < mMinHotseatIconSpacePx && numShownHotseatIcons > 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100731
Thales Lima9938c2f2022-07-25 14:38:16 +0100732 }
733
Thales Lima78d00ad2021-09-30 11:29:06 +0100734 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100735 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100736 }
737
738 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100739 if (!isScalableGrid) {
740 return new Point(0, 0);
741 }
742
Thales Lima080d8902022-03-28 15:30:29 +0100743 int horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
744 int verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
Thales Lima78d00ad2021-09-30 11:29:06 +0100745
746 return new Point(horizontalSpacePx, verticalSpacePx);
747 }
748
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700749 public Info getDisplayInfo() {
750 return mInfo;
751 }
752
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700753 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800754 WindowBounds bounds = new WindowBounds(
755 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700756 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100757 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700758
759 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
760 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
761 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
762
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700763 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700764 .setWindowBounds(bounds)
Alex Chauab800f72022-12-13 17:46:06 +0000765 .setIsMultiDisplay(isMultiDisplay)
Alex Chau6ed408f2022-03-04 12:58:05 +0000766 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700767 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000768 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800769 }
770
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700771 public DeviceProfile copy(Context context) {
772 return toBuilder(context).build();
773 }
774
775 /**
776 * TODO: Move this to the builder as part of setMultiWindowMode
777 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700778 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700779 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700780 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700781 .setMultiWindowMode(true)
782 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800783
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800784 // We use these scales to measure and layout the widgets using their full invariant profile
785 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
786 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
787 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700788 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
789 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
790 profile = profile.toBuilder(context)
791 .setViewScaleProvider(i -> p)
792 .build();
793 }
794
795 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800796
Jon Miranda93e1f042016-11-11 14:13:04 -0800797 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700798 }
799
Adam Cohen63f1ec02014-08-12 09:23:13 -0700800 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400801 * Checks if there is enough space for labels on the workspace.
802 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700803 * It is important to call this method after the All Apps variables have been set.
804 */
Jon Miranda941375e2021-03-31 13:10:45 -0400805 private void hideWorkspaceLabelsIfNotEnoughSpace() {
806 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
807 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
808 - iconTextHeight;
809
810 // We want enough space so that the text is closer to its corresponding icon.
811 if (workspaceCellPaddingY < iconTextHeight) {
812 iconTextSizePx = 0;
813 iconDrawablePaddingPx = 0;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700814 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda941375e2021-03-31 13:10:45 -0400815 autoResizeAllAppsCells();
816 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700817 }
Jon Miranda1091e532017-07-21 13:31:50 -0700818
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700819 /**
820 * Re-computes the all-apps cell size to be independent of workspace
821 */
822 public void autoResizeAllAppsCells() {
Jon Miranda941375e2021-03-31 13:10:45 -0400823 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
824 int topBottomPadding = textHeight;
Jon Miranda1091e532017-07-21 13:31:50 -0700825 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
Jon Miranda941375e2021-03-31 13:10:45 -0400826 + textHeight + (topBottomPadding * 2);
Jon Miranda1091e532017-07-21 13:31:50 -0700827 }
828
Thales Limab7ef5692022-03-10 10:32:36 +0000829 private void updateAllAppsContainerWidth(Resources res) {
Pat Manning08610ca2022-04-05 21:03:16 +0100830 int cellLayoutHorizontalPadding =
831 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
Alex Chau27b39b92022-01-14 18:02:18 +0000832 if (isTablet) {
sfufa@google.comde013292021-09-21 18:22:44 -0700833 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
Thales Limab7ef5692022-03-10 10:32:36 +0000834 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Alex Chau27b39b92022-01-14 18:02:18 +0000835 + allAppsLeftRightPadding * 2;
836 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
sfufa@google.comde013292021-09-21 18:22:44 -0700837 } else {
838 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100839 desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding;
sfufa@google.comde013292021-09-21 18:22:44 -0700840 }
841 }
842
Thales Limae9273ea2023-01-26 12:33:52 +0000843 private void setupAllAppsStyle(Context context) {
844 TypedArray allAppsStyle;
845 if (inv.allAppsStyle != INVALID_RESOURCE_HANDLE) {
846 allAppsStyle = context.obtainStyledAttributes(inv.allAppsStyle,
847 R.styleable.AllAppsStyle);
848 } else {
849 allAppsStyle = context.obtainStyledAttributes(R.style.AllAppsStyleDefault,
850 R.styleable.AllAppsStyle);
851 }
852 allAppsLeftRightPadding = allAppsStyle.getDimensionPixelSize(
853 R.styleable.AllAppsStyle_horizontalPadding, 0);
854 allAppsStyle.recycle();
855 }
856
Jon Miranda228877d2021-02-09 11:05:00 -0500857 /**
858 * Returns the amount of extra (or unused) vertical space.
859 */
860 private int updateAvailableDimensions(Resources res) {
Alex Chaua68164d2022-12-15 16:16:03 +0000861 float invIconSizeDp = inv.iconSize[mTypeIndex];
862 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
863 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
864 iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
865
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700866 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800867
Pat Manning08610ca2022-04-05 21:03:16 +0100868 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -0500869
870 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +0100871 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +0000872 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -0500873 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500874 float scaleY = maxHeight / usedHeight;
875 boolean shouldScale = scaleY < 1f;
876
877 float scaleX = 1f;
878 if (isScalableGrid) {
879 // We scale to fit the cellWidth and cellHeight in the available space.
880 // The benefit of scalable grids is that we can get consistent aspect ratios between
881 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +0100882 float usedWidth =
883 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500884 // We do not subtract padding here, as we also scale the workspace padding if needed.
885 scaleX = availableWidthPx / usedWidth;
886 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700887 }
Jon Mirandae126d722021-02-25 10:45:20 -0500888
889 if (shouldScale) {
890 float scale = Math.min(scaleX, scaleY);
891 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +0100892 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -0500893 }
894
Jon Miranda228877d2021-02-09 11:05:00 -0500895 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700896 }
897
Pat Manninga2e14992022-04-22 11:29:17 +0100898 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +0100899 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
900 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
901 }
902
Pat Manninga2e14992022-04-22 11:29:17 +0100903 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +0000904 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +0100905 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
906 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -0500907 }
908
Jon Miranda6f7e9702019-09-16 14:44:14 -0700909 /**
910 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
911 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
912 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
913 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800914 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -0700915 // Icon scale should never exceed 1, otherwise pixellation may occur.
916 iconScale = Math.min(1f, scale);
917 cellScaleToFit = scale;
918
Jon Miranda18751b62017-07-31 17:25:27 -0700919 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800920 final boolean isVerticalLayout = isVerticalBarLayout();
Jon Mirandaab3c6812021-06-28 15:42:28 -0700921 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);
Thales Lima080d8902022-03-28 15:30:29 +0100922 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500923
924 if (isScalableGrid) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100925 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
926 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +0000927
928 if (cellWidthPx < iconSizePx) {
929 // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger.
930 int numColumns = getPanelCount() * inv.numColumns;
931 int numBorders = numColumns - 1;
932 int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns;
933 if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) {
934 cellWidthPx = iconSizePx;
935 cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders;
936 } else {
937 // If it still doesn't fit, set borderSpace to 0 and distribute the space for
938 // cellWidth, and reduce iconSize.
939 cellWidthPx = (cellWidthPx * numColumns
940 + cellLayoutBorderSpacePx.x * numBorders) / numColumns;
941 iconSizePx = Math.min(iconSizePx, cellWidthPx);
942 cellLayoutBorderSpacePx.x = 0;
943 }
944 }
945
946 int cellTextAndPaddingHeight =
947 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
948 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
949 if (cellHeightPx < cellContentHeight) {
950 // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight
951 // bigger.
952 int numBorders = inv.numRows - 1;
953 int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows;
954 if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) {
955 cellHeightPx = cellContentHeight;
956 cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders;
957 } else {
Alex Chau06f36e82023-01-06 10:50:54 +0000958 // If it still doesn't fit, set borderSpace to 0 to recover space.
Alex Chaube753132022-12-09 16:46:54 +0000959 cellHeightPx = (cellHeightPx * inv.numRows
960 + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows;
Alex Chaube753132022-12-09 16:46:54 +0000961 cellLayoutBorderSpacePx.y = 0;
Alex Chau06f36e82023-01-06 10:50:54 +0000962 // Reduce iconDrawablePaddingPx to make cellContentHeight smaller.
963 int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx;
964 if (cellContentWithoutPadding <= cellHeightPx) {
965 iconDrawablePaddingPx = cellContentHeight - cellHeightPx;
966 } else {
967 // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space,
968 // then proportional reduce iconSizePx and iconTextSizePx to fit.
969 iconDrawablePaddingPx = 0;
970 float ratio = cellHeightPx / (float) cellContentWithoutPadding;
971 iconSizePx = (int) (iconSizePx * ratio);
972 iconTextSizePx = (int) (iconTextSizePx * ratio);
973 }
974 cellTextAndPaddingHeight =
975 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +0000976 }
977 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
978 }
Jon Mirandae126d722021-02-25 10:45:20 -0500979 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +0100980 desiredWorkspaceHorizontalMarginPx =
981 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -0500982 } else {
Jon Mirandae126d722021-02-25 10:45:20 -0500983 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700984 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR)
985 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -0500986 + Utilities.calculateTextHeight(iconTextSizePx);
987 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
988 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
989 && !isMultiWindowMode) {
990 // Ensures that the label is closer to its corresponding icon. This is not an issue
991 // with vertical bar layout or multi-window mode since the issue is handled
992 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
993 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
994 iconDrawablePaddingPx = cellPaddingY;
995 }
Jon Miranda846455e2017-10-02 14:58:52 -0700996 }
Jon Miranda18751b62017-07-31 17:25:27 -0700997
Sunny Goyalae190ff2020-04-14 00:19:01 +0000998 // All apps
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500999 updateAllAppsIconSize(scale, res);
Winson Chungb3800242013-10-24 11:01:54 -07001000
Thales Limab8c05952022-05-23 16:58:38 +01001001 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -07001002
Sunny Goyalbaec6ff2016-09-14 11:26:21 -07001003 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -07001004 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
1005 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Sunny Goyal6c304b12023-04-10 12:03:04 -07001006
1007 // Update widget padding:
1008 float minSpacing = pxFromDp(MIN_WIDGET_PADDING_DP, mMetrics);
1009 if (cellLayoutBorderSpacePx.x < minSpacing
1010 || cellLayoutBorderSpacePx.y < minSpacing) {
1011 widgetPadding.left = widgetPadding.right =
1012 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.x));
1013 widgetPadding.top = widgetPadding.bottom =
1014 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.y));
1015 } else {
1016 widgetPadding.setEmpty();
1017 }
Winson Chung0f785722015-04-08 10:27:49 -07001018 }
1019
Thales Lima425f6822022-05-10 13:44:58 -03001020 /**
Thales Lima6a590062022-11-22 15:52:49 +00001021 * This method calculates the space between the icons to achieve a certain width.
Thales Lima425f6822022-05-10 13:44:58 -03001022 */
Thales Lima6a590062022-11-22 15:52:49 +00001023 private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) {
Thales Lima9938c2f2022-07-25 14:38:16 +01001024 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
Thales Limaffc68b02023-01-09 16:20:23 +00001025 int hotseatBorderSpacePx =
Thales Lima6a590062022-11-22 15:52:49 +00001026 (int) (hotseatWidthPx - hotseatIconsTotalPx)
1027 / (numShownHotseatIcons - 1 + numExtraBorder);
Thales Limaffc68b02023-01-09 16:20:23 +00001028 return Math.min(hotseatBorderSpacePx, mMaxHotseatIconSpacePx);
Thales Lima425f6822022-05-10 13:44:58 -03001029 }
1030
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001031
1032 /**
1033 * Updates the iconSize for allApps* variants.
1034 */
Brian Isganitisa9a78112022-05-23 18:11:47 -07001035 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +01001036 allAppsBorderSpacePx = new Point(
1037 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
1038 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001039 // AllApps cells don't have real space between cells,
1040 // so we add the border space to the cell height
Alex Chaube753132022-12-09 16:46:54 +00001041 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics)
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001042 + allAppsBorderSpacePx.y;
1043 // but width is just the cell,
1044 // the border is added in #updateAllAppsContainerWidth
Thales Lima080d8902022-03-28 15:30:29 +01001045 if (isScalableGrid) {
Alex Chaube753132022-12-09 16:46:54 +00001046 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1047 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001048 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001049 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001050
1051 if (allAppsCellWidthPx < allAppsIconSizePx) {
1052 // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to
1053 // make allAppsCellWidth bigger.
1054 int numBorders = inv.numAllAppsColumns - 1;
1055 int extraWidthRequired =
1056 (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns;
1057 if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) {
1058 allAppsCellWidthPx = allAppsIconSizePx;
1059 allAppsBorderSpacePx.x -= extraWidthRequired / numBorders;
1060 } else {
1061 // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space
1062 // for allAppsCellWidth, and reduce allAppsIconSize.
1063 allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns
1064 + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns;
1065 allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx);
1066 allAppsBorderSpacePx.x = 0;
1067 }
1068 }
1069
1070 int cellContentHeight = allAppsIconSizePx
1071 + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y;
1072 if (allAppsCellHeightPx < cellContentHeight) {
1073 // Increase allAppsCellHeight to fit its content.
1074 allAppsCellHeightPx = cellContentHeight;
1075 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001076 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001077 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
1078 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001079 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1080 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001081 allAppsIconDrawablePaddingPx =
1082 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001083 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001084 }
1085
Thales Limab7ef5692022-03-10 10:32:36 +00001086 updateAllAppsContainerWidth(res);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001087 if (isVerticalBarLayout()) {
1088 hideWorkspaceLabelsIfNotEnoughSpace();
1089 }
1090 }
1091
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001092 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001093 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001094
Thales Lima7eee74b2023-03-16 16:00:55 -03001095 // For usability we can't have the folder use the whole width of the screen
Sunny Goyal07b69292018-01-08 14:19:34 -08001096 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -08001097
Thales Lima7eee74b2023-03-16 16:00:55 -03001098 // Check if the folder fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -05001099 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Thales Lima7eee74b2023-03-16 16:00:55 -03001100 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx)
1101 + folderFooterHeightPx
1102 + folderContentPaddingTop;
1103 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001104 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -08001105
Thales Lima7eee74b2023-03-16 16:00:55 -03001106 // Check if the folder fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -05001107 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Thales Lima7eee74b2023-03-16 16:00:55 -03001108 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx)
1109 + folderContentPaddingLeftRight * 2;
1110 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001111 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -08001112
1113 float scale = Math.min(scaleX, scaleY);
1114 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001115 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001116 }
1117 }
1118
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001119 private void updateFolderCellSize(float scale, Resources res) {
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001120 float invIconSizeDp = inv.iconSize[mTypeIndex];
Sunny Goyal35c7b192021-04-20 16:51:10 -07001121 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001122 folderChildTextSizePx = pxFromSp(inv.iconTextSize[mTypeIndex], mMetrics, scale);
Thales Lima7eee74b2023-03-16 16:00:55 -03001123 folderLabelTextSizePx = Math.max(pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale),
Thales Limab35faed2022-09-05 16:30:01 -03001124 (int) (folderChildTextSizePx * folderLabelTextScale));
Jon Mirandabf7d8122016-11-03 15:29:29 -07001125
1126 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001127
Jon Miranda823da222021-03-23 08:08:45 -04001128 if (isScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001129 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
Thales Lima7eee74b2023-03-16 16:00:55 -03001130 folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale);
1131 folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale);
1132 } else {
1133 folderCellWidthPx = roundPxValueFromFloat(folderCellWidthPx * scale);
1134 folderCellHeightPx = roundPxValueFromFloat(folderCellHeightPx * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001135 }
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001136
Thales Lima7eee74b2023-03-16 16:00:55 -03001137 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
1138 folderCellLayoutBorderSpacePx = roundPxValueFromFloat(
1139 folderCellLayoutBorderSpacePx * scale);
1140 folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale);
1141
Thales Limab35faed2022-09-05 16:30:01 -03001142 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx;
Jon Miranda823da222021-03-23 08:08:45 -04001143 } else {
1144 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1145 * scale);
1146 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1147 * scale);
1148
1149 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1150 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Lima7eee74b2023-03-16 16:00:55 -03001151 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001152 folderContentPaddingLeftRight =
1153 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1154 folderFooterHeightPx =
Thales Lima7eee74b2023-03-16 16:00:55 -03001155 roundPxValueFromFloat(
1156 res.getDimensionPixelSize(R.dimen.folder_footer_height_default)
1157 * scale);
1158
Jon Miranda823da222021-03-23 08:08:45 -04001159 }
1160
Jonathan Miranda9ad87462017-07-26 17:41:02 +00001161 folderChildDrawablePaddingPx = Math.max(0,
1162 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001163 }
1164
Winson1f064272016-07-18 17:18:02 -07001165 public void updateInsets(Rect insets) {
1166 mInsets.set(insets);
1167 }
1168
Sunny Goyalae6e3182019-04-30 12:04:37 -07001169 /**
1170 * The current device insets. This is generally same as the insets being dispatched to
1171 * {@link Insettable} elements, but can differ if the element is using a different profile.
1172 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001173 public Rect getInsets() {
1174 return mInsets;
1175 }
1176
Sunny Goyal756cd262015-08-20 12:33:21 -07001177 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001178 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001179 }
1180
Sunny Goyal19ff7282021-04-22 10:12:54 -07001181 public Point getCellSize(Point result) {
1182 if (result == null) {
1183 result = new Point();
1184 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001185
Pat Manning25d53342022-05-10 09:58:49 +00001186 int shortcutAndWidgetContainerWidth =
1187 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1188 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1189 inv.numColumns);
1190 int shortcutAndWidgetContainerHeight =
1191 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1192 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1193 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001194 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001195 }
1196
1197 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001198 * Returns the left and right space on the cell, which is the cell width - icon size
1199 */
1200 public int getCellHorizontalSpace() {
1201 return getCellSize().x - iconSizePx;
1202 }
1203
1204 /**
Pat Manning25d53342022-05-10 09:58:49 +00001205 * Gets the number of panels within the workspace.
1206 */
1207 public int getPanelCount() {
1208 return isTwoPanels ? 2 : 1;
1209 }
1210
1211 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001212 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1213 * bottom of the screen.
1214 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001215 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1216 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001217 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001218 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001219 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001220 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001221 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001222 }
1223
1224 /**
1225 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1226 */
Pat Manning25d53342022-05-10 09:58:49 +00001227 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001228 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001229 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001230 }
1231
1232 /**
1233 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1234 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001235 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001236 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001237 return heightPx - (isVerticalBarLayout()
1238 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001239 }
1240
Pat Manningea5c1d22022-04-14 10:58:16 +01001241 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001242 * Gets the scale of the workspace for the spring-loaded edit state.
1243 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001244 public float getWorkspaceSpringLoadScale(Context context) {
1245 float scale =
1246 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1247 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001248 scale = Math.min(scale, 1f);
1249
Pat Manninge63dd252022-08-02 16:15:29 +01001250 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001251 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001252 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001253 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001254 if (scaledWorkspaceWidth > maxAvailableWidth) {
1255 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1256 }
1257 return scale;
1258 }
1259
Pat Manning25d53342022-05-10 09:58:49 +00001260 /**
1261 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1262 *
1263 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1264 * layouts have two Cell Layouts per workspace.
1265 */
1266 public int getCellLayoutWidth() {
1267 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001268 }
1269
Pat Manning25d53342022-05-10 09:58:49 +00001270 /**
1271 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1272 *
1273 * <p>This is the height of a Workspace, less its vertical padding.
1274 */
1275 public int getCellLayoutHeight() {
1276 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001277 }
1278
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001279 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001280 return new Point(workspacePadding.left + workspacePadding.right,
1281 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001282 }
1283
1284 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001285 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1286 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001287 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001288 private void updateWorkspacePadding() {
1289 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001290 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -08001291 padding.top = 0;
1292 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001293 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001294 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -07001295 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -07001296 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -07001297 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001298 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -07001299 }
Winson Chungb3800242013-10-24 11:01:54 -07001300 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001301 // Pad the bottom of the workspace with hotseat bar
1302 // and leave a bit of space in case a widget go all the way down
1303 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding
1304 + workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace
1305 - mInsets.bottom;
Pat Manning08610ca2022-04-05 21:03:16 +01001306 int paddingTop = workspaceTopPadding + (isScalableGrid ? 0 : edgeMarginPx);
1307 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001308
Pat Manning08610ca2022-04-05 21:03:16 +01001309 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001310 }
Pat Manning08610ca2022-04-05 21:03:16 +01001311 insetPadding(workspacePadding, cellLayoutPaddingPx);
1312 }
1313
1314 private void insetPadding(Rect paddings, Rect insets) {
1315 insets.left = Math.min(insets.left, paddings.left);
1316 paddings.left -= insets.left;
1317
1318 insets.top = Math.min(insets.top, paddings.top);
1319 paddings.top -= insets.top;
1320
1321 insets.right = Math.min(insets.right, paddings.right);
1322 paddings.right -= insets.right;
1323
1324 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1325 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001326 }
1327
Sunny Goyal57b22792021-05-25 14:35:01 -07001328 /**
1329 * Returns the padding for hotseat view
1330 */
1331 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001332 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001333 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001334 // The hotseat icons will be placed in the middle of the hotseat cells.
1335 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1336 // in vertical bar layout.
1337 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1338 // is set to account for that difference.
1339 float diffOverlapFactor = iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
Pat Manning08610ca2022-04-05 21:03:16 +01001340 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1341 - diffOverlapFactor), 0);
1342 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001343 + diffOverlapFactor), 0);
1344
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001345 if (isSeascape()) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001346 hotseatBarPadding.set(mInsets.left + hotseatBarSidePaddingStartPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001347 hotseatBarSidePaddingEndPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001348 } else {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001349 hotseatBarPadding.set(hotseatBarSidePaddingEndPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001350 mInsets.right + hotseatBarSidePaddingStartPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001351 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001352 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001353 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001354 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1355 int hotseatBarTopPadding =
1356 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001357
Thales Lima6a590062022-11-22 15:52:49 +00001358 int hotseatWidth = getHotseatRequiredWidth();
Helen Cheuke76291f2023-02-14 17:11:05 +00001359 int startSpacing;
1360 int endSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001361 // Hotseat aligns to the left with nav buttons
1362 if (hotseatBarEndOffset > 0) {
Jon Mirandae17a9492023-03-08 16:42:20 -08001363 startSpacing = inlineNavButtonsEndSpacingPx;
Helen Cheuke76291f2023-02-14 17:11:05 +00001364 endSpacing = availableWidthPx - hotseatWidth - startSpacing + hotseatBorderSpace;
1365 } else {
1366 startSpacing = (availableWidthPx - hotseatWidth) / 2;
1367 endSpacing = startSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001368 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001369 startSpacing += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001370
Helen Cheuke76291f2023-02-14 17:11:05 +00001371 hotseatBarPadding.top = hotseatBarTopPadding;
1372 hotseatBarPadding.bottom = hotseatBarBottomPadding;
Alex Chau51da2192022-05-20 13:32:10 +01001373 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001374 if (isRtl) {
Helen Cheuke76291f2023-02-14 17:11:05 +00001375 hotseatBarPadding.left = endSpacing;
1376 hotseatBarPadding.right = startSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001377 } else {
Helen Cheuke76291f2023-02-14 17:11:05 +00001378 hotseatBarPadding.left = startSpacing;
1379 hotseatBarPadding.right = endSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001380 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001381
Thales Lima425f6822022-05-10 13:44:58 -03001382 } else if (isScalableGrid) {
Alex Chau206ede92022-08-01 17:46:12 +01001383 int sideSpacing = (availableWidthPx - hotseatQsbWidth) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001384 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001385 0,
Thales Lima425f6822022-05-10 13:44:58 -03001386 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001387 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001388 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001389 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1390 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1391 // for this, we pad the left and right of the hotseat with half of the difference of a
1392 // workspace cell vs a hotseat cell.
1393 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001394 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001395 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001396 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001397 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1398 + mInsets.left,
1399 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001400 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001401 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001402 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001403 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001404 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001405 }
1406
Thales Lima9938c2f2022-07-25 14:38:16 +01001407 private int getAdditionalQsbSpace() {
1408 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1409 }
1410
1411 /**
1412 * Calculate how much space the hotseat needs to be shown completely
1413 */
1414 private int getHotseatRequiredWidth() {
1415 int additionalQsbSpace = getAdditionalQsbSpace();
1416 return iconSizePx * numShownHotseatIcons
Thales Lima6a590062022-11-22 15:52:49 +00001417 + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1))
Thales Lima9938c2f2022-07-25 14:38:16 +01001418 + additionalQsbSpace;
1419 }
1420
Winsonfadbe8f2016-07-22 16:35:37 -07001421 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001422 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1423 */
1424 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001425 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001426 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1427 } else if (isTaskbarPresent) { // QSB on top
1428 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001429 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001430 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001431 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001432 }
1433
Thales Limab8c05952022-05-23 16:58:38 +01001434 /**
1435 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1436 */
1437 private int getHotseatBarBottomPadding() {
1438 if (isTaskbarPresent) { // QSB on top or inline
1439 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001440 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001441 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001442 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001443 }
1444
1445 /**
Alex Chau51da2192022-05-20 13:32:10 +01001446 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1447 */
1448 public int getTaskbarOffsetY() {
Jon Miranda9c478b62023-03-23 21:38:49 -07001449 int taskbarIconBottomSpace = (taskbarHeight - iconSizePx) / 2;
Alex Chau51da2192022-05-20 13:32:10 +01001450 int launcherIconBottomSpace =
1451 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001452 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001453 }
1454
1455 /**
Alex Chaua2fc7642022-04-21 14:20:23 +01001456 * Returns the number of pixels required below OverviewActions excluding insets.
1457 */
1458 public int getOverviewActionsClaimedSpaceBelow() {
Alex Chaud67ddc42022-09-30 18:15:56 +01001459 if (isTaskbarPresent) {
Jon Miranda9c478b62023-03-23 21:38:49 -07001460 return taskbarHeight + taskbarBottomMargin * 2;
Alex Chaud67ddc42022-09-30 18:15:56 +01001461 }
1462 return mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001463 }
1464
1465 /** Gets the space that the overview actions will take, including bottom margin. */
1466 public int getOverviewActionsClaimedSpace() {
Pat Manning7b8f7662023-01-18 14:48:30 +00001467 int overviewActionsSpace = isTablet && FeatureFlags.ENABLE_GRID_ONLY_OVERVIEW.get()
1468 ? 0
1469 : (overviewActionsTopMarginPx + overviewActionsHeight);
1470 return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
Alex Chaua2fc7642022-04-21 14:20:23 +01001471 }
1472
1473 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001474 * Takes the View and return the scales of width and height depending on the DeviceProfile
1475 * specifications
1476 *
1477 * @param itemInfo The tag of the widget view
1478 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1479 * height
1480 */
1481 @NonNull
1482 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1483 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1484 }
1485
1486 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001487 * @return the bounds for which the open folders should be contained within
1488 */
1489 public Rect getAbsoluteOpenFolderBounds() {
1490 if (isVerticalBarLayout()) {
1491 // Folders should only appear right of the drop target bar and left of the hotseat
1492 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1493 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001494 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001495 mInsets.top + availableHeightPx);
1496 } else {
1497 // Folders should only appear below the drop target bar and above the hotseat
Jon Miranda9c478b62023-03-23 21:38:49 -07001498 int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001499 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001500 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001501 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001502 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001503 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001504 }
1505 }
1506
Jon Miranda228877d2021-02-09 11:05:00 -05001507 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1508 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001509 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001510
Jon Miranda228877d2021-02-09 11:05:00 -05001511 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1512 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001513 }
1514
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001515 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001516 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1517 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1518 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001519 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001520 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001521 return isLandscape && transposeLayoutWithOrientation;
1522 }
1523
Sunny Goyal59d086c2018-05-07 17:31:40 -07001524 /**
1525 * Updates orientation information and returns true if it has changed from the previous value.
1526 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001527 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001528 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001529 boolean isSeascape = DisplayController.INSTANCE.get(context)
1530 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001531 if (mIsSeascape != isSeascape) {
1532 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001533 // Hotseat changing sides requires updating workspace left/right paddings
1534 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001535 return true;
1536 }
1537 }
1538 return false;
1539 }
1540
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001541 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001542 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001543 }
1544
Sunny Goyal07b69292018-01-08 14:19:34 -08001545 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001546 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001547 }
1548
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001549 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001550 switch (containerType) {
1551 case CellLayout.WORKSPACE:
1552 return cellHeightPx;
1553 case CellLayout.FOLDER:
1554 return folderCellHeightPx;
1555 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001556 // The hotseat is the only container where the cell height is going to be
1557 // different from the content within that cell.
1558 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001559 default:
1560 // ??
1561 return 0;
1562 }
1563 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001564
Jon Miranda58561d42021-03-17 10:51:54 -04001565 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001566 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001567 }
1568
Alex Chaue818bcb2022-09-02 17:27:11 +01001569 private String dpPointFToString(String name, PointF value) {
1570 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
1571 }
1572
Pat Manning5f74bfd2022-07-20 12:08:54 +01001573 /** Dumps various DeviceProfile variables to the specified writer. */
1574 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04001575 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001576 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001577
1578 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001579 writer.println(prefix + "\tisPhone:" + isPhone);
1580 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1581 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001582 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001583
1584 writer.println(prefix + "\tisLandscape:" + isLandscape);
1585 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001586 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001587
1588 writer.println(prefix + pxToDpStr("windowX", windowX));
1589 writer.println(prefix + pxToDpStr("windowY", windowY));
1590 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1591 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001592 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1593 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001594 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1595 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1596 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1597 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001598
1599 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1600
Thales Limac98b7812023-04-14 15:04:23 +01001601 writer.println(prefix + "\tisResponsiveGrid:" + mIsResponsiveGrid);
Jon Miranda58561d42021-03-17 10:51:54 -04001602 writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
1603
Thales Lima83bedbf2021-10-05 17:47:39 +01001604 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001605 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1606 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1607 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001608
Alex Chaue818bcb2022-09-02 17:27:11 +01001609 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07001610
Jon Miranda58561d42021-03-17 10:51:54 -04001611 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1612 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1613
1614 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1615 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1616
Thales Lima83bedbf2021-10-05 17:47:39 +01001617 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1618 cellLayoutBorderSpacePx.x));
1619 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1620 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001621 writer.println(
1622 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
1623 writer.println(
1624 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
1625 writer.println(
1626 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01001627 writer.println(
1628 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01001629
Jon Miranda58561d42021-03-17 10:51:54 -04001630 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1631 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1632 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1633
Helen Cheuk599109b2023-02-23 17:15:39 +00001634 writer.println(prefix + "\tinv.numFolderRows: " + inv.numFolderRows);
1635 writer.println(prefix + "\tinv.numFolderColumns: " + inv.numFolderColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001636 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1637 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1638 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1639 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1640 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1641 folderChildDrawablePaddingPx));
Thales Limab35faed2022-09-05 16:30:01 -03001642 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx",
1643 folderCellLayoutBorderSpacePx));
Thales Limaa08a4432022-08-09 09:55:17 +01001644 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
1645 folderContentPaddingLeftRight));
1646 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03001647 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001648
Alex Chaue0227552022-04-06 19:44:43 +01001649 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001650 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
1651 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
1652 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
1653 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01001654
1655 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
1656 writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001657 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
1658 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04001659 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1660 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1661 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1662 allAppsIconDrawablePaddingPx));
1663 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001664 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001665 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
1666 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001667 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau62572c02022-07-25 18:36:37 +00001668 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
Alex Chau27b39b92022-01-14 18:02:18 +00001669 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001670
1671 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03001672 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04001673 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00001674 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Jon Miranda58561d42021-03-17 10:51:54 -04001675 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
1676 hotseatBarSidePaddingStartPx));
1677 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
1678 hotseatBarSidePaddingEndPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001679 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01001680 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
1681 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01001682 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
1683 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001684 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
1685 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
1686 hotseatLayoutPadding.top));
1687 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
1688 hotseatLayoutPadding.bottom));
1689 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
1690 hotseatLayoutPadding.left));
1691 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
1692 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001693 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001694 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001695 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01001696 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001697
1698 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001699 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda9c478b62023-03-23 21:38:49 -07001700 writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight));
1701 writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight));
1702 writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin));
1703 writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001704
Thales Lima83bedbf2021-10-05 17:47:39 +01001705 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1706 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001707 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
1708 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
1709 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00001710 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001711
Jon Mirandaab3c6812021-06-28 15:42:28 -07001712 writer.println(prefix + pxToDpStr("iconScale", iconScale));
1713 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04001714 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00001715 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001716
Thales Lima171ee662022-11-22 15:52:49 +00001717 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04001718 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
1719 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00001720
1721 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00001722 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
1723 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
1724 overviewTaskIconDrawableSizePx));
1725 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
1726 overviewTaskIconDrawableSizeGridPx));
1727 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
1728 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01001729 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
1730 overviewActionsTopMarginPx));
1731 writer.println(prefix + pxToDpStr("overviewActionsHeight",
1732 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00001733 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
1734 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00001735 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
1736 overviewActionsButtonSpacing));
1737 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
1738 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
1739 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01001740
Alex Chau62572c02022-07-25 18:36:37 +00001741 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001742 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00001743 writer.println(
1744 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001745
Pat Manning5f74bfd2022-07-20 12:08:54 +01001746 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
1747 getCellLayoutSpringLoadShrunkTop()));
1748 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
1749 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01001750 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
1751 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001752 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
1753 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01001754 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
1755 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Jon Miranda58561d42021-03-17 10:51:54 -04001756 }
1757
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00001758 /** Returns a reduced representation of this DeviceProfile. */
1759 public String toSmallString() {
1760 return "isTablet:" + isTablet + ", "
1761 + "isMultiDisplay:" + isMultiDisplay + ", "
1762 + "widthPx:" + widthPx + ", "
1763 + "heightPx:" + heightPx + ", "
1764 + "insets:" + mInsets + ", "
1765 + "rotationHint:" + rotationHint;
1766 }
1767
Alex Chaua6907dc2022-03-18 15:24:07 +00001768 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07001769 Configuration config = new Configuration(c.getResources().getConfiguration());
1770 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03001771 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00001772 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07001773 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07001774 }
Sunny Goyalfde55052018-02-01 14:46:13 -08001775
1776 /**
1777 * Callback when a component changes the DeviceProfile associated with it, as a result of
1778 * configuration change
1779 */
1780 public interface OnDeviceProfileChangeListener {
1781
1782 /**
1783 * Called when the device profile is reassigned. Note that for layout and measurements, it
1784 * is sufficient to listen for inset changes. Use this callback when you need to perform
1785 * a one time operation.
1786 */
1787 void onDeviceProfileChanged(DeviceProfile dp);
1788 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001789
Sihua Mae04aa202022-07-18 12:43:56 -07001790 /**
1791 * Handler that deals with ItemInfo of the views for the DeviceProfile
1792 */
1793 @FunctionalInterface
1794 public interface ViewScaleProvider {
1795 /**
1796 * Get the scales from the view
1797 *
1798 * @param itemInfo The tag of the widget view
1799 * @return PointF instance containing the scale information, or null if using the default
1800 * app widget scale of this device profile.
1801 */
1802 @NonNull
1803 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
1804 }
1805
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001806 public static class Builder {
1807 private Context mContext;
1808 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07001809 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001810
Sunny Goyal19ff7282021-04-22 10:12:54 -07001811 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00001812 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001813
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001814 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001815 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00001816 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07001817 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001818
Sunny Goyal65190ae2022-08-02 14:16:26 -07001819 private SparseArray<DotRenderer> mDotRendererCache;
1820
Jon Miranda2b25ded2023-02-02 14:48:45 -08001821 private Consumer<DeviceProfile> mOverrideProvider;
1822
Sunny Goyalfd58da62020-08-11 12:06:49 -07001823 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001824 mContext = context;
1825 mInv = inv;
1826 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001827 }
1828
1829 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1830 mIsMultiWindowMode = isMultiWindowMode;
1831 return this;
1832 }
1833
Alex Chauab800f72022-12-13 17:46:06 +00001834 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
1835 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001836 return this;
1837 }
1838
Sunny Goyal65190ae2022-08-02 14:16:26 -07001839 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
1840 mDotRendererCache = dotRendererCache;
1841 return this;
1842 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07001843
1844 public Builder setWindowBounds(WindowBounds bounds) {
1845 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07001846 return this;
1847 }
1848
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001849 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1850 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1851 return this;
1852 }
1853
Alex Chau6ed408f2022-03-04 12:58:05 +00001854 public Builder setGestureMode(boolean isGestureMode) {
1855 mIsGestureMode = isGestureMode;
1856 return this;
1857 }
1858
Jon Miranda2b25ded2023-02-02 14:48:45 -08001859 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
1860 mOverrideProvider = overrideProvider;
1861 return this;
1862 }
1863
Sihua Mae04aa202022-07-18 12:43:56 -07001864 /**
1865 * Set the viewScaleProvider for the builder
1866 *
1867 * @param viewScaleProvider The viewScaleProvider to be set for the
Thales Limae9273ea2023-01-26 12:33:52 +00001868 * DeviceProfile
Sihua Mae04aa202022-07-18 12:43:56 -07001869 * @return This builder
1870 */
1871 @NonNull
1872 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
1873 mViewScaleProvider = viewScaleProvider;
1874 return this;
1875 }
1876
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001877 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001878 if (mWindowBounds == null) {
1879 throw new IllegalArgumentException("Window bounds not set");
1880 }
1881 if (mTransposeLayoutWithOrientation == null) {
1882 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
1883 }
Alex Chau6ed408f2022-03-04 12:58:05 +00001884 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01001885 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00001886 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001887 if (mDotRendererCache == null) {
1888 mDotRendererCache = new SparseArray<>();
1889 }
Sihua Mae04aa202022-07-18 12:43:56 -07001890 if (mViewScaleProvider == null) {
1891 mViewScaleProvider = DEFAULT_PROVIDER;
1892 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08001893 if (mOverrideProvider == null) {
1894 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
1895 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001896 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00001897 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jon Miranda2b25ded2023-02-02 14:48:45 -08001898 mIsGestureMode, mViewScaleProvider, mOverrideProvider);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001899 }
1900 }
1901
Winson Chungb3800242013-10-24 11:01:54 -07001902}