blob: 4cad919c3bf42f561c9918b02b41ded58b71069c [file] [log] [blame]
Winson Chungb3800242013-10-24 11:01:54 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.launcher3;
18
Thales Lima12d0eff2022-03-25 17:06:11 +000019import static com.android.launcher3.InvariantDeviceProfile.INDEX_DEFAULT;
20import static com.android.launcher3.InvariantDeviceProfile.INDEX_LANDSCAPE;
21import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_LANDSCAPE;
22import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_PORTRAIT;
Jon Miranda58561d42021-03-17 10:51:54 -040023import static com.android.launcher3.Utilities.dpiFromPx;
Jon Mirandaaf3aed02021-05-06 18:28:45 -070024import static com.android.launcher3.Utilities.pxFromSp;
Alex Chau3d2c0622022-09-01 21:28:14 +010025import static com.android.launcher3.anim.Interpolators.LINEAR;
Jon Miranda92c1b5d2021-07-20 13:57:16 -070026import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.ICON_OVERLAP_FACTOR;
Sunny Goyal65190ae2022-08-02 14:16:26 -070027import static com.android.launcher3.icons.GraphicsUtils.getShapePath;
Pat Manning5f74bfd2022-07-20 12:08:54 +010028import static com.android.launcher3.testing.shared.ResourceUtils.pxFromDp;
Jon Miranda228877d2021-02-09 11:05:00 -050029
Sunny Goyal35c7b192021-04-20 16:51:10 -070030import android.annotation.SuppressLint;
Winson Chungb3800242013-10-24 11:01:54 -070031import android.content.Context;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070032import android.content.res.Configuration;
Winson Chungb3800242013-10-24 11:01:54 -070033import android.content.res.Resources;
Winson Chungb3800242013-10-24 11:01:54 -070034import android.graphics.Point;
Jon Miranda7ae64ff2016-11-21 16:18:46 -080035import android.graphics.PointF;
Winson Chungb3800242013-10-24 11:01:54 -070036import android.graphics.Rect;
Sunny Goyal35c7b192021-04-20 16:51:10 -070037import android.util.DisplayMetrics;
Sunny Goyal65190ae2022-08-02 14:16:26 -070038import android.util.SparseArray;
Sunny Goyal59d086c2018-05-07 17:31:40 -070039import android.view.Surface;
Winson Chungb3800242013-10-24 11:01:54 -070040
Sunny Goyal65190ae2022-08-02 14:16:26 -070041import androidx.annotation.NonNull;
Sihua Mae04aa202022-07-18 12:43:56 -070042import androidx.annotation.Nullable;
Sunny Goyal65190ae2022-08-02 14:16:26 -070043
Sunny Goyalc13403c2016-11-18 23:44:48 -080044import com.android.launcher3.CellLayout.ContainerType;
Jon Miranda228877d2021-02-09 11:05:00 -050045import com.android.launcher3.DevicePaddings.DevicePadding;
Tony Wickham8912b042018-11-29 15:28:53 -080046import com.android.launcher3.icons.DotRenderer;
Hyunyoung Song48cb7bc2018-09-25 17:03:34 -070047import com.android.launcher3.icons.IconNormalizer;
Sihua Mae04aa202022-07-18 12:43:56 -070048import com.android.launcher3.model.data.ItemInfo;
Sunny Goyal57b22792021-05-25 14:35:01 -070049import com.android.launcher3.uioverrides.ApiWrapper;
Sunny Goyalfd58da62020-08-11 12:06:49 -070050import com.android.launcher3.util.DisplayController;
51import com.android.launcher3.util.DisplayController.Info;
Sunny Goyalb46703d2020-05-27 17:52:03 -070052import com.android.launcher3.util.WindowBounds;
Winson1f064272016-07-18 17:18:02 -070053
Jon Miranda58561d42021-03-17 10:51:54 -040054import java.io.PrintWriter;
Brian Isganitis099945b2022-01-31 18:15:00 -050055import java.util.List;
Alex Chaue818bcb2022-09-02 17:27:11 +010056import java.util.Locale;
Jon Miranda58561d42021-03-17 10:51:54 -040057
Sunny Goyal35c7b192021-04-20 16:51:10 -070058@SuppressLint("NewApi")
Winson Chungb3800242013-10-24 11:01:54 -070059public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070060
Sunny Goyal8b9919d2021-04-07 14:45:17 -070061 private static final int DEFAULT_DOT_SIZE = 100;
Alex Chau206ede92022-08-01 17:46:12 +010062 private static final float ALL_APPS_TABLET_MAX_ROWS = 5.5f;
63
Sihua Mae04aa202022-07-18 12:43:56 -070064 public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f);
65 public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE;
66
Sunny Goyal57b22792021-05-25 14:35:01 -070067 // Ratio of empty space, qsb should take up to appear visually centered.
Pratyush9afe1ea2021-10-13 11:13:27 +000068 private final float mQsbCenterFactor;
Sunny Goyal1890f672020-04-30 12:28:00 -070069
Adam Cohen2e6da152015-05-06 11:42:25 -070070 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070071 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070072 private final DisplayMetrics mMetrics;
Winson Chungbe876472014-05-14 14:15:20 -070073
Sunny Goyalc6205602015-05-21 20:46:33 -070074 // Device properties
75 public final boolean isTablet;
Sunny Goyalc6205602015-05-21 20:46:33 -070076 public final boolean isPhone;
77 public final boolean transposeLayoutWithOrientation;
Sunny Goyal19ff7282021-04-22 10:12:54 -070078 public final boolean isTwoPanels;
Thales Limaa1012902022-01-13 17:58:42 +000079 public final boolean isQsbInline;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -070080
Sunny Goyalc6205602015-05-21 20:46:33 -070081 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -070082 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -080083 public final boolean isMultiWindowMode;
Alex Chau6ed408f2022-03-04 12:58:05 +000084 public final boolean isGestureMode;
Sunny Goyald70e75a2018-02-22 10:07:32 -080085
Sunny Goyal0addbf02020-04-28 14:17:35 -070086 public final int windowX;
87 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -070088 public final int widthPx;
89 public final int heightPx;
90 public final int availableWidthPx;
91 public final int availableHeightPx;
Sunny Goyal187b16c2022-03-01 16:53:23 -080092 public final int rotationHint;
Jon Mirandabba64512019-03-27 10:54:17 -070093
94 public final float aspectRatio;
95
Jon Mirandae126d722021-02-25 10:45:20 -050096 public final boolean isScalableGrid;
Thales Lima83bedbf2021-10-05 17:47:39 +010097 private final int mTypeIndex;
Jon Mirandae126d722021-02-25 10:45:20 -050098
Tony Wickhamd6b40372015-09-23 18:37:57 -070099 /**
100 * The maximum amount of left/right workspace padding as a percentage of the screen width.
101 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
102 * 7% of the screen width can be used as right padding.
103 */
104 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -0700105
Jon Miranda3f9bab22017-07-28 14:50:17 -0700106 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700107 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda80dda302021-07-28 14:14:59 -0700108 private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252;
109 private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700110
Sunny Goyalc6205602015-05-21 20:46:33 -0700111 // Workspace
Thales Limad90faab2021-09-21 17:18:47 +0100112 public final int desiredWorkspaceHorizontalMarginOriginalPx;
113 public int desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100114 public int gridVisualizationPaddingX;
115 public int gridVisualizationPaddingY;
Thales Lima78d00ad2021-09-30 11:29:06 +0100116 public Point cellLayoutBorderSpaceOriginalPx;
117 public Point cellLayoutBorderSpacePx;
Pat Manning08610ca2022-04-05 21:03:16 +0100118 public Rect cellLayoutPaddingPx = new Rect();
119
Sunny Goyalc6205602015-05-21 20:46:33 -0700120 public final int edgeMarginPx;
Alex Chau0c4e11b2022-07-08 18:41:36 +0100121 public final float workspaceContentScale;
Alex Chau906d8822022-05-23 10:42:25 +0100122 public final int workspaceSpringLoadedMinNextPageVisiblePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700123
Jon Miranda58561d42021-03-17 10:51:54 -0400124 private final int extraSpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500125 public int workspaceTopPadding;
126 public int workspaceBottomPadding;
127
Tony Wickham5edf9e22020-03-27 20:06:52 -0700128 // Workspace page indicator
129 public final int workspacePageIndicatorHeight;
130 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700131
Sunny Goyalc6205602015-05-21 20:46:33 -0700132 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400133 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700134 public int iconSizePx;
135 public int iconTextSizePx;
136 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700137 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -0700138
Jon Mirandaab3c6812021-06-28 15:42:28 -0700139 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800140 public int cellWidthPx;
141 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700142 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800143
Jon Mirandae126d722021-02-25 10:45:20 -0500144 public int cellYPaddingPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500145
Sunny Goyalc6205602015-05-21 20:46:33 -0700146 // Folder
Jon Mirandae126d722021-02-25 10:45:20 -0500147 public float folderLabelTextScale;
148 public int folderLabelTextSizePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700149 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700150 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700151
Jon Mirandae126d722021-02-25 10:45:20 -0500152 // Folder content
Thales Lima78d00ad2021-09-30 11:29:06 +0100153 public Point folderCellLayoutBorderSpacePx;
Jon Mirandae126d722021-02-25 10:45:20 -0500154 public int folderContentPaddingLeftRight;
155 public int folderContentPaddingTop;
156
Jon Mirandabf7d8122016-11-03 15:29:29 -0700157 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700158 public int folderCellWidthPx;
159 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700160
161 // Folder child
162 public int folderChildIconSizePx;
163 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700164 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700165
Sunny Goyalc6205602015-05-21 20:46:33 -0700166 // Hotseat
Thales Lima9938c2f2022-07-25 14:38:16 +0100167 public int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700168 public int hotseatCellHeightPx;
Pat Manning26f70f72022-07-07 13:50:39 +0100169 public final boolean areNavButtonsInline;
Jon Miranda18751b62017-07-31 17:25:27 -0700170 // In portrait: size = height, in landscape: size = width
171 public int hotseatBarSizePx;
Thales Limab8c05952022-05-23 16:58:38 +0100172 public int hotseatBarBottomSpacePx;
Pat Manning26f70f72022-07-07 13:50:39 +0100173 public int hotseatBarEndOffset;
Thales Limab8c05952022-05-23 16:58:38 +0100174 public int hotseatQsbSpace;
Pat Manningde25c0d2022-04-05 19:11:26 +0100175 public int springLoadedHotseatBarTopMarginPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700176 // Start is the side next to the nav bar, end is the side next to the workspace
177 public final int hotseatBarSidePaddingStartPx;
178 public final int hotseatBarSidePaddingEndPx;
Alex Chau206ede92022-08-01 17:46:12 +0100179 public int hotseatQsbWidth; // only used when isQsbInline
Sunny Goyal57b22792021-05-25 14:35:01 -0700180 public final int hotseatQsbHeight;
Thales Limab8c05952022-05-23 16:58:38 +0100181 public final int hotseatQsbVisualHeight;
182 private final int hotseatQsbShadowHeight;
Thales Limadd027342022-01-07 12:54:37 +0000183 public int hotseatBorderSpace;
Adam Cohen2e6da152015-05-06 11:42:25 -0700184
Alex Chau3d2c0622022-09-01 21:28:14 +0100185 // Bottom sheets
186 public int bottomSheetTopPadding;
187 public int bottomSheetOpenDuration;
188 public int bottomSheetCloseDuration;
189 public float bottomSheetWorkspaceScale;
190 public float bottomSheetDepth;
191
Sunny Goyalc6205602015-05-21 20:46:33 -0700192 // All apps
Thales Lima85c942f2021-12-31 13:04:20 +0000193 public Point allAppsBorderSpacePx;
Alex Chaub8c22e12022-02-14 18:35:58 +0000194 public int allAppsShiftRange;
195 public int allAppsTopPadding;
Alex Chau3d2c0622022-09-01 21:28:14 +0100196 public int allAppsOpenDuration;
197 public int allAppsCloseDuration;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700198 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700199 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700200 public int allAppsIconSizePx;
201 public int allAppsIconDrawablePaddingPx;
sfufa@google.comde013292021-09-21 18:22:44 -0700202 public int allAppsLeftRightPadding;
Alex Chau27b39b92022-01-14 18:02:18 +0000203 public int allAppsLeftRightMargin;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700204 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700205 public float allAppsIconTextSizePx;
206
Zak Cohen334efeb2021-03-19 16:42:07 -0700207 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700208 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000209 public int overviewTaskIconSizePx;
Alex Chauac9df382021-08-02 19:08:41 +0100210 public int overviewTaskIconDrawableSizePx;
211 public int overviewTaskIconDrawableSizeGridPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000212 public int overviewTaskThumbnailTopMarginPx;
Alex Chau19c6eca2022-03-10 20:12:56 +0000213 public final int overviewActionsHeight;
Alex Chaua2fc7642022-04-21 14:20:23 +0100214 public final int overviewActionsTopMarginPx;
Alex Chau1bf0fe12021-11-30 15:32:45 +0000215 public final int overviewActionsButtonSpacing;
Alex Chau5fd9d492021-07-22 17:27:11 +0100216 public int overviewPageSpacing;
217 public int overviewRowSpacing;
Alex Chau56bd2572021-11-03 18:48:18 +0000218 public int overviewGridSideMargin;
Zak Cohen334efeb2021-03-19 16:42:07 -0700219
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800220 // Widgets
Sihua Mae04aa202022-07-18 12:43:56 -0700221 private final ViewScaleProvider mViewScaleProvider;
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800222
Sunny Goyal47328fd2016-05-25 18:56:41 -0700223 // Drop Target
224 public int dropTargetBarSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100225 public int dropTargetBarTopMarginPx;
226 public int dropTargetBarBottomMarginPx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100227 public int dropTargetDragPaddingPx;
228 public int dropTargetTextSizePx;
Pat Manningde25c0d2022-04-05 19:11:26 +0100229 public int dropTargetHorizontalPaddingPx;
230 public int dropTargetVerticalPaddingPx;
231 public int dropTargetGapPx;
Alex Chau5b019302022-05-23 10:42:25 +0100232 public int dropTargetButtonWorkspaceEdgeGapPx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700233
Winson1f064272016-07-18 17:18:02 -0700234 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800235 private final Rect mInsets = new Rect();
236 public final Rect workspacePadding = new Rect();
Jon Miranda0bd63d12019-03-06 17:29:29 -0800237 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700238 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700239
Tony Wickhamf34bee82018-12-03 18:11:39 -0800240 // Notification dots
Sunny Goyal65190ae2022-08-02 14:16:26 -0700241 public final DotRenderer mDotRendererWorkSpace;
242 public final DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800243
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +0100244 // Taskbar
Tony Wickham15883892021-02-12 11:24:40 -0800245 public boolean isTaskbarPresent;
Tony Wickham635e1802021-07-22 14:28:04 -1000246 // Whether Taskbar will inset the bottom of apps by taskbarSize.
247 public boolean isTaskbarPresentInApps;
Tony Wickham15883892021-02-12 11:24:40 -0800248 public int taskbarSize;
Alex Chau6a7d1e22022-01-20 19:54:17 +0000249 public int stashedTaskbarSize;
Tony Wickham15883892021-02-12 11:24:40 -0800250
Alex Chaua02eddc2021-04-29 00:36:06 +0100251 // DragController
252 public int flingToDeleteThresholdVelocity;
253
Vinit Nayak17c4b332021-08-05 12:54:58 -0700254 /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */
Sunny Goyal19ff7282021-04-22 10:12:54 -0700255 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal65190ae2022-08-02 14:16:26 -0700256 SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode,
Sihua Mae04aa202022-07-18 12:43:56 -0700257 boolean transposeLayoutWithOrientation, boolean useTwoPanels, boolean isGestureMode,
258 @NonNull final ViewScaleProvider viewScaleProvider) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700259
Adam Cohen2e6da152015-05-06 11:42:25 -0700260 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700261 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800262 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500263 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +0000264 this.isGestureMode = isGestureMode;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700265 windowX = windowBounds.bounds.left;
266 windowY = windowBounds.bounds.top;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800267 this.rotationHint = windowBounds.rotationHint;
Alex Chaue0227552022-04-06 19:44:43 +0100268 mInsets.set(windowBounds.insets);
Winson Chungb3800242013-10-24 11:01:54 -0700269
Jon Mirandae126d722021-02-25 10:45:20 -0500270 isScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000271 // Determine device posture.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700272 mInfo = info;
Alex Chau29983072021-11-19 15:14:20 +0000273 isTablet = info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700274 isPhone = !isTablet;
Alex Chau90125822021-11-17 14:16:58 +0000275 isTwoPanels = isTablet && useTwoPanels;
Vinit Nayak58c27cc2022-02-16 17:42:21 -0800276 isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
Adam Cohen2e6da152015-05-06 11:42:25 -0700277
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000278 // Some more constants.
Alex Chau635b3ab2022-01-26 16:49:10 +0000279 context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700280 ? Configuration.ORIENTATION_LANDSCAPE
281 : Configuration.ORIENTATION_PORTRAIT,
Alex Chaua6907dc2022-03-18 15:24:07 +0000282 windowBounds);
Sunny Goyal1890f672020-04-30 12:28:00 -0700283 final Resources res = context.getResources();
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000284 mMetrics = res.getDisplayMetrics();
285
286 // Determine sizes.
287 widthPx = windowBounds.bounds.width();
288 heightPx = windowBounds.bounds.height();
289 availableWidthPx = windowBounds.availableSize.x;
Thales Limab8c05952022-05-23 16:58:38 +0100290 availableHeightPx = windowBounds.availableSize.y;
Alex Chaudfc8ddf2022-01-25 11:26:25 +0000291
292 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
293 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
294 mQsbCenterFactor = res.getFloat(R.dimen.qsb_center_factor);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700295
Thales Lima83bedbf2021-10-05 17:47:39 +0100296 if (isTwoPanels) {
297 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000298 mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100299 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000300 mTypeIndex = INDEX_TWO_PANEL_PORTRAIT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100301 }
302 } else {
303 if (isLandscape) {
Thales Lima12d0eff2022-03-25 17:06:11 +0000304 mTypeIndex = INDEX_LANDSCAPE;
Thales Lima83bedbf2021-10-05 17:47:39 +0100305 } else {
Thales Lima12d0eff2022-03-25 17:06:11 +0000306 mTypeIndex = INDEX_DEFAULT;
Thales Lima83bedbf2021-10-05 17:47:39 +0100307 }
308 }
309
Tony Wickham15883892021-02-12 11:24:40 -0800310 if (isTaskbarPresent) {
Tony Wickham15883892021-02-12 11:24:40 -0800311 taskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_size);
Alex Chau6a7d1e22022-01-20 19:54:17 +0000312 stashedTaskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
Tony Wickham15883892021-02-12 11:24:40 -0800313 }
Tony Wickham15883892021-02-12 11:24:40 -0800314
Winson Chungb3800242013-10-24 11:01:54 -0700315 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Alex Chau0c4e11b2022-07-08 18:41:36 +0100316 workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700317
Thales Limad90faab2021-09-21 17:18:47 +0100318 desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res);
319 desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx;
Alex Chau51da2192022-05-20 13:32:10 +0100320 gridVisualizationPaddingX = res.getDimensionPixelSize(
321 R.dimen.grid_visualization_horizontal_cell_spacing);
322 gridVisualizationPaddingY = res.getDimensionPixelSize(
323 R.dimen.grid_visualization_vertical_cell_spacing);
Samuel Fufaee9aff92021-04-05 13:30:40 -0500324
Alex Chaue0227552022-04-06 19:44:43 +0100325 bottomSheetTopPadding = mInsets.top // statusbar height
Andras Kloczl142b0542022-03-09 21:26:02 +0000326 + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding)
327 + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
Alex Chau3d2c0622022-09-01 21:28:14 +0100328 bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
329 bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
330 if (isTablet) {
331 bottomSheetWorkspaceScale = workspaceContentScale;
332 // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps.
333 // When depth is 0, wallpaper zoom is set to maxWallpaperScale.
334 // When depth is 1, wallpaper zoom is set to 1.
335 // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale:
336 float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale);
337 bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale,
338 maxWallpaperScale, 1f, 0f, 1f, LINEAR);
339 } else {
340 bottomSheetWorkspaceScale = 1f;
341 bottomSheetDepth = 0f;
342 }
Andras Kloczl142b0542022-03-09 21:26:02 +0000343
Jon Mirandae126d722021-02-25 10:45:20 -0500344 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
345 folderContentPaddingLeftRight =
346 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
347 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_content_padding_top);
348
Thales Lima78d00ad2021-09-30 11:29:06 +0100349 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv);
Thales Lima85c942f2021-12-31 13:04:20 +0000350 allAppsBorderSpacePx = new Point(
Thales Limabb7d3882021-12-22 12:56:29 +0000351 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics),
352 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics));
Thales Lima78d00ad2021-09-30 11:29:06 +0100353 cellLayoutBorderSpaceOriginalPx = new Point(cellLayoutBorderSpacePx);
Thales Limaa08a4432022-08-09 09:55:17 +0100354 folderCellLayoutBorderSpacePx = new Point(pxFromDp(inv.folderBorderSpaces.x, mMetrics),
355 pxFromDp(inv.folderBorderSpaces.y, mMetrics));
Jon Mirandae126d722021-02-25 10:45:20 -0500356
Tony Wickham5edf9e22020-03-27 20:06:52 -0700357 workspacePageIndicatorHeight = res.getDimensionPixelSize(
358 R.dimen.workspace_page_indicator_height);
359 mWorkspacePageIndicatorOverlapWorkspace =
360 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700361
Winson Chungb3800242013-10-24 11:01:54 -0700362 iconDrawablePaddingOriginalPx =
363 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Alex Chaua02eddc2021-04-29 00:36:06 +0100364
Sunny Goyal47328fd2016-05-25 18:56:41 -0700365 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100366 dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
367 dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin);
Alex Chaua02eddc2021-04-29 00:36:06 +0100368 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
369 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
Pat Manningde25c0d2022-04-05 19:11:26 +0100370 dropTargetHorizontalPaddingPx = res.getDimensionPixelSize(
371 R.dimen.drop_target_button_drawable_horizontal_padding);
372 dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
373 R.dimen.drop_target_button_drawable_vertical_padding);
374 dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
Alex Chau5b019302022-05-23 10:42:25 +0100375 dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
376 R.dimen.drop_target_button_workspace_edge_gap);
Alex Chaua02eddc2021-04-29 00:36:06 +0100377
Alex Chau906d8822022-05-23 10:42:25 +0100378 workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize(
379 R.dimen.dynamic_grid_spring_loaded_min_next_space_visible);
Sunny Goyald5190522017-04-24 03:06:54 -0700380
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700381 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700382
Thales Limaa1012902022-01-13 17:58:42 +0000383 hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
Thales Limab8c05952022-05-23 16:58:38 +0100384 hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
385 hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
386
Thales Lima12d0eff2022-03-25 17:06:11 +0000387 // Whether QSB might be inline in appropriate orientation (e.g. landscape).
388 boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT]
389 || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE]
390 : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE])
391 && hotseatQsbHeight > 0;
392 isQsbInline = inv.inlineQsb[mTypeIndex] && canQsbInline;
Alex Chau6ed408f2022-03-04 12:58:05 +0000393
Thales Lima425f6822022-05-10 13:44:58 -0300394 areNavButtonsInline = isTaskbarPresent && !isGestureMode;
Thales Lima9938c2f2022-07-25 14:38:16 +0100395 numShownHotseatIcons =
396 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000397
Sunny Goyal19ff7282021-04-22 10:12:54 -0700398 numShownAllAppsColumns =
399 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Thales Limab8c05952022-05-23 16:58:38 +0100400
401 int hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
402 int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
403 hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
404 // Have a little space between the inset and the QSB
405 if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) {
406 int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace);
407
408 // Only change the spaces if there is space
409 if (availableSpace > 0) {
410 // Make sure there is enough space between hotseat/QSB and QSB/navBar
411 if (availableSpace < minQsbMargin * 2) {
412 minQsbMargin = availableSpace / 2;
413 hotseatQsbSpace = minQsbMargin;
414 } else {
415 hotseatQsbSpace -= minQsbMargin;
416 }
417 }
418 hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin;
419
Thales Limaa1012902022-01-13 17:58:42 +0000420 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100421 hotseatBarBottomSpacePx = hotseatBarBottomSpace;
Thales Limaa1012902022-01-13 17:58:42 +0000422 }
Thales Lima425f6822022-05-10 13:44:58 -0300423
Pat Manningde25c0d2022-04-05 19:11:26 +0100424 springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize(
425 R.dimen.spring_loaded_hotseat_top_margin);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700426 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800427 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700428 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700429 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Thales Limab8c05952022-05-23 16:58:38 +0100430 updateHotseatSizes(pxFromDp(inv.iconSize[INDEX_DEFAULT], mMetrics));
Vinit Nayak8a3d0552022-08-05 10:43:29 -0700431 if (areNavButtonsInline && !isPhone) {
Pat Manning26f70f72022-07-07 13:50:39 +0100432 /*
433 * 3 nav buttons +
Vinit Nayakc7293172022-07-18 16:41:50 -0700434 * Spacing between nav buttons +
Pat Manning26f70f72022-07-07 13:50:39 +0100435 * Little space at the end for contextual buttons +
436 * Little space between icons and nav buttons
437 */
438 hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
Vinit Nayakc7293172022-07-18 16:41:50 -0700439 + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
440 + res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing)
Pat Manning26f70f72022-07-07 13:50:39 +0100441 + res.getDimensionPixelSize(R.dimen.taskbar_hotseat_nav_spacing);
442 } else {
443 hotseatBarEndOffset = 0;
444 }
Jon Miranda8bdb2222021-06-23 18:10:10 -0700445
Alex Chau635b3ab2022-01-26 16:49:10 +0000446 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chau5fd9d492021-07-22 17:27:11 +0100447 overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size);
Alex Chauac9df382021-08-02 19:08:41 +0100448 overviewTaskIconDrawableSizePx =
449 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size);
450 overviewTaskIconDrawableSizeGridPx =
451 res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700452 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx;
Jeremy Sim3c2c3f12022-05-16 20:37:43 -0700453 overviewActionsTopMarginPx = res.getDimensionPixelSize(R.dimen.overview_actions_top_margin);
Alex Chau635b3ab2022-01-26 16:49:10 +0000454 overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing);
455 overviewActionsButtonSpacing = res.getDimensionPixelSize(
456 R.dimen.overview_actions_button_spacing);
Alex Chau19c6eca2022-03-10 20:12:56 +0000457 overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height);
Jeremy Sim1cfe6d42022-07-15 14:40:38 -0700458 overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
Alex Chau635b3ab2022-01-26 16:49:10 +0000459 overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin);
Zak Cohen334efeb2021-03-19 16:42:07 -0700460
Jon Miranda2ed276e2017-06-29 11:36:34 -0700461 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400462 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700463
Jon Miranda2ed276e2017-06-29 11:36:34 -0700464 // Now that we have all of the variables calculated, we can tune certain sizes.
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400465 if (isScalableGrid && inv.devicePaddings != null) {
466 // Paddings were created assuming no scaling, so we first unscale the extra space.
Jon Mirandaab3c6812021-06-28 15:42:28 -0700467 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400468 DevicePadding padding = inv.devicePaddings.getDevicePadding(unscaledExtraSpace);
Jon Miranda228877d2021-02-09 11:05:00 -0500469
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400470 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
471 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
472 int paddingHotseatBottom = padding.getHotseatBottomPadding(unscaledExtraSpace);
473
Jon Mirandaab3c6812021-06-28 15:42:28 -0700474 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
475 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700476 }
Pat Manning08610ca2022-04-05 21:03:16 +0100477
478 int cellLayoutPadding =
479 isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
480 R.dimen.cell_layout_padding);
481 cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
482 cellLayoutPadding);
Sunny Goyal07b69292018-01-08 14:19:34 -0800483 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800484
Thales Lima425f6822022-05-10 13:44:58 -0300485 // Hotseat and QSB width depends on updated cellSize and workspace padding
Thales Lima9938c2f2022-07-25 14:38:16 +0100486 recalculateHotseatWidthAndBorderSpace(res);
Alex Chau206ede92022-08-01 17:46:12 +0100487
488 // AllApps height calculation depends on updated cellSize
489 if (isTablet) {
490 int collapseHandleHeight =
491 res.getDimensionPixelOffset(R.dimen.bottom_sheet_handle_area_height);
492 int contentHeight = heightPx - collapseHandleHeight - hotseatQsbHeight;
493 int targetContentHeight = (int) (allAppsCellHeightPx * ALL_APPS_TABLET_MAX_ROWS);
494 allAppsTopPadding = Math.max(mInsets.top, contentHeight - targetContentHeight);
495 allAppsShiftRange = heightPx - allAppsTopPadding;
496 } else {
497 allAppsTopPadding = 0;
498 allAppsShiftRange =
499 res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate);
500 }
Alex Chau3d2c0622022-09-01 21:28:14 +0100501 allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration);
502 allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration);
Thales Lima425f6822022-05-10 13:44:58 -0300503
Alex Chaua02eddc2021-04-29 00:36:06 +0100504 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
505 R.dimen.drag_flingToDeleteMinVelocity);
506
Sihua Mae04aa202022-07-18 12:43:56 -0700507 mViewScaleProvider = viewScaleProvider;
508
Tony Wickham1237df02017-02-24 08:59:36 -0800509 // This is done last, after iconSizePx is calculated above.
Sunny Goyal65190ae2022-08-02 14:16:26 -0700510 mDotRendererWorkSpace = createDotRenderer(iconSizePx, dotRendererCache);
511 mDotRendererAllApps = createDotRenderer(allAppsIconSizePx, dotRendererCache);
512 }
513
514 private static DotRenderer createDotRenderer(
515 int size, @NonNull SparseArray<DotRenderer> cache) {
516 DotRenderer renderer = cache.get(size);
517 if (renderer == null) {
518 renderer = new DotRenderer(size, getShapePath(DEFAULT_DOT_SIZE), DEFAULT_DOT_SIZE);
519 cache.put(size, renderer);
520 }
521 return renderer;
Adam Cohen63f1ec02014-08-12 09:23:13 -0700522 }
523
Thales Lima425f6822022-05-10 13:44:58 -0300524 /**
525 * QSB width is always calculated because when in 3 button nav the width doesn't follow the
526 * width of the hotseat.
527 */
Thales Lima9938c2f2022-07-25 14:38:16 +0100528 private int calculateQsbWidth(int hotseatBorderSpace) {
Thales Lima425f6822022-05-10 13:44:58 -0300529 if (isQsbInline) {
Alex Chau906d8822022-05-23 10:42:25 +0100530 int columns = getPanelCount() * inv.numColumns;
Thales Lima425f6822022-05-10 13:44:58 -0300531 return getIconToIconWidthForColumns(columns)
532 - iconSizePx * numShownHotseatIcons
533 - hotseatBorderSpace * numShownHotseatIcons;
534 } else {
535 int columns = inv.hotseatColumnSpan[mTypeIndex];
536 return getIconToIconWidthForColumns(columns);
537 }
538 }
Thales Lima2903a622022-03-17 13:52:19 +0000539
Thales Lima425f6822022-05-10 13:44:58 -0300540 private int getIconToIconWidthForColumns(int columns) {
541 return columns * getCellSize().x
542 + (columns - 1) * cellLayoutBorderSpacePx.x
Thales Lima1e8b45f2022-08-25 11:50:59 -0400543 - getCellHorizontalSpace();
Thales Limaa1012902022-01-13 17:58:42 +0000544 }
545
Thales Limad90faab2021-09-21 17:18:47 +0100546 private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) {
547 if (isVerticalBarLayout()) {
548 return 0;
549 }
550
Thales Lima83bedbf2021-10-05 17:47:39 +0100551 return isScalableGrid
552 ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics)
553 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
Thales Limad90faab2021-09-21 17:18:47 +0100554 }
555
Thales Limab8c05952022-05-23 16:58:38 +0100556 /** Updates hotseatCellHeightPx and hotseatBarSizePx */
557 private void updateHotseatSizes(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700558 // Ensure there is enough space for folder icons, which have a slightly larger radius.
559 hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR);
Thales Limab8c05952022-05-23 16:58:38 +0100560
Jon Miranda0d284852021-06-22 14:50:55 -0700561 if (isVerticalBarLayout()) {
562 hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
563 + hotseatBarSidePaddingEndPx;
Thales Limab8c05952022-05-23 16:58:38 +0100564 } else if (isQsbInline) {
565 hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight)
566 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700567 } else {
Thales Limab8c05952022-05-23 16:58:38 +0100568 hotseatBarSizePx = hotseatIconSizePx
569 + hotseatQsbSpace
570 + hotseatQsbVisualHeight
571 + hotseatBarBottomSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700572 }
573 }
574
Thales Lima9938c2f2022-07-25 14:38:16 +0100575 private void recalculateHotseatWidthAndBorderSpace(Resources res) {
576 hotseatBorderSpace = calculateHotseatBorderSpace();
577 hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace);
578 // Spaces should be correct when there nav buttons are not inline
579 if (!areNavButtonsInline) {
580 return;
581 }
582
583 // Get the maximum width that the hotseat can be
584 int columns = getPanelCount() * inv.numColumns;
585 int maxHotseatWidth = getIconToIconWidthForColumns(columns);
586 int sideSpace = (availableWidthPx - maxHotseatWidth) / 2;
587 int inlineButtonsOverlap = Math.max(0, hotseatBarEndOffset - sideSpace);
588 // decrease how much the nav buttons go "inside" the hotseat
589 maxHotseatWidth -= inlineButtonsOverlap;
590
591 // Get how much space is required to show the hotseat with QSB
592 int requiredWidth = getHotseatRequiredWidth();
593
594 // If spaces are fine, use them
595 if (requiredWidth <= maxHotseatWidth) {
596 return;
597 }
598
599 // Calculate the difference of widths and remove a little from each space between icons
600 // and QSB if it's inline
601 int spaceDiff = requiredWidth - maxHotseatWidth;
602 int numOfSpaces = numShownHotseatIcons - (isQsbInline ? 0 : 1);
603 hotseatBorderSpace -= (spaceDiff / numOfSpaces);
604
605 int minHotseatIconSpaceDp = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
606 int minHotseatQsbWidthDp = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
607
608 if (hotseatBorderSpace >= minHotseatIconSpaceDp) {
609 return;
610 }
611
612 // Border space can't be less than the minimum
613 hotseatBorderSpace = minHotseatIconSpaceDp;
614 requiredWidth = getHotseatRequiredWidth();
615
616 // If there is an inline qsb, change its size
617 if (isQsbInline) {
618 hotseatQsbWidth -= requiredWidth - maxHotseatWidth;
619 if (hotseatQsbWidth >= minHotseatQsbWidthDp) {
620 return;
621 }
622
623 // QSB can't be less than the minimum
624 hotseatQsbWidth = minHotseatQsbWidthDp;
625 }
626
627 // If it still doesn't fit, start removing icons
628 do {
629 numShownHotseatIcons--;
630 requiredWidth = getHotseatRequiredWidth();
631 } while (requiredWidth > maxHotseatWidth && numShownHotseatIcons > 1);
632
633 // Add back some space between the icons
634 spaceDiff = maxHotseatWidth - requiredWidth;
635 numOfSpaces = numShownHotseatIcons - (isQsbInline ? 0 : 1);
636 hotseatBorderSpace += (spaceDiff / numOfSpaces);
637 }
638
Thales Lima78d00ad2021-09-30 11:29:06 +0100639 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) {
Thales Lima080d8902022-03-28 15:30:29 +0100640 return getCellLayoutBorderSpace(idp, 1f);
Thales Lima080d8902022-03-28 15:30:29 +0100641 }
642
643 private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100644 if (!isScalableGrid) {
645 return new Point(0, 0);
646 }
647
Thales Lima080d8902022-03-28 15:30:29 +0100648 int horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale);
649 int verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale);
Thales Lima78d00ad2021-09-30 11:29:06 +0100650
651 return new Point(horizontalSpacePx, verticalSpacePx);
652 }
653
Sunny Goyal69a8eec2021-07-22 10:02:50 -0700654 public Info getDisplayInfo() {
655 return mInfo;
656 }
657
Jon Miranda611dba42021-03-02 14:12:13 -0500658 /**
659 * We inset the widget padding added by the system and instead rely on the border spacing
660 * between cells to create reliable consistency between widgets
661 */
662 public boolean shouldInsetWidgets() {
663 Rect widgetPadding = inv.defaultWidgetPadding;
664
Jon Miranda49811182021-06-03 09:52:40 -0700665 // Check all sides to ensure that the widget won't overlap into another cell, or into
666 // status bar.
667 return workspaceTopPadding > widgetPadding.top
Thales Lima78d00ad2021-09-30 11:29:06 +0100668 && cellLayoutBorderSpacePx.x > widgetPadding.left
669 && cellLayoutBorderSpacePx.y > widgetPadding.top
670 && cellLayoutBorderSpacePx.x > widgetPadding.right
671 && cellLayoutBorderSpacePx.y > widgetPadding.bottom;
Jon Miranda611dba42021-03-02 14:12:13 -0500672 }
Jon Mirandae126d722021-02-25 10:45:20 -0500673
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700674 public Builder toBuilder(Context context) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800675 WindowBounds bounds = new WindowBounds(
676 widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700677 bounds.bounds.offsetTo(windowX, windowY);
Alex Chaue0227552022-04-06 19:44:43 +0100678 bounds.insets.set(mInsets);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700679
680 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
681 dotRendererCache.put(iconSizePx, mDotRendererWorkSpace);
682 dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps);
683
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700684 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700685 .setWindowBounds(bounds)
686 .setUseTwoPanels(isTwoPanels)
Alex Chau6ed408f2022-03-04 12:58:05 +0000687 .setMultiWindowMode(isMultiWindowMode)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700688 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000689 .setGestureMode(isGestureMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800690 }
691
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700692 public DeviceProfile copy(Context context) {
693 return toBuilder(context).build();
694 }
695
696 /**
697 * TODO: Move this to the builder as part of setMultiWindowMode
698 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700699 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700700 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700701 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700702 .setMultiWindowMode(true)
703 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800704
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800705 // We use these scales to measure and layout the widgets using their full invariant profile
706 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
707 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
708 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
Sihua Mae04aa202022-07-18 12:43:56 -0700709 if (appWidgetScaleX != 1 || appWidgetScaleY != 1) {
710 final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY);
711 profile = profile.toBuilder(context)
712 .setViewScaleProvider(i -> p)
713 .build();
714 }
715
716 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800717
Jon Miranda93e1f042016-11-11 14:13:04 -0800718 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700719 }
720
Adam Cohen63f1ec02014-08-12 09:23:13 -0700721 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400722 * Checks if there is enough space for labels on the workspace.
723 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700724 * It is important to call this method after the All Apps variables have been set.
725 */
Jon Miranda941375e2021-03-31 13:10:45 -0400726 private void hideWorkspaceLabelsIfNotEnoughSpace() {
727 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
728 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
729 - iconTextHeight;
730
731 // We want enough space so that the text is closer to its corresponding icon.
732 if (workspaceCellPaddingY < iconTextHeight) {
733 iconTextSizePx = 0;
734 iconDrawablePaddingPx = 0;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700735 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda941375e2021-03-31 13:10:45 -0400736 autoResizeAllAppsCells();
737 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700738 }
Jon Miranda1091e532017-07-21 13:31:50 -0700739
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700740 /**
741 * Re-computes the all-apps cell size to be independent of workspace
742 */
743 public void autoResizeAllAppsCells() {
Jon Miranda941375e2021-03-31 13:10:45 -0400744 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
745 int topBottomPadding = textHeight;
Jon Miranda1091e532017-07-21 13:31:50 -0700746 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
Jon Miranda941375e2021-03-31 13:10:45 -0400747 + textHeight + (topBottomPadding * 2);
Jon Miranda1091e532017-07-21 13:31:50 -0700748 }
749
Thales Limab7ef5692022-03-10 10:32:36 +0000750 private void updateAllAppsContainerWidth(Resources res) {
Pat Manning08610ca2022-04-05 21:03:16 +0100751 int cellLayoutHorizontalPadding =
752 (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
Alex Chau27b39b92022-01-14 18:02:18 +0000753 if (isTablet) {
Thales Limab7ef5692022-03-10 10:32:36 +0000754 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100755 res.getDimensionPixelSize(R.dimen.all_apps_bottom_sheet_horizontal_padding);
756
sfufa@google.comde013292021-09-21 18:22:44 -0700757 int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
Thales Limab7ef5692022-03-10 10:32:36 +0000758 + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
Alex Chau27b39b92022-01-14 18:02:18 +0000759 + allAppsLeftRightPadding * 2;
760 allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
sfufa@google.comde013292021-09-21 18:22:44 -0700761 } else {
762 allAppsLeftRightPadding =
Pat Manning08610ca2022-04-05 21:03:16 +0100763 desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding;
sfufa@google.comde013292021-09-21 18:22:44 -0700764 }
765 }
766
Jon Miranda228877d2021-02-09 11:05:00 -0500767 /**
768 * Returns the amount of extra (or unused) vertical space.
769 */
770 private int updateAvailableDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700771 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800772
Pat Manning08610ca2022-04-05 21:03:16 +0100773 updateWorkspacePadding();
Jon Mirandae126d722021-02-25 10:45:20 -0500774
775 // Check to see if the icons fit within the available height.
Pat Manninga2e14992022-04-22 11:29:17 +0100776 float usedHeight = getCellLayoutHeightSpecification();
Pat Manning25d53342022-05-10 09:58:49 +0000777 final int maxHeight = getCellLayoutHeight();
Jon Miranda228877d2021-02-09 11:05:00 -0500778 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500779 float scaleY = maxHeight / usedHeight;
780 boolean shouldScale = scaleY < 1f;
781
782 float scaleX = 1f;
783 if (isScalableGrid) {
784 // We scale to fit the cellWidth and cellHeight in the available space.
785 // The benefit of scalable grids is that we can get consistent aspect ratios between
786 // devices.
Pat Manninga2e14992022-04-22 11:29:17 +0100787 float usedWidth =
788 getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
Jon Mirandae126d722021-02-25 10:45:20 -0500789 // We do not subtract padding here, as we also scale the workspace padding if needed.
790 scaleX = availableWidthPx / usedWidth;
791 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700792 }
Jon Mirandae126d722021-02-25 10:45:20 -0500793
794 if (shouldScale) {
795 float scale = Math.min(scaleX, scaleY);
796 updateIconSize(scale, res);
Pat Manninga2e14992022-04-22 11:29:17 +0100797 extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
Jon Mirandae126d722021-02-25 10:45:20 -0500798 }
799
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700800 updateAvailableFolderCellDimensions(res);
Jon Miranda228877d2021-02-09 11:05:00 -0500801 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700802 }
803
Pat Manninga2e14992022-04-22 11:29:17 +0100804 private int getCellLayoutHeightSpecification() {
Pat Manning08610ca2022-04-05 21:03:16 +0100805 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1))
806 + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom;
807 }
808
Pat Manninga2e14992022-04-22 11:29:17 +0100809 private int getCellLayoutWidthSpecification() {
Pat Manning25d53342022-05-10 09:58:49 +0000810 int numColumns = getPanelCount() * inv.numColumns;
Pat Manning08610ca2022-04-05 21:03:16 +0100811 return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1))
812 + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
Jon Mirandae126d722021-02-25 10:45:20 -0500813 }
814
Jon Miranda6f7e9702019-09-16 14:44:14 -0700815 /**
816 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
817 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
818 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
819 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800820 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -0700821 // Icon scale should never exceed 1, otherwise pixellation may occur.
822 iconScale = Math.min(1f, scale);
823 cellScaleToFit = scale;
824
Jon Miranda18751b62017-07-31 17:25:27 -0700825 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800826 final boolean isVerticalLayout = isVerticalBarLayout();
Thales Lima83bedbf2021-10-05 17:47:39 +0100827 float invIconSizeDp = inv.iconSize[mTypeIndex];
828 float invIconTextSizeSp = inv.iconTextSize[mTypeIndex];
Andras Kloczl30fe9152021-08-05 18:02:29 +0200829
Jon Mirandaab3c6812021-06-28 15:42:28 -0700830 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, iconScale));
Jon Mirandaab3c6812021-06-28 15:42:28 -0700831 iconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * iconScale);
832 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700833
Thales Lima080d8902022-03-28 15:30:29 +0100834 cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500835
836 if (isScalableGrid) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100837 cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale);
838 cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500839 int cellContentHeight = iconSizePx + iconDrawablePaddingPx
840 + Utilities.calculateTextHeight(iconTextSizePx);
841 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
Thales Limad90faab2021-09-21 17:18:47 +0100842 desiredWorkspaceHorizontalMarginPx =
843 (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -0500844 } else {
Jon Mirandae126d722021-02-25 10:45:20 -0500845 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700846 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR)
847 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -0500848 + Utilities.calculateTextHeight(iconTextSizePx);
849 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
850 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
851 && !isMultiWindowMode) {
852 // Ensures that the label is closer to its corresponding icon. This is not an issue
853 // with vertical bar layout or multi-window mode since the issue is handled
854 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
855 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
856 iconDrawablePaddingPx = cellPaddingY;
857 }
Jon Miranda846455e2017-10-02 14:58:52 -0700858 }
Jon Miranda18751b62017-07-31 17:25:27 -0700859
Sunny Goyalae190ff2020-04-14 00:19:01 +0000860 // All apps
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500861 updateAllAppsIconSize(scale, res);
Winson Chungb3800242013-10-24 11:01:54 -0700862
Thales Limab8c05952022-05-23 16:58:38 +0100863 updateHotseatSizes(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700864
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700865 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -0700866 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
867 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Winson Chung0f785722015-04-08 10:27:49 -0700868 }
869
Thales Lima425f6822022-05-10 13:44:58 -0300870 /**
871 * Hotseat width spans a certain number of columns on scalable grids.
872 * This method calculates the space between the icons to achieve that width.
873 */
874 private int calculateHotseatBorderSpace() {
875 if (!isScalableGrid) return 0;
Thales Lima9938c2f2022-07-25 14:38:16 +0100876 int columns = inv.hotseatColumnSpan[mTypeIndex];
877 float hotseatWidthPx = getIconToIconWidthForColumns(columns);
878 float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
879 return (int) (hotseatWidthPx - hotseatIconsTotalPx) / (numShownHotseatIcons - 1);
Thales Lima425f6822022-05-10 13:44:58 -0300880 }
881
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500882
883 /**
884 * Updates the iconSize for allApps* variants.
885 */
Brian Isganitisa9a78112022-05-23 18:11:47 -0700886 private void updateAllAppsIconSize(float scale, Resources res) {
Thales Lima080d8902022-03-28 15:30:29 +0100887 allAppsBorderSpacePx = new Point(
888 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale),
889 pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale));
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700890 // AllApps cells don't have real space between cells,
891 // so we add the border space to the cell height
892 allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics, scale)
893 + allAppsBorderSpacePx.y;
894 // but width is just the cell,
895 // the border is added in #updateAllAppsContainerWidth
Thales Lima080d8902022-03-28 15:30:29 +0100896 if (isScalableGrid) {
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500897 allAppsIconSizePx =
Brandon Dayauon969f6a82022-05-19 09:46:47 -0700898 pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics, scale);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500899 allAppsIconTextSizePx =
Brandon Dayauon969f6a82022-05-19 09:46:47 -0700900 pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics, scale);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500901 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -0700902 allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500903 } else {
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700904 float invIconSizeDp = inv.allAppsIconSize[mTypeIndex];
905 float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex];
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500906 allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
907 allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Brandon Dayauon07ca8842022-04-27 10:52:28 -0700908 allAppsIconDrawablePaddingPx =
909 res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding);
Brandon Dayauon7a8a9ed2022-06-06 14:32:22 -0700910 allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500911 }
912
Thales Limab7ef5692022-03-10 10:32:36 +0000913 updateAllAppsContainerWidth(res);
Brian Isganitis25b2ac82022-01-28 16:25:13 -0500914 if (isVerticalBarLayout()) {
915 hideWorkspaceLabelsIfNotEnoughSpace();
916 }
917 }
918
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700919 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700920 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700921
Jon Mirandae126d722021-02-25 10:45:20 -0500922 final int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_height);
923
Jon Mirandac1b23992016-12-13 08:57:36 -0800924 // Don't let the folder get too close to the edges of the screen.
Jon Miranda1786df32018-09-25 13:05:23 -0700925 int folderMargin = edgeMarginPx * 2;
Sunny Goyal07b69292018-01-08 14:19:34 -0800926 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -0800927
928 // Check if the icons fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -0500929 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Thales Lima78d00ad2021-09-30 11:29:06 +0100930 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx.y);
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800931 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderBottomPanelSize
Jon Mirandae126d722021-02-25 10:45:20 -0500932 - folderMargin - folderContentPaddingTop;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800933 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -0800934
935 // Check if the icons fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -0500936 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Thales Lima78d00ad2021-09-30 11:29:06 +0100937 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x);
Jon Mirandae126d722021-02-25 10:45:20 -0500938 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin
939 - folderContentPaddingLeftRight * 2;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800940 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -0800941
942 float scale = Math.min(scaleX, scaleY);
943 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700944 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700945 }
946 }
947
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700948 private void updateFolderCellSize(float scale, Resources res) {
Thales Lima83bedbf2021-10-05 17:47:39 +0100949 float invIconSizeDp = isVerticalBarLayout()
Thales Lima12d0eff2022-03-25 17:06:11 +0000950 ? inv.iconSize[INDEX_LANDSCAPE]
951 : inv.iconSize[INDEX_DEFAULT];
Sunny Goyal35c7b192021-04-20 16:51:10 -0700952 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Thales Lima83bedbf2021-10-05 17:47:39 +0100953 folderChildTextSizePx =
Thales Lima12d0eff2022-03-25 17:06:11 +0000954 pxFromSp(inv.iconTextSize[INDEX_DEFAULT], mMetrics, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500955 folderLabelTextSizePx = (int) (folderChildTextSizePx * folderLabelTextScale);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700956
957 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700958
Jon Miranda823da222021-03-23 08:08:45 -0400959 if (isScalableGrid) {
Thales Limaa08a4432022-08-09 09:55:17 +0100960 folderCellWidthPx = pxFromDp(inv.folderCellSize.x, mMetrics, scale);
961 folderCellHeightPx = pxFromDp(inv.folderCellSize.y, mMetrics, scale);
Jon Mirandaf33f5b32021-07-22 17:15:31 -0700962
Thales Limaa08a4432022-08-09 09:55:17 +0100963 folderCellLayoutBorderSpacePx = new Point(
964 pxFromDp(inv.folderBorderSpaces.x, mMetrics, scale),
965 pxFromDp(inv.folderBorderSpaces.y, mMetrics, scale));
966 folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx.x;
967 folderContentPaddingTop = pxFromDp(inv.folderTopPadding, mMetrics, scale);
Jon Miranda823da222021-03-23 08:08:45 -0400968 } else {
969 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
970 * scale);
971 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
972 * scale);
973
974 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
975 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
976 }
977
Jonathan Miranda9ad87462017-07-26 17:41:02 +0000978 folderChildDrawablePaddingPx = Math.max(0,
979 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700980 }
981
Winson1f064272016-07-18 17:18:02 -0700982 public void updateInsets(Rect insets) {
983 mInsets.set(insets);
984 }
985
Sunny Goyalae6e3182019-04-30 12:04:37 -0700986 /**
987 * The current device insets. This is generally same as the insets being dispatched to
988 * {@link Insettable} elements, but can differ if the element is using a different profile.
989 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800990 public Rect getInsets() {
991 return mInsets;
992 }
993
Sunny Goyal756cd262015-08-20 12:33:21 -0700994 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700995 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700996 }
997
Sunny Goyal19ff7282021-04-22 10:12:54 -0700998 public Point getCellSize(Point result) {
999 if (result == null) {
1000 result = new Point();
1001 }
Thales Limad1df5fc2021-09-03 18:37:19 +01001002
Pat Manning25d53342022-05-10 09:58:49 +00001003 int shortcutAndWidgetContainerWidth =
1004 getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right);
1005 result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x,
1006 inv.numColumns);
1007 int shortcutAndWidgetContainerHeight =
1008 getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom);
1009 result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y,
1010 inv.numRows);
Sunny Goyal3e8a04b2022-05-09 19:31:45 +00001011 return result;
Pat Manningb45d6c42022-05-03 14:32:06 +01001012 }
1013
1014 /**
Thales Lima1e8b45f2022-08-25 11:50:59 -04001015 * Returns the left and right space on the cell, which is the cell width - icon size
1016 */
1017 public int getCellHorizontalSpace() {
1018 return getCellSize().x - iconSizePx;
1019 }
1020
1021 /**
Pat Manning25d53342022-05-10 09:58:49 +00001022 * Gets the number of panels within the workspace.
1023 */
1024 public int getPanelCount() {
1025 return isTwoPanels ? 2 : 1;
1026 }
1027
1028 /**
Pat Manningde25c0d2022-04-05 19:11:26 +01001029 * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the
1030 * bottom of the screen.
1031 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001032 private int getVerticalHotseatLastItemBottomOffset(Context context) {
1033 Rect hotseatBarPadding = getHotseatLayoutPadding(context);
Pat Manningde25c0d2022-04-05 19:11:26 +01001034 int cellHeight = calculateCellHeight(
Pat Manning5f74bfd2022-07-20 12:08:54 +01001035 heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
Pat Manningde25c0d2022-04-05 19:11:26 +01001036 numShownHotseatIcons);
Pat Manningde25c0d2022-04-05 19:11:26 +01001037 int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001038 return extraIconEndSpacing + hotseatBarPadding.bottom;
Pat Manningde25c0d2022-04-05 19:11:26 +01001039 }
1040
1041 /**
1042 * Gets the scaled top of the workspace in px for the spring-loaded edit state.
1043 */
Pat Manning25d53342022-05-10 09:58:49 +00001044 public float getCellLayoutSpringLoadShrunkTop() {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001045 return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx
Pat Manningde25c0d2022-04-05 19:11:26 +01001046 + dropTargetBarBottomMarginPx;
Pat Manningde25c0d2022-04-05 19:11:26 +01001047 }
1048
1049 /**
1050 * Gets the scaled bottom of the workspace in px for the spring-loaded edit state.
1051 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001052 public float getCellLayoutSpringLoadShrunkBottom(Context context) {
Pat Manningde25c0d2022-04-05 19:11:26 +01001053 int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001054 return heightPx - (isVerticalBarLayout()
1055 ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
Pat Manningde25c0d2022-04-05 19:11:26 +01001056 }
1057
Pat Manningea5c1d22022-04-14 10:58:16 +01001058 /**
Pat Manninga2e14992022-04-22 11:29:17 +01001059 * Gets the scale of the workspace for the spring-loaded edit state.
1060 */
Pat Manning5f74bfd2022-07-20 12:08:54 +01001061 public float getWorkspaceSpringLoadScale(Context context) {
1062 float scale =
1063 (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop())
1064 / getCellLayoutHeight();
Pat Manninga2e14992022-04-22 11:29:17 +01001065 scale = Math.min(scale, 1f);
1066
Pat Manninge63dd252022-08-02 16:15:29 +01001067 // Reduce scale if next pages would not be visible after scaling the workspace.
Pat Manning25d53342022-05-10 09:58:49 +00001068 int workspaceWidth = availableWidthPx;
Pat Manninga2e14992022-04-22 11:29:17 +01001069 float scaledWorkspaceWidth = workspaceWidth * scale;
Alex Chau906d8822022-05-23 10:42:25 +01001070 float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
Pat Manninga2e14992022-04-22 11:29:17 +01001071 if (scaledWorkspaceWidth > maxAvailableWidth) {
1072 scale *= maxAvailableWidth / scaledWorkspaceWidth;
1073 }
1074 return scale;
1075 }
1076
Pat Manning25d53342022-05-10 09:58:49 +00001077 /**
1078 * Gets the width of a single Cell Layout, aka a single panel within a Workspace.
1079 *
1080 * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel
1081 * layouts have two Cell Layouts per workspace.
1082 */
1083 public int getCellLayoutWidth() {
1084 return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
Alex Chau60953332021-11-24 12:41:07 +00001085 }
1086
Pat Manning25d53342022-05-10 09:58:49 +00001087 /**
1088 * Gets the height of a single Cell Layout, aka a single panel within a Workspace.
1089 *
1090 * <p>This is the height of a Workspace, less its vertical padding.
1091 */
1092 public int getCellLayoutHeight() {
1093 return availableHeightPx - getTotalWorkspacePadding().y;
Pat Manning08610ca2022-04-05 21:03:16 +01001094 }
1095
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001096 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -08001097 return new Point(workspacePadding.left + workspacePadding.right,
1098 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001099 }
1100
1101 /**
Sunny Goyal07b69292018-01-08 14:19:34 -08001102 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
1103 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -07001104 */
Sunny Goyal07b69292018-01-08 14:19:34 -08001105 private void updateWorkspacePadding() {
1106 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -07001107 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -08001108 padding.top = 0;
1109 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001110 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001111 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -07001112 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -07001113 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -07001114 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -07001115 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -07001116 }
Winson Chungb3800242013-10-24 11:01:54 -07001117 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001118 // Pad the bottom of the workspace with hotseat bar
1119 // and leave a bit of space in case a widget go all the way down
1120 int paddingBottom = hotseatBarSizePx + workspaceBottomPadding
1121 + workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace
1122 - mInsets.bottom;
Pat Manning08610ca2022-04-05 21:03:16 +01001123 int paddingTop = workspaceTopPadding + (isScalableGrid ? 0 : edgeMarginPx);
1124 int paddingSide = desiredWorkspaceHorizontalMarginPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +01001125
Pat Manning08610ca2022-04-05 21:03:16 +01001126 padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -07001127 }
Pat Manning08610ca2022-04-05 21:03:16 +01001128 insetPadding(workspacePadding, cellLayoutPaddingPx);
1129 }
1130
1131 private void insetPadding(Rect paddings, Rect insets) {
1132 insets.left = Math.min(insets.left, paddings.left);
1133 paddings.left -= insets.left;
1134
1135 insets.top = Math.min(insets.top, paddings.top);
1136 paddings.top -= insets.top;
1137
1138 insets.right = Math.min(insets.right, paddings.right);
1139 paddings.right -= insets.right;
1140
1141 insets.bottom = Math.min(insets.bottom, paddings.bottom);
1142 paddings.bottom -= insets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -07001143 }
1144
Sunny Goyal57b22792021-05-25 14:35:01 -07001145 /**
1146 * Returns the padding for hotseat view
1147 */
1148 public Rect getHotseatLayoutPadding(Context context) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001149 Rect hotseatBarPadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001150 if (isVerticalBarLayout()) {
Sihua Ma38bb3b02022-03-21 22:20:14 -07001151 // The hotseat icons will be placed in the middle of the hotseat cells.
1152 // Changing the hotseatCellHeightPx is not affecting hotseat icon positions
1153 // in vertical bar layout.
1154 // Workspace icons are moved up by a small factor. The variable diffOverlapFactor
1155 // is set to account for that difference.
1156 float diffOverlapFactor = iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2;
Pat Manning08610ca2022-04-05 21:03:16 +01001157 int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top
1158 - diffOverlapFactor), 0);
1159 int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom
Sihua Ma38bb3b02022-03-21 22:20:14 -07001160 + diffOverlapFactor), 0);
1161
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001162 if (isSeascape()) {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001163 hotseatBarPadding.set(mInsets.left + hotseatBarSidePaddingStartPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001164 hotseatBarSidePaddingEndPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001165 } else {
Pat Manning5f74bfd2022-07-20 12:08:54 +01001166 hotseatBarPadding.set(hotseatBarSidePaddingEndPx, paddingTop,
Pat Manning08610ca2022-04-05 21:03:16 +01001167 mInsets.right + hotseatBarSidePaddingStartPx, paddingBottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001168 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001169 } else if (isTaskbarPresent) {
Alex Chau51da2192022-05-20 13:32:10 +01001170 // Center the QSB vertically with hotseat
Thales Limab8c05952022-05-23 16:58:38 +01001171 int hotseatBarBottomPadding = getHotseatBarBottomPadding();
1172 int hotseatBarTopPadding =
1173 hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx;
Alex Chau51da2192022-05-20 13:32:10 +01001174
Thales Lima612230d2022-03-31 18:04:37 +01001175 // Push icons to the side
Thales Lima9938c2f2022-07-25 14:38:16 +01001176 int requiredWidth = getHotseatRequiredWidth();
Pat Manning26f70f72022-07-07 13:50:39 +01001177 int hotseatWidth = Math.min(requiredWidth, availableWidthPx - hotseatBarEndOffset);
Thales Lima612230d2022-03-31 18:04:37 +01001178 int sideSpacing = (availableWidthPx - hotseatWidth) / 2;
Thales Lima612230d2022-03-31 18:04:37 +01001179
Pat Manning5f74bfd2022-07-20 12:08:54 +01001180 hotseatBarPadding.set(sideSpacing, hotseatBarTopPadding, sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001181 hotseatBarBottomPadding);
Alex Chau51da2192022-05-20 13:32:10 +01001182
1183 boolean isRtl = Utilities.isRtl(context.getResources());
Thales Lima612230d2022-03-31 18:04:37 +01001184 if (isRtl) {
Thales Lima9938c2f2022-07-25 14:38:16 +01001185 hotseatBarPadding.right += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001186 } else {
Thales Lima9938c2f2022-07-25 14:38:16 +01001187 hotseatBarPadding.left += getAdditionalQsbSpace();
Thales Lima612230d2022-03-31 18:04:37 +01001188 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001189
Pat Manning26f70f72022-07-07 13:50:39 +01001190 if (hotseatBarEndOffset > sideSpacing) {
Thales Lima612230d2022-03-31 18:04:37 +01001191 int diff = isRtl
Pat Manning26f70f72022-07-07 13:50:39 +01001192 ? sideSpacing - hotseatBarEndOffset
1193 : hotseatBarEndOffset - sideSpacing;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001194 hotseatBarPadding.left -= diff;
1195 hotseatBarPadding.right += diff;
Sunny Goyal57b22792021-05-25 14:35:01 -07001196 }
Thales Lima425f6822022-05-10 13:44:58 -03001197 } else if (isScalableGrid) {
Alex Chau206ede92022-08-01 17:46:12 +01001198 int sideSpacing = (availableWidthPx - hotseatQsbWidth) / 2;
Pat Manning5f74bfd2022-07-20 12:08:54 +01001199 hotseatBarPadding.set(sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001200 0,
Thales Lima425f6822022-05-10 13:44:58 -03001201 sideSpacing,
Thales Limab8c05952022-05-23 16:58:38 +01001202 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001203 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001204 // We want the edges of the hotseat to line up with the edges of the workspace, but the
1205 // icons in the hotseat are a different size, and so don't line up perfectly. To account
1206 // for this, we pad the left and right of the hotseat with half of the difference of a
1207 // workspace cell vs a hotseat cell.
1208 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001209 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001210 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Pat Manning5f74bfd2022-07-20 12:08:54 +01001211 hotseatBarPadding.set(
Thales Limab8c05952022-05-23 16:58:38 +01001212 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
1213 + mInsets.left,
1214 0,
Pat Manning08610ca2022-04-05 21:03:16 +01001215 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
Sunny Goyal786940a2020-06-02 02:31:31 -07001216 + mInsets.right,
Thales Limab8c05952022-05-23 16:58:38 +01001217 getHotseatBarBottomPadding());
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001218 }
Pat Manning5f74bfd2022-07-20 12:08:54 +01001219 return hotseatBarPadding;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -07001220 }
1221
Thales Lima9938c2f2022-07-25 14:38:16 +01001222 private int getAdditionalQsbSpace() {
1223 return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0;
1224 }
1225
1226 /**
1227 * Calculate how much space the hotseat needs to be shown completely
1228 */
1229 private int getHotseatRequiredWidth() {
1230 int additionalQsbSpace = getAdditionalQsbSpace();
1231 return iconSizePx * numShownHotseatIcons
1232 + hotseatBorderSpace * (numShownHotseatIcons - 1)
1233 + additionalQsbSpace;
1234 }
1235
Winsonfadbe8f2016-07-22 16:35:37 -07001236 /**
Sunny Goyal57b22792021-05-25 14:35:01 -07001237 * Returns the number of pixels the QSB is translated from the bottom of the screen.
1238 */
1239 public int getQsbOffsetY() {
Thales Limaa1012902022-01-13 17:58:42 +00001240 if (isQsbInline) {
Thales Limab8c05952022-05-23 16:58:38 +01001241 return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2);
1242 } else if (isTaskbarPresent) { // QSB on top
1243 return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight;
Jonathan Miranda8f16a772021-07-23 23:10:37 +00001244 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001245 return hotseatBarBottomSpacePx - hotseatQsbShadowHeight;
Jonathan Miranda7a273e22021-06-24 21:29:10 +00001246 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001247 }
1248
Thales Limab8c05952022-05-23 16:58:38 +01001249 /**
1250 * Returns the number of pixels the hotseat is translated from the bottom of the screen.
1251 */
1252 private int getHotseatBarBottomPadding() {
1253 if (isTaskbarPresent) { // QSB on top or inline
1254 return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2);
Thales Limaa1012902022-01-13 17:58:42 +00001255 } else {
Thales Limab8c05952022-05-23 16:58:38 +01001256 return hotseatBarSizePx - hotseatCellHeightPx;
Thales Limaa1012902022-01-13 17:58:42 +00001257 }
Sunny Goyal57b22792021-05-25 14:35:01 -07001258 }
1259
1260 /**
Alex Chau51da2192022-05-20 13:32:10 +01001261 * Returns the number of pixels the taskbar is translated from the bottom of the screen.
1262 */
1263 public int getTaskbarOffsetY() {
1264 int taskbarIconBottomSpace = (taskbarSize - iconSizePx) / 2;
1265 int launcherIconBottomSpace =
1266 Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY);
Thales Limab8c05952022-05-23 16:58:38 +01001267 return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace;
Alex Chau51da2192022-05-20 13:32:10 +01001268 }
1269
1270 /**
Alex Chaua2fc7642022-04-21 14:20:23 +01001271 * Returns the number of pixels required below OverviewActions excluding insets.
1272 */
1273 public int getOverviewActionsClaimedSpaceBelow() {
1274 if (isTaskbarPresent && !isGestureMode) {
1275 // Align vertically to where nav buttons are.
Thales Limab8c05952022-05-23 16:58:38 +01001276 return ((taskbarSize - overviewActionsHeight) / 2) + getTaskbarOffsetY();
Alex Chaua2fc7642022-04-21 14:20:23 +01001277 }
1278
Alex Chau1fe83fe2022-05-09 19:21:13 +01001279 return isTaskbarPresent ? stashedTaskbarSize : mInsets.bottom;
Alex Chaua2fc7642022-04-21 14:20:23 +01001280 }
1281
1282 /** Gets the space that the overview actions will take, including bottom margin. */
1283 public int getOverviewActionsClaimedSpace() {
1284 return overviewActionsTopMarginPx + overviewActionsHeight
1285 + getOverviewActionsClaimedSpaceBelow();
1286 }
1287
1288 /**
Sihua Mae04aa202022-07-18 12:43:56 -07001289 * Takes the View and return the scales of width and height depending on the DeviceProfile
1290 * specifications
1291 *
1292 * @param itemInfo The tag of the widget view
1293 * @return A PointF instance with the x set to be the scale of width, and y being the scale of
1294 * height
1295 */
1296 @NonNull
1297 public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) {
1298 return mViewScaleProvider.getScaleFromItemInfo(itemInfo);
1299 }
1300
1301 /**
Winsonfadbe8f2016-07-22 16:35:37 -07001302 * @return the bounds for which the open folders should be contained within
1303 */
1304 public Rect getAbsoluteOpenFolderBounds() {
1305 if (isVerticalBarLayout()) {
1306 // Folders should only appear right of the drop target bar and left of the hotseat
1307 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
1308 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -07001309 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001310 mInsets.top + availableHeightPx);
1311 } else {
1312 // Folders should only appear below the drop target bar and above the hotseat
Tony Wickhamae72b462021-03-10 16:18:40 -08001313 int hotseatTop = isTaskbarPresent ? taskbarSize : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001314 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -07001315 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -08001316 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -08001317 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -07001318 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -07001319 }
1320 }
1321
Jon Miranda228877d2021-02-09 11:05:00 -05001322 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
1323 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -07001324 }
Pierre Barbier de Reuille578deba2021-09-24 13:47:44 +01001325
Jon Miranda228877d2021-02-09 11:05:00 -05001326 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
1327 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -07001328 }
1329
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001330 /**
Tony Wickham55616cd2015-09-23 14:55:17 -07001331 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
1332 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
1333 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -07001334 */
Tony Wickhamab946a12015-09-16 15:38:16 -07001335 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -07001336 return isLandscape && transposeLayoutWithOrientation;
1337 }
1338
Sunny Goyal59d086c2018-05-07 17:31:40 -07001339 /**
1340 * Updates orientation information and returns true if it has changed from the previous value.
1341 */
Winson Chung13c1c2c2019-09-06 11:46:19 -07001342 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001343 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001344 boolean isSeascape = DisplayController.INSTANCE.get(context)
1345 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -07001346 if (mIsSeascape != isSeascape) {
1347 mIsSeascape = isSeascape;
Pat Manning08610ca2022-04-05 21:03:16 +01001348 // Hotseat changing sides requires updating workspace left/right paddings
1349 updateWorkspacePadding();
Sunny Goyal59d086c2018-05-07 17:31:40 -07001350 return true;
1351 }
1352 }
1353 return false;
1354 }
1355
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001356 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -07001357 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -08001358 }
1359
Sunny Goyal07b69292018-01-08 14:19:34 -08001360 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001361 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -07001362 }
1363
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001364 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -08001365 switch (containerType) {
1366 case CellLayout.WORKSPACE:
1367 return cellHeightPx;
1368 case CellLayout.FOLDER:
1369 return folderCellHeightPx;
1370 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -07001371 // The hotseat is the only container where the cell height is going to be
1372 // different from the content within that cell.
1373 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -08001374 default:
1375 // ??
1376 return 0;
1377 }
1378 }
Sunny Goyal13178ac2016-04-04 16:35:22 -07001379
Jon Miranda58561d42021-03-17 10:51:54 -04001380 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -07001381 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -04001382 }
1383
Alex Chaue818bcb2022-09-02 17:27:11 +01001384 private String dpPointFToString(String name, PointF value) {
1385 return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y);
1386 }
1387
Pat Manning5f74bfd2022-07-20 12:08:54 +01001388 /** Dumps various DeviceProfile variables to the specified writer. */
1389 public void dump(Context context, String prefix, PrintWriter writer) {
Jon Miranda58561d42021-03-17 10:51:54 -04001390 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -07001391 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -04001392
1393 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -04001394 writer.println(prefix + "\tisPhone:" + isPhone);
1395 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
1396 + transposeLayoutWithOrientation);
Alex Chau6ed408f2022-03-04 12:58:05 +00001397 writer.println(prefix + "\tisGestureMode:" + isGestureMode);
Jon Miranda58561d42021-03-17 10:51:54 -04001398
1399 writer.println(prefix + "\tisLandscape:" + isLandscape);
1400 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001401 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -04001402
1403 writer.println(prefix + pxToDpStr("windowX", windowX));
1404 writer.println(prefix + pxToDpStr("windowY", windowY));
1405 writer.println(prefix + pxToDpStr("widthPx", widthPx));
1406 writer.println(prefix + pxToDpStr("heightPx", heightPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001407 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
1408 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
Alex Chaue0227552022-04-06 19:44:43 +01001409 writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
1410 writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
1411 writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
1412 writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001413
1414 writer.println(prefix + "\taspectRatio:" + aspectRatio);
1415
1416 writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
1417
Thales Lima83bedbf2021-10-05 17:47:39 +01001418 writer.println(prefix + "\tinv.numRows: " + inv.numRows);
Alex Chau9fee3fd2021-12-01 18:43:10 +00001419 writer.println(prefix + "\tinv.numColumns: " + inv.numColumns);
1420 writer.println(prefix + "\tinv.numSearchContainerColumns: "
1421 + inv.numSearchContainerColumns);
Jon Miranda58561d42021-03-17 10:51:54 -04001422
Alex Chaue818bcb2022-09-02 17:27:11 +01001423 writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex]));
Jon Mirandaab3c6812021-06-28 15:42:28 -07001424
Jon Miranda58561d42021-03-17 10:51:54 -04001425 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
1426 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
1427
1428 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
1429 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
1430
Thales Lima83bedbf2021-10-05 17:47:39 +01001431 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal",
1432 cellLayoutBorderSpacePx.x));
1433 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical",
1434 cellLayoutBorderSpacePx.y));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001435 writer.println(
1436 prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left));
1437 writer.println(
1438 prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top));
1439 writer.println(
1440 prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right));
Pat Manning08610ca2022-04-05 21:03:16 +01001441 writer.println(
1442 prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom));
Thales Lima83bedbf2021-10-05 17:47:39 +01001443
Jon Miranda58561d42021-03-17 10:51:54 -04001444 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
1445 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
1446 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
1447
1448 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
1449 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
1450 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
1451 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
1452 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
1453 folderChildDrawablePaddingPx));
Thales Lima78d00ad2021-09-30 11:29:06 +01001454 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx Horizontal",
1455 folderCellLayoutBorderSpacePx.x));
1456 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx Vertical",
1457 folderCellLayoutBorderSpacePx.y));
Thales Limaa08a4432022-08-09 09:55:17 +01001458 writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight",
1459 folderContentPaddingLeftRight));
1460 writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop));
Jon Miranda58561d42021-03-17 10:51:54 -04001461
Alex Chaue0227552022-04-06 19:44:43 +01001462 writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001463 writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration);
1464 writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration);
1465 writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale);
1466 writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth);
Alex Chaue0227552022-04-06 19:44:43 +01001467
1468 writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange));
1469 writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding));
Alex Chau3d2c0622022-09-01 21:28:14 +01001470 writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration);
1471 writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration);
Jon Miranda58561d42021-03-17 10:51:54 -04001472 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
1473 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
1474 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
1475 allAppsIconDrawablePaddingPx));
1476 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Alex Chau27b39b92022-01-14 18:02:18 +00001477 writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001478 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x));
1479 writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001480 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Alex Chau62572c02022-07-25 18:36:37 +00001481 writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding));
Alex Chau27b39b92022-01-14 18:02:18 +00001482 writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin));
Jon Miranda58561d42021-03-17 10:51:54 -04001483
1484 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
Thales Lima425f6822022-05-10 13:44:58 -03001485 writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]);
Jon Miranda58561d42021-03-17 10:51:54 -04001486 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
Alex Chau62572c02022-07-25 18:36:37 +00001487 writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx));
Jon Miranda58561d42021-03-17 10:51:54 -04001488 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
1489 hotseatBarSidePaddingStartPx));
1490 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
1491 hotseatBarSidePaddingEndPx));
Pat Manning26f70f72022-07-07 13:50:39 +01001492 writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset));
Thales Limab8c05952022-05-23 16:58:38 +01001493 writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace));
1494 writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight));
Pat Manningde25c0d2022-04-05 19:11:26 +01001495 writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx",
1496 springLoadedHotseatBarTopMarginPx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001497 Rect hotseatLayoutPadding = getHotseatLayoutPadding(context);
1498 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top",
1499 hotseatLayoutPadding.top));
1500 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom",
1501 hotseatLayoutPadding.bottom));
1502 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left",
1503 hotseatLayoutPadding.left));
1504 writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right",
1505 hotseatLayoutPadding.right));
Sunny Goyal19ff7282021-04-22 10:12:54 -07001506 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Thales Lima116b51a2022-02-03 16:19:47 +00001507 writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace));
Thales Limaa1012902022-01-13 17:58:42 +00001508 writer.println(prefix + "\tisQsbInline: " + isQsbInline);
Alex Chau206ede92022-08-01 17:46:12 +01001509 writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth));
Jon Miranda58561d42021-03-17 10:51:54 -04001510
1511 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
Tony Wickham635e1802021-07-22 14:28:04 -10001512 writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps);
Jon Miranda58561d42021-03-17 10:51:54 -04001513 writer.println(prefix + pxToDpStr("taskbarSize", taskbarSize));
Jon Miranda58561d42021-03-17 10:51:54 -04001514
Thales Lima83bedbf2021-10-05 17:47:39 +01001515 writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx",
1516 desiredWorkspaceHorizontalMarginPx));
Jon Miranda58561d42021-03-17 10:51:54 -04001517 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
1518 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
1519 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
Alex Chau62572c02022-07-25 18:36:37 +00001520 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
Jon Miranda58561d42021-03-17 10:51:54 -04001521
Jon Mirandaab3c6812021-06-28 15:42:28 -07001522 writer.println(prefix + pxToDpStr("iconScale", iconScale));
1523 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -04001524 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Alex Chau62572c02022-07-25 18:36:37 +00001525 writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale));
Jon Mirandac9e69fa2021-03-22 17:13:34 -04001526
1527 if (inv.devicePaddings != null) {
1528 int unscaledExtraSpace = (int) (extraSpace / iconScale);
1529 writer.println(prefix + pxToDpStr("maxEmptySpace",
1530 inv.devicePaddings.getDevicePadding(unscaledExtraSpace).getMaxEmptySpacePx()));
1531 }
Jon Miranda58561d42021-03-17 10:51:54 -04001532 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
1533 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
Alex Chau635b3ab2022-01-26 16:49:10 +00001534
1535 writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx));
Alex Chau635b3ab2022-01-26 16:49:10 +00001536 writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx));
1537 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx",
1538 overviewTaskIconDrawableSizePx));
1539 writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx",
1540 overviewTaskIconDrawableSizeGridPx));
1541 writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx",
1542 overviewTaskThumbnailTopMarginPx));
Alex Chaua2fc7642022-04-21 14:20:23 +01001543 writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx",
1544 overviewActionsTopMarginPx));
1545 writer.println(prefix + pxToDpStr("overviewActionsHeight",
1546 overviewActionsHeight));
Alex Chau635b3ab2022-01-26 16:49:10 +00001547 writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing",
1548 overviewActionsButtonSpacing));
1549 writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing));
1550 writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing));
1551 writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin));
Pat Manningde25c0d2022-04-05 19:11:26 +01001552
Alex Chau62572c02022-07-25 18:36:37 +00001553 writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001554 writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx));
Alex Chau62572c02022-07-25 18:36:37 +00001555 writer.println(
1556 prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx));
Pat Manningde25c0d2022-04-05 19:11:26 +01001557
Pat Manning5f74bfd2022-07-20 12:08:54 +01001558 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()",
1559 getCellLayoutSpringLoadShrunkTop()));
1560 writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()",
1561 getCellLayoutSpringLoadShrunkBottom(context)));
Alex Chau906d8822022-05-23 10:42:25 +01001562 writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx",
1563 workspaceSpringLoadedMinNextPageVisiblePx));
Pat Manning5f74bfd2022-07-20 12:08:54 +01001564 writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()",
1565 getWorkspaceSpringLoadScale(context)));
Thales Limab8c05952022-05-23 16:58:38 +01001566 writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight()));
1567 writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth()));
Jon Miranda58561d42021-03-17 10:51:54 -04001568 }
1569
Alex Chaua6907dc2022-03-18 15:24:07 +00001570 private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
Sunny Goyal1890f672020-04-30 12:28:00 -07001571 Configuration config = new Configuration(c.getResources().getConfiguration());
1572 config.orientation = orientation;
Thales Lima425f6822022-05-10 13:44:58 -03001573 config.densityDpi = info.getDensityDpi();
Alex Chaua6907dc2022-03-18 15:24:07 +00001574 config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds);
Sunny Goyal1890f672020-04-30 12:28:00 -07001575 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -07001576 }
Sunny Goyalfde55052018-02-01 14:46:13 -08001577
1578 /**
1579 * Callback when a component changes the DeviceProfile associated with it, as a result of
1580 * configuration change
1581 */
1582 public interface OnDeviceProfileChangeListener {
1583
1584 /**
1585 * Called when the device profile is reassigned. Note that for layout and measurements, it
1586 * is sufficient to listen for inset changes. Use this callback when you need to perform
1587 * a one time operation.
1588 */
1589 void onDeviceProfileChanged(DeviceProfile dp);
1590 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001591
Brian Isganitis099945b2022-01-31 18:15:00 -05001592 /** Allows registering listeners for {@link DeviceProfile} changes. */
1593 public interface DeviceProfileListenable {
1594
1595 /** The current device profile. */
1596 DeviceProfile getDeviceProfile();
1597
1598 /** Registered {@link OnDeviceProfileChangeListener} instances. */
1599 List<OnDeviceProfileChangeListener> getOnDeviceProfileChangeListeners();
1600
1601 /** Notifies listeners of a {@link DeviceProfile} change. */
1602 default void dispatchDeviceProfileChanged() {
1603 DeviceProfile deviceProfile = getDeviceProfile();
1604 List<OnDeviceProfileChangeListener> listeners = getOnDeviceProfileChangeListeners();
1605 for (int i = listeners.size() - 1; i >= 0; i--) {
1606 listeners.get(i).onDeviceProfileChanged(deviceProfile);
1607 }
1608 }
1609
1610 /** Register listener for {@link DeviceProfile} changes. */
1611 default void addOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
1612 getOnDeviceProfileChangeListeners().add(listener);
1613 }
1614
1615 /** Unregister listener for {@link DeviceProfile} changes. */
1616 default void removeOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
1617 getOnDeviceProfileChangeListeners().remove(listener);
1618 }
1619 }
1620
Sihua Mae04aa202022-07-18 12:43:56 -07001621 /**
1622 * Handler that deals with ItemInfo of the views for the DeviceProfile
1623 */
1624 @FunctionalInterface
1625 public interface ViewScaleProvider {
1626 /**
1627 * Get the scales from the view
1628 *
1629 * @param itemInfo The tag of the widget view
1630 * @return PointF instance containing the scale information, or null if using the default
1631 * app widget scale of this device profile.
1632 */
1633 @NonNull
1634 PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo);
1635 }
1636
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001637 public static class Builder {
1638 private Context mContext;
1639 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07001640 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001641
Sunny Goyal19ff7282021-04-22 10:12:54 -07001642 private WindowBounds mWindowBounds;
1643 private boolean mUseTwoPanels;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001644
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001645 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001646 private Boolean mTransposeLayoutWithOrientation;
Alex Chau6ed408f2022-03-04 12:58:05 +00001647 private Boolean mIsGestureMode;
Sihua Mae04aa202022-07-18 12:43:56 -07001648 private ViewScaleProvider mViewScaleProvider = null;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001649
Sunny Goyal65190ae2022-08-02 14:16:26 -07001650 private SparseArray<DotRenderer> mDotRendererCache;
1651
Sunny Goyalfd58da62020-08-11 12:06:49 -07001652 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001653 mContext = context;
1654 mInv = inv;
1655 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001656 }
1657
1658 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1659 mIsMultiWindowMode = isMultiWindowMode;
1660 return this;
1661 }
1662
Sunny Goyal19ff7282021-04-22 10:12:54 -07001663 public Builder setUseTwoPanels(boolean useTwoPanels) {
1664 mUseTwoPanels = useTwoPanels;
1665 return this;
1666 }
1667
Sunny Goyal65190ae2022-08-02 14:16:26 -07001668 public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) {
1669 mDotRendererCache = dotRendererCache;
1670 return this;
1671 }
Sunny Goyal19ff7282021-04-22 10:12:54 -07001672
1673 public Builder setWindowBounds(WindowBounds bounds) {
1674 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07001675 return this;
1676 }
1677
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001678 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1679 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1680 return this;
1681 }
1682
Alex Chau6ed408f2022-03-04 12:58:05 +00001683 public Builder setGestureMode(boolean isGestureMode) {
1684 mIsGestureMode = isGestureMode;
1685 return this;
1686 }
1687
Sihua Mae04aa202022-07-18 12:43:56 -07001688 /**
1689 * Set the viewScaleProvider for the builder
1690 *
1691 * @param viewScaleProvider The viewScaleProvider to be set for the
1692 * DeviceProfile
1693 * @return This builder
1694 */
1695 @NonNull
1696 public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) {
1697 mViewScaleProvider = viewScaleProvider;
1698 return this;
1699 }
1700
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001701 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001702 if (mWindowBounds == null) {
1703 throw new IllegalArgumentException("Window bounds not set");
1704 }
1705 if (mTransposeLayoutWithOrientation == null) {
1706 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
1707 }
Alex Chau6ed408f2022-03-04 12:58:05 +00001708 if (mIsGestureMode == null) {
Alex Chaue818bcb2022-09-02 17:27:11 +01001709 mIsGestureMode = mInfo.navigationMode.hasGestures;
Alex Chau6ed408f2022-03-04 12:58:05 +00001710 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001711 if (mDotRendererCache == null) {
1712 mDotRendererCache = new SparseArray<>();
1713 }
Sihua Mae04aa202022-07-18 12:43:56 -07001714 if (mViewScaleProvider == null) {
1715 mViewScaleProvider = DEFAULT_PROVIDER;
1716 }
Sunny Goyal65190ae2022-08-02 14:16:26 -07001717 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache,
1718 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mUseTwoPanels,
Sihua Mae04aa202022-07-18 12:43:56 -07001719 mIsGestureMode, mViewScaleProvider);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001720 }
1721 }
1722
Winson Chungb3800242013-10-24 11:01:54 -07001723}