blob: 91243177f265c961cfc9d3016adeb705f0ad1c1f [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;
Alex Chau2014f502023-09-12 19:18:46 +010043import android.util.Log;
Sunny Goyal65190ae2022-08-02 14:16:26 -070044import android.util.SparseArray;
Sunny Goyal59d086c2018-05-07 17:31:40 -070045import android.view.Surface;
Winson Chungb3800242013-10-24 11:01:54 -070046
Sunny Goyal65190ae2022-08-02 14:16:26 -070047import androidx.annotation.NonNull;
Sihua Mae04aa202022-07-18 12:43:56 -070048import androidx.annotation.Nullable;
Jon Miranda9c478b62023-03-23 21:38:49 -070049import androidx.core.content.res.ResourcesCompat;
Sunny Goyal65190ae2022-08-02 14:16:26 -070050
Sunny Goyalc13403c2016-11-18 23:44:48 -080051import com.android.launcher3.CellLayout.ContainerType;
Jon Miranda228877d2021-02-09 11:05:00 -050052import com.android.launcher3.DevicePaddings.DevicePadding;
Alex Chaud67ddc42022-09-30 18:15:56 +010053import com.android.launcher3.config.FeatureFlags;
Tony Wickham8912b042018-11-29 15:28:53 -080054import com.android.launcher3.icons.DotRenderer;
Hyunyoung Song48cb7bc2018-09-25 17:03:34 -070055import com.android.launcher3.icons.IconNormalizer;
Sihua Mae04aa202022-07-18 12:43:56 -070056import com.android.launcher3.model.data.ItemInfo;
Thales Limaabfe3642023-05-24 18:08:53 +010057import com.android.launcher3.responsive.AllAppsSpecs;
58import com.android.launcher3.responsive.CalculatedAllAppsSpec;
Jordan Silva637f4eb2023-06-13 11:21:53 +010059import com.android.launcher3.responsive.CalculatedFolderSpec;
Thales Limaf8bfb032023-07-24 15:08:05 +010060import com.android.launcher3.responsive.CalculatedHotseatSpec;
Jordan Silva8bd7af22023-06-21 15:35:03 +010061import com.android.launcher3.responsive.CalculatedWorkspaceSpec;
Jordan Silva637f4eb2023-06-13 11:21:53 +010062import com.android.launcher3.responsive.FolderSpecs;
Thales Limaf8bfb032023-07-24 15:08:05 +010063import com.android.launcher3.responsive.HotseatSpecs;
Jordan Silva8bd7af22023-06-21 15:35:03 +010064import com.android.launcher3.responsive.WorkspaceSpecs;
Sunny Goyal57b22792021-05-25 14:35:01 -070065import com.android.launcher3.uioverrides.ApiWrapper;
Sunny Goyalfd58da62020-08-11 12:06:49 -070066import com.android.launcher3.util.DisplayController;
67import com.android.launcher3.util.DisplayController.Info;
Thales Lima2759aa32023-06-05 16:25:45 +010068import com.android.launcher3.util.IconSizeSteps;
Thales Limac98b7812023-04-14 15:04:23 +010069import com.android.launcher3.util.ResourceHelper;
Sunny Goyalb46703d2020-05-27 17:52:03 -070070import com.android.launcher3.util.WindowBounds;
Winson1f064272016-07-18 17:18:02 -070071
Jon Miranda58561d42021-03-17 10:51:54 -040072import java.io.PrintWriter;
Alex Chaue818bcb2022-09-02 17:27:11 +010073import java.util.Locale;
Jon Miranda2b25ded2023-02-02 14:48:45 -080074import java.util.function.Consumer;
Jon Miranda58561d42021-03-17 10:51:54 -040075
Sunny Goyal35c7b192021-04-20 16:51:10 -070076@SuppressLint("NewApi")
Winson Chungb3800242013-10-24 11:01:54 -070077public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070078
Sunny Goyal8b9919d2021-04-07 14:45:17 -070079 private static final int DEFAULT_DOT_SIZE = 100;
Alex Chau206ede92022-08-01 17:46:12 +010080 private static final float ALL_APPS_TABLET_MAX_ROWS = 5.5f;
Thales Limab35faed2022-09-05 16:30:01 -030081 private static final float MIN_FOLDER_TEXT_SIZE_SP = 16f;
Sunny Goyal6c304b12023-04-10 12:03:04 -070082 private static final float MIN_WIDGET_PADDING_DP = 6f;
Alex Chau206ede92022-08-01 17:46:12 +010083
Sihua Mae04aa202022-07-18 12:43:56 -070084 public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f);
85 public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE;
Jordan Silva637f4eb2023-06-13 11:21:53 +010086 public static final Consumer<DeviceProfile> DEFAULT_DIMENSION_PROVIDER = dp -> {};
Sihua Mae04aa202022-07-18 12:43:56 -070087
Adam Cohen2e6da152015-05-06 11:42:25 -070088 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070089 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070090 private final DisplayMetrics mMetrics;
Thales Lima2759aa32023-06-05 16:25:45 +010091 private final IconSizeSteps mIconSizeSteps;
Winson Chungbe876472014-05-14 14:15:20 -070092
Sunny Goyalc6205602015-05-21 20:46:33 -070093 // Device properties
94 public final boolean isTablet;
Sunny Goyalc6205602015-05-21 20:46:33 -070095 public final boolean isPhone;
96 public final boolean transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +000097 public final boolean isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -070098 public final boolean isTwoPanels;
Thales Limaa1012902022-01-13 17:58:42 +000099 public final boolean isQsbInline;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700100
Sunny Goyalc6205602015-05-21 20:46:33 -0700101 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -0700102 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -0800103 public final boolean isMultiWindowMode;
Alex Chau6ed408f2022-03-04 12:58:05 +0000104 public final boolean isGestureMode;
Sunny Goyald70e75a2018-02-22 10:07:32 -0800105
Sunny Goyal0addbf02020-04-28 14:17:35 -0700106 public final int windowX;
107 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -0700108 public final int widthPx;
109 public final int heightPx;
110 public final int availableWidthPx;
111 public final int availableHeightPx;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800112 public final int rotationHint;
Jon Mirandabba64512019-03-27 10:54:17 -0700113
114 public final float aspectRatio;
115
Thales Lima79456492023-05-23 11:32:22 +0100116 private final boolean mIsScalableGrid;
Thales Lima83bedbf2021-10-05 17:47:39 +0100117 private final int mTypeIndex;
Jon Mirandae126d722021-02-25 10:45:20 -0500118
Thales Limac98b7812023-04-14 15:04:23 +0100119 // Responsive grid
120 private final boolean mIsResponsiveGrid;
Thales Limac98b7812023-04-14 15:04:23 +0100121 private CalculatedWorkspaceSpec mResponsiveWidthSpec;
122 private CalculatedWorkspaceSpec mResponsiveHeightSpec;
Thales Limaabfe3642023-05-24 18:08:53 +0100123 private CalculatedAllAppsSpec mAllAppsResponsiveWidthSpec;
124 private CalculatedAllAppsSpec mAllAppsResponsiveHeightSpec;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100125 private CalculatedFolderSpec mResponsiveFolderWidthSpec;
126 private CalculatedFolderSpec mResponsiveFolderHeightSpec;
Thales Limaf8bfb032023-07-24 15:08:05 +0100127 private CalculatedHotseatSpec mResponsiveHotseatSpec;
Thales Limac98b7812023-04-14 15:04:23 +0100128
Tony Wickhamd6b40372015-09-23 18:37:57 -0700129 /**
130 * The maximum amount of left/right workspace padding as a percentage of the screen width.
131 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
132 * 7% of the screen width can be used as right padding.
133 */
134 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -0700135
Jon Miranda3f9bab22017-07-28 14:50:17 -0700136 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700137 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda80dda302021-07-28 14:14:59 -0700138 private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252;
139 private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700140
Sunny Goyalc6205602015-05-21 20:46:33 -0700141 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +0100142 public final int desiredWorkspaceHorizontalMarginOriginalPx;
143 public int desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100144 public int gridVisualizationPaddingX;
145 public int gridVisualizationPaddingY;
Thales Lima78d00ad2021-09-30 11:29:06 +0100146 public Point cellLayoutBorderSpaceOriginalPx;
147 public Point cellLayoutBorderSpacePx;
Pat Manning08610ca2022-04-05 21:03:16 +0100148 public Rect cellLayoutPaddingPx = new Rect();
149
Sunny Goyalc6205602015-05-21 20:46:33 -0700150 public final int edgeMarginPx;
Alex Chau0c4e11b2022-07-08 18:41:36 +0100151 public final float workspaceContentScale;
Alex Chau906d8822022-05-23 10:42:25 +0100152 public final int workspaceSpringLoadedMinNextPageVisiblePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700153
Jon Miranda58561d42021-03-17 10:51:54 -0400154 private final int extraSpace;
Thales Lima171ee662022-11-22 15:52:49 +0000155 private int maxEmptySpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500156 public int workspaceTopPadding;
157 public int workspaceBottomPadding;
158
Tony Wickham5edf9e22020-03-27 20:06:52 -0700159 // Workspace page indicator
160 public final int workspacePageIndicatorHeight;
161 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700162
Sunny Goyalc6205602015-05-21 20:46:33 -0700163 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400164 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700165 public int iconSizePx;
166 public int iconTextSizePx;
167 public int iconDrawablePaddingPx;
Thales Lima93ee8fc2023-06-05 17:07:11 +0100168 private final int mIconDrawablePaddingOriginalPx;
Thales Lima79456492023-05-23 11:32:22 +0100169 public boolean iconCenterVertically;
Winson Chungb3800242013-10-24 11:01:54 -0700170
Jon Mirandaab3c6812021-06-28 15:42:28 -0700171 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800172 public int cellWidthPx;
173 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700174 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800175
Thales Lima79456492023-05-23 11:32:22 +0100176 public int cellYPaddingPx = -1;
Jon Mirandae126d722021-02-25 10:45:20 -0500177
Sunny Goyalc6205602015-05-21 20:46:33 -0700178 // Folder
Jon Mirandae126d722021-02-25 10:45:20 -0500179 public float folderLabelTextScale;
180 public int folderLabelTextSizePx;
Thales Limab35faed2022-09-05 16:30:01 -0300181 public int folderFooterHeightPx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700182 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700183 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700184
Jon Mirandae126d722021-02-25 10:45:20 -0500185 // Folder content
Jordan Silva637f4eb2023-06-13 11:21:53 +0100186 public Point folderCellLayoutBorderSpacePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500187 public int folderContentPaddingLeftRight;
188 public int folderContentPaddingTop;
189
Jon Mirandabf7d8122016-11-03 15:29:29 -0700190 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700191 public int folderCellWidthPx;
192 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700193
194 // Folder child
195 public int folderChildIconSizePx;
196 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700197 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700198
Sunny Goyalc6205602015-05-21 20:46:33 -0700199 // Hotseat
Thales Lima9938c2f2022-07-25 14:38:16 +0100200 public int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700201 public int hotseatCellHeightPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100202 public final boolean areNavButtonsInline;
Jon Miranda18751b62017-07-31 17:25:27 -0700203 // In portrait: size = height, in landscape: size = width
204 public int hotseatBarSizePx;
Thales Limab8c05952022-05-23 16:58:38 +0100205 public int hotseatBarBottomSpacePx;
Pat Manning26f70f72022-07-07 13:50:39 +0100206 public int hotseatBarEndOffset;
Thales Limab8c05952022-05-23 16:58:38 +0100207 public int hotseatQsbSpace;
Pat Manningde25c0d2022-04-05 19:11:26 +0100208 public int springLoadedHotseatBarTopMarginPx;
Thales Lima8e11d532023-08-31 13:40:26 +0000209 // These 2 values are only used for isVerticalBar
210 // Padding between edge of screen and hotseat
211 public final int mHotseatBarEdgePaddingPx;
212 // Space between hotseat and workspace (not used in responsive)
213 public final int mHotseatBarWorkspaceSpacePx;
Alex Chau206ede92022-08-01 17:46:12 +0100214 public int hotseatQsbWidth; // only used when isQsbInline
Sunny Goyal57b22792021-05-25 14:35:01 -0700215 public final int hotseatQsbHeight;
Thales Limab8c05952022-05-23 16:58:38 +0100216 public final int hotseatQsbVisualHeight;
217 private final int hotseatQsbShadowHeight;
Thales Limadd027342022-01-07 12:54:37 +0000218 public int hotseatBorderSpace;
Thales Limaffc68b02023-01-09 16:20:23 +0000219 private final int mMinHotseatIconSpacePx;
220 private final int mMinHotseatQsbWidthPx;
221 private final int mMaxHotseatIconSpacePx;
Jon Mirandae17a9492023-03-08 16:42:20 -0800222 public final int inlineNavButtonsEndSpacingPx;
Liran Binyamina833af32023-08-02 16:30:27 -0400223 // Space required for the bubble bar between the hotseat and the edge of the screen. If there's
224 // not enough space, the hotseat will adjust itself for the bubble bar.
225 private final int mBubbleBarSpaceThresholdPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700226
Alex Chau3d2c0622022-09-01 21:28:14 +0100227 // Bottom sheets
228 public int bottomSheetTopPadding;
229 public int bottomSheetOpenDuration;
230 public int bottomSheetCloseDuration;
231 public float bottomSheetWorkspaceScale;
232 public float bottomSheetDepth;
233
Sunny Goyalc6205602015-05-21 20:46:33 -0700234 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000235 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000236 public int allAppsShiftRange;
237 public int allAppsTopPadding;
Alex Chau3d2c0622022-09-01 21:28:14 +0100238 public int allAppsOpenDuration;
239 public int allAppsCloseDuration;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700240 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700241 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700242 public int allAppsIconSizePx;
243 public int allAppsIconDrawablePaddingPx;
sfufa@google.comde013292021-09-21 18:22:44 -0700244 public int allAppsLeftRightPadding;
Alex Chau27b39b92022-01-14 18:02:18 +0000245 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700246 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700247 public float allAppsIconTextSizePx;
248
Zak Cohen334efeb2021-03-19 16:42:07 -0700249 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700250 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000251 public int overviewTaskIconSizePx;
Alex Chauac9df382021-08-02 19:08:41 +0100252 public int overviewTaskIconDrawableSizePx;
253 public int overviewTaskIconDrawableSizeGridPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000254 public int overviewTaskThumbnailTopMarginPx;
Alex Chau19c6eca2022-03-10 20:12:56 +0000255 public final int overviewActionsHeight;
Alex Chaua2fc7642022-04-21 14:20:23 +0100256 public final int overviewActionsTopMarginPx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000257 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100258 public int overviewPageSpacing;
259 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000260 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700261
Jeremy Sim0ac47082022-10-10 13:59:40 -0700262 // Split staging
263 public int splitPlaceholderInset;
264
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800265 // Widgets
Sihua Mae04aa202022-07-18 12:43:56 -0700266 private final ViewScaleProvider mViewScaleProvider;
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800267
Sunny Goyal47328fd2016-05-25 18:56:41 -0700268 // Drop Target
269 public int dropTargetBarSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100270 public int dropTargetBarTopMarginPx;
271 public int dropTargetBarBottomMarginPx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100272 public int dropTargetDragPaddingPx;
273 public int dropTargetTextSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100274 public int dropTargetHorizontalPaddingPx;
275 public int dropTargetVerticalPaddingPx;
276 public int dropTargetGapPx;
Alex Chau5b019302022-05-23 10:42:25 +0100277 public int dropTargetButtonWorkspaceEdgeGapPx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700278
Winson1f064272016-07-18 17:18:02 -0700279 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800280 private final Rect mInsets = new Rect();
281 public final Rect workspacePadding = new Rect();
Sunny Goyal6c304b12023-04-10 12:03:04 -0700282 // Additional padding added to the widget inside its cellSpace. It is applied outside
283 // the widgetView, such that the actual view size is same as the widget size.
284 public final Rect widgetPadding = new Rect();
285
Jon Miranda0bd63d12019-03-06 17:29:29 -0800286 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700287 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700288
Tony Wickhamf34bee82018-12-03 18:11:39 -0800289 // Notification dots
Sunny Goyal65190ae2022-08-02 14:16:26 -0700290 public final DotRenderer mDotRendererWorkSpace;
291 public final DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800292
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100293 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800294 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000295 // Whether Taskbar will inset the bottom of apps by taskbarSize.
296 public boolean isTaskbarPresentInApps;
Jon Miranda9c478b62023-03-23 21:38:49 -0700297 public final int taskbarHeight;
298 public final int stashedTaskbarHeight;
299 public final int taskbarBottomMargin;
300 public final int taskbarIconSize;
Jon Miranda04f05102023-04-04 12:16:31 -0700301 // If true, used to layout taskbar in 3 button navigation mode.
302 public final boolean startAlignTaskbar;
Thales Limae9566402023-08-30 16:35:12 +0100303 public final boolean isTransientTaskbar;
Tony Wickham15883892021-02-12 11:24:40 -0800304
Alex Chaua02eddc2021-04-29 00:36:06 +0100305 // DragController
306 public int flingToDeleteThresholdVelocity;
307
Vinit Nayak17c4b332021-08-05 12:54:58 -0700308 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700309 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal65190ae2022-08-02 14:16:26 -0700310 SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
Alex Chauab800f72022-12-13 17:46:06 +0000311 boolean transposeLayoutWithOrientation, boolean isMultiDisplay, boolean isGestureMode,
Jon Miranda2b25ded2023-02-02 14:48:45 -0800312 @NonNull final ViewScaleProvider viewScaleProvider,
313 @NonNull final Consumer<DeviceProfile> dimensionOverrideProvider) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700314
Adam Cohen2e6da152015-05-06 11:42:25 -0700315 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700316 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800317 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500318 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +0000319 this.isMultiDisplay = isMultiDisplay;
Alex Chau6ed408f2022-03-04 12:58:05 +0000320 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700321 windowX = windowBounds.bounds.left;
322 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800323 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100324 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700325
Thales Limac98b7812023-04-14 15:04:23 +0100326 // TODO(b/241386436): shouldn't change any launcher behaviour
Thales Limaabfe3642023-05-24 18:08:53 +0100327 mIsResponsiveGrid = inv.workspaceSpecsId != INVALID_RESOURCE_HANDLE
Jordan Silva637f4eb2023-06-13 11:21:53 +0100328 && inv.allAppsSpecsId != INVALID_RESOURCE_HANDLE
Thales Limaf8bfb032023-07-24 15:08:05 +0100329 && inv.folderSpecsId != INVALID_RESOURCE_HANDLE
330 && inv.hotseatSpecsId != INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100331
Thales Lima79456492023-05-23 11:32:22 +0100332 mIsScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000333 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700334 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000335 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700336 isPhone = !isTablet;
Alex Chauab800f72022-12-13 17:46:06 +0000337 isTwoPanels = isTablet && isMultiDisplay;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800338 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700339
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000340 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000341 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700342 ? Configuration.ORIENTATION_LANDSCAPE
343 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000344 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700345 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000346 mMetrics = res.getDisplayMetrics();
347
Thales Lima2759aa32023-06-05 16:25:45 +0100348 mIconSizeSteps = mIsResponsiveGrid ? new IconSizeSteps(res) : null;
349
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000350 // Determine sizes.
351 widthPx = windowBounds.bounds.width();
352 heightPx = windowBounds.bounds.height();
353 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100354 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000355
356 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Thales Lima83bedbf2021-10-05 17:47:39 +0100357 if (isTwoPanels) {
358 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000359 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100360 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000361 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100362 }
363 } else {
364 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000365 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100366 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000367 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100368 }
369 }
Alex Chau2014f502023-09-12 19:18:46 +0100370 if (InvariantDeviceProfile.sDebug) {
371 Log.d("b/298077774",
372 "DeviceProfile - mTypeIndex: " + mTypeIndex + ": " + dpPointFToString(
373 "minCellSize",
374 inv.minCellSize[mTypeIndex]));
375 }
Thales Lima83bedbf2021-10-05 17:47:39 +0100376
Thales Limae9566402023-08-30 16:35:12 +0100377 isTransientTaskbar = DisplayController.isTransientTaskbar(context);
378 if (isTransientTaskbar) {
Jon Miranda9c478b62023-03-23 21:38:49 -0700379 float invTransientIconSizeDp = inv.transientTaskbarIconSize[mTypeIndex];
380 taskbarIconSize = pxFromDp(invTransientIconSizeDp, mMetrics);
Jon Miranda95f44722023-06-06 19:48:19 -0700381 taskbarHeight = Math.round((taskbarIconSize * ICON_VISIBLE_AREA_FACTOR)
382 + (2 * res.getDimensionPixelSize(R.dimen.transient_taskbar_padding)));
Jon Miranda9c478b62023-03-23 21:38:49 -0700383 stashedTaskbarHeight =
384 res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_height);
385 taskbarBottomMargin =
386 res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin);
Jon Miranda04f05102023-04-04 12:16:31 -0700387 startAlignTaskbar = false;
Jon Miranda9c478b62023-03-23 21:38:49 -0700388 } else {
389 taskbarIconSize = pxFromDp(ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size),
390 mMetrics);
391 taskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_size);
392 stashedTaskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
393 taskbarBottomMargin = 0;
Jon Miranda04f05102023-04-04 12:16:31 -0700394 startAlignTaskbar = inv.startAlignTaskbar[mTypeIndex];
Tony Wickham15883892021-02-12 11:24:40 -0800395 }
Tony Wickham15883892021-02-12 11:24:40 -0800396
Winson Chungb3800242013-10-24 11:01:54 -0700397 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100398 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700399
Alex Chau51da2192022-05-20 13:32:10 +0100400 gridVisualizationPaddingX = res.getDimensionPixelSize(
401 R.dimen.grid_visualization_horizontal_cell_spacing);
402 gridVisualizationPaddingY = res.getDimensionPixelSize(
403 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500404
Alex Chaue0227552022-04-06 19:44:43 +0100405 bottomSheetTopPadding = mInsets.top // statusbar height
Andras Kloczl142b0542022-03-09 21:26:02 +0000406 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
407 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
Alex Chau3d2c0622022-09-01 21:28:14 +0100408 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
409 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
410 if (isTablet) {
411 bottomSheetWorkspaceScale = workspaceContentScale;
Alex Chauab800f72022-12-13 17:46:06 +0000412 if (isMultiDisplay && !ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH.get()) {
413 // TODO(b/259893832): Revert to use maxWallpaperScale to calculate bottomSheetDepth
414 // when screen recorder bug is fixed.
415 bottomSheetDepth = 1f;
416 } else {
417 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
418 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
419 // When depth is 1, wallpaper zoom is set to 1.
420 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
421 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
422 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
423 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
424 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100425 } else {
426 bottomSheetWorkspaceScale = 1f;
427 bottomSheetDepth = 0f;
428 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000429
Jon Mirandae126d722021-02-25 10:45:20 -0500430 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
Thales Limab35faed2022-09-05 16:30:01 -0300431
Thales Lima79456492023-05-23 11:32:22 +0100432 if (mIsScalableGrid && inv.folderStyle != INVALID_RESOURCE_HANDLE) {
Thales Limab35faed2022-09-05 16:30:01 -0300433 TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
Thales Limad852d652023-01-17 14:01:13 +0000434 R.styleable.FolderStyle);
Thales Limab35faed2022-09-05 16:30:01 -0300435 // These are re-set in #updateFolderCellSize if the grid is not scalable
436 folderCellHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000437 R.styleable.FolderStyle_folderCellHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300438 folderCellWidthPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000439 R.styleable.FolderStyle_folderCellWidth, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300440
441 folderContentPaddingTop = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000442 R.styleable.FolderStyle_folderTopPadding, 0);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100443
444 int gutter = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000445 R.styleable.FolderStyle_folderBorderSpace, 0);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100446 folderCellLayoutBorderSpacePx = new Point(gutter, gutter);
Thales Limab35faed2022-09-05 16:30:01 -0300447 folderFooterHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000448 R.styleable.FolderStyle_folderFooterHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300449 folderStyle.recycle();
Jordan Silva637f4eb2023-06-13 11:21:53 +0100450 } else if (!mIsResponsiveGrid) {
451 folderCellLayoutBorderSpacePx = new Point(0, 0);
Thales Lima7eee74b2023-03-16 16:00:55 -0300452 folderFooterHeightPx = res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Thales Limab35faed2022-09-05 16:30:01 -0300453 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
454 }
Jon Mirandae126d722021-02-25 10:45:20 -0500455
Thales Lima85c942f2021-12-31 13:04:20 +0000456 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000457 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
458 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Thales Limae9273ea2023-01-26 12:33:52 +0000459 setupAllAppsStyle(context);
Jon Mirandae126d722021-02-25 10:45:20 -0500460
Tony Wickham5edf9e22020-03-27 20:06:52 -0700461 workspacePageIndicatorHeight = res.getDimensionPixelSize(
462 R.dimen.workspace_page_indicator_height);
463 mWorkspacePageIndicatorOverlapWorkspace =
464 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700465
Thales Limad852d652023-01-17 14:01:13 +0000466 TypedArray cellStyle;
467 if (inv.cellStyle != INVALID_RESOURCE_HANDLE) {
468 cellStyle = context.obtainStyledAttributes(inv.cellStyle,
469 R.styleable.CellStyle);
470 } else {
471 cellStyle = context.obtainStyledAttributes(R.style.CellStyleDefault,
472 R.styleable.CellStyle);
473 }
Thales Lima93ee8fc2023-06-05 17:07:11 +0100474 mIconDrawablePaddingOriginalPx = cellStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000475 R.styleable.CellStyle_iconDrawablePadding, 0);
476 cellStyle.recycle();
Alex Chaua02eddc2021-04-29 00:36:06 +0100477
Sunny Goyal47328fd2016-05-25 18:56:41 -0700478 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100479 dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
480 dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100481 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
482 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100483 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
484 R.dimen.drop_target_button_drawable_horizontal_padding);
485 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
486 R.dimen.drop_target_button_drawable_vertical_padding);
487 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100488 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
489 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100490
Alex Chau906d8822022-05-23 10:42:25 +0100491 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
492 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700493
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700494 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700495
Thales Limaa1012902022-01-13 17:58:42 +0000496 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100497 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
498 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
499
Thales Lima12d0eff2022-03-25 17:06:11 +0000500 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
501 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
502 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
503 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
504 && hotseatQsbHeight > 0;
Thales Lima79456492023-05-23 11:32:22 +0100505 isQsbInline = mIsScalableGrid && inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000506
Thales Lima425f6822022-05-10 13:44:58 -0300507 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100508 numShownHotseatIcons =
509 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000510
Sunny Goyal19ff7282021-04-22 10:12:54 -0700511 numShownAllAppsColumns =
512 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100513
Thales Lima8e11d532023-08-31 13:40:26 +0000514 int hotseatBarBottomSpace;
Thales Limab8c05952022-05-23 16:58:38 +0100515 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
Thales Limaf8bfb032023-07-24 15:08:05 +0100516
517 if (mIsResponsiveGrid) {
518 HotseatSpecs hotseatSpecs =
519 HotseatSpecs.create(new ResourceHelper(context,
520 isTwoPanels ? inv.hotseatSpecsTwoPanelId : inv.hotseatSpecsId));
Thales Lima8e11d532023-08-31 13:40:26 +0000521 mResponsiveHotseatSpec =
522 isVerticalBarLayout() ? hotseatSpecs.getCalculatedWidthSpec(widthPx)
523 : hotseatSpecs.getCalculatedHeightSpec(heightPx);
Thales Limaf8bfb032023-07-24 15:08:05 +0100524 hotseatQsbSpace = mResponsiveHotseatSpec.getHotseatQsbSpace();
Thales Lima8e11d532023-08-31 13:40:26 +0000525 hotseatBarBottomSpace =
526 isVerticalBarLayout() ? 0 : mResponsiveHotseatSpec.getEdgePadding();
527 mHotseatBarEdgePaddingPx =
528 isVerticalBarLayout() ? mResponsiveHotseatSpec.getEdgePadding() : 0;
529 mHotseatBarWorkspaceSpacePx = 0;
Thales Limaf8bfb032023-07-24 15:08:05 +0100530 } else {
531 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
Thales Lima8e11d532023-08-31 13:40:26 +0000532 hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
533 mHotseatBarEdgePaddingPx =
534 isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
535 mHotseatBarWorkspaceSpacePx =
536 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Thales Limaf8bfb032023-07-24 15:08:05 +0100537 }
538
Thales Lima8e11d532023-08-31 13:40:26 +0000539 if (!isVerticalBarLayout()) {
540 // Have a little space between the inset and the QSB
541 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
542 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
Thales Limab8c05952022-05-23 16:58:38 +0100543
Thales Lima8e11d532023-08-31 13:40:26 +0000544 // Only change the spaces if there is space
545 if (availableSpace > 0) {
546 // Make sure there is enough space between hotseat/QSB and QSB/navBar
547 if (availableSpace < minQsbMargin * 2) {
548 minQsbMargin = availableSpace / 2;
549 hotseatQsbSpace = minQsbMargin;
550 } else {
551 hotseatQsbSpace -= minQsbMargin;
552 }
Thales Limab8c05952022-05-23 16:58:38 +0100553 }
Thales Lima8e11d532023-08-31 13:40:26 +0000554 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
Thales Limab8c05952022-05-23 16:58:38 +0100555
Thales Lima8e11d532023-08-31 13:40:26 +0000556 } else {
557 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
558 }
Thales Limaa1012902022-01-13 17:58:42 +0000559 }
Thales Lima425f6822022-05-10 13:44:58 -0300560
Pat Manningde25c0d2022-04-05 19:11:26 +0100561 springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
562 R.dimen.spring_loaded_hotseat_top_margin);
Thales Lima8e11d532023-08-31 13:40:26 +0000563 updateHotseatSizes(pxFromDp(inv.iconSize[mTypeIndex], mMetrics));
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700564 if (areNavButtonsInline && !isPhone) {
Jon Mirandae17a9492023-03-08 16:42:20 -0800565 inlineNavButtonsEndSpacingPx =
Thales Limaffc68b02023-01-09 16:20:23 +0000566 res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing);
Pat Manning26f70f72022-07-07 13:50:39 +0100567 /*
568 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700569 * Spacing between nav buttons +
Thales Lima6a590062022-11-22 15:52:49 +0000570 * Space at the end for contextual buttons
Pat Manning26f70f72022-07-07 13:50:39 +0100571 */
572 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700573 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
Jon Mirandae17a9492023-03-08 16:42:20 -0800574 + inlineNavButtonsEndSpacingPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100575 } else {
Jon Mirandae17a9492023-03-08 16:42:20 -0800576 inlineNavButtonsEndSpacingPx = 0;
Pat Manning26f70f72022-07-07 13:50:39 +0100577 hotseatBarEndOffset = 0;
578 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700579
Liran Binyamina833af32023-08-02 16:30:27 -0400580 mBubbleBarSpaceThresholdPx =
581 res.getDimensionPixelSize(R.dimen.bubblebar_hotseat_adjustment_threshold);
582
Thales Lima79456492023-05-23 11:32:22 +0100583 // Needs to be calculated after hotseatBarSizePx is correct,
584 // for the available height to be correct
585 if (mIsResponsiveGrid) {
Jordan Silva8bd7af22023-06-21 15:35:03 +0100586 WorkspaceSpecs workspaceSpecs = WorkspaceSpecs.create(
Jordan Silva575c3bd2023-07-21 12:00:43 +0100587 new ResourceHelper(context,
588 isTwoPanels ? inv.workspaceSpecsTwoPanelId : inv.workspaceSpecsId));
Thales Lima2759aa32023-06-05 16:25:45 +0100589 int availableResponsiveWidth =
590 availableWidthPx - (isVerticalBarLayout() ? hotseatBarSizePx : 0);
Jordan Silvac118fb52023-06-22 11:42:01 +0100591 int numColumns = getPanelCount() * inv.numColumns;
Thales Lima8e11d532023-08-31 13:40:26 +0000592 // don't use availableHeightPx because it subtracts mInsets.bottom
593 int availableResponsiveHeight = heightPx - mInsets.top
594 - (isVerticalBarLayout() ? 0 : hotseatBarSizePx);
Jordan Silvac118fb52023-06-22 11:42:01 +0100595 mResponsiveWidthSpec = workspaceSpecs.getCalculatedWidthSpec(numColumns,
Thales Lima2759aa32023-06-05 16:25:45 +0100596 availableResponsiveWidth);
Jordan Silva8bd7af22023-06-21 15:35:03 +0100597 mResponsiveHeightSpec = workspaceSpecs.getCalculatedHeightSpec(inv.numRows,
Thales Lima2759aa32023-06-05 16:25:45 +0100598 availableResponsiveHeight);
Thales Limaabfe3642023-05-24 18:08:53 +0100599
Jordan Silva8bd7af22023-06-21 15:35:03 +0100600 AllAppsSpecs allAppsSpecs = AllAppsSpecs.create(
Jordan Silva575c3bd2023-07-21 12:00:43 +0100601 new ResourceHelper(context,
602 isTwoPanels ? inv.allAppsSpecsTwoPanelId : inv.allAppsSpecsId));
Jordan Silvac118fb52023-06-22 11:42:01 +0100603 mAllAppsResponsiveWidthSpec = allAppsSpecs.getCalculatedWidthSpec(numColumns,
Thales Limaabfe3642023-05-24 18:08:53 +0100604 mResponsiveWidthSpec.getAvailableSpace(), mResponsiveWidthSpec);
Jordan Silva8bd7af22023-06-21 15:35:03 +0100605 mAllAppsResponsiveHeightSpec = allAppsSpecs.getCalculatedHeightSpec(inv.numRows,
606 mResponsiveHeightSpec.getAvailableSpace(), mResponsiveHeightSpec);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100607
Jordan Silva8bd7af22023-06-21 15:35:03 +0100608 FolderSpecs folderSpecs = FolderSpecs.create(
Jordan Silva575c3bd2023-07-21 12:00:43 +0100609 new ResourceHelper(context,
610 isTwoPanels ? inv.folderSpecsTwoPanelId : inv.folderSpecsId));
Jordan Silva8bd7af22023-06-21 15:35:03 +0100611 mResponsiveFolderWidthSpec = folderSpecs.getCalculatedWidthSpec(inv.numFolderColumns,
Jordan Silva637f4eb2023-06-13 11:21:53 +0100612 mResponsiveWidthSpec.getAvailableSpace(), mResponsiveWidthSpec);
Jordan Silva8bd7af22023-06-21 15:35:03 +0100613 mResponsiveFolderHeightSpec = folderSpecs.getCalculatedHeightSpec(inv.numFolderRows,
Jordan Silva637f4eb2023-06-13 11:21:53 +0100614 mResponsiveHeightSpec.getAvailableSpace(), mResponsiveHeightSpec);
Thales Lima79456492023-05-23 11:32:22 +0100615 }
616
617 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
618 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
619
Alex Chau635b3ab2022-01-26 16:49:10 +0000620 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chau5fd9d492021-07-22 17:27:11 +0100621 overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100622 overviewTaskIconDrawableSizePx =
623 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
624 overviewTaskIconDrawableSizeGridPx =
625 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700626 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx;
Andy Wickhambc3bac42023-08-07 16:02:23 -0700627 // Don't add margin with floating search bar to minimize risk of overlapping.
628 overviewActionsTopMarginPx = FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get() ? 0
629 : res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000630 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
631 overviewActionsButtonSpacing = res.getDimensionPixelSize(
632 R.dimen.overview_actions_button_spacing);
Andy Wickhambc3bac42023-08-07 16:02:23 -0700633 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700634 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000635 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700636
Jeremy Sim0ac47082022-10-10 13:59:40 -0700637 splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset);
638
Jon Miranda2ed276e2017-06-29 11:36:34 -0700639 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400640 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700641
Thales Lima79456492023-05-23 11:32:22 +0100642 calculateAndSetWorkspaceVerticalPadding(context, inv, extraSpace);
Pat Manning08610ca2022-04-05 21:03:16 +0100643
644 int cellLayoutPadding =
645 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
646 R.dimen.cell_layout_padding);
647 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
648 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800649 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800650
Thales Lima7eee74b2023-03-16 16:00:55 -0300651 // Folder scaling requires correct workspace paddings
652 updateAvailableFolderCellDimensions(res);
653
Thales Limaffc68b02023-01-09 16:20:23 +0000654 mMinHotseatIconSpacePx = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
655 mMinHotseatQsbWidthPx = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
656 mMaxHotseatIconSpacePx = areNavButtonsInline
Thales Lima6a590062022-11-22 15:52:49 +0000657 ? res.getDimensionPixelSize(R.dimen.max_hotseat_icon_space) : Integer.MAX_VALUE;
Thales Lima425f6822022-05-10 13:44:58 -0300658 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima6a590062022-11-22 15:52:49 +0000659 recalculateHotseatWidthAndBorderSpace();
Alex Chau206ede92022-08-01 17:46:12 +0100660
Jordan Silva3646a1b2023-08-02 13:52:52 +0100661 if (mIsResponsiveGrid && isVerticalBarLayout()) {
662 hotseatBorderSpace = cellLayoutBorderSpacePx.y;
663 }
664
Alex Chau206ede92022-08-01 17:46:12 +0100665 // AllApps height calculation depends on updated cellSize
666 if (isTablet) {
667 int collapseHandleHeight =
668 res.getDimensionPixelOffset(R.dimen.bottom_sheet_handle_area_height);
669 int contentHeight = heightPx - collapseHandleHeight - hotseatQsbHeight;
670 int targetContentHeight = (int) (allAppsCellHeightPx * ALL_APPS_TABLET_MAX_ROWS);
671 allAppsTopPadding = Math.max(mInsets.top, contentHeight - targetContentHeight);
672 allAppsShiftRange = heightPx - allAppsTopPadding;
673 } else {
674 allAppsTopPadding = 0;
675 allAppsShiftRange =
676 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
677 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100678 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
679 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300680
Alex Chaua02eddc2021-04-29 00:36:06 +0100681 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
682 R.dimen.drag_flingToDeleteMinVelocity);
683
Sihua Mae04aa202022-07-18 12:43:56 -0700684 mViewScaleProvider = viewScaleProvider;
685
Jon Miranda2b25ded2023-02-02 14:48:45 -0800686 dimensionOverrideProvider.accept(this);
687
Tony Wickham1237df02017-02-24 08:59:36 -0800688 // This is done last, after iconSizePx is calculated above.
Sunny Goyal799e1202023-02-09 10:54:28 -0800689 mDotRendererWorkSpace = createDotRenderer(context, iconSizePx, dotRendererCache);
690 mDotRendererAllApps = createDotRenderer(context, allAppsIconSizePx, dotRendererCache);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700691 }
692
693 private static DotRenderer createDotRenderer(
Sunny Goyal799e1202023-02-09 10:54:28 -0800694 @NonNull Context context, int size, @NonNull SparseArray<DotRenderer> cache) {
Sunny Goyal65190ae2022-08-02 14:16:26 -0700695 DotRenderer renderer = cache.get(size);
696 if (renderer == null) {
Sunny Goyal799e1202023-02-09 10:54:28 -0800697 renderer = new DotRenderer(size, getShapePath(context, DEFAULT_DOT_SIZE),
698 DEFAULT_DOT_SIZE);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700699 cache.put(size, renderer);
700 }
701 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700702 }
703
Thales Lima425f6822022-05-10 13:44:58 -0300704 /**
705 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
706 * width of the hotseat.
707 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100708 private int calculateQsbWidth(int hotseatBorderSpace) {
Thales Lima425f6822022-05-10 13:44:58 -0300709 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100710 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300711 return getIconToIconWidthForColumns(columns)
712 - iconSizePx * numShownHotseatIcons
713 - hotseatBorderSpace * numShownHotseatIcons;
714 } else {
715 int columns = inv.hotseatColumnSpan[mTypeIndex];
716 return getIconToIconWidthForColumns(columns);
717 }
718 }
Thales Lima2903a622022-03-17 13:52:19 +0000719
Thales Lima425f6822022-05-10 13:44:58 -0300720 private int getIconToIconWidthForColumns(int columns) {
721 return columns * getCellSize().x
722 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400723 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000724 }
725
Thales Limad90faab2021-09-21 17:18:47 +0100726 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
Thales Lima79456492023-05-23 11:32:22 +0100727 if (mIsResponsiveGrid) {
728 return mResponsiveWidthSpec.getStartPaddingPx();
729 }
730
Thales Limad90faab2021-09-21 17:18:47 +0100731 if (isVerticalBarLayout()) {
732 return 0;
733 }
734
Thales Lima79456492023-05-23 11:32:22 +0100735 return mIsScalableGrid
Thales Lima83bedbf2021-10-05 17:47:39 +0100736 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
737 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100738 }
739
Thales Lima79456492023-05-23 11:32:22 +0100740 private void calculateAndSetWorkspaceVerticalPadding(Context context,
741 InvariantDeviceProfile inv,
742 int extraSpace) {
743 if (mIsResponsiveGrid) {
744 workspaceTopPadding = mResponsiveHeightSpec.getStartPaddingPx();
745 workspaceBottomPadding = mResponsiveHeightSpec.getEndPaddingPx();
746 } else if (mIsScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
747 // Paddings were created assuming no scaling, so we first unscale the extra space.
748 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
749 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
750 DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
751 maxEmptySpace = padding.getMaxEmptySpacePx();
752
753 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
754 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
755
756 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
757 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
758 }
759 }
760
Thales Limab8c05952022-05-23 16:58:38 +0100761 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
762 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700763 // Ensure there is enough space for folder icons, which have a slightly larger radius.
Jordan Silva3646a1b2023-08-02 13:52:52 +0100764 hotseatCellHeightPx = getIconSizeWithOverlap(hotseatIconSizePx);
Thales Limab8c05952022-05-23 16:58:38 +0100765
Jon Miranda0d284852021-06-22 14:50:55 -0700766 if (isVerticalBarLayout()) {
Thales Lima8e11d532023-08-31 13:40:26 +0000767 hotseatBarSizePx = hotseatIconSizePx + mHotseatBarEdgePaddingPx
768 + mHotseatBarWorkspaceSpacePx;
Thales Limab8c05952022-05-23 16:58:38 +0100769 } else if (isQsbInline) {
770 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
771 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700772 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100773 hotseatBarSizePx = hotseatIconSizePx
774 + hotseatQsbSpace
775 + hotseatQsbVisualHeight
776 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700777 }
778 }
779
Thales Lima6a590062022-11-22 15:52:49 +0000780 /**
781 * Calculates the width of the hotseat, changing spaces between the icons and removing icons if
782 * necessary.
783 */
784 public void recalculateHotseatWidthAndBorderSpace() {
Thales Lima79456492023-05-23 11:32:22 +0100785 if (!mIsScalableGrid) return;
Thales Lima6a590062022-11-22 15:52:49 +0000786
787 int columns = inv.hotseatColumnSpan[mTypeIndex];
788 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
789 hotseatBorderSpace = calculateHotseatBorderSpace(hotseatWidthPx, /* numExtraBorder= */ 0);
Thales Lima9938c2f2022-07-25 14:38:16 +0100790 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
Thales Lima6a590062022-11-22 15:52:49 +0000791 // Spaces should be correct when the nav buttons are not inline
Thales Lima9938c2f2022-07-25 14:38:16 +0100792 if (!areNavButtonsInline) {
793 return;
794 }
795
Thales Lima6a590062022-11-22 15:52:49 +0000796 // The side space with inline buttons should be what is defined in InvariantDeviceProfile
Jon Mirandae17a9492023-03-08 16:42:20 -0800797 int sideSpacePx = inlineNavButtonsEndSpacingPx;
Thales Limaffc68b02023-01-09 16:20:23 +0000798 int maxHotseatWidthPx = availableWidthPx - sideSpacePx - hotseatBarEndOffset;
799 int maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
800 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000801 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100802
Thales Limaffc68b02023-01-09 16:20:23 +0000803 if (hotseatBorderSpace >= mMinHotseatIconSpacePx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100804 return;
805 }
806
807 // Border space can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000808 hotseatBorderSpace = mMinHotseatIconSpacePx;
Thales Lima6a590062022-11-22 15:52:49 +0000809 int requiredWidth = getHotseatRequiredWidth();
Thales Lima9938c2f2022-07-25 14:38:16 +0100810
811 // If there is an inline qsb, change its size
812 if (isQsbInline) {
Thales Limaffc68b02023-01-09 16:20:23 +0000813 hotseatQsbWidth -= requiredWidth - maxHotseatWidthPx;
814 if (hotseatQsbWidth >= mMinHotseatQsbWidthPx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100815 return;
816 }
817
818 // QSB can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000819 hotseatQsbWidth = mMinHotseatQsbWidthPx;
Thales Lima9938c2f2022-07-25 14:38:16 +0100820 }
821
Thales Limaffc68b02023-01-09 16:20:23 +0000822 maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
Thales Lima6a590062022-11-22 15:52:49 +0000823
Thales Lima9938c2f2022-07-25 14:38:16 +0100824 // If it still doesn't fit, start removing icons
825 do {
826 numShownHotseatIcons--;
Thales Limaffc68b02023-01-09 16:20:23 +0000827 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000828 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Limaffc68b02023-01-09 16:20:23 +0000829 } while (hotseatBorderSpace < mMinHotseatIconSpacePx && numShownHotseatIcons > 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100830 }
831
Thales Lima78d00ad2021-09-30 11:29:06 +0100832 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100833 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100834 }
835
836 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima79456492023-05-23 11:32:22 +0100837 int horizontalSpacePx = 0;
838 int verticalSpacePx = 0;
Thales Lima78d00ad2021-09-30 11:29:06 +0100839
Thales Lima79456492023-05-23 11:32:22 +0100840 if (mIsResponsiveGrid) {
841 horizontalSpacePx = mResponsiveWidthSpec.getGutterPx();
842 verticalSpacePx = mResponsiveHeightSpec.getGutterPx();
843 } else if (mIsScalableGrid) {
844 horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
845 verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
846 }
Thales Lima78d00ad2021-09-30 11:29:06 +0100847
848 return new Point(horizontalSpacePx, verticalSpacePx);
849 }
850
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700851 public Info getDisplayInfo() {
852 return mInfo;
853 }
854
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700855 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800856 WindowBounds bounds = new WindowBounds(
857 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700858 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100859 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700860
861 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
862 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
863 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
864
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700865 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700866 .setWindowBounds(bounds)
Alex Chauab800f72022-12-13 17:46:06 +0000867 .setIsMultiDisplay(isMultiDisplay)
Alex Chau6ed408f2022-03-04 12:58:05 +0000868 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700869 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000870 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800871 }
872
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700873 public DeviceProfile copy(Context context) {
874 return toBuilder(context).build();
875 }
876
877 /**
878 * TODO: Move this to the builder as part of setMultiWindowMode
879 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700880 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700881 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700882 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700883 .setMultiWindowMode(true)
884 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800885
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800886 // We use these scales to measure and layout the widgets using their full invariant profile
887 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
888 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
889 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700890 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
891 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
892 profile = profile.toBuilder(context)
893 .setViewScaleProvider(i -> p)
894 .build();
895 }
896
897 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800898
Jon Miranda93e1f042016-11-11 14:13:04 -0800899 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700900 }
901
Adam Cohen63f1ec02014-08-12 09:23:13 -0700902 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400903 * Checks if there is enough space for labels on the workspace.
904 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700905 * It is important to call this method after the All Apps variables have been set.
906 */
Jon Miranda941375e2021-03-31 13:10:45 -0400907 private void hideWorkspaceLabelsIfNotEnoughSpace() {
908 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
909 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
910 - iconTextHeight;
911
Jordan Silva3646a1b2023-08-02 13:52:52 +0100912 if (mIsResponsiveGrid) {
913 // Hide text only if doesn't fit inside the cell for responsive grid
914 if (workspaceCellPaddingY < 0) {
915 iconTextSizePx = 0;
916 iconDrawablePaddingPx = 0;
917 int iconSizeWithOverlap = getIconSizeWithOverlap(iconSizePx);
918 cellYPaddingPx = Math.max(0, getCellSize().y - iconSizeWithOverlap) / 2;
919 autoResizeAllAppsCells();
920 }
921
922 return;
923 }
924
Jon Miranda941375e2021-03-31 13:10:45 -0400925 // We want enough space so that the text is closer to its corresponding icon.
926 if (workspaceCellPaddingY < iconTextHeight) {
927 iconTextSizePx = 0;
928 iconDrawablePaddingPx = 0;
Jordan Silva3646a1b2023-08-02 13:52:52 +0100929 cellHeightPx = getIconSizeWithOverlap(iconSizePx);
Jon Miranda941375e2021-03-31 13:10:45 -0400930 autoResizeAllAppsCells();
931 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700932 }
Jon Miranda1091e532017-07-21 13:31:50 -0700933
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700934 /**
Jon Miranda228877d2021-02-09 11:05:00 -0500935 * Returns the amount of extra (or unused) vertical space.
936 */
937 private int updateAvailableDimensions(Resources res) {
Alex Chaua68164d2022-12-15 16:16:03 +0000938 float invIconSizeDp = inv.iconSize[mTypeIndex];
939 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
940 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
941 iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
Thales Lima79456492023-05-23 11:32:22 +0100942 iconCenterVertically = mIsScalableGrid || mIsResponsiveGrid;
Alex Chaua68164d2022-12-15 16:16:03 +0000943
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700944 updateIconSize(1f, res);
Pat Manning08610ca2022-04-05 21:03:16 +0100945 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -0500946
Alex Chau5225e832023-08-01 16:32:15 +0100947 if (mIsResponsiveGrid) {
948 return 0;
949 }
950
Jon Mirandae126d722021-02-25 10:45:20 -0500951 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +0100952 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +0000953 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -0500954 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500955 float scaleY = maxHeight / usedHeight;
956 boolean shouldScale = scaleY < 1f;
957
958 float scaleX = 1f;
Thales Lima79456492023-05-23 11:32:22 +0100959 if (mIsScalableGrid) {
Jon Mirandae126d722021-02-25 10:45:20 -0500960 // We scale to fit the cellWidth and cellHeight in the available space.
961 // The benefit of scalable grids is that we can get consistent aspect ratios between
962 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +0100963 float usedWidth =
964 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500965 // We do not subtract padding here, as we also scale the workspace padding if needed.
966 scaleX = availableWidthPx / usedWidth;
967 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700968 }
Jon Mirandae126d722021-02-25 10:45:20 -0500969
970 if (shouldScale) {
971 float scale = Math.min(scaleX, scaleY);
972 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +0100973 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -0500974 }
975
Jon Miranda228877d2021-02-09 11:05:00 -0500976 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700977 }
978
Pat Manninga2e14992022-04-22 11:29:17 +0100979 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +0100980 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
981 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
982 }
983
Pat Manninga2e14992022-04-22 11:29:17 +0100984 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +0000985 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +0100986 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
987 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -0500988 }
989
Thales Lima93ee8fc2023-06-05 17:07:11 +0100990 private int getNormalizedIconDrawablePadding() {
991 // TODO(b/235886078): workaround needed because of this bug
992 // Icons are 10% larger on XML than their visual size,
993 // so remove that extra space to get labels closer to the correct padding
994 int iconVisibleSizePx = (int) Math.round(ICON_VISIBLE_AREA_FACTOR * iconSizePx);
995 return Math.max(0, mIconDrawablePaddingOriginalPx - ((iconSizePx - iconVisibleSizePx) / 2));
996 }
997
998 private int getNormalizedFolderChildDrawablePaddingPx(int textHeight) {
999 // TODO(b/235886078): workaround needed because of this bug
1000 // Icons are 10% larger on XML than their visual size,
1001 // so remove that extra space to get labels closer to the correct padding
1002 int drawablePadding = (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3;
1003
1004 int iconVisibleSizePx = Math.round(ICON_VISIBLE_AREA_FACTOR * folderChildIconSizePx);
1005 int iconSizeDiff = folderChildIconSizePx - iconVisibleSizePx;
1006 return Math.max(0, drawablePadding - iconSizeDiff / 2);
1007 }
1008
Jordan Silva3646a1b2023-08-02 13:52:52 +01001009 private int getIconSizeWithOverlap(int iconSize) {
1010 return (int) Math.ceil(iconSize * ICON_OVERLAP_FACTOR);
1011 }
1012
Jon Miranda6f7e9702019-09-16 14:44:14 -07001013 /**
1014 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
1015 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
1016 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
1017 */
Tony Wickham7ba547c2021-02-02 17:12:08 -08001018 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -07001019 // Icon scale should never exceed 1, otherwise pixellation may occur.
1020 iconScale = Math.min(1f, scale);
1021 cellScaleToFit = scale;
1022
Jon Miranda18751b62017-07-31 17:25:27 -07001023 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -08001024 final boolean isVerticalLayout = isVerticalBarLayout();
Thales Lima080d8902022-03-28 15:30:29 +01001025 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -05001026
Thales Lima79456492023-05-23 11:32:22 +01001027 if (mIsResponsiveGrid) {
Thales Lima79456492023-05-23 11:32:22 +01001028 cellWidthPx = mResponsiveWidthSpec.getCellSizePx();
1029 cellHeightPx = mResponsiveHeightSpec.getCellSizePx();
Thales Lima79456492023-05-23 11:32:22 +01001030
Thales Lima2759aa32023-06-05 16:25:45 +01001031 if (cellWidthPx < iconSizePx) {
1032 // get a smaller icon size
1033 iconSizePx = mIconSizeSteps.getIconSmallerThan(cellWidthPx);
Thales Lima2759aa32023-06-05 16:25:45 +01001034 }
1035
Thales Lima8e11d532023-08-31 13:40:26 +00001036 // TODO(b/296400197): isVerticalBar shouldn't show labels anymore
Thales Lima93ee8fc2023-06-05 17:07:11 +01001037 iconDrawablePaddingPx = getNormalizedIconDrawablePadding();
1038 int iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
1039 int cellContentHeight = iconSizePx + iconDrawablePaddingPx + iconTextHeight;
1040
Thales Lima2759aa32023-06-05 16:25:45 +01001041 while (iconSizePx > mIconSizeSteps.minimumIconSize()
1042 && cellContentHeight > cellHeightPx) {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001043 iconDrawablePaddingPx -= cellContentHeight - cellHeightPx;
1044 if (iconDrawablePaddingPx < 0) {
Thales Lima2759aa32023-06-05 16:25:45 +01001045 // get a smaller icon size
1046 iconSizePx = mIconSizeSteps.getNextLowerIconSize(iconSizePx);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001047 iconDrawablePaddingPx = getNormalizedIconDrawablePadding();
Thales Lima2759aa32023-06-05 16:25:45 +01001048 }
1049 // calculate new cellContentHeight
Thales Lima93ee8fc2023-06-05 17:07:11 +01001050 cellContentHeight = iconSizePx + iconDrawablePaddingPx + iconTextHeight;
Thales Lima2759aa32023-06-05 16:25:45 +01001051 }
1052
1053 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Lima79456492023-05-23 11:32:22 +01001054 } else if (mIsScalableGrid) {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001055 iconDrawablePaddingPx = (int) (getNormalizedIconDrawablePadding() * iconScale);
Thales Lima83bedbf2021-10-05 17:47:39 +01001056 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
1057 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001058
1059 if (cellWidthPx < iconSizePx) {
1060 // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger.
1061 int numColumns = getPanelCount() * inv.numColumns;
1062 int numBorders = numColumns - 1;
1063 int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns;
1064 if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) {
1065 cellWidthPx = iconSizePx;
1066 cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders;
1067 } else {
1068 // If it still doesn't fit, set borderSpace to 0 and distribute the space for
1069 // cellWidth, and reduce iconSize.
1070 cellWidthPx = (cellWidthPx * numColumns
1071 + cellLayoutBorderSpacePx.x * numBorders) / numColumns;
1072 iconSizePx = Math.min(iconSizePx, cellWidthPx);
1073 cellLayoutBorderSpacePx.x = 0;
1074 }
1075 }
1076
Thales Lima93ee8fc2023-06-05 17:07:11 +01001077 int cellTextAndPaddingHeight =
1078 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +00001079 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
1080 if (cellHeightPx < cellContentHeight) {
1081 // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight
1082 // bigger.
1083 int numBorders = inv.numRows - 1;
1084 int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows;
1085 if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) {
1086 cellHeightPx = cellContentHeight;
1087 cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders;
1088 } else {
Alex Chau06f36e82023-01-06 10:50:54 +00001089 // If it still doesn't fit, set borderSpace to 0 to recover space.
Alex Chaube753132022-12-09 16:46:54 +00001090 cellHeightPx = (cellHeightPx * inv.numRows
1091 + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows;
Alex Chaube753132022-12-09 16:46:54 +00001092 cellLayoutBorderSpacePx.y = 0;
Alex Chau06f36e82023-01-06 10:50:54 +00001093 // Reduce iconDrawablePaddingPx to make cellContentHeight smaller.
1094 int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx;
1095 if (cellContentWithoutPadding <= cellHeightPx) {
1096 iconDrawablePaddingPx = cellContentHeight - cellHeightPx;
1097 } else {
1098 // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space,
1099 // then proportional reduce iconSizePx and iconTextSizePx to fit.
1100 iconDrawablePaddingPx = 0;
1101 float ratio = cellHeightPx / (float) cellContentWithoutPadding;
1102 iconSizePx = (int) (iconSizePx * ratio);
1103 iconTextSizePx = (int) (iconTextSizePx * ratio);
1104 }
1105 cellTextAndPaddingHeight =
1106 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +00001107 }
1108 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
1109 }
Jon Mirandae126d722021-02-25 10:45:20 -05001110 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +01001111 desiredWorkspaceHorizontalMarginPx =
1112 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -05001113 } else {
Thales Lima93ee8fc2023-06-05 17:07:11 +01001114 iconDrawablePaddingPx = (int) (getNormalizedIconDrawablePadding() * iconScale);
Jon Mirandae126d722021-02-25 10:45:20 -05001115 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001116 cellHeightPx = getIconSizeWithOverlap(iconSizePx)
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001117 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -05001118 + Utilities.calculateTextHeight(iconTextSizePx);
1119 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
1120 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
1121 && !isMultiWindowMode) {
1122 // Ensures that the label is closer to its corresponding icon. This is not an issue
1123 // with vertical bar layout or multi-window mode since the issue is handled
1124 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
1125 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
1126 iconDrawablePaddingPx = cellPaddingY;
1127 }
Jon Miranda846455e2017-10-02 14:58:52 -07001128 }
Jon Miranda18751b62017-07-31 17:25:27 -07001129
Sunny Goyalae190ff2020-04-14 00:19:01 +00001130 // All apps
Thales Limaabfe3642023-05-24 18:08:53 +01001131 if (mIsResponsiveGrid) {
1132 updateAllAppsWithResponsiveMeasures();
1133 } else {
1134 updateAllAppsIconSize(scale, res);
1135 }
1136 updateAllAppsContainerWidth();
1137 if (isVerticalBarLayout()) {
1138 hideWorkspaceLabelsIfNotEnoughSpace();
1139 }
Winson Chungb3800242013-10-24 11:01:54 -07001140
Thales Limab8c05952022-05-23 16:58:38 +01001141 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -07001142
Sunny Goyalbaec6ff2016-09-14 11:26:21 -07001143 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -07001144 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
1145 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Sunny Goyal6c304b12023-04-10 12:03:04 -07001146
1147 // Update widget padding:
1148 float minSpacing = pxFromDp(MIN_WIDGET_PADDING_DP, mMetrics);
1149 if (cellLayoutBorderSpacePx.x < minSpacing
1150 || cellLayoutBorderSpacePx.y < minSpacing) {
1151 widgetPadding.left = widgetPadding.right =
1152 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.x));
1153 widgetPadding.top = widgetPadding.bottom =
1154 Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.y));
1155 } else {
1156 widgetPadding.setEmpty();
1157 }
Winson Chung0f785722015-04-08 10:27:49 -07001158 }
1159
Thales Lima425f6822022-05-10 13:44:58 -03001160 /**
Thales Lima6a590062022-11-22 15:52:49 +00001161 * This method calculates the space between the icons to achieve a certain width.
Thales Lima425f6822022-05-10 13:44:58 -03001162 */
Thales Lima6a590062022-11-22 15:52:49 +00001163 private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) {
Jordan Silvad9227182023-08-17 15:53:59 +01001164 int numBorders = (numShownHotseatIcons - 1 + numExtraBorder);
1165 if (numBorders <= 0) return 0;
1166
Thales Lima9938c2f2022-07-25 14:38:16 +01001167 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
Jordan Silvad9227182023-08-17 15:53:59 +01001168 int hotseatBorderSpacePx = (int) (hotseatWidthPx - hotseatIconsTotalPx) / numBorders;
Thales Limaffc68b02023-01-09 16:20:23 +00001169 return Math.min(hotseatBorderSpacePx, mMaxHotseatIconSpacePx);
Thales Lima425f6822022-05-10 13:44:58 -03001170 }
1171
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001172 /**
1173 * Updates the iconSize for allApps* variants.
1174 */
Brian Isganitisa9a78112022-05-23 18:11:47 -07001175 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +01001176 allAppsBorderSpacePx = new Point(
1177 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
1178 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001179 // AllApps cells don't have real space between cells,
1180 // so we add the border space to the cell height
Alex Chaube753132022-12-09 16:46:54 +00001181 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics)
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001182 + allAppsBorderSpacePx.y;
1183 // but width is just the cell,
1184 // the border is added in #updateAllAppsContainerWidth
Thales Lima79456492023-05-23 11:32:22 +01001185 if (mIsScalableGrid) {
Alex Chaube753132022-12-09 16:46:54 +00001186 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1187 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
Thales Lima93ee8fc2023-06-05 17:07:11 +01001188 allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding();
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001189 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001190
1191 if (allAppsCellWidthPx < allAppsIconSizePx) {
1192 // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to
1193 // make allAppsCellWidth bigger.
1194 int numBorders = inv.numAllAppsColumns - 1;
1195 int extraWidthRequired =
1196 (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns;
1197 if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) {
1198 allAppsCellWidthPx = allAppsIconSizePx;
1199 allAppsBorderSpacePx.x -= extraWidthRequired / numBorders;
1200 } else {
1201 // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space
1202 // for allAppsCellWidth, and reduce allAppsIconSize.
1203 allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns
1204 + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns;
1205 allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx);
1206 allAppsBorderSpacePx.x = 0;
1207 }
1208 }
1209
1210 int cellContentHeight = allAppsIconSizePx
1211 + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y;
1212 if (allAppsCellHeightPx < cellContentHeight) {
1213 // Increase allAppsCellHeight to fit its content.
1214 allAppsCellHeightPx = cellContentHeight;
1215 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001216 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001217 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
1218 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001219 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1220 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001221 allAppsIconDrawablePaddingPx =
1222 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001223 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001224 }
Thales Limaabfe3642023-05-24 18:08:53 +01001225 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001226
Thales Limaabfe3642023-05-24 18:08:53 +01001227 private void updateAllAppsWithResponsiveMeasures() {
1228 allAppsIconSizePx = iconSizePx;
1229 allAppsIconTextSizePx = iconTextSizePx;
Thales Lima93ee8fc2023-06-05 17:07:11 +01001230 allAppsIconDrawablePaddingPx = iconDrawablePaddingPx;
Thales Limaabfe3642023-05-24 18:08:53 +01001231
1232 allAppsBorderSpacePx = new Point(
1233 mAllAppsResponsiveWidthSpec.getGutterPx(),
1234 mAllAppsResponsiveHeightSpec.getGutterPx()
1235 );
1236 allAppsCellHeightPx = mAllAppsResponsiveHeightSpec.getCellSizePx()
1237 + mAllAppsResponsiveHeightSpec.getGutterPx();
1238 allAppsCellWidthPx = mAllAppsResponsiveWidthSpec.getCellSizePx();
1239 allAppsLeftRightPadding = mAllAppsResponsiveWidthSpec.getStartPaddingPx();
1240 }
1241
1242 /**
1243 * Re-computes the all-apps cell size to be independent of workspace
1244 */
1245 public void autoResizeAllAppsCells() {
1246 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
1247 int topBottomPadding = textHeight;
1248 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
1249 + textHeight + (topBottomPadding * 2);
1250 }
1251
1252 private void updateAllAppsContainerWidth() {
1253 int cellLayoutHorizontalPadding =
1254 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
1255 if (isTablet) {
1256 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
1257 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
1258 + allAppsLeftRightPadding * 2;
1259 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
1260 } else {
1261 allAppsLeftRightPadding =
1262 Math.max(0, desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding
1263 - (allAppsBorderSpacePx.x / 2));
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001264 }
1265 }
1266
Thales Limaabfe3642023-05-24 18:08:53 +01001267 private void setupAllAppsStyle(Context context) {
1268 TypedArray allAppsStyle = context.obtainStyledAttributes(
1269 inv.allAppsStyle != INVALID_RESOURCE_HANDLE ? inv.allAppsStyle
1270 : R.style.AllAppsStyleDefault, R.styleable.AllAppsStyle);
1271
1272 allAppsLeftRightPadding = allAppsStyle.getDimensionPixelSize(
1273 R.styleable.AllAppsStyle_horizontalPadding, 0);
1274 allAppsStyle.recycle();
1275 }
1276
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001277 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001278 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001279
Jordan Silva637f4eb2023-06-13 11:21:53 +01001280 // Responsive grid doesn't need to scale the folder
1281 if (mIsResponsiveGrid) return;
1282
Thales Lima7eee74b2023-03-16 16:00:55 -03001283 // For usability we can't have the folder use the whole width of the screen
Sunny Goyal07b69292018-01-08 14:19:34 -08001284 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -08001285
Thales Lima7eee74b2023-03-16 16:00:55 -03001286 // Check if the folder fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -05001287 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Jordan Silva637f4eb2023-06-13 11:21:53 +01001288 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx.y)
Thales Lima7eee74b2023-03-16 16:00:55 -03001289 + folderFooterHeightPx
1290 + folderContentPaddingTop;
1291 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001292 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -08001293
Thales Lima7eee74b2023-03-16 16:00:55 -03001294 // Check if the folder fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -05001295 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Jordan Silva637f4eb2023-06-13 11:21:53 +01001296 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x)
Thales Lima7eee74b2023-03-16 16:00:55 -03001297 + folderContentPaddingLeftRight * 2;
1298 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001299 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -08001300
1301 float scale = Math.min(scaleX, scaleY);
1302 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001303 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001304 }
1305 }
1306
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001307 private void updateFolderCellSize(float scale, Resources res) {
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001308 float invIconSizeDp = inv.iconSize[mTypeIndex];
Sunny Goyal35c7b192021-04-20 16:51:10 -07001309 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001310 folderChildTextSizePx = pxFromSp(inv.iconTextSize[mTypeIndex], mMetrics, scale);
Thales Lima7eee74b2023-03-16 16:00:55 -03001311 folderLabelTextSizePx = Math.max(pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale),
Thales Limab35faed2022-09-05 16:30:01 -03001312 (int) (folderChildTextSizePx * folderLabelTextScale));
Jon Mirandabf7d8122016-11-03 15:29:29 -07001313
1314 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001315
Jordan Silva637f4eb2023-06-13 11:21:53 +01001316 if (mIsResponsiveGrid) {
1317 folderCellWidthPx = mResponsiveFolderWidthSpec.getCellSizePx();
1318
1319 // Height
1320 folderCellHeightPx = mResponsiveFolderHeightSpec.getCellSizePx();
1321 folderContentPaddingTop = mResponsiveFolderHeightSpec.getStartPaddingPx();
1322 folderFooterHeightPx = mResponsiveFolderHeightSpec.getEndPaddingPx();
1323
1324 folderCellLayoutBorderSpacePx = new Point(mResponsiveFolderWidthSpec.getGutterPx(),
Thales Lima4cfd9502023-07-10 14:01:28 +01001325 mResponsiveFolderHeightSpec.getGutterPx());
Jordan Silva637f4eb2023-06-13 11:21:53 +01001326
1327 folderContentPaddingLeftRight = mResponsiveFolderWidthSpec.getStartPaddingPx();
Jordan Silva12fae112023-06-26 12:51:01 +01001328
1329 // Reduce icon width if it's wider than the expected folder cell width
1330 if (folderCellWidthPx < folderChildIconSizePx) {
1331 folderChildIconSizePx = mIconSizeSteps.getIconSmallerThan(folderCellWidthPx);
1332 }
1333
1334 // Recalculating padding and cell height
1335 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
1336 int folderCellContentHeight = folderChildIconSizePx + folderChildDrawablePaddingPx
1337 + textHeight;
1338
1339 // Reduce the icon in height when it's taller than the expected cell height
1340 while (folderChildIconSizePx > mIconSizeSteps.minimumIconSize()
1341 && folderCellContentHeight > folderCellHeightPx) {
1342 folderChildDrawablePaddingPx -= folderCellContentHeight - folderCellHeightPx;
1343 if (folderChildDrawablePaddingPx < 0) {
1344 // get a smaller icon size
1345 folderChildIconSizePx = mIconSizeSteps.getNextLowerIconSize(
1346 folderChildIconSizePx);
1347 folderChildDrawablePaddingPx =
1348 getNormalizedFolderChildDrawablePaddingPx(textHeight);
1349 }
1350 // calculate new cellContentHeight
1351 folderCellContentHeight = folderChildIconSizePx + folderChildDrawablePaddingPx
1352 + textHeight;
1353 }
Jordan Silva637f4eb2023-06-13 11:21:53 +01001354 } else if (mIsScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001355 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
Thales Lima7eee74b2023-03-16 16:00:55 -03001356 folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale);
1357 folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale);
1358 } else {
1359 folderCellWidthPx = roundPxValueFromFloat(folderCellWidthPx * scale);
1360 folderCellHeightPx = roundPxValueFromFloat(folderCellHeightPx * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001361 }
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001362
Thales Lima7eee74b2023-03-16 16:00:55 -03001363 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Jordan Silva637f4eb2023-06-13 11:21:53 +01001364 folderCellLayoutBorderSpacePx = new Point(
1365 roundPxValueFromFloat(folderCellLayoutBorderSpacePx.x * scale),
1366 roundPxValueFromFloat(folderCellLayoutBorderSpacePx.y * scale)
1367 );
Thales Lima7eee74b2023-03-16 16:00:55 -03001368 folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale);
1369
Jordan Silva637f4eb2023-06-13 11:21:53 +01001370 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx.x;
Jordan Silva12fae112023-06-26 12:51:01 +01001371
1372 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
Jon Miranda823da222021-03-23 08:08:45 -04001373 } else {
1374 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1375 * scale);
1376 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1377 * scale);
1378
1379 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1380 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Lima7eee74b2023-03-16 16:00:55 -03001381 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001382 folderContentPaddingLeftRight =
1383 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1384 folderFooterHeightPx =
Thales Lima7eee74b2023-03-16 16:00:55 -03001385 roundPxValueFromFloat(
1386 res.getDimensionPixelSize(R.dimen.folder_footer_height_default)
1387 * scale);
1388
Jordan Silva12fae112023-06-26 12:51:01 +01001389 folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight);
Jon Miranda823da222021-03-23 08:08:45 -04001390 }
Jon Mirandabf7d8122016-11-03 15:29:29 -07001391 }
1392
Winson1f064272016-07-18 17:18:02 -07001393 public void updateInsets(Rect insets) {
1394 mInsets.set(insets);
1395 }
1396
Sunny Goyalae6e3182019-04-30 12:04:37 -07001397 /**
1398 * The current device insets. This is generally same as the insets being dispatched to
1399 * {@link Insettable} elements, but can differ if the element is using a different profile.
1400 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001401 public Rect getInsets() {
1402 return mInsets;
1403 }
1404
Sunny Goyal756cd262015-08-20 12:33:21 -07001405 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001406 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001407 }
1408
Sunny Goyal19ff7282021-04-22 10:12:54 -07001409 public Point getCellSize(Point result) {
1410 if (result == null) {
1411 result = new Point();
1412 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001413
Pat Manning25d53342022-05-10 09:58:49 +00001414 int shortcutAndWidgetContainerWidth =
1415 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1416 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1417 inv.numColumns);
1418 int shortcutAndWidgetContainerHeight =
1419 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1420 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1421 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001422 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001423 }
1424
1425 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001426 * Returns the left and right space on the cell, which is the cell width - icon size
1427 */
1428 public int getCellHorizontalSpace() {
1429 return getCellSize().x - iconSizePx;
1430 }
1431
1432 /**
Pat Manning25d53342022-05-10 09:58:49 +00001433 * Gets the number of panels within the workspace.
1434 */
1435 public int getPanelCount() {
1436 return isTwoPanels ? 2 : 1;
1437 }
1438
1439 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001440 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1441 * bottom of the screen.
1442 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001443 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1444 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001445 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001446 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001447 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001448 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001449 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001450 }
1451
1452 /**
1453 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1454 */
Pat Manning25d53342022-05-10 09:58:49 +00001455 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001456 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001457 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001458 }
1459
1460 /**
1461 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1462 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001463 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001464 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001465 return heightPx - (isVerticalBarLayout()
1466 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001467 }
1468
Pat Manningea5c1d22022-04-14 10:58:16 +01001469 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001470 * Gets the scale of the workspace for the spring-loaded edit state.
1471 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001472 public float getWorkspaceSpringLoadScale(Context context) {
1473 float scale =
1474 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1475 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001476 scale = Math.min(scale, 1f);
1477
Pat Manninge63dd252022-08-02 16:15:29 +01001478 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001479 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001480 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001481 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001482 if (scaledWorkspaceWidth > maxAvailableWidth) {
1483 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1484 }
1485 return scale;
1486 }
1487
Pat Manning25d53342022-05-10 09:58:49 +00001488 /**
1489 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1490 *
1491 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1492 * layouts have two Cell Layouts per workspace.
1493 */
1494 public int getCellLayoutWidth() {
1495 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001496 }
1497
Pat Manning25d53342022-05-10 09:58:49 +00001498 /**
1499 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1500 *
1501 * <p>This is the height of a Workspace, less its vertical padding.
1502 */
1503 public int getCellLayoutHeight() {
1504 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001505 }
1506
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001507 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001508 return new Point(workspacePadding.left + workspacePadding.right,
1509 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001510 }
1511
1512 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001513 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1514 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001515 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001516 private void updateWorkspacePadding() {
1517 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001518 if (isVerticalBarLayout()) {
Jordan Silva3646a1b2023-08-02 13:52:52 +01001519 if (mIsResponsiveGrid) {
1520 padding.top = mResponsiveHeightSpec.getStartPaddingPx();
Thales Lima8e11d532023-08-31 13:40:26 +00001521 padding.bottom = Math.max(0,
1522 mResponsiveHeightSpec.getEndPaddingPx() - mInsets.bottom);
Jordan Silva3646a1b2023-08-02 13:52:52 +01001523 if (isSeascape()) {
1524 padding.left = hotseatBarSizePx + mResponsiveWidthSpec.getEndPaddingPx();
1525 padding.right = mResponsiveWidthSpec.getStartPaddingPx();
1526 } else {
1527 padding.left = mResponsiveWidthSpec.getStartPaddingPx();
1528 padding.right = hotseatBarSizePx + mResponsiveWidthSpec.getEndPaddingPx();
1529 }
Winson1f064272016-07-18 17:18:02 -07001530 } else {
Jordan Silva3646a1b2023-08-02 13:52:52 +01001531 padding.top = 0;
1532 padding.bottom = edgeMarginPx;
1533 if (isSeascape()) {
1534 padding.left = hotseatBarSizePx;
Thales Lima8e11d532023-08-31 13:40:26 +00001535 padding.right = mHotseatBarEdgePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001536 } else {
Thales Lima8e11d532023-08-31 13:40:26 +00001537 padding.left = mHotseatBarEdgePaddingPx;
Jordan Silva3646a1b2023-08-02 13:52:52 +01001538 padding.right = hotseatBarSizePx;
1539 }
Winson1f064272016-07-18 17:18:02 -07001540 }
Winson Chungb3800242013-10-24 11:01:54 -07001541 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001542 // Pad the bottom of the workspace with hotseat bar
1543 // and leave a bit of space in case a widget go all the way down
Thales Lima79456492023-05-23 11:32:22 +01001544 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding - mInsets.bottom;
1545 if (!mIsResponsiveGrid) {
1546 paddingBottom +=
1547 workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace;
1548 }
1549 int paddingTop = workspaceTopPadding + (mIsScalableGrid ? 0 : edgeMarginPx);
Pat Manning08610ca2022-04-05 21:03:16 +01001550 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001551
Pat Manning08610ca2022-04-05 21:03:16 +01001552 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001553 }
Pat Manning08610ca2022-04-05 21:03:16 +01001554 insetPadding(workspacePadding, cellLayoutPaddingPx);
1555 }
1556
1557 private void insetPadding(Rect paddings, Rect insets) {
1558 insets.left = Math.min(insets.left, paddings.left);
1559 paddings.left -= insets.left;
1560
1561 insets.top = Math.min(insets.top, paddings.top);
1562 paddings.top -= insets.top;
1563
1564 insets.right = Math.min(insets.right, paddings.right);
1565 paddings.right -= insets.right;
1566
1567 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1568 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001569 }
1570
Liran Binyamina833af32023-08-02 16:30:27 -04001571
1572 /**
1573 * Returns the new border space that should be used between hotseat icons after adjusting it to
1574 * the bubble bar.
1575 *
1576 * <p>If there's no adjustment needed, this method returns {@code 0}.
1577 */
1578 public float getHotseatAdjustedBorderSpaceForBubbleBar(Context context) {
1579 // only need to adjust when QSB is on top of the hotseat.
1580 if (isQsbInline) {
1581 return 0;
1582 }
1583
1584 // no need to adjust if there's enough space for the bubble bar to the right of the hotseat.
1585 if (getHotseatLayoutPadding(context).right > mBubbleBarSpaceThresholdPx) {
1586 return 0;
1587 }
1588
1589 // The adjustment is shrinking the hotseat's width by 1 icon on either side.
1590 int iconsWidth =
1591 iconSizePx * numShownHotseatIcons + hotseatBorderSpace * (numShownHotseatIcons - 1);
1592 int newWidth = iconsWidth - 2 * iconSizePx;
1593 // Evenly space the icons within the boundaries of the new width.
1594 return (float) (newWidth - iconSizePx * numShownHotseatIcons) / (numShownHotseatIcons - 1);
1595 }
1596
Sunny Goyal57b22792021-05-25 14:35:01 -07001597 /**
1598 * Returns the padding for hotseat view
1599 */
1600 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001601 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001602 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001603 // The hotseat icons will be placed in the middle of the hotseat cells.
1604 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1605 // in vertical bar layout.
1606 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1607 // is set to account for that difference.
Jordan Silva3646a1b2023-08-02 13:52:52 +01001608 float diffOverlapFactor = mIsResponsiveGrid ? 0
1609 : iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
1610
Pat Manning08610ca2022-04-05 21:03:16 +01001611 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1612 - diffOverlapFactor), 0);
1613 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001614 + diffOverlapFactor), 0);
1615
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001616 if (isSeascape()) {
Thales Lima8e11d532023-08-31 13:40:26 +00001617 hotseatBarPadding.set(mInsets.left + mHotseatBarEdgePaddingPx, paddingTop,
1618 mHotseatBarWorkspaceSpacePx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001619 } else {
Thales Lima8e11d532023-08-31 13:40:26 +00001620 hotseatBarPadding.set(mHotseatBarWorkspaceSpacePx, paddingTop,
1621 mInsets.right + mHotseatBarEdgePaddingPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001622 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001623 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001624 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001625 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1626 int hotseatBarTopPadding =
1627 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001628
Thales Lima6a590062022-11-22 15:52:49 +00001629 int hotseatWidth = getHotseatRequiredWidth();
Helen Cheuke76291f2023-02-14 17:11:05 +00001630 int startSpacing;
1631 int endSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001632 // Hotseat aligns to the left with nav buttons
1633 if (hotseatBarEndOffset > 0) {
Jon Mirandae17a9492023-03-08 16:42:20 -08001634 startSpacing = inlineNavButtonsEndSpacingPx;
Helen Cheuke76291f2023-02-14 17:11:05 +00001635 endSpacing = availableWidthPx - hotseatWidth - startSpacing + hotseatBorderSpace;
1636 } else {
1637 startSpacing = (availableWidthPx - hotseatWidth) / 2;
1638 endSpacing = startSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001639 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001640 startSpacing += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001641
Helen Cheuke76291f2023-02-14 17:11:05 +00001642 hotseatBarPadding.top = hotseatBarTopPadding;
1643 hotseatBarPadding.bottom = hotseatBarBottomPadding;
Alex Chau51da2192022-05-20 13:32:10 +01001644 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001645 if (isRtl) {
Helen Cheuke76291f2023-02-14 17:11:05 +00001646 hotseatBarPadding.left = endSpacing;
1647 hotseatBarPadding.right = startSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001648 } else {
Helen Cheuke76291f2023-02-14 17:11:05 +00001649 hotseatBarPadding.left = startSpacing;
1650 hotseatBarPadding.right = endSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001651 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001652
Thales Lima79456492023-05-23 11:32:22 +01001653 } else if (mIsScalableGrid) {
Alex Chau206ede92022-08-01 17:46:12 +01001654 int sideSpacing = (availableWidthPx - hotseatQsbWidth) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001655 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001656 0,
Thales Lima425f6822022-05-10 13:44:58 -03001657 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001658 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001659 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001660 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1661 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1662 // for this, we pad the left and right of the hotseat with half of the difference of a
1663 // workspace cell vs a hotseat cell.
1664 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001665 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001666 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001667 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001668 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1669 + mInsets.left,
1670 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001671 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001672 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001673 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001674 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001675 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001676 }
1677
Andy Wickhambd9a1802023-06-08 16:33:15 -07001678 /** The margin between the edge of all apps and the edge of the first icon. */
1679 public int getAllAppsIconStartMargin() {
1680 int allAppsSpacing;
1681 if (isVerticalBarLayout()) {
1682 // On phones, the landscape layout uses a different setup.
1683 allAppsSpacing = workspacePadding.left + workspacePadding.right;
1684 } else {
1685 allAppsSpacing = allAppsLeftRightPadding * 2 + allAppsLeftRightMargin * 2;
1686 }
1687
1688 int cellWidth = DeviceProfile.calculateCellWidth(
1689 availableWidthPx - allAppsSpacing,
1690 0 /* borderSpace */,
1691 numShownAllAppsColumns);
1692 int iconVisibleSize = Math.round(ICON_VISIBLE_AREA_FACTOR * allAppsIconSizePx);
1693 int iconAlignmentMargin = (cellWidth - iconVisibleSize) / 2;
1694 return allAppsLeftRightPadding + iconAlignmentMargin;
1695 }
1696
Thales Lima9938c2f2022-07-25 14:38:16 +01001697 private int getAdditionalQsbSpace() {
1698 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1699 }
1700
1701 /**
1702 * Calculate how much space the hotseat needs to be shown completely
1703 */
1704 private int getHotseatRequiredWidth() {
1705 int additionalQsbSpace = getAdditionalQsbSpace();
1706 return iconSizePx * numShownHotseatIcons
Thales Lima6a590062022-11-22 15:52:49 +00001707 + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1))
Thales Lima9938c2f2022-07-25 14:38:16 +01001708 + additionalQsbSpace;
1709 }
1710
Winsonfadbe8f2016-07-22 16:35:37 -07001711 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001712 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1713 */
1714 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001715 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001716 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1717 } else if (isTaskbarPresent) { // QSB on top
1718 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001719 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001720 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001721 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001722 }
1723
Thales Limab8c05952022-05-23 16:58:38 +01001724 /**
1725 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1726 */
1727 private int getHotseatBarBottomPadding() {
1728 if (isTaskbarPresent) { // QSB on top or inline
1729 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001730 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001731 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001732 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001733 }
1734
1735 /**
Alex Chau51da2192022-05-20 13:32:10 +01001736 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1737 */
1738 public int getTaskbarOffsetY() {
Jon Miranda9c478b62023-03-23 21:38:49 -07001739 int taskbarIconBottomSpace = (taskbarHeight - iconSizePx) / 2;
Alex Chau51da2192022-05-20 13:32:10 +01001740 int launcherIconBottomSpace =
1741 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001742 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001743 }
1744
1745 /**
Alex Chaua2fc7642022-04-21 14:20:23 +01001746 * Returns the number of pixels required below OverviewActions excluding insets.
1747 */
1748 public int getOverviewActionsClaimedSpaceBelow() {
Alex Chaud67ddc42022-09-30 18:15:56 +01001749 if (isTaskbarPresent) {
Jon Miranda9c478b62023-03-23 21:38:49 -07001750 return taskbarHeight + taskbarBottomMargin * 2;
Alex Chaud67ddc42022-09-30 18:15:56 +01001751 }
1752 return mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001753 }
1754
1755 /** Gets the space that the overview actions will take, including bottom margin. */
1756 public int getOverviewActionsClaimedSpace() {
Pat Manning7b8f7662023-01-18 14:48:30 +00001757 int overviewActionsSpace = isTablet && FeatureFlags.ENABLE_GRID_ONLY_OVERVIEW.get()
1758 ? 0
1759 : (overviewActionsTopMarginPx + overviewActionsHeight);
1760 return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
Alex Chaua2fc7642022-04-21 14:20:23 +01001761 }
1762
1763 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001764 * Takes the View and return the scales of width and height depending on the DeviceProfile
1765 * specifications
1766 *
1767 * @param itemInfo The tag of the widget view
1768 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1769 * height
1770 */
1771 @NonNull
1772 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1773 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1774 }
1775
1776 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001777 * @return the bounds for which the open folders should be contained within
1778 */
1779 public Rect getAbsoluteOpenFolderBounds() {
1780 if (isVerticalBarLayout()) {
1781 // Folders should only appear right of the drop target bar and left of the hotseat
1782 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1783 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001784 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001785 mInsets.top + availableHeightPx);
1786 } else {
1787 // Folders should only appear below the drop target bar and above the hotseat
Jon Miranda9c478b62023-03-23 21:38:49 -07001788 int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001789 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001790 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001791 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001792 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001793 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001794 }
1795 }
1796
Jon Miranda228877d2021-02-09 11:05:00 -05001797 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1798 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001799 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001800
Jon Miranda228877d2021-02-09 11:05:00 -05001801 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1802 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001803 }
1804
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001805 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001806 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1807 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1808 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001809 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001810 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001811 return isLandscape && transposeLayoutWithOrientation;
1812 }
1813
Sunny Goyal59d086c2018-05-07 17:31:40 -07001814 /**
1815 * Updates orientation information and returns true if it has changed from the previous value.
1816 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001817 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001818 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001819 boolean isSeascape = DisplayController.INSTANCE.get(context)
1820 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001821 if (mIsSeascape != isSeascape) {
1822 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001823 // Hotseat changing sides requires updating workspace left/right paddings
1824 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001825 return true;
1826 }
1827 }
1828 return false;
1829 }
1830
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001831 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001832 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001833 }
1834
Sunny Goyal07b69292018-01-08 14:19:34 -08001835 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001836 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001837 }
1838
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001839 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001840 switch (containerType) {
1841 case CellLayout.WORKSPACE:
1842 return cellHeightPx;
1843 case CellLayout.FOLDER:
1844 return folderCellHeightPx;
1845 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001846 // The hotseat is the only container where the cell height is going to be
1847 // different from the content within that cell.
1848 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001849 default:
1850 // ??
1851 return 0;
1852 }
1853 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001854
Jon Miranda58561d42021-03-17 10:51:54 -04001855 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001856 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001857 }
1858
Alex Chaue818bcb2022-09-02 17:27:11 +01001859 private String dpPointFToString(String name, PointF value) {
1860 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
1861 }
1862
Pat Manning5f74bfd2022-07-20 12:08:54 +01001863 /** Dumps various DeviceProfile variables to the specified writer. */
1864 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04001865 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001866 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001867
1868 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001869 writer.println(prefix + "\tisPhone:" + isPhone);
1870 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1871 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001872 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001873
1874 writer.println(prefix + "\tisLandscape:" + isLandscape);
1875 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001876 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001877
1878 writer.println(prefix + pxToDpStr("windowX", windowX));
1879 writer.println(prefix + pxToDpStr("windowY", windowY));
1880 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1881 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001882 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1883 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001884 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1885 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1886 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1887 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001888
1889 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1890
Thales Limac98b7812023-04-14 15:04:23 +01001891 writer.println(prefix + "\tisResponsiveGrid:" + mIsResponsiveGrid);
Thales Lima79456492023-05-23 11:32:22 +01001892 writer.println(prefix + "\tisScalableGrid:" + mIsScalableGrid);
Jon Miranda58561d42021-03-17 10:51:54 -04001893
Thales Lima83bedbf2021-10-05 17:47:39 +01001894 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001895 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1896 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1897 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001898
Alex Chaue818bcb2022-09-02 17:27:11 +01001899 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07001900
Jon Miranda58561d42021-03-17 10:51:54 -04001901 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1902 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1903
1904 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1905 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1906
Thales Lima83bedbf2021-10-05 17:47:39 +01001907 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1908 cellLayoutBorderSpacePx.x));
1909 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1910 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001911 writer.println(
1912 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
1913 writer.println(
1914 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
1915 writer.println(
1916 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01001917 writer.println(
1918 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01001919
Jon Miranda58561d42021-03-17 10:51:54 -04001920 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1921 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1922 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1923
Helen Cheuk599109b2023-02-23 17:15:39 +00001924 writer.println(prefix + "\tinv.numFolderRows: " + inv.numFolderRows);
1925 writer.println(prefix + "\tinv.numFolderColumns: " + inv.numFolderColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001926 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1927 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1928 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1929 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1930 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1931 folderChildDrawablePaddingPx));
Jordan Silva637f4eb2023-06-13 11:21:53 +01001932 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.x",
1933 folderCellLayoutBorderSpacePx.x));
1934 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.y",
1935 folderCellLayoutBorderSpacePx.y));
Thales Limaa08a4432022-08-09 09:55:17 +01001936 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
1937 folderContentPaddingLeftRight));
1938 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03001939 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001940
Alex Chaue0227552022-04-06 19:44:43 +01001941 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001942 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
1943 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
1944 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
1945 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01001946
1947 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
1948 writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001949 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
1950 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04001951 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1952 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1953 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1954 allAppsIconDrawablePaddingPx));
1955 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001956 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001957 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
1958 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001959 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau62572c02022-07-25 18:36:37 +00001960 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
Alex Chau27b39b92022-01-14 18:02:18 +00001961 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001962
1963 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03001964 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04001965 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00001966 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Thales Lima8e11d532023-08-31 13:40:26 +00001967 writer.println(prefix + pxToDpStr("mHotseatBarEdgePaddingPx",
1968 mHotseatBarEdgePaddingPx));
1969 writer.println(prefix + pxToDpStr("mHotseatBarWorkspaceSpacePx",
1970 mHotseatBarWorkspaceSpacePx));
Pat Manning26f70f72022-07-07 13:50:39 +01001971 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01001972 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
1973 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01001974 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
1975 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001976 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
1977 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
1978 hotseatLayoutPadding.top));
1979 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
1980 hotseatLayoutPadding.bottom));
1981 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
1982 hotseatLayoutPadding.left));
1983 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
1984 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001985 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001986 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001987 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01001988 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001989
1990 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001991 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda9c478b62023-03-23 21:38:49 -07001992 writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight));
1993 writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight));
1994 writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin));
1995 writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001996
Thales Lima83bedbf2021-10-05 17:47:39 +01001997 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1998 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001999 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
2000 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
2001 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00002002 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04002003
Jon Mirandaab3c6812021-06-28 15:42:28 -07002004 writer.println(prefix + pxToDpStr("iconScale", iconScale));
2005 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04002006 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00002007 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04002008
Thales Lima171ee662022-11-22 15:52:49 +00002009 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04002010 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
2011 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00002012
2013 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00002014 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
2015 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
2016 overviewTaskIconDrawableSizePx));
2017 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
2018 overviewTaskIconDrawableSizeGridPx));
2019 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
2020 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01002021 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
2022 overviewActionsTopMarginPx));
2023 writer.println(prefix + pxToDpStr("overviewActionsHeight",
2024 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00002025 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
2026 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00002027 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
2028 overviewActionsButtonSpacing));
2029 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
2030 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
2031 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01002032
Alex Chau62572c02022-07-25 18:36:37 +00002033 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01002034 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00002035 writer.println(
2036 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01002037
Pat Manning5f74bfd2022-07-20 12:08:54 +01002038 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
2039 getCellLayoutSpringLoadShrunkTop()));
2040 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
2041 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01002042 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
2043 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01002044 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
2045 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01002046 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
2047 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Thales Lima79456492023-05-23 11:32:22 +01002048 if (mIsResponsiveGrid) {
2049 writer.println(prefix + "\tmResponsiveHeightSpec:" + mResponsiveHeightSpec.toString());
2050 writer.println(prefix + "\tmResponsiveWidthSpec:" + mResponsiveWidthSpec.toString());
Thales Limaabfe3642023-05-24 18:08:53 +01002051 writer.println(prefix + "\tmAllAppsResponsiveHeightSpec:"
2052 + mAllAppsResponsiveHeightSpec.toString());
2053 writer.println(prefix + "\tmAllAppsResponsiveWidthSpec:"
2054 + mAllAppsResponsiveWidthSpec.toString());
Jordan Silva637f4eb2023-06-13 11:21:53 +01002055 writer.println(prefix + "\tmResponsiveFolderHeightSpec:" + mResponsiveFolderHeightSpec);
2056 writer.println(prefix + "\tmResponsiveFolderWidthSpec:" + mResponsiveFolderWidthSpec);
Thales Limaf8bfb032023-07-24 15:08:05 +01002057 writer.println(prefix + "\tmResponsiveHotseatSpec:" + mResponsiveHotseatSpec);
Thales Lima79456492023-05-23 11:32:22 +01002058 }
Jon Miranda58561d42021-03-17 10:51:54 -04002059 }
2060
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00002061 /** Returns a reduced representation of this DeviceProfile. */
2062 public String toSmallString() {
2063 return "isTablet:" + isTablet + ", "
2064 + "isMultiDisplay:" + isMultiDisplay + ", "
2065 + "widthPx:" + widthPx + ", "
2066 + "heightPx:" + heightPx + ", "
2067 + "insets:" + mInsets + ", "
2068 + "rotationHint:" + rotationHint;
2069 }
2070
Alex Chaua6907dc2022-03-18 15:24:07 +00002071 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07002072 Configuration config = new Configuration(c.getResources().getConfiguration());
2073 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03002074 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00002075 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07002076 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07002077 }
Sunny Goyalfde55052018-02-01 14:46:13 -08002078
2079 /**
2080 * Callback when a component changes the DeviceProfile associated with it, as a result of
2081 * configuration change
2082 */
2083 public interface OnDeviceProfileChangeListener {
2084
2085 /**
2086 * Called when the device profile is reassigned. Note that for layout and measurements, it
2087 * is sufficient to listen for inset changes. Use this callback when you need to perform
2088 * a one time operation.
2089 */
2090 void onDeviceProfileChanged(DeviceProfile dp);
2091 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002092
Sihua Mae04aa202022-07-18 12:43:56 -07002093 /**
2094 * Handler that deals with ItemInfo of the views for the DeviceProfile
2095 */
2096 @FunctionalInterface
2097 public interface ViewScaleProvider {
2098 /**
2099 * Get the scales from the view
2100 *
2101 * @param itemInfo The tag of the widget view
2102 * @return PointF instance containing the scale information, or null if using the default
2103 * app widget scale of this device profile.
2104 */
2105 @NonNull
2106 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
2107 }
2108
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002109 public static class Builder {
2110 private Context mContext;
2111 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07002112 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002113
Sunny Goyal19ff7282021-04-22 10:12:54 -07002114 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00002115 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002116
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002117 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07002118 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00002119 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07002120 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002121
Sunny Goyal65190ae2022-08-02 14:16:26 -07002122 private SparseArray<DotRenderer> mDotRendererCache;
2123
Jon Miranda2b25ded2023-02-02 14:48:45 -08002124 private Consumer<DeviceProfile> mOverrideProvider;
2125
Sunny Goyalfd58da62020-08-11 12:06:49 -07002126 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002127 mContext = context;
2128 mInv = inv;
2129 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002130 }
2131
2132 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
2133 mIsMultiWindowMode = isMultiWindowMode;
2134 return this;
2135 }
2136
Alex Chauab800f72022-12-13 17:46:06 +00002137 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
2138 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07002139 return this;
2140 }
2141
Sunny Goyal65190ae2022-08-02 14:16:26 -07002142 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
2143 mDotRendererCache = dotRendererCache;
2144 return this;
2145 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07002146
2147 public Builder setWindowBounds(WindowBounds bounds) {
2148 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07002149 return this;
2150 }
2151
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002152 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
2153 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
2154 return this;
2155 }
2156
Alex Chau6ed408f2022-03-04 12:58:05 +00002157 public Builder setGestureMode(boolean isGestureMode) {
2158 mIsGestureMode = isGestureMode;
2159 return this;
2160 }
2161
Jon Miranda2b25ded2023-02-02 14:48:45 -08002162 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
2163 mOverrideProvider = overrideProvider;
2164 return this;
2165 }
2166
Sihua Mae04aa202022-07-18 12:43:56 -07002167 /**
2168 * Set the viewScaleProvider for the builder
2169 *
2170 * @param viewScaleProvider The viewScaleProvider to be set for the
Thales Limae9273ea2023-01-26 12:33:52 +00002171 * DeviceProfile
Sihua Mae04aa202022-07-18 12:43:56 -07002172 * @return This builder
2173 */
2174 @NonNull
2175 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
2176 mViewScaleProvider = viewScaleProvider;
2177 return this;
2178 }
2179
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002180 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07002181 if (mWindowBounds == null) {
2182 throw new IllegalArgumentException("Window bounds not set");
2183 }
2184 if (mTransposeLayoutWithOrientation == null) {
2185 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
2186 }
Alex Chau6ed408f2022-03-04 12:58:05 +00002187 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01002188 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00002189 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002190 if (mDotRendererCache == null) {
2191 mDotRendererCache = new SparseArray<>();
2192 }
Sihua Mae04aa202022-07-18 12:43:56 -07002193 if (mViewScaleProvider == null) {
2194 mViewScaleProvider = DEFAULT_PROVIDER;
2195 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08002196 if (mOverrideProvider == null) {
2197 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
2198 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07002199 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00002200 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jon Miranda2b25ded2023-02-02 14:48:45 -08002201 mIsGestureMode, mViewScaleProvider, mOverrideProvider);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07002202 }
2203 }
Winson Chungb3800242013-10-24 11:01:54 -07002204}