blob: fcb220ebd818157e6c5db8f65e60da3de8fbba30 [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;
Tony Wickham15883892021-02-12 11:24:40 -0800270
Alex Chaua02eddc2021-04-29 00:36:06 +0100271 // DragController
272 public int flingToDeleteThresholdVelocity;
273
Vinit Nayak17c4b332021-08-05 12:54:58 -0700274 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700275 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal65190ae2022-08-02 14:16:26 -0700276 SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
Alex Chauab800f72022-12-13 17:46:06 +0000277 boolean transposeLayoutWithOrientation, boolean isMultiDisplay, boolean isGestureMode,
Jon Miranda2b25ded2023-02-02 14:48:45 -0800278 @NonNull final ViewScaleProvider viewScaleProvider,
279 @NonNull final Consumer<DeviceProfile> dimensionOverrideProvider) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700280
Adam Cohen2e6da152015-05-06 11:42:25 -0700281 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700282 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800283 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500284 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +0000285 this.isMultiDisplay = isMultiDisplay;
Alex Chau6ed408f2022-03-04 12:58:05 +0000286 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700287 windowX = windowBounds.bounds.left;
288 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800289 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100290 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700291
Jon Mirandae126d722021-02-25 10:45:20 -0500292 isScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000293 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700294 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000295 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700296 isPhone = !isTablet;
Alex Chauab800f72022-12-13 17:46:06 +0000297 isTwoPanels = isTablet && isMultiDisplay;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800298 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700299
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000300 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000301 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700302 ? Configuration.ORIENTATION_LANDSCAPE
303 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000304 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700305 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000306 mMetrics = res.getDisplayMetrics();
307
308 // Determine sizes.
309 widthPx = windowBounds.bounds.width();
310 heightPx = windowBounds.bounds.height();
311 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100312 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000313
314 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
315 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
316 mQsbCenterFactor = res.getFloat(R.dimen.qsb_center_factor);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700317
Thales Lima83bedbf2021-10-05 17:47:39 +0100318 if (isTwoPanels) {
319 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000320 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100321 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000322 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100323 }
324 } else {
325 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000326 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100327 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000328 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100329 }
330 }
331
Jon Miranda9c478b62023-03-23 21:38:49 -0700332 if (DisplayController.isTransientTaskbar(context)) {
333 float invTransientIconSizeDp = inv.transientTaskbarIconSize[mTypeIndex];
334 taskbarIconSize = pxFromDp(invTransientIconSizeDp, mMetrics);
335 taskbarHeight = taskbarIconSize
336 + (2 * res.getDimensionPixelSize(R.dimen.transient_taskbar_padding));
337 stashedTaskbarHeight =
338 res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_height);
339 taskbarBottomMargin =
340 res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin);
341 } else {
342 taskbarIconSize = pxFromDp(ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size),
343 mMetrics);
344 taskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_size);
345 stashedTaskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
346 taskbarBottomMargin = 0;
Tony Wickham15883892021-02-12 11:24:40 -0800347 }
Tony Wickham15883892021-02-12 11:24:40 -0800348
Winson Chungb3800242013-10-24 11:01:54 -0700349 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100350 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700351
Thales Limad90faab2021-09-21 17:18:47 +0100352 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
353 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100354 gridVisualizationPaddingX = res.getDimensionPixelSize(
355 R.dimen.grid_visualization_horizontal_cell_spacing);
356 gridVisualizationPaddingY = res.getDimensionPixelSize(
357 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500358
Alex Chaue0227552022-04-06 19:44:43 +0100359 bottomSheetTopPadding = mInsets.top // statusbar height
Andras Kloczl142b0542022-03-09 21:26:02 +0000360 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
361 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
Alex Chau3d2c0622022-09-01 21:28:14 +0100362 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
363 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
364 if (isTablet) {
365 bottomSheetWorkspaceScale = workspaceContentScale;
Alex Chauab800f72022-12-13 17:46:06 +0000366 if (isMultiDisplay && !ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH.get()) {
367 // TODO(b/259893832): Revert to use maxWallpaperScale to calculate bottomSheetDepth
368 // when screen recorder bug is fixed.
369 bottomSheetDepth = 1f;
370 } else {
371 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
372 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
373 // When depth is 1, wallpaper zoom is set to 1.
374 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
375 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
376 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
377 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
378 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100379 } else {
380 bottomSheetWorkspaceScale = 1f;
381 bottomSheetDepth = 0f;
382 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000383
Jon Mirandae126d722021-02-25 10:45:20 -0500384 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
Thales Limab35faed2022-09-05 16:30:01 -0300385
Thales Lima7eee74b2023-03-16 16:00:55 -0300386 if (isScalableGrid && inv.folderStyle != INVALID_RESOURCE_HANDLE) {
Thales Limab35faed2022-09-05 16:30:01 -0300387 TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
Thales Limad852d652023-01-17 14:01:13 +0000388 R.styleable.FolderStyle);
Thales Limab35faed2022-09-05 16:30:01 -0300389 // These are re-set in #updateFolderCellSize if the grid is not scalable
390 folderCellHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000391 R.styleable.FolderStyle_folderCellHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300392 folderCellWidthPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000393 R.styleable.FolderStyle_folderCellWidth, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300394
395 folderContentPaddingTop = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000396 R.styleable.FolderStyle_folderTopPadding, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300397 folderCellLayoutBorderSpacePx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000398 R.styleable.FolderStyle_folderBorderSpace, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300399 folderFooterHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000400 R.styleable.FolderStyle_folderFooterHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300401 folderStyle.recycle();
402 } else {
403 folderCellLayoutBorderSpacePx = 0;
Thales Lima7eee74b2023-03-16 16:00:55 -0300404 folderFooterHeightPx = res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Thales Limab35faed2022-09-05 16:30:01 -0300405 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
406 }
Jon Mirandae126d722021-02-25 10:45:20 -0500407
Thales Lima78d00ad2021-09-30 11:29:06 +0100408 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv);
Thales Limab35faed2022-09-05 16:30:01 -0300409 cellLayoutBorderSpaceOriginalPx = new Point(cellLayoutBorderSpacePx);
Thales Lima85c942f2021-12-31 13:04:20 +0000410 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000411 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
412 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Thales Limae9273ea2023-01-26 12:33:52 +0000413 setupAllAppsStyle(context);
Jon Mirandae126d722021-02-25 10:45:20 -0500414
Tony Wickham5edf9e22020-03-27 20:06:52 -0700415 workspacePageIndicatorHeight = res.getDimensionPixelSize(
416 R.dimen.workspace_page_indicator_height);
417 mWorkspacePageIndicatorOverlapWorkspace =
418 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700419
Thales Limad852d652023-01-17 14:01:13 +0000420 TypedArray cellStyle;
421 if (inv.cellStyle != INVALID_RESOURCE_HANDLE) {
422 cellStyle = context.obtainStyledAttributes(inv.cellStyle,
423 R.styleable.CellStyle);
424 } else {
425 cellStyle = context.obtainStyledAttributes(R.style.CellStyleDefault,
426 R.styleable.CellStyle);
427 }
428 iconDrawablePaddingOriginalPx = cellStyle.getDimensionPixelSize(
429 R.styleable.CellStyle_iconDrawablePadding, 0);
430 cellStyle.recycle();
Alex Chaua02eddc2021-04-29 00:36:06 +0100431
Sunny Goyal47328fd2016-05-25 18:56:41 -0700432 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100433 dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
434 dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100435 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
436 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100437 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
438 R.dimen.drop_target_button_drawable_horizontal_padding);
439 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
440 R.dimen.drop_target_button_drawable_vertical_padding);
441 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100442 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
443 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100444
Alex Chau906d8822022-05-23 10:42:25 +0100445 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
446 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700447
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700448 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700449
Thales Limaa1012902022-01-13 17:58:42 +0000450 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100451 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
452 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
453
Thales Lima12d0eff2022-03-25 17:06:11 +0000454 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
455 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
456 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
457 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
458 && hotseatQsbHeight > 0;
Thales Lima6a590062022-11-22 15:52:49 +0000459 isQsbInline = isScalableGrid && inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000460
Thales Lima425f6822022-05-10 13:44:58 -0300461 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100462 numShownHotseatIcons =
463 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000464
Sunny Goyal19ff7282021-04-22 10:12:54 -0700465 numShownAllAppsColumns =
466 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100467
468 int hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
469 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
470 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
471 // Have a little space between the inset and the QSB
472 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
473 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
474
475 // Only change the spaces if there is space
476 if (availableSpace > 0) {
477 // Make sure there is enough space between hotseat/QSB and QSB/navBar
478 if (availableSpace < minQsbMargin * 2) {
479 minQsbMargin = availableSpace / 2;
480 hotseatQsbSpace = minQsbMargin;
481 } else {
482 hotseatQsbSpace -= minQsbMargin;
483 }
484 }
485 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
486
Thales Limaa1012902022-01-13 17:58:42 +0000487 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100488 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
Thales Limaa1012902022-01-13 17:58:42 +0000489 }
Thales Lima425f6822022-05-10 13:44:58 -0300490
Pat Manningde25c0d2022-04-05 19:11:26 +0100491 springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
492 R.dimen.spring_loaded_hotseat_top_margin);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700493 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800494 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700495 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700496 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Thales Limab8c05952022-05-23 16:58:38 +0100497 updateHotseatSizes(pxFromDp(inv.iconSize[INDEX_DEFAULT], mMetrics));
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700498 if (areNavButtonsInline && !isPhone) {
Jon Mirandae17a9492023-03-08 16:42:20 -0800499 inlineNavButtonsEndSpacingPx =
Thales Limaffc68b02023-01-09 16:20:23 +0000500 res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing);
Pat Manning26f70f72022-07-07 13:50:39 +0100501 /*
502 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700503 * Spacing between nav buttons +
Thales Lima6a590062022-11-22 15:52:49 +0000504 * Space at the end for contextual buttons
Pat Manning26f70f72022-07-07 13:50:39 +0100505 */
506 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700507 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
Jon Mirandae17a9492023-03-08 16:42:20 -0800508 + inlineNavButtonsEndSpacingPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100509 } else {
Jon Mirandae17a9492023-03-08 16:42:20 -0800510 inlineNavButtonsEndSpacingPx = 0;
Pat Manning26f70f72022-07-07 13:50:39 +0100511 hotseatBarEndOffset = 0;
512 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700513
Alex Chau635b3ab2022-01-26 16:49:10 +0000514 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chau5fd9d492021-07-22 17:27:11 +0100515 overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100516 overviewTaskIconDrawableSizePx =
517 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
518 overviewTaskIconDrawableSizeGridPx =
519 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700520 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx;
Jeremy Sim3c2c3f12022-05-16 20:37:43 -0700521 overviewActionsTopMarginPx = res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000522 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
523 overviewActionsButtonSpacing = res.getDimensionPixelSize(
524 R.dimen.overview_actions_button_spacing);
Alex Chau19c6eca2022-03-10 20:12:56 +0000525 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700526 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000527 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700528
Jeremy Sim0ac47082022-10-10 13:59:40 -0700529 splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset);
530
Jon Miranda2ed276e2017-06-29 11:36:34 -0700531 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400532 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700533
Jon Miranda2ed276e2017-06-29 11:36:34 -0700534 // Now that we have all of the variables calculated, we can tune certain sizes.
Thales Limaae0d7ef2022-11-16 15:53:43 +0000535 if (isScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400536 // Paddings were created assuming no scaling, so we first unscale the extra space.
Jon Mirandaab3c6812021-06-28 15:42:28 -0700537 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
Thales Limaae0d7ef2022-11-16 15:53:43 +0000538 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
539 DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
Thales Lima171ee662022-11-22 15:52:49 +0000540 maxEmptySpace = padding.getMaxEmptySpacePx();
Jon Miranda228877d2021-02-09 11:05:00 -0500541
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400542 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
543 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
544 int paddingHotseatBottom = padding.getHotseatBottomPadding(unscaledExtraSpace);
545
Jon Mirandaab3c6812021-06-28 15:42:28 -0700546 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
547 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700548 }
Pat Manning08610ca2022-04-05 21:03:16 +0100549
550 int cellLayoutPadding =
551 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
552 R.dimen.cell_layout_padding);
553 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
554 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800555 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800556
Thales Lima7eee74b2023-03-16 16:00:55 -0300557 // Folder scaling requires correct workspace paddings
558 updateAvailableFolderCellDimensions(res);
559
Thales Limaffc68b02023-01-09 16:20:23 +0000560 mMinHotseatIconSpacePx = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
561 mMinHotseatQsbWidthPx = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
562 mMaxHotseatIconSpacePx = areNavButtonsInline
Thales Lima6a590062022-11-22 15:52:49 +0000563 ? res.getDimensionPixelSize(R.dimen.max_hotseat_icon_space) : Integer.MAX_VALUE;
Thales Lima425f6822022-05-10 13:44:58 -0300564 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima6a590062022-11-22 15:52:49 +0000565 recalculateHotseatWidthAndBorderSpace();
Alex Chau206ede92022-08-01 17:46:12 +0100566
567 // AllApps height calculation depends on updated cellSize
568 if (isTablet) {
569 int collapseHandleHeight =
570 res.getDimensionPixelOffset(R.dimen.bottom_sheet_handle_area_height);
571 int contentHeight = heightPx - collapseHandleHeight - hotseatQsbHeight;
572 int targetContentHeight = (int) (allAppsCellHeightPx * ALL_APPS_TABLET_MAX_ROWS);
573 allAppsTopPadding = Math.max(mInsets.top, contentHeight - targetContentHeight);
574 allAppsShiftRange = heightPx - allAppsTopPadding;
575 } else {
576 allAppsTopPadding = 0;
577 allAppsShiftRange =
578 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
579 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100580 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
581 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300582
Alex Chaua02eddc2021-04-29 00:36:06 +0100583 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
584 R.dimen.drag_flingToDeleteMinVelocity);
585
Sihua Mae04aa202022-07-18 12:43:56 -0700586 mViewScaleProvider = viewScaleProvider;
587
Jon Miranda2b25ded2023-02-02 14:48:45 -0800588 dimensionOverrideProvider.accept(this);
589
Tony Wickham1237df02017-02-24 08:59:36 -0800590 // This is done last, after iconSizePx is calculated above.
Sunny Goyal799e1202023-02-09 10:54:28 -0800591 mDotRendererWorkSpace = createDotRenderer(context, iconSizePx, dotRendererCache);
592 mDotRendererAllApps = createDotRenderer(context, allAppsIconSizePx, dotRendererCache);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700593 }
594
595 private static DotRenderer createDotRenderer(
Sunny Goyal799e1202023-02-09 10:54:28 -0800596 @NonNull Context context, int size, @NonNull SparseArray<DotRenderer> cache) {
Sunny Goyal65190ae2022-08-02 14:16:26 -0700597 DotRenderer renderer = cache.get(size);
598 if (renderer == null) {
Sunny Goyal799e1202023-02-09 10:54:28 -0800599 renderer = new DotRenderer(size, getShapePath(context, DEFAULT_DOT_SIZE),
600 DEFAULT_DOT_SIZE);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700601 cache.put(size, renderer);
602 }
603 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700604 }
605
Thales Lima425f6822022-05-10 13:44:58 -0300606 /**
607 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
608 * width of the hotseat.
609 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100610 private int calculateQsbWidth(int hotseatBorderSpace) {
Thales Lima425f6822022-05-10 13:44:58 -0300611 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100612 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300613 return getIconToIconWidthForColumns(columns)
614 - iconSizePx * numShownHotseatIcons
615 - hotseatBorderSpace * numShownHotseatIcons;
616 } else {
617 int columns = inv.hotseatColumnSpan[mTypeIndex];
618 return getIconToIconWidthForColumns(columns);
619 }
620 }
Thales Lima2903a622022-03-17 13:52:19 +0000621
Thales Lima425f6822022-05-10 13:44:58 -0300622 private int getIconToIconWidthForColumns(int columns) {
623 return columns * getCellSize().x
624 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400625 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000626 }
627
Thales Limad90faab2021-09-21 17:18:47 +0100628 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
629 if (isVerticalBarLayout()) {
630 return 0;
631 }
632
Thales Lima83bedbf2021-10-05 17:47:39 +0100633 return isScalableGrid
634 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
635 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100636 }
637
Thales Limab8c05952022-05-23 16:58:38 +0100638 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
639 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700640 // Ensure there is enough space for folder icons, which have a slightly larger radius.
641 hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR);
Thales Limab8c05952022-05-23 16:58:38 +0100642
Jon Miranda0d284852021-06-22 14:50:55 -0700643 if (isVerticalBarLayout()) {
644 hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
645 + hotseatBarSidePaddingEndPx;
Thales Limab8c05952022-05-23 16:58:38 +0100646 } else if (isQsbInline) {
647 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
648 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700649 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100650 hotseatBarSizePx = hotseatIconSizePx
651 + hotseatQsbSpace
652 + hotseatQsbVisualHeight
653 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700654 }
655 }
656
Thales Lima6a590062022-11-22 15:52:49 +0000657 /**
658 * Calculates the width of the hotseat, changing spaces between the icons and removing icons if
659 * necessary.
660 */
661 public void recalculateHotseatWidthAndBorderSpace() {
662 if (!isScalableGrid) return;
663
664 int columns = inv.hotseatColumnSpan[mTypeIndex];
665 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
666 hotseatBorderSpace = calculateHotseatBorderSpace(hotseatWidthPx, /* numExtraBorder= */ 0);
Thales Lima9938c2f2022-07-25 14:38:16 +0100667 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
Thales Lima6a590062022-11-22 15:52:49 +0000668 // Spaces should be correct when the nav buttons are not inline
Thales Lima9938c2f2022-07-25 14:38:16 +0100669 if (!areNavButtonsInline) {
670 return;
671 }
672
Thales Lima6a590062022-11-22 15:52:49 +0000673 // The side space with inline buttons should be what is defined in InvariantDeviceProfile
Jon Mirandae17a9492023-03-08 16:42:20 -0800674 int sideSpacePx = inlineNavButtonsEndSpacingPx;
Thales Limaffc68b02023-01-09 16:20:23 +0000675 int maxHotseatWidthPx = availableWidthPx - sideSpacePx - hotseatBarEndOffset;
676 int maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
677 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000678 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100679
Thales Limaffc68b02023-01-09 16:20:23 +0000680 if (hotseatBorderSpace >= mMinHotseatIconSpacePx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100681 return;
682 }
683
684 // Border space can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000685 hotseatBorderSpace = mMinHotseatIconSpacePx;
Thales Lima6a590062022-11-22 15:52:49 +0000686 int requiredWidth = getHotseatRequiredWidth();
Thales Lima9938c2f2022-07-25 14:38:16 +0100687
688 // If there is an inline qsb, change its size
689 if (isQsbInline) {
Thales Limaffc68b02023-01-09 16:20:23 +0000690 hotseatQsbWidth -= requiredWidth - maxHotseatWidthPx;
691 if (hotseatQsbWidth >= mMinHotseatQsbWidthPx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100692 return;
693 }
694
695 // QSB can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000696 hotseatQsbWidth = mMinHotseatQsbWidthPx;
Thales Lima9938c2f2022-07-25 14:38:16 +0100697 }
698
Thales Limaffc68b02023-01-09 16:20:23 +0000699 maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
Thales Lima6a590062022-11-22 15:52:49 +0000700
Thales Lima9938c2f2022-07-25 14:38:16 +0100701 // If it still doesn't fit, start removing icons
702 do {
703 numShownHotseatIcons--;
Thales Limaffc68b02023-01-09 16:20:23 +0000704 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000705 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Limaffc68b02023-01-09 16:20:23 +0000706 } while (hotseatBorderSpace < mMinHotseatIconSpacePx && numShownHotseatIcons > 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100707
Thales Lima9938c2f2022-07-25 14:38:16 +0100708 }
709
Thales Lima78d00ad2021-09-30 11:29:06 +0100710 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100711 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100712 }
713
714 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100715 if (!isScalableGrid) {
716 return new Point(0, 0);
717 }
718
Thales Lima080d8902022-03-28 15:30:29 +0100719 int horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
720 int verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
Thales Lima78d00ad2021-09-30 11:29:06 +0100721
722 return new Point(horizontalSpacePx, verticalSpacePx);
723 }
724
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700725 public Info getDisplayInfo() {
726 return mInfo;
727 }
728
Jon Miranda611dba42021-03-02 14:12:13 -0500729 /**
730 * We inset the widget padding added by the system and instead rely on the border spacing
731 * between cells to create reliable consistency between widgets
732 */
733 public boolean shouldInsetWidgets() {
734 Rect widgetPadding = inv.defaultWidgetPadding;
735
Jon Miranda49811182021-06-03 09:52:40 -0700736 // Check all sides to ensure that the widget won't overlap into another cell, or into
737 // status bar.
738 return workspaceTopPadding > widgetPadding.top
Thales Lima78d00ad2021-09-30 11:29:06 +0100739 && cellLayoutBorderSpacePx.x > widgetPadding.left
740 && cellLayoutBorderSpacePx.y > widgetPadding.top
741 && cellLayoutBorderSpacePx.x > widgetPadding.right
742 && cellLayoutBorderSpacePx.y > widgetPadding.bottom;
Jon Miranda611dba42021-03-02 14:12:13 -0500743 }
Jon Mirandae126d722021-02-25 10:45:20 -0500744
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700745 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800746 WindowBounds bounds = new WindowBounds(
747 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700748 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100749 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700750
751 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
752 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
753 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
754
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700755 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700756 .setWindowBounds(bounds)
Alex Chauab800f72022-12-13 17:46:06 +0000757 .setIsMultiDisplay(isMultiDisplay)
Alex Chau6ed408f2022-03-04 12:58:05 +0000758 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700759 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000760 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800761 }
762
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700763 public DeviceProfile copy(Context context) {
764 return toBuilder(context).build();
765 }
766
767 /**
768 * TODO: Move this to the builder as part of setMultiWindowMode
769 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700770 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700771 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700772 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700773 .setMultiWindowMode(true)
774 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800775
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800776 // We use these scales to measure and layout the widgets using their full invariant profile
777 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
778 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
779 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700780 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
781 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
782 profile = profile.toBuilder(context)
783 .setViewScaleProvider(i -> p)
784 .build();
785 }
786
787 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800788
Jon Miranda93e1f042016-11-11 14:13:04 -0800789 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700790 }
791
Adam Cohen63f1ec02014-08-12 09:23:13 -0700792 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400793 * Checks if there is enough space for labels on the workspace.
794 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700795 * It is important to call this method after the All Apps variables have been set.
796 */
Jon Miranda941375e2021-03-31 13:10:45 -0400797 private void hideWorkspaceLabelsIfNotEnoughSpace() {
798 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
799 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
800 - iconTextHeight;
801
802 // We want enough space so that the text is closer to its corresponding icon.
803 if (workspaceCellPaddingY < iconTextHeight) {
804 iconTextSizePx = 0;
805 iconDrawablePaddingPx = 0;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700806 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda941375e2021-03-31 13:10:45 -0400807 autoResizeAllAppsCells();
808 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700809 }
Jon Miranda1091e532017-07-21 13:31:50 -0700810
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700811 /**
812 * Re-computes the all-apps cell size to be independent of workspace
813 */
814 public void autoResizeAllAppsCells() {
Jon Miranda941375e2021-03-31 13:10:45 -0400815 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
816 int topBottomPadding = textHeight;
Jon Miranda1091e532017-07-21 13:31:50 -0700817 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
Jon Miranda941375e2021-03-31 13:10:45 -0400818 + textHeight + (topBottomPadding * 2);
Jon Miranda1091e532017-07-21 13:31:50 -0700819 }
820
Thales Limab7ef5692022-03-10 10:32:36 +0000821 private void updateAllAppsContainerWidth(Resources res) {
Pat Manning08610ca2022-04-05 21:03:16 +0100822 int cellLayoutHorizontalPadding =
823 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
Alex Chau27b39b92022-01-14 18:02:18 +0000824 if (isTablet) {
sfufa@google.comde013292021-09-21 18:22:44 -0700825 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
Thales Limab7ef5692022-03-10 10:32:36 +0000826 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Alex Chau27b39b92022-01-14 18:02:18 +0000827 + allAppsLeftRightPadding * 2;
828 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
sfufa@google.comde013292021-09-21 18:22:44 -0700829 } else {
830 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100831 desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding;
sfufa@google.comde013292021-09-21 18:22:44 -0700832 }
833 }
834
Thales Limae9273ea2023-01-26 12:33:52 +0000835 private void setupAllAppsStyle(Context context) {
836 TypedArray allAppsStyle;
837 if (inv.allAppsStyle != INVALID_RESOURCE_HANDLE) {
838 allAppsStyle = context.obtainStyledAttributes(inv.allAppsStyle,
839 R.styleable.AllAppsStyle);
840 } else {
841 allAppsStyle = context.obtainStyledAttributes(R.style.AllAppsStyleDefault,
842 R.styleable.AllAppsStyle);
843 }
844 allAppsLeftRightPadding = allAppsStyle.getDimensionPixelSize(
845 R.styleable.AllAppsStyle_horizontalPadding, 0);
846 allAppsStyle.recycle();
847 }
848
Jon Miranda228877d2021-02-09 11:05:00 -0500849 /**
850 * Returns the amount of extra (or unused) vertical space.
851 */
852 private int updateAvailableDimensions(Resources res) {
Alex Chaua68164d2022-12-15 16:16:03 +0000853 float invIconSizeDp = inv.iconSize[mTypeIndex];
854 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
855 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
856 iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
857
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700858 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800859
Pat Manning08610ca2022-04-05 21:03:16 +0100860 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -0500861
862 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +0100863 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +0000864 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -0500865 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500866 float scaleY = maxHeight / usedHeight;
867 boolean shouldScale = scaleY < 1f;
868
869 float scaleX = 1f;
870 if (isScalableGrid) {
871 // We scale to fit the cellWidth and cellHeight in the available space.
872 // The benefit of scalable grids is that we can get consistent aspect ratios between
873 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +0100874 float usedWidth =
875 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500876 // We do not subtract padding here, as we also scale the workspace padding if needed.
877 scaleX = availableWidthPx / usedWidth;
878 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700879 }
Jon Mirandae126d722021-02-25 10:45:20 -0500880
881 if (shouldScale) {
882 float scale = Math.min(scaleX, scaleY);
883 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +0100884 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -0500885 }
886
Jon Miranda228877d2021-02-09 11:05:00 -0500887 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700888 }
889
Pat Manninga2e14992022-04-22 11:29:17 +0100890 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +0100891 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
892 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
893 }
894
Pat Manninga2e14992022-04-22 11:29:17 +0100895 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +0000896 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +0100897 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
898 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -0500899 }
900
Jon Miranda6f7e9702019-09-16 14:44:14 -0700901 /**
902 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
903 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
904 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
905 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800906 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -0700907 // Icon scale should never exceed 1, otherwise pixellation may occur.
908 iconScale = Math.min(1f, scale);
909 cellScaleToFit = scale;
910
Jon Miranda18751b62017-07-31 17:25:27 -0700911 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800912 final boolean isVerticalLayout = isVerticalBarLayout();
Jon Mirandaab3c6812021-06-28 15:42:28 -0700913 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);
Thales Lima080d8902022-03-28 15:30:29 +0100914 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500915
916 if (isScalableGrid) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100917 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
918 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +0000919
920 if (cellWidthPx < iconSizePx) {
921 // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger.
922 int numColumns = getPanelCount() * inv.numColumns;
923 int numBorders = numColumns - 1;
924 int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns;
925 if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) {
926 cellWidthPx = iconSizePx;
927 cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders;
928 } else {
929 // If it still doesn't fit, set borderSpace to 0 and distribute the space for
930 // cellWidth, and reduce iconSize.
931 cellWidthPx = (cellWidthPx * numColumns
932 + cellLayoutBorderSpacePx.x * numBorders) / numColumns;
933 iconSizePx = Math.min(iconSizePx, cellWidthPx);
934 cellLayoutBorderSpacePx.x = 0;
935 }
936 }
937
938 int cellTextAndPaddingHeight =
939 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
940 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
941 if (cellHeightPx < cellContentHeight) {
942 // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight
943 // bigger.
944 int numBorders = inv.numRows - 1;
945 int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows;
946 if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) {
947 cellHeightPx = cellContentHeight;
948 cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders;
949 } else {
Alex Chau06f36e82023-01-06 10:50:54 +0000950 // If it still doesn't fit, set borderSpace to 0 to recover space.
Alex Chaube753132022-12-09 16:46:54 +0000951 cellHeightPx = (cellHeightPx * inv.numRows
952 + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows;
Alex Chaube753132022-12-09 16:46:54 +0000953 cellLayoutBorderSpacePx.y = 0;
Alex Chau06f36e82023-01-06 10:50:54 +0000954 // Reduce iconDrawablePaddingPx to make cellContentHeight smaller.
955 int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx;
956 if (cellContentWithoutPadding <= cellHeightPx) {
957 iconDrawablePaddingPx = cellContentHeight - cellHeightPx;
958 } else {
959 // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space,
960 // then proportional reduce iconSizePx and iconTextSizePx to fit.
961 iconDrawablePaddingPx = 0;
962 float ratio = cellHeightPx / (float) cellContentWithoutPadding;
963 iconSizePx = (int) (iconSizePx * ratio);
964 iconTextSizePx = (int) (iconTextSizePx * ratio);
965 }
966 cellTextAndPaddingHeight =
967 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +0000968 }
969 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
970 }
Jon Mirandae126d722021-02-25 10:45:20 -0500971 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +0100972 desiredWorkspaceHorizontalMarginPx =
973 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -0500974 } else {
Jon Mirandae126d722021-02-25 10:45:20 -0500975 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700976 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR)
977 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -0500978 + Utilities.calculateTextHeight(iconTextSizePx);
979 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
980 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
981 && !isMultiWindowMode) {
982 // Ensures that the label is closer to its corresponding icon. This is not an issue
983 // with vertical bar layout or multi-window mode since the issue is handled
984 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
985 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
986 iconDrawablePaddingPx = cellPaddingY;
987 }
Jon Miranda846455e2017-10-02 14:58:52 -0700988 }
Jon Miranda18751b62017-07-31 17:25:27 -0700989
Sunny Goyalae190ff2020-04-14 00:19:01 +0000990 // All apps
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500991 updateAllAppsIconSize(scale, res);
Winson Chungb3800242013-10-24 11:01:54 -0700992
Thales Limab8c05952022-05-23 16:58:38 +0100993 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700994
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700995 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -0700996 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
997 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Winson Chung0f785722015-04-08 10:27:49 -0700998 }
999
Thales Lima425f6822022-05-10 13:44:58 -03001000 /**
Thales Lima6a590062022-11-22 15:52:49 +00001001 * This method calculates the space between the icons to achieve a certain width.
Thales Lima425f6822022-05-10 13:44:58 -03001002 */
Thales Lima6a590062022-11-22 15:52:49 +00001003 private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) {
Thales Lima9938c2f2022-07-25 14:38:16 +01001004 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
Thales Limaffc68b02023-01-09 16:20:23 +00001005 int hotseatBorderSpacePx =
Thales Lima6a590062022-11-22 15:52:49 +00001006 (int) (hotseatWidthPx - hotseatIconsTotalPx)
1007 / (numShownHotseatIcons - 1 + numExtraBorder);
Thales Limaffc68b02023-01-09 16:20:23 +00001008 return Math.min(hotseatBorderSpacePx, mMaxHotseatIconSpacePx);
Thales Lima425f6822022-05-10 13:44:58 -03001009 }
1010
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001011
1012 /**
1013 * Updates the iconSize for allApps* variants.
1014 */
Brian Isganitisa9a78112022-05-23 18:11:47 -07001015 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +01001016 allAppsBorderSpacePx = new Point(
1017 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
1018 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001019 // AllApps cells don't have real space between cells,
1020 // so we add the border space to the cell height
Alex Chaube753132022-12-09 16:46:54 +00001021 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics)
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001022 + allAppsBorderSpacePx.y;
1023 // but width is just the cell,
1024 // the border is added in #updateAllAppsContainerWidth
Thales Lima080d8902022-03-28 15:30:29 +01001025 if (isScalableGrid) {
Alex Chaube753132022-12-09 16:46:54 +00001026 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1027 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001028 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001029 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001030
1031 if (allAppsCellWidthPx < allAppsIconSizePx) {
1032 // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to
1033 // make allAppsCellWidth bigger.
1034 int numBorders = inv.numAllAppsColumns - 1;
1035 int extraWidthRequired =
1036 (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns;
1037 if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) {
1038 allAppsCellWidthPx = allAppsIconSizePx;
1039 allAppsBorderSpacePx.x -= extraWidthRequired / numBorders;
1040 } else {
1041 // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space
1042 // for allAppsCellWidth, and reduce allAppsIconSize.
1043 allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns
1044 + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns;
1045 allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx);
1046 allAppsBorderSpacePx.x = 0;
1047 }
1048 }
1049
1050 int cellContentHeight = allAppsIconSizePx
1051 + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y;
1052 if (allAppsCellHeightPx < cellContentHeight) {
1053 // Increase allAppsCellHeight to fit its content.
1054 allAppsCellHeightPx = cellContentHeight;
1055 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001056 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001057 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
1058 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001059 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1060 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001061 allAppsIconDrawablePaddingPx =
1062 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001063 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001064 }
1065
Thales Limab7ef5692022-03-10 10:32:36 +00001066 updateAllAppsContainerWidth(res);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001067 if (isVerticalBarLayout()) {
1068 hideWorkspaceLabelsIfNotEnoughSpace();
1069 }
1070 }
1071
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001072 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001073 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001074
Thales Lima7eee74b2023-03-16 16:00:55 -03001075 // For usability we can't have the folder use the whole width of the screen
Sunny Goyal07b69292018-01-08 14:19:34 -08001076 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -08001077
Thales Lima7eee74b2023-03-16 16:00:55 -03001078 // Check if the folder fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -05001079 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Thales Lima7eee74b2023-03-16 16:00:55 -03001080 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx)
1081 + folderFooterHeightPx
1082 + folderContentPaddingTop;
1083 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001084 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -08001085
Thales Lima7eee74b2023-03-16 16:00:55 -03001086 // Check if the folder fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -05001087 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Thales Lima7eee74b2023-03-16 16:00:55 -03001088 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx)
1089 + folderContentPaddingLeftRight * 2;
1090 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001091 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -08001092
1093 float scale = Math.min(scaleX, scaleY);
1094 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001095 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001096 }
1097 }
1098
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001099 private void updateFolderCellSize(float scale, Resources res) {
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001100 float invIconSizeDp = inv.iconSize[mTypeIndex];
Sunny Goyal35c7b192021-04-20 16:51:10 -07001101 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001102 folderChildTextSizePx = pxFromSp(inv.iconTextSize[mTypeIndex], mMetrics, scale);
Thales Lima7eee74b2023-03-16 16:00:55 -03001103 folderLabelTextSizePx = Math.max(pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale),
Thales Limab35faed2022-09-05 16:30:01 -03001104 (int) (folderChildTextSizePx * folderLabelTextScale));
Jon Mirandabf7d8122016-11-03 15:29:29 -07001105
1106 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001107
Jon Miranda823da222021-03-23 08:08:45 -04001108 if (isScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001109 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
Thales Lima7eee74b2023-03-16 16:00:55 -03001110 folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale);
1111 folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale);
1112 } else {
1113 folderCellWidthPx = roundPxValueFromFloat(folderCellWidthPx * scale);
1114 folderCellHeightPx = roundPxValueFromFloat(folderCellHeightPx * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001115 }
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001116
Thales Lima7eee74b2023-03-16 16:00:55 -03001117 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
1118 folderCellLayoutBorderSpacePx = roundPxValueFromFloat(
1119 folderCellLayoutBorderSpacePx * scale);
1120 folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale);
1121
Thales Limab35faed2022-09-05 16:30:01 -03001122 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx;
Jon Miranda823da222021-03-23 08:08:45 -04001123 } else {
1124 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1125 * scale);
1126 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1127 * scale);
1128
1129 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1130 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Lima7eee74b2023-03-16 16:00:55 -03001131 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001132 folderContentPaddingLeftRight =
1133 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1134 folderFooterHeightPx =
Thales Lima7eee74b2023-03-16 16:00:55 -03001135 roundPxValueFromFloat(
1136 res.getDimensionPixelSize(R.dimen.folder_footer_height_default)
1137 * scale);
1138
Jon Miranda823da222021-03-23 08:08:45 -04001139 }
1140
Jonathan Miranda9ad87462017-07-26 17:41:02 +00001141 folderChildDrawablePaddingPx = Math.max(0,
1142 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001143 }
1144
Winson1f064272016-07-18 17:18:02 -07001145 public void updateInsets(Rect insets) {
1146 mInsets.set(insets);
1147 }
1148
Sunny Goyalae6e3182019-04-30 12:04:37 -07001149 /**
1150 * The current device insets. This is generally same as the insets being dispatched to
1151 * {@link Insettable} elements, but can differ if the element is using a different profile.
1152 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001153 public Rect getInsets() {
1154 return mInsets;
1155 }
1156
Sunny Goyal756cd262015-08-20 12:33:21 -07001157 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001158 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001159 }
1160
Sunny Goyal19ff7282021-04-22 10:12:54 -07001161 public Point getCellSize(Point result) {
1162 if (result == null) {
1163 result = new Point();
1164 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001165
Pat Manning25d53342022-05-10 09:58:49 +00001166 int shortcutAndWidgetContainerWidth =
1167 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1168 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1169 inv.numColumns);
1170 int shortcutAndWidgetContainerHeight =
1171 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1172 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1173 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001174 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001175 }
1176
1177 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001178 * Returns the left and right space on the cell, which is the cell width - icon size
1179 */
1180 public int getCellHorizontalSpace() {
1181 return getCellSize().x - iconSizePx;
1182 }
1183
1184 /**
Pat Manning25d53342022-05-10 09:58:49 +00001185 * Gets the number of panels within the workspace.
1186 */
1187 public int getPanelCount() {
1188 return isTwoPanels ? 2 : 1;
1189 }
1190
1191 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001192 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1193 * bottom of the screen.
1194 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001195 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1196 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001197 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001198 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001199 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001200 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001201 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001202 }
1203
1204 /**
1205 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1206 */
Pat Manning25d53342022-05-10 09:58:49 +00001207 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001208 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001209 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001210 }
1211
1212 /**
1213 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1214 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001215 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001216 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001217 return heightPx - (isVerticalBarLayout()
1218 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001219 }
1220
Pat Manningea5c1d22022-04-14 10:58:16 +01001221 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001222 * Gets the scale of the workspace for the spring-loaded edit state.
1223 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001224 public float getWorkspaceSpringLoadScale(Context context) {
1225 float scale =
1226 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1227 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001228 scale = Math.min(scale, 1f);
1229
Pat Manninge63dd252022-08-02 16:15:29 +01001230 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001231 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001232 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001233 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001234 if (scaledWorkspaceWidth > maxAvailableWidth) {
1235 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1236 }
1237 return scale;
1238 }
1239
Pat Manning25d53342022-05-10 09:58:49 +00001240 /**
1241 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1242 *
1243 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1244 * layouts have two Cell Layouts per workspace.
1245 */
1246 public int getCellLayoutWidth() {
1247 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001248 }
1249
Pat Manning25d53342022-05-10 09:58:49 +00001250 /**
1251 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1252 *
1253 * <p>This is the height of a Workspace, less its vertical padding.
1254 */
1255 public int getCellLayoutHeight() {
1256 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001257 }
1258
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001259 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001260 return new Point(workspacePadding.left + workspacePadding.right,
1261 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001262 }
1263
1264 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001265 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1266 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001267 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001268 private void updateWorkspacePadding() {
1269 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001270 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -08001271 padding.top = 0;
1272 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001273 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001274 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -07001275 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -07001276 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -07001277 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001278 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -07001279 }
Winson Chungb3800242013-10-24 11:01:54 -07001280 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001281 // Pad the bottom of the workspace with hotseat bar
1282 // and leave a bit of space in case a widget go all the way down
1283 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding
1284 + workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace
1285 - mInsets.bottom;
Pat Manning08610ca2022-04-05 21:03:16 +01001286 int paddingTop = workspaceTopPadding + (isScalableGrid ? 0 : edgeMarginPx);
1287 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001288
Pat Manning08610ca2022-04-05 21:03:16 +01001289 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001290 }
Pat Manning08610ca2022-04-05 21:03:16 +01001291 insetPadding(workspacePadding, cellLayoutPaddingPx);
1292 }
1293
1294 private void insetPadding(Rect paddings, Rect insets) {
1295 insets.left = Math.min(insets.left, paddings.left);
1296 paddings.left -= insets.left;
1297
1298 insets.top = Math.min(insets.top, paddings.top);
1299 paddings.top -= insets.top;
1300
1301 insets.right = Math.min(insets.right, paddings.right);
1302 paddings.right -= insets.right;
1303
1304 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1305 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001306 }
1307
Sunny Goyal57b22792021-05-25 14:35:01 -07001308 /**
1309 * Returns the padding for hotseat view
1310 */
1311 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001312 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001313 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001314 // The hotseat icons will be placed in the middle of the hotseat cells.
1315 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1316 // in vertical bar layout.
1317 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1318 // is set to account for that difference.
1319 float diffOverlapFactor = iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
Pat Manning08610ca2022-04-05 21:03:16 +01001320 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1321 - diffOverlapFactor), 0);
1322 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001323 + diffOverlapFactor), 0);
1324
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001325 if (isSeascape()) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001326 hotseatBarPadding.set(mInsets.left + hotseatBarSidePaddingStartPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001327 hotseatBarSidePaddingEndPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001328 } else {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001329 hotseatBarPadding.set(hotseatBarSidePaddingEndPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001330 mInsets.right + hotseatBarSidePaddingStartPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001331 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001332 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001333 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001334 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1335 int hotseatBarTopPadding =
1336 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001337
Thales Lima6a590062022-11-22 15:52:49 +00001338 int hotseatWidth = getHotseatRequiredWidth();
Helen Cheuke76291f2023-02-14 17:11:05 +00001339 int startSpacing;
1340 int endSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001341 // Hotseat aligns to the left with nav buttons
1342 if (hotseatBarEndOffset > 0) {
Jon Mirandae17a9492023-03-08 16:42:20 -08001343 startSpacing = inlineNavButtonsEndSpacingPx;
Helen Cheuke76291f2023-02-14 17:11:05 +00001344 endSpacing = availableWidthPx - hotseatWidth - startSpacing + hotseatBorderSpace;
1345 } else {
1346 startSpacing = (availableWidthPx - hotseatWidth) / 2;
1347 endSpacing = startSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001348 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001349 startSpacing += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001350
Helen Cheuke76291f2023-02-14 17:11:05 +00001351 hotseatBarPadding.top = hotseatBarTopPadding;
1352 hotseatBarPadding.bottom = hotseatBarBottomPadding;
Alex Chau51da2192022-05-20 13:32:10 +01001353 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001354 if (isRtl) {
Helen Cheuke76291f2023-02-14 17:11:05 +00001355 hotseatBarPadding.left = endSpacing;
1356 hotseatBarPadding.right = startSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001357 } else {
Helen Cheuke76291f2023-02-14 17:11:05 +00001358 hotseatBarPadding.left = startSpacing;
1359 hotseatBarPadding.right = endSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001360 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001361
Thales Lima425f6822022-05-10 13:44:58 -03001362 } else if (isScalableGrid) {
Alex Chau206ede92022-08-01 17:46:12 +01001363 int sideSpacing = (availableWidthPx - hotseatQsbWidth) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001364 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001365 0,
Thales Lima425f6822022-05-10 13:44:58 -03001366 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001367 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001368 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001369 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1370 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1371 // for this, we pad the left and right of the hotseat with half of the difference of a
1372 // workspace cell vs a hotseat cell.
1373 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001374 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001375 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001376 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001377 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1378 + mInsets.left,
1379 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001380 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001381 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001382 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001383 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001384 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001385 }
1386
Thales Lima9938c2f2022-07-25 14:38:16 +01001387 private int getAdditionalQsbSpace() {
1388 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1389 }
1390
1391 /**
1392 * Calculate how much space the hotseat needs to be shown completely
1393 */
1394 private int getHotseatRequiredWidth() {
1395 int additionalQsbSpace = getAdditionalQsbSpace();
1396 return iconSizePx * numShownHotseatIcons
Thales Lima6a590062022-11-22 15:52:49 +00001397 + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1))
Thales Lima9938c2f2022-07-25 14:38:16 +01001398 + additionalQsbSpace;
1399 }
1400
Winsonfadbe8f2016-07-22 16:35:37 -07001401 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001402 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1403 */
1404 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001405 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001406 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1407 } else if (isTaskbarPresent) { // QSB on top
1408 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001409 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001410 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001411 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001412 }
1413
Thales Limab8c05952022-05-23 16:58:38 +01001414 /**
1415 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1416 */
1417 private int getHotseatBarBottomPadding() {
1418 if (isTaskbarPresent) { // QSB on top or inline
1419 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001420 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001421 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001422 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001423 }
1424
1425 /**
Alex Chau51da2192022-05-20 13:32:10 +01001426 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1427 */
1428 public int getTaskbarOffsetY() {
Jon Miranda9c478b62023-03-23 21:38:49 -07001429 int taskbarIconBottomSpace = (taskbarHeight - iconSizePx) / 2;
Alex Chau51da2192022-05-20 13:32:10 +01001430 int launcherIconBottomSpace =
1431 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001432 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001433 }
1434
1435 /**
Alex Chaua2fc7642022-04-21 14:20:23 +01001436 * Returns the number of pixels required below OverviewActions excluding insets.
1437 */
1438 public int getOverviewActionsClaimedSpaceBelow() {
Alex Chaud67ddc42022-09-30 18:15:56 +01001439 if (isTaskbarPresent) {
Jon Miranda9c478b62023-03-23 21:38:49 -07001440 return taskbarHeight + taskbarBottomMargin * 2;
Alex Chaud67ddc42022-09-30 18:15:56 +01001441 }
1442 return mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001443 }
1444
1445 /** Gets the space that the overview actions will take, including bottom margin. */
1446 public int getOverviewActionsClaimedSpace() {
Pat Manning7b8f7662023-01-18 14:48:30 +00001447 int overviewActionsSpace = isTablet && FeatureFlags.ENABLE_GRID_ONLY_OVERVIEW.get()
1448 ? 0
1449 : (overviewActionsTopMarginPx + overviewActionsHeight);
1450 return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
Alex Chaua2fc7642022-04-21 14:20:23 +01001451 }
1452
1453 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001454 * Takes the View and return the scales of width and height depending on the DeviceProfile
1455 * specifications
1456 *
1457 * @param itemInfo The tag of the widget view
1458 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1459 * height
1460 */
1461 @NonNull
1462 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1463 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1464 }
1465
1466 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001467 * @return the bounds for which the open folders should be contained within
1468 */
1469 public Rect getAbsoluteOpenFolderBounds() {
1470 if (isVerticalBarLayout()) {
1471 // Folders should only appear right of the drop target bar and left of the hotseat
1472 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1473 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001474 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001475 mInsets.top + availableHeightPx);
1476 } else {
1477 // Folders should only appear below the drop target bar and above the hotseat
Jon Miranda9c478b62023-03-23 21:38:49 -07001478 int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001479 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001480 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001481 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001482 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001483 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001484 }
1485 }
1486
Jon Miranda228877d2021-02-09 11:05:00 -05001487 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1488 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001489 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001490
Jon Miranda228877d2021-02-09 11:05:00 -05001491 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1492 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001493 }
1494
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001495 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001496 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1497 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1498 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001499 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001500 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001501 return isLandscape && transposeLayoutWithOrientation;
1502 }
1503
Sunny Goyal59d086c2018-05-07 17:31:40 -07001504 /**
1505 * Updates orientation information and returns true if it has changed from the previous value.
1506 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001507 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001508 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001509 boolean isSeascape = DisplayController.INSTANCE.get(context)
1510 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001511 if (mIsSeascape != isSeascape) {
1512 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001513 // Hotseat changing sides requires updating workspace left/right paddings
1514 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001515 return true;
1516 }
1517 }
1518 return false;
1519 }
1520
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001521 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001522 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001523 }
1524
Sunny Goyal07b69292018-01-08 14:19:34 -08001525 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001526 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001527 }
1528
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001529 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001530 switch (containerType) {
1531 case CellLayout.WORKSPACE:
1532 return cellHeightPx;
1533 case CellLayout.FOLDER:
1534 return folderCellHeightPx;
1535 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001536 // The hotseat is the only container where the cell height is going to be
1537 // different from the content within that cell.
1538 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001539 default:
1540 // ??
1541 return 0;
1542 }
1543 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001544
Jon Miranda58561d42021-03-17 10:51:54 -04001545 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001546 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001547 }
1548
Alex Chaue818bcb2022-09-02 17:27:11 +01001549 private String dpPointFToString(String name, PointF value) {
1550 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
1551 }
1552
Pat Manning5f74bfd2022-07-20 12:08:54 +01001553 /** Dumps various DeviceProfile variables to the specified writer. */
1554 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04001555 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001556 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001557
1558 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001559 writer.println(prefix + "\tisPhone:" + isPhone);
1560 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1561 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001562 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001563
1564 writer.println(prefix + "\tisLandscape:" + isLandscape);
1565 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001566 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001567
1568 writer.println(prefix + pxToDpStr("windowX", windowX));
1569 writer.println(prefix + pxToDpStr("windowY", windowY));
1570 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1571 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001572 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1573 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001574 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1575 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1576 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1577 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001578
1579 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1580
1581 writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
1582
Thales Lima83bedbf2021-10-05 17:47:39 +01001583 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001584 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1585 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1586 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001587
Alex Chaue818bcb2022-09-02 17:27:11 +01001588 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07001589
Jon Miranda58561d42021-03-17 10:51:54 -04001590 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1591 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1592
1593 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1594 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1595
Thales Lima83bedbf2021-10-05 17:47:39 +01001596 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1597 cellLayoutBorderSpacePx.x));
1598 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1599 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001600 writer.println(
1601 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
1602 writer.println(
1603 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
1604 writer.println(
1605 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01001606 writer.println(
1607 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01001608
Jon Miranda58561d42021-03-17 10:51:54 -04001609 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1610 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1611 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1612
Helen Cheuk599109b2023-02-23 17:15:39 +00001613 writer.println(prefix + "\tinv.numFolderRows: " + inv.numFolderRows);
1614 writer.println(prefix + "\tinv.numFolderColumns: " + inv.numFolderColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001615 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1616 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1617 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1618 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1619 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1620 folderChildDrawablePaddingPx));
Thales Limab35faed2022-09-05 16:30:01 -03001621 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx",
1622 folderCellLayoutBorderSpacePx));
Thales Limaa08a4432022-08-09 09:55:17 +01001623 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
1624 folderContentPaddingLeftRight));
1625 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03001626 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001627
Alex Chaue0227552022-04-06 19:44:43 +01001628 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001629 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
1630 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
1631 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
1632 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01001633
1634 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
1635 writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001636 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
1637 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04001638 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1639 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1640 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1641 allAppsIconDrawablePaddingPx));
1642 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001643 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001644 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
1645 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001646 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau62572c02022-07-25 18:36:37 +00001647 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
Alex Chau27b39b92022-01-14 18:02:18 +00001648 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001649
1650 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03001651 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04001652 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00001653 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Jon Miranda58561d42021-03-17 10:51:54 -04001654 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
1655 hotseatBarSidePaddingStartPx));
1656 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
1657 hotseatBarSidePaddingEndPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001658 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01001659 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
1660 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01001661 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
1662 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001663 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
1664 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
1665 hotseatLayoutPadding.top));
1666 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
1667 hotseatLayoutPadding.bottom));
1668 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
1669 hotseatLayoutPadding.left));
1670 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
1671 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001672 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001673 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001674 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01001675 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001676
1677 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001678 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda9c478b62023-03-23 21:38:49 -07001679 writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight));
1680 writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight));
1681 writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin));
1682 writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001683
Thales Lima83bedbf2021-10-05 17:47:39 +01001684 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1685 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001686 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
1687 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
1688 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00001689 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001690
Jon Mirandaab3c6812021-06-28 15:42:28 -07001691 writer.println(prefix + pxToDpStr("iconScale", iconScale));
1692 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04001693 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00001694 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001695
Thales Lima171ee662022-11-22 15:52:49 +00001696 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04001697 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
1698 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00001699
1700 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00001701 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
1702 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
1703 overviewTaskIconDrawableSizePx));
1704 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
1705 overviewTaskIconDrawableSizeGridPx));
1706 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
1707 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01001708 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
1709 overviewActionsTopMarginPx));
1710 writer.println(prefix + pxToDpStr("overviewActionsHeight",
1711 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00001712 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
1713 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00001714 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
1715 overviewActionsButtonSpacing));
1716 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
1717 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
1718 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01001719
Alex Chau62572c02022-07-25 18:36:37 +00001720 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001721 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00001722 writer.println(
1723 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001724
Pat Manning5f74bfd2022-07-20 12:08:54 +01001725 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
1726 getCellLayoutSpringLoadShrunkTop()));
1727 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
1728 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01001729 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
1730 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001731 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
1732 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01001733 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
1734 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Jon Miranda58561d42021-03-17 10:51:54 -04001735 }
1736
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00001737 /** Returns a reduced representation of this DeviceProfile. */
1738 public String toSmallString() {
1739 return "isTablet:" + isTablet + ", "
1740 + "isMultiDisplay:" + isMultiDisplay + ", "
1741 + "widthPx:" + widthPx + ", "
1742 + "heightPx:" + heightPx + ", "
1743 + "insets:" + mInsets + ", "
1744 + "rotationHint:" + rotationHint;
1745 }
1746
Alex Chaua6907dc2022-03-18 15:24:07 +00001747 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07001748 Configuration config = new Configuration(c.getResources().getConfiguration());
1749 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03001750 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00001751 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07001752 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07001753 }
Sunny Goyalfde55052018-02-01 14:46:13 -08001754
1755 /**
1756 * Callback when a component changes the DeviceProfile associated with it, as a result of
1757 * configuration change
1758 */
1759 public interface OnDeviceProfileChangeListener {
1760
1761 /**
1762 * Called when the device profile is reassigned. Note that for layout and measurements, it
1763 * is sufficient to listen for inset changes. Use this callback when you need to perform
1764 * a one time operation.
1765 */
1766 void onDeviceProfileChanged(DeviceProfile dp);
1767 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001768
Sihua Mae04aa202022-07-18 12:43:56 -07001769 /**
1770 * Handler that deals with ItemInfo of the views for the DeviceProfile
1771 */
1772 @FunctionalInterface
1773 public interface ViewScaleProvider {
1774 /**
1775 * Get the scales from the view
1776 *
1777 * @param itemInfo The tag of the widget view
1778 * @return PointF instance containing the scale information, or null if using the default
1779 * app widget scale of this device profile.
1780 */
1781 @NonNull
1782 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
1783 }
1784
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001785 public static class Builder {
1786 private Context mContext;
1787 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07001788 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001789
Sunny Goyal19ff7282021-04-22 10:12:54 -07001790 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00001791 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001792
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001793 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001794 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00001795 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07001796 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001797
Sunny Goyal65190ae2022-08-02 14:16:26 -07001798 private SparseArray<DotRenderer> mDotRendererCache;
1799
Jon Miranda2b25ded2023-02-02 14:48:45 -08001800 private Consumer<DeviceProfile> mOverrideProvider;
1801
Sunny Goyalfd58da62020-08-11 12:06:49 -07001802 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001803 mContext = context;
1804 mInv = inv;
1805 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001806 }
1807
1808 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1809 mIsMultiWindowMode = isMultiWindowMode;
1810 return this;
1811 }
1812
Alex Chauab800f72022-12-13 17:46:06 +00001813 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
1814 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001815 return this;
1816 }
1817
Sunny Goyal65190ae2022-08-02 14:16:26 -07001818 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
1819 mDotRendererCache = dotRendererCache;
1820 return this;
1821 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07001822
1823 public Builder setWindowBounds(WindowBounds bounds) {
1824 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07001825 return this;
1826 }
1827
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001828 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1829 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1830 return this;
1831 }
1832
Alex Chau6ed408f2022-03-04 12:58:05 +00001833 public Builder setGestureMode(boolean isGestureMode) {
1834 mIsGestureMode = isGestureMode;
1835 return this;
1836 }
1837
Jon Miranda2b25ded2023-02-02 14:48:45 -08001838 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
1839 mOverrideProvider = overrideProvider;
1840 return this;
1841 }
1842
Sihua Mae04aa202022-07-18 12:43:56 -07001843 /**
1844 * Set the viewScaleProvider for the builder
1845 *
1846 * @param viewScaleProvider The viewScaleProvider to be set for the
Thales Limae9273ea2023-01-26 12:33:52 +00001847 * DeviceProfile
Sihua Mae04aa202022-07-18 12:43:56 -07001848 * @return This builder
1849 */
1850 @NonNull
1851 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
1852 mViewScaleProvider = viewScaleProvider;
1853 return this;
1854 }
1855
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001856 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001857 if (mWindowBounds == null) {
1858 throw new IllegalArgumentException("Window bounds not set");
1859 }
1860 if (mTransposeLayoutWithOrientation == null) {
1861 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
1862 }
Alex Chau6ed408f2022-03-04 12:58:05 +00001863 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01001864 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00001865 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001866 if (mDotRendererCache == null) {
1867 mDotRendererCache = new SparseArray<>();
1868 }
Sihua Mae04aa202022-07-18 12:43:56 -07001869 if (mViewScaleProvider == null) {
1870 mViewScaleProvider = DEFAULT_PROVIDER;
1871 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08001872 if (mOverrideProvider == null) {
1873 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
1874 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001875 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00001876 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jon Miranda2b25ded2023-02-02 14:48:45 -08001877 mIsGestureMode, mViewScaleProvider, mOverrideProvider);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001878 }
1879 }
1880
Winson Chungb3800242013-10-24 11:01:54 -07001881}