blob: 1bc269d9c35bf2dd79ab26fd5c14c6e60f34b8d4 [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 Mirandae126d722021-02-25 10:45:20 -050023import static com.android.launcher3.ResourceUtils.pxFromDp;
Jon Miranda58561d42021-03-17 10:51:54 -040024import static com.android.launcher3.Utilities.dpiFromPx;
Jon Mirandaaf3aed02021-05-06 18:28:45 -070025import static com.android.launcher3.Utilities.pxFromSp;
Jon Miranda92c1b5d2021-07-20 13:57:16 -070026import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.ICON_OVERLAP_FACTOR;
Jon Miranda228877d2021-02-09 11:05:00 -050027
Sunny Goyal35c7b192021-04-20 16:51:10 -070028import android.annotation.SuppressLint;
Winson Chungb3800242013-10-24 11:01:54 -070029import android.content.Context;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070030import android.content.res.Configuration;
Winson Chungb3800242013-10-24 11:01:54 -070031import android.content.res.Resources;
Sunny Goyal8b9919d2021-04-07 14:45:17 -070032import android.graphics.Path;
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 Goyal59d086c2018-05-07 17:31:40 -070037import android.view.Surface;
Winson Chungb3800242013-10-24 11:01:54 -070038
Sunny Goyalc13403c2016-11-18 23:44:48 -080039import com.android.launcher3.CellLayout.ContainerType;
Jon Miranda228877d2021-02-09 11:05:00 -050040import com.android.launcher3.DevicePaddings.DevicePadding;
Tony Wickham8912b042018-11-29 15:28:53 -080041import com.android.launcher3.icons.DotRenderer;
Sunny Goyal8b9919d2021-04-07 14:45:17 -070042import com.android.launcher3.icons.GraphicsUtils;
Hyunyoung Song48cb7bc2018-09-25 17:03:34 -070043import com.android.launcher3.icons.IconNormalizer;
Sunny Goyal57b22792021-05-25 14:35:01 -070044import com.android.launcher3.uioverrides.ApiWrapper;
Sunny Goyalfd58da62020-08-11 12:06:49 -070045import com.android.launcher3.util.DisplayController;
46import com.android.launcher3.util.DisplayController.Info;
Sunny Goyalb46703d2020-05-27 17:52:03 -070047import com.android.launcher3.util.WindowBounds;
Winson1f064272016-07-18 17:18:02 -070048
Jon Miranda58561d42021-03-17 10:51:54 -040049import java.io.PrintWriter;
Brian Isganitis099945b2022-01-31 18:15:00 -050050import java.util.List;
Jon Miranda58561d42021-03-17 10:51:54 -040051
Sunny Goyal35c7b192021-04-20 16:51:10 -070052@SuppressLint("NewApi")
Winson Chungb3800242013-10-24 11:01:54 -070053public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070054
Sunny Goyal8b9919d2021-04-07 14:45:17 -070055 private static final int DEFAULT_DOT_SIZE = 100;
Sunny Goyal57b22792021-05-25 14:35:01 -070056 // Ratio of empty space, qsb should take up to appear visually centered.
Pratyush9afe1ea2021-10-13 11:13:27 +000057 private final float mQsbCenterFactor;
Sunny Goyal1890f672020-04-30 12:28:00 -070058
Adam Cohen2e6da152015-05-06 11:42:25 -070059 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070060 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070061 private final DisplayMetrics mMetrics;
Winson Chungbe876472014-05-14 14:15:20 -070062
Sunny Goyalc6205602015-05-21 20:46:33 -070063 // Device properties
64 public final boolean isTablet;
Sunny Goyalc6205602015-05-21 20:46:33 -070065 public final boolean isPhone;
66 public final boolean transposeLayoutWithOrientation;
Sunny Goyal19ff7282021-04-22 10:12:54 -070067 public final boolean isTwoPanels;
Thales Limaa1012902022-01-13 17:58:42 +000068 public final boolean isQsbInline;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -070069
Sunny Goyalc6205602015-05-21 20:46:33 -070070 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -070071 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -080072 public final boolean isMultiWindowMode;
Alex Chau6ed408f2022-03-04 12:58:05 +000073 public final boolean isGestureMode;
Sunny Goyald70e75a2018-02-22 10:07:32 -080074
Sunny Goyal0addbf02020-04-28 14:17:35 -070075 public final int windowX;
76 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -070077 public final int widthPx;
78 public final int heightPx;
79 public final int availableWidthPx;
80 public final int availableHeightPx;
Sunny Goyal187b16c2022-03-01 16:53:23 -080081 public final int rotationHint;
Jon Mirandabba64512019-03-27 10:54:17 -070082
83 public final float aspectRatio;
84
Jon Mirandae126d722021-02-25 10:45:20 -050085 public final boolean isScalableGrid;
Thales Lima83bedbf2021-10-05 17:47:39 +010086 private final int mTypeIndex;
Jon Mirandae126d722021-02-25 10:45:20 -050087
Tony Wickhamd6b40372015-09-23 18:37:57 -070088 /**
89 * The maximum amount of left/right workspace padding as a percentage of the screen width.
90 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
91 * 7% of the screen width can be used as right padding.
92 */
93 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -070094
Jon Miranda3f9bab22017-07-28 14:50:17 -070095 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -070096 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda80dda302021-07-28 14:14:59 -070097 private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252;
98 private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268;
Jon Miranda30d0aa22017-07-25 15:55:29 -070099
Sunny Goyalc6205602015-05-21 20:46:33 -0700100 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +0100101 public final int desiredWorkspaceHorizontalMarginOriginalPx;
102 public int desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100103 public int gridVisualizationPaddingX;
104 public int gridVisualizationPaddingY;
Thales Lima78d00ad2021-09-30 11:29:06 +0100105 public Point cellLayoutBorderSpaceOriginalPx;
106 public Point cellLayoutBorderSpacePx;
Pat Manning08610ca2022-04-05 21:03:16 +0100107 public Rect cellLayoutPaddingPx = new Rect();
108
Sunny Goyalc6205602015-05-21 20:46:33 -0700109 public final int edgeMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100110 public float workspaceSpringLoadShrunkTop;
111 public float workspaceSpringLoadShrunkBottom;
Sunny Goyal47328fd2016-05-25 18:56:41 -0700112 public final int workspaceSpringLoadedBottomSpace;
Alex Chau906d8822022-05-23 10:42:25 +0100113 public final int workspaceSpringLoadedMinNextPageVisiblePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700114
Jon Miranda58561d42021-03-17 10:51:54 -0400115 private final int extraSpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500116 public int workspaceTopPadding;
117 public int workspaceBottomPadding;
118
Tony Wickham5edf9e22020-03-27 20:06:52 -0700119 // Workspace page indicator
120 public final int workspacePageIndicatorHeight;
121 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700122
Sunny Goyalc6205602015-05-21 20:46:33 -0700123 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400124 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700125 public int iconSizePx;
126 public int iconTextSizePx;
127 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700128 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -0700129
Jon Mirandaab3c6812021-06-28 15:42:28 -0700130 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800131 public int cellWidthPx;
132 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700133 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800134
Jon Mirandae126d722021-02-25 10:45:20 -0500135 public int cellYPaddingPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500136
Sunny Goyalc6205602015-05-21 20:46:33 -0700137 // Folder
Jon Mirandae126d722021-02-25 10:45:20 -0500138 public float folderLabelTextScale;
139 public int folderLabelTextSizePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700140 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700141 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700142
Jon Mirandae126d722021-02-25 10:45:20 -0500143 // Folder content
Thales Lima78d00ad2021-09-30 11:29:06 +0100144 public Point folderCellLayoutBorderSpacePx;
145 public int folderCellLayoutBorderSpaceOriginalPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500146 public int folderContentPaddingLeftRight;
147 public int folderContentPaddingTop;
148
Jon Mirandabf7d8122016-11-03 15:29:29 -0700149 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700150 public int folderCellWidthPx;
151 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700152
153 // Folder child
154 public int folderChildIconSizePx;
155 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700156 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700157
Sunny Goyalc6205602015-05-21 20:46:33 -0700158 // Hotseat
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700159 public final int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700160 public int hotseatCellHeightPx;
Thales Lima425f6822022-05-10 13:44:58 -0300161 private final boolean areNavButtonsInline;
Jon Miranda18751b62017-07-31 17:25:27 -0700162 // In portrait: size = height, in landscape: size = width
163 public int hotseatBarSizePx;
Thales Limab8c05952022-05-23 16:58:38 +0100164 public int hotseatBarBottomSpacePx;
165 public int hotseatQsbSpace;
Pat Manningde25c0d2022-04-05 19:11:26 +0100166 public int springLoadedHotseatBarTopMarginPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700167 // Start is the side next to the nav bar, end is the side next to the workspace
168 public final int hotseatBarSidePaddingStartPx;
169 public final int hotseatBarSidePaddingEndPx;
Sunny Goyal57b22792021-05-25 14:35:01 -0700170 public final int hotseatQsbHeight;
Thales Limab8c05952022-05-23 16:58:38 +0100171 public final int hotseatQsbVisualHeight;
172 private final int hotseatQsbShadowHeight;
Thales Limadd027342022-01-07 12:54:37 +0000173 public int hotseatBorderSpace;
Adam Cohen2e6da152015-05-06 11:42:25 -0700174
Thales Limaa1012902022-01-13 17:58:42 +0000175 public int qsbWidth; // only used when isQsbInline
Jon Miranda8bdb2222021-06-23 18:10:10 -0700176
Sunny Goyalc6205602015-05-21 20:46:33 -0700177 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000178 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000179 public int allAppsShiftRange;
180 public int allAppsTopPadding;
Andras Kloczl142b0542022-03-09 21:26:02 +0000181 public int bottomSheetTopPadding;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700182 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700183 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700184 public int allAppsIconSizePx;
185 public int allAppsIconDrawablePaddingPx;
sfufa@google.comde013292021-09-21 18:22:44 -0700186 public int allAppsLeftRightPadding;
Alex Chau27b39b92022-01-14 18:02:18 +0000187 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700188 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700189 public float allAppsIconTextSizePx;
190
Zak Cohen334efeb2021-03-19 16:42:07 -0700191 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700192 public int overviewTaskMarginPx;
Alex Chaueaa6d682021-08-17 12:56:15 +0100193 public int overviewTaskMarginGridPx;
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();
Thales Limab8c05952022-05-23 16:58:38 +0100222 private final Rect mHotseatBarPadding = new Rect();
Jon Miranda0bd63d12019-03-06 17:29:29 -0800223 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700224 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700225
Tony Wickhamf34bee82018-12-03 18:11:39 -0800226 // Notification dots
Samuel Fufac96fa242019-09-26 23:06:32 -0700227 public DotRenderer mDotRendererWorkSpace;
228 public DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800229
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100230 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800231 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000232 // Whether Taskbar will inset the bottom of apps by taskbarSize.
233 public boolean isTaskbarPresentInApps;
Tony Wickham15883892021-02-12 11:24:40 -0800234 public int taskbarSize;
Alex Chau6a7d1e22022-01-20 19:54:17 +0000235 public int stashedTaskbarSize;
Tony Wickham15883892021-02-12 11:24:40 -0800236
Alex Chaua02eddc2021-04-29 00:36:06 +0100237 // DragController
238 public int flingToDeleteThresholdVelocity;
239
Vinit Nayak17c4b332021-08-05 12:54:58 -0700240 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700241 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal0addbf02020-04-28 14:17:35 -0700242 boolean isMultiWindowMode, boolean transposeLayoutWithOrientation,
Alex Chau6ed408f2022-03-04 12:58:05 +0000243 boolean useTwoPanels, boolean isGestureMode) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700244
Adam Cohen2e6da152015-05-06 11:42:25 -0700245 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700246 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800247 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500248 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +0000249 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700250 windowX = windowBounds.bounds.left;
251 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800252 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100253 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700254
Jon Mirandae126d722021-02-25 10:45:20 -0500255 isScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000256 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700257 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000258 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700259 isPhone = !isTablet;
Alex Chau90125822021-11-17 14:16:58 +0000260 isTwoPanels = isTablet && useTwoPanels;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800261 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700262
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000263 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000264 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700265 ? Configuration.ORIENTATION_LANDSCAPE
266 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000267 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700268 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000269 mMetrics = res.getDisplayMetrics();
270
271 // Determine sizes.
272 widthPx = windowBounds.bounds.width();
273 heightPx = windowBounds.bounds.height();
274 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100275 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000276
277 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
278 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
279 mQsbCenterFactor = res.getFloat(R.dimen.qsb_center_factor);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700280
Thales Lima83bedbf2021-10-05 17:47:39 +0100281 if (isTwoPanels) {
282 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000283 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100284 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000285 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100286 }
287 } else {
288 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000289 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100290 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000291 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100292 }
293 }
294
Tony Wickham15883892021-02-12 11:24:40 -0800295 if (isTaskbarPresent) {
Tony Wickham15883892021-02-12 11:24:40 -0800296 taskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_size);
Alex Chau6a7d1e22022-01-20 19:54:17 +0000297 stashedTaskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
Tony Wickham15883892021-02-12 11:24:40 -0800298 }
Tony Wickham15883892021-02-12 11:24:40 -0800299
Winson Chungb3800242013-10-24 11:01:54 -0700300 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
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
313 allAppsTopPadding = isTablet ? bottomSheetTopPadding : 0;
Alex Chaub8c22e12022-02-14 18:35:58 +0000314 allAppsShiftRange = isTablet
315 ? heightPx - allAppsTopPadding
316 : res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
Jon Mirandae126d722021-02-25 10:45:20 -0500317 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
318 folderContentPaddingLeftRight =
319 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
320 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_content_padding_top);
321
Thales Lima78d00ad2021-09-30 11:29:06 +0100322 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv);
Thales Lima85c942f2021-12-31 13:04:20 +0000323 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000324 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
325 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Thales Lima78d00ad2021-09-30 11:29:06 +0100326 cellLayoutBorderSpaceOriginalPx = new Point(cellLayoutBorderSpacePx);
Thales Lima080d8902022-03-28 15:30:29 +0100327 folderCellLayoutBorderSpaceOriginalPx = pxFromDp(inv.folderBorderSpace, mMetrics);
Thales Lima78d00ad2021-09-30 11:29:06 +0100328 folderCellLayoutBorderSpacePx = new Point(folderCellLayoutBorderSpaceOriginalPx,
329 folderCellLayoutBorderSpaceOriginalPx);
Jon Mirandae126d722021-02-25 10:45:20 -0500330
Tony Wickham5edf9e22020-03-27 20:06:52 -0700331 workspacePageIndicatorHeight = res.getDimensionPixelSize(
332 R.dimen.workspace_page_indicator_height);
333 mWorkspacePageIndicatorOverlapWorkspace =
334 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700335
Winson Chungb3800242013-10-24 11:01:54 -0700336 iconDrawablePaddingOriginalPx =
337 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Alex Chaua02eddc2021-04-29 00:36:06 +0100338
Sunny Goyal47328fd2016-05-25 18:56:41 -0700339 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100340 dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
341 dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100342 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
343 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100344 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
345 R.dimen.drop_target_button_drawable_horizontal_padding);
346 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
347 R.dimen.drop_target_button_drawable_vertical_padding);
348 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100349 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
350 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100351
Sunny Goyal47328fd2016-05-25 18:56:41 -0700352 workspaceSpringLoadedBottomSpace =
353 res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space);
Alex Chau906d8822022-05-23 10:42:25 +0100354 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
355 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700356
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700357 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700358
Thales Limaa1012902022-01-13 17:58:42 +0000359 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100360 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
361 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
362
Thales Lima12d0eff2022-03-25 17:06:11 +0000363 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
364 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
365 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
366 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
367 && hotseatQsbHeight > 0;
368 isQsbInline = inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000369
Alex Chau8175da92022-03-09 11:19:47 +0000370 // We shrink hotseat sizes regardless of orientation, if nav buttons are inline and QSB
371 // might be inline in either orientations, to keep hotseat size consistent across rotation.
Thales Lima425f6822022-05-10 13:44:58 -0300372 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Alex Chau8175da92022-03-09 11:19:47 +0000373 if (areNavButtonsInline && canQsbInline) {
Alex Chau6ed408f2022-03-04 12:58:05 +0000374 numShownHotseatIcons = inv.numShrunkenHotseatIcons;
375 } else {
376 numShownHotseatIcons =
377 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
378 }
379
Sunny Goyal19ff7282021-04-22 10:12:54 -0700380 numShownAllAppsColumns =
381 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100382
383 int hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
384 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
385 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
386 // Have a little space between the inset and the QSB
387 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
388 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
389
390 // Only change the spaces if there is space
391 if (availableSpace > 0) {
392 // Make sure there is enough space between hotseat/QSB and QSB/navBar
393 if (availableSpace < minQsbMargin * 2) {
394 minQsbMargin = availableSpace / 2;
395 hotseatQsbSpace = minQsbMargin;
396 } else {
397 hotseatQsbSpace -= minQsbMargin;
398 }
399 }
400 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
401
Thales Limaa1012902022-01-13 17:58:42 +0000402 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100403 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
Thales Limaa1012902022-01-13 17:58:42 +0000404 }
Thales Lima425f6822022-05-10 13:44:58 -0300405
Pat Manningde25c0d2022-04-05 19:11:26 +0100406 springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
407 R.dimen.spring_loaded_hotseat_top_margin);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700408 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800409 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700410 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700411 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Thales Limab8c05952022-05-23 16:58:38 +0100412 updateHotseatSizes(pxFromDp(inv.iconSize[INDEX_DEFAULT], mMetrics));
Jon Miranda8bdb2222021-06-23 18:10:10 -0700413
Alex Chau635b3ab2022-01-26 16:49:10 +0000414 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chaueaa6d682021-08-17 12:56:15 +0100415 overviewTaskMarginGridPx = res.getDimensionPixelSize(R.dimen.overview_task_margin_grid);
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);
Alex Chaudedbc8a2021-03-17 16:53:26 +0000421 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx * 2;
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);
Alex Chau4c983742021-12-10 13:09:53 +0000427 // Grid task's top margin is only overviewTaskIconSizePx + overviewTaskMarginGridPx, but
428 // overviewTaskThumbnailTopMarginPx is applied to all TaskThumbnailView, so exclude the
429 // extra margin when calculating row spacing.
430 int extraTopMargin = overviewTaskThumbnailTopMarginPx - overviewTaskIconSizePx
431 - overviewTaskMarginGridPx;
432 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing)
433 - extraTopMargin;
Alex Chau635b3ab2022-01-26 16:49:10 +0000434 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700435
Jon Miranda2ed276e2017-06-29 11:36:34 -0700436 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400437 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700438
Jon Miranda2ed276e2017-06-29 11:36:34 -0700439 // Now that we have all of the variables calculated, we can tune certain sizes.
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400440 if (isScalableGrid && inv.devicePaddings != null) {
441 // Paddings were created assuming no scaling, so we first unscale the extra space.
Jon Mirandaab3c6812021-06-28 15:42:28 -0700442 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400443 DevicePadding padding = inv.devicePaddings.getDevicePadding(unscaledExtraSpace);
Jon Miranda228877d2021-02-09 11:05:00 -0500444
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400445 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
446 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
447 int paddingHotseatBottom = padding.getHotseatBottomPadding(unscaledExtraSpace);
448
Jon Mirandaab3c6812021-06-28 15:42:28 -0700449 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
450 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700451 }
Pat Manning08610ca2022-04-05 21:03:16 +0100452
453 int cellLayoutPadding =
454 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
455 R.dimen.cell_layout_padding);
456 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
457 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800458 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800459
Thales Lima425f6822022-05-10 13:44:58 -0300460 // Hotseat and QSB width depends on updated cellSize and workspace padding
461 hotseatBorderSpace = calculateHotseatBorderSpace();
462 qsbWidth = calculateQsbWidth();
463
Alex Chaua02eddc2021-04-29 00:36:06 +0100464 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
465 R.dimen.drag_flingToDeleteMinVelocity);
466
Tony Wickham1237df02017-02-24 08:59:36 -0800467 // This is done last, after iconSizePx is calculated above.
Sunny Goyal8b9919d2021-04-07 14:45:17 -0700468 Path dotPath = GraphicsUtils.getShapePath(DEFAULT_DOT_SIZE);
469 mDotRendererWorkSpace = new DotRenderer(iconSizePx, dotPath, DEFAULT_DOT_SIZE);
Samuel Fufac96fa242019-09-26 23:06:32 -0700470 mDotRendererAllApps = iconSizePx == allAppsIconSizePx ? mDotRendererWorkSpace :
Sunny Goyal8b9919d2021-04-07 14:45:17 -0700471 new DotRenderer(allAppsIconSizePx, dotPath, DEFAULT_DOT_SIZE);
Adam Cohen63f1ec02014-08-12 09:23:13 -0700472 }
473
Thales Lima425f6822022-05-10 13:44:58 -0300474 /**
475 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
476 * width of the hotseat.
477 */
Thales Limaa1012902022-01-13 17:58:42 +0000478 private int calculateQsbWidth() {
Thales Lima425f6822022-05-10 13:44:58 -0300479 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100480 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300481 return getIconToIconWidthForColumns(columns)
482 - iconSizePx * numShownHotseatIcons
483 - hotseatBorderSpace * numShownHotseatIcons;
484 } else {
485 int columns = inv.hotseatColumnSpan[mTypeIndex];
486 return getIconToIconWidthForColumns(columns);
487 }
488 }
Thales Lima2903a622022-03-17 13:52:19 +0000489
Thales Lima425f6822022-05-10 13:44:58 -0300490 private int getIconToIconWidthForColumns(int columns) {
491 return columns * getCellSize().x
492 + (columns - 1) * cellLayoutBorderSpacePx.x
493 - (getCellSize().x - iconSizePx); // left and right cell space
Thales Limaa1012902022-01-13 17:58:42 +0000494 }
495
Thales Limad90faab2021-09-21 17:18:47 +0100496 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
497 if (isVerticalBarLayout()) {
498 return 0;
499 }
500
Thales Lima83bedbf2021-10-05 17:47:39 +0100501 return isScalableGrid
502 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
503 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100504 }
505
Thales Limab8c05952022-05-23 16:58:38 +0100506 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
507 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700508 // Ensure there is enough space for folder icons, which have a slightly larger radius.
509 hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR);
Thales Limab8c05952022-05-23 16:58:38 +0100510
Jon Miranda0d284852021-06-22 14:50:55 -0700511 if (isVerticalBarLayout()) {
512 hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
513 + hotseatBarSidePaddingEndPx;
Thales Limab8c05952022-05-23 16:58:38 +0100514 } else if (isQsbInline) {
515 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
516 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700517 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100518 hotseatBarSizePx = hotseatIconSizePx
519 + hotseatQsbSpace
520 + hotseatQsbVisualHeight
521 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700522 }
523 }
524
Thales Lima78d00ad2021-09-30 11:29:06 +0100525 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100526 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100527 }
528
529 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100530 if (!isScalableGrid) {
531 return new Point(0, 0);
532 }
533
Thales Lima080d8902022-03-28 15:30:29 +0100534 int horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
535 int verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
Thales Lima78d00ad2021-09-30 11:29:06 +0100536
537 return new Point(horizontalSpacePx, verticalSpacePx);
538 }
539
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700540 public Info getDisplayInfo() {
541 return mInfo;
542 }
543
Jon Miranda611dba42021-03-02 14:12:13 -0500544 /**
545 * We inset the widget padding added by the system and instead rely on the border spacing
546 * between cells to create reliable consistency between widgets
547 */
548 public boolean shouldInsetWidgets() {
549 Rect widgetPadding = inv.defaultWidgetPadding;
550
Jon Miranda49811182021-06-03 09:52:40 -0700551 // Check all sides to ensure that the widget won't overlap into another cell, or into
552 // status bar.
553 return workspaceTopPadding > widgetPadding.top
Thales Lima78d00ad2021-09-30 11:29:06 +0100554 && cellLayoutBorderSpacePx.x > widgetPadding.left
555 && cellLayoutBorderSpacePx.y > widgetPadding.top
556 && cellLayoutBorderSpacePx.x > widgetPadding.right
557 && cellLayoutBorderSpacePx.y > widgetPadding.bottom;
Jon Miranda611dba42021-03-02 14:12:13 -0500558 }
Jon Mirandae126d722021-02-25 10:45:20 -0500559
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700560 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800561 WindowBounds bounds = new WindowBounds(
562 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700563 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100564 bounds.insets.set(mInsets);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700565 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700566 .setWindowBounds(bounds)
567 .setUseTwoPanels(isTwoPanels)
Alex Chau6ed408f2022-03-04 12:58:05 +0000568 .setMultiWindowMode(isMultiWindowMode)
569 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800570 }
571
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700572 public DeviceProfile copy(Context context) {
573 return toBuilder(context).build();
574 }
575
576 /**
577 * TODO: Move this to the builder as part of setMultiWindowMode
578 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700579 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700580 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700581 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700582 .setMultiWindowMode(true)
583 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800584
Jon Miranda941375e2021-03-31 13:10:45 -0400585 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda93e1f042016-11-11 14:13:04 -0800586
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800587 // We use these scales to measure and layout the widgets using their full invariant profile
588 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
589 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
590 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
591 profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY);
592
Jon Miranda93e1f042016-11-11 14:13:04 -0800593 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700594 }
595
Adam Cohen63f1ec02014-08-12 09:23:13 -0700596 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400597 * Checks if there is enough space for labels on the workspace.
598 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700599 * It is important to call this method after the All Apps variables have been set.
600 */
Jon Miranda941375e2021-03-31 13:10:45 -0400601 private void hideWorkspaceLabelsIfNotEnoughSpace() {
602 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
603 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
604 - iconTextHeight;
605
606 // We want enough space so that the text is closer to its corresponding icon.
607 if (workspaceCellPaddingY < iconTextHeight) {
608 iconTextSizePx = 0;
609 iconDrawablePaddingPx = 0;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700610 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda941375e2021-03-31 13:10:45 -0400611 autoResizeAllAppsCells();
612 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700613 }
Jon Miranda1091e532017-07-21 13:31:50 -0700614
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700615 /**
616 * Re-computes the all-apps cell size to be independent of workspace
617 */
618 public void autoResizeAllAppsCells() {
Jon Miranda941375e2021-03-31 13:10:45 -0400619 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
620 int topBottomPadding = textHeight;
Jon Miranda1091e532017-07-21 13:31:50 -0700621 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
Jon Miranda941375e2021-03-31 13:10:45 -0400622 + textHeight + (topBottomPadding * 2);
Jon Miranda1091e532017-07-21 13:31:50 -0700623 }
624
Thales Limab7ef5692022-03-10 10:32:36 +0000625 private void updateAllAppsContainerWidth(Resources res) {
Pat Manning08610ca2022-04-05 21:03:16 +0100626 int cellLayoutHorizontalPadding =
627 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
Alex Chau27b39b92022-01-14 18:02:18 +0000628 if (isTablet) {
Thales Limab7ef5692022-03-10 10:32:36 +0000629 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100630 res.getDimensionPixelSize(R.dimen.all_apps_bottom_sheet_horizontal_padding);
631
sfufa@google.comde013292021-09-21 18:22:44 -0700632 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
Thales Limab7ef5692022-03-10 10:32:36 +0000633 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Alex Chau27b39b92022-01-14 18:02:18 +0000634 + allAppsLeftRightPadding * 2;
635 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
sfufa@google.comde013292021-09-21 18:22:44 -0700636 } else {
637 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100638 desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding;
sfufa@google.comde013292021-09-21 18:22:44 -0700639 }
640 }
641
Jon Miranda228877d2021-02-09 11:05:00 -0500642 /**
643 * Returns the amount of extra (or unused) vertical space.
644 */
645 private int updateAvailableDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700646 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800647
Pat Manning08610ca2022-04-05 21:03:16 +0100648 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -0500649
650 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +0100651 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +0000652 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -0500653 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500654 float scaleY = maxHeight / usedHeight;
655 boolean shouldScale = scaleY < 1f;
656
657 float scaleX = 1f;
658 if (isScalableGrid) {
659 // We scale to fit the cellWidth and cellHeight in the available space.
660 // The benefit of scalable grids is that we can get consistent aspect ratios between
661 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +0100662 float usedWidth =
663 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500664 // We do not subtract padding here, as we also scale the workspace padding if needed.
665 scaleX = availableWidthPx / usedWidth;
666 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700667 }
Jon Mirandae126d722021-02-25 10:45:20 -0500668
669 if (shouldScale) {
670 float scale = Math.min(scaleX, scaleY);
671 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +0100672 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -0500673 }
674
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700675 updateAvailableFolderCellDimensions(res);
Jon Miranda228877d2021-02-09 11:05:00 -0500676 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700677 }
678
Pat Manninga2e14992022-04-22 11:29:17 +0100679 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +0100680 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
681 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
682 }
683
Pat Manninga2e14992022-04-22 11:29:17 +0100684 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +0000685 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +0100686 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
687 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -0500688 }
689
Jon Miranda6f7e9702019-09-16 14:44:14 -0700690 /**
691 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
692 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
693 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
694 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800695 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -0700696 // Icon scale should never exceed 1, otherwise pixellation may occur.
697 iconScale = Math.min(1f, scale);
698 cellScaleToFit = scale;
699
Jon Miranda18751b62017-07-31 17:25:27 -0700700 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800701 final boolean isVerticalLayout = isVerticalBarLayout();
Thales Lima83bedbf2021-10-05 17:47:39 +0100702 float invIconSizeDp = inv.iconSize[mTypeIndex];
703 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
Andras Kloczl30fe9152021-08-05 18:02:29 +0200704
Jon Mirandaab3c6812021-06-28 15:42:28 -0700705 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, iconScale));
Jon Mirandaab3c6812021-06-28 15:42:28 -0700706 iconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * iconScale);
707 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700708
Thales Lima080d8902022-03-28 15:30:29 +0100709 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500710
711 if (isScalableGrid) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100712 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
713 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500714 int cellContentHeight = iconSizePx + iconDrawablePaddingPx
715 + Utilities.calculateTextHeight(iconTextSizePx);
716 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +0100717 desiredWorkspaceHorizontalMarginPx =
718 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -0500719 } else {
Jon Mirandae126d722021-02-25 10:45:20 -0500720 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700721 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR)
722 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -0500723 + Utilities.calculateTextHeight(iconTextSizePx);
724 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
725 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
726 && !isMultiWindowMode) {
727 // Ensures that the label is closer to its corresponding icon. This is not an issue
728 // with vertical bar layout or multi-window mode since the issue is handled
729 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
730 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
731 iconDrawablePaddingPx = cellPaddingY;
732 }
Jon Miranda846455e2017-10-02 14:58:52 -0700733 }
Jon Miranda18751b62017-07-31 17:25:27 -0700734
Sunny Goyalae190ff2020-04-14 00:19:01 +0000735 // All apps
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500736 updateAllAppsIconSize(scale, res);
Winson Chungb3800242013-10-24 11:01:54 -0700737
Thales Limab8c05952022-05-23 16:58:38 +0100738 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700739
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700740 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -0700741 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
742 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Winson Chung0f785722015-04-08 10:27:49 -0700743 }
744
Thales Lima425f6822022-05-10 13:44:58 -0300745 /**
746 * Hotseat width spans a certain number of columns on scalable grids.
747 * This method calculates the space between the icons to achieve that width.
748 */
749 private int calculateHotseatBorderSpace() {
750 if (!isScalableGrid) return 0;
751 //TODO(http://b/228998082) remove this when 3 button spaces are fixed
752 if (areNavButtonsInline) {
753 return pxFromDp(inv.hotseatBorderSpaces[mTypeIndex], mMetrics);
754 } else {
755 int columns = inv.hotseatColumnSpan[mTypeIndex];
756 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
757 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
758 return (int) (hotseatWidthPx - hotseatIconsTotalPx) / (numShownHotseatIcons - 1);
759 }
760 }
761
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500762
763 /**
764 * Updates the iconSize for allApps* variants.
765 */
Brian Isganitisa9a78112022-05-23 18:11:47 -0700766 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +0100767 allAppsBorderSpacePx = new Point(
768 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
769 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700770 // AllApps cells don't have real space between cells,
771 // so we add the border space to the cell height
772 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics, scale)
773 + allAppsBorderSpacePx.y;
774 // but width is just the cell,
775 // the border is added in #updateAllAppsContainerWidth
Thales Lima080d8902022-03-28 15:30:29 +0100776 if (isScalableGrid) {
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500777 allAppsIconSizePx =
Brandon Dayauon969f6a82022-05-19 09:46:47 -0700778 pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics, scale);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500779 allAppsIconTextSizePx =
Brandon Dayauon969f6a82022-05-19 09:46:47 -0700780 pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics, scale);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500781 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -0700782 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500783 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700784 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
785 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500786 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
787 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700788 allAppsIconDrawablePaddingPx =
789 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -0700790 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500791 }
792
Thales Limab7ef5692022-03-10 10:32:36 +0000793 updateAllAppsContainerWidth(res);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500794 if (isVerticalBarLayout()) {
795 hideWorkspaceLabelsIfNotEnoughSpace();
796 }
797 }
798
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700799 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700800 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700801
Jon Mirandae126d722021-02-25 10:45:20 -0500802 final int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_height);
803
Jon Mirandac1b23992016-12-13 08:57:36 -0800804 // Don't let the folder get too close to the edges of the screen.
Jon Miranda1786df32018-09-25 13:05:23 -0700805 int folderMargin = edgeMarginPx * 2;
Sunny Goyal07b69292018-01-08 14:19:34 -0800806 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -0800807
808 // Check if the icons fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -0500809 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Thales Lima78d00ad2021-09-30 11:29:06 +0100810 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx.y);
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800811 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderBottomPanelSize
Jon Mirandae126d722021-02-25 10:45:20 -0500812 - folderMargin - folderContentPaddingTop;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800813 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -0800814
815 // Check if the icons fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -0500816 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Thales Lima78d00ad2021-09-30 11:29:06 +0100817 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x);
Jon Mirandae126d722021-02-25 10:45:20 -0500818 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin
819 - folderContentPaddingLeftRight * 2;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800820 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -0800821
822 float scale = Math.min(scaleX, scaleY);
823 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700824 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700825 }
826 }
827
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700828 private void updateFolderCellSize(float scale, Resources res) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100829 float invIconSizeDp = isVerticalBarLayout()
Thales Lima12d0eff2022-03-25 17:06:11 +0000830 ? inv.iconSize[INDEX_LANDSCAPE]
831 : inv.iconSize[INDEX_DEFAULT];
Sunny Goyal35c7b192021-04-20 16:51:10 -0700832 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Thales Lima83bedbf2021-10-05 17:47:39 +0100833 folderChildTextSizePx =
Thales Lima12d0eff2022-03-25 17:06:11 +0000834 pxFromSp(inv.iconTextSize[INDEX_DEFAULT], mMetrics, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500835 folderLabelTextSizePx = (int) (folderChildTextSizePx * folderLabelTextScale);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700836
837 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700838
Jon Miranda823da222021-03-23 08:08:45 -0400839 if (isScalableGrid) {
Jon Mirandaf33f5b32021-07-22 17:15:31 -0700840 int minWidth = folderChildIconSizePx + iconDrawablePaddingPx * 2;
841 int minHeight = folderChildIconSizePx + iconDrawablePaddingPx * 2 + textHeight;
842
843 folderCellWidthPx = (int) Math.max(minWidth, cellWidthPx * scale);
844 folderCellHeightPx = (int) Math.max(minHeight, cellHeightPx * scale);
Jon Miranda823da222021-03-23 08:08:45 -0400845
Thales Lima78d00ad2021-09-30 11:29:06 +0100846 int scaledSpace = (int) (folderCellLayoutBorderSpaceOriginalPx * scale);
847 folderCellLayoutBorderSpacePx = new Point(scaledSpace, scaledSpace);
848 folderContentPaddingLeftRight = scaledSpace;
849 folderContentPaddingTop = scaledSpace;
Jon Miranda823da222021-03-23 08:08:45 -0400850 } else {
851 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
852 * scale);
853 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
854 * scale);
855
856 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
857 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
858 }
859
Jonathan Miranda9ad87462017-07-26 17:41:02 +0000860 folderChildDrawablePaddingPx = Math.max(0,
861 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700862 }
863
Winson1f064272016-07-18 17:18:02 -0700864 public void updateInsets(Rect insets) {
865 mInsets.set(insets);
866 }
867
Sunny Goyalae6e3182019-04-30 12:04:37 -0700868 /**
869 * The current device insets. This is generally same as the insets being dispatched to
870 * {@link Insettable} elements, but can differ if the element is using a different profile.
871 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800872 public Rect getInsets() {
873 return mInsets;
874 }
875
Sunny Goyal756cd262015-08-20 12:33:21 -0700876 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700877 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700878 }
879
Sunny Goyal19ff7282021-04-22 10:12:54 -0700880 public Point getCellSize(Point result) {
881 if (result == null) {
882 result = new Point();
883 }
Thales Limad1df5fc2021-09-03 18:37:19 +0100884
Pat Manning25d53342022-05-10 09:58:49 +0000885 int shortcutAndWidgetContainerWidth =
886 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
887 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
888 inv.numColumns);
889 int shortcutAndWidgetContainerHeight =
890 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
891 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
892 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +0000893 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +0100894 }
895
896 /**
Pat Manning25d53342022-05-10 09:58:49 +0000897 * Gets the number of panels within the workspace.
898 */
899 public int getPanelCount() {
900 return isTwoPanels ? 2 : 1;
901 }
902
903 /**
Pat Manningde25c0d2022-04-05 19:11:26 +0100904 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
905 * bottom of the screen.
906 */
Pat Manninga7335bc2022-06-27 18:27:22 +0100907 private int getVerticalHotseatLastItemBottomOffset() {
Pat Manningde25c0d2022-04-05 19:11:26 +0100908 int cellHeight = calculateCellHeight(
Thales Limab8c05952022-05-23 16:58:38 +0100909 heightPx - mHotseatBarPadding.top - mHotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +0100910 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +0100911 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Thales Limab8c05952022-05-23 16:58:38 +0100912 return extraIconEndSpacing + mHotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +0100913 }
914
915 /**
916 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
917 */
Pat Manning25d53342022-05-10 09:58:49 +0000918 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manningde25c0d2022-04-05 19:11:26 +0100919 workspaceSpringLoadShrunkTop = mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
920 + dropTargetBarBottomMarginPx;
921 return workspaceSpringLoadShrunkTop;
922 }
923
924 /**
925 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
926 */
Pat Manninga7335bc2022-06-27 18:27:22 +0100927 public float getCellLayoutSpringLoadShrunkBottom() {
Pat Manningde25c0d2022-04-05 19:11:26 +0100928 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
929 workspaceSpringLoadShrunkBottom =
930 heightPx - (isVerticalBarLayout() ? getVerticalHotseatLastItemBottomOffset()
931 : topOfHotseat);
932 return workspaceSpringLoadShrunkBottom;
933 }
934
Pat Manningea5c1d22022-04-14 10:58:16 +0100935 /**
Pat Manninga2e14992022-04-22 11:29:17 +0100936 * Gets the scale of the workspace for the spring-loaded edit state.
937 */
938 public float getWorkspaceSpringLoadScale() {
Pat Manning25d53342022-05-10 09:58:49 +0000939 float scale = (getCellLayoutSpringLoadShrunkBottom() - getCellLayoutSpringLoadShrunkTop())
940 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +0100941 scale = Math.min(scale, 1f);
942
943 // Reduce scale if next pages would not be visible after scaling the workspace
Pat Manning25d53342022-05-10 09:58:49 +0000944 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +0100945 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +0100946 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +0100947 if (scaledWorkspaceWidth > maxAvailableWidth) {
948 scale *= maxAvailableWidth / scaledWorkspaceWidth;
949 }
950 return scale;
951 }
952
Pat Manning25d53342022-05-10 09:58:49 +0000953 /**
954 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
955 *
956 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
957 * layouts have two Cell Layouts per workspace.
958 */
959 public int getCellLayoutWidth() {
960 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +0000961 }
962
Pat Manning25d53342022-05-10 09:58:49 +0000963 /**
964 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
965 *
966 * <p>This is the height of a Workspace, less its vertical padding.
967 */
968 public int getCellLayoutHeight() {
969 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +0100970 }
971
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700972 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -0800973 return new Point(workspacePadding.left + workspacePadding.right,
974 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700975 }
976
977 /**
Sunny Goyal07b69292018-01-08 14:19:34 -0800978 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
979 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700980 */
Sunny Goyal07b69292018-01-08 14:19:34 -0800981 private void updateWorkspacePadding() {
982 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -0700983 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -0800984 padding.top = 0;
985 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800986 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700987 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -0700988 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -0700989 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -0700990 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700991 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -0700992 }
Winson Chungb3800242013-10-24 11:01:54 -0700993 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100994 // Pad the bottom of the workspace with hotseat bar
995 // and leave a bit of space in case a widget go all the way down
996 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding
997 + workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace
998 - mInsets.bottom;
Pat Manning08610ca2022-04-05 21:03:16 +0100999 int paddingTop = workspaceTopPadding + (isScalableGrid ? 0 : edgeMarginPx);
1000 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001001
Pat Manning08610ca2022-04-05 21:03:16 +01001002 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001003 }
Pat Manning08610ca2022-04-05 21:03:16 +01001004 insetPadding(workspacePadding, cellLayoutPaddingPx);
1005 }
1006
1007 private void insetPadding(Rect paddings, Rect insets) {
1008 insets.left = Math.min(insets.left, paddings.left);
1009 paddings.left -= insets.left;
1010
1011 insets.top = Math.min(insets.top, paddings.top);
1012 paddings.top -= insets.top;
1013
1014 insets.right = Math.min(insets.right, paddings.right);
1015 paddings.right -= insets.right;
1016
1017 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1018 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001019 }
1020
Sunny Goyal57b22792021-05-25 14:35:01 -07001021 /**
1022 * Returns the padding for hotseat view
1023 */
1024 public Rect getHotseatLayoutPadding(Context context) {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001025 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001026 // The hotseat icons will be placed in the middle of the hotseat cells.
1027 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1028 // in vertical bar layout.
1029 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1030 // is set to account for that difference.
1031 float diffOverlapFactor = iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
Pat Manning08610ca2022-04-05 21:03:16 +01001032 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1033 - diffOverlapFactor), 0);
1034 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001035 + diffOverlapFactor), 0);
1036
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001037 if (isSeascape()) {
Thales Limab8c05952022-05-23 16:58:38 +01001038 mHotseatBarPadding.set(mInsets.left + hotseatBarSidePaddingStartPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001039 hotseatBarSidePaddingEndPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001040 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001041 mHotseatBarPadding.set(hotseatBarSidePaddingEndPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001042 mInsets.right + hotseatBarSidePaddingStartPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001043 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001044 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001045 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001046 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1047 int hotseatBarTopPadding =
1048 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001049
Thales Lima612230d2022-03-31 18:04:37 +01001050 // Push icons to the side
1051 int additionalQsbSpace = isQsbInline ? qsbWidth + hotseatBorderSpace : 0;
Thales Lima6e7f36c2022-01-04 12:14:11 +00001052 int requiredWidth = iconSizePx * numShownHotseatIcons
Thales Limaa1012902022-01-13 17:58:42 +00001053 + hotseatBorderSpace * (numShownHotseatIcons - 1)
Thales Lima612230d2022-03-31 18:04:37 +01001054 + additionalQsbSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001055 int endOffset = ApiWrapper.getHotseatEndOffset(context);
Thales Lima612230d2022-03-31 18:04:37 +01001056 int hotseatWidth = Math.min(requiredWidth, availableWidthPx - endOffset);
1057 int sideSpacing = (availableWidthPx - hotseatWidth) / 2;
Thales Lima612230d2022-03-31 18:04:37 +01001058
Thales Limab8c05952022-05-23 16:58:38 +01001059 mHotseatBarPadding.set(sideSpacing, hotseatBarTopPadding, sideSpacing,
1060 hotseatBarBottomPadding);
Alex Chau51da2192022-05-20 13:32:10 +01001061
1062 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001063 if (isRtl) {
Thales Limab8c05952022-05-23 16:58:38 +01001064 mHotseatBarPadding.right += additionalQsbSpace;
Thales Lima612230d2022-03-31 18:04:37 +01001065 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001066 mHotseatBarPadding.left += additionalQsbSpace;
Thales Lima612230d2022-03-31 18:04:37 +01001067 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001068
Vinit Nayak8dcbde82021-07-19 12:53:28 -07001069 if (endOffset > sideSpacing) {
Thales Lima612230d2022-03-31 18:04:37 +01001070 int diff = isRtl
Vinit Nayak8dcbde82021-07-19 12:53:28 -07001071 ? sideSpacing - endOffset
1072 : endOffset - sideSpacing;
Thales Limab8c05952022-05-23 16:58:38 +01001073 mHotseatBarPadding.left -= diff;
1074 mHotseatBarPadding.right += diff;
Sunny Goyal57b22792021-05-25 14:35:01 -07001075 }
Thales Lima425f6822022-05-10 13:44:58 -03001076 } else if (isScalableGrid) {
1077 int sideSpacing = (availableWidthPx - qsbWidth) / 2;
Thales Limab8c05952022-05-23 16:58:38 +01001078 mHotseatBarPadding.set(sideSpacing,
1079 0,
Thales Lima425f6822022-05-10 13:44:58 -03001080 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001081 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001082 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001083 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1084 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1085 // for this, we pad the left and right of the hotseat with half of the difference of a
1086 // workspace cell vs a hotseat cell.
1087 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001088 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001089 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Thales Limab8c05952022-05-23 16:58:38 +01001090 mHotseatBarPadding.set(
1091 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1092 + mInsets.left,
1093 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001094 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001095 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001096 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001097 }
Thales Limab8c05952022-05-23 16:58:38 +01001098 return mHotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001099 }
1100
Winsonfadbe8f2016-07-22 16:35:37 -07001101 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001102 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1103 */
1104 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001105 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001106 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1107 } else if (isTaskbarPresent) { // QSB on top
1108 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001109 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001110 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001111 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001112 }
1113
Thales Limab8c05952022-05-23 16:58:38 +01001114 /**
1115 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1116 */
1117 private int getHotseatBarBottomPadding() {
1118 if (isTaskbarPresent) { // QSB on top or inline
1119 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001120 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001121 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001122 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001123 }
1124
1125 /**
Alex Chau51da2192022-05-20 13:32:10 +01001126 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1127 */
1128 public int getTaskbarOffsetY() {
1129 int taskbarIconBottomSpace = (taskbarSize - iconSizePx) / 2;
1130 int launcherIconBottomSpace =
1131 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001132 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001133 }
1134
1135 /**
Alex Chaua2fc7642022-04-21 14:20:23 +01001136 * Returns the number of pixels required below OverviewActions excluding insets.
1137 */
1138 public int getOverviewActionsClaimedSpaceBelow() {
1139 if (isTaskbarPresent && !isGestureMode) {
1140 // Align vertically to where nav buttons are.
Thales Limab8c05952022-05-23 16:58:38 +01001141 return ((taskbarSize - overviewActionsHeight) / 2) + getTaskbarOffsetY();
Alex Chaua2fc7642022-04-21 14:20:23 +01001142 }
1143
Alex Chau1fe83fe2022-05-09 19:21:13 +01001144 return isTaskbarPresent ? stashedTaskbarSize : mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001145 }
1146
1147 /** Gets the space that the overview actions will take, including bottom margin. */
1148 public int getOverviewActionsClaimedSpace() {
1149 return overviewActionsTopMarginPx + overviewActionsHeight
1150 + getOverviewActionsClaimedSpaceBelow();
1151 }
1152
1153 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001154 * @return the bounds for which the open folders should be contained within
1155 */
1156 public Rect getAbsoluteOpenFolderBounds() {
1157 if (isVerticalBarLayout()) {
1158 // Folders should only appear right of the drop target bar and left of the hotseat
1159 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1160 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001161 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001162 mInsets.top + availableHeightPx);
1163 } else {
1164 // Folders should only appear below the drop target bar and above the hotseat
Tony Wickhamae72b462021-03-10 16:18:40 -08001165 int hotseatTop = isTaskbarPresent ? taskbarSize : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001166 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001167 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001168 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001169 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001170 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001171 }
1172 }
1173
Jon Miranda228877d2021-02-09 11:05:00 -05001174 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1175 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001176 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001177
Jon Miranda228877d2021-02-09 11:05:00 -05001178 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1179 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001180 }
1181
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001182 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001183 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1184 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1185 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001186 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001187 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001188 return isLandscape && transposeLayoutWithOrientation;
1189 }
1190
Sunny Goyal59d086c2018-05-07 17:31:40 -07001191 /**
1192 * Updates orientation information and returns true if it has changed from the previous value.
1193 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001194 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001195 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001196 boolean isSeascape = DisplayController.INSTANCE.get(context)
1197 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001198 if (mIsSeascape != isSeascape) {
1199 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001200 // Hotseat changing sides requires updating workspace left/right paddings
1201 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001202 return true;
1203 }
1204 }
1205 return false;
1206 }
1207
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001208 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001209 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001210 }
1211
Sunny Goyal07b69292018-01-08 14:19:34 -08001212 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001213 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001214 }
1215
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001216 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001217 switch (containerType) {
1218 case CellLayout.WORKSPACE:
1219 return cellHeightPx;
1220 case CellLayout.FOLDER:
1221 return folderCellHeightPx;
1222 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001223 // The hotseat is the only container where the cell height is going to be
1224 // different from the content within that cell.
1225 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001226 default:
1227 // ??
1228 return 0;
1229 }
1230 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001231
Jon Miranda58561d42021-03-17 10:51:54 -04001232 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001233 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001234 }
1235
1236 public void dump(String prefix, PrintWriter writer) {
1237 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001238 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001239
1240 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001241 writer.println(prefix + "\tisPhone:" + isPhone);
1242 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1243 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001244 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001245
1246 writer.println(prefix + "\tisLandscape:" + isLandscape);
1247 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001248 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001249
1250 writer.println(prefix + pxToDpStr("windowX", windowX));
1251 writer.println(prefix + pxToDpStr("windowY", windowY));
1252 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1253 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001254 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1255 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001256 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1257 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1258 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1259 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001260
1261 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1262
1263 writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
1264
Thales Lima83bedbf2021-10-05 17:47:39 +01001265 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001266 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1267 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1268 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001269
Thales Lima83bedbf2021-10-05 17:47:39 +01001270 writer.println(prefix + "\tminCellSize: " + inv.minCellSize[mTypeIndex] + "dp");
Jon Mirandaab3c6812021-06-28 15:42:28 -07001271
Jon Miranda58561d42021-03-17 10:51:54 -04001272 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1273 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1274
1275 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1276 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1277
Thales Lima83bedbf2021-10-05 17:47:39 +01001278 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1279 cellLayoutBorderSpacePx.x));
1280 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1281 cellLayoutBorderSpacePx.y));
Pat Manning08610ca2022-04-05 21:03:16 +01001282 writer.println(prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
1283 writer.println(prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
1284 writer.println(prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
1285 writer.println(
1286 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01001287
Jon Miranda58561d42021-03-17 10:51:54 -04001288 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1289 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1290 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1291
1292 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1293 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1294 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1295 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1296 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1297 folderChildDrawablePaddingPx));
Thales Lima78d00ad2021-09-30 11:29:06 +01001298 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpaceOriginalPx",
1299 folderCellLayoutBorderSpaceOriginalPx));
1300 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx Horizontal",
1301 folderCellLayoutBorderSpacePx.x));
1302 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx Vertical",
1303 folderCellLayoutBorderSpacePx.y));
Jon Miranda58561d42021-03-17 10:51:54 -04001304
Alex Chaue0227552022-04-06 19:44:43 +01001305 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
1306
1307 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
1308 writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding));
Jon Miranda58561d42021-03-17 10:51:54 -04001309 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1310 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1311 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1312 allAppsIconDrawablePaddingPx));
1313 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001314 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Thales Limab7ef5692022-03-10 10:32:36 +00001315 writer.println(prefix + pxToDpStr("allAppsBorderSpacePx", allAppsBorderSpacePx.x));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001316 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau27b39b92022-01-14 18:02:18 +00001317 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
1318 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001319
1320 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03001321 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04001322 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Thales Limab8c05952022-05-23 16:58:38 +01001323 writer.println(prefix + pxToDpStr("hotseatBarBottomPaddingPx", hotseatBarBottomSpacePx));
Jon Miranda58561d42021-03-17 10:51:54 -04001324 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
1325 hotseatBarSidePaddingStartPx));
1326 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
1327 hotseatBarSidePaddingEndPx));
Thales Limab8c05952022-05-23 16:58:38 +01001328 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
1329 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01001330 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
1331 springLoadedHotseatBarTopMarginPx));
Thales Limab8c05952022-05-23 16:58:38 +01001332 writer.println(prefix + pxToDpStr("mHotseatBarPadding.top", mHotseatBarPadding.top));
1333 writer.println(prefix + pxToDpStr("mHotseatBarPadding.bottom", mHotseatBarPadding.bottom));
1334 writer.println(prefix + pxToDpStr("mHotseatBarPadding.left", mHotseatBarPadding.left));
1335 writer.println(prefix + pxToDpStr("mHotseatBarPadding.right", mHotseatBarPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001336 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001337 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001338 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
1339 writer.println(prefix + pxToDpStr("qsbWidth", qsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001340
1341 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001342 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda58561d42021-03-17 10:51:54 -04001343 writer.println(prefix + pxToDpStr("taskbarSize", taskbarSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001344
Thales Lima83bedbf2021-10-05 17:47:39 +01001345 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1346 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001347 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
1348 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
1349 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
1350 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
1351
Jon Mirandaab3c6812021-06-28 15:42:28 -07001352 writer.println(prefix + pxToDpStr("iconScale", iconScale));
1353 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04001354 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Thales Lima7a6752d2021-09-23 14:31:00 +01001355 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001356
1357 if (inv.devicePaddings != null) {
1358 int unscaledExtraSpace = (int) (extraSpace / iconScale);
1359 writer.println(prefix + pxToDpStr("maxEmptySpace",
1360 inv.devicePaddings.getDevicePadding(unscaledExtraSpace).getMaxEmptySpacePx()));
1361 }
Jon Miranda58561d42021-03-17 10:51:54 -04001362 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
1363 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00001364
1365 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
1366 writer.println(prefix + pxToDpStr("overviewTaskMarginGridPx", overviewTaskMarginGridPx));
1367 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
1368 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
1369 overviewTaskIconDrawableSizePx));
1370 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
1371 overviewTaskIconDrawableSizeGridPx));
1372 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
1373 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01001374 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
1375 overviewActionsTopMarginPx));
1376 writer.println(prefix + pxToDpStr("overviewActionsHeight",
1377 overviewActionsHeight));
Alex Chau635b3ab2022-01-26 16:49:10 +00001378 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
1379 overviewActionsButtonSpacing));
1380 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
1381 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
1382 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01001383
1384 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
1385 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
1386 writer.println(
1387 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
1388
1389 writer.println(
1390 prefix + pxToDpStr("workspaceSpringLoadShrunkTop", workspaceSpringLoadShrunkTop));
1391 writer.println(prefix + pxToDpStr("workspaceSpringLoadShrunkBottom",
1392 workspaceSpringLoadShrunkBottom));
Alex Chau906d8822022-05-23 10:42:25 +01001393 writer.println(prefix + pxToDpStr("workspaceSpringLoadedBottomSpace",
1394 workspaceSpringLoadedBottomSpace));
1395 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
1396 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manninga2e14992022-04-22 11:29:17 +01001397 writer.println(
1398 prefix + pxToDpStr("getWorkspaceSpringLoadScale()", getWorkspaceSpringLoadScale()));
Thales Limab8c05952022-05-23 16:58:38 +01001399 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
1400 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Jon Miranda58561d42021-03-17 10:51:54 -04001401 }
1402
Alex Chaua6907dc2022-03-18 15:24:07 +00001403 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07001404 Configuration config = new Configuration(c.getResources().getConfiguration());
1405 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03001406 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00001407 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07001408 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07001409 }
Sunny Goyalfde55052018-02-01 14:46:13 -08001410
1411 /**
1412 * Callback when a component changes the DeviceProfile associated with it, as a result of
1413 * configuration change
1414 */
1415 public interface OnDeviceProfileChangeListener {
1416
1417 /**
1418 * Called when the device profile is reassigned. Note that for layout and measurements, it
1419 * is sufficient to listen for inset changes. Use this callback when you need to perform
1420 * a one time operation.
1421 */
1422 void onDeviceProfileChanged(DeviceProfile dp);
1423 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001424
Brian Isganitis099945b2022-01-31 18:15:00 -05001425 /** Allows registering listeners for {@link DeviceProfile} changes. */
1426 public interface DeviceProfileListenable {
1427
1428 /** The current device profile. */
1429 DeviceProfile getDeviceProfile();
1430
1431 /** Registered {@link OnDeviceProfileChangeListener} instances. */
1432 List<OnDeviceProfileChangeListener> getOnDeviceProfileChangeListeners();
1433
1434 /** Notifies listeners of a {@link DeviceProfile} change. */
1435 default void dispatchDeviceProfileChanged() {
1436 DeviceProfile deviceProfile = getDeviceProfile();
1437 List<OnDeviceProfileChangeListener> listeners = getOnDeviceProfileChangeListeners();
1438 for (int i = listeners.size() - 1; i >= 0; i--) {
1439 listeners.get(i).onDeviceProfileChanged(deviceProfile);
1440 }
1441 }
1442
1443 /** Register listener for {@link DeviceProfile} changes. */
1444 default void addOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
1445 getOnDeviceProfileChangeListeners().add(listener);
1446 }
1447
1448 /** Unregister listener for {@link DeviceProfile} changes. */
1449 default void removeOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
1450 getOnDeviceProfileChangeListeners().remove(listener);
1451 }
1452 }
1453
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001454 public static class Builder {
1455 private Context mContext;
1456 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07001457 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001458
Sunny Goyal19ff7282021-04-22 10:12:54 -07001459 private WindowBounds mWindowBounds;
1460 private boolean mUseTwoPanels;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001461
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001462 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001463 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00001464 private Boolean mIsGestureMode;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001465
Sunny Goyalfd58da62020-08-11 12:06:49 -07001466 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001467 mContext = context;
1468 mInv = inv;
1469 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001470 }
1471
1472 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1473 mIsMultiWindowMode = isMultiWindowMode;
1474 return this;
1475 }
1476
Sunny Goyal19ff7282021-04-22 10:12:54 -07001477 public Builder setUseTwoPanels(boolean useTwoPanels) {
1478 mUseTwoPanels = useTwoPanels;
1479 return this;
1480 }
1481
1482
1483 public Builder setWindowBounds(WindowBounds bounds) {
1484 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07001485 return this;
1486 }
1487
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001488 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1489 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1490 return this;
1491 }
1492
Alex Chau6ed408f2022-03-04 12:58:05 +00001493 public Builder setGestureMode(boolean isGestureMode) {
1494 mIsGestureMode = isGestureMode;
1495 return this;
1496 }
1497
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001498 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001499 if (mWindowBounds == null) {
1500 throw new IllegalArgumentException("Window bounds not set");
1501 }
1502 if (mTransposeLayoutWithOrientation == null) {
1503 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
1504 }
Alex Chau6ed408f2022-03-04 12:58:05 +00001505 if (mIsGestureMode == null) {
1506 mIsGestureMode = DisplayController.getNavigationMode(mContext).hasGestures;
1507 }
1508 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mIsMultiWindowMode,
1509 mTransposeLayoutWithOrientation, mUseTwoPanels, mIsGestureMode);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001510 }
1511 }
1512
Winson Chungb3800242013-10-24 11:01:54 -07001513}