blob: c08dd1da36365c0b135097079ce2fcc7794f7a1f [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
Kateryna Ivanova71203732023-05-24 15:09:00 +000019import static com.android.app.animation.Interpolators.LINEAR;
Thales Lima12d0eff2022-03-25 17:06:11 +000020import static com.android.launcher3.InvariantDeviceProfile.INDEX_DEFAULT;
21import static com.android.launcher3.InvariantDeviceProfile.INDEX_LANDSCAPE;
22import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_LANDSCAPE;
23import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_PORTRAIT;
Jon Miranda58561d42021-03-17 10:51:54 -040024import static com.android.launcher3.Utilities.dpiFromPx;
Jon Mirandaaf3aed02021-05-06 18:28:45 -070025import static com.android.launcher3.Utilities.pxFromSp;
Alex Chauab800f72022-12-13 17:46:06 +000026import static com.android.launcher3.config.FeatureFlags.ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH;
Jon Miranda92c1b5d2021-07-20 13:57:16 -070027import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.ICON_OVERLAP_FACTOR;
Sunny Goyal65190ae2022-08-02 14:16:26 -070028import static com.android.launcher3.icons.GraphicsUtils.getShapePath;
Thales Limab35faed2022-09-05 16:30:01 -030029import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURCE_HANDLE;
Pat Manning5f74bfd2022-07-20 12:08:54 +010030import static com.android.launcher3.testing.shared.ResourceUtils.pxFromDp;
Thales Lima7eee74b2023-03-16 16:00:55 -030031import static com.android.launcher3.testing.shared.ResourceUtils.roundPxValueFromFloat;
Jon Miranda228877d2021-02-09 11:05:00 -050032
Sunny Goyal35c7b192021-04-20 16:51:10 -070033import android.annotation.SuppressLint;
Winson Chungb3800242013-10-24 11:01:54 -070034import android.content.Context;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070035import android.content.res.Configuration;
Winson Chungb3800242013-10-24 11:01:54 -070036import android.content.res.Resources;
Thales Limab35faed2022-09-05 16:30:01 -030037import android.content.res.TypedArray;
Winson Chungb3800242013-10-24 11:01:54 -070038import android.graphics.Point;
Jon Miranda7ae64ff2016-11-21 16:18:46 -080039import android.graphics.PointF;
Winson Chungb3800242013-10-24 11:01:54 -070040import android.graphics.Rect;
Sunny Goyal35c7b192021-04-20 16:51:10 -070041import android.util.DisplayMetrics;
Sunny Goyal65190ae2022-08-02 14:16:26 -070042import android.util.SparseArray;
Sunny Goyal59d086c2018-05-07 17:31:40 -070043import android.view.Surface;
Winson Chungb3800242013-10-24 11:01:54 -070044
Sunny Goyal65190ae2022-08-02 14:16:26 -070045import androidx.annotation.NonNull;
Sihua Mae04aa202022-07-18 12:43:56 -070046import androidx.annotation.Nullable;
Jon Miranda9c478b62023-03-23 21:38:49 -070047import androidx.core.content.res.ResourcesCompat;
Sunny Goyal65190ae2022-08-02 14:16:26 -070048
Sunny Goyalc13403c2016-11-18 23:44:48 -080049import com.android.launcher3.CellLayout.ContainerType;
Jon Miranda228877d2021-02-09 11:05:00 -050050import com.android.launcher3.DevicePaddings.DevicePadding;
Alex Chaud67ddc42022-09-30 18:15:56 +010051import com.android.launcher3.config.FeatureFlags;
Tony Wickham8912b042018-11-29 15:28:53 -080052import com.android.launcher3.icons.DotRenderer;
Hyunyoung Song48cb7bc2018-09-25 17:03:34 -070053import com.android.launcher3.icons.IconNormalizer;
Sihua Mae04aa202022-07-18 12:43:56 -070054import com.android.launcher3.model.data.ItemInfo;
Sunny Goyal57b22792021-05-25 14:35:01 -070055import com.android.launcher3.uioverrides.ApiWrapper;
Sunny Goyalfd58da62020-08-11 12:06:49 -070056import com.android.launcher3.util.DisplayController;
57import com.android.launcher3.util.DisplayController.Info;
Thales Limac98b7812023-04-14 15:04:23 +010058import com.android.launcher3.util.ResourceHelper;
Sunny Goyalb46703d2020-05-27 17:52:03 -070059import com.android.launcher3.util.WindowBounds;
Thales Limac98b7812023-04-14 15:04:23 +010060import com.android.launcher3.workspace.CalculatedWorkspaceSpec;
61import com.android.launcher3.workspace.WorkspaceSpecs;
Winson1f064272016-07-18 17:18:02 -070062
Jon Miranda58561d42021-03-17 10:51:54 -040063import java.io.PrintWriter;
Alex Chaue818bcb2022-09-02 17:27:11 +010064import java.util.Locale;
Jon Miranda2b25ded2023-02-02 14:48:45 -080065import java.util.function.Consumer;
Jon Miranda58561d42021-03-17 10:51:54 -040066
Sunny Goyal35c7b192021-04-20 16:51:10 -070067@SuppressLint("NewApi")
Winson Chungb3800242013-10-24 11:01:54 -070068public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070069
Sunny Goyal8b9919d2021-04-07 14:45:17 -070070 private static final int DEFAULT_DOT_SIZE = 100;
Alex Chau206ede92022-08-01 17:46:12 +010071 private static final float ALL_APPS_TABLET_MAX_ROWS = 5.5f;
Thales Limab35faed2022-09-05 16:30:01 -030072 private static final float MIN_FOLDER_TEXT_SIZE_SP = 16f;
Sunny Goyal6c304b12023-04-10 12:03:04 -070073 private static final float MIN_WIDGET_PADDING_DP = 6f;
Alex Chau206ede92022-08-01 17:46:12 +010074
Sihua Mae04aa202022-07-18 12:43:56 -070075 public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f);
76 public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE;
Jon Miranda2b25ded2023-02-02 14:48:45 -080077 public static final Consumer<DeviceProfile> DEFAULT_DIMENSION_PROVIDER = dp -> {};
Sihua Mae04aa202022-07-18 12:43:56 -070078
Adam Cohen2e6da152015-05-06 11:42:25 -070079 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070080 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070081 private final DisplayMetrics mMetrics;
Winson Chungbe876472014-05-14 14:15:20 -070082
Sunny Goyalc6205602015-05-21 20:46:33 -070083 // Device properties
84 public final boolean isTablet;
Sunny Goyalc6205602015-05-21 20:46:33 -070085 public final boolean isPhone;
86 public final boolean transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +000087 public final boolean isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -070088 public final boolean isTwoPanels;
Thales Limaa1012902022-01-13 17:58:42 +000089 public final boolean isQsbInline;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -070090
Sunny Goyalc6205602015-05-21 20:46:33 -070091 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -070092 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -080093 public final boolean isMultiWindowMode;
Alex Chau6ed408f2022-03-04 12:58:05 +000094 public final boolean isGestureMode;
Sunny Goyald70e75a2018-02-22 10:07:32 -080095
Sunny Goyal0addbf02020-04-28 14:17:35 -070096 public final int windowX;
97 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -070098 public final int widthPx;
99 public final int heightPx;
100 public final int availableWidthPx;
101 public final int availableHeightPx;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800102 public final int rotationHint;
Jon Mirandabba64512019-03-27 10:54:17 -0700103
104 public final float aspectRatio;
105
Thales Lima79456492023-05-23 11:32:22 +0100106 private final boolean mIsScalableGrid;
Thales Lima83bedbf2021-10-05 17:47:39 +0100107 private final int mTypeIndex;
Jon Mirandae126d722021-02-25 10:45:20 -0500108
Thales Limac98b7812023-04-14 15:04:23 +0100109 // Responsive grid
110 private final boolean mIsResponsiveGrid;
111 private WorkspaceSpecs mWorkspaceSpecs;
112 private CalculatedWorkspaceSpec mResponsiveWidthSpec;
113 private CalculatedWorkspaceSpec mResponsiveHeightSpec;
114
Tony Wickhamd6b40372015-09-23 18:37:57 -0700115 /**
116 * The maximum amount of left/right workspace padding as a percentage of the screen width.
117 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
118 * 7% of the screen width can be used as right padding.
119 */
120 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -0700121
Jon Miranda3f9bab22017-07-28 14:50:17 -0700122 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700123 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda80dda302021-07-28 14:14:59 -0700124 private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252;
125 private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700126
Sunny Goyalc6205602015-05-21 20:46:33 -0700127 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +0100128 public final int desiredWorkspaceHorizontalMarginOriginalPx;
129 public int desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100130 public int gridVisualizationPaddingX;
131 public int gridVisualizationPaddingY;
Thales Lima78d00ad2021-09-30 11:29:06 +0100132 public Point cellLayoutBorderSpaceOriginalPx;
133 public Point cellLayoutBorderSpacePx;
Pat Manning08610ca2022-04-05 21:03:16 +0100134 public Rect cellLayoutPaddingPx = new Rect();
135
Sunny Goyalc6205602015-05-21 20:46:33 -0700136 public final int edgeMarginPx;
Alex Chau0c4e11b2022-07-08 18:41:36 +0100137 public final float workspaceContentScale;
Alex Chau906d8822022-05-23 10:42:25 +0100138 public final int workspaceSpringLoadedMinNextPageVisiblePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700139
Jon Miranda58561d42021-03-17 10:51:54 -0400140 private final int extraSpace;
Thales Lima171ee662022-11-22 15:52:49 +0000141 private int maxEmptySpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500142 public int workspaceTopPadding;
143 public int workspaceBottomPadding;
144
Tony Wickham5edf9e22020-03-27 20:06:52 -0700145 // Workspace page indicator
146 public final int workspacePageIndicatorHeight;
147 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700148
Sunny Goyalc6205602015-05-21 20:46:33 -0700149 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400150 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700151 public int iconSizePx;
152 public int iconTextSizePx;
153 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700154 public int iconDrawablePaddingOriginalPx;
Thales Lima79456492023-05-23 11:32:22 +0100155 public boolean iconCenterVertically;
Winson Chungb3800242013-10-24 11:01:54 -0700156
Jon Mirandaab3c6812021-06-28 15:42:28 -0700157 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800158 public int cellWidthPx;
159 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700160 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800161
Thales Lima79456492023-05-23 11:32:22 +0100162 public int cellYPaddingPx = -1;
Jon Mirandae126d722021-02-25 10:45:20 -0500163
Sunny Goyalc6205602015-05-21 20:46:33 -0700164 // Folder
Jon Mirandae126d722021-02-25 10:45:20 -0500165 public float folderLabelTextScale;
166 public int folderLabelTextSizePx;
Thales Limab35faed2022-09-05 16:30:01 -0300167 public int folderFooterHeightPx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700168 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700169 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700170
Jon Mirandae126d722021-02-25 10:45:20 -0500171 // Folder content
Thales Limab35faed2022-09-05 16:30:01 -0300172 public int folderCellLayoutBorderSpacePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500173 public int folderContentPaddingLeftRight;
174 public int folderContentPaddingTop;
175
Jon Mirandabf7d8122016-11-03 15:29:29 -0700176 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700177 public int folderCellWidthPx;
178 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700179
180 // Folder child
181 public int folderChildIconSizePx;
182 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700183 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700184
Sunny Goyalc6205602015-05-21 20:46:33 -0700185 // Hotseat
Thales Lima9938c2f2022-07-25 14:38:16 +0100186 public int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700187 public int hotseatCellHeightPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100188 public final boolean areNavButtonsInline;
Jon Miranda18751b62017-07-31 17:25:27 -0700189 // In portrait: size = height, in landscape: size = width
190 public int hotseatBarSizePx;
Thales Limab8c05952022-05-23 16:58:38 +0100191 public int hotseatBarBottomSpacePx;
Pat Manning26f70f72022-07-07 13:50:39 +0100192 public int hotseatBarEndOffset;
Thales Limab8c05952022-05-23 16:58:38 +0100193 public int hotseatQsbSpace;
Pat Manningde25c0d2022-04-05 19:11:26 +0100194 public int springLoadedHotseatBarTopMarginPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700195 // Start is the side next to the nav bar, end is the side next to the workspace
196 public final int hotseatBarSidePaddingStartPx;
197 public final int hotseatBarSidePaddingEndPx;
Alex Chau206ede92022-08-01 17:46:12 +0100198 public int hotseatQsbWidth; // only used when isQsbInline
Sunny Goyal57b22792021-05-25 14:35:01 -0700199 public final int hotseatQsbHeight;
Thales Limab8c05952022-05-23 16:58:38 +0100200 public final int hotseatQsbVisualHeight;
201 private final int hotseatQsbShadowHeight;
Thales Limadd027342022-01-07 12:54:37 +0000202 public int hotseatBorderSpace;
Thales Limaffc68b02023-01-09 16:20:23 +0000203 private final int mMinHotseatIconSpacePx;
204 private final int mMinHotseatQsbWidthPx;
205 private final int mMaxHotseatIconSpacePx;
Jon Mirandae17a9492023-03-08 16:42:20 -0800206 public final int inlineNavButtonsEndSpacingPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700207
Alex Chau3d2c0622022-09-01 21:28:14 +0100208 // Bottom sheets
209 public int bottomSheetTopPadding;
210 public int bottomSheetOpenDuration;
211 public int bottomSheetCloseDuration;
212 public float bottomSheetWorkspaceScale;
213 public float bottomSheetDepth;
214
Sunny Goyalc6205602015-05-21 20:46:33 -0700215 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000216 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000217 public int allAppsShiftRange;
218 public int allAppsTopPadding;
Alex Chau3d2c0622022-09-01 21:28:14 +0100219 public int allAppsOpenDuration;
220 public int allAppsCloseDuration;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700221 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700222 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700223 public int allAppsIconSizePx;
224 public int allAppsIconDrawablePaddingPx;
sfufa@google.comde013292021-09-21 18:22:44 -0700225 public int allAppsLeftRightPadding;
Alex Chau27b39b92022-01-14 18:02:18 +0000226 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700227 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700228 public float allAppsIconTextSizePx;
229
Zak Cohen334efeb2021-03-19 16:42:07 -0700230 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700231 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000232 public int overviewTaskIconSizePx;
Alex Chauac9df382021-08-02 19:08:41 +0100233 public int overviewTaskIconDrawableSizePx;
234 public int overviewTaskIconDrawableSizeGridPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000235 public int overviewTaskThumbnailTopMarginPx;
Alex Chau19c6eca2022-03-10 20:12:56 +0000236 public final int overviewActionsHeight;
Alex Chaua2fc7642022-04-21 14:20:23 +0100237 public final int overviewActionsTopMarginPx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000238 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100239 public int overviewPageSpacing;
240 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000241 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700242
Jeremy Sim0ac47082022-10-10 13:59:40 -0700243 // Split staging
244 public int splitPlaceholderInset;
245
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800246 // Widgets
Sihua Mae04aa202022-07-18 12:43:56 -0700247 private final ViewScaleProvider mViewScaleProvider;
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800248
Sunny Goyal47328fd2016-05-25 18:56:41 -0700249 // Drop Target
250 public int dropTargetBarSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100251 public int dropTargetBarTopMarginPx;
252 public int dropTargetBarBottomMarginPx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100253 public int dropTargetDragPaddingPx;
254 public int dropTargetTextSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100255 public int dropTargetHorizontalPaddingPx;
256 public int dropTargetVerticalPaddingPx;
257 public int dropTargetGapPx;
Alex Chau5b019302022-05-23 10:42:25 +0100258 public int dropTargetButtonWorkspaceEdgeGapPx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700259
Winson1f064272016-07-18 17:18:02 -0700260 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800261 private final Rect mInsets = new Rect();
262 public final Rect workspacePadding = new Rect();
Sunny Goyal6c304b12023-04-10 12:03:04 -0700263 // Additional padding added to the widget inside its cellSpace. It is applied outside
264 // the widgetView, such that the actual view size is same as the widget size.
265 public final Rect widgetPadding = new Rect();
266
Jon Miranda0bd63d12019-03-06 17:29:29 -0800267 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700268 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700269
Tony Wickhamf34bee82018-12-03 18:11:39 -0800270 // Notification dots
Sunny Goyal65190ae2022-08-02 14:16:26 -0700271 public final DotRenderer mDotRendererWorkSpace;
272 public final DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800273
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100274 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800275 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000276 // Whether Taskbar will inset the bottom of apps by taskbarSize.
277 public boolean isTaskbarPresentInApps;
Jon Miranda9c478b62023-03-23 21:38:49 -0700278 public final int taskbarHeight;
279 public final int stashedTaskbarHeight;
280 public final int taskbarBottomMargin;
281 public final int taskbarIconSize;
Jon Miranda04f05102023-04-04 12:16:31 -0700282 // If true, used to layout taskbar in 3 button navigation mode.
283 public final boolean startAlignTaskbar;
Tony Wickham15883892021-02-12 11:24:40 -0800284
Alex Chaua02eddc2021-04-29 00:36:06 +0100285 // DragController
286 public int flingToDeleteThresholdVelocity;
287
Vinit Nayak17c4b332021-08-05 12:54:58 -0700288 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700289 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal65190ae2022-08-02 14:16:26 -0700290 SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
Alex Chauab800f72022-12-13 17:46:06 +0000291 boolean transposeLayoutWithOrientation, boolean isMultiDisplay, boolean isGestureMode,
Jon Miranda2b25ded2023-02-02 14:48:45 -0800292 @NonNull final ViewScaleProvider viewScaleProvider,
293 @NonNull final Consumer<DeviceProfile> dimensionOverrideProvider) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700294
Adam Cohen2e6da152015-05-06 11:42:25 -0700295 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700296 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800297 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500298 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +0000299 this.isMultiDisplay = isMultiDisplay;
Alex Chau6ed408f2022-03-04 12:58:05 +0000300 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700301 windowX = windowBounds.bounds.left;
302 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800303 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100304 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700305
Thales Limac98b7812023-04-14 15:04:23 +0100306 // TODO(b/241386436): shouldn't change any launcher behaviour
307 mIsResponsiveGrid = inv.workspaceSpecsId != INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100308
Thales Lima79456492023-05-23 11:32:22 +0100309 mIsScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000310 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700311 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000312 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700313 isPhone = !isTablet;
Alex Chauab800f72022-12-13 17:46:06 +0000314 isTwoPanels = isTablet && isMultiDisplay;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800315 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700316
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000317 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000318 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700319 ? Configuration.ORIENTATION_LANDSCAPE
320 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000321 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700322 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000323 mMetrics = res.getDisplayMetrics();
324
325 // Determine sizes.
326 widthPx = windowBounds.bounds.width();
327 heightPx = windowBounds.bounds.height();
328 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100329 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000330
331 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Thales Lima83bedbf2021-10-05 17:47:39 +0100332 if (isTwoPanels) {
333 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000334 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100335 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000336 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100337 }
338 } else {
339 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000340 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100341 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000342 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100343 }
344 }
345
Jon Miranda9c478b62023-03-23 21:38:49 -0700346 if (DisplayController.isTransientTaskbar(context)) {
347 float invTransientIconSizeDp = inv.transientTaskbarIconSize[mTypeIndex];
348 taskbarIconSize = pxFromDp(invTransientIconSizeDp, mMetrics);
349 taskbarHeight = taskbarIconSize
350 + (2 * res.getDimensionPixelSize(R.dimen.transient_taskbar_padding));
351 stashedTaskbarHeight =
352 res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_height);
353 taskbarBottomMargin =
354 res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin);
Jon Miranda04f05102023-04-04 12:16:31 -0700355 startAlignTaskbar = false;
Jon Miranda9c478b62023-03-23 21:38:49 -0700356 } else {
357 taskbarIconSize = pxFromDp(ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size),
358 mMetrics);
359 taskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_size);
360 stashedTaskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
361 taskbarBottomMargin = 0;
Jon Miranda04f05102023-04-04 12:16:31 -0700362 startAlignTaskbar = inv.startAlignTaskbar[mTypeIndex];
Tony Wickham15883892021-02-12 11:24:40 -0800363 }
Tony Wickham15883892021-02-12 11:24:40 -0800364
Winson Chungb3800242013-10-24 11:01:54 -0700365 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100366 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700367
Alex Chau51da2192022-05-20 13:32:10 +0100368 gridVisualizationPaddingX = res.getDimensionPixelSize(
369 R.dimen.grid_visualization_horizontal_cell_spacing);
370 gridVisualizationPaddingY = res.getDimensionPixelSize(
371 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500372
Alex Chaue0227552022-04-06 19:44:43 +0100373 bottomSheetTopPadding = mInsets.top // statusbar height
Andras Kloczl142b0542022-03-09 21:26:02 +0000374 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
375 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
Alex Chau3d2c0622022-09-01 21:28:14 +0100376 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
377 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
378 if (isTablet) {
379 bottomSheetWorkspaceScale = workspaceContentScale;
Alex Chauab800f72022-12-13 17:46:06 +0000380 if (isMultiDisplay && !ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH.get()) {
381 // TODO(b/259893832): Revert to use maxWallpaperScale to calculate bottomSheetDepth
382 // when screen recorder bug is fixed.
383 bottomSheetDepth = 1f;
384 } else {
385 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
386 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
387 // When depth is 1, wallpaper zoom is set to 1.
388 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
389 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
390 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
391 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
392 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100393 } else {
394 bottomSheetWorkspaceScale = 1f;
395 bottomSheetDepth = 0f;
396 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000397
Jon Mirandae126d722021-02-25 10:45:20 -0500398 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
Thales Limab35faed2022-09-05 16:30:01 -0300399
Thales Lima79456492023-05-23 11:32:22 +0100400 if (mIsScalableGrid && inv.folderStyle != INVALID_RESOURCE_HANDLE) {
Thales Limab35faed2022-09-05 16:30:01 -0300401 TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
Thales Limad852d652023-01-17 14:01:13 +0000402 R.styleable.FolderStyle);
Thales Limab35faed2022-09-05 16:30:01 -0300403 // These are re-set in #updateFolderCellSize if the grid is not scalable
404 folderCellHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000405 R.styleable.FolderStyle_folderCellHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300406 folderCellWidthPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000407 R.styleable.FolderStyle_folderCellWidth, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300408
409 folderContentPaddingTop = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000410 R.styleable.FolderStyle_folderTopPadding, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300411 folderCellLayoutBorderSpacePx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000412 R.styleable.FolderStyle_folderBorderSpace, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300413 folderFooterHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000414 R.styleable.FolderStyle_folderFooterHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300415 folderStyle.recycle();
416 } else {
417 folderCellLayoutBorderSpacePx = 0;
Thales Lima7eee74b2023-03-16 16:00:55 -0300418 folderFooterHeightPx = res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Thales Limab35faed2022-09-05 16:30:01 -0300419 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
420 }
Jon Mirandae126d722021-02-25 10:45:20 -0500421
Thales Lima85c942f2021-12-31 13:04:20 +0000422 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000423 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
424 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Thales Limae9273ea2023-01-26 12:33:52 +0000425 setupAllAppsStyle(context);
Jon Mirandae126d722021-02-25 10:45:20 -0500426
Tony Wickham5edf9e22020-03-27 20:06:52 -0700427 workspacePageIndicatorHeight = res.getDimensionPixelSize(
428 R.dimen.workspace_page_indicator_height);
429 mWorkspacePageIndicatorOverlapWorkspace =
430 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700431
Thales Limad852d652023-01-17 14:01:13 +0000432 TypedArray cellStyle;
433 if (inv.cellStyle != INVALID_RESOURCE_HANDLE) {
434 cellStyle = context.obtainStyledAttributes(inv.cellStyle,
435 R.styleable.CellStyle);
436 } else {
437 cellStyle = context.obtainStyledAttributes(R.style.CellStyleDefault,
438 R.styleable.CellStyle);
439 }
440 iconDrawablePaddingOriginalPx = cellStyle.getDimensionPixelSize(
441 R.styleable.CellStyle_iconDrawablePadding, 0);
442 cellStyle.recycle();
Alex Chaua02eddc2021-04-29 00:36:06 +0100443
Sunny Goyal47328fd2016-05-25 18:56:41 -0700444 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100445 dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
446 dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100447 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
448 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100449 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
450 R.dimen.drop_target_button_drawable_horizontal_padding);
451 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
452 R.dimen.drop_target_button_drawable_vertical_padding);
453 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100454 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
455 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100456
Alex Chau906d8822022-05-23 10:42:25 +0100457 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
458 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700459
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700460 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700461
Thales Limaa1012902022-01-13 17:58:42 +0000462 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100463 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
464 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
465
Thales Lima12d0eff2022-03-25 17:06:11 +0000466 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
467 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
468 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
469 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
470 && hotseatQsbHeight > 0;
Thales Lima79456492023-05-23 11:32:22 +0100471 isQsbInline = mIsScalableGrid && inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000472
Thales Lima425f6822022-05-10 13:44:58 -0300473 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100474 numShownHotseatIcons =
475 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000476
Sunny Goyal19ff7282021-04-22 10:12:54 -0700477 numShownAllAppsColumns =
478 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100479
480 int hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
481 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
482 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
483 // Have a little space between the inset and the QSB
484 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
485 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
486
487 // Only change the spaces if there is space
488 if (availableSpace > 0) {
489 // Make sure there is enough space between hotseat/QSB and QSB/navBar
490 if (availableSpace < minQsbMargin * 2) {
491 minQsbMargin = availableSpace / 2;
492 hotseatQsbSpace = minQsbMargin;
493 } else {
494 hotseatQsbSpace -= minQsbMargin;
495 }
496 }
497 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
498
Thales Limaa1012902022-01-13 17:58:42 +0000499 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100500 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
Thales Limaa1012902022-01-13 17:58:42 +0000501 }
Thales Lima425f6822022-05-10 13:44:58 -0300502
Pat Manningde25c0d2022-04-05 19:11:26 +0100503 springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
504 R.dimen.spring_loaded_hotseat_top_margin);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700505 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800506 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700507 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700508 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Thales Limab8c05952022-05-23 16:58:38 +0100509 updateHotseatSizes(pxFromDp(inv.iconSize[INDEX_DEFAULT], mMetrics));
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700510 if (areNavButtonsInline && !isPhone) {
Jon Mirandae17a9492023-03-08 16:42:20 -0800511 inlineNavButtonsEndSpacingPx =
Thales Limaffc68b02023-01-09 16:20:23 +0000512 res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing);
Pat Manning26f70f72022-07-07 13:50:39 +0100513 /*
514 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700515 * Spacing between nav buttons +
Thales Lima6a590062022-11-22 15:52:49 +0000516 * Space at the end for contextual buttons
Pat Manning26f70f72022-07-07 13:50:39 +0100517 */
518 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700519 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
Jon Mirandae17a9492023-03-08 16:42:20 -0800520 + inlineNavButtonsEndSpacingPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100521 } else {
Jon Mirandae17a9492023-03-08 16:42:20 -0800522 inlineNavButtonsEndSpacingPx = 0;
Pat Manning26f70f72022-07-07 13:50:39 +0100523 hotseatBarEndOffset = 0;
524 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700525
Thales Lima79456492023-05-23 11:32:22 +0100526 // Needs to be calculated after hotseatBarSizePx is correct,
527 // for the available height to be correct
528 if (mIsResponsiveGrid) {
529 mWorkspaceSpecs = new WorkspaceSpecs(new ResourceHelper(context, inv.workspaceSpecsId));
530 mResponsiveWidthSpec = mWorkspaceSpecs.getCalculatedWidthSpec(inv.numColumns,
531 availableWidthPx);
532 mResponsiveHeightSpec = mWorkspaceSpecs.getCalculatedHeightSpec(inv.numRows,
533 // don't use availableHeightPx because it subtracts bottom padding,
534 // but the hotseat go behind it
535 heightPx - mInsets.top - hotseatBarSizePx);
536 }
537
538 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
539 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
540
Alex Chau635b3ab2022-01-26 16:49:10 +0000541 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chau5fd9d492021-07-22 17:27:11 +0100542 overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100543 overviewTaskIconDrawableSizePx =
544 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
545 overviewTaskIconDrawableSizeGridPx =
546 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700547 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx;
Jeremy Sim3c2c3f12022-05-16 20:37:43 -0700548 overviewActionsTopMarginPx = res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000549 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
550 overviewActionsButtonSpacing = res.getDimensionPixelSize(
551 R.dimen.overview_actions_button_spacing);
Alex Chau19c6eca2022-03-10 20:12:56 +0000552 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700553 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000554 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700555
Jeremy Sim0ac47082022-10-10 13:59:40 -0700556 splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset);
557
Jon Miranda2ed276e2017-06-29 11:36:34 -0700558 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400559 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700560
Thales Lima79456492023-05-23 11:32:22 +0100561 calculateAndSetWorkspaceVerticalPadding(context, inv, extraSpace);
Pat Manning08610ca2022-04-05 21:03:16 +0100562
563 int cellLayoutPadding =
564 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
565 R.dimen.cell_layout_padding);
566 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
567 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800568 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800569
Thales Lima7eee74b2023-03-16 16:00:55 -0300570 // Folder scaling requires correct workspace paddings
571 updateAvailableFolderCellDimensions(res);
572
Thales Limaffc68b02023-01-09 16:20:23 +0000573 mMinHotseatIconSpacePx = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
574 mMinHotseatQsbWidthPx = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
575 mMaxHotseatIconSpacePx = areNavButtonsInline
Thales Lima6a590062022-11-22 15:52:49 +0000576 ? res.getDimensionPixelSize(R.dimen.max_hotseat_icon_space) : Integer.MAX_VALUE;
Thales Lima425f6822022-05-10 13:44:58 -0300577 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima6a590062022-11-22 15:52:49 +0000578 recalculateHotseatWidthAndBorderSpace();
Alex Chau206ede92022-08-01 17:46:12 +0100579
580 // AllApps height calculation depends on updated cellSize
581 if (isTablet) {
582 int collapseHandleHeight =
583 res.getDimensionPixelOffset(R.dimen.bottom_sheet_handle_area_height);
584 int contentHeight = heightPx - collapseHandleHeight - hotseatQsbHeight;
585 int targetContentHeight = (int) (allAppsCellHeightPx * ALL_APPS_TABLET_MAX_ROWS);
586 allAppsTopPadding = Math.max(mInsets.top, contentHeight - targetContentHeight);
587 allAppsShiftRange = heightPx - allAppsTopPadding;
588 } else {
589 allAppsTopPadding = 0;
590 allAppsShiftRange =
591 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
592 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100593 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
594 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300595
Alex Chaua02eddc2021-04-29 00:36:06 +0100596 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
597 R.dimen.drag_flingToDeleteMinVelocity);
598
Sihua Mae04aa202022-07-18 12:43:56 -0700599 mViewScaleProvider = viewScaleProvider;
600
Jon Miranda2b25ded2023-02-02 14:48:45 -0800601 dimensionOverrideProvider.accept(this);
602
Tony Wickham1237df02017-02-24 08:59:36 -0800603 // This is done last, after iconSizePx is calculated above.
Sunny Goyal799e1202023-02-09 10:54:28 -0800604 mDotRendererWorkSpace = createDotRenderer(context, iconSizePx, dotRendererCache);
605 mDotRendererAllApps = createDotRenderer(context, allAppsIconSizePx, dotRendererCache);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700606 }
607
608 private static DotRenderer createDotRenderer(
Sunny Goyal799e1202023-02-09 10:54:28 -0800609 @NonNull Context context, int size, @NonNull SparseArray<DotRenderer> cache) {
Sunny Goyal65190ae2022-08-02 14:16:26 -0700610 DotRenderer renderer = cache.get(size);
611 if (renderer == null) {
Sunny Goyal799e1202023-02-09 10:54:28 -0800612 renderer = new DotRenderer(size, getShapePath(context, DEFAULT_DOT_SIZE),
613 DEFAULT_DOT_SIZE);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700614 cache.put(size, renderer);
615 }
616 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700617 }
618
Thales Lima425f6822022-05-10 13:44:58 -0300619 /**
620 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
621 * width of the hotseat.
622 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100623 private int calculateQsbWidth(int hotseatBorderSpace) {
Thales Lima425f6822022-05-10 13:44:58 -0300624 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100625 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300626 return getIconToIconWidthForColumns(columns)
627 - iconSizePx * numShownHotseatIcons
628 - hotseatBorderSpace * numShownHotseatIcons;
629 } else {
630 int columns = inv.hotseatColumnSpan[mTypeIndex];
631 return getIconToIconWidthForColumns(columns);
632 }
633 }
Thales Lima2903a622022-03-17 13:52:19 +0000634
Thales Lima425f6822022-05-10 13:44:58 -0300635 private int getIconToIconWidthForColumns(int columns) {
636 return columns * getCellSize().x
637 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400638 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000639 }
640
Thales Limad90faab2021-09-21 17:18:47 +0100641 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
Thales Lima79456492023-05-23 11:32:22 +0100642 if (mIsResponsiveGrid) {
643 return mResponsiveWidthSpec.getStartPaddingPx();
644 }
645
Thales Limad90faab2021-09-21 17:18:47 +0100646 if (isVerticalBarLayout()) {
647 return 0;
648 }
649
Thales Lima79456492023-05-23 11:32:22 +0100650 return mIsScalableGrid
Thales Lima83bedbf2021-10-05 17:47:39 +0100651 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
652 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100653 }
654
Thales Lima79456492023-05-23 11:32:22 +0100655 private void calculateAndSetWorkspaceVerticalPadding(Context context,
656 InvariantDeviceProfile inv,
657 int extraSpace) {
658 if (mIsResponsiveGrid) {
659 workspaceTopPadding = mResponsiveHeightSpec.getStartPaddingPx();
660 workspaceBottomPadding = mResponsiveHeightSpec.getEndPaddingPx();
661 } else if (mIsScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
662 // Paddings were created assuming no scaling, so we first unscale the extra space.
663 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
664 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
665 DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
666 maxEmptySpace = padding.getMaxEmptySpacePx();
667
668 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
669 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
670
671 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
672 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
673 }
674 }
675
Thales Limab8c05952022-05-23 16:58:38 +0100676 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
677 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700678 // Ensure there is enough space for folder icons, which have a slightly larger radius.
679 hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR);
Thales Limab8c05952022-05-23 16:58:38 +0100680
Jon Miranda0d284852021-06-22 14:50:55 -0700681 if (isVerticalBarLayout()) {
682 hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
683 + hotseatBarSidePaddingEndPx;
Thales Limab8c05952022-05-23 16:58:38 +0100684 } else if (isQsbInline) {
685 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
686 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700687 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100688 hotseatBarSizePx = hotseatIconSizePx
689 + hotseatQsbSpace
690 + hotseatQsbVisualHeight
691 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700692 }
693 }
694
Thales Lima6a590062022-11-22 15:52:49 +0000695 /**
696 * Calculates the width of the hotseat, changing spaces between the icons and removing icons if
697 * necessary.
698 */
699 public void recalculateHotseatWidthAndBorderSpace() {
Thales Lima79456492023-05-23 11:32:22 +0100700 if (!mIsScalableGrid) return;
Thales Lima6a590062022-11-22 15:52:49 +0000701
702 int columns = inv.hotseatColumnSpan[mTypeIndex];
703 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
704 hotseatBorderSpace = calculateHotseatBorderSpace(hotseatWidthPx, /* numExtraBorder= */ 0);
Thales Lima9938c2f2022-07-25 14:38:16 +0100705 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
Thales Lima6a590062022-11-22 15:52:49 +0000706 // Spaces should be correct when the nav buttons are not inline
Thales Lima9938c2f2022-07-25 14:38:16 +0100707 if (!areNavButtonsInline) {
708 return;
709 }
710
Thales Lima6a590062022-11-22 15:52:49 +0000711 // The side space with inline buttons should be what is defined in InvariantDeviceProfile
Jon Mirandae17a9492023-03-08 16:42:20 -0800712 int sideSpacePx = inlineNavButtonsEndSpacingPx;
Thales Limaffc68b02023-01-09 16:20:23 +0000713 int maxHotseatWidthPx = availableWidthPx - sideSpacePx - hotseatBarEndOffset;
714 int maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
715 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000716 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100717
Thales Limaffc68b02023-01-09 16:20:23 +0000718 if (hotseatBorderSpace >= mMinHotseatIconSpacePx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100719 return;
720 }
721
722 // Border space can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000723 hotseatBorderSpace = mMinHotseatIconSpacePx;
Thales Lima6a590062022-11-22 15:52:49 +0000724 int requiredWidth = getHotseatRequiredWidth();
Thales Lima9938c2f2022-07-25 14:38:16 +0100725
726 // If there is an inline qsb, change its size
727 if (isQsbInline) {
Thales Limaffc68b02023-01-09 16:20:23 +0000728 hotseatQsbWidth -= requiredWidth - maxHotseatWidthPx;
729 if (hotseatQsbWidth >= mMinHotseatQsbWidthPx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100730 return;
731 }
732
733 // QSB can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000734 hotseatQsbWidth = mMinHotseatQsbWidthPx;
Thales Lima9938c2f2022-07-25 14:38:16 +0100735 }
736
Thales Limaffc68b02023-01-09 16:20:23 +0000737 maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
Thales Lima6a590062022-11-22 15:52:49 +0000738
Thales Lima9938c2f2022-07-25 14:38:16 +0100739 // If it still doesn't fit, start removing icons
740 do {
741 numShownHotseatIcons--;
Thales Limaffc68b02023-01-09 16:20:23 +0000742 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000743 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Limaffc68b02023-01-09 16:20:23 +0000744 } while (hotseatBorderSpace < mMinHotseatIconSpacePx && numShownHotseatIcons > 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100745
Thales Lima9938c2f2022-07-25 14:38:16 +0100746 }
747
Thales Lima78d00ad2021-09-30 11:29:06 +0100748 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100749 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100750 }
751
752 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima79456492023-05-23 11:32:22 +0100753 int horizontalSpacePx = 0;
754 int verticalSpacePx = 0;
Thales Lima78d00ad2021-09-30 11:29:06 +0100755
Thales Lima79456492023-05-23 11:32:22 +0100756 if (mIsResponsiveGrid) {
757 horizontalSpacePx = mResponsiveWidthSpec.getGutterPx();
758 verticalSpacePx = mResponsiveHeightSpec.getGutterPx();
759 } else if (mIsScalableGrid) {
760 horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
761 verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
762 }
Thales Lima78d00ad2021-09-30 11:29:06 +0100763
764 return new Point(horizontalSpacePx, verticalSpacePx);
765 }
766
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700767 public Info getDisplayInfo() {
768 return mInfo;
769 }
770
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700771 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800772 WindowBounds bounds = new WindowBounds(
773 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700774 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100775 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700776
777 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
778 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
779 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
780
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700781 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700782 .setWindowBounds(bounds)
Alex Chauab800f72022-12-13 17:46:06 +0000783 .setIsMultiDisplay(isMultiDisplay)
Alex Chau6ed408f2022-03-04 12:58:05 +0000784 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700785 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000786 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800787 }
788
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700789 public DeviceProfile copy(Context context) {
790 return toBuilder(context).build();
791 }
792
793 /**
794 * TODO: Move this to the builder as part of setMultiWindowMode
795 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700796 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700797 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700798 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700799 .setMultiWindowMode(true)
800 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800801
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800802 // We use these scales to measure and layout the widgets using their full invariant profile
803 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
804 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
805 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700806 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
807 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
808 profile = profile.toBuilder(context)
809 .setViewScaleProvider(i -> p)
810 .build();
811 }
812
813 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800814
Jon Miranda93e1f042016-11-11 14:13:04 -0800815 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700816 }
817
Adam Cohen63f1ec02014-08-12 09:23:13 -0700818 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400819 * Checks if there is enough space for labels on the workspace.
820 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700821 * It is important to call this method after the All Apps variables have been set.
822 */
Jon Miranda941375e2021-03-31 13:10:45 -0400823 private void hideWorkspaceLabelsIfNotEnoughSpace() {
824 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
825 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
826 - iconTextHeight;
827
828 // We want enough space so that the text is closer to its corresponding icon.
829 if (workspaceCellPaddingY < iconTextHeight) {
830 iconTextSizePx = 0;
831 iconDrawablePaddingPx = 0;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700832 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda941375e2021-03-31 13:10:45 -0400833 autoResizeAllAppsCells();
834 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700835 }
Jon Miranda1091e532017-07-21 13:31:50 -0700836
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700837 /**
838 * Re-computes the all-apps cell size to be independent of workspace
839 */
840 public void autoResizeAllAppsCells() {
Jon Miranda941375e2021-03-31 13:10:45 -0400841 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
842 int topBottomPadding = textHeight;
Jon Miranda1091e532017-07-21 13:31:50 -0700843 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
Jon Miranda941375e2021-03-31 13:10:45 -0400844 + textHeight + (topBottomPadding * 2);
Jon Miranda1091e532017-07-21 13:31:50 -0700845 }
846
Thales Limab7ef5692022-03-10 10:32:36 +0000847 private void updateAllAppsContainerWidth(Resources res) {
Pat Manning08610ca2022-04-05 21:03:16 +0100848 int cellLayoutHorizontalPadding =
849 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
Alex Chau27b39b92022-01-14 18:02:18 +0000850 if (isTablet) {
sfufa@google.comde013292021-09-21 18:22:44 -0700851 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
Thales Limab7ef5692022-03-10 10:32:36 +0000852 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Alex Chau27b39b92022-01-14 18:02:18 +0000853 + allAppsLeftRightPadding * 2;
854 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
sfufa@google.comde013292021-09-21 18:22:44 -0700855 } else {
856 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100857 desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding;
sfufa@google.comde013292021-09-21 18:22:44 -0700858 }
859 }
860
Thales Limae9273ea2023-01-26 12:33:52 +0000861 private void setupAllAppsStyle(Context context) {
862 TypedArray allAppsStyle;
863 if (inv.allAppsStyle != INVALID_RESOURCE_HANDLE) {
864 allAppsStyle = context.obtainStyledAttributes(inv.allAppsStyle,
865 R.styleable.AllAppsStyle);
866 } else {
867 allAppsStyle = context.obtainStyledAttributes(R.style.AllAppsStyleDefault,
868 R.styleable.AllAppsStyle);
869 }
870 allAppsLeftRightPadding = allAppsStyle.getDimensionPixelSize(
871 R.styleable.AllAppsStyle_horizontalPadding, 0);
872 allAppsStyle.recycle();
873 }
874
Jon Miranda228877d2021-02-09 11:05:00 -0500875 /**
876 * Returns the amount of extra (or unused) vertical space.
877 */
878 private int updateAvailableDimensions(Resources res) {
Alex Chaua68164d2022-12-15 16:16:03 +0000879 float invIconSizeDp = inv.iconSize[mTypeIndex];
880 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
881 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
882 iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
Thales Lima79456492023-05-23 11:32:22 +0100883 iconCenterVertically = mIsScalableGrid || mIsResponsiveGrid;
Alex Chaua68164d2022-12-15 16:16:03 +0000884
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700885 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800886
Pat Manning08610ca2022-04-05 21:03:16 +0100887 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -0500888
889 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +0100890 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +0000891 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -0500892 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500893 float scaleY = maxHeight / usedHeight;
894 boolean shouldScale = scaleY < 1f;
895
896 float scaleX = 1f;
Thales Lima79456492023-05-23 11:32:22 +0100897 if (mIsScalableGrid) {
Jon Mirandae126d722021-02-25 10:45:20 -0500898 // We scale to fit the cellWidth and cellHeight in the available space.
899 // The benefit of scalable grids is that we can get consistent aspect ratios between
900 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +0100901 float usedWidth =
902 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500903 // We do not subtract padding here, as we also scale the workspace padding if needed.
904 scaleX = availableWidthPx / usedWidth;
905 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700906 }
Jon Mirandae126d722021-02-25 10:45:20 -0500907
908 if (shouldScale) {
909 float scale = Math.min(scaleX, scaleY);
910 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +0100911 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -0500912 }
913
Jon Miranda228877d2021-02-09 11:05:00 -0500914 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700915 }
916
Pat Manninga2e14992022-04-22 11:29:17 +0100917 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +0100918 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
919 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
920 }
921
Pat Manninga2e14992022-04-22 11:29:17 +0100922 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +0000923 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +0100924 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
925 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -0500926 }
927
Jon Miranda6f7e9702019-09-16 14:44:14 -0700928 /**
929 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
930 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
931 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
932 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800933 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -0700934 // Icon scale should never exceed 1, otherwise pixellation may occur.
935 iconScale = Math.min(1f, scale);
936 cellScaleToFit = scale;
937
Jon Miranda18751b62017-07-31 17:25:27 -0700938 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800939 final boolean isVerticalLayout = isVerticalBarLayout();
Jon Mirandaab3c6812021-06-28 15:42:28 -0700940 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);
Thales Lima080d8902022-03-28 15:30:29 +0100941 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Thales Lima79456492023-05-23 11:32:22 +0100942 int cellTextAndPaddingHeight =
943 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Jon Mirandae126d722021-02-25 10:45:20 -0500944
Thales Lima79456492023-05-23 11:32:22 +0100945 if (mIsResponsiveGrid) {
946 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
947
948 cellWidthPx = mResponsiveWidthSpec.getCellSizePx();
949 cellHeightPx = mResponsiveHeightSpec.getCellSizePx();
950 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
951
952 // TODO(b/283929701): decrease icon size if content doesn't fit on cell
953 } else if (mIsScalableGrid) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100954 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
955 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +0000956
957 if (cellWidthPx < iconSizePx) {
958 // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger.
959 int numColumns = getPanelCount() * inv.numColumns;
960 int numBorders = numColumns - 1;
961 int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns;
962 if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) {
963 cellWidthPx = iconSizePx;
964 cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders;
965 } else {
966 // If it still doesn't fit, set borderSpace to 0 and distribute the space for
967 // cellWidth, and reduce iconSize.
968 cellWidthPx = (cellWidthPx * numColumns
969 + cellLayoutBorderSpacePx.x * numBorders) / numColumns;
970 iconSizePx = Math.min(iconSizePx, cellWidthPx);
971 cellLayoutBorderSpacePx.x = 0;
972 }
973 }
974
Alex Chaube753132022-12-09 16:46:54 +0000975 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
976 if (cellHeightPx < cellContentHeight) {
977 // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight
978 // bigger.
979 int numBorders = inv.numRows - 1;
980 int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows;
981 if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) {
982 cellHeightPx = cellContentHeight;
983 cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders;
984 } else {
Alex Chau06f36e82023-01-06 10:50:54 +0000985 // If it still doesn't fit, set borderSpace to 0 to recover space.
Alex Chaube753132022-12-09 16:46:54 +0000986 cellHeightPx = (cellHeightPx * inv.numRows
987 + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows;
Alex Chaube753132022-12-09 16:46:54 +0000988 cellLayoutBorderSpacePx.y = 0;
Alex Chau06f36e82023-01-06 10:50:54 +0000989 // Reduce iconDrawablePaddingPx to make cellContentHeight smaller.
990 int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx;
991 if (cellContentWithoutPadding <= cellHeightPx) {
992 iconDrawablePaddingPx = cellContentHeight - cellHeightPx;
993 } else {
994 // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space,
995 // then proportional reduce iconSizePx and iconTextSizePx to fit.
996 iconDrawablePaddingPx = 0;
997 float ratio = cellHeightPx / (float) cellContentWithoutPadding;
998 iconSizePx = (int) (iconSizePx * ratio);
999 iconTextSizePx = (int) (iconTextSizePx * ratio);
1000 }
1001 cellTextAndPaddingHeight =
1002 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +00001003 }
1004 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
1005 }
Jon Mirandae126d722021-02-25 10:45:20 -05001006 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +01001007 desiredWorkspaceHorizontalMarginPx =
1008 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -05001009 } else {
Jon Mirandae126d722021-02-25 10:45:20 -05001010 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001011 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR)
1012 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -05001013 + Utilities.calculateTextHeight(iconTextSizePx);
1014 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
1015 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
1016 && !isMultiWindowMode) {
1017 // Ensures that the label is closer to its corresponding icon. This is not an issue
1018 // with vertical bar layout or multi-window mode since the issue is handled
1019 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
1020 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
1021 iconDrawablePaddingPx = cellPaddingY;
1022 }
Jon Miranda846455e2017-10-02 14:58:52 -07001023 }
Jon Miranda18751b62017-07-31 17:25:27 -07001024
Sunny Goyalae190ff2020-04-14 00:19:01 +00001025 // All apps
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001026 updateAllAppsIconSize(scale, res);
Winson Chungb3800242013-10-24 11:01:54 -07001027
Thales Limab8c05952022-05-23 16:58:38 +01001028 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -07001029
Sunny Goyalbaec6ff2016-09-14 11:26:21 -07001030 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -07001031 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
1032 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Sunny Goyal6c304b12023-04-10 12:03:04 -07001033
1034 // Update widget padding:
1035 float minSpacing = pxFromDp(MIN_WIDGET_PADDING_DP, mMetrics);
1036 if (cellLayoutBorderSpacePx.x < minSpacing
1037 || cellLayoutBorderSpacePx.y < minSpacing) {
1038 widgetPadding.left = widgetPadding.right =
1039 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.x));
1040 widgetPadding.top = widgetPadding.bottom =
1041 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.y));
1042 } else {
1043 widgetPadding.setEmpty();
1044 }
Winson Chung0f785722015-04-08 10:27:49 -07001045 }
1046
Thales Lima425f6822022-05-10 13:44:58 -03001047 /**
Thales Lima6a590062022-11-22 15:52:49 +00001048 * This method calculates the space between the icons to achieve a certain width.
Thales Lima425f6822022-05-10 13:44:58 -03001049 */
Thales Lima6a590062022-11-22 15:52:49 +00001050 private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) {
Thales Lima9938c2f2022-07-25 14:38:16 +01001051 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
Thales Limaffc68b02023-01-09 16:20:23 +00001052 int hotseatBorderSpacePx =
Thales Lima6a590062022-11-22 15:52:49 +00001053 (int) (hotseatWidthPx - hotseatIconsTotalPx)
1054 / (numShownHotseatIcons - 1 + numExtraBorder);
Thales Limaffc68b02023-01-09 16:20:23 +00001055 return Math.min(hotseatBorderSpacePx, mMaxHotseatIconSpacePx);
Thales Lima425f6822022-05-10 13:44:58 -03001056 }
1057
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001058
1059 /**
1060 * Updates the iconSize for allApps* variants.
1061 */
Brian Isganitisa9a78112022-05-23 18:11:47 -07001062 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +01001063 allAppsBorderSpacePx = new Point(
1064 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
1065 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001066 // AllApps cells don't have real space between cells,
1067 // so we add the border space to the cell height
Alex Chaube753132022-12-09 16:46:54 +00001068 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics)
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001069 + allAppsBorderSpacePx.y;
1070 // but width is just the cell,
1071 // the border is added in #updateAllAppsContainerWidth
Thales Lima79456492023-05-23 11:32:22 +01001072 if (mIsScalableGrid) {
Alex Chaube753132022-12-09 16:46:54 +00001073 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1074 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001075 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001076 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001077
1078 if (allAppsCellWidthPx < allAppsIconSizePx) {
1079 // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to
1080 // make allAppsCellWidth bigger.
1081 int numBorders = inv.numAllAppsColumns - 1;
1082 int extraWidthRequired =
1083 (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns;
1084 if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) {
1085 allAppsCellWidthPx = allAppsIconSizePx;
1086 allAppsBorderSpacePx.x -= extraWidthRequired / numBorders;
1087 } else {
1088 // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space
1089 // for allAppsCellWidth, and reduce allAppsIconSize.
1090 allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns
1091 + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns;
1092 allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx);
1093 allAppsBorderSpacePx.x = 0;
1094 }
1095 }
1096
1097 int cellContentHeight = allAppsIconSizePx
1098 + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y;
1099 if (allAppsCellHeightPx < cellContentHeight) {
1100 // Increase allAppsCellHeight to fit its content.
1101 allAppsCellHeightPx = cellContentHeight;
1102 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001103 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001104 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
1105 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001106 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1107 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001108 allAppsIconDrawablePaddingPx =
1109 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001110 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001111 }
1112
Thales Limab7ef5692022-03-10 10:32:36 +00001113 updateAllAppsContainerWidth(res);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001114 if (isVerticalBarLayout()) {
1115 hideWorkspaceLabelsIfNotEnoughSpace();
1116 }
1117 }
1118
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001119 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001120 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001121
Thales Lima7eee74b2023-03-16 16:00:55 -03001122 // For usability we can't have the folder use the whole width of the screen
Sunny Goyal07b69292018-01-08 14:19:34 -08001123 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -08001124
Thales Lima7eee74b2023-03-16 16:00:55 -03001125 // Check if the folder fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -05001126 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Thales Lima7eee74b2023-03-16 16:00:55 -03001127 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx)
1128 + folderFooterHeightPx
1129 + folderContentPaddingTop;
1130 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001131 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -08001132
Thales Lima7eee74b2023-03-16 16:00:55 -03001133 // Check if the folder fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -05001134 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Thales Lima7eee74b2023-03-16 16:00:55 -03001135 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx)
1136 + folderContentPaddingLeftRight * 2;
1137 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001138 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -08001139
1140 float scale = Math.min(scaleX, scaleY);
1141 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001142 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001143 }
1144 }
1145
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001146 private void updateFolderCellSize(float scale, Resources res) {
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001147 float invIconSizeDp = inv.iconSize[mTypeIndex];
Sunny Goyal35c7b192021-04-20 16:51:10 -07001148 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001149 folderChildTextSizePx = pxFromSp(inv.iconTextSize[mTypeIndex], mMetrics, scale);
Thales Lima7eee74b2023-03-16 16:00:55 -03001150 folderLabelTextSizePx = Math.max(pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale),
Thales Limab35faed2022-09-05 16:30:01 -03001151 (int) (folderChildTextSizePx * folderLabelTextScale));
Jon Mirandabf7d8122016-11-03 15:29:29 -07001152
1153 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001154
Thales Lima79456492023-05-23 11:32:22 +01001155 if (mIsScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001156 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
Thales Lima7eee74b2023-03-16 16:00:55 -03001157 folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale);
1158 folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale);
1159 } else {
1160 folderCellWidthPx = roundPxValueFromFloat(folderCellWidthPx * scale);
1161 folderCellHeightPx = roundPxValueFromFloat(folderCellHeightPx * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001162 }
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001163
Thales Lima7eee74b2023-03-16 16:00:55 -03001164 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
1165 folderCellLayoutBorderSpacePx = roundPxValueFromFloat(
1166 folderCellLayoutBorderSpacePx * scale);
1167 folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale);
1168
Thales Limab35faed2022-09-05 16:30:01 -03001169 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx;
Jon Miranda823da222021-03-23 08:08:45 -04001170 } else {
1171 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1172 * scale);
1173 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1174 * scale);
1175
1176 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1177 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Lima7eee74b2023-03-16 16:00:55 -03001178 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001179 folderContentPaddingLeftRight =
1180 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1181 folderFooterHeightPx =
Thales Lima7eee74b2023-03-16 16:00:55 -03001182 roundPxValueFromFloat(
1183 res.getDimensionPixelSize(R.dimen.folder_footer_height_default)
1184 * scale);
1185
Jon Miranda823da222021-03-23 08:08:45 -04001186 }
1187
Jonathan Miranda9ad87462017-07-26 17:41:02 +00001188 folderChildDrawablePaddingPx = Math.max(0,
1189 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001190 }
1191
Winson1f064272016-07-18 17:18:02 -07001192 public void updateInsets(Rect insets) {
1193 mInsets.set(insets);
1194 }
1195
Sunny Goyalae6e3182019-04-30 12:04:37 -07001196 /**
1197 * The current device insets. This is generally same as the insets being dispatched to
1198 * {@link Insettable} elements, but can differ if the element is using a different profile.
1199 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001200 public Rect getInsets() {
1201 return mInsets;
1202 }
1203
Sunny Goyal756cd262015-08-20 12:33:21 -07001204 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001205 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001206 }
1207
Sunny Goyal19ff7282021-04-22 10:12:54 -07001208 public Point getCellSize(Point result) {
1209 if (result == null) {
1210 result = new Point();
1211 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001212
Pat Manning25d53342022-05-10 09:58:49 +00001213 int shortcutAndWidgetContainerWidth =
1214 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1215 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1216 inv.numColumns);
1217 int shortcutAndWidgetContainerHeight =
1218 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1219 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1220 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001221 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001222 }
1223
1224 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001225 * Returns the left and right space on the cell, which is the cell width - icon size
1226 */
1227 public int getCellHorizontalSpace() {
1228 return getCellSize().x - iconSizePx;
1229 }
1230
1231 /**
Pat Manning25d53342022-05-10 09:58:49 +00001232 * Gets the number of panels within the workspace.
1233 */
1234 public int getPanelCount() {
1235 return isTwoPanels ? 2 : 1;
1236 }
1237
1238 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001239 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1240 * bottom of the screen.
1241 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001242 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1243 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001244 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001245 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001246 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001247 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001248 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001249 }
1250
1251 /**
1252 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1253 */
Pat Manning25d53342022-05-10 09:58:49 +00001254 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001255 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001256 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001257 }
1258
1259 /**
1260 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1261 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001262 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001263 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001264 return heightPx - (isVerticalBarLayout()
1265 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001266 }
1267
Pat Manningea5c1d22022-04-14 10:58:16 +01001268 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001269 * Gets the scale of the workspace for the spring-loaded edit state.
1270 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001271 public float getWorkspaceSpringLoadScale(Context context) {
1272 float scale =
1273 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1274 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001275 scale = Math.min(scale, 1f);
1276
Pat Manninge63dd252022-08-02 16:15:29 +01001277 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001278 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001279 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001280 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001281 if (scaledWorkspaceWidth > maxAvailableWidth) {
1282 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1283 }
1284 return scale;
1285 }
1286
Pat Manning25d53342022-05-10 09:58:49 +00001287 /**
1288 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1289 *
1290 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1291 * layouts have two Cell Layouts per workspace.
1292 */
1293 public int getCellLayoutWidth() {
1294 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001295 }
1296
Pat Manning25d53342022-05-10 09:58:49 +00001297 /**
1298 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1299 *
1300 * <p>This is the height of a Workspace, less its vertical padding.
1301 */
1302 public int getCellLayoutHeight() {
1303 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001304 }
1305
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001306 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001307 return new Point(workspacePadding.left + workspacePadding.right,
1308 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001309 }
1310
1311 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001312 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1313 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001314 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001315 private void updateWorkspacePadding() {
1316 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001317 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -08001318 padding.top = 0;
1319 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001320 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001321 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -07001322 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -07001323 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -07001324 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001325 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -07001326 }
Winson Chungb3800242013-10-24 11:01:54 -07001327 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001328 // Pad the bottom of the workspace with hotseat bar
1329 // and leave a bit of space in case a widget go all the way down
Thales Lima79456492023-05-23 11:32:22 +01001330 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding - mInsets.bottom;
1331 if (!mIsResponsiveGrid) {
1332 paddingBottom +=
1333 workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace;
1334 }
1335 int paddingTop = workspaceTopPadding + (mIsScalableGrid ? 0 : edgeMarginPx);
Pat Manning08610ca2022-04-05 21:03:16 +01001336 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001337
Pat Manning08610ca2022-04-05 21:03:16 +01001338 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001339 }
Pat Manning08610ca2022-04-05 21:03:16 +01001340 insetPadding(workspacePadding, cellLayoutPaddingPx);
1341 }
1342
1343 private void insetPadding(Rect paddings, Rect insets) {
1344 insets.left = Math.min(insets.left, paddings.left);
1345 paddings.left -= insets.left;
1346
1347 insets.top = Math.min(insets.top, paddings.top);
1348 paddings.top -= insets.top;
1349
1350 insets.right = Math.min(insets.right, paddings.right);
1351 paddings.right -= insets.right;
1352
1353 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1354 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001355 }
1356
Sunny Goyal57b22792021-05-25 14:35:01 -07001357 /**
1358 * Returns the padding for hotseat view
1359 */
1360 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001361 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001362 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001363 // The hotseat icons will be placed in the middle of the hotseat cells.
1364 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1365 // in vertical bar layout.
1366 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1367 // is set to account for that difference.
1368 float diffOverlapFactor = iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
Pat Manning08610ca2022-04-05 21:03:16 +01001369 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1370 - diffOverlapFactor), 0);
1371 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001372 + diffOverlapFactor), 0);
1373
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001374 if (isSeascape()) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001375 hotseatBarPadding.set(mInsets.left + hotseatBarSidePaddingStartPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001376 hotseatBarSidePaddingEndPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001377 } else {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001378 hotseatBarPadding.set(hotseatBarSidePaddingEndPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001379 mInsets.right + hotseatBarSidePaddingStartPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001380 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001381 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001382 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001383 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1384 int hotseatBarTopPadding =
1385 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001386
Thales Lima6a590062022-11-22 15:52:49 +00001387 int hotseatWidth = getHotseatRequiredWidth();
Helen Cheuke76291f2023-02-14 17:11:05 +00001388 int startSpacing;
1389 int endSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001390 // Hotseat aligns to the left with nav buttons
1391 if (hotseatBarEndOffset > 0) {
Jon Mirandae17a9492023-03-08 16:42:20 -08001392 startSpacing = inlineNavButtonsEndSpacingPx;
Helen Cheuke76291f2023-02-14 17:11:05 +00001393 endSpacing = availableWidthPx - hotseatWidth - startSpacing + hotseatBorderSpace;
1394 } else {
1395 startSpacing = (availableWidthPx - hotseatWidth) / 2;
1396 endSpacing = startSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001397 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001398 startSpacing += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001399
Helen Cheuke76291f2023-02-14 17:11:05 +00001400 hotseatBarPadding.top = hotseatBarTopPadding;
1401 hotseatBarPadding.bottom = hotseatBarBottomPadding;
Alex Chau51da2192022-05-20 13:32:10 +01001402 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001403 if (isRtl) {
Helen Cheuke76291f2023-02-14 17:11:05 +00001404 hotseatBarPadding.left = endSpacing;
1405 hotseatBarPadding.right = startSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001406 } else {
Helen Cheuke76291f2023-02-14 17:11:05 +00001407 hotseatBarPadding.left = startSpacing;
1408 hotseatBarPadding.right = endSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001409 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001410
Thales Lima79456492023-05-23 11:32:22 +01001411 } else if (mIsScalableGrid) {
Alex Chau206ede92022-08-01 17:46:12 +01001412 int sideSpacing = (availableWidthPx - hotseatQsbWidth) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001413 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001414 0,
Thales Lima425f6822022-05-10 13:44:58 -03001415 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001416 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001417 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001418 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1419 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1420 // for this, we pad the left and right of the hotseat with half of the difference of a
1421 // workspace cell vs a hotseat cell.
1422 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001423 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001424 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001425 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001426 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1427 + mInsets.left,
1428 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001429 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001430 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001431 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001432 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001433 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001434 }
1435
Thales Lima9938c2f2022-07-25 14:38:16 +01001436 private int getAdditionalQsbSpace() {
1437 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1438 }
1439
1440 /**
1441 * Calculate how much space the hotseat needs to be shown completely
1442 */
1443 private int getHotseatRequiredWidth() {
1444 int additionalQsbSpace = getAdditionalQsbSpace();
1445 return iconSizePx * numShownHotseatIcons
Thales Lima6a590062022-11-22 15:52:49 +00001446 + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1))
Thales Lima9938c2f2022-07-25 14:38:16 +01001447 + additionalQsbSpace;
1448 }
1449
Winsonfadbe8f2016-07-22 16:35:37 -07001450 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001451 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1452 */
1453 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001454 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001455 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1456 } else if (isTaskbarPresent) { // QSB on top
1457 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001458 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001459 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001460 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001461 }
1462
Thales Limab8c05952022-05-23 16:58:38 +01001463 /**
1464 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1465 */
1466 private int getHotseatBarBottomPadding() {
1467 if (isTaskbarPresent) { // QSB on top or inline
1468 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001469 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001470 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001471 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001472 }
1473
1474 /**
Alex Chau51da2192022-05-20 13:32:10 +01001475 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1476 */
1477 public int getTaskbarOffsetY() {
Jon Miranda9c478b62023-03-23 21:38:49 -07001478 int taskbarIconBottomSpace = (taskbarHeight - iconSizePx) / 2;
Alex Chau51da2192022-05-20 13:32:10 +01001479 int launcherIconBottomSpace =
1480 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001481 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001482 }
1483
1484 /**
Alex Chaua2fc7642022-04-21 14:20:23 +01001485 * Returns the number of pixels required below OverviewActions excluding insets.
1486 */
1487 public int getOverviewActionsClaimedSpaceBelow() {
Alex Chaud67ddc42022-09-30 18:15:56 +01001488 if (isTaskbarPresent) {
Jon Miranda9c478b62023-03-23 21:38:49 -07001489 return taskbarHeight + taskbarBottomMargin * 2;
Alex Chaud67ddc42022-09-30 18:15:56 +01001490 }
1491 return mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001492 }
1493
1494 /** Gets the space that the overview actions will take, including bottom margin. */
1495 public int getOverviewActionsClaimedSpace() {
Pat Manning7b8f7662023-01-18 14:48:30 +00001496 int overviewActionsSpace = isTablet && FeatureFlags.ENABLE_GRID_ONLY_OVERVIEW.get()
1497 ? 0
1498 : (overviewActionsTopMarginPx + overviewActionsHeight);
1499 return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
Alex Chaua2fc7642022-04-21 14:20:23 +01001500 }
1501
1502 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001503 * Takes the View and return the scales of width and height depending on the DeviceProfile
1504 * specifications
1505 *
1506 * @param itemInfo The tag of the widget view
1507 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1508 * height
1509 */
1510 @NonNull
1511 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1512 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1513 }
1514
1515 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001516 * @return the bounds for which the open folders should be contained within
1517 */
1518 public Rect getAbsoluteOpenFolderBounds() {
1519 if (isVerticalBarLayout()) {
1520 // Folders should only appear right of the drop target bar and left of the hotseat
1521 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1522 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001523 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001524 mInsets.top + availableHeightPx);
1525 } else {
1526 // Folders should only appear below the drop target bar and above the hotseat
Jon Miranda9c478b62023-03-23 21:38:49 -07001527 int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001528 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001529 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001530 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001531 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001532 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001533 }
1534 }
1535
Jon Miranda228877d2021-02-09 11:05:00 -05001536 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1537 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001538 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001539
Jon Miranda228877d2021-02-09 11:05:00 -05001540 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1541 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001542 }
1543
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001544 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001545 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1546 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1547 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001548 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001549 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001550 return isLandscape && transposeLayoutWithOrientation;
1551 }
1552
Sunny Goyal59d086c2018-05-07 17:31:40 -07001553 /**
1554 * Updates orientation information and returns true if it has changed from the previous value.
1555 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001556 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001557 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001558 boolean isSeascape = DisplayController.INSTANCE.get(context)
1559 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001560 if (mIsSeascape != isSeascape) {
1561 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001562 // Hotseat changing sides requires updating workspace left/right paddings
1563 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001564 return true;
1565 }
1566 }
1567 return false;
1568 }
1569
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001570 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001571 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001572 }
1573
Sunny Goyal07b69292018-01-08 14:19:34 -08001574 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001575 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001576 }
1577
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001578 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001579 switch (containerType) {
1580 case CellLayout.WORKSPACE:
1581 return cellHeightPx;
1582 case CellLayout.FOLDER:
1583 return folderCellHeightPx;
1584 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001585 // The hotseat is the only container where the cell height is going to be
1586 // different from the content within that cell.
1587 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001588 default:
1589 // ??
1590 return 0;
1591 }
1592 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001593
Jon Miranda58561d42021-03-17 10:51:54 -04001594 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001595 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001596 }
1597
Alex Chaue818bcb2022-09-02 17:27:11 +01001598 private String dpPointFToString(String name, PointF value) {
1599 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
1600 }
1601
Pat Manning5f74bfd2022-07-20 12:08:54 +01001602 /** Dumps various DeviceProfile variables to the specified writer. */
1603 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04001604 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001605 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001606
1607 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001608 writer.println(prefix + "\tisPhone:" + isPhone);
1609 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1610 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001611 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001612
1613 writer.println(prefix + "\tisLandscape:" + isLandscape);
1614 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001615 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001616
1617 writer.println(prefix + pxToDpStr("windowX", windowX));
1618 writer.println(prefix + pxToDpStr("windowY", windowY));
1619 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1620 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001621 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1622 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001623 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1624 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1625 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1626 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001627
1628 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1629
Thales Limac98b7812023-04-14 15:04:23 +01001630 writer.println(prefix + "\tisResponsiveGrid:" + mIsResponsiveGrid);
Thales Lima79456492023-05-23 11:32:22 +01001631 writer.println(prefix + "\tisScalableGrid:" + mIsScalableGrid);
Jon Miranda58561d42021-03-17 10:51:54 -04001632
Thales Lima83bedbf2021-10-05 17:47:39 +01001633 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001634 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1635 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1636 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001637
Alex Chaue818bcb2022-09-02 17:27:11 +01001638 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07001639
Jon Miranda58561d42021-03-17 10:51:54 -04001640 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1641 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1642
1643 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1644 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1645
Thales Lima83bedbf2021-10-05 17:47:39 +01001646 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1647 cellLayoutBorderSpacePx.x));
1648 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1649 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001650 writer.println(
1651 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
1652 writer.println(
1653 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
1654 writer.println(
1655 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01001656 writer.println(
1657 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01001658
Jon Miranda58561d42021-03-17 10:51:54 -04001659 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1660 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1661 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1662
Helen Cheuk599109b2023-02-23 17:15:39 +00001663 writer.println(prefix + "\tinv.numFolderRows: " + inv.numFolderRows);
1664 writer.println(prefix + "\tinv.numFolderColumns: " + inv.numFolderColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001665 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1666 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1667 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1668 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1669 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1670 folderChildDrawablePaddingPx));
Thales Limab35faed2022-09-05 16:30:01 -03001671 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx",
1672 folderCellLayoutBorderSpacePx));
Thales Limaa08a4432022-08-09 09:55:17 +01001673 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
1674 folderContentPaddingLeftRight));
1675 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03001676 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001677
Alex Chaue0227552022-04-06 19:44:43 +01001678 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001679 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
1680 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
1681 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
1682 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01001683
1684 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
1685 writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001686 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
1687 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04001688 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1689 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1690 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1691 allAppsIconDrawablePaddingPx));
1692 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001693 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001694 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
1695 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001696 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau62572c02022-07-25 18:36:37 +00001697 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
Alex Chau27b39b92022-01-14 18:02:18 +00001698 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001699
1700 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03001701 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04001702 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00001703 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Jon Miranda58561d42021-03-17 10:51:54 -04001704 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
1705 hotseatBarSidePaddingStartPx));
1706 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
1707 hotseatBarSidePaddingEndPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001708 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01001709 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
1710 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01001711 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
1712 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001713 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
1714 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
1715 hotseatLayoutPadding.top));
1716 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
1717 hotseatLayoutPadding.bottom));
1718 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
1719 hotseatLayoutPadding.left));
1720 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
1721 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001722 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001723 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001724 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01001725 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001726
1727 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001728 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda9c478b62023-03-23 21:38:49 -07001729 writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight));
1730 writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight));
1731 writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin));
1732 writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001733
Thales Lima83bedbf2021-10-05 17:47:39 +01001734 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1735 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001736 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
1737 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
1738 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00001739 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001740
Jon Mirandaab3c6812021-06-28 15:42:28 -07001741 writer.println(prefix + pxToDpStr("iconScale", iconScale));
1742 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04001743 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00001744 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001745
Thales Lima171ee662022-11-22 15:52:49 +00001746 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04001747 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
1748 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00001749
1750 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00001751 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
1752 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
1753 overviewTaskIconDrawableSizePx));
1754 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
1755 overviewTaskIconDrawableSizeGridPx));
1756 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
1757 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01001758 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
1759 overviewActionsTopMarginPx));
1760 writer.println(prefix + pxToDpStr("overviewActionsHeight",
1761 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00001762 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
1763 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00001764 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
1765 overviewActionsButtonSpacing));
1766 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
1767 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
1768 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01001769
Alex Chau62572c02022-07-25 18:36:37 +00001770 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001771 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00001772 writer.println(
1773 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001774
Pat Manning5f74bfd2022-07-20 12:08:54 +01001775 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
1776 getCellLayoutSpringLoadShrunkTop()));
1777 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
1778 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01001779 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
1780 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001781 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
1782 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01001783 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
1784 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Thales Lima79456492023-05-23 11:32:22 +01001785 if (mIsResponsiveGrid) {
1786 writer.println(prefix + "\tmResponsiveHeightSpec:" + mResponsiveHeightSpec.toString());
1787 writer.println(prefix + "\tmResponsiveWidthSpec:" + mResponsiveWidthSpec.toString());
1788 }
Jon Miranda58561d42021-03-17 10:51:54 -04001789 }
1790
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00001791 /** Returns a reduced representation of this DeviceProfile. */
1792 public String toSmallString() {
1793 return "isTablet:" + isTablet + ", "
1794 + "isMultiDisplay:" + isMultiDisplay + ", "
1795 + "widthPx:" + widthPx + ", "
1796 + "heightPx:" + heightPx + ", "
1797 + "insets:" + mInsets + ", "
1798 + "rotationHint:" + rotationHint;
1799 }
1800
Alex Chaua6907dc2022-03-18 15:24:07 +00001801 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07001802 Configuration config = new Configuration(c.getResources().getConfiguration());
1803 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03001804 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00001805 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07001806 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07001807 }
Sunny Goyalfde55052018-02-01 14:46:13 -08001808
1809 /**
1810 * Callback when a component changes the DeviceProfile associated with it, as a result of
1811 * configuration change
1812 */
1813 public interface OnDeviceProfileChangeListener {
1814
1815 /**
1816 * Called when the device profile is reassigned. Note that for layout and measurements, it
1817 * is sufficient to listen for inset changes. Use this callback when you need to perform
1818 * a one time operation.
1819 */
1820 void onDeviceProfileChanged(DeviceProfile dp);
1821 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001822
Sihua Mae04aa202022-07-18 12:43:56 -07001823 /**
1824 * Handler that deals with ItemInfo of the views for the DeviceProfile
1825 */
1826 @FunctionalInterface
1827 public interface ViewScaleProvider {
1828 /**
1829 * Get the scales from the view
1830 *
1831 * @param itemInfo The tag of the widget view
1832 * @return PointF instance containing the scale information, or null if using the default
1833 * app widget scale of this device profile.
1834 */
1835 @NonNull
1836 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
1837 }
1838
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001839 public static class Builder {
1840 private Context mContext;
1841 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07001842 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001843
Sunny Goyal19ff7282021-04-22 10:12:54 -07001844 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00001845 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001846
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001847 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001848 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00001849 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07001850 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001851
Sunny Goyal65190ae2022-08-02 14:16:26 -07001852 private SparseArray<DotRenderer> mDotRendererCache;
1853
Jon Miranda2b25ded2023-02-02 14:48:45 -08001854 private Consumer<DeviceProfile> mOverrideProvider;
1855
Sunny Goyalfd58da62020-08-11 12:06:49 -07001856 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001857 mContext = context;
1858 mInv = inv;
1859 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001860 }
1861
1862 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1863 mIsMultiWindowMode = isMultiWindowMode;
1864 return this;
1865 }
1866
Alex Chauab800f72022-12-13 17:46:06 +00001867 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
1868 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001869 return this;
1870 }
1871
Sunny Goyal65190ae2022-08-02 14:16:26 -07001872 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
1873 mDotRendererCache = dotRendererCache;
1874 return this;
1875 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07001876
1877 public Builder setWindowBounds(WindowBounds bounds) {
1878 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07001879 return this;
1880 }
1881
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001882 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1883 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1884 return this;
1885 }
1886
Alex Chau6ed408f2022-03-04 12:58:05 +00001887 public Builder setGestureMode(boolean isGestureMode) {
1888 mIsGestureMode = isGestureMode;
1889 return this;
1890 }
1891
Jon Miranda2b25ded2023-02-02 14:48:45 -08001892 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
1893 mOverrideProvider = overrideProvider;
1894 return this;
1895 }
1896
Sihua Mae04aa202022-07-18 12:43:56 -07001897 /**
1898 * Set the viewScaleProvider for the builder
1899 *
1900 * @param viewScaleProvider The viewScaleProvider to be set for the
Thales Limae9273ea2023-01-26 12:33:52 +00001901 * DeviceProfile
Sihua Mae04aa202022-07-18 12:43:56 -07001902 * @return This builder
1903 */
1904 @NonNull
1905 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
1906 mViewScaleProvider = viewScaleProvider;
1907 return this;
1908 }
1909
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001910 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001911 if (mWindowBounds == null) {
1912 throw new IllegalArgumentException("Window bounds not set");
1913 }
1914 if (mTransposeLayoutWithOrientation == null) {
1915 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
1916 }
Alex Chau6ed408f2022-03-04 12:58:05 +00001917 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01001918 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00001919 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001920 if (mDotRendererCache == null) {
1921 mDotRendererCache = new SparseArray<>();
1922 }
Sihua Mae04aa202022-07-18 12:43:56 -07001923 if (mViewScaleProvider == null) {
1924 mViewScaleProvider = DEFAULT_PROVIDER;
1925 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08001926 if (mOverrideProvider == null) {
1927 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
1928 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001929 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00001930 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jon Miranda2b25ded2023-02-02 14:48:45 -08001931 mIsGestureMode, mViewScaleProvider, mOverrideProvider);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001932 }
1933 }
1934
Winson Chungb3800242013-10-24 11:01:54 -07001935}