blob: 867522699f9c69c4225a8aa7656367341f5f0937 [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;
Sunny Goyalb46703d2020-05-27 17:52:03 -070058import com.android.launcher3.util.WindowBounds;
Winson1f064272016-07-18 17:18:02 -070059
Jon Miranda58561d42021-03-17 10:51:54 -040060import java.io.PrintWriter;
Alex Chaue818bcb2022-09-02 17:27:11 +010061import java.util.Locale;
Jon Miranda2b25ded2023-02-02 14:48:45 -080062import java.util.function.Consumer;
Jon Miranda58561d42021-03-17 10:51:54 -040063
Sunny Goyal35c7b192021-04-20 16:51:10 -070064@SuppressLint("NewApi")
Winson Chungb3800242013-10-24 11:01:54 -070065public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070066
Sunny Goyal8b9919d2021-04-07 14:45:17 -070067 private static final int DEFAULT_DOT_SIZE = 100;
Alex Chau206ede92022-08-01 17:46:12 +010068 private static final float ALL_APPS_TABLET_MAX_ROWS = 5.5f;
Thales Limab35faed2022-09-05 16:30:01 -030069 private static final float MIN_FOLDER_TEXT_SIZE_SP = 16f;
Sunny Goyal6c304b12023-04-10 12:03:04 -070070 private static final float MIN_WIDGET_PADDING_DP = 6f;
Alex Chau206ede92022-08-01 17:46:12 +010071
Sihua Mae04aa202022-07-18 12:43:56 -070072 public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f);
73 public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE;
Jon Miranda2b25ded2023-02-02 14:48:45 -080074 public static final Consumer<DeviceProfile> DEFAULT_DIMENSION_PROVIDER = dp -> {};
Sihua Mae04aa202022-07-18 12:43:56 -070075
Adam Cohen2e6da152015-05-06 11:42:25 -070076 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070077 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070078 private final DisplayMetrics mMetrics;
Winson Chungbe876472014-05-14 14:15:20 -070079
Sunny Goyalc6205602015-05-21 20:46:33 -070080 // Device properties
81 public final boolean isTablet;
Sunny Goyalc6205602015-05-21 20:46:33 -070082 public final boolean isPhone;
83 public final boolean transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +000084 public final boolean isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -070085 public final boolean isTwoPanels;
Thales Limaa1012902022-01-13 17:58:42 +000086 public final boolean isQsbInline;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -070087
Sunny Goyalc6205602015-05-21 20:46:33 -070088 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -070089 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -080090 public final boolean isMultiWindowMode;
Alex Chau6ed408f2022-03-04 12:58:05 +000091 public final boolean isGestureMode;
Sunny Goyald70e75a2018-02-22 10:07:32 -080092
Sunny Goyal0addbf02020-04-28 14:17:35 -070093 public final int windowX;
94 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -070095 public final int widthPx;
96 public final int heightPx;
97 public final int availableWidthPx;
98 public final int availableHeightPx;
Sunny Goyal187b16c2022-03-01 16:53:23 -080099 public final int rotationHint;
Jon Mirandabba64512019-03-27 10:54:17 -0700100
101 public final float aspectRatio;
102
Jon Mirandae126d722021-02-25 10:45:20 -0500103 public final boolean isScalableGrid;
Thales Lima83bedbf2021-10-05 17:47:39 +0100104 private final int mTypeIndex;
Jon Mirandae126d722021-02-25 10:45:20 -0500105
Tony Wickhamd6b40372015-09-23 18:37:57 -0700106 /**
107 * The maximum amount of left/right workspace padding as a percentage of the screen width.
108 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
109 * 7% of the screen width can be used as right padding.
110 */
111 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -0700112
Jon Miranda3f9bab22017-07-28 14:50:17 -0700113 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700114 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda80dda302021-07-28 14:14:59 -0700115 private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252;
116 private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700117
Sunny Goyalc6205602015-05-21 20:46:33 -0700118 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +0100119 public final int desiredWorkspaceHorizontalMarginOriginalPx;
120 public int desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100121 public int gridVisualizationPaddingX;
122 public int gridVisualizationPaddingY;
Thales Lima78d00ad2021-09-30 11:29:06 +0100123 public Point cellLayoutBorderSpaceOriginalPx;
124 public Point cellLayoutBorderSpacePx;
Pat Manning08610ca2022-04-05 21:03:16 +0100125 public Rect cellLayoutPaddingPx = new Rect();
126
Sunny Goyalc6205602015-05-21 20:46:33 -0700127 public final int edgeMarginPx;
Alex Chau0c4e11b2022-07-08 18:41:36 +0100128 public final float workspaceContentScale;
Alex Chau906d8822022-05-23 10:42:25 +0100129 public final int workspaceSpringLoadedMinNextPageVisiblePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700130
Jon Miranda58561d42021-03-17 10:51:54 -0400131 private final int extraSpace;
Thales Lima171ee662022-11-22 15:52:49 +0000132 private int maxEmptySpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500133 public int workspaceTopPadding;
134 public int workspaceBottomPadding;
135
Tony Wickham5edf9e22020-03-27 20:06:52 -0700136 // Workspace page indicator
137 public final int workspacePageIndicatorHeight;
138 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700139
Sunny Goyalc6205602015-05-21 20:46:33 -0700140 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400141 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700142 public int iconSizePx;
143 public int iconTextSizePx;
144 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700145 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -0700146
Jon Mirandaab3c6812021-06-28 15:42:28 -0700147 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800148 public int cellWidthPx;
149 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700150 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800151
Jon Mirandae126d722021-02-25 10:45:20 -0500152 public int cellYPaddingPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500153
Sunny Goyalc6205602015-05-21 20:46:33 -0700154 // Folder
Jon Mirandae126d722021-02-25 10:45:20 -0500155 public float folderLabelTextScale;
156 public int folderLabelTextSizePx;
Thales Limab35faed2022-09-05 16:30:01 -0300157 public int folderFooterHeightPx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700158 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700159 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700160
Jon Mirandae126d722021-02-25 10:45:20 -0500161 // Folder content
Thales Limab35faed2022-09-05 16:30:01 -0300162 public int folderCellLayoutBorderSpacePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500163 public int folderContentPaddingLeftRight;
164 public int folderContentPaddingTop;
165
Jon Mirandabf7d8122016-11-03 15:29:29 -0700166 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700167 public int folderCellWidthPx;
168 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700169
170 // Folder child
171 public int folderChildIconSizePx;
172 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700173 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700174
Sunny Goyalc6205602015-05-21 20:46:33 -0700175 // Hotseat
Thales Lima9938c2f2022-07-25 14:38:16 +0100176 public int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700177 public int hotseatCellHeightPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100178 public final boolean areNavButtonsInline;
Jon Miranda18751b62017-07-31 17:25:27 -0700179 // In portrait: size = height, in landscape: size = width
180 public int hotseatBarSizePx;
Thales Limab8c05952022-05-23 16:58:38 +0100181 public int hotseatBarBottomSpacePx;
Pat Manning26f70f72022-07-07 13:50:39 +0100182 public int hotseatBarEndOffset;
Thales Limab8c05952022-05-23 16:58:38 +0100183 public int hotseatQsbSpace;
Pat Manningde25c0d2022-04-05 19:11:26 +0100184 public int springLoadedHotseatBarTopMarginPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700185 // Start is the side next to the nav bar, end is the side next to the workspace
186 public final int hotseatBarSidePaddingStartPx;
187 public final int hotseatBarSidePaddingEndPx;
Alex Chau206ede92022-08-01 17:46:12 +0100188 public int hotseatQsbWidth; // only used when isQsbInline
Sunny Goyal57b22792021-05-25 14:35:01 -0700189 public final int hotseatQsbHeight;
Thales Limab8c05952022-05-23 16:58:38 +0100190 public final int hotseatQsbVisualHeight;
191 private final int hotseatQsbShadowHeight;
Thales Limadd027342022-01-07 12:54:37 +0000192 public int hotseatBorderSpace;
Thales Limaffc68b02023-01-09 16:20:23 +0000193 private final int mMinHotseatIconSpacePx;
194 private final int mMinHotseatQsbWidthPx;
195 private final int mMaxHotseatIconSpacePx;
Jon Mirandae17a9492023-03-08 16:42:20 -0800196 public final int inlineNavButtonsEndSpacingPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700197
Alex Chau3d2c0622022-09-01 21:28:14 +0100198 // Bottom sheets
199 public int bottomSheetTopPadding;
200 public int bottomSheetOpenDuration;
201 public int bottomSheetCloseDuration;
202 public float bottomSheetWorkspaceScale;
203 public float bottomSheetDepth;
204
Sunny Goyalc6205602015-05-21 20:46:33 -0700205 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000206 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000207 public int allAppsShiftRange;
208 public int allAppsTopPadding;
Alex Chau3d2c0622022-09-01 21:28:14 +0100209 public int allAppsOpenDuration;
210 public int allAppsCloseDuration;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700211 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700212 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700213 public int allAppsIconSizePx;
214 public int allAppsIconDrawablePaddingPx;
sfufa@google.comde013292021-09-21 18:22:44 -0700215 public int allAppsLeftRightPadding;
Alex Chau27b39b92022-01-14 18:02:18 +0000216 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700217 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700218 public float allAppsIconTextSizePx;
219
Zak Cohen334efeb2021-03-19 16:42:07 -0700220 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700221 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000222 public int overviewTaskIconSizePx;
Alex Chauac9df382021-08-02 19:08:41 +0100223 public int overviewTaskIconDrawableSizePx;
224 public int overviewTaskIconDrawableSizeGridPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000225 public int overviewTaskThumbnailTopMarginPx;
Alex Chau19c6eca2022-03-10 20:12:56 +0000226 public final int overviewActionsHeight;
Alex Chaua2fc7642022-04-21 14:20:23 +0100227 public final int overviewActionsTopMarginPx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000228 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100229 public int overviewPageSpacing;
230 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000231 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700232
Jeremy Sim0ac47082022-10-10 13:59:40 -0700233 // Split staging
234 public int splitPlaceholderInset;
235
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800236 // Widgets
Sihua Mae04aa202022-07-18 12:43:56 -0700237 private final ViewScaleProvider mViewScaleProvider;
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800238
Sunny Goyal47328fd2016-05-25 18:56:41 -0700239 // Drop Target
240 public int dropTargetBarSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100241 public int dropTargetBarTopMarginPx;
242 public int dropTargetBarBottomMarginPx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100243 public int dropTargetDragPaddingPx;
244 public int dropTargetTextSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100245 public int dropTargetHorizontalPaddingPx;
246 public int dropTargetVerticalPaddingPx;
247 public int dropTargetGapPx;
Alex Chau5b019302022-05-23 10:42:25 +0100248 public int dropTargetButtonWorkspaceEdgeGapPx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700249
Winson1f064272016-07-18 17:18:02 -0700250 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800251 private final Rect mInsets = new Rect();
252 public final Rect workspacePadding = new Rect();
Sunny Goyal6c304b12023-04-10 12:03:04 -0700253 // Additional padding added to the widget inside its cellSpace. It is applied outside
254 // the widgetView, such that the actual view size is same as the widget size.
255 public final Rect widgetPadding = new Rect();
256
Jon Miranda0bd63d12019-03-06 17:29:29 -0800257 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700258 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700259
Tony Wickhamf34bee82018-12-03 18:11:39 -0800260 // Notification dots
Sunny Goyal65190ae2022-08-02 14:16:26 -0700261 public final DotRenderer mDotRendererWorkSpace;
262 public final DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800263
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100264 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800265 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000266 // Whether Taskbar will inset the bottom of apps by taskbarSize.
267 public boolean isTaskbarPresentInApps;
Jon Miranda9c478b62023-03-23 21:38:49 -0700268 public final int taskbarHeight;
269 public final int stashedTaskbarHeight;
270 public final int taskbarBottomMargin;
271 public final int taskbarIconSize;
Jon Miranda04f05102023-04-04 12:16:31 -0700272 // If true, used to layout taskbar in 3 button navigation mode.
273 public final boolean startAlignTaskbar;
Tony Wickham15883892021-02-12 11:24:40 -0800274
Alex Chaua02eddc2021-04-29 00:36:06 +0100275 // DragController
276 public int flingToDeleteThresholdVelocity;
277
Vinit Nayak17c4b332021-08-05 12:54:58 -0700278 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700279 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal65190ae2022-08-02 14:16:26 -0700280 SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
Alex Chauab800f72022-12-13 17:46:06 +0000281 boolean transposeLayoutWithOrientation, boolean isMultiDisplay, boolean isGestureMode,
Jon Miranda2b25ded2023-02-02 14:48:45 -0800282 @NonNull final ViewScaleProvider viewScaleProvider,
283 @NonNull final Consumer<DeviceProfile> dimensionOverrideProvider) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700284
Adam Cohen2e6da152015-05-06 11:42:25 -0700285 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700286 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800287 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500288 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +0000289 this.isMultiDisplay = isMultiDisplay;
Alex Chau6ed408f2022-03-04 12:58:05 +0000290 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700291 windowX = windowBounds.bounds.left;
292 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800293 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100294 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700295
Jon Mirandae126d722021-02-25 10:45:20 -0500296 isScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000297 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700298 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000299 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700300 isPhone = !isTablet;
Alex Chauab800f72022-12-13 17:46:06 +0000301 isTwoPanels = isTablet && isMultiDisplay;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800302 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700303
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000304 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000305 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700306 ? Configuration.ORIENTATION_LANDSCAPE
307 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000308 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700309 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000310 mMetrics = res.getDisplayMetrics();
311
312 // Determine sizes.
313 widthPx = windowBounds.bounds.width();
314 heightPx = windowBounds.bounds.height();
315 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100316 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000317
318 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Thales Lima83bedbf2021-10-05 17:47:39 +0100319 if (isTwoPanels) {
320 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000321 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100322 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000323 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100324 }
325 } else {
326 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000327 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100328 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000329 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100330 }
331 }
332
Jon Miranda9c478b62023-03-23 21:38:49 -0700333 if (DisplayController.isTransientTaskbar(context)) {
334 float invTransientIconSizeDp = inv.transientTaskbarIconSize[mTypeIndex];
335 taskbarIconSize = pxFromDp(invTransientIconSizeDp, mMetrics);
336 taskbarHeight = taskbarIconSize
337 + (2 * res.getDimensionPixelSize(R.dimen.transient_taskbar_padding));
338 stashedTaskbarHeight =
339 res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_height);
340 taskbarBottomMargin =
341 res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin);
Jon Miranda04f05102023-04-04 12:16:31 -0700342 startAlignTaskbar = false;
Jon Miranda9c478b62023-03-23 21:38:49 -0700343 } else {
344 taskbarIconSize = pxFromDp(ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size),
345 mMetrics);
346 taskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_size);
347 stashedTaskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
348 taskbarBottomMargin = 0;
Jon Miranda04f05102023-04-04 12:16:31 -0700349 startAlignTaskbar = inv.startAlignTaskbar[mTypeIndex];
Tony Wickham15883892021-02-12 11:24:40 -0800350 }
Tony Wickham15883892021-02-12 11:24:40 -0800351
Winson Chungb3800242013-10-24 11:01:54 -0700352 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100353 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700354
Thales Limad90faab2021-09-21 17:18:47 +0100355 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
356 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100357 gridVisualizationPaddingX = res.getDimensionPixelSize(
358 R.dimen.grid_visualization_horizontal_cell_spacing);
359 gridVisualizationPaddingY = res.getDimensionPixelSize(
360 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500361
Alex Chaue0227552022-04-06 19:44:43 +0100362 bottomSheetTopPadding = mInsets.top // statusbar height
Andras Kloczl142b0542022-03-09 21:26:02 +0000363 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
364 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
Alex Chau3d2c0622022-09-01 21:28:14 +0100365 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
366 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
367 if (isTablet) {
368 bottomSheetWorkspaceScale = workspaceContentScale;
Alex Chauab800f72022-12-13 17:46:06 +0000369 if (isMultiDisplay && !ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH.get()) {
370 // TODO(b/259893832): Revert to use maxWallpaperScale to calculate bottomSheetDepth
371 // when screen recorder bug is fixed.
372 bottomSheetDepth = 1f;
373 } else {
374 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
375 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
376 // When depth is 1, wallpaper zoom is set to 1.
377 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
378 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
379 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
380 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
381 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100382 } else {
383 bottomSheetWorkspaceScale = 1f;
384 bottomSheetDepth = 0f;
385 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000386
Jon Mirandae126d722021-02-25 10:45:20 -0500387 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
Thales Limab35faed2022-09-05 16:30:01 -0300388
Thales Lima7eee74b2023-03-16 16:00:55 -0300389 if (isScalableGrid && inv.folderStyle != INVALID_RESOURCE_HANDLE) {
Thales Limab35faed2022-09-05 16:30:01 -0300390 TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
Thales Limad852d652023-01-17 14:01:13 +0000391 R.styleable.FolderStyle);
Thales Limab35faed2022-09-05 16:30:01 -0300392 // These are re-set in #updateFolderCellSize if the grid is not scalable
393 folderCellHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000394 R.styleable.FolderStyle_folderCellHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300395 folderCellWidthPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000396 R.styleable.FolderStyle_folderCellWidth, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300397
398 folderContentPaddingTop = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000399 R.styleable.FolderStyle_folderTopPadding, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300400 folderCellLayoutBorderSpacePx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000401 R.styleable.FolderStyle_folderBorderSpace, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300402 folderFooterHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000403 R.styleable.FolderStyle_folderFooterHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300404 folderStyle.recycle();
405 } else {
406 folderCellLayoutBorderSpacePx = 0;
Thales Lima7eee74b2023-03-16 16:00:55 -0300407 folderFooterHeightPx = res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Thales Limab35faed2022-09-05 16:30:01 -0300408 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
409 }
Jon Mirandae126d722021-02-25 10:45:20 -0500410
Thales Lima78d00ad2021-09-30 11:29:06 +0100411 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv);
Thales Limab35faed2022-09-05 16:30:01 -0300412 cellLayoutBorderSpaceOriginalPx = new Point(cellLayoutBorderSpacePx);
Thales Lima85c942f2021-12-31 13:04:20 +0000413 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000414 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
415 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Thales Limae9273ea2023-01-26 12:33:52 +0000416 setupAllAppsStyle(context);
Jon Mirandae126d722021-02-25 10:45:20 -0500417
Tony Wickham5edf9e22020-03-27 20:06:52 -0700418 workspacePageIndicatorHeight = res.getDimensionPixelSize(
419 R.dimen.workspace_page_indicator_height);
420 mWorkspacePageIndicatorOverlapWorkspace =
421 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700422
Thales Limad852d652023-01-17 14:01:13 +0000423 TypedArray cellStyle;
424 if (inv.cellStyle != INVALID_RESOURCE_HANDLE) {
425 cellStyle = context.obtainStyledAttributes(inv.cellStyle,
426 R.styleable.CellStyle);
427 } else {
428 cellStyle = context.obtainStyledAttributes(R.style.CellStyleDefault,
429 R.styleable.CellStyle);
430 }
431 iconDrawablePaddingOriginalPx = cellStyle.getDimensionPixelSize(
432 R.styleable.CellStyle_iconDrawablePadding, 0);
433 cellStyle.recycle();
Alex Chaua02eddc2021-04-29 00:36:06 +0100434
Sunny Goyal47328fd2016-05-25 18:56:41 -0700435 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100436 dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
437 dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100438 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
439 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100440 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
441 R.dimen.drop_target_button_drawable_horizontal_padding);
442 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
443 R.dimen.drop_target_button_drawable_vertical_padding);
444 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100445 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
446 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100447
Alex Chau906d8822022-05-23 10:42:25 +0100448 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
449 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700450
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700451 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700452
Thales Limaa1012902022-01-13 17:58:42 +0000453 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100454 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
455 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
456
Thales Lima12d0eff2022-03-25 17:06:11 +0000457 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
458 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
459 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
460 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
461 && hotseatQsbHeight > 0;
Thales Lima6a590062022-11-22 15:52:49 +0000462 isQsbInline = isScalableGrid && inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000463
Thales Lima425f6822022-05-10 13:44:58 -0300464 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100465 numShownHotseatIcons =
466 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000467
Sunny Goyal19ff7282021-04-22 10:12:54 -0700468 numShownAllAppsColumns =
469 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100470
471 int hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
472 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
473 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
474 // Have a little space between the inset and the QSB
475 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
476 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
477
478 // Only change the spaces if there is space
479 if (availableSpace > 0) {
480 // Make sure there is enough space between hotseat/QSB and QSB/navBar
481 if (availableSpace < minQsbMargin * 2) {
482 minQsbMargin = availableSpace / 2;
483 hotseatQsbSpace = minQsbMargin;
484 } else {
485 hotseatQsbSpace -= minQsbMargin;
486 }
487 }
488 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
489
Thales Limaa1012902022-01-13 17:58:42 +0000490 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100491 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
Thales Limaa1012902022-01-13 17:58:42 +0000492 }
Thales Lima425f6822022-05-10 13:44:58 -0300493
Pat Manningde25c0d2022-04-05 19:11:26 +0100494 springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
495 R.dimen.spring_loaded_hotseat_top_margin);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700496 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800497 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700498 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700499 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Thales Limab8c05952022-05-23 16:58:38 +0100500 updateHotseatSizes(pxFromDp(inv.iconSize[INDEX_DEFAULT], mMetrics));
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700501 if (areNavButtonsInline && !isPhone) {
Jon Mirandae17a9492023-03-08 16:42:20 -0800502 inlineNavButtonsEndSpacingPx =
Thales Limaffc68b02023-01-09 16:20:23 +0000503 res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing);
Pat Manning26f70f72022-07-07 13:50:39 +0100504 /*
505 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700506 * Spacing between nav buttons +
Thales Lima6a590062022-11-22 15:52:49 +0000507 * Space at the end for contextual buttons
Pat Manning26f70f72022-07-07 13:50:39 +0100508 */
509 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700510 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
Jon Mirandae17a9492023-03-08 16:42:20 -0800511 + inlineNavButtonsEndSpacingPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100512 } else {
Jon Mirandae17a9492023-03-08 16:42:20 -0800513 inlineNavButtonsEndSpacingPx = 0;
Pat Manning26f70f72022-07-07 13:50:39 +0100514 hotseatBarEndOffset = 0;
515 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700516
Alex Chau635b3ab2022-01-26 16:49:10 +0000517 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chau5fd9d492021-07-22 17:27:11 +0100518 overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100519 overviewTaskIconDrawableSizePx =
520 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
521 overviewTaskIconDrawableSizeGridPx =
522 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700523 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx;
Jeremy Sim3c2c3f12022-05-16 20:37:43 -0700524 overviewActionsTopMarginPx = res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000525 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
526 overviewActionsButtonSpacing = res.getDimensionPixelSize(
527 R.dimen.overview_actions_button_spacing);
Alex Chau19c6eca2022-03-10 20:12:56 +0000528 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700529 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000530 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700531
Jeremy Sim0ac47082022-10-10 13:59:40 -0700532 splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset);
533
Jon Miranda2ed276e2017-06-29 11:36:34 -0700534 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400535 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700536
Jon Miranda2ed276e2017-06-29 11:36:34 -0700537 // Now that we have all of the variables calculated, we can tune certain sizes.
Thales Limaae0d7ef2022-11-16 15:53:43 +0000538 if (isScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400539 // Paddings were created assuming no scaling, so we first unscale the extra space.
Jon Mirandaab3c6812021-06-28 15:42:28 -0700540 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
Thales Limaae0d7ef2022-11-16 15:53:43 +0000541 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
542 DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
Thales Lima171ee662022-11-22 15:52:49 +0000543 maxEmptySpace = padding.getMaxEmptySpacePx();
Jon Miranda228877d2021-02-09 11:05:00 -0500544
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400545 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
546 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
547 int paddingHotseatBottom = padding.getHotseatBottomPadding(unscaledExtraSpace);
548
Jon Mirandaab3c6812021-06-28 15:42:28 -0700549 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
550 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700551 }
Pat Manning08610ca2022-04-05 21:03:16 +0100552
553 int cellLayoutPadding =
554 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
555 R.dimen.cell_layout_padding);
556 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
557 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800558 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800559
Thales Lima7eee74b2023-03-16 16:00:55 -0300560 // Folder scaling requires correct workspace paddings
561 updateAvailableFolderCellDimensions(res);
562
Thales Limaffc68b02023-01-09 16:20:23 +0000563 mMinHotseatIconSpacePx = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
564 mMinHotseatQsbWidthPx = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
565 mMaxHotseatIconSpacePx = areNavButtonsInline
Thales Lima6a590062022-11-22 15:52:49 +0000566 ? res.getDimensionPixelSize(R.dimen.max_hotseat_icon_space) : Integer.MAX_VALUE;
Thales Lima425f6822022-05-10 13:44:58 -0300567 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima6a590062022-11-22 15:52:49 +0000568 recalculateHotseatWidthAndBorderSpace();
Alex Chau206ede92022-08-01 17:46:12 +0100569
570 // AllApps height calculation depends on updated cellSize
571 if (isTablet) {
572 int collapseHandleHeight =
573 res.getDimensionPixelOffset(R.dimen.bottom_sheet_handle_area_height);
574 int contentHeight = heightPx - collapseHandleHeight - hotseatQsbHeight;
575 int targetContentHeight = (int) (allAppsCellHeightPx * ALL_APPS_TABLET_MAX_ROWS);
576 allAppsTopPadding = Math.max(mInsets.top, contentHeight - targetContentHeight);
577 allAppsShiftRange = heightPx - allAppsTopPadding;
578 } else {
579 allAppsTopPadding = 0;
580 allAppsShiftRange =
581 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
582 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100583 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
584 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300585
Alex Chaua02eddc2021-04-29 00:36:06 +0100586 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
587 R.dimen.drag_flingToDeleteMinVelocity);
588
Sihua Mae04aa202022-07-18 12:43:56 -0700589 mViewScaleProvider = viewScaleProvider;
590
Jon Miranda2b25ded2023-02-02 14:48:45 -0800591 dimensionOverrideProvider.accept(this);
592
Tony Wickham1237df02017-02-24 08:59:36 -0800593 // This is done last, after iconSizePx is calculated above.
Sunny Goyal799e1202023-02-09 10:54:28 -0800594 mDotRendererWorkSpace = createDotRenderer(context, iconSizePx, dotRendererCache);
595 mDotRendererAllApps = createDotRenderer(context, allAppsIconSizePx, dotRendererCache);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700596 }
597
598 private static DotRenderer createDotRenderer(
Sunny Goyal799e1202023-02-09 10:54:28 -0800599 @NonNull Context context, int size, @NonNull SparseArray<DotRenderer> cache) {
Sunny Goyal65190ae2022-08-02 14:16:26 -0700600 DotRenderer renderer = cache.get(size);
601 if (renderer == null) {
Sunny Goyal799e1202023-02-09 10:54:28 -0800602 renderer = new DotRenderer(size, getShapePath(context, DEFAULT_DOT_SIZE),
603 DEFAULT_DOT_SIZE);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700604 cache.put(size, renderer);
605 }
606 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700607 }
608
Thales Lima425f6822022-05-10 13:44:58 -0300609 /**
610 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
611 * width of the hotseat.
612 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100613 private int calculateQsbWidth(int hotseatBorderSpace) {
Thales Lima425f6822022-05-10 13:44:58 -0300614 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100615 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300616 return getIconToIconWidthForColumns(columns)
617 - iconSizePx * numShownHotseatIcons
618 - hotseatBorderSpace * numShownHotseatIcons;
619 } else {
620 int columns = inv.hotseatColumnSpan[mTypeIndex];
621 return getIconToIconWidthForColumns(columns);
622 }
623 }
Thales Lima2903a622022-03-17 13:52:19 +0000624
Thales Lima425f6822022-05-10 13:44:58 -0300625 private int getIconToIconWidthForColumns(int columns) {
626 return columns * getCellSize().x
627 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400628 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000629 }
630
Thales Limad90faab2021-09-21 17:18:47 +0100631 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
632 if (isVerticalBarLayout()) {
633 return 0;
634 }
635
Thales Lima83bedbf2021-10-05 17:47:39 +0100636 return isScalableGrid
637 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
638 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100639 }
640
Thales Limab8c05952022-05-23 16:58:38 +0100641 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
642 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700643 // Ensure there is enough space for folder icons, which have a slightly larger radius.
644 hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR);
Thales Limab8c05952022-05-23 16:58:38 +0100645
Jon Miranda0d284852021-06-22 14:50:55 -0700646 if (isVerticalBarLayout()) {
647 hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
648 + hotseatBarSidePaddingEndPx;
Thales Limab8c05952022-05-23 16:58:38 +0100649 } else if (isQsbInline) {
650 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
651 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700652 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100653 hotseatBarSizePx = hotseatIconSizePx
654 + hotseatQsbSpace
655 + hotseatQsbVisualHeight
656 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700657 }
658 }
659
Thales Lima6a590062022-11-22 15:52:49 +0000660 /**
661 * Calculates the width of the hotseat, changing spaces between the icons and removing icons if
662 * necessary.
663 */
664 public void recalculateHotseatWidthAndBorderSpace() {
665 if (!isScalableGrid) return;
666
667 int columns = inv.hotseatColumnSpan[mTypeIndex];
668 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
669 hotseatBorderSpace = calculateHotseatBorderSpace(hotseatWidthPx, /* numExtraBorder= */ 0);
Thales Lima9938c2f2022-07-25 14:38:16 +0100670 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
Thales Lima6a590062022-11-22 15:52:49 +0000671 // Spaces should be correct when the nav buttons are not inline
Thales Lima9938c2f2022-07-25 14:38:16 +0100672 if (!areNavButtonsInline) {
673 return;
674 }
675
Thales Lima6a590062022-11-22 15:52:49 +0000676 // The side space with inline buttons should be what is defined in InvariantDeviceProfile
Jon Mirandae17a9492023-03-08 16:42:20 -0800677 int sideSpacePx = inlineNavButtonsEndSpacingPx;
Thales Limaffc68b02023-01-09 16:20:23 +0000678 int maxHotseatWidthPx = availableWidthPx - sideSpacePx - hotseatBarEndOffset;
679 int maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
680 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000681 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100682
Thales Limaffc68b02023-01-09 16:20:23 +0000683 if (hotseatBorderSpace >= mMinHotseatIconSpacePx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100684 return;
685 }
686
687 // Border space can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000688 hotseatBorderSpace = mMinHotseatIconSpacePx;
Thales Lima6a590062022-11-22 15:52:49 +0000689 int requiredWidth = getHotseatRequiredWidth();
Thales Lima9938c2f2022-07-25 14:38:16 +0100690
691 // If there is an inline qsb, change its size
692 if (isQsbInline) {
Thales Limaffc68b02023-01-09 16:20:23 +0000693 hotseatQsbWidth -= requiredWidth - maxHotseatWidthPx;
694 if (hotseatQsbWidth >= mMinHotseatQsbWidthPx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100695 return;
696 }
697
698 // QSB can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000699 hotseatQsbWidth = mMinHotseatQsbWidthPx;
Thales Lima9938c2f2022-07-25 14:38:16 +0100700 }
701
Thales Limaffc68b02023-01-09 16:20:23 +0000702 maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
Thales Lima6a590062022-11-22 15:52:49 +0000703
Thales Lima9938c2f2022-07-25 14:38:16 +0100704 // If it still doesn't fit, start removing icons
705 do {
706 numShownHotseatIcons--;
Thales Limaffc68b02023-01-09 16:20:23 +0000707 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000708 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Limaffc68b02023-01-09 16:20:23 +0000709 } while (hotseatBorderSpace < mMinHotseatIconSpacePx && numShownHotseatIcons > 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100710
Thales Lima9938c2f2022-07-25 14:38:16 +0100711 }
712
Thales Lima78d00ad2021-09-30 11:29:06 +0100713 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100714 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100715 }
716
717 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100718 if (!isScalableGrid) {
719 return new Point(0, 0);
720 }
721
Thales Lima080d8902022-03-28 15:30:29 +0100722 int horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
723 int verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
Thales Lima78d00ad2021-09-30 11:29:06 +0100724
725 return new Point(horizontalSpacePx, verticalSpacePx);
726 }
727
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700728 public Info getDisplayInfo() {
729 return mInfo;
730 }
731
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700732 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800733 WindowBounds bounds = new WindowBounds(
734 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700735 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100736 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700737
738 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
739 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
740 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
741
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700742 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700743 .setWindowBounds(bounds)
Alex Chauab800f72022-12-13 17:46:06 +0000744 .setIsMultiDisplay(isMultiDisplay)
Alex Chau6ed408f2022-03-04 12:58:05 +0000745 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700746 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000747 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800748 }
749
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700750 public DeviceProfile copy(Context context) {
751 return toBuilder(context).build();
752 }
753
754 /**
755 * TODO: Move this to the builder as part of setMultiWindowMode
756 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700757 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700758 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700759 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700760 .setMultiWindowMode(true)
761 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800762
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800763 // We use these scales to measure and layout the widgets using their full invariant profile
764 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
765 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
766 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700767 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
768 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
769 profile = profile.toBuilder(context)
770 .setViewScaleProvider(i -> p)
771 .build();
772 }
773
774 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800775
Jon Miranda93e1f042016-11-11 14:13:04 -0800776 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700777 }
778
Adam Cohen63f1ec02014-08-12 09:23:13 -0700779 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400780 * Checks if there is enough space for labels on the workspace.
781 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700782 * It is important to call this method after the All Apps variables have been set.
783 */
Jon Miranda941375e2021-03-31 13:10:45 -0400784 private void hideWorkspaceLabelsIfNotEnoughSpace() {
785 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
786 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
787 - iconTextHeight;
788
789 // We want enough space so that the text is closer to its corresponding icon.
790 if (workspaceCellPaddingY < iconTextHeight) {
791 iconTextSizePx = 0;
792 iconDrawablePaddingPx = 0;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700793 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda941375e2021-03-31 13:10:45 -0400794 autoResizeAllAppsCells();
795 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700796 }
Jon Miranda1091e532017-07-21 13:31:50 -0700797
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700798 /**
799 * Re-computes the all-apps cell size to be independent of workspace
800 */
801 public void autoResizeAllAppsCells() {
Jon Miranda941375e2021-03-31 13:10:45 -0400802 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
803 int topBottomPadding = textHeight;
Jon Miranda1091e532017-07-21 13:31:50 -0700804 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
Jon Miranda941375e2021-03-31 13:10:45 -0400805 + textHeight + (topBottomPadding * 2);
Jon Miranda1091e532017-07-21 13:31:50 -0700806 }
807
Thales Limab7ef5692022-03-10 10:32:36 +0000808 private void updateAllAppsContainerWidth(Resources res) {
Pat Manning08610ca2022-04-05 21:03:16 +0100809 int cellLayoutHorizontalPadding =
810 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
Alex Chau27b39b92022-01-14 18:02:18 +0000811 if (isTablet) {
sfufa@google.comde013292021-09-21 18:22:44 -0700812 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
Thales Limab7ef5692022-03-10 10:32:36 +0000813 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Alex Chau27b39b92022-01-14 18:02:18 +0000814 + allAppsLeftRightPadding * 2;
815 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
sfufa@google.comde013292021-09-21 18:22:44 -0700816 } else {
817 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100818 desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding;
sfufa@google.comde013292021-09-21 18:22:44 -0700819 }
820 }
821
Thales Limae9273ea2023-01-26 12:33:52 +0000822 private void setupAllAppsStyle(Context context) {
823 TypedArray allAppsStyle;
824 if (inv.allAppsStyle != INVALID_RESOURCE_HANDLE) {
825 allAppsStyle = context.obtainStyledAttributes(inv.allAppsStyle,
826 R.styleable.AllAppsStyle);
827 } else {
828 allAppsStyle = context.obtainStyledAttributes(R.style.AllAppsStyleDefault,
829 R.styleable.AllAppsStyle);
830 }
831 allAppsLeftRightPadding = allAppsStyle.getDimensionPixelSize(
832 R.styleable.AllAppsStyle_horizontalPadding, 0);
833 allAppsStyle.recycle();
834 }
835
Jon Miranda228877d2021-02-09 11:05:00 -0500836 /**
837 * Returns the amount of extra (or unused) vertical space.
838 */
839 private int updateAvailableDimensions(Resources res) {
Alex Chaua68164d2022-12-15 16:16:03 +0000840 float invIconSizeDp = inv.iconSize[mTypeIndex];
841 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
842 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
843 iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
844
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700845 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800846
Pat Manning08610ca2022-04-05 21:03:16 +0100847 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -0500848
849 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +0100850 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +0000851 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -0500852 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500853 float scaleY = maxHeight / usedHeight;
854 boolean shouldScale = scaleY < 1f;
855
856 float scaleX = 1f;
857 if (isScalableGrid) {
858 // We scale to fit the cellWidth and cellHeight in the available space.
859 // The benefit of scalable grids is that we can get consistent aspect ratios between
860 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +0100861 float usedWidth =
862 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500863 // We do not subtract padding here, as we also scale the workspace padding if needed.
864 scaleX = availableWidthPx / usedWidth;
865 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700866 }
Jon Mirandae126d722021-02-25 10:45:20 -0500867
868 if (shouldScale) {
869 float scale = Math.min(scaleX, scaleY);
870 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +0100871 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -0500872 }
873
Jon Miranda228877d2021-02-09 11:05:00 -0500874 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700875 }
876
Pat Manninga2e14992022-04-22 11:29:17 +0100877 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +0100878 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
879 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
880 }
881
Pat Manninga2e14992022-04-22 11:29:17 +0100882 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +0000883 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +0100884 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
885 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -0500886 }
887
Jon Miranda6f7e9702019-09-16 14:44:14 -0700888 /**
889 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
890 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
891 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
892 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800893 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -0700894 // Icon scale should never exceed 1, otherwise pixellation may occur.
895 iconScale = Math.min(1f, scale);
896 cellScaleToFit = scale;
897
Jon Miranda18751b62017-07-31 17:25:27 -0700898 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800899 final boolean isVerticalLayout = isVerticalBarLayout();
Jon Mirandaab3c6812021-06-28 15:42:28 -0700900 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);
Thales Lima080d8902022-03-28 15:30:29 +0100901 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500902
903 if (isScalableGrid) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100904 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
905 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +0000906
907 if (cellWidthPx < iconSizePx) {
908 // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger.
909 int numColumns = getPanelCount() * inv.numColumns;
910 int numBorders = numColumns - 1;
911 int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns;
912 if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) {
913 cellWidthPx = iconSizePx;
914 cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders;
915 } else {
916 // If it still doesn't fit, set borderSpace to 0 and distribute the space for
917 // cellWidth, and reduce iconSize.
918 cellWidthPx = (cellWidthPx * numColumns
919 + cellLayoutBorderSpacePx.x * numBorders) / numColumns;
920 iconSizePx = Math.min(iconSizePx, cellWidthPx);
921 cellLayoutBorderSpacePx.x = 0;
922 }
923 }
924
925 int cellTextAndPaddingHeight =
926 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
927 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
928 if (cellHeightPx < cellContentHeight) {
929 // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight
930 // bigger.
931 int numBorders = inv.numRows - 1;
932 int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows;
933 if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) {
934 cellHeightPx = cellContentHeight;
935 cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders;
936 } else {
Alex Chau06f36e82023-01-06 10:50:54 +0000937 // If it still doesn't fit, set borderSpace to 0 to recover space.
Alex Chaube753132022-12-09 16:46:54 +0000938 cellHeightPx = (cellHeightPx * inv.numRows
939 + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows;
Alex Chaube753132022-12-09 16:46:54 +0000940 cellLayoutBorderSpacePx.y = 0;
Alex Chau06f36e82023-01-06 10:50:54 +0000941 // Reduce iconDrawablePaddingPx to make cellContentHeight smaller.
942 int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx;
943 if (cellContentWithoutPadding <= cellHeightPx) {
944 iconDrawablePaddingPx = cellContentHeight - cellHeightPx;
945 } else {
946 // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space,
947 // then proportional reduce iconSizePx and iconTextSizePx to fit.
948 iconDrawablePaddingPx = 0;
949 float ratio = cellHeightPx / (float) cellContentWithoutPadding;
950 iconSizePx = (int) (iconSizePx * ratio);
951 iconTextSizePx = (int) (iconTextSizePx * ratio);
952 }
953 cellTextAndPaddingHeight =
954 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +0000955 }
956 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
957 }
Jon Mirandae126d722021-02-25 10:45:20 -0500958 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +0100959 desiredWorkspaceHorizontalMarginPx =
960 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -0500961 } else {
Jon Mirandae126d722021-02-25 10:45:20 -0500962 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700963 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR)
964 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -0500965 + Utilities.calculateTextHeight(iconTextSizePx);
966 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
967 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
968 && !isMultiWindowMode) {
969 // Ensures that the label is closer to its corresponding icon. This is not an issue
970 // with vertical bar layout or multi-window mode since the issue is handled
971 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
972 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
973 iconDrawablePaddingPx = cellPaddingY;
974 }
Jon Miranda846455e2017-10-02 14:58:52 -0700975 }
Jon Miranda18751b62017-07-31 17:25:27 -0700976
Sunny Goyalae190ff2020-04-14 00:19:01 +0000977 // All apps
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500978 updateAllAppsIconSize(scale, res);
Winson Chungb3800242013-10-24 11:01:54 -0700979
Thales Limab8c05952022-05-23 16:58:38 +0100980 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700981
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700982 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -0700983 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
984 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Sunny Goyal6c304b12023-04-10 12:03:04 -0700985
986 // Update widget padding:
987 float minSpacing = pxFromDp(MIN_WIDGET_PADDING_DP, mMetrics);
988 if (cellLayoutBorderSpacePx.x < minSpacing
989 || cellLayoutBorderSpacePx.y < minSpacing) {
990 widgetPadding.left = widgetPadding.right =
991 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.x));
992 widgetPadding.top = widgetPadding.bottom =
993 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.y));
994 } else {
995 widgetPadding.setEmpty();
996 }
Winson Chung0f785722015-04-08 10:27:49 -0700997 }
998
Thales Lima425f6822022-05-10 13:44:58 -0300999 /**
Thales Lima6a590062022-11-22 15:52:49 +00001000 * This method calculates the space between the icons to achieve a certain width.
Thales Lima425f6822022-05-10 13:44:58 -03001001 */
Thales Lima6a590062022-11-22 15:52:49 +00001002 private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) {
Thales Lima9938c2f2022-07-25 14:38:16 +01001003 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
Thales Limaffc68b02023-01-09 16:20:23 +00001004 int hotseatBorderSpacePx =
Thales Lima6a590062022-11-22 15:52:49 +00001005 (int) (hotseatWidthPx - hotseatIconsTotalPx)
1006 / (numShownHotseatIcons - 1 + numExtraBorder);
Thales Limaffc68b02023-01-09 16:20:23 +00001007 return Math.min(hotseatBorderSpacePx, mMaxHotseatIconSpacePx);
Thales Lima425f6822022-05-10 13:44:58 -03001008 }
1009
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001010
1011 /**
1012 * Updates the iconSize for allApps* variants.
1013 */
Brian Isganitisa9a78112022-05-23 18:11:47 -07001014 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +01001015 allAppsBorderSpacePx = new Point(
1016 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
1017 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001018 // AllApps cells don't have real space between cells,
1019 // so we add the border space to the cell height
Alex Chaube753132022-12-09 16:46:54 +00001020 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics)
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001021 + allAppsBorderSpacePx.y;
1022 // but width is just the cell,
1023 // the border is added in #updateAllAppsContainerWidth
Thales Lima080d8902022-03-28 15:30:29 +01001024 if (isScalableGrid) {
Alex Chaube753132022-12-09 16:46:54 +00001025 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1026 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001027 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001028 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001029
1030 if (allAppsCellWidthPx < allAppsIconSizePx) {
1031 // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to
1032 // make allAppsCellWidth bigger.
1033 int numBorders = inv.numAllAppsColumns - 1;
1034 int extraWidthRequired =
1035 (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns;
1036 if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) {
1037 allAppsCellWidthPx = allAppsIconSizePx;
1038 allAppsBorderSpacePx.x -= extraWidthRequired / numBorders;
1039 } else {
1040 // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space
1041 // for allAppsCellWidth, and reduce allAppsIconSize.
1042 allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns
1043 + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns;
1044 allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx);
1045 allAppsBorderSpacePx.x = 0;
1046 }
1047 }
1048
1049 int cellContentHeight = allAppsIconSizePx
1050 + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y;
1051 if (allAppsCellHeightPx < cellContentHeight) {
1052 // Increase allAppsCellHeight to fit its content.
1053 allAppsCellHeightPx = cellContentHeight;
1054 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001055 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001056 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
1057 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001058 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1059 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001060 allAppsIconDrawablePaddingPx =
1061 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001062 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001063 }
1064
Thales Limab7ef5692022-03-10 10:32:36 +00001065 updateAllAppsContainerWidth(res);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001066 if (isVerticalBarLayout()) {
1067 hideWorkspaceLabelsIfNotEnoughSpace();
1068 }
1069 }
1070
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001071 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001072 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001073
Thales Lima7eee74b2023-03-16 16:00:55 -03001074 // For usability we can't have the folder use the whole width of the screen
Sunny Goyal07b69292018-01-08 14:19:34 -08001075 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -08001076
Thales Lima7eee74b2023-03-16 16:00:55 -03001077 // Check if the folder fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -05001078 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Thales Lima7eee74b2023-03-16 16:00:55 -03001079 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx)
1080 + folderFooterHeightPx
1081 + folderContentPaddingTop;
1082 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001083 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -08001084
Thales Lima7eee74b2023-03-16 16:00:55 -03001085 // Check if the folder fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -05001086 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Thales Lima7eee74b2023-03-16 16:00:55 -03001087 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx)
1088 + folderContentPaddingLeftRight * 2;
1089 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001090 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -08001091
1092 float scale = Math.min(scaleX, scaleY);
1093 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001094 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001095 }
1096 }
1097
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001098 private void updateFolderCellSize(float scale, Resources res) {
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001099 float invIconSizeDp = inv.iconSize[mTypeIndex];
Sunny Goyal35c7b192021-04-20 16:51:10 -07001100 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001101 folderChildTextSizePx = pxFromSp(inv.iconTextSize[mTypeIndex], mMetrics, scale);
Thales Lima7eee74b2023-03-16 16:00:55 -03001102 folderLabelTextSizePx = Math.max(pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale),
Thales Limab35faed2022-09-05 16:30:01 -03001103 (int) (folderChildTextSizePx * folderLabelTextScale));
Jon Mirandabf7d8122016-11-03 15:29:29 -07001104
1105 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001106
Jon Miranda823da222021-03-23 08:08:45 -04001107 if (isScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001108 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
Thales Lima7eee74b2023-03-16 16:00:55 -03001109 folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale);
1110 folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale);
1111 } else {
1112 folderCellWidthPx = roundPxValueFromFloat(folderCellWidthPx * scale);
1113 folderCellHeightPx = roundPxValueFromFloat(folderCellHeightPx * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001114 }
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001115
Thales Lima7eee74b2023-03-16 16:00:55 -03001116 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
1117 folderCellLayoutBorderSpacePx = roundPxValueFromFloat(
1118 folderCellLayoutBorderSpacePx * scale);
1119 folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale);
1120
Thales Limab35faed2022-09-05 16:30:01 -03001121 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx;
Jon Miranda823da222021-03-23 08:08:45 -04001122 } else {
1123 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1124 * scale);
1125 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1126 * scale);
1127
1128 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1129 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Lima7eee74b2023-03-16 16:00:55 -03001130 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001131 folderContentPaddingLeftRight =
1132 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1133 folderFooterHeightPx =
Thales Lima7eee74b2023-03-16 16:00:55 -03001134 roundPxValueFromFloat(
1135 res.getDimensionPixelSize(R.dimen.folder_footer_height_default)
1136 * scale);
1137
Jon Miranda823da222021-03-23 08:08:45 -04001138 }
1139
Jonathan Miranda9ad87462017-07-26 17:41:02 +00001140 folderChildDrawablePaddingPx = Math.max(0,
1141 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001142 }
1143
Winson1f064272016-07-18 17:18:02 -07001144 public void updateInsets(Rect insets) {
1145 mInsets.set(insets);
1146 }
1147
Sunny Goyalae6e3182019-04-30 12:04:37 -07001148 /**
1149 * The current device insets. This is generally same as the insets being dispatched to
1150 * {@link Insettable} elements, but can differ if the element is using a different profile.
1151 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001152 public Rect getInsets() {
1153 return mInsets;
1154 }
1155
Sunny Goyal756cd262015-08-20 12:33:21 -07001156 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001157 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001158 }
1159
Sunny Goyal19ff7282021-04-22 10:12:54 -07001160 public Point getCellSize(Point result) {
1161 if (result == null) {
1162 result = new Point();
1163 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001164
Pat Manning25d53342022-05-10 09:58:49 +00001165 int shortcutAndWidgetContainerWidth =
1166 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1167 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1168 inv.numColumns);
1169 int shortcutAndWidgetContainerHeight =
1170 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1171 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1172 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001173 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001174 }
1175
1176 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001177 * Returns the left and right space on the cell, which is the cell width - icon size
1178 */
1179 public int getCellHorizontalSpace() {
1180 return getCellSize().x - iconSizePx;
1181 }
1182
1183 /**
Pat Manning25d53342022-05-10 09:58:49 +00001184 * Gets the number of panels within the workspace.
1185 */
1186 public int getPanelCount() {
1187 return isTwoPanels ? 2 : 1;
1188 }
1189
1190 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001191 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1192 * bottom of the screen.
1193 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001194 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1195 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001196 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001197 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001198 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001199 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001200 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001201 }
1202
1203 /**
1204 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1205 */
Pat Manning25d53342022-05-10 09:58:49 +00001206 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001207 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001208 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001209 }
1210
1211 /**
1212 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1213 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001214 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001215 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001216 return heightPx - (isVerticalBarLayout()
1217 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001218 }
1219
Pat Manningea5c1d22022-04-14 10:58:16 +01001220 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001221 * Gets the scale of the workspace for the spring-loaded edit state.
1222 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001223 public float getWorkspaceSpringLoadScale(Context context) {
1224 float scale =
1225 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1226 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001227 scale = Math.min(scale, 1f);
1228
Pat Manninge63dd252022-08-02 16:15:29 +01001229 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001230 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001231 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001232 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001233 if (scaledWorkspaceWidth > maxAvailableWidth) {
1234 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1235 }
1236 return scale;
1237 }
1238
Pat Manning25d53342022-05-10 09:58:49 +00001239 /**
1240 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1241 *
1242 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1243 * layouts have two Cell Layouts per workspace.
1244 */
1245 public int getCellLayoutWidth() {
1246 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001247 }
1248
Pat Manning25d53342022-05-10 09:58:49 +00001249 /**
1250 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1251 *
1252 * <p>This is the height of a Workspace, less its vertical padding.
1253 */
1254 public int getCellLayoutHeight() {
1255 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001256 }
1257
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001258 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001259 return new Point(workspacePadding.left + workspacePadding.right,
1260 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001261 }
1262
1263 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001264 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1265 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001266 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001267 private void updateWorkspacePadding() {
1268 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001269 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -08001270 padding.top = 0;
1271 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001272 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001273 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -07001274 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -07001275 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -07001276 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001277 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -07001278 }
Winson Chungb3800242013-10-24 11:01:54 -07001279 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001280 // Pad the bottom of the workspace with hotseat bar
1281 // and leave a bit of space in case a widget go all the way down
1282 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding
1283 + workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace
1284 - mInsets.bottom;
Pat Manning08610ca2022-04-05 21:03:16 +01001285 int paddingTop = workspaceTopPadding + (isScalableGrid ? 0 : edgeMarginPx);
1286 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001287
Pat Manning08610ca2022-04-05 21:03:16 +01001288 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001289 }
Pat Manning08610ca2022-04-05 21:03:16 +01001290 insetPadding(workspacePadding, cellLayoutPaddingPx);
1291 }
1292
1293 private void insetPadding(Rect paddings, Rect insets) {
1294 insets.left = Math.min(insets.left, paddings.left);
1295 paddings.left -= insets.left;
1296
1297 insets.top = Math.min(insets.top, paddings.top);
1298 paddings.top -= insets.top;
1299
1300 insets.right = Math.min(insets.right, paddings.right);
1301 paddings.right -= insets.right;
1302
1303 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1304 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001305 }
1306
Sunny Goyal57b22792021-05-25 14:35:01 -07001307 /**
1308 * Returns the padding for hotseat view
1309 */
1310 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001311 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001312 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001313 // The hotseat icons will be placed in the middle of the hotseat cells.
1314 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1315 // in vertical bar layout.
1316 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1317 // is set to account for that difference.
1318 float diffOverlapFactor = iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
Pat Manning08610ca2022-04-05 21:03:16 +01001319 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1320 - diffOverlapFactor), 0);
1321 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001322 + diffOverlapFactor), 0);
1323
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001324 if (isSeascape()) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001325 hotseatBarPadding.set(mInsets.left + hotseatBarSidePaddingStartPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001326 hotseatBarSidePaddingEndPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001327 } else {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001328 hotseatBarPadding.set(hotseatBarSidePaddingEndPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001329 mInsets.right + hotseatBarSidePaddingStartPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001330 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001331 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001332 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001333 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1334 int hotseatBarTopPadding =
1335 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001336
Thales Lima6a590062022-11-22 15:52:49 +00001337 int hotseatWidth = getHotseatRequiredWidth();
Helen Cheuke76291f2023-02-14 17:11:05 +00001338 int startSpacing;
1339 int endSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001340 // Hotseat aligns to the left with nav buttons
1341 if (hotseatBarEndOffset > 0) {
Jon Mirandae17a9492023-03-08 16:42:20 -08001342 startSpacing = inlineNavButtonsEndSpacingPx;
Helen Cheuke76291f2023-02-14 17:11:05 +00001343 endSpacing = availableWidthPx - hotseatWidth - startSpacing + hotseatBorderSpace;
1344 } else {
1345 startSpacing = (availableWidthPx - hotseatWidth) / 2;
1346 endSpacing = startSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001347 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001348 startSpacing += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001349
Helen Cheuke76291f2023-02-14 17:11:05 +00001350 hotseatBarPadding.top = hotseatBarTopPadding;
1351 hotseatBarPadding.bottom = hotseatBarBottomPadding;
Alex Chau51da2192022-05-20 13:32:10 +01001352 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001353 if (isRtl) {
Helen Cheuke76291f2023-02-14 17:11:05 +00001354 hotseatBarPadding.left = endSpacing;
1355 hotseatBarPadding.right = startSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001356 } else {
Helen Cheuke76291f2023-02-14 17:11:05 +00001357 hotseatBarPadding.left = startSpacing;
1358 hotseatBarPadding.right = endSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001359 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001360
Thales Lima425f6822022-05-10 13:44:58 -03001361 } else if (isScalableGrid) {
Alex Chau206ede92022-08-01 17:46:12 +01001362 int sideSpacing = (availableWidthPx - hotseatQsbWidth) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001363 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001364 0,
Thales Lima425f6822022-05-10 13:44:58 -03001365 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001366 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001367 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001368 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1369 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1370 // for this, we pad the left and right of the hotseat with half of the difference of a
1371 // workspace cell vs a hotseat cell.
1372 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001373 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001374 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001375 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001376 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1377 + mInsets.left,
1378 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001379 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001380 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001381 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001382 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001383 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001384 }
1385
Thales Lima9938c2f2022-07-25 14:38:16 +01001386 private int getAdditionalQsbSpace() {
1387 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1388 }
1389
1390 /**
1391 * Calculate how much space the hotseat needs to be shown completely
1392 */
1393 private int getHotseatRequiredWidth() {
1394 int additionalQsbSpace = getAdditionalQsbSpace();
1395 return iconSizePx * numShownHotseatIcons
Thales Lima6a590062022-11-22 15:52:49 +00001396 + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1))
Thales Lima9938c2f2022-07-25 14:38:16 +01001397 + additionalQsbSpace;
1398 }
1399
Winsonfadbe8f2016-07-22 16:35:37 -07001400 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001401 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1402 */
1403 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001404 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001405 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1406 } else if (isTaskbarPresent) { // QSB on top
1407 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001408 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001409 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001410 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001411 }
1412
Thales Limab8c05952022-05-23 16:58:38 +01001413 /**
1414 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1415 */
1416 private int getHotseatBarBottomPadding() {
1417 if (isTaskbarPresent) { // QSB on top or inline
1418 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001419 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001420 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001421 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001422 }
1423
1424 /**
Alex Chau51da2192022-05-20 13:32:10 +01001425 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1426 */
1427 public int getTaskbarOffsetY() {
Jon Miranda9c478b62023-03-23 21:38:49 -07001428 int taskbarIconBottomSpace = (taskbarHeight - iconSizePx) / 2;
Alex Chau51da2192022-05-20 13:32:10 +01001429 int launcherIconBottomSpace =
1430 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001431 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001432 }
1433
1434 /**
Alex Chaua2fc7642022-04-21 14:20:23 +01001435 * Returns the number of pixels required below OverviewActions excluding insets.
1436 */
1437 public int getOverviewActionsClaimedSpaceBelow() {
Alex Chaud67ddc42022-09-30 18:15:56 +01001438 if (isTaskbarPresent) {
Jon Miranda9c478b62023-03-23 21:38:49 -07001439 return taskbarHeight + taskbarBottomMargin * 2;
Alex Chaud67ddc42022-09-30 18:15:56 +01001440 }
1441 return mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001442 }
1443
1444 /** Gets the space that the overview actions will take, including bottom margin. */
1445 public int getOverviewActionsClaimedSpace() {
Pat Manning7b8f7662023-01-18 14:48:30 +00001446 int overviewActionsSpace = isTablet && FeatureFlags.ENABLE_GRID_ONLY_OVERVIEW.get()
1447 ? 0
1448 : (overviewActionsTopMarginPx + overviewActionsHeight);
1449 return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
Alex Chaua2fc7642022-04-21 14:20:23 +01001450 }
1451
1452 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001453 * Takes the View and return the scales of width and height depending on the DeviceProfile
1454 * specifications
1455 *
1456 * @param itemInfo The tag of the widget view
1457 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1458 * height
1459 */
1460 @NonNull
1461 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1462 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1463 }
1464
1465 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001466 * @return the bounds for which the open folders should be contained within
1467 */
1468 public Rect getAbsoluteOpenFolderBounds() {
1469 if (isVerticalBarLayout()) {
1470 // Folders should only appear right of the drop target bar and left of the hotseat
1471 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1472 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001473 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001474 mInsets.top + availableHeightPx);
1475 } else {
1476 // Folders should only appear below the drop target bar and above the hotseat
Jon Miranda9c478b62023-03-23 21:38:49 -07001477 int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001478 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001479 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001480 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001481 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001482 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001483 }
1484 }
1485
Jon Miranda228877d2021-02-09 11:05:00 -05001486 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1487 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001488 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001489
Jon Miranda228877d2021-02-09 11:05:00 -05001490 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1491 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001492 }
1493
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001494 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001495 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1496 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1497 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001498 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001499 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001500 return isLandscape && transposeLayoutWithOrientation;
1501 }
1502
Sunny Goyal59d086c2018-05-07 17:31:40 -07001503 /**
1504 * Updates orientation information and returns true if it has changed from the previous value.
1505 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001506 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001507 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001508 boolean isSeascape = DisplayController.INSTANCE.get(context)
1509 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001510 if (mIsSeascape != isSeascape) {
1511 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001512 // Hotseat changing sides requires updating workspace left/right paddings
1513 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001514 return true;
1515 }
1516 }
1517 return false;
1518 }
1519
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001520 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001521 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001522 }
1523
Sunny Goyal07b69292018-01-08 14:19:34 -08001524 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001525 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001526 }
1527
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001528 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001529 switch (containerType) {
1530 case CellLayout.WORKSPACE:
1531 return cellHeightPx;
1532 case CellLayout.FOLDER:
1533 return folderCellHeightPx;
1534 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001535 // The hotseat is the only container where the cell height is going to be
1536 // different from the content within that cell.
1537 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001538 default:
1539 // ??
1540 return 0;
1541 }
1542 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001543
Jon Miranda58561d42021-03-17 10:51:54 -04001544 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001545 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001546 }
1547
Alex Chaue818bcb2022-09-02 17:27:11 +01001548 private String dpPointFToString(String name, PointF value) {
1549 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
1550 }
1551
Pat Manning5f74bfd2022-07-20 12:08:54 +01001552 /** Dumps various DeviceProfile variables to the specified writer. */
1553 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04001554 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001555 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001556
1557 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001558 writer.println(prefix + "\tisPhone:" + isPhone);
1559 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1560 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001561 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001562
1563 writer.println(prefix + "\tisLandscape:" + isLandscape);
1564 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001565 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001566
1567 writer.println(prefix + pxToDpStr("windowX", windowX));
1568 writer.println(prefix + pxToDpStr("windowY", windowY));
1569 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1570 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001571 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1572 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001573 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1574 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1575 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1576 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001577
1578 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1579
1580 writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
1581
Thales Lima83bedbf2021-10-05 17:47:39 +01001582 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001583 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1584 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1585 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001586
Alex Chaue818bcb2022-09-02 17:27:11 +01001587 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07001588
Jon Miranda58561d42021-03-17 10:51:54 -04001589 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1590 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1591
1592 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1593 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1594
Thales Lima83bedbf2021-10-05 17:47:39 +01001595 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1596 cellLayoutBorderSpacePx.x));
1597 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1598 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001599 writer.println(
1600 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
1601 writer.println(
1602 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
1603 writer.println(
1604 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01001605 writer.println(
1606 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01001607
Jon Miranda58561d42021-03-17 10:51:54 -04001608 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1609 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1610 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1611
Helen Cheuk599109b2023-02-23 17:15:39 +00001612 writer.println(prefix + "\tinv.numFolderRows: " + inv.numFolderRows);
1613 writer.println(prefix + "\tinv.numFolderColumns: " + inv.numFolderColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001614 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1615 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1616 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1617 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1618 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1619 folderChildDrawablePaddingPx));
Thales Limab35faed2022-09-05 16:30:01 -03001620 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx",
1621 folderCellLayoutBorderSpacePx));
Thales Limaa08a4432022-08-09 09:55:17 +01001622 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
1623 folderContentPaddingLeftRight));
1624 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03001625 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001626
Alex Chaue0227552022-04-06 19:44:43 +01001627 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001628 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
1629 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
1630 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
1631 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01001632
1633 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
1634 writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001635 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
1636 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04001637 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1638 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1639 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1640 allAppsIconDrawablePaddingPx));
1641 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001642 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001643 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
1644 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001645 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau62572c02022-07-25 18:36:37 +00001646 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
Alex Chau27b39b92022-01-14 18:02:18 +00001647 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001648
1649 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03001650 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04001651 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00001652 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Jon Miranda58561d42021-03-17 10:51:54 -04001653 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
1654 hotseatBarSidePaddingStartPx));
1655 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
1656 hotseatBarSidePaddingEndPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001657 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01001658 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
1659 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01001660 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
1661 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001662 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
1663 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
1664 hotseatLayoutPadding.top));
1665 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
1666 hotseatLayoutPadding.bottom));
1667 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
1668 hotseatLayoutPadding.left));
1669 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
1670 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001671 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001672 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001673 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01001674 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001675
1676 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001677 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda9c478b62023-03-23 21:38:49 -07001678 writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight));
1679 writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight));
1680 writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin));
1681 writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001682
Thales Lima83bedbf2021-10-05 17:47:39 +01001683 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1684 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001685 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
1686 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
1687 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00001688 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001689
Jon Mirandaab3c6812021-06-28 15:42:28 -07001690 writer.println(prefix + pxToDpStr("iconScale", iconScale));
1691 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04001692 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00001693 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001694
Thales Lima171ee662022-11-22 15:52:49 +00001695 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04001696 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
1697 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00001698
1699 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00001700 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
1701 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
1702 overviewTaskIconDrawableSizePx));
1703 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
1704 overviewTaskIconDrawableSizeGridPx));
1705 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
1706 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01001707 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
1708 overviewActionsTopMarginPx));
1709 writer.println(prefix + pxToDpStr("overviewActionsHeight",
1710 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00001711 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
1712 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00001713 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
1714 overviewActionsButtonSpacing));
1715 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
1716 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
1717 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01001718
Alex Chau62572c02022-07-25 18:36:37 +00001719 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001720 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00001721 writer.println(
1722 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001723
Pat Manning5f74bfd2022-07-20 12:08:54 +01001724 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
1725 getCellLayoutSpringLoadShrunkTop()));
1726 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
1727 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01001728 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
1729 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001730 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
1731 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01001732 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
1733 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Jon Miranda58561d42021-03-17 10:51:54 -04001734 }
1735
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00001736 /** Returns a reduced representation of this DeviceProfile. */
1737 public String toSmallString() {
1738 return "isTablet:" + isTablet + ", "
1739 + "isMultiDisplay:" + isMultiDisplay + ", "
1740 + "widthPx:" + widthPx + ", "
1741 + "heightPx:" + heightPx + ", "
1742 + "insets:" + mInsets + ", "
1743 + "rotationHint:" + rotationHint;
1744 }
1745
Alex Chaua6907dc2022-03-18 15:24:07 +00001746 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07001747 Configuration config = new Configuration(c.getResources().getConfiguration());
1748 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03001749 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00001750 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07001751 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07001752 }
Sunny Goyalfde55052018-02-01 14:46:13 -08001753
1754 /**
1755 * Callback when a component changes the DeviceProfile associated with it, as a result of
1756 * configuration change
1757 */
1758 public interface OnDeviceProfileChangeListener {
1759
1760 /**
1761 * Called when the device profile is reassigned. Note that for layout and measurements, it
1762 * is sufficient to listen for inset changes. Use this callback when you need to perform
1763 * a one time operation.
1764 */
1765 void onDeviceProfileChanged(DeviceProfile dp);
1766 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001767
Sihua Mae04aa202022-07-18 12:43:56 -07001768 /**
1769 * Handler that deals with ItemInfo of the views for the DeviceProfile
1770 */
1771 @FunctionalInterface
1772 public interface ViewScaleProvider {
1773 /**
1774 * Get the scales from the view
1775 *
1776 * @param itemInfo The tag of the widget view
1777 * @return PointF instance containing the scale information, or null if using the default
1778 * app widget scale of this device profile.
1779 */
1780 @NonNull
1781 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
1782 }
1783
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001784 public static class Builder {
1785 private Context mContext;
1786 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07001787 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001788
Sunny Goyal19ff7282021-04-22 10:12:54 -07001789 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00001790 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001791
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001792 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001793 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00001794 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07001795 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001796
Sunny Goyal65190ae2022-08-02 14:16:26 -07001797 private SparseArray<DotRenderer> mDotRendererCache;
1798
Jon Miranda2b25ded2023-02-02 14:48:45 -08001799 private Consumer<DeviceProfile> mOverrideProvider;
1800
Sunny Goyalfd58da62020-08-11 12:06:49 -07001801 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001802 mContext = context;
1803 mInv = inv;
1804 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001805 }
1806
1807 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1808 mIsMultiWindowMode = isMultiWindowMode;
1809 return this;
1810 }
1811
Alex Chauab800f72022-12-13 17:46:06 +00001812 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
1813 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001814 return this;
1815 }
1816
Sunny Goyal65190ae2022-08-02 14:16:26 -07001817 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
1818 mDotRendererCache = dotRendererCache;
1819 return this;
1820 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07001821
1822 public Builder setWindowBounds(WindowBounds bounds) {
1823 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07001824 return this;
1825 }
1826
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001827 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1828 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1829 return this;
1830 }
1831
Alex Chau6ed408f2022-03-04 12:58:05 +00001832 public Builder setGestureMode(boolean isGestureMode) {
1833 mIsGestureMode = isGestureMode;
1834 return this;
1835 }
1836
Jon Miranda2b25ded2023-02-02 14:48:45 -08001837 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
1838 mOverrideProvider = overrideProvider;
1839 return this;
1840 }
1841
Sihua Mae04aa202022-07-18 12:43:56 -07001842 /**
1843 * Set the viewScaleProvider for the builder
1844 *
1845 * @param viewScaleProvider The viewScaleProvider to be set for the
Thales Limae9273ea2023-01-26 12:33:52 +00001846 * DeviceProfile
Sihua Mae04aa202022-07-18 12:43:56 -07001847 * @return This builder
1848 */
1849 @NonNull
1850 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
1851 mViewScaleProvider = viewScaleProvider;
1852 return this;
1853 }
1854
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001855 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001856 if (mWindowBounds == null) {
1857 throw new IllegalArgumentException("Window bounds not set");
1858 }
1859 if (mTransposeLayoutWithOrientation == null) {
1860 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
1861 }
Alex Chau6ed408f2022-03-04 12:58:05 +00001862 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01001863 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00001864 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001865 if (mDotRendererCache == null) {
1866 mDotRendererCache = new SparseArray<>();
1867 }
Sihua Mae04aa202022-07-18 12:43:56 -07001868 if (mViewScaleProvider == null) {
1869 mViewScaleProvider = DEFAULT_PROVIDER;
1870 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08001871 if (mOverrideProvider == null) {
1872 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
1873 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001874 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00001875 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jon Miranda2b25ded2023-02-02 14:48:45 -08001876 mIsGestureMode, mViewScaleProvider, mOverrideProvider);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001877 }
1878 }
1879
Winson Chungb3800242013-10-24 11:01:54 -07001880}