blob: aca03e37f3aadc6eb91810434c3bbfe03c417974 [file] [log] [blame]
Winson Chungb3800242013-10-24 11:01:54 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.launcher3;
18
Thales Lima12d0eff2022-03-25 17:06:11 +000019import static com.android.launcher3.InvariantDeviceProfile.INDEX_DEFAULT;
20import static com.android.launcher3.InvariantDeviceProfile.INDEX_LANDSCAPE;
21import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_LANDSCAPE;
22import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_PORTRAIT;
Jon Miranda58561d42021-03-17 10:51:54 -040023import static com.android.launcher3.Utilities.dpiFromPx;
Jon Mirandaaf3aed02021-05-06 18:28:45 -070024import static com.android.launcher3.Utilities.pxFromSp;
Alex Chau3d2c0622022-09-01 21:28:14 +010025import static com.android.launcher3.anim.Interpolators.LINEAR;
Alex Chauab800f72022-12-13 17:46:06 +000026import static com.android.launcher3.config.FeatureFlags.ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH;
Jon Miranda92c1b5d2021-07-20 13:57:16 -070027import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.ICON_OVERLAP_FACTOR;
Sunny Goyal65190ae2022-08-02 14:16:26 -070028import static com.android.launcher3.icons.GraphicsUtils.getShapePath;
Thales Limab35faed2022-09-05 16:30:01 -030029import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURCE_HANDLE;
Pat Manning5f74bfd2022-07-20 12:08:54 +010030import static com.android.launcher3.testing.shared.ResourceUtils.pxFromDp;
Thales Lima7eee74b2023-03-16 16:00:55 -030031import static com.android.launcher3.testing.shared.ResourceUtils.roundPxValueFromFloat;
Jon Miranda228877d2021-02-09 11:05:00 -050032
Sunny Goyal35c7b192021-04-20 16:51:10 -070033import android.annotation.SuppressLint;
Winson Chungb3800242013-10-24 11:01:54 -070034import android.content.Context;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070035import android.content.res.Configuration;
Winson Chungb3800242013-10-24 11:01:54 -070036import android.content.res.Resources;
Thales Limab35faed2022-09-05 16:30:01 -030037import android.content.res.TypedArray;
Winson Chungb3800242013-10-24 11:01:54 -070038import android.graphics.Point;
Jon Miranda7ae64ff2016-11-21 16:18:46 -080039import android.graphics.PointF;
Winson Chungb3800242013-10-24 11:01:54 -070040import android.graphics.Rect;
Sunny Goyal35c7b192021-04-20 16:51:10 -070041import android.util.DisplayMetrics;
Sunny Goyal65190ae2022-08-02 14:16:26 -070042import android.util.SparseArray;
Sunny Goyal59d086c2018-05-07 17:31:40 -070043import android.view.Surface;
Winson Chungb3800242013-10-24 11:01:54 -070044
Sunny Goyal65190ae2022-08-02 14:16:26 -070045import androidx.annotation.NonNull;
Sihua Mae04aa202022-07-18 12:43:56 -070046import androidx.annotation.Nullable;
Sunny Goyal65190ae2022-08-02 14:16:26 -070047
Sunny Goyalc13403c2016-11-18 23:44:48 -080048import com.android.launcher3.CellLayout.ContainerType;
Jon Miranda228877d2021-02-09 11:05:00 -050049import com.android.launcher3.DevicePaddings.DevicePadding;
Alex Chaud67ddc42022-09-30 18:15:56 +010050import com.android.launcher3.config.FeatureFlags;
Tony Wickham8912b042018-11-29 15:28:53 -080051import com.android.launcher3.icons.DotRenderer;
Hyunyoung Song48cb7bc2018-09-25 17:03:34 -070052import com.android.launcher3.icons.IconNormalizer;
Sihua Mae04aa202022-07-18 12:43:56 -070053import com.android.launcher3.model.data.ItemInfo;
Sunny Goyal57b22792021-05-25 14:35:01 -070054import com.android.launcher3.uioverrides.ApiWrapper;
Sunny Goyalfd58da62020-08-11 12:06:49 -070055import com.android.launcher3.util.DisplayController;
56import com.android.launcher3.util.DisplayController.Info;
Sunny Goyalb46703d2020-05-27 17:52:03 -070057import com.android.launcher3.util.WindowBounds;
Winson1f064272016-07-18 17:18:02 -070058
Jon Miranda58561d42021-03-17 10:51:54 -040059import java.io.PrintWriter;
Alex Chaue818bcb2022-09-02 17:27:11 +010060import java.util.Locale;
Jon Miranda2b25ded2023-02-02 14:48:45 -080061import java.util.function.Consumer;
Jon Miranda58561d42021-03-17 10:51:54 -040062
Sunny Goyal35c7b192021-04-20 16:51:10 -070063@SuppressLint("NewApi")
Winson Chungb3800242013-10-24 11:01:54 -070064public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070065
Sunny Goyal8b9919d2021-04-07 14:45:17 -070066 private static final int DEFAULT_DOT_SIZE = 100;
Alex Chau206ede92022-08-01 17:46:12 +010067 private static final float ALL_APPS_TABLET_MAX_ROWS = 5.5f;
Thales Limab35faed2022-09-05 16:30:01 -030068 private static final float MIN_FOLDER_TEXT_SIZE_SP = 16f;
Alex Chau206ede92022-08-01 17:46:12 +010069
Sihua Mae04aa202022-07-18 12:43:56 -070070 public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f);
71 public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE;
Jon Miranda2b25ded2023-02-02 14:48:45 -080072 public static final Consumer<DeviceProfile> DEFAULT_DIMENSION_PROVIDER = dp -> {};
Sihua Mae04aa202022-07-18 12:43:56 -070073
Sunny Goyal57b22792021-05-25 14:35:01 -070074 // Ratio of empty space, qsb should take up to appear visually centered.
Pratyush9afe1ea2021-10-13 11:13:27 +000075 private final float mQsbCenterFactor;
Sunny Goyal1890f672020-04-30 12:28:00 -070076
Adam Cohen2e6da152015-05-06 11:42:25 -070077 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070078 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070079 private final DisplayMetrics mMetrics;
Winson Chungbe876472014-05-14 14:15:20 -070080
Sunny Goyalc6205602015-05-21 20:46:33 -070081 // Device properties
82 public final boolean isTablet;
Sunny Goyalc6205602015-05-21 20:46:33 -070083 public final boolean isPhone;
84 public final boolean transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +000085 public final boolean isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -070086 public final boolean isTwoPanels;
Thales Limaa1012902022-01-13 17:58:42 +000087 public final boolean isQsbInline;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -070088
Sunny Goyalc6205602015-05-21 20:46:33 -070089 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -070090 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -080091 public final boolean isMultiWindowMode;
Alex Chau6ed408f2022-03-04 12:58:05 +000092 public final boolean isGestureMode;
Sunny Goyald70e75a2018-02-22 10:07:32 -080093
Sunny Goyal0addbf02020-04-28 14:17:35 -070094 public final int windowX;
95 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -070096 public final int widthPx;
97 public final int heightPx;
98 public final int availableWidthPx;
99 public final int availableHeightPx;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800100 public final int rotationHint;
Jon Mirandabba64512019-03-27 10:54:17 -0700101
102 public final float aspectRatio;
103
Jon Mirandae126d722021-02-25 10:45:20 -0500104 public final boolean isScalableGrid;
Thales Lima83bedbf2021-10-05 17:47:39 +0100105 private final int mTypeIndex;
Jon Mirandae126d722021-02-25 10:45:20 -0500106
Tony Wickhamd6b40372015-09-23 18:37:57 -0700107 /**
108 * The maximum amount of left/right workspace padding as a percentage of the screen width.
109 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
110 * 7% of the screen width can be used as right padding.
111 */
112 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -0700113
Jon Miranda3f9bab22017-07-28 14:50:17 -0700114 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700115 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda80dda302021-07-28 14:14:59 -0700116 private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252;
117 private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700118
Sunny Goyalc6205602015-05-21 20:46:33 -0700119 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +0100120 public final int desiredWorkspaceHorizontalMarginOriginalPx;
121 public int desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100122 public int gridVisualizationPaddingX;
123 public int gridVisualizationPaddingY;
Thales Lima78d00ad2021-09-30 11:29:06 +0100124 public Point cellLayoutBorderSpaceOriginalPx;
125 public Point cellLayoutBorderSpacePx;
Pat Manning08610ca2022-04-05 21:03:16 +0100126 public Rect cellLayoutPaddingPx = new Rect();
127
Sunny Goyalc6205602015-05-21 20:46:33 -0700128 public final int edgeMarginPx;
Alex Chau0c4e11b2022-07-08 18:41:36 +0100129 public final float workspaceContentScale;
Alex Chau906d8822022-05-23 10:42:25 +0100130 public final int workspaceSpringLoadedMinNextPageVisiblePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700131
Jon Miranda58561d42021-03-17 10:51:54 -0400132 private final int extraSpace;
Thales Lima171ee662022-11-22 15:52:49 +0000133 private int maxEmptySpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500134 public int workspaceTopPadding;
135 public int workspaceBottomPadding;
136
Tony Wickham5edf9e22020-03-27 20:06:52 -0700137 // Workspace page indicator
138 public final int workspacePageIndicatorHeight;
139 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700140
Sunny Goyalc6205602015-05-21 20:46:33 -0700141 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400142 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700143 public int iconSizePx;
144 public int iconTextSizePx;
145 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700146 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -0700147
Jon Mirandaab3c6812021-06-28 15:42:28 -0700148 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800149 public int cellWidthPx;
150 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700151 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800152
Jon Mirandae126d722021-02-25 10:45:20 -0500153 public int cellYPaddingPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500154
Sunny Goyalc6205602015-05-21 20:46:33 -0700155 // Folder
Jon Mirandae126d722021-02-25 10:45:20 -0500156 public float folderLabelTextScale;
157 public int folderLabelTextSizePx;
Thales Limab35faed2022-09-05 16:30:01 -0300158 public int folderFooterHeightPx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700159 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700160 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700161
Jon Mirandae126d722021-02-25 10:45:20 -0500162 // Folder content
Thales Limab35faed2022-09-05 16:30:01 -0300163 public int folderCellLayoutBorderSpacePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500164 public int folderContentPaddingLeftRight;
165 public int folderContentPaddingTop;
166
Jon Mirandabf7d8122016-11-03 15:29:29 -0700167 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700168 public int folderCellWidthPx;
169 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700170
171 // Folder child
172 public int folderChildIconSizePx;
173 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700174 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700175
Sunny Goyalc6205602015-05-21 20:46:33 -0700176 // Hotseat
Thales Lima9938c2f2022-07-25 14:38:16 +0100177 public int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700178 public int hotseatCellHeightPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100179 public final boolean areNavButtonsInline;
Jon Miranda18751b62017-07-31 17:25:27 -0700180 // In portrait: size = height, in landscape: size = width
181 public int hotseatBarSizePx;
Thales Limab8c05952022-05-23 16:58:38 +0100182 public int hotseatBarBottomSpacePx;
Pat Manning26f70f72022-07-07 13:50:39 +0100183 public int hotseatBarEndOffset;
Thales Limab8c05952022-05-23 16:58:38 +0100184 public int hotseatQsbSpace;
Pat Manningde25c0d2022-04-05 19:11:26 +0100185 public int springLoadedHotseatBarTopMarginPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700186 // Start is the side next to the nav bar, end is the side next to the workspace
187 public final int hotseatBarSidePaddingStartPx;
188 public final int hotseatBarSidePaddingEndPx;
Alex Chau206ede92022-08-01 17:46:12 +0100189 public int hotseatQsbWidth; // only used when isQsbInline
Sunny Goyal57b22792021-05-25 14:35:01 -0700190 public final int hotseatQsbHeight;
Thales Limab8c05952022-05-23 16:58:38 +0100191 public final int hotseatQsbVisualHeight;
192 private final int hotseatQsbShadowHeight;
Thales Limadd027342022-01-07 12:54:37 +0000193 public int hotseatBorderSpace;
Thales Limaffc68b02023-01-09 16:20:23 +0000194 private final int mMinHotseatIconSpacePx;
195 private final int mMinHotseatQsbWidthPx;
196 private final int mMaxHotseatIconSpacePx;
Jon Mirandae17a9492023-03-08 16:42:20 -0800197 public final int inlineNavButtonsEndSpacingPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700198
Alex Chau3d2c0622022-09-01 21:28:14 +0100199 // Bottom sheets
200 public int bottomSheetTopPadding;
201 public int bottomSheetOpenDuration;
202 public int bottomSheetCloseDuration;
203 public float bottomSheetWorkspaceScale;
204 public float bottomSheetDepth;
205
Sunny Goyalc6205602015-05-21 20:46:33 -0700206 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000207 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000208 public int allAppsShiftRange;
209 public int allAppsTopPadding;
Alex Chau3d2c0622022-09-01 21:28:14 +0100210 public int allAppsOpenDuration;
211 public int allAppsCloseDuration;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700212 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700213 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700214 public int allAppsIconSizePx;
215 public int allAppsIconDrawablePaddingPx;
sfufa@google.comde013292021-09-21 18:22:44 -0700216 public int allAppsLeftRightPadding;
Alex Chau27b39b92022-01-14 18:02:18 +0000217 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700218 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700219 public float allAppsIconTextSizePx;
220
Zak Cohen334efeb2021-03-19 16:42:07 -0700221 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700222 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000223 public int overviewTaskIconSizePx;
Alex Chauac9df382021-08-02 19:08:41 +0100224 public int overviewTaskIconDrawableSizePx;
225 public int overviewTaskIconDrawableSizeGridPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000226 public int overviewTaskThumbnailTopMarginPx;
Alex Chau19c6eca2022-03-10 20:12:56 +0000227 public final int overviewActionsHeight;
Alex Chaua2fc7642022-04-21 14:20:23 +0100228 public final int overviewActionsTopMarginPx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000229 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100230 public int overviewPageSpacing;
231 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000232 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700233
Jeremy Sim0ac47082022-10-10 13:59:40 -0700234 // Split staging
235 public int splitPlaceholderInset;
236
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800237 // Widgets
Sihua Mae04aa202022-07-18 12:43:56 -0700238 private final ViewScaleProvider mViewScaleProvider;
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800239
Sunny Goyal47328fd2016-05-25 18:56:41 -0700240 // Drop Target
241 public int dropTargetBarSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100242 public int dropTargetBarTopMarginPx;
243 public int dropTargetBarBottomMarginPx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100244 public int dropTargetDragPaddingPx;
245 public int dropTargetTextSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100246 public int dropTargetHorizontalPaddingPx;
247 public int dropTargetVerticalPaddingPx;
248 public int dropTargetGapPx;
Alex Chau5b019302022-05-23 10:42:25 +0100249 public int dropTargetButtonWorkspaceEdgeGapPx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700250
Winson1f064272016-07-18 17:18:02 -0700251 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800252 private final Rect mInsets = new Rect();
253 public final Rect workspacePadding = new Rect();
Jon Miranda0bd63d12019-03-06 17:29:29 -0800254 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700255 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700256
Tony Wickhamf34bee82018-12-03 18:11:39 -0800257 // Notification dots
Sunny Goyal65190ae2022-08-02 14:16:26 -0700258 public final DotRenderer mDotRendererWorkSpace;
259 public final DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800260
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100261 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800262 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000263 // Whether Taskbar will inset the bottom of apps by taskbarSize.
264 public boolean isTaskbarPresentInApps;
Tony Wickham15883892021-02-12 11:24:40 -0800265 public int taskbarSize;
Alex Chau85d664e2023-01-16 16:31:59 +0000266 public int transientTaskbarSize;
Alex Chau6a7d1e22022-01-20 19:54:17 +0000267 public int stashedTaskbarSize;
Alex Chau905e0f12022-11-14 21:55:37 +0000268 public int transientTaskbarMargin;
Tony Wickham15883892021-02-12 11:24:40 -0800269
Alex Chaua02eddc2021-04-29 00:36:06 +0100270 // DragController
271 public int flingToDeleteThresholdVelocity;
272
Vinit Nayak17c4b332021-08-05 12:54:58 -0700273 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700274 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal65190ae2022-08-02 14:16:26 -0700275 SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
Alex Chauab800f72022-12-13 17:46:06 +0000276 boolean transposeLayoutWithOrientation, boolean isMultiDisplay, boolean isGestureMode,
Jon Miranda2b25ded2023-02-02 14:48:45 -0800277 @NonNull final ViewScaleProvider viewScaleProvider,
278 @NonNull final Consumer<DeviceProfile> dimensionOverrideProvider) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700279
Adam Cohen2e6da152015-05-06 11:42:25 -0700280 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700281 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800282 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500283 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chauab800f72022-12-13 17:46:06 +0000284 this.isMultiDisplay = isMultiDisplay;
Alex Chau6ed408f2022-03-04 12:58:05 +0000285 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700286 windowX = windowBounds.bounds.left;
287 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800288 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100289 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700290
Jon Mirandae126d722021-02-25 10:45:20 -0500291 isScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000292 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700293 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000294 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700295 isPhone = !isTablet;
Alex Chauab800f72022-12-13 17:46:06 +0000296 isTwoPanels = isTablet && isMultiDisplay;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800297 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700298
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000299 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000300 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700301 ? Configuration.ORIENTATION_LANDSCAPE
302 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000303 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700304 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000305 mMetrics = res.getDisplayMetrics();
306
307 // Determine sizes.
308 widthPx = windowBounds.bounds.width();
309 heightPx = windowBounds.bounds.height();
310 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100311 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000312
313 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
314 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
315 mQsbCenterFactor = res.getFloat(R.dimen.qsb_center_factor);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700316
Thales Lima83bedbf2021-10-05 17:47:39 +0100317 if (isTwoPanels) {
318 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000319 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100320 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000321 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100322 }
323 } else {
324 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000325 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100326 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000327 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100328 }
329 }
330
Tony Wickham15883892021-02-12 11:24:40 -0800331 if (isTaskbarPresent) {
Alex Chau85d664e2023-01-16 16:31:59 +0000332 transientTaskbarSize = res.getDimensionPixelSize(R.dimen.transient_taskbar_size);
333 transientTaskbarMargin = res.getDimensionPixelSize(R.dimen.transient_taskbar_margin);
Jon Miranda7e819502022-11-03 10:56:32 -0700334 if (DisplayController.isTransientTaskbar(context)) {
Alex Chau85d664e2023-01-16 16:31:59 +0000335 taskbarSize = transientTaskbarSize;
Jon Miranda7e819502022-11-03 10:56:32 -0700336 stashedTaskbarSize =
337 res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_size);
338 } else {
339 taskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_size);
340 stashedTaskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
341 }
Tony Wickham15883892021-02-12 11:24:40 -0800342 }
Tony Wickham15883892021-02-12 11:24:40 -0800343
Winson Chungb3800242013-10-24 11:01:54 -0700344 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100345 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700346
Thales Limad90faab2021-09-21 17:18:47 +0100347 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
348 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100349 gridVisualizationPaddingX = res.getDimensionPixelSize(
350 R.dimen.grid_visualization_horizontal_cell_spacing);
351 gridVisualizationPaddingY = res.getDimensionPixelSize(
352 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500353
Alex Chaue0227552022-04-06 19:44:43 +0100354 bottomSheetTopPadding = mInsets.top // statusbar height
Andras Kloczl142b0542022-03-09 21:26:02 +0000355 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
356 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
Alex Chau3d2c0622022-09-01 21:28:14 +0100357 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
358 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
359 if (isTablet) {
360 bottomSheetWorkspaceScale = workspaceContentScale;
Alex Chauab800f72022-12-13 17:46:06 +0000361 if (isMultiDisplay && !ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH.get()) {
362 // TODO(b/259893832): Revert to use maxWallpaperScale to calculate bottomSheetDepth
363 // when screen recorder bug is fixed.
364 bottomSheetDepth = 1f;
365 } else {
366 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
367 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
368 // When depth is 1, wallpaper zoom is set to 1.
369 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
370 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
371 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
372 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
373 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100374 } else {
375 bottomSheetWorkspaceScale = 1f;
376 bottomSheetDepth = 0f;
377 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000378
Jon Mirandae126d722021-02-25 10:45:20 -0500379 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
Thales Limab35faed2022-09-05 16:30:01 -0300380
Thales Lima7eee74b2023-03-16 16:00:55 -0300381 if (isScalableGrid && inv.folderStyle != INVALID_RESOURCE_HANDLE) {
Thales Limab35faed2022-09-05 16:30:01 -0300382 TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
Thales Limad852d652023-01-17 14:01:13 +0000383 R.styleable.FolderStyle);
Thales Limab35faed2022-09-05 16:30:01 -0300384 // These are re-set in #updateFolderCellSize if the grid is not scalable
385 folderCellHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000386 R.styleable.FolderStyle_folderCellHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300387 folderCellWidthPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000388 R.styleable.FolderStyle_folderCellWidth, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300389
390 folderContentPaddingTop = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000391 R.styleable.FolderStyle_folderTopPadding, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300392 folderCellLayoutBorderSpacePx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000393 R.styleable.FolderStyle_folderBorderSpace, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300394 folderFooterHeightPx = folderStyle.getDimensionPixelSize(
Thales Limad852d652023-01-17 14:01:13 +0000395 R.styleable.FolderStyle_folderFooterHeight, 0);
Thales Limab35faed2022-09-05 16:30:01 -0300396 folderStyle.recycle();
397 } else {
398 folderCellLayoutBorderSpacePx = 0;
Thales Lima7eee74b2023-03-16 16:00:55 -0300399 folderFooterHeightPx = res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Thales Limab35faed2022-09-05 16:30:01 -0300400 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
401 }
Jon Mirandae126d722021-02-25 10:45:20 -0500402
Thales Lima78d00ad2021-09-30 11:29:06 +0100403 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv);
Thales Limab35faed2022-09-05 16:30:01 -0300404 cellLayoutBorderSpaceOriginalPx = new Point(cellLayoutBorderSpacePx);
Thales Lima85c942f2021-12-31 13:04:20 +0000405 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000406 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
407 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Thales Limae9273ea2023-01-26 12:33:52 +0000408 setupAllAppsStyle(context);
Jon Mirandae126d722021-02-25 10:45:20 -0500409
Tony Wickham5edf9e22020-03-27 20:06:52 -0700410 workspacePageIndicatorHeight = res.getDimensionPixelSize(
411 R.dimen.workspace_page_indicator_height);
412 mWorkspacePageIndicatorOverlapWorkspace =
413 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700414
Thales Limad852d652023-01-17 14:01:13 +0000415 TypedArray cellStyle;
416 if (inv.cellStyle != INVALID_RESOURCE_HANDLE) {
417 cellStyle = context.obtainStyledAttributes(inv.cellStyle,
418 R.styleable.CellStyle);
419 } else {
420 cellStyle = context.obtainStyledAttributes(R.style.CellStyleDefault,
421 R.styleable.CellStyle);
422 }
423 iconDrawablePaddingOriginalPx = cellStyle.getDimensionPixelSize(
424 R.styleable.CellStyle_iconDrawablePadding, 0);
425 cellStyle.recycle();
Alex Chaua02eddc2021-04-29 00:36:06 +0100426
Sunny Goyal47328fd2016-05-25 18:56:41 -0700427 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100428 dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
429 dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100430 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
431 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100432 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
433 R.dimen.drop_target_button_drawable_horizontal_padding);
434 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
435 R.dimen.drop_target_button_drawable_vertical_padding);
436 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100437 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
438 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100439
Alex Chau906d8822022-05-23 10:42:25 +0100440 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
441 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700442
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700443 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700444
Thales Limaa1012902022-01-13 17:58:42 +0000445 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100446 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
447 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
448
Thales Lima12d0eff2022-03-25 17:06:11 +0000449 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
450 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
451 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
452 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
453 && hotseatQsbHeight > 0;
Thales Lima6a590062022-11-22 15:52:49 +0000454 isQsbInline = isScalableGrid && inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000455
Thales Lima425f6822022-05-10 13:44:58 -0300456 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100457 numShownHotseatIcons =
458 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000459
Sunny Goyal19ff7282021-04-22 10:12:54 -0700460 numShownAllAppsColumns =
461 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100462
463 int hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
464 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
465 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
466 // Have a little space between the inset and the QSB
467 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
468 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
469
470 // Only change the spaces if there is space
471 if (availableSpace > 0) {
472 // Make sure there is enough space between hotseat/QSB and QSB/navBar
473 if (availableSpace < minQsbMargin * 2) {
474 minQsbMargin = availableSpace / 2;
475 hotseatQsbSpace = minQsbMargin;
476 } else {
477 hotseatQsbSpace -= minQsbMargin;
478 }
479 }
480 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
481
Thales Limaa1012902022-01-13 17:58:42 +0000482 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100483 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
Thales Limaa1012902022-01-13 17:58:42 +0000484 }
Thales Lima425f6822022-05-10 13:44:58 -0300485
Pat Manningde25c0d2022-04-05 19:11:26 +0100486 springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
487 R.dimen.spring_loaded_hotseat_top_margin);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700488 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800489 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700490 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700491 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Thales Limab8c05952022-05-23 16:58:38 +0100492 updateHotseatSizes(pxFromDp(inv.iconSize[INDEX_DEFAULT], mMetrics));
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700493 if (areNavButtonsInline && !isPhone) {
Jon Mirandae17a9492023-03-08 16:42:20 -0800494 inlineNavButtonsEndSpacingPx =
Thales Limaffc68b02023-01-09 16:20:23 +0000495 res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing);
Pat Manning26f70f72022-07-07 13:50:39 +0100496 /*
497 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700498 * Spacing between nav buttons +
Thales Lima6a590062022-11-22 15:52:49 +0000499 * Space at the end for contextual buttons
Pat Manning26f70f72022-07-07 13:50:39 +0100500 */
501 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700502 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
Jon Mirandae17a9492023-03-08 16:42:20 -0800503 + inlineNavButtonsEndSpacingPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100504 } else {
Jon Mirandae17a9492023-03-08 16:42:20 -0800505 inlineNavButtonsEndSpacingPx = 0;
Pat Manning26f70f72022-07-07 13:50:39 +0100506 hotseatBarEndOffset = 0;
507 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700508
Alex Chau635b3ab2022-01-26 16:49:10 +0000509 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chau5fd9d492021-07-22 17:27:11 +0100510 overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100511 overviewTaskIconDrawableSizePx =
512 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
513 overviewTaskIconDrawableSizeGridPx =
514 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700515 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx;
Jeremy Sim3c2c3f12022-05-16 20:37:43 -0700516 overviewActionsTopMarginPx = res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000517 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
518 overviewActionsButtonSpacing = res.getDimensionPixelSize(
519 R.dimen.overview_actions_button_spacing);
Alex Chau19c6eca2022-03-10 20:12:56 +0000520 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700521 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000522 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700523
Jeremy Sim0ac47082022-10-10 13:59:40 -0700524 splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset);
525
Jon Miranda2ed276e2017-06-29 11:36:34 -0700526 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400527 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700528
Jon Miranda2ed276e2017-06-29 11:36:34 -0700529 // Now that we have all of the variables calculated, we can tune certain sizes.
Thales Limaae0d7ef2022-11-16 15:53:43 +0000530 if (isScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400531 // Paddings were created assuming no scaling, so we first unscale the extra space.
Jon Mirandaab3c6812021-06-28 15:42:28 -0700532 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
Thales Limaae0d7ef2022-11-16 15:53:43 +0000533 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
534 DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
Thales Lima171ee662022-11-22 15:52:49 +0000535 maxEmptySpace = padding.getMaxEmptySpacePx();
Jon Miranda228877d2021-02-09 11:05:00 -0500536
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400537 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
538 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
539 int paddingHotseatBottom = padding.getHotseatBottomPadding(unscaledExtraSpace);
540
Jon Mirandaab3c6812021-06-28 15:42:28 -0700541 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
542 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700543 }
Pat Manning08610ca2022-04-05 21:03:16 +0100544
545 int cellLayoutPadding =
546 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
547 R.dimen.cell_layout_padding);
548 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
549 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800550 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800551
Thales Lima7eee74b2023-03-16 16:00:55 -0300552 // Folder scaling requires correct workspace paddings
553 updateAvailableFolderCellDimensions(res);
554
Thales Limaffc68b02023-01-09 16:20:23 +0000555 mMinHotseatIconSpacePx = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
556 mMinHotseatQsbWidthPx = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
557 mMaxHotseatIconSpacePx = areNavButtonsInline
Thales Lima6a590062022-11-22 15:52:49 +0000558 ? res.getDimensionPixelSize(R.dimen.max_hotseat_icon_space) : Integer.MAX_VALUE;
Thales Lima425f6822022-05-10 13:44:58 -0300559 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima6a590062022-11-22 15:52:49 +0000560 recalculateHotseatWidthAndBorderSpace();
Alex Chau206ede92022-08-01 17:46:12 +0100561
562 // AllApps height calculation depends on updated cellSize
563 if (isTablet) {
564 int collapseHandleHeight =
565 res.getDimensionPixelOffset(R.dimen.bottom_sheet_handle_area_height);
566 int contentHeight = heightPx - collapseHandleHeight - hotseatQsbHeight;
567 int targetContentHeight = (int) (allAppsCellHeightPx * ALL_APPS_TABLET_MAX_ROWS);
568 allAppsTopPadding = Math.max(mInsets.top, contentHeight - targetContentHeight);
569 allAppsShiftRange = heightPx - allAppsTopPadding;
570 } else {
571 allAppsTopPadding = 0;
572 allAppsShiftRange =
573 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
574 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100575 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
576 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300577
Alex Chaua02eddc2021-04-29 00:36:06 +0100578 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
579 R.dimen.drag_flingToDeleteMinVelocity);
580
Sihua Mae04aa202022-07-18 12:43:56 -0700581 mViewScaleProvider = viewScaleProvider;
582
Jon Miranda2b25ded2023-02-02 14:48:45 -0800583 dimensionOverrideProvider.accept(this);
584
Tony Wickham1237df02017-02-24 08:59:36 -0800585 // This is done last, after iconSizePx is calculated above.
Sunny Goyal799e1202023-02-09 10:54:28 -0800586 mDotRendererWorkSpace = createDotRenderer(context, iconSizePx, dotRendererCache);
587 mDotRendererAllApps = createDotRenderer(context, allAppsIconSizePx, dotRendererCache);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700588 }
589
590 private static DotRenderer createDotRenderer(
Sunny Goyal799e1202023-02-09 10:54:28 -0800591 @NonNull Context context, int size, @NonNull SparseArray<DotRenderer> cache) {
Sunny Goyal65190ae2022-08-02 14:16:26 -0700592 DotRenderer renderer = cache.get(size);
593 if (renderer == null) {
Sunny Goyal799e1202023-02-09 10:54:28 -0800594 renderer = new DotRenderer(size, getShapePath(context, DEFAULT_DOT_SIZE),
595 DEFAULT_DOT_SIZE);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700596 cache.put(size, renderer);
597 }
598 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700599 }
600
Thales Lima425f6822022-05-10 13:44:58 -0300601 /**
602 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
603 * width of the hotseat.
604 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100605 private int calculateQsbWidth(int hotseatBorderSpace) {
Thales Lima425f6822022-05-10 13:44:58 -0300606 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100607 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300608 return getIconToIconWidthForColumns(columns)
609 - iconSizePx * numShownHotseatIcons
610 - hotseatBorderSpace * numShownHotseatIcons;
611 } else {
612 int columns = inv.hotseatColumnSpan[mTypeIndex];
613 return getIconToIconWidthForColumns(columns);
614 }
615 }
Thales Lima2903a622022-03-17 13:52:19 +0000616
Thales Lima425f6822022-05-10 13:44:58 -0300617 private int getIconToIconWidthForColumns(int columns) {
618 return columns * getCellSize().x
619 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400620 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000621 }
622
Thales Limad90faab2021-09-21 17:18:47 +0100623 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
624 if (isVerticalBarLayout()) {
625 return 0;
626 }
627
Thales Lima83bedbf2021-10-05 17:47:39 +0100628 return isScalableGrid
629 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
630 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100631 }
632
Thales Limab8c05952022-05-23 16:58:38 +0100633 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
634 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700635 // Ensure there is enough space for folder icons, which have a slightly larger radius.
636 hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR);
Thales Limab8c05952022-05-23 16:58:38 +0100637
Jon Miranda0d284852021-06-22 14:50:55 -0700638 if (isVerticalBarLayout()) {
639 hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
640 + hotseatBarSidePaddingEndPx;
Thales Limab8c05952022-05-23 16:58:38 +0100641 } else if (isQsbInline) {
642 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
643 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700644 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100645 hotseatBarSizePx = hotseatIconSizePx
646 + hotseatQsbSpace
647 + hotseatQsbVisualHeight
648 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700649 }
650 }
651
Thales Lima6a590062022-11-22 15:52:49 +0000652 /**
653 * Calculates the width of the hotseat, changing spaces between the icons and removing icons if
654 * necessary.
655 */
656 public void recalculateHotseatWidthAndBorderSpace() {
657 if (!isScalableGrid) return;
658
659 int columns = inv.hotseatColumnSpan[mTypeIndex];
660 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
661 hotseatBorderSpace = calculateHotseatBorderSpace(hotseatWidthPx, /* numExtraBorder= */ 0);
Thales Lima9938c2f2022-07-25 14:38:16 +0100662 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
Thales Lima6a590062022-11-22 15:52:49 +0000663 // Spaces should be correct when the nav buttons are not inline
Thales Lima9938c2f2022-07-25 14:38:16 +0100664 if (!areNavButtonsInline) {
665 return;
666 }
667
Thales Lima6a590062022-11-22 15:52:49 +0000668 // The side space with inline buttons should be what is defined in InvariantDeviceProfile
Jon Mirandae17a9492023-03-08 16:42:20 -0800669 int sideSpacePx = inlineNavButtonsEndSpacingPx;
Thales Limaffc68b02023-01-09 16:20:23 +0000670 int maxHotseatWidthPx = availableWidthPx - sideSpacePx - hotseatBarEndOffset;
671 int maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
672 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000673 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100674
Thales Limaffc68b02023-01-09 16:20:23 +0000675 if (hotseatBorderSpace >= mMinHotseatIconSpacePx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100676 return;
677 }
678
679 // Border space can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000680 hotseatBorderSpace = mMinHotseatIconSpacePx;
Thales Lima6a590062022-11-22 15:52:49 +0000681 int requiredWidth = getHotseatRequiredWidth();
Thales Lima9938c2f2022-07-25 14:38:16 +0100682
683 // If there is an inline qsb, change its size
684 if (isQsbInline) {
Thales Limaffc68b02023-01-09 16:20:23 +0000685 hotseatQsbWidth -= requiredWidth - maxHotseatWidthPx;
686 if (hotseatQsbWidth >= mMinHotseatQsbWidthPx) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100687 return;
688 }
689
690 // QSB can't be less than the minimum
Thales Limaffc68b02023-01-09 16:20:23 +0000691 hotseatQsbWidth = mMinHotseatQsbWidthPx;
Thales Lima9938c2f2022-07-25 14:38:16 +0100692 }
693
Thales Limaffc68b02023-01-09 16:20:23 +0000694 maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
Thales Lima6a590062022-11-22 15:52:49 +0000695
Thales Lima9938c2f2022-07-25 14:38:16 +0100696 // If it still doesn't fit, start removing icons
697 do {
698 numShownHotseatIcons--;
Thales Limaffc68b02023-01-09 16:20:23 +0000699 hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
Thales Lima6a590062022-11-22 15:52:49 +0000700 (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
Thales Limaffc68b02023-01-09 16:20:23 +0000701 } while (hotseatBorderSpace < mMinHotseatIconSpacePx && numShownHotseatIcons > 1);
Thales Lima9938c2f2022-07-25 14:38:16 +0100702
Thales Lima9938c2f2022-07-25 14:38:16 +0100703 }
704
Thales Lima78d00ad2021-09-30 11:29:06 +0100705 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100706 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100707 }
708
709 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100710 if (!isScalableGrid) {
711 return new Point(0, 0);
712 }
713
Thales Lima080d8902022-03-28 15:30:29 +0100714 int horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
715 int verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
Thales Lima78d00ad2021-09-30 11:29:06 +0100716
717 return new Point(horizontalSpacePx, verticalSpacePx);
718 }
719
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700720 public Info getDisplayInfo() {
721 return mInfo;
722 }
723
Jon Miranda611dba42021-03-02 14:12:13 -0500724 /**
725 * We inset the widget padding added by the system and instead rely on the border spacing
726 * between cells to create reliable consistency between widgets
727 */
728 public boolean shouldInsetWidgets() {
729 Rect widgetPadding = inv.defaultWidgetPadding;
730
Jon Miranda49811182021-06-03 09:52:40 -0700731 // Check all sides to ensure that the widget won't overlap into another cell, or into
732 // status bar.
733 return workspaceTopPadding > widgetPadding.top
Thales Lima78d00ad2021-09-30 11:29:06 +0100734 && cellLayoutBorderSpacePx.x > widgetPadding.left
735 && cellLayoutBorderSpacePx.y > widgetPadding.top
736 && cellLayoutBorderSpacePx.x > widgetPadding.right
737 && cellLayoutBorderSpacePx.y > widgetPadding.bottom;
Jon Miranda611dba42021-03-02 14:12:13 -0500738 }
Jon Mirandae126d722021-02-25 10:45:20 -0500739
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700740 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800741 WindowBounds bounds = new WindowBounds(
742 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700743 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100744 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700745
746 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
747 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
748 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
749
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700750 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700751 .setWindowBounds(bounds)
Alex Chauab800f72022-12-13 17:46:06 +0000752 .setIsMultiDisplay(isMultiDisplay)
Alex Chau6ed408f2022-03-04 12:58:05 +0000753 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700754 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000755 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800756 }
757
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700758 public DeviceProfile copy(Context context) {
759 return toBuilder(context).build();
760 }
761
762 /**
763 * TODO: Move this to the builder as part of setMultiWindowMode
764 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700765 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700766 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700767 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700768 .setMultiWindowMode(true)
769 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800770
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800771 // We use these scales to measure and layout the widgets using their full invariant profile
772 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
773 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
774 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700775 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
776 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
777 profile = profile.toBuilder(context)
778 .setViewScaleProvider(i -> p)
779 .build();
780 }
781
782 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800783
Jon Miranda93e1f042016-11-11 14:13:04 -0800784 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700785 }
786
Adam Cohen63f1ec02014-08-12 09:23:13 -0700787 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400788 * Checks if there is enough space for labels on the workspace.
789 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700790 * It is important to call this method after the All Apps variables have been set.
791 */
Jon Miranda941375e2021-03-31 13:10:45 -0400792 private void hideWorkspaceLabelsIfNotEnoughSpace() {
793 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
794 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
795 - iconTextHeight;
796
797 // We want enough space so that the text is closer to its corresponding icon.
798 if (workspaceCellPaddingY < iconTextHeight) {
799 iconTextSizePx = 0;
800 iconDrawablePaddingPx = 0;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700801 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda941375e2021-03-31 13:10:45 -0400802 autoResizeAllAppsCells();
803 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700804 }
Jon Miranda1091e532017-07-21 13:31:50 -0700805
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700806 /**
807 * Re-computes the all-apps cell size to be independent of workspace
808 */
809 public void autoResizeAllAppsCells() {
Jon Miranda941375e2021-03-31 13:10:45 -0400810 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
811 int topBottomPadding = textHeight;
Jon Miranda1091e532017-07-21 13:31:50 -0700812 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
Jon Miranda941375e2021-03-31 13:10:45 -0400813 + textHeight + (topBottomPadding * 2);
Jon Miranda1091e532017-07-21 13:31:50 -0700814 }
815
Thales Limab7ef5692022-03-10 10:32:36 +0000816 private void updateAllAppsContainerWidth(Resources res) {
Pat Manning08610ca2022-04-05 21:03:16 +0100817 int cellLayoutHorizontalPadding =
818 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
Alex Chau27b39b92022-01-14 18:02:18 +0000819 if (isTablet) {
sfufa@google.comde013292021-09-21 18:22:44 -0700820 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
Thales Limab7ef5692022-03-10 10:32:36 +0000821 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Alex Chau27b39b92022-01-14 18:02:18 +0000822 + allAppsLeftRightPadding * 2;
823 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
sfufa@google.comde013292021-09-21 18:22:44 -0700824 } else {
825 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100826 desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding;
sfufa@google.comde013292021-09-21 18:22:44 -0700827 }
828 }
829
Thales Limae9273ea2023-01-26 12:33:52 +0000830 private void setupAllAppsStyle(Context context) {
831 TypedArray allAppsStyle;
832 if (inv.allAppsStyle != INVALID_RESOURCE_HANDLE) {
833 allAppsStyle = context.obtainStyledAttributes(inv.allAppsStyle,
834 R.styleable.AllAppsStyle);
835 } else {
836 allAppsStyle = context.obtainStyledAttributes(R.style.AllAppsStyleDefault,
837 R.styleable.AllAppsStyle);
838 }
839 allAppsLeftRightPadding = allAppsStyle.getDimensionPixelSize(
840 R.styleable.AllAppsStyle_horizontalPadding, 0);
841 allAppsStyle.recycle();
842 }
843
Jon Miranda228877d2021-02-09 11:05:00 -0500844 /**
845 * Returns the amount of extra (or unused) vertical space.
846 */
847 private int updateAvailableDimensions(Resources res) {
Alex Chaua68164d2022-12-15 16:16:03 +0000848 float invIconSizeDp = inv.iconSize[mTypeIndex];
849 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
850 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics));
851 iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics);
852
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700853 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800854
Pat Manning08610ca2022-04-05 21:03:16 +0100855 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -0500856
857 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +0100858 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +0000859 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -0500860 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500861 float scaleY = maxHeight / usedHeight;
862 boolean shouldScale = scaleY < 1f;
863
864 float scaleX = 1f;
865 if (isScalableGrid) {
866 // We scale to fit the cellWidth and cellHeight in the available space.
867 // The benefit of scalable grids is that we can get consistent aspect ratios between
868 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +0100869 float usedWidth =
870 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500871 // We do not subtract padding here, as we also scale the workspace padding if needed.
872 scaleX = availableWidthPx / usedWidth;
873 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700874 }
Jon Mirandae126d722021-02-25 10:45:20 -0500875
876 if (shouldScale) {
877 float scale = Math.min(scaleX, scaleY);
878 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +0100879 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -0500880 }
881
Jon Miranda228877d2021-02-09 11:05:00 -0500882 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700883 }
884
Pat Manninga2e14992022-04-22 11:29:17 +0100885 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +0100886 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
887 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
888 }
889
Pat Manninga2e14992022-04-22 11:29:17 +0100890 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +0000891 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +0100892 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
893 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -0500894 }
895
Jon Miranda6f7e9702019-09-16 14:44:14 -0700896 /**
897 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
898 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
899 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
900 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800901 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -0700902 // Icon scale should never exceed 1, otherwise pixellation may occur.
903 iconScale = Math.min(1f, scale);
904 cellScaleToFit = scale;
905
Jon Miranda18751b62017-07-31 17:25:27 -0700906 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800907 final boolean isVerticalLayout = isVerticalBarLayout();
Jon Mirandaab3c6812021-06-28 15:42:28 -0700908 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);
Thales Lima080d8902022-03-28 15:30:29 +0100909 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500910
911 if (isScalableGrid) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100912 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
913 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +0000914
915 if (cellWidthPx < iconSizePx) {
916 // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger.
917 int numColumns = getPanelCount() * inv.numColumns;
918 int numBorders = numColumns - 1;
919 int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns;
920 if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) {
921 cellWidthPx = iconSizePx;
922 cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders;
923 } else {
924 // If it still doesn't fit, set borderSpace to 0 and distribute the space for
925 // cellWidth, and reduce iconSize.
926 cellWidthPx = (cellWidthPx * numColumns
927 + cellLayoutBorderSpacePx.x * numBorders) / numColumns;
928 iconSizePx = Math.min(iconSizePx, cellWidthPx);
929 cellLayoutBorderSpacePx.x = 0;
930 }
931 }
932
933 int cellTextAndPaddingHeight =
934 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
935 int cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
936 if (cellHeightPx < cellContentHeight) {
937 // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight
938 // bigger.
939 int numBorders = inv.numRows - 1;
940 int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows;
941 if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) {
942 cellHeightPx = cellContentHeight;
943 cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders;
944 } else {
Alex Chau06f36e82023-01-06 10:50:54 +0000945 // If it still doesn't fit, set borderSpace to 0 to recover space.
Alex Chaube753132022-12-09 16:46:54 +0000946 cellHeightPx = (cellHeightPx * inv.numRows
947 + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows;
Alex Chaube753132022-12-09 16:46:54 +0000948 cellLayoutBorderSpacePx.y = 0;
Alex Chau06f36e82023-01-06 10:50:54 +0000949 // Reduce iconDrawablePaddingPx to make cellContentHeight smaller.
950 int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx;
951 if (cellContentWithoutPadding <= cellHeightPx) {
952 iconDrawablePaddingPx = cellContentHeight - cellHeightPx;
953 } else {
954 // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space,
955 // then proportional reduce iconSizePx and iconTextSizePx to fit.
956 iconDrawablePaddingPx = 0;
957 float ratio = cellHeightPx / (float) cellContentWithoutPadding;
958 iconSizePx = (int) (iconSizePx * ratio);
959 iconTextSizePx = (int) (iconTextSizePx * ratio);
960 }
961 cellTextAndPaddingHeight =
962 iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx);
Alex Chaube753132022-12-09 16:46:54 +0000963 }
964 cellContentHeight = iconSizePx + cellTextAndPaddingHeight;
965 }
Jon Mirandae126d722021-02-25 10:45:20 -0500966 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +0100967 desiredWorkspaceHorizontalMarginPx =
968 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -0500969 } else {
Jon Mirandae126d722021-02-25 10:45:20 -0500970 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700971 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR)
972 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -0500973 + Utilities.calculateTextHeight(iconTextSizePx);
974 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
975 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
976 && !isMultiWindowMode) {
977 // Ensures that the label is closer to its corresponding icon. This is not an issue
978 // with vertical bar layout or multi-window mode since the issue is handled
979 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
980 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
981 iconDrawablePaddingPx = cellPaddingY;
982 }
Jon Miranda846455e2017-10-02 14:58:52 -0700983 }
Jon Miranda18751b62017-07-31 17:25:27 -0700984
Sunny Goyalae190ff2020-04-14 00:19:01 +0000985 // All apps
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500986 updateAllAppsIconSize(scale, res);
Winson Chungb3800242013-10-24 11:01:54 -0700987
Thales Limab8c05952022-05-23 16:58:38 +0100988 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700989
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700990 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -0700991 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
992 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Winson Chung0f785722015-04-08 10:27:49 -0700993 }
994
Thales Lima425f6822022-05-10 13:44:58 -0300995 /**
Thales Lima6a590062022-11-22 15:52:49 +0000996 * This method calculates the space between the icons to achieve a certain width.
Thales Lima425f6822022-05-10 13:44:58 -0300997 */
Thales Lima6a590062022-11-22 15:52:49 +0000998 private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) {
Thales Lima9938c2f2022-07-25 14:38:16 +0100999 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
Thales Limaffc68b02023-01-09 16:20:23 +00001000 int hotseatBorderSpacePx =
Thales Lima6a590062022-11-22 15:52:49 +00001001 (int) (hotseatWidthPx - hotseatIconsTotalPx)
1002 / (numShownHotseatIcons - 1 + numExtraBorder);
Thales Limaffc68b02023-01-09 16:20:23 +00001003 return Math.min(hotseatBorderSpacePx, mMaxHotseatIconSpacePx);
Thales Lima425f6822022-05-10 13:44:58 -03001004 }
1005
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001006
1007 /**
1008 * Updates the iconSize for allApps* variants.
1009 */
Brian Isganitisa9a78112022-05-23 18:11:47 -07001010 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +01001011 allAppsBorderSpacePx = new Point(
1012 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
1013 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001014 // AllApps cells don't have real space between cells,
1015 // so we add the border space to the cell height
Alex Chaube753132022-12-09 16:46:54 +00001016 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics)
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001017 + allAppsBorderSpacePx.y;
1018 // but width is just the cell,
1019 // the border is added in #updateAllAppsContainerWidth
Thales Lima080d8902022-03-28 15:30:29 +01001020 if (isScalableGrid) {
Alex Chaube753132022-12-09 16:46:54 +00001021 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
1022 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001023 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001024 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Alex Chaube753132022-12-09 16:46:54 +00001025
1026 if (allAppsCellWidthPx < allAppsIconSizePx) {
1027 // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to
1028 // make allAppsCellWidth bigger.
1029 int numBorders = inv.numAllAppsColumns - 1;
1030 int extraWidthRequired =
1031 (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns;
1032 if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) {
1033 allAppsCellWidthPx = allAppsIconSizePx;
1034 allAppsBorderSpacePx.x -= extraWidthRequired / numBorders;
1035 } else {
1036 // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space
1037 // for allAppsCellWidth, and reduce allAppsIconSize.
1038 allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns
1039 + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns;
1040 allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx);
1041 allAppsBorderSpacePx.x = 0;
1042 }
1043 }
1044
1045 int cellContentHeight = allAppsIconSizePx
1046 + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y;
1047 if (allAppsCellHeightPx < cellContentHeight) {
1048 // Increase allAppsCellHeight to fit its content.
1049 allAppsCellHeightPx = cellContentHeight;
1050 }
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001051 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001052 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
1053 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001054 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
1055 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -07001056 allAppsIconDrawablePaddingPx =
1057 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -07001058 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001059 }
1060
Thales Limab7ef5692022-03-10 10:32:36 +00001061 updateAllAppsContainerWidth(res);
Brian Isganitis25b2ac82022-01-28 16:25:13 -05001062 if (isVerticalBarLayout()) {
1063 hideWorkspaceLabelsIfNotEnoughSpace();
1064 }
1065 }
1066
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001067 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001068 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001069
Thales Lima7eee74b2023-03-16 16:00:55 -03001070 // For usability we can't have the folder use the whole width of the screen
Sunny Goyal07b69292018-01-08 14:19:34 -08001071 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -08001072
Thales Lima7eee74b2023-03-16 16:00:55 -03001073 // Check if the folder fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -05001074 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Thales Lima7eee74b2023-03-16 16:00:55 -03001075 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx)
1076 + folderFooterHeightPx
1077 + folderContentPaddingTop;
1078 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001079 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -08001080
Thales Lima7eee74b2023-03-16 16:00:55 -03001081 // Check if the folder fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -05001082 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Thales Lima7eee74b2023-03-16 16:00:55 -03001083 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx)
1084 + folderContentPaddingLeftRight * 2;
1085 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -08001086 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -08001087
1088 float scale = Math.min(scaleX, scaleY);
1089 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001090 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001091 }
1092 }
1093
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001094 private void updateFolderCellSize(float scale, Resources res) {
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001095 float invIconSizeDp = inv.iconSize[mTypeIndex];
Sunny Goyal35c7b192021-04-20 16:51:10 -07001096 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Alex Chau0d4f1ac2022-12-20 12:31:14 +00001097 folderChildTextSizePx = pxFromSp(inv.iconTextSize[mTypeIndex], mMetrics, scale);
Thales Lima7eee74b2023-03-16 16:00:55 -03001098 folderLabelTextSizePx = Math.max(pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale),
Thales Limab35faed2022-09-05 16:30:01 -03001099 (int) (folderChildTextSizePx * folderLabelTextScale));
Jon Mirandabf7d8122016-11-03 15:29:29 -07001100
1101 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001102
Jon Miranda823da222021-03-23 08:08:45 -04001103 if (isScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001104 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
Thales Lima7eee74b2023-03-16 16:00:55 -03001105 folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale);
1106 folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale);
1107 } else {
1108 folderCellWidthPx = roundPxValueFromFloat(folderCellWidthPx * scale);
1109 folderCellHeightPx = roundPxValueFromFloat(folderCellHeightPx * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001110 }
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001111
Thales Lima7eee74b2023-03-16 16:00:55 -03001112 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
1113 folderCellLayoutBorderSpacePx = roundPxValueFromFloat(
1114 folderCellLayoutBorderSpacePx * scale);
1115 folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale);
1116
Thales Limab35faed2022-09-05 16:30:01 -03001117 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx;
Jon Miranda823da222021-03-23 08:08:45 -04001118 } else {
1119 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1120 * scale);
1121 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1122 * scale);
1123
1124 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1125 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Lima7eee74b2023-03-16 16:00:55 -03001126 folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
Thales Limab35faed2022-09-05 16:30:01 -03001127 folderContentPaddingLeftRight =
1128 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1129 folderFooterHeightPx =
Thales Lima7eee74b2023-03-16 16:00:55 -03001130 roundPxValueFromFloat(
1131 res.getDimensionPixelSize(R.dimen.folder_footer_height_default)
1132 * scale);
1133
Jon Miranda823da222021-03-23 08:08:45 -04001134 }
1135
Jonathan Miranda9ad87462017-07-26 17:41:02 +00001136 folderChildDrawablePaddingPx = Math.max(0,
1137 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001138 }
1139
Winson1f064272016-07-18 17:18:02 -07001140 public void updateInsets(Rect insets) {
1141 mInsets.set(insets);
1142 }
1143
Sunny Goyalae6e3182019-04-30 12:04:37 -07001144 /**
1145 * The current device insets. This is generally same as the insets being dispatched to
1146 * {@link Insettable} elements, but can differ if the element is using a different profile.
1147 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001148 public Rect getInsets() {
1149 return mInsets;
1150 }
1151
Sunny Goyal756cd262015-08-20 12:33:21 -07001152 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001153 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001154 }
1155
Sunny Goyal19ff7282021-04-22 10:12:54 -07001156 public Point getCellSize(Point result) {
1157 if (result == null) {
1158 result = new Point();
1159 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001160
Pat Manning25d53342022-05-10 09:58:49 +00001161 int shortcutAndWidgetContainerWidth =
1162 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1163 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1164 inv.numColumns);
1165 int shortcutAndWidgetContainerHeight =
1166 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1167 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1168 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001169 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001170 }
1171
1172 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001173 * Returns the left and right space on the cell, which is the cell width - icon size
1174 */
1175 public int getCellHorizontalSpace() {
1176 return getCellSize().x - iconSizePx;
1177 }
1178
1179 /**
Pat Manning25d53342022-05-10 09:58:49 +00001180 * Gets the number of panels within the workspace.
1181 */
1182 public int getPanelCount() {
1183 return isTwoPanels ? 2 : 1;
1184 }
1185
1186 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001187 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1188 * bottom of the screen.
1189 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001190 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1191 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001192 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001193 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001194 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001195 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001196 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001197 }
1198
1199 /**
1200 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1201 */
Pat Manning25d53342022-05-10 09:58:49 +00001202 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001203 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001204 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001205 }
1206
1207 /**
1208 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1209 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001210 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001211 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001212 return heightPx - (isVerticalBarLayout()
1213 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001214 }
1215
Pat Manningea5c1d22022-04-14 10:58:16 +01001216 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001217 * Gets the scale of the workspace for the spring-loaded edit state.
1218 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001219 public float getWorkspaceSpringLoadScale(Context context) {
1220 float scale =
1221 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1222 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001223 scale = Math.min(scale, 1f);
1224
Pat Manninge63dd252022-08-02 16:15:29 +01001225 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001226 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001227 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001228 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001229 if (scaledWorkspaceWidth > maxAvailableWidth) {
1230 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1231 }
1232 return scale;
1233 }
1234
Pat Manning25d53342022-05-10 09:58:49 +00001235 /**
1236 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1237 *
1238 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1239 * layouts have two Cell Layouts per workspace.
1240 */
1241 public int getCellLayoutWidth() {
1242 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001243 }
1244
Pat Manning25d53342022-05-10 09:58:49 +00001245 /**
1246 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1247 *
1248 * <p>This is the height of a Workspace, less its vertical padding.
1249 */
1250 public int getCellLayoutHeight() {
1251 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001252 }
1253
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001254 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001255 return new Point(workspacePadding.left + workspacePadding.right,
1256 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001257 }
1258
1259 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001260 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1261 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001262 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001263 private void updateWorkspacePadding() {
1264 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001265 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -08001266 padding.top = 0;
1267 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001268 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001269 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -07001270 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -07001271 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -07001272 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001273 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -07001274 }
Winson Chungb3800242013-10-24 11:01:54 -07001275 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001276 // Pad the bottom of the workspace with hotseat bar
1277 // and leave a bit of space in case a widget go all the way down
1278 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding
1279 + workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace
1280 - mInsets.bottom;
Pat Manning08610ca2022-04-05 21:03:16 +01001281 int paddingTop = workspaceTopPadding + (isScalableGrid ? 0 : edgeMarginPx);
1282 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001283
Pat Manning08610ca2022-04-05 21:03:16 +01001284 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001285 }
Pat Manning08610ca2022-04-05 21:03:16 +01001286 insetPadding(workspacePadding, cellLayoutPaddingPx);
1287 }
1288
1289 private void insetPadding(Rect paddings, Rect insets) {
1290 insets.left = Math.min(insets.left, paddings.left);
1291 paddings.left -= insets.left;
1292
1293 insets.top = Math.min(insets.top, paddings.top);
1294 paddings.top -= insets.top;
1295
1296 insets.right = Math.min(insets.right, paddings.right);
1297 paddings.right -= insets.right;
1298
1299 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1300 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001301 }
1302
Sunny Goyal57b22792021-05-25 14:35:01 -07001303 /**
1304 * Returns the padding for hotseat view
1305 */
1306 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001307 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001308 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001309 // The hotseat icons will be placed in the middle of the hotseat cells.
1310 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1311 // in vertical bar layout.
1312 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1313 // is set to account for that difference.
1314 float diffOverlapFactor = iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
Pat Manning08610ca2022-04-05 21:03:16 +01001315 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1316 - diffOverlapFactor), 0);
1317 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001318 + diffOverlapFactor), 0);
1319
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001320 if (isSeascape()) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001321 hotseatBarPadding.set(mInsets.left + hotseatBarSidePaddingStartPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001322 hotseatBarSidePaddingEndPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001323 } else {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001324 hotseatBarPadding.set(hotseatBarSidePaddingEndPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001325 mInsets.right + hotseatBarSidePaddingStartPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001326 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001327 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001328 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001329 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1330 int hotseatBarTopPadding =
1331 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001332
Thales Lima6a590062022-11-22 15:52:49 +00001333 int hotseatWidth = getHotseatRequiredWidth();
Helen Cheuke76291f2023-02-14 17:11:05 +00001334 int startSpacing;
1335 int endSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001336 // Hotseat aligns to the left with nav buttons
1337 if (hotseatBarEndOffset > 0) {
Jon Mirandae17a9492023-03-08 16:42:20 -08001338 startSpacing = inlineNavButtonsEndSpacingPx;
Helen Cheuke76291f2023-02-14 17:11:05 +00001339 endSpacing = availableWidthPx - hotseatWidth - startSpacing + hotseatBorderSpace;
1340 } else {
1341 startSpacing = (availableWidthPx - hotseatWidth) / 2;
1342 endSpacing = startSpacing;
Thales Lima6a590062022-11-22 15:52:49 +00001343 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001344 startSpacing += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001345
Helen Cheuke76291f2023-02-14 17:11:05 +00001346 hotseatBarPadding.top = hotseatBarTopPadding;
1347 hotseatBarPadding.bottom = hotseatBarBottomPadding;
Alex Chau51da2192022-05-20 13:32:10 +01001348 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001349 if (isRtl) {
Helen Cheuke76291f2023-02-14 17:11:05 +00001350 hotseatBarPadding.left = endSpacing;
1351 hotseatBarPadding.right = startSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001352 } else {
Helen Cheuke76291f2023-02-14 17:11:05 +00001353 hotseatBarPadding.left = startSpacing;
1354 hotseatBarPadding.right = endSpacing;
Thales Lima612230d2022-03-31 18:04:37 +01001355 }
Helen Cheuke76291f2023-02-14 17:11:05 +00001356
Thales Lima425f6822022-05-10 13:44:58 -03001357 } else if (isScalableGrid) {
Alex Chau206ede92022-08-01 17:46:12 +01001358 int sideSpacing = (availableWidthPx - hotseatQsbWidth) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001359 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001360 0,
Thales Lima425f6822022-05-10 13:44:58 -03001361 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001362 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001363 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001364 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1365 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1366 // for this, we pad the left and right of the hotseat with half of the difference of a
1367 // workspace cell vs a hotseat cell.
1368 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001369 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001370 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001371 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001372 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1373 + mInsets.left,
1374 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001375 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001376 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001377 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001378 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001379 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001380 }
1381
Thales Lima9938c2f2022-07-25 14:38:16 +01001382 private int getAdditionalQsbSpace() {
1383 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1384 }
1385
1386 /**
1387 * Calculate how much space the hotseat needs to be shown completely
1388 */
1389 private int getHotseatRequiredWidth() {
1390 int additionalQsbSpace = getAdditionalQsbSpace();
1391 return iconSizePx * numShownHotseatIcons
Thales Lima6a590062022-11-22 15:52:49 +00001392 + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1))
Thales Lima9938c2f2022-07-25 14:38:16 +01001393 + additionalQsbSpace;
1394 }
1395
Winsonfadbe8f2016-07-22 16:35:37 -07001396 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001397 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1398 */
1399 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001400 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001401 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1402 } else if (isTaskbarPresent) { // QSB on top
1403 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001404 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001405 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001406 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001407 }
1408
Thales Limab8c05952022-05-23 16:58:38 +01001409 /**
1410 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1411 */
1412 private int getHotseatBarBottomPadding() {
1413 if (isTaskbarPresent) { // QSB on top or inline
1414 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001415 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001416 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001417 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001418 }
1419
1420 /**
Alex Chau51da2192022-05-20 13:32:10 +01001421 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1422 */
1423 public int getTaskbarOffsetY() {
1424 int taskbarIconBottomSpace = (taskbarSize - iconSizePx) / 2;
1425 int launcherIconBottomSpace =
1426 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001427 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001428 }
1429
1430 /**
Alex Chaua2fc7642022-04-21 14:20:23 +01001431 * Returns the number of pixels required below OverviewActions excluding insets.
1432 */
1433 public int getOverviewActionsClaimedSpaceBelow() {
Alex Chaud67ddc42022-09-30 18:15:56 +01001434 if (isTaskbarPresent) {
Alex Chau8aa3f002023-02-22 20:44:27 +00001435 return transientTaskbarSize + transientTaskbarMargin * 2;
Alex Chaud67ddc42022-09-30 18:15:56 +01001436 }
1437 return mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001438 }
1439
1440 /** Gets the space that the overview actions will take, including bottom margin. */
1441 public int getOverviewActionsClaimedSpace() {
Pat Manning7b8f7662023-01-18 14:48:30 +00001442 int overviewActionsSpace = isTablet && FeatureFlags.ENABLE_GRID_ONLY_OVERVIEW.get()
1443 ? 0
1444 : (overviewActionsTopMarginPx + overviewActionsHeight);
1445 return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
Alex Chaua2fc7642022-04-21 14:20:23 +01001446 }
1447
1448 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001449 * Takes the View and return the scales of width and height depending on the DeviceProfile
1450 * specifications
1451 *
1452 * @param itemInfo The tag of the widget view
1453 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1454 * height
1455 */
1456 @NonNull
1457 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1458 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1459 }
1460
1461 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001462 * @return the bounds for which the open folders should be contained within
1463 */
1464 public Rect getAbsoluteOpenFolderBounds() {
1465 if (isVerticalBarLayout()) {
1466 // Folders should only appear right of the drop target bar and left of the hotseat
1467 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1468 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001469 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001470 mInsets.top + availableHeightPx);
1471 } else {
1472 // Folders should only appear below the drop target bar and above the hotseat
Tony Wickhamae72b462021-03-10 16:18:40 -08001473 int hotseatTop = isTaskbarPresent ? taskbarSize : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001474 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001475 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001476 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001477 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001478 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001479 }
1480 }
1481
Jon Miranda228877d2021-02-09 11:05:00 -05001482 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1483 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001484 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001485
Jon Miranda228877d2021-02-09 11:05:00 -05001486 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1487 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001488 }
1489
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001490 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001491 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1492 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1493 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001494 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001495 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001496 return isLandscape && transposeLayoutWithOrientation;
1497 }
1498
Sunny Goyal59d086c2018-05-07 17:31:40 -07001499 /**
1500 * Updates orientation information and returns true if it has changed from the previous value.
1501 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001502 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001503 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001504 boolean isSeascape = DisplayController.INSTANCE.get(context)
1505 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001506 if (mIsSeascape != isSeascape) {
1507 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001508 // Hotseat changing sides requires updating workspace left/right paddings
1509 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001510 return true;
1511 }
1512 }
1513 return false;
1514 }
1515
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001516 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001517 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001518 }
1519
Sunny Goyal07b69292018-01-08 14:19:34 -08001520 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001521 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001522 }
1523
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001524 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001525 switch (containerType) {
1526 case CellLayout.WORKSPACE:
1527 return cellHeightPx;
1528 case CellLayout.FOLDER:
1529 return folderCellHeightPx;
1530 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001531 // The hotseat is the only container where the cell height is going to be
1532 // different from the content within that cell.
1533 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001534 default:
1535 // ??
1536 return 0;
1537 }
1538 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001539
Jon Miranda58561d42021-03-17 10:51:54 -04001540 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001541 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001542 }
1543
Alex Chaue818bcb2022-09-02 17:27:11 +01001544 private String dpPointFToString(String name, PointF value) {
1545 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
1546 }
1547
Pat Manning5f74bfd2022-07-20 12:08:54 +01001548 /** Dumps various DeviceProfile variables to the specified writer. */
1549 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04001550 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001551 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001552
1553 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001554 writer.println(prefix + "\tisPhone:" + isPhone);
1555 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1556 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001557 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001558
1559 writer.println(prefix + "\tisLandscape:" + isLandscape);
1560 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001561 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001562
1563 writer.println(prefix + pxToDpStr("windowX", windowX));
1564 writer.println(prefix + pxToDpStr("windowY", windowY));
1565 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1566 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001567 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1568 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001569 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1570 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1571 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1572 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001573
1574 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1575
1576 writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
1577
Thales Lima83bedbf2021-10-05 17:47:39 +01001578 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001579 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1580 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1581 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001582
Alex Chaue818bcb2022-09-02 17:27:11 +01001583 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07001584
Jon Miranda58561d42021-03-17 10:51:54 -04001585 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1586 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1587
1588 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1589 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1590
Thales Lima83bedbf2021-10-05 17:47:39 +01001591 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1592 cellLayoutBorderSpacePx.x));
1593 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1594 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001595 writer.println(
1596 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
1597 writer.println(
1598 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
1599 writer.println(
1600 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01001601 writer.println(
1602 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01001603
Jon Miranda58561d42021-03-17 10:51:54 -04001604 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1605 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1606 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1607
Helen Cheuk599109b2023-02-23 17:15:39 +00001608 writer.println(prefix + "\tinv.numFolderRows: " + inv.numFolderRows);
1609 writer.println(prefix + "\tinv.numFolderColumns: " + inv.numFolderColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001610 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1611 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1612 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1613 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1614 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1615 folderChildDrawablePaddingPx));
Thales Limab35faed2022-09-05 16:30:01 -03001616 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx",
1617 folderCellLayoutBorderSpacePx));
Thales Limaa08a4432022-08-09 09:55:17 +01001618 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
1619 folderContentPaddingLeftRight));
1620 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03001621 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001622
Alex Chaue0227552022-04-06 19:44:43 +01001623 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001624 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
1625 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
1626 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
1627 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01001628
1629 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
1630 writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001631 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
1632 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04001633 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1634 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1635 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1636 allAppsIconDrawablePaddingPx));
1637 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001638 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001639 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
1640 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001641 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau62572c02022-07-25 18:36:37 +00001642 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
Alex Chau27b39b92022-01-14 18:02:18 +00001643 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001644
1645 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03001646 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04001647 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00001648 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Jon Miranda58561d42021-03-17 10:51:54 -04001649 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
1650 hotseatBarSidePaddingStartPx));
1651 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
1652 hotseatBarSidePaddingEndPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001653 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01001654 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
1655 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01001656 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
1657 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001658 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
1659 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
1660 hotseatLayoutPadding.top));
1661 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
1662 hotseatLayoutPadding.bottom));
1663 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
1664 hotseatLayoutPadding.left));
1665 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
1666 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001667 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001668 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001669 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01001670 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001671
1672 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001673 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda58561d42021-03-17 10:51:54 -04001674 writer.println(prefix + pxToDpStr("taskbarSize", taskbarSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001675
Thales Lima83bedbf2021-10-05 17:47:39 +01001676 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1677 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001678 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
1679 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
1680 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00001681 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001682
Jon Mirandaab3c6812021-06-28 15:42:28 -07001683 writer.println(prefix + pxToDpStr("iconScale", iconScale));
1684 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04001685 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00001686 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001687
Thales Lima171ee662022-11-22 15:52:49 +00001688 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04001689 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
1690 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00001691
1692 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00001693 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
1694 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
1695 overviewTaskIconDrawableSizePx));
1696 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
1697 overviewTaskIconDrawableSizeGridPx));
1698 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
1699 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01001700 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
1701 overviewActionsTopMarginPx));
1702 writer.println(prefix + pxToDpStr("overviewActionsHeight",
1703 overviewActionsHeight));
Alex Chau1b276a12022-12-19 14:01:36 +00001704 writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow",
1705 getOverviewActionsClaimedSpaceBelow()));
Alex Chau635b3ab2022-01-26 16:49:10 +00001706 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
1707 overviewActionsButtonSpacing));
1708 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
1709 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
1710 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01001711
Alex Chau62572c02022-07-25 18:36:37 +00001712 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001713 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00001714 writer.println(
1715 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001716
Pat Manning5f74bfd2022-07-20 12:08:54 +01001717 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
1718 getCellLayoutSpringLoadShrunkTop()));
1719 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
1720 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01001721 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
1722 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001723 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
1724 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01001725 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
1726 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Jon Miranda58561d42021-03-17 10:51:54 -04001727 }
1728
Nicolo' Mazzucatocb7bd502023-01-16 19:46:30 +00001729 /** Returns a reduced representation of this DeviceProfile. */
1730 public String toSmallString() {
1731 return "isTablet:" + isTablet + ", "
1732 + "isMultiDisplay:" + isMultiDisplay + ", "
1733 + "widthPx:" + widthPx + ", "
1734 + "heightPx:" + heightPx + ", "
1735 + "insets:" + mInsets + ", "
1736 + "rotationHint:" + rotationHint;
1737 }
1738
Alex Chaua6907dc2022-03-18 15:24:07 +00001739 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07001740 Configuration config = new Configuration(c.getResources().getConfiguration());
1741 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03001742 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00001743 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07001744 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07001745 }
Sunny Goyalfde55052018-02-01 14:46:13 -08001746
1747 /**
1748 * Callback when a component changes the DeviceProfile associated with it, as a result of
1749 * configuration change
1750 */
1751 public interface OnDeviceProfileChangeListener {
1752
1753 /**
1754 * Called when the device profile is reassigned. Note that for layout and measurements, it
1755 * is sufficient to listen for inset changes. Use this callback when you need to perform
1756 * a one time operation.
1757 */
1758 void onDeviceProfileChanged(DeviceProfile dp);
1759 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001760
Sihua Mae04aa202022-07-18 12:43:56 -07001761 /**
1762 * Handler that deals with ItemInfo of the views for the DeviceProfile
1763 */
1764 @FunctionalInterface
1765 public interface ViewScaleProvider {
1766 /**
1767 * Get the scales from the view
1768 *
1769 * @param itemInfo The tag of the widget view
1770 * @return PointF instance containing the scale information, or null if using the default
1771 * app widget scale of this device profile.
1772 */
1773 @NonNull
1774 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
1775 }
1776
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001777 public static class Builder {
1778 private Context mContext;
1779 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07001780 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001781
Sunny Goyal19ff7282021-04-22 10:12:54 -07001782 private WindowBounds mWindowBounds;
Alex Chauab800f72022-12-13 17:46:06 +00001783 private boolean mIsMultiDisplay;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001784
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001785 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001786 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00001787 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07001788 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001789
Sunny Goyal65190ae2022-08-02 14:16:26 -07001790 private SparseArray<DotRenderer> mDotRendererCache;
1791
Jon Miranda2b25ded2023-02-02 14:48:45 -08001792 private Consumer<DeviceProfile> mOverrideProvider;
1793
Sunny Goyalfd58da62020-08-11 12:06:49 -07001794 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001795 mContext = context;
1796 mInv = inv;
1797 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001798 }
1799
1800 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1801 mIsMultiWindowMode = isMultiWindowMode;
1802 return this;
1803 }
1804
Alex Chauab800f72022-12-13 17:46:06 +00001805 public Builder setIsMultiDisplay(boolean isMultiDisplay) {
1806 mIsMultiDisplay = isMultiDisplay;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001807 return this;
1808 }
1809
Sunny Goyal65190ae2022-08-02 14:16:26 -07001810 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
1811 mDotRendererCache = dotRendererCache;
1812 return this;
1813 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07001814
1815 public Builder setWindowBounds(WindowBounds bounds) {
1816 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07001817 return this;
1818 }
1819
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001820 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1821 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1822 return this;
1823 }
1824
Alex Chau6ed408f2022-03-04 12:58:05 +00001825 public Builder setGestureMode(boolean isGestureMode) {
1826 mIsGestureMode = isGestureMode;
1827 return this;
1828 }
1829
Jon Miranda2b25ded2023-02-02 14:48:45 -08001830 public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) {
1831 mOverrideProvider = overrideProvider;
1832 return this;
1833 }
1834
Sihua Mae04aa202022-07-18 12:43:56 -07001835 /**
1836 * Set the viewScaleProvider for the builder
1837 *
1838 * @param viewScaleProvider The viewScaleProvider to be set for the
Thales Limae9273ea2023-01-26 12:33:52 +00001839 * DeviceProfile
Sihua Mae04aa202022-07-18 12:43:56 -07001840 * @return This builder
1841 */
1842 @NonNull
1843 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
1844 mViewScaleProvider = viewScaleProvider;
1845 return this;
1846 }
1847
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001848 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001849 if (mWindowBounds == null) {
1850 throw new IllegalArgumentException("Window bounds not set");
1851 }
1852 if (mTransposeLayoutWithOrientation == null) {
1853 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
1854 }
Alex Chau6ed408f2022-03-04 12:58:05 +00001855 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01001856 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00001857 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001858 if (mDotRendererCache == null) {
1859 mDotRendererCache = new SparseArray<>();
1860 }
Sihua Mae04aa202022-07-18 12:43:56 -07001861 if (mViewScaleProvider == null) {
1862 mViewScaleProvider = DEFAULT_PROVIDER;
1863 }
Jon Miranda2b25ded2023-02-02 14:48:45 -08001864 if (mOverrideProvider == null) {
1865 mOverrideProvider = DEFAULT_DIMENSION_PROVIDER;
1866 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001867 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
Alex Chauab800f72022-12-13 17:46:06 +00001868 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay,
Jon Miranda2b25ded2023-02-02 14:48:45 -08001869 mIsGestureMode, mViewScaleProvider, mOverrideProvider);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001870 }
1871 }
1872
Winson Chungb3800242013-10-24 11:01:54 -07001873}