blob: 0070f956662b1904bad762c7400f7d9b52257880 [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;
Jon Miranda228877d2021-02-09 11:05:00 -050031
Sunny Goyal35c7b192021-04-20 16:51:10 -070032import android.annotation.SuppressLint;
Winson Chungb3800242013-10-24 11:01:54 -070033import android.content.Context;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070034import android.content.res.Configuration;
Winson Chungb3800242013-10-24 11:01:54 -070035import android.content.res.Resources;
Thales Limab35faed2022-09-05 16:30:01 -030036import android.content.res.TypedArray;
Winson Chungb3800242013-10-24 11:01:54 -070037import android.graphics.Point;
Jon Miranda7ae64ff2016-11-21 16:18:46 -080038import android.graphics.PointF;
Winson Chungb3800242013-10-24 11:01:54 -070039import android.graphics.Rect;
Sunny Goyal35c7b192021-04-20 16:51:10 -070040import android.util.DisplayMetrics;
Sunny Goyal65190ae2022-08-02 14:16:26 -070041import android.util.SparseArray;
Sunny Goyal59d086c2018-05-07 17:31:40 -070042import android.view.Surface;
Winson Chungb3800242013-10-24 11:01:54 -070043
Sunny Goyal65190ae2022-08-02 14:16:26 -070044import androidx.annotation.NonNull;
Sihua Mae04aa202022-07-18 12:43:56 -070045import androidx.annotation.Nullable;
Sunny Goyal65190ae2022-08-02 14:16:26 -070046
Sunny Goyalc13403c2016-11-18 23:44:48 -080047import com.android.launcher3.CellLayout.ContainerType;
Jon Miranda228877d2021-02-09 11:05:00 -050048import com.android.launcher3.DevicePaddings.DevicePadding;
Alex Chaud67ddc42022-09-30 18:15:56 +010049import com.android.launcher3.config.FeatureFlags;
Tony Wickham8912b042018-11-29 15:28:53 -080050import com.android.launcher3.icons.DotRenderer;
Hyunyoung Song48cb7bc2018-09-25 17:03:34 -070051import com.android.launcher3.icons.IconNormalizer;
Sihua Mae04aa202022-07-18 12:43:56 -070052import com.android.launcher3.model.data.ItemInfo;
Sunny Goyal57b22792021-05-25 14:35:01 -070053import com.android.launcher3.uioverrides.ApiWrapper;
Sunny Goyalfd58da62020-08-11 12:06:49 -070054import com.android.launcher3.util.DisplayController;
55import com.android.launcher3.util.DisplayController.Info;
Sunny Goyalb46703d2020-05-27 17:52:03 -070056import com.android.launcher3.util.WindowBounds;
Winson1f064272016-07-18 17:18:02 -070057
Jon Miranda58561d42021-03-17 10:51:54 -040058import java.io.PrintWriter;
Alex Chaue818bcb2022-09-02 17:27:11 +010059import java.util.Locale;
Jon Miranda2b25ded2023-02-02 14:48:45 -080060import java.util.function.Consumer;
Jon Miranda58561d42021-03-17 10:51:54 -040061
Sunny Goyal35c7b192021-04-20 16:51:10 -070062@SuppressLint("NewApi")
Winson Chungb3800242013-10-24 11:01:54 -070063public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070064
Sunny Goyal8b9919d2021-04-07 14:45:17 -070065 private static final int DEFAULT_DOT_SIZE = 100;
Alex Chau206ede92022-08-01 17:46:12 +010066 private static final float ALL_APPS_TABLET_MAX_ROWS = 5.5f;
Thales Limab35faed2022-09-05 16:30:01 -030067 private static final float MIN_FOLDER_TEXT_SIZE_SP = 16f;
Alex Chau206ede92022-08-01 17:46:12 +010068
Sihua Mae04aa202022-07-18 12:43:56 -070069 public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f);
70 public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE;
Jon Miranda2b25ded2023-02-02 14:48:45 -080071 public static final Consumer<DeviceProfile> DEFAULT_DIMENSION_PROVIDER = dp -> {};
Sihua Mae04aa202022-07-18 12:43:56 -070072
Sunny Goyal57b22792021-05-25 14:35:01 -070073 // Ratio of empty space, qsb should take up to appear visually centered.
Pratyush9afe1ea2021-10-13 11:13:27 +000074 private final float mQsbCenterFactor;
Sunny Goyal1890f672020-04-30 12:28:00 -070075
Adam Cohen2e6da152015-05-06 11:42:25 -070076 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070077 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070078 private final DisplayMetrics mMetrics;
Winson Chungbe876472014-05-14 14:15:20 -070079
Sunny Goyalc6205602015-05-21 20:46:33 -070080 // Device properties
81 public final boolean isTablet;
Sunny Goyalc6205602015-05-21 20:46:33 -070082 public final boolean isPhone;
83 public final boolean transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +000084 public final boolean isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -070085 public final boolean isTwoPanels;
Thales Limaa1012902022-01-13 17:58:42 +000086 public final boolean isQsbInline;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -070087
Sunny Goyalc6205602015-05-21 20:46:33 -070088 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -070089 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -080090 public final boolean isMultiWindowMode;
Alex Chau6ed408f2022-03-04 12:58:05 +000091 public final boolean isGestureMode;
Sunny Goyald70e75a2018-02-22 10:07:32 -080092
Sunny Goyal0addbf02020-04-28 14:17:35 -070093 public final int windowX;
94 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -070095 public final int widthPx;
96 public final int heightPx;
97 public final int availableWidthPx;
98 public final int availableHeightPx;
Sunny Goyal187b16c2022-03-01 16:53:23 -080099 public final int rotationHint;
Jon Mirandabba64512019-03-27 10:54:17 -0700100
101 public final float aspectRatio;
102
Jon Mirandae126d722021-02-25 10:45:20 -0500103 public final boolean isScalableGrid;
Thales Lima83bedbf2021-10-05 17:47:39 +0100104 private final int mTypeIndex;
Jon Mirandae126d722021-02-25 10:45:20 -0500105
Tony Wickhamd6b40372015-09-23 18:37:57 -0700106 /**
107 * The maximum amount of left/right workspace padding as a percentage of the screen width.
108 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
109 * 7% of the screen width can be used as right padding.
110 */
111 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -0700112
Jon Miranda3f9bab22017-07-28 14:50:17 -0700113 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700114 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda80dda302021-07-28 14:14:59 -0700115 private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252;
116 private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700117
Sunny Goyalc6205602015-05-21 20:46:33 -0700118 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +0100119 public final int desiredWorkspaceHorizontalMarginOriginalPx;
120 public int desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100121 public int gridVisualizationPaddingX;
122 public int gridVisualizationPaddingY;
Thales Lima78d00ad2021-09-30 11:29:06 +0100123 public Point cellLayoutBorderSpaceOriginalPx;
124 public Point cellLayoutBorderSpacePx;
Pat Manning08610ca2022-04-05 21:03:16 +0100125 public Rect cellLayoutPaddingPx = new Rect();
126
Sunny Goyalc6205602015-05-21 20:46:33 -0700127 public final int edgeMarginPx;
Alex Chau0c4e11b2022-07-08 18:41:36 +0100128 public final float workspaceContentScale;
Alex Chau906d8822022-05-23 10:42:25 +0100129 public final int workspaceSpringLoadedMinNextPageVisiblePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700130
Jon Miranda58561d42021-03-17 10:51:54 -0400131 private final int extraSpace;
Thales Lima171ee662022-11-22 15:52:49 +0000132 private int maxEmptySpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500133 public int workspaceTopPadding;
134 public int workspaceBottomPadding;
135
Tony Wickham5edf9e22020-03-27 20:06:52 -0700136 // Workspace page indicator
137 public final int workspacePageIndicatorHeight;
138 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700139
Sunny Goyalc6205602015-05-21 20:46:33 -0700140 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400141 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700142 public int iconSizePx;
143 public int iconTextSizePx;
144 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700145 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -0700146
Jon Mirandaab3c6812021-06-28 15:42:28 -0700147 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800148 public int cellWidthPx;
149 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700150 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800151
Jon Mirandae126d722021-02-25 10:45:20 -0500152 public int cellYPaddingPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500153
Sunny Goyalc6205602015-05-21 20:46:33 -0700154 // Folder
Jon Mirandae126d722021-02-25 10:45:20 -0500155 public float folderLabelTextScale;
156 public int folderLabelTextSizePx;
Thales Limab35faed2022-09-05 16:30:01 -0300157 public int folderFooterHeightPx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700158 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700159 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700160
Jon Mirandae126d722021-02-25 10:45:20 -0500161 // Folder content
Thales Limab35faed2022-09-05 16:30:01 -0300162 public int folderCellLayoutBorderSpacePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500163 public int folderContentPaddingLeftRight;
164 public int folderContentPaddingTop;
165
Jon Mirandabf7d8122016-11-03 15:29:29 -0700166 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700167 public int folderCellWidthPx;
168 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700169
170 // Folder child
171 public int folderChildIconSizePx;
172 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700173 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700174
Sunny Goyalc6205602015-05-21 20:46:33 -0700175 // Hotseat
Thales Lima9938c2f2022-07-25 14:38:16 +0100176 public int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700177 public int hotseatCellHeightPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100178 public final boolean areNavButtonsInline;
Jon Miranda18751b62017-07-31 17:25:27 -0700179 // In portrait: size = height, in landscape: size = width
180 public int hotseatBarSizePx;
Thales Limab8c05952022-05-23 16:58:38 +0100181 public int hotseatBarBottomSpacePx;
Pat Manning26f70f72022-07-07 13:50:39 +0100182 public int hotseatBarEndOffset;
Thales Limab8c05952022-05-23 16:58:38 +0100183 public int hotseatQsbSpace;
Pat Manningde25c0d2022-04-05 19:11:26 +0100184 public int springLoadedHotseatBarTopMarginPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700185 // Start is the side next to the nav bar, end is the side next to the workspace
186 public final int hotseatBarSidePaddingStartPx;
187 public final int hotseatBarSidePaddingEndPx;
Alex Chau206ede92022-08-01 17:46:12 +0100188 public int hotseatQsbWidth; // only used when isQsbInline
Sunny Goyal57b22792021-05-25 14:35:01 -0700189 public final int hotseatQsbHeight;
Thales Limab8c05952022-05-23 16:58:38 +0100190 public final int hotseatQsbVisualHeight;
191 private final int hotseatQsbShadowHeight;
Thales Limadd027342022-01-07 12:54:37 +0000192 public int hotseatBorderSpace;
Thales Lima6a590062022-11-22 15:52:49 +0000193 private int minHotseatIconSpacePx;
194 private int minHotseatQsbWidthPx;
195 private final int maxHotseatIconSpacePx;
196 private int inlineNavButtonsEndSpacing;
Adam Cohen2e6da152015-05-06 11:42:25 -0700197
Alex Chau3d2c0622022-09-01 21:28:14 +0100198 // Bottom sheets
199 public int bottomSheetTopPadding;
200 public int bottomSheetOpenDuration;
201 public int bottomSheetCloseDuration;
202 public float bottomSheetWorkspaceScale;
203 public float bottomSheetDepth;
204
Sunny Goyalc6205602015-05-21 20:46:33 -0700205 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000206 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000207 public int allAppsShiftRange;
208 public int allAppsTopPadding;
Alex Chau3d2c0622022-09-01 21:28:14 +0100209 public int allAppsOpenDuration;
210 public int allAppsCloseDuration;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700211 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700212 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700213 public int allAppsIconSizePx;
214 public int allAppsIconDrawablePaddingPx;
sfufa@google.comde013292021-09-21 18:22:44 -0700215 public int allAppsLeftRightPadding;
Alex Chau27b39b92022-01-14 18:02:18 +0000216 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700217 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700218 public float allAppsIconTextSizePx;
219
Zak Cohen334efeb2021-03-19 16:42:07 -0700220 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700221 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000222 public int overviewTaskIconSizePx;
Alex Chauac9df382021-08-02 19:08:41 +0100223 public int overviewTaskIconDrawableSizePx;
224 public int overviewTaskIconDrawableSizeGridPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000225 public int overviewTaskThumbnailTopMarginPx;
Alex Chau19c6eca2022-03-10 20:12:56 +0000226 public final int overviewActionsHeight;
Alex Chaua2fc7642022-04-21 14:20:23 +0100227 public final int overviewActionsTopMarginPx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000228 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100229 public int overviewPageSpacing;
230 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000231 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700232
Jeremy Sim0ac47082022-10-10 13:59:40 -0700233 // Split staging
234 public int splitPlaceholderInset;
235
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800236 // Widgets
Sihua Mae04aa202022-07-18 12:43:56 -0700237 private final ViewScaleProvider mViewScaleProvider;
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800238
Sunny Goyal47328fd2016-05-25 18:56:41 -0700239 // Drop Target
240 public int dropTargetBarSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100241 public int dropTargetBarTopMarginPx;
242 public int dropTargetBarBottomMarginPx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100243 public int dropTargetDragPaddingPx;
244 public int dropTargetTextSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100245 public int dropTargetHorizontalPaddingPx;
246 public int dropTargetVerticalPaddingPx;
247 public int dropTargetGapPx;
Alex Chau5b019302022-05-23 10:42:25 +0100248 public int dropTargetButtonWorkspaceEdgeGapPx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700249
Winson1f064272016-07-18 17:18:02 -0700250 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800251 private final Rect mInsets = new Rect();
252 public final Rect workspacePadding = new Rect();
Jon Miranda0bd63d12019-03-06 17:29:29 -0800253 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700254 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700255
Tony Wickhamf34bee82018-12-03 18:11:39 -0800256 // Notification dots
Sunny Goyal65190ae2022-08-02 14:16:26 -0700257 public final DotRenderer mDotRendererWorkSpace;
258 public final DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800259
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100260 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800261 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000262 // Whether Taskbar will inset the bottom of apps by taskbarSize.
263 public boolean isTaskbarPresentInApps;
Tony Wickham15883892021-02-12 11:24:40 -0800264 public int taskbarSize;
Alex Chau85d664e2023-01-16 16:31:59 +0000265 public int transientTaskbarSize;
Alex Chau6a7d1e22022-01-20 19:54:17 +0000266 public int stashedTaskbarSize;
Alex Chau905e0f12022-11-14 21:55:37 +0000267 public int transientTaskbarMargin;
Tony Wickham15883892021-02-12 11:24:40 -0800268
Alex Chaua02eddc2021-04-29 00:36:06 +0100269 // DragController
270 public int flingToDeleteThresholdVelocity;
271
Vinit Nayak17c4b332021-08-05 12:54:58 -0700272 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700273 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal65190ae2022-08-02 14:16:26 -0700274 SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
Alex Chauab800f72022-12-13 17:46:06 +0000275 boolean transposeLayoutWithOrientation, boolean isMultiDisplay, boolean isGestureMode,
Jon Miranda2b25ded2023-02-02 14:48:45 -0800276 @NonNull final ViewScaleProvider viewScaleProvider,
277 @NonNull final Consumer<DeviceProfile> dimensionOverrideProvider) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700278
Adam Cohen2e6da152015-05-06 11:42:25 -0700279 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700280 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800281 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500282 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +0000283 this.isMultiDisplay = isMultiDisplay;
Alex Chau6ed408f2022-03-04 12:58:05 +0000284 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700285 windowX = windowBounds.bounds.left;
286 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800287 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100288 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700289
Jon Mirandae126d722021-02-25 10:45:20 -0500290 isScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000291 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700292 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000293 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700294 isPhone = !isTablet;
Alex Chauab800f72022-12-13 17:46:06 +0000295 isTwoPanels = isTablet && isMultiDisplay;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800296 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700297
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000298 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000299 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700300 ? Configuration.ORIENTATION_LANDSCAPE
301 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000302 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700303 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000304 mMetrics = res.getDisplayMetrics();
305
306 // Determine sizes.
307 widthPx = windowBounds.bounds.width();
308 heightPx = windowBounds.bounds.height();
309 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100310 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000311
312 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
313 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
314 mQsbCenterFactor = res.getFloat(R.dimen.qsb_center_factor);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700315
Thales Lima83bedbf2021-10-05 17:47:39 +0100316 if (isTwoPanels) {
317 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000318 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100319 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000320 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100321 }
322 } else {
323 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000324 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100325 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000326 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100327 }
328 }
329
Tony Wickham15883892021-02-12 11:24:40 -0800330 if (isTaskbarPresent) {
Alex Chau85d664e2023-01-16 16:31:59 +0000331 transientTaskbarSize = res.getDimensionPixelSize(R.dimen.transient_taskbar_size);
332 transientTaskbarMargin = res.getDimensionPixelSize(R.dimen.transient_taskbar_margin);
Jon Miranda7e819502022-11-03 10:56:32 -0700333 if (DisplayController.isTransientTaskbar(context)) {
Alex Chau85d664e2023-01-16 16:31:59 +0000334 taskbarSize = transientTaskbarSize;
Jon Miranda7e819502022-11-03 10:56:32 -0700335 stashedTaskbarSize =
336 res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_size);
337 } else {
338 taskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_size);
339 stashedTaskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
340 }
Tony Wickham15883892021-02-12 11:24:40 -0800341 }
Tony Wickham15883892021-02-12 11:24:40 -0800342
Winson Chungb3800242013-10-24 11:01:54 -0700343 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100344 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700345
Thales Limad90faab2021-09-21 17:18:47 +0100346 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
347 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100348 gridVisualizationPaddingX = res.getDimensionPixelSize(
349 R.dimen.grid_visualization_horizontal_cell_spacing);
350 gridVisualizationPaddingY = res.getDimensionPixelSize(
351 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500352
Alex Chaue0227552022-04-06 19:44:43 +0100353 bottomSheetTopPadding = mInsets.top // statusbar height
Andras Kloczl142b0542022-03-09 21:26:02 +0000354 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
355 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
Alex Chau3d2c0622022-09-01 21:28:14 +0100356 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
357 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
358 if (isTablet) {
359 bottomSheetWorkspaceScale = workspaceContentScale;
Alex Chauab800f72022-12-13 17:46:06 +0000360 if (isMultiDisplay && !ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH.get()) {
361 // TODO(b/259893832): Revert to use maxWallpaperScale to calculate bottomSheetDepth
362 // when screen recorder bug is fixed.
363 bottomSheetDepth = 1f;
364 } else {
365 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
366 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
367 // When depth is 1, wallpaper zoom is set to 1.
368 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
369 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
370 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
371 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
372 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100373 } else {
374 bottomSheetWorkspaceScale = 1f;
375 bottomSheetDepth = 0f;
376 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000377
Jon Mirandae126d722021-02-25 10:45:20 -0500378 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
Thales Limab35faed2022-09-05 16:30:01 -0300379
380 if (inv.folderStyle != INVALID_RESOURCE_HANDLE) {
381 TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
Thales Limad852d652023-01-17 14:01:13 +0000382 R.styleable.FolderStyle);
Thales Limab35faed2022-09-05 16:30:01 -0300383 // These are re-set in #updateFolderCellSize if the grid is not scalable
384 folderCellHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000385 R.styleable.FolderStyle_folderCellHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300386 folderCellWidthPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000387 R.styleable.FolderStyle_folderCellWidth, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300388
389 folderContentPaddingTop = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000390 R.styleable.FolderStyle_folderTopPadding, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300391 folderCellLayoutBorderSpacePx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000392 R.styleable.FolderStyle_folderBorderSpace, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300393 folderFooterHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000394 R.styleable.FolderStyle_folderFooterHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300395 folderStyle.recycle();
396 } else {
397 folderCellLayoutBorderSpacePx = 0;
398 folderFooterHeightPx = 0;
399 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
400 }
Jon Mirandae126d722021-02-25 10:45:20 -0500401
Thales Lima78d00ad2021-09-30 11:29:06 +0100402 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv);
Thales Limab35faed2022-09-05 16:30:01 -0300403 cellLayoutBorderSpaceOriginalPx = new Point(cellLayoutBorderSpacePx);
Thales Lima85c942f2021-12-31 13:04:20 +0000404 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000405 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
406 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Jon Mirandae126d722021-02-25 10:45:20 -0500407
Tony Wickham5edf9e22020-03-27 20:06:52 -0700408 workspacePageIndicatorHeight = res.getDimensionPixelSize(
409 R.dimen.workspace_page_indicator_height);
410 mWorkspacePageIndicatorOverlapWorkspace =
411 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700412
Thales Limad852d652023-01-17 14:01:13 +0000413 TypedArray cellStyle;
414 if (inv.cellStyle != INVALID_RESOURCE_HANDLE) {
415 cellStyle = context.obtainStyledAttributes(inv.cellStyle,
416 R.styleable.CellStyle);
417 } else {
418 cellStyle = context.obtainStyledAttributes(R.style.CellStyleDefault,
419 R.styleable.CellStyle);
420 }
421 iconDrawablePaddingOriginalPx = cellStyle.getDimensionPixelSize(
422 R.styleable.CellStyle_iconDrawablePadding, 0);
423 cellStyle.recycle();
Alex Chaua02eddc2021-04-29 00:36:06 +0100424
Sunny Goyal47328fd2016-05-25 18:56:41 -0700425 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100426 dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
427 dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100428 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
429 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100430 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
431 R.dimen.drop_target_button_drawable_horizontal_padding);
432 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
433 R.dimen.drop_target_button_drawable_vertical_padding);
434 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100435 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
436 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100437
Alex Chau906d8822022-05-23 10:42:25 +0100438 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
439 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700440
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700441 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700442
Thales Limaa1012902022-01-13 17:58:42 +0000443 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100444 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
445 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
446
Thales Lima12d0eff2022-03-25 17:06:11 +0000447 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
448 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
449 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
450 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
451 && hotseatQsbHeight > 0;
Thales Lima6a590062022-11-22 15:52:49 +0000452 isQsbInline = isScalableGrid && inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000453
Thales Lima425f6822022-05-10 13:44:58 -0300454 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100455 numShownHotseatIcons =
456 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000457
Sunny Goyal19ff7282021-04-22 10:12:54 -0700458 numShownAllAppsColumns =
459 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100460
461 int hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
462 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
463 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
464 // Have a little space between the inset and the QSB
465 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
466 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
467
468 // Only change the spaces if there is space
469 if (availableSpace > 0) {
470 // Make sure there is enough space between hotseat/QSB and QSB/navBar
471 if (availableSpace < minQsbMargin * 2) {
472 minQsbMargin = availableSpace / 2;
473 hotseatQsbSpace = minQsbMargin;
474 } else {
475 hotseatQsbSpace -= minQsbMargin;
476 }
477 }
478 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
479
Thales Limaa1012902022-01-13 17:58:42 +0000480 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100481 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
Thales Limaa1012902022-01-13 17:58:42 +0000482 }
Thales Lima425f6822022-05-10 13:44:58 -0300483
Pat Manningde25c0d2022-04-05 19:11:26 +0100484 springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
485 R.dimen.spring_loaded_hotseat_top_margin);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700486 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800487 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700488 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700489 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Thales Limab8c05952022-05-23 16:58:38 +0100490 updateHotseatSizes(pxFromDp(inv.iconSize[INDEX_DEFAULT], mMetrics));
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700491 if (areNavButtonsInline && !isPhone) {
Thales Lima6a590062022-11-22 15:52:49 +0000492 inlineNavButtonsEndSpacing = res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing);
Pat Manning26f70f72022-07-07 13:50:39 +0100493 /*
494 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700495 * Spacing between nav buttons +
Thales Lima6a590062022-11-22 15:52:49 +0000496 * Space at the end for contextual buttons
Pat Manning26f70f72022-07-07 13:50:39 +0100497 */
498 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700499 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
Thales Lima6a590062022-11-22 15:52:49 +0000500 + inlineNavButtonsEndSpacing;
Pat Manning26f70f72022-07-07 13:50:39 +0100501 } else {
Thales Lima6a590062022-11-22 15:52:49 +0000502 inlineNavButtonsEndSpacing = 0;
Pat Manning26f70f72022-07-07 13:50:39 +0100503 hotseatBarEndOffset = 0;
504 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700505
Alex Chau635b3ab2022-01-26 16:49:10 +0000506 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chau5fd9d492021-07-22 17:27:11 +0100507 overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100508 overviewTaskIconDrawableSizePx =
509 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
510 overviewTaskIconDrawableSizeGridPx =
511 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700512 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx;
Jeremy Sim3c2c3f12022-05-16 20:37:43 -0700513 overviewActionsTopMarginPx = res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000514 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
515 overviewActionsButtonSpacing = res.getDimensionPixelSize(
516 R.dimen.overview_actions_button_spacing);
Alex Chau19c6eca2022-03-10 20:12:56 +0000517 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700518 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000519 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700520
Jeremy Sim0ac47082022-10-10 13:59:40 -0700521 splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset);
522
Jon Miranda2ed276e2017-06-29 11:36:34 -0700523 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400524 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700525
Jon Miranda2ed276e2017-06-29 11:36:34 -0700526 // Now that we have all of the variables calculated, we can tune certain sizes.
Thales Limaae0d7ef2022-11-16 15:53:43 +0000527 if (isScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400528 // Paddings were created assuming no scaling, so we first unscale the extra space.
Jon Mirandaab3c6812021-06-28 15:42:28 -0700529 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
Thales Limaae0d7ef2022-11-16 15:53:43 +0000530 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
531 DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
Thales Lima171ee662022-11-22 15:52:49 +0000532 maxEmptySpace = padding.getMaxEmptySpacePx();
Jon Miranda228877d2021-02-09 11:05:00 -0500533
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400534 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
535 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
536 int paddingHotseatBottom = padding.getHotseatBottomPadding(unscaledExtraSpace);
537
Jon Mirandaab3c6812021-06-28 15:42:28 -0700538 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
539 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700540 }
Pat Manning08610ca2022-04-05 21:03:16 +0100541
542 int cellLayoutPadding =
543 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
544 R.dimen.cell_layout_padding);
545 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
546 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800547 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800548
Thales Lima6a590062022-11-22 15:52:49 +0000549 minHotseatIconSpacePx = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
550 minHotseatQsbWidthPx = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
551 maxHotseatIconSpacePx = areNavButtonsInline
552 ? res.getDimensionPixelSize(R.dimen.max_hotseat_icon_space) : Integer.MAX_VALUE;
Thales Lima425f6822022-05-10 13:44:58 -0300553 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima6a590062022-11-22 15:52:49 +0000554 recalculateHotseatWidthAndBorderSpace();
Alex Chau206ede92022-08-01 17:46:12 +0100555
556 // AllApps height calculation depends on updated cellSize
557 if (isTablet) {
558 int collapseHandleHeight =
559 res.getDimensionPixelOffset(R.dimen.bottom_sheet_handle_area_height);
560 int contentHeight = heightPx - collapseHandleHeight - hotseatQsbHeight;
561 int targetContentHeight = (int) (allAppsCellHeightPx * ALL_APPS_TABLET_MAX_ROWS);
562 allAppsTopPadding = Math.max(mInsets.top, contentHeight - targetContentHeight);
563 allAppsShiftRange = heightPx - allAppsTopPadding;
564 } else {
565 allAppsTopPadding = 0;
566 allAppsShiftRange =
567 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
568 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100569 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
570 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300571
Alex Chaua02eddc2021-04-29 00:36:06 +0100572 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
573 R.dimen.drag_flingToDeleteMinVelocity);
574
Sihua Mae04aa202022-07-18 12:43:56 -0700575 mViewScaleProvider = viewScaleProvider;
576
Jon Miranda2b25ded2023-02-02 14:48:45 -0800577 dimensionOverrideProvider.accept(this);
578
Tony Wickham1237df02017-02-24 08:59:36 -0800579 // This is done last, after iconSizePx is calculated above.
Sunny Goyal65190ae2022-08-02 14:16:26 -0700580 mDotRendererWorkSpace = createDotRenderer(iconSizePx, dotRendererCache);
581 mDotRendererAllApps = createDotRenderer(allAppsIconSizePx, dotRendererCache);
582 }
583
584 private static DotRenderer createDotRenderer(
585 int size, @NonNull SparseArray<DotRenderer> cache) {
586 DotRenderer renderer = cache.get(size);
587 if (renderer == null) {
588 renderer = new DotRenderer(size, getShapePath(DEFAULT_DOT_SIZE), DEFAULT_DOT_SIZE);
589 cache.put(size, renderer);
590 }
591 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700592 }
593
Thales Lima425f6822022-05-10 13:44:58 -0300594 /**
595 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
596 * width of the hotseat.
597 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100598 private int calculateQsbWidth(int hotseatBorderSpace) {
Thales Lima425f6822022-05-10 13:44:58 -0300599 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100600 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300601 return getIconToIconWidthForColumns(columns)
602 - iconSizePx * numShownHotseatIcons
603 - hotseatBorderSpace * numShownHotseatIcons;
604 } else {
605 int columns = inv.hotseatColumnSpan[mTypeIndex];
606 return getIconToIconWidthForColumns(columns);
607 }
608 }
Thales Lima2903a622022-03-17 13:52:19 +0000609
Thales Lima425f6822022-05-10 13:44:58 -0300610 private int getIconToIconWidthForColumns(int columns) {
611 return columns * getCellSize().x
612 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400613 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000614 }
615
Thales Limad90faab2021-09-21 17:18:47 +0100616 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
617 if (isVerticalBarLayout()) {
618 return 0;
619 }
620
Thales Lima83bedbf2021-10-05 17:47:39 +0100621 return isScalableGrid
622 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
623 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100624 }
625
Thales Limab8c05952022-05-23 16:58:38 +0100626 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
627 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700628 // Ensure there is enough space for folder icons, which have a slightly larger radius.
629 hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR);
Thales Limab8c05952022-05-23 16:58:38 +0100630
Jon Miranda0d284852021-06-22 14:50:55 -0700631 if (isVerticalBarLayout()) {
632 hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
633 + hotseatBarSidePaddingEndPx;
Thales Limab8c05952022-05-23 16:58:38 +0100634 } else if (isQsbInline) {
635 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
636 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700637 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100638 hotseatBarSizePx = hotseatIconSizePx
639 + hotseatQsbSpace
640 + hotseatQsbVisualHeight
641 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700642 }
643 }
644
Thales Lima6a590062022-11-22 15:52:49 +0000645 /**
646 * Calculates the width of the hotseat, changing spaces between the icons and removing icons if
647 * necessary.
648 */
649 public void recalculateHotseatWidthAndBorderSpace() {
650 if (!isScalableGrid) return;
651
652 int columns = inv.hotseatColumnSpan[mTypeIndex];
653 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
654 hotseatBorderSpace = calculateHotseatBorderSpace(hotseatWidthPx, /* numExtraBorder= */ 0);
Thales Lima9938c2f2022-07-25 14:38:16 +0100655 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
Thales Lima6a590062022-11-22 15:52:49 +0000656 // Spaces should be correct when the nav buttons are not inline
Thales Lima9938c2f2022-07-25 14:38:16 +0100657 if (!areNavButtonsInline) {
658 return;
659 }
660
Thales Lima6a590062022-11-22 15:52:49 +0000661 // The side space with inline buttons should be what is defined in InvariantDeviceProfile
662 int sideSpace = inlineNavButtonsEndSpacing;
663 int maxHotseatWidth = availableWidthPx - sideSpace - hotseatBarEndOffset;
664 int maxHotseatIconsWidth = maxHotseatWidth - (isQsbInline ? hotseatQsbWidth : 0);
665 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidth,
666 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100667
Thales Lima6a590062022-11-22 15:52:49 +0000668 if (hotseatBorderSpace >= minHotseatIconSpacePx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100669 return;
670 }
671
672 // Border space can't be less than the minimum
Thales Lima6a590062022-11-22 15:52:49 +0000673 hotseatBorderSpace = minHotseatIconSpacePx;
674 int requiredWidth = getHotseatRequiredWidth();
Thales Lima9938c2f2022-07-25 14:38:16 +0100675
676 // If there is an inline qsb, change its size
677 if (isQsbInline) {
678 hotseatQsbWidth -= requiredWidth - maxHotseatWidth;
Thales Lima6a590062022-11-22 15:52:49 +0000679 if (hotseatQsbWidth >= minHotseatQsbWidthPx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100680 return;
681 }
682
683 // QSB can't be less than the minimum
Thales Lima6a590062022-11-22 15:52:49 +0000684 hotseatQsbWidth = minHotseatQsbWidthPx;
Thales Lima9938c2f2022-07-25 14:38:16 +0100685 }
686
Thales Lima6a590062022-11-22 15:52:49 +0000687 maxHotseatIconsWidth = maxHotseatWidth - (isQsbInline ? hotseatQsbWidth : 0);
688
Thales Lima9938c2f2022-07-25 14:38:16 +0100689 // If it still doesn't fit, start removing icons
690 do {
691 numShownHotseatIcons--;
Thales Lima6a590062022-11-22 15:52:49 +0000692 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidth,
693 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
694 } while (hotseatBorderSpace < minHotseatIconSpacePx && numShownHotseatIcons > 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100695
Thales Lima9938c2f2022-07-25 14:38:16 +0100696 }
697
Thales Lima78d00ad2021-09-30 11:29:06 +0100698 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100699 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100700 }
701
702 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100703 if (!isScalableGrid) {
704 return new Point(0, 0);
705 }
706
Thales Lima080d8902022-03-28 15:30:29 +0100707 int horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
708 int verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
Thales Lima78d00ad2021-09-30 11:29:06 +0100709
710 return new Point(horizontalSpacePx, verticalSpacePx);
711 }
712
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700713 public Info getDisplayInfo() {
714 return mInfo;
715 }
716
Jon Miranda611dba42021-03-02 14:12:13 -0500717 /**
718 * We inset the widget padding added by the system and instead rely on the border spacing
719 * between cells to create reliable consistency between widgets
720 */
721 public boolean shouldInsetWidgets() {
722 Rect widgetPadding = inv.defaultWidgetPadding;
723
Jon Miranda49811182021-06-03 09:52:40 -0700724 // Check all sides to ensure that the widget won't overlap into another cell, or into
725 // status bar.
726 return workspaceTopPadding > widgetPadding.top
Thales Lima78d00ad2021-09-30 11:29:06 +0100727 && cellLayoutBorderSpacePx.x > widgetPadding.left
728 && cellLayoutBorderSpacePx.y > widgetPadding.top
729 && cellLayoutBorderSpacePx.x > widgetPadding.right
730 && cellLayoutBorderSpacePx.y > widgetPadding.bottom;
Jon Miranda611dba42021-03-02 14:12:13 -0500731 }
Jon Mirandae126d722021-02-25 10:45:20 -0500732
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700733 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800734 WindowBounds bounds = new WindowBounds(
735 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700736 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100737 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700738
739 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
740 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
741 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
742
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700743 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700744 .setWindowBounds(bounds)
Alex Chauab800f72022-12-13 17:46:06 +0000745 .setIsMultiDisplay(isMultiDisplay)
Alex Chau6ed408f2022-03-04 12:58:05 +0000746 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700747 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000748 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800749 }
750
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700751 public DeviceProfile copy(Context context) {
752 return toBuilder(context).build();
753 }
754
755 /**
756 * TODO: Move this to the builder as part of setMultiWindowMode
757 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700758 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700759 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700760 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700761 .setMultiWindowMode(true)
762 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800763
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800764 // We use these scales to measure and layout the widgets using their full invariant profile
765 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
766 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
767 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700768 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
769 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
770 profile = profile.toBuilder(context)
771 .setViewScaleProvider(i -> p)
772 .build();
773 }
774
775 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800776
Jon Miranda93e1f042016-11-11 14:13:04 -0800777 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700778 }
779
Adam Cohen63f1ec02014-08-12 09:23:13 -0700780 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400781 * Checks if there is enough space for labels on the workspace.
782 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700783 * It is important to call this method after the All Apps variables have been set.
784 */
Jon Miranda941375e2021-03-31 13:10:45 -0400785 private void hideWorkspaceLabelsIfNotEnoughSpace() {
786 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
787 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
788 - iconTextHeight;
789
790 // We want enough space so that the text is closer to its corresponding icon.
791 if (workspaceCellPaddingY < iconTextHeight) {
792 iconTextSizePx = 0;
793 iconDrawablePaddingPx = 0;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700794 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda941375e2021-03-31 13:10:45 -0400795 autoResizeAllAppsCells();
796 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700797 }
Jon Miranda1091e532017-07-21 13:31:50 -0700798
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700799 /**
800 * Re-computes the all-apps cell size to be independent of workspace
801 */
802 public void autoResizeAllAppsCells() {
Jon Miranda941375e2021-03-31 13:10:45 -0400803 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
804 int topBottomPadding = textHeight;
Jon Miranda1091e532017-07-21 13:31:50 -0700805 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
Jon Miranda941375e2021-03-31 13:10:45 -0400806 + textHeight + (topBottomPadding * 2);
Jon Miranda1091e532017-07-21 13:31:50 -0700807 }
808
Thales Limab7ef5692022-03-10 10:32:36 +0000809 private void updateAllAppsContainerWidth(Resources res) {
Pat Manning08610ca2022-04-05 21:03:16 +0100810 int cellLayoutHorizontalPadding =
811 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
Alex Chau27b39b92022-01-14 18:02:18 +0000812 if (isTablet) {
Thales Limab7ef5692022-03-10 10:32:36 +0000813 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100814 res.getDimensionPixelSize(R.dimen.all_apps_bottom_sheet_horizontal_padding);
815
sfufa@google.comde013292021-09-21 18:22:44 -0700816 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
Thales Limab7ef5692022-03-10 10:32:36 +0000817 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Alex Chau27b39b92022-01-14 18:02:18 +0000818 + allAppsLeftRightPadding * 2;
819 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
sfufa@google.comde013292021-09-21 18:22:44 -0700820 } else {
821 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100822 desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding;
sfufa@google.comde013292021-09-21 18:22:44 -0700823 }
824 }
825
Jon Miranda228877d2021-02-09 11:05:00 -0500826 /**
827 * Returns the amount of extra (or unused) vertical space.
828 */
829 private int updateAvailableDimensions(Resources res) {
Alex Chaua68164d2022-12-15 16:16:03 +0000830 float invIconSizeDp = inv.iconSize[mTypeIndex];
831 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
832 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
833 iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
834
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700835 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800836
Pat Manning08610ca2022-04-05 21:03:16 +0100837 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -0500838
839 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +0100840 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +0000841 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -0500842 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500843 float scaleY = maxHeight / usedHeight;
844 boolean shouldScale = scaleY < 1f;
845
846 float scaleX = 1f;
847 if (isScalableGrid) {
848 // We scale to fit the cellWidth and cellHeight in the available space.
849 // The benefit of scalable grids is that we can get consistent aspect ratios between
850 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +0100851 float usedWidth =
852 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500853 // We do not subtract padding here, as we also scale the workspace padding if needed.
854 scaleX = availableWidthPx / usedWidth;
855 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700856 }
Jon Mirandae126d722021-02-25 10:45:20 -0500857
858 if (shouldScale) {
859 float scale = Math.min(scaleX, scaleY);
860 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +0100861 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -0500862 }
863
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700864 updateAvailableFolderCellDimensions(res);
Jon Miranda228877d2021-02-09 11:05:00 -0500865 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700866 }
867
Pat Manninga2e14992022-04-22 11:29:17 +0100868 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +0100869 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
870 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
871 }
872
Pat Manninga2e14992022-04-22 11:29:17 +0100873 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +0000874 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +0100875 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
876 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -0500877 }
878
Jon Miranda6f7e9702019-09-16 14:44:14 -0700879 /**
880 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
881 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
882 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
883 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800884 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -0700885 // Icon scale should never exceed 1, otherwise pixellation may occur.
886 iconScale = Math.min(1f, scale);
887 cellScaleToFit = scale;
888
Jon Miranda18751b62017-07-31 17:25:27 -0700889 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800890 final boolean isVerticalLayout = isVerticalBarLayout();
Jon Mirandaab3c6812021-06-28 15:42:28 -0700891 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);
Thales Lima080d8902022-03-28 15:30:29 +0100892 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500893
894 if (isScalableGrid) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100895 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
896 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +0000897
898 if (cellWidthPx < iconSizePx) {
899 // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger.
900 int numColumns = getPanelCount() * inv.numColumns;
901 int numBorders = numColumns - 1;
902 int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns;
903 if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) {
904 cellWidthPx = iconSizePx;
905 cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders;
906 } else {
907 // If it still doesn't fit, set borderSpace to 0 and distribute the space for
908 // cellWidth, and reduce iconSize.
909 cellWidthPx = (cellWidthPx * numColumns
910 + cellLayoutBorderSpacePx.x * numBorders) / numColumns;
911 iconSizePx = Math.min(iconSizePx, cellWidthPx);
912 cellLayoutBorderSpacePx.x = 0;
913 }
914 }
915
916 int cellTextAndPaddingHeight =
917 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
918 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
919 if (cellHeightPx < cellContentHeight) {
920 // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight
921 // bigger.
922 int numBorders = inv.numRows - 1;
923 int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows;
924 if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) {
925 cellHeightPx = cellContentHeight;
926 cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders;
927 } else {
Alex Chau06f36e82023-01-06 10:50:54 +0000928 // If it still doesn't fit, set borderSpace to 0 to recover space.
Alex Chaube753132022-12-09 16:46:54 +0000929 cellHeightPx = (cellHeightPx * inv.numRows
930 + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows;
Alex Chaube753132022-12-09 16:46:54 +0000931 cellLayoutBorderSpacePx.y = 0;
Alex Chau06f36e82023-01-06 10:50:54 +0000932 // Reduce iconDrawablePaddingPx to make cellContentHeight smaller.
933 int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx;
934 if (cellContentWithoutPadding <= cellHeightPx) {
935 iconDrawablePaddingPx = cellContentHeight - cellHeightPx;
936 } else {
937 // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space,
938 // then proportional reduce iconSizePx and iconTextSizePx to fit.
939 iconDrawablePaddingPx = 0;
940 float ratio = cellHeightPx / (float) cellContentWithoutPadding;
941 iconSizePx = (int) (iconSizePx * ratio);
942 iconTextSizePx = (int) (iconTextSizePx * ratio);
943 }
944 cellTextAndPaddingHeight =
945 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +0000946 }
947 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
948 }
Jon Mirandae126d722021-02-25 10:45:20 -0500949 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +0100950 desiredWorkspaceHorizontalMarginPx =
951 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -0500952 } else {
Jon Mirandae126d722021-02-25 10:45:20 -0500953 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700954 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR)
955 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -0500956 + Utilities.calculateTextHeight(iconTextSizePx);
957 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
958 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
959 && !isMultiWindowMode) {
960 // Ensures that the label is closer to its corresponding icon. This is not an issue
961 // with vertical bar layout or multi-window mode since the issue is handled
962 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
963 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
964 iconDrawablePaddingPx = cellPaddingY;
965 }
Jon Miranda846455e2017-10-02 14:58:52 -0700966 }
Jon Miranda18751b62017-07-31 17:25:27 -0700967
Sunny Goyalae190ff2020-04-14 00:19:01 +0000968 // All apps
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500969 updateAllAppsIconSize(scale, res);
Winson Chungb3800242013-10-24 11:01:54 -0700970
Thales Limab8c05952022-05-23 16:58:38 +0100971 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700972
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700973 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -0700974 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
975 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Winson Chung0f785722015-04-08 10:27:49 -0700976 }
977
Thales Lima425f6822022-05-10 13:44:58 -0300978 /**
Thales Lima6a590062022-11-22 15:52:49 +0000979 * This method calculates the space between the icons to achieve a certain width.
Thales Lima425f6822022-05-10 13:44:58 -0300980 */
Thales Lima6a590062022-11-22 15:52:49 +0000981 private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100982 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
Thales Lima6a590062022-11-22 15:52:49 +0000983 int hotseatBorderSpace =
984 (int) (hotseatWidthPx - hotseatIconsTotalPx)
985 / (numShownHotseatIcons - 1 + numExtraBorder);
986 return Math.min(hotseatBorderSpace, maxHotseatIconSpacePx);
Thales Lima425f6822022-05-10 13:44:58 -0300987 }
988
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500989
990 /**
991 * Updates the iconSize for allApps* variants.
992 */
Brian Isganitisa9a78112022-05-23 18:11:47 -0700993 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +0100994 allAppsBorderSpacePx = new Point(
995 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
996 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700997 // AllApps cells don't have real space between cells,
998 // so we add the border space to the cell height
Alex Chaube753132022-12-09 16:46:54 +0000999 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics)
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001000 + allAppsBorderSpacePx.y;
1001 // but width is just the cell,
1002 // the border is added in #updateAllAppsContainerWidth
Thales Lima080d8902022-03-28 15:30:29 +01001003 if (isScalableGrid) {
Alex Chaube753132022-12-09 16:46:54 +00001004 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1005 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001006 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001007 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001008
1009 if (allAppsCellWidthPx < allAppsIconSizePx) {
1010 // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to
1011 // make allAppsCellWidth bigger.
1012 int numBorders = inv.numAllAppsColumns - 1;
1013 int extraWidthRequired =
1014 (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns;
1015 if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) {
1016 allAppsCellWidthPx = allAppsIconSizePx;
1017 allAppsBorderSpacePx.x -= extraWidthRequired / numBorders;
1018 } else {
1019 // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space
1020 // for allAppsCellWidth, and reduce allAppsIconSize.
1021 allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns
1022 + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns;
1023 allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx);
1024 allAppsBorderSpacePx.x = 0;
1025 }
1026 }
1027
1028 int cellContentHeight = allAppsIconSizePx
1029 + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y;
1030 if (allAppsCellHeightPx < cellContentHeight) {
1031 // Increase allAppsCellHeight to fit its content.
1032 allAppsCellHeightPx = cellContentHeight;
1033 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001034 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001035 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
1036 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001037 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1038 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001039 allAppsIconDrawablePaddingPx =
1040 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001041 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001042 }
1043
Thales Limab7ef5692022-03-10 10:32:36 +00001044 updateAllAppsContainerWidth(res);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001045 if (isVerticalBarLayout()) {
1046 hideWorkspaceLabelsIfNotEnoughSpace();
1047 }
1048 }
1049
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001050 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001051 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001052
Jon Mirandac1b23992016-12-13 08:57:36 -08001053 // Don't let the folder get too close to the edges of the screen.
Jon Miranda1786df32018-09-25 13:05:23 -07001054 int folderMargin = edgeMarginPx * 2;
Sunny Goyal07b69292018-01-08 14:19:34 -08001055 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -08001056
1057 // Check if the icons fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -05001058 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Thales Limab35faed2022-09-05 16:30:01 -03001059 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx);
1060 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderFooterHeightPx
Jon Mirandae126d722021-02-25 10:45:20 -05001061 - folderMargin - folderContentPaddingTop;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001062 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -08001063
1064 // Check if the icons fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -05001065 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Thales Limab35faed2022-09-05 16:30:01 -03001066 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx);
Jon Mirandae126d722021-02-25 10:45:20 -05001067 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin
1068 - folderContentPaddingLeftRight * 2;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001069 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -08001070
1071 float scale = Math.min(scaleX, scaleY);
1072 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001073 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001074 }
1075 }
1076
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001077 private void updateFolderCellSize(float scale, Resources res) {
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001078 float invIconSizeDp = inv.iconSize[mTypeIndex];
Sunny Goyal35c7b192021-04-20 16:51:10 -07001079 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001080 folderChildTextSizePx = pxFromSp(inv.iconTextSize[mTypeIndex], mMetrics, scale);
Thales Limab35faed2022-09-05 16:30:01 -03001081 folderLabelTextSizePx = Math.max(pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics),
1082 (int) (folderChildTextSizePx * folderLabelTextScale));
Jon Mirandabf7d8122016-11-03 15:29:29 -07001083
1084 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001085
Jon Miranda823da222021-03-23 08:08:45 -04001086 if (isScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001087 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
1088 folderCellWidthPx = pxFromDp(getCellSize().x, mMetrics, scale);
1089 folderCellHeightPx = pxFromDp(getCellSize().y, mMetrics, scale);
1090 }
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001091
Thales Limab35faed2022-09-05 16:30:01 -03001092 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx;
Jon Miranda823da222021-03-23 08:08:45 -04001093 } else {
1094 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1095 * scale);
1096 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1097 * scale);
1098
1099 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1100 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Limab35faed2022-09-05 16:30:01 -03001101 folderContentPaddingLeftRight =
1102 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1103 folderFooterHeightPx =
1104 res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Jon Miranda823da222021-03-23 08:08:45 -04001105 }
1106
Jonathan Miranda9ad87462017-07-26 17:41:02 +00001107 folderChildDrawablePaddingPx = Math.max(0,
1108 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001109 }
1110
Winson1f064272016-07-18 17:18:02 -07001111 public void updateInsets(Rect insets) {
1112 mInsets.set(insets);
1113 }
1114
Sunny Goyalae6e3182019-04-30 12:04:37 -07001115 /**
1116 * The current device insets. This is generally same as the insets being dispatched to
1117 * {@link Insettable} elements, but can differ if the element is using a different profile.
1118 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001119 public Rect getInsets() {
1120 return mInsets;
1121 }
1122
Sunny Goyal756cd262015-08-20 12:33:21 -07001123 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001124 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001125 }
1126
Sunny Goyal19ff7282021-04-22 10:12:54 -07001127 public Point getCellSize(Point result) {
1128 if (result == null) {
1129 result = new Point();
1130 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001131
Pat Manning25d53342022-05-10 09:58:49 +00001132 int shortcutAndWidgetContainerWidth =
1133 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1134 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1135 inv.numColumns);
1136 int shortcutAndWidgetContainerHeight =
1137 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1138 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1139 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001140 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001141 }
1142
1143 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001144 * Returns the left and right space on the cell, which is the cell width - icon size
1145 */
1146 public int getCellHorizontalSpace() {
1147 return getCellSize().x - iconSizePx;
1148 }
1149
1150 /**
Pat Manning25d53342022-05-10 09:58:49 +00001151 * Gets the number of panels within the workspace.
1152 */
1153 public int getPanelCount() {
1154 return isTwoPanels ? 2 : 1;
1155 }
1156
1157 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001158 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1159 * bottom of the screen.
1160 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001161 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1162 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001163 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001164 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001165 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001166 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001167 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001168 }
1169
1170 /**
1171 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1172 */
Pat Manning25d53342022-05-10 09:58:49 +00001173 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001174 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001175 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001176 }
1177
1178 /**
1179 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1180 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001181 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001182 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001183 return heightPx - (isVerticalBarLayout()
1184 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001185 }
1186
Pat Manningea5c1d22022-04-14 10:58:16 +01001187 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001188 * Gets the scale of the workspace for the spring-loaded edit state.
1189 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001190 public float getWorkspaceSpringLoadScale(Context context) {
1191 float scale =
1192 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1193 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001194 scale = Math.min(scale, 1f);
1195
Pat Manninge63dd252022-08-02 16:15:29 +01001196 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001197 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001198 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001199 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001200 if (scaledWorkspaceWidth > maxAvailableWidth) {
1201 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1202 }
1203 return scale;
1204 }
1205
Pat Manning25d53342022-05-10 09:58:49 +00001206 /**
1207 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1208 *
1209 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1210 * layouts have two Cell Layouts per workspace.
1211 */
1212 public int getCellLayoutWidth() {
1213 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001214 }
1215
Pat Manning25d53342022-05-10 09:58:49 +00001216 /**
1217 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1218 *
1219 * <p>This is the height of a Workspace, less its vertical padding.
1220 */
1221 public int getCellLayoutHeight() {
1222 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001223 }
1224
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001225 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001226 return new Point(workspacePadding.left + workspacePadding.right,
1227 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001228 }
1229
1230 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001231 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1232 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001233 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001234 private void updateWorkspacePadding() {
1235 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001236 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -08001237 padding.top = 0;
1238 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001239 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001240 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -07001241 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -07001242 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -07001243 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001244 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -07001245 }
Winson Chungb3800242013-10-24 11:01:54 -07001246 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001247 // Pad the bottom of the workspace with hotseat bar
1248 // and leave a bit of space in case a widget go all the way down
1249 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding
1250 + workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace
1251 - mInsets.bottom;
Pat Manning08610ca2022-04-05 21:03:16 +01001252 int paddingTop = workspaceTopPadding + (isScalableGrid ? 0 : edgeMarginPx);
1253 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001254
Pat Manning08610ca2022-04-05 21:03:16 +01001255 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001256 }
Pat Manning08610ca2022-04-05 21:03:16 +01001257 insetPadding(workspacePadding, cellLayoutPaddingPx);
1258 }
1259
1260 private void insetPadding(Rect paddings, Rect insets) {
1261 insets.left = Math.min(insets.left, paddings.left);
1262 paddings.left -= insets.left;
1263
1264 insets.top = Math.min(insets.top, paddings.top);
1265 paddings.top -= insets.top;
1266
1267 insets.right = Math.min(insets.right, paddings.right);
1268 paddings.right -= insets.right;
1269
1270 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1271 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001272 }
1273
Sunny Goyal57b22792021-05-25 14:35:01 -07001274 /**
1275 * Returns the padding for hotseat view
1276 */
1277 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001278 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001279 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001280 // The hotseat icons will be placed in the middle of the hotseat cells.
1281 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1282 // in vertical bar layout.
1283 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1284 // is set to account for that difference.
1285 float diffOverlapFactor = iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
Pat Manning08610ca2022-04-05 21:03:16 +01001286 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1287 - diffOverlapFactor), 0);
1288 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001289 + diffOverlapFactor), 0);
1290
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001291 if (isSeascape()) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001292 hotseatBarPadding.set(mInsets.left + hotseatBarSidePaddingStartPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001293 hotseatBarSidePaddingEndPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001294 } else {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001295 hotseatBarPadding.set(hotseatBarSidePaddingEndPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001296 mInsets.right + hotseatBarSidePaddingStartPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001297 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001298 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001299 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001300 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1301 int hotseatBarTopPadding =
1302 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001303
Thales Lima6a590062022-11-22 15:52:49 +00001304 int hotseatWidth = getHotseatRequiredWidth();
1305 int leftSpacing = (availableWidthPx - hotseatWidth) / 2;
1306 int rightSpacing = leftSpacing;
1307 // Hotseat aligns to the left with nav buttons
1308 if (hotseatBarEndOffset > 0) {
1309 leftSpacing = inlineNavButtonsEndSpacing;
1310 rightSpacing = availableWidthPx - hotseatWidth - leftSpacing + hotseatBorderSpace;
1311 }
Thales Lima612230d2022-03-31 18:04:37 +01001312
Thales Lima6a590062022-11-22 15:52:49 +00001313 hotseatBarPadding.set(leftSpacing, hotseatBarTopPadding, rightSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001314 hotseatBarBottomPadding);
Alex Chau51da2192022-05-20 13:32:10 +01001315
1316 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001317 if (isRtl) {
Thales Lima9938c2f2022-07-25 14:38:16 +01001318 hotseatBarPadding.right += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001319 } else {
Thales Lima9938c2f2022-07-25 14:38:16 +01001320 hotseatBarPadding.left += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001321 }
Thales Lima425f6822022-05-10 13:44:58 -03001322 } else if (isScalableGrid) {
Alex Chau206ede92022-08-01 17:46:12 +01001323 int sideSpacing = (availableWidthPx - hotseatQsbWidth) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001324 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001325 0,
Thales Lima425f6822022-05-10 13:44:58 -03001326 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001327 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001328 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001329 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1330 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1331 // for this, we pad the left and right of the hotseat with half of the difference of a
1332 // workspace cell vs a hotseat cell.
1333 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001334 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001335 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001336 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001337 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1338 + mInsets.left,
1339 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001340 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001341 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001342 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001343 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001344 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001345 }
1346
Thales Lima9938c2f2022-07-25 14:38:16 +01001347 private int getAdditionalQsbSpace() {
1348 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1349 }
1350
1351 /**
1352 * Calculate how much space the hotseat needs to be shown completely
1353 */
1354 private int getHotseatRequiredWidth() {
1355 int additionalQsbSpace = getAdditionalQsbSpace();
1356 return iconSizePx * numShownHotseatIcons
Thales Lima6a590062022-11-22 15:52:49 +00001357 + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1))
Thales Lima9938c2f2022-07-25 14:38:16 +01001358 + additionalQsbSpace;
1359 }
1360
Winsonfadbe8f2016-07-22 16:35:37 -07001361 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001362 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1363 */
1364 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001365 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001366 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1367 } else if (isTaskbarPresent) { // QSB on top
1368 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001369 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001370 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001371 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001372 }
1373
Thales Limab8c05952022-05-23 16:58:38 +01001374 /**
1375 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1376 */
1377 private int getHotseatBarBottomPadding() {
1378 if (isTaskbarPresent) { // QSB on top or inline
1379 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001380 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001381 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001382 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001383 }
1384
1385 /**
Alex Chau51da2192022-05-20 13:32:10 +01001386 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1387 */
1388 public int getTaskbarOffsetY() {
1389 int taskbarIconBottomSpace = (taskbarSize - iconSizePx) / 2;
1390 int launcherIconBottomSpace =
1391 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001392 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001393 }
1394
1395 /**
Alex Chaua2fc7642022-04-21 14:20:23 +01001396 * Returns the number of pixels required below OverviewActions excluding insets.
1397 */
1398 public int getOverviewActionsClaimedSpaceBelow() {
Alex Chaud67ddc42022-09-30 18:15:56 +01001399 if (isTaskbarPresent) {
Alex Chau905e0f12022-11-14 21:55:37 +00001400 if (FeatureFlags.ENABLE_TASKBAR_IN_OVERVIEW.get()) {
Alex Chau85d664e2023-01-16 16:31:59 +00001401 return transientTaskbarSize + transientTaskbarMargin * 2;
Alex Chau905e0f12022-11-14 21:55:37 +00001402 }
1403
1404 return isGestureMode
1405 ? stashedTaskbarSize
1406 // Align vertically to where nav buttons are.
1407 : ((taskbarSize - overviewActionsHeight) / 2) + getTaskbarOffsetY();
Alex Chaud67ddc42022-09-30 18:15:56 +01001408 }
1409 return mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001410 }
1411
1412 /** Gets the space that the overview actions will take, including bottom margin. */
1413 public int getOverviewActionsClaimedSpace() {
Pat Manning7b8f7662023-01-18 14:48:30 +00001414 int overviewActionsSpace = isTablet && FeatureFlags.ENABLE_GRID_ONLY_OVERVIEW.get()
1415 ? 0
1416 : (overviewActionsTopMarginPx + overviewActionsHeight);
1417 return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
Alex Chaua2fc7642022-04-21 14:20:23 +01001418 }
1419
1420 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001421 * Takes the View and return the scales of width and height depending on the DeviceProfile
1422 * specifications
1423 *
1424 * @param itemInfo The tag of the widget view
1425 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1426 * height
1427 */
1428 @NonNull
1429 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1430 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1431 }
1432
1433 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001434 * @return the bounds for which the open folders should be contained within
1435 */
1436 public Rect getAbsoluteOpenFolderBounds() {
1437 if (isVerticalBarLayout()) {
1438 // Folders should only appear right of the drop target bar and left of the hotseat
1439 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1440 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001441 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001442 mInsets.top + availableHeightPx);
1443 } else {
1444 // Folders should only appear below the drop target bar and above the hotseat
Tony Wickhamae72b462021-03-10 16:18:40 -08001445 int hotseatTop = isTaskbarPresent ? taskbarSize : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001446 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001447 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001448 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001449 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001450 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001451 }
1452 }
1453
Jon Miranda228877d2021-02-09 11:05:00 -05001454 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1455 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001456 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001457
Jon Miranda228877d2021-02-09 11:05:00 -05001458 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1459 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001460 }
1461
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001462 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001463 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1464 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1465 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001466 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001467 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001468 return isLandscape && transposeLayoutWithOrientation;
1469 }
1470
Sunny Goyal59d086c2018-05-07 17:31:40 -07001471 /**
1472 * Updates orientation information and returns true if it has changed from the previous value.
1473 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001474 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001475 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001476 boolean isSeascape = DisplayController.INSTANCE.get(context)
1477 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001478 if (mIsSeascape != isSeascape) {
1479 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001480 // Hotseat changing sides requires updating workspace left/right paddings
1481 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001482 return true;
1483 }
1484 }
1485 return false;
1486 }
1487
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001488 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001489 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001490 }
1491
Sunny Goyal07b69292018-01-08 14:19:34 -08001492 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001493 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001494 }
1495
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001496 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001497 switch (containerType) {
1498 case CellLayout.WORKSPACE:
1499 return cellHeightPx;
1500 case CellLayout.FOLDER:
1501 return folderCellHeightPx;
1502 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001503 // The hotseat is the only container where the cell height is going to be
1504 // different from the content within that cell.
1505 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001506 default:
1507 // ??
1508 return 0;
1509 }
1510 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001511
Jon Miranda58561d42021-03-17 10:51:54 -04001512 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001513 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001514 }
1515
Alex Chaue818bcb2022-09-02 17:27:11 +01001516 private String dpPointFToString(String name, PointF value) {
1517 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
1518 }
1519
Pat Manning5f74bfd2022-07-20 12:08:54 +01001520 /** Dumps various DeviceProfile variables to the specified writer. */
1521 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04001522 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001523 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001524
1525 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001526 writer.println(prefix + "\tisPhone:" + isPhone);
1527 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1528 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001529 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001530
1531 writer.println(prefix + "\tisLandscape:" + isLandscape);
1532 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001533 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001534
1535 writer.println(prefix + pxToDpStr("windowX", windowX));
1536 writer.println(prefix + pxToDpStr("windowY", windowY));
1537 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1538 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001539 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1540 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001541 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1542 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1543 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1544 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001545
1546 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1547
1548 writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
1549
Thales Lima83bedbf2021-10-05 17:47:39 +01001550 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001551 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1552 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1553 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001554
Alex Chaue818bcb2022-09-02 17:27:11 +01001555 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07001556
Jon Miranda58561d42021-03-17 10:51:54 -04001557 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1558 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1559
1560 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1561 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1562
Thales Lima83bedbf2021-10-05 17:47:39 +01001563 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1564 cellLayoutBorderSpacePx.x));
1565 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1566 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001567 writer.println(
1568 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
1569 writer.println(
1570 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
1571 writer.println(
1572 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01001573 writer.println(
1574 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01001575
Jon Miranda58561d42021-03-17 10:51:54 -04001576 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1577 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1578 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1579
1580 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1581 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1582 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1583 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1584 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1585 folderChildDrawablePaddingPx));
Thales Limab35faed2022-09-05 16:30:01 -03001586 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx",
1587 folderCellLayoutBorderSpacePx));
Thales Limaa08a4432022-08-09 09:55:17 +01001588 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
1589 folderContentPaddingLeftRight));
1590 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03001591 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001592
Alex Chaue0227552022-04-06 19:44:43 +01001593 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001594 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
1595 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
1596 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
1597 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01001598
1599 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
1600 writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001601 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
1602 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04001603 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1604 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1605 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1606 allAppsIconDrawablePaddingPx));
1607 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001608 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001609 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
1610 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001611 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau62572c02022-07-25 18:36:37 +00001612 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
Alex Chau27b39b92022-01-14 18:02:18 +00001613 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001614
1615 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03001616 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04001617 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00001618 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Jon Miranda58561d42021-03-17 10:51:54 -04001619 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
1620 hotseatBarSidePaddingStartPx));
1621 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
1622 hotseatBarSidePaddingEndPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001623 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01001624 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
1625 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01001626 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
1627 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001628 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
1629 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
1630 hotseatLayoutPadding.top));
1631 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
1632 hotseatLayoutPadding.bottom));
1633 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
1634 hotseatLayoutPadding.left));
1635 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
1636 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001637 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001638 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001639 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01001640 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001641
1642 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001643 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda58561d42021-03-17 10:51:54 -04001644 writer.println(prefix + pxToDpStr("taskbarSize", taskbarSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001645
Thales Lima83bedbf2021-10-05 17:47:39 +01001646 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1647 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001648 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
1649 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
1650 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00001651 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001652
Jon Mirandaab3c6812021-06-28 15:42:28 -07001653 writer.println(prefix + pxToDpStr("iconScale", iconScale));
1654 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04001655 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00001656 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001657
Thales Lima171ee662022-11-22 15:52:49 +00001658 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04001659 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
1660 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00001661
1662 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00001663 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
1664 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
1665 overviewTaskIconDrawableSizePx));
1666 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
1667 overviewTaskIconDrawableSizeGridPx));
1668 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
1669 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01001670 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
1671 overviewActionsTopMarginPx));
1672 writer.println(prefix + pxToDpStr("overviewActionsHeight",
1673 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00001674 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
1675 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00001676 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
1677 overviewActionsButtonSpacing));
1678 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
1679 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
1680 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01001681
Alex Chau62572c02022-07-25 18:36:37 +00001682 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001683 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00001684 writer.println(
1685 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001686
Pat Manning5f74bfd2022-07-20 12:08:54 +01001687 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
1688 getCellLayoutSpringLoadShrunkTop()));
1689 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
1690 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01001691 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
1692 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001693 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
1694 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01001695 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
1696 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Jon Miranda58561d42021-03-17 10:51:54 -04001697 }
1698
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00001699 /** Returns a reduced representation of this DeviceProfile. */
1700 public String toSmallString() {
1701 return "isTablet:" + isTablet + ", "
1702 + "isMultiDisplay:" + isMultiDisplay + ", "
1703 + "widthPx:" + widthPx + ", "
1704 + "heightPx:" + heightPx + ", "
1705 + "insets:" + mInsets + ", "
1706 + "rotationHint:" + rotationHint;
1707 }
1708
Alex Chaua6907dc2022-03-18 15:24:07 +00001709 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07001710 Configuration config = new Configuration(c.getResources().getConfiguration());
1711 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03001712 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00001713 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07001714 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07001715 }
Sunny Goyalfde55052018-02-01 14:46:13 -08001716
1717 /**
1718 * Callback when a component changes the DeviceProfile associated with it, as a result of
1719 * configuration change
1720 */
1721 public interface OnDeviceProfileChangeListener {
1722
1723 /**
1724 * Called when the device profile is reassigned. Note that for layout and measurements, it
1725 * is sufficient to listen for inset changes. Use this callback when you need to perform
1726 * a one time operation.
1727 */
1728 void onDeviceProfileChanged(DeviceProfile dp);
1729 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001730
Sihua Mae04aa202022-07-18 12:43:56 -07001731 /**
1732 * Handler that deals with ItemInfo of the views for the DeviceProfile
1733 */
1734 @FunctionalInterface
1735 public interface ViewScaleProvider {
1736 /**
1737 * Get the scales from the view
1738 *
1739 * @param itemInfo The tag of the widget view
1740 * @return PointF instance containing the scale information, or null if using the default
1741 * app widget scale of this device profile.
1742 */
1743 @NonNull
1744 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
1745 }
1746
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001747 public static class Builder {
1748 private Context mContext;
1749 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07001750 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001751
Sunny Goyal19ff7282021-04-22 10:12:54 -07001752 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00001753 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001754
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001755 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001756 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00001757 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07001758 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001759
Sunny Goyal65190ae2022-08-02 14:16:26 -07001760 private SparseArray<DotRenderer> mDotRendererCache;
1761
Jon Miranda2b25ded2023-02-02 14:48:45 -08001762 private Consumer<DeviceProfile> mOverrideProvider;
1763
Sunny Goyalfd58da62020-08-11 12:06:49 -07001764 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001765 mContext = context;
1766 mInv = inv;
1767 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001768 }
1769
1770 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1771 mIsMultiWindowMode = isMultiWindowMode;
1772 return this;
1773 }
1774
Alex Chauab800f72022-12-13 17:46:06 +00001775 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
1776 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001777 return this;
1778 }
1779
Sunny Goyal65190ae2022-08-02 14:16:26 -07001780 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
1781 mDotRendererCache = dotRendererCache;
1782 return this;
1783 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07001784
1785 public Builder setWindowBounds(WindowBounds bounds) {
1786 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07001787 return this;
1788 }
1789
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001790 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1791 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1792 return this;
1793 }
1794
Alex Chau6ed408f2022-03-04 12:58:05 +00001795 public Builder setGestureMode(boolean isGestureMode) {
1796 mIsGestureMode = isGestureMode;
1797 return this;
1798 }
1799
Jon Miranda2b25ded2023-02-02 14:48:45 -08001800 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
1801 mOverrideProvider = overrideProvider;
1802 return this;
1803 }
1804
Sihua Mae04aa202022-07-18 12:43:56 -07001805 /**
1806 * Set the viewScaleProvider for the builder
1807 *
1808 * @param viewScaleProvider The viewScaleProvider to be set for the
1809 * DeviceProfile
1810 * @return This builder
1811 */
1812 @NonNull
1813 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
1814 mViewScaleProvider = viewScaleProvider;
1815 return this;
1816 }
1817
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001818 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001819 if (mWindowBounds == null) {
1820 throw new IllegalArgumentException("Window bounds not set");
1821 }
1822 if (mTransposeLayoutWithOrientation == null) {
1823 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
1824 }
Alex Chau6ed408f2022-03-04 12:58:05 +00001825 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01001826 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00001827 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001828 if (mDotRendererCache == null) {
1829 mDotRendererCache = new SparseArray<>();
1830 }
Sihua Mae04aa202022-07-18 12:43:56 -07001831 if (mViewScaleProvider == null) {
1832 mViewScaleProvider = DEFAULT_PROVIDER;
1833 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08001834 if (mOverrideProvider == null) {
1835 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
1836 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001837 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00001838 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jon Miranda2b25ded2023-02-02 14:48:45 -08001839 mIsGestureMode, mViewScaleProvider, mOverrideProvider);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001840 }
1841 }
1842
Winson Chungb3800242013-10-24 11:01:54 -07001843}