blob: 514490adc0e3670d4c61f2ab3e086d9e40bec6c4 [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
Jon Mirandae126d722021-02-25 10:45:20 -050019import static com.android.launcher3.ResourceUtils.pxFromDp;
Jon Miranda58561d42021-03-17 10:51:54 -040020import static com.android.launcher3.Utilities.dpiFromPx;
Jon Mirandaaf3aed02021-05-06 18:28:45 -070021import static com.android.launcher3.Utilities.pxFromSp;
Jon Miranda92c1b5d2021-07-20 13:57:16 -070022import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.ICON_OVERLAP_FACTOR;
Jon Miranda228877d2021-02-09 11:05:00 -050023
Sunny Goyal35c7b192021-04-20 16:51:10 -070024import android.annotation.SuppressLint;
Winson Chungb3800242013-10-24 11:01:54 -070025import android.content.Context;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070026import android.content.res.Configuration;
Winson Chungb3800242013-10-24 11:01:54 -070027import android.content.res.Resources;
Sunny Goyal8b9919d2021-04-07 14:45:17 -070028import android.graphics.Path;
Winson Chungb3800242013-10-24 11:01:54 -070029import android.graphics.Point;
Jon Miranda7ae64ff2016-11-21 16:18:46 -080030import android.graphics.PointF;
Winson Chungb3800242013-10-24 11:01:54 -070031import android.graphics.Rect;
Sunny Goyal35c7b192021-04-20 16:51:10 -070032import android.util.DisplayMetrics;
Sunny Goyal59d086c2018-05-07 17:31:40 -070033import android.view.Surface;
Winson Chungb3800242013-10-24 11:01:54 -070034
Sunny Goyalc13403c2016-11-18 23:44:48 -080035import com.android.launcher3.CellLayout.ContainerType;
Jon Miranda228877d2021-02-09 11:05:00 -050036import com.android.launcher3.DevicePaddings.DevicePadding;
Tony Wickham8912b042018-11-29 15:28:53 -080037import com.android.launcher3.icons.DotRenderer;
Sunny Goyal8b9919d2021-04-07 14:45:17 -070038import com.android.launcher3.icons.GraphicsUtils;
Hyunyoung Song48cb7bc2018-09-25 17:03:34 -070039import com.android.launcher3.icons.IconNormalizer;
Sunny Goyal57b22792021-05-25 14:35:01 -070040import com.android.launcher3.uioverrides.ApiWrapper;
Sunny Goyalfd58da62020-08-11 12:06:49 -070041import com.android.launcher3.util.DisplayController;
42import com.android.launcher3.util.DisplayController.Info;
Sunny Goyalb46703d2020-05-27 17:52:03 -070043import com.android.launcher3.util.WindowBounds;
Winson1f064272016-07-18 17:18:02 -070044
Jon Miranda58561d42021-03-17 10:51:54 -040045import java.io.PrintWriter;
Brian Isganitis099945b2022-01-31 18:15:00 -050046import java.util.List;
Jon Miranda58561d42021-03-17 10:51:54 -040047
Sunny Goyal35c7b192021-04-20 16:51:10 -070048@SuppressLint("NewApi")
Winson Chungb3800242013-10-24 11:01:54 -070049public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070050
Sunny Goyal8b9919d2021-04-07 14:45:17 -070051 private static final int DEFAULT_DOT_SIZE = 100;
Sunny Goyal57b22792021-05-25 14:35:01 -070052 // Ratio of empty space, qsb should take up to appear visually centered.
Pratyush9afe1ea2021-10-13 11:13:27 +000053 private final float mQsbCenterFactor;
Sunny Goyal1890f672020-04-30 12:28:00 -070054
Adam Cohen2e6da152015-05-06 11:42:25 -070055 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070056 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070057 private final DisplayMetrics mMetrics;
Winson Chungbe876472014-05-14 14:15:20 -070058
Sunny Goyalc6205602015-05-21 20:46:33 -070059 // Device properties
60 public final boolean isTablet;
Alex Chau6ed408f2022-03-04 12:58:05 +000061 public final boolean isLargeTablet;
Sunny Goyalc6205602015-05-21 20:46:33 -070062 public final boolean isPhone;
63 public final boolean transposeLayoutWithOrientation;
Sunny Goyal19ff7282021-04-22 10:12:54 -070064 public final boolean isTwoPanels;
Thales Limaa1012902022-01-13 17:58:42 +000065 public final boolean isQsbInline;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -070066
Sunny Goyalc6205602015-05-21 20:46:33 -070067 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -070068 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -080069 public final boolean isMultiWindowMode;
Alex Chau6ed408f2022-03-04 12:58:05 +000070 public final boolean isGestureMode;
Sunny Goyald70e75a2018-02-22 10:07:32 -080071
Sunny Goyal0addbf02020-04-28 14:17:35 -070072 public final int windowX;
73 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -070074 public final int widthPx;
75 public final int heightPx;
76 public final int availableWidthPx;
77 public final int availableHeightPx;
Sunny Goyal187b16c2022-03-01 16:53:23 -080078 public final int rotationHint;
Jon Mirandabba64512019-03-27 10:54:17 -070079
80 public final float aspectRatio;
81
Jon Mirandae126d722021-02-25 10:45:20 -050082 public final boolean isScalableGrid;
Thales Lima83bedbf2021-10-05 17:47:39 +010083 private final int mTypeIndex;
Jon Mirandae126d722021-02-25 10:45:20 -050084
Tony Wickhamd6b40372015-09-23 18:37:57 -070085 /**
86 * The maximum amount of left/right workspace padding as a percentage of the screen width.
87 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
88 * 7% of the screen width can be used as right padding.
89 */
90 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -070091
Jon Miranda3f9bab22017-07-28 14:50:17 -070092 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -070093 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda80dda302021-07-28 14:14:59 -070094 private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252;
95 private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268;
Jon Miranda30d0aa22017-07-25 15:55:29 -070096
Sunny Goyalc6205602015-05-21 20:46:33 -070097 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +010098 public final int desiredWorkspaceHorizontalMarginOriginalPx;
99 public int desiredWorkspaceHorizontalMarginPx;
Thales Lima78d00ad2021-09-30 11:29:06 +0100100 public Point cellLayoutBorderSpaceOriginalPx;
101 public Point cellLayoutBorderSpacePx;
Pat Manning1acf2b12022-02-25 15:41:55 +0000102 public Rect cellLayoutPaddingPx = new Rect();
103
Sunny Goyalc6205602015-05-21 20:46:33 -0700104 public final int edgeMarginPx;
Pat Manning1acf2b12022-02-25 15:41:55 +0000105 public float workspaceSpringLoadShrunkTop;
106 public float workspaceSpringLoadShrunkBottom;
Sunny Goyal47328fd2016-05-25 18:56:41 -0700107 public final int workspaceSpringLoadedBottomSpace;
Sunny Goyalc6205602015-05-21 20:46:33 -0700108
Jon Miranda58561d42021-03-17 10:51:54 -0400109 private final int extraSpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500110 public int workspaceTopPadding;
111 public int workspaceBottomPadding;
Jon Miranda58561d42021-03-17 10:51:54 -0400112 public int extraHotseatBottomPadding;
Jon Miranda228877d2021-02-09 11:05:00 -0500113
Tony Wickham5edf9e22020-03-27 20:06:52 -0700114 // Workspace page indicator
115 public final int workspacePageIndicatorHeight;
116 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700117
Sunny Goyalc6205602015-05-21 20:46:33 -0700118 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400119 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700120 public int iconSizePx;
121 public int iconTextSizePx;
122 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700123 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -0700124
Jon Mirandaab3c6812021-06-28 15:42:28 -0700125 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800126 public int cellWidthPx;
127 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700128 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800129
Jon Mirandae126d722021-02-25 10:45:20 -0500130 public int cellYPaddingPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500131
Sunny Goyalc6205602015-05-21 20:46:33 -0700132 // Folder
Jon Mirandae126d722021-02-25 10:45:20 -0500133 public float folderLabelTextScale;
134 public int folderLabelTextSizePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700135 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700136 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700137
Jon Mirandae126d722021-02-25 10:45:20 -0500138 // Folder content
Thales Lima78d00ad2021-09-30 11:29:06 +0100139 public Point folderCellLayoutBorderSpacePx;
140 public int folderCellLayoutBorderSpaceOriginalPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500141 public int folderContentPaddingLeftRight;
142 public int folderContentPaddingTop;
143
Jon Mirandabf7d8122016-11-03 15:29:29 -0700144 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700145 public int folderCellWidthPx;
146 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700147
148 // Folder child
149 public int folderChildIconSizePx;
150 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700151 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700152
Sunny Goyalc6205602015-05-21 20:46:33 -0700153 // Hotseat
Jon Miranda80cddbc2021-07-22 13:51:16 -0700154 public int hotseatBarSizeExtraSpacePx;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700155 public final int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700156 public int hotseatCellHeightPx;
Jon Miranda0d284852021-06-22 14:50:55 -0700157 private final int hotseatExtraVerticalSize;
Jon Miranda18751b62017-07-31 17:25:27 -0700158 // In portrait: size = height, in landscape: size = width
159 public int hotseatBarSizePx;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700160 public int hotseatBarTopPaddingPx;
Jon Miranda0d284852021-06-22 14:50:55 -0700161 public final int hotseatBarBottomPaddingPx;
Pat Manning1acf2b12022-02-25 15:41:55 +0000162 public int springLoadedHotseatBarTopMarginPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700163 // Start is the side next to the nav bar, end is the side next to the workspace
164 public final int hotseatBarSidePaddingStartPx;
165 public final int hotseatBarSidePaddingEndPx;
Sunny Goyal57b22792021-05-25 14:35:01 -0700166 public final int hotseatQsbHeight;
Thales Limadd027342022-01-07 12:54:37 +0000167 public int hotseatBorderSpace;
Adam Cohen2e6da152015-05-06 11:42:25 -0700168
Jon Miranda8bdb2222021-06-23 18:10:10 -0700169 public final float qsbBottomMarginOriginalPx;
170 public int qsbBottomMarginPx;
Thales Limaa1012902022-01-13 17:58:42 +0000171 public int qsbWidth; // only used when isQsbInline
Jon Miranda8bdb2222021-06-23 18:10:10 -0700172
Sunny Goyalc6205602015-05-21 20:46:33 -0700173 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000174 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000175 public int allAppsShiftRange;
176 public int allAppsTopPadding;
Andras Kloczl142b0542022-03-09 21:26:02 +0000177 public int bottomSheetTopPadding;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700178 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700179 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700180 public int allAppsIconSizePx;
181 public int allAppsIconDrawablePaddingPx;
sfufa@google.comde013292021-09-21 18:22:44 -0700182 public int allAppsLeftRightPadding;
Alex Chau27b39b92022-01-14 18:02:18 +0000183 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700184 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700185 public float allAppsIconTextSizePx;
186
Zak Cohen334efeb2021-03-19 16:42:07 -0700187 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700188 public int overviewTaskMarginPx;
Alex Chaueaa6d682021-08-17 12:56:15 +0100189 public int overviewTaskMarginGridPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000190 public int overviewTaskIconSizePx;
Alex Chauac9df382021-08-02 19:08:41 +0100191 public int overviewTaskIconDrawableSizePx;
192 public int overviewTaskIconDrawableSizeGridPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000193 public int overviewTaskThumbnailTopMarginPx;
Alex Chau19c6eca2022-03-10 20:12:56 +0000194 public final int overviewActionsHeight;
zakcohendad8a802021-05-20 09:52:26 -0700195 public final int overviewActionsMarginThreeButtonPx;
Alex Chau5fd9d492021-07-22 17:27:11 +0100196 public final int overviewActionsTopMarginGesturePx;
197 public final int overviewActionsBottomMarginGesturePx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000198 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100199 public int overviewPageSpacing;
200 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000201 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700202
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800203 // Widgets
204 public final PointF appWidgetScale = new PointF(1.0f, 1.0f);
205
Sunny Goyal47328fd2016-05-25 18:56:41 -0700206 // Drop Target
207 public int dropTargetBarSizePx;
Pat Manning1acf2b12022-02-25 15:41:55 +0000208 public int dropTargetBarTopMarginPx;
209 public int dropTargetBarBottomMarginPx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100210 public int dropTargetDragPaddingPx;
211 public int dropTargetTextSizePx;
Pat Manning1acf2b12022-02-25 15:41:55 +0000212 public int dropTargetHorizontalPaddingPx;
213 public int dropTargetVerticalPaddingPx;
214 public int dropTargetGapPx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700215
Winson1f064272016-07-18 17:18:02 -0700216 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800217 private final Rect mInsets = new Rect();
218 public final Rect workspacePadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700219 private final Rect mHotseatPadding = new Rect();
Jon Miranda0bd63d12019-03-06 17:29:29 -0800220 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700221 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700222
Tony Wickhamf34bee82018-12-03 18:11:39 -0800223 // Notification dots
Samuel Fufac96fa242019-09-26 23:06:32 -0700224 public DotRenderer mDotRendererWorkSpace;
225 public DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800226
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100227 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800228 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000229 // Whether Taskbar will inset the bottom of apps by taskbarSize.
230 public boolean isTaskbarPresentInApps;
Tony Wickham15883892021-02-12 11:24:40 -0800231 public int taskbarSize;
Alex Chau6a7d1e22022-01-20 19:54:17 +0000232 public int stashedTaskbarSize;
Tony Wickham15883892021-02-12 11:24:40 -0800233
Alex Chaua02eddc2021-04-29 00:36:06 +0100234 // DragController
235 public int flingToDeleteThresholdVelocity;
236
Vinit Nayak17c4b332021-08-05 12:54:58 -0700237 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700238 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal0addbf02020-04-28 14:17:35 -0700239 boolean isMultiWindowMode, boolean transposeLayoutWithOrientation,
Alex Chau6ed408f2022-03-04 12:58:05 +0000240 boolean useTwoPanels, boolean isGestureMode) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700241
Adam Cohen2e6da152015-05-06 11:42:25 -0700242 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700243 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800244 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500245 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +0000246 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700247 windowX = windowBounds.bounds.left;
248 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800249 this.rotationHint = windowBounds.rotationHint;
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);
Alex Chau6ed408f2022-03-04 12:58:05 +0000256 isLargeTablet = info.isLargeTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700257 isPhone = !isTablet;
Alex Chau90125822021-11-17 14:16:58 +0000258 isTwoPanels = isTablet && useTwoPanels;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800259 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700260
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000261 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000262 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700263 ? Configuration.ORIENTATION_LANDSCAPE
264 : Configuration.ORIENTATION_PORTRAIT);
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) {
280 mTypeIndex = InvariantDeviceProfile.INDEX_TWO_PANEL_LANDSCAPE;
281 } else {
282 mTypeIndex = InvariantDeviceProfile.INDEX_TWO_PANEL_PORTRAIT;
283 }
284 } else {
285 if (isLandscape) {
286 mTypeIndex = InvariantDeviceProfile.INDEX_LANDSCAPE;
287 } else {
288 mTypeIndex = InvariantDeviceProfile.INDEX_DEFAULT;
289 }
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
Andras Kloczl142b0542022-03-09 21:26:02 +0000302 bottomSheetTopPadding = windowBounds.insets.top // statusbar height
303 + 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);
321 folderCellLayoutBorderSpaceOriginalPx = pxFromDp(inv.folderBorderSpace, mMetrics, 1f);
322 folderCellLayoutBorderSpacePx = new Point(folderCellLayoutBorderSpaceOriginalPx,
323 folderCellLayoutBorderSpaceOriginalPx);
Jon Mirandae126d722021-02-25 10:45:20 -0500324
Tony Wickham5edf9e22020-03-27 20:06:52 -0700325 workspacePageIndicatorHeight = res.getDimensionPixelSize(
326 R.dimen.workspace_page_indicator_height);
327 mWorkspacePageIndicatorOverlapWorkspace =
328 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700329
Winson Chungb3800242013-10-24 11:01:54 -0700330 iconDrawablePaddingOriginalPx =
331 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Alex Chaua02eddc2021-04-29 00:36:06 +0100332
Sunny Goyal47328fd2016-05-25 18:56:41 -0700333 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Pat Manning1acf2b12022-02-25 15:41:55 +0000334 dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
335 dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100336 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
337 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manning1acf2b12022-02-25 15:41:55 +0000338 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
339 R.dimen.drop_target_button_drawable_horizontal_padding);
340 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
341 R.dimen.drop_target_button_drawable_vertical_padding);
342 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100343
Sunny Goyal47328fd2016-05-25 18:56:41 -0700344 workspaceSpringLoadedBottomSpace =
345 res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space);
Sunny Goyald5190522017-04-24 03:06:54 -0700346
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700347 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700348
Thales Limaa1012902022-01-13 17:58:42 +0000349 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Alex Chau8175da92022-03-09 11:19:47 +0000350 // Whether QSB might be inline in appropriate orientation (landscape).
351 boolean canQsbInline = isLargeTablet && hotseatQsbHeight > 0;
352 isQsbInline = canQsbInline && isLandscape;
Alex Chau6ed408f2022-03-04 12:58:05 +0000353
Alex Chau8175da92022-03-09 11:19:47 +0000354 // We shrink hotseat sizes regardless of orientation, if nav buttons are inline and QSB
355 // might be inline in either orientations, to keep hotseat size consistent across rotation.
356 boolean areNavButtonsInline = isTaskbarPresent && !isGestureMode;
357 if (areNavButtonsInline && canQsbInline) {
Alex Chau6ed408f2022-03-04 12:58:05 +0000358 numShownHotseatIcons = inv.numShrunkenHotseatIcons;
359 } else {
360 numShownHotseatIcons =
361 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
362 }
363
Sunny Goyal19ff7282021-04-22 10:12:54 -0700364 numShownAllAppsColumns =
365 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700366 hotseatBarSizeExtraSpacePx = 0;
Winson1f064272016-07-18 17:18:02 -0700367 hotseatBarTopPaddingPx =
368 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding);
Thales Limaa1012902022-01-13 17:58:42 +0000369 if (isQsbInline) {
370 hotseatBarBottomPaddingPx = res.getDimensionPixelSize(R.dimen.inline_qsb_bottom_margin);
371 qsbWidth = calculateQsbWidth();
372 } else {
373 hotseatBarBottomPaddingPx = (isTallDevice ? res.getDimensionPixelSize(
374 R.dimen.dynamic_grid_hotseat_bottom_tall_padding)
375 : res.getDimensionPixelSize(
376 R.dimen.dynamic_grid_hotseat_bottom_non_tall_padding))
377 + res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_padding);
378 qsbWidth = 0;
379 }
Pat Manning1acf2b12022-02-25 15:41:55 +0000380 springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
381 R.dimen.spring_loaded_hotseat_top_margin);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700382 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800383 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700384 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700385 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Jon Miranda0d284852021-06-22 14:50:55 -0700386 hotseatExtraVerticalSize =
Jon Miranda228877d2021-02-09 11:05:00 -0500387 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_extra_vertical_size);
Thales Lima6e7f36c2022-01-04 12:14:11 +0000388 hotseatBorderSpace = pxFromDp(inv.hotseatBorderSpaces[mTypeIndex], mMetrics);
Thales Lima83bedbf2021-10-05 17:47:39 +0100389 updateHotseatIconSize(
Thales Lima6e7f36c2022-01-04 12:14:11 +0000390 pxFromDp(inv.iconSize[InvariantDeviceProfile.INDEX_DEFAULT], mMetrics));
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700391
Jon Miranda8bdb2222021-06-23 18:10:10 -0700392 qsbBottomMarginOriginalPx = isScalableGrid
393 ? res.getDimensionPixelSize(R.dimen.scalable_grid_qsb_bottom_margin)
394 : 0;
395
Alex Chau635b3ab2022-01-26 16:49:10 +0000396 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chaueaa6d682021-08-17 12:56:15 +0100397 overviewTaskMarginGridPx = res.getDimensionPixelSize(R.dimen.overview_task_margin_grid);
Alex Chau5fd9d492021-07-22 17:27:11 +0100398 overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100399 overviewTaskIconDrawableSizePx =
400 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
401 overviewTaskIconDrawableSizeGridPx =
402 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Alex Chaudedbc8a2021-03-17 16:53:26 +0000403 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx * 2;
Alex Chau635b3ab2022-01-26 16:49:10 +0000404 overviewActionsTopMarginGesturePx = res.getDimensionPixelSize(
405 R.dimen.overview_actions_top_margin_gesture);
406 overviewActionsBottomMarginGesturePx = res.getDimensionPixelSize(
407 R.dimen.overview_actions_bottom_margin_gesture);
408 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
409 overviewActionsButtonSpacing = res.getDimensionPixelSize(
410 R.dimen.overview_actions_button_spacing);
Alex Chau19c6eca2022-03-10 20:12:56 +0000411 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
zakcohendad8a802021-05-20 09:52:26 -0700412 overviewActionsMarginThreeButtonPx = res.getDimensionPixelSize(
Alex Chau5fd9d492021-07-22 17:27:11 +0100413 R.dimen.overview_actions_margin_three_button);
Alex Chau4c983742021-12-10 13:09:53 +0000414 // Grid task's top margin is only overviewTaskIconSizePx + overviewTaskMarginGridPx, but
415 // overviewTaskThumbnailTopMarginPx is applied to all TaskThumbnailView, so exclude the
416 // extra margin when calculating row spacing.
417 int extraTopMargin = overviewTaskThumbnailTopMarginPx - overviewTaskIconSizePx
418 - overviewTaskMarginGridPx;
419 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing)
420 - extraTopMargin;
Alex Chau635b3ab2022-01-26 16:49:10 +0000421 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700422
Jon Miranda2ed276e2017-06-29 11:36:34 -0700423 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400424 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700425
Jon Miranda2ed276e2017-06-29 11:36:34 -0700426 // Now that we have all of the variables calculated, we can tune certain sizes.
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400427 if (isScalableGrid && inv.devicePaddings != null) {
428 // Paddings were created assuming no scaling, so we first unscale the extra space.
Jon Mirandaab3c6812021-06-28 15:42:28 -0700429 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400430 DevicePadding padding = inv.devicePaddings.getDevicePadding(unscaledExtraSpace);
Jon Miranda228877d2021-02-09 11:05:00 -0500431
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400432 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
433 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
434 int paddingHotseatBottom = padding.getHotseatBottomPadding(unscaledExtraSpace);
435
Jon Mirandaab3c6812021-06-28 15:42:28 -0700436 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
437 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
438 extraHotseatBottomPadding = Math.round(paddingHotseatBottom * cellScaleToFit);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400439
Jon Miranda58561d42021-03-17 10:51:54 -0400440 hotseatBarSizePx += extraHotseatBottomPadding;
Jon Miranda8bdb2222021-06-23 18:10:10 -0700441
Jon Mirandaab3c6812021-06-28 15:42:28 -0700442 qsbBottomMarginPx = Math.round(qsbBottomMarginOriginalPx * cellScaleToFit);
Jon Miranda228877d2021-02-09 11:05:00 -0500443 } else if (!isVerticalBarLayout() && isPhone && isTallDevice) {
Jon Miranda3f9bab22017-07-28 14:50:17 -0700444 // We increase the hotseat size when there is extra space.
Jon Miranda80cddbc2021-07-22 13:51:16 -0700445
Jon Miranda80dda302021-07-28 14:14:59 -0700446 if (Float.compare(aspectRatio, TALLER_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0
447 && extraSpace >= Utilities.dpToPx(TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP)) {
448 // For taller devices, we will take a piece of the extra space from each row,
Jon Miranda80cddbc2021-07-22 13:51:16 -0700449 // and add it to the space above and below the hotseat.
Jon Miranda80dda302021-07-28 14:14:59 -0700450
451 // For devices with more extra space, we take a larger piece from each cell.
452 int piece = extraSpace < Utilities.dpToPx(TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP)
Jon Mirandaa56cb842021-08-03 17:26:44 -0700453 ? 7 : 5;
Jon Miranda80dda302021-07-28 14:14:59 -0700454
Jon Miranda80cddbc2021-07-22 13:51:16 -0700455 int extraSpace = ((getCellSize().y - iconSizePx - iconDrawablePaddingPx * 2)
Jon Miranda80dda302021-07-28 14:14:59 -0700456 * inv.numRows) / piece;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700457
Jon Mirandaa56cb842021-08-03 17:26:44 -0700458 workspaceTopPadding = extraSpace / 8;
459 int halfLeftOver = (extraSpace - workspaceTopPadding) / 2;
460 hotseatBarTopPaddingPx += halfLeftOver;
461 hotseatBarSizeExtraSpacePx = halfLeftOver;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700462 } else {
463 // ie. For a display with a large aspect ratio, we can keep the icons on the
464 // workspace in portrait mode closer together by adding more height to the hotseat.
465 // Note: This calculation was created after noticing a pattern in the design spec.
466 hotseatBarSizeExtraSpacePx = getCellSize().y - iconSizePx
467 - iconDrawablePaddingPx * 2 - workspacePageIndicatorHeight;
468 }
469
470 updateHotseatIconSize(iconSizePx);
Jon Miranda30d0aa22017-07-25 15:55:29 -0700471
Jon Miranda3f9bab22017-07-28 14:50:17 -0700472 // Recalculate the available dimensions using the new hotseat size.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700473 updateAvailableDimensions(res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700474 }
Pat Manning1acf2b12022-02-25 15:41:55 +0000475
476 int cellLayoutPadding =
477 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
478 R.dimen.cell_layout_padding);
479 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
480 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800481 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800482
Alex Chaua02eddc2021-04-29 00:36:06 +0100483 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
484 R.dimen.drag_flingToDeleteMinVelocity);
485
Tony Wickham1237df02017-02-24 08:59:36 -0800486 // This is done last, after iconSizePx is calculated above.
Sunny Goyal8b9919d2021-04-07 14:45:17 -0700487 Path dotPath = GraphicsUtils.getShapePath(DEFAULT_DOT_SIZE);
488 mDotRendererWorkSpace = new DotRenderer(iconSizePx, dotPath, DEFAULT_DOT_SIZE);
Samuel Fufac96fa242019-09-26 23:06:32 -0700489 mDotRendererAllApps = iconSizePx == allAppsIconSizePx ? mDotRendererWorkSpace :
Sunny Goyal8b9919d2021-04-07 14:45:17 -0700490 new DotRenderer(allAppsIconSizePx, dotPath, DEFAULT_DOT_SIZE);
Adam Cohen63f1ec02014-08-12 09:23:13 -0700491 }
492
Thales Limaa1012902022-01-13 17:58:42 +0000493 private int calculateQsbWidth() {
494 return cellWidthPx * inv.numColumns
495 + cellLayoutBorderSpacePx.x * (inv.numColumns - 1)
496 - (cellWidthPx - iconSizePx) // left and right cell space
497 - iconSizePx * numShownHotseatIcons
498 - hotseatBorderSpace * numShownHotseatIcons;
499 }
500
Thales Limad90faab2021-09-21 17:18:47 +0100501 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
502 if (isVerticalBarLayout()) {
503 return 0;
504 }
505
Thales Lima83bedbf2021-10-05 17:47:39 +0100506 return isScalableGrid
507 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
508 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100509 }
510
Jon Miranda0d284852021-06-22 14:50:55 -0700511 private void updateHotseatIconSize(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700512 // Ensure there is enough space for folder icons, which have a slightly larger radius.
513 hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda0d284852021-06-22 14:50:55 -0700514 if (isVerticalBarLayout()) {
515 hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
516 + hotseatBarSidePaddingEndPx;
517 } else {
518 hotseatBarSizePx = hotseatIconSizePx + hotseatBarTopPaddingPx
Jon Miranda80cddbc2021-07-22 13:51:16 -0700519 + hotseatBarBottomPaddingPx + (isScalableGrid ? 0 : hotseatExtraVerticalSize)
520 + hotseatBarSizeExtraSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700521 }
522 }
523
Thales Lima78d00ad2021-09-30 11:29:06 +0100524 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
525 if (!isScalableGrid) {
526 return new Point(0, 0);
527 }
528
Thales Lima83bedbf2021-10-05 17:47:39 +0100529 int horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics);
530 int verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics);
Thales Lima78d00ad2021-09-30 11:29:06 +0100531
532 return new Point(horizontalSpacePx, verticalSpacePx);
533 }
534
535 private Point getCellLayoutBorderSpaceScaled(InvariantDeviceProfile idp, float scale) {
536 Point original = getCellLayoutBorderSpace(idp);
537 return new Point((int) (original.x * scale), (int) (original.y * scale));
Jon Mirandae126d722021-02-25 10:45:20 -0500538 }
539
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700540 public Info getDisplayInfo() {
541 return mInfo;
542 }
543
Jon Miranda611dba42021-03-02 14:12:13 -0500544 /**
545 * We inset the widget padding added by the system and instead rely on the border spacing
546 * between cells to create reliable consistency between widgets
547 */
548 public boolean shouldInsetWidgets() {
549 Rect widgetPadding = inv.defaultWidgetPadding;
550
Jon Miranda49811182021-06-03 09:52:40 -0700551 // Check all sides to ensure that the widget won't overlap into another cell, or into
552 // status bar.
553 return workspaceTopPadding > widgetPadding.top
Thales Lima78d00ad2021-09-30 11:29:06 +0100554 && cellLayoutBorderSpacePx.x > widgetPadding.left
555 && cellLayoutBorderSpacePx.y > widgetPadding.top
556 && cellLayoutBorderSpacePx.x > widgetPadding.right
557 && cellLayoutBorderSpacePx.y > widgetPadding.bottom;
Jon Miranda611dba42021-03-02 14:12:13 -0500558 }
Jon Mirandae126d722021-02-25 10:45:20 -0500559
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700560 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800561 WindowBounds bounds = new WindowBounds(
562 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700563 bounds.bounds.offsetTo(windowX, windowY);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700564 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700565 .setWindowBounds(bounds)
566 .setUseTwoPanels(isTwoPanels)
Alex Chau6ed408f2022-03-04 12:58:05 +0000567 .setMultiWindowMode(isMultiWindowMode)
568 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800569 }
570
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700571 public DeviceProfile copy(Context context) {
572 return toBuilder(context).build();
573 }
574
575 /**
576 * TODO: Move this to the builder as part of setMultiWindowMode
577 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700578 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700579 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700580 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700581 .setMultiWindowMode(true)
582 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800583
Jon Miranda941375e2021-03-31 13:10:45 -0400584 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda93e1f042016-11-11 14:13:04 -0800585
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800586 // We use these scales to measure and layout the widgets using their full invariant profile
587 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
588 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
589 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
590 profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY);
591
Jon Miranda93e1f042016-11-11 14:13:04 -0800592 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700593 }
594
Adam Cohen63f1ec02014-08-12 09:23:13 -0700595 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400596 * Checks if there is enough space for labels on the workspace.
597 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700598 * It is important to call this method after the All Apps variables have been set.
599 */
Jon Miranda941375e2021-03-31 13:10:45 -0400600 private void hideWorkspaceLabelsIfNotEnoughSpace() {
601 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
602 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
603 - iconTextHeight;
604
605 // We want enough space so that the text is closer to its corresponding icon.
606 if (workspaceCellPaddingY < iconTextHeight) {
607 iconTextSizePx = 0;
608 iconDrawablePaddingPx = 0;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700609 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda941375e2021-03-31 13:10:45 -0400610 autoResizeAllAppsCells();
611 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700612 }
Jon Miranda1091e532017-07-21 13:31:50 -0700613
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700614 /**
615 * Re-computes the all-apps cell size to be independent of workspace
616 */
617 public void autoResizeAllAppsCells() {
Jon Miranda941375e2021-03-31 13:10:45 -0400618 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
619 int topBottomPadding = textHeight;
Jon Miranda1091e532017-07-21 13:31:50 -0700620 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
Jon Miranda941375e2021-03-31 13:10:45 -0400621 + textHeight + (topBottomPadding * 2);
Jon Miranda1091e532017-07-21 13:31:50 -0700622 }
623
Alex Chau27b39b92022-01-14 18:02:18 +0000624 private void updateAllAppsWidth(Resources res) {
Pat Manning1acf2b12022-02-25 15:41:55 +0000625 int cellLayoutHorizontalPadding =
626 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
Alex Chau27b39b92022-01-14 18:02:18 +0000627 if (isTablet) {
Pat Manning1acf2b12022-02-25 15:41:55 +0000628 allAppsLeftRightPadding = res.getDimensionPixelSize(
629 R.dimen.all_apps_bottom_sheet_horizontal_padding) + cellLayoutHorizontalPadding;
sfufa@google.comde013292021-09-21 18:22:44 -0700630 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
Alex Chau27b39b92022-01-14 18:02:18 +0000631 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns + 1))
632 + allAppsLeftRightPadding * 2;
633 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
sfufa@google.comde013292021-09-21 18:22:44 -0700634 } else {
635 allAppsLeftRightPadding =
Pat Manning1acf2b12022-02-25 15:41:55 +0000636 desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding;
sfufa@google.comde013292021-09-21 18:22:44 -0700637 }
638 }
639
Jon Miranda228877d2021-02-09 11:05:00 -0500640 /**
641 * Returns the amount of extra (or unused) vertical space.
642 */
643 private int updateAvailableDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700644 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800645
Pat Manning1acf2b12022-02-25 15:41:55 +0000646 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -0500647 Point workspacePadding = getTotalWorkspacePadding();
648
649 // Check to see if the icons fit within the available height.
650 float usedHeight = getCellLayoutHeight();
Pat Manning1acf2b12022-02-25 15:41:55 +0000651 final int maxHeight = getWorkspaceHeight(workspacePadding);
Jon Miranda228877d2021-02-09 11:05:00 -0500652 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500653 float scaleY = maxHeight / usedHeight;
654 boolean shouldScale = scaleY < 1f;
655
656 float scaleX = 1f;
657 if (isScalableGrid) {
658 // We scale to fit the cellWidth and cellHeight in the available space.
659 // The benefit of scalable grids is that we can get consistent aspect ratios between
660 // devices.
Pat Manning1acf2b12022-02-25 15:41:55 +0000661 float usedWidth = getCellLayoutWidth() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500662 // We do not subtract padding here, as we also scale the workspace padding if needed.
663 scaleX = availableWidthPx / usedWidth;
664 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700665 }
Jon Mirandae126d722021-02-25 10:45:20 -0500666
667 if (shouldScale) {
668 float scale = Math.min(scaleX, scaleY);
669 updateIconSize(scale, res);
670 extraHeight = Math.max(0, maxHeight - getCellLayoutHeight());
671 }
672
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700673 updateAvailableFolderCellDimensions(res);
Jon Miranda228877d2021-02-09 11:05:00 -0500674 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700675 }
676
Jon Mirandae126d722021-02-25 10:45:20 -0500677 private int getCellLayoutHeight() {
Pat Manning1acf2b12022-02-25 15:41:55 +0000678 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
679 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
680 }
681
682 private int getCellLayoutWidth() {
683 int numColumns = isTwoPanels ? inv.numColumns * 2 : inv.numColumns;
684 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
685 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -0500686 }
687
Jon Miranda6f7e9702019-09-16 14:44:14 -0700688 /**
689 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
690 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
691 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
692 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800693 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -0700694 // Icon scale should never exceed 1, otherwise pixellation may occur.
695 iconScale = Math.min(1f, scale);
696 cellScaleToFit = scale;
697
Jon Miranda18751b62017-07-31 17:25:27 -0700698 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800699 final boolean isVerticalLayout = isVerticalBarLayout();
Thales Lima83bedbf2021-10-05 17:47:39 +0100700 float invIconSizeDp = inv.iconSize[mTypeIndex];
701 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
Andras Kloczl30fe9152021-08-05 18:02:29 +0200702
Jon Mirandaab3c6812021-06-28 15:42:28 -0700703 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, iconScale));
Jon Mirandaab3c6812021-06-28 15:42:28 -0700704 iconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * iconScale);
705 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700706
Thales Lima78d00ad2021-09-30 11:29:06 +0100707 cellLayoutBorderSpacePx = getCellLayoutBorderSpaceScaled(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500708
709 if (isScalableGrid) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100710 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
711 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500712 int cellContentHeight = iconSizePx + iconDrawablePaddingPx
713 + Utilities.calculateTextHeight(iconTextSizePx);
714 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +0100715 desiredWorkspaceHorizontalMarginPx =
716 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -0500717 } else {
Jon Mirandae126d722021-02-25 10:45:20 -0500718 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700719 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR)
720 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -0500721 + Utilities.calculateTextHeight(iconTextSizePx);
722 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
723 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
724 && !isMultiWindowMode) {
725 // Ensures that the label is closer to its corresponding icon. This is not an issue
726 // with vertical bar layout or multi-window mode since the issue is handled
727 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
728 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
729 iconDrawablePaddingPx = cellPaddingY;
730 }
Jon Miranda846455e2017-10-02 14:58:52 -0700731 }
Jon Miranda18751b62017-07-31 17:25:27 -0700732
Sunny Goyalae190ff2020-04-14 00:19:01 +0000733 // All apps
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500734 updateAllAppsIconSize(scale, res);
Winson Chungb3800242013-10-24 11:01:54 -0700735
Winson Chungb3800242013-10-24 11:01:54 -0700736 // Hotseat
Thales Limadd027342022-01-07 12:54:37 +0000737 hotseatBorderSpace = pxFromDp(inv.hotseatBorderSpaces[mTypeIndex], mMetrics, scale);
Thales Limaa1012902022-01-13 17:58:42 +0000738 if (isQsbInline) {
739 qsbWidth = calculateQsbWidth();
740 } else {
741 qsbWidth = 0;
742 }
Jon Miranda0d284852021-06-22 14:50:55 -0700743 updateHotseatIconSize(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700744
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700745 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -0700746 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
747 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Winson Chung0f785722015-04-08 10:27:49 -0700748 }
749
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500750
751 /**
752 * Updates the iconSize for allApps* variants.
753 */
754 public void updateAllAppsIconSize(float scale, Resources res) {
755 if (numShownAllAppsColumns != inv.numColumns) {
756 allAppsIconSizePx =
757 pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
758 allAppsIconTextSizePx =
759 pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
760 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
761 autoResizeAllAppsCells();
762 } else {
763 float invIconSizeDp = inv.iconSize[mTypeIndex];
764 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
765 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
766 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
767 allAppsIconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * scale);
768 allAppsCellHeightPx = getCellSize().y;
769 }
770
771 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
772 updateAllAppsWidth(res);
773 if (isVerticalBarLayout()) {
774 hideWorkspaceLabelsIfNotEnoughSpace();
775 }
776 }
777
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700778 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700779 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700780
Jon Mirandae126d722021-02-25 10:45:20 -0500781 final int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_height);
782
Jon Mirandac1b23992016-12-13 08:57:36 -0800783 // Don't let the folder get too close to the edges of the screen.
Jon Miranda1786df32018-09-25 13:05:23 -0700784 int folderMargin = edgeMarginPx * 2;
Sunny Goyal07b69292018-01-08 14:19:34 -0800785 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -0800786
787 // Check if the icons fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -0500788 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Thales Lima78d00ad2021-09-30 11:29:06 +0100789 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx.y);
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800790 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderBottomPanelSize
Jon Mirandae126d722021-02-25 10:45:20 -0500791 - folderMargin - folderContentPaddingTop;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800792 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -0800793
794 // Check if the icons fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -0500795 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Thales Lima78d00ad2021-09-30 11:29:06 +0100796 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x);
Jon Mirandae126d722021-02-25 10:45:20 -0500797 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin
798 - folderContentPaddingLeftRight * 2;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800799 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -0800800
801 float scale = Math.min(scaleX, scaleY);
802 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700803 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700804 }
805 }
806
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700807 private void updateFolderCellSize(float scale, Resources res) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100808 float invIconSizeDp = isVerticalBarLayout()
809 ? inv.iconSize[InvariantDeviceProfile.INDEX_LANDSCAPE]
810 : inv.iconSize[InvariantDeviceProfile.INDEX_DEFAULT];
Sunny Goyal35c7b192021-04-20 16:51:10 -0700811 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Thales Lima83bedbf2021-10-05 17:47:39 +0100812 folderChildTextSizePx =
813 pxFromSp(inv.iconTextSize[InvariantDeviceProfile.INDEX_DEFAULT], mMetrics, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500814 folderLabelTextSizePx = (int) (folderChildTextSizePx * folderLabelTextScale);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700815
816 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700817
Jon Miranda823da222021-03-23 08:08:45 -0400818 if (isScalableGrid) {
Jon Mirandaf33f5b32021-07-22 17:15:31 -0700819 int minWidth = folderChildIconSizePx + iconDrawablePaddingPx * 2;
820 int minHeight = folderChildIconSizePx + iconDrawablePaddingPx * 2 + textHeight;
821
822 folderCellWidthPx = (int) Math.max(minWidth, cellWidthPx * scale);
823 folderCellHeightPx = (int) Math.max(minHeight, cellHeightPx * scale);
Jon Miranda823da222021-03-23 08:08:45 -0400824
Thales Lima78d00ad2021-09-30 11:29:06 +0100825 int scaledSpace = (int) (folderCellLayoutBorderSpaceOriginalPx * scale);
826 folderCellLayoutBorderSpacePx = new Point(scaledSpace, scaledSpace);
827 folderContentPaddingLeftRight = scaledSpace;
828 folderContentPaddingTop = scaledSpace;
Jon Miranda823da222021-03-23 08:08:45 -0400829 } else {
830 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
831 * scale);
832 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
833 * scale);
834
835 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
836 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
837 }
838
Jonathan Miranda9ad87462017-07-26 17:41:02 +0000839 folderChildDrawablePaddingPx = Math.max(0,
840 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700841 }
842
Winson1f064272016-07-18 17:18:02 -0700843 public void updateInsets(Rect insets) {
844 mInsets.set(insets);
845 }
846
Sunny Goyalae6e3182019-04-30 12:04:37 -0700847 /**
848 * The current device insets. This is generally same as the insets being dispatched to
849 * {@link Insettable} elements, but can differ if the element is using a different profile.
850 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800851 public Rect getInsets() {
852 return mInsets;
853 }
854
Sunny Goyal756cd262015-08-20 12:33:21 -0700855 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700856 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700857 }
858
Sunny Goyal19ff7282021-04-22 10:12:54 -0700859 public Point getCellSize(Point result) {
860 if (result == null) {
861 result = new Point();
862 }
Thales Limad1df5fc2021-09-03 18:37:19 +0100863
Sunny Goyal756cd262015-08-20 12:33:21 -0700864 // Since we are only concerned with the overall padding, layout direction does
865 // not matter.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700866 Point padding = getTotalWorkspacePadding();
Thales Limad1df5fc2021-09-03 18:37:19 +0100867
868 int numColumns = isTwoPanels ? inv.numColumns * 2 : inv.numColumns;
Alex Chau60953332021-11-24 12:41:07 +0000869 int screenWidthPx = getWorkspaceWidth(padding);
Thales Lima78d00ad2021-09-30 11:29:06 +0100870 result.x = calculateCellWidth(screenWidthPx, cellLayoutBorderSpacePx.x, numColumns);
Pat Manning1acf2b12022-02-25 15:41:55 +0000871 int screenHeightPx = getWorkspaceHeight(padding);
872 result.y = calculateCellHeight(screenHeightPx, cellLayoutBorderSpacePx.y, inv.numRows);
Sunny Goyal756cd262015-08-20 12:33:21 -0700873 return result;
874 }
875
Pat Manning1acf2b12022-02-25 15:41:55 +0000876 /**
877 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
878 * bottom of the screen.
879 */
880 public int getVerticalHotseatLastItemBottomOffset() {
881 int cellHeight = calculateCellHeight(
882 heightPx - mHotseatPadding.top - mHotseatPadding.bottom, hotseatBorderSpace,
883 numShownHotseatIcons);
884 int hotseatSize = (cellHeight * numShownHotseatIcons)
885 + (hotseatBorderSpace * (numShownHotseatIcons - 1));
886 int extraHotseatEndSpacing = (heightPx - hotseatSize) / 2;
887 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
888 return extraHotseatEndSpacing + extraIconEndSpacing + mHotseatPadding.bottom;
889 }
890
891 /**
892 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
893 */
894 public float getWorkspaceSpringLoadShrunkTop() {
895 workspaceSpringLoadShrunkTop = mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
896 + dropTargetBarBottomMarginPx;
897 return workspaceSpringLoadShrunkTop;
898 }
899
900 /**
901 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
902 */
903 public float getWorkspaceSpringLoadShrunkBottom() {
904 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
905 workspaceSpringLoadShrunkBottom =
906 heightPx - (isVerticalBarLayout() ? getVerticalHotseatLastItemBottomOffset()
907 : topOfHotseat);
908 return workspaceSpringLoadShrunkBottom;
909 }
910
Alex Chau60953332021-11-24 12:41:07 +0000911 public int getWorkspaceWidth() {
912 return getWorkspaceWidth(getTotalWorkspacePadding());
913 }
914
915 public int getWorkspaceWidth(Point workspacePadding) {
916 int cellLayoutTotalPadding =
Pat Manning1acf2b12022-02-25 15:41:55 +0000917 (isTwoPanels ? 2 : 1) * (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
Alex Chau60953332021-11-24 12:41:07 +0000918 return availableWidthPx - workspacePadding.x - cellLayoutTotalPadding;
919 }
920
Pat Manning1acf2b12022-02-25 15:41:55 +0000921 private int getWorkspaceHeight(Point workspacePadding) {
922 return availableHeightPx - workspacePadding.y - (cellLayoutPaddingPx.top
923 + cellLayoutPaddingPx.bottom);
924 }
925
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700926 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -0800927 return new Point(workspacePadding.left + workspacePadding.right,
928 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700929 }
930
931 /**
Sunny Goyal07b69292018-01-08 14:19:34 -0800932 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
933 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700934 */
Sunny Goyal07b69292018-01-08 14:19:34 -0800935 private void updateWorkspacePadding() {
936 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -0700937 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -0800938 padding.top = 0;
939 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800940 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700941 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -0700942 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -0700943 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -0700944 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700945 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -0700946 }
Winson Chungb3800242013-10-24 11:01:54 -0700947 } else {
Thales Lima7a6752d2021-09-23 14:31:00 +0100948 // Pad the bottom of the workspace with search/hotseat bar sizes
Tony Wickham21970cc2021-09-15 15:44:05 -0700949 int hotseatTop = hotseatBarSizePx;
Tony Wickhama29a0462021-03-02 12:28:25 -0800950 int paddingBottom = hotseatTop + workspacePageIndicatorHeight
Jon Miranda228877d2021-02-09 11:05:00 -0500951 + workspaceBottomPadding - mWorkspacePageIndicatorOverlapWorkspace;
Pat Manning1acf2b12022-02-25 15:41:55 +0000952 int paddingTop = workspaceTopPadding + (isScalableGrid ? 0 : edgeMarginPx);
953 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +0100954
Pat Manning1acf2b12022-02-25 15:41:55 +0000955 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -0700956 }
Pat Manning1acf2b12022-02-25 15:41:55 +0000957 insetPadding(workspacePadding, cellLayoutPaddingPx);
958 }
959
960 private void insetPadding(Rect paddings, Rect insets) {
961 insets.left = Math.min(insets.left, paddings.left);
962 paddings.left -= insets.left;
963
964 insets.top = Math.min(insets.top, paddings.top);
965 paddings.top -= insets.top;
966
967 insets.right = Math.min(insets.right, paddings.right);
968 paddings.right -= insets.right;
969
970 insets.bottom = Math.min(insets.bottom, paddings.bottom);
971 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -0700972 }
973
Sunny Goyal57b22792021-05-25 14:35:01 -0700974 /**
975 * Returns the padding for hotseat view
976 */
977 public Rect getHotseatLayoutPadding(Context context) {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700978 if (isVerticalBarLayout()) {
Pat Manning1acf2b12022-02-25 15:41:55 +0000979 int paddingTop = Math.max(mInsets.top - cellLayoutPaddingPx.top, 0);
980 int paddingBottom = Math.max(mInsets.bottom - cellLayoutPaddingPx.bottom, 0);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700981 if (isSeascape()) {
Pat Manning1acf2b12022-02-25 15:41:55 +0000982 mHotseatPadding.set(mInsets.left + hotseatBarSidePaddingStartPx, paddingTop,
983 hotseatBarSidePaddingEndPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700984 } else {
Pat Manning1acf2b12022-02-25 15:41:55 +0000985 mHotseatPadding.set(hotseatBarSidePaddingEndPx, paddingTop,
986 mInsets.right + hotseatBarSidePaddingStartPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700987 }
Sunny Goyal57b22792021-05-25 14:35:01 -0700988 } else if (isTaskbarPresent) {
Tony Wickham21970cc2021-09-15 15:44:05 -0700989 int hotseatHeight = workspacePadding.bottom;
Sunny Goyal57b22792021-05-25 14:35:01 -0700990 int taskbarOffset = getTaskbarOffsetY();
Thales Limaa1012902022-01-13 17:58:42 +0000991 int additionalLeftSpace = 0;
992
993 // Center the QSB with hotseat and push icons to the right
994 if (isQsbInline) {
995 additionalLeftSpace = qsbWidth + hotseatBorderSpace;
996 }
997
Tony Wickham21970cc2021-09-15 15:44:05 -0700998 int hotseatTopDiff = hotseatHeight - taskbarOffset;
Sunny Goyal57b22792021-05-25 14:35:01 -0700999
Vinit Nayak8dcbde82021-07-19 12:53:28 -07001000 int endOffset = ApiWrapper.getHotseatEndOffset(context);
Thales Lima6e7f36c2022-01-04 12:14:11 +00001001 int requiredWidth = iconSizePx * numShownHotseatIcons
Thales Limaa1012902022-01-13 17:58:42 +00001002 + hotseatBorderSpace * (numShownHotseatIcons - 1)
1003 + additionalLeftSpace;
Sunny Goyal57b22792021-05-25 14:35:01 -07001004
Thales Lima6e7f36c2022-01-04 12:14:11 +00001005 int hotseatSize = Math.min(requiredWidth, availableWidthPx - endOffset);
Sunny Goyal57b22792021-05-25 14:35:01 -07001006 int sideSpacing = (availableWidthPx - hotseatSize) / 2;
Thales Limaa1012902022-01-13 17:58:42 +00001007 mHotseatPadding.set(sideSpacing + additionalLeftSpace, hotseatTopDiff, sideSpacing,
1008 taskbarOffset);
Sunny Goyal57b22792021-05-25 14:35:01 -07001009
Vinit Nayak8dcbde82021-07-19 12:53:28 -07001010 if (endOffset > sideSpacing) {
Sunny Goyal57b22792021-05-25 14:35:01 -07001011 int diff = Utilities.isRtl(context.getResources())
Vinit Nayak8dcbde82021-07-19 12:53:28 -07001012 ? sideSpacing - endOffset
1013 : endOffset - sideSpacing;
1014 mHotseatPadding.left -= diff;
1015 mHotseatPadding.right += diff;
Sunny Goyal57b22792021-05-25 14:35:01 -07001016 }
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001017 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001018 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1019 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1020 // for this, we pad the left and right of the hotseat with half of the difference of a
1021 // workspace cell vs a hotseat cell.
1022 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001023 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001024 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning1acf2b12022-02-25 15:41:55 +00001025 mHotseatPadding.set(hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1026 + mInsets.left, hotseatBarTopPaddingPx,
1027 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001028 + mInsets.right,
Jon Miranda0d284852021-06-22 14:50:55 -07001029 hotseatBarSizePx - hotseatCellHeightPx - hotseatBarTopPaddingPx
Pat Manning1acf2b12022-02-25 15:41:55 +00001030 + mInsets.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001031 }
1032 return mHotseatPadding;
1033 }
1034
Winsonfadbe8f2016-07-22 16:35:37 -07001035 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001036 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1037 */
1038 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001039 if (isQsbInline) {
1040 return hotseatBarBottomPaddingPx;
1041 }
1042
Sunny Goyal57b22792021-05-25 14:35:01 -07001043 int freeSpace = isTaskbarPresent
1044 ? workspacePadding.bottom
1045 : hotseatBarSizePx - hotseatCellHeightPx - hotseatQsbHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001046
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001047 if (isScalableGrid && qsbBottomMarginPx > mInsets.bottom) {
Tony Wickham21970cc2021-09-15 15:44:05 -07001048 // Note that taskbarSize = 0 unless isTaskbarPresent.
1049 return Math.min(qsbBottomMarginPx + taskbarSize, freeSpace);
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001050 } else {
Pratyush9afe1ea2021-10-13 11:13:27 +00001051 return (int) (freeSpace * mQsbCenterFactor)
1052 + (isTaskbarPresent ? taskbarSize : mInsets.bottom);
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001053 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001054 }
1055
1056 /**
1057 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1058 */
1059 public int getTaskbarOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001060 if (isQsbInline) {
1061 return getQsbOffsetY() + (Math.abs(hotseatQsbHeight - iconSizePx) / 2);
1062 } else {
1063 return (getQsbOffsetY() - taskbarSize) / 2;
1064 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001065 }
1066
1067 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001068 * @return the bounds for which the open folders should be contained within
1069 */
1070 public Rect getAbsoluteOpenFolderBounds() {
1071 if (isVerticalBarLayout()) {
1072 // Folders should only appear right of the drop target bar and left of the hotseat
1073 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1074 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001075 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001076 mInsets.top + availableHeightPx);
1077 } else {
1078 // Folders should only appear below the drop target bar and above the hotseat
Tony Wickhamae72b462021-03-10 16:18:40 -08001079 int hotseatTop = isTaskbarPresent ? taskbarSize : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001080 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001081 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001082 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001083 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001084 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001085 }
1086 }
1087
Jon Miranda228877d2021-02-09 11:05:00 -05001088 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1089 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001090 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001091
Jon Miranda228877d2021-02-09 11:05:00 -05001092 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1093 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001094 }
1095
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001096 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001097 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1098 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1099 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001100 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001101 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001102 return isLandscape && transposeLayoutWithOrientation;
1103 }
1104
Sunny Goyal59d086c2018-05-07 17:31:40 -07001105 /**
1106 * Updates orientation information and returns true if it has changed from the previous value.
1107 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001108 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001109 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001110 boolean isSeascape = DisplayController.INSTANCE.get(context)
1111 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001112 if (mIsSeascape != isSeascape) {
1113 mIsSeascape = isSeascape;
Pat Manning1acf2b12022-02-25 15:41:55 +00001114 // Hotseat changing sides requires updating workspace left/right paddings
1115 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001116 return true;
1117 }
1118 }
1119 return false;
1120 }
1121
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001122 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001123 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001124 }
1125
Sunny Goyal07b69292018-01-08 14:19:34 -08001126 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001127 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001128 }
1129
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001130 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001131 switch (containerType) {
1132 case CellLayout.WORKSPACE:
1133 return cellHeightPx;
1134 case CellLayout.FOLDER:
1135 return folderCellHeightPx;
1136 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001137 // The hotseat is the only container where the cell height is going to be
1138 // different from the content within that cell.
1139 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001140 default:
1141 // ??
1142 return 0;
1143 }
1144 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001145
Jon Miranda58561d42021-03-17 10:51:54 -04001146 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001147 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001148 }
1149
1150 public void dump(String prefix, PrintWriter writer) {
1151 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001152 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001153
1154 writer.println(prefix + "\tisTablet:" + isTablet);
Alex Chau6ed408f2022-03-04 12:58:05 +00001155 writer.println(prefix + "\tisLargeTablet:" + isLargeTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001156 writer.println(prefix + "\tisPhone:" + isPhone);
1157 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1158 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001159 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001160
1161 writer.println(prefix + "\tisLandscape:" + isLandscape);
1162 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001163 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001164
1165 writer.println(prefix + pxToDpStr("windowX", windowX));
1166 writer.println(prefix + pxToDpStr("windowY", windowY));
1167 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1168 writer.println(prefix + pxToDpStr("heightPx", heightPx));
1169
1170 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1171 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
1172
1173 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1174
1175 writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
1176
Thales Lima83bedbf2021-10-05 17:47:39 +01001177 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001178 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1179 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1180 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001181
Thales Lima83bedbf2021-10-05 17:47:39 +01001182 writer.println(prefix + "\tminCellSize: " + inv.minCellSize[mTypeIndex] + "dp");
Jon Mirandaab3c6812021-06-28 15:42:28 -07001183
Jon Miranda58561d42021-03-17 10:51:54 -04001184 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1185 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1186
1187 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1188 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1189
Thales Lima83bedbf2021-10-05 17:47:39 +01001190 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1191 cellLayoutBorderSpacePx.x));
1192 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1193 cellLayoutBorderSpacePx.y));
Pat Manning1acf2b12022-02-25 15:41:55 +00001194 writer.println(prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
1195 writer.println(prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
1196 writer.println(prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
1197 writer.println(
1198 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01001199
Jon Miranda58561d42021-03-17 10:51:54 -04001200 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1201 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1202 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1203
1204 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1205 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1206 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1207 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1208 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1209 folderChildDrawablePaddingPx));
Thales Lima78d00ad2021-09-30 11:29:06 +01001210 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpaceOriginalPx",
1211 folderCellLayoutBorderSpaceOriginalPx));
1212 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx Horizontal",
1213 folderCellLayoutBorderSpacePx.x));
1214 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx Vertical",
1215 folderCellLayoutBorderSpacePx.y));
Jon Miranda58561d42021-03-17 10:51:54 -04001216
Jon Miranda58561d42021-03-17 10:51:54 -04001217 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1218 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1219 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1220 allAppsIconDrawablePaddingPx));
1221 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001222 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001223 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau27b39b92022-01-14 18:02:18 +00001224 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
1225 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001226
1227 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
1228 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
1229 writer.println(prefix + pxToDpStr("hotseatBarTopPaddingPx", hotseatBarTopPaddingPx));
1230 writer.println(prefix + pxToDpStr("hotseatBarBottomPaddingPx", hotseatBarBottomPaddingPx));
1231 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
1232 hotseatBarSidePaddingStartPx));
1233 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
1234 hotseatBarSidePaddingEndPx));
Pat Manning1acf2b12022-02-25 15:41:55 +00001235 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
1236 springLoadedHotseatBarTopMarginPx));
1237 writer.println(prefix + pxToDpStr("mHotseatPadding.top", mHotseatPadding.top));
1238 writer.println(prefix + pxToDpStr("mHotseatPadding.bottom", mHotseatPadding.bottom));
1239 writer.println(prefix + pxToDpStr("mHotseatPadding.left", mHotseatPadding.left));
1240 writer.println(prefix + pxToDpStr("mHotseatPadding.right", mHotseatPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001241 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001242 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001243 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
1244 writer.println(prefix + pxToDpStr("qsbWidth", qsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001245
1246 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001247 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda58561d42021-03-17 10:51:54 -04001248 writer.println(prefix + pxToDpStr("taskbarSize", taskbarSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001249
Thales Lima83bedbf2021-10-05 17:47:39 +01001250 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1251 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001252 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
1253 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
1254 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
1255 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
1256
Jon Mirandaab3c6812021-06-28 15:42:28 -07001257 writer.println(prefix + pxToDpStr("iconScale", iconScale));
1258 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04001259 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Thales Lima7a6752d2021-09-23 14:31:00 +01001260 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001261
1262 if (inv.devicePaddings != null) {
1263 int unscaledExtraSpace = (int) (extraSpace / iconScale);
1264 writer.println(prefix + pxToDpStr("maxEmptySpace",
1265 inv.devicePaddings.getDevicePadding(unscaledExtraSpace).getMaxEmptySpacePx()));
1266 }
Jon Miranda58561d42021-03-17 10:51:54 -04001267 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
1268 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
1269 writer.println(prefix + pxToDpStr("extraHotseatBottomPadding", extraHotseatBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00001270
1271 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
1272 writer.println(prefix + pxToDpStr("overviewTaskMarginGridPx", overviewTaskMarginGridPx));
1273 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
1274 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
1275 overviewTaskIconDrawableSizePx));
1276 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
1277 overviewTaskIconDrawableSizeGridPx));
1278 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
1279 overviewTaskThumbnailTopMarginPx));
1280 writer.println(prefix + pxToDpStr("overviewActionsMarginThreeButtonPx",
1281 overviewActionsMarginThreeButtonPx));
1282 writer.println(prefix + pxToDpStr("overviewActionsTopMarginGesturePx",
1283 overviewActionsTopMarginGesturePx));
1284 writer.println(prefix + pxToDpStr("overviewActionsBottomMarginGesturePx",
1285 overviewActionsBottomMarginGesturePx));
1286 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
1287 overviewActionsButtonSpacing));
1288 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
1289 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
1290 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manning1acf2b12022-02-25 15:41:55 +00001291
1292 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
1293 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
1294 writer.println(
1295 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
1296
1297 writer.println(
1298 prefix + pxToDpStr("workspaceSpringLoadShrunkTop", workspaceSpringLoadShrunkTop));
1299 writer.println(prefix + pxToDpStr("workspaceSpringLoadShrunkBottom",
1300 workspaceSpringLoadShrunkBottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001301 }
1302
Sunny Goyalfd58da62020-08-11 12:06:49 -07001303 private static Context getContext(Context c, Info info, int orientation) {
Sunny Goyal1890f672020-04-30 12:28:00 -07001304 Configuration config = new Configuration(c.getResources().getConfiguration());
1305 config.orientation = orientation;
Sunny Goyal35c7b192021-04-20 16:51:10 -07001306 config.densityDpi = info.densityDpi;
Sunny Goyal1890f672020-04-30 12:28:00 -07001307 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07001308 }
Sunny Goyalfde55052018-02-01 14:46:13 -08001309
1310 /**
1311 * Callback when a component changes the DeviceProfile associated with it, as a result of
1312 * configuration change
1313 */
1314 public interface OnDeviceProfileChangeListener {
1315
1316 /**
1317 * Called when the device profile is reassigned. Note that for layout and measurements, it
1318 * is sufficient to listen for inset changes. Use this callback when you need to perform
1319 * a one time operation.
1320 */
1321 void onDeviceProfileChanged(DeviceProfile dp);
1322 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001323
Brian Isganitis099945b2022-01-31 18:15:00 -05001324 /** Allows registering listeners for {@link DeviceProfile} changes. */
1325 public interface DeviceProfileListenable {
1326
1327 /** The current device profile. */
1328 DeviceProfile getDeviceProfile();
1329
1330 /** Registered {@link OnDeviceProfileChangeListener} instances. */
1331 List<OnDeviceProfileChangeListener> getOnDeviceProfileChangeListeners();
1332
1333 /** Notifies listeners of a {@link DeviceProfile} change. */
1334 default void dispatchDeviceProfileChanged() {
1335 DeviceProfile deviceProfile = getDeviceProfile();
1336 List<OnDeviceProfileChangeListener> listeners = getOnDeviceProfileChangeListeners();
1337 for (int i = listeners.size() - 1; i >= 0; i--) {
1338 listeners.get(i).onDeviceProfileChanged(deviceProfile);
1339 }
1340 }
1341
1342 /** Register listener for {@link DeviceProfile} changes. */
1343 default void addOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
1344 getOnDeviceProfileChangeListeners().add(listener);
1345 }
1346
1347 /** Unregister listener for {@link DeviceProfile} changes. */
1348 default void removeOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
1349 getOnDeviceProfileChangeListeners().remove(listener);
1350 }
1351 }
1352
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001353 public static class Builder {
1354 private Context mContext;
1355 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07001356 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001357
Sunny Goyal19ff7282021-04-22 10:12:54 -07001358 private WindowBounds mWindowBounds;
1359 private boolean mUseTwoPanels;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001360
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001361 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001362 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00001363 private Boolean mIsGestureMode;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001364
Sunny Goyalfd58da62020-08-11 12:06:49 -07001365 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001366 mContext = context;
1367 mInv = inv;
1368 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001369 }
1370
1371 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1372 mIsMultiWindowMode = isMultiWindowMode;
1373 return this;
1374 }
1375
Sunny Goyal19ff7282021-04-22 10:12:54 -07001376 public Builder setUseTwoPanels(boolean useTwoPanels) {
1377 mUseTwoPanels = useTwoPanels;
1378 return this;
1379 }
1380
1381
1382 public Builder setWindowBounds(WindowBounds bounds) {
1383 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07001384 return this;
1385 }
1386
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001387 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1388 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1389 return this;
1390 }
1391
Alex Chau6ed408f2022-03-04 12:58:05 +00001392 public Builder setGestureMode(boolean isGestureMode) {
1393 mIsGestureMode = isGestureMode;
1394 return this;
1395 }
1396
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001397 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001398 if (mWindowBounds == null) {
1399 throw new IllegalArgumentException("Window bounds not set");
1400 }
1401 if (mTransposeLayoutWithOrientation == null) {
1402 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
1403 }
Alex Chau6ed408f2022-03-04 12:58:05 +00001404 if (mIsGestureMode == null) {
1405 mIsGestureMode = DisplayController.getNavigationMode(mContext).hasGestures;
1406 }
1407 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mIsMultiWindowMode,
1408 mTransposeLayoutWithOrientation, mUseTwoPanels, mIsGestureMode);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001409 }
1410 }
1411
Winson Chungb3800242013-10-24 11:01:54 -07001412}