blob: 9ca753dd926f1dd86fb887bd3979b04601cd9151 [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
Alex Chaua02eddc2021-04-29 00:36:06 +010019import static android.util.DisplayMetrics.DENSITY_DEVICE_STABLE;
Sunny Goyal35c7b192021-04-20 16:51:10 -070020import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
21
Jon Mirandae126d722021-02-25 10:45:20 -050022import static com.android.launcher3.ResourceUtils.pxFromDp;
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;
Jon Miranda92c1b5d2021-07-20 13:57:16 -070025import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.ICON_OVERLAP_FACTOR;
Alex Chaua02eddc2021-04-29 00:36:06 +010026import static com.android.launcher3.util.WindowManagerCompat.MIN_TABLET_WIDTH;
Jon Miranda228877d2021-02-09 11:05:00 -050027
Sunny Goyal35c7b192021-04-20 16:51:10 -070028import android.annotation.SuppressLint;
Winson Chungb3800242013-10-24 11:01:54 -070029import android.content.Context;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070030import android.content.res.Configuration;
Winson Chungb3800242013-10-24 11:01:54 -070031import android.content.res.Resources;
Sunny Goyal8b9919d2021-04-07 14:45:17 -070032import android.graphics.Path;
Winson Chungb3800242013-10-24 11:01:54 -070033import android.graphics.Point;
Jon Miranda7ae64ff2016-11-21 16:18:46 -080034import android.graphics.PointF;
Winson Chungb3800242013-10-24 11:01:54 -070035import android.graphics.Rect;
Sunny Goyal35c7b192021-04-20 16:51:10 -070036import android.hardware.display.DisplayManager;
37import android.util.DisplayMetrics;
Sunny Goyal59d086c2018-05-07 17:31:40 -070038import android.view.Surface;
Tony Wickham15883892021-02-12 11:24:40 -080039import android.view.WindowInsets;
40import android.view.WindowManager;
Winson Chungb3800242013-10-24 11:01:54 -070041
Sunny Goyalc13403c2016-11-18 23:44:48 -080042import com.android.launcher3.CellLayout.ContainerType;
Jon Miranda228877d2021-02-09 11:05:00 -050043import com.android.launcher3.DevicePaddings.DevicePadding;
Tony Wickham15883892021-02-12 11:24:40 -080044import com.android.launcher3.config.FeatureFlags;
Tony Wickham8912b042018-11-29 15:28:53 -080045import com.android.launcher3.icons.DotRenderer;
Sunny Goyal8b9919d2021-04-07 14:45:17 -070046import com.android.launcher3.icons.GraphicsUtils;
Hyunyoung Song48cb7bc2018-09-25 17:03:34 -070047import com.android.launcher3.icons.IconNormalizer;
Sunny Goyalfd58da62020-08-11 12:06:49 -070048import com.android.launcher3.util.DisplayController;
49import com.android.launcher3.util.DisplayController.Info;
Sunny Goyalb46703d2020-05-27 17:52:03 -070050import com.android.launcher3.util.WindowBounds;
Winson1f064272016-07-18 17:18:02 -070051
Jon Miranda58561d42021-03-17 10:51:54 -040052import java.io.PrintWriter;
53
Sunny Goyal35c7b192021-04-20 16:51:10 -070054@SuppressLint("NewApi")
Winson Chungb3800242013-10-24 11:01:54 -070055public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070056
Sunny Goyal8b9919d2021-04-07 14:45:17 -070057 private static final int DEFAULT_DOT_SIZE = 100;
Sunny Goyal1890f672020-04-30 12:28:00 -070058
Adam Cohen2e6da152015-05-06 11:42:25 -070059 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070060 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070061 private final DisplayMetrics mMetrics;
Winson Chungbe876472014-05-14 14:15:20 -070062
Sunny Goyalc6205602015-05-21 20:46:33 -070063 // Device properties
64 public final boolean isTablet;
Sunny Goyalc6205602015-05-21 20:46:33 -070065 public final boolean isPhone;
66 public final boolean transposeLayoutWithOrientation;
Sunny Goyal19ff7282021-04-22 10:12:54 -070067 public final boolean isTwoPanels;
Alex Chaua02eddc2021-04-29 00:36:06 +010068 public final boolean allowRotation;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -070069
Sunny Goyalc6205602015-05-21 20:46:33 -070070 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -070071 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -080072 public final boolean isMultiWindowMode;
73
Sunny Goyal0addbf02020-04-28 14:17:35 -070074 public final int windowX;
75 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -070076 public final int widthPx;
77 public final int heightPx;
78 public final int availableWidthPx;
79 public final int availableHeightPx;
Jon Mirandabba64512019-03-27 10:54:17 -070080
81 public final float aspectRatio;
82
Jon Mirandae126d722021-02-25 10:45:20 -050083 public final boolean isScalableGrid;
84
Tony Wickhamd6b40372015-09-23 18:37:57 -070085 /**
86 * The maximum amount of left/right workspace padding as a percentage of the screen width.
87 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
88 * 7% of the screen width can be used as right padding.
89 */
90 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -070091
Jon Miranda3f9bab22017-07-28 14:50:17 -070092 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda80cddbc2021-07-22 13:51:16 -070093 private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f;
Jon Miranda30d0aa22017-07-25 15:55:29 -070094
Jon Miranda5eacbb72018-07-31 11:14:46 -070095 // To evenly space the icons, increase the left/right margins for tablets in portrait mode.
96 private static final int PORTRAIT_TABLET_LEFT_RIGHT_PADDING_MULTIPLIER = 4;
97
Sunny Goyalc6205602015-05-21 20:46:33 -070098 // Workspace
Jon Mirandae126d722021-02-25 10:45:20 -050099 public final int desiredWorkspaceLeftRightOriginalPx;
100 public int desiredWorkspaceLeftRightMarginPx;
101 public final int cellLayoutBorderSpacingOriginalPx;
102 public int cellLayoutBorderSpacingPx;
Jon Miranda28032002017-07-13 16:18:56 -0700103 public final int cellLayoutPaddingLeftRightPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700104 public final int cellLayoutBottomPaddingPx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700105 public final int edgeMarginPx;
Sunny Goyal47328fd2016-05-25 18:56:41 -0700106 public float workspaceSpringLoadShrinkFactor;
107 public final int workspaceSpringLoadedBottomSpace;
Sunny Goyalc6205602015-05-21 20:46:33 -0700108
Jon Miranda58561d42021-03-17 10:51:54 -0400109 private final int extraSpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500110 public int workspaceTopPadding;
111 public int workspaceBottomPadding;
Jon Miranda58561d42021-03-17 10:51:54 -0400112 public int extraHotseatBottomPadding;
Jon Miranda228877d2021-02-09 11:05:00 -0500113
Tony Wickham5edf9e22020-03-27 20:06:52 -0700114 // Workspace page indicator
115 public final int workspacePageIndicatorHeight;
116 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700117
Sunny Goyalc6205602015-05-21 20:46:33 -0700118 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400119 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700120 public int iconSizePx;
121 public int iconTextSizePx;
122 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700123 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -0700124
Jon Mirandaab3c6812021-06-28 15:42:28 -0700125 public float cellScaleToFit;
Adam Cohen59400422014-03-05 18:07:04 -0800126 public int cellWidthPx;
127 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700128 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800129
Jon Mirandae126d722021-02-25 10:45:20 -0500130 public int cellYPaddingPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500131
Sunny Goyalc6205602015-05-21 20:46:33 -0700132 // Folder
Jon Mirandae126d722021-02-25 10:45:20 -0500133 public float folderLabelTextScale;
134 public int folderLabelTextSizePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700135 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700136 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700137
Jon Mirandae126d722021-02-25 10:45:20 -0500138 // Folder content
Jon Miranda823da222021-03-23 08:08:45 -0400139 public int folderCellLayoutBorderSpacingPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500140 public int folderContentPaddingLeftRight;
141 public int folderContentPaddingTop;
142
Jon Mirandabf7d8122016-11-03 15:29:29 -0700143 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700144 public int folderCellWidthPx;
145 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700146
147 // Folder child
148 public int folderChildIconSizePx;
149 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700150 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700151
Sunny Goyalc6205602015-05-21 20:46:33 -0700152 // Hotseat
Jon Miranda80cddbc2021-07-22 13:51:16 -0700153 public int hotseatBarSizeExtraSpacePx;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700154 public final int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700155 public int hotseatCellHeightPx;
Jon Miranda0d284852021-06-22 14:50:55 -0700156 private final int hotseatExtraVerticalSize;
Jon Miranda18751b62017-07-31 17:25:27 -0700157 // In portrait: size = height, in landscape: size = width
158 public int hotseatBarSizePx;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700159 public int hotseatBarTopPaddingPx;
Jon Miranda0d284852021-06-22 14:50:55 -0700160 public final int hotseatBarBottomPaddingPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700161 // Start is the side next to the nav bar, end is the side next to the workspace
162 public final int hotseatBarSidePaddingStartPx;
163 public final int hotseatBarSidePaddingEndPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700164
Jon Miranda8bdb2222021-06-23 18:10:10 -0700165 public final float qsbBottomMarginOriginalPx;
166 public int qsbBottomMarginPx;
167
Sunny Goyalc6205602015-05-21 20:46:33 -0700168 // All apps
Samuel Fufaee9aff92021-04-05 13:30:40 -0500169 public int allAppsOpenVerticalTranslate;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700170 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700171 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700172 public int allAppsIconSizePx;
173 public int allAppsIconDrawablePaddingPx;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700174 public final int numShownAllAppsColumns;
Winson1f064272016-07-18 17:18:02 -0700175 public float allAppsIconTextSizePx;
176
Zak Cohen334efeb2021-03-19 16:42:07 -0700177 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700178 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000179 public int overviewTaskIconSizePx;
180 public int overviewTaskThumbnailTopMarginPx;
zakcohendad8a802021-05-20 09:52:26 -0700181 public final int overviewActionsMarginThreeButtonPx;
182 public final int overviewActionsMarginGesturePx;
Zak Cohen334efeb2021-03-19 16:42:07 -0700183
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800184 // Widgets
185 public final PointF appWidgetScale = new PointF(1.0f, 1.0f);
186
Sunny Goyal47328fd2016-05-25 18:56:41 -0700187 // Drop Target
188 public int dropTargetBarSizePx;
Alex Chaua02eddc2021-04-29 00:36:06 +0100189 public int dropTargetDragPaddingPx;
190 public int dropTargetTextSizePx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700191
Winson1f064272016-07-18 17:18:02 -0700192 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800193 private final Rect mInsets = new Rect();
194 public final Rect workspacePadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700195 private final Rect mHotseatPadding = new Rect();
Jon Miranda0bd63d12019-03-06 17:29:29 -0800196 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700197 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700198
Tony Wickhamf34bee82018-12-03 18:11:39 -0800199 // Notification dots
Samuel Fufac96fa242019-09-26 23:06:32 -0700200 public DotRenderer mDotRendererWorkSpace;
201 public DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800202
Tony Wickham15883892021-02-12 11:24:40 -0800203 // Taskbar
204 public boolean isTaskbarPresent;
205 public int taskbarSize;
Tony Wickham145b7fd2021-03-11 10:03:12 -0800206 // How much of the bottom inset is due to Taskbar rather than other system elements.
207 public int nonOverlappingTaskbarInset;
Tony Wickham15883892021-02-12 11:24:40 -0800208
Alex Chaua02eddc2021-04-29 00:36:06 +0100209 // DragController
210 public int flingToDeleteThresholdVelocity;
211
Sunny Goyal19ff7282021-04-22 10:12:54 -0700212 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds,
Sunny Goyal0addbf02020-04-28 14:17:35 -0700213 boolean isMultiWindowMode, boolean transposeLayoutWithOrientation,
Sunny Goyal19ff7282021-04-22 10:12:54 -0700214 boolean useTwoPanels) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700215
Adam Cohen2e6da152015-05-06 11:42:25 -0700216 this.inv = inv;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700217 this.isLandscape = windowBounds.isLandscape();
Sunny Goyald70e75a2018-02-22 10:07:32 -0800218 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500219 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700220 windowX = windowBounds.bounds.left;
221 windowY = windowBounds.bounds.top;
Winson Chungb3800242013-10-24 11:01:54 -0700222
Jon Mirandae126d722021-02-25 10:45:20 -0500223 isScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
224
Jon Miranda7e183c32018-06-20 11:05:27 -0700225 // Determine sizes.
Sunny Goyal19ff7282021-04-22 10:12:54 -0700226 widthPx = windowBounds.bounds.width();
227 heightPx = windowBounds.bounds.height();
228 availableWidthPx = windowBounds.availableSize.x;
229 int nonFinalAvailableHeightPx = windowBounds.availableSize.y;
Jon Miranda7e183c32018-06-20 11:05:27 -0700230
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700231 mInfo = info;
Alex Chaua02eddc2021-04-29 00:36:06 +0100232 // If the device's pixel density was scaled (usually via settings for A11y), use the
233 // original dimensions to determine if rotation is allowed of not.
234 float originalSmallestWidth = dpiFromPx(Math.min(widthPx, heightPx), DENSITY_DEVICE_STABLE);
235 allowRotation = originalSmallestWidth >= MIN_TABLET_WIDTH;
236 // Tablet UI does not support emulated landscape.
237 isTablet = allowRotation && info.isTablet(windowBounds);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700238 isPhone = !isTablet;
239 isTwoPanels = isTablet && useTwoPanels;
Adam Cohen2e6da152015-05-06 11:42:25 -0700240
Jon Mirandabba64512019-03-27 10:54:17 -0700241 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Jon Miranda7e183c32018-06-20 11:05:27 -0700242 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
Sunny Goyalc6205602015-05-21 20:46:33 -0700243
244 // Some more constants
Sunny Goyal1890f672020-04-30 12:28:00 -0700245 context = getContext(context, info, isVerticalBarLayout()
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700246 ? Configuration.ORIENTATION_LANDSCAPE
247 : Configuration.ORIENTATION_PORTRAIT);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700248 mMetrics = context.getResources().getDisplayMetrics();
Sunny Goyal1890f672020-04-30 12:28:00 -0700249 final Resources res = context.getResources();
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700250
Tony Wickham15883892021-02-12 11:24:40 -0800251 isTaskbarPresent = isTablet && FeatureFlags.ENABLE_TASKBAR.get();
252 if (isTaskbarPresent) {
253 // Taskbar will be added later, but provides bottom insets that we should subtract
254 // from availableHeightPx.
255 taskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_size);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700256 WindowInsets windowInsets =
257 context.createWindowContext(
258 context.getSystemService(DisplayManager.class).getDisplay(mInfo.id),
259 TYPE_APPLICATION, null)
260 .getSystemService(WindowManager.class)
Tony Wickham15883892021-02-12 11:24:40 -0800261 .getCurrentWindowMetrics().getWindowInsets();
Sunny Goyal35c7b192021-04-20 16:51:10 -0700262 nonOverlappingTaskbarInset = taskbarSize - windowInsets.getSystemWindowInsetBottom();
Tony Wickham15883892021-02-12 11:24:40 -0800263 if (nonOverlappingTaskbarInset > 0) {
264 nonFinalAvailableHeightPx -= nonOverlappingTaskbarInset;
265 }
266 }
267 availableHeightPx = nonFinalAvailableHeightPx;
268
Winson Chungb3800242013-10-24 11:01:54 -0700269 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700270
Jon Mirandae126d722021-02-25 10:45:20 -0500271 desiredWorkspaceLeftRightMarginPx = isVerticalBarLayout() ? 0 : isScalableGrid
272 ? res.getDimensionPixelSize(R.dimen.scalable_grid_left_right_margin)
273 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
274 desiredWorkspaceLeftRightOriginalPx = desiredWorkspaceLeftRightMarginPx;
275
Samuel Fufaee9aff92021-04-05 13:30:40 -0500276
277 allAppsOpenVerticalTranslate = res.getDimensionPixelSize(
278 R.dimen.all_apps_open_vertical_translate);
279
Jon Mirandae126d722021-02-25 10:45:20 -0500280 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
281 folderContentPaddingLeftRight =
282 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
283 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_content_padding_top);
284
Sunny Goyal35c7b192021-04-20 16:51:10 -0700285 setCellLayoutBorderSpacing(pxFromDp(inv.borderSpacing, mMetrics, 1f));
Jon Mirandae126d722021-02-25 10:45:20 -0500286 cellLayoutBorderSpacingOriginalPx = cellLayoutBorderSpacingPx;
Jon Miranda823da222021-03-23 08:08:45 -0400287 folderCellLayoutBorderSpacingPx = cellLayoutBorderSpacingPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500288
Jon Miranda5eacbb72018-07-31 11:14:46 -0700289 int cellLayoutPaddingLeftRightMultiplier = !isVerticalBarLayout() && isTablet
290 ? PORTRAIT_TABLET_LEFT_RIGHT_PADDING_MULTIPLIER : 1;
Jon Mirandae126d722021-02-25 10:45:20 -0500291 int cellLayoutPadding = isScalableGrid
292 ? 0
293 : res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_padding);
Andras Kloczl8e57cce2021-02-11 23:51:19 +0100294
Sunny Goyal19ff7282021-04-22 10:12:54 -0700295 if (isTwoPanels) {
Andras Kloczl8e57cce2021-02-11 23:51:19 +0100296 cellLayoutPaddingLeftRightPx =
297 res.getDimensionPixelSize(R.dimen.two_panel_home_side_padding);
298 cellLayoutBottomPaddingPx = 0;
299 } else if (isLandscape) {
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700300 cellLayoutPaddingLeftRightPx = 0;
301 cellLayoutBottomPaddingPx = cellLayoutPadding;
302 } else {
303 cellLayoutPaddingLeftRightPx = cellLayoutPaddingLeftRightMultiplier * cellLayoutPadding;
304 cellLayoutBottomPaddingPx = 0;
305 }
306
Tony Wickham5edf9e22020-03-27 20:06:52 -0700307 workspacePageIndicatorHeight = res.getDimensionPixelSize(
308 R.dimen.workspace_page_indicator_height);
309 mWorkspacePageIndicatorOverlapWorkspace =
310 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700311
Winson Chungb3800242013-10-24 11:01:54 -0700312 iconDrawablePaddingOriginalPx =
313 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Alex Chaua02eddc2021-04-29 00:36:06 +0100314
Sunny Goyal47328fd2016-05-25 18:56:41 -0700315 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
Alex Chaua02eddc2021-04-29 00:36:06 +0100316 dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding);
317 dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size);
318
Sunny Goyal47328fd2016-05-25 18:56:41 -0700319 workspaceSpringLoadedBottomSpace =
320 res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space);
Sunny Goyald5190522017-04-24 03:06:54 -0700321
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700322 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700323
Sunny Goyal19ff7282021-04-22 10:12:54 -0700324 numShownHotseatIcons =
325 isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons;
326 numShownAllAppsColumns =
327 isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns;
Jon Miranda80cddbc2021-07-22 13:51:16 -0700328 hotseatBarSizeExtraSpacePx = 0;
Winson1f064272016-07-18 17:18:02 -0700329 hotseatBarTopPaddingPx =
330 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding);
Jon Miranda7e183c32018-06-20 11:05:27 -0700331 hotseatBarBottomPaddingPx = (isTallDevice ? 0
332 : res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_non_tall_padding))
333 + res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_padding);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700334 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800335 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700336 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700337 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Jon Miranda0d284852021-06-22 14:50:55 -0700338 hotseatExtraVerticalSize =
Jon Miranda228877d2021-02-09 11:05:00 -0500339 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_extra_vertical_size);
Jon Miranda0d284852021-06-22 14:50:55 -0700340 updateHotseatIconSize(pxFromDp(inv.iconSize, mMetrics, 1f));
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700341
Jon Miranda8bdb2222021-06-23 18:10:10 -0700342 qsbBottomMarginOriginalPx = isScalableGrid
343 ? res.getDimensionPixelSize(R.dimen.scalable_grid_qsb_bottom_margin)
344 : 0;
345
Zak Cohen334efeb2021-03-19 16:42:07 -0700346 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chaudedbc8a2021-03-17 16:53:26 +0000347 overviewTaskIconSizePx =
348 isTablet && FeatureFlags.ENABLE_OVERVIEW_GRID.get() ? res.getDimensionPixelSize(
349 R.dimen.task_thumbnail_icon_size_grid) : res.getDimensionPixelSize(
350 R.dimen.task_thumbnail_icon_size);
351 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx * 2;
zakcohendad8a802021-05-20 09:52:26 -0700352 overviewActionsMarginGesturePx = res.getDimensionPixelSize(
353 R.dimen.overview_actions_bottom_margin_gesture);
354 overviewActionsMarginThreeButtonPx = res.getDimensionPixelSize(
355 R.dimen.overview_actions_bottom_margin_three_button);
Zak Cohen334efeb2021-03-19 16:42:07 -0700356
Jon Miranda2ed276e2017-06-29 11:36:34 -0700357 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400358 extraSpace = updateAvailableDimensions(res);
Jon Miranda80cddbc2021-07-22 13:51:16 -0700359
Jon Miranda2ed276e2017-06-29 11:36:34 -0700360 // Now that we have all of the variables calculated, we can tune certain sizes.
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400361 if (isScalableGrid && inv.devicePaddings != null) {
362 // Paddings were created assuming no scaling, so we first unscale the extra space.
Jon Mirandaab3c6812021-06-28 15:42:28 -0700363 int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400364 DevicePadding padding = inv.devicePaddings.getDevicePadding(unscaledExtraSpace);
Jon Miranda228877d2021-02-09 11:05:00 -0500365
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400366 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
367 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
368 int paddingHotseatBottom = padding.getHotseatBottomPadding(unscaledExtraSpace);
369
Jon Mirandaab3c6812021-06-28 15:42:28 -0700370 workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit);
371 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit);
372 extraHotseatBottomPadding = Math.round(paddingHotseatBottom * cellScaleToFit);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400373
Jon Miranda58561d42021-03-17 10:51:54 -0400374 hotseatBarSizePx += extraHotseatBottomPadding;
Jon Miranda8bdb2222021-06-23 18:10:10 -0700375
Jon Mirandaab3c6812021-06-28 15:42:28 -0700376 qsbBottomMarginPx = Math.round(qsbBottomMarginOriginalPx * cellScaleToFit);
Jon Miranda228877d2021-02-09 11:05:00 -0500377 } else if (!isVerticalBarLayout() && isPhone && isTallDevice) {
Jon Miranda3f9bab22017-07-28 14:50:17 -0700378 // We increase the hotseat size when there is extra space.
Jon Miranda80cddbc2021-07-22 13:51:16 -0700379
380 if (Float.compare(aspectRatio, TALLER_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0) {
381 // For taller devices, we will take a third of the extra space from each row,
382 // and add it to the space above and below the hotseat.
383 int extraSpace = ((getCellSize().y - iconSizePx - iconDrawablePaddingPx * 2)
384 * inv.numRows) / 3;
385
386 int halfExtraSpace = extraSpace / 2;
387 hotseatBarTopPaddingPx += halfExtraSpace;
388 hotseatBarSizeExtraSpacePx = halfExtraSpace;
389 } else {
390 // ie. For a display with a large aspect ratio, we can keep the icons on the
391 // workspace in portrait mode closer together by adding more height to the hotseat.
392 // Note: This calculation was created after noticing a pattern in the design spec.
393 hotseatBarSizeExtraSpacePx = getCellSize().y - iconSizePx
394 - iconDrawablePaddingPx * 2 - workspacePageIndicatorHeight;
395 }
396
397 updateHotseatIconSize(iconSizePx);
Jon Miranda30d0aa22017-07-25 15:55:29 -0700398
Jon Miranda3f9bab22017-07-28 14:50:17 -0700399 // Recalculate the available dimensions using the new hotseat size.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700400 updateAvailableDimensions(res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700401 }
Sunny Goyal07b69292018-01-08 14:19:34 -0800402 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800403
Alex Chaua02eddc2021-04-29 00:36:06 +0100404 flingToDeleteThresholdVelocity = res.getDimensionPixelSize(
405 R.dimen.drag_flingToDeleteMinVelocity);
406
Tony Wickham1237df02017-02-24 08:59:36 -0800407 // This is done last, after iconSizePx is calculated above.
Sunny Goyal8b9919d2021-04-07 14:45:17 -0700408 Path dotPath = GraphicsUtils.getShapePath(DEFAULT_DOT_SIZE);
409 mDotRendererWorkSpace = new DotRenderer(iconSizePx, dotPath, DEFAULT_DOT_SIZE);
Samuel Fufac96fa242019-09-26 23:06:32 -0700410 mDotRendererAllApps = iconSizePx == allAppsIconSizePx ? mDotRendererWorkSpace :
Sunny Goyal8b9919d2021-04-07 14:45:17 -0700411 new DotRenderer(allAppsIconSizePx, dotPath, DEFAULT_DOT_SIZE);
Adam Cohen63f1ec02014-08-12 09:23:13 -0700412 }
413
Jon Miranda0d284852021-06-22 14:50:55 -0700414 private void updateHotseatIconSize(int hotseatIconSizePx) {
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700415 // Ensure there is enough space for folder icons, which have a slightly larger radius.
416 hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda0d284852021-06-22 14:50:55 -0700417 if (isVerticalBarLayout()) {
418 hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx
419 + hotseatBarSidePaddingEndPx;
420 } else {
421 hotseatBarSizePx = hotseatIconSizePx + hotseatBarTopPaddingPx
Jon Miranda80cddbc2021-07-22 13:51:16 -0700422 + hotseatBarBottomPaddingPx + (isScalableGrid ? 0 : hotseatExtraVerticalSize)
423 + hotseatBarSizeExtraSpacePx;
Jon Miranda0d284852021-06-22 14:50:55 -0700424 }
425 }
426
Jon Mirandae126d722021-02-25 10:45:20 -0500427 private void setCellLayoutBorderSpacing(int borderSpacing) {
Jon Miranda823da222021-03-23 08:08:45 -0400428 cellLayoutBorderSpacingPx = isScalableGrid ? borderSpacing : 0;
Jon Mirandae126d722021-02-25 10:45:20 -0500429 }
430
Jon Miranda611dba42021-03-02 14:12:13 -0500431 /**
432 * We inset the widget padding added by the system and instead rely on the border spacing
433 * between cells to create reliable consistency between widgets
434 */
435 public boolean shouldInsetWidgets() {
436 Rect widgetPadding = inv.defaultWidgetPadding;
437
Jon Miranda49811182021-06-03 09:52:40 -0700438 // Check all sides to ensure that the widget won't overlap into another cell, or into
439 // status bar.
440 return workspaceTopPadding > widgetPadding.top
441 && cellLayoutBorderSpacingPx > widgetPadding.left
Jon Miranda611dba42021-03-02 14:12:13 -0500442 && cellLayoutBorderSpacingPx > widgetPadding.top
443 && cellLayoutBorderSpacingPx > widgetPadding.right
444 && cellLayoutBorderSpacingPx > widgetPadding.bottom;
445 }
Jon Mirandae126d722021-02-25 10:45:20 -0500446
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700447 public Builder toBuilder(Context context) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700448 WindowBounds bounds =
449 new WindowBounds(widthPx, heightPx, availableWidthPx, availableHeightPx);
450 bounds.bounds.offsetTo(windowX, windowY);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700451 return new Builder(context, inv, mInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700452 .setWindowBounds(bounds)
453 .setUseTwoPanels(isTwoPanels)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700454 .setMultiWindowMode(isMultiWindowMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800455 }
456
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700457 public DeviceProfile copy(Context context) {
458 return toBuilder(context).build();
459 }
460
461 /**
462 * TODO: Move this to the builder as part of setMultiWindowMode
463 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700464 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700465 DeviceProfile profile = toBuilder(context)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700466 .setWindowBounds(windowBounds)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700467 .setMultiWindowMode(true)
468 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800469
Jon Miranda941375e2021-03-31 13:10:45 -0400470 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda93e1f042016-11-11 14:13:04 -0800471
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800472 // We use these scales to measure and layout the widgets using their full invariant profile
473 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
474 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
475 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
476 profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY);
Sunny Goyal07b69292018-01-08 14:19:34 -0800477 profile.updateWorkspacePadding();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800478
Jon Miranda93e1f042016-11-11 14:13:04 -0800479 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700480 }
481
Adam Cohen63f1ec02014-08-12 09:23:13 -0700482 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400483 * Checks if there is enough space for labels on the workspace.
484 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700485 * It is important to call this method after the All Apps variables have been set.
486 */
Jon Miranda941375e2021-03-31 13:10:45 -0400487 private void hideWorkspaceLabelsIfNotEnoughSpace() {
488 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
489 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
490 - iconTextHeight;
491
492 // We want enough space so that the text is closer to its corresponding icon.
493 if (workspaceCellPaddingY < iconTextHeight) {
494 iconTextSizePx = 0;
495 iconDrawablePaddingPx = 0;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700496 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR);
Jon Miranda941375e2021-03-31 13:10:45 -0400497 autoResizeAllAppsCells();
498 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700499 }
Jon Miranda1091e532017-07-21 13:31:50 -0700500
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700501 /**
502 * Re-computes the all-apps cell size to be independent of workspace
503 */
504 public void autoResizeAllAppsCells() {
Jon Miranda941375e2021-03-31 13:10:45 -0400505 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
506 int topBottomPadding = textHeight;
Jon Miranda1091e532017-07-21 13:31:50 -0700507 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
Jon Miranda941375e2021-03-31 13:10:45 -0400508 + textHeight + (topBottomPadding * 2);
Jon Miranda1091e532017-07-21 13:31:50 -0700509 }
510
Jon Miranda228877d2021-02-09 11:05:00 -0500511 /**
512 * Returns the amount of extra (or unused) vertical space.
513 */
514 private int updateAvailableDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700515 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800516
Jon Mirandae126d722021-02-25 10:45:20 -0500517 Point workspacePadding = getTotalWorkspacePadding();
518
519 // Check to see if the icons fit within the available height.
520 float usedHeight = getCellLayoutHeight();
521 final int maxHeight = availableHeightPx - workspacePadding.y;
Jon Miranda228877d2021-02-09 11:05:00 -0500522 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500523 float scaleY = maxHeight / usedHeight;
524 boolean shouldScale = scaleY < 1f;
525
526 float scaleX = 1f;
527 if (isScalableGrid) {
528 // We scale to fit the cellWidth and cellHeight in the available space.
529 // The benefit of scalable grids is that we can get consistent aspect ratios between
530 // devices.
531 float usedWidth = (cellWidthPx * inv.numColumns)
532 + (cellLayoutBorderSpacingPx * (inv.numColumns - 1))
533 + (desiredWorkspaceLeftRightMarginPx * 2);
534 // We do not subtract padding here, as we also scale the workspace padding if needed.
535 scaleX = availableWidthPx / usedWidth;
536 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700537 }
Jon Mirandae126d722021-02-25 10:45:20 -0500538
539 if (shouldScale) {
540 float scale = Math.min(scaleX, scaleY);
541 updateIconSize(scale, res);
542 extraHeight = Math.max(0, maxHeight - getCellLayoutHeight());
543 }
544
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700545 updateAvailableFolderCellDimensions(res);
Jon Miranda228877d2021-02-09 11:05:00 -0500546 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700547 }
548
Jon Mirandae126d722021-02-25 10:45:20 -0500549 private int getCellLayoutHeight() {
550 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacingPx * (inv.numRows - 1));
551 }
552
Jon Miranda6f7e9702019-09-16 14:44:14 -0700553 /**
554 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
555 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
556 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
557 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800558 public void updateIconSize(float scale, Resources res) {
Jon Mirandaab3c6812021-06-28 15:42:28 -0700559 // Icon scale should never exceed 1, otherwise pixellation may occur.
560 iconScale = Math.min(1f, scale);
561 cellScaleToFit = scale;
562
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400563
Jon Miranda18751b62017-07-31 17:25:27 -0700564 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800565 final boolean isVerticalLayout = isVerticalBarLayout();
Andras Kloczl6057cb92021-04-07 13:45:17 +0200566 float invIconSizeDp = isLandscape ? inv.landscapeIconSize : inv.iconSize;
Jon Mirandaab3c6812021-06-28 15:42:28 -0700567 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, iconScale));
Andras Kloczl6057cb92021-04-07 13:45:17 +0200568 float invIconTextSizeSp = isLandscape ? inv.landscapeIconTextSize : inv.iconTextSize;
Jon Mirandaab3c6812021-06-28 15:42:28 -0700569 iconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * iconScale);
570 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700571
Jon Mirandae126d722021-02-25 10:45:20 -0500572 setCellLayoutBorderSpacing((int) (cellLayoutBorderSpacingOriginalPx * scale));
573
574 if (isScalableGrid) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700575 cellWidthPx = pxFromDp(inv.minCellWidth, mMetrics, scale);
576 cellHeightPx = pxFromDp(inv.minCellHeight, mMetrics, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500577 int cellContentHeight = iconSizePx + iconDrawablePaddingPx
578 + Utilities.calculateTextHeight(iconTextSizePx);
579 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
580 desiredWorkspaceLeftRightMarginPx = (int) (desiredWorkspaceLeftRightOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -0500581 } else {
Jon Mirandae126d722021-02-25 10:45:20 -0500582 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700583 cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR)
584 + iconDrawablePaddingPx
Jon Miranda228877d2021-02-09 11:05:00 -0500585 + Utilities.calculateTextHeight(iconTextSizePx);
586 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
587 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
588 && !isMultiWindowMode) {
589 // Ensures that the label is closer to its corresponding icon. This is not an issue
590 // with vertical bar layout or multi-window mode since the issue is handled
591 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
592 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
593 iconDrawablePaddingPx = cellPaddingY;
594 }
Jon Miranda846455e2017-10-02 14:58:52 -0700595 }
Jon Miranda18751b62017-07-31 17:25:27 -0700596
Sunny Goyalae190ff2020-04-14 00:19:01 +0000597 // All apps
Sunny Goyal19ff7282021-04-22 10:12:54 -0700598 if (numShownAllAppsColumns != inv.numColumns) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700599 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize, mMetrics);
Jon Mirandaaf3aed02021-05-06 18:28:45 -0700600 allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize, mMetrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000601 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Jon Miranda941375e2021-03-31 13:10:45 -0400602 autoResizeAllAppsCells();
Sunny Goyalae190ff2020-04-14 00:19:01 +0000603 } else {
604 allAppsIconSizePx = iconSizePx;
605 allAppsIconTextSizePx = iconTextSizePx;
606 allAppsIconDrawablePaddingPx = iconDrawablePaddingPx;
607 allAppsCellHeightPx = getCellSize().y;
608 }
609 allAppsCellWidthPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700610
Jon Miranda941375e2021-03-31 13:10:45 -0400611 if (isVerticalLayout) {
612 hideWorkspaceLabelsIfNotEnoughSpace();
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700613 }
Winson Chungb3800242013-10-24 11:01:54 -0700614
Winson Chungb3800242013-10-24 11:01:54 -0700615 // Hotseat
Jon Miranda0d284852021-06-22 14:50:55 -0700616 updateHotseatIconSize(iconSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700617
Sunny Goyal07b69292018-01-08 14:19:34 -0800618 if (!isVerticalLayout) {
Jon Miranda18751b62017-07-31 17:25:27 -0700619 int expectedWorkspaceHeight = availableHeightPx - hotseatBarSizePx
Tony Wickham5edf9e22020-03-27 20:06:52 -0700620 - workspacePageIndicatorHeight - edgeMarginPx;
Sunny Goyal47328fd2016-05-25 18:56:41 -0700621 float minRequiredHeight = dropTargetBarSizePx + workspaceSpringLoadedBottomSpace;
622 workspaceSpringLoadShrinkFactor = Math.min(
623 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f,
624 1 - (minRequiredHeight / expectedWorkspaceHeight));
625 } else {
626 workspaceSpringLoadShrinkFactor =
627 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
628 }
629
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700630 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -0700631 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
632 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Winson Chung0f785722015-04-08 10:27:49 -0700633 }
634
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700635 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700636 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700637
Jon Mirandae126d722021-02-25 10:45:20 -0500638 final int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_height);
639
Jon Mirandac1b23992016-12-13 08:57:36 -0800640 // Don't let the folder get too close to the edges of the screen.
Jon Miranda1786df32018-09-25 13:05:23 -0700641 int folderMargin = edgeMarginPx * 2;
Sunny Goyal07b69292018-01-08 14:19:34 -0800642 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -0800643
644 // Check if the icons fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -0500645 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Jon Miranda823da222021-03-23 08:08:45 -0400646 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacingPx);
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800647 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderBottomPanelSize
Jon Mirandae126d722021-02-25 10:45:20 -0500648 - folderMargin - folderContentPaddingTop;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800649 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -0800650
651 // Check if the icons fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -0500652 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Jon Miranda823da222021-03-23 08:08:45 -0400653 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacingPx);
Jon Mirandae126d722021-02-25 10:45:20 -0500654 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin
655 - folderContentPaddingLeftRight * 2;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800656 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -0800657
658 float scale = Math.min(scaleX, scaleY);
659 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700660 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700661 }
662 }
663
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700664 private void updateFolderCellSize(float scale, Resources res) {
Jon Mirandae126d722021-02-25 10:45:20 -0500665 float invIconSizeDp = isVerticalBarLayout() ? inv.landscapeIconSize : inv.iconSize;
Sunny Goyal35c7b192021-04-20 16:51:10 -0700666 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Jon Mirandaaf3aed02021-05-06 18:28:45 -0700667 folderChildTextSizePx = pxFromSp(inv.iconTextSize, mMetrics, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500668 folderLabelTextSizePx = (int) (folderChildTextSizePx * folderLabelTextScale);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700669
670 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700671
Jon Miranda823da222021-03-23 08:08:45 -0400672 if (isScalableGrid) {
Jon Mirandaf33f5b32021-07-22 17:15:31 -0700673 int minWidth = folderChildIconSizePx + iconDrawablePaddingPx * 2;
674 int minHeight = folderChildIconSizePx + iconDrawablePaddingPx * 2 + textHeight;
675
676 folderCellWidthPx = (int) Math.max(minWidth, cellWidthPx * scale);
677 folderCellHeightPx = (int) Math.max(minHeight, cellHeightPx * scale);
Jon Miranda823da222021-03-23 08:08:45 -0400678
679 int borderSpacing = (int) (cellLayoutBorderSpacingOriginalPx * scale);
680 folderCellLayoutBorderSpacingPx = borderSpacing;
681 folderContentPaddingLeftRight = borderSpacing;
682 folderContentPaddingTop = borderSpacing;
683 } else {
684 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
685 * scale);
686 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
687 * scale);
688
689 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
690 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
691 }
692
Jonathan Miranda9ad87462017-07-26 17:41:02 +0000693 folderChildDrawablePaddingPx = Math.max(0,
694 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700695 }
696
Winson1f064272016-07-18 17:18:02 -0700697 public void updateInsets(Rect insets) {
698 mInsets.set(insets);
Sunny Goyal07b69292018-01-08 14:19:34 -0800699 updateWorkspacePadding();
Winson1f064272016-07-18 17:18:02 -0700700 }
701
Sunny Goyalae6e3182019-04-30 12:04:37 -0700702 /**
703 * The current device insets. This is generally same as the insets being dispatched to
704 * {@link Insettable} elements, but can differ if the element is using a different profile.
705 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800706 public Rect getInsets() {
707 return mInsets;
708 }
709
Sunny Goyal756cd262015-08-20 12:33:21 -0700710 public Point getCellSize() {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700711 return getCellSize(null);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700712 }
713
Sunny Goyal19ff7282021-04-22 10:12:54 -0700714 public Point getCellSize(Point result) {
715 if (result == null) {
716 result = new Point();
717 }
Sunny Goyal756cd262015-08-20 12:33:21 -0700718 // Since we are only concerned with the overall padding, layout direction does
719 // not matter.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700720 Point padding = getTotalWorkspacePadding();
Jon Miranda18751b62017-07-31 17:25:27 -0700721 result.x = calculateCellWidth(availableWidthPx - padding.x
Sunny Goyal19ff7282021-04-22 10:12:54 -0700722 - cellLayoutPaddingLeftRightPx * 2, cellLayoutBorderSpacingPx, inv.numColumns);
Jon Miranda18751b62017-07-31 17:25:27 -0700723 result.y = calculateCellHeight(availableHeightPx - padding.y
Sunny Goyal19ff7282021-04-22 10:12:54 -0700724 - cellLayoutBottomPaddingPx, cellLayoutBorderSpacingPx, inv.numRows);
Sunny Goyal756cd262015-08-20 12:33:21 -0700725 return result;
726 }
727
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700728 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -0800729 updateWorkspacePadding();
730 return new Point(workspacePadding.left + workspacePadding.right,
731 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700732 }
733
734 /**
Sunny Goyal07b69292018-01-08 14:19:34 -0800735 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
736 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700737 */
Sunny Goyal07b69292018-01-08 14:19:34 -0800738 private void updateWorkspacePadding() {
739 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -0700740 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -0800741 padding.top = 0;
742 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800743 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700744 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -0700745 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -0700746 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -0700747 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700748 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -0700749 }
Winson Chungb3800242013-10-24 11:01:54 -0700750 } else {
Tony Wickhama29a0462021-03-02 12:28:25 -0800751 int hotseatTop = isTaskbarPresent ? taskbarSize : hotseatBarSizePx;
752 int paddingBottom = hotseatTop + workspacePageIndicatorHeight
Jon Miranda228877d2021-02-09 11:05:00 -0500753 + workspaceBottomPadding - mWorkspacePageIndicatorOverlapWorkspace;
Sunny Goyalc6205602015-05-21 20:46:33 -0700754 if (isTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700755 // Pad the left and right of the workspace to ensure consistent spacing
756 // between all icons
Tony Wickhamd6b40372015-09-23 18:37:57 -0700757 // The amount of screen space available for left/right padding.
Sunny Goyal228153d2018-01-04 15:35:22 -0800758 int availablePaddingX = Math.max(0, widthPx - ((inv.numColumns * cellWidthPx) +
Sunny Goyalf5440cb2016-12-14 15:13:00 -0800759 ((inv.numColumns - 1) * cellWidthPx)));
Tony Wickhamd6b40372015-09-23 18:37:57 -0700760 availablePaddingX = (int) Math.min(availablePaddingX,
Sunny Goyal07b69292018-01-08 14:19:34 -0800761 widthPx * MAX_HORIZONTAL_PADDING_PERCENT);
Tony Wickhama29a0462021-03-02 12:28:25 -0800762 int hotseatVerticalPadding = isTaskbarPresent ? 0
763 : hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700764 int availablePaddingY = Math.max(0, heightPx - edgeMarginPx - paddingBottom
Tony Wickhama29a0462021-03-02 12:28:25 -0800765 - (2 * inv.numRows * cellHeightPx) - hotseatVerticalPadding);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700766 padding.set(availablePaddingX / 2, edgeMarginPx + availablePaddingY / 2,
Tony Wickhamd6b40372015-09-23 18:37:57 -0700767 availablePaddingX / 2, paddingBottom + availablePaddingY / 2);
Andras Kloczl8e57cce2021-02-11 23:51:19 +0100768
Sunny Goyal19ff7282021-04-22 10:12:54 -0700769 if (isTwoPanels) {
Andras Kloczl8e57cce2021-02-11 23:51:19 +0100770 padding.set(0, padding.top, 0, padding.bottom);
771 }
Winson Chungb3800242013-10-24 11:01:54 -0700772 } else {
773 // Pad the top and bottom of the workspace with search/hotseat bar sizes
Winson1f064272016-07-18 17:18:02 -0700774 padding.set(desiredWorkspaceLeftRightMarginPx,
Jon Mirandae126d722021-02-25 10:45:20 -0500775 workspaceTopPadding + (isScalableGrid ? 0 : edgeMarginPx),
Winson1f064272016-07-18 17:18:02 -0700776 desiredWorkspaceLeftRightMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700777 paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -0700778 }
779 }
Winson Chungb3800242013-10-24 11:01:54 -0700780 }
781
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700782 public Rect getHotseatLayoutPadding() {
783 if (isVerticalBarLayout()) {
784 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700785 mHotseatPadding.set(mInsets.left + hotseatBarSidePaddingStartPx,
786 mInsets.top, hotseatBarSidePaddingEndPx, mInsets.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700787 } else {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700788 mHotseatPadding.set(hotseatBarSidePaddingEndPx, mInsets.top,
789 mInsets.right + hotseatBarSidePaddingStartPx, mInsets.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700790 }
791 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700792 // We want the edges of the hotseat to line up with the edges of the workspace, but the
793 // icons in the hotseat are a different size, and so don't line up perfectly. To account
794 // for this, we pad the left and right of the hotseat with half of the difference of a
795 // workspace cell vs a hotseat cell.
796 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700797 float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700798 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
799 mHotseatPadding.set(
Sunny Goyal786940a2020-06-02 02:31:31 -0700800 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingLeftRightPx
801 + mInsets.left,
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700802 hotseatBarTopPaddingPx,
Sunny Goyal786940a2020-06-02 02:31:31 -0700803 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx
804 + mInsets.right,
Jon Miranda0d284852021-06-22 14:50:55 -0700805 hotseatBarSizePx - hotseatCellHeightPx - hotseatBarTopPaddingPx
806 + cellLayoutBottomPaddingPx + mInsets.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700807 }
808 return mHotseatPadding;
809 }
810
Winsonfadbe8f2016-07-22 16:35:37 -0700811 /**
812 * @return the bounds for which the open folders should be contained within
813 */
814 public Rect getAbsoluteOpenFolderBounds() {
815 if (isVerticalBarLayout()) {
816 // Folders should only appear right of the drop target bar and left of the hotseat
817 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
818 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -0700819 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700820 mInsets.top + availableHeightPx);
821 } else {
822 // Folders should only appear below the drop target bar and above the hotseat
Tony Wickhamae72b462021-03-10 16:18:40 -0800823 int hotseatTop = isTaskbarPresent ? taskbarSize : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -0800824 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700825 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -0800826 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -0800827 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -0700828 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -0700829 }
830 }
831
Jon Miranda228877d2021-02-09 11:05:00 -0500832 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
833 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -0700834 }
Jon Miranda228877d2021-02-09 11:05:00 -0500835 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
836 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -0700837 }
838
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700839 /**
Tony Wickham55616cd2015-09-23 14:55:17 -0700840 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
841 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
842 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700843 */
Tony Wickhamab946a12015-09-16 15:38:16 -0700844 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -0700845 return isLandscape && transposeLayoutWithOrientation;
846 }
847
Sunny Goyal59d086c2018-05-07 17:31:40 -0700848 /**
849 * Updates orientation information and returns true if it has changed from the previous value.
850 */
Winson Chung13c1c2c2019-09-06 11:46:19 -0700851 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -0700852 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700853 boolean isSeascape = DisplayController.INSTANCE.get(context)
854 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -0700855 if (mIsSeascape != isSeascape) {
856 mIsSeascape = isSeascape;
857 return true;
858 }
859 }
860 return false;
861 }
862
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800863 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -0700864 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800865 }
866
Sunny Goyal07b69292018-01-08 14:19:34 -0800867 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700868 return isVerticalBarLayout();
Winson Chungb3800242013-10-24 11:01:54 -0700869 }
870
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700871 public int getCellContentHeight(@ContainerType int containerType) {
Sunny Goyalc13403c2016-11-18 23:44:48 -0800872 switch (containerType) {
873 case CellLayout.WORKSPACE:
874 return cellHeightPx;
875 case CellLayout.FOLDER:
876 return folderCellHeightPx;
877 case CellLayout.HOTSEAT:
Jon Miranda92c1b5d2021-07-20 13:57:16 -0700878 // The hotseat is the only container where the cell height is going to be
879 // different from the content within that cell.
880 return iconSizePx;
Sunny Goyalc13403c2016-11-18 23:44:48 -0800881 default:
882 // ??
883 return 0;
884 }
885 }
Sunny Goyal13178ac2016-04-04 16:35:22 -0700886
Jon Miranda58561d42021-03-17 10:51:54 -0400887 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700888 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -0400889 }
890
891 public void dump(String prefix, PrintWriter writer) {
892 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -0700893 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -0400894
Alex Chaua02eddc2021-04-29 00:36:06 +0100895 writer.println(prefix + "\tallowRotation:" + allowRotation);
Jon Miranda58561d42021-03-17 10:51:54 -0400896 writer.println(prefix + "\tisTablet:" + isTablet);
Jon Miranda58561d42021-03-17 10:51:54 -0400897 writer.println(prefix + "\tisPhone:" + isPhone);
898 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
899 + transposeLayoutWithOrientation);
900
901 writer.println(prefix + "\tisLandscape:" + isLandscape);
902 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700903 writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
Jon Miranda58561d42021-03-17 10:51:54 -0400904
905 writer.println(prefix + pxToDpStr("windowX", windowX));
906 writer.println(prefix + pxToDpStr("windowY", windowY));
907 writer.println(prefix + pxToDpStr("widthPx", widthPx));
908 writer.println(prefix + pxToDpStr("heightPx", heightPx));
909
910 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
911 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
912
913 writer.println(prefix + "\taspectRatio:" + aspectRatio);
914
915 writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
916
917 writer.println(prefix + "\tinv.minCellWidth:" + inv.minCellWidth + "dp");
918 writer.println(prefix + "\tinv.minCellHeight:" + inv.minCellHeight + "dp");
919
Jon Mirandaab3c6812021-06-28 15:42:28 -0700920 writer.println(prefix + "\tinv.numColumns:" + inv.numColumns);
921 writer.println(prefix + "\tinv.numRows:" + inv.numRows);
922
Jon Miranda58561d42021-03-17 10:51:54 -0400923 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
924 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
925
926 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
927 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
928
929 writer.println(prefix + "\tinv.iconSize:" + inv.iconSize + "dp");
930 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
931 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
932 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
933
934 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
935 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
936 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
937 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
938 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
939 folderChildDrawablePaddingPx));
Jon Miranda823da222021-03-23 08:08:45 -0400940 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacingPx",
941 folderCellLayoutBorderSpacingPx));
Jon Miranda58561d42021-03-17 10:51:54 -0400942
943 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacingPx",
944 cellLayoutBorderSpacingPx));
945 writer.println(prefix + pxToDpStr("desiredWorkspaceLeftRightMarginPx",
946 desiredWorkspaceLeftRightMarginPx));
947
948 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
949 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
950 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
951 allAppsIconDrawablePaddingPx));
952 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
Sunny Goyal19ff7282021-04-22 10:12:54 -0700953 writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns);
Jon Miranda58561d42021-03-17 10:51:54 -0400954
955 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
956 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
957 writer.println(prefix + pxToDpStr("hotseatBarTopPaddingPx", hotseatBarTopPaddingPx));
958 writer.println(prefix + pxToDpStr("hotseatBarBottomPaddingPx", hotseatBarBottomPaddingPx));
959 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
960 hotseatBarSidePaddingStartPx));
961 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
962 hotseatBarSidePaddingEndPx));
Sunny Goyal19ff7282021-04-22 10:12:54 -0700963 writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons);
Jon Miranda58561d42021-03-17 10:51:54 -0400964
965 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
966
967 writer.println(prefix + pxToDpStr("taskbarSize", taskbarSize));
968 writer.println(prefix + pxToDpStr("nonOverlappingTaskbarInset",
969 nonOverlappingTaskbarInset));
970
971 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
972 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
973 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
974 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
975
Jon Mirandaab3c6812021-06-28 15:42:28 -0700976 writer.println(prefix + pxToDpStr("iconScale", iconScale));
977 writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit));
Jon Miranda58561d42021-03-17 10:51:54 -0400978 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400979
980 if (inv.devicePaddings != null) {
981 int unscaledExtraSpace = (int) (extraSpace / iconScale);
982 writer.println(prefix + pxToDpStr("maxEmptySpace",
983 inv.devicePaddings.getDevicePadding(unscaledExtraSpace).getMaxEmptySpacePx()));
984 }
Jon Miranda58561d42021-03-17 10:51:54 -0400985 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
986 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
987 writer.println(prefix + pxToDpStr("extraHotseatBottomPadding", extraHotseatBottomPadding));
988 }
989
Sunny Goyalfd58da62020-08-11 12:06:49 -0700990 private static Context getContext(Context c, Info info, int orientation) {
Sunny Goyal1890f672020-04-30 12:28:00 -0700991 Configuration config = new Configuration(c.getResources().getConfiguration());
992 config.orientation = orientation;
Sunny Goyal35c7b192021-04-20 16:51:10 -0700993 config.densityDpi = info.densityDpi;
Sunny Goyal1890f672020-04-30 12:28:00 -0700994 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700995 }
Sunny Goyalfde55052018-02-01 14:46:13 -0800996
997 /**
998 * Callback when a component changes the DeviceProfile associated with it, as a result of
999 * configuration change
1000 */
1001 public interface OnDeviceProfileChangeListener {
1002
1003 /**
1004 * Called when the device profile is reassigned. Note that for layout and measurements, it
1005 * is sufficient to listen for inset changes. Use this callback when you need to perform
1006 * a one time operation.
1007 */
1008 void onDeviceProfileChanged(DeviceProfile dp);
1009 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001010
1011 public static class Builder {
1012 private Context mContext;
1013 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -07001014 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001015
Sunny Goyal19ff7282021-04-22 10:12:54 -07001016 private WindowBounds mWindowBounds;
1017 private boolean mUseTwoPanels;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001018
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001019 private boolean mIsMultiWindowMode = false;
Sunny Goyal19ff7282021-04-22 10:12:54 -07001020 private Boolean mTransposeLayoutWithOrientation;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001021
Sunny Goyalfd58da62020-08-11 12:06:49 -07001022 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001023 mContext = context;
1024 mInv = inv;
1025 mInfo = info;
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001026 }
1027
1028 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1029 mIsMultiWindowMode = isMultiWindowMode;
1030 return this;
1031 }
1032
Sunny Goyal19ff7282021-04-22 10:12:54 -07001033 public Builder setUseTwoPanels(boolean useTwoPanels) {
1034 mUseTwoPanels = useTwoPanels;
1035 return this;
1036 }
1037
1038
1039 public Builder setWindowBounds(WindowBounds bounds) {
1040 mWindowBounds = bounds;
Sunny Goyal0addbf02020-04-28 14:17:35 -07001041 return this;
1042 }
1043
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001044 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1045 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1046 return this;
1047 }
1048
1049 public DeviceProfile build() {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001050 if (mWindowBounds == null) {
1051 throw new IllegalArgumentException("Window bounds not set");
1052 }
1053 if (mTransposeLayoutWithOrientation == null) {
1054 mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds);
1055 }
1056 return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds,
1057 mIsMultiWindowMode, mTransposeLayoutWithOrientation, mUseTwoPanels);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001058 }
1059 }
1060
Winson Chungb3800242013-10-24 11:01:54 -07001061}