blob: 7cefef9eaf9f8da3418128ecebb30dbf461ada86 [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;
Jon Miranda92c1b5d2021-07-20 13:57:16 -070025import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.ICON_OVERLAP_FACTOR;
Sunny Goyal65190ae2022-08-02 14:16:26 -070026import static com.android.launcher3.icons.GraphicsUtils.getShapePath;
Pat Manning5f74bfd2022-07-20 12:08:54 +010027import static com.android.launcher3.testing.shared.ResourceUtils.pxFromDp;
Jon Miranda228877d2021-02-09 11:05:00 -050028
Sunny Goyal35c7b192021-04-20 16:51:10 -070029import android.annotation.SuppressLint;
Winson Chungb3800242013-10-24 11:01:54 -070030import android.content.Context;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070031import android.content.res.Configuration;
Winson Chungb3800242013-10-24 11:01:54 -070032import android.content.res.Resources;
Winson Chungb3800242013-10-24 11:01:54 -070033import android.graphics.Point;
Jon Miranda7ae64ff2016-11-21 16:18:46 -080034import android.graphics.PointF;
Winson Chungb3800242013-10-24 11:01:54 -070035import android.graphics.Rect;
Sunny Goyal35c7b192021-04-20 16:51:10 -070036import android.util.DisplayMetrics;
Sunny Goyal65190ae2022-08-02 14:16:26 -070037import android.util.SparseArray;
Sunny Goyal59d086c2018-05-07 17:31:40 -070038import android.view.Surface;
Winson Chungb3800242013-10-24 11:01:54 -070039
Sunny Goyal65190ae2022-08-02 14:16:26 -070040import androidx.annotation.NonNull;
41
Sunny Goyalc13403c2016-11-18 23:44:48 -080042import com.android.launcher3.CellLayout.ContainerType;
Jon Miranda228877d2021-02-09 11:05:00 -050043import com.android.launcher3.DevicePaddings.DevicePadding;
Tony Wickham8912b042018-11-29 15:28:53 -080044import com.android.launcher3.icons.DotRenderer;
Hyunyoung Song48cb7bc2018-09-25 17:03:34 -070045import com.android.launcher3.icons.IconNormalizer;
Sunny Goyal57b22792021-05-25 14:35:01 -070046import com.android.launcher3.uioverrides.ApiWrapper;
Sunny Goyalfd58da62020-08-11 12:06:49 -070047import com.android.launcher3.util.DisplayController;
48import com.android.launcher3.util.DisplayController.Info;
Sunny Goyalb46703d2020-05-27 17:52:03 -070049import com.android.launcher3.util.WindowBounds;
Winson1f064272016-07-18 17:18:02 -070050
Jon Miranda58561d42021-03-17 10:51:54 -040051import java.io.PrintWriter;
Brian Isganitis099945b2022-01-31 18:15:00 -050052import java.util.List;
Jon Miranda58561d42021-03-17 10:51:54 -040053
Sunny Goyal35c7b192021-04-20 16:51:10 -070054@SuppressLint("NewApi")
Winson Chungb3800242013-10-24 11:01:54 -070055public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070056
Sunny Goyal8b9919d2021-04-07 14:45:17 -070057 private static final int DEFAULT_DOT_SIZE = 100;
Alex Chau206ede92022-08-01 17:46:12 +010058 private static final float ALL_APPS_TABLET_MAX_ROWS = 5.5f;
59
Sunny Goyal57b22792021-05-25 14:35:01 -070060 // Ratio of empty space, qsb should take up to appear visually centered.
Pratyush9afe1ea2021-10-13 11:13:27 +000061 private final float mQsbCenterFactor;
Sunny Goyal1890f672020-04-30 12:28:00 -070062
Adam Cohen2e6da152015-05-06 11:42:25 -070063 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070064 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070065 private final DisplayMetrics mMetrics;
Winson Chungbe876472014-05-14 14:15:20 -070066
Sunny Goyalc6205602015-05-21 20:46:33 -070067 // Device properties
68 public final boolean isTablet;
Sunny Goyalc6205602015-05-21 20:46:33 -070069 public final boolean isPhone;
70 public final boolean transposeLayoutWithOrientation;
Sunny Goyal19ff7282021-04-22 10:12:54 -070071 public final boolean isTwoPanels;
Thales Limaa1012902022-01-13 17:58:42 +000072 public final boolean isQsbInline;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -070073
Sunny Goyalc6205602015-05-21 20:46:33 -070074 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -070075 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -080076 public final boolean isMultiWindowMode;
Alex Chau6ed408f2022-03-04 12:58:05 +000077 public final boolean isGestureMode;
Sunny Goyald70e75a2018-02-22 10:07:32 -080078
Sunny Goyal0addbf02020-04-28 14:17:35 -070079 public final int windowX;
80 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -070081 public final int widthPx;
82 public final int heightPx;
83 public final int availableWidthPx;
84 public final int availableHeightPx;
Sunny Goyal187b16c2022-03-01 16:53:23 -080085 public final int rotationHint;
Jon Mirandabba64512019-03-27 10:54:17 -070086
87 public final float aspectRatio;
88
Jon Mirandae126d722021-02-25 10:45:20 -050089 public final boolean isScalableGrid;
Thales Lima83bedbf2021-10-05 17:47:39 +010090 private final int mTypeIndex;
Jon Mirandae126d722021-02-25 10:45:20 -050091
Tony Wickhamd6b40372015-09-23 18:37:57 -070092 /**
93 * The maximum amount of left/right workspace padding as a percentage of the screen width.
94 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
95 * 7% of the screen width can be used as right padding.
96 */
97 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -070098
Jon Miranda3f9bab22017-07-28 14:50:17 -070099 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700100 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda80dda302021-07-28 14:14:59 -0700101 private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252;
102 private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700103
Sunny Goyalc6205602015-05-21 20:46:33 -0700104 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +0100105 public final int desiredWorkspaceHorizontalMarginOriginalPx;
106 public int desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100107 public int gridVisualizationPaddingX;
108 public int gridVisualizationPaddingY;
Thales Lima78d00ad2021-09-30 11:29:06 +0100109 public Point cellLayoutBorderSpaceOriginalPx;
110 public Point cellLayoutBorderSpacePx;
Pat Manning08610ca2022-04-05 21:03:16 +0100111 public Rect cellLayoutPaddingPx = new Rect();
112
Sunny Goyalc6205602015-05-21 20:46:33 -0700113 public final int edgeMarginPx;
Alex Chau0c4e11b2022-07-08 18:41:36 +0100114 public final float workspaceContentScale;
Alex Chau906d8822022-05-23 10:42:25 +0100115 public final int workspaceSpringLoadedMinNextPageVisiblePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700116
Jon Miranda58561d42021-03-17 10:51:54 -0400117 private final int extraSpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500118 public int workspaceTopPadding;
119 public int workspaceBottomPadding;
120
Tony Wickham5edf9e22020-03-27 20:06:52 -0700121 // Workspace page indicator
122 public final int workspacePageIndicatorHeight;
123 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700124
Sunny Goyalc6205602015-05-21 20:46:33 -0700125 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400126 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700127 public int iconSizePx;
128 public int iconTextSizePx;
129 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700130 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -0700131
Jon Mirandaab3c6812021-06-28 15:42:28 -0700132 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800133 public int cellWidthPx;
134 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700135 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800136
Jon Mirandae126d722021-02-25 10:45:20 -0500137 public int cellYPaddingPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500138
Sunny Goyalc6205602015-05-21 20:46:33 -0700139 // Folder
Jon Mirandae126d722021-02-25 10:45:20 -0500140 public float folderLabelTextScale;
141 public int folderLabelTextSizePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700142 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700143 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700144
Jon Mirandae126d722021-02-25 10:45:20 -0500145 // Folder content
Thales Lima78d00ad2021-09-30 11:29:06 +0100146 public Point folderCellLayoutBorderSpacePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500147 public int folderContentPaddingLeftRight;
148 public int folderContentPaddingTop;
149
Jon Mirandabf7d8122016-11-03 15:29:29 -0700150 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700151 public int folderCellWidthPx;
152 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700153
154 // Folder child
155 public int folderChildIconSizePx;
156 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700157 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700158
Sunny Goyalc6205602015-05-21 20:46:33 -0700159 // Hotseat
Thales Lima9938c2f2022-07-25 14:38:16 +0100160 public int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700161 public int hotseatCellHeightPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100162 public final boolean areNavButtonsInline;
Jon Miranda18751b62017-07-31 17:25:27 -0700163 // In portrait: size = height, in landscape: size = width
164 public int hotseatBarSizePx;
Thales Limab8c05952022-05-23 16:58:38 +0100165 public int hotseatBarBottomSpacePx;
Pat Manning26f70f72022-07-07 13:50:39 +0100166 public int hotseatBarEndOffset;
Thales Limab8c05952022-05-23 16:58:38 +0100167 public int hotseatQsbSpace;
Pat Manningde25c0d2022-04-05 19:11:26 +0100168 public int springLoadedHotseatBarTopMarginPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700169 // Start is the side next to the nav bar, end is the side next to the workspace
170 public final int hotseatBarSidePaddingStartPx;
171 public final int hotseatBarSidePaddingEndPx;
Alex Chau206ede92022-08-01 17:46:12 +0100172 public int hotseatQsbWidth; // only used when isQsbInline
Sunny Goyal57b22792021-05-25 14:35:01 -0700173 public final int hotseatQsbHeight;
Thales Limab8c05952022-05-23 16:58:38 +0100174 public final int hotseatQsbVisualHeight;
175 private final int hotseatQsbShadowHeight;
Thales Limadd027342022-01-07 12:54:37 +0000176 public int hotseatBorderSpace;
Adam Cohen2e6da152015-05-06 11:42:25 -0700177
Sunny Goyalc6205602015-05-21 20:46:33 -0700178 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000179 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000180 public int allAppsShiftRange;
181 public int allAppsTopPadding;
Andras Kloczl142b0542022-03-09 21:26:02 +0000182 public int bottomSheetTopPadding;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700183 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700184 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700185 public int allAppsIconSizePx;
186 public int allAppsIconDrawablePaddingPx;
sfufa@google.comde013292021-09-21 18:22:44 -0700187 public int allAppsLeftRightPadding;
Alex Chau27b39b92022-01-14 18:02:18 +0000188 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700189 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700190 public float allAppsIconTextSizePx;
191
Zak Cohen334efeb2021-03-19 16:42:07 -0700192 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700193 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000194 public int overviewTaskIconSizePx;
Alex Chauac9df382021-08-02 19:08:41 +0100195 public int overviewTaskIconDrawableSizePx;
196 public int overviewTaskIconDrawableSizeGridPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000197 public int overviewTaskThumbnailTopMarginPx;
Alex Chau19c6eca2022-03-10 20:12:56 +0000198 public final int overviewActionsHeight;
Alex Chaua2fc7642022-04-21 14:20:23 +0100199 public final int overviewActionsTopMarginPx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000200 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100201 public int overviewPageSpacing;
202 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000203 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700204
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800205 // Widgets
206 public final PointF appWidgetScale = new PointF(1.0f, 1.0f);
207
Sunny Goyal47328fd2016-05-25 18:56:41 -0700208 // Drop Target
209 public int dropTargetBarSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100210 public int dropTargetBarTopMarginPx;
211 public int dropTargetBarBottomMarginPx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100212 public int dropTargetDragPaddingPx;
213 public int dropTargetTextSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100214 public int dropTargetHorizontalPaddingPx;
215 public int dropTargetVerticalPaddingPx;
216 public int dropTargetGapPx;
Alex Chau5b019302022-05-23 10:42:25 +0100217 public int dropTargetButtonWorkspaceEdgeGapPx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700218
Winson1f064272016-07-18 17:18:02 -0700219 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800220 private final Rect mInsets = new Rect();
221 public final Rect workspacePadding = new Rect();
Jon Miranda0bd63d12019-03-06 17:29:29 -0800222 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700223 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700224
Tony Wickhamf34bee82018-12-03 18:11:39 -0800225 // Notification dots
Sunny Goyal65190ae2022-08-02 14:16:26 -0700226 public final DotRenderer mDotRendererWorkSpace;
227 public final DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800228
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100229 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800230 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000231 // Whether Taskbar will inset the bottom of apps by taskbarSize.
232 public boolean isTaskbarPresentInApps;
Tony Wickham15883892021-02-12 11:24:40 -0800233 public int taskbarSize;
Alex Chau6a7d1e22022-01-20 19:54:17 +0000234 public int stashedTaskbarSize;
Tony Wickham15883892021-02-12 11:24:40 -0800235
Alex Chaua02eddc2021-04-29 00:36:06 +0100236 // DragController
237 public int flingToDeleteThresholdVelocity;
238
Vinit Nayak17c4b332021-08-05 12:54:58 -0700239 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700240 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal65190ae2022-08-02 14:16:26 -0700241 SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
242 boolean transposeLayoutWithOrientation, boolean useTwoPanels, boolean isGestureMode) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700243
Adam Cohen2e6da152015-05-06 11:42:25 -0700244 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700245 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800246 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500247 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +0000248 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700249 windowX = windowBounds.bounds.left;
250 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800251 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100252 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700253
Jon Mirandae126d722021-02-25 10:45:20 -0500254 isScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000255 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700256 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000257 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700258 isPhone = !isTablet;
Alex Chau90125822021-11-17 14:16:58 +0000259 isTwoPanels = isTablet && useTwoPanels;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800260 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700261
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000262 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000263 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700264 ? Configuration.ORIENTATION_LANDSCAPE
265 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000266 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700267 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000268 mMetrics = res.getDisplayMetrics();
269
270 // Determine sizes.
271 widthPx = windowBounds.bounds.width();
272 heightPx = windowBounds.bounds.height();
273 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100274 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000275
276 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
277 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
278 mQsbCenterFactor = res.getFloat(R.dimen.qsb_center_factor);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700279
Thales Lima83bedbf2021-10-05 17:47:39 +0100280 if (isTwoPanels) {
281 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000282 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100283 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000284 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100285 }
286 } else {
287 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000288 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100289 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000290 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100291 }
292 }
293
Tony Wickham15883892021-02-12 11:24:40 -0800294 if (isTaskbarPresent) {
Tony Wickham15883892021-02-12 11:24:40 -0800295 taskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_size);
Alex Chau6a7d1e22022-01-20 19:54:17 +0000296 stashedTaskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
Tony Wickham15883892021-02-12 11:24:40 -0800297 }
Tony Wickham15883892021-02-12 11:24:40 -0800298
Winson Chungb3800242013-10-24 11:01:54 -0700299 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100300 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700301
Thales Limad90faab2021-09-21 17:18:47 +0100302 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
303 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100304 gridVisualizationPaddingX = res.getDimensionPixelSize(
305 R.dimen.grid_visualization_horizontal_cell_spacing);
306 gridVisualizationPaddingY = res.getDimensionPixelSize(
307 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500308
Alex Chaue0227552022-04-06 19:44:43 +0100309 bottomSheetTopPadding = mInsets.top // statusbar height
Andras Kloczl142b0542022-03-09 21:26:02 +0000310 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
311 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
312
Jon Mirandae126d722021-02-25 10:45:20 -0500313 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
314 folderContentPaddingLeftRight =
315 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
316 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_content_padding_top);
317
Thales Lima78d00ad2021-09-30 11:29:06 +0100318 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv);
Thales Lima85c942f2021-12-31 13:04:20 +0000319 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000320 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
321 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Thales Lima78d00ad2021-09-30 11:29:06 +0100322 cellLayoutBorderSpaceOriginalPx = new Point(cellLayoutBorderSpacePx);
Thales Limaa08a4432022-08-09 09:55:17 +0100323 folderCellLayoutBorderSpacePx = new Point(pxFromDp(inv.folderBorderSpaces.x, mMetrics),
324 pxFromDp(inv.folderBorderSpaces.y, mMetrics));
Jon Mirandae126d722021-02-25 10:45:20 -0500325
Tony Wickham5edf9e22020-03-27 20:06:52 -0700326 workspacePageIndicatorHeight = res.getDimensionPixelSize(
327 R.dimen.workspace_page_indicator_height);
328 mWorkspacePageIndicatorOverlapWorkspace =
329 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700330
Winson Chungb3800242013-10-24 11:01:54 -0700331 iconDrawablePaddingOriginalPx =
332 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Alex Chaua02eddc2021-04-29 00:36:06 +0100333
Sunny Goyal47328fd2016-05-25 18:56:41 -0700334 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100335 dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
336 dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100337 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
338 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100339 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
340 R.dimen.drop_target_button_drawable_horizontal_padding);
341 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
342 R.dimen.drop_target_button_drawable_vertical_padding);
343 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100344 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
345 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100346
Alex Chau906d8822022-05-23 10:42:25 +0100347 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
348 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700349
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700350 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700351
Thales Limaa1012902022-01-13 17:58:42 +0000352 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100353 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
354 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
355
Thales Lima12d0eff2022-03-25 17:06:11 +0000356 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
357 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
358 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
359 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
360 && hotseatQsbHeight > 0;
361 isQsbInline = inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000362
Thales Lima425f6822022-05-10 13:44:58 -0300363 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100364 numShownHotseatIcons =
365 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000366
Sunny Goyal19ff7282021-04-22 10:12:54 -0700367 numShownAllAppsColumns =
368 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100369
370 int hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
371 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
372 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
373 // Have a little space between the inset and the QSB
374 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
375 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
376
377 // Only change the spaces if there is space
378 if (availableSpace > 0) {
379 // Make sure there is enough space between hotseat/QSB and QSB/navBar
380 if (availableSpace < minQsbMargin * 2) {
381 minQsbMargin = availableSpace / 2;
382 hotseatQsbSpace = minQsbMargin;
383 } else {
384 hotseatQsbSpace -= minQsbMargin;
385 }
386 }
387 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
388
Thales Limaa1012902022-01-13 17:58:42 +0000389 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100390 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
Thales Limaa1012902022-01-13 17:58:42 +0000391 }
Thales Lima425f6822022-05-10 13:44:58 -0300392
Pat Manningde25c0d2022-04-05 19:11:26 +0100393 springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
394 R.dimen.spring_loaded_hotseat_top_margin);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700395 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800396 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700397 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700398 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Thales Limab8c05952022-05-23 16:58:38 +0100399 updateHotseatSizes(pxFromDp(inv.iconSize[INDEX_DEFAULT], mMetrics));
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700400 if (areNavButtonsInline && !isPhone) {
Pat Manning26f70f72022-07-07 13:50:39 +0100401 /*
402 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700403 * Spacing between nav buttons +
Pat Manning26f70f72022-07-07 13:50:39 +0100404 * Little space at the end for contextual buttons +
405 * Little space between icons and nav buttons
406 */
407 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700408 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
409 + res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing)
Pat Manning26f70f72022-07-07 13:50:39 +0100410 + res.getDimensionPixelSize(R.dimen.taskbar_hotseat_nav_spacing);
411 } else {
412 hotseatBarEndOffset = 0;
413 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700414
Alex Chau635b3ab2022-01-26 16:49:10 +0000415 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chau5fd9d492021-07-22 17:27:11 +0100416 overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100417 overviewTaskIconDrawableSizePx =
418 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
419 overviewTaskIconDrawableSizeGridPx =
420 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700421 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx;
Jeremy Sim3c2c3f12022-05-16 20:37:43 -0700422 overviewActionsTopMarginPx = res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000423 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
424 overviewActionsButtonSpacing = res.getDimensionPixelSize(
425 R.dimen.overview_actions_button_spacing);
Alex Chau19c6eca2022-03-10 20:12:56 +0000426 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700427 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000428 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700429
Jon Miranda2ed276e2017-06-29 11:36:34 -0700430 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400431 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700432
Jon Miranda2ed276e2017-06-29 11:36:34 -0700433 // Now that we have all of the variables calculated, we can tune certain sizes.
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400434 if (isScalableGrid && inv.devicePaddings != null) {
435 // Paddings were created assuming no scaling, so we first unscale the extra space.
Jon Mirandaab3c6812021-06-28 15:42:28 -0700436 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400437 DevicePadding padding = inv.devicePaddings.getDevicePadding(unscaledExtraSpace);
Jon Miranda228877d2021-02-09 11:05:00 -0500438
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400439 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
440 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
441 int paddingHotseatBottom = padding.getHotseatBottomPadding(unscaledExtraSpace);
442
Jon Mirandaab3c6812021-06-28 15:42:28 -0700443 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
444 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700445 }
Pat Manning08610ca2022-04-05 21:03:16 +0100446
447 int cellLayoutPadding =
448 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
449 R.dimen.cell_layout_padding);
450 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
451 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800452 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800453
Thales Lima425f6822022-05-10 13:44:58 -0300454 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima9938c2f2022-07-25 14:38:16 +0100455 recalculateHotseatWidthAndBorderSpace(res);
Alex Chau206ede92022-08-01 17:46:12 +0100456
457 // AllApps height calculation depends on updated cellSize
458 if (isTablet) {
459 int collapseHandleHeight =
460 res.getDimensionPixelOffset(R.dimen.bottom_sheet_handle_area_height);
461 int contentHeight = heightPx - collapseHandleHeight - hotseatQsbHeight;
462 int targetContentHeight = (int) (allAppsCellHeightPx * ALL_APPS_TABLET_MAX_ROWS);
463 allAppsTopPadding = Math.max(mInsets.top, contentHeight - targetContentHeight);
464 allAppsShiftRange = heightPx - allAppsTopPadding;
465 } else {
466 allAppsTopPadding = 0;
467 allAppsShiftRange =
468 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
469 }
Thales Lima425f6822022-05-10 13:44:58 -0300470
Alex Chaua02eddc2021-04-29 00:36:06 +0100471 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
472 R.dimen.drag_flingToDeleteMinVelocity);
473
Tony Wickham1237df02017-02-24 08:59:36 -0800474 // This is done last, after iconSizePx is calculated above.
Sunny Goyal65190ae2022-08-02 14:16:26 -0700475 mDotRendererWorkSpace = createDotRenderer(iconSizePx, dotRendererCache);
476 mDotRendererAllApps = createDotRenderer(allAppsIconSizePx, dotRendererCache);
477 }
478
479 private static DotRenderer createDotRenderer(
480 int size, @NonNull SparseArray<DotRenderer> cache) {
481 DotRenderer renderer = cache.get(size);
482 if (renderer == null) {
483 renderer = new DotRenderer(size, getShapePath(DEFAULT_DOT_SIZE), DEFAULT_DOT_SIZE);
484 cache.put(size, renderer);
485 }
486 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700487 }
488
Thales Lima425f6822022-05-10 13:44:58 -0300489 /**
490 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
491 * width of the hotseat.
492 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100493 private int calculateQsbWidth(int hotseatBorderSpace) {
Thales Lima425f6822022-05-10 13:44:58 -0300494 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100495 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300496 return getIconToIconWidthForColumns(columns)
497 - iconSizePx * numShownHotseatIcons
498 - hotseatBorderSpace * numShownHotseatIcons;
499 } else {
500 int columns = inv.hotseatColumnSpan[mTypeIndex];
501 return getIconToIconWidthForColumns(columns);
502 }
503 }
Thales Lima2903a622022-03-17 13:52:19 +0000504
Thales Lima425f6822022-05-10 13:44:58 -0300505 private int getIconToIconWidthForColumns(int columns) {
506 return columns * getCellSize().x
507 + (columns - 1) * cellLayoutBorderSpacePx.x
508 - (getCellSize().x - iconSizePx); // left and right cell space
Thales Limaa1012902022-01-13 17:58:42 +0000509 }
510
Thales Limad90faab2021-09-21 17:18:47 +0100511 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
512 if (isVerticalBarLayout()) {
513 return 0;
514 }
515
Thales Lima83bedbf2021-10-05 17:47:39 +0100516 return isScalableGrid
517 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
518 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100519 }
520
Thales Limab8c05952022-05-23 16:58:38 +0100521 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
522 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700523 // Ensure there is enough space for folder icons, which have a slightly larger radius.
524 hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR);
Thales Limab8c05952022-05-23 16:58:38 +0100525
Jon Miranda0d284852021-06-22 14:50:55 -0700526 if (isVerticalBarLayout()) {
527 hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
528 + hotseatBarSidePaddingEndPx;
Thales Limab8c05952022-05-23 16:58:38 +0100529 } else if (isQsbInline) {
530 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
531 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700532 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100533 hotseatBarSizePx = hotseatIconSizePx
534 + hotseatQsbSpace
535 + hotseatQsbVisualHeight
536 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700537 }
538 }
539
Thales Lima9938c2f2022-07-25 14:38:16 +0100540 private void recalculateHotseatWidthAndBorderSpace(Resources res) {
541 hotseatBorderSpace = calculateHotseatBorderSpace();
542 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
543 // Spaces should be correct when there nav buttons are not inline
544 if (!areNavButtonsInline) {
545 return;
546 }
547
548 // Get the maximum width that the hotseat can be
549 int columns = getPanelCount() * inv.numColumns;
550 int maxHotseatWidth = getIconToIconWidthForColumns(columns);
551 int sideSpace = (availableWidthPx - maxHotseatWidth) / 2;
552 int inlineButtonsOverlap = Math.max(0, hotseatBarEndOffset - sideSpace);
553 // decrease how much the nav buttons go "inside" the hotseat
554 maxHotseatWidth -= inlineButtonsOverlap;
555
556 // Get how much space is required to show the hotseat with QSB
557 int requiredWidth = getHotseatRequiredWidth();
558
559 // If spaces are fine, use them
560 if (requiredWidth <= maxHotseatWidth) {
561 return;
562 }
563
564 // Calculate the difference of widths and remove a little from each space between icons
565 // and QSB if it's inline
566 int spaceDiff = requiredWidth - maxHotseatWidth;
567 int numOfSpaces = numShownHotseatIcons - (isQsbInline ? 0 : 1);
568 hotseatBorderSpace -= (spaceDiff / numOfSpaces);
569
570 int minHotseatIconSpaceDp = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
571 int minHotseatQsbWidthDp = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
572
573 if (hotseatBorderSpace >= minHotseatIconSpaceDp) {
574 return;
575 }
576
577 // Border space can't be less than the minimum
578 hotseatBorderSpace = minHotseatIconSpaceDp;
579 requiredWidth = getHotseatRequiredWidth();
580
581 // If there is an inline qsb, change its size
582 if (isQsbInline) {
583 hotseatQsbWidth -= requiredWidth - maxHotseatWidth;
584 if (hotseatQsbWidth >= minHotseatQsbWidthDp) {
585 return;
586 }
587
588 // QSB can't be less than the minimum
589 hotseatQsbWidth = minHotseatQsbWidthDp;
590 }
591
592 // If it still doesn't fit, start removing icons
593 do {
594 numShownHotseatIcons--;
595 requiredWidth = getHotseatRequiredWidth();
596 } while (requiredWidth > maxHotseatWidth && numShownHotseatIcons > 1);
597
598 // Add back some space between the icons
599 spaceDiff = maxHotseatWidth - requiredWidth;
600 numOfSpaces = numShownHotseatIcons - (isQsbInline ? 0 : 1);
601 hotseatBorderSpace += (spaceDiff / numOfSpaces);
602 }
603
Thales Lima78d00ad2021-09-30 11:29:06 +0100604 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100605 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100606 }
607
608 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100609 if (!isScalableGrid) {
610 return new Point(0, 0);
611 }
612
Thales Lima080d8902022-03-28 15:30:29 +0100613 int horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
614 int verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
Thales Lima78d00ad2021-09-30 11:29:06 +0100615
616 return new Point(horizontalSpacePx, verticalSpacePx);
617 }
618
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700619 public Info getDisplayInfo() {
620 return mInfo;
621 }
622
Jon Miranda611dba42021-03-02 14:12:13 -0500623 /**
624 * We inset the widget padding added by the system and instead rely on the border spacing
625 * between cells to create reliable consistency between widgets
626 */
627 public boolean shouldInsetWidgets() {
628 Rect widgetPadding = inv.defaultWidgetPadding;
629
Jon Miranda49811182021-06-03 09:52:40 -0700630 // Check all sides to ensure that the widget won't overlap into another cell, or into
631 // status bar.
632 return workspaceTopPadding > widgetPadding.top
Thales Lima78d00ad2021-09-30 11:29:06 +0100633 && cellLayoutBorderSpacePx.x > widgetPadding.left
634 && cellLayoutBorderSpacePx.y > widgetPadding.top
635 && cellLayoutBorderSpacePx.x > widgetPadding.right
636 && cellLayoutBorderSpacePx.y > widgetPadding.bottom;
Jon Miranda611dba42021-03-02 14:12:13 -0500637 }
Jon Mirandae126d722021-02-25 10:45:20 -0500638
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700639 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800640 WindowBounds bounds = new WindowBounds(
641 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700642 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100643 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700644
645 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
646 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
647 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
648
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700649 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700650 .setWindowBounds(bounds)
651 .setUseTwoPanels(isTwoPanels)
Alex Chau6ed408f2022-03-04 12:58:05 +0000652 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700653 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000654 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800655 }
656
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700657 public DeviceProfile copy(Context context) {
658 return toBuilder(context).build();
659 }
660
661 /**
662 * TODO: Move this to the builder as part of setMultiWindowMode
663 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700664 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700665 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700666 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700667 .setMultiWindowMode(true)
668 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800669
Jon Miranda941375e2021-03-31 13:10:45 -0400670 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda93e1f042016-11-11 14:13:04 -0800671
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800672 // We use these scales to measure and layout the widgets using their full invariant profile
673 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
674 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
675 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
676 profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY);
677
Jon Miranda93e1f042016-11-11 14:13:04 -0800678 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700679 }
680
Adam Cohen63f1ec02014-08-12 09:23:13 -0700681 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400682 * Checks if there is enough space for labels on the workspace.
683 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700684 * It is important to call this method after the All Apps variables have been set.
685 */
Jon Miranda941375e2021-03-31 13:10:45 -0400686 private void hideWorkspaceLabelsIfNotEnoughSpace() {
687 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
688 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
689 - iconTextHeight;
690
691 // We want enough space so that the text is closer to its corresponding icon.
692 if (workspaceCellPaddingY < iconTextHeight) {
693 iconTextSizePx = 0;
694 iconDrawablePaddingPx = 0;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700695 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda941375e2021-03-31 13:10:45 -0400696 autoResizeAllAppsCells();
697 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700698 }
Jon Miranda1091e532017-07-21 13:31:50 -0700699
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700700 /**
701 * Re-computes the all-apps cell size to be independent of workspace
702 */
703 public void autoResizeAllAppsCells() {
Jon Miranda941375e2021-03-31 13:10:45 -0400704 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
705 int topBottomPadding = textHeight;
Jon Miranda1091e532017-07-21 13:31:50 -0700706 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
Jon Miranda941375e2021-03-31 13:10:45 -0400707 + textHeight + (topBottomPadding * 2);
Jon Miranda1091e532017-07-21 13:31:50 -0700708 }
709
Thales Limab7ef5692022-03-10 10:32:36 +0000710 private void updateAllAppsContainerWidth(Resources res) {
Pat Manning08610ca2022-04-05 21:03:16 +0100711 int cellLayoutHorizontalPadding =
712 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
Alex Chau27b39b92022-01-14 18:02:18 +0000713 if (isTablet) {
Thales Limab7ef5692022-03-10 10:32:36 +0000714 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100715 res.getDimensionPixelSize(R.dimen.all_apps_bottom_sheet_horizontal_padding);
716
sfufa@google.comde013292021-09-21 18:22:44 -0700717 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
Thales Limab7ef5692022-03-10 10:32:36 +0000718 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Alex Chau27b39b92022-01-14 18:02:18 +0000719 + allAppsLeftRightPadding * 2;
720 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
sfufa@google.comde013292021-09-21 18:22:44 -0700721 } else {
722 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100723 desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding;
sfufa@google.comde013292021-09-21 18:22:44 -0700724 }
725 }
726
Jon Miranda228877d2021-02-09 11:05:00 -0500727 /**
728 * Returns the amount of extra (or unused) vertical space.
729 */
730 private int updateAvailableDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700731 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800732
Pat Manning08610ca2022-04-05 21:03:16 +0100733 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -0500734
735 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +0100736 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +0000737 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -0500738 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500739 float scaleY = maxHeight / usedHeight;
740 boolean shouldScale = scaleY < 1f;
741
742 float scaleX = 1f;
743 if (isScalableGrid) {
744 // We scale to fit the cellWidth and cellHeight in the available space.
745 // The benefit of scalable grids is that we can get consistent aspect ratios between
746 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +0100747 float usedWidth =
748 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500749 // We do not subtract padding here, as we also scale the workspace padding if needed.
750 scaleX = availableWidthPx / usedWidth;
751 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700752 }
Jon Mirandae126d722021-02-25 10:45:20 -0500753
754 if (shouldScale) {
755 float scale = Math.min(scaleX, scaleY);
756 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +0100757 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -0500758 }
759
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700760 updateAvailableFolderCellDimensions(res);
Jon Miranda228877d2021-02-09 11:05:00 -0500761 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700762 }
763
Pat Manninga2e14992022-04-22 11:29:17 +0100764 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +0100765 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
766 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
767 }
768
Pat Manninga2e14992022-04-22 11:29:17 +0100769 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +0000770 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +0100771 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
772 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -0500773 }
774
Jon Miranda6f7e9702019-09-16 14:44:14 -0700775 /**
776 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
777 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
778 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
779 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800780 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -0700781 // Icon scale should never exceed 1, otherwise pixellation may occur.
782 iconScale = Math.min(1f, scale);
783 cellScaleToFit = scale;
784
Jon Miranda18751b62017-07-31 17:25:27 -0700785 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800786 final boolean isVerticalLayout = isVerticalBarLayout();
Thales Lima83bedbf2021-10-05 17:47:39 +0100787 float invIconSizeDp = inv.iconSize[mTypeIndex];
788 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
Andras Kloczl30fe9152021-08-05 18:02:29 +0200789
Jon Mirandaab3c6812021-06-28 15:42:28 -0700790 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, iconScale));
Jon Mirandaab3c6812021-06-28 15:42:28 -0700791 iconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * iconScale);
792 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700793
Thales Lima080d8902022-03-28 15:30:29 +0100794 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500795
796 if (isScalableGrid) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100797 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
798 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500799 int cellContentHeight = iconSizePx + iconDrawablePaddingPx
800 + Utilities.calculateTextHeight(iconTextSizePx);
801 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +0100802 desiredWorkspaceHorizontalMarginPx =
803 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -0500804 } else {
Jon Mirandae126d722021-02-25 10:45:20 -0500805 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700806 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR)
807 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -0500808 + Utilities.calculateTextHeight(iconTextSizePx);
809 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
810 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
811 && !isMultiWindowMode) {
812 // Ensures that the label is closer to its corresponding icon. This is not an issue
813 // with vertical bar layout or multi-window mode since the issue is handled
814 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
815 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
816 iconDrawablePaddingPx = cellPaddingY;
817 }
Jon Miranda846455e2017-10-02 14:58:52 -0700818 }
Jon Miranda18751b62017-07-31 17:25:27 -0700819
Sunny Goyalae190ff2020-04-14 00:19:01 +0000820 // All apps
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500821 updateAllAppsIconSize(scale, res);
Winson Chungb3800242013-10-24 11:01:54 -0700822
Thales Limab8c05952022-05-23 16:58:38 +0100823 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700824
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700825 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -0700826 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
827 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Winson Chung0f785722015-04-08 10:27:49 -0700828 }
829
Thales Lima425f6822022-05-10 13:44:58 -0300830 /**
831 * Hotseat width spans a certain number of columns on scalable grids.
832 * This method calculates the space between the icons to achieve that width.
833 */
834 private int calculateHotseatBorderSpace() {
835 if (!isScalableGrid) return 0;
Thales Lima9938c2f2022-07-25 14:38:16 +0100836 int columns = inv.hotseatColumnSpan[mTypeIndex];
837 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
838 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
839 return (int) (hotseatWidthPx - hotseatIconsTotalPx) / (numShownHotseatIcons - 1);
Thales Lima425f6822022-05-10 13:44:58 -0300840 }
841
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500842
843 /**
844 * Updates the iconSize for allApps* variants.
845 */
Brian Isganitisa9a78112022-05-23 18:11:47 -0700846 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +0100847 allAppsBorderSpacePx = new Point(
848 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
849 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700850 // AllApps cells don't have real space between cells,
851 // so we add the border space to the cell height
852 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics, scale)
853 + allAppsBorderSpacePx.y;
854 // but width is just the cell,
855 // the border is added in #updateAllAppsContainerWidth
Thales Lima080d8902022-03-28 15:30:29 +0100856 if (isScalableGrid) {
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500857 allAppsIconSizePx =
Brandon Dayauon969f6a82022-05-19 09:46:47 -0700858 pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics, scale);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500859 allAppsIconTextSizePx =
Brandon Dayauon969f6a82022-05-19 09:46:47 -0700860 pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics, scale);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500861 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -0700862 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500863 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700864 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
865 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500866 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
867 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700868 allAppsIconDrawablePaddingPx =
869 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -0700870 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500871 }
872
Thales Limab7ef5692022-03-10 10:32:36 +0000873 updateAllAppsContainerWidth(res);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500874 if (isVerticalBarLayout()) {
875 hideWorkspaceLabelsIfNotEnoughSpace();
876 }
877 }
878
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700879 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700880 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700881
Jon Mirandae126d722021-02-25 10:45:20 -0500882 final int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_height);
883
Jon Mirandac1b23992016-12-13 08:57:36 -0800884 // Don't let the folder get too close to the edges of the screen.
Jon Miranda1786df32018-09-25 13:05:23 -0700885 int folderMargin = edgeMarginPx * 2;
Sunny Goyal07b69292018-01-08 14:19:34 -0800886 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -0800887
888 // Check if the icons fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -0500889 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Thales Lima78d00ad2021-09-30 11:29:06 +0100890 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx.y);
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800891 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderBottomPanelSize
Jon Mirandae126d722021-02-25 10:45:20 -0500892 - folderMargin - folderContentPaddingTop;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800893 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -0800894
895 // Check if the icons fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -0500896 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Thales Lima78d00ad2021-09-30 11:29:06 +0100897 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x);
Jon Mirandae126d722021-02-25 10:45:20 -0500898 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin
899 - folderContentPaddingLeftRight * 2;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800900 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -0800901
902 float scale = Math.min(scaleX, scaleY);
903 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700904 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700905 }
906 }
907
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700908 private void updateFolderCellSize(float scale, Resources res) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100909 float invIconSizeDp = isVerticalBarLayout()
Thales Lima12d0eff2022-03-25 17:06:11 +0000910 ? inv.iconSize[INDEX_LANDSCAPE]
911 : inv.iconSize[INDEX_DEFAULT];
Sunny Goyal35c7b192021-04-20 16:51:10 -0700912 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Thales Lima83bedbf2021-10-05 17:47:39 +0100913 folderChildTextSizePx =
Thales Lima12d0eff2022-03-25 17:06:11 +0000914 pxFromSp(inv.iconTextSize[INDEX_DEFAULT], mMetrics, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500915 folderLabelTextSizePx = (int) (folderChildTextSizePx * folderLabelTextScale);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700916
917 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700918
Jon Miranda823da222021-03-23 08:08:45 -0400919 if (isScalableGrid) {
Thales Limaa08a4432022-08-09 09:55:17 +0100920 folderCellWidthPx = pxFromDp(inv.folderCellSize.x, mMetrics, scale);
921 folderCellHeightPx = pxFromDp(inv.folderCellSize.y, mMetrics, scale);
Jon Mirandaf33f5b32021-07-22 17:15:31 -0700922
Thales Limaa08a4432022-08-09 09:55:17 +0100923 folderCellLayoutBorderSpacePx = new Point(
924 pxFromDp(inv.folderBorderSpaces.x, mMetrics, scale),
925 pxFromDp(inv.folderBorderSpaces.y, mMetrics, scale));
926 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx.x;
927 folderContentPaddingTop = pxFromDp(inv.folderTopPadding, mMetrics, scale);
Jon Miranda823da222021-03-23 08:08:45 -0400928 } else {
929 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
930 * scale);
931 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
932 * scale);
933
934 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
935 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
936 }
937
Jonathan Miranda9ad87462017-07-26 17:41:02 +0000938 folderChildDrawablePaddingPx = Math.max(0,
939 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700940 }
941
Winson1f064272016-07-18 17:18:02 -0700942 public void updateInsets(Rect insets) {
943 mInsets.set(insets);
944 }
945
Sunny Goyalae6e3182019-04-30 12:04:37 -0700946 /**
947 * The current device insets. This is generally same as the insets being dispatched to
948 * {@link Insettable} elements, but can differ if the element is using a different profile.
949 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800950 public Rect getInsets() {
951 return mInsets;
952 }
953
Sunny Goyal756cd262015-08-20 12:33:21 -0700954 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700955 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700956 }
957
Sunny Goyal19ff7282021-04-22 10:12:54 -0700958 public Point getCellSize(Point result) {
959 if (result == null) {
960 result = new Point();
961 }
Thales Limad1df5fc2021-09-03 18:37:19 +0100962
Pat Manning25d53342022-05-10 09:58:49 +0000963 int shortcutAndWidgetContainerWidth =
964 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
965 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
966 inv.numColumns);
967 int shortcutAndWidgetContainerHeight =
968 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
969 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
970 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +0000971 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +0100972 }
973
974 /**
Pat Manning25d53342022-05-10 09:58:49 +0000975 * Gets the number of panels within the workspace.
976 */
977 public int getPanelCount() {
978 return isTwoPanels ? 2 : 1;
979 }
980
981 /**
Pat Manningde25c0d2022-04-05 19:11:26 +0100982 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
983 * bottom of the screen.
984 */
Pat Manning5f74bfd2022-07-20 12:08:54 +0100985 private int getVerticalHotseatLastItemBottomOffset(Context context) {
986 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +0100987 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +0100988 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +0100989 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +0100990 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +0100991 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +0100992 }
993
994 /**
995 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
996 */
Pat Manning25d53342022-05-10 09:58:49 +0000997 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +0100998 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +0100999 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001000 }
1001
1002 /**
1003 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1004 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001005 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001006 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001007 return heightPx - (isVerticalBarLayout()
1008 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001009 }
1010
Pat Manningea5c1d22022-04-14 10:58:16 +01001011 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001012 * Gets the scale of the workspace for the spring-loaded edit state.
1013 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001014 public float getWorkspaceSpringLoadScale(Context context) {
1015 float scale =
1016 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1017 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001018 scale = Math.min(scale, 1f);
1019
1020 // Reduce scale if next pages would not be visible after scaling the workspace
Pat Manning25d53342022-05-10 09:58:49 +00001021 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001022 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001023 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001024 if (scaledWorkspaceWidth > maxAvailableWidth) {
1025 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1026 }
1027 return scale;
1028 }
1029
Pat Manning25d53342022-05-10 09:58:49 +00001030 /**
1031 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1032 *
1033 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1034 * layouts have two Cell Layouts per workspace.
1035 */
1036 public int getCellLayoutWidth() {
1037 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001038 }
1039
Pat Manning25d53342022-05-10 09:58:49 +00001040 /**
1041 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1042 *
1043 * <p>This is the height of a Workspace, less its vertical padding.
1044 */
1045 public int getCellLayoutHeight() {
1046 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001047 }
1048
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001049 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001050 return new Point(workspacePadding.left + workspacePadding.right,
1051 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001052 }
1053
1054 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001055 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1056 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001057 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001058 private void updateWorkspacePadding() {
1059 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001060 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -08001061 padding.top = 0;
1062 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001063 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001064 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -07001065 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -07001066 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -07001067 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001068 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -07001069 }
Winson Chungb3800242013-10-24 11:01:54 -07001070 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001071 // Pad the bottom of the workspace with hotseat bar
1072 // and leave a bit of space in case a widget go all the way down
1073 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding
1074 + workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace
1075 - mInsets.bottom;
Pat Manning08610ca2022-04-05 21:03:16 +01001076 int paddingTop = workspaceTopPadding + (isScalableGrid ? 0 : edgeMarginPx);
1077 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001078
Pat Manning08610ca2022-04-05 21:03:16 +01001079 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001080 }
Pat Manning08610ca2022-04-05 21:03:16 +01001081 insetPadding(workspacePadding, cellLayoutPaddingPx);
1082 }
1083
1084 private void insetPadding(Rect paddings, Rect insets) {
1085 insets.left = Math.min(insets.left, paddings.left);
1086 paddings.left -= insets.left;
1087
1088 insets.top = Math.min(insets.top, paddings.top);
1089 paddings.top -= insets.top;
1090
1091 insets.right = Math.min(insets.right, paddings.right);
1092 paddings.right -= insets.right;
1093
1094 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1095 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001096 }
1097
Sunny Goyal57b22792021-05-25 14:35:01 -07001098 /**
1099 * Returns the padding for hotseat view
1100 */
1101 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001102 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001103 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001104 // The hotseat icons will be placed in the middle of the hotseat cells.
1105 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1106 // in vertical bar layout.
1107 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1108 // is set to account for that difference.
1109 float diffOverlapFactor = iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
Pat Manning08610ca2022-04-05 21:03:16 +01001110 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1111 - diffOverlapFactor), 0);
1112 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001113 + diffOverlapFactor), 0);
1114
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001115 if (isSeascape()) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001116 hotseatBarPadding.set(mInsets.left + hotseatBarSidePaddingStartPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001117 hotseatBarSidePaddingEndPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001118 } else {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001119 hotseatBarPadding.set(hotseatBarSidePaddingEndPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001120 mInsets.right + hotseatBarSidePaddingStartPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001121 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001122 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001123 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001124 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1125 int hotseatBarTopPadding =
1126 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001127
Thales Lima612230d2022-03-31 18:04:37 +01001128 // Push icons to the side
Thales Lima9938c2f2022-07-25 14:38:16 +01001129 int requiredWidth = getHotseatRequiredWidth();
Pat Manning26f70f72022-07-07 13:50:39 +01001130 int hotseatWidth = Math.min(requiredWidth, availableWidthPx - hotseatBarEndOffset);
Thales Lima612230d2022-03-31 18:04:37 +01001131 int sideSpacing = (availableWidthPx - hotseatWidth) / 2;
Thales Lima612230d2022-03-31 18:04:37 +01001132
Pat Manning5f74bfd2022-07-20 12:08:54 +01001133 hotseatBarPadding.set(sideSpacing, hotseatBarTopPadding, sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001134 hotseatBarBottomPadding);
Alex Chau51da2192022-05-20 13:32:10 +01001135
1136 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001137 if (isRtl) {
Thales Lima9938c2f2022-07-25 14:38:16 +01001138 hotseatBarPadding.right += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001139 } else {
Thales Lima9938c2f2022-07-25 14:38:16 +01001140 hotseatBarPadding.left += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001141 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001142
Pat Manning26f70f72022-07-07 13:50:39 +01001143 if (hotseatBarEndOffset > sideSpacing) {
Thales Lima612230d2022-03-31 18:04:37 +01001144 int diff = isRtl
Pat Manning26f70f72022-07-07 13:50:39 +01001145 ? sideSpacing - hotseatBarEndOffset
1146 : hotseatBarEndOffset - sideSpacing;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001147 hotseatBarPadding.left -= diff;
1148 hotseatBarPadding.right += diff;
Sunny Goyal57b22792021-05-25 14:35:01 -07001149 }
Thales Lima425f6822022-05-10 13:44:58 -03001150 } else if (isScalableGrid) {
Alex Chau206ede92022-08-01 17:46:12 +01001151 int sideSpacing = (availableWidthPx - hotseatQsbWidth) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001152 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001153 0,
Thales Lima425f6822022-05-10 13:44:58 -03001154 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001155 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001156 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001157 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1158 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1159 // for this, we pad the left and right of the hotseat with half of the difference of a
1160 // workspace cell vs a hotseat cell.
1161 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001162 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001163 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001164 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001165 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1166 + mInsets.left,
1167 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001168 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001169 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001170 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001171 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001172 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001173 }
1174
Thales Lima9938c2f2022-07-25 14:38:16 +01001175 private int getAdditionalQsbSpace() {
1176 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1177 }
1178
1179 /**
1180 * Calculate how much space the hotseat needs to be shown completely
1181 */
1182 private int getHotseatRequiredWidth() {
1183 int additionalQsbSpace = getAdditionalQsbSpace();
1184 return iconSizePx * numShownHotseatIcons
1185 + hotseatBorderSpace * (numShownHotseatIcons - 1)
1186 + additionalQsbSpace;
1187 }
1188
Winsonfadbe8f2016-07-22 16:35:37 -07001189 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001190 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1191 */
1192 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001193 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001194 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1195 } else if (isTaskbarPresent) { // QSB on top
1196 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001197 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001198 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001199 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001200 }
1201
Thales Limab8c05952022-05-23 16:58:38 +01001202 /**
1203 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1204 */
1205 private int getHotseatBarBottomPadding() {
1206 if (isTaskbarPresent) { // QSB on top or inline
1207 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001208 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001209 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001210 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001211 }
1212
1213 /**
Alex Chau51da2192022-05-20 13:32:10 +01001214 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1215 */
1216 public int getTaskbarOffsetY() {
1217 int taskbarIconBottomSpace = (taskbarSize - iconSizePx) / 2;
1218 int launcherIconBottomSpace =
1219 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001220 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001221 }
1222
1223 /**
Alex Chaua2fc7642022-04-21 14:20:23 +01001224 * Returns the number of pixels required below OverviewActions excluding insets.
1225 */
1226 public int getOverviewActionsClaimedSpaceBelow() {
1227 if (isTaskbarPresent && !isGestureMode) {
1228 // Align vertically to where nav buttons are.
Thales Limab8c05952022-05-23 16:58:38 +01001229 return ((taskbarSize - overviewActionsHeight) / 2) + getTaskbarOffsetY();
Alex Chaua2fc7642022-04-21 14:20:23 +01001230 }
1231
Alex Chau1fe83fe2022-05-09 19:21:13 +01001232 return isTaskbarPresent ? stashedTaskbarSize : mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001233 }
1234
1235 /** Gets the space that the overview actions will take, including bottom margin. */
1236 public int getOverviewActionsClaimedSpace() {
1237 return overviewActionsTopMarginPx + overviewActionsHeight
1238 + getOverviewActionsClaimedSpaceBelow();
1239 }
1240
1241 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001242 * @return the bounds for which the open folders should be contained within
1243 */
1244 public Rect getAbsoluteOpenFolderBounds() {
1245 if (isVerticalBarLayout()) {
1246 // Folders should only appear right of the drop target bar and left of the hotseat
1247 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1248 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001249 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001250 mInsets.top + availableHeightPx);
1251 } else {
1252 // Folders should only appear below the drop target bar and above the hotseat
Tony Wickhamae72b462021-03-10 16:18:40 -08001253 int hotseatTop = isTaskbarPresent ? taskbarSize : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001254 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001255 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001256 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001257 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001258 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001259 }
1260 }
1261
Jon Miranda228877d2021-02-09 11:05:00 -05001262 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1263 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001264 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001265
Jon Miranda228877d2021-02-09 11:05:00 -05001266 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1267 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001268 }
1269
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001270 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001271 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1272 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1273 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001274 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001275 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001276 return isLandscape && transposeLayoutWithOrientation;
1277 }
1278
Sunny Goyal59d086c2018-05-07 17:31:40 -07001279 /**
1280 * Updates orientation information and returns true if it has changed from the previous value.
1281 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001282 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001283 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001284 boolean isSeascape = DisplayController.INSTANCE.get(context)
1285 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001286 if (mIsSeascape != isSeascape) {
1287 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001288 // Hotseat changing sides requires updating workspace left/right paddings
1289 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001290 return true;
1291 }
1292 }
1293 return false;
1294 }
1295
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001296 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001297 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001298 }
1299
Sunny Goyal07b69292018-01-08 14:19:34 -08001300 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001301 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001302 }
1303
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001304 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001305 switch (containerType) {
1306 case CellLayout.WORKSPACE:
1307 return cellHeightPx;
1308 case CellLayout.FOLDER:
1309 return folderCellHeightPx;
1310 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001311 // The hotseat is the only container where the cell height is going to be
1312 // different from the content within that cell.
1313 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001314 default:
1315 // ??
1316 return 0;
1317 }
1318 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001319
Jon Miranda58561d42021-03-17 10:51:54 -04001320 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001321 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001322 }
1323
Pat Manning5f74bfd2022-07-20 12:08:54 +01001324 /** Dumps various DeviceProfile variables to the specified writer. */
1325 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04001326 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001327 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001328
1329 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001330 writer.println(prefix + "\tisPhone:" + isPhone);
1331 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1332 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001333 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001334
1335 writer.println(prefix + "\tisLandscape:" + isLandscape);
1336 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001337 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001338
1339 writer.println(prefix + pxToDpStr("windowX", windowX));
1340 writer.println(prefix + pxToDpStr("windowY", windowY));
1341 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1342 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001343 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1344 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001345 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1346 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1347 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1348 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001349
1350 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1351
1352 writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
1353
Thales Lima83bedbf2021-10-05 17:47:39 +01001354 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001355 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1356 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1357 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001358
Thales Lima83bedbf2021-10-05 17:47:39 +01001359 writer.println(prefix + "\tminCellSize: " + inv.minCellSize[mTypeIndex] + "dp");
Jon Mirandaab3c6812021-06-28 15:42:28 -07001360
Jon Miranda58561d42021-03-17 10:51:54 -04001361 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1362 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1363
1364 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1365 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1366
Thales Lima83bedbf2021-10-05 17:47:39 +01001367 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1368 cellLayoutBorderSpacePx.x));
1369 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1370 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001371 writer.println(
1372 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
1373 writer.println(
1374 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
1375 writer.println(
1376 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01001377 writer.println(
1378 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01001379
Jon Miranda58561d42021-03-17 10:51:54 -04001380 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1381 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1382 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1383
1384 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1385 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1386 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1387 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1388 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1389 folderChildDrawablePaddingPx));
Thales Lima78d00ad2021-09-30 11:29:06 +01001390 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx Horizontal",
1391 folderCellLayoutBorderSpacePx.x));
1392 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx Vertical",
1393 folderCellLayoutBorderSpacePx.y));
Thales Limaa08a4432022-08-09 09:55:17 +01001394 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
1395 folderContentPaddingLeftRight));
1396 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Jon Miranda58561d42021-03-17 10:51:54 -04001397
Alex Chaue0227552022-04-06 19:44:43 +01001398 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
1399
1400 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
1401 writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding));
Jon Miranda58561d42021-03-17 10:51:54 -04001402 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1403 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1404 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1405 allAppsIconDrawablePaddingPx));
1406 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001407 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001408 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
1409 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001410 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau62572c02022-07-25 18:36:37 +00001411 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
Alex Chau27b39b92022-01-14 18:02:18 +00001412 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001413
1414 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03001415 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04001416 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00001417 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Jon Miranda58561d42021-03-17 10:51:54 -04001418 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
1419 hotseatBarSidePaddingStartPx));
1420 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
1421 hotseatBarSidePaddingEndPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001422 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01001423 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
1424 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01001425 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
1426 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001427 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
1428 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
1429 hotseatLayoutPadding.top));
1430 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
1431 hotseatLayoutPadding.bottom));
1432 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
1433 hotseatLayoutPadding.left));
1434 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
1435 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001436 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001437 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001438 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01001439 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001440
1441 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001442 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda58561d42021-03-17 10:51:54 -04001443 writer.println(prefix + pxToDpStr("taskbarSize", taskbarSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001444
Thales Lima83bedbf2021-10-05 17:47:39 +01001445 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1446 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001447 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
1448 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
1449 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00001450 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001451
Jon Mirandaab3c6812021-06-28 15:42:28 -07001452 writer.println(prefix + pxToDpStr("iconScale", iconScale));
1453 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04001454 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00001455 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001456
1457 if (inv.devicePaddings != null) {
1458 int unscaledExtraSpace = (int) (extraSpace / iconScale);
1459 writer.println(prefix + pxToDpStr("maxEmptySpace",
1460 inv.devicePaddings.getDevicePadding(unscaledExtraSpace).getMaxEmptySpacePx()));
1461 }
Jon Miranda58561d42021-03-17 10:51:54 -04001462 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
1463 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00001464
1465 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00001466 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
1467 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
1468 overviewTaskIconDrawableSizePx));
1469 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
1470 overviewTaskIconDrawableSizeGridPx));
1471 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
1472 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01001473 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
1474 overviewActionsTopMarginPx));
1475 writer.println(prefix + pxToDpStr("overviewActionsHeight",
1476 overviewActionsHeight));
Alex Chau635b3ab2022-01-26 16:49:10 +00001477 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
1478 overviewActionsButtonSpacing));
1479 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
1480 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
1481 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01001482
Alex Chau62572c02022-07-25 18:36:37 +00001483 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001484 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00001485 writer.println(
1486 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001487
Pat Manning5f74bfd2022-07-20 12:08:54 +01001488 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
1489 getCellLayoutSpringLoadShrunkTop()));
1490 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
1491 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01001492 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
1493 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001494 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
1495 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01001496 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
1497 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Jon Miranda58561d42021-03-17 10:51:54 -04001498 }
1499
Alex Chaua6907dc2022-03-18 15:24:07 +00001500 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07001501 Configuration config = new Configuration(c.getResources().getConfiguration());
1502 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03001503 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00001504 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07001505 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07001506 }
Sunny Goyalfde55052018-02-01 14:46:13 -08001507
1508 /**
1509 * Callback when a component changes the DeviceProfile associated with it, as a result of
1510 * configuration change
1511 */
1512 public interface OnDeviceProfileChangeListener {
1513
1514 /**
1515 * Called when the device profile is reassigned. Note that for layout and measurements, it
1516 * is sufficient to listen for inset changes. Use this callback when you need to perform
1517 * a one time operation.
1518 */
1519 void onDeviceProfileChanged(DeviceProfile dp);
1520 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001521
Brian Isganitis099945b2022-01-31 18:15:00 -05001522 /** Allows registering listeners for {@link DeviceProfile} changes. */
1523 public interface DeviceProfileListenable {
1524
1525 /** The current device profile. */
1526 DeviceProfile getDeviceProfile();
1527
1528 /** Registered {@link OnDeviceProfileChangeListener} instances. */
1529 List<OnDeviceProfileChangeListener> getOnDeviceProfileChangeListeners();
1530
1531 /** Notifies listeners of a {@link DeviceProfile} change. */
1532 default void dispatchDeviceProfileChanged() {
1533 DeviceProfile deviceProfile = getDeviceProfile();
1534 List<OnDeviceProfileChangeListener> listeners = getOnDeviceProfileChangeListeners();
1535 for (int i = listeners.size() - 1; i >= 0; i--) {
1536 listeners.get(i).onDeviceProfileChanged(deviceProfile);
1537 }
1538 }
1539
1540 /** Register listener for {@link DeviceProfile} changes. */
1541 default void addOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
1542 getOnDeviceProfileChangeListeners().add(listener);
1543 }
1544
1545 /** Unregister listener for {@link DeviceProfile} changes. */
1546 default void removeOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
1547 getOnDeviceProfileChangeListeners().remove(listener);
1548 }
1549 }
1550
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001551 public static class Builder {
1552 private Context mContext;
1553 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07001554 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001555
Sunny Goyal19ff7282021-04-22 10:12:54 -07001556 private WindowBounds mWindowBounds;
1557 private boolean mUseTwoPanels;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001558
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001559 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001560 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00001561 private Boolean mIsGestureMode;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001562
Sunny Goyal65190ae2022-08-02 14:16:26 -07001563 private SparseArray<DotRenderer> mDotRendererCache;
1564
Sunny Goyalfd58da62020-08-11 12:06:49 -07001565 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001566 mContext = context;
1567 mInv = inv;
1568 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001569 }
1570
1571 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1572 mIsMultiWindowMode = isMultiWindowMode;
1573 return this;
1574 }
1575
Sunny Goyal19ff7282021-04-22 10:12:54 -07001576 public Builder setUseTwoPanels(boolean useTwoPanels) {
1577 mUseTwoPanels = useTwoPanels;
1578 return this;
1579 }
1580
Sunny Goyal65190ae2022-08-02 14:16:26 -07001581 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
1582 mDotRendererCache = dotRendererCache;
1583 return this;
1584 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07001585
1586 public Builder setWindowBounds(WindowBounds bounds) {
1587 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07001588 return this;
1589 }
1590
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001591 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1592 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1593 return this;
1594 }
1595
Alex Chau6ed408f2022-03-04 12:58:05 +00001596 public Builder setGestureMode(boolean isGestureMode) {
1597 mIsGestureMode = isGestureMode;
1598 return this;
1599 }
1600
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001601 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001602 if (mWindowBounds == null) {
1603 throw new IllegalArgumentException("Window bounds not set");
1604 }
1605 if (mTransposeLayoutWithOrientation == null) {
1606 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
1607 }
Alex Chau6ed408f2022-03-04 12:58:05 +00001608 if (mIsGestureMode == null) {
1609 mIsGestureMode = DisplayController.getNavigationMode(mContext).hasGestures;
1610 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001611 if (mDotRendererCache == null) {
1612 mDotRendererCache = new SparseArray<>();
1613 }
1614 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
1615 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mUseTwoPanels,
1616 mIsGestureMode);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001617 }
1618 }
1619
Winson Chungb3800242013-10-24 11:01:54 -07001620}