blob: 92530eaae65936a4bd8b2c0f0a750a785df9e353 [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;
Jon Miranda228877d2021-02-09 11:05:00 -0500129 public int workspaceTopPadding;
130 public int workspaceBottomPadding;
131
Tony Wickham5edf9e22020-03-27 20:06:52 -0700132 // Workspace page indicator
133 public final int workspacePageIndicatorHeight;
134 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700135
Sunny Goyalc6205602015-05-21 20:46:33 -0700136 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400137 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700138 public int iconSizePx;
139 public int iconTextSizePx;
140 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700141 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -0700142
Jon Mirandaab3c6812021-06-28 15:42:28 -0700143 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800144 public int cellWidthPx;
145 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700146 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800147
Jon Mirandae126d722021-02-25 10:45:20 -0500148 public int cellYPaddingPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500149
Sunny Goyalc6205602015-05-21 20:46:33 -0700150 // Folder
Jon Mirandae126d722021-02-25 10:45:20 -0500151 public float folderLabelTextScale;
152 public int folderLabelTextSizePx;
Thales Limab35faed2022-09-05 16:30:01 -0300153 public int folderFooterHeightPx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700154 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700155 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700156
Jon Mirandae126d722021-02-25 10:45:20 -0500157 // Folder content
Thales Limab35faed2022-09-05 16:30:01 -0300158 public int folderCellLayoutBorderSpacePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500159 public int folderContentPaddingLeftRight;
160 public int folderContentPaddingTop;
161
Jon Mirandabf7d8122016-11-03 15:29:29 -0700162 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700163 public int folderCellWidthPx;
164 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700165
166 // Folder child
167 public int folderChildIconSizePx;
168 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700169 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700170
Sunny Goyalc6205602015-05-21 20:46:33 -0700171 // Hotseat
Thales Lima9938c2f2022-07-25 14:38:16 +0100172 public int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700173 public int hotseatCellHeightPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100174 public final boolean areNavButtonsInline;
Jon Miranda18751b62017-07-31 17:25:27 -0700175 // In portrait: size = height, in landscape: size = width
176 public int hotseatBarSizePx;
Thales Limab8c05952022-05-23 16:58:38 +0100177 public int hotseatBarBottomSpacePx;
Pat Manning26f70f72022-07-07 13:50:39 +0100178 public int hotseatBarEndOffset;
Thales Limab8c05952022-05-23 16:58:38 +0100179 public int hotseatQsbSpace;
Pat Manningde25c0d2022-04-05 19:11:26 +0100180 public int springLoadedHotseatBarTopMarginPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700181 // Start is the side next to the nav bar, end is the side next to the workspace
182 public final int hotseatBarSidePaddingStartPx;
183 public final int hotseatBarSidePaddingEndPx;
Alex Chau206ede92022-08-01 17:46:12 +0100184 public int hotseatQsbWidth; // only used when isQsbInline
Sunny Goyal57b22792021-05-25 14:35:01 -0700185 public final int hotseatQsbHeight;
Thales Limab8c05952022-05-23 16:58:38 +0100186 public final int hotseatQsbVisualHeight;
187 private final int hotseatQsbShadowHeight;
Thales Limadd027342022-01-07 12:54:37 +0000188 public int hotseatBorderSpace;
Adam Cohen2e6da152015-05-06 11:42:25 -0700189
Alex Chau3d2c0622022-09-01 21:28:14 +0100190 // Bottom sheets
191 public int bottomSheetTopPadding;
192 public int bottomSheetOpenDuration;
193 public int bottomSheetCloseDuration;
194 public float bottomSheetWorkspaceScale;
195 public float bottomSheetDepth;
196
Sunny Goyalc6205602015-05-21 20:46:33 -0700197 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000198 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000199 public int allAppsShiftRange;
200 public int allAppsTopPadding;
Alex Chau3d2c0622022-09-01 21:28:14 +0100201 public int allAppsOpenDuration;
202 public int allAppsCloseDuration;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700203 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700204 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700205 public int allAppsIconSizePx;
206 public int allAppsIconDrawablePaddingPx;
sfufa@google.comde013292021-09-21 18:22:44 -0700207 public int allAppsLeftRightPadding;
Alex Chau27b39b92022-01-14 18:02:18 +0000208 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700209 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700210 public float allAppsIconTextSizePx;
211
Zak Cohen334efeb2021-03-19 16:42:07 -0700212 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700213 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000214 public int overviewTaskIconSizePx;
Alex Chauac9df382021-08-02 19:08:41 +0100215 public int overviewTaskIconDrawableSizePx;
216 public int overviewTaskIconDrawableSizeGridPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000217 public int overviewTaskThumbnailTopMarginPx;
Alex Chau19c6eca2022-03-10 20:12:56 +0000218 public final int overviewActionsHeight;
Alex Chaua2fc7642022-04-21 14:20:23 +0100219 public final int overviewActionsTopMarginPx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000220 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100221 public int overviewPageSpacing;
222 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000223 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700224
Jeremy Sim0ac47082022-10-10 13:59:40 -0700225 // Split staging
226 public int splitPlaceholderInset;
227
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800228 // Widgets
Sihua Mae04aa202022-07-18 12:43:56 -0700229 private final ViewScaleProvider mViewScaleProvider;
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800230
Sunny Goyal47328fd2016-05-25 18:56:41 -0700231 // Drop Target
232 public int dropTargetBarSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100233 public int dropTargetBarTopMarginPx;
234 public int dropTargetBarBottomMarginPx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100235 public int dropTargetDragPaddingPx;
236 public int dropTargetTextSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100237 public int dropTargetHorizontalPaddingPx;
238 public int dropTargetVerticalPaddingPx;
239 public int dropTargetGapPx;
Alex Chau5b019302022-05-23 10:42:25 +0100240 public int dropTargetButtonWorkspaceEdgeGapPx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700241
Winson1f064272016-07-18 17:18:02 -0700242 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800243 private final Rect mInsets = new Rect();
244 public final Rect workspacePadding = new Rect();
Jon Miranda0bd63d12019-03-06 17:29:29 -0800245 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700246 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700247
Tony Wickhamf34bee82018-12-03 18:11:39 -0800248 // Notification dots
Sunny Goyal65190ae2022-08-02 14:16:26 -0700249 public final DotRenderer mDotRendererWorkSpace;
250 public final DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800251
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100252 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800253 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000254 // Whether Taskbar will inset the bottom of apps by taskbarSize.
255 public boolean isTaskbarPresentInApps;
Tony Wickham15883892021-02-12 11:24:40 -0800256 public int taskbarSize;
Alex Chau6a7d1e22022-01-20 19:54:17 +0000257 public int stashedTaskbarSize;
Alex Chau905e0f12022-11-14 21:55:37 +0000258 public int transientTaskbarMargin;
Tony Wickham15883892021-02-12 11:24:40 -0800259
Alex Chaua02eddc2021-04-29 00:36:06 +0100260 // DragController
261 public int flingToDeleteThresholdVelocity;
262
Vinit Nayak17c4b332021-08-05 12:54:58 -0700263 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700264 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal65190ae2022-08-02 14:16:26 -0700265 SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
Sihua Mae04aa202022-07-18 12:43:56 -0700266 boolean transposeLayoutWithOrientation, boolean useTwoPanels, boolean isGestureMode,
267 @NonNull final ViewScaleProvider viewScaleProvider) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700268
Adam Cohen2e6da152015-05-06 11:42:25 -0700269 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700270 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800271 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500272 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +0000273 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700274 windowX = windowBounds.bounds.left;
275 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800276 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100277 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700278
Jon Mirandae126d722021-02-25 10:45:20 -0500279 isScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000280 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700281 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000282 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700283 isPhone = !isTablet;
Alex Chau90125822021-11-17 14:16:58 +0000284 isTwoPanels = isTablet && useTwoPanels;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800285 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700286
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000287 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000288 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700289 ? Configuration.ORIENTATION_LANDSCAPE
290 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000291 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700292 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000293 mMetrics = res.getDisplayMetrics();
294
295 // Determine sizes.
296 widthPx = windowBounds.bounds.width();
297 heightPx = windowBounds.bounds.height();
298 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100299 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000300
301 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
302 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
303 mQsbCenterFactor = res.getFloat(R.dimen.qsb_center_factor);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700304
Thales Lima83bedbf2021-10-05 17:47:39 +0100305 if (isTwoPanels) {
306 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000307 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100308 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000309 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100310 }
311 } else {
312 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000313 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100314 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000315 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100316 }
317 }
318
Tony Wickham15883892021-02-12 11:24:40 -0800319 if (isTaskbarPresent) {
Jon Miranda7e819502022-11-03 10:56:32 -0700320 if (DisplayController.isTransientTaskbar(context)) {
321 taskbarSize = res.getDimensionPixelSize(R.dimen.transient_taskbar_size);
322 stashedTaskbarSize =
323 res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_size);
Alex Chau905e0f12022-11-14 21:55:37 +0000324 transientTaskbarMargin =
325 res.getDimensionPixelSize(R.dimen.transient_taskbar_margin);
Jon Miranda7e819502022-11-03 10:56:32 -0700326 } else {
327 taskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_size);
328 stashedTaskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
329 }
Tony Wickham15883892021-02-12 11:24:40 -0800330 }
Tony Wickham15883892021-02-12 11:24:40 -0800331
Winson Chungb3800242013-10-24 11:01:54 -0700332 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100333 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700334
Thales Limad90faab2021-09-21 17:18:47 +0100335 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
336 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100337 gridVisualizationPaddingX = res.getDimensionPixelSize(
338 R.dimen.grid_visualization_horizontal_cell_spacing);
339 gridVisualizationPaddingY = res.getDimensionPixelSize(
340 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500341
Alex Chaue0227552022-04-06 19:44:43 +0100342 bottomSheetTopPadding = mInsets.top // statusbar height
Andras Kloczl142b0542022-03-09 21:26:02 +0000343 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
344 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
Alex Chau3d2c0622022-09-01 21:28:14 +0100345 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
346 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
347 if (isTablet) {
348 bottomSheetWorkspaceScale = workspaceContentScale;
349 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
350 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
351 // When depth is 1, wallpaper zoom is set to 1.
352 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
353 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
354 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
355 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
356 } else {
357 bottomSheetWorkspaceScale = 1f;
358 bottomSheetDepth = 0f;
359 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000360
Jon Mirandae126d722021-02-25 10:45:20 -0500361 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
Thales Limab35faed2022-09-05 16:30:01 -0300362
363 if (inv.folderStyle != INVALID_RESOURCE_HANDLE) {
364 TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
365 R.styleable.FolderDisplayStyle);
366 // These are re-set in #updateFolderCellSize if the grid is not scalable
367 folderCellHeightPx = folderStyle.getDimensionPixelSize(
368 R.styleable.FolderDisplayStyle_folderCellHeight, 0);
369 folderCellWidthPx = folderStyle.getDimensionPixelSize(
370 R.styleable.FolderDisplayStyle_folderCellWidth, 0);
371
372 folderContentPaddingTop = folderStyle.getDimensionPixelSize(
373 R.styleable.FolderDisplayStyle_folderTopPadding, 0);
374 folderCellLayoutBorderSpacePx = folderStyle.getDimensionPixelSize(
375 R.styleable.FolderDisplayStyle_folderBorderSpace, 0);
376 folderFooterHeightPx = folderStyle.getDimensionPixelSize(
377 R.styleable.FolderDisplayStyle_folderFooterHeight, 0);
378 folderStyle.recycle();
379 } else {
380 folderCellLayoutBorderSpacePx = 0;
381 folderFooterHeightPx = 0;
382 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
383 }
Jon Mirandae126d722021-02-25 10:45:20 -0500384
Thales Lima78d00ad2021-09-30 11:29:06 +0100385 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv);
Thales Limab35faed2022-09-05 16:30:01 -0300386 cellLayoutBorderSpaceOriginalPx = new Point(cellLayoutBorderSpacePx);
Thales Lima85c942f2021-12-31 13:04:20 +0000387 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000388 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
389 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Jon Mirandae126d722021-02-25 10:45:20 -0500390
Tony Wickham5edf9e22020-03-27 20:06:52 -0700391 workspacePageIndicatorHeight = res.getDimensionPixelSize(
392 R.dimen.workspace_page_indicator_height);
393 mWorkspacePageIndicatorOverlapWorkspace =
394 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700395
Winson Chungb3800242013-10-24 11:01:54 -0700396 iconDrawablePaddingOriginalPx =
397 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Alex Chaua02eddc2021-04-29 00:36:06 +0100398
Sunny Goyal47328fd2016-05-25 18:56:41 -0700399 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100400 dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
401 dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100402 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
403 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100404 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
405 R.dimen.drop_target_button_drawable_horizontal_padding);
406 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
407 R.dimen.drop_target_button_drawable_vertical_padding);
408 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100409 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
410 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100411
Alex Chau906d8822022-05-23 10:42:25 +0100412 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
413 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700414
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700415 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700416
Thales Limaa1012902022-01-13 17:58:42 +0000417 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100418 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
419 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
420
Thales Lima12d0eff2022-03-25 17:06:11 +0000421 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
422 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
423 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
424 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
425 && hotseatQsbHeight > 0;
426 isQsbInline = inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000427
Thales Lima425f6822022-05-10 13:44:58 -0300428 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100429 numShownHotseatIcons =
430 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000431
Sunny Goyal19ff7282021-04-22 10:12:54 -0700432 numShownAllAppsColumns =
433 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100434
435 int hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
436 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
437 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
438 // Have a little space between the inset and the QSB
439 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
440 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
441
442 // Only change the spaces if there is space
443 if (availableSpace > 0) {
444 // Make sure there is enough space between hotseat/QSB and QSB/navBar
445 if (availableSpace < minQsbMargin * 2) {
446 minQsbMargin = availableSpace / 2;
447 hotseatQsbSpace = minQsbMargin;
448 } else {
449 hotseatQsbSpace -= minQsbMargin;
450 }
451 }
452 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
453
Thales Limaa1012902022-01-13 17:58:42 +0000454 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100455 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
Thales Limaa1012902022-01-13 17:58:42 +0000456 }
Thales Lima425f6822022-05-10 13:44:58 -0300457
Pat Manningde25c0d2022-04-05 19:11:26 +0100458 springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
459 R.dimen.spring_loaded_hotseat_top_margin);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700460 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800461 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700462 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700463 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Thales Limab8c05952022-05-23 16:58:38 +0100464 updateHotseatSizes(pxFromDp(inv.iconSize[INDEX_DEFAULT], mMetrics));
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700465 if (areNavButtonsInline && !isPhone) {
Pat Manning26f70f72022-07-07 13:50:39 +0100466 /*
467 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700468 * Spacing between nav buttons +
Pat Manning26f70f72022-07-07 13:50:39 +0100469 * Little space at the end for contextual buttons +
470 * Little space between icons and nav buttons
471 */
472 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700473 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
474 + res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing)
Pat Manning26f70f72022-07-07 13:50:39 +0100475 + res.getDimensionPixelSize(R.dimen.taskbar_hotseat_nav_spacing);
476 } else {
477 hotseatBarEndOffset = 0;
478 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700479
Alex Chau635b3ab2022-01-26 16:49:10 +0000480 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chau5fd9d492021-07-22 17:27:11 +0100481 overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100482 overviewTaskIconDrawableSizePx =
483 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
484 overviewTaskIconDrawableSizeGridPx =
485 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700486 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx;
Jeremy Sim3c2c3f12022-05-16 20:37:43 -0700487 overviewActionsTopMarginPx = res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000488 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
489 overviewActionsButtonSpacing = res.getDimensionPixelSize(
490 R.dimen.overview_actions_button_spacing);
Alex Chau19c6eca2022-03-10 20:12:56 +0000491 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700492 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000493 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700494
Jeremy Sim0ac47082022-10-10 13:59:40 -0700495 splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset);
496
Jon Miranda2ed276e2017-06-29 11:36:34 -0700497 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400498 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700499
Jon Miranda2ed276e2017-06-29 11:36:34 -0700500 // Now that we have all of the variables calculated, we can tune certain sizes.
Thales Limaae0d7ef2022-11-16 15:53:43 +0000501 if (isScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400502 // Paddings were created assuming no scaling, so we first unscale the extra space.
Jon Mirandaab3c6812021-06-28 15:42:28 -0700503 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
Thales Limaae0d7ef2022-11-16 15:53:43 +0000504 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
505 DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace);
Jon Miranda228877d2021-02-09 11:05:00 -0500506
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400507 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
508 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
509 int paddingHotseatBottom = padding.getHotseatBottomPadding(unscaledExtraSpace);
510
Jon Mirandaab3c6812021-06-28 15:42:28 -0700511 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
512 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700513 }
Pat Manning08610ca2022-04-05 21:03:16 +0100514
515 int cellLayoutPadding =
516 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
517 R.dimen.cell_layout_padding);
518 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
519 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800520 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800521
Thales Lima425f6822022-05-10 13:44:58 -0300522 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima9938c2f2022-07-25 14:38:16 +0100523 recalculateHotseatWidthAndBorderSpace(res);
Alex Chau206ede92022-08-01 17:46:12 +0100524
525 // AllApps height calculation depends on updated cellSize
526 if (isTablet) {
527 int collapseHandleHeight =
528 res.getDimensionPixelOffset(R.dimen.bottom_sheet_handle_area_height);
529 int contentHeight = heightPx - collapseHandleHeight - hotseatQsbHeight;
530 int targetContentHeight = (int) (allAppsCellHeightPx * ALL_APPS_TABLET_MAX_ROWS);
531 allAppsTopPadding = Math.max(mInsets.top, contentHeight - targetContentHeight);
532 allAppsShiftRange = heightPx - allAppsTopPadding;
533 } else {
534 allAppsTopPadding = 0;
535 allAppsShiftRange =
536 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
537 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100538 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
539 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300540
Alex Chaua02eddc2021-04-29 00:36:06 +0100541 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
542 R.dimen.drag_flingToDeleteMinVelocity);
543
Sihua Mae04aa202022-07-18 12:43:56 -0700544 mViewScaleProvider = viewScaleProvider;
545
Tony Wickham1237df02017-02-24 08:59:36 -0800546 // This is done last, after iconSizePx is calculated above.
Sunny Goyal65190ae2022-08-02 14:16:26 -0700547 mDotRendererWorkSpace = createDotRenderer(iconSizePx, dotRendererCache);
548 mDotRendererAllApps = createDotRenderer(allAppsIconSizePx, dotRendererCache);
549 }
550
551 private static DotRenderer createDotRenderer(
552 int size, @NonNull SparseArray<DotRenderer> cache) {
553 DotRenderer renderer = cache.get(size);
554 if (renderer == null) {
555 renderer = new DotRenderer(size, getShapePath(DEFAULT_DOT_SIZE), DEFAULT_DOT_SIZE);
556 cache.put(size, renderer);
557 }
558 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700559 }
560
Thales Lima425f6822022-05-10 13:44:58 -0300561 /**
562 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
563 * width of the hotseat.
564 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100565 private int calculateQsbWidth(int hotseatBorderSpace) {
Thales Lima425f6822022-05-10 13:44:58 -0300566 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100567 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300568 return getIconToIconWidthForColumns(columns)
569 - iconSizePx * numShownHotseatIcons
570 - hotseatBorderSpace * numShownHotseatIcons;
571 } else {
572 int columns = inv.hotseatColumnSpan[mTypeIndex];
573 return getIconToIconWidthForColumns(columns);
574 }
575 }
Thales Lima2903a622022-03-17 13:52:19 +0000576
Thales Lima425f6822022-05-10 13:44:58 -0300577 private int getIconToIconWidthForColumns(int columns) {
578 return columns * getCellSize().x
579 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400580 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000581 }
582
Thales Limad90faab2021-09-21 17:18:47 +0100583 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
584 if (isVerticalBarLayout()) {
585 return 0;
586 }
587
Thales Lima83bedbf2021-10-05 17:47:39 +0100588 return isScalableGrid
589 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
590 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100591 }
592
Thales Limab8c05952022-05-23 16:58:38 +0100593 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
594 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700595 // Ensure there is enough space for folder icons, which have a slightly larger radius.
596 hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR);
Thales Limab8c05952022-05-23 16:58:38 +0100597
Jon Miranda0d284852021-06-22 14:50:55 -0700598 if (isVerticalBarLayout()) {
599 hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
600 + hotseatBarSidePaddingEndPx;
Thales Limab8c05952022-05-23 16:58:38 +0100601 } else if (isQsbInline) {
602 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
603 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700604 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100605 hotseatBarSizePx = hotseatIconSizePx
606 + hotseatQsbSpace
607 + hotseatQsbVisualHeight
608 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700609 }
610 }
611
Thales Lima9938c2f2022-07-25 14:38:16 +0100612 private void recalculateHotseatWidthAndBorderSpace(Resources res) {
613 hotseatBorderSpace = calculateHotseatBorderSpace();
614 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
615 // Spaces should be correct when there nav buttons are not inline
616 if (!areNavButtonsInline) {
617 return;
618 }
619
620 // Get the maximum width that the hotseat can be
621 int columns = getPanelCount() * inv.numColumns;
622 int maxHotseatWidth = getIconToIconWidthForColumns(columns);
623 int sideSpace = (availableWidthPx - maxHotseatWidth) / 2;
624 int inlineButtonsOverlap = Math.max(0, hotseatBarEndOffset - sideSpace);
625 // decrease how much the nav buttons go "inside" the hotseat
626 maxHotseatWidth -= inlineButtonsOverlap;
627
628 // Get how much space is required to show the hotseat with QSB
629 int requiredWidth = getHotseatRequiredWidth();
630
631 // If spaces are fine, use them
632 if (requiredWidth <= maxHotseatWidth) {
633 return;
634 }
635
636 // Calculate the difference of widths and remove a little from each space between icons
637 // and QSB if it's inline
638 int spaceDiff = requiredWidth - maxHotseatWidth;
639 int numOfSpaces = numShownHotseatIcons - (isQsbInline ? 0 : 1);
640 hotseatBorderSpace -= (spaceDiff / numOfSpaces);
641
642 int minHotseatIconSpaceDp = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
643 int minHotseatQsbWidthDp = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
644
645 if (hotseatBorderSpace >= minHotseatIconSpaceDp) {
646 return;
647 }
648
649 // Border space can't be less than the minimum
650 hotseatBorderSpace = minHotseatIconSpaceDp;
651 requiredWidth = getHotseatRequiredWidth();
652
653 // If there is an inline qsb, change its size
654 if (isQsbInline) {
655 hotseatQsbWidth -= requiredWidth - maxHotseatWidth;
656 if (hotseatQsbWidth >= minHotseatQsbWidthDp) {
657 return;
658 }
659
660 // QSB can't be less than the minimum
661 hotseatQsbWidth = minHotseatQsbWidthDp;
662 }
663
664 // If it still doesn't fit, start removing icons
665 do {
666 numShownHotseatIcons--;
667 requiredWidth = getHotseatRequiredWidth();
668 } while (requiredWidth > maxHotseatWidth && numShownHotseatIcons > 1);
669
670 // Add back some space between the icons
671 spaceDiff = maxHotseatWidth - requiredWidth;
672 numOfSpaces = numShownHotseatIcons - (isQsbInline ? 0 : 1);
673 hotseatBorderSpace += (spaceDiff / numOfSpaces);
674 }
675
Thales Lima78d00ad2021-09-30 11:29:06 +0100676 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100677 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100678 }
679
680 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100681 if (!isScalableGrid) {
682 return new Point(0, 0);
683 }
684
Thales Lima080d8902022-03-28 15:30:29 +0100685 int horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
686 int verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
Thales Lima78d00ad2021-09-30 11:29:06 +0100687
688 return new Point(horizontalSpacePx, verticalSpacePx);
689 }
690
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700691 public Info getDisplayInfo() {
692 return mInfo;
693 }
694
Jon Miranda611dba42021-03-02 14:12:13 -0500695 /**
696 * We inset the widget padding added by the system and instead rely on the border spacing
697 * between cells to create reliable consistency between widgets
698 */
699 public boolean shouldInsetWidgets() {
700 Rect widgetPadding = inv.defaultWidgetPadding;
701
Jon Miranda49811182021-06-03 09:52:40 -0700702 // Check all sides to ensure that the widget won't overlap into another cell, or into
703 // status bar.
704 return workspaceTopPadding > widgetPadding.top
Thales Lima78d00ad2021-09-30 11:29:06 +0100705 && cellLayoutBorderSpacePx.x > widgetPadding.left
706 && cellLayoutBorderSpacePx.y > widgetPadding.top
707 && cellLayoutBorderSpacePx.x > widgetPadding.right
708 && cellLayoutBorderSpacePx.y > widgetPadding.bottom;
Jon Miranda611dba42021-03-02 14:12:13 -0500709 }
Jon Mirandae126d722021-02-25 10:45:20 -0500710
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700711 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800712 WindowBounds bounds = new WindowBounds(
713 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700714 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100715 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700716
717 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
718 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
719 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
720
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700721 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700722 .setWindowBounds(bounds)
723 .setUseTwoPanels(isTwoPanels)
Alex Chau6ed408f2022-03-04 12:58:05 +0000724 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700725 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000726 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800727 }
728
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700729 public DeviceProfile copy(Context context) {
730 return toBuilder(context).build();
731 }
732
733 /**
734 * TODO: Move this to the builder as part of setMultiWindowMode
735 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700736 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700737 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700738 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700739 .setMultiWindowMode(true)
740 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800741
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800742 // We use these scales to measure and layout the widgets using their full invariant profile
743 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
744 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
745 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700746 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
747 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
748 profile = profile.toBuilder(context)
749 .setViewScaleProvider(i -> p)
750 .build();
751 }
752
753 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800754
Jon Miranda93e1f042016-11-11 14:13:04 -0800755 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700756 }
757
Adam Cohen63f1ec02014-08-12 09:23:13 -0700758 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400759 * Checks if there is enough space for labels on the workspace.
760 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700761 * It is important to call this method after the All Apps variables have been set.
762 */
Jon Miranda941375e2021-03-31 13:10:45 -0400763 private void hideWorkspaceLabelsIfNotEnoughSpace() {
764 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
765 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
766 - iconTextHeight;
767
768 // We want enough space so that the text is closer to its corresponding icon.
769 if (workspaceCellPaddingY < iconTextHeight) {
770 iconTextSizePx = 0;
771 iconDrawablePaddingPx = 0;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700772 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda941375e2021-03-31 13:10:45 -0400773 autoResizeAllAppsCells();
774 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700775 }
Jon Miranda1091e532017-07-21 13:31:50 -0700776
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700777 /**
778 * Re-computes the all-apps cell size to be independent of workspace
779 */
780 public void autoResizeAllAppsCells() {
Jon Miranda941375e2021-03-31 13:10:45 -0400781 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
782 int topBottomPadding = textHeight;
Jon Miranda1091e532017-07-21 13:31:50 -0700783 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
Jon Miranda941375e2021-03-31 13:10:45 -0400784 + textHeight + (topBottomPadding * 2);
Jon Miranda1091e532017-07-21 13:31:50 -0700785 }
786
Thales Limab7ef5692022-03-10 10:32:36 +0000787 private void updateAllAppsContainerWidth(Resources res) {
Pat Manning08610ca2022-04-05 21:03:16 +0100788 int cellLayoutHorizontalPadding =
789 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
Alex Chau27b39b92022-01-14 18:02:18 +0000790 if (isTablet) {
Thales Limab7ef5692022-03-10 10:32:36 +0000791 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100792 res.getDimensionPixelSize(R.dimen.all_apps_bottom_sheet_horizontal_padding);
793
sfufa@google.comde013292021-09-21 18:22:44 -0700794 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
Thales Limab7ef5692022-03-10 10:32:36 +0000795 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Alex Chau27b39b92022-01-14 18:02:18 +0000796 + allAppsLeftRightPadding * 2;
797 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
sfufa@google.comde013292021-09-21 18:22:44 -0700798 } else {
799 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100800 desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding;
sfufa@google.comde013292021-09-21 18:22:44 -0700801 }
802 }
803
Jon Miranda228877d2021-02-09 11:05:00 -0500804 /**
805 * Returns the amount of extra (or unused) vertical space.
806 */
807 private int updateAvailableDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700808 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800809
Pat Manning08610ca2022-04-05 21:03:16 +0100810 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -0500811
812 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +0100813 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +0000814 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -0500815 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500816 float scaleY = maxHeight / usedHeight;
817 boolean shouldScale = scaleY < 1f;
818
819 float scaleX = 1f;
820 if (isScalableGrid) {
821 // We scale to fit the cellWidth and cellHeight in the available space.
822 // The benefit of scalable grids is that we can get consistent aspect ratios between
823 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +0100824 float usedWidth =
825 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500826 // We do not subtract padding here, as we also scale the workspace padding if needed.
827 scaleX = availableWidthPx / usedWidth;
828 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700829 }
Jon Mirandae126d722021-02-25 10:45:20 -0500830
831 if (shouldScale) {
832 float scale = Math.min(scaleX, scaleY);
833 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +0100834 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -0500835 }
836
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700837 updateAvailableFolderCellDimensions(res);
Jon Miranda228877d2021-02-09 11:05:00 -0500838 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700839 }
840
Pat Manninga2e14992022-04-22 11:29:17 +0100841 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +0100842 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
843 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
844 }
845
Pat Manninga2e14992022-04-22 11:29:17 +0100846 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +0000847 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +0100848 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
849 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -0500850 }
851
Jon Miranda6f7e9702019-09-16 14:44:14 -0700852 /**
853 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
854 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
855 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
856 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800857 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -0700858 // Icon scale should never exceed 1, otherwise pixellation may occur.
859 iconScale = Math.min(1f, scale);
860 cellScaleToFit = scale;
861
Jon Miranda18751b62017-07-31 17:25:27 -0700862 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800863 final boolean isVerticalLayout = isVerticalBarLayout();
Thales Lima83bedbf2021-10-05 17:47:39 +0100864 float invIconSizeDp = inv.iconSize[mTypeIndex];
865 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
Andras Kloczl30fe9152021-08-05 18:02:29 +0200866
Jon Mirandaab3c6812021-06-28 15:42:28 -0700867 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, iconScale));
Jon Mirandaab3c6812021-06-28 15:42:28 -0700868 iconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * iconScale);
869 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700870
Thales Lima080d8902022-03-28 15:30:29 +0100871 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500872
873 if (isScalableGrid) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100874 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
875 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500876 int cellContentHeight = iconSizePx + iconDrawablePaddingPx
877 + Utilities.calculateTextHeight(iconTextSizePx);
878 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +0100879 desiredWorkspaceHorizontalMarginPx =
880 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -0500881 } else {
Jon Mirandae126d722021-02-25 10:45:20 -0500882 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700883 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR)
884 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -0500885 + Utilities.calculateTextHeight(iconTextSizePx);
886 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
887 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
888 && !isMultiWindowMode) {
889 // Ensures that the label is closer to its corresponding icon. This is not an issue
890 // with vertical bar layout or multi-window mode since the issue is handled
891 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
892 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
893 iconDrawablePaddingPx = cellPaddingY;
894 }
Jon Miranda846455e2017-10-02 14:58:52 -0700895 }
Jon Miranda18751b62017-07-31 17:25:27 -0700896
Sunny Goyalae190ff2020-04-14 00:19:01 +0000897 // All apps
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500898 updateAllAppsIconSize(scale, res);
Winson Chungb3800242013-10-24 11:01:54 -0700899
Thales Limab8c05952022-05-23 16:58:38 +0100900 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700901
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700902 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -0700903 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
904 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Winson Chung0f785722015-04-08 10:27:49 -0700905 }
906
Thales Lima425f6822022-05-10 13:44:58 -0300907 /**
908 * Hotseat width spans a certain number of columns on scalable grids.
909 * This method calculates the space between the icons to achieve that width.
910 */
911 private int calculateHotseatBorderSpace() {
912 if (!isScalableGrid) return 0;
Thales Lima9938c2f2022-07-25 14:38:16 +0100913 int columns = inv.hotseatColumnSpan[mTypeIndex];
914 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
915 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
916 return (int) (hotseatWidthPx - hotseatIconsTotalPx) / (numShownHotseatIcons - 1);
Thales Lima425f6822022-05-10 13:44:58 -0300917 }
918
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500919
920 /**
921 * Updates the iconSize for allApps* variants.
922 */
Brian Isganitisa9a78112022-05-23 18:11:47 -0700923 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +0100924 allAppsBorderSpacePx = new Point(
925 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
926 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700927 // AllApps cells don't have real space between cells,
928 // so we add the border space to the cell height
929 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics, scale)
930 + allAppsBorderSpacePx.y;
931 // but width is just the cell,
932 // the border is added in #updateAllAppsContainerWidth
Thales Lima080d8902022-03-28 15:30:29 +0100933 if (isScalableGrid) {
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500934 allAppsIconSizePx =
Brandon Dayauon969f6a82022-05-19 09:46:47 -0700935 pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics, scale);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500936 allAppsIconTextSizePx =
Brandon Dayauon969f6a82022-05-19 09:46:47 -0700937 pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics, scale);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500938 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -0700939 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500940 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700941 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
942 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500943 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
944 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700945 allAppsIconDrawablePaddingPx =
946 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -0700947 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500948 }
949
Thales Limab7ef5692022-03-10 10:32:36 +0000950 updateAllAppsContainerWidth(res);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500951 if (isVerticalBarLayout()) {
952 hideWorkspaceLabelsIfNotEnoughSpace();
953 }
954 }
955
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700956 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700957 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700958
Jon Mirandac1b23992016-12-13 08:57:36 -0800959 // Don't let the folder get too close to the edges of the screen.
Jon Miranda1786df32018-09-25 13:05:23 -0700960 int folderMargin = edgeMarginPx * 2;
Sunny Goyal07b69292018-01-08 14:19:34 -0800961 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -0800962
963 // Check if the icons fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -0500964 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Thales Limab35faed2022-09-05 16:30:01 -0300965 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx);
966 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderFooterHeightPx
Jon Mirandae126d722021-02-25 10:45:20 -0500967 - folderMargin - folderContentPaddingTop;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800968 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -0800969
970 // Check if the icons fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -0500971 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Thales Limab35faed2022-09-05 16:30:01 -0300972 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx);
Jon Mirandae126d722021-02-25 10:45:20 -0500973 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin
974 - folderContentPaddingLeftRight * 2;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800975 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -0800976
977 float scale = Math.min(scaleX, scaleY);
978 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700979 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700980 }
981 }
982
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700983 private void updateFolderCellSize(float scale, Resources res) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100984 float invIconSizeDp = isVerticalBarLayout()
Thales Lima12d0eff2022-03-25 17:06:11 +0000985 ? inv.iconSize[INDEX_LANDSCAPE]
986 : inv.iconSize[INDEX_DEFAULT];
Sunny Goyal35c7b192021-04-20 16:51:10 -0700987 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Thales Lima83bedbf2021-10-05 17:47:39 +0100988 folderChildTextSizePx =
Thales Lima12d0eff2022-03-25 17:06:11 +0000989 pxFromSp(inv.iconTextSize[INDEX_DEFAULT], mMetrics, scale);
Thales Limab35faed2022-09-05 16:30:01 -0300990 folderLabelTextSizePx = Math.max(pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics),
991 (int) (folderChildTextSizePx * folderLabelTextScale));
Jon Mirandabf7d8122016-11-03 15:29:29 -0700992
993 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700994
Jon Miranda823da222021-03-23 08:08:45 -0400995 if (isScalableGrid) {
Thales Limab35faed2022-09-05 16:30:01 -0300996 if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
997 folderCellWidthPx = pxFromDp(getCellSize().x, mMetrics, scale);
998 folderCellHeightPx = pxFromDp(getCellSize().y, mMetrics, scale);
999 }
Jon Mirandaf33f5b32021-07-22 17:15:31 -07001000
Thales Limab35faed2022-09-05 16:30:01 -03001001 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx;
Jon Miranda823da222021-03-23 08:08:45 -04001002 } else {
1003 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
1004 * scale);
1005 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
1006 * scale);
1007
1008 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
1009 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Thales Limab35faed2022-09-05 16:30:01 -03001010 folderContentPaddingLeftRight =
1011 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
1012 folderFooterHeightPx =
1013 res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
Jon Miranda823da222021-03-23 08:08:45 -04001014 }
1015
Jonathan Miranda9ad87462017-07-26 17:41:02 +00001016 folderChildDrawablePaddingPx = Math.max(0,
1017 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -07001018 }
1019
Winson1f064272016-07-18 17:18:02 -07001020 public void updateInsets(Rect insets) {
1021 mInsets.set(insets);
1022 }
1023
Sunny Goyalae6e3182019-04-30 12:04:37 -07001024 /**
1025 * The current device insets. This is generally same as the insets being dispatched to
1026 * {@link Insettable} elements, but can differ if the element is using a different profile.
1027 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -08001028 public Rect getInsets() {
1029 return mInsets;
1030 }
1031
Sunny Goyal756cd262015-08-20 12:33:21 -07001032 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001033 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001034 }
1035
Sunny Goyal19ff7282021-04-22 10:12:54 -07001036 public Point getCellSize(Point result) {
1037 if (result == null) {
1038 result = new Point();
1039 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001040
Pat Manning25d53342022-05-10 09:58:49 +00001041 int shortcutAndWidgetContainerWidth =
1042 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1043 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1044 inv.numColumns);
1045 int shortcutAndWidgetContainerHeight =
1046 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1047 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1048 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001049 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001050 }
1051
1052 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001053 * Returns the left and right space on the cell, which is the cell width - icon size
1054 */
1055 public int getCellHorizontalSpace() {
1056 return getCellSize().x - iconSizePx;
1057 }
1058
1059 /**
Pat Manning25d53342022-05-10 09:58:49 +00001060 * Gets the number of panels within the workspace.
1061 */
1062 public int getPanelCount() {
1063 return isTwoPanels ? 2 : 1;
1064 }
1065
1066 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001067 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1068 * bottom of the screen.
1069 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001070 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1071 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001072 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001073 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001074 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001075 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001076 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001077 }
1078
1079 /**
1080 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1081 */
Pat Manning25d53342022-05-10 09:58:49 +00001082 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001083 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001084 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001085 }
1086
1087 /**
1088 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1089 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001090 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001091 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001092 return heightPx - (isVerticalBarLayout()
1093 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001094 }
1095
Pat Manningea5c1d22022-04-14 10:58:16 +01001096 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001097 * Gets the scale of the workspace for the spring-loaded edit state.
1098 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001099 public float getWorkspaceSpringLoadScale(Context context) {
1100 float scale =
1101 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1102 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001103 scale = Math.min(scale, 1f);
1104
Pat Manninge63dd252022-08-02 16:15:29 +01001105 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001106 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001107 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001108 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001109 if (scaledWorkspaceWidth > maxAvailableWidth) {
1110 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1111 }
1112 return scale;
1113 }
1114
Pat Manning25d53342022-05-10 09:58:49 +00001115 /**
1116 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1117 *
1118 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1119 * layouts have two Cell Layouts per workspace.
1120 */
1121 public int getCellLayoutWidth() {
1122 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001123 }
1124
Pat Manning25d53342022-05-10 09:58:49 +00001125 /**
1126 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1127 *
1128 * <p>This is the height of a Workspace, less its vertical padding.
1129 */
1130 public int getCellLayoutHeight() {
1131 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001132 }
1133
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001134 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001135 return new Point(workspacePadding.left + workspacePadding.right,
1136 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001137 }
1138
1139 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001140 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1141 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001142 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001143 private void updateWorkspacePadding() {
1144 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001145 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -08001146 padding.top = 0;
1147 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001148 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001149 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -07001150 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -07001151 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -07001152 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001153 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -07001154 }
Winson Chungb3800242013-10-24 11:01:54 -07001155 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001156 // Pad the bottom of the workspace with hotseat bar
1157 // and leave a bit of space in case a widget go all the way down
1158 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding
1159 + workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace
1160 - mInsets.bottom;
Pat Manning08610ca2022-04-05 21:03:16 +01001161 int paddingTop = workspaceTopPadding + (isScalableGrid ? 0 : edgeMarginPx);
1162 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001163
Pat Manning08610ca2022-04-05 21:03:16 +01001164 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001165 }
Pat Manning08610ca2022-04-05 21:03:16 +01001166 insetPadding(workspacePadding, cellLayoutPaddingPx);
1167 }
1168
1169 private void insetPadding(Rect paddings, Rect insets) {
1170 insets.left = Math.min(insets.left, paddings.left);
1171 paddings.left -= insets.left;
1172
1173 insets.top = Math.min(insets.top, paddings.top);
1174 paddings.top -= insets.top;
1175
1176 insets.right = Math.min(insets.right, paddings.right);
1177 paddings.right -= insets.right;
1178
1179 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1180 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001181 }
1182
Sunny Goyal57b22792021-05-25 14:35:01 -07001183 /**
1184 * Returns the padding for hotseat view
1185 */
1186 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001187 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001188 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001189 // The hotseat icons will be placed in the middle of the hotseat cells.
1190 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1191 // in vertical bar layout.
1192 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1193 // is set to account for that difference.
1194 float diffOverlapFactor = iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
Pat Manning08610ca2022-04-05 21:03:16 +01001195 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1196 - diffOverlapFactor), 0);
1197 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001198 + diffOverlapFactor), 0);
1199
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001200 if (isSeascape()) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001201 hotseatBarPadding.set(mInsets.left + hotseatBarSidePaddingStartPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001202 hotseatBarSidePaddingEndPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001203 } else {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001204 hotseatBarPadding.set(hotseatBarSidePaddingEndPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001205 mInsets.right + hotseatBarSidePaddingStartPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001206 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001207 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001208 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001209 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1210 int hotseatBarTopPadding =
1211 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001212
Thales Lima612230d2022-03-31 18:04:37 +01001213 // Push icons to the side
Thales Lima9938c2f2022-07-25 14:38:16 +01001214 int requiredWidth = getHotseatRequiredWidth();
Pat Manning26f70f72022-07-07 13:50:39 +01001215 int hotseatWidth = Math.min(requiredWidth, availableWidthPx - hotseatBarEndOffset);
Thales Lima612230d2022-03-31 18:04:37 +01001216 int sideSpacing = (availableWidthPx - hotseatWidth) / 2;
Thales Lima612230d2022-03-31 18:04:37 +01001217
Pat Manning5f74bfd2022-07-20 12:08:54 +01001218 hotseatBarPadding.set(sideSpacing, hotseatBarTopPadding, sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001219 hotseatBarBottomPadding);
Alex Chau51da2192022-05-20 13:32:10 +01001220
1221 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001222 if (isRtl) {
Thales Lima9938c2f2022-07-25 14:38:16 +01001223 hotseatBarPadding.right += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001224 } else {
Thales Lima9938c2f2022-07-25 14:38:16 +01001225 hotseatBarPadding.left += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001226 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001227
Pat Manning26f70f72022-07-07 13:50:39 +01001228 if (hotseatBarEndOffset > sideSpacing) {
Thales Lima612230d2022-03-31 18:04:37 +01001229 int diff = isRtl
Pat Manning26f70f72022-07-07 13:50:39 +01001230 ? sideSpacing - hotseatBarEndOffset
1231 : hotseatBarEndOffset - sideSpacing;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001232 hotseatBarPadding.left -= diff;
1233 hotseatBarPadding.right += diff;
Sunny Goyal57b22792021-05-25 14:35:01 -07001234 }
Thales Lima425f6822022-05-10 13:44:58 -03001235 } else if (isScalableGrid) {
Alex Chau206ede92022-08-01 17:46:12 +01001236 int sideSpacing = (availableWidthPx - hotseatQsbWidth) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001237 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001238 0,
Thales Lima425f6822022-05-10 13:44:58 -03001239 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001240 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001241 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001242 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1243 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1244 // for this, we pad the left and right of the hotseat with half of the difference of a
1245 // workspace cell vs a hotseat cell.
1246 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001247 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001248 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001249 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001250 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1251 + mInsets.left,
1252 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001253 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001254 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001255 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001256 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001257 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001258 }
1259
Thales Lima9938c2f2022-07-25 14:38:16 +01001260 private int getAdditionalQsbSpace() {
1261 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1262 }
1263
1264 /**
1265 * Calculate how much space the hotseat needs to be shown completely
1266 */
1267 private int getHotseatRequiredWidth() {
1268 int additionalQsbSpace = getAdditionalQsbSpace();
1269 return iconSizePx * numShownHotseatIcons
1270 + hotseatBorderSpace * (numShownHotseatIcons - 1)
1271 + additionalQsbSpace;
1272 }
1273
Winsonfadbe8f2016-07-22 16:35:37 -07001274 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001275 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1276 */
1277 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001278 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001279 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1280 } else if (isTaskbarPresent) { // QSB on top
1281 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001282 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001283 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001284 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001285 }
1286
Thales Limab8c05952022-05-23 16:58:38 +01001287 /**
1288 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1289 */
1290 private int getHotseatBarBottomPadding() {
1291 if (isTaskbarPresent) { // QSB on top or inline
1292 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001293 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001294 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001295 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001296 }
1297
1298 /**
Alex Chau51da2192022-05-20 13:32:10 +01001299 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1300 */
1301 public int getTaskbarOffsetY() {
1302 int taskbarIconBottomSpace = (taskbarSize - iconSizePx) / 2;
1303 int launcherIconBottomSpace =
1304 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001305 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001306 }
1307
1308 /**
Alex Chaua2fc7642022-04-21 14:20:23 +01001309 * Returns the number of pixels required below OverviewActions excluding insets.
1310 */
1311 public int getOverviewActionsClaimedSpaceBelow() {
Alex Chaud67ddc42022-09-30 18:15:56 +01001312 if (isTaskbarPresent) {
Alex Chau905e0f12022-11-14 21:55:37 +00001313 if (FeatureFlags.ENABLE_TASKBAR_IN_OVERVIEW.get()) {
1314 return taskbarSize + transientTaskbarMargin;
1315 }
1316
1317 return isGestureMode
1318 ? stashedTaskbarSize
1319 // Align vertically to where nav buttons are.
1320 : ((taskbarSize - overviewActionsHeight) / 2) + getTaskbarOffsetY();
Alex Chaud67ddc42022-09-30 18:15:56 +01001321 }
1322 return mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001323 }
1324
1325 /** Gets the space that the overview actions will take, including bottom margin. */
1326 public int getOverviewActionsClaimedSpace() {
1327 return overviewActionsTopMarginPx + overviewActionsHeight
1328 + getOverviewActionsClaimedSpaceBelow();
1329 }
1330
1331 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001332 * Takes the View and return the scales of width and height depending on the DeviceProfile
1333 * specifications
1334 *
1335 * @param itemInfo The tag of the widget view
1336 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1337 * height
1338 */
1339 @NonNull
1340 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1341 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1342 }
1343
1344 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001345 * @return the bounds for which the open folders should be contained within
1346 */
1347 public Rect getAbsoluteOpenFolderBounds() {
1348 if (isVerticalBarLayout()) {
1349 // Folders should only appear right of the drop target bar and left of the hotseat
1350 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1351 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001352 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001353 mInsets.top + availableHeightPx);
1354 } else {
1355 // Folders should only appear below the drop target bar and above the hotseat
Tony Wickhamae72b462021-03-10 16:18:40 -08001356 int hotseatTop = isTaskbarPresent ? taskbarSize : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001357 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001358 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001359 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001360 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001361 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001362 }
1363 }
1364
Jon Miranda228877d2021-02-09 11:05:00 -05001365 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1366 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001367 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001368
Jon Miranda228877d2021-02-09 11:05:00 -05001369 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1370 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001371 }
1372
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001373 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001374 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1375 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1376 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001377 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001378 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001379 return isLandscape && transposeLayoutWithOrientation;
1380 }
1381
Sunny Goyal59d086c2018-05-07 17:31:40 -07001382 /**
1383 * Updates orientation information and returns true if it has changed from the previous value.
1384 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001385 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001386 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001387 boolean isSeascape = DisplayController.INSTANCE.get(context)
1388 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001389 if (mIsSeascape != isSeascape) {
1390 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001391 // Hotseat changing sides requires updating workspace left/right paddings
1392 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001393 return true;
1394 }
1395 }
1396 return false;
1397 }
1398
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001399 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001400 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001401 }
1402
Sunny Goyal07b69292018-01-08 14:19:34 -08001403 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001404 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001405 }
1406
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001407 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001408 switch (containerType) {
1409 case CellLayout.WORKSPACE:
1410 return cellHeightPx;
1411 case CellLayout.FOLDER:
1412 return folderCellHeightPx;
1413 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001414 // The hotseat is the only container where the cell height is going to be
1415 // different from the content within that cell.
1416 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001417 default:
1418 // ??
1419 return 0;
1420 }
1421 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001422
Jon Miranda58561d42021-03-17 10:51:54 -04001423 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001424 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001425 }
1426
Alex Chaue818bcb2022-09-02 17:27:11 +01001427 private String dpPointFToString(String name, PointF value) {
1428 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
1429 }
1430
Pat Manning5f74bfd2022-07-20 12:08:54 +01001431 /** Dumps various DeviceProfile variables to the specified writer. */
1432 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04001433 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001434 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001435
1436 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001437 writer.println(prefix + "\tisPhone:" + isPhone);
1438 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1439 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001440 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001441
1442 writer.println(prefix + "\tisLandscape:" + isLandscape);
1443 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001444 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001445
1446 writer.println(prefix + pxToDpStr("windowX", windowX));
1447 writer.println(prefix + pxToDpStr("windowY", windowY));
1448 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1449 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001450 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1451 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001452 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1453 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1454 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1455 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001456
1457 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1458
1459 writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
1460
Thales Lima83bedbf2021-10-05 17:47:39 +01001461 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001462 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1463 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1464 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001465
Alex Chaue818bcb2022-09-02 17:27:11 +01001466 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07001467
Jon Miranda58561d42021-03-17 10:51:54 -04001468 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1469 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1470
1471 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1472 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1473
Thales Lima83bedbf2021-10-05 17:47:39 +01001474 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1475 cellLayoutBorderSpacePx.x));
1476 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1477 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001478 writer.println(
1479 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
1480 writer.println(
1481 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
1482 writer.println(
1483 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01001484 writer.println(
1485 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01001486
Jon Miranda58561d42021-03-17 10:51:54 -04001487 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1488 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1489 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1490
1491 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1492 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1493 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1494 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1495 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1496 folderChildDrawablePaddingPx));
Thales Limab35faed2022-09-05 16:30:01 -03001497 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx",
1498 folderCellLayoutBorderSpacePx));
Thales Limaa08a4432022-08-09 09:55:17 +01001499 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
1500 folderContentPaddingLeftRight));
1501 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Thales Limab35faed2022-09-05 16:30:01 -03001502 writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001503
Alex Chaue0227552022-04-06 19:44:43 +01001504 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001505 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
1506 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
1507 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
1508 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01001509
1510 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
1511 writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001512 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
1513 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04001514 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1515 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1516 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1517 allAppsIconDrawablePaddingPx));
1518 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001519 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001520 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
1521 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001522 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau62572c02022-07-25 18:36:37 +00001523 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
Alex Chau27b39b92022-01-14 18:02:18 +00001524 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001525
1526 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03001527 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04001528 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00001529 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Jon Miranda58561d42021-03-17 10:51:54 -04001530 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
1531 hotseatBarSidePaddingStartPx));
1532 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
1533 hotseatBarSidePaddingEndPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001534 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01001535 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
1536 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01001537 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
1538 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001539 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
1540 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
1541 hotseatLayoutPadding.top));
1542 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
1543 hotseatLayoutPadding.bottom));
1544 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
1545 hotseatLayoutPadding.left));
1546 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
1547 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001548 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001549 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001550 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01001551 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001552
1553 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001554 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda58561d42021-03-17 10:51:54 -04001555 writer.println(prefix + pxToDpStr("taskbarSize", taskbarSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001556
Thales Lima83bedbf2021-10-05 17:47:39 +01001557 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1558 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001559 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
1560 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
1561 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00001562 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001563
Jon Mirandaab3c6812021-06-28 15:42:28 -07001564 writer.println(prefix + pxToDpStr("iconScale", iconScale));
1565 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04001566 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00001567 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001568
Thales Limaae0d7ef2022-11-16 15:53:43 +00001569 if (inv.devicePaddingId != INVALID_RESOURCE_HANDLE) {
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001570 int unscaledExtraSpace = (int) (extraSpace / iconScale);
Thales Limaae0d7ef2022-11-16 15:53:43 +00001571 DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId);
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001572 writer.println(prefix + pxToDpStr("maxEmptySpace",
Thales Limaae0d7ef2022-11-16 15:53:43 +00001573 devicePaddings.getDevicePadding(unscaledExtraSpace).getMaxEmptySpacePx()));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001574 }
Jon Miranda58561d42021-03-17 10:51:54 -04001575 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
1576 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00001577
1578 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00001579 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
1580 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
1581 overviewTaskIconDrawableSizePx));
1582 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
1583 overviewTaskIconDrawableSizeGridPx));
1584 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
1585 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01001586 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
1587 overviewActionsTopMarginPx));
1588 writer.println(prefix + pxToDpStr("overviewActionsHeight",
1589 overviewActionsHeight));
Alex Chau635b3ab2022-01-26 16:49:10 +00001590 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
1591 overviewActionsButtonSpacing));
1592 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
1593 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
1594 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01001595
Alex Chau62572c02022-07-25 18:36:37 +00001596 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001597 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00001598 writer.println(
1599 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001600
Pat Manning5f74bfd2022-07-20 12:08:54 +01001601 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
1602 getCellLayoutSpringLoadShrunkTop()));
1603 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
1604 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01001605 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
1606 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001607 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
1608 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01001609 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
1610 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Jon Miranda58561d42021-03-17 10:51:54 -04001611 }
1612
Alex Chaua6907dc2022-03-18 15:24:07 +00001613 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07001614 Configuration config = new Configuration(c.getResources().getConfiguration());
1615 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03001616 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00001617 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07001618 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07001619 }
Sunny Goyalfde55052018-02-01 14:46:13 -08001620
1621 /**
1622 * Callback when a component changes the DeviceProfile associated with it, as a result of
1623 * configuration change
1624 */
1625 public interface OnDeviceProfileChangeListener {
1626
1627 /**
1628 * Called when the device profile is reassigned. Note that for layout and measurements, it
1629 * is sufficient to listen for inset changes. Use this callback when you need to perform
1630 * a one time operation.
1631 */
1632 void onDeviceProfileChanged(DeviceProfile dp);
1633 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001634
Brian Isganitis099945b2022-01-31 18:15:00 -05001635 /** Allows registering listeners for {@link DeviceProfile} changes. */
1636 public interface DeviceProfileListenable {
1637
1638 /** The current device profile. */
1639 DeviceProfile getDeviceProfile();
1640
1641 /** Registered {@link OnDeviceProfileChangeListener} instances. */
1642 List<OnDeviceProfileChangeListener> getOnDeviceProfileChangeListeners();
1643
1644 /** Notifies listeners of a {@link DeviceProfile} change. */
1645 default void dispatchDeviceProfileChanged() {
1646 DeviceProfile deviceProfile = getDeviceProfile();
1647 List<OnDeviceProfileChangeListener> listeners = getOnDeviceProfileChangeListeners();
1648 for (int i = listeners.size() - 1; i >= 0; i--) {
1649 listeners.get(i).onDeviceProfileChanged(deviceProfile);
1650 }
1651 }
1652
1653 /** Register listener for {@link DeviceProfile} changes. */
1654 default void addOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
1655 getOnDeviceProfileChangeListeners().add(listener);
1656 }
1657
1658 /** Unregister listener for {@link DeviceProfile} changes. */
1659 default void removeOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
1660 getOnDeviceProfileChangeListeners().remove(listener);
1661 }
1662 }
1663
Sihua Mae04aa202022-07-18 12:43:56 -07001664 /**
1665 * Handler that deals with ItemInfo of the views for the DeviceProfile
1666 */
1667 @FunctionalInterface
1668 public interface ViewScaleProvider {
1669 /**
1670 * Get the scales from the view
1671 *
1672 * @param itemInfo The tag of the widget view
1673 * @return PointF instance containing the scale information, or null if using the default
1674 * app widget scale of this device profile.
1675 */
1676 @NonNull
1677 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
1678 }
1679
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001680 public static class Builder {
1681 private Context mContext;
1682 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07001683 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001684
Sunny Goyal19ff7282021-04-22 10:12:54 -07001685 private WindowBounds mWindowBounds;
1686 private boolean mUseTwoPanels;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001687
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001688 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001689 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00001690 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07001691 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001692
Sunny Goyal65190ae2022-08-02 14:16:26 -07001693 private SparseArray<DotRenderer> mDotRendererCache;
1694
Sunny Goyalfd58da62020-08-11 12:06:49 -07001695 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001696 mContext = context;
1697 mInv = inv;
1698 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001699 }
1700
1701 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1702 mIsMultiWindowMode = isMultiWindowMode;
1703 return this;
1704 }
1705
Sunny Goyal19ff7282021-04-22 10:12:54 -07001706 public Builder setUseTwoPanels(boolean useTwoPanels) {
1707 mUseTwoPanels = useTwoPanels;
1708 return this;
1709 }
1710
Sunny Goyal65190ae2022-08-02 14:16:26 -07001711 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
1712 mDotRendererCache = dotRendererCache;
1713 return this;
1714 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07001715
1716 public Builder setWindowBounds(WindowBounds bounds) {
1717 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07001718 return this;
1719 }
1720
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001721 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1722 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1723 return this;
1724 }
1725
Alex Chau6ed408f2022-03-04 12:58:05 +00001726 public Builder setGestureMode(boolean isGestureMode) {
1727 mIsGestureMode = isGestureMode;
1728 return this;
1729 }
1730
Sihua Mae04aa202022-07-18 12:43:56 -07001731 /**
1732 * Set the viewScaleProvider for the builder
1733 *
1734 * @param viewScaleProvider The viewScaleProvider to be set for the
1735 * DeviceProfile
1736 * @return This builder
1737 */
1738 @NonNull
1739 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
1740 mViewScaleProvider = viewScaleProvider;
1741 return this;
1742 }
1743
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001744 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001745 if (mWindowBounds == null) {
1746 throw new IllegalArgumentException("Window bounds not set");
1747 }
1748 if (mTransposeLayoutWithOrientation == null) {
1749 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
1750 }
Alex Chau6ed408f2022-03-04 12:58:05 +00001751 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01001752 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00001753 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001754 if (mDotRendererCache == null) {
1755 mDotRendererCache = new SparseArray<>();
1756 }
Sihua Mae04aa202022-07-18 12:43:56 -07001757 if (mViewScaleProvider == null) {
1758 mViewScaleProvider = DEFAULT_PROVIDER;
1759 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001760 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
1761 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mUseTwoPanels,
Sihua Mae04aa202022-07-18 12:43:56 -07001762 mIsGestureMode, mViewScaleProvider);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001763 }
1764 }
1765
Winson Chungb3800242013-10-24 11:01:54 -07001766}