blob: fe3fd4952b26e393b255b95671c4b8b83c73659e [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 Goyal799e1202023-02-09 10:54:28 -0800580 mDotRendererWorkSpace = createDotRenderer(context, iconSizePx, dotRendererCache);
581 mDotRendererAllApps = createDotRenderer(context, allAppsIconSizePx, dotRendererCache);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700582 }
583
584 private static DotRenderer createDotRenderer(
Sunny Goyal799e1202023-02-09 10:54:28 -0800585 @NonNull Context context, int size, @NonNull SparseArray<DotRenderer> cache) {
Sunny Goyal65190ae2022-08-02 14:16:26 -0700586 DotRenderer renderer = cache.get(size);
587 if (renderer == null) {
Sunny Goyal799e1202023-02-09 10:54:28 -0800588 renderer = new DotRenderer(size, getShapePath(context, DEFAULT_DOT_SIZE),
589 DEFAULT_DOT_SIZE);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700590 cache.put(size, renderer);
591 }
592 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700593 }
594
Thales Lima425f6822022-05-10 13:44:58 -0300595 /**
596 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
597 * width of the hotseat.
598 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100599 private int calculateQsbWidth(int hotseatBorderSpace) {
Thales Lima425f6822022-05-10 13:44:58 -0300600 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100601 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300602 return getIconToIconWidthForColumns(columns)
603 - iconSizePx * numShownHotseatIcons
604 - hotseatBorderSpace * numShownHotseatIcons;
605 } else {
606 int columns = inv.hotseatColumnSpan[mTypeIndex];
607 return getIconToIconWidthForColumns(columns);
608 }
609 }
Thales Lima2903a622022-03-17 13:52:19 +0000610
Thales Lima425f6822022-05-10 13:44:58 -0300611 private int getIconToIconWidthForColumns(int columns) {
612 return columns * getCellSize().x
613 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400614 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000615 }
616
Thales Limad90faab2021-09-21 17:18:47 +0100617 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
618 if (isVerticalBarLayout()) {
619 return 0;
620 }
621
Thales Lima83bedbf2021-10-05 17:47:39 +0100622 return isScalableGrid
623 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
624 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100625 }
626
Thales Limab8c05952022-05-23 16:58:38 +0100627 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
628 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700629 // Ensure there is enough space for folder icons, which have a slightly larger radius.
630 hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR);
Thales Limab8c05952022-05-23 16:58:38 +0100631
Jon Miranda0d284852021-06-22 14:50:55 -0700632 if (isVerticalBarLayout()) {
633 hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
634 + hotseatBarSidePaddingEndPx;
Thales Limab8c05952022-05-23 16:58:38 +0100635 } else if (isQsbInline) {
636 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
637 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700638 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100639 hotseatBarSizePx = hotseatIconSizePx
640 + hotseatQsbSpace
641 + hotseatQsbVisualHeight
642 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700643 }
644 }
645
Thales Lima6a590062022-11-22 15:52:49 +0000646 /**
647 * Calculates the width of the hotseat, changing spaces between the icons and removing icons if
648 * necessary.
649 */
650 public void recalculateHotseatWidthAndBorderSpace() {
651 if (!isScalableGrid) return;
652
653 int columns = inv.hotseatColumnSpan[mTypeIndex];
654 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
655 hotseatBorderSpace = calculateHotseatBorderSpace(hotseatWidthPx, /* numExtraBorder= */ 0);
Thales Lima9938c2f2022-07-25 14:38:16 +0100656 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
Thales Lima6a590062022-11-22 15:52:49 +0000657 // Spaces should be correct when the nav buttons are not inline
Thales Lima9938c2f2022-07-25 14:38:16 +0100658 if (!areNavButtonsInline) {
659 return;
660 }
661
Thales Lima6a590062022-11-22 15:52:49 +0000662 // The side space with inline buttons should be what is defined in InvariantDeviceProfile
663 int sideSpace = inlineNavButtonsEndSpacing;
664 int maxHotseatWidth = availableWidthPx - sideSpace - hotseatBarEndOffset;
665 int maxHotseatIconsWidth = maxHotseatWidth - (isQsbInline ? hotseatQsbWidth : 0);
666 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidth,
667 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100668
Thales Lima6a590062022-11-22 15:52:49 +0000669 if (hotseatBorderSpace >= minHotseatIconSpacePx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100670 return;
671 }
672
673 // Border space can't be less than the minimum
Thales Lima6a590062022-11-22 15:52:49 +0000674 hotseatBorderSpace = minHotseatIconSpacePx;
675 int requiredWidth = getHotseatRequiredWidth();
Thales Lima9938c2f2022-07-25 14:38:16 +0100676
677 // If there is an inline qsb, change its size
678 if (isQsbInline) {
679 hotseatQsbWidth -= requiredWidth - maxHotseatWidth;
Thales Lima6a590062022-11-22 15:52:49 +0000680 if (hotseatQsbWidth >= minHotseatQsbWidthPx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100681 return;
682 }
683
684 // QSB can't be less than the minimum
Thales Lima6a590062022-11-22 15:52:49 +0000685 hotseatQsbWidth = minHotseatQsbWidthPx;
Thales Lima9938c2f2022-07-25 14:38:16 +0100686 }
687
Thales Lima6a590062022-11-22 15:52:49 +0000688 maxHotseatIconsWidth = maxHotseatWidth - (isQsbInline ? hotseatQsbWidth : 0);
689
Thales Lima9938c2f2022-07-25 14:38:16 +0100690 // If it still doesn't fit, start removing icons
691 do {
692 numShownHotseatIcons--;
Thales Lima6a590062022-11-22 15:52:49 +0000693 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidth,
694 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
695 } while (hotseatBorderSpace < minHotseatIconSpacePx && numShownHotseatIcons > 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100696
Thales Lima9938c2f2022-07-25 14:38:16 +0100697 }
698
Thales Lima78d00ad2021-09-30 11:29:06 +0100699 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100700 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100701 }
702
703 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100704 if (!isScalableGrid) {
705 return new Point(0, 0);
706 }
707
Thales Lima080d8902022-03-28 15:30:29 +0100708 int horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
709 int verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
Thales Lima78d00ad2021-09-30 11:29:06 +0100710
711 return new Point(horizontalSpacePx, verticalSpacePx);
712 }
713
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700714 public Info getDisplayInfo() {
715 return mInfo;
716 }
717
Jon Miranda611dba42021-03-02 14:12:13 -0500718 /**
719 * We inset the widget padding added by the system and instead rely on the border spacing
720 * between cells to create reliable consistency between widgets
721 */
722 public boolean shouldInsetWidgets() {
723 Rect widgetPadding = inv.defaultWidgetPadding;
724
Jon Miranda49811182021-06-03 09:52:40 -0700725 // Check all sides to ensure that the widget won't overlap into another cell, or into
726 // status bar.
727 return workspaceTopPadding > widgetPadding.top
Thales Lima78d00ad2021-09-30 11:29:06 +0100728 && cellLayoutBorderSpacePx.x > widgetPadding.left
729 && cellLayoutBorderSpacePx.y > widgetPadding.top
730 && cellLayoutBorderSpacePx.x > widgetPadding.right
731 && cellLayoutBorderSpacePx.y > widgetPadding.bottom;
Jon Miranda611dba42021-03-02 14:12:13 -0500732 }
Jon Mirandae126d722021-02-25 10:45:20 -0500733
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700734 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800735 WindowBounds bounds = new WindowBounds(
736 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700737 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100738 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700739
740 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
741 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
742 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
743
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700744 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700745 .setWindowBounds(bounds)
Alex Chauab800f72022-12-13 17:46:06 +0000746 .setIsMultiDisplay(isMultiDisplay)
Alex Chau6ed408f2022-03-04 12:58:05 +0000747 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700748 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000749 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800750 }
751
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700752 public DeviceProfile copy(Context context) {
753 return toBuilder(context).build();
754 }
755
756 /**
757 * TODO: Move this to the builder as part of setMultiWindowMode
758 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700759 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700760 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700761 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700762 .setMultiWindowMode(true)
763 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800764
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800765 // We use these scales to measure and layout the widgets using their full invariant profile
766 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
767 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
768 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700769 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
770 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
771 profile = profile.toBuilder(context)
772 .setViewScaleProvider(i -> p)
773 .build();
774 }
775
776 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800777
Jon Miranda93e1f042016-11-11 14:13:04 -0800778 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700779 }
780
Adam Cohen63f1ec02014-08-12 09:23:13 -0700781 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400782 * Checks if there is enough space for labels on the workspace.
783 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700784 * It is important to call this method after the All Apps variables have been set.
785 */
Jon Miranda941375e2021-03-31 13:10:45 -0400786 private void hideWorkspaceLabelsIfNotEnoughSpace() {
787 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
788 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
789 - iconTextHeight;
790
791 // We want enough space so that the text is closer to its corresponding icon.
792 if (workspaceCellPaddingY < iconTextHeight) {
793 iconTextSizePx = 0;
794 iconDrawablePaddingPx = 0;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700795 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda941375e2021-03-31 13:10:45 -0400796 autoResizeAllAppsCells();
797 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700798 }
Jon Miranda1091e532017-07-21 13:31:50 -0700799
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700800 /**
801 * Re-computes the all-apps cell size to be independent of workspace
802 */
803 public void autoResizeAllAppsCells() {
Jon Miranda941375e2021-03-31 13:10:45 -0400804 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
805 int topBottomPadding = textHeight;
Jon Miranda1091e532017-07-21 13:31:50 -0700806 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
Jon Miranda941375e2021-03-31 13:10:45 -0400807 + textHeight + (topBottomPadding * 2);
Jon Miranda1091e532017-07-21 13:31:50 -0700808 }
809
Thales Limab7ef5692022-03-10 10:32:36 +0000810 private void updateAllAppsContainerWidth(Resources res) {
Pat Manning08610ca2022-04-05 21:03:16 +0100811 int cellLayoutHorizontalPadding =
812 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
Alex Chau27b39b92022-01-14 18:02:18 +0000813 if (isTablet) {
Thales Limab7ef5692022-03-10 10:32:36 +0000814 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100815 res.getDimensionPixelSize(R.dimen.all_apps_bottom_sheet_horizontal_padding);
816
sfufa@google.comde013292021-09-21 18:22:44 -0700817 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
Thales Limab7ef5692022-03-10 10:32:36 +0000818 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Alex Chau27b39b92022-01-14 18:02:18 +0000819 + allAppsLeftRightPadding * 2;
820 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
sfufa@google.comde013292021-09-21 18:22:44 -0700821 } else {
822 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100823 desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding;
sfufa@google.comde013292021-09-21 18:22:44 -0700824 }
825 }
826
Jon Miranda228877d2021-02-09 11:05:00 -0500827 /**
828 * Returns the amount of extra (or unused) vertical space.
829 */
830 private int updateAvailableDimensions(Resources res) {
Alex Chaua68164d2022-12-15 16:16:03 +0000831 float invIconSizeDp = inv.iconSize[mTypeIndex];
832 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
833 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
834 iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
835
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700836 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800837
Pat Manning08610ca2022-04-05 21:03:16 +0100838 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -0500839
840 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +0100841 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +0000842 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -0500843 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500844 float scaleY = maxHeight / usedHeight;
845 boolean shouldScale = scaleY < 1f;
846
847 float scaleX = 1f;
848 if (isScalableGrid) {
849 // We scale to fit the cellWidth and cellHeight in the available space.
850 // The benefit of scalable grids is that we can get consistent aspect ratios between
851 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +0100852 float usedWidth =
853 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500854 // We do not subtract padding here, as we also scale the workspace padding if needed.
855 scaleX = availableWidthPx / usedWidth;
856 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700857 }
Jon Mirandae126d722021-02-25 10:45:20 -0500858
859 if (shouldScale) {
860 float scale = Math.min(scaleX, scaleY);
861 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +0100862 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -0500863 }
864
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700865 updateAvailableFolderCellDimensions(res);
Jon Miranda228877d2021-02-09 11:05:00 -0500866 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700867 }
868
Pat Manninga2e14992022-04-22 11:29:17 +0100869 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +0100870 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
871 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
872 }
873
Pat Manninga2e14992022-04-22 11:29:17 +0100874 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +0000875 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +0100876 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
877 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -0500878 }
879
Jon Miranda6f7e9702019-09-16 14:44:14 -0700880 /**
881 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
882 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
883 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
884 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800885 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -0700886 // Icon scale should never exceed 1, otherwise pixellation may occur.
887 iconScale = Math.min(1f, scale);
888 cellScaleToFit = scale;
889
Jon Miranda18751b62017-07-31 17:25:27 -0700890 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800891 final boolean isVerticalLayout = isVerticalBarLayout();
Jon Mirandaab3c6812021-06-28 15:42:28 -0700892 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);
Thales Lima080d8902022-03-28 15:30:29 +0100893 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500894
895 if (isScalableGrid) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100896 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
897 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +0000898
899 if (cellWidthPx < iconSizePx) {
900 // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger.
901 int numColumns = getPanelCount() * inv.numColumns;
902 int numBorders = numColumns - 1;
903 int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns;
904 if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) {
905 cellWidthPx = iconSizePx;
906 cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders;
907 } else {
908 // If it still doesn't fit, set borderSpace to 0 and distribute the space for
909 // cellWidth, and reduce iconSize.
910 cellWidthPx = (cellWidthPx * numColumns
911 + cellLayoutBorderSpacePx.x * numBorders) / numColumns;
912 iconSizePx = Math.min(iconSizePx, cellWidthPx);
913 cellLayoutBorderSpacePx.x = 0;
914 }
915 }
916
917 int cellTextAndPaddingHeight =
918 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
919 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
920 if (cellHeightPx < cellContentHeight) {
921 // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight
922 // bigger.
923 int numBorders = inv.numRows - 1;
924 int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows;
925 if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) {
926 cellHeightPx = cellContentHeight;
927 cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders;
928 } else {
Alex Chau06f36e82023-01-06 10:50:54 +0000929 // If it still doesn't fit, set borderSpace to 0 to recover space.
Alex Chaube753132022-12-09 16:46:54 +0000930 cellHeightPx = (cellHeightPx * inv.numRows
931 + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows;
Alex Chaube753132022-12-09 16:46:54 +0000932 cellLayoutBorderSpacePx.y = 0;
Alex Chau06f36e82023-01-06 10:50:54 +0000933 // Reduce iconDrawablePaddingPx to make cellContentHeight smaller.
934 int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx;
935 if (cellContentWithoutPadding <= cellHeightPx) {
936 iconDrawablePaddingPx = cellContentHeight - cellHeightPx;
937 } else {
938 // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space,
939 // then proportional reduce iconSizePx and iconTextSizePx to fit.
940 iconDrawablePaddingPx = 0;
941 float ratio = cellHeightPx / (float) cellContentWithoutPadding;
942 iconSizePx = (int) (iconSizePx * ratio);
943 iconTextSizePx = (int) (iconTextSizePx * ratio);
944 }
945 cellTextAndPaddingHeight =
946 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +0000947 }
948 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
949 }
Jon Mirandae126d722021-02-25 10:45:20 -0500950 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +0100951 desiredWorkspaceHorizontalMarginPx =
952 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -0500953 } else {
Jon Mirandae126d722021-02-25 10:45:20 -0500954 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700955 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR)
956 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -0500957 + Utilities.calculateTextHeight(iconTextSizePx);
958 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
959 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
960 && !isMultiWindowMode) {
961 // Ensures that the label is closer to its corresponding icon. This is not an issue
962 // with vertical bar layout or multi-window mode since the issue is handled
963 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
964 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
965 iconDrawablePaddingPx = cellPaddingY;
966 }
Jon Miranda846455e2017-10-02 14:58:52 -0700967 }
Jon Miranda18751b62017-07-31 17:25:27 -0700968
Sunny Goyalae190ff2020-04-14 00:19:01 +0000969 // All apps
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500970 updateAllAppsIconSize(scale, res);
Winson Chungb3800242013-10-24 11:01:54 -0700971
Thales Limab8c05952022-05-23 16:58:38 +0100972 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700973
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700974 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -0700975 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
976 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Winson Chung0f785722015-04-08 10:27:49 -0700977 }
978
Thales Lima425f6822022-05-10 13:44:58 -0300979 /**
Thales Lima6a590062022-11-22 15:52:49 +0000980 * This method calculates the space between the icons to achieve a certain width.
Thales Lima425f6822022-05-10 13:44:58 -0300981 */
Thales Lima6a590062022-11-22 15:52:49 +0000982 private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100983 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
Thales Lima6a590062022-11-22 15:52:49 +0000984 int hotseatBorderSpace =
985 (int) (hotseatWidthPx - hotseatIconsTotalPx)
986 / (numShownHotseatIcons - 1 + numExtraBorder);
987 return Math.min(hotseatBorderSpace, maxHotseatIconSpacePx);
Thales Lima425f6822022-05-10 13:44:58 -0300988 }
989
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500990
991 /**
992 * Updates the iconSize for allApps* variants.
993 */
Brian Isganitisa9a78112022-05-23 18:11:47 -0700994 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +0100995 allAppsBorderSpacePx = new Point(
996 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
997 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700998 // AllApps cells don't have real space between cells,
999 // so we add the border space to the cell height
Alex Chaube753132022-12-09 16:46:54 +00001000 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics)
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001001 + allAppsBorderSpacePx.y;
1002 // but width is just the cell,
1003 // the border is added in #updateAllAppsContainerWidth
Thales Lima080d8902022-03-28 15:30:29 +01001004 if (isScalableGrid) {
Alex Chaube753132022-12-09 16:46:54 +00001005 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1006 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001007 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001008 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001009
1010 if (allAppsCellWidthPx < allAppsIconSizePx) {
1011 // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to
1012 // make allAppsCellWidth bigger.
1013 int numBorders = inv.numAllAppsColumns - 1;
1014 int extraWidthRequired =
1015 (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns;
1016 if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) {
1017 allAppsCellWidthPx = allAppsIconSizePx;
1018 allAppsBorderSpacePx.x -= extraWidthRequired / numBorders;
1019 } else {
1020 // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space
1021 // for allAppsCellWidth, and reduce allAppsIconSize.
1022 allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns
1023 + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns;
1024 allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx);
1025 allAppsBorderSpacePx.x = 0;
1026 }
1027 }
1028
1029 int cellContentHeight = allAppsIconSizePx
1030 + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y;
1031 if (allAppsCellHeightPx < cellContentHeight) {
1032 // Increase allAppsCellHeight to fit its content.
1033 allAppsCellHeightPx = cellContentHeight;
1034 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001035 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001036 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
1037 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001038 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1039 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001040 allAppsIconDrawablePaddingPx =
1041 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001042 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001043 }
1044
Thales Limab7ef5692022-03-10 10:32:36 +00001045 updateAllAppsContainerWidth(res);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001046 if (isVerticalBarLayout()) {
1047 hideWorkspaceLabelsIfNotEnoughSpace();
1048 }
1049 }
1050
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001051 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001052 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001053
Jon Mirandac1b23992016-12-13 08:57:36 -08001054 // Don't let the folder get too close to the edges of the screen.
Jon Miranda1786df32018-09-25 13:05:23 -07001055 int folderMargin = edgeMarginPx * 2;
Sunny Goyal07b69292018-01-08 14:19:34 -08001056 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -08001057
1058 // Check if the icons fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -05001059 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Thales Limab35faed2022-09-05 16:30:01 -03001060 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx);
1061 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderFooterHeightPx
Jon Mirandae126d722021-02-25 10:45:20 -05001062 - folderMargin - folderContentPaddingTop;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001063 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -08001064
1065 // Check if the icons fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -05001066 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Thales Limab35faed2022-09-05 16:30:01 -03001067 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx);
Jon Mirandae126d722021-02-25 10:45:20 -05001068 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin
1069 - folderContentPaddingLeftRight * 2;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001070 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -08001071
1072 float scale = Math.min(scaleX, scaleY);
1073 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001074 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001075 }
1076 }
1077
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001078 private void updateFolderCellSize(float scale, Resources res) {
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001079 float invIconSizeDp = inv.iconSize[mTypeIndex];
Sunny Goyal35c7b192021-04-20 16:51:10 -07001080 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001081 folderChildTextSizePx = pxFromSp(inv.iconTextSize[mTypeIndex], mMetrics, scale);
Thales Limab35faed2022-09-05 16:30:01 -03001082 folderLabelTextSizePx = Math.max(pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics),
1083 (int) (folderChildTextSizePx * folderLabelTextScale));
Jon Mirandabf7d8122016-11-03 15:29:29 -07001084
1085 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001086
Jon Miranda823da222021-03-23 08:08:45 -04001087 if (isScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001088 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
1089 folderCellWidthPx = pxFromDp(getCellSize().x, mMetrics, scale);
1090 folderCellHeightPx = pxFromDp(getCellSize().y, mMetrics, scale);
1091 }
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001092
Thales Limab35faed2022-09-05 16:30:01 -03001093 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx;
Jon Miranda823da222021-03-23 08:08:45 -04001094 } else {
1095 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1096 * scale);
1097 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1098 * scale);
1099
1100 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1101 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Limab35faed2022-09-05 16:30:01 -03001102 folderContentPaddingLeftRight =
1103 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1104 folderFooterHeightPx =
1105 res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Jon Miranda823da222021-03-23 08:08:45 -04001106 }
1107
Jonathan Miranda9ad87462017-07-26 17:41:02 +00001108 folderChildDrawablePaddingPx = Math.max(0,
1109 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001110 }
1111
Winson1f064272016-07-18 17:18:02 -07001112 public void updateInsets(Rect insets) {
1113 mInsets.set(insets);
1114 }
1115
Sunny Goyalae6e3182019-04-30 12:04:37 -07001116 /**
1117 * The current device insets. This is generally same as the insets being dispatched to
1118 * {@link Insettable} elements, but can differ if the element is using a different profile.
1119 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001120 public Rect getInsets() {
1121 return mInsets;
1122 }
1123
Sunny Goyal756cd262015-08-20 12:33:21 -07001124 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001125 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001126 }
1127
Sunny Goyal19ff7282021-04-22 10:12:54 -07001128 public Point getCellSize(Point result) {
1129 if (result == null) {
1130 result = new Point();
1131 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001132
Pat Manning25d53342022-05-10 09:58:49 +00001133 int shortcutAndWidgetContainerWidth =
1134 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1135 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1136 inv.numColumns);
1137 int shortcutAndWidgetContainerHeight =
1138 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1139 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1140 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001141 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001142 }
1143
1144 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001145 * Returns the left and right space on the cell, which is the cell width - icon size
1146 */
1147 public int getCellHorizontalSpace() {
1148 return getCellSize().x - iconSizePx;
1149 }
1150
1151 /**
Pat Manning25d53342022-05-10 09:58:49 +00001152 * Gets the number of panels within the workspace.
1153 */
1154 public int getPanelCount() {
1155 return isTwoPanels ? 2 : 1;
1156 }
1157
1158 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001159 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1160 * bottom of the screen.
1161 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001162 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1163 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001164 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001165 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001166 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001167 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001168 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001169 }
1170
1171 /**
1172 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1173 */
Pat Manning25d53342022-05-10 09:58:49 +00001174 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001175 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001176 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001177 }
1178
1179 /**
1180 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1181 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001182 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001183 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001184 return heightPx - (isVerticalBarLayout()
1185 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001186 }
1187
Pat Manningea5c1d22022-04-14 10:58:16 +01001188 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001189 * Gets the scale of the workspace for the spring-loaded edit state.
1190 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001191 public float getWorkspaceSpringLoadScale(Context context) {
1192 float scale =
1193 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1194 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001195 scale = Math.min(scale, 1f);
1196
Pat Manninge63dd252022-08-02 16:15:29 +01001197 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001198 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001199 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001200 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001201 if (scaledWorkspaceWidth > maxAvailableWidth) {
1202 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1203 }
1204 return scale;
1205 }
1206
Pat Manning25d53342022-05-10 09:58:49 +00001207 /**
1208 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1209 *
1210 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1211 * layouts have two Cell Layouts per workspace.
1212 */
1213 public int getCellLayoutWidth() {
1214 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001215 }
1216
Pat Manning25d53342022-05-10 09:58:49 +00001217 /**
1218 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1219 *
1220 * <p>This is the height of a Workspace, less its vertical padding.
1221 */
1222 public int getCellLayoutHeight() {
1223 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001224 }
1225
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001226 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001227 return new Point(workspacePadding.left + workspacePadding.right,
1228 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001229 }
1230
1231 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001232 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1233 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001234 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001235 private void updateWorkspacePadding() {
1236 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001237 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -08001238 padding.top = 0;
1239 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001240 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001241 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -07001242 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -07001243 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -07001244 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001245 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -07001246 }
Winson Chungb3800242013-10-24 11:01:54 -07001247 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001248 // Pad the bottom of the workspace with hotseat bar
1249 // and leave a bit of space in case a widget go all the way down
1250 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding
1251 + workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace
1252 - mInsets.bottom;
Pat Manning08610ca2022-04-05 21:03:16 +01001253 int paddingTop = workspaceTopPadding + (isScalableGrid ? 0 : edgeMarginPx);
1254 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001255
Pat Manning08610ca2022-04-05 21:03:16 +01001256 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001257 }
Pat Manning08610ca2022-04-05 21:03:16 +01001258 insetPadding(workspacePadding, cellLayoutPaddingPx);
1259 }
1260
1261 private void insetPadding(Rect paddings, Rect insets) {
1262 insets.left = Math.min(insets.left, paddings.left);
1263 paddings.left -= insets.left;
1264
1265 insets.top = Math.min(insets.top, paddings.top);
1266 paddings.top -= insets.top;
1267
1268 insets.right = Math.min(insets.right, paddings.right);
1269 paddings.right -= insets.right;
1270
1271 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1272 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001273 }
1274
Sunny Goyal57b22792021-05-25 14:35:01 -07001275 /**
1276 * Returns the padding for hotseat view
1277 */
1278 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001279 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001280 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001281 // The hotseat icons will be placed in the middle of the hotseat cells.
1282 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1283 // in vertical bar layout.
1284 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1285 // is set to account for that difference.
1286 float diffOverlapFactor = iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
Pat Manning08610ca2022-04-05 21:03:16 +01001287 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1288 - diffOverlapFactor), 0);
1289 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001290 + diffOverlapFactor), 0);
1291
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001292 if (isSeascape()) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001293 hotseatBarPadding.set(mInsets.left + hotseatBarSidePaddingStartPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001294 hotseatBarSidePaddingEndPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001295 } else {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001296 hotseatBarPadding.set(hotseatBarSidePaddingEndPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001297 mInsets.right + hotseatBarSidePaddingStartPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001298 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001299 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001300 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001301 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1302 int hotseatBarTopPadding =
1303 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001304
Thales Lima6a590062022-11-22 15:52:49 +00001305 int hotseatWidth = getHotseatRequiredWidth();
1306 int leftSpacing = (availableWidthPx - hotseatWidth) / 2;
1307 int rightSpacing = leftSpacing;
1308 // Hotseat aligns to the left with nav buttons
1309 if (hotseatBarEndOffset > 0) {
1310 leftSpacing = inlineNavButtonsEndSpacing;
1311 rightSpacing = availableWidthPx - hotseatWidth - leftSpacing + hotseatBorderSpace;
1312 }
Thales Lima612230d2022-03-31 18:04:37 +01001313
Thales Lima6a590062022-11-22 15:52:49 +00001314 hotseatBarPadding.set(leftSpacing, hotseatBarTopPadding, rightSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001315 hotseatBarBottomPadding);
Alex Chau51da2192022-05-20 13:32:10 +01001316
1317 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001318 if (isRtl) {
Thales Lima9938c2f2022-07-25 14:38:16 +01001319 hotseatBarPadding.right += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001320 } else {
Thales Lima9938c2f2022-07-25 14:38:16 +01001321 hotseatBarPadding.left += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001322 }
Thales Lima425f6822022-05-10 13:44:58 -03001323 } else if (isScalableGrid) {
Alex Chau206ede92022-08-01 17:46:12 +01001324 int sideSpacing = (availableWidthPx - hotseatQsbWidth) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001325 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001326 0,
Thales Lima425f6822022-05-10 13:44:58 -03001327 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001328 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001329 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001330 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1331 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1332 // for this, we pad the left and right of the hotseat with half of the difference of a
1333 // workspace cell vs a hotseat cell.
1334 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001335 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001336 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001337 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001338 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1339 + mInsets.left,
1340 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001341 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001342 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001343 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001344 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001345 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001346 }
1347
Thales Lima9938c2f2022-07-25 14:38:16 +01001348 private int getAdditionalQsbSpace() {
1349 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1350 }
1351
1352 /**
1353 * Calculate how much space the hotseat needs to be shown completely
1354 */
1355 private int getHotseatRequiredWidth() {
1356 int additionalQsbSpace = getAdditionalQsbSpace();
1357 return iconSizePx * numShownHotseatIcons
Thales Lima6a590062022-11-22 15:52:49 +00001358 + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1))
Thales Lima9938c2f2022-07-25 14:38:16 +01001359 + additionalQsbSpace;
1360 }
1361
Winsonfadbe8f2016-07-22 16:35:37 -07001362 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001363 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1364 */
1365 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001366 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001367 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1368 } else if (isTaskbarPresent) { // QSB on top
1369 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001370 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001371 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001372 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001373 }
1374
Thales Limab8c05952022-05-23 16:58:38 +01001375 /**
1376 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1377 */
1378 private int getHotseatBarBottomPadding() {
1379 if (isTaskbarPresent) { // QSB on top or inline
1380 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001381 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001382 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001383 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001384 }
1385
1386 /**
Alex Chau51da2192022-05-20 13:32:10 +01001387 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1388 */
1389 public int getTaskbarOffsetY() {
1390 int taskbarIconBottomSpace = (taskbarSize - iconSizePx) / 2;
1391 int launcherIconBottomSpace =
1392 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001393 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001394 }
1395
1396 /**
Alex Chaua2fc7642022-04-21 14:20:23 +01001397 * Returns the number of pixels required below OverviewActions excluding insets.
1398 */
1399 public int getOverviewActionsClaimedSpaceBelow() {
Alex Chaud67ddc42022-09-30 18:15:56 +01001400 if (isTaskbarPresent) {
Alex Chau905e0f12022-11-14 21:55:37 +00001401 if (FeatureFlags.ENABLE_TASKBAR_IN_OVERVIEW.get()) {
Alex Chau85d664e2023-01-16 16:31:59 +00001402 return transientTaskbarSize + transientTaskbarMargin * 2;
Alex Chau905e0f12022-11-14 21:55:37 +00001403 }
1404
1405 return isGestureMode
1406 ? stashedTaskbarSize
1407 // Align vertically to where nav buttons are.
1408 : ((taskbarSize - overviewActionsHeight) / 2) + getTaskbarOffsetY();
Alex Chaud67ddc42022-09-30 18:15:56 +01001409 }
1410 return mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001411 }
1412
1413 /** Gets the space that the overview actions will take, including bottom margin. */
1414 public int getOverviewActionsClaimedSpace() {
Pat Manning7b8f7662023-01-18 14:48:30 +00001415 int overviewActionsSpace = isTablet && FeatureFlags.ENABLE_GRID_ONLY_OVERVIEW.get()
1416 ? 0
1417 : (overviewActionsTopMarginPx + overviewActionsHeight);
1418 return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
Alex Chaua2fc7642022-04-21 14:20:23 +01001419 }
1420
1421 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001422 * Takes the View and return the scales of width and height depending on the DeviceProfile
1423 * specifications
1424 *
1425 * @param itemInfo The tag of the widget view
1426 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1427 * height
1428 */
1429 @NonNull
1430 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1431 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1432 }
1433
1434 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001435 * @return the bounds for which the open folders should be contained within
1436 */
1437 public Rect getAbsoluteOpenFolderBounds() {
1438 if (isVerticalBarLayout()) {
1439 // Folders should only appear right of the drop target bar and left of the hotseat
1440 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1441 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001442 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001443 mInsets.top + availableHeightPx);
1444 } else {
1445 // Folders should only appear below the drop target bar and above the hotseat
Tony Wickhamae72b462021-03-10 16:18:40 -08001446 int hotseatTop = isTaskbarPresent ? taskbarSize : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001447 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001448 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001449 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001450 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001451 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001452 }
1453 }
1454
Jon Miranda228877d2021-02-09 11:05:00 -05001455 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1456 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001457 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001458
Jon Miranda228877d2021-02-09 11:05:00 -05001459 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1460 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001461 }
1462
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001463 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001464 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1465 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1466 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001467 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001468 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001469 return isLandscape && transposeLayoutWithOrientation;
1470 }
1471
Sunny Goyal59d086c2018-05-07 17:31:40 -07001472 /**
1473 * Updates orientation information and returns true if it has changed from the previous value.
1474 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001475 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001476 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001477 boolean isSeascape = DisplayController.INSTANCE.get(context)
1478 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001479 if (mIsSeascape != isSeascape) {
1480 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001481 // Hotseat changing sides requires updating workspace left/right paddings
1482 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001483 return true;
1484 }
1485 }
1486 return false;
1487 }
1488
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001489 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001490 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001491 }
1492
Sunny Goyal07b69292018-01-08 14:19:34 -08001493 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001494 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001495 }
1496
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001497 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001498 switch (containerType) {
1499 case CellLayout.WORKSPACE:
1500 return cellHeightPx;
1501 case CellLayout.FOLDER:
1502 return folderCellHeightPx;
1503 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001504 // The hotseat is the only container where the cell height is going to be
1505 // different from the content within that cell.
1506 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001507 default:
1508 // ??
1509 return 0;
1510 }
1511 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001512
Jon Miranda58561d42021-03-17 10:51:54 -04001513 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001514 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001515 }
1516
Alex Chaue818bcb2022-09-02 17:27:11 +01001517 private String dpPointFToString(String name, PointF value) {
1518 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
1519 }
1520
Pat Manning5f74bfd2022-07-20 12:08:54 +01001521 /** Dumps various DeviceProfile variables to the specified writer. */
1522 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04001523 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001524 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001525
1526 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001527 writer.println(prefix + "\tisPhone:" + isPhone);
1528 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1529 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001530 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001531
1532 writer.println(prefix + "\tisLandscape:" + isLandscape);
1533 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001534 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001535
1536 writer.println(prefix + pxToDpStr("windowX", windowX));
1537 writer.println(prefix + pxToDpStr("windowY", windowY));
1538 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1539 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001540 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1541 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001542 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1543 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1544 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1545 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001546
1547 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1548
1549 writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
1550
Thales Lima83bedbf2021-10-05 17:47:39 +01001551 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001552 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1553 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1554 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001555
Alex Chaue818bcb2022-09-02 17:27:11 +01001556 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07001557
Jon Miranda58561d42021-03-17 10:51:54 -04001558 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1559 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1560
1561 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1562 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1563
Thales Lima83bedbf2021-10-05 17:47:39 +01001564 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1565 cellLayoutBorderSpacePx.x));
1566 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1567 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001568 writer.println(
1569 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
1570 writer.println(
1571 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
1572 writer.println(
1573 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01001574 writer.println(
1575 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01001576
Jon Miranda58561d42021-03-17 10:51:54 -04001577 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1578 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1579 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1580
1581 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1582 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1583 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1584 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1585 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1586 folderChildDrawablePaddingPx));
Thales Limab35faed2022-09-05 16:30:01 -03001587 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx",
1588 folderCellLayoutBorderSpacePx));
Thales Limaa08a4432022-08-09 09:55:17 +01001589 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
1590 folderContentPaddingLeftRight));
1591 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03001592 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001593
Alex Chaue0227552022-04-06 19:44:43 +01001594 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001595 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
1596 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
1597 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
1598 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01001599
1600 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
1601 writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001602 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
1603 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04001604 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1605 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1606 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1607 allAppsIconDrawablePaddingPx));
1608 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001609 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001610 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
1611 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001612 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau62572c02022-07-25 18:36:37 +00001613 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
Alex Chau27b39b92022-01-14 18:02:18 +00001614 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001615
1616 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03001617 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04001618 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00001619 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Jon Miranda58561d42021-03-17 10:51:54 -04001620 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
1621 hotseatBarSidePaddingStartPx));
1622 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
1623 hotseatBarSidePaddingEndPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001624 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01001625 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
1626 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01001627 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
1628 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001629 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
1630 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
1631 hotseatLayoutPadding.top));
1632 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
1633 hotseatLayoutPadding.bottom));
1634 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
1635 hotseatLayoutPadding.left));
1636 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
1637 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001638 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001639 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001640 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01001641 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001642
1643 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001644 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda58561d42021-03-17 10:51:54 -04001645 writer.println(prefix + pxToDpStr("taskbarSize", taskbarSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001646
Thales Lima83bedbf2021-10-05 17:47:39 +01001647 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1648 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001649 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
1650 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
1651 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00001652 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001653
Jon Mirandaab3c6812021-06-28 15:42:28 -07001654 writer.println(prefix + pxToDpStr("iconScale", iconScale));
1655 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04001656 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00001657 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001658
Thales Lima171ee662022-11-22 15:52:49 +00001659 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04001660 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
1661 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00001662
1663 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00001664 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
1665 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
1666 overviewTaskIconDrawableSizePx));
1667 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
1668 overviewTaskIconDrawableSizeGridPx));
1669 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
1670 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01001671 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
1672 overviewActionsTopMarginPx));
1673 writer.println(prefix + pxToDpStr("overviewActionsHeight",
1674 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00001675 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
1676 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00001677 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
1678 overviewActionsButtonSpacing));
1679 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
1680 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
1681 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01001682
Alex Chau62572c02022-07-25 18:36:37 +00001683 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001684 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00001685 writer.println(
1686 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001687
Pat Manning5f74bfd2022-07-20 12:08:54 +01001688 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
1689 getCellLayoutSpringLoadShrunkTop()));
1690 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
1691 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01001692 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
1693 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001694 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
1695 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01001696 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
1697 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Jon Miranda58561d42021-03-17 10:51:54 -04001698 }
1699
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00001700 /** Returns a reduced representation of this DeviceProfile. */
1701 public String toSmallString() {
1702 return "isTablet:" + isTablet + ", "
1703 + "isMultiDisplay:" + isMultiDisplay + ", "
1704 + "widthPx:" + widthPx + ", "
1705 + "heightPx:" + heightPx + ", "
1706 + "insets:" + mInsets + ", "
1707 + "rotationHint:" + rotationHint;
1708 }
1709
Alex Chaua6907dc2022-03-18 15:24:07 +00001710 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07001711 Configuration config = new Configuration(c.getResources().getConfiguration());
1712 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03001713 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00001714 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07001715 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07001716 }
Sunny Goyalfde55052018-02-01 14:46:13 -08001717
1718 /**
1719 * Callback when a component changes the DeviceProfile associated with it, as a result of
1720 * configuration change
1721 */
1722 public interface OnDeviceProfileChangeListener {
1723
1724 /**
1725 * Called when the device profile is reassigned. Note that for layout and measurements, it
1726 * is sufficient to listen for inset changes. Use this callback when you need to perform
1727 * a one time operation.
1728 */
1729 void onDeviceProfileChanged(DeviceProfile dp);
1730 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001731
Sihua Mae04aa202022-07-18 12:43:56 -07001732 /**
1733 * Handler that deals with ItemInfo of the views for the DeviceProfile
1734 */
1735 @FunctionalInterface
1736 public interface ViewScaleProvider {
1737 /**
1738 * Get the scales from the view
1739 *
1740 * @param itemInfo The tag of the widget view
1741 * @return PointF instance containing the scale information, or null if using the default
1742 * app widget scale of this device profile.
1743 */
1744 @NonNull
1745 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
1746 }
1747
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001748 public static class Builder {
1749 private Context mContext;
1750 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07001751 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001752
Sunny Goyal19ff7282021-04-22 10:12:54 -07001753 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00001754 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001755
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001756 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001757 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00001758 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07001759 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001760
Sunny Goyal65190ae2022-08-02 14:16:26 -07001761 private SparseArray<DotRenderer> mDotRendererCache;
1762
Jon Miranda2b25ded2023-02-02 14:48:45 -08001763 private Consumer<DeviceProfile> mOverrideProvider;
1764
Sunny Goyalfd58da62020-08-11 12:06:49 -07001765 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001766 mContext = context;
1767 mInv = inv;
1768 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001769 }
1770
1771 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1772 mIsMultiWindowMode = isMultiWindowMode;
1773 return this;
1774 }
1775
Alex Chauab800f72022-12-13 17:46:06 +00001776 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
1777 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001778 return this;
1779 }
1780
Sunny Goyal65190ae2022-08-02 14:16:26 -07001781 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
1782 mDotRendererCache = dotRendererCache;
1783 return this;
1784 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07001785
1786 public Builder setWindowBounds(WindowBounds bounds) {
1787 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07001788 return this;
1789 }
1790
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001791 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1792 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1793 return this;
1794 }
1795
Alex Chau6ed408f2022-03-04 12:58:05 +00001796 public Builder setGestureMode(boolean isGestureMode) {
1797 mIsGestureMode = isGestureMode;
1798 return this;
1799 }
1800
Jon Miranda2b25ded2023-02-02 14:48:45 -08001801 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
1802 mOverrideProvider = overrideProvider;
1803 return this;
1804 }
1805
Sihua Mae04aa202022-07-18 12:43:56 -07001806 /**
1807 * Set the viewScaleProvider for the builder
1808 *
1809 * @param viewScaleProvider The viewScaleProvider to be set for the
1810 * DeviceProfile
1811 * @return This builder
1812 */
1813 @NonNull
1814 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
1815 mViewScaleProvider = viewScaleProvider;
1816 return this;
1817 }
1818
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001819 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001820 if (mWindowBounds == null) {
1821 throw new IllegalArgumentException("Window bounds not set");
1822 }
1823 if (mTransposeLayoutWithOrientation == null) {
1824 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
1825 }
Alex Chau6ed408f2022-03-04 12:58:05 +00001826 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01001827 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00001828 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001829 if (mDotRendererCache == null) {
1830 mDotRendererCache = new SparseArray<>();
1831 }
Sihua Mae04aa202022-07-18 12:43:56 -07001832 if (mViewScaleProvider == null) {
1833 mViewScaleProvider = DEFAULT_PROVIDER;
1834 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08001835 if (mOverrideProvider == null) {
1836 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
1837 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001838 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00001839 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jon Miranda2b25ded2023-02-02 14:48:45 -08001840 mIsGestureMode, mViewScaleProvider, mOverrideProvider);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001841 }
1842 }
1843
Winson Chungb3800242013-10-24 11:01:54 -07001844}