blob: 3f4d0360c1d9414444b3ed92d25549714ae96f38 [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;
Jon Miranda92c1b5d2021-07-20 13:57:16 -070026import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.ICON_OVERLAP_FACTOR;
Sunny Goyal65190ae2022-08-02 14:16:26 -070027import static com.android.launcher3.icons.GraphicsUtils.getShapePath;
Thales Limab35faed2022-09-05 16:30:01 -030028import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURCE_HANDLE;
Pat Manning5f74bfd2022-07-20 12:08:54 +010029import static com.android.launcher3.testing.shared.ResourceUtils.pxFromDp;
Jon Miranda228877d2021-02-09 11:05:00 -050030
Sunny Goyal35c7b192021-04-20 16:51:10 -070031import android.annotation.SuppressLint;
Winson Chungb3800242013-10-24 11:01:54 -070032import android.content.Context;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070033import android.content.res.Configuration;
Winson Chungb3800242013-10-24 11:01:54 -070034import android.content.res.Resources;
Thales Limab35faed2022-09-05 16:30:01 -030035import android.content.res.TypedArray;
Winson Chungb3800242013-10-24 11:01:54 -070036import android.graphics.Point;
Jon Miranda7ae64ff2016-11-21 16:18:46 -080037import android.graphics.PointF;
Winson Chungb3800242013-10-24 11:01:54 -070038import android.graphics.Rect;
Sunny Goyal35c7b192021-04-20 16:51:10 -070039import android.util.DisplayMetrics;
Sunny Goyal65190ae2022-08-02 14:16:26 -070040import android.util.SparseArray;
Sunny Goyal59d086c2018-05-07 17:31:40 -070041import android.view.Surface;
Winson Chungb3800242013-10-24 11:01:54 -070042
Sunny Goyal65190ae2022-08-02 14:16:26 -070043import androidx.annotation.NonNull;
Sihua Mae04aa202022-07-18 12:43:56 -070044import androidx.annotation.Nullable;
Sunny Goyal65190ae2022-08-02 14:16:26 -070045
Sunny Goyalc13403c2016-11-18 23:44:48 -080046import com.android.launcher3.CellLayout.ContainerType;
Jon Miranda228877d2021-02-09 11:05:00 -050047import com.android.launcher3.DevicePaddings.DevicePadding;
Alex Chaud67ddc42022-09-30 18:15:56 +010048import com.android.launcher3.config.FeatureFlags;
Tony Wickham8912b042018-11-29 15:28:53 -080049import com.android.launcher3.icons.DotRenderer;
Hyunyoung Song48cb7bc2018-09-25 17:03:34 -070050import com.android.launcher3.icons.IconNormalizer;
Sihua Mae04aa202022-07-18 12:43:56 -070051import com.android.launcher3.model.data.ItemInfo;
Sunny Goyal57b22792021-05-25 14:35:01 -070052import com.android.launcher3.uioverrides.ApiWrapper;
Sunny Goyalfd58da62020-08-11 12:06:49 -070053import com.android.launcher3.util.DisplayController;
54import com.android.launcher3.util.DisplayController.Info;
Sunny Goyalb46703d2020-05-27 17:52:03 -070055import com.android.launcher3.util.WindowBounds;
Winson1f064272016-07-18 17:18:02 -070056
Jon Miranda58561d42021-03-17 10:51:54 -040057import java.io.PrintWriter;
Brian Isganitis099945b2022-01-31 18:15:00 -050058import java.util.List;
Alex Chaue818bcb2022-09-02 17:27:11 +010059import java.util.Locale;
Jon Miranda58561d42021-03-17 10:51:54 -040060
Sunny Goyal35c7b192021-04-20 16:51:10 -070061@SuppressLint("NewApi")
Winson Chungb3800242013-10-24 11:01:54 -070062public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070063
Sunny Goyal8b9919d2021-04-07 14:45:17 -070064 private static final int DEFAULT_DOT_SIZE = 100;
Alex Chau206ede92022-08-01 17:46:12 +010065 private static final float ALL_APPS_TABLET_MAX_ROWS = 5.5f;
Thales Limab35faed2022-09-05 16:30:01 -030066 private static final float MIN_FOLDER_TEXT_SIZE_SP = 16f;
Alex Chau206ede92022-08-01 17:46:12 +010067
Sihua Mae04aa202022-07-18 12:43:56 -070068 public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f);
69 public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE;
70
Sunny Goyal57b22792021-05-25 14:35:01 -070071 // Ratio of empty space, qsb should take up to appear visually centered.
Pratyush9afe1ea2021-10-13 11:13:27 +000072 private final float mQsbCenterFactor;
Sunny Goyal1890f672020-04-30 12:28:00 -070073
Adam Cohen2e6da152015-05-06 11:42:25 -070074 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070075 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070076 private final DisplayMetrics mMetrics;
Winson Chungbe876472014-05-14 14:15:20 -070077
Sunny Goyalc6205602015-05-21 20:46:33 -070078 // Device properties
79 public final boolean isTablet;
Sunny Goyalc6205602015-05-21 20:46:33 -070080 public final boolean isPhone;
81 public final boolean transposeLayoutWithOrientation;
Sunny Goyal19ff7282021-04-22 10:12:54 -070082 public final boolean isTwoPanels;
Thales Limaa1012902022-01-13 17:58:42 +000083 public final boolean isQsbInline;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -070084
Sunny Goyalc6205602015-05-21 20:46:33 -070085 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -070086 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -080087 public final boolean isMultiWindowMode;
Alex Chau6ed408f2022-03-04 12:58:05 +000088 public final boolean isGestureMode;
Sunny Goyald70e75a2018-02-22 10:07:32 -080089
Sunny Goyal0addbf02020-04-28 14:17:35 -070090 public final int windowX;
91 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -070092 public final int widthPx;
93 public final int heightPx;
94 public final int availableWidthPx;
95 public final int availableHeightPx;
Sunny Goyal187b16c2022-03-01 16:53:23 -080096 public final int rotationHint;
Jon Mirandabba64512019-03-27 10:54:17 -070097
98 public final float aspectRatio;
99
Jon Mirandae126d722021-02-25 10:45:20 -0500100 public final boolean isScalableGrid;
Thales Lima83bedbf2021-10-05 17:47:39 +0100101 private final int mTypeIndex;
Jon Mirandae126d722021-02-25 10:45:20 -0500102
Tony Wickhamd6b40372015-09-23 18:37:57 -0700103 /**
104 * The maximum amount of left/right workspace padding as a percentage of the screen width.
105 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
106 * 7% of the screen width can be used as right padding.
107 */
108 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -0700109
Jon Miranda3f9bab22017-07-28 14:50:17 -0700110 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700111 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda80dda302021-07-28 14:14:59 -0700112 private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252;
113 private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700114
Sunny Goyalc6205602015-05-21 20:46:33 -0700115 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +0100116 public final int desiredWorkspaceHorizontalMarginOriginalPx;
117 public int desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100118 public int gridVisualizationPaddingX;
119 public int gridVisualizationPaddingY;
Thales Lima78d00ad2021-09-30 11:29:06 +0100120 public Point cellLayoutBorderSpaceOriginalPx;
121 public Point cellLayoutBorderSpacePx;
Pat Manning08610ca2022-04-05 21:03:16 +0100122 public Rect cellLayoutPaddingPx = new Rect();
123
Sunny Goyalc6205602015-05-21 20:46:33 -0700124 public final int edgeMarginPx;
Alex Chau0c4e11b2022-07-08 18:41:36 +0100125 public final float workspaceContentScale;
Alex Chau906d8822022-05-23 10:42:25 +0100126 public final int workspaceSpringLoadedMinNextPageVisiblePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700127
Jon Miranda58561d42021-03-17 10:51:54 -0400128 private final int extraSpace;
Thales Lima171ee662022-11-22 15:52:49 +0000129 private int maxEmptySpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500130 public int workspaceTopPadding;
131 public int workspaceBottomPadding;
132
Tony Wickham5edf9e22020-03-27 20:06:52 -0700133 // Workspace page indicator
134 public final int workspacePageIndicatorHeight;
135 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700136
Sunny Goyalc6205602015-05-21 20:46:33 -0700137 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400138 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700139 public int iconSizePx;
140 public int iconTextSizePx;
141 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700142 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -0700143
Jon Mirandaab3c6812021-06-28 15:42:28 -0700144 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800145 public int cellWidthPx;
146 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700147 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800148
Jon Mirandae126d722021-02-25 10:45:20 -0500149 public int cellYPaddingPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500150
Sunny Goyalc6205602015-05-21 20:46:33 -0700151 // Folder
Jon Mirandae126d722021-02-25 10:45:20 -0500152 public float folderLabelTextScale;
153 public int folderLabelTextSizePx;
Thales Limab35faed2022-09-05 16:30:01 -0300154 public int folderFooterHeightPx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700155 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700156 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700157
Jon Mirandae126d722021-02-25 10:45:20 -0500158 // Folder content
Thales Limab35faed2022-09-05 16:30:01 -0300159 public int folderCellLayoutBorderSpacePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500160 public int folderContentPaddingLeftRight;
161 public int folderContentPaddingTop;
162
Jon Mirandabf7d8122016-11-03 15:29:29 -0700163 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700164 public int folderCellWidthPx;
165 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700166
167 // Folder child
168 public int folderChildIconSizePx;
169 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700170 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700171
Sunny Goyalc6205602015-05-21 20:46:33 -0700172 // Hotseat
Thales Lima9938c2f2022-07-25 14:38:16 +0100173 public int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700174 public int hotseatCellHeightPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100175 public final boolean areNavButtonsInline;
Jon Miranda18751b62017-07-31 17:25:27 -0700176 // In portrait: size = height, in landscape: size = width
177 public int hotseatBarSizePx;
Thales Limab8c05952022-05-23 16:58:38 +0100178 public int hotseatBarBottomSpacePx;
Pat Manning26f70f72022-07-07 13:50:39 +0100179 public int hotseatBarEndOffset;
Thales Limab8c05952022-05-23 16:58:38 +0100180 public int hotseatQsbSpace;
Pat Manningde25c0d2022-04-05 19:11:26 +0100181 public int springLoadedHotseatBarTopMarginPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700182 // Start is the side next to the nav bar, end is the side next to the workspace
183 public final int hotseatBarSidePaddingStartPx;
184 public final int hotseatBarSidePaddingEndPx;
Alex Chau206ede92022-08-01 17:46:12 +0100185 public int hotseatQsbWidth; // only used when isQsbInline
Sunny Goyal57b22792021-05-25 14:35:01 -0700186 public final int hotseatQsbHeight;
Thales Limab8c05952022-05-23 16:58:38 +0100187 public final int hotseatQsbVisualHeight;
188 private final int hotseatQsbShadowHeight;
Thales Limadd027342022-01-07 12:54:37 +0000189 public int hotseatBorderSpace;
Adam Cohen2e6da152015-05-06 11:42:25 -0700190
Alex Chau3d2c0622022-09-01 21:28:14 +0100191 // Bottom sheets
192 public int bottomSheetTopPadding;
193 public int bottomSheetOpenDuration;
194 public int bottomSheetCloseDuration;
195 public float bottomSheetWorkspaceScale;
196 public float bottomSheetDepth;
197
Sunny Goyalc6205602015-05-21 20:46:33 -0700198 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000199 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000200 public int allAppsShiftRange;
201 public int allAppsTopPadding;
Alex Chau3d2c0622022-09-01 21:28:14 +0100202 public int allAppsOpenDuration;
203 public int allAppsCloseDuration;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700204 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700205 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700206 public int allAppsIconSizePx;
207 public int allAppsIconDrawablePaddingPx;
sfufa@google.comde013292021-09-21 18:22:44 -0700208 public int allAppsLeftRightPadding;
Alex Chau27b39b92022-01-14 18:02:18 +0000209 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700210 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700211 public float allAppsIconTextSizePx;
212
Zak Cohen334efeb2021-03-19 16:42:07 -0700213 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700214 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000215 public int overviewTaskIconSizePx;
Alex Chauac9df382021-08-02 19:08:41 +0100216 public int overviewTaskIconDrawableSizePx;
217 public int overviewTaskIconDrawableSizeGridPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000218 public int overviewTaskThumbnailTopMarginPx;
Alex Chau19c6eca2022-03-10 20:12:56 +0000219 public final int overviewActionsHeight;
Alex Chaua2fc7642022-04-21 14:20:23 +0100220 public final int overviewActionsTopMarginPx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000221 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100222 public int overviewPageSpacing;
223 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000224 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700225
Jeremy Sim0ac47082022-10-10 13:59:40 -0700226 // Split staging
227 public int splitPlaceholderInset;
228
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800229 // Widgets
Sihua Mae04aa202022-07-18 12:43:56 -0700230 private final ViewScaleProvider mViewScaleProvider;
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800231
Sunny Goyal47328fd2016-05-25 18:56:41 -0700232 // Drop Target
233 public int dropTargetBarSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100234 public int dropTargetBarTopMarginPx;
235 public int dropTargetBarBottomMarginPx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100236 public int dropTargetDragPaddingPx;
237 public int dropTargetTextSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100238 public int dropTargetHorizontalPaddingPx;
239 public int dropTargetVerticalPaddingPx;
240 public int dropTargetGapPx;
Alex Chau5b019302022-05-23 10:42:25 +0100241 public int dropTargetButtonWorkspaceEdgeGapPx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700242
Winson1f064272016-07-18 17:18:02 -0700243 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800244 private final Rect mInsets = new Rect();
245 public final Rect workspacePadding = new Rect();
Jon Miranda0bd63d12019-03-06 17:29:29 -0800246 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700247 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700248
Tony Wickhamf34bee82018-12-03 18:11:39 -0800249 // Notification dots
Sunny Goyal65190ae2022-08-02 14:16:26 -0700250 public final DotRenderer mDotRendererWorkSpace;
251 public final DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800252
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100253 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800254 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000255 // Whether Taskbar will inset the bottom of apps by taskbarSize.
256 public boolean isTaskbarPresentInApps;
Tony Wickham15883892021-02-12 11:24:40 -0800257 public int taskbarSize;
Alex Chau6a7d1e22022-01-20 19:54:17 +0000258 public int stashedTaskbarSize;
Alex Chau905e0f12022-11-14 21:55:37 +0000259 public int transientTaskbarMargin;
Tony Wickham15883892021-02-12 11:24:40 -0800260
Alex Chaua02eddc2021-04-29 00:36:06 +0100261 // DragController
262 public int flingToDeleteThresholdVelocity;
263
Vinit Nayak17c4b332021-08-05 12:54:58 -0700264 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700265 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal65190ae2022-08-02 14:16:26 -0700266 SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
Sihua Mae04aa202022-07-18 12:43:56 -0700267 boolean transposeLayoutWithOrientation, boolean useTwoPanels, boolean isGestureMode,
268 @NonNull final ViewScaleProvider viewScaleProvider) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700269
Adam Cohen2e6da152015-05-06 11:42:25 -0700270 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700271 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800272 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500273 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +0000274 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700275 windowX = windowBounds.bounds.left;
276 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800277 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100278 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700279
Jon Mirandae126d722021-02-25 10:45:20 -0500280 isScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000281 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700282 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000283 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700284 isPhone = !isTablet;
Alex Chau90125822021-11-17 14:16:58 +0000285 isTwoPanels = isTablet && useTwoPanels;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800286 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700287
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000288 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000289 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700290 ? Configuration.ORIENTATION_LANDSCAPE
291 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000292 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700293 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000294 mMetrics = res.getDisplayMetrics();
295
296 // Determine sizes.
297 widthPx = windowBounds.bounds.width();
298 heightPx = windowBounds.bounds.height();
299 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100300 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000301
302 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
303 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
304 mQsbCenterFactor = res.getFloat(R.dimen.qsb_center_factor);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700305
Thales Lima83bedbf2021-10-05 17:47:39 +0100306 if (isTwoPanels) {
307 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000308 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100309 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000310 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100311 }
312 } else {
313 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000314 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100315 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000316 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100317 }
318 }
319
Tony Wickham15883892021-02-12 11:24:40 -0800320 if (isTaskbarPresent) {
Jon Miranda7e819502022-11-03 10:56:32 -0700321 if (DisplayController.isTransientTaskbar(context)) {
322 taskbarSize = res.getDimensionPixelSize(R.dimen.transient_taskbar_size);
323 stashedTaskbarSize =
324 res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_size);
Alex Chau905e0f12022-11-14 21:55:37 +0000325 transientTaskbarMargin =
326 res.getDimensionPixelSize(R.dimen.transient_taskbar_margin);
Jon Miranda7e819502022-11-03 10:56:32 -0700327 } else {
328 taskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_size);
329 stashedTaskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
330 }
Tony Wickham15883892021-02-12 11:24:40 -0800331 }
Tony Wickham15883892021-02-12 11:24:40 -0800332
Winson Chungb3800242013-10-24 11:01:54 -0700333 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100334 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700335
Thales Limad90faab2021-09-21 17:18:47 +0100336 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
337 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100338 gridVisualizationPaddingX = res.getDimensionPixelSize(
339 R.dimen.grid_visualization_horizontal_cell_spacing);
340 gridVisualizationPaddingY = res.getDimensionPixelSize(
341 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500342
Alex Chaue0227552022-04-06 19:44:43 +0100343 bottomSheetTopPadding = mInsets.top // statusbar height
Andras Kloczl142b0542022-03-09 21:26:02 +0000344 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
345 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
Alex Chau3d2c0622022-09-01 21:28:14 +0100346 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
347 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
348 if (isTablet) {
349 bottomSheetWorkspaceScale = workspaceContentScale;
350 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
351 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
352 // When depth is 1, wallpaper zoom is set to 1.
353 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
354 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
355 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
356 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
357 } else {
358 bottomSheetWorkspaceScale = 1f;
359 bottomSheetDepth = 0f;
360 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000361
Jon Mirandae126d722021-02-25 10:45:20 -0500362 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
Thales Limab35faed2022-09-05 16:30:01 -0300363
364 if (inv.folderStyle != INVALID_RESOURCE_HANDLE) {
365 TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
366 R.styleable.FolderDisplayStyle);
367 // These are re-set in #updateFolderCellSize if the grid is not scalable
368 folderCellHeightPx = folderStyle.getDimensionPixelSize(
369 R.styleable.FolderDisplayStyle_folderCellHeight, 0);
370 folderCellWidthPx = folderStyle.getDimensionPixelSize(
371 R.styleable.FolderDisplayStyle_folderCellWidth, 0);
372
373 folderContentPaddingTop = folderStyle.getDimensionPixelSize(
374 R.styleable.FolderDisplayStyle_folderTopPadding, 0);
375 folderCellLayoutBorderSpacePx = folderStyle.getDimensionPixelSize(
376 R.styleable.FolderDisplayStyle_folderBorderSpace, 0);
377 folderFooterHeightPx = folderStyle.getDimensionPixelSize(
378 R.styleable.FolderDisplayStyle_folderFooterHeight, 0);
379 folderStyle.recycle();
380 } else {
381 folderCellLayoutBorderSpacePx = 0;
382 folderFooterHeightPx = 0;
383 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
384 }
Jon Mirandae126d722021-02-25 10:45:20 -0500385
Thales Lima78d00ad2021-09-30 11:29:06 +0100386 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv);
Thales Limab35faed2022-09-05 16:30:01 -0300387 cellLayoutBorderSpaceOriginalPx = new Point(cellLayoutBorderSpacePx);
Thales Lima85c942f2021-12-31 13:04:20 +0000388 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000389 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
390 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Jon Mirandae126d722021-02-25 10:45:20 -0500391
Tony Wickham5edf9e22020-03-27 20:06:52 -0700392 workspacePageIndicatorHeight = res.getDimensionPixelSize(
393 R.dimen.workspace_page_indicator_height);
394 mWorkspacePageIndicatorOverlapWorkspace =
395 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700396
Winson Chungb3800242013-10-24 11:01:54 -0700397 iconDrawablePaddingOriginalPx =
398 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Alex Chaua02eddc2021-04-29 00:36:06 +0100399
Sunny Goyal47328fd2016-05-25 18:56:41 -0700400 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100401 dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
402 dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100403 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
404 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100405 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
406 R.dimen.drop_target_button_drawable_horizontal_padding);
407 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
408 R.dimen.drop_target_button_drawable_vertical_padding);
409 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100410 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
411 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100412
Alex Chau906d8822022-05-23 10:42:25 +0100413 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
414 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700415
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700416 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700417
Thales Limaa1012902022-01-13 17:58:42 +0000418 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100419 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
420 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
421
Thales Lima12d0eff2022-03-25 17:06:11 +0000422 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
423 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
424 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
425 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
426 && hotseatQsbHeight > 0;
427 isQsbInline = inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000428
Thales Lima425f6822022-05-10 13:44:58 -0300429 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100430 numShownHotseatIcons =
431 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000432
Sunny Goyal19ff7282021-04-22 10:12:54 -0700433 numShownAllAppsColumns =
434 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100435
436 int hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
437 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
438 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
439 // Have a little space between the inset and the QSB
440 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
441 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
442
443 // Only change the spaces if there is space
444 if (availableSpace > 0) {
445 // Make sure there is enough space between hotseat/QSB and QSB/navBar
446 if (availableSpace < minQsbMargin * 2) {
447 minQsbMargin = availableSpace / 2;
448 hotseatQsbSpace = minQsbMargin;
449 } else {
450 hotseatQsbSpace -= minQsbMargin;
451 }
452 }
453 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
454
Thales Limaa1012902022-01-13 17:58:42 +0000455 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100456 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
Thales Limaa1012902022-01-13 17:58:42 +0000457 }
Thales Lima425f6822022-05-10 13:44:58 -0300458
Pat Manningde25c0d2022-04-05 19:11:26 +0100459 springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
460 R.dimen.spring_loaded_hotseat_top_margin);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700461 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800462 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700463 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700464 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Thales Limab8c05952022-05-23 16:58:38 +0100465 updateHotseatSizes(pxFromDp(inv.iconSize[INDEX_DEFAULT], mMetrics));
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700466 if (areNavButtonsInline && !isPhone) {
Pat Manning26f70f72022-07-07 13:50:39 +0100467 /*
468 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700469 * Spacing between nav buttons +
Pat Manning26f70f72022-07-07 13:50:39 +0100470 * Little space at the end for contextual buttons +
471 * Little space between icons and nav buttons
472 */
473 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700474 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
475 + res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing)
Pat Manning26f70f72022-07-07 13:50:39 +0100476 + res.getDimensionPixelSize(R.dimen.taskbar_hotseat_nav_spacing);
477 } else {
478 hotseatBarEndOffset = 0;
479 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700480
Alex Chau635b3ab2022-01-26 16:49:10 +0000481 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chau5fd9d492021-07-22 17:27:11 +0100482 overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100483 overviewTaskIconDrawableSizePx =
484 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
485 overviewTaskIconDrawableSizeGridPx =
486 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700487 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx;
Jeremy Sim3c2c3f12022-05-16 20:37:43 -0700488 overviewActionsTopMarginPx = res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000489 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
490 overviewActionsButtonSpacing = res.getDimensionPixelSize(
491 R.dimen.overview_actions_button_spacing);
Alex Chau19c6eca2022-03-10 20:12:56 +0000492 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700493 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000494 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700495
Jeremy Sim0ac47082022-10-10 13:59:40 -0700496 splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset);
497
Jon Miranda2ed276e2017-06-29 11:36:34 -0700498 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400499 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700500
Jon Miranda2ed276e2017-06-29 11:36:34 -0700501 // Now that we have all of the variables calculated, we can tune certain sizes.
Thales Limaae0d7ef2022-11-16 15:53:43 +0000502 if (isScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400503 // Paddings were created assuming no scaling, so we first unscale the extra space.
Jon Mirandaab3c6812021-06-28 15:42:28 -0700504 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
Thales Limaae0d7ef2022-11-16 15:53:43 +0000505 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
506 DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
Thales Lima171ee662022-11-22 15:52:49 +0000507 maxEmptySpace = padding.getMaxEmptySpacePx();
Jon Miranda228877d2021-02-09 11:05:00 -0500508
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400509 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
510 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
511 int paddingHotseatBottom = padding.getHotseatBottomPadding(unscaledExtraSpace);
512
Jon Mirandaab3c6812021-06-28 15:42:28 -0700513 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
514 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700515 }
Pat Manning08610ca2022-04-05 21:03:16 +0100516
517 int cellLayoutPadding =
518 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
519 R.dimen.cell_layout_padding);
520 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
521 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800522 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800523
Thales Lima425f6822022-05-10 13:44:58 -0300524 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima9938c2f2022-07-25 14:38:16 +0100525 recalculateHotseatWidthAndBorderSpace(res);
Alex Chau206ede92022-08-01 17:46:12 +0100526
527 // AllApps height calculation depends on updated cellSize
528 if (isTablet) {
529 int collapseHandleHeight =
530 res.getDimensionPixelOffset(R.dimen.bottom_sheet_handle_area_height);
531 int contentHeight = heightPx - collapseHandleHeight - hotseatQsbHeight;
532 int targetContentHeight = (int) (allAppsCellHeightPx * ALL_APPS_TABLET_MAX_ROWS);
533 allAppsTopPadding = Math.max(mInsets.top, contentHeight - targetContentHeight);
534 allAppsShiftRange = heightPx - allAppsTopPadding;
535 } else {
536 allAppsTopPadding = 0;
537 allAppsShiftRange =
538 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
539 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100540 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
541 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300542
Alex Chaua02eddc2021-04-29 00:36:06 +0100543 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
544 R.dimen.drag_flingToDeleteMinVelocity);
545
Sihua Mae04aa202022-07-18 12:43:56 -0700546 mViewScaleProvider = viewScaleProvider;
547
Tony Wickham1237df02017-02-24 08:59:36 -0800548 // This is done last, after iconSizePx is calculated above.
Sunny Goyal65190ae2022-08-02 14:16:26 -0700549 mDotRendererWorkSpace = createDotRenderer(iconSizePx, dotRendererCache);
550 mDotRendererAllApps = createDotRenderer(allAppsIconSizePx, dotRendererCache);
551 }
552
553 private static DotRenderer createDotRenderer(
554 int size, @NonNull SparseArray<DotRenderer> cache) {
555 DotRenderer renderer = cache.get(size);
556 if (renderer == null) {
557 renderer = new DotRenderer(size, getShapePath(DEFAULT_DOT_SIZE), DEFAULT_DOT_SIZE);
558 cache.put(size, renderer);
559 }
560 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700561 }
562
Thales Lima425f6822022-05-10 13:44:58 -0300563 /**
564 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
565 * width of the hotseat.
566 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100567 private int calculateQsbWidth(int hotseatBorderSpace) {
Thales Lima425f6822022-05-10 13:44:58 -0300568 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100569 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300570 return getIconToIconWidthForColumns(columns)
571 - iconSizePx * numShownHotseatIcons
572 - hotseatBorderSpace * numShownHotseatIcons;
573 } else {
574 int columns = inv.hotseatColumnSpan[mTypeIndex];
575 return getIconToIconWidthForColumns(columns);
576 }
577 }
Thales Lima2903a622022-03-17 13:52:19 +0000578
Thales Lima425f6822022-05-10 13:44:58 -0300579 private int getIconToIconWidthForColumns(int columns) {
580 return columns * getCellSize().x
581 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400582 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000583 }
584
Thales Limad90faab2021-09-21 17:18:47 +0100585 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
586 if (isVerticalBarLayout()) {
587 return 0;
588 }
589
Thales Lima83bedbf2021-10-05 17:47:39 +0100590 return isScalableGrid
591 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
592 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100593 }
594
Thales Limab8c05952022-05-23 16:58:38 +0100595 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
596 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700597 // Ensure there is enough space for folder icons, which have a slightly larger radius.
598 hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR);
Thales Limab8c05952022-05-23 16:58:38 +0100599
Jon Miranda0d284852021-06-22 14:50:55 -0700600 if (isVerticalBarLayout()) {
601 hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
602 + hotseatBarSidePaddingEndPx;
Thales Limab8c05952022-05-23 16:58:38 +0100603 } else if (isQsbInline) {
604 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
605 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700606 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100607 hotseatBarSizePx = hotseatIconSizePx
608 + hotseatQsbSpace
609 + hotseatQsbVisualHeight
610 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700611 }
612 }
613
Thales Lima9938c2f2022-07-25 14:38:16 +0100614 private void recalculateHotseatWidthAndBorderSpace(Resources res) {
615 hotseatBorderSpace = calculateHotseatBorderSpace();
616 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
617 // Spaces should be correct when there nav buttons are not inline
618 if (!areNavButtonsInline) {
619 return;
620 }
621
622 // Get the maximum width that the hotseat can be
623 int columns = getPanelCount() * inv.numColumns;
624 int maxHotseatWidth = getIconToIconWidthForColumns(columns);
625 int sideSpace = (availableWidthPx - maxHotseatWidth) / 2;
626 int inlineButtonsOverlap = Math.max(0, hotseatBarEndOffset - sideSpace);
627 // decrease how much the nav buttons go "inside" the hotseat
628 maxHotseatWidth -= inlineButtonsOverlap;
629
630 // Get how much space is required to show the hotseat with QSB
631 int requiredWidth = getHotseatRequiredWidth();
632
633 // If spaces are fine, use them
634 if (requiredWidth <= maxHotseatWidth) {
635 return;
636 }
637
638 // Calculate the difference of widths and remove a little from each space between icons
639 // and QSB if it's inline
640 int spaceDiff = requiredWidth - maxHotseatWidth;
641 int numOfSpaces = numShownHotseatIcons - (isQsbInline ? 0 : 1);
642 hotseatBorderSpace -= (spaceDiff / numOfSpaces);
643
644 int minHotseatIconSpaceDp = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
645 int minHotseatQsbWidthDp = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
646
647 if (hotseatBorderSpace >= minHotseatIconSpaceDp) {
648 return;
649 }
650
651 // Border space can't be less than the minimum
652 hotseatBorderSpace = minHotseatIconSpaceDp;
653 requiredWidth = getHotseatRequiredWidth();
654
655 // If there is an inline qsb, change its size
656 if (isQsbInline) {
657 hotseatQsbWidth -= requiredWidth - maxHotseatWidth;
658 if (hotseatQsbWidth >= minHotseatQsbWidthDp) {
659 return;
660 }
661
662 // QSB can't be less than the minimum
663 hotseatQsbWidth = minHotseatQsbWidthDp;
664 }
665
666 // If it still doesn't fit, start removing icons
667 do {
668 numShownHotseatIcons--;
669 requiredWidth = getHotseatRequiredWidth();
670 } while (requiredWidth > maxHotseatWidth && numShownHotseatIcons > 1);
671
672 // Add back some space between the icons
673 spaceDiff = maxHotseatWidth - requiredWidth;
674 numOfSpaces = numShownHotseatIcons - (isQsbInline ? 0 : 1);
675 hotseatBorderSpace += (spaceDiff / numOfSpaces);
676 }
677
Thales Lima78d00ad2021-09-30 11:29:06 +0100678 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100679 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100680 }
681
682 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100683 if (!isScalableGrid) {
684 return new Point(0, 0);
685 }
686
Thales Lima080d8902022-03-28 15:30:29 +0100687 int horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
688 int verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
Thales Lima78d00ad2021-09-30 11:29:06 +0100689
690 return new Point(horizontalSpacePx, verticalSpacePx);
691 }
692
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700693 public Info getDisplayInfo() {
694 return mInfo;
695 }
696
Jon Miranda611dba42021-03-02 14:12:13 -0500697 /**
698 * We inset the widget padding added by the system and instead rely on the border spacing
699 * between cells to create reliable consistency between widgets
700 */
701 public boolean shouldInsetWidgets() {
702 Rect widgetPadding = inv.defaultWidgetPadding;
703
Jon Miranda49811182021-06-03 09:52:40 -0700704 // Check all sides to ensure that the widget won't overlap into another cell, or into
705 // status bar.
706 return workspaceTopPadding > widgetPadding.top
Thales Lima78d00ad2021-09-30 11:29:06 +0100707 && cellLayoutBorderSpacePx.x > widgetPadding.left
708 && cellLayoutBorderSpacePx.y > widgetPadding.top
709 && cellLayoutBorderSpacePx.x > widgetPadding.right
710 && cellLayoutBorderSpacePx.y > widgetPadding.bottom;
Jon Miranda611dba42021-03-02 14:12:13 -0500711 }
Jon Mirandae126d722021-02-25 10:45:20 -0500712
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700713 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800714 WindowBounds bounds = new WindowBounds(
715 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700716 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100717 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700718
719 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
720 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
721 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
722
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700723 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700724 .setWindowBounds(bounds)
725 .setUseTwoPanels(isTwoPanels)
Alex Chau6ed408f2022-03-04 12:58:05 +0000726 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700727 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000728 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800729 }
730
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700731 public DeviceProfile copy(Context context) {
732 return toBuilder(context).build();
733 }
734
735 /**
736 * TODO: Move this to the builder as part of setMultiWindowMode
737 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700738 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700739 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700740 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700741 .setMultiWindowMode(true)
742 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800743
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800744 // We use these scales to measure and layout the widgets using their full invariant profile
745 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
746 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
747 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700748 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
749 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
750 profile = profile.toBuilder(context)
751 .setViewScaleProvider(i -> p)
752 .build();
753 }
754
755 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800756
Jon Miranda93e1f042016-11-11 14:13:04 -0800757 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700758 }
759
Adam Cohen63f1ec02014-08-12 09:23:13 -0700760 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400761 * Checks if there is enough space for labels on the workspace.
762 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700763 * It is important to call this method after the All Apps variables have been set.
764 */
Jon Miranda941375e2021-03-31 13:10:45 -0400765 private void hideWorkspaceLabelsIfNotEnoughSpace() {
766 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
767 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
768 - iconTextHeight;
769
770 // We want enough space so that the text is closer to its corresponding icon.
771 if (workspaceCellPaddingY < iconTextHeight) {
772 iconTextSizePx = 0;
773 iconDrawablePaddingPx = 0;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700774 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda941375e2021-03-31 13:10:45 -0400775 autoResizeAllAppsCells();
776 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700777 }
Jon Miranda1091e532017-07-21 13:31:50 -0700778
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700779 /**
780 * Re-computes the all-apps cell size to be independent of workspace
781 */
782 public void autoResizeAllAppsCells() {
Jon Miranda941375e2021-03-31 13:10:45 -0400783 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
784 int topBottomPadding = textHeight;
Jon Miranda1091e532017-07-21 13:31:50 -0700785 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
Jon Miranda941375e2021-03-31 13:10:45 -0400786 + textHeight + (topBottomPadding * 2);
Jon Miranda1091e532017-07-21 13:31:50 -0700787 }
788
Thales Limab7ef5692022-03-10 10:32:36 +0000789 private void updateAllAppsContainerWidth(Resources res) {
Pat Manning08610ca2022-04-05 21:03:16 +0100790 int cellLayoutHorizontalPadding =
791 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
Alex Chau27b39b92022-01-14 18:02:18 +0000792 if (isTablet) {
Thales Limab7ef5692022-03-10 10:32:36 +0000793 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100794 res.getDimensionPixelSize(R.dimen.all_apps_bottom_sheet_horizontal_padding);
795
sfufa@google.comde013292021-09-21 18:22:44 -0700796 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
Thales Limab7ef5692022-03-10 10:32:36 +0000797 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Alex Chau27b39b92022-01-14 18:02:18 +0000798 + allAppsLeftRightPadding * 2;
799 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
sfufa@google.comde013292021-09-21 18:22:44 -0700800 } else {
801 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100802 desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding;
sfufa@google.comde013292021-09-21 18:22:44 -0700803 }
804 }
805
Jon Miranda228877d2021-02-09 11:05:00 -0500806 /**
807 * Returns the amount of extra (or unused) vertical space.
808 */
809 private int updateAvailableDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700810 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800811
Pat Manning08610ca2022-04-05 21:03:16 +0100812 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -0500813
814 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +0100815 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +0000816 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -0500817 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500818 float scaleY = maxHeight / usedHeight;
819 boolean shouldScale = scaleY < 1f;
820
821 float scaleX = 1f;
822 if (isScalableGrid) {
823 // We scale to fit the cellWidth and cellHeight in the available space.
824 // The benefit of scalable grids is that we can get consistent aspect ratios between
825 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +0100826 float usedWidth =
827 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500828 // We do not subtract padding here, as we also scale the workspace padding if needed.
829 scaleX = availableWidthPx / usedWidth;
830 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700831 }
Jon Mirandae126d722021-02-25 10:45:20 -0500832
833 if (shouldScale) {
834 float scale = Math.min(scaleX, scaleY);
835 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +0100836 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -0500837 }
838
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700839 updateAvailableFolderCellDimensions(res);
Jon Miranda228877d2021-02-09 11:05:00 -0500840 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700841 }
842
Pat Manninga2e14992022-04-22 11:29:17 +0100843 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +0100844 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
845 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
846 }
847
Pat Manninga2e14992022-04-22 11:29:17 +0100848 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +0000849 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +0100850 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
851 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -0500852 }
853
Jon Miranda6f7e9702019-09-16 14:44:14 -0700854 /**
855 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
856 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
857 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
858 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800859 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -0700860 // Icon scale should never exceed 1, otherwise pixellation may occur.
861 iconScale = Math.min(1f, scale);
862 cellScaleToFit = scale;
863
Jon Miranda18751b62017-07-31 17:25:27 -0700864 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800865 final boolean isVerticalLayout = isVerticalBarLayout();
Thales Lima83bedbf2021-10-05 17:47:39 +0100866 float invIconSizeDp = inv.iconSize[mTypeIndex];
867 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
Andras Kloczl30fe9152021-08-05 18:02:29 +0200868
Jon Mirandaab3c6812021-06-28 15:42:28 -0700869 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, iconScale));
Jon Mirandaab3c6812021-06-28 15:42:28 -0700870 iconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * iconScale);
871 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700872
Thales Lima080d8902022-03-28 15:30:29 +0100873 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500874
875 if (isScalableGrid) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100876 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
877 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500878 int cellContentHeight = iconSizePx + iconDrawablePaddingPx
879 + Utilities.calculateTextHeight(iconTextSizePx);
880 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +0100881 desiredWorkspaceHorizontalMarginPx =
882 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -0500883 } else {
Jon Mirandae126d722021-02-25 10:45:20 -0500884 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700885 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR)
886 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -0500887 + Utilities.calculateTextHeight(iconTextSizePx);
888 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
889 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
890 && !isMultiWindowMode) {
891 // Ensures that the label is closer to its corresponding icon. This is not an issue
892 // with vertical bar layout or multi-window mode since the issue is handled
893 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
894 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
895 iconDrawablePaddingPx = cellPaddingY;
896 }
Jon Miranda846455e2017-10-02 14:58:52 -0700897 }
Jon Miranda18751b62017-07-31 17:25:27 -0700898
Sunny Goyalae190ff2020-04-14 00:19:01 +0000899 // All apps
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500900 updateAllAppsIconSize(scale, res);
Winson Chungb3800242013-10-24 11:01:54 -0700901
Thales Limab8c05952022-05-23 16:58:38 +0100902 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700903
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700904 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -0700905 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
906 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Winson Chung0f785722015-04-08 10:27:49 -0700907 }
908
Thales Lima425f6822022-05-10 13:44:58 -0300909 /**
910 * Hotseat width spans a certain number of columns on scalable grids.
911 * This method calculates the space between the icons to achieve that width.
912 */
913 private int calculateHotseatBorderSpace() {
914 if (!isScalableGrid) return 0;
Thales Lima9938c2f2022-07-25 14:38:16 +0100915 int columns = inv.hotseatColumnSpan[mTypeIndex];
916 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
917 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
918 return (int) (hotseatWidthPx - hotseatIconsTotalPx) / (numShownHotseatIcons - 1);
Thales Lima425f6822022-05-10 13:44:58 -0300919 }
920
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500921
922 /**
923 * Updates the iconSize for allApps* variants.
924 */
Brian Isganitisa9a78112022-05-23 18:11:47 -0700925 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +0100926 allAppsBorderSpacePx = new Point(
927 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
928 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700929 // AllApps cells don't have real space between cells,
930 // so we add the border space to the cell height
931 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics, scale)
932 + allAppsBorderSpacePx.y;
933 // but width is just the cell,
934 // the border is added in #updateAllAppsContainerWidth
Thales Lima080d8902022-03-28 15:30:29 +0100935 if (isScalableGrid) {
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500936 allAppsIconSizePx =
Brandon Dayauon969f6a82022-05-19 09:46:47 -0700937 pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics, scale);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500938 allAppsIconTextSizePx =
Brandon Dayauon969f6a82022-05-19 09:46:47 -0700939 pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics, scale);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500940 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -0700941 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500942 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700943 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
944 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500945 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
946 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700947 allAppsIconDrawablePaddingPx =
948 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -0700949 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500950 }
951
Thales Limab7ef5692022-03-10 10:32:36 +0000952 updateAllAppsContainerWidth(res);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500953 if (isVerticalBarLayout()) {
954 hideWorkspaceLabelsIfNotEnoughSpace();
955 }
956 }
957
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700958 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700959 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700960
Jon Mirandac1b23992016-12-13 08:57:36 -0800961 // Don't let the folder get too close to the edges of the screen.
Jon Miranda1786df32018-09-25 13:05:23 -0700962 int folderMargin = edgeMarginPx * 2;
Sunny Goyal07b69292018-01-08 14:19:34 -0800963 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -0800964
965 // Check if the icons fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -0500966 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Thales Limab35faed2022-09-05 16:30:01 -0300967 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx);
968 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderFooterHeightPx
Jon Mirandae126d722021-02-25 10:45:20 -0500969 - folderMargin - folderContentPaddingTop;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800970 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -0800971
972 // Check if the icons fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -0500973 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Thales Limab35faed2022-09-05 16:30:01 -0300974 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx);
Jon Mirandae126d722021-02-25 10:45:20 -0500975 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin
976 - folderContentPaddingLeftRight * 2;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800977 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -0800978
979 float scale = Math.min(scaleX, scaleY);
980 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700981 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700982 }
983 }
984
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700985 private void updateFolderCellSize(float scale, Resources res) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100986 float invIconSizeDp = isVerticalBarLayout()
Thales Lima12d0eff2022-03-25 17:06:11 +0000987 ? inv.iconSize[INDEX_LANDSCAPE]
988 : inv.iconSize[INDEX_DEFAULT];
Sunny Goyal35c7b192021-04-20 16:51:10 -0700989 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Thales Lima83bedbf2021-10-05 17:47:39 +0100990 folderChildTextSizePx =
Thales Lima12d0eff2022-03-25 17:06:11 +0000991 pxFromSp(inv.iconTextSize[INDEX_DEFAULT], mMetrics, scale);
Thales Limab35faed2022-09-05 16:30:01 -0300992 folderLabelTextSizePx = Math.max(pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics),
993 (int) (folderChildTextSizePx * folderLabelTextScale));
Jon Mirandabf7d8122016-11-03 15:29:29 -0700994
995 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700996
Jon Miranda823da222021-03-23 08:08:45 -0400997 if (isScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -0300998 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
999 folderCellWidthPx = pxFromDp(getCellSize().x, mMetrics, scale);
1000 folderCellHeightPx = pxFromDp(getCellSize().y, mMetrics, scale);
1001 }
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001002
Thales Limab35faed2022-09-05 16:30:01 -03001003 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx;
Jon Miranda823da222021-03-23 08:08:45 -04001004 } else {
1005 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1006 * scale);
1007 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1008 * scale);
1009
1010 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1011 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Limab35faed2022-09-05 16:30:01 -03001012 folderContentPaddingLeftRight =
1013 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1014 folderFooterHeightPx =
1015 res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Jon Miranda823da222021-03-23 08:08:45 -04001016 }
1017
Jonathan Miranda9ad87462017-07-26 17:41:02 +00001018 folderChildDrawablePaddingPx = Math.max(0,
1019 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001020 }
1021
Winson1f064272016-07-18 17:18:02 -07001022 public void updateInsets(Rect insets) {
1023 mInsets.set(insets);
1024 }
1025
Sunny Goyalae6e3182019-04-30 12:04:37 -07001026 /**
1027 * The current device insets. This is generally same as the insets being dispatched to
1028 * {@link Insettable} elements, but can differ if the element is using a different profile.
1029 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001030 public Rect getInsets() {
1031 return mInsets;
1032 }
1033
Sunny Goyal756cd262015-08-20 12:33:21 -07001034 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001035 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001036 }
1037
Sunny Goyal19ff7282021-04-22 10:12:54 -07001038 public Point getCellSize(Point result) {
1039 if (result == null) {
1040 result = new Point();
1041 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001042
Pat Manning25d53342022-05-10 09:58:49 +00001043 int shortcutAndWidgetContainerWidth =
1044 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1045 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1046 inv.numColumns);
1047 int shortcutAndWidgetContainerHeight =
1048 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1049 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1050 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001051 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001052 }
1053
1054 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001055 * Returns the left and right space on the cell, which is the cell width - icon size
1056 */
1057 public int getCellHorizontalSpace() {
1058 return getCellSize().x - iconSizePx;
1059 }
1060
1061 /**
Pat Manning25d53342022-05-10 09:58:49 +00001062 * Gets the number of panels within the workspace.
1063 */
1064 public int getPanelCount() {
1065 return isTwoPanels ? 2 : 1;
1066 }
1067
1068 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001069 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1070 * bottom of the screen.
1071 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001072 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1073 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001074 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001075 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001076 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001077 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001078 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001079 }
1080
1081 /**
1082 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1083 */
Pat Manning25d53342022-05-10 09:58:49 +00001084 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001085 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001086 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001087 }
1088
1089 /**
1090 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1091 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001092 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001093 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001094 return heightPx - (isVerticalBarLayout()
1095 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001096 }
1097
Pat Manningea5c1d22022-04-14 10:58:16 +01001098 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001099 * Gets the scale of the workspace for the spring-loaded edit state.
1100 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001101 public float getWorkspaceSpringLoadScale(Context context) {
1102 float scale =
1103 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1104 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001105 scale = Math.min(scale, 1f);
1106
Pat Manninge63dd252022-08-02 16:15:29 +01001107 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001108 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001109 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001110 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001111 if (scaledWorkspaceWidth > maxAvailableWidth) {
1112 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1113 }
1114 return scale;
1115 }
1116
Pat Manning25d53342022-05-10 09:58:49 +00001117 /**
1118 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1119 *
1120 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1121 * layouts have two Cell Layouts per workspace.
1122 */
1123 public int getCellLayoutWidth() {
1124 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001125 }
1126
Pat Manning25d53342022-05-10 09:58:49 +00001127 /**
1128 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1129 *
1130 * <p>This is the height of a Workspace, less its vertical padding.
1131 */
1132 public int getCellLayoutHeight() {
1133 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001134 }
1135
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001136 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001137 return new Point(workspacePadding.left + workspacePadding.right,
1138 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001139 }
1140
1141 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001142 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1143 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001144 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001145 private void updateWorkspacePadding() {
1146 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001147 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -08001148 padding.top = 0;
1149 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001150 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001151 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -07001152 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -07001153 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -07001154 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001155 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -07001156 }
Winson Chungb3800242013-10-24 11:01:54 -07001157 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001158 // Pad the bottom of the workspace with hotseat bar
1159 // and leave a bit of space in case a widget go all the way down
1160 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding
1161 + workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace
1162 - mInsets.bottom;
Pat Manning08610ca2022-04-05 21:03:16 +01001163 int paddingTop = workspaceTopPadding + (isScalableGrid ? 0 : edgeMarginPx);
1164 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001165
Pat Manning08610ca2022-04-05 21:03:16 +01001166 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001167 }
Pat Manning08610ca2022-04-05 21:03:16 +01001168 insetPadding(workspacePadding, cellLayoutPaddingPx);
1169 }
1170
1171 private void insetPadding(Rect paddings, Rect insets) {
1172 insets.left = Math.min(insets.left, paddings.left);
1173 paddings.left -= insets.left;
1174
1175 insets.top = Math.min(insets.top, paddings.top);
1176 paddings.top -= insets.top;
1177
1178 insets.right = Math.min(insets.right, paddings.right);
1179 paddings.right -= insets.right;
1180
1181 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1182 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001183 }
1184
Sunny Goyal57b22792021-05-25 14:35:01 -07001185 /**
1186 * Returns the padding for hotseat view
1187 */
1188 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001189 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001190 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001191 // The hotseat icons will be placed in the middle of the hotseat cells.
1192 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1193 // in vertical bar layout.
1194 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1195 // is set to account for that difference.
1196 float diffOverlapFactor = iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
Pat Manning08610ca2022-04-05 21:03:16 +01001197 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1198 - diffOverlapFactor), 0);
1199 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001200 + diffOverlapFactor), 0);
1201
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001202 if (isSeascape()) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001203 hotseatBarPadding.set(mInsets.left + hotseatBarSidePaddingStartPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001204 hotseatBarSidePaddingEndPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001205 } else {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001206 hotseatBarPadding.set(hotseatBarSidePaddingEndPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001207 mInsets.right + hotseatBarSidePaddingStartPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001208 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001209 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001210 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001211 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1212 int hotseatBarTopPadding =
1213 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001214
Thales Lima612230d2022-03-31 18:04:37 +01001215 // Push icons to the side
Thales Lima9938c2f2022-07-25 14:38:16 +01001216 int requiredWidth = getHotseatRequiredWidth();
Pat Manning26f70f72022-07-07 13:50:39 +01001217 int hotseatWidth = Math.min(requiredWidth, availableWidthPx - hotseatBarEndOffset);
Thales Lima612230d2022-03-31 18:04:37 +01001218 int sideSpacing = (availableWidthPx - hotseatWidth) / 2;
Thales Lima612230d2022-03-31 18:04:37 +01001219
Pat Manning5f74bfd2022-07-20 12:08:54 +01001220 hotseatBarPadding.set(sideSpacing, hotseatBarTopPadding, sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001221 hotseatBarBottomPadding);
Alex Chau51da2192022-05-20 13:32:10 +01001222
1223 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001224 if (isRtl) {
Thales Lima9938c2f2022-07-25 14:38:16 +01001225 hotseatBarPadding.right += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001226 } else {
Thales Lima9938c2f2022-07-25 14:38:16 +01001227 hotseatBarPadding.left += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001228 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001229
Pat Manning26f70f72022-07-07 13:50:39 +01001230 if (hotseatBarEndOffset > sideSpacing) {
Thales Lima612230d2022-03-31 18:04:37 +01001231 int diff = isRtl
Pat Manning26f70f72022-07-07 13:50:39 +01001232 ? sideSpacing - hotseatBarEndOffset
1233 : hotseatBarEndOffset - sideSpacing;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001234 hotseatBarPadding.left -= diff;
1235 hotseatBarPadding.right += diff;
Sunny Goyal57b22792021-05-25 14:35:01 -07001236 }
Thales Lima425f6822022-05-10 13:44:58 -03001237 } else if (isScalableGrid) {
Alex Chau206ede92022-08-01 17:46:12 +01001238 int sideSpacing = (availableWidthPx - hotseatQsbWidth) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001239 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001240 0,
Thales Lima425f6822022-05-10 13:44:58 -03001241 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001242 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001243 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001244 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1245 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1246 // for this, we pad the left and right of the hotseat with half of the difference of a
1247 // workspace cell vs a hotseat cell.
1248 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001249 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001250 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001251 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001252 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1253 + mInsets.left,
1254 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001255 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001256 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001257 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001258 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001259 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001260 }
1261
Thales Lima9938c2f2022-07-25 14:38:16 +01001262 private int getAdditionalQsbSpace() {
1263 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1264 }
1265
1266 /**
1267 * Calculate how much space the hotseat needs to be shown completely
1268 */
1269 private int getHotseatRequiredWidth() {
1270 int additionalQsbSpace = getAdditionalQsbSpace();
1271 return iconSizePx * numShownHotseatIcons
1272 + hotseatBorderSpace * (numShownHotseatIcons - 1)
1273 + additionalQsbSpace;
1274 }
1275
Winsonfadbe8f2016-07-22 16:35:37 -07001276 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001277 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1278 */
1279 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001280 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001281 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1282 } else if (isTaskbarPresent) { // QSB on top
1283 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001284 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001285 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001286 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001287 }
1288
Thales Limab8c05952022-05-23 16:58:38 +01001289 /**
1290 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1291 */
1292 private int getHotseatBarBottomPadding() {
1293 if (isTaskbarPresent) { // QSB on top or inline
1294 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001295 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001296 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001297 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001298 }
1299
1300 /**
Alex Chau51da2192022-05-20 13:32:10 +01001301 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1302 */
1303 public int getTaskbarOffsetY() {
1304 int taskbarIconBottomSpace = (taskbarSize - iconSizePx) / 2;
1305 int launcherIconBottomSpace =
1306 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001307 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001308 }
1309
1310 /**
Alex Chaua2fc7642022-04-21 14:20:23 +01001311 * Returns the number of pixels required below OverviewActions excluding insets.
1312 */
1313 public int getOverviewActionsClaimedSpaceBelow() {
Alex Chaud67ddc42022-09-30 18:15:56 +01001314 if (isTaskbarPresent) {
Alex Chau905e0f12022-11-14 21:55:37 +00001315 if (FeatureFlags.ENABLE_TASKBAR_IN_OVERVIEW.get()) {
1316 return taskbarSize + transientTaskbarMargin;
1317 }
1318
1319 return isGestureMode
1320 ? stashedTaskbarSize
1321 // Align vertically to where nav buttons are.
1322 : ((taskbarSize - overviewActionsHeight) / 2) + getTaskbarOffsetY();
Alex Chaud67ddc42022-09-30 18:15:56 +01001323 }
1324 return mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001325 }
1326
1327 /** Gets the space that the overview actions will take, including bottom margin. */
1328 public int getOverviewActionsClaimedSpace() {
1329 return overviewActionsTopMarginPx + overviewActionsHeight
1330 + getOverviewActionsClaimedSpaceBelow();
1331 }
1332
1333 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001334 * Takes the View and return the scales of width and height depending on the DeviceProfile
1335 * specifications
1336 *
1337 * @param itemInfo The tag of the widget view
1338 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1339 * height
1340 */
1341 @NonNull
1342 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1343 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1344 }
1345
1346 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001347 * @return the bounds for which the open folders should be contained within
1348 */
1349 public Rect getAbsoluteOpenFolderBounds() {
1350 if (isVerticalBarLayout()) {
1351 // Folders should only appear right of the drop target bar and left of the hotseat
1352 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1353 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001354 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001355 mInsets.top + availableHeightPx);
1356 } else {
1357 // Folders should only appear below the drop target bar and above the hotseat
Tony Wickhamae72b462021-03-10 16:18:40 -08001358 int hotseatTop = isTaskbarPresent ? taskbarSize : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001359 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001360 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001361 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001362 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001363 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001364 }
1365 }
1366
Jon Miranda228877d2021-02-09 11:05:00 -05001367 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1368 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001369 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001370
Jon Miranda228877d2021-02-09 11:05:00 -05001371 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1372 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001373 }
1374
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001375 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001376 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1377 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1378 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001379 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001380 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001381 return isLandscape && transposeLayoutWithOrientation;
1382 }
1383
Sunny Goyal59d086c2018-05-07 17:31:40 -07001384 /**
1385 * Updates orientation information and returns true if it has changed from the previous value.
1386 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001387 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001388 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001389 boolean isSeascape = DisplayController.INSTANCE.get(context)
1390 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001391 if (mIsSeascape != isSeascape) {
1392 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001393 // Hotseat changing sides requires updating workspace left/right paddings
1394 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001395 return true;
1396 }
1397 }
1398 return false;
1399 }
1400
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001401 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001402 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001403 }
1404
Sunny Goyal07b69292018-01-08 14:19:34 -08001405 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001406 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001407 }
1408
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001409 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001410 switch (containerType) {
1411 case CellLayout.WORKSPACE:
1412 return cellHeightPx;
1413 case CellLayout.FOLDER:
1414 return folderCellHeightPx;
1415 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001416 // The hotseat is the only container where the cell height is going to be
1417 // different from the content within that cell.
1418 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001419 default:
1420 // ??
1421 return 0;
1422 }
1423 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001424
Jon Miranda58561d42021-03-17 10:51:54 -04001425 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001426 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001427 }
1428
Alex Chaue818bcb2022-09-02 17:27:11 +01001429 private String dpPointFToString(String name, PointF value) {
1430 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
1431 }
1432
Pat Manning5f74bfd2022-07-20 12:08:54 +01001433 /** Dumps various DeviceProfile variables to the specified writer. */
1434 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04001435 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001436 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001437
1438 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001439 writer.println(prefix + "\tisPhone:" + isPhone);
1440 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1441 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001442 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001443
1444 writer.println(prefix + "\tisLandscape:" + isLandscape);
1445 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001446 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001447
1448 writer.println(prefix + pxToDpStr("windowX", windowX));
1449 writer.println(prefix + pxToDpStr("windowY", windowY));
1450 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1451 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001452 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1453 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001454 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1455 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1456 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1457 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001458
1459 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1460
1461 writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
1462
Thales Lima83bedbf2021-10-05 17:47:39 +01001463 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001464 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1465 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1466 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001467
Alex Chaue818bcb2022-09-02 17:27:11 +01001468 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07001469
Jon Miranda58561d42021-03-17 10:51:54 -04001470 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1471 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1472
1473 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1474 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1475
Thales Lima83bedbf2021-10-05 17:47:39 +01001476 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1477 cellLayoutBorderSpacePx.x));
1478 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1479 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001480 writer.println(
1481 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
1482 writer.println(
1483 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
1484 writer.println(
1485 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01001486 writer.println(
1487 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01001488
Jon Miranda58561d42021-03-17 10:51:54 -04001489 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1490 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1491 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1492
1493 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1494 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1495 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1496 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1497 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1498 folderChildDrawablePaddingPx));
Thales Limab35faed2022-09-05 16:30:01 -03001499 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx",
1500 folderCellLayoutBorderSpacePx));
Thales Limaa08a4432022-08-09 09:55:17 +01001501 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
1502 folderContentPaddingLeftRight));
1503 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03001504 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001505
Alex Chaue0227552022-04-06 19:44:43 +01001506 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001507 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
1508 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
1509 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
1510 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01001511
1512 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
1513 writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001514 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
1515 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04001516 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1517 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1518 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1519 allAppsIconDrawablePaddingPx));
1520 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001521 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001522 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
1523 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001524 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau62572c02022-07-25 18:36:37 +00001525 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
Alex Chau27b39b92022-01-14 18:02:18 +00001526 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001527
1528 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03001529 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04001530 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00001531 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Jon Miranda58561d42021-03-17 10:51:54 -04001532 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
1533 hotseatBarSidePaddingStartPx));
1534 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
1535 hotseatBarSidePaddingEndPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001536 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01001537 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
1538 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01001539 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
1540 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001541 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
1542 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
1543 hotseatLayoutPadding.top));
1544 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
1545 hotseatLayoutPadding.bottom));
1546 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
1547 hotseatLayoutPadding.left));
1548 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
1549 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001550 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001551 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001552 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01001553 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001554
1555 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001556 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda58561d42021-03-17 10:51:54 -04001557 writer.println(prefix + pxToDpStr("taskbarSize", taskbarSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001558
Thales Lima83bedbf2021-10-05 17:47:39 +01001559 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1560 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001561 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
1562 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
1563 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00001564 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001565
Jon Mirandaab3c6812021-06-28 15:42:28 -07001566 writer.println(prefix + pxToDpStr("iconScale", iconScale));
1567 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04001568 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00001569 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001570
Thales Lima171ee662022-11-22 15:52:49 +00001571 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04001572 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
1573 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00001574
1575 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00001576 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
1577 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
1578 overviewTaskIconDrawableSizePx));
1579 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
1580 overviewTaskIconDrawableSizeGridPx));
1581 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
1582 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01001583 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
1584 overviewActionsTopMarginPx));
1585 writer.println(prefix + pxToDpStr("overviewActionsHeight",
1586 overviewActionsHeight));
Alex Chau635b3ab2022-01-26 16:49:10 +00001587 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
1588 overviewActionsButtonSpacing));
1589 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
1590 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
1591 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01001592
Alex Chau62572c02022-07-25 18:36:37 +00001593 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001594 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00001595 writer.println(
1596 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001597
Pat Manning5f74bfd2022-07-20 12:08:54 +01001598 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
1599 getCellLayoutSpringLoadShrunkTop()));
1600 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
1601 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01001602 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
1603 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001604 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
1605 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01001606 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
1607 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Jon Miranda58561d42021-03-17 10:51:54 -04001608 }
1609
Alex Chaua6907dc2022-03-18 15:24:07 +00001610 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07001611 Configuration config = new Configuration(c.getResources().getConfiguration());
1612 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03001613 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00001614 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07001615 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07001616 }
Sunny Goyalfde55052018-02-01 14:46:13 -08001617
1618 /**
1619 * Callback when a component changes the DeviceProfile associated with it, as a result of
1620 * configuration change
1621 */
1622 public interface OnDeviceProfileChangeListener {
1623
1624 /**
1625 * Called when the device profile is reassigned. Note that for layout and measurements, it
1626 * is sufficient to listen for inset changes. Use this callback when you need to perform
1627 * a one time operation.
1628 */
1629 void onDeviceProfileChanged(DeviceProfile dp);
1630 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001631
Brian Isganitis099945b2022-01-31 18:15:00 -05001632 /** Allows registering listeners for {@link DeviceProfile} changes. */
1633 public interface DeviceProfileListenable {
1634
1635 /** The current device profile. */
1636 DeviceProfile getDeviceProfile();
1637
1638 /** Registered {@link OnDeviceProfileChangeListener} instances. */
1639 List<OnDeviceProfileChangeListener> getOnDeviceProfileChangeListeners();
1640
1641 /** Notifies listeners of a {@link DeviceProfile} change. */
1642 default void dispatchDeviceProfileChanged() {
1643 DeviceProfile deviceProfile = getDeviceProfile();
1644 List<OnDeviceProfileChangeListener> listeners = getOnDeviceProfileChangeListeners();
1645 for (int i = listeners.size() - 1; i >= 0; i--) {
1646 listeners.get(i).onDeviceProfileChanged(deviceProfile);
1647 }
1648 }
1649
1650 /** Register listener for {@link DeviceProfile} changes. */
1651 default void addOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
1652 getOnDeviceProfileChangeListeners().add(listener);
1653 }
1654
1655 /** Unregister listener for {@link DeviceProfile} changes. */
1656 default void removeOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
1657 getOnDeviceProfileChangeListeners().remove(listener);
1658 }
1659 }
1660
Sihua Mae04aa202022-07-18 12:43:56 -07001661 /**
1662 * Handler that deals with ItemInfo of the views for the DeviceProfile
1663 */
1664 @FunctionalInterface
1665 public interface ViewScaleProvider {
1666 /**
1667 * Get the scales from the view
1668 *
1669 * @param itemInfo The tag of the widget view
1670 * @return PointF instance containing the scale information, or null if using the default
1671 * app widget scale of this device profile.
1672 */
1673 @NonNull
1674 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
1675 }
1676
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001677 public static class Builder {
1678 private Context mContext;
1679 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07001680 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001681
Sunny Goyal19ff7282021-04-22 10:12:54 -07001682 private WindowBounds mWindowBounds;
1683 private boolean mUseTwoPanels;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001684
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001685 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001686 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00001687 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07001688 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001689
Sunny Goyal65190ae2022-08-02 14:16:26 -07001690 private SparseArray<DotRenderer> mDotRendererCache;
1691
Sunny Goyalfd58da62020-08-11 12:06:49 -07001692 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001693 mContext = context;
1694 mInv = inv;
1695 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001696 }
1697
1698 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1699 mIsMultiWindowMode = isMultiWindowMode;
1700 return this;
1701 }
1702
Sunny Goyal19ff7282021-04-22 10:12:54 -07001703 public Builder setUseTwoPanels(boolean useTwoPanels) {
1704 mUseTwoPanels = useTwoPanels;
1705 return this;
1706 }
1707
Sunny Goyal65190ae2022-08-02 14:16:26 -07001708 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
1709 mDotRendererCache = dotRendererCache;
1710 return this;
1711 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07001712
1713 public Builder setWindowBounds(WindowBounds bounds) {
1714 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07001715 return this;
1716 }
1717
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001718 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1719 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1720 return this;
1721 }
1722
Alex Chau6ed408f2022-03-04 12:58:05 +00001723 public Builder setGestureMode(boolean isGestureMode) {
1724 mIsGestureMode = isGestureMode;
1725 return this;
1726 }
1727
Sihua Mae04aa202022-07-18 12:43:56 -07001728 /**
1729 * Set the viewScaleProvider for the builder
1730 *
1731 * @param viewScaleProvider The viewScaleProvider to be set for the
1732 * DeviceProfile
1733 * @return This builder
1734 */
1735 @NonNull
1736 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
1737 mViewScaleProvider = viewScaleProvider;
1738 return this;
1739 }
1740
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001741 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001742 if (mWindowBounds == null) {
1743 throw new IllegalArgumentException("Window bounds not set");
1744 }
1745 if (mTransposeLayoutWithOrientation == null) {
1746 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
1747 }
Alex Chau6ed408f2022-03-04 12:58:05 +00001748 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01001749 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00001750 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001751 if (mDotRendererCache == null) {
1752 mDotRendererCache = new SparseArray<>();
1753 }
Sihua Mae04aa202022-07-18 12:43:56 -07001754 if (mViewScaleProvider == null) {
1755 mViewScaleProvider = DEFAULT_PROVIDER;
1756 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001757 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
1758 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mUseTwoPanels,
Sihua Mae04aa202022-07-18 12:43:56 -07001759 mIsGestureMode, mViewScaleProvider);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001760 }
1761 }
1762
Winson Chungb3800242013-10-24 11:01:54 -07001763}