blob: 828066a1b02d9b85c179e370a14bba1d529c9f2e [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)) {
Jon Mirandaa4aaf1a2022-12-01 15:22:43 -0800322 taskbarSize = res.getDimensionPixelSize(isTwoPanels
323 ? R.dimen.transient_taskbar_two_panels_size
324 : R.dimen.transient_taskbar_size);
Jon Miranda7e819502022-11-03 10:56:32 -0700325 stashedTaskbarSize =
326 res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_size);
Alex Chau905e0f12022-11-14 21:55:37 +0000327 transientTaskbarMargin =
328 res.getDimensionPixelSize(R.dimen.transient_taskbar_margin);
Jon Miranda7e819502022-11-03 10:56:32 -0700329 } else {
330 taskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_size);
331 stashedTaskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
332 }
Tony Wickham15883892021-02-12 11:24:40 -0800333 }
Tony Wickham15883892021-02-12 11:24:40 -0800334
Winson Chungb3800242013-10-24 11:01:54 -0700335 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100336 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700337
Thales Limad90faab2021-09-21 17:18:47 +0100338 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
339 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100340 gridVisualizationPaddingX = res.getDimensionPixelSize(
341 R.dimen.grid_visualization_horizontal_cell_spacing);
342 gridVisualizationPaddingY = res.getDimensionPixelSize(
343 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500344
Alex Chaue0227552022-04-06 19:44:43 +0100345 bottomSheetTopPadding = mInsets.top // statusbar height
Andras Kloczl142b0542022-03-09 21:26:02 +0000346 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
347 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
Alex Chau3d2c0622022-09-01 21:28:14 +0100348 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
349 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
350 if (isTablet) {
351 bottomSheetWorkspaceScale = workspaceContentScale;
352 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
353 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
354 // When depth is 1, wallpaper zoom is set to 1.
355 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
356 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
357 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
358 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
359 } else {
360 bottomSheetWorkspaceScale = 1f;
361 bottomSheetDepth = 0f;
362 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000363
Jon Mirandae126d722021-02-25 10:45:20 -0500364 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
Thales Limab35faed2022-09-05 16:30:01 -0300365
366 if (inv.folderStyle != INVALID_RESOURCE_HANDLE) {
367 TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
368 R.styleable.FolderDisplayStyle);
369 // These are re-set in #updateFolderCellSize if the grid is not scalable
370 folderCellHeightPx = folderStyle.getDimensionPixelSize(
371 R.styleable.FolderDisplayStyle_folderCellHeight, 0);
372 folderCellWidthPx = folderStyle.getDimensionPixelSize(
373 R.styleable.FolderDisplayStyle_folderCellWidth, 0);
374
375 folderContentPaddingTop = folderStyle.getDimensionPixelSize(
376 R.styleable.FolderDisplayStyle_folderTopPadding, 0);
377 folderCellLayoutBorderSpacePx = folderStyle.getDimensionPixelSize(
378 R.styleable.FolderDisplayStyle_folderBorderSpace, 0);
379 folderFooterHeightPx = folderStyle.getDimensionPixelSize(
380 R.styleable.FolderDisplayStyle_folderFooterHeight, 0);
381 folderStyle.recycle();
382 } else {
383 folderCellLayoutBorderSpacePx = 0;
384 folderFooterHeightPx = 0;
385 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
386 }
Jon Mirandae126d722021-02-25 10:45:20 -0500387
Thales Lima78d00ad2021-09-30 11:29:06 +0100388 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv);
Thales Limab35faed2022-09-05 16:30:01 -0300389 cellLayoutBorderSpaceOriginalPx = new Point(cellLayoutBorderSpacePx);
Thales Lima85c942f2021-12-31 13:04:20 +0000390 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000391 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
392 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Jon Mirandae126d722021-02-25 10:45:20 -0500393
Tony Wickham5edf9e22020-03-27 20:06:52 -0700394 workspacePageIndicatorHeight = res.getDimensionPixelSize(
395 R.dimen.workspace_page_indicator_height);
396 mWorkspacePageIndicatorOverlapWorkspace =
397 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700398
Winson Chungb3800242013-10-24 11:01:54 -0700399 iconDrawablePaddingOriginalPx =
400 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Alex Chaua02eddc2021-04-29 00:36:06 +0100401
Sunny Goyal47328fd2016-05-25 18:56:41 -0700402 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100403 dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
404 dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100405 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
406 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100407 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
408 R.dimen.drop_target_button_drawable_horizontal_padding);
409 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
410 R.dimen.drop_target_button_drawable_vertical_padding);
411 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100412 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
413 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100414
Alex Chau906d8822022-05-23 10:42:25 +0100415 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
416 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700417
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700418 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700419
Thales Limaa1012902022-01-13 17:58:42 +0000420 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100421 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
422 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
423
Thales Lima12d0eff2022-03-25 17:06:11 +0000424 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
425 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
426 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
427 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
428 && hotseatQsbHeight > 0;
429 isQsbInline = inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000430
Thales Lima425f6822022-05-10 13:44:58 -0300431 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100432 numShownHotseatIcons =
433 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000434
Sunny Goyal19ff7282021-04-22 10:12:54 -0700435 numShownAllAppsColumns =
436 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100437
438 int hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
439 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
440 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
441 // Have a little space between the inset and the QSB
442 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
443 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
444
445 // Only change the spaces if there is space
446 if (availableSpace > 0) {
447 // Make sure there is enough space between hotseat/QSB and QSB/navBar
448 if (availableSpace < minQsbMargin * 2) {
449 minQsbMargin = availableSpace / 2;
450 hotseatQsbSpace = minQsbMargin;
451 } else {
452 hotseatQsbSpace -= minQsbMargin;
453 }
454 }
455 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
456
Thales Limaa1012902022-01-13 17:58:42 +0000457 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100458 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
Thales Limaa1012902022-01-13 17:58:42 +0000459 }
Thales Lima425f6822022-05-10 13:44:58 -0300460
Pat Manningde25c0d2022-04-05 19:11:26 +0100461 springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
462 R.dimen.spring_loaded_hotseat_top_margin);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700463 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800464 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700465 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700466 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Thales Limab8c05952022-05-23 16:58:38 +0100467 updateHotseatSizes(pxFromDp(inv.iconSize[INDEX_DEFAULT], mMetrics));
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700468 if (areNavButtonsInline && !isPhone) {
Pat Manning26f70f72022-07-07 13:50:39 +0100469 /*
470 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700471 * Spacing between nav buttons +
Pat Manning26f70f72022-07-07 13:50:39 +0100472 * Little space at the end for contextual buttons +
473 * Little space between icons and nav buttons
474 */
475 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700476 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
477 + res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing)
Pat Manning26f70f72022-07-07 13:50:39 +0100478 + res.getDimensionPixelSize(R.dimen.taskbar_hotseat_nav_spacing);
479 } else {
480 hotseatBarEndOffset = 0;
481 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700482
Alex Chau635b3ab2022-01-26 16:49:10 +0000483 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chau5fd9d492021-07-22 17:27:11 +0100484 overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100485 overviewTaskIconDrawableSizePx =
486 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
487 overviewTaskIconDrawableSizeGridPx =
488 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700489 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx;
Jeremy Sim3c2c3f12022-05-16 20:37:43 -0700490 overviewActionsTopMarginPx = res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000491 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
492 overviewActionsButtonSpacing = res.getDimensionPixelSize(
493 R.dimen.overview_actions_button_spacing);
Alex Chau19c6eca2022-03-10 20:12:56 +0000494 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700495 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000496 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700497
Jeremy Sim0ac47082022-10-10 13:59:40 -0700498 splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset);
499
Jon Miranda2ed276e2017-06-29 11:36:34 -0700500 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400501 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700502
Jon Miranda2ed276e2017-06-29 11:36:34 -0700503 // Now that we have all of the variables calculated, we can tune certain sizes.
Thales Limaae0d7ef2022-11-16 15:53:43 +0000504 if (isScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400505 // Paddings were created assuming no scaling, so we first unscale the extra space.
Jon Mirandaab3c6812021-06-28 15:42:28 -0700506 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
Thales Limaae0d7ef2022-11-16 15:53:43 +0000507 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
508 DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
Thales Lima171ee662022-11-22 15:52:49 +0000509 maxEmptySpace = padding.getMaxEmptySpacePx();
Jon Miranda228877d2021-02-09 11:05:00 -0500510
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400511 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
512 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
513 int paddingHotseatBottom = padding.getHotseatBottomPadding(unscaledExtraSpace);
514
Jon Mirandaab3c6812021-06-28 15:42:28 -0700515 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
516 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700517 }
Pat Manning08610ca2022-04-05 21:03:16 +0100518
519 int cellLayoutPadding =
520 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
521 R.dimen.cell_layout_padding);
522 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
523 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800524 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800525
Thales Lima425f6822022-05-10 13:44:58 -0300526 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima9938c2f2022-07-25 14:38:16 +0100527 recalculateHotseatWidthAndBorderSpace(res);
Alex Chau206ede92022-08-01 17:46:12 +0100528
529 // AllApps height calculation depends on updated cellSize
530 if (isTablet) {
531 int collapseHandleHeight =
532 res.getDimensionPixelOffset(R.dimen.bottom_sheet_handle_area_height);
533 int contentHeight = heightPx - collapseHandleHeight - hotseatQsbHeight;
534 int targetContentHeight = (int) (allAppsCellHeightPx * ALL_APPS_TABLET_MAX_ROWS);
535 allAppsTopPadding = Math.max(mInsets.top, contentHeight - targetContentHeight);
536 allAppsShiftRange = heightPx - allAppsTopPadding;
537 } else {
538 allAppsTopPadding = 0;
539 allAppsShiftRange =
540 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
541 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100542 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
543 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300544
Alex Chaua02eddc2021-04-29 00:36:06 +0100545 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
546 R.dimen.drag_flingToDeleteMinVelocity);
547
Sihua Mae04aa202022-07-18 12:43:56 -0700548 mViewScaleProvider = viewScaleProvider;
549
Tony Wickham1237df02017-02-24 08:59:36 -0800550 // This is done last, after iconSizePx is calculated above.
Sunny Goyal65190ae2022-08-02 14:16:26 -0700551 mDotRendererWorkSpace = createDotRenderer(iconSizePx, dotRendererCache);
552 mDotRendererAllApps = createDotRenderer(allAppsIconSizePx, dotRendererCache);
553 }
554
555 private static DotRenderer createDotRenderer(
556 int size, @NonNull SparseArray<DotRenderer> cache) {
557 DotRenderer renderer = cache.get(size);
558 if (renderer == null) {
559 renderer = new DotRenderer(size, getShapePath(DEFAULT_DOT_SIZE), DEFAULT_DOT_SIZE);
560 cache.put(size, renderer);
561 }
562 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700563 }
564
Thales Lima425f6822022-05-10 13:44:58 -0300565 /**
566 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
567 * width of the hotseat.
568 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100569 private int calculateQsbWidth(int hotseatBorderSpace) {
Thales Lima425f6822022-05-10 13:44:58 -0300570 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100571 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300572 return getIconToIconWidthForColumns(columns)
573 - iconSizePx * numShownHotseatIcons
574 - hotseatBorderSpace * numShownHotseatIcons;
575 } else {
576 int columns = inv.hotseatColumnSpan[mTypeIndex];
577 return getIconToIconWidthForColumns(columns);
578 }
579 }
Thales Lima2903a622022-03-17 13:52:19 +0000580
Thales Lima425f6822022-05-10 13:44:58 -0300581 private int getIconToIconWidthForColumns(int columns) {
582 return columns * getCellSize().x
583 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400584 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000585 }
586
Thales Limad90faab2021-09-21 17:18:47 +0100587 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
588 if (isVerticalBarLayout()) {
589 return 0;
590 }
591
Thales Lima83bedbf2021-10-05 17:47:39 +0100592 return isScalableGrid
593 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
594 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100595 }
596
Thales Limab8c05952022-05-23 16:58:38 +0100597 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
598 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700599 // Ensure there is enough space for folder icons, which have a slightly larger radius.
600 hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR);
Thales Limab8c05952022-05-23 16:58:38 +0100601
Jon Miranda0d284852021-06-22 14:50:55 -0700602 if (isVerticalBarLayout()) {
603 hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
604 + hotseatBarSidePaddingEndPx;
Thales Limab8c05952022-05-23 16:58:38 +0100605 } else if (isQsbInline) {
606 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
607 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700608 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100609 hotseatBarSizePx = hotseatIconSizePx
610 + hotseatQsbSpace
611 + hotseatQsbVisualHeight
612 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700613 }
614 }
615
Thales Lima9938c2f2022-07-25 14:38:16 +0100616 private void recalculateHotseatWidthAndBorderSpace(Resources res) {
617 hotseatBorderSpace = calculateHotseatBorderSpace();
618 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
619 // Spaces should be correct when there nav buttons are not inline
620 if (!areNavButtonsInline) {
621 return;
622 }
623
624 // Get the maximum width that the hotseat can be
625 int columns = getPanelCount() * inv.numColumns;
626 int maxHotseatWidth = getIconToIconWidthForColumns(columns);
627 int sideSpace = (availableWidthPx - maxHotseatWidth) / 2;
628 int inlineButtonsOverlap = Math.max(0, hotseatBarEndOffset - sideSpace);
629 // decrease how much the nav buttons go "inside" the hotseat
630 maxHotseatWidth -= inlineButtonsOverlap;
631
632 // Get how much space is required to show the hotseat with QSB
633 int requiredWidth = getHotseatRequiredWidth();
634
635 // If spaces are fine, use them
636 if (requiredWidth <= maxHotseatWidth) {
637 return;
638 }
639
640 // Calculate the difference of widths and remove a little from each space between icons
641 // and QSB if it's inline
642 int spaceDiff = requiredWidth - maxHotseatWidth;
643 int numOfSpaces = numShownHotseatIcons - (isQsbInline ? 0 : 1);
644 hotseatBorderSpace -= (spaceDiff / numOfSpaces);
645
646 int minHotseatIconSpaceDp = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
647 int minHotseatQsbWidthDp = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
648
649 if (hotseatBorderSpace >= minHotseatIconSpaceDp) {
650 return;
651 }
652
653 // Border space can't be less than the minimum
654 hotseatBorderSpace = minHotseatIconSpaceDp;
655 requiredWidth = getHotseatRequiredWidth();
656
657 // If there is an inline qsb, change its size
658 if (isQsbInline) {
659 hotseatQsbWidth -= requiredWidth - maxHotseatWidth;
660 if (hotseatQsbWidth >= minHotseatQsbWidthDp) {
661 return;
662 }
663
664 // QSB can't be less than the minimum
665 hotseatQsbWidth = minHotseatQsbWidthDp;
666 }
667
668 // If it still doesn't fit, start removing icons
669 do {
670 numShownHotseatIcons--;
671 requiredWidth = getHotseatRequiredWidth();
672 } while (requiredWidth > maxHotseatWidth && numShownHotseatIcons > 1);
673
674 // Add back some space between the icons
675 spaceDiff = maxHotseatWidth - requiredWidth;
676 numOfSpaces = numShownHotseatIcons - (isQsbInline ? 0 : 1);
677 hotseatBorderSpace += (spaceDiff / numOfSpaces);
678 }
679
Thales Lima78d00ad2021-09-30 11:29:06 +0100680 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100681 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100682 }
683
684 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100685 if (!isScalableGrid) {
686 return new Point(0, 0);
687 }
688
Thales Lima080d8902022-03-28 15:30:29 +0100689 int horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
690 int verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
Thales Lima78d00ad2021-09-30 11:29:06 +0100691
692 return new Point(horizontalSpacePx, verticalSpacePx);
693 }
694
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700695 public Info getDisplayInfo() {
696 return mInfo;
697 }
698
Jon Miranda611dba42021-03-02 14:12:13 -0500699 /**
700 * We inset the widget padding added by the system and instead rely on the border spacing
701 * between cells to create reliable consistency between widgets
702 */
703 public boolean shouldInsetWidgets() {
704 Rect widgetPadding = inv.defaultWidgetPadding;
705
Jon Miranda49811182021-06-03 09:52:40 -0700706 // Check all sides to ensure that the widget won't overlap into another cell, or into
707 // status bar.
708 return workspaceTopPadding > widgetPadding.top
Thales Lima78d00ad2021-09-30 11:29:06 +0100709 && cellLayoutBorderSpacePx.x > widgetPadding.left
710 && cellLayoutBorderSpacePx.y > widgetPadding.top
711 && cellLayoutBorderSpacePx.x > widgetPadding.right
712 && cellLayoutBorderSpacePx.y > widgetPadding.bottom;
Jon Miranda611dba42021-03-02 14:12:13 -0500713 }
Jon Mirandae126d722021-02-25 10:45:20 -0500714
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700715 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800716 WindowBounds bounds = new WindowBounds(
717 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700718 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100719 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700720
721 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
722 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
723 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
724
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700725 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700726 .setWindowBounds(bounds)
727 .setUseTwoPanels(isTwoPanels)
Alex Chau6ed408f2022-03-04 12:58:05 +0000728 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700729 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000730 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800731 }
732
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700733 public DeviceProfile copy(Context context) {
734 return toBuilder(context).build();
735 }
736
737 /**
738 * TODO: Move this to the builder as part of setMultiWindowMode
739 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700740 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700741 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700742 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700743 .setMultiWindowMode(true)
744 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800745
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800746 // We use these scales to measure and layout the widgets using their full invariant profile
747 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
748 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
749 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700750 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
751 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
752 profile = profile.toBuilder(context)
753 .setViewScaleProvider(i -> p)
754 .build();
755 }
756
757 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800758
Jon Miranda93e1f042016-11-11 14:13:04 -0800759 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700760 }
761
Adam Cohen63f1ec02014-08-12 09:23:13 -0700762 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400763 * Checks if there is enough space for labels on the workspace.
764 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700765 * It is important to call this method after the All Apps variables have been set.
766 */
Jon Miranda941375e2021-03-31 13:10:45 -0400767 private void hideWorkspaceLabelsIfNotEnoughSpace() {
768 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
769 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
770 - iconTextHeight;
771
772 // We want enough space so that the text is closer to its corresponding icon.
773 if (workspaceCellPaddingY < iconTextHeight) {
774 iconTextSizePx = 0;
775 iconDrawablePaddingPx = 0;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700776 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda941375e2021-03-31 13:10:45 -0400777 autoResizeAllAppsCells();
778 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700779 }
Jon Miranda1091e532017-07-21 13:31:50 -0700780
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700781 /**
782 * Re-computes the all-apps cell size to be independent of workspace
783 */
784 public void autoResizeAllAppsCells() {
Jon Miranda941375e2021-03-31 13:10:45 -0400785 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
786 int topBottomPadding = textHeight;
Jon Miranda1091e532017-07-21 13:31:50 -0700787 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
Jon Miranda941375e2021-03-31 13:10:45 -0400788 + textHeight + (topBottomPadding * 2);
Jon Miranda1091e532017-07-21 13:31:50 -0700789 }
790
Thales Limab7ef5692022-03-10 10:32:36 +0000791 private void updateAllAppsContainerWidth(Resources res) {
Pat Manning08610ca2022-04-05 21:03:16 +0100792 int cellLayoutHorizontalPadding =
793 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
Alex Chau27b39b92022-01-14 18:02:18 +0000794 if (isTablet) {
Thales Limab7ef5692022-03-10 10:32:36 +0000795 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100796 res.getDimensionPixelSize(R.dimen.all_apps_bottom_sheet_horizontal_padding);
797
sfufa@google.comde013292021-09-21 18:22:44 -0700798 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
Thales Limab7ef5692022-03-10 10:32:36 +0000799 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Alex Chau27b39b92022-01-14 18:02:18 +0000800 + allAppsLeftRightPadding * 2;
801 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
sfufa@google.comde013292021-09-21 18:22:44 -0700802 } else {
803 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100804 desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding;
sfufa@google.comde013292021-09-21 18:22:44 -0700805 }
806 }
807
Jon Miranda228877d2021-02-09 11:05:00 -0500808 /**
809 * Returns the amount of extra (or unused) vertical space.
810 */
811 private int updateAvailableDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700812 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800813
Pat Manning08610ca2022-04-05 21:03:16 +0100814 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -0500815
816 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +0100817 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +0000818 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -0500819 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500820 float scaleY = maxHeight / usedHeight;
821 boolean shouldScale = scaleY < 1f;
822
823 float scaleX = 1f;
824 if (isScalableGrid) {
825 // We scale to fit the cellWidth and cellHeight in the available space.
826 // The benefit of scalable grids is that we can get consistent aspect ratios between
827 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +0100828 float usedWidth =
829 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500830 // We do not subtract padding here, as we also scale the workspace padding if needed.
831 scaleX = availableWidthPx / usedWidth;
832 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700833 }
Jon Mirandae126d722021-02-25 10:45:20 -0500834
835 if (shouldScale) {
836 float scale = Math.min(scaleX, scaleY);
837 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +0100838 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -0500839 }
840
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700841 updateAvailableFolderCellDimensions(res);
Jon Miranda228877d2021-02-09 11:05:00 -0500842 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700843 }
844
Pat Manninga2e14992022-04-22 11:29:17 +0100845 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +0100846 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
847 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
848 }
849
Pat Manninga2e14992022-04-22 11:29:17 +0100850 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +0000851 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +0100852 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
853 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -0500854 }
855
Jon Miranda6f7e9702019-09-16 14:44:14 -0700856 /**
857 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
858 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
859 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
860 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800861 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -0700862 // Icon scale should never exceed 1, otherwise pixellation may occur.
863 iconScale = Math.min(1f, scale);
864 cellScaleToFit = scale;
865
Jon Miranda18751b62017-07-31 17:25:27 -0700866 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800867 final boolean isVerticalLayout = isVerticalBarLayout();
Thales Lima83bedbf2021-10-05 17:47:39 +0100868 float invIconSizeDp = inv.iconSize[mTypeIndex];
869 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
Andras Kloczl30fe9152021-08-05 18:02:29 +0200870
Jon Mirandaab3c6812021-06-28 15:42:28 -0700871 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, iconScale));
Jon Mirandaab3c6812021-06-28 15:42:28 -0700872 iconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * iconScale);
873 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700874
Thales Lima080d8902022-03-28 15:30:29 +0100875 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500876
877 if (isScalableGrid) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100878 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
879 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500880 int cellContentHeight = iconSizePx + iconDrawablePaddingPx
881 + Utilities.calculateTextHeight(iconTextSizePx);
882 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +0100883 desiredWorkspaceHorizontalMarginPx =
884 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -0500885 } else {
Jon Mirandae126d722021-02-25 10:45:20 -0500886 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700887 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR)
888 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -0500889 + Utilities.calculateTextHeight(iconTextSizePx);
890 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
891 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
892 && !isMultiWindowMode) {
893 // Ensures that the label is closer to its corresponding icon. This is not an issue
894 // with vertical bar layout or multi-window mode since the issue is handled
895 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
896 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
897 iconDrawablePaddingPx = cellPaddingY;
898 }
Jon Miranda846455e2017-10-02 14:58:52 -0700899 }
Jon Miranda18751b62017-07-31 17:25:27 -0700900
Sunny Goyalae190ff2020-04-14 00:19:01 +0000901 // All apps
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500902 updateAllAppsIconSize(scale, res);
Winson Chungb3800242013-10-24 11:01:54 -0700903
Thales Limab8c05952022-05-23 16:58:38 +0100904 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700905
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700906 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -0700907 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
908 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Winson Chung0f785722015-04-08 10:27:49 -0700909 }
910
Thales Lima425f6822022-05-10 13:44:58 -0300911 /**
912 * Hotseat width spans a certain number of columns on scalable grids.
913 * This method calculates the space between the icons to achieve that width.
914 */
915 private int calculateHotseatBorderSpace() {
916 if (!isScalableGrid) return 0;
Thales Lima9938c2f2022-07-25 14:38:16 +0100917 int columns = inv.hotseatColumnSpan[mTypeIndex];
918 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
919 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
920 return (int) (hotseatWidthPx - hotseatIconsTotalPx) / (numShownHotseatIcons - 1);
Thales Lima425f6822022-05-10 13:44:58 -0300921 }
922
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500923
924 /**
925 * Updates the iconSize for allApps* variants.
926 */
Brian Isganitisa9a78112022-05-23 18:11:47 -0700927 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +0100928 allAppsBorderSpacePx = new Point(
929 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
930 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700931 // AllApps cells don't have real space between cells,
932 // so we add the border space to the cell height
933 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics, scale)
934 + allAppsBorderSpacePx.y;
935 // but width is just the cell,
936 // the border is added in #updateAllAppsContainerWidth
Thales Lima080d8902022-03-28 15:30:29 +0100937 if (isScalableGrid) {
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500938 allAppsIconSizePx =
Brandon Dayauon969f6a82022-05-19 09:46:47 -0700939 pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics, scale);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500940 allAppsIconTextSizePx =
Brandon Dayauon969f6a82022-05-19 09:46:47 -0700941 pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics, scale);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500942 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -0700943 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500944 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700945 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
946 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500947 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
948 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700949 allAppsIconDrawablePaddingPx =
950 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -0700951 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500952 }
953
Thales Limab7ef5692022-03-10 10:32:36 +0000954 updateAllAppsContainerWidth(res);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500955 if (isVerticalBarLayout()) {
956 hideWorkspaceLabelsIfNotEnoughSpace();
957 }
958 }
959
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700960 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700961 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700962
Jon Mirandac1b23992016-12-13 08:57:36 -0800963 // Don't let the folder get too close to the edges of the screen.
Jon Miranda1786df32018-09-25 13:05:23 -0700964 int folderMargin = edgeMarginPx * 2;
Sunny Goyal07b69292018-01-08 14:19:34 -0800965 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -0800966
967 // Check if the icons fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -0500968 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Thales Limab35faed2022-09-05 16:30:01 -0300969 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx);
970 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderFooterHeightPx
Jon Mirandae126d722021-02-25 10:45:20 -0500971 - folderMargin - folderContentPaddingTop;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800972 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -0800973
974 // Check if the icons fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -0500975 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Thales Limab35faed2022-09-05 16:30:01 -0300976 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx);
Jon Mirandae126d722021-02-25 10:45:20 -0500977 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin
978 - folderContentPaddingLeftRight * 2;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800979 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -0800980
981 float scale = Math.min(scaleX, scaleY);
982 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700983 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700984 }
985 }
986
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700987 private void updateFolderCellSize(float scale, Resources res) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100988 float invIconSizeDp = isVerticalBarLayout()
Thales Lima12d0eff2022-03-25 17:06:11 +0000989 ? inv.iconSize[INDEX_LANDSCAPE]
990 : inv.iconSize[INDEX_DEFAULT];
Sunny Goyal35c7b192021-04-20 16:51:10 -0700991 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Thales Lima83bedbf2021-10-05 17:47:39 +0100992 folderChildTextSizePx =
Thales Lima12d0eff2022-03-25 17:06:11 +0000993 pxFromSp(inv.iconTextSize[INDEX_DEFAULT], mMetrics, scale);
Thales Limab35faed2022-09-05 16:30:01 -0300994 folderLabelTextSizePx = Math.max(pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics),
995 (int) (folderChildTextSizePx * folderLabelTextScale));
Jon Mirandabf7d8122016-11-03 15:29:29 -0700996
997 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700998
Jon Miranda823da222021-03-23 08:08:45 -0400999 if (isScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -03001000 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
1001 folderCellWidthPx = pxFromDp(getCellSize().x, mMetrics, scale);
1002 folderCellHeightPx = pxFromDp(getCellSize().y, mMetrics, scale);
1003 }
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001004
Thales Limab35faed2022-09-05 16:30:01 -03001005 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx;
Jon Miranda823da222021-03-23 08:08:45 -04001006 } else {
1007 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1008 * scale);
1009 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1010 * scale);
1011
1012 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1013 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Limab35faed2022-09-05 16:30:01 -03001014 folderContentPaddingLeftRight =
1015 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1016 folderFooterHeightPx =
1017 res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Jon Miranda823da222021-03-23 08:08:45 -04001018 }
1019
Jonathan Miranda9ad87462017-07-26 17:41:02 +00001020 folderChildDrawablePaddingPx = Math.max(0,
1021 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001022 }
1023
Winson1f064272016-07-18 17:18:02 -07001024 public void updateInsets(Rect insets) {
1025 mInsets.set(insets);
1026 }
1027
Sunny Goyalae6e3182019-04-30 12:04:37 -07001028 /**
1029 * The current device insets. This is generally same as the insets being dispatched to
1030 * {@link Insettable} elements, but can differ if the element is using a different profile.
1031 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001032 public Rect getInsets() {
1033 return mInsets;
1034 }
1035
Sunny Goyal756cd262015-08-20 12:33:21 -07001036 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001037 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001038 }
1039
Sunny Goyal19ff7282021-04-22 10:12:54 -07001040 public Point getCellSize(Point result) {
1041 if (result == null) {
1042 result = new Point();
1043 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001044
Pat Manning25d53342022-05-10 09:58:49 +00001045 int shortcutAndWidgetContainerWidth =
1046 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1047 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1048 inv.numColumns);
1049 int shortcutAndWidgetContainerHeight =
1050 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1051 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1052 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001053 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001054 }
1055
1056 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001057 * Returns the left and right space on the cell, which is the cell width - icon size
1058 */
1059 public int getCellHorizontalSpace() {
1060 return getCellSize().x - iconSizePx;
1061 }
1062
1063 /**
Pat Manning25d53342022-05-10 09:58:49 +00001064 * Gets the number of panels within the workspace.
1065 */
1066 public int getPanelCount() {
1067 return isTwoPanels ? 2 : 1;
1068 }
1069
1070 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001071 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1072 * bottom of the screen.
1073 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001074 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1075 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001076 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001077 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001078 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001079 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001080 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001081 }
1082
1083 /**
1084 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1085 */
Pat Manning25d53342022-05-10 09:58:49 +00001086 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001087 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001088 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001089 }
1090
1091 /**
1092 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1093 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001094 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001095 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001096 return heightPx - (isVerticalBarLayout()
1097 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001098 }
1099
Pat Manningea5c1d22022-04-14 10:58:16 +01001100 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001101 * Gets the scale of the workspace for the spring-loaded edit state.
1102 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001103 public float getWorkspaceSpringLoadScale(Context context) {
1104 float scale =
1105 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1106 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001107 scale = Math.min(scale, 1f);
1108
Pat Manninge63dd252022-08-02 16:15:29 +01001109 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001110 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001111 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001112 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001113 if (scaledWorkspaceWidth > maxAvailableWidth) {
1114 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1115 }
1116 return scale;
1117 }
1118
Pat Manning25d53342022-05-10 09:58:49 +00001119 /**
1120 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1121 *
1122 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1123 * layouts have two Cell Layouts per workspace.
1124 */
1125 public int getCellLayoutWidth() {
1126 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001127 }
1128
Pat Manning25d53342022-05-10 09:58:49 +00001129 /**
1130 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1131 *
1132 * <p>This is the height of a Workspace, less its vertical padding.
1133 */
1134 public int getCellLayoutHeight() {
1135 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001136 }
1137
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001138 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001139 return new Point(workspacePadding.left + workspacePadding.right,
1140 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001141 }
1142
1143 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001144 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1145 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001146 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001147 private void updateWorkspacePadding() {
1148 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001149 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -08001150 padding.top = 0;
1151 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001152 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001153 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -07001154 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -07001155 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -07001156 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001157 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -07001158 }
Winson Chungb3800242013-10-24 11:01:54 -07001159 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001160 // Pad the bottom of the workspace with hotseat bar
1161 // and leave a bit of space in case a widget go all the way down
1162 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding
1163 + workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace
1164 - mInsets.bottom;
Pat Manning08610ca2022-04-05 21:03:16 +01001165 int paddingTop = workspaceTopPadding + (isScalableGrid ? 0 : edgeMarginPx);
1166 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001167
Pat Manning08610ca2022-04-05 21:03:16 +01001168 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001169 }
Pat Manning08610ca2022-04-05 21:03:16 +01001170 insetPadding(workspacePadding, cellLayoutPaddingPx);
1171 }
1172
1173 private void insetPadding(Rect paddings, Rect insets) {
1174 insets.left = Math.min(insets.left, paddings.left);
1175 paddings.left -= insets.left;
1176
1177 insets.top = Math.min(insets.top, paddings.top);
1178 paddings.top -= insets.top;
1179
1180 insets.right = Math.min(insets.right, paddings.right);
1181 paddings.right -= insets.right;
1182
1183 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1184 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001185 }
1186
Sunny Goyal57b22792021-05-25 14:35:01 -07001187 /**
1188 * Returns the padding for hotseat view
1189 */
1190 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001191 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001192 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001193 // The hotseat icons will be placed in the middle of the hotseat cells.
1194 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1195 // in vertical bar layout.
1196 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1197 // is set to account for that difference.
1198 float diffOverlapFactor = iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
Pat Manning08610ca2022-04-05 21:03:16 +01001199 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1200 - diffOverlapFactor), 0);
1201 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001202 + diffOverlapFactor), 0);
1203
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001204 if (isSeascape()) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001205 hotseatBarPadding.set(mInsets.left + hotseatBarSidePaddingStartPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001206 hotseatBarSidePaddingEndPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001207 } else {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001208 hotseatBarPadding.set(hotseatBarSidePaddingEndPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001209 mInsets.right + hotseatBarSidePaddingStartPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001210 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001211 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001212 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001213 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1214 int hotseatBarTopPadding =
1215 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001216
Thales Lima612230d2022-03-31 18:04:37 +01001217 // Push icons to the side
Thales Lima9938c2f2022-07-25 14:38:16 +01001218 int requiredWidth = getHotseatRequiredWidth();
Pat Manning26f70f72022-07-07 13:50:39 +01001219 int hotseatWidth = Math.min(requiredWidth, availableWidthPx - hotseatBarEndOffset);
Thales Lima612230d2022-03-31 18:04:37 +01001220 int sideSpacing = (availableWidthPx - hotseatWidth) / 2;
Thales Lima612230d2022-03-31 18:04:37 +01001221
Pat Manning5f74bfd2022-07-20 12:08:54 +01001222 hotseatBarPadding.set(sideSpacing, hotseatBarTopPadding, sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001223 hotseatBarBottomPadding);
Alex Chau51da2192022-05-20 13:32:10 +01001224
1225 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001226 if (isRtl) {
Thales Lima9938c2f2022-07-25 14:38:16 +01001227 hotseatBarPadding.right += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001228 } else {
Thales Lima9938c2f2022-07-25 14:38:16 +01001229 hotseatBarPadding.left += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001230 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001231
Pat Manning26f70f72022-07-07 13:50:39 +01001232 if (hotseatBarEndOffset > sideSpacing) {
Thales Lima612230d2022-03-31 18:04:37 +01001233 int diff = isRtl
Pat Manning26f70f72022-07-07 13:50:39 +01001234 ? sideSpacing - hotseatBarEndOffset
1235 : hotseatBarEndOffset - sideSpacing;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001236 hotseatBarPadding.left -= diff;
1237 hotseatBarPadding.right += diff;
Sunny Goyal57b22792021-05-25 14:35:01 -07001238 }
Thales Lima425f6822022-05-10 13:44:58 -03001239 } else if (isScalableGrid) {
Alex Chau206ede92022-08-01 17:46:12 +01001240 int sideSpacing = (availableWidthPx - hotseatQsbWidth) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001241 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001242 0,
Thales Lima425f6822022-05-10 13:44:58 -03001243 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001244 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001245 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001246 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1247 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1248 // for this, we pad the left and right of the hotseat with half of the difference of a
1249 // workspace cell vs a hotseat cell.
1250 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001251 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001252 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001253 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001254 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1255 + mInsets.left,
1256 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001257 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001258 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001259 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001260 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001261 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001262 }
1263
Thales Lima9938c2f2022-07-25 14:38:16 +01001264 private int getAdditionalQsbSpace() {
1265 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1266 }
1267
1268 /**
1269 * Calculate how much space the hotseat needs to be shown completely
1270 */
1271 private int getHotseatRequiredWidth() {
1272 int additionalQsbSpace = getAdditionalQsbSpace();
1273 return iconSizePx * numShownHotseatIcons
1274 + hotseatBorderSpace * (numShownHotseatIcons - 1)
1275 + additionalQsbSpace;
1276 }
1277
Winsonfadbe8f2016-07-22 16:35:37 -07001278 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001279 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1280 */
1281 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001282 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001283 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1284 } else if (isTaskbarPresent) { // QSB on top
1285 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001286 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001287 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001288 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001289 }
1290
Thales Limab8c05952022-05-23 16:58:38 +01001291 /**
1292 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1293 */
1294 private int getHotseatBarBottomPadding() {
1295 if (isTaskbarPresent) { // QSB on top or inline
1296 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001297 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001298 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001299 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001300 }
1301
1302 /**
Alex Chau51da2192022-05-20 13:32:10 +01001303 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1304 */
1305 public int getTaskbarOffsetY() {
1306 int taskbarIconBottomSpace = (taskbarSize - iconSizePx) / 2;
1307 int launcherIconBottomSpace =
1308 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001309 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001310 }
1311
1312 /**
Alex Chaua2fc7642022-04-21 14:20:23 +01001313 * Returns the number of pixels required below OverviewActions excluding insets.
1314 */
1315 public int getOverviewActionsClaimedSpaceBelow() {
Alex Chaud67ddc42022-09-30 18:15:56 +01001316 if (isTaskbarPresent) {
Alex Chau905e0f12022-11-14 21:55:37 +00001317 if (FeatureFlags.ENABLE_TASKBAR_IN_OVERVIEW.get()) {
1318 return taskbarSize + transientTaskbarMargin;
1319 }
1320
1321 return isGestureMode
1322 ? stashedTaskbarSize
1323 // Align vertically to where nav buttons are.
1324 : ((taskbarSize - overviewActionsHeight) / 2) + getTaskbarOffsetY();
Alex Chaud67ddc42022-09-30 18:15:56 +01001325 }
1326 return mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001327 }
1328
1329 /** Gets the space that the overview actions will take, including bottom margin. */
1330 public int getOverviewActionsClaimedSpace() {
1331 return overviewActionsTopMarginPx + overviewActionsHeight
1332 + getOverviewActionsClaimedSpaceBelow();
1333 }
1334
1335 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001336 * Takes the View and return the scales of width and height depending on the DeviceProfile
1337 * specifications
1338 *
1339 * @param itemInfo The tag of the widget view
1340 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1341 * height
1342 */
1343 @NonNull
1344 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1345 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1346 }
1347
1348 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001349 * @return the bounds for which the open folders should be contained within
1350 */
1351 public Rect getAbsoluteOpenFolderBounds() {
1352 if (isVerticalBarLayout()) {
1353 // Folders should only appear right of the drop target bar and left of the hotseat
1354 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1355 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001356 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001357 mInsets.top + availableHeightPx);
1358 } else {
1359 // Folders should only appear below the drop target bar and above the hotseat
Tony Wickhamae72b462021-03-10 16:18:40 -08001360 int hotseatTop = isTaskbarPresent ? taskbarSize : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001361 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001362 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001363 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001364 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001365 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001366 }
1367 }
1368
Jon Miranda228877d2021-02-09 11:05:00 -05001369 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1370 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001371 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001372
Jon Miranda228877d2021-02-09 11:05:00 -05001373 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1374 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001375 }
1376
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001377 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001378 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1379 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1380 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001381 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001382 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001383 return isLandscape && transposeLayoutWithOrientation;
1384 }
1385
Sunny Goyal59d086c2018-05-07 17:31:40 -07001386 /**
1387 * Updates orientation information and returns true if it has changed from the previous value.
1388 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001389 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001390 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001391 boolean isSeascape = DisplayController.INSTANCE.get(context)
1392 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001393 if (mIsSeascape != isSeascape) {
1394 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001395 // Hotseat changing sides requires updating workspace left/right paddings
1396 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001397 return true;
1398 }
1399 }
1400 return false;
1401 }
1402
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001403 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001404 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001405 }
1406
Sunny Goyal07b69292018-01-08 14:19:34 -08001407 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001408 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001409 }
1410
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001411 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001412 switch (containerType) {
1413 case CellLayout.WORKSPACE:
1414 return cellHeightPx;
1415 case CellLayout.FOLDER:
1416 return folderCellHeightPx;
1417 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001418 // The hotseat is the only container where the cell height is going to be
1419 // different from the content within that cell.
1420 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001421 default:
1422 // ??
1423 return 0;
1424 }
1425 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001426
Jon Miranda58561d42021-03-17 10:51:54 -04001427 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001428 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001429 }
1430
Alex Chaue818bcb2022-09-02 17:27:11 +01001431 private String dpPointFToString(String name, PointF value) {
1432 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
1433 }
1434
Pat Manning5f74bfd2022-07-20 12:08:54 +01001435 /** Dumps various DeviceProfile variables to the specified writer. */
1436 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04001437 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001438 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001439
1440 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001441 writer.println(prefix + "\tisPhone:" + isPhone);
1442 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1443 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001444 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001445
1446 writer.println(prefix + "\tisLandscape:" + isLandscape);
1447 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001448 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001449
1450 writer.println(prefix + pxToDpStr("windowX", windowX));
1451 writer.println(prefix + pxToDpStr("windowY", windowY));
1452 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1453 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001454 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1455 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001456 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1457 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1458 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1459 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001460
1461 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1462
1463 writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
1464
Thales Lima83bedbf2021-10-05 17:47:39 +01001465 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001466 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1467 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1468 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001469
Alex Chaue818bcb2022-09-02 17:27:11 +01001470 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07001471
Jon Miranda58561d42021-03-17 10:51:54 -04001472 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1473 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1474
1475 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1476 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1477
Thales Lima83bedbf2021-10-05 17:47:39 +01001478 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1479 cellLayoutBorderSpacePx.x));
1480 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1481 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001482 writer.println(
1483 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
1484 writer.println(
1485 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
1486 writer.println(
1487 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01001488 writer.println(
1489 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01001490
Jon Miranda58561d42021-03-17 10:51:54 -04001491 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1492 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1493 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1494
1495 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1496 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1497 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1498 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1499 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1500 folderChildDrawablePaddingPx));
Thales Limab35faed2022-09-05 16:30:01 -03001501 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx",
1502 folderCellLayoutBorderSpacePx));
Thales Limaa08a4432022-08-09 09:55:17 +01001503 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
1504 folderContentPaddingLeftRight));
1505 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03001506 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001507
Alex Chaue0227552022-04-06 19:44:43 +01001508 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001509 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
1510 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
1511 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
1512 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01001513
1514 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
1515 writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001516 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
1517 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04001518 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1519 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1520 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1521 allAppsIconDrawablePaddingPx));
1522 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001523 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001524 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
1525 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001526 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau62572c02022-07-25 18:36:37 +00001527 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
Alex Chau27b39b92022-01-14 18:02:18 +00001528 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001529
1530 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03001531 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04001532 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00001533 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Jon Miranda58561d42021-03-17 10:51:54 -04001534 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
1535 hotseatBarSidePaddingStartPx));
1536 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
1537 hotseatBarSidePaddingEndPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001538 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01001539 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
1540 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01001541 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
1542 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001543 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
1544 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
1545 hotseatLayoutPadding.top));
1546 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
1547 hotseatLayoutPadding.bottom));
1548 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
1549 hotseatLayoutPadding.left));
1550 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
1551 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001552 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001553 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001554 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01001555 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001556
1557 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001558 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda58561d42021-03-17 10:51:54 -04001559 writer.println(prefix + pxToDpStr("taskbarSize", taskbarSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001560
Thales Lima83bedbf2021-10-05 17:47:39 +01001561 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1562 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001563 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
1564 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
1565 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00001566 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001567
Jon Mirandaab3c6812021-06-28 15:42:28 -07001568 writer.println(prefix + pxToDpStr("iconScale", iconScale));
1569 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04001570 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00001571 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001572
Thales Lima171ee662022-11-22 15:52:49 +00001573 writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace));
Jon Miranda58561d42021-03-17 10:51:54 -04001574 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
1575 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00001576
1577 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00001578 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
1579 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
1580 overviewTaskIconDrawableSizePx));
1581 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
1582 overviewTaskIconDrawableSizeGridPx));
1583 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
1584 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01001585 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
1586 overviewActionsTopMarginPx));
1587 writer.println(prefix + pxToDpStr("overviewActionsHeight",
1588 overviewActionsHeight));
Alex Chau635b3ab2022-01-26 16:49:10 +00001589 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
1590 overviewActionsButtonSpacing));
1591 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
1592 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
1593 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01001594
Alex Chau62572c02022-07-25 18:36:37 +00001595 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001596 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00001597 writer.println(
1598 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001599
Pat Manning5f74bfd2022-07-20 12:08:54 +01001600 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
1601 getCellLayoutSpringLoadShrunkTop()));
1602 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
1603 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01001604 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
1605 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001606 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
1607 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01001608 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
1609 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Jon Miranda58561d42021-03-17 10:51:54 -04001610 }
1611
Alex Chaua6907dc2022-03-18 15:24:07 +00001612 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07001613 Configuration config = new Configuration(c.getResources().getConfiguration());
1614 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03001615 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00001616 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07001617 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07001618 }
Sunny Goyalfde55052018-02-01 14:46:13 -08001619
1620 /**
1621 * Callback when a component changes the DeviceProfile associated with it, as a result of
1622 * configuration change
1623 */
1624 public interface OnDeviceProfileChangeListener {
1625
1626 /**
1627 * Called when the device profile is reassigned. Note that for layout and measurements, it
1628 * is sufficient to listen for inset changes. Use this callback when you need to perform
1629 * a one time operation.
1630 */
1631 void onDeviceProfileChanged(DeviceProfile dp);
1632 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001633
Brian Isganitis099945b2022-01-31 18:15:00 -05001634 /** Allows registering listeners for {@link DeviceProfile} changes. */
1635 public interface DeviceProfileListenable {
1636
1637 /** The current device profile. */
1638 DeviceProfile getDeviceProfile();
1639
1640 /** Registered {@link OnDeviceProfileChangeListener} instances. */
1641 List<OnDeviceProfileChangeListener> getOnDeviceProfileChangeListeners();
1642
1643 /** Notifies listeners of a {@link DeviceProfile} change. */
1644 default void dispatchDeviceProfileChanged() {
1645 DeviceProfile deviceProfile = getDeviceProfile();
1646 List<OnDeviceProfileChangeListener> listeners = getOnDeviceProfileChangeListeners();
1647 for (int i = listeners.size() - 1; i >= 0; i--) {
1648 listeners.get(i).onDeviceProfileChanged(deviceProfile);
1649 }
1650 }
1651
1652 /** Register listener for {@link DeviceProfile} changes. */
1653 default void addOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
1654 getOnDeviceProfileChangeListeners().add(listener);
1655 }
1656
1657 /** Unregister listener for {@link DeviceProfile} changes. */
1658 default void removeOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
1659 getOnDeviceProfileChangeListeners().remove(listener);
1660 }
1661 }
1662
Sihua Mae04aa202022-07-18 12:43:56 -07001663 /**
1664 * Handler that deals with ItemInfo of the views for the DeviceProfile
1665 */
1666 @FunctionalInterface
1667 public interface ViewScaleProvider {
1668 /**
1669 * Get the scales from the view
1670 *
1671 * @param itemInfo The tag of the widget view
1672 * @return PointF instance containing the scale information, or null if using the default
1673 * app widget scale of this device profile.
1674 */
1675 @NonNull
1676 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
1677 }
1678
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001679 public static class Builder {
1680 private Context mContext;
1681 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07001682 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001683
Sunny Goyal19ff7282021-04-22 10:12:54 -07001684 private WindowBounds mWindowBounds;
1685 private boolean mUseTwoPanels;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001686
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001687 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001688 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00001689 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07001690 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001691
Sunny Goyal65190ae2022-08-02 14:16:26 -07001692 private SparseArray<DotRenderer> mDotRendererCache;
1693
Sunny Goyalfd58da62020-08-11 12:06:49 -07001694 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001695 mContext = context;
1696 mInv = inv;
1697 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001698 }
1699
1700 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1701 mIsMultiWindowMode = isMultiWindowMode;
1702 return this;
1703 }
1704
Sunny Goyal19ff7282021-04-22 10:12:54 -07001705 public Builder setUseTwoPanels(boolean useTwoPanels) {
1706 mUseTwoPanels = useTwoPanels;
1707 return this;
1708 }
1709
Sunny Goyal65190ae2022-08-02 14:16:26 -07001710 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
1711 mDotRendererCache = dotRendererCache;
1712 return this;
1713 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07001714
1715 public Builder setWindowBounds(WindowBounds bounds) {
1716 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07001717 return this;
1718 }
1719
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001720 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1721 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1722 return this;
1723 }
1724
Alex Chau6ed408f2022-03-04 12:58:05 +00001725 public Builder setGestureMode(boolean isGestureMode) {
1726 mIsGestureMode = isGestureMode;
1727 return this;
1728 }
1729
Sihua Mae04aa202022-07-18 12:43:56 -07001730 /**
1731 * Set the viewScaleProvider for the builder
1732 *
1733 * @param viewScaleProvider The viewScaleProvider to be set for the
1734 * DeviceProfile
1735 * @return This builder
1736 */
1737 @NonNull
1738 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
1739 mViewScaleProvider = viewScaleProvider;
1740 return this;
1741 }
1742
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001743 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001744 if (mWindowBounds == null) {
1745 throw new IllegalArgumentException("Window bounds not set");
1746 }
1747 if (mTransposeLayoutWithOrientation == null) {
1748 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
1749 }
Alex Chau6ed408f2022-03-04 12:58:05 +00001750 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01001751 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00001752 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001753 if (mDotRendererCache == null) {
1754 mDotRendererCache = new SparseArray<>();
1755 }
Sihua Mae04aa202022-07-18 12:43:56 -07001756 if (mViewScaleProvider == null) {
1757 mViewScaleProvider = DEFAULT_PROVIDER;
1758 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001759 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
1760 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mUseTwoPanels,
Sihua Mae04aa202022-07-18 12:43:56 -07001761 mIsGestureMode, mViewScaleProvider);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001762 }
1763 }
1764
Winson Chungb3800242013-10-24 11:01:54 -07001765}