blob: baa170bfa1ab338520d712b697956196cd772f8a [file] [log] [blame]
Winson Chungb3800242013-10-24 11:01:54 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.launcher3;
18
Kateryna Ivanova71203732023-05-24 15:09:00 +000019import static com.android.app.animation.Interpolators.LINEAR;
Thales Lima12d0eff2022-03-25 17:06:11 +000020import static com.android.launcher3.InvariantDeviceProfile.INDEX_DEFAULT;
21import static com.android.launcher3.InvariantDeviceProfile.INDEX_LANDSCAPE;
22import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_LANDSCAPE;
23import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_PORTRAIT;
Jon Miranda58561d42021-03-17 10:51:54 -040024import static com.android.launcher3.Utilities.dpiFromPx;
Jon Mirandaaf3aed02021-05-06 18:28:45 -070025import static com.android.launcher3.Utilities.pxFromSp;
Alex Chauab800f72022-12-13 17:46:06 +000026import static com.android.launcher3.config.FeatureFlags.ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH;
Jon Miranda92c1b5d2021-07-20 13:57:16 -070027import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.ICON_OVERLAP_FACTOR;
Sunny Goyal65190ae2022-08-02 14:16:26 -070028import static com.android.launcher3.icons.GraphicsUtils.getShapePath;
Jon Miranda95f44722023-06-06 19:48:19 -070029import static com.android.launcher3.icons.IconNormalizer.ICON_VISIBLE_AREA_FACTOR;
Thales Limab35faed2022-09-05 16:30:01 -030030import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURCE_HANDLE;
Pat Manning5f74bfd2022-07-20 12:08:54 +010031import static com.android.launcher3.testing.shared.ResourceUtils.pxFromDp;
Thales Lima7eee74b2023-03-16 16:00:55 -030032import static com.android.launcher3.testing.shared.ResourceUtils.roundPxValueFromFloat;
Jon Miranda228877d2021-02-09 11:05:00 -050033
Sunny Goyal35c7b192021-04-20 16:51:10 -070034import android.annotation.SuppressLint;
Winson Chungb3800242013-10-24 11:01:54 -070035import android.content.Context;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070036import android.content.res.Configuration;
Winson Chungb3800242013-10-24 11:01:54 -070037import android.content.res.Resources;
Thales Limab35faed2022-09-05 16:30:01 -030038import android.content.res.TypedArray;
Winson Chungb3800242013-10-24 11:01:54 -070039import android.graphics.Point;
Jon Miranda7ae64ff2016-11-21 16:18:46 -080040import android.graphics.PointF;
Winson Chungb3800242013-10-24 11:01:54 -070041import android.graphics.Rect;
Sunny Goyal35c7b192021-04-20 16:51:10 -070042import android.util.DisplayMetrics;
Alex Chau2014f502023-09-12 19:18:46 +010043import android.util.Log;
Sunny Goyal65190ae2022-08-02 14:16:26 -070044import android.util.SparseArray;
Sunny Goyal59d086c2018-05-07 17:31:40 -070045import android.view.Surface;
Winson Chungb3800242013-10-24 11:01:54 -070046
Sunny Goyal65190ae2022-08-02 14:16:26 -070047import androidx.annotation.NonNull;
Sihua Mae04aa202022-07-18 12:43:56 -070048import androidx.annotation.Nullable;
Jon Miranda9c478b62023-03-23 21:38:49 -070049import androidx.core.content.res.ResourcesCompat;
Sunny Goyal65190ae2022-08-02 14:16:26 -070050
Sunny Goyalc13403c2016-11-18 23:44:48 -080051import com.android.launcher3.CellLayout.ContainerType;
Jon Miranda228877d2021-02-09 11:05:00 -050052import com.android.launcher3.DevicePaddings.DevicePadding;
Alex Chaud67ddc42022-09-30 18:15:56 +010053import com.android.launcher3.config.FeatureFlags;
Tony Wickham8912b042018-11-29 15:28:53 -080054import com.android.launcher3.icons.DotRenderer;
Hyunyoung Song48cb7bc2018-09-25 17:03:34 -070055import com.android.launcher3.icons.IconNormalizer;
Sihua Mae04aa202022-07-18 12:43:56 -070056import com.android.launcher3.model.data.ItemInfo;
Thales Limaabfe3642023-05-24 18:08:53 +010057import com.android.launcher3.responsive.AllAppsSpecs;
58import com.android.launcher3.responsive.CalculatedAllAppsSpec;
Jordan Silva637f4eb2023-06-13 11:21:53 +010059import com.android.launcher3.responsive.CalculatedFolderSpec;
Thales Limaf8bfb032023-07-24 15:08:05 +010060import com.android.launcher3.responsive.CalculatedHotseatSpec;
Jordan Silva8bd7af22023-06-21 15:35:03 +010061import com.android.launcher3.responsive.CalculatedWorkspaceSpec;
Jordan Silva637f4eb2023-06-13 11:21:53 +010062import com.android.launcher3.responsive.FolderSpecs;
Thales Limaf8bfb032023-07-24 15:08:05 +010063import com.android.launcher3.responsive.HotseatSpecs;
Jordan Silva8bd7af22023-06-21 15:35:03 +010064import com.android.launcher3.responsive.WorkspaceSpecs;
Sunny Goyal57b22792021-05-25 14:35:01 -070065import com.android.launcher3.uioverrides.ApiWrapper;
Sunny Goyalfd58da62020-08-11 12:06:49 -070066import com.android.launcher3.util.DisplayController;
67import com.android.launcher3.util.DisplayController.Info;
Thales Lima2759aa32023-06-05 16:25:45 +010068import com.android.launcher3.util.IconSizeSteps;
Thales Limac98b7812023-04-14 15:04:23 +010069import com.android.launcher3.util.ResourceHelper;
Sunny Goyalb46703d2020-05-27 17:52:03 -070070import com.android.launcher3.util.WindowBounds;
Winson1f064272016-07-18 17:18:02 -070071
Jon Miranda58561d42021-03-17 10:51:54 -040072import java.io.PrintWriter;
Alex Chaue818bcb2022-09-02 17:27:11 +010073import java.util.Locale;
Jon Miranda2b25ded2023-02-02 14:48:45 -080074import java.util.function.Consumer;
Jon Miranda58561d42021-03-17 10:51:54 -040075
Sunny Goyal35c7b192021-04-20 16:51:10 -070076@SuppressLint("NewApi")
Winson Chungb3800242013-10-24 11:01:54 -070077public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070078
Sunny Goyal8b9919d2021-04-07 14:45:17 -070079 private static final int DEFAULT_DOT_SIZE = 100;
Alex Chau206ede92022-08-01 17:46:12 +010080 private static final float ALL_APPS_TABLET_MAX_ROWS = 5.5f;
Thales Limab35faed2022-09-05 16:30:01 -030081 private static final float MIN_FOLDER_TEXT_SIZE_SP = 16f;
Sunny Goyal6c304b12023-04-10 12:03:04 -070082 private static final float MIN_WIDGET_PADDING_DP = 6f;
Alex Chau206ede92022-08-01 17:46:12 +010083
Sihua Mae04aa202022-07-18 12:43:56 -070084 public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f);
85 public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE;
Jordan Silva637f4eb2023-06-13 11:21:53 +010086 public static final Consumer<DeviceProfile> DEFAULT_DIMENSION_PROVIDER = dp -> {};
Sihua Mae04aa202022-07-18 12:43:56 -070087
Adam Cohen2e6da152015-05-06 11:42:25 -070088 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070089 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070090 private final DisplayMetrics mMetrics;
Thales Lima2759aa32023-06-05 16:25:45 +010091 private final IconSizeSteps mIconSizeSteps;
Winson Chungbe876472014-05-14 14:15:20 -070092
Sunny Goyalc6205602015-05-21 20:46:33 -070093 // Device properties
94 public final boolean isTablet;
Sunny Goyalc6205602015-05-21 20:46:33 -070095 public final boolean isPhone;
96 public final boolean transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +000097 public final boolean isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -070098 public final boolean isTwoPanels;
Thales Limaa1012902022-01-13 17:58:42 +000099 public final boolean isQsbInline;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700100
Sunny Goyalc6205602015-05-21 20:46:33 -0700101 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -0700102 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -0800103 public final boolean isMultiWindowMode;
Alex Chau6ed408f2022-03-04 12:58:05 +0000104 public final boolean isGestureMode;
Sunny Goyald70e75a2018-02-22 10:07:32 -0800105
Sunny Goyal0addbf02020-04-28 14:17:35 -0700106 public final int windowX;
107 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -0700108 public final int widthPx;
109 public final int heightPx;
110 public final int availableWidthPx;
111 public final int availableHeightPx;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800112 public final int rotationHint;
Jon Mirandabba64512019-03-27 10:54:17 -0700113
114 public final float aspectRatio;
115
Thales Lima79456492023-05-23 11:32:22 +0100116 private final boolean mIsScalableGrid;
Thales Lima83bedbf2021-10-05 17:47:39 +0100117 private final int mTypeIndex;
Jon Mirandae126d722021-02-25 10:45:20 -0500118
Thales Limac98b7812023-04-14 15:04:23 +0100119 // Responsive grid
120 private final boolean mIsResponsiveGrid;
Thales Limac98b7812023-04-14 15:04:23 +0100121 private CalculatedWorkspaceSpec mResponsiveWidthSpec;
122 private CalculatedWorkspaceSpec mResponsiveHeightSpec;
Thales Limaabfe3642023-05-24 18:08:53 +0100123 private CalculatedAllAppsSpec mAllAppsResponsiveWidthSpec;
124 private CalculatedAllAppsSpec mAllAppsResponsiveHeightSpec;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100125 private CalculatedFolderSpec mResponsiveFolderWidthSpec;
126 private CalculatedFolderSpec mResponsiveFolderHeightSpec;
Thales Limaf8bfb032023-07-24 15:08:05 +0100127 private CalculatedHotseatSpec mResponsiveHotseatSpec;
Thales Limac98b7812023-04-14 15:04:23 +0100128
Tony Wickhamd6b40372015-09-23 18:37:57 -0700129 /**
130 * The maximum amount of left/right workspace padding as a percentage of the screen width.
131 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
132 * 7% of the screen width can be used as right padding.
133 */
134 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -0700135
Jon Miranda3f9bab22017-07-28 14:50:17 -0700136 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700137 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda80dda302021-07-28 14:14:59 -0700138 private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252;
139 private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700140
Sunny Goyalc6205602015-05-21 20:46:33 -0700141 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +0100142 public final int desiredWorkspaceHorizontalMarginOriginalPx;
143 public int desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100144 public int gridVisualizationPaddingX;
145 public int gridVisualizationPaddingY;
Thales Lima78d00ad2021-09-30 11:29:06 +0100146 public Point cellLayoutBorderSpaceOriginalPx;
147 public Point cellLayoutBorderSpacePx;
Pat Manning08610ca2022-04-05 21:03:16 +0100148 public Rect cellLayoutPaddingPx = new Rect();
149
Sunny Goyalc6205602015-05-21 20:46:33 -0700150 public final int edgeMarginPx;
Alex Chau0c4e11b2022-07-08 18:41:36 +0100151 public final float workspaceContentScale;
Alex Chau906d8822022-05-23 10:42:25 +0100152 public final int workspaceSpringLoadedMinNextPageVisiblePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700153
Jon Miranda58561d42021-03-17 10:51:54 -0400154 private final int extraSpace;
Thales Lima171ee662022-11-22 15:52:49 +0000155 private int maxEmptySpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500156 public int workspaceTopPadding;
157 public int workspaceBottomPadding;
158
Tony Wickham5edf9e22020-03-27 20:06:52 -0700159 // Workspace page indicator
160 public final int workspacePageIndicatorHeight;
161 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700162
Sunny Goyalc6205602015-05-21 20:46:33 -0700163 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400164 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700165 public int iconSizePx;
166 public int iconTextSizePx;
167 public int iconDrawablePaddingPx;
Thales Lima93ee8fc2023-06-05 17:07:11 +0100168 private final int mIconDrawablePaddingOriginalPx;
Thales Lima79456492023-05-23 11:32:22 +0100169 public boolean iconCenterVertically;
Winson Chungb3800242013-10-24 11:01:54 -0700170
Jon Mirandaab3c6812021-06-28 15:42:28 -0700171 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800172 public int cellWidthPx;
173 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700174 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800175
Thales Lima79456492023-05-23 11:32:22 +0100176 public int cellYPaddingPx = -1;
Jon Mirandae126d722021-02-25 10:45:20 -0500177
Sunny Goyalc6205602015-05-21 20:46:33 -0700178 // Folder
Jon Mirandae126d722021-02-25 10:45:20 -0500179 public float folderLabelTextScale;
180 public int folderLabelTextSizePx;
Thales Limab35faed2022-09-05 16:30:01 -0300181 public int folderFooterHeightPx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700182 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700183 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700184
Jon Mirandae126d722021-02-25 10:45:20 -0500185 // Folder content
Jordan Silva637f4eb2023-06-13 11:21:53 +0100186 public Point folderCellLayoutBorderSpacePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500187 public int folderContentPaddingLeftRight;
188 public int folderContentPaddingTop;
189
Jon Mirandabf7d8122016-11-03 15:29:29 -0700190 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700191 public int folderCellWidthPx;
192 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700193
194 // Folder child
195 public int folderChildIconSizePx;
196 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700197 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700198
Sunny Goyalc6205602015-05-21 20:46:33 -0700199 // Hotseat
Thales Lima9938c2f2022-07-25 14:38:16 +0100200 public int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700201 public int hotseatCellHeightPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100202 public final boolean areNavButtonsInline;
Jon Miranda18751b62017-07-31 17:25:27 -0700203 // In portrait: size = height, in landscape: size = width
204 public int hotseatBarSizePx;
Thales Limab8c05952022-05-23 16:58:38 +0100205 public int hotseatBarBottomSpacePx;
Pat Manning26f70f72022-07-07 13:50:39 +0100206 public int hotseatBarEndOffset;
Thales Limab8c05952022-05-23 16:58:38 +0100207 public int hotseatQsbSpace;
Pat Manningde25c0d2022-04-05 19:11:26 +0100208 public int springLoadedHotseatBarTopMarginPx;
Thales Lima8e11d532023-08-31 13:40:26 +0000209 // These 2 values are only used for isVerticalBar
210 // Padding between edge of screen and hotseat
211 public final int mHotseatBarEdgePaddingPx;
212 // Space between hotseat and workspace (not used in responsive)
213 public final int mHotseatBarWorkspaceSpacePx;
Alex Chau206ede92022-08-01 17:46:12 +0100214 public int hotseatQsbWidth; // only used when isQsbInline
Sunny Goyal57b22792021-05-25 14:35:01 -0700215 public final int hotseatQsbHeight;
Thales Limab8c05952022-05-23 16:58:38 +0100216 public final int hotseatQsbVisualHeight;
217 private final int hotseatQsbShadowHeight;
Thales Limadd027342022-01-07 12:54:37 +0000218 public int hotseatBorderSpace;
Thales Limaffc68b02023-01-09 16:20:23 +0000219 private final int mMinHotseatIconSpacePx;
220 private final int mMinHotseatQsbWidthPx;
221 private final int mMaxHotseatIconSpacePx;
Jon Mirandae17a9492023-03-08 16:42:20 -0800222 public final int inlineNavButtonsEndSpacingPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700223
Alex Chau3d2c0622022-09-01 21:28:14 +0100224 // Bottom sheets
225 public int bottomSheetTopPadding;
226 public int bottomSheetOpenDuration;
227 public int bottomSheetCloseDuration;
228 public float bottomSheetWorkspaceScale;
229 public float bottomSheetDepth;
230
Sunny Goyalc6205602015-05-21 20:46:33 -0700231 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000232 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000233 public int allAppsShiftRange;
234 public int allAppsTopPadding;
Alex Chau3d2c0622022-09-01 21:28:14 +0100235 public int allAppsOpenDuration;
236 public int allAppsCloseDuration;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700237 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700238 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700239 public int allAppsIconSizePx;
240 public int allAppsIconDrawablePaddingPx;
sfufa@google.comde013292021-09-21 18:22:44 -0700241 public int allAppsLeftRightPadding;
Alex Chau27b39b92022-01-14 18:02:18 +0000242 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700243 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700244 public float allAppsIconTextSizePx;
245
Zak Cohen334efeb2021-03-19 16:42:07 -0700246 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700247 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000248 public int overviewTaskIconSizePx;
Alex Chauac9df382021-08-02 19:08:41 +0100249 public int overviewTaskIconDrawableSizePx;
250 public int overviewTaskIconDrawableSizeGridPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000251 public int overviewTaskThumbnailTopMarginPx;
Alex Chau19c6eca2022-03-10 20:12:56 +0000252 public final int overviewActionsHeight;
Alex Chaua2fc7642022-04-21 14:20:23 +0100253 public final int overviewActionsTopMarginPx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000254 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100255 public int overviewPageSpacing;
256 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000257 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700258
Jeremy Sim0ac47082022-10-10 13:59:40 -0700259 // Split staging
260 public int splitPlaceholderInset;
261
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800262 // Widgets
Sihua Mae04aa202022-07-18 12:43:56 -0700263 private final ViewScaleProvider mViewScaleProvider;
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800264
Sunny Goyal47328fd2016-05-25 18:56:41 -0700265 // Drop Target
266 public int dropTargetBarSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100267 public int dropTargetBarTopMarginPx;
268 public int dropTargetBarBottomMarginPx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100269 public int dropTargetDragPaddingPx;
270 public int dropTargetTextSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100271 public int dropTargetHorizontalPaddingPx;
272 public int dropTargetVerticalPaddingPx;
273 public int dropTargetGapPx;
Alex Chau5b019302022-05-23 10:42:25 +0100274 public int dropTargetButtonWorkspaceEdgeGapPx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700275
Winson1f064272016-07-18 17:18:02 -0700276 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800277 private final Rect mInsets = new Rect();
278 public final Rect workspacePadding = new Rect();
Sunny Goyal6c304b12023-04-10 12:03:04 -0700279 // Additional padding added to the widget inside its cellSpace. It is applied outside
280 // the widgetView, such that the actual view size is same as the widget size.
281 public final Rect widgetPadding = new Rect();
282
Jon Miranda0bd63d12019-03-06 17:29:29 -0800283 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700284 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700285
Tony Wickhamf34bee82018-12-03 18:11:39 -0800286 // Notification dots
Sunny Goyal65190ae2022-08-02 14:16:26 -0700287 public final DotRenderer mDotRendererWorkSpace;
288 public final DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800289
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100290 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800291 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000292 // Whether Taskbar will inset the bottom of apps by taskbarSize.
293 public boolean isTaskbarPresentInApps;
Jon Miranda9c478b62023-03-23 21:38:49 -0700294 public final int taskbarHeight;
295 public final int stashedTaskbarHeight;
296 public final int taskbarBottomMargin;
297 public final int taskbarIconSize;
Jon Miranda04f05102023-04-04 12:16:31 -0700298 // If true, used to layout taskbar in 3 button navigation mode.
299 public final boolean startAlignTaskbar;
Thales Limae9566402023-08-30 16:35:12 +0100300 public final boolean isTransientTaskbar;
Tony Wickham15883892021-02-12 11:24:40 -0800301
Alex Chaua02eddc2021-04-29 00:36:06 +0100302 // DragController
303 public int flingToDeleteThresholdVelocity;
304
Vinit Nayak17c4b332021-08-05 12:54:58 -0700305 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700306 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal65190ae2022-08-02 14:16:26 -0700307 SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
Alex Chauab800f72022-12-13 17:46:06 +0000308 boolean transposeLayoutWithOrientation, boolean isMultiDisplay, boolean isGestureMode,
Jon Miranda2b25ded2023-02-02 14:48:45 -0800309 @NonNull final ViewScaleProvider viewScaleProvider,
310 @NonNull final Consumer<DeviceProfile> dimensionOverrideProvider) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700311
Adam Cohen2e6da152015-05-06 11:42:25 -0700312 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700313 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800314 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500315 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +0000316 this.isMultiDisplay = isMultiDisplay;
Alex Chau6ed408f2022-03-04 12:58:05 +0000317 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700318 windowX = windowBounds.bounds.left;
319 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800320 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100321 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700322
Thales Limac98b7812023-04-14 15:04:23 +0100323 // TODO(b/241386436): shouldn't change any launcher behaviour
Thales Limaabfe3642023-05-24 18:08:53 +0100324 mIsResponsiveGrid = inv.workspaceSpecsId != INVALID_RESOURCE_HANDLE
Jordan Silva637f4eb2023-06-13 11:21:53 +0100325 && inv.allAppsSpecsId != INVALID_RESOURCE_HANDLE
Thales Limaf8bfb032023-07-24 15:08:05 +0100326 && inv.folderSpecsId != INVALID_RESOURCE_HANDLE
327 && inv.hotseatSpecsId != INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100328
Thales Lima79456492023-05-23 11:32:22 +0100329 mIsScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000330 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700331 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000332 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700333 isPhone = !isTablet;
Alex Chauab800f72022-12-13 17:46:06 +0000334 isTwoPanels = isTablet && isMultiDisplay;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800335 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700336
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000337 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000338 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700339 ? Configuration.ORIENTATION_LANDSCAPE
340 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000341 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700342 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000343 mMetrics = res.getDisplayMetrics();
344
Thales Lima2759aa32023-06-05 16:25:45 +0100345 mIconSizeSteps = mIsResponsiveGrid ? new IconSizeSteps(res) : null;
346
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000347 // Determine sizes.
348 widthPx = windowBounds.bounds.width();
349 heightPx = windowBounds.bounds.height();
350 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100351 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000352
353 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Thales Lima83bedbf2021-10-05 17:47:39 +0100354 if (isTwoPanels) {
355 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000356 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100357 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000358 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100359 }
360 } else {
361 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000362 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100363 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000364 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100365 }
366 }
Alex Chau2014f502023-09-12 19:18:46 +0100367 if (InvariantDeviceProfile.sDebug) {
368 Log.d("b/298077774",
369 "DeviceProfile - mTypeIndex: " + mTypeIndex + ": " + dpPointFToString(
370 "minCellSize",
371 inv.minCellSize[mTypeIndex]));
372 }
Thales Lima83bedbf2021-10-05 17:47:39 +0100373
Thales Limae9566402023-08-30 16:35:12 +0100374 isTransientTaskbar = DisplayController.isTransientTaskbar(context);
375 if (isTransientTaskbar) {
Jon Miranda9c478b62023-03-23 21:38:49 -0700376 float invTransientIconSizeDp = inv.transientTaskbarIconSize[mTypeIndex];
377 taskbarIconSize = pxFromDp(invTransientIconSizeDp, mMetrics);
Jon Miranda95f44722023-06-06 19:48:19 -0700378 taskbarHeight = Math.round((taskbarIconSize * ICON_VISIBLE_AREA_FACTOR)
379 + (2 * res.getDimensionPixelSize(R.dimen.transient_taskbar_padding)));
Jon Miranda9c478b62023-03-23 21:38:49 -0700380 stashedTaskbarHeight =
381 res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_height);
382 taskbarBottomMargin =
383 res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin);
Jon Miranda04f05102023-04-04 12:16:31 -0700384 startAlignTaskbar = false;
Jon Miranda9c478b62023-03-23 21:38:49 -0700385 } else {
386 taskbarIconSize = pxFromDp(ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size),
387 mMetrics);
388 taskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_size);
389 stashedTaskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
390 taskbarBottomMargin = 0;
Jon Miranda04f05102023-04-04 12:16:31 -0700391 startAlignTaskbar = inv.startAlignTaskbar[mTypeIndex];
Tony Wickham15883892021-02-12 11:24:40 -0800392 }
Tony Wickham15883892021-02-12 11:24:40 -0800393
Winson Chungb3800242013-10-24 11:01:54 -0700394 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100395 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700396
Alex Chau51da2192022-05-20 13:32:10 +0100397 gridVisualizationPaddingX = res.getDimensionPixelSize(
398 R.dimen.grid_visualization_horizontal_cell_spacing);
399 gridVisualizationPaddingY = res.getDimensionPixelSize(
400 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500401
Alex Chaue0227552022-04-06 19:44:43 +0100402 bottomSheetTopPadding = mInsets.top // statusbar height
Andras Kloczl142b0542022-03-09 21:26:02 +0000403 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
404 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
Alex Chau3d2c0622022-09-01 21:28:14 +0100405 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
406 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
407 if (isTablet) {
408 bottomSheetWorkspaceScale = workspaceContentScale;
Alex Chauab800f72022-12-13 17:46:06 +0000409 if (isMultiDisplay && !ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH.get()) {
410 // TODO(b/259893832): Revert to use maxWallpaperScale to calculate bottomSheetDepth
411 // when screen recorder bug is fixed.
412 bottomSheetDepth = 1f;
413 } else {
414 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
415 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
416 // When depth is 1, wallpaper zoom is set to 1.
417 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
418 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
419 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
420 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
421 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100422 } else {
423 bottomSheetWorkspaceScale = 1f;
424 bottomSheetDepth = 0f;
425 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000426
Jon Mirandae126d722021-02-25 10:45:20 -0500427 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
Thales Limab35faed2022-09-05 16:30:01 -0300428
Thales Lima79456492023-05-23 11:32:22 +0100429 if (mIsScalableGrid && inv.folderStyle != INVALID_RESOURCE_HANDLE) {
Thales Limab35faed2022-09-05 16:30:01 -0300430 TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
Thales Limad852d652023-01-17 14:01:13 +0000431 R.styleable.FolderStyle);
Thales Limab35faed2022-09-05 16:30:01 -0300432 // These are re-set in #updateFolderCellSize if the grid is not scalable
433 folderCellHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000434 R.styleable.FolderStyle_folderCellHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300435 folderCellWidthPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000436 R.styleable.FolderStyle_folderCellWidth, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300437
438 folderContentPaddingTop = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000439 R.styleable.FolderStyle_folderTopPadding, 0);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100440
441 int gutter = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000442 R.styleable.FolderStyle_folderBorderSpace, 0);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100443 folderCellLayoutBorderSpacePx = new Point(gutter, gutter);
Thales Limab35faed2022-09-05 16:30:01 -0300444 folderFooterHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000445 R.styleable.FolderStyle_folderFooterHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300446 folderStyle.recycle();
Jordan Silva637f4eb2023-06-13 11:21:53 +0100447 } else if (!mIsResponsiveGrid) {
448 folderCellLayoutBorderSpacePx = new Point(0, 0);
Thales Lima7eee74b2023-03-16 16:00:55 -0300449 folderFooterHeightPx = res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Thales Limab35faed2022-09-05 16:30:01 -0300450 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
451 }
Jon Mirandae126d722021-02-25 10:45:20 -0500452
Thales Lima85c942f2021-12-31 13:04:20 +0000453 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000454 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
455 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Thales Limae9273ea2023-01-26 12:33:52 +0000456 setupAllAppsStyle(context);
Jon Mirandae126d722021-02-25 10:45:20 -0500457
Tony Wickham5edf9e22020-03-27 20:06:52 -0700458 workspacePageIndicatorHeight = res.getDimensionPixelSize(
459 R.dimen.workspace_page_indicator_height);
460 mWorkspacePageIndicatorOverlapWorkspace =
461 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700462
Thales Limad852d652023-01-17 14:01:13 +0000463 TypedArray cellStyle;
464 if (inv.cellStyle != INVALID_RESOURCE_HANDLE) {
465 cellStyle = context.obtainStyledAttributes(inv.cellStyle,
466 R.styleable.CellStyle);
467 } else {
468 cellStyle = context.obtainStyledAttributes(R.style.CellStyleDefault,
469 R.styleable.CellStyle);
470 }
Thales Lima93ee8fc2023-06-05 17:07:11 +0100471 mIconDrawablePaddingOriginalPx = cellStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000472 R.styleable.CellStyle_iconDrawablePadding, 0);
473 cellStyle.recycle();
Alex Chaua02eddc2021-04-29 00:36:06 +0100474
Sunny Goyal47328fd2016-05-25 18:56:41 -0700475 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100476 dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
477 dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100478 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
479 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100480 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
481 R.dimen.drop_target_button_drawable_horizontal_padding);
482 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
483 R.dimen.drop_target_button_drawable_vertical_padding);
484 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100485 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
486 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100487
Alex Chau906d8822022-05-23 10:42:25 +0100488 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
489 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700490
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700491 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700492
Thales Limaa1012902022-01-13 17:58:42 +0000493 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100494 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
495 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
496
Thales Lima12d0eff2022-03-25 17:06:11 +0000497 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
498 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
499 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
500 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
501 && hotseatQsbHeight > 0;
Thales Lima79456492023-05-23 11:32:22 +0100502 isQsbInline = mIsScalableGrid && inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000503
Thales Lima425f6822022-05-10 13:44:58 -0300504 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100505 numShownHotseatIcons =
506 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000507
Sunny Goyal19ff7282021-04-22 10:12:54 -0700508 numShownAllAppsColumns =
509 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100510
Thales Lima8e11d532023-08-31 13:40:26 +0000511 int hotseatBarBottomSpace;
Thales Limab8c05952022-05-23 16:58:38 +0100512 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
Thales Limaf8bfb032023-07-24 15:08:05 +0100513
514 if (mIsResponsiveGrid) {
515 HotseatSpecs hotseatSpecs =
516 HotseatSpecs.create(new ResourceHelper(context,
517 isTwoPanels ? inv.hotseatSpecsTwoPanelId : inv.hotseatSpecsId));
Thales Lima8e11d532023-08-31 13:40:26 +0000518 mResponsiveHotseatSpec =
519 isVerticalBarLayout() ? hotseatSpecs.getCalculatedWidthSpec(widthPx)
520 : hotseatSpecs.getCalculatedHeightSpec(heightPx);
Thales Limaf8bfb032023-07-24 15:08:05 +0100521 hotseatQsbSpace = mResponsiveHotseatSpec.getHotseatQsbSpace();
Thales Lima8e11d532023-08-31 13:40:26 +0000522 hotseatBarBottomSpace =
523 isVerticalBarLayout() ? 0 : mResponsiveHotseatSpec.getEdgePadding();
524 mHotseatBarEdgePaddingPx =
525 isVerticalBarLayout() ? mResponsiveHotseatSpec.getEdgePadding() : 0;
526 mHotseatBarWorkspaceSpacePx = 0;
Thales Limaf8bfb032023-07-24 15:08:05 +0100527 } else {
528 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
Thales Lima8e11d532023-08-31 13:40:26 +0000529 hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
530 mHotseatBarEdgePaddingPx =
531 isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
532 mHotseatBarWorkspaceSpacePx =
533 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Thales Limaf8bfb032023-07-24 15:08:05 +0100534 }
535
Thales Lima8e11d532023-08-31 13:40:26 +0000536 if (!isVerticalBarLayout()) {
537 // Have a little space between the inset and the QSB
538 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
539 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
Thales Limab8c05952022-05-23 16:58:38 +0100540
Thales Lima8e11d532023-08-31 13:40:26 +0000541 // Only change the spaces if there is space
542 if (availableSpace > 0) {
543 // Make sure there is enough space between hotseat/QSB and QSB/navBar
544 if (availableSpace < minQsbMargin * 2) {
545 minQsbMargin = availableSpace / 2;
546 hotseatQsbSpace = minQsbMargin;
547 } else {
548 hotseatQsbSpace -= minQsbMargin;
549 }
Thales Limab8c05952022-05-23 16:58:38 +0100550 }
Thales Lima8e11d532023-08-31 13:40:26 +0000551 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
Thales Limab8c05952022-05-23 16:58:38 +0100552
Thales Lima8e11d532023-08-31 13:40:26 +0000553 } else {
554 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
555 }
Thales Limaa1012902022-01-13 17:58:42 +0000556 }
Thales Lima425f6822022-05-10 13:44:58 -0300557
Pat Manningde25c0d2022-04-05 19:11:26 +0100558 springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
559 R.dimen.spring_loaded_hotseat_top_margin);
Thales Lima8e11d532023-08-31 13:40:26 +0000560 updateHotseatSizes(pxFromDp(inv.iconSize[mTypeIndex], mMetrics));
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700561 if (areNavButtonsInline && !isPhone) {
Jon Mirandae17a9492023-03-08 16:42:20 -0800562 inlineNavButtonsEndSpacingPx =
Thales Limaffc68b02023-01-09 16:20:23 +0000563 res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing);
Pat Manning26f70f72022-07-07 13:50:39 +0100564 /*
565 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700566 * Spacing between nav buttons +
Thales Lima6a590062022-11-22 15:52:49 +0000567 * Space at the end for contextual buttons
Pat Manning26f70f72022-07-07 13:50:39 +0100568 */
569 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700570 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
Jon Mirandae17a9492023-03-08 16:42:20 -0800571 + inlineNavButtonsEndSpacingPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100572 } else {
Jon Mirandae17a9492023-03-08 16:42:20 -0800573 inlineNavButtonsEndSpacingPx = 0;
Pat Manning26f70f72022-07-07 13:50:39 +0100574 hotseatBarEndOffset = 0;
575 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700576
Thales Lima79456492023-05-23 11:32:22 +0100577 // Needs to be calculated after hotseatBarSizePx is correct,
578 // for the available height to be correct
579 if (mIsResponsiveGrid) {
Jordan Silva8bd7af22023-06-21 15:35:03 +0100580 WorkspaceSpecs workspaceSpecs = WorkspaceSpecs.create(
Jordan Silva575c3bd2023-07-21 12:00:43 +0100581 new ResourceHelper(context,
582 isTwoPanels ? inv.workspaceSpecsTwoPanelId : inv.workspaceSpecsId));
Thales Lima2759aa32023-06-05 16:25:45 +0100583 int availableResponsiveWidth =
584 availableWidthPx - (isVerticalBarLayout() ? hotseatBarSizePx : 0);
Jordan Silvac118fb52023-06-22 11:42:01 +0100585 int numColumns = getPanelCount() * inv.numColumns;
Thales Lima8e11d532023-08-31 13:40:26 +0000586 // don't use availableHeightPx because it subtracts mInsets.bottom
587 int availableResponsiveHeight = heightPx - mInsets.top
588 - (isVerticalBarLayout() ? 0 : hotseatBarSizePx);
Jordan Silvac118fb52023-06-22 11:42:01 +0100589 mResponsiveWidthSpec = workspaceSpecs.getCalculatedWidthSpec(numColumns,
Thales Lima2759aa32023-06-05 16:25:45 +0100590 availableResponsiveWidth);
Jordan Silva8bd7af22023-06-21 15:35:03 +0100591 mResponsiveHeightSpec = workspaceSpecs.getCalculatedHeightSpec(inv.numRows,
Thales Lima2759aa32023-06-05 16:25:45 +0100592 availableResponsiveHeight);
Thales Limaabfe3642023-05-24 18:08:53 +0100593
Jordan Silva8bd7af22023-06-21 15:35:03 +0100594 AllAppsSpecs allAppsSpecs = AllAppsSpecs.create(
Jordan Silva575c3bd2023-07-21 12:00:43 +0100595 new ResourceHelper(context,
596 isTwoPanels ? inv.allAppsSpecsTwoPanelId : inv.allAppsSpecsId));
Jordan Silvac118fb52023-06-22 11:42:01 +0100597 mAllAppsResponsiveWidthSpec = allAppsSpecs.getCalculatedWidthSpec(numColumns,
Thales Limaabfe3642023-05-24 18:08:53 +0100598 mResponsiveWidthSpec.getAvailableSpace(), mResponsiveWidthSpec);
Jordan Silva8bd7af22023-06-21 15:35:03 +0100599 mAllAppsResponsiveHeightSpec = allAppsSpecs.getCalculatedHeightSpec(inv.numRows,
600 mResponsiveHeightSpec.getAvailableSpace(), mResponsiveHeightSpec);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100601
Jordan Silva8bd7af22023-06-21 15:35:03 +0100602 FolderSpecs folderSpecs = FolderSpecs.create(
Jordan Silva575c3bd2023-07-21 12:00:43 +0100603 new ResourceHelper(context,
604 isTwoPanels ? inv.folderSpecsTwoPanelId : inv.folderSpecsId));
Jordan Silva8bd7af22023-06-21 15:35:03 +0100605 mResponsiveFolderWidthSpec = folderSpecs.getCalculatedWidthSpec(inv.numFolderColumns,
Jordan Silva637f4eb2023-06-13 11:21:53 +0100606 mResponsiveWidthSpec.getAvailableSpace(), mResponsiveWidthSpec);
Jordan Silva8bd7af22023-06-21 15:35:03 +0100607 mResponsiveFolderHeightSpec = folderSpecs.getCalculatedHeightSpec(inv.numFolderRows,
Jordan Silva637f4eb2023-06-13 11:21:53 +0100608 mResponsiveHeightSpec.getAvailableSpace(), mResponsiveHeightSpec);
Thales Lima79456492023-05-23 11:32:22 +0100609 }
610
611 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
612 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
613
Alex Chau635b3ab2022-01-26 16:49:10 +0000614 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chau5fd9d492021-07-22 17:27:11 +0100615 overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100616 overviewTaskIconDrawableSizePx =
617 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
618 overviewTaskIconDrawableSizeGridPx =
619 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700620 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx;
Andy Wickhambc3bac42023-08-07 16:02:23 -0700621 // Don't add margin with floating search bar to minimize risk of overlapping.
622 overviewActionsTopMarginPx = FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get() ? 0
623 : res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000624 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
625 overviewActionsButtonSpacing = res.getDimensionPixelSize(
626 R.dimen.overview_actions_button_spacing);
Andy Wickhambc3bac42023-08-07 16:02:23 -0700627 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700628 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000629 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700630
Jeremy Sim0ac47082022-10-10 13:59:40 -0700631 splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset);
632
Jon Miranda2ed276e2017-06-29 11:36:34 -0700633 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400634 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700635
Thales Lima79456492023-05-23 11:32:22 +0100636 calculateAndSetWorkspaceVerticalPadding(context, inv, extraSpace);
Pat Manning08610ca2022-04-05 21:03:16 +0100637
638 int cellLayoutPadding =
639 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
640 R.dimen.cell_layout_padding);
641 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
642 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800643 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800644
Thales Lima7eee74b2023-03-16 16:00:55 -0300645 // Folder scaling requires correct workspace paddings
646 updateAvailableFolderCellDimensions(res);
647
Thales Limaffc68b02023-01-09 16:20:23 +0000648 mMinHotseatIconSpacePx = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
649 mMinHotseatQsbWidthPx = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
650 mMaxHotseatIconSpacePx = areNavButtonsInline
Thales Lima6a590062022-11-22 15:52:49 +0000651 ? res.getDimensionPixelSize(R.dimen.max_hotseat_icon_space) : Integer.MAX_VALUE;
Thales Lima425f6822022-05-10 13:44:58 -0300652 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima6a590062022-11-22 15:52:49 +0000653 recalculateHotseatWidthAndBorderSpace();
Alex Chau206ede92022-08-01 17:46:12 +0100654
Jordan Silva3646a1b2023-08-02 13:52:52 +0100655 if (mIsResponsiveGrid && isVerticalBarLayout()) {
656 hotseatBorderSpace = cellLayoutBorderSpacePx.y;
657 }
658
Alex Chau206ede92022-08-01 17:46:12 +0100659 // AllApps height calculation depends on updated cellSize
660 if (isTablet) {
661 int collapseHandleHeight =
662 res.getDimensionPixelOffset(R.dimen.bottom_sheet_handle_area_height);
663 int contentHeight = heightPx - collapseHandleHeight - hotseatQsbHeight;
664 int targetContentHeight = (int) (allAppsCellHeightPx * ALL_APPS_TABLET_MAX_ROWS);
665 allAppsTopPadding = Math.max(mInsets.top, contentHeight - targetContentHeight);
666 allAppsShiftRange = heightPx - allAppsTopPadding;
667 } else {
668 allAppsTopPadding = 0;
669 allAppsShiftRange =
670 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
671 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100672 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
673 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300674
Alex Chaua02eddc2021-04-29 00:36:06 +0100675 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
676 R.dimen.drag_flingToDeleteMinVelocity);
677
Sihua Mae04aa202022-07-18 12:43:56 -0700678 mViewScaleProvider = viewScaleProvider;
679
Jon Miranda2b25ded2023-02-02 14:48:45 -0800680 dimensionOverrideProvider.accept(this);
681
Tony Wickham1237df02017-02-24 08:59:36 -0800682 // This is done last, after iconSizePx is calculated above.
Sunny Goyal799e1202023-02-09 10:54:28 -0800683 mDotRendererWorkSpace = createDotRenderer(context, iconSizePx, dotRendererCache);
684 mDotRendererAllApps = createDotRenderer(context, allAppsIconSizePx, dotRendererCache);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700685 }
686
687 private static DotRenderer createDotRenderer(
Sunny Goyal799e1202023-02-09 10:54:28 -0800688 @NonNull Context context, int size, @NonNull SparseArray<DotRenderer> cache) {
Sunny Goyal65190ae2022-08-02 14:16:26 -0700689 DotRenderer renderer = cache.get(size);
690 if (renderer == null) {
Sunny Goyal799e1202023-02-09 10:54:28 -0800691 renderer = new DotRenderer(size, getShapePath(context, DEFAULT_DOT_SIZE),
692 DEFAULT_DOT_SIZE);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700693 cache.put(size, renderer);
694 }
695 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700696 }
697
Thales Lima425f6822022-05-10 13:44:58 -0300698 /**
699 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
700 * width of the hotseat.
701 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100702 private int calculateQsbWidth(int hotseatBorderSpace) {
Thales Lima425f6822022-05-10 13:44:58 -0300703 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100704 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300705 return getIconToIconWidthForColumns(columns)
706 - iconSizePx * numShownHotseatIcons
707 - hotseatBorderSpace * numShownHotseatIcons;
708 } else {
709 int columns = inv.hotseatColumnSpan[mTypeIndex];
710 return getIconToIconWidthForColumns(columns);
711 }
712 }
Thales Lima2903a622022-03-17 13:52:19 +0000713
Thales Lima425f6822022-05-10 13:44:58 -0300714 private int getIconToIconWidthForColumns(int columns) {
715 return columns * getCellSize().x
716 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400717 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000718 }
719
Thales Limad90faab2021-09-21 17:18:47 +0100720 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
Thales Lima79456492023-05-23 11:32:22 +0100721 if (mIsResponsiveGrid) {
722 return mResponsiveWidthSpec.getStartPaddingPx();
723 }
724
Thales Limad90faab2021-09-21 17:18:47 +0100725 if (isVerticalBarLayout()) {
726 return 0;
727 }
728
Thales Lima79456492023-05-23 11:32:22 +0100729 return mIsScalableGrid
Thales Lima83bedbf2021-10-05 17:47:39 +0100730 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
731 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100732 }
733
Thales Lima79456492023-05-23 11:32:22 +0100734 private void calculateAndSetWorkspaceVerticalPadding(Context context,
735 InvariantDeviceProfile inv,
736 int extraSpace) {
737 if (mIsResponsiveGrid) {
738 workspaceTopPadding = mResponsiveHeightSpec.getStartPaddingPx();
739 workspaceBottomPadding = mResponsiveHeightSpec.getEndPaddingPx();
740 } else if (mIsScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
741 // Paddings were created assuming no scaling, so we first unscale the extra space.
742 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
743 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
744 DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
745 maxEmptySpace = padding.getMaxEmptySpacePx();
746
747 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
748 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
749
750 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
751 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
752 }
753 }
754
Thales Limab8c05952022-05-23 16:58:38 +0100755 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
756 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700757 // Ensure there is enough space for folder icons, which have a slightly larger radius.
Jordan Silva3646a1b2023-08-02 13:52:52 +0100758 hotseatCellHeightPx = getIconSizeWithOverlap(hotseatIconSizePx);
Thales Limab8c05952022-05-23 16:58:38 +0100759
Jon Miranda0d284852021-06-22 14:50:55 -0700760 if (isVerticalBarLayout()) {
Thales Lima8e11d532023-08-31 13:40:26 +0000761 hotseatBarSizePx = hotseatIconSizePx + mHotseatBarEdgePaddingPx
762 + mHotseatBarWorkspaceSpacePx;
Thales Limab8c05952022-05-23 16:58:38 +0100763 } else if (isQsbInline) {
764 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
765 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700766 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100767 hotseatBarSizePx = hotseatIconSizePx
768 + hotseatQsbSpace
769 + hotseatQsbVisualHeight
770 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700771 }
772 }
773
Thales Lima6a590062022-11-22 15:52:49 +0000774 /**
775 * Calculates the width of the hotseat, changing spaces between the icons and removing icons if
776 * necessary.
777 */
778 public void recalculateHotseatWidthAndBorderSpace() {
Thales Lima79456492023-05-23 11:32:22 +0100779 if (!mIsScalableGrid) return;
Thales Lima6a590062022-11-22 15:52:49 +0000780
781 int columns = inv.hotseatColumnSpan[mTypeIndex];
782 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
783 hotseatBorderSpace = calculateHotseatBorderSpace(hotseatWidthPx, /* numExtraBorder= */ 0);
Thales Lima9938c2f2022-07-25 14:38:16 +0100784 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
Thales Lima6a590062022-11-22 15:52:49 +0000785 // Spaces should be correct when the nav buttons are not inline
Thales Lima9938c2f2022-07-25 14:38:16 +0100786 if (!areNavButtonsInline) {
787 return;
788 }
789
Thales Lima6a590062022-11-22 15:52:49 +0000790 // The side space with inline buttons should be what is defined in InvariantDeviceProfile
Jon Mirandae17a9492023-03-08 16:42:20 -0800791 int sideSpacePx = inlineNavButtonsEndSpacingPx;
Thales Limaffc68b02023-01-09 16:20:23 +0000792 int maxHotseatWidthPx = availableWidthPx - sideSpacePx - hotseatBarEndOffset;
793 int maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
794 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000795 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100796
Thales Limaffc68b02023-01-09 16:20:23 +0000797 if (hotseatBorderSpace >= mMinHotseatIconSpacePx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100798 return;
799 }
800
801 // Border space can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000802 hotseatBorderSpace = mMinHotseatIconSpacePx;
Thales Lima6a590062022-11-22 15:52:49 +0000803 int requiredWidth = getHotseatRequiredWidth();
Thales Lima9938c2f2022-07-25 14:38:16 +0100804
805 // If there is an inline qsb, change its size
806 if (isQsbInline) {
Thales Limaffc68b02023-01-09 16:20:23 +0000807 hotseatQsbWidth -= requiredWidth - maxHotseatWidthPx;
808 if (hotseatQsbWidth >= mMinHotseatQsbWidthPx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100809 return;
810 }
811
812 // QSB can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000813 hotseatQsbWidth = mMinHotseatQsbWidthPx;
Thales Lima9938c2f2022-07-25 14:38:16 +0100814 }
815
Thales Limaffc68b02023-01-09 16:20:23 +0000816 maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
Thales Lima6a590062022-11-22 15:52:49 +0000817
Thales Lima9938c2f2022-07-25 14:38:16 +0100818 // If it still doesn't fit, start removing icons
819 do {
820 numShownHotseatIcons--;
Thales Limaffc68b02023-01-09 16:20:23 +0000821 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000822 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Limaffc68b02023-01-09 16:20:23 +0000823 } while (hotseatBorderSpace < mMinHotseatIconSpacePx && numShownHotseatIcons > 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100824 }
825
Thales Lima78d00ad2021-09-30 11:29:06 +0100826 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100827 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100828 }
829
830 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima79456492023-05-23 11:32:22 +0100831 int horizontalSpacePx = 0;
832 int verticalSpacePx = 0;
Thales Lima78d00ad2021-09-30 11:29:06 +0100833
Thales Lima79456492023-05-23 11:32:22 +0100834 if (mIsResponsiveGrid) {
835 horizontalSpacePx = mResponsiveWidthSpec.getGutterPx();
836 verticalSpacePx = mResponsiveHeightSpec.getGutterPx();
837 } else if (mIsScalableGrid) {
838 horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
839 verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
840 }
Thales Lima78d00ad2021-09-30 11:29:06 +0100841
842 return new Point(horizontalSpacePx, verticalSpacePx);
843 }
844
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700845 public Info getDisplayInfo() {
846 return mInfo;
847 }
848
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700849 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800850 WindowBounds bounds = new WindowBounds(
851 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700852 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100853 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700854
855 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
856 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
857 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
858
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700859 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700860 .setWindowBounds(bounds)
Alex Chauab800f72022-12-13 17:46:06 +0000861 .setIsMultiDisplay(isMultiDisplay)
Alex Chau6ed408f2022-03-04 12:58:05 +0000862 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700863 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000864 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800865 }
866
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700867 public DeviceProfile copy(Context context) {
868 return toBuilder(context).build();
869 }
870
871 /**
872 * TODO: Move this to the builder as part of setMultiWindowMode
873 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700874 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700875 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700876 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700877 .setMultiWindowMode(true)
878 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800879
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800880 // We use these scales to measure and layout the widgets using their full invariant profile
881 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
882 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
883 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700884 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
885 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
886 profile = profile.toBuilder(context)
887 .setViewScaleProvider(i -> p)
888 .build();
889 }
890
891 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800892
Jon Miranda93e1f042016-11-11 14:13:04 -0800893 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700894 }
895
Adam Cohen63f1ec02014-08-12 09:23:13 -0700896 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400897 * Checks if there is enough space for labels on the workspace.
898 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700899 * It is important to call this method after the All Apps variables have been set.
900 */
Jon Miranda941375e2021-03-31 13:10:45 -0400901 private void hideWorkspaceLabelsIfNotEnoughSpace() {
902 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
903 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
904 - iconTextHeight;
905
Jordan Silva3646a1b2023-08-02 13:52:52 +0100906 if (mIsResponsiveGrid) {
907 // Hide text only if doesn't fit inside the cell for responsive grid
908 if (workspaceCellPaddingY < 0) {
909 iconTextSizePx = 0;
910 iconDrawablePaddingPx = 0;
911 int iconSizeWithOverlap = getIconSizeWithOverlap(iconSizePx);
912 cellYPaddingPx = Math.max(0, getCellSize().y - iconSizeWithOverlap) / 2;
913 autoResizeAllAppsCells();
914 }
915
916 return;
917 }
918
Jon Miranda941375e2021-03-31 13:10:45 -0400919 // We want enough space so that the text is closer to its corresponding icon.
920 if (workspaceCellPaddingY < iconTextHeight) {
921 iconTextSizePx = 0;
922 iconDrawablePaddingPx = 0;
Jordan Silva3646a1b2023-08-02 13:52:52 +0100923 cellHeightPx = getIconSizeWithOverlap(iconSizePx);
Jon Miranda941375e2021-03-31 13:10:45 -0400924 autoResizeAllAppsCells();
925 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700926 }
Jon Miranda1091e532017-07-21 13:31:50 -0700927
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700928 /**
Jon Miranda228877d2021-02-09 11:05:00 -0500929 * Returns the amount of extra (or unused) vertical space.
930 */
931 private int updateAvailableDimensions(Resources res) {
Alex Chaua68164d2022-12-15 16:16:03 +0000932 float invIconSizeDp = inv.iconSize[mTypeIndex];
933 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
934 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
935 iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
Thales Lima79456492023-05-23 11:32:22 +0100936 iconCenterVertically = mIsScalableGrid || mIsResponsiveGrid;
Alex Chaua68164d2022-12-15 16:16:03 +0000937
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700938 updateIconSize(1f, res);
Pat Manning08610ca2022-04-05 21:03:16 +0100939 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -0500940
Alex Chau5225e832023-08-01 16:32:15 +0100941 if (mIsResponsiveGrid) {
942 return 0;
943 }
944
Jon Mirandae126d722021-02-25 10:45:20 -0500945 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +0100946 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +0000947 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -0500948 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500949 float scaleY = maxHeight / usedHeight;
950 boolean shouldScale = scaleY < 1f;
951
952 float scaleX = 1f;
Thales Lima79456492023-05-23 11:32:22 +0100953 if (mIsScalableGrid) {
Jon Mirandae126d722021-02-25 10:45:20 -0500954 // We scale to fit the cellWidth and cellHeight in the available space.
955 // The benefit of scalable grids is that we can get consistent aspect ratios between
956 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +0100957 float usedWidth =
958 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500959 // We do not subtract padding here, as we also scale the workspace padding if needed.
960 scaleX = availableWidthPx / usedWidth;
961 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700962 }
Jon Mirandae126d722021-02-25 10:45:20 -0500963
964 if (shouldScale) {
965 float scale = Math.min(scaleX, scaleY);
966 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +0100967 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -0500968 }
969
Jon Miranda228877d2021-02-09 11:05:00 -0500970 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700971 }
972
Pat Manninga2e14992022-04-22 11:29:17 +0100973 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +0100974 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
975 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
976 }
977
Pat Manninga2e14992022-04-22 11:29:17 +0100978 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +0000979 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +0100980 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
981 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -0500982 }
983
Thales Lima93ee8fc2023-06-05 17:07:11 +0100984 private int getNormalizedIconDrawablePadding() {
985 // TODO(b/235886078): workaround needed because of this bug
986 // Icons are 10% larger on XML than their visual size,
987 // so remove that extra space to get labels closer to the correct padding
988 int iconVisibleSizePx = (int) Math.round(ICON_VISIBLE_AREA_FACTOR * iconSizePx);
989 return Math.max(0, mIconDrawablePaddingOriginalPx - ((iconSizePx - iconVisibleSizePx) / 2));
990 }
991
992 private int getNormalizedFolderChildDrawablePaddingPx(int textHeight) {
993 // TODO(b/235886078): workaround needed because of this bug
994 // Icons are 10% larger on XML than their visual size,
995 // so remove that extra space to get labels closer to the correct padding
996 int drawablePadding = (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3;
997
998 int iconVisibleSizePx = Math.round(ICON_VISIBLE_AREA_FACTOR * folderChildIconSizePx);
999 int iconSizeDiff = folderChildIconSizePx - iconVisibleSizePx;
1000 return Math.max(0, drawablePadding - iconSizeDiff / 2);
1001 }
1002
Jordan Silva3646a1b2023-08-02 13:52:52 +01001003 private int getIconSizeWithOverlap(int iconSize) {
1004 return (int) Math.ceil(iconSize * ICON_OVERLAP_FACTOR);
1005 }
1006
Jon Miranda6f7e9702019-09-16 14:44:14 -07001007 /**
1008 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
1009 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
1010 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
1011 */
Tony Wickham7ba547c2021-02-02 17:12:08 -08001012 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -07001013 // Icon scale should never exceed 1, otherwise pixellation may occur.
1014 iconScale = Math.min(1f, scale);
1015 cellScaleToFit = scale;
1016
Jon Miranda18751b62017-07-31 17:25:27 -07001017 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -08001018 final boolean isVerticalLayout = isVerticalBarLayout();
Thales Lima080d8902022-03-28 15:30:29 +01001019 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -05001020
Thales Lima79456492023-05-23 11:32:22 +01001021 if (mIsResponsiveGrid) {
Thales Lima79456492023-05-23 11:32:22 +01001022 cellWidthPx = mResponsiveWidthSpec.getCellSizePx();
1023 cellHeightPx = mResponsiveHeightSpec.getCellSizePx();
Thales Lima79456492023-05-23 11:32:22 +01001024
Thales Lima2759aa32023-06-05 16:25:45 +01001025 if (cellWidthPx < iconSizePx) {
1026 // get a smaller icon size
1027 iconSizePx = mIconSizeSteps.getIconSmallerThan(cellWidthPx);
Thales Lima2759aa32023-06-05 16:25:45 +01001028 }
1029
Thales Lima8e11d532023-08-31 13:40:26 +00001030 // TODO(b/296400197): isVerticalBar shouldn't show labels anymore
Thales Lima93ee8fc2023-06-05 17:07:11 +01001031 iconDrawablePaddingPx = getNormalizedIconDrawablePadding();
1032 int iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
1033 int cellContentHeight = iconSizePx + iconDrawablePaddingPx + iconTextHeight;
1034
Thales Lima2759aa32023-06-05 16:25:45 +01001035 while (iconSizePx > mIconSizeSteps.minimumIconSize()
1036 && cellContentHeight > cellHeightPx) {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001037 iconDrawablePaddingPx -= cellContentHeight - cellHeightPx;
1038 if (iconDrawablePaddingPx < 0) {
Thales Lima2759aa32023-06-05 16:25:45 +01001039 // get a smaller icon size
1040 iconSizePx = mIconSizeSteps.getNextLowerIconSize(iconSizePx);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001041 iconDrawablePaddingPx = getNormalizedIconDrawablePadding();
Thales Lima2759aa32023-06-05 16:25:45 +01001042 }
1043 // calculate new cellContentHeight
Thales Lima93ee8fc2023-06-05 17:07:11 +01001044 cellContentHeight = iconSizePx + iconDrawablePaddingPx + iconTextHeight;
Thales Lima2759aa32023-06-05 16:25:45 +01001045 }
1046
1047 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Lima79456492023-05-23 11:32:22 +01001048 } else if (mIsScalableGrid) {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001049 iconDrawablePaddingPx = (int) (getNormalizedIconDrawablePadding() * iconScale);
Thales Lima83bedbf2021-10-05 17:47:39 +01001050 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
1051 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001052
1053 if (cellWidthPx < iconSizePx) {
1054 // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger.
1055 int numColumns = getPanelCount() * inv.numColumns;
1056 int numBorders = numColumns - 1;
1057 int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns;
1058 if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) {
1059 cellWidthPx = iconSizePx;
1060 cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders;
1061 } else {
1062 // If it still doesn't fit, set borderSpace to 0 and distribute the space for
1063 // cellWidth, and reduce iconSize.
1064 cellWidthPx = (cellWidthPx * numColumns
1065 + cellLayoutBorderSpacePx.x * numBorders) / numColumns;
1066 iconSizePx = Math.min(iconSizePx, cellWidthPx);
1067 cellLayoutBorderSpacePx.x = 0;
1068 }
1069 }
1070
Thales Lima93ee8fc2023-06-05 17:07:11 +01001071 int cellTextAndPaddingHeight =
1072 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +00001073 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
1074 if (cellHeightPx < cellContentHeight) {
1075 // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight
1076 // bigger.
1077 int numBorders = inv.numRows - 1;
1078 int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows;
1079 if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) {
1080 cellHeightPx = cellContentHeight;
1081 cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders;
1082 } else {
Alex Chau06f36e82023-01-06 10:50:54 +00001083 // If it still doesn't fit, set borderSpace to 0 to recover space.
Alex Chaube753132022-12-09 16:46:54 +00001084 cellHeightPx = (cellHeightPx * inv.numRows
1085 + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows;
Alex Chaube753132022-12-09 16:46:54 +00001086 cellLayoutBorderSpacePx.y = 0;
Alex Chau06f36e82023-01-06 10:50:54 +00001087 // Reduce iconDrawablePaddingPx to make cellContentHeight smaller.
1088 int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx;
1089 if (cellContentWithoutPadding <= cellHeightPx) {
1090 iconDrawablePaddingPx = cellContentHeight - cellHeightPx;
1091 } else {
1092 // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space,
1093 // then proportional reduce iconSizePx and iconTextSizePx to fit.
1094 iconDrawablePaddingPx = 0;
1095 float ratio = cellHeightPx / (float) cellContentWithoutPadding;
1096 iconSizePx = (int) (iconSizePx * ratio);
1097 iconTextSizePx = (int) (iconTextSizePx * ratio);
1098 }
1099 cellTextAndPaddingHeight =
1100 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +00001101 }
1102 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
1103 }
Jon Mirandae126d722021-02-25 10:45:20 -05001104 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +01001105 desiredWorkspaceHorizontalMarginPx =
1106 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -05001107 } else {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001108 iconDrawablePaddingPx = (int) (getNormalizedIconDrawablePadding() * iconScale);
Jon Mirandae126d722021-02-25 10:45:20 -05001109 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001110 cellHeightPx = getIconSizeWithOverlap(iconSizePx)
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001111 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -05001112 + Utilities.calculateTextHeight(iconTextSizePx);
1113 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
1114 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
1115 && !isMultiWindowMode) {
1116 // Ensures that the label is closer to its corresponding icon. This is not an issue
1117 // with vertical bar layout or multi-window mode since the issue is handled
1118 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
1119 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
1120 iconDrawablePaddingPx = cellPaddingY;
1121 }
Jon Miranda846455e2017-10-02 14:58:52 -07001122 }
Jon Miranda18751b62017-07-31 17:25:27 -07001123
Sunny Goyalae190ff2020-04-14 00:19:01 +00001124 // All apps
Thales Limaabfe3642023-05-24 18:08:53 +01001125 if (mIsResponsiveGrid) {
1126 updateAllAppsWithResponsiveMeasures();
1127 } else {
1128 updateAllAppsIconSize(scale, res);
1129 }
1130 updateAllAppsContainerWidth();
1131 if (isVerticalBarLayout()) {
1132 hideWorkspaceLabelsIfNotEnoughSpace();
1133 }
Winson Chungb3800242013-10-24 11:01:54 -07001134
Thales Limab8c05952022-05-23 16:58:38 +01001135 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -07001136
Sunny Goyalbaec6ff2016-09-14 11:26:21 -07001137 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -07001138 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
1139 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Sunny Goyal6c304b12023-04-10 12:03:04 -07001140
1141 // Update widget padding:
1142 float minSpacing = pxFromDp(MIN_WIDGET_PADDING_DP, mMetrics);
1143 if (cellLayoutBorderSpacePx.x < minSpacing
1144 || cellLayoutBorderSpacePx.y < minSpacing) {
1145 widgetPadding.left = widgetPadding.right =
1146 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.x));
1147 widgetPadding.top = widgetPadding.bottom =
1148 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.y));
1149 } else {
1150 widgetPadding.setEmpty();
1151 }
Winson Chung0f785722015-04-08 10:27:49 -07001152 }
1153
Thales Lima425f6822022-05-10 13:44:58 -03001154 /**
Thales Lima6a590062022-11-22 15:52:49 +00001155 * This method calculates the space between the icons to achieve a certain width.
Thales Lima425f6822022-05-10 13:44:58 -03001156 */
Thales Lima6a590062022-11-22 15:52:49 +00001157 private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) {
Jordan Silvad9227182023-08-17 15:53:59 +01001158 int numBorders = (numShownHotseatIcons - 1 + numExtraBorder);
1159 if (numBorders <= 0) return 0;
1160
Thales Lima9938c2f2022-07-25 14:38:16 +01001161 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
Jordan Silvad9227182023-08-17 15:53:59 +01001162 int hotseatBorderSpacePx = (int) (hotseatWidthPx - hotseatIconsTotalPx) / numBorders;
Thales Limaffc68b02023-01-09 16:20:23 +00001163 return Math.min(hotseatBorderSpacePx, mMaxHotseatIconSpacePx);
Thales Lima425f6822022-05-10 13:44:58 -03001164 }
1165
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001166 /**
1167 * Updates the iconSize for allApps* variants.
1168 */
Brian Isganitisa9a78112022-05-23 18:11:47 -07001169 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +01001170 allAppsBorderSpacePx = new Point(
1171 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
1172 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001173 // AllApps cells don't have real space between cells,
1174 // so we add the border space to the cell height
Alex Chaube753132022-12-09 16:46:54 +00001175 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics)
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001176 + allAppsBorderSpacePx.y;
1177 // but width is just the cell,
1178 // the border is added in #updateAllAppsContainerWidth
Thales Lima79456492023-05-23 11:32:22 +01001179 if (mIsScalableGrid) {
Alex Chaube753132022-12-09 16:46:54 +00001180 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1181 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001182 allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding();
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001183 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001184
1185 if (allAppsCellWidthPx < allAppsIconSizePx) {
1186 // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to
1187 // make allAppsCellWidth bigger.
1188 int numBorders = inv.numAllAppsColumns - 1;
1189 int extraWidthRequired =
1190 (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns;
1191 if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) {
1192 allAppsCellWidthPx = allAppsIconSizePx;
1193 allAppsBorderSpacePx.x -= extraWidthRequired / numBorders;
1194 } else {
1195 // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space
1196 // for allAppsCellWidth, and reduce allAppsIconSize.
1197 allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns
1198 + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns;
1199 allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx);
1200 allAppsBorderSpacePx.x = 0;
1201 }
1202 }
1203
1204 int cellContentHeight = allAppsIconSizePx
1205 + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y;
1206 if (allAppsCellHeightPx < cellContentHeight) {
1207 // Increase allAppsCellHeight to fit its content.
1208 allAppsCellHeightPx = cellContentHeight;
1209 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001210 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001211 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
1212 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001213 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1214 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001215 allAppsIconDrawablePaddingPx =
1216 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001217 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001218 }
Thales Limaabfe3642023-05-24 18:08:53 +01001219 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001220
Thales Limaabfe3642023-05-24 18:08:53 +01001221 private void updateAllAppsWithResponsiveMeasures() {
1222 allAppsIconSizePx = iconSizePx;
1223 allAppsIconTextSizePx = iconTextSizePx;
Thales Lima93ee8fc2023-06-05 17:07:11 +01001224 allAppsIconDrawablePaddingPx = iconDrawablePaddingPx;
Thales Limaabfe3642023-05-24 18:08:53 +01001225
1226 allAppsBorderSpacePx = new Point(
1227 mAllAppsResponsiveWidthSpec.getGutterPx(),
1228 mAllAppsResponsiveHeightSpec.getGutterPx()
1229 );
1230 allAppsCellHeightPx = mAllAppsResponsiveHeightSpec.getCellSizePx()
1231 + mAllAppsResponsiveHeightSpec.getGutterPx();
1232 allAppsCellWidthPx = mAllAppsResponsiveWidthSpec.getCellSizePx();
1233 allAppsLeftRightPadding = mAllAppsResponsiveWidthSpec.getStartPaddingPx();
1234 }
1235
1236 /**
1237 * Re-computes the all-apps cell size to be independent of workspace
1238 */
1239 public void autoResizeAllAppsCells() {
1240 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
1241 int topBottomPadding = textHeight;
1242 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
1243 + textHeight + (topBottomPadding * 2);
1244 }
1245
1246 private void updateAllAppsContainerWidth() {
1247 int cellLayoutHorizontalPadding =
1248 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
1249 if (isTablet) {
1250 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
1251 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
1252 + allAppsLeftRightPadding * 2;
1253 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
1254 } else {
1255 allAppsLeftRightPadding =
1256 Math.max(0, desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding
1257 - (allAppsBorderSpacePx.x / 2));
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001258 }
1259 }
1260
Thales Limaabfe3642023-05-24 18:08:53 +01001261 private void setupAllAppsStyle(Context context) {
1262 TypedArray allAppsStyle = context.obtainStyledAttributes(
1263 inv.allAppsStyle != INVALID_RESOURCE_HANDLE ? inv.allAppsStyle
1264 : R.style.AllAppsStyleDefault, R.styleable.AllAppsStyle);
1265
1266 allAppsLeftRightPadding = allAppsStyle.getDimensionPixelSize(
1267 R.styleable.AllAppsStyle_horizontalPadding, 0);
1268 allAppsStyle.recycle();
1269 }
1270
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001271 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001272 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001273
Jordan Silva637f4eb2023-06-13 11:21:53 +01001274 // Responsive grid doesn't need to scale the folder
1275 if (mIsResponsiveGrid) return;
1276
Thales Lima7eee74b2023-03-16 16:00:55 -03001277 // For usability we can't have the folder use the whole width of the screen
Sunny Goyal07b69292018-01-08 14:19:34 -08001278 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -08001279
Thales Lima7eee74b2023-03-16 16:00:55 -03001280 // Check if the folder fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -05001281 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Jordan Silva637f4eb2023-06-13 11:21:53 +01001282 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx.y)
Thales Lima7eee74b2023-03-16 16:00:55 -03001283 + folderFooterHeightPx
1284 + folderContentPaddingTop;
1285 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001286 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -08001287
Thales Lima7eee74b2023-03-16 16:00:55 -03001288 // Check if the folder fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -05001289 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Jordan Silva637f4eb2023-06-13 11:21:53 +01001290 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x)
Thales Lima7eee74b2023-03-16 16:00:55 -03001291 + folderContentPaddingLeftRight * 2;
1292 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001293 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -08001294
1295 float scale = Math.min(scaleX, scaleY);
1296 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001297 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001298 }
1299 }
1300
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001301 private void updateFolderCellSize(float scale, Resources res) {
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001302 float invIconSizeDp = inv.iconSize[mTypeIndex];
Sunny Goyal35c7b192021-04-20 16:51:10 -07001303 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001304 folderChildTextSizePx = pxFromSp(inv.iconTextSize[mTypeIndex], mMetrics, scale);
Thales Lima7eee74b2023-03-16 16:00:55 -03001305 folderLabelTextSizePx = Math.max(pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale),
Thales Limab35faed2022-09-05 16:30:01 -03001306 (int) (folderChildTextSizePx * folderLabelTextScale));
Jon Mirandabf7d8122016-11-03 15:29:29 -07001307
1308 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001309
Jordan Silva637f4eb2023-06-13 11:21:53 +01001310 if (mIsResponsiveGrid) {
1311 folderCellWidthPx = mResponsiveFolderWidthSpec.getCellSizePx();
1312
1313 // Height
1314 folderCellHeightPx = mResponsiveFolderHeightSpec.getCellSizePx();
1315 folderContentPaddingTop = mResponsiveFolderHeightSpec.getStartPaddingPx();
1316 folderFooterHeightPx = mResponsiveFolderHeightSpec.getEndPaddingPx();
1317
1318 folderCellLayoutBorderSpacePx = new Point(mResponsiveFolderWidthSpec.getGutterPx(),
Thales Lima4cfd9502023-07-10 14:01:28 +01001319 mResponsiveFolderHeightSpec.getGutterPx());
Jordan Silva637f4eb2023-06-13 11:21:53 +01001320
1321 folderContentPaddingLeftRight = mResponsiveFolderWidthSpec.getStartPaddingPx();
Jordan Silva12fae112023-06-26 12:51:01 +01001322
1323 // Reduce icon width if it's wider than the expected folder cell width
1324 if (folderCellWidthPx < folderChildIconSizePx) {
1325 folderChildIconSizePx = mIconSizeSteps.getIconSmallerThan(folderCellWidthPx);
1326 }
1327
1328 // Recalculating padding and cell height
1329 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
1330 int folderCellContentHeight = folderChildIconSizePx + folderChildDrawablePaddingPx
1331 + textHeight;
1332
1333 // Reduce the icon in height when it's taller than the expected cell height
1334 while (folderChildIconSizePx > mIconSizeSteps.minimumIconSize()
1335 && folderCellContentHeight > folderCellHeightPx) {
1336 folderChildDrawablePaddingPx -= folderCellContentHeight - folderCellHeightPx;
1337 if (folderChildDrawablePaddingPx < 0) {
1338 // get a smaller icon size
1339 folderChildIconSizePx = mIconSizeSteps.getNextLowerIconSize(
1340 folderChildIconSizePx);
1341 folderChildDrawablePaddingPx =
1342 getNormalizedFolderChildDrawablePaddingPx(textHeight);
1343 }
1344 // calculate new cellContentHeight
1345 folderCellContentHeight = folderChildIconSizePx + folderChildDrawablePaddingPx
1346 + textHeight;
1347 }
Jordan Silva637f4eb2023-06-13 11:21:53 +01001348 } else if (mIsScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001349 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
Thales Lima7eee74b2023-03-16 16:00:55 -03001350 folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale);
1351 folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale);
1352 } else {
1353 folderCellWidthPx = roundPxValueFromFloat(folderCellWidthPx * scale);
1354 folderCellHeightPx = roundPxValueFromFloat(folderCellHeightPx * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001355 }
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001356
Thales Lima7eee74b2023-03-16 16:00:55 -03001357 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001358 folderCellLayoutBorderSpacePx = new Point(
1359 roundPxValueFromFloat(folderCellLayoutBorderSpacePx.x * scale),
1360 roundPxValueFromFloat(folderCellLayoutBorderSpacePx.y * scale)
1361 );
Thales Lima7eee74b2023-03-16 16:00:55 -03001362 folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale);
1363
Jordan Silva637f4eb2023-06-13 11:21:53 +01001364 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx.x;
Jordan Silva12fae112023-06-26 12:51:01 +01001365
1366 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
Jon Miranda823da222021-03-23 08:08:45 -04001367 } else {
1368 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1369 * scale);
1370 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1371 * scale);
1372
1373 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1374 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Lima7eee74b2023-03-16 16:00:55 -03001375 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001376 folderContentPaddingLeftRight =
1377 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1378 folderFooterHeightPx =
Thales Lima7eee74b2023-03-16 16:00:55 -03001379 roundPxValueFromFloat(
1380 res.getDimensionPixelSize(R.dimen.folder_footer_height_default)
1381 * scale);
1382
Jordan Silva12fae112023-06-26 12:51:01 +01001383 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
Jon Miranda823da222021-03-23 08:08:45 -04001384 }
Jon Mirandabf7d8122016-11-03 15:29:29 -07001385 }
1386
Winson1f064272016-07-18 17:18:02 -07001387 public void updateInsets(Rect insets) {
1388 mInsets.set(insets);
1389 }
1390
Sunny Goyalae6e3182019-04-30 12:04:37 -07001391 /**
1392 * The current device insets. This is generally same as the insets being dispatched to
1393 * {@link Insettable} elements, but can differ if the element is using a different profile.
1394 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001395 public Rect getInsets() {
1396 return mInsets;
1397 }
1398
Sunny Goyal756cd262015-08-20 12:33:21 -07001399 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001400 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001401 }
1402
Sunny Goyal19ff7282021-04-22 10:12:54 -07001403 public Point getCellSize(Point result) {
1404 if (result == null) {
1405 result = new Point();
1406 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001407
Pat Manning25d53342022-05-10 09:58:49 +00001408 int shortcutAndWidgetContainerWidth =
1409 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1410 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1411 inv.numColumns);
1412 int shortcutAndWidgetContainerHeight =
1413 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1414 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1415 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001416 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001417 }
1418
1419 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001420 * Returns the left and right space on the cell, which is the cell width - icon size
1421 */
1422 public int getCellHorizontalSpace() {
1423 return getCellSize().x - iconSizePx;
1424 }
1425
1426 /**
Pat Manning25d53342022-05-10 09:58:49 +00001427 * Gets the number of panels within the workspace.
1428 */
1429 public int getPanelCount() {
1430 return isTwoPanels ? 2 : 1;
1431 }
1432
1433 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001434 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1435 * bottom of the screen.
1436 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001437 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1438 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001439 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001440 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001441 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001442 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001443 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001444 }
1445
1446 /**
1447 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1448 */
Pat Manning25d53342022-05-10 09:58:49 +00001449 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001450 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001451 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001452 }
1453
1454 /**
1455 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1456 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001457 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001458 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001459 return heightPx - (isVerticalBarLayout()
1460 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001461 }
1462
Pat Manningea5c1d22022-04-14 10:58:16 +01001463 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001464 * Gets the scale of the workspace for the spring-loaded edit state.
1465 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001466 public float getWorkspaceSpringLoadScale(Context context) {
1467 float scale =
1468 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1469 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001470 scale = Math.min(scale, 1f);
1471
Pat Manninge63dd252022-08-02 16:15:29 +01001472 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001473 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001474 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001475 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001476 if (scaledWorkspaceWidth > maxAvailableWidth) {
1477 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1478 }
1479 return scale;
1480 }
1481
Pat Manning25d53342022-05-10 09:58:49 +00001482 /**
1483 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1484 *
1485 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1486 * layouts have two Cell Layouts per workspace.
1487 */
1488 public int getCellLayoutWidth() {
1489 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001490 }
1491
Pat Manning25d53342022-05-10 09:58:49 +00001492 /**
1493 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1494 *
1495 * <p>This is the height of a Workspace, less its vertical padding.
1496 */
1497 public int getCellLayoutHeight() {
1498 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001499 }
1500
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001501 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001502 return new Point(workspacePadding.left + workspacePadding.right,
1503 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001504 }
1505
1506 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001507 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1508 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001509 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001510 private void updateWorkspacePadding() {
1511 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001512 if (isVerticalBarLayout()) {
Jordan Silva3646a1b2023-08-02 13:52:52 +01001513 if (mIsResponsiveGrid) {
1514 padding.top = mResponsiveHeightSpec.getStartPaddingPx();
Thales Lima8e11d532023-08-31 13:40:26 +00001515 padding.bottom = Math.max(0,
1516 mResponsiveHeightSpec.getEndPaddingPx() - mInsets.bottom);
Jordan Silva3646a1b2023-08-02 13:52:52 +01001517 if (isSeascape()) {
1518 padding.left = hotseatBarSizePx + mResponsiveWidthSpec.getEndPaddingPx();
1519 padding.right = mResponsiveWidthSpec.getStartPaddingPx();
1520 } else {
1521 padding.left = mResponsiveWidthSpec.getStartPaddingPx();
1522 padding.right = hotseatBarSizePx + mResponsiveWidthSpec.getEndPaddingPx();
1523 }
Winson1f064272016-07-18 17:18:02 -07001524 } else {
Jordan Silva3646a1b2023-08-02 13:52:52 +01001525 padding.top = 0;
1526 padding.bottom = edgeMarginPx;
1527 if (isSeascape()) {
1528 padding.left = hotseatBarSizePx;
Thales Lima8e11d532023-08-31 13:40:26 +00001529 padding.right = mHotseatBarEdgePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001530 } else {
Thales Lima8e11d532023-08-31 13:40:26 +00001531 padding.left = mHotseatBarEdgePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001532 padding.right = hotseatBarSizePx;
1533 }
Winson1f064272016-07-18 17:18:02 -07001534 }
Winson Chungb3800242013-10-24 11:01:54 -07001535 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001536 // Pad the bottom of the workspace with hotseat bar
1537 // and leave a bit of space in case a widget go all the way down
Thales Lima79456492023-05-23 11:32:22 +01001538 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding - mInsets.bottom;
1539 if (!mIsResponsiveGrid) {
1540 paddingBottom +=
1541 workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace;
1542 }
1543 int paddingTop = workspaceTopPadding + (mIsScalableGrid ? 0 : edgeMarginPx);
Pat Manning08610ca2022-04-05 21:03:16 +01001544 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001545
Pat Manning08610ca2022-04-05 21:03:16 +01001546 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001547 }
Pat Manning08610ca2022-04-05 21:03:16 +01001548 insetPadding(workspacePadding, cellLayoutPaddingPx);
1549 }
1550
1551 private void insetPadding(Rect paddings, Rect insets) {
1552 insets.left = Math.min(insets.left, paddings.left);
1553 paddings.left -= insets.left;
1554
1555 insets.top = Math.min(insets.top, paddings.top);
1556 paddings.top -= insets.top;
1557
1558 insets.right = Math.min(insets.right, paddings.right);
1559 paddings.right -= insets.right;
1560
1561 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1562 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001563 }
1564
Sunny Goyal57b22792021-05-25 14:35:01 -07001565 /**
1566 * Returns the padding for hotseat view
1567 */
1568 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001569 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001570 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001571 // The hotseat icons will be placed in the middle of the hotseat cells.
1572 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1573 // in vertical bar layout.
1574 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1575 // is set to account for that difference.
Jordan Silva3646a1b2023-08-02 13:52:52 +01001576 float diffOverlapFactor = mIsResponsiveGrid ? 0
1577 : iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
1578
Pat Manning08610ca2022-04-05 21:03:16 +01001579 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1580 - diffOverlapFactor), 0);
1581 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001582 + diffOverlapFactor), 0);
1583
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001584 if (isSeascape()) {
Thales Lima8e11d532023-08-31 13:40:26 +00001585 hotseatBarPadding.set(mInsets.left + mHotseatBarEdgePaddingPx, paddingTop,
1586 mHotseatBarWorkspaceSpacePx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001587 } else {
Thales Lima8e11d532023-08-31 13:40:26 +00001588 hotseatBarPadding.set(mHotseatBarWorkspaceSpacePx, paddingTop,
1589 mInsets.right + mHotseatBarEdgePaddingPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001590 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001591 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001592 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001593 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1594 int hotseatBarTopPadding =
1595 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001596
Thales Lima6a590062022-11-22 15:52:49 +00001597 int hotseatWidth = getHotseatRequiredWidth();
Helen Cheuke76291f2023-02-14 17:11:05 +00001598 int startSpacing;
1599 int endSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001600 // Hotseat aligns to the left with nav buttons
1601 if (hotseatBarEndOffset > 0) {
Jon Mirandae17a9492023-03-08 16:42:20 -08001602 startSpacing = inlineNavButtonsEndSpacingPx;
Helen Cheuke76291f2023-02-14 17:11:05 +00001603 endSpacing = availableWidthPx - hotseatWidth - startSpacing + hotseatBorderSpace;
1604 } else {
1605 startSpacing = (availableWidthPx - hotseatWidth) / 2;
1606 endSpacing = startSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001607 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001608 startSpacing += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001609
Helen Cheuke76291f2023-02-14 17:11:05 +00001610 hotseatBarPadding.top = hotseatBarTopPadding;
1611 hotseatBarPadding.bottom = hotseatBarBottomPadding;
Alex Chau51da2192022-05-20 13:32:10 +01001612 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001613 if (isRtl) {
Helen Cheuke76291f2023-02-14 17:11:05 +00001614 hotseatBarPadding.left = endSpacing;
1615 hotseatBarPadding.right = startSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001616 } else {
Helen Cheuke76291f2023-02-14 17:11:05 +00001617 hotseatBarPadding.left = startSpacing;
1618 hotseatBarPadding.right = endSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001619 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001620
Thales Lima79456492023-05-23 11:32:22 +01001621 } else if (mIsScalableGrid) {
Alex Chau206ede92022-08-01 17:46:12 +01001622 int sideSpacing = (availableWidthPx - hotseatQsbWidth) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001623 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001624 0,
Thales Lima425f6822022-05-10 13:44:58 -03001625 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001626 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001627 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001628 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1629 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1630 // for this, we pad the left and right of the hotseat with half of the difference of a
1631 // workspace cell vs a hotseat cell.
1632 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001633 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001634 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001635 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001636 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1637 + mInsets.left,
1638 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001639 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001640 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001641 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001642 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001643 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001644 }
1645
Andy Wickhambd9a1802023-06-08 16:33:15 -07001646 /** The margin between the edge of all apps and the edge of the first icon. */
1647 public int getAllAppsIconStartMargin() {
1648 int allAppsSpacing;
1649 if (isVerticalBarLayout()) {
1650 // On phones, the landscape layout uses a different setup.
1651 allAppsSpacing = workspacePadding.left + workspacePadding.right;
1652 } else {
1653 allAppsSpacing = allAppsLeftRightPadding * 2 + allAppsLeftRightMargin * 2;
1654 }
1655
1656 int cellWidth = DeviceProfile.calculateCellWidth(
1657 availableWidthPx - allAppsSpacing,
1658 0 /* borderSpace */,
1659 numShownAllAppsColumns);
1660 int iconVisibleSize = Math.round(ICON_VISIBLE_AREA_FACTOR * allAppsIconSizePx);
1661 int iconAlignmentMargin = (cellWidth - iconVisibleSize) / 2;
1662 return allAppsLeftRightPadding + iconAlignmentMargin;
1663 }
1664
Thales Lima9938c2f2022-07-25 14:38:16 +01001665 private int getAdditionalQsbSpace() {
1666 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1667 }
1668
1669 /**
1670 * Calculate how much space the hotseat needs to be shown completely
1671 */
1672 private int getHotseatRequiredWidth() {
1673 int additionalQsbSpace = getAdditionalQsbSpace();
1674 return iconSizePx * numShownHotseatIcons
Thales Lima6a590062022-11-22 15:52:49 +00001675 + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1))
Thales Lima9938c2f2022-07-25 14:38:16 +01001676 + additionalQsbSpace;
1677 }
1678
Winsonfadbe8f2016-07-22 16:35:37 -07001679 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001680 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1681 */
1682 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001683 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001684 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1685 } else if (isTaskbarPresent) { // QSB on top
1686 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001687 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001688 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001689 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001690 }
1691
Thales Limab8c05952022-05-23 16:58:38 +01001692 /**
1693 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1694 */
1695 private int getHotseatBarBottomPadding() {
1696 if (isTaskbarPresent) { // QSB on top or inline
1697 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001698 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001699 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001700 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001701 }
1702
1703 /**
Alex Chau51da2192022-05-20 13:32:10 +01001704 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1705 */
1706 public int getTaskbarOffsetY() {
Jon Miranda9c478b62023-03-23 21:38:49 -07001707 int taskbarIconBottomSpace = (taskbarHeight - iconSizePx) / 2;
Alex Chau51da2192022-05-20 13:32:10 +01001708 int launcherIconBottomSpace =
1709 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001710 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001711 }
1712
1713 /**
Alex Chaua2fc7642022-04-21 14:20:23 +01001714 * Returns the number of pixels required below OverviewActions excluding insets.
1715 */
1716 public int getOverviewActionsClaimedSpaceBelow() {
Alex Chaud67ddc42022-09-30 18:15:56 +01001717 if (isTaskbarPresent) {
Jon Miranda9c478b62023-03-23 21:38:49 -07001718 return taskbarHeight + taskbarBottomMargin * 2;
Alex Chaud67ddc42022-09-30 18:15:56 +01001719 }
1720 return mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001721 }
1722
1723 /** Gets the space that the overview actions will take, including bottom margin. */
1724 public int getOverviewActionsClaimedSpace() {
Pat Manning7b8f7662023-01-18 14:48:30 +00001725 int overviewActionsSpace = isTablet && FeatureFlags.ENABLE_GRID_ONLY_OVERVIEW.get()
1726 ? 0
1727 : (overviewActionsTopMarginPx + overviewActionsHeight);
1728 return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
Alex Chaua2fc7642022-04-21 14:20:23 +01001729 }
1730
1731 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001732 * Takes the View and return the scales of width and height depending on the DeviceProfile
1733 * specifications
1734 *
1735 * @param itemInfo The tag of the widget view
1736 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1737 * height
1738 */
1739 @NonNull
1740 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1741 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1742 }
1743
1744 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001745 * @return the bounds for which the open folders should be contained within
1746 */
1747 public Rect getAbsoluteOpenFolderBounds() {
1748 if (isVerticalBarLayout()) {
1749 // Folders should only appear right of the drop target bar and left of the hotseat
1750 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1751 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001752 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001753 mInsets.top + availableHeightPx);
1754 } else {
1755 // Folders should only appear below the drop target bar and above the hotseat
Jon Miranda9c478b62023-03-23 21:38:49 -07001756 int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001757 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001758 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001759 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001760 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001761 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001762 }
1763 }
1764
Jon Miranda228877d2021-02-09 11:05:00 -05001765 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1766 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001767 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001768
Jon Miranda228877d2021-02-09 11:05:00 -05001769 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1770 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001771 }
1772
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001773 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001774 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1775 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1776 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001777 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001778 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001779 return isLandscape && transposeLayoutWithOrientation;
1780 }
1781
Sunny Goyal59d086c2018-05-07 17:31:40 -07001782 /**
1783 * Updates orientation information and returns true if it has changed from the previous value.
1784 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001785 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001786 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001787 boolean isSeascape = DisplayController.INSTANCE.get(context)
1788 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001789 if (mIsSeascape != isSeascape) {
1790 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001791 // Hotseat changing sides requires updating workspace left/right paddings
1792 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001793 return true;
1794 }
1795 }
1796 return false;
1797 }
1798
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001799 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001800 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001801 }
1802
Sunny Goyal07b69292018-01-08 14:19:34 -08001803 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001804 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001805 }
1806
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001807 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001808 switch (containerType) {
1809 case CellLayout.WORKSPACE:
1810 return cellHeightPx;
1811 case CellLayout.FOLDER:
1812 return folderCellHeightPx;
1813 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001814 // The hotseat is the only container where the cell height is going to be
1815 // different from the content within that cell.
1816 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001817 default:
1818 // ??
1819 return 0;
1820 }
1821 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001822
Jon Miranda58561d42021-03-17 10:51:54 -04001823 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001824 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001825 }
1826
Alex Chaue818bcb2022-09-02 17:27:11 +01001827 private String dpPointFToString(String name, PointF value) {
1828 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
1829 }
1830
Pat Manning5f74bfd2022-07-20 12:08:54 +01001831 /** Dumps various DeviceProfile variables to the specified writer. */
1832 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04001833 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001834 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001835
1836 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001837 writer.println(prefix + "\tisPhone:" + isPhone);
1838 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1839 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001840 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001841
1842 writer.println(prefix + "\tisLandscape:" + isLandscape);
1843 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001844 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001845
1846 writer.println(prefix + pxToDpStr("windowX", windowX));
1847 writer.println(prefix + pxToDpStr("windowY", windowY));
1848 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1849 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001850 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1851 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001852 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1853 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1854 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1855 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001856
1857 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1858
Thales Limac98b7812023-04-14 15:04:23 +01001859 writer.println(prefix + "\tisResponsiveGrid:" + mIsResponsiveGrid);
Thales Lima79456492023-05-23 11:32:22 +01001860 writer.println(prefix + "\tisScalableGrid:" + mIsScalableGrid);
Jon Miranda58561d42021-03-17 10:51:54 -04001861
Thales Lima83bedbf2021-10-05 17:47:39 +01001862 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001863 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1864 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1865 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001866
Alex Chaue818bcb2022-09-02 17:27:11 +01001867 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07001868
Jon Miranda58561d42021-03-17 10:51:54 -04001869 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1870 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1871
1872 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1873 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1874
Thales Lima83bedbf2021-10-05 17:47:39 +01001875 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1876 cellLayoutBorderSpacePx.x));
1877 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1878 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001879 writer.println(
1880 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
1881 writer.println(
1882 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
1883 writer.println(
1884 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01001885 writer.println(
1886 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01001887
Jon Miranda58561d42021-03-17 10:51:54 -04001888 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1889 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1890 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1891
Helen Cheuk599109b2023-02-23 17:15:39 +00001892 writer.println(prefix + "\tinv.numFolderRows: " + inv.numFolderRows);
1893 writer.println(prefix + "\tinv.numFolderColumns: " + inv.numFolderColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001894 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1895 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1896 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1897 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1898 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1899 folderChildDrawablePaddingPx));
Jordan Silva637f4eb2023-06-13 11:21:53 +01001900 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.x",
1901 folderCellLayoutBorderSpacePx.x));
1902 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.y",
1903 folderCellLayoutBorderSpacePx.y));
Thales Limaa08a4432022-08-09 09:55:17 +01001904 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
1905 folderContentPaddingLeftRight));
1906 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03001907 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001908
Alex Chaue0227552022-04-06 19:44:43 +01001909 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001910 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
1911 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
1912 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
1913 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01001914
1915 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
1916 writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001917 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
1918 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04001919 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1920 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1921 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1922 allAppsIconDrawablePaddingPx));
1923 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001924 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001925 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
1926 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001927 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau62572c02022-07-25 18:36:37 +00001928 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
Alex Chau27b39b92022-01-14 18:02:18 +00001929 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001930
1931 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03001932 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04001933 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00001934 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Thales Lima8e11d532023-08-31 13:40:26 +00001935 writer.println(prefix + pxToDpStr("mHotseatBarEdgePaddingPx",
1936 mHotseatBarEdgePaddingPx));
1937 writer.println(prefix + pxToDpStr("mHotseatBarWorkspaceSpacePx",
1938 mHotseatBarWorkspaceSpacePx));
Pat Manning26f70f72022-07-07 13:50:39 +01001939 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01001940 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
1941 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01001942 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
1943 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001944 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
1945 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
1946 hotseatLayoutPadding.top));
1947 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
1948 hotseatLayoutPadding.bottom));
1949 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
1950 hotseatLayoutPadding.left));
1951 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
1952 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001953 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001954 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001955 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01001956 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001957
1958 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001959 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda9c478b62023-03-23 21:38:49 -07001960 writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight));
1961 writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight));
1962 writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin));
1963 writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001964
Thales Lima83bedbf2021-10-05 17:47:39 +01001965 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1966 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001967 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
1968 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
1969 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00001970 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001971
Jon Mirandaab3c6812021-06-28 15:42:28 -07001972 writer.println(prefix + pxToDpStr("iconScale", iconScale));
1973 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04001974 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00001975 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001976
Thales Lima171ee662022-11-22 15:52:49 +00001977 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04001978 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
1979 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00001980
1981 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00001982 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
1983 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
1984 overviewTaskIconDrawableSizePx));
1985 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
1986 overviewTaskIconDrawableSizeGridPx));
1987 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
1988 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01001989 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
1990 overviewActionsTopMarginPx));
1991 writer.println(prefix + pxToDpStr("overviewActionsHeight",
1992 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00001993 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
1994 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00001995 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
1996 overviewActionsButtonSpacing));
1997 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
1998 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
1999 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01002000
Alex Chau62572c02022-07-25 18:36:37 +00002001 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01002002 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00002003 writer.println(
2004 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01002005
Pat Manning5f74bfd2022-07-20 12:08:54 +01002006 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
2007 getCellLayoutSpringLoadShrunkTop()));
2008 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
2009 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01002010 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
2011 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002012 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
2013 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01002014 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
2015 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Thales Lima79456492023-05-23 11:32:22 +01002016 if (mIsResponsiveGrid) {
2017 writer.println(prefix + "\tmResponsiveHeightSpec:" + mResponsiveHeightSpec.toString());
2018 writer.println(prefix + "\tmResponsiveWidthSpec:" + mResponsiveWidthSpec.toString());
Thales Limaabfe3642023-05-24 18:08:53 +01002019 writer.println(prefix + "\tmAllAppsResponsiveHeightSpec:"
2020 + mAllAppsResponsiveHeightSpec.toString());
2021 writer.println(prefix + "\tmAllAppsResponsiveWidthSpec:"
2022 + mAllAppsResponsiveWidthSpec.toString());
Jordan Silva637f4eb2023-06-13 11:21:53 +01002023 writer.println(prefix + "\tmResponsiveFolderHeightSpec:" + mResponsiveFolderHeightSpec);
2024 writer.println(prefix + "\tmResponsiveFolderWidthSpec:" + mResponsiveFolderWidthSpec);
Thales Limaf8bfb032023-07-24 15:08:05 +01002025 writer.println(prefix + "\tmResponsiveHotseatSpec:" + mResponsiveHotseatSpec);
Thales Lima79456492023-05-23 11:32:22 +01002026 }
Jon Miranda58561d42021-03-17 10:51:54 -04002027 }
2028
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00002029 /** Returns a reduced representation of this DeviceProfile. */
2030 public String toSmallString() {
2031 return "isTablet:" + isTablet + ", "
2032 + "isMultiDisplay:" + isMultiDisplay + ", "
2033 + "widthPx:" + widthPx + ", "
2034 + "heightPx:" + heightPx + ", "
2035 + "insets:" + mInsets + ", "
2036 + "rotationHint:" + rotationHint;
2037 }
2038
Alex Chaua6907dc2022-03-18 15:24:07 +00002039 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07002040 Configuration config = new Configuration(c.getResources().getConfiguration());
2041 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03002042 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00002043 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07002044 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07002045 }
Sunny Goyalfde55052018-02-01 14:46:13 -08002046
2047 /**
2048 * Callback when a component changes the DeviceProfile associated with it, as a result of
2049 * configuration change
2050 */
2051 public interface OnDeviceProfileChangeListener {
2052
2053 /**
2054 * Called when the device profile is reassigned. Note that for layout and measurements, it
2055 * is sufficient to listen for inset changes. Use this callback when you need to perform
2056 * a one time operation.
2057 */
2058 void onDeviceProfileChanged(DeviceProfile dp);
2059 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002060
Sihua Mae04aa202022-07-18 12:43:56 -07002061 /**
2062 * Handler that deals with ItemInfo of the views for the DeviceProfile
2063 */
2064 @FunctionalInterface
2065 public interface ViewScaleProvider {
2066 /**
2067 * Get the scales from the view
2068 *
2069 * @param itemInfo The tag of the widget view
2070 * @return PointF instance containing the scale information, or null if using the default
2071 * app widget scale of this device profile.
2072 */
2073 @NonNull
2074 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
2075 }
2076
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002077 public static class Builder {
2078 private Context mContext;
2079 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07002080 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002081
Sunny Goyal19ff7282021-04-22 10:12:54 -07002082 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00002083 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002084
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002085 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07002086 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00002087 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07002088 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002089
Sunny Goyal65190ae2022-08-02 14:16:26 -07002090 private SparseArray<DotRenderer> mDotRendererCache;
2091
Jon Miranda2b25ded2023-02-02 14:48:45 -08002092 private Consumer<DeviceProfile> mOverrideProvider;
2093
Sunny Goyalfd58da62020-08-11 12:06:49 -07002094 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002095 mContext = context;
2096 mInv = inv;
2097 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002098 }
2099
2100 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
2101 mIsMultiWindowMode = isMultiWindowMode;
2102 return this;
2103 }
2104
Alex Chauab800f72022-12-13 17:46:06 +00002105 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
2106 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07002107 return this;
2108 }
2109
Sunny Goyal65190ae2022-08-02 14:16:26 -07002110 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
2111 mDotRendererCache = dotRendererCache;
2112 return this;
2113 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07002114
2115 public Builder setWindowBounds(WindowBounds bounds) {
2116 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07002117 return this;
2118 }
2119
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002120 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
2121 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
2122 return this;
2123 }
2124
Alex Chau6ed408f2022-03-04 12:58:05 +00002125 public Builder setGestureMode(boolean isGestureMode) {
2126 mIsGestureMode = isGestureMode;
2127 return this;
2128 }
2129
Jon Miranda2b25ded2023-02-02 14:48:45 -08002130 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
2131 mOverrideProvider = overrideProvider;
2132 return this;
2133 }
2134
Sihua Mae04aa202022-07-18 12:43:56 -07002135 /**
2136 * Set the viewScaleProvider for the builder
2137 *
2138 * @param viewScaleProvider The viewScaleProvider to be set for the
Thales Limae9273ea2023-01-26 12:33:52 +00002139 * DeviceProfile
Sihua Mae04aa202022-07-18 12:43:56 -07002140 * @return This builder
2141 */
2142 @NonNull
2143 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
2144 mViewScaleProvider = viewScaleProvider;
2145 return this;
2146 }
2147
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002148 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07002149 if (mWindowBounds == null) {
2150 throw new IllegalArgumentException("Window bounds not set");
2151 }
2152 if (mTransposeLayoutWithOrientation == null) {
2153 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
2154 }
Alex Chau6ed408f2022-03-04 12:58:05 +00002155 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01002156 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00002157 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002158 if (mDotRendererCache == null) {
2159 mDotRendererCache = new SparseArray<>();
2160 }
Sihua Mae04aa202022-07-18 12:43:56 -07002161 if (mViewScaleProvider == null) {
2162 mViewScaleProvider = DEFAULT_PROVIDER;
2163 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08002164 if (mOverrideProvider == null) {
2165 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
2166 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002167 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00002168 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jon Miranda2b25ded2023-02-02 14:48:45 -08002169 mIsGestureMode, mViewScaleProvider, mOverrideProvider);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002170 }
2171 }
2172
Winson Chungb3800242013-10-24 11:01:54 -07002173}