blob: d6669ea4f0ba088d75c61599e01152f74cdb28ee [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;
Jon Miranda95f44722023-06-06 19:48:19 -070029import static com.android.launcher3.icons.IconNormalizer.ICON_VISIBLE_AREA_FACTOR;
Thales Limab35faed2022-09-05 16:30:01 -030030import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURCE_HANDLE;
Pat Manning5f74bfd2022-07-20 12:08:54 +010031import static com.android.launcher3.testing.shared.ResourceUtils.pxFromDp;
Thales Lima7eee74b2023-03-16 16:00:55 -030032import static com.android.launcher3.testing.shared.ResourceUtils.roundPxValueFromFloat;
Jon Miranda228877d2021-02-09 11:05:00 -050033
Sunny Goyal35c7b192021-04-20 16:51:10 -070034import android.annotation.SuppressLint;
Winson Chungb3800242013-10-24 11:01:54 -070035import android.content.Context;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070036import android.content.res.Configuration;
Winson Chungb3800242013-10-24 11:01:54 -070037import android.content.res.Resources;
Thales Limab35faed2022-09-05 16:30:01 -030038import android.content.res.TypedArray;
Winson Chungb3800242013-10-24 11:01:54 -070039import android.graphics.Point;
Jon Miranda7ae64ff2016-11-21 16:18:46 -080040import android.graphics.PointF;
Winson Chungb3800242013-10-24 11:01:54 -070041import android.graphics.Rect;
Sunny Goyal35c7b192021-04-20 16:51:10 -070042import android.util.DisplayMetrics;
Sunny Goyal65190ae2022-08-02 14:16:26 -070043import android.util.SparseArray;
Sunny Goyal59d086c2018-05-07 17:31:40 -070044import android.view.Surface;
Winson Chungb3800242013-10-24 11:01:54 -070045
Sunny Goyal65190ae2022-08-02 14:16:26 -070046import androidx.annotation.NonNull;
Sihua Mae04aa202022-07-18 12:43:56 -070047import androidx.annotation.Nullable;
Jon Miranda9c478b62023-03-23 21:38:49 -070048import androidx.core.content.res.ResourcesCompat;
Sunny Goyal65190ae2022-08-02 14:16:26 -070049
Sunny Goyalc13403c2016-11-18 23:44:48 -080050import com.android.launcher3.CellLayout.ContainerType;
Jon Miranda228877d2021-02-09 11:05:00 -050051import com.android.launcher3.DevicePaddings.DevicePadding;
Alex Chaud67ddc42022-09-30 18:15:56 +010052import com.android.launcher3.config.FeatureFlags;
Tony Wickham8912b042018-11-29 15:28:53 -080053import com.android.launcher3.icons.DotRenderer;
Hyunyoung Song48cb7bc2018-09-25 17:03:34 -070054import com.android.launcher3.icons.IconNormalizer;
Sihua Mae04aa202022-07-18 12:43:56 -070055import com.android.launcher3.model.data.ItemInfo;
Sunny Goyal57b22792021-05-25 14:35:01 -070056import com.android.launcher3.uioverrides.ApiWrapper;
Sunny Goyalfd58da62020-08-11 12:06:49 -070057import com.android.launcher3.util.DisplayController;
58import com.android.launcher3.util.DisplayController.Info;
Thales Limac98b7812023-04-14 15:04:23 +010059import com.android.launcher3.util.ResourceHelper;
Sunny Goyalb46703d2020-05-27 17:52:03 -070060import com.android.launcher3.util.WindowBounds;
Thales Limac98b7812023-04-14 15:04:23 +010061import com.android.launcher3.workspace.CalculatedWorkspaceSpec;
62import com.android.launcher3.workspace.WorkspaceSpecs;
Winson1f064272016-07-18 17:18:02 -070063
Jon Miranda58561d42021-03-17 10:51:54 -040064import java.io.PrintWriter;
Alex Chaue818bcb2022-09-02 17:27:11 +010065import java.util.Locale;
Jon Miranda2b25ded2023-02-02 14:48:45 -080066import java.util.function.Consumer;
Jon Miranda58561d42021-03-17 10:51:54 -040067
Sunny Goyal35c7b192021-04-20 16:51:10 -070068@SuppressLint("NewApi")
Winson Chungb3800242013-10-24 11:01:54 -070069public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070070
Sunny Goyal8b9919d2021-04-07 14:45:17 -070071 private static final int DEFAULT_DOT_SIZE = 100;
Alex Chau206ede92022-08-01 17:46:12 +010072 private static final float ALL_APPS_TABLET_MAX_ROWS = 5.5f;
Thales Limab35faed2022-09-05 16:30:01 -030073 private static final float MIN_FOLDER_TEXT_SIZE_SP = 16f;
Sunny Goyal6c304b12023-04-10 12:03:04 -070074 private static final float MIN_WIDGET_PADDING_DP = 6f;
Alex Chau206ede92022-08-01 17:46:12 +010075
Sihua Mae04aa202022-07-18 12:43:56 -070076 public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f);
77 public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE;
Jon Miranda2b25ded2023-02-02 14:48:45 -080078 public static final Consumer<DeviceProfile> DEFAULT_DIMENSION_PROVIDER = dp -> {};
Sihua Mae04aa202022-07-18 12:43:56 -070079
Adam Cohen2e6da152015-05-06 11:42:25 -070080 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070081 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070082 private final DisplayMetrics mMetrics;
Winson Chungbe876472014-05-14 14:15:20 -070083
Sunny Goyalc6205602015-05-21 20:46:33 -070084 // Device properties
85 public final boolean isTablet;
Sunny Goyalc6205602015-05-21 20:46:33 -070086 public final boolean isPhone;
87 public final boolean transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +000088 public final boolean isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -070089 public final boolean isTwoPanels;
Thales Limaa1012902022-01-13 17:58:42 +000090 public final boolean isQsbInline;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -070091
Sunny Goyalc6205602015-05-21 20:46:33 -070092 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -070093 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -080094 public final boolean isMultiWindowMode;
Alex Chau6ed408f2022-03-04 12:58:05 +000095 public final boolean isGestureMode;
Sunny Goyald70e75a2018-02-22 10:07:32 -080096
Sunny Goyal0addbf02020-04-28 14:17:35 -070097 public final int windowX;
98 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -070099 public final int widthPx;
100 public final int heightPx;
101 public final int availableWidthPx;
102 public final int availableHeightPx;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800103 public final int rotationHint;
Jon Mirandabba64512019-03-27 10:54:17 -0700104
105 public final float aspectRatio;
106
Thales Lima79456492023-05-23 11:32:22 +0100107 private final boolean mIsScalableGrid;
Thales Lima83bedbf2021-10-05 17:47:39 +0100108 private final int mTypeIndex;
Jon Mirandae126d722021-02-25 10:45:20 -0500109
Thales Limac98b7812023-04-14 15:04:23 +0100110 // Responsive grid
111 private final boolean mIsResponsiveGrid;
112 private WorkspaceSpecs mWorkspaceSpecs;
113 private CalculatedWorkspaceSpec mResponsiveWidthSpec;
114 private CalculatedWorkspaceSpec mResponsiveHeightSpec;
115
Tony Wickhamd6b40372015-09-23 18:37:57 -0700116 /**
117 * The maximum amount of left/right workspace padding as a percentage of the screen width.
118 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
119 * 7% of the screen width can be used as right padding.
120 */
121 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -0700122
Jon Miranda3f9bab22017-07-28 14:50:17 -0700123 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700124 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda80dda302021-07-28 14:14:59 -0700125 private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252;
126 private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700127
Sunny Goyalc6205602015-05-21 20:46:33 -0700128 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +0100129 public final int desiredWorkspaceHorizontalMarginOriginalPx;
130 public int desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100131 public int gridVisualizationPaddingX;
132 public int gridVisualizationPaddingY;
Thales Lima78d00ad2021-09-30 11:29:06 +0100133 public Point cellLayoutBorderSpaceOriginalPx;
134 public Point cellLayoutBorderSpacePx;
Pat Manning08610ca2022-04-05 21:03:16 +0100135 public Rect cellLayoutPaddingPx = new Rect();
136
Sunny Goyalc6205602015-05-21 20:46:33 -0700137 public final int edgeMarginPx;
Alex Chau0c4e11b2022-07-08 18:41:36 +0100138 public final float workspaceContentScale;
Alex Chau906d8822022-05-23 10:42:25 +0100139 public final int workspaceSpringLoadedMinNextPageVisiblePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700140
Jon Miranda58561d42021-03-17 10:51:54 -0400141 private final int extraSpace;
Thales Lima171ee662022-11-22 15:52:49 +0000142 private int maxEmptySpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500143 public int workspaceTopPadding;
144 public int workspaceBottomPadding;
145
Tony Wickham5edf9e22020-03-27 20:06:52 -0700146 // Workspace page indicator
147 public final int workspacePageIndicatorHeight;
148 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700149
Sunny Goyalc6205602015-05-21 20:46:33 -0700150 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400151 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700152 public int iconSizePx;
153 public int iconTextSizePx;
154 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700155 public int iconDrawablePaddingOriginalPx;
Thales Lima79456492023-05-23 11:32:22 +0100156 public boolean iconCenterVertically;
Winson Chungb3800242013-10-24 11:01:54 -0700157
Jon Mirandaab3c6812021-06-28 15:42:28 -0700158 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800159 public int cellWidthPx;
160 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700161 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800162
Thales Lima79456492023-05-23 11:32:22 +0100163 public int cellYPaddingPx = -1;
Jon Mirandae126d722021-02-25 10:45:20 -0500164
Sunny Goyalc6205602015-05-21 20:46:33 -0700165 // Folder
Jon Mirandae126d722021-02-25 10:45:20 -0500166 public float folderLabelTextScale;
167 public int folderLabelTextSizePx;
Thales Limab35faed2022-09-05 16:30:01 -0300168 public int folderFooterHeightPx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700169 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700170 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700171
Jon Mirandae126d722021-02-25 10:45:20 -0500172 // Folder content
Thales Limab35faed2022-09-05 16:30:01 -0300173 public int folderCellLayoutBorderSpacePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500174 public int folderContentPaddingLeftRight;
175 public int folderContentPaddingTop;
176
Jon Mirandabf7d8122016-11-03 15:29:29 -0700177 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700178 public int folderCellWidthPx;
179 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700180
181 // Folder child
182 public int folderChildIconSizePx;
183 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700184 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700185
Sunny Goyalc6205602015-05-21 20:46:33 -0700186 // Hotseat
Thales Lima9938c2f2022-07-25 14:38:16 +0100187 public int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700188 public int hotseatCellHeightPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100189 public final boolean areNavButtonsInline;
Jon Miranda18751b62017-07-31 17:25:27 -0700190 // In portrait: size = height, in landscape: size = width
191 public int hotseatBarSizePx;
Thales Limab8c05952022-05-23 16:58:38 +0100192 public int hotseatBarBottomSpacePx;
Pat Manning26f70f72022-07-07 13:50:39 +0100193 public int hotseatBarEndOffset;
Thales Limab8c05952022-05-23 16:58:38 +0100194 public int hotseatQsbSpace;
Pat Manningde25c0d2022-04-05 19:11:26 +0100195 public int springLoadedHotseatBarTopMarginPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700196 // Start is the side next to the nav bar, end is the side next to the workspace
197 public final int hotseatBarSidePaddingStartPx;
198 public final int hotseatBarSidePaddingEndPx;
Alex Chau206ede92022-08-01 17:46:12 +0100199 public int hotseatQsbWidth; // only used when isQsbInline
Sunny Goyal57b22792021-05-25 14:35:01 -0700200 public final int hotseatQsbHeight;
Thales Limab8c05952022-05-23 16:58:38 +0100201 public final int hotseatQsbVisualHeight;
202 private final int hotseatQsbShadowHeight;
Thales Limadd027342022-01-07 12:54:37 +0000203 public int hotseatBorderSpace;
Thales Limaffc68b02023-01-09 16:20:23 +0000204 private final int mMinHotseatIconSpacePx;
205 private final int mMinHotseatQsbWidthPx;
206 private final int mMaxHotseatIconSpacePx;
Jon Mirandae17a9492023-03-08 16:42:20 -0800207 public final int inlineNavButtonsEndSpacingPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700208
Alex Chau3d2c0622022-09-01 21:28:14 +0100209 // Bottom sheets
210 public int bottomSheetTopPadding;
211 public int bottomSheetOpenDuration;
212 public int bottomSheetCloseDuration;
213 public float bottomSheetWorkspaceScale;
214 public float bottomSheetDepth;
215
Sunny Goyalc6205602015-05-21 20:46:33 -0700216 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000217 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000218 public int allAppsShiftRange;
219 public int allAppsTopPadding;
Alex Chau3d2c0622022-09-01 21:28:14 +0100220 public int allAppsOpenDuration;
221 public int allAppsCloseDuration;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700222 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700223 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700224 public int allAppsIconSizePx;
225 public int allAppsIconDrawablePaddingPx;
sfufa@google.comde013292021-09-21 18:22:44 -0700226 public int allAppsLeftRightPadding;
Alex Chau27b39b92022-01-14 18:02:18 +0000227 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700228 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700229 public float allAppsIconTextSizePx;
230
Zak Cohen334efeb2021-03-19 16:42:07 -0700231 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700232 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000233 public int overviewTaskIconSizePx;
Alex Chauac9df382021-08-02 19:08:41 +0100234 public int overviewTaskIconDrawableSizePx;
235 public int overviewTaskIconDrawableSizeGridPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000236 public int overviewTaskThumbnailTopMarginPx;
Alex Chau19c6eca2022-03-10 20:12:56 +0000237 public final int overviewActionsHeight;
Alex Chaua2fc7642022-04-21 14:20:23 +0100238 public final int overviewActionsTopMarginPx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000239 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100240 public int overviewPageSpacing;
241 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000242 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700243
Jeremy Sim0ac47082022-10-10 13:59:40 -0700244 // Split staging
245 public int splitPlaceholderInset;
246
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800247 // Widgets
Sihua Mae04aa202022-07-18 12:43:56 -0700248 private final ViewScaleProvider mViewScaleProvider;
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800249
Sunny Goyal47328fd2016-05-25 18:56:41 -0700250 // Drop Target
251 public int dropTargetBarSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100252 public int dropTargetBarTopMarginPx;
253 public int dropTargetBarBottomMarginPx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100254 public int dropTargetDragPaddingPx;
255 public int dropTargetTextSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100256 public int dropTargetHorizontalPaddingPx;
257 public int dropTargetVerticalPaddingPx;
258 public int dropTargetGapPx;
Alex Chau5b019302022-05-23 10:42:25 +0100259 public int dropTargetButtonWorkspaceEdgeGapPx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700260
Winson1f064272016-07-18 17:18:02 -0700261 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800262 private final Rect mInsets = new Rect();
263 public final Rect workspacePadding = new Rect();
Sunny Goyal6c304b12023-04-10 12:03:04 -0700264 // Additional padding added to the widget inside its cellSpace. It is applied outside
265 // the widgetView, such that the actual view size is same as the widget size.
266 public final Rect widgetPadding = new Rect();
267
Jon Miranda0bd63d12019-03-06 17:29:29 -0800268 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700269 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700270
Tony Wickhamf34bee82018-12-03 18:11:39 -0800271 // Notification dots
Sunny Goyal65190ae2022-08-02 14:16:26 -0700272 public final DotRenderer mDotRendererWorkSpace;
273 public final DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800274
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100275 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800276 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000277 // Whether Taskbar will inset the bottom of apps by taskbarSize.
278 public boolean isTaskbarPresentInApps;
Jon Miranda9c478b62023-03-23 21:38:49 -0700279 public final int taskbarHeight;
280 public final int stashedTaskbarHeight;
281 public final int taskbarBottomMargin;
282 public final int taskbarIconSize;
Jon Miranda04f05102023-04-04 12:16:31 -0700283 // If true, used to layout taskbar in 3 button navigation mode.
284 public final boolean startAlignTaskbar;
Tony Wickham15883892021-02-12 11:24:40 -0800285
Alex Chaua02eddc2021-04-29 00:36:06 +0100286 // DragController
287 public int flingToDeleteThresholdVelocity;
288
Vinit Nayak17c4b332021-08-05 12:54:58 -0700289 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700290 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal65190ae2022-08-02 14:16:26 -0700291 SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
Alex Chauab800f72022-12-13 17:46:06 +0000292 boolean transposeLayoutWithOrientation, boolean isMultiDisplay, boolean isGestureMode,
Jon Miranda2b25ded2023-02-02 14:48:45 -0800293 @NonNull final ViewScaleProvider viewScaleProvider,
294 @NonNull final Consumer<DeviceProfile> dimensionOverrideProvider) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700295
Adam Cohen2e6da152015-05-06 11:42:25 -0700296 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700297 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800298 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500299 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +0000300 this.isMultiDisplay = isMultiDisplay;
Alex Chau6ed408f2022-03-04 12:58:05 +0000301 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700302 windowX = windowBounds.bounds.left;
303 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800304 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100305 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700306
Thales Limac98b7812023-04-14 15:04:23 +0100307 // TODO(b/241386436): shouldn't change any launcher behaviour
308 mIsResponsiveGrid = inv.workspaceSpecsId != INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100309
Thales Lima79456492023-05-23 11:32:22 +0100310 mIsScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000311 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700312 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000313 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700314 isPhone = !isTablet;
Alex Chauab800f72022-12-13 17:46:06 +0000315 isTwoPanels = isTablet && isMultiDisplay;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800316 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700317
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000318 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000319 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700320 ? Configuration.ORIENTATION_LANDSCAPE
321 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000322 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700323 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000324 mMetrics = res.getDisplayMetrics();
325
326 // Determine sizes.
327 widthPx = windowBounds.bounds.width();
328 heightPx = windowBounds.bounds.height();
329 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100330 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000331
332 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Thales Lima83bedbf2021-10-05 17:47:39 +0100333 if (isTwoPanels) {
334 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000335 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100336 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000337 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100338 }
339 } else {
340 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000341 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100342 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000343 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100344 }
345 }
346
Jon Miranda9c478b62023-03-23 21:38:49 -0700347 if (DisplayController.isTransientTaskbar(context)) {
348 float invTransientIconSizeDp = inv.transientTaskbarIconSize[mTypeIndex];
349 taskbarIconSize = pxFromDp(invTransientIconSizeDp, mMetrics);
Jon Miranda95f44722023-06-06 19:48:19 -0700350 taskbarHeight = Math.round((taskbarIconSize * ICON_VISIBLE_AREA_FACTOR)
351 + (2 * res.getDimensionPixelSize(R.dimen.transient_taskbar_padding)));
Jon Miranda9c478b62023-03-23 21:38:49 -0700352 stashedTaskbarHeight =
353 res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_height);
354 taskbarBottomMargin =
355 res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin);
Jon Miranda04f05102023-04-04 12:16:31 -0700356 startAlignTaskbar = false;
Jon Miranda9c478b62023-03-23 21:38:49 -0700357 } else {
358 taskbarIconSize = pxFromDp(ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size),
359 mMetrics);
360 taskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_size);
361 stashedTaskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
362 taskbarBottomMargin = 0;
Jon Miranda04f05102023-04-04 12:16:31 -0700363 startAlignTaskbar = inv.startAlignTaskbar[mTypeIndex];
Tony Wickham15883892021-02-12 11:24:40 -0800364 }
Tony Wickham15883892021-02-12 11:24:40 -0800365
Winson Chungb3800242013-10-24 11:01:54 -0700366 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100367 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700368
Alex Chau51da2192022-05-20 13:32:10 +0100369 gridVisualizationPaddingX = res.getDimensionPixelSize(
370 R.dimen.grid_visualization_horizontal_cell_spacing);
371 gridVisualizationPaddingY = res.getDimensionPixelSize(
372 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500373
Alex Chaue0227552022-04-06 19:44:43 +0100374 bottomSheetTopPadding = mInsets.top // statusbar height
Andras Kloczl142b0542022-03-09 21:26:02 +0000375 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
376 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
Alex Chau3d2c0622022-09-01 21:28:14 +0100377 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
378 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
379 if (isTablet) {
380 bottomSheetWorkspaceScale = workspaceContentScale;
Alex Chauab800f72022-12-13 17:46:06 +0000381 if (isMultiDisplay && !ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH.get()) {
382 // TODO(b/259893832): Revert to use maxWallpaperScale to calculate bottomSheetDepth
383 // when screen recorder bug is fixed.
384 bottomSheetDepth = 1f;
385 } else {
386 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
387 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
388 // When depth is 1, wallpaper zoom is set to 1.
389 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
390 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
391 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
392 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
393 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100394 } else {
395 bottomSheetWorkspaceScale = 1f;
396 bottomSheetDepth = 0f;
397 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000398
Jon Mirandae126d722021-02-25 10:45:20 -0500399 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
Thales Limab35faed2022-09-05 16:30:01 -0300400
Thales Lima79456492023-05-23 11:32:22 +0100401 if (mIsScalableGrid && inv.folderStyle != INVALID_RESOURCE_HANDLE) {
Thales Limab35faed2022-09-05 16:30:01 -0300402 TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
Thales Limad852d652023-01-17 14:01:13 +0000403 R.styleable.FolderStyle);
Thales Limab35faed2022-09-05 16:30:01 -0300404 // These are re-set in #updateFolderCellSize if the grid is not scalable
405 folderCellHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000406 R.styleable.FolderStyle_folderCellHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300407 folderCellWidthPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000408 R.styleable.FolderStyle_folderCellWidth, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300409
410 folderContentPaddingTop = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000411 R.styleable.FolderStyle_folderTopPadding, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300412 folderCellLayoutBorderSpacePx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000413 R.styleable.FolderStyle_folderBorderSpace, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300414 folderFooterHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000415 R.styleable.FolderStyle_folderFooterHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300416 folderStyle.recycle();
417 } else {
418 folderCellLayoutBorderSpacePx = 0;
Thales Lima7eee74b2023-03-16 16:00:55 -0300419 folderFooterHeightPx = res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Thales Limab35faed2022-09-05 16:30:01 -0300420 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
421 }
Jon Mirandae126d722021-02-25 10:45:20 -0500422
Thales Lima85c942f2021-12-31 13:04:20 +0000423 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000424 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
425 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Thales Limae9273ea2023-01-26 12:33:52 +0000426 setupAllAppsStyle(context);
Jon Mirandae126d722021-02-25 10:45:20 -0500427
Tony Wickham5edf9e22020-03-27 20:06:52 -0700428 workspacePageIndicatorHeight = res.getDimensionPixelSize(
429 R.dimen.workspace_page_indicator_height);
430 mWorkspacePageIndicatorOverlapWorkspace =
431 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700432
Thales Limad852d652023-01-17 14:01:13 +0000433 TypedArray cellStyle;
434 if (inv.cellStyle != INVALID_RESOURCE_HANDLE) {
435 cellStyle = context.obtainStyledAttributes(inv.cellStyle,
436 R.styleable.CellStyle);
437 } else {
438 cellStyle = context.obtainStyledAttributes(R.style.CellStyleDefault,
439 R.styleable.CellStyle);
440 }
441 iconDrawablePaddingOriginalPx = cellStyle.getDimensionPixelSize(
442 R.styleable.CellStyle_iconDrawablePadding, 0);
443 cellStyle.recycle();
Alex Chaua02eddc2021-04-29 00:36:06 +0100444
Sunny Goyal47328fd2016-05-25 18:56:41 -0700445 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100446 dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
447 dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100448 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
449 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100450 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
451 R.dimen.drop_target_button_drawable_horizontal_padding);
452 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
453 R.dimen.drop_target_button_drawable_vertical_padding);
454 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100455 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
456 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100457
Alex Chau906d8822022-05-23 10:42:25 +0100458 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
459 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700460
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700461 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700462
Thales Limaa1012902022-01-13 17:58:42 +0000463 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100464 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
465 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
466
Thales Lima12d0eff2022-03-25 17:06:11 +0000467 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
468 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
469 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
470 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
471 && hotseatQsbHeight > 0;
Thales Lima79456492023-05-23 11:32:22 +0100472 isQsbInline = mIsScalableGrid && inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000473
Thales Lima425f6822022-05-10 13:44:58 -0300474 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100475 numShownHotseatIcons =
476 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000477
Sunny Goyal19ff7282021-04-22 10:12:54 -0700478 numShownAllAppsColumns =
479 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100480
481 int hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
482 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
483 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
484 // Have a little space between the inset and the QSB
485 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
486 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
487
488 // Only change the spaces if there is space
489 if (availableSpace > 0) {
490 // Make sure there is enough space between hotseat/QSB and QSB/navBar
491 if (availableSpace < minQsbMargin * 2) {
492 minQsbMargin = availableSpace / 2;
493 hotseatQsbSpace = minQsbMargin;
494 } else {
495 hotseatQsbSpace -= minQsbMargin;
496 }
497 }
498 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
499
Thales Limaa1012902022-01-13 17:58:42 +0000500 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100501 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
Thales Limaa1012902022-01-13 17:58:42 +0000502 }
Thales Lima425f6822022-05-10 13:44:58 -0300503
Pat Manningde25c0d2022-04-05 19:11:26 +0100504 springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
505 R.dimen.spring_loaded_hotseat_top_margin);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700506 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800507 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700508 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700509 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Thales Limab8c05952022-05-23 16:58:38 +0100510 updateHotseatSizes(pxFromDp(inv.iconSize[INDEX_DEFAULT], mMetrics));
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700511 if (areNavButtonsInline && !isPhone) {
Jon Mirandae17a9492023-03-08 16:42:20 -0800512 inlineNavButtonsEndSpacingPx =
Thales Limaffc68b02023-01-09 16:20:23 +0000513 res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing);
Pat Manning26f70f72022-07-07 13:50:39 +0100514 /*
515 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700516 * Spacing between nav buttons +
Thales Lima6a590062022-11-22 15:52:49 +0000517 * Space at the end for contextual buttons
Pat Manning26f70f72022-07-07 13:50:39 +0100518 */
519 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700520 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
Jon Mirandae17a9492023-03-08 16:42:20 -0800521 + inlineNavButtonsEndSpacingPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100522 } else {
Jon Mirandae17a9492023-03-08 16:42:20 -0800523 inlineNavButtonsEndSpacingPx = 0;
Pat Manning26f70f72022-07-07 13:50:39 +0100524 hotseatBarEndOffset = 0;
525 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700526
Thales Lima79456492023-05-23 11:32:22 +0100527 // Needs to be calculated after hotseatBarSizePx is correct,
528 // for the available height to be correct
529 if (mIsResponsiveGrid) {
530 mWorkspaceSpecs = new WorkspaceSpecs(new ResourceHelper(context, inv.workspaceSpecsId));
531 mResponsiveWidthSpec = mWorkspaceSpecs.getCalculatedWidthSpec(inv.numColumns,
532 availableWidthPx);
533 mResponsiveHeightSpec = mWorkspaceSpecs.getCalculatedHeightSpec(inv.numRows,
534 // don't use availableHeightPx because it subtracts bottom padding,
535 // but the hotseat go behind it
536 heightPx - mInsets.top - hotseatBarSizePx);
537 }
538
539 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
540 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
541
Alex Chau635b3ab2022-01-26 16:49:10 +0000542 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chau5fd9d492021-07-22 17:27:11 +0100543 overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100544 overviewTaskIconDrawableSizePx =
545 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
546 overviewTaskIconDrawableSizeGridPx =
547 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700548 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx;
Andy Wickham64896f32023-05-30 21:46:24 -0700549 // Don't add margin with floating search bar to minimize risk of overlapping.
550 overviewActionsTopMarginPx = FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get() ? 0
551 : res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000552 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
553 overviewActionsButtonSpacing = res.getDimensionPixelSize(
554 R.dimen.overview_actions_button_spacing);
Alex Chau19c6eca2022-03-10 20:12:56 +0000555 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700556 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000557 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700558
Jeremy Sim0ac47082022-10-10 13:59:40 -0700559 splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset);
560
Jon Miranda2ed276e2017-06-29 11:36:34 -0700561 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400562 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700563
Thales Lima79456492023-05-23 11:32:22 +0100564 calculateAndSetWorkspaceVerticalPadding(context, inv, extraSpace);
Pat Manning08610ca2022-04-05 21:03:16 +0100565
566 int cellLayoutPadding =
567 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
568 R.dimen.cell_layout_padding);
569 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
570 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800571 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800572
Thales Lima7eee74b2023-03-16 16:00:55 -0300573 // Folder scaling requires correct workspace paddings
574 updateAvailableFolderCellDimensions(res);
575
Thales Limaffc68b02023-01-09 16:20:23 +0000576 mMinHotseatIconSpacePx = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
577 mMinHotseatQsbWidthPx = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
578 mMaxHotseatIconSpacePx = areNavButtonsInline
Thales Lima6a590062022-11-22 15:52:49 +0000579 ? res.getDimensionPixelSize(R.dimen.max_hotseat_icon_space) : Integer.MAX_VALUE;
Thales Lima425f6822022-05-10 13:44:58 -0300580 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima6a590062022-11-22 15:52:49 +0000581 recalculateHotseatWidthAndBorderSpace();
Alex Chau206ede92022-08-01 17:46:12 +0100582
583 // AllApps height calculation depends on updated cellSize
584 if (isTablet) {
585 int collapseHandleHeight =
586 res.getDimensionPixelOffset(R.dimen.bottom_sheet_handle_area_height);
587 int contentHeight = heightPx - collapseHandleHeight - hotseatQsbHeight;
588 int targetContentHeight = (int) (allAppsCellHeightPx * ALL_APPS_TABLET_MAX_ROWS);
589 allAppsTopPadding = Math.max(mInsets.top, contentHeight - targetContentHeight);
590 allAppsShiftRange = heightPx - allAppsTopPadding;
591 } else {
592 allAppsTopPadding = 0;
593 allAppsShiftRange =
594 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
595 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100596 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
597 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300598
Alex Chaua02eddc2021-04-29 00:36:06 +0100599 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
600 R.dimen.drag_flingToDeleteMinVelocity);
601
Sihua Mae04aa202022-07-18 12:43:56 -0700602 mViewScaleProvider = viewScaleProvider;
603
Jon Miranda2b25ded2023-02-02 14:48:45 -0800604 dimensionOverrideProvider.accept(this);
605
Tony Wickham1237df02017-02-24 08:59:36 -0800606 // This is done last, after iconSizePx is calculated above.
Sunny Goyal799e1202023-02-09 10:54:28 -0800607 mDotRendererWorkSpace = createDotRenderer(context, iconSizePx, dotRendererCache);
608 mDotRendererAllApps = createDotRenderer(context, allAppsIconSizePx, dotRendererCache);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700609 }
610
611 private static DotRenderer createDotRenderer(
Sunny Goyal799e1202023-02-09 10:54:28 -0800612 @NonNull Context context, int size, @NonNull SparseArray<DotRenderer> cache) {
Sunny Goyal65190ae2022-08-02 14:16:26 -0700613 DotRenderer renderer = cache.get(size);
614 if (renderer == null) {
Sunny Goyal799e1202023-02-09 10:54:28 -0800615 renderer = new DotRenderer(size, getShapePath(context, DEFAULT_DOT_SIZE),
616 DEFAULT_DOT_SIZE);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700617 cache.put(size, renderer);
618 }
619 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700620 }
621
Thales Lima425f6822022-05-10 13:44:58 -0300622 /**
623 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
624 * width of the hotseat.
625 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100626 private int calculateQsbWidth(int hotseatBorderSpace) {
Thales Lima425f6822022-05-10 13:44:58 -0300627 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100628 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300629 return getIconToIconWidthForColumns(columns)
630 - iconSizePx * numShownHotseatIcons
631 - hotseatBorderSpace * numShownHotseatIcons;
632 } else {
633 int columns = inv.hotseatColumnSpan[mTypeIndex];
634 return getIconToIconWidthForColumns(columns);
635 }
636 }
Thales Lima2903a622022-03-17 13:52:19 +0000637
Thales Lima425f6822022-05-10 13:44:58 -0300638 private int getIconToIconWidthForColumns(int columns) {
639 return columns * getCellSize().x
640 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400641 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000642 }
643
Thales Limad90faab2021-09-21 17:18:47 +0100644 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
Thales Lima79456492023-05-23 11:32:22 +0100645 if (mIsResponsiveGrid) {
646 return mResponsiveWidthSpec.getStartPaddingPx();
647 }
648
Thales Limad90faab2021-09-21 17:18:47 +0100649 if (isVerticalBarLayout()) {
650 return 0;
651 }
652
Thales Lima79456492023-05-23 11:32:22 +0100653 return mIsScalableGrid
Thales Lima83bedbf2021-10-05 17:47:39 +0100654 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
655 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100656 }
657
Thales Lima79456492023-05-23 11:32:22 +0100658 private void calculateAndSetWorkspaceVerticalPadding(Context context,
659 InvariantDeviceProfile inv,
660 int extraSpace) {
661 if (mIsResponsiveGrid) {
662 workspaceTopPadding = mResponsiveHeightSpec.getStartPaddingPx();
663 workspaceBottomPadding = mResponsiveHeightSpec.getEndPaddingPx();
664 } else if (mIsScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
665 // Paddings were created assuming no scaling, so we first unscale the extra space.
666 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
667 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
668 DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
669 maxEmptySpace = padding.getMaxEmptySpacePx();
670
671 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
672 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
673
674 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
675 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
676 }
677 }
678
Thales Limab8c05952022-05-23 16:58:38 +0100679 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
680 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700681 // Ensure there is enough space for folder icons, which have a slightly larger radius.
682 hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR);
Thales Limab8c05952022-05-23 16:58:38 +0100683
Jon Miranda0d284852021-06-22 14:50:55 -0700684 if (isVerticalBarLayout()) {
685 hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
686 + hotseatBarSidePaddingEndPx;
Thales Limab8c05952022-05-23 16:58:38 +0100687 } else if (isQsbInline) {
688 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
689 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700690 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100691 hotseatBarSizePx = hotseatIconSizePx
692 + hotseatQsbSpace
693 + hotseatQsbVisualHeight
694 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700695 }
696 }
697
Thales Lima6a590062022-11-22 15:52:49 +0000698 /**
699 * Calculates the width of the hotseat, changing spaces between the icons and removing icons if
700 * necessary.
701 */
702 public void recalculateHotseatWidthAndBorderSpace() {
Thales Lima79456492023-05-23 11:32:22 +0100703 if (!mIsScalableGrid) return;
Thales Lima6a590062022-11-22 15:52:49 +0000704
705 int columns = inv.hotseatColumnSpan[mTypeIndex];
706 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
707 hotseatBorderSpace = calculateHotseatBorderSpace(hotseatWidthPx, /* numExtraBorder= */ 0);
Thales Lima9938c2f2022-07-25 14:38:16 +0100708 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
Thales Lima6a590062022-11-22 15:52:49 +0000709 // Spaces should be correct when the nav buttons are not inline
Thales Lima9938c2f2022-07-25 14:38:16 +0100710 if (!areNavButtonsInline) {
711 return;
712 }
713
Thales Lima6a590062022-11-22 15:52:49 +0000714 // The side space with inline buttons should be what is defined in InvariantDeviceProfile
Jon Mirandae17a9492023-03-08 16:42:20 -0800715 int sideSpacePx = inlineNavButtonsEndSpacingPx;
Thales Limaffc68b02023-01-09 16:20:23 +0000716 int maxHotseatWidthPx = availableWidthPx - sideSpacePx - hotseatBarEndOffset;
717 int maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
718 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000719 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100720
Thales Limaffc68b02023-01-09 16:20:23 +0000721 if (hotseatBorderSpace >= mMinHotseatIconSpacePx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100722 return;
723 }
724
725 // Border space can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000726 hotseatBorderSpace = mMinHotseatIconSpacePx;
Thales Lima6a590062022-11-22 15:52:49 +0000727 int requiredWidth = getHotseatRequiredWidth();
Thales Lima9938c2f2022-07-25 14:38:16 +0100728
729 // If there is an inline qsb, change its size
730 if (isQsbInline) {
Thales Limaffc68b02023-01-09 16:20:23 +0000731 hotseatQsbWidth -= requiredWidth - maxHotseatWidthPx;
732 if (hotseatQsbWidth >= mMinHotseatQsbWidthPx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100733 return;
734 }
735
736 // QSB can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000737 hotseatQsbWidth = mMinHotseatQsbWidthPx;
Thales Lima9938c2f2022-07-25 14:38:16 +0100738 }
739
Thales Limaffc68b02023-01-09 16:20:23 +0000740 maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
Thales Lima6a590062022-11-22 15:52:49 +0000741
Thales Lima9938c2f2022-07-25 14:38:16 +0100742 // If it still doesn't fit, start removing icons
743 do {
744 numShownHotseatIcons--;
Thales Limaffc68b02023-01-09 16:20:23 +0000745 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000746 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Limaffc68b02023-01-09 16:20:23 +0000747 } while (hotseatBorderSpace < mMinHotseatIconSpacePx && numShownHotseatIcons > 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100748
Thales Lima9938c2f2022-07-25 14:38:16 +0100749 }
750
Thales Lima78d00ad2021-09-30 11:29:06 +0100751 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100752 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100753 }
754
755 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima79456492023-05-23 11:32:22 +0100756 int horizontalSpacePx = 0;
757 int verticalSpacePx = 0;
Thales Lima78d00ad2021-09-30 11:29:06 +0100758
Thales Lima79456492023-05-23 11:32:22 +0100759 if (mIsResponsiveGrid) {
760 horizontalSpacePx = mResponsiveWidthSpec.getGutterPx();
761 verticalSpacePx = mResponsiveHeightSpec.getGutterPx();
762 } else if (mIsScalableGrid) {
763 horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
764 verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
765 }
Thales Lima78d00ad2021-09-30 11:29:06 +0100766
767 return new Point(horizontalSpacePx, verticalSpacePx);
768 }
769
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700770 public Info getDisplayInfo() {
771 return mInfo;
772 }
773
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700774 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800775 WindowBounds bounds = new WindowBounds(
776 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700777 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100778 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700779
780 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
781 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
782 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
783
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700784 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700785 .setWindowBounds(bounds)
Alex Chauab800f72022-12-13 17:46:06 +0000786 .setIsMultiDisplay(isMultiDisplay)
Alex Chau6ed408f2022-03-04 12:58:05 +0000787 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700788 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000789 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800790 }
791
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700792 public DeviceProfile copy(Context context) {
793 return toBuilder(context).build();
794 }
795
796 /**
797 * TODO: Move this to the builder as part of setMultiWindowMode
798 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700799 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700800 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700801 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700802 .setMultiWindowMode(true)
803 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800804
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800805 // We use these scales to measure and layout the widgets using their full invariant profile
806 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
807 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
808 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700809 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
810 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
811 profile = profile.toBuilder(context)
812 .setViewScaleProvider(i -> p)
813 .build();
814 }
815
816 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800817
Jon Miranda93e1f042016-11-11 14:13:04 -0800818 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700819 }
820
Adam Cohen63f1ec02014-08-12 09:23:13 -0700821 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400822 * Checks if there is enough space for labels on the workspace.
823 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700824 * It is important to call this method after the All Apps variables have been set.
825 */
Jon Miranda941375e2021-03-31 13:10:45 -0400826 private void hideWorkspaceLabelsIfNotEnoughSpace() {
827 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
828 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
829 - iconTextHeight;
830
831 // We want enough space so that the text is closer to its corresponding icon.
832 if (workspaceCellPaddingY < iconTextHeight) {
833 iconTextSizePx = 0;
834 iconDrawablePaddingPx = 0;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700835 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda941375e2021-03-31 13:10:45 -0400836 autoResizeAllAppsCells();
837 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700838 }
Jon Miranda1091e532017-07-21 13:31:50 -0700839
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700840 /**
841 * Re-computes the all-apps cell size to be independent of workspace
842 */
843 public void autoResizeAllAppsCells() {
Jon Miranda941375e2021-03-31 13:10:45 -0400844 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
845 int topBottomPadding = textHeight;
Jon Miranda1091e532017-07-21 13:31:50 -0700846 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
Jon Miranda941375e2021-03-31 13:10:45 -0400847 + textHeight + (topBottomPadding * 2);
Jon Miranda1091e532017-07-21 13:31:50 -0700848 }
849
Thales Limab7ef5692022-03-10 10:32:36 +0000850 private void updateAllAppsContainerWidth(Resources res) {
Pat Manning08610ca2022-04-05 21:03:16 +0100851 int cellLayoutHorizontalPadding =
852 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
Alex Chau27b39b92022-01-14 18:02:18 +0000853 if (isTablet) {
sfufa@google.comde013292021-09-21 18:22:44 -0700854 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
Thales Limab7ef5692022-03-10 10:32:36 +0000855 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Alex Chau27b39b92022-01-14 18:02:18 +0000856 + allAppsLeftRightPadding * 2;
857 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
sfufa@google.comde013292021-09-21 18:22:44 -0700858 } else {
859 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100860 desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding;
sfufa@google.comde013292021-09-21 18:22:44 -0700861 }
862 }
863
Thales Limae9273ea2023-01-26 12:33:52 +0000864 private void setupAllAppsStyle(Context context) {
865 TypedArray allAppsStyle;
866 if (inv.allAppsStyle != INVALID_RESOURCE_HANDLE) {
867 allAppsStyle = context.obtainStyledAttributes(inv.allAppsStyle,
868 R.styleable.AllAppsStyle);
869 } else {
870 allAppsStyle = context.obtainStyledAttributes(R.style.AllAppsStyleDefault,
871 R.styleable.AllAppsStyle);
872 }
873 allAppsLeftRightPadding = allAppsStyle.getDimensionPixelSize(
874 R.styleable.AllAppsStyle_horizontalPadding, 0);
875 allAppsStyle.recycle();
876 }
877
Jon Miranda228877d2021-02-09 11:05:00 -0500878 /**
879 * Returns the amount of extra (or unused) vertical space.
880 */
881 private int updateAvailableDimensions(Resources res) {
Alex Chaua68164d2022-12-15 16:16:03 +0000882 float invIconSizeDp = inv.iconSize[mTypeIndex];
883 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
884 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
885 iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
Thales Lima79456492023-05-23 11:32:22 +0100886 iconCenterVertically = mIsScalableGrid || mIsResponsiveGrid;
Alex Chaua68164d2022-12-15 16:16:03 +0000887
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700888 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800889
Pat Manning08610ca2022-04-05 21:03:16 +0100890 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -0500891
892 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +0100893 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +0000894 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -0500895 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500896 float scaleY = maxHeight / usedHeight;
897 boolean shouldScale = scaleY < 1f;
898
899 float scaleX = 1f;
Thales Lima79456492023-05-23 11:32:22 +0100900 if (mIsScalableGrid) {
Jon Mirandae126d722021-02-25 10:45:20 -0500901 // We scale to fit the cellWidth and cellHeight in the available space.
902 // The benefit of scalable grids is that we can get consistent aspect ratios between
903 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +0100904 float usedWidth =
905 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500906 // We do not subtract padding here, as we also scale the workspace padding if needed.
907 scaleX = availableWidthPx / usedWidth;
908 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700909 }
Jon Mirandae126d722021-02-25 10:45:20 -0500910
911 if (shouldScale) {
912 float scale = Math.min(scaleX, scaleY);
913 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +0100914 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -0500915 }
916
Jon Miranda228877d2021-02-09 11:05:00 -0500917 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700918 }
919
Pat Manninga2e14992022-04-22 11:29:17 +0100920 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +0100921 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
922 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
923 }
924
Pat Manninga2e14992022-04-22 11:29:17 +0100925 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +0000926 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +0100927 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
928 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -0500929 }
930
Jon Miranda6f7e9702019-09-16 14:44:14 -0700931 /**
932 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
933 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
934 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
935 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800936 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -0700937 // Icon scale should never exceed 1, otherwise pixellation may occur.
938 iconScale = Math.min(1f, scale);
939 cellScaleToFit = scale;
940
Jon Miranda18751b62017-07-31 17:25:27 -0700941 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800942 final boolean isVerticalLayout = isVerticalBarLayout();
Jon Mirandaab3c6812021-06-28 15:42:28 -0700943 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);
Thales Lima080d8902022-03-28 15:30:29 +0100944 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Thales Lima79456492023-05-23 11:32:22 +0100945 int cellTextAndPaddingHeight =
946 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Jon Mirandae126d722021-02-25 10:45:20 -0500947
Thales Lima79456492023-05-23 11:32:22 +0100948 if (mIsResponsiveGrid) {
949 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
950
951 cellWidthPx = mResponsiveWidthSpec.getCellSizePx();
952 cellHeightPx = mResponsiveHeightSpec.getCellSizePx();
953 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
954
955 // TODO(b/283929701): decrease icon size if content doesn't fit on cell
956 } else if (mIsScalableGrid) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100957 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
958 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +0000959
960 if (cellWidthPx < iconSizePx) {
961 // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger.
962 int numColumns = getPanelCount() * inv.numColumns;
963 int numBorders = numColumns - 1;
964 int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns;
965 if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) {
966 cellWidthPx = iconSizePx;
967 cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders;
968 } else {
969 // If it still doesn't fit, set borderSpace to 0 and distribute the space for
970 // cellWidth, and reduce iconSize.
971 cellWidthPx = (cellWidthPx * numColumns
972 + cellLayoutBorderSpacePx.x * numBorders) / numColumns;
973 iconSizePx = Math.min(iconSizePx, cellWidthPx);
974 cellLayoutBorderSpacePx.x = 0;
975 }
976 }
977
Alex Chaube753132022-12-09 16:46:54 +0000978 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
979 if (cellHeightPx < cellContentHeight) {
980 // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight
981 // bigger.
982 int numBorders = inv.numRows - 1;
983 int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows;
984 if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) {
985 cellHeightPx = cellContentHeight;
986 cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders;
987 } else {
Alex Chau06f36e82023-01-06 10:50:54 +0000988 // If it still doesn't fit, set borderSpace to 0 to recover space.
Alex Chaube753132022-12-09 16:46:54 +0000989 cellHeightPx = (cellHeightPx * inv.numRows
990 + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows;
Alex Chaube753132022-12-09 16:46:54 +0000991 cellLayoutBorderSpacePx.y = 0;
Alex Chau06f36e82023-01-06 10:50:54 +0000992 // Reduce iconDrawablePaddingPx to make cellContentHeight smaller.
993 int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx;
994 if (cellContentWithoutPadding <= cellHeightPx) {
995 iconDrawablePaddingPx = cellContentHeight - cellHeightPx;
996 } else {
997 // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space,
998 // then proportional reduce iconSizePx and iconTextSizePx to fit.
999 iconDrawablePaddingPx = 0;
1000 float ratio = cellHeightPx / (float) cellContentWithoutPadding;
1001 iconSizePx = (int) (iconSizePx * ratio);
1002 iconTextSizePx = (int) (iconTextSizePx * ratio);
1003 }
1004 cellTextAndPaddingHeight =
1005 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +00001006 }
1007 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
1008 }
Jon Mirandae126d722021-02-25 10:45:20 -05001009 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +01001010 desiredWorkspaceHorizontalMarginPx =
1011 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -05001012 } else {
Jon Mirandae126d722021-02-25 10:45:20 -05001013 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001014 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR)
1015 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -05001016 + Utilities.calculateTextHeight(iconTextSizePx);
1017 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
1018 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
1019 && !isMultiWindowMode) {
1020 // Ensures that the label is closer to its corresponding icon. This is not an issue
1021 // with vertical bar layout or multi-window mode since the issue is handled
1022 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
1023 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
1024 iconDrawablePaddingPx = cellPaddingY;
1025 }
Jon Miranda846455e2017-10-02 14:58:52 -07001026 }
Jon Miranda18751b62017-07-31 17:25:27 -07001027
Sunny Goyalae190ff2020-04-14 00:19:01 +00001028 // All apps
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001029 updateAllAppsIconSize(scale, res);
Winson Chungb3800242013-10-24 11:01:54 -07001030
Thales Limab8c05952022-05-23 16:58:38 +01001031 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -07001032
Sunny Goyalbaec6ff2016-09-14 11:26:21 -07001033 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -07001034 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
1035 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Sunny Goyal6c304b12023-04-10 12:03:04 -07001036
1037 // Update widget padding:
1038 float minSpacing = pxFromDp(MIN_WIDGET_PADDING_DP, mMetrics);
1039 if (cellLayoutBorderSpacePx.x < minSpacing
1040 || cellLayoutBorderSpacePx.y < minSpacing) {
1041 widgetPadding.left = widgetPadding.right =
1042 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.x));
1043 widgetPadding.top = widgetPadding.bottom =
1044 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.y));
1045 } else {
1046 widgetPadding.setEmpty();
1047 }
Winson Chung0f785722015-04-08 10:27:49 -07001048 }
1049
Thales Lima425f6822022-05-10 13:44:58 -03001050 /**
Thales Lima6a590062022-11-22 15:52:49 +00001051 * This method calculates the space between the icons to achieve a certain width.
Thales Lima425f6822022-05-10 13:44:58 -03001052 */
Thales Lima6a590062022-11-22 15:52:49 +00001053 private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) {
Thales Lima9938c2f2022-07-25 14:38:16 +01001054 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
Thales Limaffc68b02023-01-09 16:20:23 +00001055 int hotseatBorderSpacePx =
Thales Lima6a590062022-11-22 15:52:49 +00001056 (int) (hotseatWidthPx - hotseatIconsTotalPx)
1057 / (numShownHotseatIcons - 1 + numExtraBorder);
Thales Limaffc68b02023-01-09 16:20:23 +00001058 return Math.min(hotseatBorderSpacePx, mMaxHotseatIconSpacePx);
Thales Lima425f6822022-05-10 13:44:58 -03001059 }
1060
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001061
1062 /**
1063 * Updates the iconSize for allApps* variants.
1064 */
Brian Isganitisa9a78112022-05-23 18:11:47 -07001065 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +01001066 allAppsBorderSpacePx = new Point(
1067 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
1068 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001069 // AllApps cells don't have real space between cells,
1070 // so we add the border space to the cell height
Alex Chaube753132022-12-09 16:46:54 +00001071 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics)
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001072 + allAppsBorderSpacePx.y;
1073 // but width is just the cell,
1074 // the border is added in #updateAllAppsContainerWidth
Thales Lima79456492023-05-23 11:32:22 +01001075 if (mIsScalableGrid) {
Alex Chaube753132022-12-09 16:46:54 +00001076 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1077 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001078 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001079 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001080
1081 if (allAppsCellWidthPx < allAppsIconSizePx) {
1082 // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to
1083 // make allAppsCellWidth bigger.
1084 int numBorders = inv.numAllAppsColumns - 1;
1085 int extraWidthRequired =
1086 (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns;
1087 if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) {
1088 allAppsCellWidthPx = allAppsIconSizePx;
1089 allAppsBorderSpacePx.x -= extraWidthRequired / numBorders;
1090 } else {
1091 // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space
1092 // for allAppsCellWidth, and reduce allAppsIconSize.
1093 allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns
1094 + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns;
1095 allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx);
1096 allAppsBorderSpacePx.x = 0;
1097 }
1098 }
1099
1100 int cellContentHeight = allAppsIconSizePx
1101 + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y;
1102 if (allAppsCellHeightPx < cellContentHeight) {
1103 // Increase allAppsCellHeight to fit its content.
1104 allAppsCellHeightPx = cellContentHeight;
1105 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001106 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001107 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
1108 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001109 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1110 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001111 allAppsIconDrawablePaddingPx =
1112 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001113 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001114 }
1115
Thales Limab7ef5692022-03-10 10:32:36 +00001116 updateAllAppsContainerWidth(res);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001117 if (isVerticalBarLayout()) {
1118 hideWorkspaceLabelsIfNotEnoughSpace();
1119 }
1120 }
1121
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001122 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001123 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001124
Thales Lima7eee74b2023-03-16 16:00:55 -03001125 // For usability we can't have the folder use the whole width of the screen
Sunny Goyal07b69292018-01-08 14:19:34 -08001126 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -08001127
Thales Lima7eee74b2023-03-16 16:00:55 -03001128 // Check if the folder fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -05001129 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Thales Lima7eee74b2023-03-16 16:00:55 -03001130 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx)
1131 + folderFooterHeightPx
1132 + folderContentPaddingTop;
1133 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001134 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -08001135
Thales Lima7eee74b2023-03-16 16:00:55 -03001136 // Check if the folder fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -05001137 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Thales Lima7eee74b2023-03-16 16:00:55 -03001138 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx)
1139 + folderContentPaddingLeftRight * 2;
1140 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001141 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -08001142
1143 float scale = Math.min(scaleX, scaleY);
1144 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001145 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001146 }
1147 }
1148
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001149 private void updateFolderCellSize(float scale, Resources res) {
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001150 float invIconSizeDp = inv.iconSize[mTypeIndex];
Sunny Goyal35c7b192021-04-20 16:51:10 -07001151 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001152 folderChildTextSizePx = pxFromSp(inv.iconTextSize[mTypeIndex], mMetrics, scale);
Thales Lima7eee74b2023-03-16 16:00:55 -03001153 folderLabelTextSizePx = Math.max(pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale),
Thales Limab35faed2022-09-05 16:30:01 -03001154 (int) (folderChildTextSizePx * folderLabelTextScale));
Jon Mirandabf7d8122016-11-03 15:29:29 -07001155
1156 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001157
Thales Lima79456492023-05-23 11:32:22 +01001158 if (mIsScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001159 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
Thales Lima7eee74b2023-03-16 16:00:55 -03001160 folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale);
1161 folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale);
1162 } else {
1163 folderCellWidthPx = roundPxValueFromFloat(folderCellWidthPx * scale);
1164 folderCellHeightPx = roundPxValueFromFloat(folderCellHeightPx * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001165 }
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001166
Thales Lima7eee74b2023-03-16 16:00:55 -03001167 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
1168 folderCellLayoutBorderSpacePx = roundPxValueFromFloat(
1169 folderCellLayoutBorderSpacePx * scale);
1170 folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale);
1171
Thales Limab35faed2022-09-05 16:30:01 -03001172 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx;
Jon Miranda823da222021-03-23 08:08:45 -04001173 } else {
1174 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1175 * scale);
1176 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1177 * scale);
1178
1179 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1180 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Lima7eee74b2023-03-16 16:00:55 -03001181 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001182 folderContentPaddingLeftRight =
1183 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1184 folderFooterHeightPx =
Thales Lima7eee74b2023-03-16 16:00:55 -03001185 roundPxValueFromFloat(
1186 res.getDimensionPixelSize(R.dimen.folder_footer_height_default)
1187 * scale);
1188
Jon Miranda823da222021-03-23 08:08:45 -04001189 }
1190
Jonathan Miranda9ad87462017-07-26 17:41:02 +00001191 folderChildDrawablePaddingPx = Math.max(0,
1192 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001193 }
1194
Winson1f064272016-07-18 17:18:02 -07001195 public void updateInsets(Rect insets) {
1196 mInsets.set(insets);
1197 }
1198
Sunny Goyalae6e3182019-04-30 12:04:37 -07001199 /**
1200 * The current device insets. This is generally same as the insets being dispatched to
1201 * {@link Insettable} elements, but can differ if the element is using a different profile.
1202 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001203 public Rect getInsets() {
1204 return mInsets;
1205 }
1206
Sunny Goyal756cd262015-08-20 12:33:21 -07001207 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001208 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001209 }
1210
Sunny Goyal19ff7282021-04-22 10:12:54 -07001211 public Point getCellSize(Point result) {
1212 if (result == null) {
1213 result = new Point();
1214 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001215
Pat Manning25d53342022-05-10 09:58:49 +00001216 int shortcutAndWidgetContainerWidth =
1217 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1218 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1219 inv.numColumns);
1220 int shortcutAndWidgetContainerHeight =
1221 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1222 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1223 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001224 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001225 }
1226
1227 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001228 * Returns the left and right space on the cell, which is the cell width - icon size
1229 */
1230 public int getCellHorizontalSpace() {
1231 return getCellSize().x - iconSizePx;
1232 }
1233
1234 /**
Pat Manning25d53342022-05-10 09:58:49 +00001235 * Gets the number of panels within the workspace.
1236 */
1237 public int getPanelCount() {
1238 return isTwoPanels ? 2 : 1;
1239 }
1240
1241 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001242 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1243 * bottom of the screen.
1244 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001245 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1246 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001247 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001248 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001249 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001250 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001251 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001252 }
1253
1254 /**
1255 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1256 */
Pat Manning25d53342022-05-10 09:58:49 +00001257 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001258 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001259 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001260 }
1261
1262 /**
1263 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1264 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001265 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001266 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001267 return heightPx - (isVerticalBarLayout()
1268 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001269 }
1270
Pat Manningea5c1d22022-04-14 10:58:16 +01001271 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001272 * Gets the scale of the workspace for the spring-loaded edit state.
1273 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001274 public float getWorkspaceSpringLoadScale(Context context) {
1275 float scale =
1276 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1277 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001278 scale = Math.min(scale, 1f);
1279
Pat Manninge63dd252022-08-02 16:15:29 +01001280 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001281 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001282 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001283 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001284 if (scaledWorkspaceWidth > maxAvailableWidth) {
1285 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1286 }
1287 return scale;
1288 }
1289
Pat Manning25d53342022-05-10 09:58:49 +00001290 /**
1291 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1292 *
1293 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1294 * layouts have two Cell Layouts per workspace.
1295 */
1296 public int getCellLayoutWidth() {
1297 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001298 }
1299
Pat Manning25d53342022-05-10 09:58:49 +00001300 /**
1301 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1302 *
1303 * <p>This is the height of a Workspace, less its vertical padding.
1304 */
1305 public int getCellLayoutHeight() {
1306 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001307 }
1308
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001309 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001310 return new Point(workspacePadding.left + workspacePadding.right,
1311 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001312 }
1313
1314 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001315 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1316 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001317 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001318 private void updateWorkspacePadding() {
1319 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001320 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -08001321 padding.top = 0;
1322 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001323 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001324 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -07001325 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -07001326 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -07001327 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001328 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -07001329 }
Winson Chungb3800242013-10-24 11:01:54 -07001330 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001331 // Pad the bottom of the workspace with hotseat bar
1332 // and leave a bit of space in case a widget go all the way down
Thales Lima79456492023-05-23 11:32:22 +01001333 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding - mInsets.bottom;
1334 if (!mIsResponsiveGrid) {
1335 paddingBottom +=
1336 workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace;
1337 }
1338 int paddingTop = workspaceTopPadding + (mIsScalableGrid ? 0 : edgeMarginPx);
Pat Manning08610ca2022-04-05 21:03:16 +01001339 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001340
Pat Manning08610ca2022-04-05 21:03:16 +01001341 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001342 }
Pat Manning08610ca2022-04-05 21:03:16 +01001343 insetPadding(workspacePadding, cellLayoutPaddingPx);
1344 }
1345
1346 private void insetPadding(Rect paddings, Rect insets) {
1347 insets.left = Math.min(insets.left, paddings.left);
1348 paddings.left -= insets.left;
1349
1350 insets.top = Math.min(insets.top, paddings.top);
1351 paddings.top -= insets.top;
1352
1353 insets.right = Math.min(insets.right, paddings.right);
1354 paddings.right -= insets.right;
1355
1356 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1357 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001358 }
1359
Sunny Goyal57b22792021-05-25 14:35:01 -07001360 /**
1361 * Returns the padding for hotseat view
1362 */
1363 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001364 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001365 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001366 // The hotseat icons will be placed in the middle of the hotseat cells.
1367 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1368 // in vertical bar layout.
1369 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1370 // is set to account for that difference.
1371 float diffOverlapFactor = iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
Pat Manning08610ca2022-04-05 21:03:16 +01001372 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1373 - diffOverlapFactor), 0);
1374 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001375 + diffOverlapFactor), 0);
1376
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001377 if (isSeascape()) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001378 hotseatBarPadding.set(mInsets.left + hotseatBarSidePaddingStartPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001379 hotseatBarSidePaddingEndPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001380 } else {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001381 hotseatBarPadding.set(hotseatBarSidePaddingEndPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001382 mInsets.right + hotseatBarSidePaddingStartPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001383 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001384 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001385 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001386 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1387 int hotseatBarTopPadding =
1388 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001389
Thales Lima6a590062022-11-22 15:52:49 +00001390 int hotseatWidth = getHotseatRequiredWidth();
Helen Cheuke76291f2023-02-14 17:11:05 +00001391 int startSpacing;
1392 int endSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001393 // Hotseat aligns to the left with nav buttons
1394 if (hotseatBarEndOffset > 0) {
Jon Mirandae17a9492023-03-08 16:42:20 -08001395 startSpacing = inlineNavButtonsEndSpacingPx;
Helen Cheuke76291f2023-02-14 17:11:05 +00001396 endSpacing = availableWidthPx - hotseatWidth - startSpacing + hotseatBorderSpace;
1397 } else {
1398 startSpacing = (availableWidthPx - hotseatWidth) / 2;
1399 endSpacing = startSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001400 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001401 startSpacing += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001402
Helen Cheuke76291f2023-02-14 17:11:05 +00001403 hotseatBarPadding.top = hotseatBarTopPadding;
1404 hotseatBarPadding.bottom = hotseatBarBottomPadding;
Alex Chau51da2192022-05-20 13:32:10 +01001405 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001406 if (isRtl) {
Helen Cheuke76291f2023-02-14 17:11:05 +00001407 hotseatBarPadding.left = endSpacing;
1408 hotseatBarPadding.right = startSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001409 } else {
Helen Cheuke76291f2023-02-14 17:11:05 +00001410 hotseatBarPadding.left = startSpacing;
1411 hotseatBarPadding.right = endSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001412 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001413
Thales Lima79456492023-05-23 11:32:22 +01001414 } else if (mIsScalableGrid) {
Alex Chau206ede92022-08-01 17:46:12 +01001415 int sideSpacing = (availableWidthPx - hotseatQsbWidth) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001416 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001417 0,
Thales Lima425f6822022-05-10 13:44:58 -03001418 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001419 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001420 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001421 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1422 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1423 // for this, we pad the left and right of the hotseat with half of the difference of a
1424 // workspace cell vs a hotseat cell.
1425 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001426 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001427 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001428 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001429 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1430 + mInsets.left,
1431 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001432 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001433 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001434 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001435 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001436 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001437 }
1438
Andy Wickhambd9a1802023-06-08 16:33:15 -07001439 /** The margin between the edge of all apps and the edge of the first icon. */
1440 public int getAllAppsIconStartMargin() {
1441 int allAppsSpacing;
1442 if (isVerticalBarLayout()) {
1443 // On phones, the landscape layout uses a different setup.
1444 allAppsSpacing = workspacePadding.left + workspacePadding.right;
1445 } else {
1446 allAppsSpacing = allAppsLeftRightPadding * 2 + allAppsLeftRightMargin * 2;
1447 }
1448
1449 int cellWidth = DeviceProfile.calculateCellWidth(
1450 availableWidthPx - allAppsSpacing,
1451 0 /* borderSpace */,
1452 numShownAllAppsColumns);
1453 int iconVisibleSize = Math.round(ICON_VISIBLE_AREA_FACTOR * allAppsIconSizePx);
1454 int iconAlignmentMargin = (cellWidth - iconVisibleSize) / 2;
1455 return allAppsLeftRightPadding + iconAlignmentMargin;
1456 }
1457
Thales Lima9938c2f2022-07-25 14:38:16 +01001458 private int getAdditionalQsbSpace() {
1459 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1460 }
1461
1462 /**
1463 * Calculate how much space the hotseat needs to be shown completely
1464 */
1465 private int getHotseatRequiredWidth() {
1466 int additionalQsbSpace = getAdditionalQsbSpace();
1467 return iconSizePx * numShownHotseatIcons
Thales Lima6a590062022-11-22 15:52:49 +00001468 + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1))
Thales Lima9938c2f2022-07-25 14:38:16 +01001469 + additionalQsbSpace;
1470 }
1471
Winsonfadbe8f2016-07-22 16:35:37 -07001472 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001473 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1474 */
1475 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001476 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001477 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1478 } else if (isTaskbarPresent) { // QSB on top
1479 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001480 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001481 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001482 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001483 }
1484
Thales Limab8c05952022-05-23 16:58:38 +01001485 /**
1486 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1487 */
1488 private int getHotseatBarBottomPadding() {
1489 if (isTaskbarPresent) { // QSB on top or inline
1490 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001491 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001492 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001493 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001494 }
1495
1496 /**
Alex Chau51da2192022-05-20 13:32:10 +01001497 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1498 */
1499 public int getTaskbarOffsetY() {
Jon Miranda9c478b62023-03-23 21:38:49 -07001500 int taskbarIconBottomSpace = (taskbarHeight - iconSizePx) / 2;
Alex Chau51da2192022-05-20 13:32:10 +01001501 int launcherIconBottomSpace =
1502 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001503 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001504 }
1505
1506 /**
Alex Chaua2fc7642022-04-21 14:20:23 +01001507 * Returns the number of pixels required below OverviewActions excluding insets.
1508 */
1509 public int getOverviewActionsClaimedSpaceBelow() {
Alex Chaud67ddc42022-09-30 18:15:56 +01001510 if (isTaskbarPresent) {
Jon Miranda9c478b62023-03-23 21:38:49 -07001511 return taskbarHeight + taskbarBottomMargin * 2;
Alex Chaud67ddc42022-09-30 18:15:56 +01001512 }
1513 return mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001514 }
1515
1516 /** Gets the space that the overview actions will take, including bottom margin. */
1517 public int getOverviewActionsClaimedSpace() {
Pat Manning7b8f7662023-01-18 14:48:30 +00001518 int overviewActionsSpace = isTablet && FeatureFlags.ENABLE_GRID_ONLY_OVERVIEW.get()
1519 ? 0
1520 : (overviewActionsTopMarginPx + overviewActionsHeight);
1521 return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
Alex Chaua2fc7642022-04-21 14:20:23 +01001522 }
1523
1524 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001525 * Takes the View and return the scales of width and height depending on the DeviceProfile
1526 * specifications
1527 *
1528 * @param itemInfo The tag of the widget view
1529 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1530 * height
1531 */
1532 @NonNull
1533 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1534 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1535 }
1536
1537 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001538 * @return the bounds for which the open folders should be contained within
1539 */
1540 public Rect getAbsoluteOpenFolderBounds() {
1541 if (isVerticalBarLayout()) {
1542 // Folders should only appear right of the drop target bar and left of the hotseat
1543 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1544 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001545 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001546 mInsets.top + availableHeightPx);
1547 } else {
1548 // Folders should only appear below the drop target bar and above the hotseat
Jon Miranda9c478b62023-03-23 21:38:49 -07001549 int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001550 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001551 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001552 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001553 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001554 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001555 }
1556 }
1557
Jon Miranda228877d2021-02-09 11:05:00 -05001558 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1559 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001560 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001561
Jon Miranda228877d2021-02-09 11:05:00 -05001562 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1563 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001564 }
1565
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001566 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001567 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1568 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1569 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001570 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001571 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001572 return isLandscape && transposeLayoutWithOrientation;
1573 }
1574
Sunny Goyal59d086c2018-05-07 17:31:40 -07001575 /**
1576 * Updates orientation information and returns true if it has changed from the previous value.
1577 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001578 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001579 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001580 boolean isSeascape = DisplayController.INSTANCE.get(context)
1581 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001582 if (mIsSeascape != isSeascape) {
1583 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001584 // Hotseat changing sides requires updating workspace left/right paddings
1585 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001586 return true;
1587 }
1588 }
1589 return false;
1590 }
1591
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001592 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001593 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001594 }
1595
Sunny Goyal07b69292018-01-08 14:19:34 -08001596 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001597 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001598 }
1599
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001600 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001601 switch (containerType) {
1602 case CellLayout.WORKSPACE:
1603 return cellHeightPx;
1604 case CellLayout.FOLDER:
1605 return folderCellHeightPx;
1606 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001607 // The hotseat is the only container where the cell height is going to be
1608 // different from the content within that cell.
1609 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001610 default:
1611 // ??
1612 return 0;
1613 }
1614 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001615
Jon Miranda58561d42021-03-17 10:51:54 -04001616 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001617 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001618 }
1619
Alex Chaue818bcb2022-09-02 17:27:11 +01001620 private String dpPointFToString(String name, PointF value) {
1621 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
1622 }
1623
Pat Manning5f74bfd2022-07-20 12:08:54 +01001624 /** Dumps various DeviceProfile variables to the specified writer. */
1625 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04001626 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001627 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001628
1629 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001630 writer.println(prefix + "\tisPhone:" + isPhone);
1631 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1632 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001633 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001634
1635 writer.println(prefix + "\tisLandscape:" + isLandscape);
1636 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001637 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001638
1639 writer.println(prefix + pxToDpStr("windowX", windowX));
1640 writer.println(prefix + pxToDpStr("windowY", windowY));
1641 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1642 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001643 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1644 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001645 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1646 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1647 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1648 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001649
1650 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1651
Thales Limac98b7812023-04-14 15:04:23 +01001652 writer.println(prefix + "\tisResponsiveGrid:" + mIsResponsiveGrid);
Thales Lima79456492023-05-23 11:32:22 +01001653 writer.println(prefix + "\tisScalableGrid:" + mIsScalableGrid);
Jon Miranda58561d42021-03-17 10:51:54 -04001654
Thales Lima83bedbf2021-10-05 17:47:39 +01001655 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001656 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1657 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1658 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001659
Alex Chaue818bcb2022-09-02 17:27:11 +01001660 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07001661
Jon Miranda58561d42021-03-17 10:51:54 -04001662 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1663 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1664
1665 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1666 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1667
Thales Lima83bedbf2021-10-05 17:47:39 +01001668 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1669 cellLayoutBorderSpacePx.x));
1670 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1671 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001672 writer.println(
1673 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
1674 writer.println(
1675 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
1676 writer.println(
1677 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01001678 writer.println(
1679 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01001680
Jon Miranda58561d42021-03-17 10:51:54 -04001681 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1682 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1683 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1684
Helen Cheuk599109b2023-02-23 17:15:39 +00001685 writer.println(prefix + "\tinv.numFolderRows: " + inv.numFolderRows);
1686 writer.println(prefix + "\tinv.numFolderColumns: " + inv.numFolderColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001687 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1688 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1689 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1690 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1691 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1692 folderChildDrawablePaddingPx));
Thales Limab35faed2022-09-05 16:30:01 -03001693 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx",
1694 folderCellLayoutBorderSpacePx));
Thales Limaa08a4432022-08-09 09:55:17 +01001695 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
1696 folderContentPaddingLeftRight));
1697 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03001698 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001699
Alex Chaue0227552022-04-06 19:44:43 +01001700 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001701 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
1702 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
1703 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
1704 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01001705
1706 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
1707 writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001708 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
1709 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04001710 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1711 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1712 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1713 allAppsIconDrawablePaddingPx));
1714 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001715 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001716 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
1717 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001718 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau62572c02022-07-25 18:36:37 +00001719 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
Alex Chau27b39b92022-01-14 18:02:18 +00001720 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001721
1722 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03001723 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04001724 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00001725 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Jon Miranda58561d42021-03-17 10:51:54 -04001726 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
1727 hotseatBarSidePaddingStartPx));
1728 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
1729 hotseatBarSidePaddingEndPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001730 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01001731 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
1732 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01001733 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
1734 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001735 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
1736 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
1737 hotseatLayoutPadding.top));
1738 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
1739 hotseatLayoutPadding.bottom));
1740 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
1741 hotseatLayoutPadding.left));
1742 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
1743 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001744 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001745 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001746 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01001747 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001748
1749 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001750 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda9c478b62023-03-23 21:38:49 -07001751 writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight));
1752 writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight));
1753 writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin));
1754 writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001755
Thales Lima83bedbf2021-10-05 17:47:39 +01001756 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1757 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001758 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
1759 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
1760 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00001761 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001762
Jon Mirandaab3c6812021-06-28 15:42:28 -07001763 writer.println(prefix + pxToDpStr("iconScale", iconScale));
1764 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04001765 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00001766 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001767
Thales Lima171ee662022-11-22 15:52:49 +00001768 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04001769 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
1770 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00001771
1772 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00001773 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
1774 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
1775 overviewTaskIconDrawableSizePx));
1776 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
1777 overviewTaskIconDrawableSizeGridPx));
1778 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
1779 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01001780 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
1781 overviewActionsTopMarginPx));
1782 writer.println(prefix + pxToDpStr("overviewActionsHeight",
1783 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00001784 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
1785 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00001786 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
1787 overviewActionsButtonSpacing));
1788 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
1789 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
1790 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01001791
Alex Chau62572c02022-07-25 18:36:37 +00001792 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001793 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00001794 writer.println(
1795 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001796
Pat Manning5f74bfd2022-07-20 12:08:54 +01001797 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
1798 getCellLayoutSpringLoadShrunkTop()));
1799 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
1800 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01001801 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
1802 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001803 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
1804 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01001805 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
1806 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Thales Lima79456492023-05-23 11:32:22 +01001807 if (mIsResponsiveGrid) {
1808 writer.println(prefix + "\tmResponsiveHeightSpec:" + mResponsiveHeightSpec.toString());
1809 writer.println(prefix + "\tmResponsiveWidthSpec:" + mResponsiveWidthSpec.toString());
1810 }
Jon Miranda58561d42021-03-17 10:51:54 -04001811 }
1812
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00001813 /** Returns a reduced representation of this DeviceProfile. */
1814 public String toSmallString() {
1815 return "isTablet:" + isTablet + ", "
1816 + "isMultiDisplay:" + isMultiDisplay + ", "
1817 + "widthPx:" + widthPx + ", "
1818 + "heightPx:" + heightPx + ", "
1819 + "insets:" + mInsets + ", "
1820 + "rotationHint:" + rotationHint;
1821 }
1822
Alex Chaua6907dc2022-03-18 15:24:07 +00001823 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07001824 Configuration config = new Configuration(c.getResources().getConfiguration());
1825 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03001826 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00001827 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07001828 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07001829 }
Sunny Goyalfde55052018-02-01 14:46:13 -08001830
1831 /**
1832 * Callback when a component changes the DeviceProfile associated with it, as a result of
1833 * configuration change
1834 */
1835 public interface OnDeviceProfileChangeListener {
1836
1837 /**
1838 * Called when the device profile is reassigned. Note that for layout and measurements, it
1839 * is sufficient to listen for inset changes. Use this callback when you need to perform
1840 * a one time operation.
1841 */
1842 void onDeviceProfileChanged(DeviceProfile dp);
1843 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001844
Sihua Mae04aa202022-07-18 12:43:56 -07001845 /**
1846 * Handler that deals with ItemInfo of the views for the DeviceProfile
1847 */
1848 @FunctionalInterface
1849 public interface ViewScaleProvider {
1850 /**
1851 * Get the scales from the view
1852 *
1853 * @param itemInfo The tag of the widget view
1854 * @return PointF instance containing the scale information, or null if using the default
1855 * app widget scale of this device profile.
1856 */
1857 @NonNull
1858 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
1859 }
1860
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001861 public static class Builder {
1862 private Context mContext;
1863 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07001864 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001865
Sunny Goyal19ff7282021-04-22 10:12:54 -07001866 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00001867 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001868
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001869 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001870 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00001871 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07001872 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001873
Sunny Goyal65190ae2022-08-02 14:16:26 -07001874 private SparseArray<DotRenderer> mDotRendererCache;
1875
Jon Miranda2b25ded2023-02-02 14:48:45 -08001876 private Consumer<DeviceProfile> mOverrideProvider;
1877
Sunny Goyalfd58da62020-08-11 12:06:49 -07001878 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001879 mContext = context;
1880 mInv = inv;
1881 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001882 }
1883
1884 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1885 mIsMultiWindowMode = isMultiWindowMode;
1886 return this;
1887 }
1888
Alex Chauab800f72022-12-13 17:46:06 +00001889 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
1890 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001891 return this;
1892 }
1893
Sunny Goyal65190ae2022-08-02 14:16:26 -07001894 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
1895 mDotRendererCache = dotRendererCache;
1896 return this;
1897 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07001898
1899 public Builder setWindowBounds(WindowBounds bounds) {
1900 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07001901 return this;
1902 }
1903
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001904 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1905 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1906 return this;
1907 }
1908
Alex Chau6ed408f2022-03-04 12:58:05 +00001909 public Builder setGestureMode(boolean isGestureMode) {
1910 mIsGestureMode = isGestureMode;
1911 return this;
1912 }
1913
Jon Miranda2b25ded2023-02-02 14:48:45 -08001914 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
1915 mOverrideProvider = overrideProvider;
1916 return this;
1917 }
1918
Sihua Mae04aa202022-07-18 12:43:56 -07001919 /**
1920 * Set the viewScaleProvider for the builder
1921 *
1922 * @param viewScaleProvider The viewScaleProvider to be set for the
Thales Limae9273ea2023-01-26 12:33:52 +00001923 * DeviceProfile
Sihua Mae04aa202022-07-18 12:43:56 -07001924 * @return This builder
1925 */
1926 @NonNull
1927 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
1928 mViewScaleProvider = viewScaleProvider;
1929 return this;
1930 }
1931
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001932 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001933 if (mWindowBounds == null) {
1934 throw new IllegalArgumentException("Window bounds not set");
1935 }
1936 if (mTransposeLayoutWithOrientation == null) {
1937 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
1938 }
Alex Chau6ed408f2022-03-04 12:58:05 +00001939 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01001940 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00001941 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001942 if (mDotRendererCache == null) {
1943 mDotRendererCache = new SparseArray<>();
1944 }
Sihua Mae04aa202022-07-18 12:43:56 -07001945 if (mViewScaleProvider == null) {
1946 mViewScaleProvider = DEFAULT_PROVIDER;
1947 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08001948 if (mOverrideProvider == null) {
1949 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
1950 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001951 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00001952 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jon Miranda2b25ded2023-02-02 14:48:45 -08001953 mIsGestureMode, mViewScaleProvider, mOverrideProvider);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001954 }
1955 }
1956
Winson Chungb3800242013-10-24 11:01:54 -07001957}