blob: fb41044875aa681f7879313779c604d742008b04 [file] [log] [blame]
Winson Chungb3800242013-10-24 11:01:54 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.launcher3;
18
Thales Lima12d0eff2022-03-25 17:06:11 +000019import static com.android.launcher3.InvariantDeviceProfile.INDEX_DEFAULT;
20import static com.android.launcher3.InvariantDeviceProfile.INDEX_LANDSCAPE;
21import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_LANDSCAPE;
22import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_PORTRAIT;
Jon Miranda58561d42021-03-17 10:51:54 -040023import static com.android.launcher3.Utilities.dpiFromPx;
Jon Mirandaaf3aed02021-05-06 18:28:45 -070024import static com.android.launcher3.Utilities.pxFromSp;
Alex Chau3d2c0622022-09-01 21:28:14 +010025import static com.android.launcher3.anim.Interpolators.LINEAR;
Alex Chauab800f72022-12-13 17:46:06 +000026import static com.android.launcher3.config.FeatureFlags.ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH;
Jon Miranda92c1b5d2021-07-20 13:57:16 -070027import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.ICON_OVERLAP_FACTOR;
Sunny Goyal65190ae2022-08-02 14:16:26 -070028import static com.android.launcher3.icons.GraphicsUtils.getShapePath;
Thales Limab35faed2022-09-05 16:30:01 -030029import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURCE_HANDLE;
Pat Manning5f74bfd2022-07-20 12:08:54 +010030import static com.android.launcher3.testing.shared.ResourceUtils.pxFromDp;
Thales Lima7eee74b2023-03-16 16:00:55 -030031import static com.android.launcher3.testing.shared.ResourceUtils.roundPxValueFromFloat;
Jon Miranda228877d2021-02-09 11:05:00 -050032
Sunny Goyal35c7b192021-04-20 16:51:10 -070033import android.annotation.SuppressLint;
Winson Chungb3800242013-10-24 11:01:54 -070034import android.content.Context;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070035import android.content.res.Configuration;
Winson Chungb3800242013-10-24 11:01:54 -070036import android.content.res.Resources;
Thales Limab35faed2022-09-05 16:30:01 -030037import android.content.res.TypedArray;
Winson Chungb3800242013-10-24 11:01:54 -070038import android.graphics.Point;
Jon Miranda7ae64ff2016-11-21 16:18:46 -080039import android.graphics.PointF;
Winson Chungb3800242013-10-24 11:01:54 -070040import android.graphics.Rect;
Sunny Goyal35c7b192021-04-20 16:51:10 -070041import android.util.DisplayMetrics;
Sunny Goyal65190ae2022-08-02 14:16:26 -070042import android.util.SparseArray;
Sunny Goyal59d086c2018-05-07 17:31:40 -070043import android.view.Surface;
Winson Chungb3800242013-10-24 11:01:54 -070044
Sunny Goyal65190ae2022-08-02 14:16:26 -070045import androidx.annotation.NonNull;
Sihua Mae04aa202022-07-18 12:43:56 -070046import androidx.annotation.Nullable;
Jon Miranda9c478b62023-03-23 21:38:49 -070047import androidx.core.content.res.ResourcesCompat;
Sunny Goyal65190ae2022-08-02 14:16:26 -070048
Sunny Goyalc13403c2016-11-18 23:44:48 -080049import com.android.launcher3.CellLayout.ContainerType;
Jon Miranda228877d2021-02-09 11:05:00 -050050import com.android.launcher3.DevicePaddings.DevicePadding;
Alex Chaud67ddc42022-09-30 18:15:56 +010051import com.android.launcher3.config.FeatureFlags;
Tony Wickham8912b042018-11-29 15:28:53 -080052import com.android.launcher3.icons.DotRenderer;
Hyunyoung Song48cb7bc2018-09-25 17:03:34 -070053import com.android.launcher3.icons.IconNormalizer;
Sihua Mae04aa202022-07-18 12:43:56 -070054import com.android.launcher3.model.data.ItemInfo;
Sunny Goyal57b22792021-05-25 14:35:01 -070055import com.android.launcher3.uioverrides.ApiWrapper;
Sunny Goyalfd58da62020-08-11 12:06:49 -070056import com.android.launcher3.util.DisplayController;
57import com.android.launcher3.util.DisplayController.Info;
Thales Limac98b7812023-04-14 15:04:23 +010058import com.android.launcher3.util.ResourceHelper;
Sunny Goyalb46703d2020-05-27 17:52:03 -070059import com.android.launcher3.util.WindowBounds;
Thales Limac98b7812023-04-14 15:04:23 +010060import com.android.launcher3.workspace.CalculatedWorkspaceSpec;
61import com.android.launcher3.workspace.WorkspaceSpecs;
Winson1f064272016-07-18 17:18:02 -070062
Jon Miranda58561d42021-03-17 10:51:54 -040063import java.io.PrintWriter;
Alex Chaue818bcb2022-09-02 17:27:11 +010064import java.util.Locale;
Jon Miranda2b25ded2023-02-02 14:48:45 -080065import java.util.function.Consumer;
Jon Miranda58561d42021-03-17 10:51:54 -040066
Sunny Goyal35c7b192021-04-20 16:51:10 -070067@SuppressLint("NewApi")
Winson Chungb3800242013-10-24 11:01:54 -070068public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070069
Sunny Goyal8b9919d2021-04-07 14:45:17 -070070 private static final int DEFAULT_DOT_SIZE = 100;
Alex Chau206ede92022-08-01 17:46:12 +010071 private static final float ALL_APPS_TABLET_MAX_ROWS = 5.5f;
Thales Limab35faed2022-09-05 16:30:01 -030072 private static final float MIN_FOLDER_TEXT_SIZE_SP = 16f;
Sunny Goyal6c304b12023-04-10 12:03:04 -070073 private static final float MIN_WIDGET_PADDING_DP = 6f;
Alex Chau206ede92022-08-01 17:46:12 +010074
Sihua Mae04aa202022-07-18 12:43:56 -070075 public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f);
76 public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE;
Jon Miranda2b25ded2023-02-02 14:48:45 -080077 public static final Consumer<DeviceProfile> DEFAULT_DIMENSION_PROVIDER = dp -> {};
Sihua Mae04aa202022-07-18 12:43:56 -070078
Adam Cohen2e6da152015-05-06 11:42:25 -070079 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070080 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070081 private final DisplayMetrics mMetrics;
Winson Chungbe876472014-05-14 14:15:20 -070082
Sunny Goyalc6205602015-05-21 20:46:33 -070083 // Device properties
84 public final boolean isTablet;
Sunny Goyalc6205602015-05-21 20:46:33 -070085 public final boolean isPhone;
86 public final boolean transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +000087 public final boolean isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -070088 public final boolean isTwoPanels;
Thales Limaa1012902022-01-13 17:58:42 +000089 public final boolean isQsbInline;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -070090
Sunny Goyalc6205602015-05-21 20:46:33 -070091 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -070092 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -080093 public final boolean isMultiWindowMode;
Alex Chau6ed408f2022-03-04 12:58:05 +000094 public final boolean isGestureMode;
Sunny Goyald70e75a2018-02-22 10:07:32 -080095
Sunny Goyal0addbf02020-04-28 14:17:35 -070096 public final int windowX;
97 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -070098 public final int widthPx;
99 public final int heightPx;
100 public final int availableWidthPx;
101 public final int availableHeightPx;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800102 public final int rotationHint;
Jon Mirandabba64512019-03-27 10:54:17 -0700103
104 public final float aspectRatio;
105
Jon Mirandae126d722021-02-25 10:45:20 -0500106 public final boolean isScalableGrid;
Thales Lima83bedbf2021-10-05 17:47:39 +0100107 private final int mTypeIndex;
Jon Mirandae126d722021-02-25 10:45:20 -0500108
Thales Limac98b7812023-04-14 15:04:23 +0100109 // Responsive grid
110 private final boolean mIsResponsiveGrid;
111 private WorkspaceSpecs mWorkspaceSpecs;
112 private CalculatedWorkspaceSpec mResponsiveWidthSpec;
113 private CalculatedWorkspaceSpec mResponsiveHeightSpec;
114
Tony Wickhamd6b40372015-09-23 18:37:57 -0700115 /**
116 * The maximum amount of left/right workspace padding as a percentage of the screen width.
117 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
118 * 7% of the screen width can be used as right padding.
119 */
120 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -0700121
Jon Miranda3f9bab22017-07-28 14:50:17 -0700122 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700123 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda80dda302021-07-28 14:14:59 -0700124 private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252;
125 private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700126
Sunny Goyalc6205602015-05-21 20:46:33 -0700127 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +0100128 public final int desiredWorkspaceHorizontalMarginOriginalPx;
129 public int desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100130 public int gridVisualizationPaddingX;
131 public int gridVisualizationPaddingY;
Thales Lima78d00ad2021-09-30 11:29:06 +0100132 public Point cellLayoutBorderSpaceOriginalPx;
133 public Point cellLayoutBorderSpacePx;
Pat Manning08610ca2022-04-05 21:03:16 +0100134 public Rect cellLayoutPaddingPx = new Rect();
135
Sunny Goyalc6205602015-05-21 20:46:33 -0700136 public final int edgeMarginPx;
Alex Chau0c4e11b2022-07-08 18:41:36 +0100137 public final float workspaceContentScale;
Alex Chau906d8822022-05-23 10:42:25 +0100138 public final int workspaceSpringLoadedMinNextPageVisiblePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700139
Jon Miranda58561d42021-03-17 10:51:54 -0400140 private final int extraSpace;
Thales Lima171ee662022-11-22 15:52:49 +0000141 private int maxEmptySpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500142 public int workspaceTopPadding;
143 public int workspaceBottomPadding;
144
Tony Wickham5edf9e22020-03-27 20:06:52 -0700145 // Workspace page indicator
146 public final int workspacePageIndicatorHeight;
147 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700148
Sunny Goyalc6205602015-05-21 20:46:33 -0700149 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400150 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700151 public int iconSizePx;
152 public int iconTextSizePx;
153 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700154 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -0700155
Jon Mirandaab3c6812021-06-28 15:42:28 -0700156 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800157 public int cellWidthPx;
158 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700159 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800160
Jon Mirandae126d722021-02-25 10:45:20 -0500161 public int cellYPaddingPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500162
Sunny Goyalc6205602015-05-21 20:46:33 -0700163 // Folder
Jon Mirandae126d722021-02-25 10:45:20 -0500164 public float folderLabelTextScale;
165 public int folderLabelTextSizePx;
Thales Limab35faed2022-09-05 16:30:01 -0300166 public int folderFooterHeightPx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700167 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700168 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700169
Jon Mirandae126d722021-02-25 10:45:20 -0500170 // Folder content
Thales Limab35faed2022-09-05 16:30:01 -0300171 public int folderCellLayoutBorderSpacePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500172 public int folderContentPaddingLeftRight;
173 public int folderContentPaddingTop;
174
Jon Mirandabf7d8122016-11-03 15:29:29 -0700175 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700176 public int folderCellWidthPx;
177 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700178
179 // Folder child
180 public int folderChildIconSizePx;
181 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700182 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700183
Sunny Goyalc6205602015-05-21 20:46:33 -0700184 // Hotseat
Thales Lima9938c2f2022-07-25 14:38:16 +0100185 public int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700186 public int hotseatCellHeightPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100187 public final boolean areNavButtonsInline;
Jon Miranda18751b62017-07-31 17:25:27 -0700188 // In portrait: size = height, in landscape: size = width
189 public int hotseatBarSizePx;
Thales Limab8c05952022-05-23 16:58:38 +0100190 public int hotseatBarBottomSpacePx;
Pat Manning26f70f72022-07-07 13:50:39 +0100191 public int hotseatBarEndOffset;
Thales Limab8c05952022-05-23 16:58:38 +0100192 public int hotseatQsbSpace;
Pat Manningde25c0d2022-04-05 19:11:26 +0100193 public int springLoadedHotseatBarTopMarginPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700194 // Start is the side next to the nav bar, end is the side next to the workspace
195 public final int hotseatBarSidePaddingStartPx;
196 public final int hotseatBarSidePaddingEndPx;
Alex Chau206ede92022-08-01 17:46:12 +0100197 public int hotseatQsbWidth; // only used when isQsbInline
Sunny Goyal57b22792021-05-25 14:35:01 -0700198 public final int hotseatQsbHeight;
Thales Limab8c05952022-05-23 16:58:38 +0100199 public final int hotseatQsbVisualHeight;
200 private final int hotseatQsbShadowHeight;
Thales Limadd027342022-01-07 12:54:37 +0000201 public int hotseatBorderSpace;
Thales Limaffc68b02023-01-09 16:20:23 +0000202 private final int mMinHotseatIconSpacePx;
203 private final int mMinHotseatQsbWidthPx;
204 private final int mMaxHotseatIconSpacePx;
Jon Mirandae17a9492023-03-08 16:42:20 -0800205 public final int inlineNavButtonsEndSpacingPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700206
Alex Chau3d2c0622022-09-01 21:28:14 +0100207 // Bottom sheets
208 public int bottomSheetTopPadding;
209 public int bottomSheetOpenDuration;
210 public int bottomSheetCloseDuration;
211 public float bottomSheetWorkspaceScale;
212 public float bottomSheetDepth;
213
Sunny Goyalc6205602015-05-21 20:46:33 -0700214 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000215 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000216 public int allAppsShiftRange;
217 public int allAppsTopPadding;
Alex Chau3d2c0622022-09-01 21:28:14 +0100218 public int allAppsOpenDuration;
219 public int allAppsCloseDuration;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700220 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700221 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700222 public int allAppsIconSizePx;
223 public int allAppsIconDrawablePaddingPx;
sfufa@google.comde013292021-09-21 18:22:44 -0700224 public int allAppsLeftRightPadding;
Alex Chau27b39b92022-01-14 18:02:18 +0000225 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700226 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700227 public float allAppsIconTextSizePx;
228
Zak Cohen334efeb2021-03-19 16:42:07 -0700229 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700230 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000231 public int overviewTaskIconSizePx;
Alex Chauac9df382021-08-02 19:08:41 +0100232 public int overviewTaskIconDrawableSizePx;
233 public int overviewTaskIconDrawableSizeGridPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000234 public int overviewTaskThumbnailTopMarginPx;
Alex Chau19c6eca2022-03-10 20:12:56 +0000235 public final int overviewActionsHeight;
Alex Chaua2fc7642022-04-21 14:20:23 +0100236 public final int overviewActionsTopMarginPx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000237 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100238 public int overviewPageSpacing;
239 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000240 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700241
Jeremy Sim0ac47082022-10-10 13:59:40 -0700242 // Split staging
243 public int splitPlaceholderInset;
244
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800245 // Widgets
Sihua Mae04aa202022-07-18 12:43:56 -0700246 private final ViewScaleProvider mViewScaleProvider;
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800247
Sunny Goyal47328fd2016-05-25 18:56:41 -0700248 // Drop Target
249 public int dropTargetBarSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100250 public int dropTargetBarTopMarginPx;
251 public int dropTargetBarBottomMarginPx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100252 public int dropTargetDragPaddingPx;
253 public int dropTargetTextSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100254 public int dropTargetHorizontalPaddingPx;
255 public int dropTargetVerticalPaddingPx;
256 public int dropTargetGapPx;
Alex Chau5b019302022-05-23 10:42:25 +0100257 public int dropTargetButtonWorkspaceEdgeGapPx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700258
Winson1f064272016-07-18 17:18:02 -0700259 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800260 private final Rect mInsets = new Rect();
261 public final Rect workspacePadding = new Rect();
Sunny Goyal6c304b12023-04-10 12:03:04 -0700262 // Additional padding added to the widget inside its cellSpace. It is applied outside
263 // the widgetView, such that the actual view size is same as the widget size.
264 public final Rect widgetPadding = new Rect();
265
Jon Miranda0bd63d12019-03-06 17:29:29 -0800266 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700267 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700268
Tony Wickhamf34bee82018-12-03 18:11:39 -0800269 // Notification dots
Sunny Goyal65190ae2022-08-02 14:16:26 -0700270 public final DotRenderer mDotRendererWorkSpace;
271 public final DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800272
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100273 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800274 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000275 // Whether Taskbar will inset the bottom of apps by taskbarSize.
276 public boolean isTaskbarPresentInApps;
Jon Miranda9c478b62023-03-23 21:38:49 -0700277 public final int taskbarHeight;
278 public final int stashedTaskbarHeight;
279 public final int taskbarBottomMargin;
280 public final int taskbarIconSize;
Jon Miranda04f05102023-04-04 12:16:31 -0700281 // If true, used to layout taskbar in 3 button navigation mode.
282 public final boolean startAlignTaskbar;
Tony Wickham15883892021-02-12 11:24:40 -0800283
Alex Chaua02eddc2021-04-29 00:36:06 +0100284 // DragController
285 public int flingToDeleteThresholdVelocity;
286
Vinit Nayak17c4b332021-08-05 12:54:58 -0700287 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700288 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal65190ae2022-08-02 14:16:26 -0700289 SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
Alex Chauab800f72022-12-13 17:46:06 +0000290 boolean transposeLayoutWithOrientation, boolean isMultiDisplay, boolean isGestureMode,
Jon Miranda2b25ded2023-02-02 14:48:45 -0800291 @NonNull final ViewScaleProvider viewScaleProvider,
292 @NonNull final Consumer<DeviceProfile> dimensionOverrideProvider) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700293
Adam Cohen2e6da152015-05-06 11:42:25 -0700294 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700295 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800296 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500297 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +0000298 this.isMultiDisplay = isMultiDisplay;
Alex Chau6ed408f2022-03-04 12:58:05 +0000299 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700300 windowX = windowBounds.bounds.left;
301 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800302 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100303 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700304
Thales Limac98b7812023-04-14 15:04:23 +0100305 // TODO(b/241386436): shouldn't change any launcher behaviour
306 mIsResponsiveGrid = inv.workspaceSpecsId != INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100307
Jon Mirandae126d722021-02-25 10:45:20 -0500308 isScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000309 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700310 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000311 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700312 isPhone = !isTablet;
Alex Chauab800f72022-12-13 17:46:06 +0000313 isTwoPanels = isTablet && isMultiDisplay;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800314 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700315
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000316 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000317 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700318 ? Configuration.ORIENTATION_LANDSCAPE
319 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000320 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700321 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000322 mMetrics = res.getDisplayMetrics();
323
324 // Determine sizes.
325 widthPx = windowBounds.bounds.width();
326 heightPx = windowBounds.bounds.height();
327 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100328 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000329
330 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Thales Lima83bedbf2021-10-05 17:47:39 +0100331 if (isTwoPanels) {
332 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000333 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100334 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000335 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100336 }
337 } else {
338 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000339 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100340 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000341 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100342 }
343 }
344
Thales Limac98b7812023-04-14 15:04:23 +0100345 if (mIsResponsiveGrid) {
346 mWorkspaceSpecs = new WorkspaceSpecs(new ResourceHelper(context, inv.workspaceSpecsId));
347 mResponsiveWidthSpec = mWorkspaceSpecs.getCalculatedWidthSpec(inv.numColumns,
348 availableWidthPx);
349 mResponsiveHeightSpec = mWorkspaceSpecs.getCalculatedHeightSpec(inv.numRows,
350 availableHeightPx);
351 }
352
Jon Miranda9c478b62023-03-23 21:38:49 -0700353 if (DisplayController.isTransientTaskbar(context)) {
354 float invTransientIconSizeDp = inv.transientTaskbarIconSize[mTypeIndex];
355 taskbarIconSize = pxFromDp(invTransientIconSizeDp, mMetrics);
356 taskbarHeight = taskbarIconSize
357 + (2 * res.getDimensionPixelSize(R.dimen.transient_taskbar_padding));
358 stashedTaskbarHeight =
359 res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_height);
360 taskbarBottomMargin =
361 res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin);
Jon Miranda04f05102023-04-04 12:16:31 -0700362 startAlignTaskbar = false;
Jon Miranda9c478b62023-03-23 21:38:49 -0700363 } else {
364 taskbarIconSize = pxFromDp(ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size),
365 mMetrics);
366 taskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_size);
367 stashedTaskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
368 taskbarBottomMargin = 0;
Jon Miranda04f05102023-04-04 12:16:31 -0700369 startAlignTaskbar = inv.startAlignTaskbar[mTypeIndex];
Tony Wickham15883892021-02-12 11:24:40 -0800370 }
Tony Wickham15883892021-02-12 11:24:40 -0800371
Winson Chungb3800242013-10-24 11:01:54 -0700372 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100373 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700374
Thales Limad90faab2021-09-21 17:18:47 +0100375 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
376 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100377 gridVisualizationPaddingX = res.getDimensionPixelSize(
378 R.dimen.grid_visualization_horizontal_cell_spacing);
379 gridVisualizationPaddingY = res.getDimensionPixelSize(
380 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500381
Alex Chaue0227552022-04-06 19:44:43 +0100382 bottomSheetTopPadding = mInsets.top // statusbar height
Andras Kloczl142b0542022-03-09 21:26:02 +0000383 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
384 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
Alex Chau3d2c0622022-09-01 21:28:14 +0100385 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
386 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
387 if (isTablet) {
388 bottomSheetWorkspaceScale = workspaceContentScale;
Alex Chauab800f72022-12-13 17:46:06 +0000389 if (isMultiDisplay && !ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH.get()) {
390 // TODO(b/259893832): Revert to use maxWallpaperScale to calculate bottomSheetDepth
391 // when screen recorder bug is fixed.
392 bottomSheetDepth = 1f;
393 } else {
394 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
395 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
396 // When depth is 1, wallpaper zoom is set to 1.
397 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
398 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
399 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
400 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
401 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100402 } else {
403 bottomSheetWorkspaceScale = 1f;
404 bottomSheetDepth = 0f;
405 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000406
Jon Mirandae126d722021-02-25 10:45:20 -0500407 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
Thales Limab35faed2022-09-05 16:30:01 -0300408
Thales Lima7eee74b2023-03-16 16:00:55 -0300409 if (isScalableGrid && inv.folderStyle != INVALID_RESOURCE_HANDLE) {
Thales Limab35faed2022-09-05 16:30:01 -0300410 TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
Thales Limad852d652023-01-17 14:01:13 +0000411 R.styleable.FolderStyle);
Thales Limab35faed2022-09-05 16:30:01 -0300412 // These are re-set in #updateFolderCellSize if the grid is not scalable
413 folderCellHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000414 R.styleable.FolderStyle_folderCellHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300415 folderCellWidthPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000416 R.styleable.FolderStyle_folderCellWidth, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300417
418 folderContentPaddingTop = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000419 R.styleable.FolderStyle_folderTopPadding, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300420 folderCellLayoutBorderSpacePx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000421 R.styleable.FolderStyle_folderBorderSpace, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300422 folderFooterHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000423 R.styleable.FolderStyle_folderFooterHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300424 folderStyle.recycle();
425 } else {
426 folderCellLayoutBorderSpacePx = 0;
Thales Lima7eee74b2023-03-16 16:00:55 -0300427 folderFooterHeightPx = res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Thales Limab35faed2022-09-05 16:30:01 -0300428 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
429 }
Jon Mirandae126d722021-02-25 10:45:20 -0500430
Thales Lima78d00ad2021-09-30 11:29:06 +0100431 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv);
Thales Limab35faed2022-09-05 16:30:01 -0300432 cellLayoutBorderSpaceOriginalPx = new Point(cellLayoutBorderSpacePx);
Thales Lima85c942f2021-12-31 13:04:20 +0000433 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000434 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
435 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Thales Limae9273ea2023-01-26 12:33:52 +0000436 setupAllAppsStyle(context);
Jon Mirandae126d722021-02-25 10:45:20 -0500437
Tony Wickham5edf9e22020-03-27 20:06:52 -0700438 workspacePageIndicatorHeight = res.getDimensionPixelSize(
439 R.dimen.workspace_page_indicator_height);
440 mWorkspacePageIndicatorOverlapWorkspace =
441 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700442
Thales Limad852d652023-01-17 14:01:13 +0000443 TypedArray cellStyle;
444 if (inv.cellStyle != INVALID_RESOURCE_HANDLE) {
445 cellStyle = context.obtainStyledAttributes(inv.cellStyle,
446 R.styleable.CellStyle);
447 } else {
448 cellStyle = context.obtainStyledAttributes(R.style.CellStyleDefault,
449 R.styleable.CellStyle);
450 }
451 iconDrawablePaddingOriginalPx = cellStyle.getDimensionPixelSize(
452 R.styleable.CellStyle_iconDrawablePadding, 0);
453 cellStyle.recycle();
Alex Chaua02eddc2021-04-29 00:36:06 +0100454
Sunny Goyal47328fd2016-05-25 18:56:41 -0700455 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100456 dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
457 dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100458 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
459 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100460 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
461 R.dimen.drop_target_button_drawable_horizontal_padding);
462 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
463 R.dimen.drop_target_button_drawable_vertical_padding);
464 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100465 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
466 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100467
Alex Chau906d8822022-05-23 10:42:25 +0100468 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
469 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700470
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700471 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700472
Thales Limaa1012902022-01-13 17:58:42 +0000473 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100474 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
475 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
476
Thales Lima12d0eff2022-03-25 17:06:11 +0000477 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
478 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
479 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
480 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
481 && hotseatQsbHeight > 0;
Thales Lima6a590062022-11-22 15:52:49 +0000482 isQsbInline = isScalableGrid && inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000483
Thales Lima425f6822022-05-10 13:44:58 -0300484 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100485 numShownHotseatIcons =
486 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000487
Sunny Goyal19ff7282021-04-22 10:12:54 -0700488 numShownAllAppsColumns =
489 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100490
491 int hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
492 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
493 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
494 // Have a little space between the inset and the QSB
495 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
496 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
497
498 // Only change the spaces if there is space
499 if (availableSpace > 0) {
500 // Make sure there is enough space between hotseat/QSB and QSB/navBar
501 if (availableSpace < minQsbMargin * 2) {
502 minQsbMargin = availableSpace / 2;
503 hotseatQsbSpace = minQsbMargin;
504 } else {
505 hotseatQsbSpace -= minQsbMargin;
506 }
507 }
508 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
509
Thales Limaa1012902022-01-13 17:58:42 +0000510 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100511 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
Thales Limaa1012902022-01-13 17:58:42 +0000512 }
Thales Lima425f6822022-05-10 13:44:58 -0300513
Pat Manningde25c0d2022-04-05 19:11:26 +0100514 springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
515 R.dimen.spring_loaded_hotseat_top_margin);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700516 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800517 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700518 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700519 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Thales Limab8c05952022-05-23 16:58:38 +0100520 updateHotseatSizes(pxFromDp(inv.iconSize[INDEX_DEFAULT], mMetrics));
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700521 if (areNavButtonsInline && !isPhone) {
Jon Mirandae17a9492023-03-08 16:42:20 -0800522 inlineNavButtonsEndSpacingPx =
Thales Limaffc68b02023-01-09 16:20:23 +0000523 res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing);
Pat Manning26f70f72022-07-07 13:50:39 +0100524 /*
525 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700526 * Spacing between nav buttons +
Thales Lima6a590062022-11-22 15:52:49 +0000527 * Space at the end for contextual buttons
Pat Manning26f70f72022-07-07 13:50:39 +0100528 */
529 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700530 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
Jon Mirandae17a9492023-03-08 16:42:20 -0800531 + inlineNavButtonsEndSpacingPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100532 } else {
Jon Mirandae17a9492023-03-08 16:42:20 -0800533 inlineNavButtonsEndSpacingPx = 0;
Pat Manning26f70f72022-07-07 13:50:39 +0100534 hotseatBarEndOffset = 0;
535 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700536
Alex Chau635b3ab2022-01-26 16:49:10 +0000537 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chau5fd9d492021-07-22 17:27:11 +0100538 overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100539 overviewTaskIconDrawableSizePx =
540 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
541 overviewTaskIconDrawableSizeGridPx =
542 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700543 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx;
Jeremy Sim3c2c3f12022-05-16 20:37:43 -0700544 overviewActionsTopMarginPx = res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000545 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
546 overviewActionsButtonSpacing = res.getDimensionPixelSize(
547 R.dimen.overview_actions_button_spacing);
Alex Chau19c6eca2022-03-10 20:12:56 +0000548 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700549 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000550 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700551
Jeremy Sim0ac47082022-10-10 13:59:40 -0700552 splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset);
553
Jon Miranda2ed276e2017-06-29 11:36:34 -0700554 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400555 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700556
Jon Miranda2ed276e2017-06-29 11:36:34 -0700557 // Now that we have all of the variables calculated, we can tune certain sizes.
Thales Limaae0d7ef2022-11-16 15:53:43 +0000558 if (isScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400559 // Paddings were created assuming no scaling, so we first unscale the extra space.
Jon Mirandaab3c6812021-06-28 15:42:28 -0700560 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
Thales Limaae0d7ef2022-11-16 15:53:43 +0000561 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
562 DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
Thales Lima171ee662022-11-22 15:52:49 +0000563 maxEmptySpace = padding.getMaxEmptySpacePx();
Jon Miranda228877d2021-02-09 11:05:00 -0500564
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400565 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
566 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
567 int paddingHotseatBottom = padding.getHotseatBottomPadding(unscaledExtraSpace);
568
Jon Mirandaab3c6812021-06-28 15:42:28 -0700569 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
570 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700571 }
Pat Manning08610ca2022-04-05 21:03:16 +0100572
573 int cellLayoutPadding =
574 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
575 R.dimen.cell_layout_padding);
576 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
577 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800578 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800579
Thales Lima7eee74b2023-03-16 16:00:55 -0300580 // Folder scaling requires correct workspace paddings
581 updateAvailableFolderCellDimensions(res);
582
Thales Limaffc68b02023-01-09 16:20:23 +0000583 mMinHotseatIconSpacePx = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
584 mMinHotseatQsbWidthPx = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
585 mMaxHotseatIconSpacePx = areNavButtonsInline
Thales Lima6a590062022-11-22 15:52:49 +0000586 ? res.getDimensionPixelSize(R.dimen.max_hotseat_icon_space) : Integer.MAX_VALUE;
Thales Lima425f6822022-05-10 13:44:58 -0300587 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima6a590062022-11-22 15:52:49 +0000588 recalculateHotseatWidthAndBorderSpace();
Alex Chau206ede92022-08-01 17:46:12 +0100589
590 // AllApps height calculation depends on updated cellSize
591 if (isTablet) {
592 int collapseHandleHeight =
593 res.getDimensionPixelOffset(R.dimen.bottom_sheet_handle_area_height);
594 int contentHeight = heightPx - collapseHandleHeight - hotseatQsbHeight;
595 int targetContentHeight = (int) (allAppsCellHeightPx * ALL_APPS_TABLET_MAX_ROWS);
596 allAppsTopPadding = Math.max(mInsets.top, contentHeight - targetContentHeight);
597 allAppsShiftRange = heightPx - allAppsTopPadding;
598 } else {
599 allAppsTopPadding = 0;
600 allAppsShiftRange =
601 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
602 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100603 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
604 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300605
Alex Chaua02eddc2021-04-29 00:36:06 +0100606 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
607 R.dimen.drag_flingToDeleteMinVelocity);
608
Sihua Mae04aa202022-07-18 12:43:56 -0700609 mViewScaleProvider = viewScaleProvider;
610
Jon Miranda2b25ded2023-02-02 14:48:45 -0800611 dimensionOverrideProvider.accept(this);
612
Tony Wickham1237df02017-02-24 08:59:36 -0800613 // This is done last, after iconSizePx is calculated above.
Sunny Goyal799e1202023-02-09 10:54:28 -0800614 mDotRendererWorkSpace = createDotRenderer(context, iconSizePx, dotRendererCache);
615 mDotRendererAllApps = createDotRenderer(context, allAppsIconSizePx, dotRendererCache);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700616 }
617
618 private static DotRenderer createDotRenderer(
Sunny Goyal799e1202023-02-09 10:54:28 -0800619 @NonNull Context context, int size, @NonNull SparseArray<DotRenderer> cache) {
Sunny Goyal65190ae2022-08-02 14:16:26 -0700620 DotRenderer renderer = cache.get(size);
621 if (renderer == null) {
Sunny Goyal799e1202023-02-09 10:54:28 -0800622 renderer = new DotRenderer(size, getShapePath(context, DEFAULT_DOT_SIZE),
623 DEFAULT_DOT_SIZE);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700624 cache.put(size, renderer);
625 }
626 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700627 }
628
Thales Lima425f6822022-05-10 13:44:58 -0300629 /**
630 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
631 * width of the hotseat.
632 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100633 private int calculateQsbWidth(int hotseatBorderSpace) {
Thales Lima425f6822022-05-10 13:44:58 -0300634 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100635 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300636 return getIconToIconWidthForColumns(columns)
637 - iconSizePx * numShownHotseatIcons
638 - hotseatBorderSpace * numShownHotseatIcons;
639 } else {
640 int columns = inv.hotseatColumnSpan[mTypeIndex];
641 return getIconToIconWidthForColumns(columns);
642 }
643 }
Thales Lima2903a622022-03-17 13:52:19 +0000644
Thales Lima425f6822022-05-10 13:44:58 -0300645 private int getIconToIconWidthForColumns(int columns) {
646 return columns * getCellSize().x
647 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400648 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000649 }
650
Thales Limad90faab2021-09-21 17:18:47 +0100651 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
652 if (isVerticalBarLayout()) {
653 return 0;
654 }
655
Thales Lima83bedbf2021-10-05 17:47:39 +0100656 return isScalableGrid
657 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
658 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100659 }
660
Thales Limab8c05952022-05-23 16:58:38 +0100661 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
662 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700663 // Ensure there is enough space for folder icons, which have a slightly larger radius.
664 hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR);
Thales Limab8c05952022-05-23 16:58:38 +0100665
Jon Miranda0d284852021-06-22 14:50:55 -0700666 if (isVerticalBarLayout()) {
667 hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
668 + hotseatBarSidePaddingEndPx;
Thales Limab8c05952022-05-23 16:58:38 +0100669 } else if (isQsbInline) {
670 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
671 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700672 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100673 hotseatBarSizePx = hotseatIconSizePx
674 + hotseatQsbSpace
675 + hotseatQsbVisualHeight
676 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700677 }
678 }
679
Thales Lima6a590062022-11-22 15:52:49 +0000680 /**
681 * Calculates the width of the hotseat, changing spaces between the icons and removing icons if
682 * necessary.
683 */
684 public void recalculateHotseatWidthAndBorderSpace() {
685 if (!isScalableGrid) return;
686
687 int columns = inv.hotseatColumnSpan[mTypeIndex];
688 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
689 hotseatBorderSpace = calculateHotseatBorderSpace(hotseatWidthPx, /* numExtraBorder= */ 0);
Thales Lima9938c2f2022-07-25 14:38:16 +0100690 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
Thales Lima6a590062022-11-22 15:52:49 +0000691 // Spaces should be correct when the nav buttons are not inline
Thales Lima9938c2f2022-07-25 14:38:16 +0100692 if (!areNavButtonsInline) {
693 return;
694 }
695
Thales Lima6a590062022-11-22 15:52:49 +0000696 // The side space with inline buttons should be what is defined in InvariantDeviceProfile
Jon Mirandae17a9492023-03-08 16:42:20 -0800697 int sideSpacePx = inlineNavButtonsEndSpacingPx;
Thales Limaffc68b02023-01-09 16:20:23 +0000698 int maxHotseatWidthPx = availableWidthPx - sideSpacePx - hotseatBarEndOffset;
699 int maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
700 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000701 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100702
Thales Limaffc68b02023-01-09 16:20:23 +0000703 if (hotseatBorderSpace >= mMinHotseatIconSpacePx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100704 return;
705 }
706
707 // Border space can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000708 hotseatBorderSpace = mMinHotseatIconSpacePx;
Thales Lima6a590062022-11-22 15:52:49 +0000709 int requiredWidth = getHotseatRequiredWidth();
Thales Lima9938c2f2022-07-25 14:38:16 +0100710
711 // If there is an inline qsb, change its size
712 if (isQsbInline) {
Thales Limaffc68b02023-01-09 16:20:23 +0000713 hotseatQsbWidth -= requiredWidth - maxHotseatWidthPx;
714 if (hotseatQsbWidth >= mMinHotseatQsbWidthPx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100715 return;
716 }
717
718 // QSB can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000719 hotseatQsbWidth = mMinHotseatQsbWidthPx;
Thales Lima9938c2f2022-07-25 14:38:16 +0100720 }
721
Thales Limaffc68b02023-01-09 16:20:23 +0000722 maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
Thales Lima6a590062022-11-22 15:52:49 +0000723
Thales Lima9938c2f2022-07-25 14:38:16 +0100724 // If it still doesn't fit, start removing icons
725 do {
726 numShownHotseatIcons--;
Thales Limaffc68b02023-01-09 16:20:23 +0000727 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000728 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Limaffc68b02023-01-09 16:20:23 +0000729 } while (hotseatBorderSpace < mMinHotseatIconSpacePx && numShownHotseatIcons > 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100730
Thales Lima9938c2f2022-07-25 14:38:16 +0100731 }
732
Thales Lima78d00ad2021-09-30 11:29:06 +0100733 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100734 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100735 }
736
737 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100738 if (!isScalableGrid) {
739 return new Point(0, 0);
740 }
741
Thales Lima080d8902022-03-28 15:30:29 +0100742 int horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
743 int verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
Thales Lima78d00ad2021-09-30 11:29:06 +0100744
745 return new Point(horizontalSpacePx, verticalSpacePx);
746 }
747
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700748 public Info getDisplayInfo() {
749 return mInfo;
750 }
751
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700752 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800753 WindowBounds bounds = new WindowBounds(
754 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700755 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100756 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700757
758 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
759 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
760 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
761
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700762 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700763 .setWindowBounds(bounds)
Alex Chauab800f72022-12-13 17:46:06 +0000764 .setIsMultiDisplay(isMultiDisplay)
Alex Chau6ed408f2022-03-04 12:58:05 +0000765 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700766 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000767 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800768 }
769
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700770 public DeviceProfile copy(Context context) {
771 return toBuilder(context).build();
772 }
773
774 /**
775 * TODO: Move this to the builder as part of setMultiWindowMode
776 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700777 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700778 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700779 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700780 .setMultiWindowMode(true)
781 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800782
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800783 // We use these scales to measure and layout the widgets using their full invariant profile
784 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
785 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
786 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700787 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
788 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
789 profile = profile.toBuilder(context)
790 .setViewScaleProvider(i -> p)
791 .build();
792 }
793
794 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800795
Jon Miranda93e1f042016-11-11 14:13:04 -0800796 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700797 }
798
Adam Cohen63f1ec02014-08-12 09:23:13 -0700799 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400800 * Checks if there is enough space for labels on the workspace.
801 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700802 * It is important to call this method after the All Apps variables have been set.
803 */
Jon Miranda941375e2021-03-31 13:10:45 -0400804 private void hideWorkspaceLabelsIfNotEnoughSpace() {
805 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
806 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
807 - iconTextHeight;
808
809 // We want enough space so that the text is closer to its corresponding icon.
810 if (workspaceCellPaddingY < iconTextHeight) {
811 iconTextSizePx = 0;
812 iconDrawablePaddingPx = 0;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700813 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda941375e2021-03-31 13:10:45 -0400814 autoResizeAllAppsCells();
815 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700816 }
Jon Miranda1091e532017-07-21 13:31:50 -0700817
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700818 /**
819 * Re-computes the all-apps cell size to be independent of workspace
820 */
821 public void autoResizeAllAppsCells() {
Jon Miranda941375e2021-03-31 13:10:45 -0400822 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
823 int topBottomPadding = textHeight;
Jon Miranda1091e532017-07-21 13:31:50 -0700824 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
Jon Miranda941375e2021-03-31 13:10:45 -0400825 + textHeight + (topBottomPadding * 2);
Jon Miranda1091e532017-07-21 13:31:50 -0700826 }
827
Thales Limab7ef5692022-03-10 10:32:36 +0000828 private void updateAllAppsContainerWidth(Resources res) {
Pat Manning08610ca2022-04-05 21:03:16 +0100829 int cellLayoutHorizontalPadding =
830 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
Alex Chau27b39b92022-01-14 18:02:18 +0000831 if (isTablet) {
sfufa@google.comde013292021-09-21 18:22:44 -0700832 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
Thales Limab7ef5692022-03-10 10:32:36 +0000833 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Alex Chau27b39b92022-01-14 18:02:18 +0000834 + allAppsLeftRightPadding * 2;
835 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
sfufa@google.comde013292021-09-21 18:22:44 -0700836 } else {
837 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100838 desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding;
sfufa@google.comde013292021-09-21 18:22:44 -0700839 }
840 }
841
Thales Limae9273ea2023-01-26 12:33:52 +0000842 private void setupAllAppsStyle(Context context) {
843 TypedArray allAppsStyle;
844 if (inv.allAppsStyle != INVALID_RESOURCE_HANDLE) {
845 allAppsStyle = context.obtainStyledAttributes(inv.allAppsStyle,
846 R.styleable.AllAppsStyle);
847 } else {
848 allAppsStyle = context.obtainStyledAttributes(R.style.AllAppsStyleDefault,
849 R.styleable.AllAppsStyle);
850 }
851 allAppsLeftRightPadding = allAppsStyle.getDimensionPixelSize(
852 R.styleable.AllAppsStyle_horizontalPadding, 0);
853 allAppsStyle.recycle();
854 }
855
Jon Miranda228877d2021-02-09 11:05:00 -0500856 /**
857 * Returns the amount of extra (or unused) vertical space.
858 */
859 private int updateAvailableDimensions(Resources res) {
Alex Chaua68164d2022-12-15 16:16:03 +0000860 float invIconSizeDp = inv.iconSize[mTypeIndex];
861 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
862 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
863 iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
864
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700865 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800866
Pat Manning08610ca2022-04-05 21:03:16 +0100867 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -0500868
869 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +0100870 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +0000871 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -0500872 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500873 float scaleY = maxHeight / usedHeight;
874 boolean shouldScale = scaleY < 1f;
875
876 float scaleX = 1f;
877 if (isScalableGrid) {
878 // We scale to fit the cellWidth and cellHeight in the available space.
879 // The benefit of scalable grids is that we can get consistent aspect ratios between
880 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +0100881 float usedWidth =
882 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500883 // We do not subtract padding here, as we also scale the workspace padding if needed.
884 scaleX = availableWidthPx / usedWidth;
885 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700886 }
Jon Mirandae126d722021-02-25 10:45:20 -0500887
888 if (shouldScale) {
889 float scale = Math.min(scaleX, scaleY);
890 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +0100891 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -0500892 }
893
Jon Miranda228877d2021-02-09 11:05:00 -0500894 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700895 }
896
Pat Manninga2e14992022-04-22 11:29:17 +0100897 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +0100898 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
899 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
900 }
901
Pat Manninga2e14992022-04-22 11:29:17 +0100902 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +0000903 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +0100904 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
905 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -0500906 }
907
Jon Miranda6f7e9702019-09-16 14:44:14 -0700908 /**
909 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
910 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
911 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
912 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800913 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -0700914 // Icon scale should never exceed 1, otherwise pixellation may occur.
915 iconScale = Math.min(1f, scale);
916 cellScaleToFit = scale;
917
Jon Miranda18751b62017-07-31 17:25:27 -0700918 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800919 final boolean isVerticalLayout = isVerticalBarLayout();
Jon Mirandaab3c6812021-06-28 15:42:28 -0700920 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);
Thales Lima080d8902022-03-28 15:30:29 +0100921 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500922
923 if (isScalableGrid) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100924 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
925 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +0000926
927 if (cellWidthPx < iconSizePx) {
928 // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger.
929 int numColumns = getPanelCount() * inv.numColumns;
930 int numBorders = numColumns - 1;
931 int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns;
932 if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) {
933 cellWidthPx = iconSizePx;
934 cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders;
935 } else {
936 // If it still doesn't fit, set borderSpace to 0 and distribute the space for
937 // cellWidth, and reduce iconSize.
938 cellWidthPx = (cellWidthPx * numColumns
939 + cellLayoutBorderSpacePx.x * numBorders) / numColumns;
940 iconSizePx = Math.min(iconSizePx, cellWidthPx);
941 cellLayoutBorderSpacePx.x = 0;
942 }
943 }
944
945 int cellTextAndPaddingHeight =
946 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
947 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
948 if (cellHeightPx < cellContentHeight) {
949 // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight
950 // bigger.
951 int numBorders = inv.numRows - 1;
952 int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows;
953 if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) {
954 cellHeightPx = cellContentHeight;
955 cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders;
956 } else {
Alex Chau06f36e82023-01-06 10:50:54 +0000957 // If it still doesn't fit, set borderSpace to 0 to recover space.
Alex Chaube753132022-12-09 16:46:54 +0000958 cellHeightPx = (cellHeightPx * inv.numRows
959 + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows;
Alex Chaube753132022-12-09 16:46:54 +0000960 cellLayoutBorderSpacePx.y = 0;
Alex Chau06f36e82023-01-06 10:50:54 +0000961 // Reduce iconDrawablePaddingPx to make cellContentHeight smaller.
962 int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx;
963 if (cellContentWithoutPadding <= cellHeightPx) {
964 iconDrawablePaddingPx = cellContentHeight - cellHeightPx;
965 } else {
966 // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space,
967 // then proportional reduce iconSizePx and iconTextSizePx to fit.
968 iconDrawablePaddingPx = 0;
969 float ratio = cellHeightPx / (float) cellContentWithoutPadding;
970 iconSizePx = (int) (iconSizePx * ratio);
971 iconTextSizePx = (int) (iconTextSizePx * ratio);
972 }
973 cellTextAndPaddingHeight =
974 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +0000975 }
976 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
977 }
Jon Mirandae126d722021-02-25 10:45:20 -0500978 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +0100979 desiredWorkspaceHorizontalMarginPx =
980 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -0500981 } else {
Jon Mirandae126d722021-02-25 10:45:20 -0500982 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700983 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR)
984 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -0500985 + Utilities.calculateTextHeight(iconTextSizePx);
986 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
987 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
988 && !isMultiWindowMode) {
989 // Ensures that the label is closer to its corresponding icon. This is not an issue
990 // with vertical bar layout or multi-window mode since the issue is handled
991 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
992 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
993 iconDrawablePaddingPx = cellPaddingY;
994 }
Jon Miranda846455e2017-10-02 14:58:52 -0700995 }
Jon Miranda18751b62017-07-31 17:25:27 -0700996
Sunny Goyalae190ff2020-04-14 00:19:01 +0000997 // All apps
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500998 updateAllAppsIconSize(scale, res);
Winson Chungb3800242013-10-24 11:01:54 -0700999
Thales Limab8c05952022-05-23 16:58:38 +01001000 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -07001001
Sunny Goyalbaec6ff2016-09-14 11:26:21 -07001002 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -07001003 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
1004 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Sunny Goyal6c304b12023-04-10 12:03:04 -07001005
1006 // Update widget padding:
1007 float minSpacing = pxFromDp(MIN_WIDGET_PADDING_DP, mMetrics);
1008 if (cellLayoutBorderSpacePx.x < minSpacing
1009 || cellLayoutBorderSpacePx.y < minSpacing) {
1010 widgetPadding.left = widgetPadding.right =
1011 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.x));
1012 widgetPadding.top = widgetPadding.bottom =
1013 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.y));
1014 } else {
1015 widgetPadding.setEmpty();
1016 }
Winson Chung0f785722015-04-08 10:27:49 -07001017 }
1018
Thales Lima425f6822022-05-10 13:44:58 -03001019 /**
Thales Lima6a590062022-11-22 15:52:49 +00001020 * This method calculates the space between the icons to achieve a certain width.
Thales Lima425f6822022-05-10 13:44:58 -03001021 */
Thales Lima6a590062022-11-22 15:52:49 +00001022 private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) {
Thales Lima9938c2f2022-07-25 14:38:16 +01001023 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
Thales Limaffc68b02023-01-09 16:20:23 +00001024 int hotseatBorderSpacePx =
Thales Lima6a590062022-11-22 15:52:49 +00001025 (int) (hotseatWidthPx - hotseatIconsTotalPx)
1026 / (numShownHotseatIcons - 1 + numExtraBorder);
Thales Limaffc68b02023-01-09 16:20:23 +00001027 return Math.min(hotseatBorderSpacePx, mMaxHotseatIconSpacePx);
Thales Lima425f6822022-05-10 13:44:58 -03001028 }
1029
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001030
1031 /**
1032 * Updates the iconSize for allApps* variants.
1033 */
Brian Isganitisa9a78112022-05-23 18:11:47 -07001034 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +01001035 allAppsBorderSpacePx = new Point(
1036 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
1037 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001038 // AllApps cells don't have real space between cells,
1039 // so we add the border space to the cell height
Alex Chaube753132022-12-09 16:46:54 +00001040 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics)
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001041 + allAppsBorderSpacePx.y;
1042 // but width is just the cell,
1043 // the border is added in #updateAllAppsContainerWidth
Thales Lima080d8902022-03-28 15:30:29 +01001044 if (isScalableGrid) {
Alex Chaube753132022-12-09 16:46:54 +00001045 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1046 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001047 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001048 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001049
1050 if (allAppsCellWidthPx < allAppsIconSizePx) {
1051 // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to
1052 // make allAppsCellWidth bigger.
1053 int numBorders = inv.numAllAppsColumns - 1;
1054 int extraWidthRequired =
1055 (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns;
1056 if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) {
1057 allAppsCellWidthPx = allAppsIconSizePx;
1058 allAppsBorderSpacePx.x -= extraWidthRequired / numBorders;
1059 } else {
1060 // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space
1061 // for allAppsCellWidth, and reduce allAppsIconSize.
1062 allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns
1063 + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns;
1064 allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx);
1065 allAppsBorderSpacePx.x = 0;
1066 }
1067 }
1068
1069 int cellContentHeight = allAppsIconSizePx
1070 + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y;
1071 if (allAppsCellHeightPx < cellContentHeight) {
1072 // Increase allAppsCellHeight to fit its content.
1073 allAppsCellHeightPx = cellContentHeight;
1074 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001075 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001076 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
1077 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001078 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1079 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001080 allAppsIconDrawablePaddingPx =
1081 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001082 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001083 }
1084
Thales Limab7ef5692022-03-10 10:32:36 +00001085 updateAllAppsContainerWidth(res);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001086 if (isVerticalBarLayout()) {
1087 hideWorkspaceLabelsIfNotEnoughSpace();
1088 }
1089 }
1090
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001091 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001092 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001093
Thales Lima7eee74b2023-03-16 16:00:55 -03001094 // For usability we can't have the folder use the whole width of the screen
Sunny Goyal07b69292018-01-08 14:19:34 -08001095 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -08001096
Thales Lima7eee74b2023-03-16 16:00:55 -03001097 // Check if the folder fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -05001098 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Thales Lima7eee74b2023-03-16 16:00:55 -03001099 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx)
1100 + folderFooterHeightPx
1101 + folderContentPaddingTop;
1102 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001103 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -08001104
Thales Lima7eee74b2023-03-16 16:00:55 -03001105 // Check if the folder fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -05001106 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Thales Lima7eee74b2023-03-16 16:00:55 -03001107 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx)
1108 + folderContentPaddingLeftRight * 2;
1109 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001110 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -08001111
1112 float scale = Math.min(scaleX, scaleY);
1113 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001114 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001115 }
1116 }
1117
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001118 private void updateFolderCellSize(float scale, Resources res) {
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001119 float invIconSizeDp = inv.iconSize[mTypeIndex];
Sunny Goyal35c7b192021-04-20 16:51:10 -07001120 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001121 folderChildTextSizePx = pxFromSp(inv.iconTextSize[mTypeIndex], mMetrics, scale);
Thales Lima7eee74b2023-03-16 16:00:55 -03001122 folderLabelTextSizePx = Math.max(pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale),
Thales Limab35faed2022-09-05 16:30:01 -03001123 (int) (folderChildTextSizePx * folderLabelTextScale));
Jon Mirandabf7d8122016-11-03 15:29:29 -07001124
1125 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001126
Jon Miranda823da222021-03-23 08:08:45 -04001127 if (isScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001128 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
Thales Lima7eee74b2023-03-16 16:00:55 -03001129 folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale);
1130 folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale);
1131 } else {
1132 folderCellWidthPx = roundPxValueFromFloat(folderCellWidthPx * scale);
1133 folderCellHeightPx = roundPxValueFromFloat(folderCellHeightPx * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001134 }
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001135
Thales Lima7eee74b2023-03-16 16:00:55 -03001136 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
1137 folderCellLayoutBorderSpacePx = roundPxValueFromFloat(
1138 folderCellLayoutBorderSpacePx * scale);
1139 folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale);
1140
Thales Limab35faed2022-09-05 16:30:01 -03001141 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx;
Jon Miranda823da222021-03-23 08:08:45 -04001142 } else {
1143 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1144 * scale);
1145 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1146 * scale);
1147
1148 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1149 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Lima7eee74b2023-03-16 16:00:55 -03001150 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001151 folderContentPaddingLeftRight =
1152 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1153 folderFooterHeightPx =
Thales Lima7eee74b2023-03-16 16:00:55 -03001154 roundPxValueFromFloat(
1155 res.getDimensionPixelSize(R.dimen.folder_footer_height_default)
1156 * scale);
1157
Jon Miranda823da222021-03-23 08:08:45 -04001158 }
1159
Jonathan Miranda9ad87462017-07-26 17:41:02 +00001160 folderChildDrawablePaddingPx = Math.max(0,
1161 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001162 }
1163
Winson1f064272016-07-18 17:18:02 -07001164 public void updateInsets(Rect insets) {
1165 mInsets.set(insets);
1166 }
1167
Sunny Goyalae6e3182019-04-30 12:04:37 -07001168 /**
1169 * The current device insets. This is generally same as the insets being dispatched to
1170 * {@link Insettable} elements, but can differ if the element is using a different profile.
1171 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001172 public Rect getInsets() {
1173 return mInsets;
1174 }
1175
Sunny Goyal756cd262015-08-20 12:33:21 -07001176 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001177 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001178 }
1179
Sunny Goyal19ff7282021-04-22 10:12:54 -07001180 public Point getCellSize(Point result) {
1181 if (result == null) {
1182 result = new Point();
1183 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001184
Pat Manning25d53342022-05-10 09:58:49 +00001185 int shortcutAndWidgetContainerWidth =
1186 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1187 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1188 inv.numColumns);
1189 int shortcutAndWidgetContainerHeight =
1190 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1191 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1192 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001193 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001194 }
1195
1196 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001197 * Returns the left and right space on the cell, which is the cell width - icon size
1198 */
1199 public int getCellHorizontalSpace() {
1200 return getCellSize().x - iconSizePx;
1201 }
1202
1203 /**
Pat Manning25d53342022-05-10 09:58:49 +00001204 * Gets the number of panels within the workspace.
1205 */
1206 public int getPanelCount() {
1207 return isTwoPanels ? 2 : 1;
1208 }
1209
1210 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001211 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1212 * bottom of the screen.
1213 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001214 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1215 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001216 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001217 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001218 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001219 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001220 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001221 }
1222
1223 /**
1224 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1225 */
Pat Manning25d53342022-05-10 09:58:49 +00001226 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001227 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001228 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001229 }
1230
1231 /**
1232 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1233 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001234 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001235 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001236 return heightPx - (isVerticalBarLayout()
1237 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001238 }
1239
Pat Manningea5c1d22022-04-14 10:58:16 +01001240 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001241 * Gets the scale of the workspace for the spring-loaded edit state.
1242 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001243 public float getWorkspaceSpringLoadScale(Context context) {
1244 float scale =
1245 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1246 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001247 scale = Math.min(scale, 1f);
1248
Pat Manninge63dd252022-08-02 16:15:29 +01001249 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001250 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001251 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001252 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001253 if (scaledWorkspaceWidth > maxAvailableWidth) {
1254 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1255 }
1256 return scale;
1257 }
1258
Pat Manning25d53342022-05-10 09:58:49 +00001259 /**
1260 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1261 *
1262 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1263 * layouts have two Cell Layouts per workspace.
1264 */
1265 public int getCellLayoutWidth() {
1266 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001267 }
1268
Pat Manning25d53342022-05-10 09:58:49 +00001269 /**
1270 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1271 *
1272 * <p>This is the height of a Workspace, less its vertical padding.
1273 */
1274 public int getCellLayoutHeight() {
1275 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001276 }
1277
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001278 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001279 return new Point(workspacePadding.left + workspacePadding.right,
1280 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001281 }
1282
1283 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001284 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1285 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001286 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001287 private void updateWorkspacePadding() {
1288 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001289 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -08001290 padding.top = 0;
1291 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001292 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001293 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -07001294 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -07001295 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -07001296 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001297 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -07001298 }
Winson Chungb3800242013-10-24 11:01:54 -07001299 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001300 // Pad the bottom of the workspace with hotseat bar
1301 // and leave a bit of space in case a widget go all the way down
1302 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding
1303 + workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace
1304 - mInsets.bottom;
Pat Manning08610ca2022-04-05 21:03:16 +01001305 int paddingTop = workspaceTopPadding + (isScalableGrid ? 0 : edgeMarginPx);
1306 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001307
Pat Manning08610ca2022-04-05 21:03:16 +01001308 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001309 }
Pat Manning08610ca2022-04-05 21:03:16 +01001310 insetPadding(workspacePadding, cellLayoutPaddingPx);
1311 }
1312
1313 private void insetPadding(Rect paddings, Rect insets) {
1314 insets.left = Math.min(insets.left, paddings.left);
1315 paddings.left -= insets.left;
1316
1317 insets.top = Math.min(insets.top, paddings.top);
1318 paddings.top -= insets.top;
1319
1320 insets.right = Math.min(insets.right, paddings.right);
1321 paddings.right -= insets.right;
1322
1323 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1324 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001325 }
1326
Sunny Goyal57b22792021-05-25 14:35:01 -07001327 /**
1328 * Returns the padding for hotseat view
1329 */
1330 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001331 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001332 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001333 // The hotseat icons will be placed in the middle of the hotseat cells.
1334 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1335 // in vertical bar layout.
1336 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1337 // is set to account for that difference.
1338 float diffOverlapFactor = iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
Pat Manning08610ca2022-04-05 21:03:16 +01001339 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1340 - diffOverlapFactor), 0);
1341 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001342 + diffOverlapFactor), 0);
1343
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001344 if (isSeascape()) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001345 hotseatBarPadding.set(mInsets.left + hotseatBarSidePaddingStartPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001346 hotseatBarSidePaddingEndPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001347 } else {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001348 hotseatBarPadding.set(hotseatBarSidePaddingEndPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001349 mInsets.right + hotseatBarSidePaddingStartPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001350 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001351 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001352 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001353 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1354 int hotseatBarTopPadding =
1355 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001356
Thales Lima6a590062022-11-22 15:52:49 +00001357 int hotseatWidth = getHotseatRequiredWidth();
Helen Cheuke76291f2023-02-14 17:11:05 +00001358 int startSpacing;
1359 int endSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001360 // Hotseat aligns to the left with nav buttons
1361 if (hotseatBarEndOffset > 0) {
Jon Mirandae17a9492023-03-08 16:42:20 -08001362 startSpacing = inlineNavButtonsEndSpacingPx;
Helen Cheuke76291f2023-02-14 17:11:05 +00001363 endSpacing = availableWidthPx - hotseatWidth - startSpacing + hotseatBorderSpace;
1364 } else {
1365 startSpacing = (availableWidthPx - hotseatWidth) / 2;
1366 endSpacing = startSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001367 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001368 startSpacing += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001369
Helen Cheuke76291f2023-02-14 17:11:05 +00001370 hotseatBarPadding.top = hotseatBarTopPadding;
1371 hotseatBarPadding.bottom = hotseatBarBottomPadding;
Alex Chau51da2192022-05-20 13:32:10 +01001372 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001373 if (isRtl) {
Helen Cheuke76291f2023-02-14 17:11:05 +00001374 hotseatBarPadding.left = endSpacing;
1375 hotseatBarPadding.right = startSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001376 } else {
Helen Cheuke76291f2023-02-14 17:11:05 +00001377 hotseatBarPadding.left = startSpacing;
1378 hotseatBarPadding.right = endSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001379 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001380
Thales Lima425f6822022-05-10 13:44:58 -03001381 } else if (isScalableGrid) {
Alex Chau206ede92022-08-01 17:46:12 +01001382 int sideSpacing = (availableWidthPx - hotseatQsbWidth) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001383 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001384 0,
Thales Lima425f6822022-05-10 13:44:58 -03001385 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001386 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001387 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001388 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1389 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1390 // for this, we pad the left and right of the hotseat with half of the difference of a
1391 // workspace cell vs a hotseat cell.
1392 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001393 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001394 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001395 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001396 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1397 + mInsets.left,
1398 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001399 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001400 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001401 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001402 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001403 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001404 }
1405
Thales Lima9938c2f2022-07-25 14:38:16 +01001406 private int getAdditionalQsbSpace() {
1407 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1408 }
1409
1410 /**
1411 * Calculate how much space the hotseat needs to be shown completely
1412 */
1413 private int getHotseatRequiredWidth() {
1414 int additionalQsbSpace = getAdditionalQsbSpace();
1415 return iconSizePx * numShownHotseatIcons
Thales Lima6a590062022-11-22 15:52:49 +00001416 + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1))
Thales Lima9938c2f2022-07-25 14:38:16 +01001417 + additionalQsbSpace;
1418 }
1419
Winsonfadbe8f2016-07-22 16:35:37 -07001420 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001421 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1422 */
1423 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001424 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001425 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1426 } else if (isTaskbarPresent) { // QSB on top
1427 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001428 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001429 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001430 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001431 }
1432
Thales Limab8c05952022-05-23 16:58:38 +01001433 /**
1434 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1435 */
1436 private int getHotseatBarBottomPadding() {
1437 if (isTaskbarPresent) { // QSB on top or inline
1438 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001439 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001440 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001441 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001442 }
1443
1444 /**
Alex Chau51da2192022-05-20 13:32:10 +01001445 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1446 */
1447 public int getTaskbarOffsetY() {
Jon Miranda9c478b62023-03-23 21:38:49 -07001448 int taskbarIconBottomSpace = (taskbarHeight - iconSizePx) / 2;
Alex Chau51da2192022-05-20 13:32:10 +01001449 int launcherIconBottomSpace =
1450 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001451 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001452 }
1453
1454 /**
Alex Chaua2fc7642022-04-21 14:20:23 +01001455 * Returns the number of pixels required below OverviewActions excluding insets.
1456 */
1457 public int getOverviewActionsClaimedSpaceBelow() {
Alex Chaud67ddc42022-09-30 18:15:56 +01001458 if (isTaskbarPresent) {
Jon Miranda9c478b62023-03-23 21:38:49 -07001459 return taskbarHeight + taskbarBottomMargin * 2;
Alex Chaud67ddc42022-09-30 18:15:56 +01001460 }
1461 return mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001462 }
1463
1464 /** Gets the space that the overview actions will take, including bottom margin. */
1465 public int getOverviewActionsClaimedSpace() {
Pat Manning7b8f7662023-01-18 14:48:30 +00001466 int overviewActionsSpace = isTablet && FeatureFlags.ENABLE_GRID_ONLY_OVERVIEW.get()
1467 ? 0
1468 : (overviewActionsTopMarginPx + overviewActionsHeight);
1469 return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
Alex Chaua2fc7642022-04-21 14:20:23 +01001470 }
1471
1472 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001473 * Takes the View and return the scales of width and height depending on the DeviceProfile
1474 * specifications
1475 *
1476 * @param itemInfo The tag of the widget view
1477 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1478 * height
1479 */
1480 @NonNull
1481 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1482 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1483 }
1484
1485 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001486 * @return the bounds for which the open folders should be contained within
1487 */
1488 public Rect getAbsoluteOpenFolderBounds() {
1489 if (isVerticalBarLayout()) {
1490 // Folders should only appear right of the drop target bar and left of the hotseat
1491 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1492 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001493 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001494 mInsets.top + availableHeightPx);
1495 } else {
1496 // Folders should only appear below the drop target bar and above the hotseat
Jon Miranda9c478b62023-03-23 21:38:49 -07001497 int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001498 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001499 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001500 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001501 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001502 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001503 }
1504 }
1505
Jon Miranda228877d2021-02-09 11:05:00 -05001506 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1507 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001508 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001509
Jon Miranda228877d2021-02-09 11:05:00 -05001510 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1511 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001512 }
1513
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001514 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001515 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1516 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1517 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001518 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001519 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001520 return isLandscape && transposeLayoutWithOrientation;
1521 }
1522
Sunny Goyal59d086c2018-05-07 17:31:40 -07001523 /**
1524 * Updates orientation information and returns true if it has changed from the previous value.
1525 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001526 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001527 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001528 boolean isSeascape = DisplayController.INSTANCE.get(context)
1529 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001530 if (mIsSeascape != isSeascape) {
1531 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001532 // Hotseat changing sides requires updating workspace left/right paddings
1533 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001534 return true;
1535 }
1536 }
1537 return false;
1538 }
1539
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001540 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001541 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001542 }
1543
Sunny Goyal07b69292018-01-08 14:19:34 -08001544 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001545 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001546 }
1547
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001548 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001549 switch (containerType) {
1550 case CellLayout.WORKSPACE:
1551 return cellHeightPx;
1552 case CellLayout.FOLDER:
1553 return folderCellHeightPx;
1554 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001555 // The hotseat is the only container where the cell height is going to be
1556 // different from the content within that cell.
1557 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001558 default:
1559 // ??
1560 return 0;
1561 }
1562 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001563
Jon Miranda58561d42021-03-17 10:51:54 -04001564 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001565 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001566 }
1567
Alex Chaue818bcb2022-09-02 17:27:11 +01001568 private String dpPointFToString(String name, PointF value) {
1569 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
1570 }
1571
Pat Manning5f74bfd2022-07-20 12:08:54 +01001572 /** Dumps various DeviceProfile variables to the specified writer. */
1573 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04001574 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001575 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001576
1577 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001578 writer.println(prefix + "\tisPhone:" + isPhone);
1579 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1580 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001581 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001582
1583 writer.println(prefix + "\tisLandscape:" + isLandscape);
1584 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001585 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001586
1587 writer.println(prefix + pxToDpStr("windowX", windowX));
1588 writer.println(prefix + pxToDpStr("windowY", windowY));
1589 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1590 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001591 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1592 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001593 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1594 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1595 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1596 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001597
1598 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1599
Thales Limac98b7812023-04-14 15:04:23 +01001600 writer.println(prefix + "\tisResponsiveGrid:" + mIsResponsiveGrid);
Jon Miranda58561d42021-03-17 10:51:54 -04001601 writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
1602
Thales Lima83bedbf2021-10-05 17:47:39 +01001603 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001604 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1605 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1606 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001607
Alex Chaue818bcb2022-09-02 17:27:11 +01001608 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07001609
Jon Miranda58561d42021-03-17 10:51:54 -04001610 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1611 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1612
1613 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1614 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1615
Thales Lima83bedbf2021-10-05 17:47:39 +01001616 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1617 cellLayoutBorderSpacePx.x));
1618 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1619 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001620 writer.println(
1621 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
1622 writer.println(
1623 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
1624 writer.println(
1625 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01001626 writer.println(
1627 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01001628
Jon Miranda58561d42021-03-17 10:51:54 -04001629 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1630 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1631 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1632
Helen Cheuk599109b2023-02-23 17:15:39 +00001633 writer.println(prefix + "\tinv.numFolderRows: " + inv.numFolderRows);
1634 writer.println(prefix + "\tinv.numFolderColumns: " + inv.numFolderColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001635 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1636 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1637 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1638 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1639 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1640 folderChildDrawablePaddingPx));
Thales Limab35faed2022-09-05 16:30:01 -03001641 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx",
1642 folderCellLayoutBorderSpacePx));
Thales Limaa08a4432022-08-09 09:55:17 +01001643 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
1644 folderContentPaddingLeftRight));
1645 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03001646 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001647
Alex Chaue0227552022-04-06 19:44:43 +01001648 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001649 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
1650 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
1651 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
1652 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01001653
1654 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
1655 writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001656 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
1657 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04001658 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1659 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1660 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1661 allAppsIconDrawablePaddingPx));
1662 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001663 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001664 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
1665 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001666 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau62572c02022-07-25 18:36:37 +00001667 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
Alex Chau27b39b92022-01-14 18:02:18 +00001668 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001669
1670 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03001671 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04001672 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00001673 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Jon Miranda58561d42021-03-17 10:51:54 -04001674 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
1675 hotseatBarSidePaddingStartPx));
1676 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
1677 hotseatBarSidePaddingEndPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001678 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01001679 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
1680 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01001681 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
1682 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001683 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
1684 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
1685 hotseatLayoutPadding.top));
1686 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
1687 hotseatLayoutPadding.bottom));
1688 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
1689 hotseatLayoutPadding.left));
1690 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
1691 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001692 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001693 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001694 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01001695 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001696
1697 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001698 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda9c478b62023-03-23 21:38:49 -07001699 writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight));
1700 writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight));
1701 writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin));
1702 writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001703
Thales Lima83bedbf2021-10-05 17:47:39 +01001704 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1705 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001706 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
1707 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
1708 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00001709 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001710
Jon Mirandaab3c6812021-06-28 15:42:28 -07001711 writer.println(prefix + pxToDpStr("iconScale", iconScale));
1712 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04001713 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00001714 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001715
Thales Lima171ee662022-11-22 15:52:49 +00001716 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04001717 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
1718 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00001719
1720 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00001721 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
1722 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
1723 overviewTaskIconDrawableSizePx));
1724 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
1725 overviewTaskIconDrawableSizeGridPx));
1726 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
1727 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01001728 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
1729 overviewActionsTopMarginPx));
1730 writer.println(prefix + pxToDpStr("overviewActionsHeight",
1731 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00001732 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
1733 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00001734 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
1735 overviewActionsButtonSpacing));
1736 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
1737 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
1738 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01001739
Alex Chau62572c02022-07-25 18:36:37 +00001740 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001741 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00001742 writer.println(
1743 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001744
Pat Manning5f74bfd2022-07-20 12:08:54 +01001745 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
1746 getCellLayoutSpringLoadShrunkTop()));
1747 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
1748 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01001749 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
1750 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001751 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
1752 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01001753 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
1754 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Jon Miranda58561d42021-03-17 10:51:54 -04001755 }
1756
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00001757 /** Returns a reduced representation of this DeviceProfile. */
1758 public String toSmallString() {
1759 return "isTablet:" + isTablet + ", "
1760 + "isMultiDisplay:" + isMultiDisplay + ", "
1761 + "widthPx:" + widthPx + ", "
1762 + "heightPx:" + heightPx + ", "
1763 + "insets:" + mInsets + ", "
1764 + "rotationHint:" + rotationHint;
1765 }
1766
Alex Chaua6907dc2022-03-18 15:24:07 +00001767 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07001768 Configuration config = new Configuration(c.getResources().getConfiguration());
1769 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03001770 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00001771 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07001772 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07001773 }
Sunny Goyalfde55052018-02-01 14:46:13 -08001774
1775 /**
1776 * Callback when a component changes the DeviceProfile associated with it, as a result of
1777 * configuration change
1778 */
1779 public interface OnDeviceProfileChangeListener {
1780
1781 /**
1782 * Called when the device profile is reassigned. Note that for layout and measurements, it
1783 * is sufficient to listen for inset changes. Use this callback when you need to perform
1784 * a one time operation.
1785 */
1786 void onDeviceProfileChanged(DeviceProfile dp);
1787 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001788
Sihua Mae04aa202022-07-18 12:43:56 -07001789 /**
1790 * Handler that deals with ItemInfo of the views for the DeviceProfile
1791 */
1792 @FunctionalInterface
1793 public interface ViewScaleProvider {
1794 /**
1795 * Get the scales from the view
1796 *
1797 * @param itemInfo The tag of the widget view
1798 * @return PointF instance containing the scale information, or null if using the default
1799 * app widget scale of this device profile.
1800 */
1801 @NonNull
1802 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
1803 }
1804
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001805 public static class Builder {
1806 private Context mContext;
1807 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07001808 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001809
Sunny Goyal19ff7282021-04-22 10:12:54 -07001810 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00001811 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001812
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001813 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001814 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00001815 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07001816 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001817
Sunny Goyal65190ae2022-08-02 14:16:26 -07001818 private SparseArray<DotRenderer> mDotRendererCache;
1819
Jon Miranda2b25ded2023-02-02 14:48:45 -08001820 private Consumer<DeviceProfile> mOverrideProvider;
1821
Sunny Goyalfd58da62020-08-11 12:06:49 -07001822 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001823 mContext = context;
1824 mInv = inv;
1825 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001826 }
1827
1828 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1829 mIsMultiWindowMode = isMultiWindowMode;
1830 return this;
1831 }
1832
Alex Chauab800f72022-12-13 17:46:06 +00001833 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
1834 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001835 return this;
1836 }
1837
Sunny Goyal65190ae2022-08-02 14:16:26 -07001838 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
1839 mDotRendererCache = dotRendererCache;
1840 return this;
1841 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07001842
1843 public Builder setWindowBounds(WindowBounds bounds) {
1844 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07001845 return this;
1846 }
1847
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001848 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1849 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1850 return this;
1851 }
1852
Alex Chau6ed408f2022-03-04 12:58:05 +00001853 public Builder setGestureMode(boolean isGestureMode) {
1854 mIsGestureMode = isGestureMode;
1855 return this;
1856 }
1857
Jon Miranda2b25ded2023-02-02 14:48:45 -08001858 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
1859 mOverrideProvider = overrideProvider;
1860 return this;
1861 }
1862
Sihua Mae04aa202022-07-18 12:43:56 -07001863 /**
1864 * Set the viewScaleProvider for the builder
1865 *
1866 * @param viewScaleProvider The viewScaleProvider to be set for the
Thales Limae9273ea2023-01-26 12:33:52 +00001867 * DeviceProfile
Sihua Mae04aa202022-07-18 12:43:56 -07001868 * @return This builder
1869 */
1870 @NonNull
1871 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
1872 mViewScaleProvider = viewScaleProvider;
1873 return this;
1874 }
1875
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001876 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001877 if (mWindowBounds == null) {
1878 throw new IllegalArgumentException("Window bounds not set");
1879 }
1880 if (mTransposeLayoutWithOrientation == null) {
1881 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
1882 }
Alex Chau6ed408f2022-03-04 12:58:05 +00001883 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01001884 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00001885 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001886 if (mDotRendererCache == null) {
1887 mDotRendererCache = new SparseArray<>();
1888 }
Sihua Mae04aa202022-07-18 12:43:56 -07001889 if (mViewScaleProvider == null) {
1890 mViewScaleProvider = DEFAULT_PROVIDER;
1891 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08001892 if (mOverrideProvider == null) {
1893 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
1894 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001895 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00001896 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jon Miranda2b25ded2023-02-02 14:48:45 -08001897 mIsGestureMode, mViewScaleProvider, mOverrideProvider);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001898 }
1899 }
1900
Winson Chungb3800242013-10-24 11:01:54 -07001901}