blob: d8956c2f83d028b5a2aca4dc36d679b25af7a14f [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;
Alex Chaue0227552022-04-06 19:44:43 +0100249 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700250
Jon Mirandae126d722021-02-25 10:45:20 -0500251 isScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
252
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000253 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700254 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000255 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700256 isPhone = !isTablet;
Alex Chau90125822021-11-17 14:16:58 +0000257 isTwoPanels = isTablet && useTwoPanels;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800258 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700259
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000260 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000261 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700262 ? Configuration.ORIENTATION_LANDSCAPE
Alex Chaua6907dc2022-03-18 15:24:07 +0000263 : Configuration.ORIENTATION_PORTRAIT,
264 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700265 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000266 mMetrics = res.getDisplayMetrics();
267
268 // Determine sizes.
269 widthPx = windowBounds.bounds.width();
270 heightPx = windowBounds.bounds.height();
271 availableWidthPx = windowBounds.availableSize.x;
Alex Chau6a7d1e22022-01-20 19:54:17 +0000272 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000273
274 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
275 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
276 mQsbCenterFactor = res.getFloat(R.dimen.qsb_center_factor);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700277
Thales Lima83bedbf2021-10-05 17:47:39 +0100278 if (isTwoPanels) {
279 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000280 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100281 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000282 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100283 }
284 } else {
285 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000286 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100287 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000288 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100289 }
290 }
291
Tony Wickham15883892021-02-12 11:24:40 -0800292 if (isTaskbarPresent) {
Tony Wickham15883892021-02-12 11:24:40 -0800293 taskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_size);
Alex Chau6a7d1e22022-01-20 19:54:17 +0000294 stashedTaskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
Tony Wickham15883892021-02-12 11:24:40 -0800295 }
Tony Wickham15883892021-02-12 11:24:40 -0800296
Winson Chungb3800242013-10-24 11:01:54 -0700297 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700298
Thales Limad90faab2021-09-21 17:18:47 +0100299 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
300 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
Samuel Fufaee9aff92021-04-05 13:30:40 -0500301
Alex Chaue0227552022-04-06 19:44:43 +0100302 bottomSheetTopPadding = mInsets.top // statusbar height
Andras Kloczl142b0542022-03-09 21:26:02 +0000303 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
304 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
305
306 allAppsTopPadding = isTablet ? bottomSheetTopPadding : 0;
Alex Chaub8c22e12022-02-14 18:35:58 +0000307 allAppsShiftRange = isTablet
308 ? heightPx - allAppsTopPadding
309 : res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500310
Jon Mirandae126d722021-02-25 10:45:20 -0500311 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
312 folderContentPaddingLeftRight =
313 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
314 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_content_padding_top);
315
Thales Lima78d00ad2021-09-30 11:29:06 +0100316 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv);
Thales Lima85c942f2021-12-31 13:04:20 +0000317 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000318 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
319 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Thales Lima78d00ad2021-09-30 11:29:06 +0100320 cellLayoutBorderSpaceOriginalPx = new Point(cellLayoutBorderSpacePx);
Thales Lima080d8902022-03-28 15:30:29 +0100321 folderCellLayoutBorderSpaceOriginalPx = pxFromDp(inv.folderBorderSpace, mMetrics);
Thales Lima78d00ad2021-09-30 11:29:06 +0100322 folderCellLayoutBorderSpacePx = new Point(folderCellLayoutBorderSpaceOriginalPx,
323 folderCellLayoutBorderSpaceOriginalPx);
Jon Mirandae126d722021-02-25 10:45:20 -0500324
Pat Manninge3723662022-03-25 16:07:46 +0000325 int cellLayoutPaddingLeftRightMultiplier = !isVerticalBarLayout() && isTablet
326 ? PORTRAIT_TABLET_LEFT_RIGHT_PADDING_MULTIPLIER : 1;
327 int cellLayoutPadding = isScalableGrid
328 ? 0
329 : res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_padding);
330
331 if (isTwoPanels) {
332 cellLayoutPaddingLeftRightPx = 0;
333 cellLayoutBottomPaddingPx = 0;
334 } else if (isLandscape) {
335 cellLayoutPaddingLeftRightPx = 0;
336 cellLayoutBottomPaddingPx = cellLayoutPadding;
337 } else {
338 cellLayoutPaddingLeftRightPx = cellLayoutPaddingLeftRightMultiplier * cellLayoutPadding;
339 cellLayoutBottomPaddingPx = 0;
340 }
341
Tony Wickham5edf9e22020-03-27 20:06:52 -0700342 workspacePageIndicatorHeight = res.getDimensionPixelSize(
343 R.dimen.workspace_page_indicator_height);
344 mWorkspacePageIndicatorOverlapWorkspace =
345 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700346
Winson Chungb3800242013-10-24 11:01:54 -0700347 iconDrawablePaddingOriginalPx =
348 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Alex Chaua02eddc2021-04-29 00:36:06 +0100349
Sunny Goyal47328fd2016-05-25 18:56:41 -0700350 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Alex Chaua02eddc2021-04-29 00:36:06 +0100351 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
352 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
353
Sunny Goyal47328fd2016-05-25 18:56:41 -0700354 workspaceSpringLoadedBottomSpace =
355 res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space);
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 Lima12d0eff2022-03-25 17:06:11 +0000360 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
361 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
362 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
363 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
364 && hotseatQsbHeight > 0;
365 isQsbInline = inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000366
Alex Chau8175da92022-03-09 11:19:47 +0000367 // We shrink hotseat sizes regardless of orientation, if nav buttons are inline and QSB
368 // might be inline in either orientations, to keep hotseat size consistent across rotation.
369 boolean areNavButtonsInline = isTaskbarPresent && !isGestureMode;
370 if (areNavButtonsInline && canQsbInline) {
Alex Chau6ed408f2022-03-04 12:58:05 +0000371 numShownHotseatIcons = inv.numShrunkenHotseatIcons;
372 } else {
373 numShownHotseatIcons =
374 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
375 }
376
Sunny Goyal19ff7282021-04-22 10:12:54 -0700377 numShownAllAppsColumns =
378 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700379 hotseatBarSizeExtraSpacePx = 0;
Winson1f064272016-07-18 17:18:02 -0700380 hotseatBarTopPaddingPx =
381 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding);
Thales Limaa1012902022-01-13 17:58:42 +0000382 if (isQsbInline) {
383 hotseatBarBottomPaddingPx = res.getDimensionPixelSize(R.dimen.inline_qsb_bottom_margin);
384 qsbWidth = calculateQsbWidth();
385 } else {
386 hotseatBarBottomPaddingPx = (isTallDevice ? res.getDimensionPixelSize(
387 R.dimen.dynamic_grid_hotseat_bottom_tall_padding)
388 : res.getDimensionPixelSize(
389 R.dimen.dynamic_grid_hotseat_bottom_non_tall_padding))
390 + res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_padding);
391 qsbWidth = 0;
392 }
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700393 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800394 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700395 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700396 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Jon Miranda0d284852021-06-22 14:50:55 -0700397 hotseatExtraVerticalSize =
Jon Miranda228877d2021-02-09 11:05:00 -0500398 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_extra_vertical_size);
Thales Lima6e7f36c2022-01-04 12:14:11 +0000399 hotseatBorderSpace = pxFromDp(inv.hotseatBorderSpaces[mTypeIndex], mMetrics);
Thales Lima83bedbf2021-10-05 17:47:39 +0100400 updateHotseatIconSize(
Thales Lima12d0eff2022-03-25 17:06:11 +0000401 pxFromDp(inv.iconSize[INDEX_DEFAULT], mMetrics));
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700402
Jon Miranda8bdb2222021-06-23 18:10:10 -0700403 qsbBottomMarginOriginalPx = isScalableGrid
404 ? res.getDimensionPixelSize(R.dimen.scalable_grid_qsb_bottom_margin)
405 : 0;
406
Alex Chau635b3ab2022-01-26 16:49:10 +0000407 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chaueaa6d682021-08-17 12:56:15 +0100408 overviewTaskMarginGridPx = res.getDimensionPixelSize(R.dimen.overview_task_margin_grid);
Alex Chau5fd9d492021-07-22 17:27:11 +0100409 overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100410 overviewTaskIconDrawableSizePx =
411 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
412 overviewTaskIconDrawableSizeGridPx =
413 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Alex Chaudedbc8a2021-03-17 16:53:26 +0000414 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx * 2;
Alex Chau635b3ab2022-01-26 16:49:10 +0000415 overviewActionsTopMarginGesturePx = res.getDimensionPixelSize(
416 R.dimen.overview_actions_top_margin_gesture);
417 overviewActionsBottomMarginGesturePx = res.getDimensionPixelSize(
418 R.dimen.overview_actions_bottom_margin_gesture);
419 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
420 overviewActionsButtonSpacing = res.getDimensionPixelSize(
421 R.dimen.overview_actions_button_spacing);
Alex Chau19c6eca2022-03-10 20:12:56 +0000422 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
zakcohendad8a802021-05-20 09:52:26 -0700423 overviewActionsMarginThreeButtonPx = res.getDimensionPixelSize(
Alex Chau5fd9d492021-07-22 17:27:11 +0100424 R.dimen.overview_actions_margin_three_button);
Alex Chau4c983742021-12-10 13:09:53 +0000425 // Grid task's top margin is only overviewTaskIconSizePx + overviewTaskMarginGridPx, but
426 // overviewTaskThumbnailTopMarginPx is applied to all TaskThumbnailView, so exclude the
427 // extra margin when calculating row spacing.
428 int extraTopMargin = overviewTaskThumbnailTopMarginPx - overviewTaskIconSizePx
429 - overviewTaskMarginGridPx;
430 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing)
431 - extraTopMargin;
Alex Chau635b3ab2022-01-26 16:49:10 +0000432 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700433
Jon Miranda2ed276e2017-06-29 11:36:34 -0700434 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400435 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700436
Jon Miranda2ed276e2017-06-29 11:36:34 -0700437 // Now that we have all of the variables calculated, we can tune certain sizes.
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400438 if (isScalableGrid && inv.devicePaddings != null) {
439 // Paddings were created assuming no scaling, so we first unscale the extra space.
Jon Mirandaab3c6812021-06-28 15:42:28 -0700440 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400441 DevicePadding padding = inv.devicePaddings.getDevicePadding(unscaledExtraSpace);
Jon Miranda228877d2021-02-09 11:05:00 -0500442
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400443 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
444 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
445 int paddingHotseatBottom = padding.getHotseatBottomPadding(unscaledExtraSpace);
446
Jon Mirandaab3c6812021-06-28 15:42:28 -0700447 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
448 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
449 extraHotseatBottomPadding = Math.round(paddingHotseatBottom * cellScaleToFit);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400450
Jon Miranda58561d42021-03-17 10:51:54 -0400451 hotseatBarSizePx += extraHotseatBottomPadding;
Jon Miranda8bdb2222021-06-23 18:10:10 -0700452
Jon Mirandaab3c6812021-06-28 15:42:28 -0700453 qsbBottomMarginPx = Math.round(qsbBottomMarginOriginalPx * cellScaleToFit);
Jon Miranda228877d2021-02-09 11:05:00 -0500454 } else if (!isVerticalBarLayout() && isPhone && isTallDevice) {
Jon Miranda3f9bab22017-07-28 14:50:17 -0700455 // We increase the hotseat size when there is extra space.
Jon Miranda80cddbc2021-07-22 13:51:16 -0700456
Jon Miranda80dda302021-07-28 14:14:59 -0700457 if (Float.compare(aspectRatio, TALLER_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0
458 && extraSpace >= Utilities.dpToPx(TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP)) {
459 // For taller devices, we will take a piece of the extra space from each row,
Jon Miranda80cddbc2021-07-22 13:51:16 -0700460 // and add it to the space above and below the hotseat.
Jon Miranda80dda302021-07-28 14:14:59 -0700461
462 // For devices with more extra space, we take a larger piece from each cell.
463 int piece = extraSpace < Utilities.dpToPx(TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP)
Jon Mirandaa56cb842021-08-03 17:26:44 -0700464 ? 7 : 5;
Jon Miranda80dda302021-07-28 14:14:59 -0700465
Jon Miranda80cddbc2021-07-22 13:51:16 -0700466 int extraSpace = ((getCellSize().y - iconSizePx - iconDrawablePaddingPx * 2)
Jon Miranda80dda302021-07-28 14:14:59 -0700467 * inv.numRows) / piece;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700468
Jon Mirandaa56cb842021-08-03 17:26:44 -0700469 workspaceTopPadding = extraSpace / 8;
470 int halfLeftOver = (extraSpace - workspaceTopPadding) / 2;
471 hotseatBarTopPaddingPx += halfLeftOver;
472 hotseatBarSizeExtraSpacePx = halfLeftOver;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700473 } else {
474 // ie. For a display with a large aspect ratio, we can keep the icons on the
475 // workspace in portrait mode closer together by adding more height to the hotseat.
476 // Note: This calculation was created after noticing a pattern in the design spec.
477 hotseatBarSizeExtraSpacePx = getCellSize().y - iconSizePx
478 - iconDrawablePaddingPx * 2 - workspacePageIndicatorHeight;
479 }
480
481 updateHotseatIconSize(iconSizePx);
Jon Miranda30d0aa22017-07-25 15:55:29 -0700482
Jon Miranda3f9bab22017-07-28 14:50:17 -0700483 // Recalculate the available dimensions using the new hotseat size.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700484 updateAvailableDimensions(res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700485 }
Sunny Goyal07b69292018-01-08 14:19:34 -0800486 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800487
Alex Chaua02eddc2021-04-29 00:36:06 +0100488 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
489 R.dimen.drag_flingToDeleteMinVelocity);
490
Tony Wickham1237df02017-02-24 08:59:36 -0800491 // This is done last, after iconSizePx is calculated above.
Sunny Goyal8b9919d2021-04-07 14:45:17 -0700492 Path dotPath = GraphicsUtils.getShapePath(DEFAULT_DOT_SIZE);
493 mDotRendererWorkSpace = new DotRenderer(iconSizePx, dotPath, DEFAULT_DOT_SIZE);
Samuel Fufac96fa242019-09-26 23:06:32 -0700494 mDotRendererAllApps = iconSizePx == allAppsIconSizePx ? mDotRendererWorkSpace :
Sunny Goyal8b9919d2021-04-07 14:45:17 -0700495 new DotRenderer(allAppsIconSizePx, dotPath, DEFAULT_DOT_SIZE);
Adam Cohen63f1ec02014-08-12 09:23:13 -0700496 }
497
Thales Limaa1012902022-01-13 17:58:42 +0000498 private int calculateQsbWidth() {
Thales Lima2903a622022-03-17 13:52:19 +0000499 int columns = isTwoPanels ? inv.numColumns * 2 : inv.numColumns;
500
501 return cellWidthPx * columns
502 + cellLayoutBorderSpacePx.x * (columns - 1)
Thales Limaa1012902022-01-13 17:58:42 +0000503 - (cellWidthPx - iconSizePx) // left and right cell space
504 - iconSizePx * numShownHotseatIcons
505 - hotseatBorderSpace * numShownHotseatIcons;
506 }
507
Thales Limad90faab2021-09-21 17:18:47 +0100508 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
509 if (isVerticalBarLayout()) {
510 return 0;
511 }
512
Thales Lima83bedbf2021-10-05 17:47:39 +0100513 return isScalableGrid
514 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
515 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100516 }
517
Jon Miranda0d284852021-06-22 14:50:55 -0700518 private void updateHotseatIconSize(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700519 // Ensure there is enough space for folder icons, which have a slightly larger radius.
520 hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda0d284852021-06-22 14:50:55 -0700521 if (isVerticalBarLayout()) {
522 hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
523 + hotseatBarSidePaddingEndPx;
524 } else {
525 hotseatBarSizePx = hotseatIconSizePx + hotseatBarTopPaddingPx
Jon Miranda80cddbc2021-07-22 13:51:16 -0700526 + hotseatBarBottomPaddingPx + (isScalableGrid ? 0 : hotseatExtraVerticalSize)
527 + hotseatBarSizeExtraSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700528 }
529 }
530
Thales Lima78d00ad2021-09-30 11:29:06 +0100531 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100532 return getCellLayoutBorderSpace(idp, 1f);
533
534 }
535
536 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100537 if (!isScalableGrid) {
538 return new Point(0, 0);
539 }
540
Thales Lima080d8902022-03-28 15:30:29 +0100541 int horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
542 int verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
Thales Lima78d00ad2021-09-30 11:29:06 +0100543
544 return new Point(horizontalSpacePx, verticalSpacePx);
545 }
546
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700547 public Info getDisplayInfo() {
548 return mInfo;
549 }
550
Jon Miranda611dba42021-03-02 14:12:13 -0500551 /**
552 * We inset the widget padding added by the system and instead rely on the border spacing
553 * between cells to create reliable consistency between widgets
554 */
555 public boolean shouldInsetWidgets() {
556 Rect widgetPadding = inv.defaultWidgetPadding;
557
Jon Miranda49811182021-06-03 09:52:40 -0700558 // Check all sides to ensure that the widget won't overlap into another cell, or into
559 // status bar.
560 return workspaceTopPadding > widgetPadding.top
Thales Lima78d00ad2021-09-30 11:29:06 +0100561 && cellLayoutBorderSpacePx.x > widgetPadding.left
562 && cellLayoutBorderSpacePx.y > widgetPadding.top
563 && cellLayoutBorderSpacePx.x > widgetPadding.right
564 && cellLayoutBorderSpacePx.y > widgetPadding.bottom;
Jon Miranda611dba42021-03-02 14:12:13 -0500565 }
Jon Mirandae126d722021-02-25 10:45:20 -0500566
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700567 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800568 WindowBounds bounds = new WindowBounds(
569 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700570 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100571 bounds.insets.set(mInsets);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700572 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700573 .setWindowBounds(bounds)
574 .setUseTwoPanels(isTwoPanels)
Alex Chau6ed408f2022-03-04 12:58:05 +0000575 .setMultiWindowMode(isMultiWindowMode)
576 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800577 }
578
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700579 public DeviceProfile copy(Context context) {
580 return toBuilder(context).build();
581 }
582
583 /**
584 * TODO: Move this to the builder as part of setMultiWindowMode
585 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700586 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700587 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700588 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700589 .setMultiWindowMode(true)
590 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800591
Jon Miranda941375e2021-03-31 13:10:45 -0400592 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda93e1f042016-11-11 14:13:04 -0800593
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800594 // We use these scales to measure and layout the widgets using their full invariant profile
595 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
596 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
597 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
598 profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY);
Pat Manninge3723662022-03-25 16:07:46 +0000599 profile.updateWorkspacePadding();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800600
Jon Miranda93e1f042016-11-11 14:13:04 -0800601 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700602 }
603
Adam Cohen63f1ec02014-08-12 09:23:13 -0700604 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400605 * Checks if there is enough space for labels on the workspace.
606 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700607 * It is important to call this method after the All Apps variables have been set.
608 */
Jon Miranda941375e2021-03-31 13:10:45 -0400609 private void hideWorkspaceLabelsIfNotEnoughSpace() {
610 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
611 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
612 - iconTextHeight;
613
614 // We want enough space so that the text is closer to its corresponding icon.
615 if (workspaceCellPaddingY < iconTextHeight) {
616 iconTextSizePx = 0;
617 iconDrawablePaddingPx = 0;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700618 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda941375e2021-03-31 13:10:45 -0400619 autoResizeAllAppsCells();
620 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700621 }
Jon Miranda1091e532017-07-21 13:31:50 -0700622
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700623 /**
624 * Re-computes the all-apps cell size to be independent of workspace
625 */
626 public void autoResizeAllAppsCells() {
Jon Miranda941375e2021-03-31 13:10:45 -0400627 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
628 int topBottomPadding = textHeight;
Jon Miranda1091e532017-07-21 13:31:50 -0700629 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
Jon Miranda941375e2021-03-31 13:10:45 -0400630 + textHeight + (topBottomPadding * 2);
Jon Miranda1091e532017-07-21 13:31:50 -0700631 }
632
Thales Limab7ef5692022-03-10 10:32:36 +0000633 private void updateAllAppsContainerWidth(Resources res) {
Pat Manninge3723662022-03-25 16:07:46 +0000634
Alex Chau27b39b92022-01-14 18:02:18 +0000635 if (isTablet) {
Thales Limab7ef5692022-03-10 10:32:36 +0000636 allAppsLeftRightPadding =
Pat Manninge3723662022-03-25 16:07:46 +0000637 res.getDimensionPixelSize(R.dimen.all_apps_bottom_sheet_horizontal_padding)
638 + cellLayoutPaddingLeftRightPx;
sfufa@google.comde013292021-09-21 18:22:44 -0700639 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
Thales Limab7ef5692022-03-10 10:32:36 +0000640 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Alex Chau27b39b92022-01-14 18:02:18 +0000641 + allAppsLeftRightPadding * 2;
642 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
sfufa@google.comde013292021-09-21 18:22:44 -0700643 } else {
644 allAppsLeftRightPadding =
Pat Manninge3723662022-03-25 16:07:46 +0000645 desiredWorkspaceHorizontalMarginPx + cellLayoutPaddingLeftRightPx;
sfufa@google.comde013292021-09-21 18:22:44 -0700646 }
647 }
648
Jon Miranda228877d2021-02-09 11:05:00 -0500649 /**
650 * Returns the amount of extra (or unused) vertical space.
651 */
652 private int updateAvailableDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700653 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800654
Jon Mirandae126d722021-02-25 10:45:20 -0500655 Point workspacePadding = getTotalWorkspacePadding();
656
657 // Check to see if the icons fit within the available height.
658 float usedHeight = getCellLayoutHeight();
Pat Manninge3723662022-03-25 16:07:46 +0000659 final int maxHeight = availableHeightPx - workspacePadding.y;
Jon Miranda228877d2021-02-09 11:05:00 -0500660 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500661 float scaleY = maxHeight / usedHeight;
662 boolean shouldScale = scaleY < 1f;
663
664 float scaleX = 1f;
665 if (isScalableGrid) {
666 // We scale to fit the cellWidth and cellHeight in the available space.
667 // The benefit of scalable grids is that we can get consistent aspect ratios between
668 // devices.
Pat Manninge3723662022-03-25 16:07:46 +0000669 int numColumns = isTwoPanels ? inv.numColumns * 2 : inv.numColumns;
670 float usedWidth = (cellWidthPx * numColumns)
671 + (cellLayoutBorderSpacePx.x * (numColumns - 1))
672 + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500673 // We do not subtract padding here, as we also scale the workspace padding if needed.
674 scaleX = availableWidthPx / usedWidth;
675 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700676 }
Jon Mirandae126d722021-02-25 10:45:20 -0500677
678 if (shouldScale) {
679 float scale = Math.min(scaleX, scaleY);
680 updateIconSize(scale, res);
681 extraHeight = Math.max(0, maxHeight - getCellLayoutHeight());
682 }
683
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700684 updateAvailableFolderCellDimensions(res);
Jon Miranda228877d2021-02-09 11:05:00 -0500685 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700686 }
687
Jon Mirandae126d722021-02-25 10:45:20 -0500688 private int getCellLayoutHeight() {
Pat Manninge3723662022-03-25 16:07:46 +0000689 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1));
Jon Mirandae126d722021-02-25 10:45:20 -0500690 }
691
Jon Miranda6f7e9702019-09-16 14:44:14 -0700692 /**
693 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
694 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
695 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
696 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800697 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -0700698 // Icon scale should never exceed 1, otherwise pixellation may occur.
699 iconScale = Math.min(1f, scale);
700 cellScaleToFit = scale;
701
Jon Miranda18751b62017-07-31 17:25:27 -0700702 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800703 final boolean isVerticalLayout = isVerticalBarLayout();
Thales Lima83bedbf2021-10-05 17:47:39 +0100704 float invIconSizeDp = inv.iconSize[mTypeIndex];
705 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
Andras Kloczl30fe9152021-08-05 18:02:29 +0200706
Jon Mirandaab3c6812021-06-28 15:42:28 -0700707 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, iconScale));
Jon Mirandaab3c6812021-06-28 15:42:28 -0700708 iconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * iconScale);
709 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700710
Thales Lima080d8902022-03-28 15:30:29 +0100711 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500712
713 if (isScalableGrid) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100714 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
715 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500716 int cellContentHeight = iconSizePx + iconDrawablePaddingPx
717 + Utilities.calculateTextHeight(iconTextSizePx);
718 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +0100719 desiredWorkspaceHorizontalMarginPx =
720 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -0500721 } else {
Jon Mirandae126d722021-02-25 10:45:20 -0500722 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700723 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR)
724 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -0500725 + Utilities.calculateTextHeight(iconTextSizePx);
726 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
727 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
728 && !isMultiWindowMode) {
729 // Ensures that the label is closer to its corresponding icon. This is not an issue
730 // with vertical bar layout or multi-window mode since the issue is handled
731 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
732 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
733 iconDrawablePaddingPx = cellPaddingY;
734 }
Jon Miranda846455e2017-10-02 14:58:52 -0700735 }
Jon Miranda18751b62017-07-31 17:25:27 -0700736
Sunny Goyalae190ff2020-04-14 00:19:01 +0000737 // All apps
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500738 updateAllAppsIconSize(scale, res);
Winson Chungb3800242013-10-24 11:01:54 -0700739
Winson Chungb3800242013-10-24 11:01:54 -0700740 // Hotseat
Thales Limadd027342022-01-07 12:54:37 +0000741 hotseatBorderSpace = pxFromDp(inv.hotseatBorderSpaces[mTypeIndex], mMetrics, scale);
Thales Limaa1012902022-01-13 17:58:42 +0000742 if (isQsbInline) {
743 qsbWidth = calculateQsbWidth();
744 } else {
745 qsbWidth = 0;
746 }
Jon Miranda0d284852021-06-22 14:50:55 -0700747 updateHotseatIconSize(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700748
Pat Manninge3723662022-03-25 16:07:46 +0000749 if (!isVerticalLayout) {
750 int expectedWorkspaceHeight = availableHeightPx - hotseatBarSizePx
751 - workspacePageIndicatorHeight - edgeMarginPx;
752 float minRequiredHeight = dropTargetBarSizePx + workspaceSpringLoadedBottomSpace;
753 workspaceSpringLoadShrinkFactor = Math.min(
754 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f,
755 1 - (minRequiredHeight / expectedWorkspaceHeight));
756 } else {
757 workspaceSpringLoadShrinkFactor =
758 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
759 }
760
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700761 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -0700762 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
763 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Winson Chung0f785722015-04-08 10:27:49 -0700764 }
765
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500766
767 /**
768 * Updates the iconSize for allApps* variants.
769 */
770 public void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +0100771 allAppsBorderSpacePx = new Point(
772 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
773 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
774 if (isScalableGrid) {
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500775 allAppsIconSizePx =
776 pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
777 allAppsIconTextSizePx =
778 pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
779 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Thales Lima080d8902022-03-28 15:30:29 +0100780 // AllApps cells don't have real space between cells,
781 // so we add the border space to the cell height
782 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics, scale)
783 + allAppsBorderSpacePx.y;
784 // but width is just the cell,
785 // the border is added in #updateAllAppsContainerWidth
Thales Limab7ef5692022-03-10 10:32:36 +0000786 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500787 } else {
788 float invIconSizeDp = inv.iconSize[mTypeIndex];
789 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
790 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
791 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
792 allAppsIconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * scale);
Thales Limab7ef5692022-03-10 10:32:36 +0000793 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500794 allAppsCellHeightPx = getCellSize().y;
795 }
796
Thales Limab7ef5692022-03-10 10:32:36 +0000797 updateAllAppsContainerWidth(res);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500798 if (isVerticalBarLayout()) {
799 hideWorkspaceLabelsIfNotEnoughSpace();
800 }
801 }
802
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700803 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700804 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700805
Jon Mirandae126d722021-02-25 10:45:20 -0500806 final int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_height);
807
Jon Mirandac1b23992016-12-13 08:57:36 -0800808 // Don't let the folder get too close to the edges of the screen.
Jon Miranda1786df32018-09-25 13:05:23 -0700809 int folderMargin = edgeMarginPx * 2;
Sunny Goyal07b69292018-01-08 14:19:34 -0800810 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -0800811
812 // Check if the icons fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -0500813 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Thales Lima78d00ad2021-09-30 11:29:06 +0100814 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx.y);
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800815 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderBottomPanelSize
Jon Mirandae126d722021-02-25 10:45:20 -0500816 - folderMargin - folderContentPaddingTop;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800817 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -0800818
819 // Check if the icons fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -0500820 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Thales Lima78d00ad2021-09-30 11:29:06 +0100821 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x);
Jon Mirandae126d722021-02-25 10:45:20 -0500822 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin
823 - folderContentPaddingLeftRight * 2;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800824 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -0800825
826 float scale = Math.min(scaleX, scaleY);
827 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700828 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700829 }
830 }
831
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700832 private void updateFolderCellSize(float scale, Resources res) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100833 float invIconSizeDp = isVerticalBarLayout()
Thales Lima12d0eff2022-03-25 17:06:11 +0000834 ? inv.iconSize[INDEX_LANDSCAPE]
835 : inv.iconSize[INDEX_DEFAULT];
Sunny Goyal35c7b192021-04-20 16:51:10 -0700836 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Thales Lima83bedbf2021-10-05 17:47:39 +0100837 folderChildTextSizePx =
Thales Lima12d0eff2022-03-25 17:06:11 +0000838 pxFromSp(inv.iconTextSize[INDEX_DEFAULT], mMetrics, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500839 folderLabelTextSizePx = (int) (folderChildTextSizePx * folderLabelTextScale);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700840
841 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700842
Jon Miranda823da222021-03-23 08:08:45 -0400843 if (isScalableGrid) {
Jon Mirandaf33f5b32021-07-22 17:15:31 -0700844 int minWidth = folderChildIconSizePx + iconDrawablePaddingPx * 2;
845 int minHeight = folderChildIconSizePx + iconDrawablePaddingPx * 2 + textHeight;
846
847 folderCellWidthPx = (int) Math.max(minWidth, cellWidthPx * scale);
848 folderCellHeightPx = (int) Math.max(minHeight, cellHeightPx * scale);
Jon Miranda823da222021-03-23 08:08:45 -0400849
Thales Lima78d00ad2021-09-30 11:29:06 +0100850 int scaledSpace = (int) (folderCellLayoutBorderSpaceOriginalPx * scale);
851 folderCellLayoutBorderSpacePx = new Point(scaledSpace, scaledSpace);
852 folderContentPaddingLeftRight = scaledSpace;
853 folderContentPaddingTop = scaledSpace;
Jon Miranda823da222021-03-23 08:08:45 -0400854 } else {
855 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
856 * scale);
857 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
858 * scale);
859
860 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
861 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
862 }
863
Jonathan Miranda9ad87462017-07-26 17:41:02 +0000864 folderChildDrawablePaddingPx = Math.max(0,
865 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700866 }
867
Winson1f064272016-07-18 17:18:02 -0700868 public void updateInsets(Rect insets) {
869 mInsets.set(insets);
Pat Manninge3723662022-03-25 16:07:46 +0000870 updateWorkspacePadding();
Winson1f064272016-07-18 17:18:02 -0700871 }
872
Sunny Goyalae6e3182019-04-30 12:04:37 -0700873 /**
874 * The current device insets. This is generally same as the insets being dispatched to
875 * {@link Insettable} elements, but can differ if the element is using a different profile.
876 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800877 public Rect getInsets() {
878 return mInsets;
879 }
880
Sunny Goyal756cd262015-08-20 12:33:21 -0700881 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700882 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700883 }
884
Sunny Goyal19ff7282021-04-22 10:12:54 -0700885 public Point getCellSize(Point result) {
886 if (result == null) {
887 result = new Point();
888 }
Thales Limad1df5fc2021-09-03 18:37:19 +0100889
Sunny Goyal756cd262015-08-20 12:33:21 -0700890 // Since we are only concerned with the overall padding, layout direction does
891 // not matter.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700892 Point padding = getTotalWorkspacePadding();
Thales Limad1df5fc2021-09-03 18:37:19 +0100893
894 int numColumns = isTwoPanels ? inv.numColumns * 2 : inv.numColumns;
Alex Chau60953332021-11-24 12:41:07 +0000895 int screenWidthPx = getWorkspaceWidth(padding);
Thales Lima78d00ad2021-09-30 11:29:06 +0100896 result.x = calculateCellWidth(screenWidthPx, cellLayoutBorderSpacePx.x, numColumns);
Pat Manninge3723662022-03-25 16:07:46 +0000897 result.y = calculateCellHeight(availableHeightPx - padding.y
898 - cellLayoutBottomPaddingPx, cellLayoutBorderSpacePx.y, inv.numRows);
Sunny Goyal756cd262015-08-20 12:33:21 -0700899 return result;
900 }
901
Alex Chau60953332021-11-24 12:41:07 +0000902 public int getWorkspaceWidth() {
903 return getWorkspaceWidth(getTotalWorkspacePadding());
904 }
905
906 public int getWorkspaceWidth(Point workspacePadding) {
907 int cellLayoutTotalPadding =
Pat Manninge3723662022-03-25 16:07:46 +0000908 isTwoPanels ? 4 * cellLayoutPaddingLeftRightPx : 2 * cellLayoutPaddingLeftRightPx;
Alex Chau60953332021-11-24 12:41:07 +0000909 return availableWidthPx - workspacePadding.x - cellLayoutTotalPadding;
910 }
911
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700912 public Point getTotalWorkspacePadding() {
Pat Manninge3723662022-03-25 16:07:46 +0000913 updateWorkspacePadding();
Sunny Goyal07b69292018-01-08 14:19:34 -0800914 return new Point(workspacePadding.left + workspacePadding.right,
915 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700916 }
917
918 /**
Sunny Goyal07b69292018-01-08 14:19:34 -0800919 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
920 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700921 */
Sunny Goyal07b69292018-01-08 14:19:34 -0800922 private void updateWorkspacePadding() {
923 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -0700924 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -0800925 padding.top = 0;
926 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800927 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700928 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -0700929 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -0700930 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -0700931 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700932 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -0700933 }
Winson Chungb3800242013-10-24 11:01:54 -0700934 } else {
Thales Lima7a6752d2021-09-23 14:31:00 +0100935 // Pad the bottom of the workspace with search/hotseat bar sizes
Tony Wickham21970cc2021-09-15 15:44:05 -0700936 int hotseatTop = hotseatBarSizePx;
Tony Wickhama29a0462021-03-02 12:28:25 -0800937 int paddingBottom = hotseatTop + workspacePageIndicatorHeight
Jon Miranda228877d2021-02-09 11:05:00 -0500938 + workspaceBottomPadding - mWorkspacePageIndicatorOverlapWorkspace;
Andras Kloczl8e57cce2021-02-11 23:51:19 +0100939
Pat Manninge3723662022-03-25 16:07:46 +0000940 padding.set(desiredWorkspaceHorizontalMarginPx,
941 workspaceTopPadding + (isScalableGrid ? 0 : edgeMarginPx),
942 desiredWorkspaceHorizontalMarginPx,
943 paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -0700944 }
Winson Chungb3800242013-10-24 11:01:54 -0700945 }
946
Sunny Goyal57b22792021-05-25 14:35:01 -0700947 /**
948 * Returns the padding for hotseat view
949 */
950 public Rect getHotseatLayoutPadding(Context context) {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700951 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -0700952 // The hotseat icons will be placed in the middle of the hotseat cells.
953 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
954 // in vertical bar layout.
955 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
956 // is set to account for that difference.
957 float diffOverlapFactor = iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
Pat Manninge3723662022-03-25 16:07:46 +0000958 int paddingTop = Math.max((int) (mInsets.top - diffOverlapFactor), 0);
959 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutBottomPaddingPx
Sihua Ma38bb3b02022-03-21 22:20:14 -0700960 + diffOverlapFactor), 0);
961
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700962 if (isSeascape()) {
Pat Manninge3723662022-03-25 16:07:46 +0000963 mHotseatPadding.set(mInsets.left + hotseatBarSidePaddingStartPx,
964 mInsets.top, hotseatBarSidePaddingEndPx, mInsets.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700965 } else {
Pat Manninge3723662022-03-25 16:07:46 +0000966 mHotseatPadding.set(hotseatBarSidePaddingEndPx, mInsets.top,
967 mInsets.right + hotseatBarSidePaddingStartPx, mInsets.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700968 }
Sunny Goyal57b22792021-05-25 14:35:01 -0700969 } else if (isTaskbarPresent) {
Tony Wickham21970cc2021-09-15 15:44:05 -0700970 int hotseatHeight = workspacePadding.bottom;
Sunny Goyal57b22792021-05-25 14:35:01 -0700971 int taskbarOffset = getTaskbarOffsetY();
Thales Limaa1012902022-01-13 17:58:42 +0000972 int additionalLeftSpace = 0;
973
974 // Center the QSB with hotseat and push icons to the right
975 if (isQsbInline) {
976 additionalLeftSpace = qsbWidth + hotseatBorderSpace;
977 }
978
Thales Lima7d149232022-03-21 18:27:45 +0000979 int hotseatTopPadding = hotseatHeight - taskbarOffset - hotseatCellHeightPx;
Sunny Goyal57b22792021-05-25 14:35:01 -0700980
Vinit Nayak8dcbde82021-07-19 12:53:28 -0700981 int endOffset = ApiWrapper.getHotseatEndOffset(context);
Thales Lima6e7f36c2022-01-04 12:14:11 +0000982 int requiredWidth = iconSizePx * numShownHotseatIcons
Thales Limaa1012902022-01-13 17:58:42 +0000983 + hotseatBorderSpace * (numShownHotseatIcons - 1)
984 + additionalLeftSpace;
Sunny Goyal57b22792021-05-25 14:35:01 -0700985
Thales Lima6e7f36c2022-01-04 12:14:11 +0000986 int hotseatSize = Math.min(requiredWidth, availableWidthPx - endOffset);
Sunny Goyal57b22792021-05-25 14:35:01 -0700987 int sideSpacing = (availableWidthPx - hotseatSize) / 2;
Thales Lima7d149232022-03-21 18:27:45 +0000988 mHotseatPadding.set(sideSpacing + additionalLeftSpace, hotseatTopPadding, sideSpacing,
Thales Limaa1012902022-01-13 17:58:42 +0000989 taskbarOffset);
Sunny Goyal57b22792021-05-25 14:35:01 -0700990
Vinit Nayak8dcbde82021-07-19 12:53:28 -0700991 if (endOffset > sideSpacing) {
Sunny Goyal57b22792021-05-25 14:35:01 -0700992 int diff = Utilities.isRtl(context.getResources())
Vinit Nayak8dcbde82021-07-19 12:53:28 -0700993 ? sideSpacing - endOffset
994 : endOffset - sideSpacing;
995 mHotseatPadding.left -= diff;
996 mHotseatPadding.right += diff;
Sunny Goyal57b22792021-05-25 14:35:01 -0700997 }
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700998 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700999 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1000 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1001 // for this, we pad the left and right of the hotseat with half of the difference of a
1002 // workspace cell vs a hotseat cell.
1003 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001004 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001005 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manninge3723662022-03-25 16:07:46 +00001006 mHotseatPadding.set(
1007 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingLeftRightPx
1008 + mInsets.left,
1009 hotseatBarTopPaddingPx,
1010 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx
Sunny Goyal786940a2020-06-02 02:31:31 -07001011 + mInsets.right,
Jon Miranda0d284852021-06-22 14:50:55 -07001012 hotseatBarSizePx - hotseatCellHeightPx - hotseatBarTopPaddingPx
Pat Manninge3723662022-03-25 16:07:46 +00001013 + cellLayoutBottomPaddingPx + mInsets.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001014 }
1015 return mHotseatPadding;
1016 }
1017
Winsonfadbe8f2016-07-22 16:35:37 -07001018 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001019 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1020 */
1021 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001022 if (isQsbInline) {
1023 return hotseatBarBottomPaddingPx;
1024 }
1025
Sunny Goyal57b22792021-05-25 14:35:01 -07001026 int freeSpace = isTaskbarPresent
1027 ? workspacePadding.bottom
1028 : hotseatBarSizePx - hotseatCellHeightPx - hotseatQsbHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001029
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001030 if (isScalableGrid && qsbBottomMarginPx > mInsets.bottom) {
Tony Wickham21970cc2021-09-15 15:44:05 -07001031 // Note that taskbarSize = 0 unless isTaskbarPresent.
1032 return Math.min(qsbBottomMarginPx + taskbarSize, freeSpace);
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001033 } else {
Pratyush9afe1ea2021-10-13 11:13:27 +00001034 return (int) (freeSpace * mQsbCenterFactor)
1035 + (isTaskbarPresent ? taskbarSize : mInsets.bottom);
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001036 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001037 }
1038
1039 /**
1040 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1041 */
1042 public int getTaskbarOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001043 if (isQsbInline) {
1044 return getQsbOffsetY() + (Math.abs(hotseatQsbHeight - iconSizePx) / 2);
1045 } else {
1046 return (getQsbOffsetY() - taskbarSize) / 2;
1047 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001048 }
1049
1050 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001051 * @return the bounds for which the open folders should be contained within
1052 */
1053 public Rect getAbsoluteOpenFolderBounds() {
1054 if (isVerticalBarLayout()) {
1055 // Folders should only appear right of the drop target bar and left of the hotseat
1056 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1057 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001058 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001059 mInsets.top + availableHeightPx);
1060 } else {
1061 // Folders should only appear below the drop target bar and above the hotseat
Tony Wickhamae72b462021-03-10 16:18:40 -08001062 int hotseatTop = isTaskbarPresent ? taskbarSize : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001063 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001064 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001065 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001066 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001067 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001068 }
1069 }
1070
Jon Miranda228877d2021-02-09 11:05:00 -05001071 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1072 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001073 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001074
Jon Miranda228877d2021-02-09 11:05:00 -05001075 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1076 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001077 }
1078
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001079 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001080 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1081 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1082 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001083 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001084 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001085 return isLandscape && transposeLayoutWithOrientation;
1086 }
1087
Sunny Goyal59d086c2018-05-07 17:31:40 -07001088 /**
1089 * Updates orientation information and returns true if it has changed from the previous value.
1090 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001091 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001092 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001093 boolean isSeascape = DisplayController.INSTANCE.get(context)
1094 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001095 if (mIsSeascape != isSeascape) {
1096 mIsSeascape = isSeascape;
1097 return true;
1098 }
1099 }
1100 return false;
1101 }
1102
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001103 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001104 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001105 }
1106
Sunny Goyal07b69292018-01-08 14:19:34 -08001107 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001108 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001109 }
1110
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001111 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001112 switch (containerType) {
1113 case CellLayout.WORKSPACE:
1114 return cellHeightPx;
1115 case CellLayout.FOLDER:
1116 return folderCellHeightPx;
1117 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001118 // The hotseat is the only container where the cell height is going to be
1119 // different from the content within that cell.
1120 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001121 default:
1122 // ??
1123 return 0;
1124 }
1125 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001126
Jon Miranda58561d42021-03-17 10:51:54 -04001127 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001128 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001129 }
1130
1131 public void dump(String prefix, PrintWriter writer) {
1132 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001133 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001134
1135 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001136 writer.println(prefix + "\tisPhone:" + isPhone);
1137 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1138 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001139 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001140
1141 writer.println(prefix + "\tisLandscape:" + isLandscape);
1142 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001143 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001144
1145 writer.println(prefix + pxToDpStr("windowX", windowX));
1146 writer.println(prefix + pxToDpStr("windowY", windowY));
1147 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1148 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001149 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1150 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001151 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1152 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1153 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1154 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001155
1156 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1157
1158 writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
1159
Thales Lima83bedbf2021-10-05 17:47:39 +01001160 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001161 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1162 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1163 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001164
Thales Lima83bedbf2021-10-05 17:47:39 +01001165 writer.println(prefix + "\tminCellSize: " + inv.minCellSize[mTypeIndex] + "dp");
Jon Mirandaab3c6812021-06-28 15:42:28 -07001166
Jon Miranda58561d42021-03-17 10:51:54 -04001167 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1168 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1169
1170 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1171 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1172
Thales Lima83bedbf2021-10-05 17:47:39 +01001173 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1174 cellLayoutBorderSpacePx.x));
1175 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1176 cellLayoutBorderSpacePx.y));
1177
Jon Miranda58561d42021-03-17 10:51:54 -04001178 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1179 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1180 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1181
1182 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1183 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1184 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1185 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1186 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1187 folderChildDrawablePaddingPx));
Thales Lima78d00ad2021-09-30 11:29:06 +01001188 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpaceOriginalPx",
1189 folderCellLayoutBorderSpaceOriginalPx));
1190 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx Horizontal",
1191 folderCellLayoutBorderSpacePx.x));
1192 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx Vertical",
1193 folderCellLayoutBorderSpacePx.y));
Jon Miranda58561d42021-03-17 10:51:54 -04001194
Alex Chaue0227552022-04-06 19:44:43 +01001195 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
1196
1197 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
1198 writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding));
Jon Miranda58561d42021-03-17 10:51:54 -04001199 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1200 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1201 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1202 allAppsIconDrawablePaddingPx));
1203 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001204 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Thales Limab7ef5692022-03-10 10:32:36 +00001205 writer.println(prefix + pxToDpStr("allAppsBorderSpacePx", allAppsBorderSpacePx.x));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001206 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau27b39b92022-01-14 18:02:18 +00001207 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
1208 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001209
1210 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
1211 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
1212 writer.println(prefix + pxToDpStr("hotseatBarTopPaddingPx", hotseatBarTopPaddingPx));
1213 writer.println(prefix + pxToDpStr("hotseatBarBottomPaddingPx", hotseatBarBottomPaddingPx));
1214 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
1215 hotseatBarSidePaddingStartPx));
1216 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
1217 hotseatBarSidePaddingEndPx));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001218 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001219 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001220 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
1221 writer.println(prefix + pxToDpStr("qsbWidth", qsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001222
1223 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001224 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda58561d42021-03-17 10:51:54 -04001225 writer.println(prefix + pxToDpStr("taskbarSize", taskbarSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001226
Thales Lima83bedbf2021-10-05 17:47:39 +01001227 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1228 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001229 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
1230 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
1231 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
1232 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
1233
Jon Mirandaab3c6812021-06-28 15:42:28 -07001234 writer.println(prefix + pxToDpStr("iconScale", iconScale));
1235 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04001236 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Thales Lima7a6752d2021-09-23 14:31:00 +01001237 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001238
1239 if (inv.devicePaddings != null) {
1240 int unscaledExtraSpace = (int) (extraSpace / iconScale);
1241 writer.println(prefix + pxToDpStr("maxEmptySpace",
1242 inv.devicePaddings.getDevicePadding(unscaledExtraSpace).getMaxEmptySpacePx()));
1243 }
Jon Miranda58561d42021-03-17 10:51:54 -04001244 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
1245 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
1246 writer.println(prefix + pxToDpStr("extraHotseatBottomPadding", extraHotseatBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00001247
1248 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
1249 writer.println(prefix + pxToDpStr("overviewTaskMarginGridPx", overviewTaskMarginGridPx));
1250 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
1251 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
1252 overviewTaskIconDrawableSizePx));
1253 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
1254 overviewTaskIconDrawableSizeGridPx));
1255 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
1256 overviewTaskThumbnailTopMarginPx));
1257 writer.println(prefix + pxToDpStr("overviewActionsMarginThreeButtonPx",
1258 overviewActionsMarginThreeButtonPx));
1259 writer.println(prefix + pxToDpStr("overviewActionsTopMarginGesturePx",
1260 overviewActionsTopMarginGesturePx));
1261 writer.println(prefix + pxToDpStr("overviewActionsBottomMarginGesturePx",
1262 overviewActionsBottomMarginGesturePx));
1263 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
1264 overviewActionsButtonSpacing));
1265 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
1266 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
1267 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001268 }
1269
Alex Chaua6907dc2022-03-18 15:24:07 +00001270 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07001271 Configuration config = new Configuration(c.getResources().getConfiguration());
1272 config.orientation = orientation;
Sunny Goyal35c7b192021-04-20 16:51:10 -07001273 config.densityDpi = info.densityDpi;
Alex Chaua6907dc2022-03-18 15:24:07 +00001274 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07001275 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07001276 }
Sunny Goyalfde55052018-02-01 14:46:13 -08001277
1278 /**
1279 * Callback when a component changes the DeviceProfile associated with it, as a result of
1280 * configuration change
1281 */
1282 public interface OnDeviceProfileChangeListener {
1283
1284 /**
1285 * Called when the device profile is reassigned. Note that for layout and measurements, it
1286 * is sufficient to listen for inset changes. Use this callback when you need to perform
1287 * a one time operation.
1288 */
1289 void onDeviceProfileChanged(DeviceProfile dp);
1290 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001291
Brian Isganitis099945b2022-01-31 18:15:00 -05001292 /** Allows registering listeners for {@link DeviceProfile} changes. */
1293 public interface DeviceProfileListenable {
1294
1295 /** The current device profile. */
1296 DeviceProfile getDeviceProfile();
1297
1298 /** Registered {@link OnDeviceProfileChangeListener} instances. */
1299 List<OnDeviceProfileChangeListener> getOnDeviceProfileChangeListeners();
1300
1301 /** Notifies listeners of a {@link DeviceProfile} change. */
1302 default void dispatchDeviceProfileChanged() {
1303 DeviceProfile deviceProfile = getDeviceProfile();
1304 List<OnDeviceProfileChangeListener> listeners = getOnDeviceProfileChangeListeners();
1305 for (int i = listeners.size() - 1; i >= 0; i--) {
1306 listeners.get(i).onDeviceProfileChanged(deviceProfile);
1307 }
1308 }
1309
1310 /** Register listener for {@link DeviceProfile} changes. */
1311 default void addOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
1312 getOnDeviceProfileChangeListeners().add(listener);
1313 }
1314
1315 /** Unregister listener for {@link DeviceProfile} changes. */
1316 default void removeOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
1317 getOnDeviceProfileChangeListeners().remove(listener);
1318 }
1319 }
1320
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001321 public static class Builder {
1322 private Context mContext;
1323 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07001324 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001325
Sunny Goyal19ff7282021-04-22 10:12:54 -07001326 private WindowBounds mWindowBounds;
1327 private boolean mUseTwoPanels;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001328
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001329 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001330 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00001331 private Boolean mIsGestureMode;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001332
Sunny Goyalfd58da62020-08-11 12:06:49 -07001333 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001334 mContext = context;
1335 mInv = inv;
1336 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001337 }
1338
1339 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1340 mIsMultiWindowMode = isMultiWindowMode;
1341 return this;
1342 }
1343
Sunny Goyal19ff7282021-04-22 10:12:54 -07001344 public Builder setUseTwoPanels(boolean useTwoPanels) {
1345 mUseTwoPanels = useTwoPanels;
1346 return this;
1347 }
1348
1349
1350 public Builder setWindowBounds(WindowBounds bounds) {
1351 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07001352 return this;
1353 }
1354
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001355 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1356 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1357 return this;
1358 }
1359
Alex Chau6ed408f2022-03-04 12:58:05 +00001360 public Builder setGestureMode(boolean isGestureMode) {
1361 mIsGestureMode = isGestureMode;
1362 return this;
1363 }
1364
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001365 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001366 if (mWindowBounds == null) {
1367 throw new IllegalArgumentException("Window bounds not set");
1368 }
1369 if (mTransposeLayoutWithOrientation == null) {
1370 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
1371 }
Alex Chau6ed408f2022-03-04 12:58:05 +00001372 if (mIsGestureMode == null) {
1373 mIsGestureMode = DisplayController.getNavigationMode(mContext).hasGestures;
1374 }
1375 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mIsMultiWindowMode,
1376 mTransposeLayoutWithOrientation, mUseTwoPanels, mIsGestureMode);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001377 }
1378 }
1379
Winson Chungb3800242013-10-24 11:01:54 -07001380}