blob: 0231090d7e0d5d9a9220c5c55196f4733a7a8f8b [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 Limaec5abba2023-04-05 16:33:50 +0100104 public final boolean isResponsiveGrid;
Thales Lima83bedbf2021-10-05 17:47:39 +0100105 private final int mTypeIndex;
Jon Mirandae126d722021-02-25 10:45:20 -0500106
Tony Wickhamd6b40372015-09-23 18:37:57 -0700107 /**
108 * The maximum amount of left/right workspace padding as a percentage of the screen width.
109 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
110 * 7% of the screen width can be used as right padding.
111 */
112 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -0700113
Jon Miranda3f9bab22017-07-28 14:50:17 -0700114 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700115 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda80dda302021-07-28 14:14:59 -0700116 private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252;
117 private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700118
Sunny Goyalc6205602015-05-21 20:46:33 -0700119 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +0100120 public final int desiredWorkspaceHorizontalMarginOriginalPx;
121 public int desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100122 public int gridVisualizationPaddingX;
123 public int gridVisualizationPaddingY;
Thales Lima78d00ad2021-09-30 11:29:06 +0100124 public Point cellLayoutBorderSpaceOriginalPx;
125 public Point cellLayoutBorderSpacePx;
Pat Manning08610ca2022-04-05 21:03:16 +0100126 public Rect cellLayoutPaddingPx = new Rect();
127
Sunny Goyalc6205602015-05-21 20:46:33 -0700128 public final int edgeMarginPx;
Alex Chau0c4e11b2022-07-08 18:41:36 +0100129 public final float workspaceContentScale;
Alex Chau906d8822022-05-23 10:42:25 +0100130 public final int workspaceSpringLoadedMinNextPageVisiblePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700131
Jon Miranda58561d42021-03-17 10:51:54 -0400132 private final int extraSpace;
Thales Lima171ee662022-11-22 15:52:49 +0000133 private int maxEmptySpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500134 public int workspaceTopPadding;
135 public int workspaceBottomPadding;
136
Tony Wickham5edf9e22020-03-27 20:06:52 -0700137 // Workspace page indicator
138 public final int workspacePageIndicatorHeight;
139 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700140
Sunny Goyalc6205602015-05-21 20:46:33 -0700141 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400142 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700143 public int iconSizePx;
144 public int iconTextSizePx;
145 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700146 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -0700147
Jon Mirandaab3c6812021-06-28 15:42:28 -0700148 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800149 public int cellWidthPx;
150 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700151 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800152
Jon Mirandae126d722021-02-25 10:45:20 -0500153 public int cellYPaddingPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500154
Sunny Goyalc6205602015-05-21 20:46:33 -0700155 // Folder
Jon Mirandae126d722021-02-25 10:45:20 -0500156 public float folderLabelTextScale;
157 public int folderLabelTextSizePx;
Thales Limab35faed2022-09-05 16:30:01 -0300158 public int folderFooterHeightPx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700159 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700160 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700161
Jon Mirandae126d722021-02-25 10:45:20 -0500162 // Folder content
Thales Limab35faed2022-09-05 16:30:01 -0300163 public int folderCellLayoutBorderSpacePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500164 public int folderContentPaddingLeftRight;
165 public int folderContentPaddingTop;
166
Jon Mirandabf7d8122016-11-03 15:29:29 -0700167 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700168 public int folderCellWidthPx;
169 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700170
171 // Folder child
172 public int folderChildIconSizePx;
173 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700174 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700175
Sunny Goyalc6205602015-05-21 20:46:33 -0700176 // Hotseat
Thales Lima9938c2f2022-07-25 14:38:16 +0100177 public int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700178 public int hotseatCellHeightPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100179 public final boolean areNavButtonsInline;
Jon Miranda18751b62017-07-31 17:25:27 -0700180 // In portrait: size = height, in landscape: size = width
181 public int hotseatBarSizePx;
Thales Limab8c05952022-05-23 16:58:38 +0100182 public int hotseatBarBottomSpacePx;
Pat Manning26f70f72022-07-07 13:50:39 +0100183 public int hotseatBarEndOffset;
Thales Limab8c05952022-05-23 16:58:38 +0100184 public int hotseatQsbSpace;
Pat Manningde25c0d2022-04-05 19:11:26 +0100185 public int springLoadedHotseatBarTopMarginPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700186 // Start is the side next to the nav bar, end is the side next to the workspace
187 public final int hotseatBarSidePaddingStartPx;
188 public final int hotseatBarSidePaddingEndPx;
Alex Chau206ede92022-08-01 17:46:12 +0100189 public int hotseatQsbWidth; // only used when isQsbInline
Sunny Goyal57b22792021-05-25 14:35:01 -0700190 public final int hotseatQsbHeight;
Thales Limab8c05952022-05-23 16:58:38 +0100191 public final int hotseatQsbVisualHeight;
192 private final int hotseatQsbShadowHeight;
Thales Limadd027342022-01-07 12:54:37 +0000193 public int hotseatBorderSpace;
Thales Limaffc68b02023-01-09 16:20:23 +0000194 private final int mMinHotseatIconSpacePx;
195 private final int mMinHotseatQsbWidthPx;
196 private final int mMaxHotseatIconSpacePx;
Jon Mirandae17a9492023-03-08 16:42:20 -0800197 public final int inlineNavButtonsEndSpacingPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700198
Alex Chau3d2c0622022-09-01 21:28:14 +0100199 // Bottom sheets
200 public int bottomSheetTopPadding;
201 public int bottomSheetOpenDuration;
202 public int bottomSheetCloseDuration;
203 public float bottomSheetWorkspaceScale;
204 public float bottomSheetDepth;
205
Sunny Goyalc6205602015-05-21 20:46:33 -0700206 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000207 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000208 public int allAppsShiftRange;
209 public int allAppsTopPadding;
Alex Chau3d2c0622022-09-01 21:28:14 +0100210 public int allAppsOpenDuration;
211 public int allAppsCloseDuration;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700212 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700213 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700214 public int allAppsIconSizePx;
215 public int allAppsIconDrawablePaddingPx;
sfufa@google.comde013292021-09-21 18:22:44 -0700216 public int allAppsLeftRightPadding;
Alex Chau27b39b92022-01-14 18:02:18 +0000217 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700218 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700219 public float allAppsIconTextSizePx;
220
Zak Cohen334efeb2021-03-19 16:42:07 -0700221 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700222 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000223 public int overviewTaskIconSizePx;
Alex Chauac9df382021-08-02 19:08:41 +0100224 public int overviewTaskIconDrawableSizePx;
225 public int overviewTaskIconDrawableSizeGridPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000226 public int overviewTaskThumbnailTopMarginPx;
Alex Chau19c6eca2022-03-10 20:12:56 +0000227 public final int overviewActionsHeight;
Alex Chaua2fc7642022-04-21 14:20:23 +0100228 public final int overviewActionsTopMarginPx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000229 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100230 public int overviewPageSpacing;
231 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000232 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700233
Jeremy Sim0ac47082022-10-10 13:59:40 -0700234 // Split staging
235 public int splitPlaceholderInset;
236
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800237 // Widgets
Sihua Mae04aa202022-07-18 12:43:56 -0700238 private final ViewScaleProvider mViewScaleProvider;
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800239
Sunny Goyal47328fd2016-05-25 18:56:41 -0700240 // Drop Target
241 public int dropTargetBarSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100242 public int dropTargetBarTopMarginPx;
243 public int dropTargetBarBottomMarginPx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100244 public int dropTargetDragPaddingPx;
245 public int dropTargetTextSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100246 public int dropTargetHorizontalPaddingPx;
247 public int dropTargetVerticalPaddingPx;
248 public int dropTargetGapPx;
Alex Chau5b019302022-05-23 10:42:25 +0100249 public int dropTargetButtonWorkspaceEdgeGapPx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700250
Winson1f064272016-07-18 17:18:02 -0700251 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800252 private final Rect mInsets = new Rect();
253 public final Rect workspacePadding = new Rect();
Sunny Goyal6c304b12023-04-10 12:03:04 -0700254 // Additional padding added to the widget inside its cellSpace. It is applied outside
255 // the widgetView, such that the actual view size is same as the widget size.
256 public final Rect widgetPadding = new Rect();
257
Jon Miranda0bd63d12019-03-06 17:29:29 -0800258 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700259 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700260
Tony Wickhamf34bee82018-12-03 18:11:39 -0800261 // Notification dots
Sunny Goyal65190ae2022-08-02 14:16:26 -0700262 public final DotRenderer mDotRendererWorkSpace;
263 public final DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800264
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100265 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800266 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000267 // Whether Taskbar will inset the bottom of apps by taskbarSize.
268 public boolean isTaskbarPresentInApps;
Jon Miranda9c478b62023-03-23 21:38:49 -0700269 public final int taskbarHeight;
270 public final int stashedTaskbarHeight;
271 public final int taskbarBottomMargin;
272 public final int taskbarIconSize;
Jon Miranda04f05102023-04-04 12:16:31 -0700273 // If true, used to layout taskbar in 3 button navigation mode.
274 public final boolean startAlignTaskbar;
Tony Wickham15883892021-02-12 11:24:40 -0800275
Alex Chaua02eddc2021-04-29 00:36:06 +0100276 // DragController
277 public int flingToDeleteThresholdVelocity;
278
Vinit Nayak17c4b332021-08-05 12:54:58 -0700279 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700280 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal65190ae2022-08-02 14:16:26 -0700281 SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
Alex Chauab800f72022-12-13 17:46:06 +0000282 boolean transposeLayoutWithOrientation, boolean isMultiDisplay, boolean isGestureMode,
Jon Miranda2b25ded2023-02-02 14:48:45 -0800283 @NonNull final ViewScaleProvider viewScaleProvider,
284 @NonNull final Consumer<DeviceProfile> dimensionOverrideProvider) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700285
Adam Cohen2e6da152015-05-06 11:42:25 -0700286 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700287 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800288 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500289 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +0000290 this.isMultiDisplay = isMultiDisplay;
Alex Chau6ed408f2022-03-04 12:58:05 +0000291 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700292 windowX = windowBounds.bounds.left;
293 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800294 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100295 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700296
Thales Limaec5abba2023-04-05 16:33:50 +0100297 // TODO(b/241386436):
298 // for testing that the flag works only, shouldn't change any launcher behaviour
299 isResponsiveGrid = inv.workspaceSpecsId != INVALID_RESOURCE_HANDLE;
300
Jon Mirandae126d722021-02-25 10:45:20 -0500301 isScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000302 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700303 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000304 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700305 isPhone = !isTablet;
Alex Chauab800f72022-12-13 17:46:06 +0000306 isTwoPanels = isTablet && isMultiDisplay;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800307 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700308
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000309 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000310 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700311 ? Configuration.ORIENTATION_LANDSCAPE
312 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000313 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700314 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000315 mMetrics = res.getDisplayMetrics();
316
317 // Determine sizes.
318 widthPx = windowBounds.bounds.width();
319 heightPx = windowBounds.bounds.height();
320 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100321 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000322
323 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Thales Lima83bedbf2021-10-05 17:47:39 +0100324 if (isTwoPanels) {
325 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000326 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100327 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000328 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100329 }
330 } else {
331 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000332 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100333 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000334 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100335 }
336 }
337
Jon Miranda9c478b62023-03-23 21:38:49 -0700338 if (DisplayController.isTransientTaskbar(context)) {
339 float invTransientIconSizeDp = inv.transientTaskbarIconSize[mTypeIndex];
340 taskbarIconSize = pxFromDp(invTransientIconSizeDp, mMetrics);
341 taskbarHeight = taskbarIconSize
342 + (2 * res.getDimensionPixelSize(R.dimen.transient_taskbar_padding));
343 stashedTaskbarHeight =
344 res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_height);
345 taskbarBottomMargin =
346 res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin);
Jon Miranda04f05102023-04-04 12:16:31 -0700347 startAlignTaskbar = false;
Jon Miranda9c478b62023-03-23 21:38:49 -0700348 } else {
349 taskbarIconSize = pxFromDp(ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size),
350 mMetrics);
351 taskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_size);
352 stashedTaskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
353 taskbarBottomMargin = 0;
Jon Miranda04f05102023-04-04 12:16:31 -0700354 startAlignTaskbar = inv.startAlignTaskbar[mTypeIndex];
Tony Wickham15883892021-02-12 11:24:40 -0800355 }
Tony Wickham15883892021-02-12 11:24:40 -0800356
Winson Chungb3800242013-10-24 11:01:54 -0700357 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100358 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700359
Thales Limad90faab2021-09-21 17:18:47 +0100360 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
361 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100362 gridVisualizationPaddingX = res.getDimensionPixelSize(
363 R.dimen.grid_visualization_horizontal_cell_spacing);
364 gridVisualizationPaddingY = res.getDimensionPixelSize(
365 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500366
Alex Chaue0227552022-04-06 19:44:43 +0100367 bottomSheetTopPadding = mInsets.top // statusbar height
Andras Kloczl142b0542022-03-09 21:26:02 +0000368 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
369 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
Alex Chau3d2c0622022-09-01 21:28:14 +0100370 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
371 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
372 if (isTablet) {
373 bottomSheetWorkspaceScale = workspaceContentScale;
Alex Chauab800f72022-12-13 17:46:06 +0000374 if (isMultiDisplay && !ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH.get()) {
375 // TODO(b/259893832): Revert to use maxWallpaperScale to calculate bottomSheetDepth
376 // when screen recorder bug is fixed.
377 bottomSheetDepth = 1f;
378 } else {
379 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
380 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
381 // When depth is 1, wallpaper zoom is set to 1.
382 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
383 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
384 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
385 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
386 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100387 } else {
388 bottomSheetWorkspaceScale = 1f;
389 bottomSheetDepth = 0f;
390 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000391
Jon Mirandae126d722021-02-25 10:45:20 -0500392 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
Thales Limab35faed2022-09-05 16:30:01 -0300393
Thales Lima7eee74b2023-03-16 16:00:55 -0300394 if (isScalableGrid && inv.folderStyle != INVALID_RESOURCE_HANDLE) {
Thales Limab35faed2022-09-05 16:30:01 -0300395 TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
Thales Limad852d652023-01-17 14:01:13 +0000396 R.styleable.FolderStyle);
Thales Limab35faed2022-09-05 16:30:01 -0300397 // These are re-set in #updateFolderCellSize if the grid is not scalable
398 folderCellHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000399 R.styleable.FolderStyle_folderCellHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300400 folderCellWidthPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000401 R.styleable.FolderStyle_folderCellWidth, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300402
403 folderContentPaddingTop = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000404 R.styleable.FolderStyle_folderTopPadding, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300405 folderCellLayoutBorderSpacePx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000406 R.styleable.FolderStyle_folderBorderSpace, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300407 folderFooterHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000408 R.styleable.FolderStyle_folderFooterHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300409 folderStyle.recycle();
410 } else {
411 folderCellLayoutBorderSpacePx = 0;
Thales Lima7eee74b2023-03-16 16:00:55 -0300412 folderFooterHeightPx = res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Thales Limab35faed2022-09-05 16:30:01 -0300413 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
414 }
Jon Mirandae126d722021-02-25 10:45:20 -0500415
Thales Lima78d00ad2021-09-30 11:29:06 +0100416 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv);
Thales Limab35faed2022-09-05 16:30:01 -0300417 cellLayoutBorderSpaceOriginalPx = new Point(cellLayoutBorderSpacePx);
Thales Lima85c942f2021-12-31 13:04:20 +0000418 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000419 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
420 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Thales Limae9273ea2023-01-26 12:33:52 +0000421 setupAllAppsStyle(context);
Jon Mirandae126d722021-02-25 10:45:20 -0500422
Tony Wickham5edf9e22020-03-27 20:06:52 -0700423 workspacePageIndicatorHeight = res.getDimensionPixelSize(
424 R.dimen.workspace_page_indicator_height);
425 mWorkspacePageIndicatorOverlapWorkspace =
426 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700427
Thales Limad852d652023-01-17 14:01:13 +0000428 TypedArray cellStyle;
429 if (inv.cellStyle != INVALID_RESOURCE_HANDLE) {
430 cellStyle = context.obtainStyledAttributes(inv.cellStyle,
431 R.styleable.CellStyle);
432 } else {
433 cellStyle = context.obtainStyledAttributes(R.style.CellStyleDefault,
434 R.styleable.CellStyle);
435 }
436 iconDrawablePaddingOriginalPx = cellStyle.getDimensionPixelSize(
437 R.styleable.CellStyle_iconDrawablePadding, 0);
438 cellStyle.recycle();
Alex Chaua02eddc2021-04-29 00:36:06 +0100439
Sunny Goyal47328fd2016-05-25 18:56:41 -0700440 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100441 dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
442 dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100443 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
444 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100445 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
446 R.dimen.drop_target_button_drawable_horizontal_padding);
447 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
448 R.dimen.drop_target_button_drawable_vertical_padding);
449 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100450 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
451 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100452
Alex Chau906d8822022-05-23 10:42:25 +0100453 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
454 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700455
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700456 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700457
Thales Limaa1012902022-01-13 17:58:42 +0000458 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100459 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
460 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
461
Thales Lima12d0eff2022-03-25 17:06:11 +0000462 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
463 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
464 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
465 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
466 && hotseatQsbHeight > 0;
Thales Lima6a590062022-11-22 15:52:49 +0000467 isQsbInline = isScalableGrid && inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000468
Thales Lima425f6822022-05-10 13:44:58 -0300469 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100470 numShownHotseatIcons =
471 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000472
Sunny Goyal19ff7282021-04-22 10:12:54 -0700473 numShownAllAppsColumns =
474 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100475
476 int hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
477 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
478 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
479 // Have a little space between the inset and the QSB
480 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
481 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
482
483 // Only change the spaces if there is space
484 if (availableSpace > 0) {
485 // Make sure there is enough space between hotseat/QSB and QSB/navBar
486 if (availableSpace < minQsbMargin * 2) {
487 minQsbMargin = availableSpace / 2;
488 hotseatQsbSpace = minQsbMargin;
489 } else {
490 hotseatQsbSpace -= minQsbMargin;
491 }
492 }
493 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
494
Thales Limaa1012902022-01-13 17:58:42 +0000495 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100496 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
Thales Limaa1012902022-01-13 17:58:42 +0000497 }
Thales Lima425f6822022-05-10 13:44:58 -0300498
Pat Manningde25c0d2022-04-05 19:11:26 +0100499 springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
500 R.dimen.spring_loaded_hotseat_top_margin);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700501 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800502 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700503 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700504 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Thales Limab8c05952022-05-23 16:58:38 +0100505 updateHotseatSizes(pxFromDp(inv.iconSize[INDEX_DEFAULT], mMetrics));
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700506 if (areNavButtonsInline && !isPhone) {
Jon Mirandae17a9492023-03-08 16:42:20 -0800507 inlineNavButtonsEndSpacingPx =
Thales Limaffc68b02023-01-09 16:20:23 +0000508 res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing);
Pat Manning26f70f72022-07-07 13:50:39 +0100509 /*
510 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700511 * Spacing between nav buttons +
Thales Lima6a590062022-11-22 15:52:49 +0000512 * Space at the end for contextual buttons
Pat Manning26f70f72022-07-07 13:50:39 +0100513 */
514 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700515 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
Jon Mirandae17a9492023-03-08 16:42:20 -0800516 + inlineNavButtonsEndSpacingPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100517 } else {
Jon Mirandae17a9492023-03-08 16:42:20 -0800518 inlineNavButtonsEndSpacingPx = 0;
Pat Manning26f70f72022-07-07 13:50:39 +0100519 hotseatBarEndOffset = 0;
520 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700521
Alex Chau635b3ab2022-01-26 16:49:10 +0000522 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chau5fd9d492021-07-22 17:27:11 +0100523 overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100524 overviewTaskIconDrawableSizePx =
525 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
526 overviewTaskIconDrawableSizeGridPx =
527 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700528 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx;
Jeremy Sim3c2c3f12022-05-16 20:37:43 -0700529 overviewActionsTopMarginPx = res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000530 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
531 overviewActionsButtonSpacing = res.getDimensionPixelSize(
532 R.dimen.overview_actions_button_spacing);
Alex Chau19c6eca2022-03-10 20:12:56 +0000533 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700534 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000535 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700536
Jeremy Sim0ac47082022-10-10 13:59:40 -0700537 splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset);
538
Jon Miranda2ed276e2017-06-29 11:36:34 -0700539 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400540 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700541
Jon Miranda2ed276e2017-06-29 11:36:34 -0700542 // Now that we have all of the variables calculated, we can tune certain sizes.
Thales Limaae0d7ef2022-11-16 15:53:43 +0000543 if (isScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400544 // Paddings were created assuming no scaling, so we first unscale the extra space.
Jon Mirandaab3c6812021-06-28 15:42:28 -0700545 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
Thales Limaae0d7ef2022-11-16 15:53:43 +0000546 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
547 DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
Thales Lima171ee662022-11-22 15:52:49 +0000548 maxEmptySpace = padding.getMaxEmptySpacePx();
Jon Miranda228877d2021-02-09 11:05:00 -0500549
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400550 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
551 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
552 int paddingHotseatBottom = padding.getHotseatBottomPadding(unscaledExtraSpace);
553
Jon Mirandaab3c6812021-06-28 15:42:28 -0700554 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
555 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700556 }
Pat Manning08610ca2022-04-05 21:03:16 +0100557
558 int cellLayoutPadding =
559 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
560 R.dimen.cell_layout_padding);
561 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
562 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800563 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800564
Thales Lima7eee74b2023-03-16 16:00:55 -0300565 // Folder scaling requires correct workspace paddings
566 updateAvailableFolderCellDimensions(res);
567
Thales Limaffc68b02023-01-09 16:20:23 +0000568 mMinHotseatIconSpacePx = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
569 mMinHotseatQsbWidthPx = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
570 mMaxHotseatIconSpacePx = areNavButtonsInline
Thales Lima6a590062022-11-22 15:52:49 +0000571 ? res.getDimensionPixelSize(R.dimen.max_hotseat_icon_space) : Integer.MAX_VALUE;
Thales Lima425f6822022-05-10 13:44:58 -0300572 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima6a590062022-11-22 15:52:49 +0000573 recalculateHotseatWidthAndBorderSpace();
Alex Chau206ede92022-08-01 17:46:12 +0100574
575 // AllApps height calculation depends on updated cellSize
576 if (isTablet) {
577 int collapseHandleHeight =
578 res.getDimensionPixelOffset(R.dimen.bottom_sheet_handle_area_height);
579 int contentHeight = heightPx - collapseHandleHeight - hotseatQsbHeight;
580 int targetContentHeight = (int) (allAppsCellHeightPx * ALL_APPS_TABLET_MAX_ROWS);
581 allAppsTopPadding = Math.max(mInsets.top, contentHeight - targetContentHeight);
582 allAppsShiftRange = heightPx - allAppsTopPadding;
583 } else {
584 allAppsTopPadding = 0;
585 allAppsShiftRange =
586 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
587 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100588 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
589 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300590
Alex Chaua02eddc2021-04-29 00:36:06 +0100591 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
592 R.dimen.drag_flingToDeleteMinVelocity);
593
Sihua Mae04aa202022-07-18 12:43:56 -0700594 mViewScaleProvider = viewScaleProvider;
595
Jon Miranda2b25ded2023-02-02 14:48:45 -0800596 dimensionOverrideProvider.accept(this);
597
Tony Wickham1237df02017-02-24 08:59:36 -0800598 // This is done last, after iconSizePx is calculated above.
Sunny Goyal799e1202023-02-09 10:54:28 -0800599 mDotRendererWorkSpace = createDotRenderer(context, iconSizePx, dotRendererCache);
600 mDotRendererAllApps = createDotRenderer(context, allAppsIconSizePx, dotRendererCache);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700601 }
602
603 private static DotRenderer createDotRenderer(
Sunny Goyal799e1202023-02-09 10:54:28 -0800604 @NonNull Context context, int size, @NonNull SparseArray<DotRenderer> cache) {
Sunny Goyal65190ae2022-08-02 14:16:26 -0700605 DotRenderer renderer = cache.get(size);
606 if (renderer == null) {
Sunny Goyal799e1202023-02-09 10:54:28 -0800607 renderer = new DotRenderer(size, getShapePath(context, DEFAULT_DOT_SIZE),
608 DEFAULT_DOT_SIZE);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700609 cache.put(size, renderer);
610 }
611 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700612 }
613
Thales Lima425f6822022-05-10 13:44:58 -0300614 /**
615 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
616 * width of the hotseat.
617 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100618 private int calculateQsbWidth(int hotseatBorderSpace) {
Thales Lima425f6822022-05-10 13:44:58 -0300619 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100620 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300621 return getIconToIconWidthForColumns(columns)
622 - iconSizePx * numShownHotseatIcons
623 - hotseatBorderSpace * numShownHotseatIcons;
624 } else {
625 int columns = inv.hotseatColumnSpan[mTypeIndex];
626 return getIconToIconWidthForColumns(columns);
627 }
628 }
Thales Lima2903a622022-03-17 13:52:19 +0000629
Thales Lima425f6822022-05-10 13:44:58 -0300630 private int getIconToIconWidthForColumns(int columns) {
631 return columns * getCellSize().x
632 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400633 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000634 }
635
Thales Limad90faab2021-09-21 17:18:47 +0100636 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
637 if (isVerticalBarLayout()) {
638 return 0;
639 }
640
Thales Lima83bedbf2021-10-05 17:47:39 +0100641 return isScalableGrid
642 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
643 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100644 }
645
Thales Limab8c05952022-05-23 16:58:38 +0100646 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
647 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700648 // Ensure there is enough space for folder icons, which have a slightly larger radius.
649 hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR);
Thales Limab8c05952022-05-23 16:58:38 +0100650
Jon Miranda0d284852021-06-22 14:50:55 -0700651 if (isVerticalBarLayout()) {
652 hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
653 + hotseatBarSidePaddingEndPx;
Thales Limab8c05952022-05-23 16:58:38 +0100654 } else if (isQsbInline) {
655 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
656 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700657 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100658 hotseatBarSizePx = hotseatIconSizePx
659 + hotseatQsbSpace
660 + hotseatQsbVisualHeight
661 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700662 }
663 }
664
Thales Lima6a590062022-11-22 15:52:49 +0000665 /**
666 * Calculates the width of the hotseat, changing spaces between the icons and removing icons if
667 * necessary.
668 */
669 public void recalculateHotseatWidthAndBorderSpace() {
670 if (!isScalableGrid) return;
671
672 int columns = inv.hotseatColumnSpan[mTypeIndex];
673 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
674 hotseatBorderSpace = calculateHotseatBorderSpace(hotseatWidthPx, /* numExtraBorder= */ 0);
Thales Lima9938c2f2022-07-25 14:38:16 +0100675 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
Thales Lima6a590062022-11-22 15:52:49 +0000676 // Spaces should be correct when the nav buttons are not inline
Thales Lima9938c2f2022-07-25 14:38:16 +0100677 if (!areNavButtonsInline) {
678 return;
679 }
680
Thales Lima6a590062022-11-22 15:52:49 +0000681 // The side space with inline buttons should be what is defined in InvariantDeviceProfile
Jon Mirandae17a9492023-03-08 16:42:20 -0800682 int sideSpacePx = inlineNavButtonsEndSpacingPx;
Thales Limaffc68b02023-01-09 16:20:23 +0000683 int maxHotseatWidthPx = availableWidthPx - sideSpacePx - hotseatBarEndOffset;
684 int maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
685 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000686 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100687
Thales Limaffc68b02023-01-09 16:20:23 +0000688 if (hotseatBorderSpace >= mMinHotseatIconSpacePx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100689 return;
690 }
691
692 // Border space can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000693 hotseatBorderSpace = mMinHotseatIconSpacePx;
Thales Lima6a590062022-11-22 15:52:49 +0000694 int requiredWidth = getHotseatRequiredWidth();
Thales Lima9938c2f2022-07-25 14:38:16 +0100695
696 // If there is an inline qsb, change its size
697 if (isQsbInline) {
Thales Limaffc68b02023-01-09 16:20:23 +0000698 hotseatQsbWidth -= requiredWidth - maxHotseatWidthPx;
699 if (hotseatQsbWidth >= mMinHotseatQsbWidthPx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100700 return;
701 }
702
703 // QSB can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000704 hotseatQsbWidth = mMinHotseatQsbWidthPx;
Thales Lima9938c2f2022-07-25 14:38:16 +0100705 }
706
Thales Limaffc68b02023-01-09 16:20:23 +0000707 maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
Thales Lima6a590062022-11-22 15:52:49 +0000708
Thales Lima9938c2f2022-07-25 14:38:16 +0100709 // If it still doesn't fit, start removing icons
710 do {
711 numShownHotseatIcons--;
Thales Limaffc68b02023-01-09 16:20:23 +0000712 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000713 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Limaffc68b02023-01-09 16:20:23 +0000714 } while (hotseatBorderSpace < mMinHotseatIconSpacePx && numShownHotseatIcons > 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100715
Thales Lima9938c2f2022-07-25 14:38:16 +0100716 }
717
Thales Lima78d00ad2021-09-30 11:29:06 +0100718 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100719 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100720 }
721
722 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100723 if (!isScalableGrid) {
724 return new Point(0, 0);
725 }
726
Thales Lima080d8902022-03-28 15:30:29 +0100727 int horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
728 int verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
Thales Lima78d00ad2021-09-30 11:29:06 +0100729
730 return new Point(horizontalSpacePx, verticalSpacePx);
731 }
732
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700733 public Info getDisplayInfo() {
734 return mInfo;
735 }
736
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700737 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800738 WindowBounds bounds = new WindowBounds(
739 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700740 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100741 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700742
743 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
744 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
745 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
746
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700747 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700748 .setWindowBounds(bounds)
Alex Chauab800f72022-12-13 17:46:06 +0000749 .setIsMultiDisplay(isMultiDisplay)
Alex Chau6ed408f2022-03-04 12:58:05 +0000750 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700751 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000752 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800753 }
754
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700755 public DeviceProfile copy(Context context) {
756 return toBuilder(context).build();
757 }
758
759 /**
760 * TODO: Move this to the builder as part of setMultiWindowMode
761 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700762 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700763 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700764 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700765 .setMultiWindowMode(true)
766 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800767
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800768 // We use these scales to measure and layout the widgets using their full invariant profile
769 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
770 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
771 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700772 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
773 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
774 profile = profile.toBuilder(context)
775 .setViewScaleProvider(i -> p)
776 .build();
777 }
778
779 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800780
Jon Miranda93e1f042016-11-11 14:13:04 -0800781 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700782 }
783
Adam Cohen63f1ec02014-08-12 09:23:13 -0700784 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400785 * Checks if there is enough space for labels on the workspace.
786 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700787 * It is important to call this method after the All Apps variables have been set.
788 */
Jon Miranda941375e2021-03-31 13:10:45 -0400789 private void hideWorkspaceLabelsIfNotEnoughSpace() {
790 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
791 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
792 - iconTextHeight;
793
794 // We want enough space so that the text is closer to its corresponding icon.
795 if (workspaceCellPaddingY < iconTextHeight) {
796 iconTextSizePx = 0;
797 iconDrawablePaddingPx = 0;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700798 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda941375e2021-03-31 13:10:45 -0400799 autoResizeAllAppsCells();
800 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700801 }
Jon Miranda1091e532017-07-21 13:31:50 -0700802
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700803 /**
804 * Re-computes the all-apps cell size to be independent of workspace
805 */
806 public void autoResizeAllAppsCells() {
Jon Miranda941375e2021-03-31 13:10:45 -0400807 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
808 int topBottomPadding = textHeight;
Jon Miranda1091e532017-07-21 13:31:50 -0700809 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
Jon Miranda941375e2021-03-31 13:10:45 -0400810 + textHeight + (topBottomPadding * 2);
Jon Miranda1091e532017-07-21 13:31:50 -0700811 }
812
Thales Limab7ef5692022-03-10 10:32:36 +0000813 private void updateAllAppsContainerWidth(Resources res) {
Pat Manning08610ca2022-04-05 21:03:16 +0100814 int cellLayoutHorizontalPadding =
815 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
Alex Chau27b39b92022-01-14 18:02:18 +0000816 if (isTablet) {
sfufa@google.comde013292021-09-21 18:22:44 -0700817 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
Thales Limab7ef5692022-03-10 10:32:36 +0000818 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Alex Chau27b39b92022-01-14 18:02:18 +0000819 + allAppsLeftRightPadding * 2;
820 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
sfufa@google.comde013292021-09-21 18:22:44 -0700821 } else {
822 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100823 desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding;
sfufa@google.comde013292021-09-21 18:22:44 -0700824 }
825 }
826
Thales Limae9273ea2023-01-26 12:33:52 +0000827 private void setupAllAppsStyle(Context context) {
828 TypedArray allAppsStyle;
829 if (inv.allAppsStyle != INVALID_RESOURCE_HANDLE) {
830 allAppsStyle = context.obtainStyledAttributes(inv.allAppsStyle,
831 R.styleable.AllAppsStyle);
832 } else {
833 allAppsStyle = context.obtainStyledAttributes(R.style.AllAppsStyleDefault,
834 R.styleable.AllAppsStyle);
835 }
836 allAppsLeftRightPadding = allAppsStyle.getDimensionPixelSize(
837 R.styleable.AllAppsStyle_horizontalPadding, 0);
838 allAppsStyle.recycle();
839 }
840
Jon Miranda228877d2021-02-09 11:05:00 -0500841 /**
842 * Returns the amount of extra (or unused) vertical space.
843 */
844 private int updateAvailableDimensions(Resources res) {
Alex Chaua68164d2022-12-15 16:16:03 +0000845 float invIconSizeDp = inv.iconSize[mTypeIndex];
846 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
847 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
848 iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
849
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700850 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800851
Pat Manning08610ca2022-04-05 21:03:16 +0100852 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -0500853
854 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +0100855 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +0000856 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -0500857 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500858 float scaleY = maxHeight / usedHeight;
859 boolean shouldScale = scaleY < 1f;
860
861 float scaleX = 1f;
862 if (isScalableGrid) {
863 // We scale to fit the cellWidth and cellHeight in the available space.
864 // The benefit of scalable grids is that we can get consistent aspect ratios between
865 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +0100866 float usedWidth =
867 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500868 // We do not subtract padding here, as we also scale the workspace padding if needed.
869 scaleX = availableWidthPx / usedWidth;
870 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700871 }
Jon Mirandae126d722021-02-25 10:45:20 -0500872
873 if (shouldScale) {
874 float scale = Math.min(scaleX, scaleY);
875 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +0100876 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -0500877 }
878
Jon Miranda228877d2021-02-09 11:05:00 -0500879 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700880 }
881
Pat Manninga2e14992022-04-22 11:29:17 +0100882 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +0100883 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
884 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
885 }
886
Pat Manninga2e14992022-04-22 11:29:17 +0100887 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +0000888 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +0100889 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
890 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -0500891 }
892
Jon Miranda6f7e9702019-09-16 14:44:14 -0700893 /**
894 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
895 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
896 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
897 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800898 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -0700899 // Icon scale should never exceed 1, otherwise pixellation may occur.
900 iconScale = Math.min(1f, scale);
901 cellScaleToFit = scale;
902
Jon Miranda18751b62017-07-31 17:25:27 -0700903 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800904 final boolean isVerticalLayout = isVerticalBarLayout();
Jon Mirandaab3c6812021-06-28 15:42:28 -0700905 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);
Thales Lima080d8902022-03-28 15:30:29 +0100906 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500907
908 if (isScalableGrid) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100909 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
910 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +0000911
912 if (cellWidthPx < iconSizePx) {
913 // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger.
914 int numColumns = getPanelCount() * inv.numColumns;
915 int numBorders = numColumns - 1;
916 int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns;
917 if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) {
918 cellWidthPx = iconSizePx;
919 cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders;
920 } else {
921 // If it still doesn't fit, set borderSpace to 0 and distribute the space for
922 // cellWidth, and reduce iconSize.
923 cellWidthPx = (cellWidthPx * numColumns
924 + cellLayoutBorderSpacePx.x * numBorders) / numColumns;
925 iconSizePx = Math.min(iconSizePx, cellWidthPx);
926 cellLayoutBorderSpacePx.x = 0;
927 }
928 }
929
930 int cellTextAndPaddingHeight =
931 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
932 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
933 if (cellHeightPx < cellContentHeight) {
934 // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight
935 // bigger.
936 int numBorders = inv.numRows - 1;
937 int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows;
938 if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) {
939 cellHeightPx = cellContentHeight;
940 cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders;
941 } else {
Alex Chau06f36e82023-01-06 10:50:54 +0000942 // If it still doesn't fit, set borderSpace to 0 to recover space.
Alex Chaube753132022-12-09 16:46:54 +0000943 cellHeightPx = (cellHeightPx * inv.numRows
944 + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows;
Alex Chaube753132022-12-09 16:46:54 +0000945 cellLayoutBorderSpacePx.y = 0;
Alex Chau06f36e82023-01-06 10:50:54 +0000946 // Reduce iconDrawablePaddingPx to make cellContentHeight smaller.
947 int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx;
948 if (cellContentWithoutPadding <= cellHeightPx) {
949 iconDrawablePaddingPx = cellContentHeight - cellHeightPx;
950 } else {
951 // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space,
952 // then proportional reduce iconSizePx and iconTextSizePx to fit.
953 iconDrawablePaddingPx = 0;
954 float ratio = cellHeightPx / (float) cellContentWithoutPadding;
955 iconSizePx = (int) (iconSizePx * ratio);
956 iconTextSizePx = (int) (iconTextSizePx * ratio);
957 }
958 cellTextAndPaddingHeight =
959 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +0000960 }
961 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
962 }
Jon Mirandae126d722021-02-25 10:45:20 -0500963 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +0100964 desiredWorkspaceHorizontalMarginPx =
965 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -0500966 } else {
Jon Mirandae126d722021-02-25 10:45:20 -0500967 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700968 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR)
969 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -0500970 + Utilities.calculateTextHeight(iconTextSizePx);
971 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
972 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
973 && !isMultiWindowMode) {
974 // Ensures that the label is closer to its corresponding icon. This is not an issue
975 // with vertical bar layout or multi-window mode since the issue is handled
976 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
977 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
978 iconDrawablePaddingPx = cellPaddingY;
979 }
Jon Miranda846455e2017-10-02 14:58:52 -0700980 }
Jon Miranda18751b62017-07-31 17:25:27 -0700981
Sunny Goyalae190ff2020-04-14 00:19:01 +0000982 // All apps
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500983 updateAllAppsIconSize(scale, res);
Winson Chungb3800242013-10-24 11:01:54 -0700984
Thales Limab8c05952022-05-23 16:58:38 +0100985 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700986
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700987 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -0700988 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
989 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Sunny Goyal6c304b12023-04-10 12:03:04 -0700990
991 // Update widget padding:
992 float minSpacing = pxFromDp(MIN_WIDGET_PADDING_DP, mMetrics);
993 if (cellLayoutBorderSpacePx.x < minSpacing
994 || cellLayoutBorderSpacePx.y < minSpacing) {
995 widgetPadding.left = widgetPadding.right =
996 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.x));
997 widgetPadding.top = widgetPadding.bottom =
998 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.y));
999 } else {
1000 widgetPadding.setEmpty();
1001 }
Winson Chung0f785722015-04-08 10:27:49 -07001002 }
1003
Thales Lima425f6822022-05-10 13:44:58 -03001004 /**
Thales Lima6a590062022-11-22 15:52:49 +00001005 * This method calculates the space between the icons to achieve a certain width.
Thales Lima425f6822022-05-10 13:44:58 -03001006 */
Thales Lima6a590062022-11-22 15:52:49 +00001007 private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) {
Thales Lima9938c2f2022-07-25 14:38:16 +01001008 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
Thales Limaffc68b02023-01-09 16:20:23 +00001009 int hotseatBorderSpacePx =
Thales Lima6a590062022-11-22 15:52:49 +00001010 (int) (hotseatWidthPx - hotseatIconsTotalPx)
1011 / (numShownHotseatIcons - 1 + numExtraBorder);
Thales Limaffc68b02023-01-09 16:20:23 +00001012 return Math.min(hotseatBorderSpacePx, mMaxHotseatIconSpacePx);
Thales Lima425f6822022-05-10 13:44:58 -03001013 }
1014
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001015
1016 /**
1017 * Updates the iconSize for allApps* variants.
1018 */
Brian Isganitisa9a78112022-05-23 18:11:47 -07001019 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +01001020 allAppsBorderSpacePx = new Point(
1021 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
1022 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001023 // AllApps cells don't have real space between cells,
1024 // so we add the border space to the cell height
Alex Chaube753132022-12-09 16:46:54 +00001025 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics)
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001026 + allAppsBorderSpacePx.y;
1027 // but width is just the cell,
1028 // the border is added in #updateAllAppsContainerWidth
Thales Lima080d8902022-03-28 15:30:29 +01001029 if (isScalableGrid) {
Alex Chaube753132022-12-09 16:46:54 +00001030 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1031 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001032 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001033 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001034
1035 if (allAppsCellWidthPx < allAppsIconSizePx) {
1036 // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to
1037 // make allAppsCellWidth bigger.
1038 int numBorders = inv.numAllAppsColumns - 1;
1039 int extraWidthRequired =
1040 (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns;
1041 if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) {
1042 allAppsCellWidthPx = allAppsIconSizePx;
1043 allAppsBorderSpacePx.x -= extraWidthRequired / numBorders;
1044 } else {
1045 // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space
1046 // for allAppsCellWidth, and reduce allAppsIconSize.
1047 allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns
1048 + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns;
1049 allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx);
1050 allAppsBorderSpacePx.x = 0;
1051 }
1052 }
1053
1054 int cellContentHeight = allAppsIconSizePx
1055 + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y;
1056 if (allAppsCellHeightPx < cellContentHeight) {
1057 // Increase allAppsCellHeight to fit its content.
1058 allAppsCellHeightPx = cellContentHeight;
1059 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001060 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001061 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
1062 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001063 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1064 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001065 allAppsIconDrawablePaddingPx =
1066 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001067 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001068 }
1069
Thales Limab7ef5692022-03-10 10:32:36 +00001070 updateAllAppsContainerWidth(res);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001071 if (isVerticalBarLayout()) {
1072 hideWorkspaceLabelsIfNotEnoughSpace();
1073 }
1074 }
1075
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001076 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001077 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001078
Thales Lima7eee74b2023-03-16 16:00:55 -03001079 // For usability we can't have the folder use the whole width of the screen
Sunny Goyal07b69292018-01-08 14:19:34 -08001080 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -08001081
Thales Lima7eee74b2023-03-16 16:00:55 -03001082 // Check if the folder fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -05001083 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Thales Lima7eee74b2023-03-16 16:00:55 -03001084 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx)
1085 + folderFooterHeightPx
1086 + folderContentPaddingTop;
1087 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001088 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -08001089
Thales Lima7eee74b2023-03-16 16:00:55 -03001090 // Check if the folder fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -05001091 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Thales Lima7eee74b2023-03-16 16:00:55 -03001092 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx)
1093 + folderContentPaddingLeftRight * 2;
1094 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001095 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -08001096
1097 float scale = Math.min(scaleX, scaleY);
1098 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001099 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001100 }
1101 }
1102
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001103 private void updateFolderCellSize(float scale, Resources res) {
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001104 float invIconSizeDp = inv.iconSize[mTypeIndex];
Sunny Goyal35c7b192021-04-20 16:51:10 -07001105 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001106 folderChildTextSizePx = pxFromSp(inv.iconTextSize[mTypeIndex], mMetrics, scale);
Thales Lima7eee74b2023-03-16 16:00:55 -03001107 folderLabelTextSizePx = Math.max(pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale),
Thales Limab35faed2022-09-05 16:30:01 -03001108 (int) (folderChildTextSizePx * folderLabelTextScale));
Jon Mirandabf7d8122016-11-03 15:29:29 -07001109
1110 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001111
Jon Miranda823da222021-03-23 08:08:45 -04001112 if (isScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001113 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
Thales Lima7eee74b2023-03-16 16:00:55 -03001114 folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale);
1115 folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale);
1116 } else {
1117 folderCellWidthPx = roundPxValueFromFloat(folderCellWidthPx * scale);
1118 folderCellHeightPx = roundPxValueFromFloat(folderCellHeightPx * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001119 }
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001120
Thales Lima7eee74b2023-03-16 16:00:55 -03001121 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
1122 folderCellLayoutBorderSpacePx = roundPxValueFromFloat(
1123 folderCellLayoutBorderSpacePx * scale);
1124 folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale);
1125
Thales Limab35faed2022-09-05 16:30:01 -03001126 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx;
Jon Miranda823da222021-03-23 08:08:45 -04001127 } else {
1128 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1129 * scale);
1130 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1131 * scale);
1132
1133 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1134 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Lima7eee74b2023-03-16 16:00:55 -03001135 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001136 folderContentPaddingLeftRight =
1137 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1138 folderFooterHeightPx =
Thales Lima7eee74b2023-03-16 16:00:55 -03001139 roundPxValueFromFloat(
1140 res.getDimensionPixelSize(R.dimen.folder_footer_height_default)
1141 * scale);
1142
Jon Miranda823da222021-03-23 08:08:45 -04001143 }
1144
Jonathan Miranda9ad87462017-07-26 17:41:02 +00001145 folderChildDrawablePaddingPx = Math.max(0,
1146 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001147 }
1148
Winson1f064272016-07-18 17:18:02 -07001149 public void updateInsets(Rect insets) {
1150 mInsets.set(insets);
1151 }
1152
Sunny Goyalae6e3182019-04-30 12:04:37 -07001153 /**
1154 * The current device insets. This is generally same as the insets being dispatched to
1155 * {@link Insettable} elements, but can differ if the element is using a different profile.
1156 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001157 public Rect getInsets() {
1158 return mInsets;
1159 }
1160
Sunny Goyal756cd262015-08-20 12:33:21 -07001161 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001162 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001163 }
1164
Sunny Goyal19ff7282021-04-22 10:12:54 -07001165 public Point getCellSize(Point result) {
1166 if (result == null) {
1167 result = new Point();
1168 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001169
Pat Manning25d53342022-05-10 09:58:49 +00001170 int shortcutAndWidgetContainerWidth =
1171 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1172 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1173 inv.numColumns);
1174 int shortcutAndWidgetContainerHeight =
1175 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1176 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1177 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001178 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001179 }
1180
1181 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001182 * Returns the left and right space on the cell, which is the cell width - icon size
1183 */
1184 public int getCellHorizontalSpace() {
1185 return getCellSize().x - iconSizePx;
1186 }
1187
1188 /**
Pat Manning25d53342022-05-10 09:58:49 +00001189 * Gets the number of panels within the workspace.
1190 */
1191 public int getPanelCount() {
1192 return isTwoPanels ? 2 : 1;
1193 }
1194
1195 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001196 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1197 * bottom of the screen.
1198 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001199 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1200 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001201 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001202 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001203 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001204 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001205 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001206 }
1207
1208 /**
1209 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1210 */
Pat Manning25d53342022-05-10 09:58:49 +00001211 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001212 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001213 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001214 }
1215
1216 /**
1217 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1218 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001219 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001220 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001221 return heightPx - (isVerticalBarLayout()
1222 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001223 }
1224
Pat Manningea5c1d22022-04-14 10:58:16 +01001225 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001226 * Gets the scale of the workspace for the spring-loaded edit state.
1227 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001228 public float getWorkspaceSpringLoadScale(Context context) {
1229 float scale =
1230 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1231 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001232 scale = Math.min(scale, 1f);
1233
Pat Manninge63dd252022-08-02 16:15:29 +01001234 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001235 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001236 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001237 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001238 if (scaledWorkspaceWidth > maxAvailableWidth) {
1239 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1240 }
1241 return scale;
1242 }
1243
Pat Manning25d53342022-05-10 09:58:49 +00001244 /**
1245 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1246 *
1247 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1248 * layouts have two Cell Layouts per workspace.
1249 */
1250 public int getCellLayoutWidth() {
1251 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001252 }
1253
Pat Manning25d53342022-05-10 09:58:49 +00001254 /**
1255 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1256 *
1257 * <p>This is the height of a Workspace, less its vertical padding.
1258 */
1259 public int getCellLayoutHeight() {
1260 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001261 }
1262
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001263 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001264 return new Point(workspacePadding.left + workspacePadding.right,
1265 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001266 }
1267
1268 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001269 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1270 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001271 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001272 private void updateWorkspacePadding() {
1273 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001274 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -08001275 padding.top = 0;
1276 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001277 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001278 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -07001279 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -07001280 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -07001281 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001282 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -07001283 }
Winson Chungb3800242013-10-24 11:01:54 -07001284 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001285 // Pad the bottom of the workspace with hotseat bar
1286 // and leave a bit of space in case a widget go all the way down
1287 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding
1288 + workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace
1289 - mInsets.bottom;
Pat Manning08610ca2022-04-05 21:03:16 +01001290 int paddingTop = workspaceTopPadding + (isScalableGrid ? 0 : edgeMarginPx);
1291 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001292
Pat Manning08610ca2022-04-05 21:03:16 +01001293 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001294 }
Pat Manning08610ca2022-04-05 21:03:16 +01001295 insetPadding(workspacePadding, cellLayoutPaddingPx);
1296 }
1297
1298 private void insetPadding(Rect paddings, Rect insets) {
1299 insets.left = Math.min(insets.left, paddings.left);
1300 paddings.left -= insets.left;
1301
1302 insets.top = Math.min(insets.top, paddings.top);
1303 paddings.top -= insets.top;
1304
1305 insets.right = Math.min(insets.right, paddings.right);
1306 paddings.right -= insets.right;
1307
1308 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1309 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001310 }
1311
Sunny Goyal57b22792021-05-25 14:35:01 -07001312 /**
1313 * Returns the padding for hotseat view
1314 */
1315 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001316 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001317 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001318 // The hotseat icons will be placed in the middle of the hotseat cells.
1319 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1320 // in vertical bar layout.
1321 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1322 // is set to account for that difference.
1323 float diffOverlapFactor = iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
Pat Manning08610ca2022-04-05 21:03:16 +01001324 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1325 - diffOverlapFactor), 0);
1326 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001327 + diffOverlapFactor), 0);
1328
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001329 if (isSeascape()) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001330 hotseatBarPadding.set(mInsets.left + hotseatBarSidePaddingStartPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001331 hotseatBarSidePaddingEndPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001332 } else {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001333 hotseatBarPadding.set(hotseatBarSidePaddingEndPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001334 mInsets.right + hotseatBarSidePaddingStartPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001335 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001336 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001337 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001338 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1339 int hotseatBarTopPadding =
1340 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001341
Thales Lima6a590062022-11-22 15:52:49 +00001342 int hotseatWidth = getHotseatRequiredWidth();
Helen Cheuke76291f2023-02-14 17:11:05 +00001343 int startSpacing;
1344 int endSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001345 // Hotseat aligns to the left with nav buttons
1346 if (hotseatBarEndOffset > 0) {
Jon Mirandae17a9492023-03-08 16:42:20 -08001347 startSpacing = inlineNavButtonsEndSpacingPx;
Helen Cheuke76291f2023-02-14 17:11:05 +00001348 endSpacing = availableWidthPx - hotseatWidth - startSpacing + hotseatBorderSpace;
1349 } else {
1350 startSpacing = (availableWidthPx - hotseatWidth) / 2;
1351 endSpacing = startSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001352 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001353 startSpacing += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001354
Helen Cheuke76291f2023-02-14 17:11:05 +00001355 hotseatBarPadding.top = hotseatBarTopPadding;
1356 hotseatBarPadding.bottom = hotseatBarBottomPadding;
Alex Chau51da2192022-05-20 13:32:10 +01001357 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001358 if (isRtl) {
Helen Cheuke76291f2023-02-14 17:11:05 +00001359 hotseatBarPadding.left = endSpacing;
1360 hotseatBarPadding.right = startSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001361 } else {
Helen Cheuke76291f2023-02-14 17:11:05 +00001362 hotseatBarPadding.left = startSpacing;
1363 hotseatBarPadding.right = endSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001364 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001365
Thales Lima425f6822022-05-10 13:44:58 -03001366 } else if (isScalableGrid) {
Alex Chau206ede92022-08-01 17:46:12 +01001367 int sideSpacing = (availableWidthPx - hotseatQsbWidth) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001368 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001369 0,
Thales Lima425f6822022-05-10 13:44:58 -03001370 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001371 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001372 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001373 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1374 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1375 // for this, we pad the left and right of the hotseat with half of the difference of a
1376 // workspace cell vs a hotseat cell.
1377 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001378 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001379 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001380 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001381 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1382 + mInsets.left,
1383 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001384 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001385 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001386 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001387 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001388 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001389 }
1390
Thales Lima9938c2f2022-07-25 14:38:16 +01001391 private int getAdditionalQsbSpace() {
1392 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1393 }
1394
1395 /**
1396 * Calculate how much space the hotseat needs to be shown completely
1397 */
1398 private int getHotseatRequiredWidth() {
1399 int additionalQsbSpace = getAdditionalQsbSpace();
1400 return iconSizePx * numShownHotseatIcons
Thales Lima6a590062022-11-22 15:52:49 +00001401 + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1))
Thales Lima9938c2f2022-07-25 14:38:16 +01001402 + additionalQsbSpace;
1403 }
1404
Winsonfadbe8f2016-07-22 16:35:37 -07001405 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001406 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1407 */
1408 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001409 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001410 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1411 } else if (isTaskbarPresent) { // QSB on top
1412 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001413 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001414 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001415 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001416 }
1417
Thales Limab8c05952022-05-23 16:58:38 +01001418 /**
1419 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1420 */
1421 private int getHotseatBarBottomPadding() {
1422 if (isTaskbarPresent) { // QSB on top or inline
1423 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001424 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001425 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001426 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001427 }
1428
1429 /**
Alex Chau51da2192022-05-20 13:32:10 +01001430 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1431 */
1432 public int getTaskbarOffsetY() {
Jon Miranda9c478b62023-03-23 21:38:49 -07001433 int taskbarIconBottomSpace = (taskbarHeight - iconSizePx) / 2;
Alex Chau51da2192022-05-20 13:32:10 +01001434 int launcherIconBottomSpace =
1435 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001436 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001437 }
1438
1439 /**
Alex Chaua2fc7642022-04-21 14:20:23 +01001440 * Returns the number of pixels required below OverviewActions excluding insets.
1441 */
1442 public int getOverviewActionsClaimedSpaceBelow() {
Alex Chaud67ddc42022-09-30 18:15:56 +01001443 if (isTaskbarPresent) {
Jon Miranda9c478b62023-03-23 21:38:49 -07001444 return taskbarHeight + taskbarBottomMargin * 2;
Alex Chaud67ddc42022-09-30 18:15:56 +01001445 }
1446 return mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001447 }
1448
1449 /** Gets the space that the overview actions will take, including bottom margin. */
1450 public int getOverviewActionsClaimedSpace() {
Pat Manning7b8f7662023-01-18 14:48:30 +00001451 int overviewActionsSpace = isTablet && FeatureFlags.ENABLE_GRID_ONLY_OVERVIEW.get()
1452 ? 0
1453 : (overviewActionsTopMarginPx + overviewActionsHeight);
1454 return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
Alex Chaua2fc7642022-04-21 14:20:23 +01001455 }
1456
1457 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001458 * Takes the View and return the scales of width and height depending on the DeviceProfile
1459 * specifications
1460 *
1461 * @param itemInfo The tag of the widget view
1462 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1463 * height
1464 */
1465 @NonNull
1466 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1467 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1468 }
1469
1470 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001471 * @return the bounds for which the open folders should be contained within
1472 */
1473 public Rect getAbsoluteOpenFolderBounds() {
1474 if (isVerticalBarLayout()) {
1475 // Folders should only appear right of the drop target bar and left of the hotseat
1476 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1477 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001478 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001479 mInsets.top + availableHeightPx);
1480 } else {
1481 // Folders should only appear below the drop target bar and above the hotseat
Jon Miranda9c478b62023-03-23 21:38:49 -07001482 int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001483 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001484 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001485 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001486 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001487 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001488 }
1489 }
1490
Jon Miranda228877d2021-02-09 11:05:00 -05001491 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1492 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001493 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001494
Jon Miranda228877d2021-02-09 11:05:00 -05001495 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1496 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001497 }
1498
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001499 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001500 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1501 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1502 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001503 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001504 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001505 return isLandscape && transposeLayoutWithOrientation;
1506 }
1507
Sunny Goyal59d086c2018-05-07 17:31:40 -07001508 /**
1509 * Updates orientation information and returns true if it has changed from the previous value.
1510 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001511 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001512 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001513 boolean isSeascape = DisplayController.INSTANCE.get(context)
1514 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001515 if (mIsSeascape != isSeascape) {
1516 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001517 // Hotseat changing sides requires updating workspace left/right paddings
1518 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001519 return true;
1520 }
1521 }
1522 return false;
1523 }
1524
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001525 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001526 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001527 }
1528
Sunny Goyal07b69292018-01-08 14:19:34 -08001529 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001530 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001531 }
1532
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001533 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001534 switch (containerType) {
1535 case CellLayout.WORKSPACE:
1536 return cellHeightPx;
1537 case CellLayout.FOLDER:
1538 return folderCellHeightPx;
1539 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001540 // The hotseat is the only container where the cell height is going to be
1541 // different from the content within that cell.
1542 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001543 default:
1544 // ??
1545 return 0;
1546 }
1547 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001548
Jon Miranda58561d42021-03-17 10:51:54 -04001549 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001550 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001551 }
1552
Alex Chaue818bcb2022-09-02 17:27:11 +01001553 private String dpPointFToString(String name, PointF value) {
1554 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
1555 }
1556
Pat Manning5f74bfd2022-07-20 12:08:54 +01001557 /** Dumps various DeviceProfile variables to the specified writer. */
1558 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04001559 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001560 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001561
1562 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001563 writer.println(prefix + "\tisPhone:" + isPhone);
1564 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1565 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001566 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001567
1568 writer.println(prefix + "\tisLandscape:" + isLandscape);
1569 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001570 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001571
1572 writer.println(prefix + pxToDpStr("windowX", windowX));
1573 writer.println(prefix + pxToDpStr("windowY", windowY));
1574 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1575 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001576 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1577 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001578 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1579 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1580 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1581 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001582
1583 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1584
Thales Limaec5abba2023-04-05 16:33:50 +01001585 writer.println(prefix + "\tisResponsiveGrid:" + isResponsiveGrid);
Jon Miranda58561d42021-03-17 10:51:54 -04001586 writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
1587
Thales Lima83bedbf2021-10-05 17:47:39 +01001588 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001589 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1590 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1591 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001592
Alex Chaue818bcb2022-09-02 17:27:11 +01001593 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07001594
Jon Miranda58561d42021-03-17 10:51:54 -04001595 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1596 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1597
1598 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1599 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1600
Thales Lima83bedbf2021-10-05 17:47:39 +01001601 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1602 cellLayoutBorderSpacePx.x));
1603 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1604 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001605 writer.println(
1606 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
1607 writer.println(
1608 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
1609 writer.println(
1610 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01001611 writer.println(
1612 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01001613
Jon Miranda58561d42021-03-17 10:51:54 -04001614 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1615 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1616 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1617
Helen Cheuk599109b2023-02-23 17:15:39 +00001618 writer.println(prefix + "\tinv.numFolderRows: " + inv.numFolderRows);
1619 writer.println(prefix + "\tinv.numFolderColumns: " + inv.numFolderColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001620 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1621 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1622 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1623 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1624 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1625 folderChildDrawablePaddingPx));
Thales Limab35faed2022-09-05 16:30:01 -03001626 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx",
1627 folderCellLayoutBorderSpacePx));
Thales Limaa08a4432022-08-09 09:55:17 +01001628 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
1629 folderContentPaddingLeftRight));
1630 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03001631 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001632
Alex Chaue0227552022-04-06 19:44:43 +01001633 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001634 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
1635 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
1636 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
1637 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01001638
1639 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
1640 writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001641 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
1642 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04001643 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1644 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1645 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1646 allAppsIconDrawablePaddingPx));
1647 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001648 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001649 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
1650 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001651 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau62572c02022-07-25 18:36:37 +00001652 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
Alex Chau27b39b92022-01-14 18:02:18 +00001653 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001654
1655 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03001656 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04001657 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00001658 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Jon Miranda58561d42021-03-17 10:51:54 -04001659 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
1660 hotseatBarSidePaddingStartPx));
1661 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
1662 hotseatBarSidePaddingEndPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001663 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01001664 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
1665 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01001666 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
1667 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001668 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
1669 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
1670 hotseatLayoutPadding.top));
1671 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
1672 hotseatLayoutPadding.bottom));
1673 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
1674 hotseatLayoutPadding.left));
1675 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
1676 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001677 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001678 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001679 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01001680 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001681
1682 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001683 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda9c478b62023-03-23 21:38:49 -07001684 writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight));
1685 writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight));
1686 writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin));
1687 writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001688
Thales Lima83bedbf2021-10-05 17:47:39 +01001689 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1690 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001691 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
1692 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
1693 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00001694 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001695
Jon Mirandaab3c6812021-06-28 15:42:28 -07001696 writer.println(prefix + pxToDpStr("iconScale", iconScale));
1697 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04001698 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00001699 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001700
Thales Lima171ee662022-11-22 15:52:49 +00001701 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04001702 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
1703 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00001704
1705 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00001706 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
1707 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
1708 overviewTaskIconDrawableSizePx));
1709 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
1710 overviewTaskIconDrawableSizeGridPx));
1711 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
1712 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01001713 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
1714 overviewActionsTopMarginPx));
1715 writer.println(prefix + pxToDpStr("overviewActionsHeight",
1716 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00001717 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
1718 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00001719 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
1720 overviewActionsButtonSpacing));
1721 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
1722 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
1723 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01001724
Alex Chau62572c02022-07-25 18:36:37 +00001725 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001726 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00001727 writer.println(
1728 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001729
Pat Manning5f74bfd2022-07-20 12:08:54 +01001730 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
1731 getCellLayoutSpringLoadShrunkTop()));
1732 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
1733 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01001734 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
1735 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001736 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
1737 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01001738 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
1739 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Jon Miranda58561d42021-03-17 10:51:54 -04001740 }
1741
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00001742 /** Returns a reduced representation of this DeviceProfile. */
1743 public String toSmallString() {
1744 return "isTablet:" + isTablet + ", "
1745 + "isMultiDisplay:" + isMultiDisplay + ", "
1746 + "widthPx:" + widthPx + ", "
1747 + "heightPx:" + heightPx + ", "
1748 + "insets:" + mInsets + ", "
1749 + "rotationHint:" + rotationHint;
1750 }
1751
Alex Chaua6907dc2022-03-18 15:24:07 +00001752 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07001753 Configuration config = new Configuration(c.getResources().getConfiguration());
1754 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03001755 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00001756 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07001757 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07001758 }
Sunny Goyalfde55052018-02-01 14:46:13 -08001759
1760 /**
1761 * Callback when a component changes the DeviceProfile associated with it, as a result of
1762 * configuration change
1763 */
1764 public interface OnDeviceProfileChangeListener {
1765
1766 /**
1767 * Called when the device profile is reassigned. Note that for layout and measurements, it
1768 * is sufficient to listen for inset changes. Use this callback when you need to perform
1769 * a one time operation.
1770 */
1771 void onDeviceProfileChanged(DeviceProfile dp);
1772 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001773
Sihua Mae04aa202022-07-18 12:43:56 -07001774 /**
1775 * Handler that deals with ItemInfo of the views for the DeviceProfile
1776 */
1777 @FunctionalInterface
1778 public interface ViewScaleProvider {
1779 /**
1780 * Get the scales from the view
1781 *
1782 * @param itemInfo The tag of the widget view
1783 * @return PointF instance containing the scale information, or null if using the default
1784 * app widget scale of this device profile.
1785 */
1786 @NonNull
1787 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
1788 }
1789
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001790 public static class Builder {
1791 private Context mContext;
1792 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07001793 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001794
Sunny Goyal19ff7282021-04-22 10:12:54 -07001795 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00001796 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001797
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001798 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001799 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00001800 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07001801 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001802
Sunny Goyal65190ae2022-08-02 14:16:26 -07001803 private SparseArray<DotRenderer> mDotRendererCache;
1804
Jon Miranda2b25ded2023-02-02 14:48:45 -08001805 private Consumer<DeviceProfile> mOverrideProvider;
1806
Sunny Goyalfd58da62020-08-11 12:06:49 -07001807 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001808 mContext = context;
1809 mInv = inv;
1810 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001811 }
1812
1813 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1814 mIsMultiWindowMode = isMultiWindowMode;
1815 return this;
1816 }
1817
Alex Chauab800f72022-12-13 17:46:06 +00001818 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
1819 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001820 return this;
1821 }
1822
Sunny Goyal65190ae2022-08-02 14:16:26 -07001823 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
1824 mDotRendererCache = dotRendererCache;
1825 return this;
1826 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07001827
1828 public Builder setWindowBounds(WindowBounds bounds) {
1829 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07001830 return this;
1831 }
1832
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001833 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1834 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1835 return this;
1836 }
1837
Alex Chau6ed408f2022-03-04 12:58:05 +00001838 public Builder setGestureMode(boolean isGestureMode) {
1839 mIsGestureMode = isGestureMode;
1840 return this;
1841 }
1842
Jon Miranda2b25ded2023-02-02 14:48:45 -08001843 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
1844 mOverrideProvider = overrideProvider;
1845 return this;
1846 }
1847
Sihua Mae04aa202022-07-18 12:43:56 -07001848 /**
1849 * Set the viewScaleProvider for the builder
1850 *
1851 * @param viewScaleProvider The viewScaleProvider to be set for the
Thales Limae9273ea2023-01-26 12:33:52 +00001852 * DeviceProfile
Sihua Mae04aa202022-07-18 12:43:56 -07001853 * @return This builder
1854 */
1855 @NonNull
1856 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
1857 mViewScaleProvider = viewScaleProvider;
1858 return this;
1859 }
1860
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001861 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001862 if (mWindowBounds == null) {
1863 throw new IllegalArgumentException("Window bounds not set");
1864 }
1865 if (mTransposeLayoutWithOrientation == null) {
1866 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
1867 }
Alex Chau6ed408f2022-03-04 12:58:05 +00001868 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01001869 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00001870 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001871 if (mDotRendererCache == null) {
1872 mDotRendererCache = new SparseArray<>();
1873 }
Sihua Mae04aa202022-07-18 12:43:56 -07001874 if (mViewScaleProvider == null) {
1875 mViewScaleProvider = DEFAULT_PROVIDER;
1876 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08001877 if (mOverrideProvider == null) {
1878 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
1879 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001880 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00001881 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jon Miranda2b25ded2023-02-02 14:48:45 -08001882 mIsGestureMode, mViewScaleProvider, mOverrideProvider);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001883 }
1884 }
1885
Winson Chungb3800242013-10-24 11:01:54 -07001886}