blob: 3489c313064b857b8fdb4caa36420bbb11b492f7 [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
Pat Manninge3723662022-03-25 16:07:46 +0000100 // To evenly space the icons, increase the left/right margins for tablets in portrait mode.
101 private static final int PORTRAIT_TABLET_LEFT_RIGHT_PADDING_MULTIPLIER = 4;
102
Sunny Goyalc6205602015-05-21 20:46:33 -0700103 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +0100104 public final int desiredWorkspaceHorizontalMarginOriginalPx;
105 public int desiredWorkspaceHorizontalMarginPx;
Thales Lima78d00ad2021-09-30 11:29:06 +0100106 public Point cellLayoutBorderSpaceOriginalPx;
107 public Point cellLayoutBorderSpacePx;
Pat Manninge3723662022-03-25 16:07:46 +0000108 public final int cellLayoutPaddingLeftRightPx;
109 public final int cellLayoutBottomPaddingPx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700110 public final int edgeMarginPx;
Pat Manninge3723662022-03-25 16:07:46 +0000111 public float workspaceSpringLoadShrinkFactor;
Sunny Goyal47328fd2016-05-25 18:56:41 -0700112 public final int workspaceSpringLoadedBottomSpace;
Sunny Goyalc6205602015-05-21 20:46:33 -0700113
Jon Miranda58561d42021-03-17 10:51:54 -0400114 private final int extraSpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500115 public int workspaceTopPadding;
116 public int workspaceBottomPadding;
Jon Miranda58561d42021-03-17 10:51:54 -0400117 public int extraHotseatBottomPadding;
Jon Miranda228877d2021-02-09 11:05:00 -0500118
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
Jon Miranda80cddbc2021-07-22 13:51:16 -0700159 public int hotseatBarSizeExtraSpacePx;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700160 public final int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700161 public int hotseatCellHeightPx;
Jon Miranda0d284852021-06-22 14:50:55 -0700162 private final int hotseatExtraVerticalSize;
Jon Miranda18751b62017-07-31 17:25:27 -0700163 // In portrait: size = height, in landscape: size = width
164 public int hotseatBarSizePx;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700165 public int hotseatBarTopPaddingPx;
Jon Miranda0d284852021-06-22 14:50:55 -0700166 public final int hotseatBarBottomPaddingPx;
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 Limadd027342022-01-07 12:54:37 +0000171 public int hotseatBorderSpace;
Adam Cohen2e6da152015-05-06 11:42:25 -0700172
Jon Miranda8bdb2222021-06-23 18:10:10 -0700173 public final float qsbBottomMarginOriginalPx;
174 public int qsbBottomMarginPx;
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;
zakcohendad8a802021-05-20 09:52:26 -0700199 public final int overviewActionsMarginThreeButtonPx;
Alex Chau5fd9d492021-07-22 17:27:11 +0100200 public final int overviewActionsTopMarginGesturePx;
201 public final int overviewActionsBottomMarginGesturePx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000202 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100203 public int overviewPageSpacing;
204 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000205 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700206
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800207 // Widgets
208 public final PointF appWidgetScale = new PointF(1.0f, 1.0f);
209
Sunny Goyal47328fd2016-05-25 18:56:41 -0700210 // Drop Target
211 public int dropTargetBarSizePx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100212 public int dropTargetDragPaddingPx;
213 public int dropTargetTextSizePx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700214
Winson1f064272016-07-18 17:18:02 -0700215 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800216 private final Rect mInsets = new Rect();
217 public final Rect workspacePadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700218 private final Rect mHotseatPadding = new Rect();
Jon Miranda0bd63d12019-03-06 17:29:29 -0800219 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700220 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700221
Tony Wickhamf34bee82018-12-03 18:11:39 -0800222 // Notification dots
Samuel Fufac96fa242019-09-26 23:06:32 -0700223 public DotRenderer mDotRendererWorkSpace;
224 public DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800225
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100226 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800227 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000228 // Whether Taskbar will inset the bottom of apps by taskbarSize.
229 public boolean isTaskbarPresentInApps;
Tony Wickham15883892021-02-12 11:24:40 -0800230 public int taskbarSize;
Alex Chau6a7d1e22022-01-20 19:54:17 +0000231 public int stashedTaskbarSize;
Tony Wickham15883892021-02-12 11:24:40 -0800232
Alex Chaua02eddc2021-04-29 00:36:06 +0100233 // DragController
234 public int flingToDeleteThresholdVelocity;
235
Vinit Nayak17c4b332021-08-05 12:54:58 -0700236 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700237 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal0addbf02020-04-28 14:17:35 -0700238 boolean isMultiWindowMode, boolean transposeLayoutWithOrientation,
Alex Chau6ed408f2022-03-04 12:58:05 +0000239 boolean useTwoPanels, boolean isGestureMode) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700240
Adam Cohen2e6da152015-05-06 11:42:25 -0700241 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700242 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800243 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500244 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +0000245 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700246 windowX = windowBounds.bounds.left;
247 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800248 this.rotationHint = windowBounds.rotationHint;
Winson Chungb3800242013-10-24 11:01:54 -0700249
Jon Mirandae126d722021-02-25 10:45:20 -0500250 isScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
251
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000252 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700253 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000254 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700255 isPhone = !isTablet;
Alex Chau90125822021-11-17 14:16:58 +0000256 isTwoPanels = isTablet && useTwoPanels;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800257 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700258
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000259 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000260 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700261 ? Configuration.ORIENTATION_LANDSCAPE
Alex Chaua6907dc2022-03-18 15:24:07 +0000262 : Configuration.ORIENTATION_PORTRAIT,
263 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700264 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000265 mMetrics = res.getDisplayMetrics();
266
267 // Determine sizes.
268 widthPx = windowBounds.bounds.width();
269 heightPx = windowBounds.bounds.height();
270 availableWidthPx = windowBounds.availableSize.x;
Alex Chau6a7d1e22022-01-20 19:54:17 +0000271 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000272
273 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
274 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
275 mQsbCenterFactor = res.getFloat(R.dimen.qsb_center_factor);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700276
Thales Lima83bedbf2021-10-05 17:47:39 +0100277 if (isTwoPanels) {
278 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000279 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100280 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000281 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100282 }
283 } else {
284 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000285 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100286 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000287 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100288 }
289 }
290
Tony Wickham15883892021-02-12 11:24:40 -0800291 if (isTaskbarPresent) {
Tony Wickham15883892021-02-12 11:24:40 -0800292 taskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_size);
Alex Chau6a7d1e22022-01-20 19:54:17 +0000293 stashedTaskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
Tony Wickham15883892021-02-12 11:24:40 -0800294 }
Tony Wickham15883892021-02-12 11:24:40 -0800295
Winson Chungb3800242013-10-24 11:01:54 -0700296 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700297
Thales Limad90faab2021-09-21 17:18:47 +0100298 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
299 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
Samuel Fufaee9aff92021-04-05 13:30:40 -0500300
Andras Kloczl142b0542022-03-09 21:26:02 +0000301 bottomSheetTopPadding = windowBounds.insets.top // statusbar height
302 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
303 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
304
305 allAppsTopPadding = isTablet ? bottomSheetTopPadding : 0;
Alex Chaub8c22e12022-02-14 18:35:58 +0000306 allAppsShiftRange = isTablet
307 ? heightPx - allAppsTopPadding
308 : res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500309
Jon Mirandae126d722021-02-25 10:45:20 -0500310 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
311 folderContentPaddingLeftRight =
312 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
313 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_content_padding_top);
314
Thales Lima78d00ad2021-09-30 11:29:06 +0100315 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv);
Thales Lima85c942f2021-12-31 13:04:20 +0000316 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000317 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
318 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Thales Lima78d00ad2021-09-30 11:29:06 +0100319 cellLayoutBorderSpaceOriginalPx = new Point(cellLayoutBorderSpacePx);
Thales Lima080d8902022-03-28 15:30:29 +0100320 folderCellLayoutBorderSpaceOriginalPx = pxFromDp(inv.folderBorderSpace, mMetrics);
Thales Lima78d00ad2021-09-30 11:29:06 +0100321 folderCellLayoutBorderSpacePx = new Point(folderCellLayoutBorderSpaceOriginalPx,
322 folderCellLayoutBorderSpaceOriginalPx);
Jon Mirandae126d722021-02-25 10:45:20 -0500323
Pat Manninge3723662022-03-25 16:07:46 +0000324 int cellLayoutPaddingLeftRightMultiplier = !isVerticalBarLayout() && isTablet
325 ? PORTRAIT_TABLET_LEFT_RIGHT_PADDING_MULTIPLIER : 1;
326 int cellLayoutPadding = isScalableGrid
327 ? 0
328 : res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_padding);
329
330 if (isTwoPanels) {
331 cellLayoutPaddingLeftRightPx = 0;
332 cellLayoutBottomPaddingPx = 0;
333 } else if (isLandscape) {
334 cellLayoutPaddingLeftRightPx = 0;
335 cellLayoutBottomPaddingPx = cellLayoutPadding;
336 } else {
337 cellLayoutPaddingLeftRightPx = cellLayoutPaddingLeftRightMultiplier * cellLayoutPadding;
338 cellLayoutBottomPaddingPx = 0;
339 }
340
Tony Wickham5edf9e22020-03-27 20:06:52 -0700341 workspacePageIndicatorHeight = res.getDimensionPixelSize(
342 R.dimen.workspace_page_indicator_height);
343 mWorkspacePageIndicatorOverlapWorkspace =
344 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700345
Winson Chungb3800242013-10-24 11:01:54 -0700346 iconDrawablePaddingOriginalPx =
347 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Alex Chaua02eddc2021-04-29 00:36:06 +0100348
Sunny Goyal47328fd2016-05-25 18:56:41 -0700349 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Alex Chaua02eddc2021-04-29 00:36:06 +0100350 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
351 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
352
Sunny Goyal47328fd2016-05-25 18:56:41 -0700353 workspaceSpringLoadedBottomSpace =
354 res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space);
Sunny Goyald5190522017-04-24 03:06:54 -0700355
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700356 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700357
Thales Limaa1012902022-01-13 17:58:42 +0000358 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Lima12d0eff2022-03-25 17:06:11 +0000359 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
360 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
361 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
362 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
363 && hotseatQsbHeight > 0;
364 isQsbInline = inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000365
Alex Chau8175da92022-03-09 11:19:47 +0000366 // We shrink hotseat sizes regardless of orientation, if nav buttons are inline and QSB
367 // might be inline in either orientations, to keep hotseat size consistent across rotation.
368 boolean areNavButtonsInline = isTaskbarPresent && !isGestureMode;
369 if (areNavButtonsInline && canQsbInline) {
Alex Chau6ed408f2022-03-04 12:58:05 +0000370 numShownHotseatIcons = inv.numShrunkenHotseatIcons;
371 } else {
372 numShownHotseatIcons =
373 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
374 }
375
Sunny Goyal19ff7282021-04-22 10:12:54 -0700376 numShownAllAppsColumns =
377 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700378 hotseatBarSizeExtraSpacePx = 0;
Winson1f064272016-07-18 17:18:02 -0700379 hotseatBarTopPaddingPx =
380 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding);
Thales Limaa1012902022-01-13 17:58:42 +0000381 if (isQsbInline) {
382 hotseatBarBottomPaddingPx = res.getDimensionPixelSize(R.dimen.inline_qsb_bottom_margin);
383 qsbWidth = calculateQsbWidth();
384 } else {
385 hotseatBarBottomPaddingPx = (isTallDevice ? res.getDimensionPixelSize(
386 R.dimen.dynamic_grid_hotseat_bottom_tall_padding)
387 : res.getDimensionPixelSize(
388 R.dimen.dynamic_grid_hotseat_bottom_non_tall_padding))
389 + res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_padding);
390 qsbWidth = 0;
391 }
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700392 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800393 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700394 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700395 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Jon Miranda0d284852021-06-22 14:50:55 -0700396 hotseatExtraVerticalSize =
Jon Miranda228877d2021-02-09 11:05:00 -0500397 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_extra_vertical_size);
Thales Lima6e7f36c2022-01-04 12:14:11 +0000398 hotseatBorderSpace = pxFromDp(inv.hotseatBorderSpaces[mTypeIndex], mMetrics);
Thales Lima83bedbf2021-10-05 17:47:39 +0100399 updateHotseatIconSize(
Thales Lima12d0eff2022-03-25 17:06:11 +0000400 pxFromDp(inv.iconSize[INDEX_DEFAULT], mMetrics));
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700401
Jon Miranda8bdb2222021-06-23 18:10:10 -0700402 qsbBottomMarginOriginalPx = isScalableGrid
403 ? res.getDimensionPixelSize(R.dimen.scalable_grid_qsb_bottom_margin)
404 : 0;
405
Alex Chau635b3ab2022-01-26 16:49:10 +0000406 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chaueaa6d682021-08-17 12:56:15 +0100407 overviewTaskMarginGridPx = res.getDimensionPixelSize(R.dimen.overview_task_margin_grid);
Alex Chau5fd9d492021-07-22 17:27:11 +0100408 overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100409 overviewTaskIconDrawableSizePx =
410 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
411 overviewTaskIconDrawableSizeGridPx =
412 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Alex Chaudedbc8a2021-03-17 16:53:26 +0000413 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx * 2;
Alex Chau635b3ab2022-01-26 16:49:10 +0000414 overviewActionsTopMarginGesturePx = res.getDimensionPixelSize(
415 R.dimen.overview_actions_top_margin_gesture);
416 overviewActionsBottomMarginGesturePx = res.getDimensionPixelSize(
417 R.dimen.overview_actions_bottom_margin_gesture);
418 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
419 overviewActionsButtonSpacing = res.getDimensionPixelSize(
420 R.dimen.overview_actions_button_spacing);
Alex Chau19c6eca2022-03-10 20:12:56 +0000421 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
zakcohendad8a802021-05-20 09:52:26 -0700422 overviewActionsMarginThreeButtonPx = res.getDimensionPixelSize(
Alex Chau5fd9d492021-07-22 17:27:11 +0100423 R.dimen.overview_actions_margin_three_button);
Alex Chau4c983742021-12-10 13:09:53 +0000424 // Grid task's top margin is only overviewTaskIconSizePx + overviewTaskMarginGridPx, but
425 // overviewTaskThumbnailTopMarginPx is applied to all TaskThumbnailView, so exclude the
426 // extra margin when calculating row spacing.
427 int extraTopMargin = overviewTaskThumbnailTopMarginPx - overviewTaskIconSizePx
428 - overviewTaskMarginGridPx;
429 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing)
430 - extraTopMargin;
Alex Chau635b3ab2022-01-26 16:49:10 +0000431 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700432
Jon Miranda2ed276e2017-06-29 11:36:34 -0700433 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400434 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700435
Jon Miranda2ed276e2017-06-29 11:36:34 -0700436 // Now that we have all of the variables calculated, we can tune certain sizes.
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400437 if (isScalableGrid && inv.devicePaddings != null) {
438 // Paddings were created assuming no scaling, so we first unscale the extra space.
Jon Mirandaab3c6812021-06-28 15:42:28 -0700439 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400440 DevicePadding padding = inv.devicePaddings.getDevicePadding(unscaledExtraSpace);
Jon Miranda228877d2021-02-09 11:05:00 -0500441
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400442 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
443 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
444 int paddingHotseatBottom = padding.getHotseatBottomPadding(unscaledExtraSpace);
445
Jon Mirandaab3c6812021-06-28 15:42:28 -0700446 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
447 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
448 extraHotseatBottomPadding = Math.round(paddingHotseatBottom * cellScaleToFit);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400449
Jon Miranda58561d42021-03-17 10:51:54 -0400450 hotseatBarSizePx += extraHotseatBottomPadding;
Jon Miranda8bdb2222021-06-23 18:10:10 -0700451
Jon Mirandaab3c6812021-06-28 15:42:28 -0700452 qsbBottomMarginPx = Math.round(qsbBottomMarginOriginalPx * cellScaleToFit);
Jon Miranda228877d2021-02-09 11:05:00 -0500453 } else if (!isVerticalBarLayout() && isPhone && isTallDevice) {
Jon Miranda3f9bab22017-07-28 14:50:17 -0700454 // We increase the hotseat size when there is extra space.
Jon Miranda80cddbc2021-07-22 13:51:16 -0700455
Jon Miranda80dda302021-07-28 14:14:59 -0700456 if (Float.compare(aspectRatio, TALLER_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0
457 && extraSpace >= Utilities.dpToPx(TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP)) {
458 // For taller devices, we will take a piece of the extra space from each row,
Jon Miranda80cddbc2021-07-22 13:51:16 -0700459 // and add it to the space above and below the hotseat.
Jon Miranda80dda302021-07-28 14:14:59 -0700460
461 // For devices with more extra space, we take a larger piece from each cell.
462 int piece = extraSpace < Utilities.dpToPx(TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP)
Jon Mirandaa56cb842021-08-03 17:26:44 -0700463 ? 7 : 5;
Jon Miranda80dda302021-07-28 14:14:59 -0700464
Jon Miranda80cddbc2021-07-22 13:51:16 -0700465 int extraSpace = ((getCellSize().y - iconSizePx - iconDrawablePaddingPx * 2)
Jon Miranda80dda302021-07-28 14:14:59 -0700466 * inv.numRows) / piece;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700467
Jon Mirandaa56cb842021-08-03 17:26:44 -0700468 workspaceTopPadding = extraSpace / 8;
469 int halfLeftOver = (extraSpace - workspaceTopPadding) / 2;
470 hotseatBarTopPaddingPx += halfLeftOver;
471 hotseatBarSizeExtraSpacePx = halfLeftOver;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700472 } else {
473 // ie. For a display with a large aspect ratio, we can keep the icons on the
474 // workspace in portrait mode closer together by adding more height to the hotseat.
475 // Note: This calculation was created after noticing a pattern in the design spec.
476 hotseatBarSizeExtraSpacePx = getCellSize().y - iconSizePx
477 - iconDrawablePaddingPx * 2 - workspacePageIndicatorHeight;
478 }
479
480 updateHotseatIconSize(iconSizePx);
Jon Miranda30d0aa22017-07-25 15:55:29 -0700481
Jon Miranda3f9bab22017-07-28 14:50:17 -0700482 // Recalculate the available dimensions using the new hotseat size.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700483 updateAvailableDimensions(res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700484 }
Sunny Goyal07b69292018-01-08 14:19:34 -0800485 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800486
Alex Chaua02eddc2021-04-29 00:36:06 +0100487 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
488 R.dimen.drag_flingToDeleteMinVelocity);
489
Tony Wickham1237df02017-02-24 08:59:36 -0800490 // This is done last, after iconSizePx is calculated above.
Sunny Goyal8b9919d2021-04-07 14:45:17 -0700491 Path dotPath = GraphicsUtils.getShapePath(DEFAULT_DOT_SIZE);
492 mDotRendererWorkSpace = new DotRenderer(iconSizePx, dotPath, DEFAULT_DOT_SIZE);
Samuel Fufac96fa242019-09-26 23:06:32 -0700493 mDotRendererAllApps = iconSizePx == allAppsIconSizePx ? mDotRendererWorkSpace :
Sunny Goyal8b9919d2021-04-07 14:45:17 -0700494 new DotRenderer(allAppsIconSizePx, dotPath, DEFAULT_DOT_SIZE);
Adam Cohen63f1ec02014-08-12 09:23:13 -0700495 }
496
Thales Limaa1012902022-01-13 17:58:42 +0000497 private int calculateQsbWidth() {
Thales Lima2903a622022-03-17 13:52:19 +0000498 int columns = isTwoPanels ? inv.numColumns * 2 : inv.numColumns;
499
500 return cellWidthPx * columns
501 + cellLayoutBorderSpacePx.x * (columns - 1)
Thales Limaa1012902022-01-13 17:58:42 +0000502 - (cellWidthPx - iconSizePx) // left and right cell space
503 - iconSizePx * numShownHotseatIcons
504 - hotseatBorderSpace * numShownHotseatIcons;
505 }
506
Thales Limad90faab2021-09-21 17:18:47 +0100507 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
508 if (isVerticalBarLayout()) {
509 return 0;
510 }
511
Thales Lima83bedbf2021-10-05 17:47:39 +0100512 return isScalableGrid
513 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
514 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100515 }
516
Jon Miranda0d284852021-06-22 14:50:55 -0700517 private void updateHotseatIconSize(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700518 // Ensure there is enough space for folder icons, which have a slightly larger radius.
519 hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda0d284852021-06-22 14:50:55 -0700520 if (isVerticalBarLayout()) {
521 hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
522 + hotseatBarSidePaddingEndPx;
523 } else {
524 hotseatBarSizePx = hotseatIconSizePx + hotseatBarTopPaddingPx
Jon Miranda80cddbc2021-07-22 13:51:16 -0700525 + hotseatBarBottomPaddingPx + (isScalableGrid ? 0 : hotseatExtraVerticalSize)
526 + hotseatBarSizeExtraSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700527 }
528 }
529
Thales Lima78d00ad2021-09-30 11:29:06 +0100530 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100531 return getCellLayoutBorderSpace(idp, 1f);
532
533 }
534
535 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100536 if (!isScalableGrid) {
537 return new Point(0, 0);
538 }
539
Thales Lima080d8902022-03-28 15:30:29 +0100540 int horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
541 int verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
Thales Lima78d00ad2021-09-30 11:29:06 +0100542
543 return new Point(horizontalSpacePx, verticalSpacePx);
544 }
545
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700546 public Info getDisplayInfo() {
547 return mInfo;
548 }
549
Jon Miranda611dba42021-03-02 14:12:13 -0500550 /**
551 * We inset the widget padding added by the system and instead rely on the border spacing
552 * between cells to create reliable consistency between widgets
553 */
554 public boolean shouldInsetWidgets() {
555 Rect widgetPadding = inv.defaultWidgetPadding;
556
Jon Miranda49811182021-06-03 09:52:40 -0700557 // Check all sides to ensure that the widget won't overlap into another cell, or into
558 // status bar.
559 return workspaceTopPadding > widgetPadding.top
Thales Lima78d00ad2021-09-30 11:29:06 +0100560 && cellLayoutBorderSpacePx.x > widgetPadding.left
561 && cellLayoutBorderSpacePx.y > widgetPadding.top
562 && cellLayoutBorderSpacePx.x > widgetPadding.right
563 && cellLayoutBorderSpacePx.y > widgetPadding.bottom;
Jon Miranda611dba42021-03-02 14:12:13 -0500564 }
Jon Mirandae126d722021-02-25 10:45:20 -0500565
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700566 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800567 WindowBounds bounds = new WindowBounds(
568 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700569 bounds.bounds.offsetTo(windowX, windowY);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700570 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700571 .setWindowBounds(bounds)
572 .setUseTwoPanels(isTwoPanels)
Alex Chau6ed408f2022-03-04 12:58:05 +0000573 .setMultiWindowMode(isMultiWindowMode)
574 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800575 }
576
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700577 public DeviceProfile copy(Context context) {
578 return toBuilder(context).build();
579 }
580
581 /**
582 * TODO: Move this to the builder as part of setMultiWindowMode
583 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700584 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700585 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700586 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700587 .setMultiWindowMode(true)
588 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800589
Jon Miranda941375e2021-03-31 13:10:45 -0400590 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda93e1f042016-11-11 14:13:04 -0800591
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800592 // We use these scales to measure and layout the widgets using their full invariant profile
593 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
594 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
595 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
596 profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY);
Pat Manninge3723662022-03-25 16:07:46 +0000597 profile.updateWorkspacePadding();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800598
Jon Miranda93e1f042016-11-11 14:13:04 -0800599 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700600 }
601
Adam Cohen63f1ec02014-08-12 09:23:13 -0700602 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400603 * Checks if there is enough space for labels on the workspace.
604 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700605 * It is important to call this method after the All Apps variables have been set.
606 */
Jon Miranda941375e2021-03-31 13:10:45 -0400607 private void hideWorkspaceLabelsIfNotEnoughSpace() {
608 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
609 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
610 - iconTextHeight;
611
612 // We want enough space so that the text is closer to its corresponding icon.
613 if (workspaceCellPaddingY < iconTextHeight) {
614 iconTextSizePx = 0;
615 iconDrawablePaddingPx = 0;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700616 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda941375e2021-03-31 13:10:45 -0400617 autoResizeAllAppsCells();
618 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700619 }
Jon Miranda1091e532017-07-21 13:31:50 -0700620
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700621 /**
622 * Re-computes the all-apps cell size to be independent of workspace
623 */
624 public void autoResizeAllAppsCells() {
Jon Miranda941375e2021-03-31 13:10:45 -0400625 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
626 int topBottomPadding = textHeight;
Jon Miranda1091e532017-07-21 13:31:50 -0700627 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
Jon Miranda941375e2021-03-31 13:10:45 -0400628 + textHeight + (topBottomPadding * 2);
Jon Miranda1091e532017-07-21 13:31:50 -0700629 }
630
Thales Limab7ef5692022-03-10 10:32:36 +0000631 private void updateAllAppsContainerWidth(Resources res) {
Pat Manninge3723662022-03-25 16:07:46 +0000632
Alex Chau27b39b92022-01-14 18:02:18 +0000633 if (isTablet) {
Thales Limab7ef5692022-03-10 10:32:36 +0000634 allAppsLeftRightPadding =
Pat Manninge3723662022-03-25 16:07:46 +0000635 res.getDimensionPixelSize(R.dimen.all_apps_bottom_sheet_horizontal_padding)
636 + cellLayoutPaddingLeftRightPx;
sfufa@google.comde013292021-09-21 18:22:44 -0700637 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
Thales Limab7ef5692022-03-10 10:32:36 +0000638 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Alex Chau27b39b92022-01-14 18:02:18 +0000639 + allAppsLeftRightPadding * 2;
640 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
sfufa@google.comde013292021-09-21 18:22:44 -0700641 } else {
642 allAppsLeftRightPadding =
Pat Manninge3723662022-03-25 16:07:46 +0000643 desiredWorkspaceHorizontalMarginPx + cellLayoutPaddingLeftRightPx;
sfufa@google.comde013292021-09-21 18:22:44 -0700644 }
645 }
646
Jon Miranda228877d2021-02-09 11:05:00 -0500647 /**
648 * Returns the amount of extra (or unused) vertical space.
649 */
650 private int updateAvailableDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700651 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800652
Jon Mirandae126d722021-02-25 10:45:20 -0500653 Point workspacePadding = getTotalWorkspacePadding();
654
655 // Check to see if the icons fit within the available height.
656 float usedHeight = getCellLayoutHeight();
Pat Manninge3723662022-03-25 16:07:46 +0000657 final int maxHeight = availableHeightPx - workspacePadding.y;
Jon Miranda228877d2021-02-09 11:05:00 -0500658 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500659 float scaleY = maxHeight / usedHeight;
660 boolean shouldScale = scaleY < 1f;
661
662 float scaleX = 1f;
663 if (isScalableGrid) {
664 // We scale to fit the cellWidth and cellHeight in the available space.
665 // The benefit of scalable grids is that we can get consistent aspect ratios between
666 // devices.
Pat Manninge3723662022-03-25 16:07:46 +0000667 int numColumns = isTwoPanels ? inv.numColumns * 2 : inv.numColumns;
668 float usedWidth = (cellWidthPx * numColumns)
669 + (cellLayoutBorderSpacePx.x * (numColumns - 1))
670 + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500671 // We do not subtract padding here, as we also scale the workspace padding if needed.
672 scaleX = availableWidthPx / usedWidth;
673 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700674 }
Jon Mirandae126d722021-02-25 10:45:20 -0500675
676 if (shouldScale) {
677 float scale = Math.min(scaleX, scaleY);
678 updateIconSize(scale, res);
679 extraHeight = Math.max(0, maxHeight - getCellLayoutHeight());
680 }
681
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700682 updateAvailableFolderCellDimensions(res);
Jon Miranda228877d2021-02-09 11:05:00 -0500683 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700684 }
685
Jon Mirandae126d722021-02-25 10:45:20 -0500686 private int getCellLayoutHeight() {
Pat Manninge3723662022-03-25 16:07:46 +0000687 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1));
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
Winson Chungb3800242013-10-24 11:01:54 -0700738 // Hotseat
Thales Limadd027342022-01-07 12:54:37 +0000739 hotseatBorderSpace = pxFromDp(inv.hotseatBorderSpaces[mTypeIndex], mMetrics, scale);
Thales Limaa1012902022-01-13 17:58:42 +0000740 if (isQsbInline) {
741 qsbWidth = calculateQsbWidth();
742 } else {
743 qsbWidth = 0;
744 }
Jon Miranda0d284852021-06-22 14:50:55 -0700745 updateHotseatIconSize(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700746
Pat Manninge3723662022-03-25 16:07:46 +0000747 if (!isVerticalLayout) {
748 int expectedWorkspaceHeight = availableHeightPx - hotseatBarSizePx
749 - workspacePageIndicatorHeight - edgeMarginPx;
750 float minRequiredHeight = dropTargetBarSizePx + workspaceSpringLoadedBottomSpace;
751 workspaceSpringLoadShrinkFactor = Math.min(
752 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f,
753 1 - (minRequiredHeight / expectedWorkspaceHeight));
754 } else {
755 workspaceSpringLoadShrinkFactor =
756 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
757 }
758
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700759 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -0700760 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
761 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Winson Chung0f785722015-04-08 10:27:49 -0700762 }
763
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500764
765 /**
766 * Updates the iconSize for allApps* variants.
767 */
768 public void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +0100769 allAppsBorderSpacePx = new Point(
770 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
771 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
772 if (isScalableGrid) {
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500773 allAppsIconSizePx =
774 pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
775 allAppsIconTextSizePx =
776 pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
777 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Thales Lima080d8902022-03-28 15:30:29 +0100778 // AllApps cells don't have real space between cells,
779 // so we add the border space to the cell height
780 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics, scale)
781 + allAppsBorderSpacePx.y;
782 // but width is just the cell,
783 // the border is added in #updateAllAppsContainerWidth
Thales Limab7ef5692022-03-10 10:32:36 +0000784 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500785 } else {
786 float invIconSizeDp = inv.iconSize[mTypeIndex];
787 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
788 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
789 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
790 allAppsIconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * scale);
Thales Limab7ef5692022-03-10 10:32:36 +0000791 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500792 allAppsCellHeightPx = getCellSize().y;
793 }
794
Thales Limab7ef5692022-03-10 10:32:36 +0000795 updateAllAppsContainerWidth(res);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500796 if (isVerticalBarLayout()) {
797 hideWorkspaceLabelsIfNotEnoughSpace();
798 }
799 }
800
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700801 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700802 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700803
Jon Mirandae126d722021-02-25 10:45:20 -0500804 final int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_height);
805
Jon Mirandac1b23992016-12-13 08:57:36 -0800806 // Don't let the folder get too close to the edges of the screen.
Jon Miranda1786df32018-09-25 13:05:23 -0700807 int folderMargin = edgeMarginPx * 2;
Sunny Goyal07b69292018-01-08 14:19:34 -0800808 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -0800809
810 // Check if the icons fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -0500811 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Thales Lima78d00ad2021-09-30 11:29:06 +0100812 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx.y);
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800813 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderBottomPanelSize
Jon Mirandae126d722021-02-25 10:45:20 -0500814 - folderMargin - folderContentPaddingTop;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800815 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -0800816
817 // Check if the icons fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -0500818 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Thales Lima78d00ad2021-09-30 11:29:06 +0100819 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x);
Jon Mirandae126d722021-02-25 10:45:20 -0500820 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin
821 - folderContentPaddingLeftRight * 2;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800822 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -0800823
824 float scale = Math.min(scaleX, scaleY);
825 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700826 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700827 }
828 }
829
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700830 private void updateFolderCellSize(float scale, Resources res) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100831 float invIconSizeDp = isVerticalBarLayout()
Thales Lima12d0eff2022-03-25 17:06:11 +0000832 ? inv.iconSize[INDEX_LANDSCAPE]
833 : inv.iconSize[INDEX_DEFAULT];
Sunny Goyal35c7b192021-04-20 16:51:10 -0700834 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Thales Lima83bedbf2021-10-05 17:47:39 +0100835 folderChildTextSizePx =
Thales Lima12d0eff2022-03-25 17:06:11 +0000836 pxFromSp(inv.iconTextSize[INDEX_DEFAULT], mMetrics, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500837 folderLabelTextSizePx = (int) (folderChildTextSizePx * folderLabelTextScale);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700838
839 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700840
Jon Miranda823da222021-03-23 08:08:45 -0400841 if (isScalableGrid) {
Jon Mirandaf33f5b32021-07-22 17:15:31 -0700842 int minWidth = folderChildIconSizePx + iconDrawablePaddingPx * 2;
843 int minHeight = folderChildIconSizePx + iconDrawablePaddingPx * 2 + textHeight;
844
845 folderCellWidthPx = (int) Math.max(minWidth, cellWidthPx * scale);
846 folderCellHeightPx = (int) Math.max(minHeight, cellHeightPx * scale);
Jon Miranda823da222021-03-23 08:08:45 -0400847
Thales Lima78d00ad2021-09-30 11:29:06 +0100848 int scaledSpace = (int) (folderCellLayoutBorderSpaceOriginalPx * scale);
849 folderCellLayoutBorderSpacePx = new Point(scaledSpace, scaledSpace);
850 folderContentPaddingLeftRight = scaledSpace;
851 folderContentPaddingTop = scaledSpace;
Jon Miranda823da222021-03-23 08:08:45 -0400852 } else {
853 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
854 * scale);
855 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
856 * scale);
857
858 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
859 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
860 }
861
Jonathan Miranda9ad87462017-07-26 17:41:02 +0000862 folderChildDrawablePaddingPx = Math.max(0,
863 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700864 }
865
Winson1f064272016-07-18 17:18:02 -0700866 public void updateInsets(Rect insets) {
867 mInsets.set(insets);
Pat Manninge3723662022-03-25 16:07:46 +0000868 updateWorkspacePadding();
Winson1f064272016-07-18 17:18:02 -0700869 }
870
Sunny Goyalae6e3182019-04-30 12:04:37 -0700871 /**
872 * The current device insets. This is generally same as the insets being dispatched to
873 * {@link Insettable} elements, but can differ if the element is using a different profile.
874 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800875 public Rect getInsets() {
876 return mInsets;
877 }
878
Sunny Goyal756cd262015-08-20 12:33:21 -0700879 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700880 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700881 }
882
Sunny Goyal19ff7282021-04-22 10:12:54 -0700883 public Point getCellSize(Point result) {
884 if (result == null) {
885 result = new Point();
886 }
Thales Limad1df5fc2021-09-03 18:37:19 +0100887
Sunny Goyal756cd262015-08-20 12:33:21 -0700888 // Since we are only concerned with the overall padding, layout direction does
889 // not matter.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700890 Point padding = getTotalWorkspacePadding();
Thales Limad1df5fc2021-09-03 18:37:19 +0100891
892 int numColumns = isTwoPanels ? inv.numColumns * 2 : inv.numColumns;
Alex Chau60953332021-11-24 12:41:07 +0000893 int screenWidthPx = getWorkspaceWidth(padding);
Thales Lima78d00ad2021-09-30 11:29:06 +0100894 result.x = calculateCellWidth(screenWidthPx, cellLayoutBorderSpacePx.x, numColumns);
Pat Manninge3723662022-03-25 16:07:46 +0000895 result.y = calculateCellHeight(availableHeightPx - padding.y
896 - cellLayoutBottomPaddingPx, cellLayoutBorderSpacePx.y, inv.numRows);
Sunny Goyal756cd262015-08-20 12:33:21 -0700897 return result;
898 }
899
Alex Chau60953332021-11-24 12:41:07 +0000900 public int getWorkspaceWidth() {
901 return getWorkspaceWidth(getTotalWorkspacePadding());
902 }
903
904 public int getWorkspaceWidth(Point workspacePadding) {
905 int cellLayoutTotalPadding =
Pat Manninge3723662022-03-25 16:07:46 +0000906 isTwoPanels ? 4 * cellLayoutPaddingLeftRightPx : 2 * cellLayoutPaddingLeftRightPx;
Alex Chau60953332021-11-24 12:41:07 +0000907 return availableWidthPx - workspacePadding.x - cellLayoutTotalPadding;
908 }
909
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700910 public Point getTotalWorkspacePadding() {
Pat Manninge3723662022-03-25 16:07:46 +0000911 updateWorkspacePadding();
Sunny Goyal07b69292018-01-08 14:19:34 -0800912 return new Point(workspacePadding.left + workspacePadding.right,
913 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700914 }
915
916 /**
Sunny Goyal07b69292018-01-08 14:19:34 -0800917 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
918 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700919 */
Sunny Goyal07b69292018-01-08 14:19:34 -0800920 private void updateWorkspacePadding() {
921 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -0700922 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -0800923 padding.top = 0;
924 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800925 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700926 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -0700927 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -0700928 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -0700929 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700930 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -0700931 }
Winson Chungb3800242013-10-24 11:01:54 -0700932 } else {
Thales Lima7a6752d2021-09-23 14:31:00 +0100933 // Pad the bottom of the workspace with search/hotseat bar sizes
Tony Wickham21970cc2021-09-15 15:44:05 -0700934 int hotseatTop = hotseatBarSizePx;
Tony Wickhama29a0462021-03-02 12:28:25 -0800935 int paddingBottom = hotseatTop + workspacePageIndicatorHeight
Jon Miranda228877d2021-02-09 11:05:00 -0500936 + workspaceBottomPadding - mWorkspacePageIndicatorOverlapWorkspace;
Andras Kloczl8e57cce2021-02-11 23:51:19 +0100937
Pat Manninge3723662022-03-25 16:07:46 +0000938 padding.set(desiredWorkspaceHorizontalMarginPx,
939 workspaceTopPadding + (isScalableGrid ? 0 : edgeMarginPx),
940 desiredWorkspaceHorizontalMarginPx,
941 paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -0700942 }
Winson Chungb3800242013-10-24 11:01:54 -0700943 }
944
Sunny Goyal57b22792021-05-25 14:35:01 -0700945 /**
946 * Returns the padding for hotseat view
947 */
948 public Rect getHotseatLayoutPadding(Context context) {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700949 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -0700950 // The hotseat icons will be placed in the middle of the hotseat cells.
951 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
952 // in vertical bar layout.
953 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
954 // is set to account for that difference.
955 float diffOverlapFactor = iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
Pat Manninge3723662022-03-25 16:07:46 +0000956 int paddingTop = Math.max((int) (mInsets.top - diffOverlapFactor), 0);
957 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutBottomPaddingPx
Sihua Ma38bb3b02022-03-21 22:20:14 -0700958 + diffOverlapFactor), 0);
959
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700960 if (isSeascape()) {
Pat Manninge3723662022-03-25 16:07:46 +0000961 mHotseatPadding.set(mInsets.left + hotseatBarSidePaddingStartPx,
962 mInsets.top, hotseatBarSidePaddingEndPx, mInsets.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700963 } else {
Pat Manninge3723662022-03-25 16:07:46 +0000964 mHotseatPadding.set(hotseatBarSidePaddingEndPx, mInsets.top,
965 mInsets.right + hotseatBarSidePaddingStartPx, mInsets.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700966 }
Sunny Goyal57b22792021-05-25 14:35:01 -0700967 } else if (isTaskbarPresent) {
Tony Wickham21970cc2021-09-15 15:44:05 -0700968 int hotseatHeight = workspacePadding.bottom;
Sunny Goyal57b22792021-05-25 14:35:01 -0700969 int taskbarOffset = getTaskbarOffsetY();
Thales Limaa1012902022-01-13 17:58:42 +0000970 int additionalLeftSpace = 0;
971
972 // Center the QSB with hotseat and push icons to the right
973 if (isQsbInline) {
974 additionalLeftSpace = qsbWidth + hotseatBorderSpace;
975 }
976
Thales Lima7d149232022-03-21 18:27:45 +0000977 int hotseatTopPadding = hotseatHeight - taskbarOffset - hotseatCellHeightPx;
Sunny Goyal57b22792021-05-25 14:35:01 -0700978
Vinit Nayak8dcbde82021-07-19 12:53:28 -0700979 int endOffset = ApiWrapper.getHotseatEndOffset(context);
Thales Lima6e7f36c2022-01-04 12:14:11 +0000980 int requiredWidth = iconSizePx * numShownHotseatIcons
Thales Limaa1012902022-01-13 17:58:42 +0000981 + hotseatBorderSpace * (numShownHotseatIcons - 1)
982 + additionalLeftSpace;
Sunny Goyal57b22792021-05-25 14:35:01 -0700983
Thales Lima6e7f36c2022-01-04 12:14:11 +0000984 int hotseatSize = Math.min(requiredWidth, availableWidthPx - endOffset);
Sunny Goyal57b22792021-05-25 14:35:01 -0700985 int sideSpacing = (availableWidthPx - hotseatSize) / 2;
Thales Lima7d149232022-03-21 18:27:45 +0000986 mHotseatPadding.set(sideSpacing + additionalLeftSpace, hotseatTopPadding, sideSpacing,
Thales Limaa1012902022-01-13 17:58:42 +0000987 taskbarOffset);
Sunny Goyal57b22792021-05-25 14:35:01 -0700988
Vinit Nayak8dcbde82021-07-19 12:53:28 -0700989 if (endOffset > sideSpacing) {
Sunny Goyal57b22792021-05-25 14:35:01 -0700990 int diff = Utilities.isRtl(context.getResources())
Vinit Nayak8dcbde82021-07-19 12:53:28 -0700991 ? sideSpacing - endOffset
992 : endOffset - sideSpacing;
993 mHotseatPadding.left -= diff;
994 mHotseatPadding.right += diff;
Sunny Goyal57b22792021-05-25 14:35:01 -0700995 }
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700996 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700997 // We want the edges of the hotseat to line up with the edges of the workspace, but the
998 // icons in the hotseat are a different size, and so don't line up perfectly. To account
999 // for this, we pad the left and right of the hotseat with half of the difference of a
1000 // workspace cell vs a hotseat cell.
1001 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001002 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001003 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manninge3723662022-03-25 16:07:46 +00001004 mHotseatPadding.set(
1005 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingLeftRightPx
1006 + mInsets.left,
1007 hotseatBarTopPaddingPx,
1008 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx
Sunny Goyal786940a2020-06-02 02:31:31 -07001009 + mInsets.right,
Jon Miranda0d284852021-06-22 14:50:55 -07001010 hotseatBarSizePx - hotseatCellHeightPx - hotseatBarTopPaddingPx
Pat Manninge3723662022-03-25 16:07:46 +00001011 + cellLayoutBottomPaddingPx + mInsets.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001012 }
1013 return mHotseatPadding;
1014 }
1015
Winsonfadbe8f2016-07-22 16:35:37 -07001016 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001017 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1018 */
1019 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001020 if (isQsbInline) {
1021 return hotseatBarBottomPaddingPx;
1022 }
1023
Sunny Goyal57b22792021-05-25 14:35:01 -07001024 int freeSpace = isTaskbarPresent
1025 ? workspacePadding.bottom
1026 : hotseatBarSizePx - hotseatCellHeightPx - hotseatQsbHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001027
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001028 if (isScalableGrid && qsbBottomMarginPx > mInsets.bottom) {
Tony Wickham21970cc2021-09-15 15:44:05 -07001029 // Note that taskbarSize = 0 unless isTaskbarPresent.
1030 return Math.min(qsbBottomMarginPx + taskbarSize, freeSpace);
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001031 } else {
Pratyush9afe1ea2021-10-13 11:13:27 +00001032 return (int) (freeSpace * mQsbCenterFactor)
1033 + (isTaskbarPresent ? taskbarSize : mInsets.bottom);
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001034 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001035 }
1036
1037 /**
1038 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1039 */
1040 public int getTaskbarOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001041 if (isQsbInline) {
1042 return getQsbOffsetY() + (Math.abs(hotseatQsbHeight - iconSizePx) / 2);
1043 } else {
1044 return (getQsbOffsetY() - taskbarSize) / 2;
1045 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001046 }
1047
1048 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001049 * @return the bounds for which the open folders should be contained within
1050 */
1051 public Rect getAbsoluteOpenFolderBounds() {
1052 if (isVerticalBarLayout()) {
1053 // Folders should only appear right of the drop target bar and left of the hotseat
1054 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1055 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001056 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001057 mInsets.top + availableHeightPx);
1058 } else {
1059 // Folders should only appear below the drop target bar and above the hotseat
Tony Wickhamae72b462021-03-10 16:18:40 -08001060 int hotseatTop = isTaskbarPresent ? taskbarSize : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001061 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001062 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001063 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001064 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001065 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001066 }
1067 }
1068
Jon Miranda228877d2021-02-09 11:05:00 -05001069 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1070 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001071 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001072
Jon Miranda228877d2021-02-09 11:05:00 -05001073 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1074 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001075 }
1076
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001077 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001078 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1079 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1080 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001081 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001082 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001083 return isLandscape && transposeLayoutWithOrientation;
1084 }
1085
Sunny Goyal59d086c2018-05-07 17:31:40 -07001086 /**
1087 * Updates orientation information and returns true if it has changed from the previous value.
1088 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001089 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001090 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001091 boolean isSeascape = DisplayController.INSTANCE.get(context)
1092 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001093 if (mIsSeascape != isSeascape) {
1094 mIsSeascape = isSeascape;
1095 return true;
1096 }
1097 }
1098 return false;
1099 }
1100
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001101 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001102 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001103 }
1104
Sunny Goyal07b69292018-01-08 14:19:34 -08001105 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001106 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001107 }
1108
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001109 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001110 switch (containerType) {
1111 case CellLayout.WORKSPACE:
1112 return cellHeightPx;
1113 case CellLayout.FOLDER:
1114 return folderCellHeightPx;
1115 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001116 // The hotseat is the only container where the cell height is going to be
1117 // different from the content within that cell.
1118 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001119 default:
1120 // ??
1121 return 0;
1122 }
1123 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001124
Jon Miranda58561d42021-03-17 10:51:54 -04001125 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001126 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001127 }
1128
1129 public void dump(String prefix, PrintWriter writer) {
1130 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001131 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001132
1133 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001134 writer.println(prefix + "\tisPhone:" + isPhone);
1135 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1136 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001137 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001138
1139 writer.println(prefix + "\tisLandscape:" + isLandscape);
1140 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001141 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001142
1143 writer.println(prefix + pxToDpStr("windowX", windowX));
1144 writer.println(prefix + pxToDpStr("windowY", windowY));
1145 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1146 writer.println(prefix + pxToDpStr("heightPx", heightPx));
1147
1148 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1149 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
1150
1151 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1152
1153 writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
1154
Thales Lima83bedbf2021-10-05 17:47:39 +01001155 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001156 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1157 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1158 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001159
Thales Lima83bedbf2021-10-05 17:47:39 +01001160 writer.println(prefix + "\tminCellSize: " + inv.minCellSize[mTypeIndex] + "dp");
Jon Mirandaab3c6812021-06-28 15:42:28 -07001161
Jon Miranda58561d42021-03-17 10:51:54 -04001162 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1163 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1164
1165 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1166 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1167
Thales Lima83bedbf2021-10-05 17:47:39 +01001168 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1169 cellLayoutBorderSpacePx.x));
1170 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1171 cellLayoutBorderSpacePx.y));
1172
Jon Miranda58561d42021-03-17 10:51:54 -04001173 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1174 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1175 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1176
1177 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1178 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1179 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1180 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1181 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1182 folderChildDrawablePaddingPx));
Thales Lima78d00ad2021-09-30 11:29:06 +01001183 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpaceOriginalPx",
1184 folderCellLayoutBorderSpaceOriginalPx));
1185 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx Horizontal",
1186 folderCellLayoutBorderSpacePx.x));
1187 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx Vertical",
1188 folderCellLayoutBorderSpacePx.y));
Jon Miranda58561d42021-03-17 10:51:54 -04001189
Jon Miranda58561d42021-03-17 10:51:54 -04001190 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1191 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1192 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1193 allAppsIconDrawablePaddingPx));
1194 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001195 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Thales Limab7ef5692022-03-10 10:32:36 +00001196 writer.println(prefix + pxToDpStr("allAppsBorderSpacePx", allAppsBorderSpacePx.x));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001197 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau27b39b92022-01-14 18:02:18 +00001198 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
1199 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001200
1201 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
1202 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
1203 writer.println(prefix + pxToDpStr("hotseatBarTopPaddingPx", hotseatBarTopPaddingPx));
1204 writer.println(prefix + pxToDpStr("hotseatBarBottomPaddingPx", hotseatBarBottomPaddingPx));
1205 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
1206 hotseatBarSidePaddingStartPx));
1207 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
1208 hotseatBarSidePaddingEndPx));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001209 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001210 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001211 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
1212 writer.println(prefix + pxToDpStr("qsbWidth", qsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001213
1214 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001215 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda58561d42021-03-17 10:51:54 -04001216 writer.println(prefix + pxToDpStr("taskbarSize", taskbarSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001217
Thales Lima83bedbf2021-10-05 17:47:39 +01001218 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1219 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001220 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
1221 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
1222 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
1223 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
1224
Jon Mirandaab3c6812021-06-28 15:42:28 -07001225 writer.println(prefix + pxToDpStr("iconScale", iconScale));
1226 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04001227 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Thales Lima7a6752d2021-09-23 14:31:00 +01001228 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001229
1230 if (inv.devicePaddings != null) {
1231 int unscaledExtraSpace = (int) (extraSpace / iconScale);
1232 writer.println(prefix + pxToDpStr("maxEmptySpace",
1233 inv.devicePaddings.getDevicePadding(unscaledExtraSpace).getMaxEmptySpacePx()));
1234 }
Jon Miranda58561d42021-03-17 10:51:54 -04001235 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
1236 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
1237 writer.println(prefix + pxToDpStr("extraHotseatBottomPadding", extraHotseatBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00001238
1239 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
1240 writer.println(prefix + pxToDpStr("overviewTaskMarginGridPx", overviewTaskMarginGridPx));
1241 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
1242 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
1243 overviewTaskIconDrawableSizePx));
1244 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
1245 overviewTaskIconDrawableSizeGridPx));
1246 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
1247 overviewTaskThumbnailTopMarginPx));
1248 writer.println(prefix + pxToDpStr("overviewActionsMarginThreeButtonPx",
1249 overviewActionsMarginThreeButtonPx));
1250 writer.println(prefix + pxToDpStr("overviewActionsTopMarginGesturePx",
1251 overviewActionsTopMarginGesturePx));
1252 writer.println(prefix + pxToDpStr("overviewActionsBottomMarginGesturePx",
1253 overviewActionsBottomMarginGesturePx));
1254 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
1255 overviewActionsButtonSpacing));
1256 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
1257 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
1258 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001259 }
1260
Alex Chaua6907dc2022-03-18 15:24:07 +00001261 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07001262 Configuration config = new Configuration(c.getResources().getConfiguration());
1263 config.orientation = orientation;
Sunny Goyal35c7b192021-04-20 16:51:10 -07001264 config.densityDpi = info.densityDpi;
Alex Chaua6907dc2022-03-18 15:24:07 +00001265 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07001266 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07001267 }
Sunny Goyalfde55052018-02-01 14:46:13 -08001268
1269 /**
1270 * Callback when a component changes the DeviceProfile associated with it, as a result of
1271 * configuration change
1272 */
1273 public interface OnDeviceProfileChangeListener {
1274
1275 /**
1276 * Called when the device profile is reassigned. Note that for layout and measurements, it
1277 * is sufficient to listen for inset changes. Use this callback when you need to perform
1278 * a one time operation.
1279 */
1280 void onDeviceProfileChanged(DeviceProfile dp);
1281 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001282
Brian Isganitis099945b2022-01-31 18:15:00 -05001283 /** Allows registering listeners for {@link DeviceProfile} changes. */
1284 public interface DeviceProfileListenable {
1285
1286 /** The current device profile. */
1287 DeviceProfile getDeviceProfile();
1288
1289 /** Registered {@link OnDeviceProfileChangeListener} instances. */
1290 List<OnDeviceProfileChangeListener> getOnDeviceProfileChangeListeners();
1291
1292 /** Notifies listeners of a {@link DeviceProfile} change. */
1293 default void dispatchDeviceProfileChanged() {
1294 DeviceProfile deviceProfile = getDeviceProfile();
1295 List<OnDeviceProfileChangeListener> listeners = getOnDeviceProfileChangeListeners();
1296 for (int i = listeners.size() - 1; i >= 0; i--) {
1297 listeners.get(i).onDeviceProfileChanged(deviceProfile);
1298 }
1299 }
1300
1301 /** Register listener for {@link DeviceProfile} changes. */
1302 default void addOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
1303 getOnDeviceProfileChangeListeners().add(listener);
1304 }
1305
1306 /** Unregister listener for {@link DeviceProfile} changes. */
1307 default void removeOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
1308 getOnDeviceProfileChangeListeners().remove(listener);
1309 }
1310 }
1311
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001312 public static class Builder {
1313 private Context mContext;
1314 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07001315 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001316
Sunny Goyal19ff7282021-04-22 10:12:54 -07001317 private WindowBounds mWindowBounds;
1318 private boolean mUseTwoPanels;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001319
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001320 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001321 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00001322 private Boolean mIsGestureMode;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001323
Sunny Goyalfd58da62020-08-11 12:06:49 -07001324 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001325 mContext = context;
1326 mInv = inv;
1327 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001328 }
1329
1330 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1331 mIsMultiWindowMode = isMultiWindowMode;
1332 return this;
1333 }
1334
Sunny Goyal19ff7282021-04-22 10:12:54 -07001335 public Builder setUseTwoPanels(boolean useTwoPanels) {
1336 mUseTwoPanels = useTwoPanels;
1337 return this;
1338 }
1339
1340
1341 public Builder setWindowBounds(WindowBounds bounds) {
1342 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07001343 return this;
1344 }
1345
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001346 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1347 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1348 return this;
1349 }
1350
Alex Chau6ed408f2022-03-04 12:58:05 +00001351 public Builder setGestureMode(boolean isGestureMode) {
1352 mIsGestureMode = isGestureMode;
1353 return this;
1354 }
1355
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001356 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001357 if (mWindowBounds == null) {
1358 throw new IllegalArgumentException("Window bounds not set");
1359 }
1360 if (mTransposeLayoutWithOrientation == null) {
1361 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
1362 }
Alex Chau6ed408f2022-03-04 12:58:05 +00001363 if (mIsGestureMode == null) {
1364 mIsGestureMode = DisplayController.getNavigationMode(mContext).hasGestures;
1365 }
1366 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mIsMultiWindowMode,
1367 mTransposeLayoutWithOrientation, mUseTwoPanels, mIsGestureMode);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001368 }
1369 }
1370
Winson Chungb3800242013-10-24 11:01:54 -07001371}