blob: 86c9f1617e5fc34c530b6637cef9ee499df68845 [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;
Alex Chau206ede92022-08-01 17:46:12 +010070
Sihua Mae04aa202022-07-18 12:43:56 -070071 public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f);
72 public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE;
Jon Miranda2b25ded2023-02-02 14:48:45 -080073 public static final Consumer<DeviceProfile> DEFAULT_DIMENSION_PROVIDER = dp -> {};
Sihua Mae04aa202022-07-18 12:43:56 -070074
Sunny Goyal57b22792021-05-25 14:35:01 -070075 // Ratio of empty space, qsb should take up to appear visually centered.
Pratyush9afe1ea2021-10-13 11:13:27 +000076 private final float mQsbCenterFactor;
Sunny Goyal1890f672020-04-30 12:28:00 -070077
Adam Cohen2e6da152015-05-06 11:42:25 -070078 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070079 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070080 private final DisplayMetrics mMetrics;
Winson Chungbe876472014-05-14 14:15:20 -070081
Sunny Goyalc6205602015-05-21 20:46:33 -070082 // Device properties
83 public final boolean isTablet;
Sunny Goyalc6205602015-05-21 20:46:33 -070084 public final boolean isPhone;
85 public final boolean transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +000086 public final boolean isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -070087 public final boolean isTwoPanels;
Thales Limaa1012902022-01-13 17:58:42 +000088 public final boolean isQsbInline;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -070089
Sunny Goyalc6205602015-05-21 20:46:33 -070090 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -070091 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -080092 public final boolean isMultiWindowMode;
Alex Chau6ed408f2022-03-04 12:58:05 +000093 public final boolean isGestureMode;
Sunny Goyald70e75a2018-02-22 10:07:32 -080094
Sunny Goyal0addbf02020-04-28 14:17:35 -070095 public final int windowX;
96 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -070097 public final int widthPx;
98 public final int heightPx;
99 public final int availableWidthPx;
100 public final int availableHeightPx;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800101 public final int rotationHint;
Jon Mirandabba64512019-03-27 10:54:17 -0700102
103 public final float aspectRatio;
104
Jon Mirandae126d722021-02-25 10:45:20 -0500105 public final boolean isScalableGrid;
Thales Lima83bedbf2021-10-05 17:47:39 +0100106 private final int mTypeIndex;
Jon Mirandae126d722021-02-25 10:45:20 -0500107
Tony Wickhamd6b40372015-09-23 18:37:57 -0700108 /**
109 * The maximum amount of left/right workspace padding as a percentage of the screen width.
110 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
111 * 7% of the screen width can be used as right padding.
112 */
113 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -0700114
Jon Miranda3f9bab22017-07-28 14:50:17 -0700115 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700116 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda80dda302021-07-28 14:14:59 -0700117 private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252;
118 private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700119
Sunny Goyalc6205602015-05-21 20:46:33 -0700120 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +0100121 public final int desiredWorkspaceHorizontalMarginOriginalPx;
122 public int desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100123 public int gridVisualizationPaddingX;
124 public int gridVisualizationPaddingY;
Thales Lima78d00ad2021-09-30 11:29:06 +0100125 public Point cellLayoutBorderSpaceOriginalPx;
126 public Point cellLayoutBorderSpacePx;
Pat Manning08610ca2022-04-05 21:03:16 +0100127 public Rect cellLayoutPaddingPx = new Rect();
128
Sunny Goyalc6205602015-05-21 20:46:33 -0700129 public final int edgeMarginPx;
Alex Chau0c4e11b2022-07-08 18:41:36 +0100130 public final float workspaceContentScale;
Alex Chau906d8822022-05-23 10:42:25 +0100131 public final int workspaceSpringLoadedMinNextPageVisiblePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700132
Jon Miranda58561d42021-03-17 10:51:54 -0400133 private final int extraSpace;
Thales Lima171ee662022-11-22 15:52:49 +0000134 private int maxEmptySpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500135 public int workspaceTopPadding;
136 public int workspaceBottomPadding;
137
Tony Wickham5edf9e22020-03-27 20:06:52 -0700138 // Workspace page indicator
139 public final int workspacePageIndicatorHeight;
140 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700141
Sunny Goyalc6205602015-05-21 20:46:33 -0700142 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400143 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700144 public int iconSizePx;
145 public int iconTextSizePx;
146 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700147 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -0700148
Jon Mirandaab3c6812021-06-28 15:42:28 -0700149 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800150 public int cellWidthPx;
151 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700152 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800153
Jon Mirandae126d722021-02-25 10:45:20 -0500154 public int cellYPaddingPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500155
Sunny Goyalc6205602015-05-21 20:46:33 -0700156 // Folder
Jon Mirandae126d722021-02-25 10:45:20 -0500157 public float folderLabelTextScale;
158 public int folderLabelTextSizePx;
Thales Limab35faed2022-09-05 16:30:01 -0300159 public int folderFooterHeightPx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700160 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700161 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700162
Jon Mirandae126d722021-02-25 10:45:20 -0500163 // Folder content
Thales Limab35faed2022-09-05 16:30:01 -0300164 public int folderCellLayoutBorderSpacePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500165 public int folderContentPaddingLeftRight;
166 public int folderContentPaddingTop;
167
Jon Mirandabf7d8122016-11-03 15:29:29 -0700168 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700169 public int folderCellWidthPx;
170 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700171
172 // Folder child
173 public int folderChildIconSizePx;
174 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700175 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700176
Sunny Goyalc6205602015-05-21 20:46:33 -0700177 // Hotseat
Thales Lima9938c2f2022-07-25 14:38:16 +0100178 public int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700179 public int hotseatCellHeightPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100180 public final boolean areNavButtonsInline;
Jon Miranda18751b62017-07-31 17:25:27 -0700181 // In portrait: size = height, in landscape: size = width
182 public int hotseatBarSizePx;
Thales Limab8c05952022-05-23 16:58:38 +0100183 public int hotseatBarBottomSpacePx;
Pat Manning26f70f72022-07-07 13:50:39 +0100184 public int hotseatBarEndOffset;
Thales Limab8c05952022-05-23 16:58:38 +0100185 public int hotseatQsbSpace;
Pat Manningde25c0d2022-04-05 19:11:26 +0100186 public int springLoadedHotseatBarTopMarginPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700187 // Start is the side next to the nav bar, end is the side next to the workspace
188 public final int hotseatBarSidePaddingStartPx;
189 public final int hotseatBarSidePaddingEndPx;
Alex Chau206ede92022-08-01 17:46:12 +0100190 public int hotseatQsbWidth; // only used when isQsbInline
Sunny Goyal57b22792021-05-25 14:35:01 -0700191 public final int hotseatQsbHeight;
Thales Limab8c05952022-05-23 16:58:38 +0100192 public final int hotseatQsbVisualHeight;
193 private final int hotseatQsbShadowHeight;
Thales Limadd027342022-01-07 12:54:37 +0000194 public int hotseatBorderSpace;
Thales Limaffc68b02023-01-09 16:20:23 +0000195 private final int mMinHotseatIconSpacePx;
196 private final int mMinHotseatQsbWidthPx;
197 private final int mMaxHotseatIconSpacePx;
Jon Mirandae17a9492023-03-08 16:42:20 -0800198 public final int inlineNavButtonsEndSpacingPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700199
Alex Chau3d2c0622022-09-01 21:28:14 +0100200 // Bottom sheets
201 public int bottomSheetTopPadding;
202 public int bottomSheetOpenDuration;
203 public int bottomSheetCloseDuration;
204 public float bottomSheetWorkspaceScale;
205 public float bottomSheetDepth;
206
Sunny Goyalc6205602015-05-21 20:46:33 -0700207 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000208 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000209 public int allAppsShiftRange;
210 public int allAppsTopPadding;
Alex Chau3d2c0622022-09-01 21:28:14 +0100211 public int allAppsOpenDuration;
212 public int allAppsCloseDuration;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700213 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700214 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700215 public int allAppsIconSizePx;
216 public int allAppsIconDrawablePaddingPx;
sfufa@google.comde013292021-09-21 18:22:44 -0700217 public int allAppsLeftRightPadding;
Alex Chau27b39b92022-01-14 18:02:18 +0000218 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700219 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700220 public float allAppsIconTextSizePx;
221
Zak Cohen334efeb2021-03-19 16:42:07 -0700222 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700223 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000224 public int overviewTaskIconSizePx;
Alex Chauac9df382021-08-02 19:08:41 +0100225 public int overviewTaskIconDrawableSizePx;
226 public int overviewTaskIconDrawableSizeGridPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000227 public int overviewTaskThumbnailTopMarginPx;
Alex Chau19c6eca2022-03-10 20:12:56 +0000228 public final int overviewActionsHeight;
Alex Chaua2fc7642022-04-21 14:20:23 +0100229 public final int overviewActionsTopMarginPx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000230 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100231 public int overviewPageSpacing;
232 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000233 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700234
Jeremy Sim0ac47082022-10-10 13:59:40 -0700235 // Split staging
236 public int splitPlaceholderInset;
237
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800238 // Widgets
Sihua Mae04aa202022-07-18 12:43:56 -0700239 private final ViewScaleProvider mViewScaleProvider;
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800240
Sunny Goyal47328fd2016-05-25 18:56:41 -0700241 // Drop Target
242 public int dropTargetBarSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100243 public int dropTargetBarTopMarginPx;
244 public int dropTargetBarBottomMarginPx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100245 public int dropTargetDragPaddingPx;
246 public int dropTargetTextSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100247 public int dropTargetHorizontalPaddingPx;
248 public int dropTargetVerticalPaddingPx;
249 public int dropTargetGapPx;
Alex Chau5b019302022-05-23 10:42:25 +0100250 public int dropTargetButtonWorkspaceEdgeGapPx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700251
Winson1f064272016-07-18 17:18:02 -0700252 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800253 private final Rect mInsets = new Rect();
254 public final Rect workspacePadding = new Rect();
Jon Miranda0bd63d12019-03-06 17:29:29 -0800255 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700256 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700257
Tony Wickhamf34bee82018-12-03 18:11:39 -0800258 // Notification dots
Sunny Goyal65190ae2022-08-02 14:16:26 -0700259 public final DotRenderer mDotRendererWorkSpace;
260 public final DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800261
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100262 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800263 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000264 // Whether Taskbar will inset the bottom of apps by taskbarSize.
265 public boolean isTaskbarPresentInApps;
Jon Miranda9c478b62023-03-23 21:38:49 -0700266 public final int taskbarHeight;
267 public final int stashedTaskbarHeight;
268 public final int taskbarBottomMargin;
269 public final int taskbarIconSize;
Jon Miranda04f05102023-04-04 12:16:31 -0700270 // If true, used to layout taskbar in 3 button navigation mode.
271 public final boolean startAlignTaskbar;
Tony Wickham15883892021-02-12 11:24:40 -0800272
Alex Chaua02eddc2021-04-29 00:36:06 +0100273 // DragController
274 public int flingToDeleteThresholdVelocity;
275
Vinit Nayak17c4b332021-08-05 12:54:58 -0700276 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700277 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal65190ae2022-08-02 14:16:26 -0700278 SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
Alex Chauab800f72022-12-13 17:46:06 +0000279 boolean transposeLayoutWithOrientation, boolean isMultiDisplay, boolean isGestureMode,
Jon Miranda2b25ded2023-02-02 14:48:45 -0800280 @NonNull final ViewScaleProvider viewScaleProvider,
281 @NonNull final Consumer<DeviceProfile> dimensionOverrideProvider) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700282
Adam Cohen2e6da152015-05-06 11:42:25 -0700283 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700284 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800285 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500286 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +0000287 this.isMultiDisplay = isMultiDisplay;
Alex Chau6ed408f2022-03-04 12:58:05 +0000288 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700289 windowX = windowBounds.bounds.left;
290 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800291 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100292 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700293
Jon Mirandae126d722021-02-25 10:45:20 -0500294 isScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000295 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700296 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000297 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700298 isPhone = !isTablet;
Alex Chauab800f72022-12-13 17:46:06 +0000299 isTwoPanels = isTablet && isMultiDisplay;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800300 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700301
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000302 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000303 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700304 ? Configuration.ORIENTATION_LANDSCAPE
305 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000306 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700307 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000308 mMetrics = res.getDisplayMetrics();
309
310 // Determine sizes.
311 widthPx = windowBounds.bounds.width();
312 heightPx = windowBounds.bounds.height();
313 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100314 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000315
316 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
317 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
318 mQsbCenterFactor = res.getFloat(R.dimen.qsb_center_factor);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700319
Thales Lima83bedbf2021-10-05 17:47:39 +0100320 if (isTwoPanels) {
321 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000322 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100323 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000324 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100325 }
326 } else {
327 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000328 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100329 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000330 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100331 }
332 }
333
Jon Miranda9c478b62023-03-23 21:38:49 -0700334 if (DisplayController.isTransientTaskbar(context)) {
335 float invTransientIconSizeDp = inv.transientTaskbarIconSize[mTypeIndex];
336 taskbarIconSize = pxFromDp(invTransientIconSizeDp, mMetrics);
337 taskbarHeight = taskbarIconSize
338 + (2 * res.getDimensionPixelSize(R.dimen.transient_taskbar_padding));
339 stashedTaskbarHeight =
340 res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_height);
341 taskbarBottomMargin =
342 res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin);
Jon Miranda04f05102023-04-04 12:16:31 -0700343 startAlignTaskbar = false;
Jon Miranda9c478b62023-03-23 21:38:49 -0700344 } else {
345 taskbarIconSize = pxFromDp(ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size),
346 mMetrics);
347 taskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_size);
348 stashedTaskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
349 taskbarBottomMargin = 0;
Jon Miranda04f05102023-04-04 12:16:31 -0700350 startAlignTaskbar = inv.startAlignTaskbar[mTypeIndex];
Tony Wickham15883892021-02-12 11:24:40 -0800351 }
Tony Wickham15883892021-02-12 11:24:40 -0800352
Winson Chungb3800242013-10-24 11:01:54 -0700353 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100354 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700355
Thales Limad90faab2021-09-21 17:18:47 +0100356 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
357 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100358 gridVisualizationPaddingX = res.getDimensionPixelSize(
359 R.dimen.grid_visualization_horizontal_cell_spacing);
360 gridVisualizationPaddingY = res.getDimensionPixelSize(
361 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500362
Alex Chaue0227552022-04-06 19:44:43 +0100363 bottomSheetTopPadding = mInsets.top // statusbar height
Andras Kloczl142b0542022-03-09 21:26:02 +0000364 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
365 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
Alex Chau3d2c0622022-09-01 21:28:14 +0100366 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
367 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
368 if (isTablet) {
369 bottomSheetWorkspaceScale = workspaceContentScale;
Alex Chauab800f72022-12-13 17:46:06 +0000370 if (isMultiDisplay && !ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH.get()) {
371 // TODO(b/259893832): Revert to use maxWallpaperScale to calculate bottomSheetDepth
372 // when screen recorder bug is fixed.
373 bottomSheetDepth = 1f;
374 } else {
375 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
376 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
377 // When depth is 1, wallpaper zoom is set to 1.
378 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
379 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
380 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
381 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
382 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100383 } else {
384 bottomSheetWorkspaceScale = 1f;
385 bottomSheetDepth = 0f;
386 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000387
Jon Mirandae126d722021-02-25 10:45:20 -0500388 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
Thales Limab35faed2022-09-05 16:30:01 -0300389
Thales Lima7eee74b2023-03-16 16:00:55 -0300390 if (isScalableGrid && inv.folderStyle != INVALID_RESOURCE_HANDLE) {
Thales Limab35faed2022-09-05 16:30:01 -0300391 TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
Thales Limad852d652023-01-17 14:01:13 +0000392 R.styleable.FolderStyle);
Thales Limab35faed2022-09-05 16:30:01 -0300393 // These are re-set in #updateFolderCellSize if the grid is not scalable
394 folderCellHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000395 R.styleable.FolderStyle_folderCellHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300396 folderCellWidthPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000397 R.styleable.FolderStyle_folderCellWidth, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300398
399 folderContentPaddingTop = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000400 R.styleable.FolderStyle_folderTopPadding, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300401 folderCellLayoutBorderSpacePx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000402 R.styleable.FolderStyle_folderBorderSpace, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300403 folderFooterHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000404 R.styleable.FolderStyle_folderFooterHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300405 folderStyle.recycle();
406 } else {
407 folderCellLayoutBorderSpacePx = 0;
Thales Lima7eee74b2023-03-16 16:00:55 -0300408 folderFooterHeightPx = res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Thales Limab35faed2022-09-05 16:30:01 -0300409 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
410 }
Jon Mirandae126d722021-02-25 10:45:20 -0500411
Thales Lima78d00ad2021-09-30 11:29:06 +0100412 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv);
Thales Limab35faed2022-09-05 16:30:01 -0300413 cellLayoutBorderSpaceOriginalPx = new Point(cellLayoutBorderSpacePx);
Thales Lima85c942f2021-12-31 13:04:20 +0000414 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000415 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
416 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Thales Limae9273ea2023-01-26 12:33:52 +0000417 setupAllAppsStyle(context);
Jon Mirandae126d722021-02-25 10:45:20 -0500418
Tony Wickham5edf9e22020-03-27 20:06:52 -0700419 workspacePageIndicatorHeight = res.getDimensionPixelSize(
420 R.dimen.workspace_page_indicator_height);
421 mWorkspacePageIndicatorOverlapWorkspace =
422 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700423
Thales Limad852d652023-01-17 14:01:13 +0000424 TypedArray cellStyle;
425 if (inv.cellStyle != INVALID_RESOURCE_HANDLE) {
426 cellStyle = context.obtainStyledAttributes(inv.cellStyle,
427 R.styleable.CellStyle);
428 } else {
429 cellStyle = context.obtainStyledAttributes(R.style.CellStyleDefault,
430 R.styleable.CellStyle);
431 }
432 iconDrawablePaddingOriginalPx = cellStyle.getDimensionPixelSize(
433 R.styleable.CellStyle_iconDrawablePadding, 0);
434 cellStyle.recycle();
Alex Chaua02eddc2021-04-29 00:36:06 +0100435
Sunny Goyal47328fd2016-05-25 18:56:41 -0700436 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100437 dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
438 dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100439 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
440 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100441 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
442 R.dimen.drop_target_button_drawable_horizontal_padding);
443 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
444 R.dimen.drop_target_button_drawable_vertical_padding);
445 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100446 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
447 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100448
Alex Chau906d8822022-05-23 10:42:25 +0100449 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
450 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700451
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700452 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700453
Thales Limaa1012902022-01-13 17:58:42 +0000454 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100455 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
456 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
457
Thales Lima12d0eff2022-03-25 17:06:11 +0000458 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
459 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
460 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
461 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
462 && hotseatQsbHeight > 0;
Thales Lima6a590062022-11-22 15:52:49 +0000463 isQsbInline = isScalableGrid && inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000464
Thales Lima425f6822022-05-10 13:44:58 -0300465 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100466 numShownHotseatIcons =
467 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000468
Sunny Goyal19ff7282021-04-22 10:12:54 -0700469 numShownAllAppsColumns =
470 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100471
472 int hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
473 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
474 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
475 // Have a little space between the inset and the QSB
476 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
477 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
478
479 // Only change the spaces if there is space
480 if (availableSpace > 0) {
481 // Make sure there is enough space between hotseat/QSB and QSB/navBar
482 if (availableSpace < minQsbMargin * 2) {
483 minQsbMargin = availableSpace / 2;
484 hotseatQsbSpace = minQsbMargin;
485 } else {
486 hotseatQsbSpace -= minQsbMargin;
487 }
488 }
489 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
490
Thales Limaa1012902022-01-13 17:58:42 +0000491 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100492 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
Thales Limaa1012902022-01-13 17:58:42 +0000493 }
Thales Lima425f6822022-05-10 13:44:58 -0300494
Pat Manningde25c0d2022-04-05 19:11:26 +0100495 springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
496 R.dimen.spring_loaded_hotseat_top_margin);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700497 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800498 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700499 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700500 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Thales Limab8c05952022-05-23 16:58:38 +0100501 updateHotseatSizes(pxFromDp(inv.iconSize[INDEX_DEFAULT], mMetrics));
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700502 if (areNavButtonsInline && !isPhone) {
Jon Mirandae17a9492023-03-08 16:42:20 -0800503 inlineNavButtonsEndSpacingPx =
Thales Limaffc68b02023-01-09 16:20:23 +0000504 res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing);
Pat Manning26f70f72022-07-07 13:50:39 +0100505 /*
506 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700507 * Spacing between nav buttons +
Thales Lima6a590062022-11-22 15:52:49 +0000508 * Space at the end for contextual buttons
Pat Manning26f70f72022-07-07 13:50:39 +0100509 */
510 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700511 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
Jon Mirandae17a9492023-03-08 16:42:20 -0800512 + inlineNavButtonsEndSpacingPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100513 } else {
Jon Mirandae17a9492023-03-08 16:42:20 -0800514 inlineNavButtonsEndSpacingPx = 0;
Pat Manning26f70f72022-07-07 13:50:39 +0100515 hotseatBarEndOffset = 0;
516 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700517
Alex Chau635b3ab2022-01-26 16:49:10 +0000518 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chau5fd9d492021-07-22 17:27:11 +0100519 overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100520 overviewTaskIconDrawableSizePx =
521 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
522 overviewTaskIconDrawableSizeGridPx =
523 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700524 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx;
Jeremy Sim3c2c3f12022-05-16 20:37:43 -0700525 overviewActionsTopMarginPx = res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000526 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
527 overviewActionsButtonSpacing = res.getDimensionPixelSize(
528 R.dimen.overview_actions_button_spacing);
Alex Chau19c6eca2022-03-10 20:12:56 +0000529 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700530 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000531 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700532
Jeremy Sim0ac47082022-10-10 13:59:40 -0700533 splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset);
534
Jon Miranda2ed276e2017-06-29 11:36:34 -0700535 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400536 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700537
Jon Miranda2ed276e2017-06-29 11:36:34 -0700538 // Now that we have all of the variables calculated, we can tune certain sizes.
Thales Limaae0d7ef2022-11-16 15:53:43 +0000539 if (isScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400540 // Paddings were created assuming no scaling, so we first unscale the extra space.
Jon Mirandaab3c6812021-06-28 15:42:28 -0700541 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
Thales Limaae0d7ef2022-11-16 15:53:43 +0000542 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
543 DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
Thales Lima171ee662022-11-22 15:52:49 +0000544 maxEmptySpace = padding.getMaxEmptySpacePx();
Jon Miranda228877d2021-02-09 11:05:00 -0500545
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400546 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
547 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
548 int paddingHotseatBottom = padding.getHotseatBottomPadding(unscaledExtraSpace);
549
Jon Mirandaab3c6812021-06-28 15:42:28 -0700550 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
551 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700552 }
Pat Manning08610ca2022-04-05 21:03:16 +0100553
554 int cellLayoutPadding =
555 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
556 R.dimen.cell_layout_padding);
557 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
558 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800559 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800560
Thales Lima7eee74b2023-03-16 16:00:55 -0300561 // Folder scaling requires correct workspace paddings
562 updateAvailableFolderCellDimensions(res);
563
Thales Limaffc68b02023-01-09 16:20:23 +0000564 mMinHotseatIconSpacePx = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
565 mMinHotseatQsbWidthPx = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
566 mMaxHotseatIconSpacePx = areNavButtonsInline
Thales Lima6a590062022-11-22 15:52:49 +0000567 ? res.getDimensionPixelSize(R.dimen.max_hotseat_icon_space) : Integer.MAX_VALUE;
Thales Lima425f6822022-05-10 13:44:58 -0300568 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima6a590062022-11-22 15:52:49 +0000569 recalculateHotseatWidthAndBorderSpace();
Alex Chau206ede92022-08-01 17:46:12 +0100570
571 // AllApps height calculation depends on updated cellSize
572 if (isTablet) {
573 int collapseHandleHeight =
574 res.getDimensionPixelOffset(R.dimen.bottom_sheet_handle_area_height);
575 int contentHeight = heightPx - collapseHandleHeight - hotseatQsbHeight;
576 int targetContentHeight = (int) (allAppsCellHeightPx * ALL_APPS_TABLET_MAX_ROWS);
577 allAppsTopPadding = Math.max(mInsets.top, contentHeight - targetContentHeight);
578 allAppsShiftRange = heightPx - allAppsTopPadding;
579 } else {
580 allAppsTopPadding = 0;
581 allAppsShiftRange =
582 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
583 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100584 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
585 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300586
Alex Chaua02eddc2021-04-29 00:36:06 +0100587 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
588 R.dimen.drag_flingToDeleteMinVelocity);
589
Sihua Mae04aa202022-07-18 12:43:56 -0700590 mViewScaleProvider = viewScaleProvider;
591
Jon Miranda2b25ded2023-02-02 14:48:45 -0800592 dimensionOverrideProvider.accept(this);
593
Tony Wickham1237df02017-02-24 08:59:36 -0800594 // This is done last, after iconSizePx is calculated above.
Sunny Goyal799e1202023-02-09 10:54:28 -0800595 mDotRendererWorkSpace = createDotRenderer(context, iconSizePx, dotRendererCache);
596 mDotRendererAllApps = createDotRenderer(context, allAppsIconSizePx, dotRendererCache);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700597 }
598
599 private static DotRenderer createDotRenderer(
Sunny Goyal799e1202023-02-09 10:54:28 -0800600 @NonNull Context context, int size, @NonNull SparseArray<DotRenderer> cache) {
Sunny Goyal65190ae2022-08-02 14:16:26 -0700601 DotRenderer renderer = cache.get(size);
602 if (renderer == null) {
Sunny Goyal799e1202023-02-09 10:54:28 -0800603 renderer = new DotRenderer(size, getShapePath(context, DEFAULT_DOT_SIZE),
604 DEFAULT_DOT_SIZE);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700605 cache.put(size, renderer);
606 }
607 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700608 }
609
Thales Lima425f6822022-05-10 13:44:58 -0300610 /**
611 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
612 * width of the hotseat.
613 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100614 private int calculateQsbWidth(int hotseatBorderSpace) {
Thales Lima425f6822022-05-10 13:44:58 -0300615 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100616 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300617 return getIconToIconWidthForColumns(columns)
618 - iconSizePx * numShownHotseatIcons
619 - hotseatBorderSpace * numShownHotseatIcons;
620 } else {
621 int columns = inv.hotseatColumnSpan[mTypeIndex];
622 return getIconToIconWidthForColumns(columns);
623 }
624 }
Thales Lima2903a622022-03-17 13:52:19 +0000625
Thales Lima425f6822022-05-10 13:44:58 -0300626 private int getIconToIconWidthForColumns(int columns) {
627 return columns * getCellSize().x
628 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400629 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000630 }
631
Thales Limad90faab2021-09-21 17:18:47 +0100632 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
633 if (isVerticalBarLayout()) {
634 return 0;
635 }
636
Thales Lima83bedbf2021-10-05 17:47:39 +0100637 return isScalableGrid
638 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
639 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100640 }
641
Thales Limab8c05952022-05-23 16:58:38 +0100642 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
643 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700644 // Ensure there is enough space for folder icons, which have a slightly larger radius.
645 hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR);
Thales Limab8c05952022-05-23 16:58:38 +0100646
Jon Miranda0d284852021-06-22 14:50:55 -0700647 if (isVerticalBarLayout()) {
648 hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
649 + hotseatBarSidePaddingEndPx;
Thales Limab8c05952022-05-23 16:58:38 +0100650 } else if (isQsbInline) {
651 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
652 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700653 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100654 hotseatBarSizePx = hotseatIconSizePx
655 + hotseatQsbSpace
656 + hotseatQsbVisualHeight
657 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700658 }
659 }
660
Thales Lima6a590062022-11-22 15:52:49 +0000661 /**
662 * Calculates the width of the hotseat, changing spaces between the icons and removing icons if
663 * necessary.
664 */
665 public void recalculateHotseatWidthAndBorderSpace() {
666 if (!isScalableGrid) return;
667
668 int columns = inv.hotseatColumnSpan[mTypeIndex];
669 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
670 hotseatBorderSpace = calculateHotseatBorderSpace(hotseatWidthPx, /* numExtraBorder= */ 0);
Thales Lima9938c2f2022-07-25 14:38:16 +0100671 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
Thales Lima6a590062022-11-22 15:52:49 +0000672 // Spaces should be correct when the nav buttons are not inline
Thales Lima9938c2f2022-07-25 14:38:16 +0100673 if (!areNavButtonsInline) {
674 return;
675 }
676
Thales Lima6a590062022-11-22 15:52:49 +0000677 // The side space with inline buttons should be what is defined in InvariantDeviceProfile
Jon Mirandae17a9492023-03-08 16:42:20 -0800678 int sideSpacePx = inlineNavButtonsEndSpacingPx;
Thales Limaffc68b02023-01-09 16:20:23 +0000679 int maxHotseatWidthPx = availableWidthPx - sideSpacePx - hotseatBarEndOffset;
680 int maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
681 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000682 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100683
Thales Limaffc68b02023-01-09 16:20:23 +0000684 if (hotseatBorderSpace >= mMinHotseatIconSpacePx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100685 return;
686 }
687
688 // Border space can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000689 hotseatBorderSpace = mMinHotseatIconSpacePx;
Thales Lima6a590062022-11-22 15:52:49 +0000690 int requiredWidth = getHotseatRequiredWidth();
Thales Lima9938c2f2022-07-25 14:38:16 +0100691
692 // If there is an inline qsb, change its size
693 if (isQsbInline) {
Thales Limaffc68b02023-01-09 16:20:23 +0000694 hotseatQsbWidth -= requiredWidth - maxHotseatWidthPx;
695 if (hotseatQsbWidth >= mMinHotseatQsbWidthPx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100696 return;
697 }
698
699 // QSB can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000700 hotseatQsbWidth = mMinHotseatQsbWidthPx;
Thales Lima9938c2f2022-07-25 14:38:16 +0100701 }
702
Thales Limaffc68b02023-01-09 16:20:23 +0000703 maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
Thales Lima6a590062022-11-22 15:52:49 +0000704
Thales Lima9938c2f2022-07-25 14:38:16 +0100705 // If it still doesn't fit, start removing icons
706 do {
707 numShownHotseatIcons--;
Thales Limaffc68b02023-01-09 16:20:23 +0000708 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000709 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Limaffc68b02023-01-09 16:20:23 +0000710 } while (hotseatBorderSpace < mMinHotseatIconSpacePx && numShownHotseatIcons > 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100711
Thales Lima9938c2f2022-07-25 14:38:16 +0100712 }
713
Thales Lima78d00ad2021-09-30 11:29:06 +0100714 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100715 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100716 }
717
718 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100719 if (!isScalableGrid) {
720 return new Point(0, 0);
721 }
722
Thales Lima080d8902022-03-28 15:30:29 +0100723 int horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
724 int verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
Thales Lima78d00ad2021-09-30 11:29:06 +0100725
726 return new Point(horizontalSpacePx, verticalSpacePx);
727 }
728
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700729 public Info getDisplayInfo() {
730 return mInfo;
731 }
732
Jon Miranda611dba42021-03-02 14:12:13 -0500733 /**
734 * We inset the widget padding added by the system and instead rely on the border spacing
735 * between cells to create reliable consistency between widgets
736 */
737 public boolean shouldInsetWidgets() {
738 Rect widgetPadding = inv.defaultWidgetPadding;
739
Jon Miranda49811182021-06-03 09:52:40 -0700740 // Check all sides to ensure that the widget won't overlap into another cell, or into
741 // status bar.
742 return workspaceTopPadding > widgetPadding.top
Thales Lima78d00ad2021-09-30 11:29:06 +0100743 && cellLayoutBorderSpacePx.x > widgetPadding.left
744 && cellLayoutBorderSpacePx.y > widgetPadding.top
745 && cellLayoutBorderSpacePx.x > widgetPadding.right
746 && cellLayoutBorderSpacePx.y > widgetPadding.bottom;
Jon Miranda611dba42021-03-02 14:12:13 -0500747 }
Jon Mirandae126d722021-02-25 10:45:20 -0500748
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700749 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800750 WindowBounds bounds = new WindowBounds(
751 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700752 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100753 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700754
755 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
756 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
757 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
758
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700759 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700760 .setWindowBounds(bounds)
Alex Chauab800f72022-12-13 17:46:06 +0000761 .setIsMultiDisplay(isMultiDisplay)
Alex Chau6ed408f2022-03-04 12:58:05 +0000762 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700763 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000764 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800765 }
766
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700767 public DeviceProfile copy(Context context) {
768 return toBuilder(context).build();
769 }
770
771 /**
772 * TODO: Move this to the builder as part of setMultiWindowMode
773 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700774 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700775 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700776 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700777 .setMultiWindowMode(true)
778 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800779
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800780 // We use these scales to measure and layout the widgets using their full invariant profile
781 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
782 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
783 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700784 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
785 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
786 profile = profile.toBuilder(context)
787 .setViewScaleProvider(i -> p)
788 .build();
789 }
790
791 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800792
Jon Miranda93e1f042016-11-11 14:13:04 -0800793 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700794 }
795
Adam Cohen63f1ec02014-08-12 09:23:13 -0700796 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400797 * Checks if there is enough space for labels on the workspace.
798 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700799 * It is important to call this method after the All Apps variables have been set.
800 */
Jon Miranda941375e2021-03-31 13:10:45 -0400801 private void hideWorkspaceLabelsIfNotEnoughSpace() {
802 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
803 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
804 - iconTextHeight;
805
806 // We want enough space so that the text is closer to its corresponding icon.
807 if (workspaceCellPaddingY < iconTextHeight) {
808 iconTextSizePx = 0;
809 iconDrawablePaddingPx = 0;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700810 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda941375e2021-03-31 13:10:45 -0400811 autoResizeAllAppsCells();
812 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700813 }
Jon Miranda1091e532017-07-21 13:31:50 -0700814
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700815 /**
816 * Re-computes the all-apps cell size to be independent of workspace
817 */
818 public void autoResizeAllAppsCells() {
Jon Miranda941375e2021-03-31 13:10:45 -0400819 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
820 int topBottomPadding = textHeight;
Jon Miranda1091e532017-07-21 13:31:50 -0700821 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
Jon Miranda941375e2021-03-31 13:10:45 -0400822 + textHeight + (topBottomPadding * 2);
Jon Miranda1091e532017-07-21 13:31:50 -0700823 }
824
Thales Limab7ef5692022-03-10 10:32:36 +0000825 private void updateAllAppsContainerWidth(Resources res) {
Pat Manning08610ca2022-04-05 21:03:16 +0100826 int cellLayoutHorizontalPadding =
827 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
Alex Chau27b39b92022-01-14 18:02:18 +0000828 if (isTablet) {
sfufa@google.comde013292021-09-21 18:22:44 -0700829 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
Thales Limab7ef5692022-03-10 10:32:36 +0000830 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Alex Chau27b39b92022-01-14 18:02:18 +0000831 + allAppsLeftRightPadding * 2;
832 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
sfufa@google.comde013292021-09-21 18:22:44 -0700833 } else {
834 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100835 desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding;
sfufa@google.comde013292021-09-21 18:22:44 -0700836 }
837 }
838
Thales Limae9273ea2023-01-26 12:33:52 +0000839 private void setupAllAppsStyle(Context context) {
840 TypedArray allAppsStyle;
841 if (inv.allAppsStyle != INVALID_RESOURCE_HANDLE) {
842 allAppsStyle = context.obtainStyledAttributes(inv.allAppsStyle,
843 R.styleable.AllAppsStyle);
844 } else {
845 allAppsStyle = context.obtainStyledAttributes(R.style.AllAppsStyleDefault,
846 R.styleable.AllAppsStyle);
847 }
848 allAppsLeftRightPadding = allAppsStyle.getDimensionPixelSize(
849 R.styleable.AllAppsStyle_horizontalPadding, 0);
850 allAppsStyle.recycle();
851 }
852
Jon Miranda228877d2021-02-09 11:05:00 -0500853 /**
854 * Returns the amount of extra (or unused) vertical space.
855 */
856 private int updateAvailableDimensions(Resources res) {
Alex Chaua68164d2022-12-15 16:16:03 +0000857 float invIconSizeDp = inv.iconSize[mTypeIndex];
858 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
859 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
860 iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
861
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700862 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800863
Pat Manning08610ca2022-04-05 21:03:16 +0100864 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -0500865
866 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +0100867 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +0000868 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -0500869 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500870 float scaleY = maxHeight / usedHeight;
871 boolean shouldScale = scaleY < 1f;
872
873 float scaleX = 1f;
874 if (isScalableGrid) {
875 // We scale to fit the cellWidth and cellHeight in the available space.
876 // The benefit of scalable grids is that we can get consistent aspect ratios between
877 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +0100878 float usedWidth =
879 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500880 // We do not subtract padding here, as we also scale the workspace padding if needed.
881 scaleX = availableWidthPx / usedWidth;
882 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700883 }
Jon Mirandae126d722021-02-25 10:45:20 -0500884
885 if (shouldScale) {
886 float scale = Math.min(scaleX, scaleY);
887 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +0100888 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -0500889 }
890
Jon Miranda228877d2021-02-09 11:05:00 -0500891 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700892 }
893
Pat Manninga2e14992022-04-22 11:29:17 +0100894 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +0100895 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
896 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
897 }
898
Pat Manninga2e14992022-04-22 11:29:17 +0100899 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +0000900 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +0100901 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
902 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -0500903 }
904
Jon Miranda6f7e9702019-09-16 14:44:14 -0700905 /**
906 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
907 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
908 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
909 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800910 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -0700911 // Icon scale should never exceed 1, otherwise pixellation may occur.
912 iconScale = Math.min(1f, scale);
913 cellScaleToFit = scale;
914
Jon Miranda18751b62017-07-31 17:25:27 -0700915 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800916 final boolean isVerticalLayout = isVerticalBarLayout();
Jon Mirandaab3c6812021-06-28 15:42:28 -0700917 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);
Thales Lima080d8902022-03-28 15:30:29 +0100918 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500919
920 if (isScalableGrid) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100921 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
922 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +0000923
924 if (cellWidthPx < iconSizePx) {
925 // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger.
926 int numColumns = getPanelCount() * inv.numColumns;
927 int numBorders = numColumns - 1;
928 int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns;
929 if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) {
930 cellWidthPx = iconSizePx;
931 cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders;
932 } else {
933 // If it still doesn't fit, set borderSpace to 0 and distribute the space for
934 // cellWidth, and reduce iconSize.
935 cellWidthPx = (cellWidthPx * numColumns
936 + cellLayoutBorderSpacePx.x * numBorders) / numColumns;
937 iconSizePx = Math.min(iconSizePx, cellWidthPx);
938 cellLayoutBorderSpacePx.x = 0;
939 }
940 }
941
942 int cellTextAndPaddingHeight =
943 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
944 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
945 if (cellHeightPx < cellContentHeight) {
946 // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight
947 // bigger.
948 int numBorders = inv.numRows - 1;
949 int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows;
950 if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) {
951 cellHeightPx = cellContentHeight;
952 cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders;
953 } else {
Alex Chau06f36e82023-01-06 10:50:54 +0000954 // If it still doesn't fit, set borderSpace to 0 to recover space.
Alex Chaube753132022-12-09 16:46:54 +0000955 cellHeightPx = (cellHeightPx * inv.numRows
956 + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows;
Alex Chaube753132022-12-09 16:46:54 +0000957 cellLayoutBorderSpacePx.y = 0;
Alex Chau06f36e82023-01-06 10:50:54 +0000958 // Reduce iconDrawablePaddingPx to make cellContentHeight smaller.
959 int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx;
960 if (cellContentWithoutPadding <= cellHeightPx) {
961 iconDrawablePaddingPx = cellContentHeight - cellHeightPx;
962 } else {
963 // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space,
964 // then proportional reduce iconSizePx and iconTextSizePx to fit.
965 iconDrawablePaddingPx = 0;
966 float ratio = cellHeightPx / (float) cellContentWithoutPadding;
967 iconSizePx = (int) (iconSizePx * ratio);
968 iconTextSizePx = (int) (iconTextSizePx * ratio);
969 }
970 cellTextAndPaddingHeight =
971 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +0000972 }
973 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
974 }
Jon Mirandae126d722021-02-25 10:45:20 -0500975 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +0100976 desiredWorkspaceHorizontalMarginPx =
977 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -0500978 } else {
Jon Mirandae126d722021-02-25 10:45:20 -0500979 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700980 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR)
981 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -0500982 + Utilities.calculateTextHeight(iconTextSizePx);
983 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
984 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
985 && !isMultiWindowMode) {
986 // Ensures that the label is closer to its corresponding icon. This is not an issue
987 // with vertical bar layout or multi-window mode since the issue is handled
988 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
989 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
990 iconDrawablePaddingPx = cellPaddingY;
991 }
Jon Miranda846455e2017-10-02 14:58:52 -0700992 }
Jon Miranda18751b62017-07-31 17:25:27 -0700993
Sunny Goyalae190ff2020-04-14 00:19:01 +0000994 // All apps
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500995 updateAllAppsIconSize(scale, res);
Winson Chungb3800242013-10-24 11:01:54 -0700996
Thales Limab8c05952022-05-23 16:58:38 +0100997 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700998
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700999 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -07001000 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
1001 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
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
1585 writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
1586
Thales Lima83bedbf2021-10-05 17:47:39 +01001587 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001588 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1589 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1590 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001591
Alex Chaue818bcb2022-09-02 17:27:11 +01001592 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07001593
Jon Miranda58561d42021-03-17 10:51:54 -04001594 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1595 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1596
1597 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1598 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1599
Thales Lima83bedbf2021-10-05 17:47:39 +01001600 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1601 cellLayoutBorderSpacePx.x));
1602 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1603 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001604 writer.println(
1605 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
1606 writer.println(
1607 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
1608 writer.println(
1609 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01001610 writer.println(
1611 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01001612
Jon Miranda58561d42021-03-17 10:51:54 -04001613 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1614 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1615 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1616
Helen Cheuk599109b2023-02-23 17:15:39 +00001617 writer.println(prefix + "\tinv.numFolderRows: " + inv.numFolderRows);
1618 writer.println(prefix + "\tinv.numFolderColumns: " + inv.numFolderColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001619 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1620 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1621 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1622 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1623 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1624 folderChildDrawablePaddingPx));
Thales Limab35faed2022-09-05 16:30:01 -03001625 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx",
1626 folderCellLayoutBorderSpacePx));
Thales Limaa08a4432022-08-09 09:55:17 +01001627 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
1628 folderContentPaddingLeftRight));
1629 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03001630 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001631
Alex Chaue0227552022-04-06 19:44:43 +01001632 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001633 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
1634 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
1635 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
1636 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01001637
1638 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
1639 writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001640 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
1641 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04001642 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1643 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1644 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1645 allAppsIconDrawablePaddingPx));
1646 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001647 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001648 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
1649 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001650 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau62572c02022-07-25 18:36:37 +00001651 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
Alex Chau27b39b92022-01-14 18:02:18 +00001652 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001653
1654 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03001655 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04001656 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00001657 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Jon Miranda58561d42021-03-17 10:51:54 -04001658 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
1659 hotseatBarSidePaddingStartPx));
1660 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
1661 hotseatBarSidePaddingEndPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001662 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01001663 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
1664 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01001665 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
1666 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001667 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
1668 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
1669 hotseatLayoutPadding.top));
1670 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
1671 hotseatLayoutPadding.bottom));
1672 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
1673 hotseatLayoutPadding.left));
1674 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
1675 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001676 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001677 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001678 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01001679 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001680
1681 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001682 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda9c478b62023-03-23 21:38:49 -07001683 writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight));
1684 writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight));
1685 writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin));
1686 writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001687
Thales Lima83bedbf2021-10-05 17:47:39 +01001688 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1689 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001690 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
1691 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
1692 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00001693 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001694
Jon Mirandaab3c6812021-06-28 15:42:28 -07001695 writer.println(prefix + pxToDpStr("iconScale", iconScale));
1696 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04001697 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00001698 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001699
Thales Lima171ee662022-11-22 15:52:49 +00001700 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04001701 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
1702 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00001703
1704 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00001705 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
1706 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
1707 overviewTaskIconDrawableSizePx));
1708 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
1709 overviewTaskIconDrawableSizeGridPx));
1710 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
1711 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01001712 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
1713 overviewActionsTopMarginPx));
1714 writer.println(prefix + pxToDpStr("overviewActionsHeight",
1715 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00001716 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
1717 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00001718 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
1719 overviewActionsButtonSpacing));
1720 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
1721 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
1722 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01001723
Alex Chau62572c02022-07-25 18:36:37 +00001724 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001725 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00001726 writer.println(
1727 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001728
Pat Manning5f74bfd2022-07-20 12:08:54 +01001729 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
1730 getCellLayoutSpringLoadShrunkTop()));
1731 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
1732 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01001733 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
1734 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001735 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
1736 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01001737 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
1738 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Jon Miranda58561d42021-03-17 10:51:54 -04001739 }
1740
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00001741 /** Returns a reduced representation of this DeviceProfile. */
1742 public String toSmallString() {
1743 return "isTablet:" + isTablet + ", "
1744 + "isMultiDisplay:" + isMultiDisplay + ", "
1745 + "widthPx:" + widthPx + ", "
1746 + "heightPx:" + heightPx + ", "
1747 + "insets:" + mInsets + ", "
1748 + "rotationHint:" + rotationHint;
1749 }
1750
Alex Chaua6907dc2022-03-18 15:24:07 +00001751 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07001752 Configuration config = new Configuration(c.getResources().getConfiguration());
1753 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03001754 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00001755 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07001756 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07001757 }
Sunny Goyalfde55052018-02-01 14:46:13 -08001758
1759 /**
1760 * Callback when a component changes the DeviceProfile associated with it, as a result of
1761 * configuration change
1762 */
1763 public interface OnDeviceProfileChangeListener {
1764
1765 /**
1766 * Called when the device profile is reassigned. Note that for layout and measurements, it
1767 * is sufficient to listen for inset changes. Use this callback when you need to perform
1768 * a one time operation.
1769 */
1770 void onDeviceProfileChanged(DeviceProfile dp);
1771 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001772
Sihua Mae04aa202022-07-18 12:43:56 -07001773 /**
1774 * Handler that deals with ItemInfo of the views for the DeviceProfile
1775 */
1776 @FunctionalInterface
1777 public interface ViewScaleProvider {
1778 /**
1779 * Get the scales from the view
1780 *
1781 * @param itemInfo The tag of the widget view
1782 * @return PointF instance containing the scale information, or null if using the default
1783 * app widget scale of this device profile.
1784 */
1785 @NonNull
1786 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
1787 }
1788
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001789 public static class Builder {
1790 private Context mContext;
1791 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07001792 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001793
Sunny Goyal19ff7282021-04-22 10:12:54 -07001794 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00001795 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001796
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001797 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001798 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00001799 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07001800 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001801
Sunny Goyal65190ae2022-08-02 14:16:26 -07001802 private SparseArray<DotRenderer> mDotRendererCache;
1803
Jon Miranda2b25ded2023-02-02 14:48:45 -08001804 private Consumer<DeviceProfile> mOverrideProvider;
1805
Sunny Goyalfd58da62020-08-11 12:06:49 -07001806 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001807 mContext = context;
1808 mInv = inv;
1809 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001810 }
1811
1812 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1813 mIsMultiWindowMode = isMultiWindowMode;
1814 return this;
1815 }
1816
Alex Chauab800f72022-12-13 17:46:06 +00001817 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
1818 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001819 return this;
1820 }
1821
Sunny Goyal65190ae2022-08-02 14:16:26 -07001822 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
1823 mDotRendererCache = dotRendererCache;
1824 return this;
1825 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07001826
1827 public Builder setWindowBounds(WindowBounds bounds) {
1828 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07001829 return this;
1830 }
1831
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001832 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1833 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1834 return this;
1835 }
1836
Alex Chau6ed408f2022-03-04 12:58:05 +00001837 public Builder setGestureMode(boolean isGestureMode) {
1838 mIsGestureMode = isGestureMode;
1839 return this;
1840 }
1841
Jon Miranda2b25ded2023-02-02 14:48:45 -08001842 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
1843 mOverrideProvider = overrideProvider;
1844 return this;
1845 }
1846
Sihua Mae04aa202022-07-18 12:43:56 -07001847 /**
1848 * Set the viewScaleProvider for the builder
1849 *
1850 * @param viewScaleProvider The viewScaleProvider to be set for the
Thales Limae9273ea2023-01-26 12:33:52 +00001851 * DeviceProfile
Sihua Mae04aa202022-07-18 12:43:56 -07001852 * @return This builder
1853 */
1854 @NonNull
1855 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
1856 mViewScaleProvider = viewScaleProvider;
1857 return this;
1858 }
1859
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001860 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001861 if (mWindowBounds == null) {
1862 throw new IllegalArgumentException("Window bounds not set");
1863 }
1864 if (mTransposeLayoutWithOrientation == null) {
1865 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
1866 }
Alex Chau6ed408f2022-03-04 12:58:05 +00001867 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01001868 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00001869 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001870 if (mDotRendererCache == null) {
1871 mDotRendererCache = new SparseArray<>();
1872 }
Sihua Mae04aa202022-07-18 12:43:56 -07001873 if (mViewScaleProvider == null) {
1874 mViewScaleProvider = DEFAULT_PROVIDER;
1875 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08001876 if (mOverrideProvider == null) {
1877 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
1878 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001879 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00001880 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jon Miranda2b25ded2023-02-02 14:48:45 -08001881 mIsGestureMode, mViewScaleProvider, mOverrideProvider);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001882 }
1883 }
1884
Winson Chungb3800242013-10-24 11:01:54 -07001885}