blob: fd9793625efaac5cd9cbcfe0ad5a6ff4b44175b1 [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
Sunny Goyal35c7b192021-04-20 16:51:10 -070019import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
20
Jon Mirandae126d722021-02-25 10:45:20 -050021import static com.android.launcher3.ResourceUtils.pxFromDp;
Jon Miranda58561d42021-03-17 10:51:54 -040022import static com.android.launcher3.Utilities.dpiFromPx;
Jon Miranda228877d2021-02-09 11:05:00 -050023
Sunny Goyal35c7b192021-04-20 16:51:10 -070024import android.annotation.SuppressLint;
Winson Chungb3800242013-10-24 11:01:54 -070025import android.content.Context;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070026import android.content.res.Configuration;
Winson Chungb3800242013-10-24 11:01:54 -070027import android.content.res.Resources;
Sunny Goyal8b9919d2021-04-07 14:45:17 -070028import android.graphics.Path;
Winson Chungb3800242013-10-24 11:01:54 -070029import android.graphics.Point;
Jon Miranda7ae64ff2016-11-21 16:18:46 -080030import android.graphics.PointF;
Winson Chungb3800242013-10-24 11:01:54 -070031import android.graphics.Rect;
Sunny Goyal35c7b192021-04-20 16:51:10 -070032import android.hardware.display.DisplayManager;
33import android.util.DisplayMetrics;
Winson Chung8e64bba2021-04-20 13:26:26 -070034import android.util.Log;
Sunny Goyal59d086c2018-05-07 17:31:40 -070035import android.view.Surface;
Tony Wickham15883892021-02-12 11:24:40 -080036import android.view.WindowInsets;
37import android.view.WindowManager;
Winson Chungb3800242013-10-24 11:01:54 -070038
Sunny Goyalc13403c2016-11-18 23:44:48 -080039import com.android.launcher3.CellLayout.ContainerType;
Jon Miranda228877d2021-02-09 11:05:00 -050040import com.android.launcher3.DevicePaddings.DevicePadding;
Tony Wickham15883892021-02-12 11:24:40 -080041import com.android.launcher3.config.FeatureFlags;
Tony Wickham8912b042018-11-29 15:28:53 -080042import com.android.launcher3.icons.DotRenderer;
Sunny Goyal8b9919d2021-04-07 14:45:17 -070043import com.android.launcher3.icons.GraphicsUtils;
Hyunyoung Song48cb7bc2018-09-25 17:03:34 -070044import com.android.launcher3.icons.IconNormalizer;
Winson Chung8e64bba2021-04-20 13:26:26 -070045import com.android.launcher3.testing.TestProtocol;
Sunny Goyalfd58da62020-08-11 12:06:49 -070046import com.android.launcher3.util.DisplayController;
47import com.android.launcher3.util.DisplayController.Info;
Sunny Goyalb46703d2020-05-27 17:52:03 -070048import com.android.launcher3.util.WindowBounds;
Winson1f064272016-07-18 17:18:02 -070049
Jon Miranda58561d42021-03-17 10:51:54 -040050import java.io.PrintWriter;
51
Sunny Goyal35c7b192021-04-20 16:51:10 -070052@SuppressLint("NewApi")
Winson Chungb3800242013-10-24 11:01:54 -070053public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070054
Sunny Goyal1890f672020-04-30 12:28:00 -070055 private static final float TABLET_MIN_DPS = 600;
56 private static final float LARGE_TABLET_MIN_DPS = 720;
57
Sunny Goyal8b9919d2021-04-07 14:45:17 -070058 private static final int DEFAULT_DOT_SIZE = 100;
Sunny Goyal1890f672020-04-30 12:28:00 -070059
Adam Cohen2e6da152015-05-06 11:42:25 -070060 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070061 private final Info mInfo;
Sunny Goyal35c7b192021-04-20 16:51:10 -070062 private final DisplayMetrics mMetrics;
Winson Chungbe876472014-05-14 14:15:20 -070063
Sunny Goyalc6205602015-05-21 20:46:33 -070064 // Device properties
65 public final boolean isTablet;
66 public final boolean isLargeTablet;
67 public final boolean isPhone;
68 public final boolean transposeLayoutWithOrientation;
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 Miranda30d0aa22017-07-25 15:55:29 -070093
Jon Miranda5eacbb72018-07-31 11:14:46 -070094 // To evenly space the icons, increase the left/right margins for tablets in portrait mode.
95 private static final int PORTRAIT_TABLET_LEFT_RIGHT_PADDING_MULTIPLIER = 4;
96
Sunny Goyalc6205602015-05-21 20:46:33 -070097 // Workspace
Jon Mirandae126d722021-02-25 10:45:20 -050098 public final int desiredWorkspaceLeftRightOriginalPx;
99 public int desiredWorkspaceLeftRightMarginPx;
100 public final int cellLayoutBorderSpacingOriginalPx;
101 public int cellLayoutBorderSpacingPx;
Jon Miranda28032002017-07-13 16:18:56 -0700102 public final int cellLayoutPaddingLeftRightPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700103 public final int cellLayoutBottomPaddingPx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700104 public final int edgeMarginPx;
Sunny Goyal47328fd2016-05-25 18:56:41 -0700105 public float workspaceSpringLoadShrinkFactor;
106 public final int workspaceSpringLoadedBottomSpace;
Sunny Goyalc6205602015-05-21 20:46:33 -0700107
Jon Miranda58561d42021-03-17 10:51:54 -0400108 private final int extraSpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500109 public int workspaceTopPadding;
110 public int workspaceBottomPadding;
Jon Miranda58561d42021-03-17 10:51:54 -0400111 public int extraHotseatBottomPadding;
Jon Miranda228877d2021-02-09 11:05:00 -0500112
Tony Wickham5edf9e22020-03-27 20:06:52 -0700113 // Workspace page indicator
114 public final int workspacePageIndicatorHeight;
115 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700116
Sunny Goyalc6205602015-05-21 20:46:33 -0700117 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400118 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700119 public int iconSizePx;
120 public int iconTextSizePx;
121 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700122 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -0700123
Adam Cohen59400422014-03-05 18:07:04 -0800124 public int cellWidthPx;
125 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700126 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800127
Jon Mirandae126d722021-02-25 10:45:20 -0500128 public int cellYPaddingPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500129
Sunny Goyalc6205602015-05-21 20:46:33 -0700130 // Folder
Jon Mirandae126d722021-02-25 10:45:20 -0500131 public float folderLabelTextScale;
132 public int folderLabelTextSizePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700133 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700134 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700135
Jon Mirandae126d722021-02-25 10:45:20 -0500136 // Folder content
Jon Miranda823da222021-03-23 08:08:45 -0400137 public int folderCellLayoutBorderSpacingPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500138 public int folderContentPaddingLeftRight;
139 public int folderContentPaddingTop;
140
Jon Mirandabf7d8122016-11-03 15:29:29 -0700141 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700142 public int folderCellWidthPx;
143 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700144
145 // Folder child
146 public int folderChildIconSizePx;
147 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700148 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700149
Sunny Goyalc6205602015-05-21 20:46:33 -0700150 // Hotseat
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700151 public final int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700152 public int hotseatCellHeightPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700153 // In portrait: size = height, in landscape: size = width
154 public int hotseatBarSizePx;
Sunny Goyal07b69292018-01-08 14:19:34 -0800155 public final int hotseatBarTopPaddingPx;
Jon Miranda7e183c32018-06-20 11:05:27 -0700156 public int hotseatBarBottomPaddingPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700157 // Start is the side next to the nav bar, end is the side next to the workspace
158 public final int hotseatBarSidePaddingStartPx;
159 public final int hotseatBarSidePaddingEndPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700160
Sunny Goyalc6205602015-05-21 20:46:33 -0700161 // All apps
Samuel Fufaee9aff92021-04-05 13:30:40 -0500162 public int allAppsOpenVerticalTranslate;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700163 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700164 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700165 public int allAppsIconSizePx;
166 public int allAppsIconDrawablePaddingPx;
167 public float allAppsIconTextSizePx;
168
Zak Cohen334efeb2021-03-19 16:42:07 -0700169 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700170 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000171 public int overviewTaskIconSizePx;
172 public int overviewTaskThumbnailTopMarginPx;
Zak Cohen334efeb2021-03-19 16:42:07 -0700173
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800174 // Widgets
175 public final PointF appWidgetScale = new PointF(1.0f, 1.0f);
176
Sunny Goyal47328fd2016-05-25 18:56:41 -0700177 // Drop Target
178 public int dropTargetBarSizePx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700179
Winson1f064272016-07-18 17:18:02 -0700180 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800181 private final Rect mInsets = new Rect();
182 public final Rect workspacePadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700183 private final Rect mHotseatPadding = new Rect();
Jon Miranda0bd63d12019-03-06 17:29:29 -0800184 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700185 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700186
Tony Wickhamf34bee82018-12-03 18:11:39 -0800187 // Notification dots
Samuel Fufac96fa242019-09-26 23:06:32 -0700188 public DotRenderer mDotRendererWorkSpace;
189 public DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800190
Tony Wickham15883892021-02-12 11:24:40 -0800191 // Taskbar
192 public boolean isTaskbarPresent;
193 public int taskbarSize;
Tony Wickham145b7fd2021-03-11 10:03:12 -0800194 // How much of the bottom inset is due to Taskbar rather than other system elements.
195 public int nonOverlappingTaskbarInset;
Tony Wickham15883892021-02-12 11:24:40 -0800196
Sunny Goyalfd58da62020-08-11 12:06:49 -0700197 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info,
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700198 Point minSize, Point maxSize, int width, int height, boolean isLandscape,
Sunny Goyal0addbf02020-04-28 14:17:35 -0700199 boolean isMultiWindowMode, boolean transposeLayoutWithOrientation,
200 Point windowPosition) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700201
Adam Cohen2e6da152015-05-06 11:42:25 -0700202 this.inv = inv;
Sunny Goyalc6205602015-05-21 20:46:33 -0700203 this.isLandscape = isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -0800204 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500205 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Sunny Goyal0addbf02020-04-28 14:17:35 -0700206 windowX = windowPosition.x;
207 windowY = windowPosition.y;
Winson Chungb3800242013-10-24 11:01:54 -0700208
Jon Mirandae126d722021-02-25 10:45:20 -0500209 isScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
210
Jon Miranda7e183c32018-06-20 11:05:27 -0700211 // Determine sizes.
212 widthPx = width;
213 heightPx = height;
Tony Wickham15883892021-02-12 11:24:40 -0800214 int nonFinalAvailableHeightPx;
Jon Miranda7e183c32018-06-20 11:05:27 -0700215 if (isLandscape) {
216 availableWidthPx = maxSize.x;
Tony Wickham15883892021-02-12 11:24:40 -0800217 nonFinalAvailableHeightPx = minSize.y;
Jon Miranda7e183c32018-06-20 11:05:27 -0700218 } else {
219 availableWidthPx = minSize.x;
Tony Wickham15883892021-02-12 11:24:40 -0800220 nonFinalAvailableHeightPx = maxSize.y;
Jon Miranda7e183c32018-06-20 11:05:27 -0700221 }
222
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700223 mInfo = info;
Adam Cohen2e6da152015-05-06 11:42:25 -0700224
Sunny Goyalc6205602015-05-21 20:46:33 -0700225 // Constants from resources
Sunny Goyal35c7b192021-04-20 16:51:10 -0700226 float swDPs = dpiFromPx(Math.min(info.smallestSize.x, info.smallestSize.y),
227 info.densityDpi);
Alex Chau4e2c25a2021-02-03 16:20:04 +0000228 boolean allowRotation = context.getResources().getBoolean(R.bool.allow_rotation);
229 // Tablet UI is built with assumption that simulated landscape is disabled.
230 isTablet = allowRotation && swDPs >= TABLET_MIN_DPS;
231 isLargeTablet = isTablet && swDPs >= LARGE_TABLET_MIN_DPS;
Sunny Goyalc6205602015-05-21 20:46:33 -0700232 isPhone = !isTablet && !isLargeTablet;
Jon Mirandabba64512019-03-27 10:54:17 -0700233 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Jon Miranda7e183c32018-06-20 11:05:27 -0700234 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
Sunny Goyalc6205602015-05-21 20:46:33 -0700235
236 // Some more constants
Sunny Goyal1890f672020-04-30 12:28:00 -0700237 context = getContext(context, info, isVerticalBarLayout()
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700238 ? Configuration.ORIENTATION_LANDSCAPE
239 : Configuration.ORIENTATION_PORTRAIT);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700240 mMetrics = context.getResources().getDisplayMetrics();
Sunny Goyal1890f672020-04-30 12:28:00 -0700241 final Resources res = context.getResources();
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700242
Tony Wickham15883892021-02-12 11:24:40 -0800243 isTaskbarPresent = isTablet && FeatureFlags.ENABLE_TASKBAR.get();
244 if (isTaskbarPresent) {
245 // Taskbar will be added later, but provides bottom insets that we should subtract
246 // from availableHeightPx.
247 taskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_size);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700248 WindowInsets windowInsets =
249 context.createWindowContext(
250 context.getSystemService(DisplayManager.class).getDisplay(mInfo.id),
251 TYPE_APPLICATION, null)
252 .getSystemService(WindowManager.class)
Tony Wickham15883892021-02-12 11:24:40 -0800253 .getCurrentWindowMetrics().getWindowInsets();
Sunny Goyal35c7b192021-04-20 16:51:10 -0700254 nonOverlappingTaskbarInset = taskbarSize - windowInsets.getSystemWindowInsetBottom();
Tony Wickham15883892021-02-12 11:24:40 -0800255 if (nonOverlappingTaskbarInset > 0) {
256 nonFinalAvailableHeightPx -= nonOverlappingTaskbarInset;
257 }
258 }
259 availableHeightPx = nonFinalAvailableHeightPx;
260
Winson Chungb3800242013-10-24 11:01:54 -0700261 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700262
Jon Mirandae126d722021-02-25 10:45:20 -0500263 desiredWorkspaceLeftRightMarginPx = isVerticalBarLayout() ? 0 : isScalableGrid
264 ? res.getDimensionPixelSize(R.dimen.scalable_grid_left_right_margin)
265 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
266 desiredWorkspaceLeftRightOriginalPx = desiredWorkspaceLeftRightMarginPx;
267
Samuel Fufaee9aff92021-04-05 13:30:40 -0500268
269 allAppsOpenVerticalTranslate = res.getDimensionPixelSize(
270 R.dimen.all_apps_open_vertical_translate);
271
Jon Mirandae126d722021-02-25 10:45:20 -0500272 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
273 folderContentPaddingLeftRight =
274 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
275 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_content_padding_top);
276
Sunny Goyal35c7b192021-04-20 16:51:10 -0700277 setCellLayoutBorderSpacing(pxFromDp(inv.borderSpacing, mMetrics, 1f));
Jon Mirandae126d722021-02-25 10:45:20 -0500278 cellLayoutBorderSpacingOriginalPx = cellLayoutBorderSpacingPx;
Jon Miranda823da222021-03-23 08:08:45 -0400279 folderCellLayoutBorderSpacingPx = cellLayoutBorderSpacingPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500280
Jon Miranda5eacbb72018-07-31 11:14:46 -0700281 int cellLayoutPaddingLeftRightMultiplier = !isVerticalBarLayout() && isTablet
282 ? PORTRAIT_TABLET_LEFT_RIGHT_PADDING_MULTIPLIER : 1;
Jon Mirandae126d722021-02-25 10:45:20 -0500283 int cellLayoutPadding = isScalableGrid
284 ? 0
285 : res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_padding);
Andras Kloczl8e57cce2021-02-11 23:51:19 +0100286
287 if (FeatureFlags.ENABLE_TWO_PANEL_HOME.get() && isTablet) {
288 cellLayoutPaddingLeftRightPx =
289 res.getDimensionPixelSize(R.dimen.two_panel_home_side_padding);
290 cellLayoutBottomPaddingPx = 0;
291 } else if (isLandscape) {
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700292 cellLayoutPaddingLeftRightPx = 0;
293 cellLayoutBottomPaddingPx = cellLayoutPadding;
294 } else {
295 cellLayoutPaddingLeftRightPx = cellLayoutPaddingLeftRightMultiplier * cellLayoutPadding;
296 cellLayoutBottomPaddingPx = 0;
297 }
298
Tony Wickham5edf9e22020-03-27 20:06:52 -0700299 workspacePageIndicatorHeight = res.getDimensionPixelSize(
300 R.dimen.workspace_page_indicator_height);
301 mWorkspacePageIndicatorOverlapWorkspace =
302 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700303
Winson Chungb3800242013-10-24 11:01:54 -0700304 iconDrawablePaddingOriginalPx =
305 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700306 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
307 workspaceSpringLoadedBottomSpace =
308 res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space);
Sunny Goyald5190522017-04-24 03:06:54 -0700309
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700310 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700311
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700312 numShownHotseatIcons = inv.numShownHotseatIcons;
Winson1f064272016-07-18 17:18:02 -0700313 hotseatBarTopPaddingPx =
314 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding);
Jon Miranda7e183c32018-06-20 11:05:27 -0700315 hotseatBarBottomPaddingPx = (isTallDevice ? 0
316 : res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_non_tall_padding))
317 + res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_padding);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700318 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800319 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700320 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700321 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Jon Miranda228877d2021-02-09 11:05:00 -0500322 int hotseatExtraVerticalSize =
323 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_extra_vertical_size);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700324 hotseatBarSizePx = pxFromDp(inv.iconSize, mMetrics, 1f)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700325 + (isVerticalBarLayout()
Sunny Goyal415f1732018-11-29 10:33:47 -0800326 ? (hotseatBarSidePaddingStartPx + hotseatBarSidePaddingEndPx)
Jon Miranda228877d2021-02-09 11:05:00 -0500327 : (hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx
Jon Mirandae126d722021-02-25 10:45:20 -0500328 + (isScalableGrid ? 0 : hotseatExtraVerticalSize)));
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700329
Zak Cohen334efeb2021-03-19 16:42:07 -0700330 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chaudedbc8a2021-03-17 16:53:26 +0000331 overviewTaskIconSizePx =
332 isTablet && FeatureFlags.ENABLE_OVERVIEW_GRID.get() ? res.getDimensionPixelSize(
333 R.dimen.task_thumbnail_icon_size_grid) : res.getDimensionPixelSize(
334 R.dimen.task_thumbnail_icon_size);
335 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx * 2;
Zak Cohen334efeb2021-03-19 16:42:07 -0700336
Jon Miranda2ed276e2017-06-29 11:36:34 -0700337 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400338 extraSpace = updateAvailableDimensions(res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700339 // Now that we have all of the variables calculated, we can tune certain sizes.
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400340 if (isScalableGrid && inv.devicePaddings != null) {
341 // Paddings were created assuming no scaling, so we first unscale the extra space.
342 int unscaledExtraSpace = (int) (extraSpace / iconScale);
343 DevicePadding padding = inv.devicePaddings.getDevicePadding(unscaledExtraSpace);
Jon Miranda228877d2021-02-09 11:05:00 -0500344
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400345 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
346 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
347 int paddingHotseatBottom = padding.getHotseatBottomPadding(unscaledExtraSpace);
348
349 workspaceTopPadding = Math.round(paddingWorkspaceTop * iconScale);
350 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * iconScale);
351 extraHotseatBottomPadding = Math.round(paddingHotseatBottom * iconScale);
352
Jon Miranda58561d42021-03-17 10:51:54 -0400353 hotseatBarSizePx += extraHotseatBottomPadding;
354 hotseatBarBottomPaddingPx += extraHotseatBottomPadding;
Jon Miranda228877d2021-02-09 11:05:00 -0500355 } else if (!isVerticalBarLayout() && isPhone && isTallDevice) {
Jon Miranda3f9bab22017-07-28 14:50:17 -0700356 // We increase the hotseat size when there is extra space.
Jon Miranda2ed276e2017-06-29 11:36:34 -0700357 // ie. For a display with a large aspect ratio, we can keep the icons on the workspace
Jon Miranda3f9bab22017-07-28 14:50:17 -0700358 // in portrait mode closer together by adding more height to the hotseat.
Jon Miranda30d0aa22017-07-25 15:55:29 -0700359 // Note: This calculation was created after noticing a pattern in the design spec.
Jon Miranda58561d42021-03-17 10:51:54 -0400360 int extraSpace = getCellSize().y - iconSizePx - iconDrawablePaddingPx * 2
Tony Wickham5edf9e22020-03-27 20:06:52 -0700361 - workspacePageIndicatorHeight;
Jon Miranda7e183c32018-06-20 11:05:27 -0700362 hotseatBarSizePx += extraSpace;
363 hotseatBarBottomPaddingPx += extraSpace;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700364
Jon Miranda3f9bab22017-07-28 14:50:17 -0700365 // Recalculate the available dimensions using the new hotseat size.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700366 updateAvailableDimensions(res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700367 }
Sunny Goyal07b69292018-01-08 14:19:34 -0800368 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800369
370 // This is done last, after iconSizePx is calculated above.
Sunny Goyal8b9919d2021-04-07 14:45:17 -0700371 Path dotPath = GraphicsUtils.getShapePath(DEFAULT_DOT_SIZE);
372 mDotRendererWorkSpace = new DotRenderer(iconSizePx, dotPath, DEFAULT_DOT_SIZE);
Samuel Fufac96fa242019-09-26 23:06:32 -0700373 mDotRendererAllApps = iconSizePx == allAppsIconSizePx ? mDotRendererWorkSpace :
Sunny Goyal8b9919d2021-04-07 14:45:17 -0700374 new DotRenderer(allAppsIconSizePx, dotPath, DEFAULT_DOT_SIZE);
Adam Cohen63f1ec02014-08-12 09:23:13 -0700375 }
376
Jon Mirandae126d722021-02-25 10:45:20 -0500377 private void setCellLayoutBorderSpacing(int borderSpacing) {
Jon Miranda823da222021-03-23 08:08:45 -0400378 cellLayoutBorderSpacingPx = isScalableGrid ? borderSpacing : 0;
Jon Mirandae126d722021-02-25 10:45:20 -0500379 }
380
Jon Miranda611dba42021-03-02 14:12:13 -0500381 /**
382 * We inset the widget padding added by the system and instead rely on the border spacing
383 * between cells to create reliable consistency between widgets
384 */
385 public boolean shouldInsetWidgets() {
386 Rect widgetPadding = inv.defaultWidgetPadding;
387
388 // Check all sides to ensure that the widget won't overlap into another cell.
389 return cellLayoutBorderSpacingPx > widgetPadding.left
390 && cellLayoutBorderSpacingPx > widgetPadding.top
391 && cellLayoutBorderSpacingPx > widgetPadding.right
392 && cellLayoutBorderSpacingPx > widgetPadding.bottom;
393 }
Jon Mirandae126d722021-02-25 10:45:20 -0500394
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700395 public Builder toBuilder(Context context) {
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800396 Point size = new Point(availableWidthPx, availableHeightPx);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700397 return new Builder(context, inv, mInfo)
398 .setSizeRange(size, size)
399 .setSize(widthPx, heightPx)
Sunny Goyal0addbf02020-04-28 14:17:35 -0700400 .setWindowPosition(windowX, windowY)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700401 .setMultiWindowMode(isMultiWindowMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800402 }
403
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700404 public DeviceProfile copy(Context context) {
405 return toBuilder(context).build();
406 }
407
408 /**
409 * TODO: Move this to the builder as part of setMultiWindowMode
410 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700411 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Jon Mirandaa11380d2017-08-24 11:30:03 -0700412 // We take the minimum sizes of this profile and it's multi-window variant to ensure that
413 // the system decor is always excluded.
Sunny Goyalb46703d2020-05-27 17:52:03 -0700414 Point mwSize = new Point(Math.min(availableWidthPx, windowBounds.availableSize.x),
415 Math.min(availableHeightPx, windowBounds.availableSize.y));
Jon Mirandaa11380d2017-08-24 11:30:03 -0700416
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700417 DeviceProfile profile = toBuilder(context)
418 .setSizeRange(mwSize, mwSize)
Sunny Goyalb46703d2020-05-27 17:52:03 -0700419 .setSize(windowBounds.bounds.width(), windowBounds.bounds.height())
420 .setWindowPosition(windowBounds.bounds.left, windowBounds.bounds.top)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700421 .setMultiWindowMode(true)
422 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800423
Jon Miranda941375e2021-03-31 13:10:45 -0400424 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda93e1f042016-11-11 14:13:04 -0800425
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800426 // We use these scales to measure and layout the widgets using their full invariant profile
427 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
428 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
429 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
430 profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY);
Sunny Goyal07b69292018-01-08 14:19:34 -0800431 profile.updateWorkspacePadding();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800432
Jon Miranda93e1f042016-11-11 14:13:04 -0800433 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700434 }
435
Adam Cohen63f1ec02014-08-12 09:23:13 -0700436 /**
Sunny Goyalb46703d2020-05-27 17:52:03 -0700437 * Inverse of {@link #getMultiWindowProfile(Context, WindowBounds)}
Sunny Goyal2e2e2b42018-02-27 16:52:55 -0800438 * @return device profile corresponding to the current orientation in non multi-window mode.
439 */
440 public DeviceProfile getFullScreenProfile() {
441 return isLandscape ? inv.landscapeProfile : inv.portraitProfile;
442 }
443
444 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400445 * Checks if there is enough space for labels on the workspace.
446 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700447 * It is important to call this method after the All Apps variables have been set.
448 */
Jon Miranda941375e2021-03-31 13:10:45 -0400449 private void hideWorkspaceLabelsIfNotEnoughSpace() {
450 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
451 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
452 - iconTextHeight;
453
454 // We want enough space so that the text is closer to its corresponding icon.
455 if (workspaceCellPaddingY < iconTextHeight) {
456 iconTextSizePx = 0;
457 iconDrawablePaddingPx = 0;
458 cellHeightPx = iconSizePx;
459 autoResizeAllAppsCells();
460 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700461 }
Jon Miranda1091e532017-07-21 13:31:50 -0700462
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700463 /**
464 * Re-computes the all-apps cell size to be independent of workspace
465 */
466 public void autoResizeAllAppsCells() {
Jon Miranda941375e2021-03-31 13:10:45 -0400467 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
468 int topBottomPadding = textHeight;
Jon Miranda1091e532017-07-21 13:31:50 -0700469 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
Jon Miranda941375e2021-03-31 13:10:45 -0400470 + textHeight + (topBottomPadding * 2);
Jon Miranda1091e532017-07-21 13:31:50 -0700471 }
472
Jon Miranda228877d2021-02-09 11:05:00 -0500473 /**
474 * Returns the amount of extra (or unused) vertical space.
475 */
476 private int updateAvailableDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700477 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800478
Jon Mirandae126d722021-02-25 10:45:20 -0500479 Point workspacePadding = getTotalWorkspacePadding();
480
481 // Check to see if the icons fit within the available height.
482 float usedHeight = getCellLayoutHeight();
483 final int maxHeight = availableHeightPx - workspacePadding.y;
Jon Miranda228877d2021-02-09 11:05:00 -0500484 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500485 float scaleY = maxHeight / usedHeight;
486 boolean shouldScale = scaleY < 1f;
487
488 float scaleX = 1f;
489 if (isScalableGrid) {
490 // We scale to fit the cellWidth and cellHeight in the available space.
491 // The benefit of scalable grids is that we can get consistent aspect ratios between
492 // devices.
493 float usedWidth = (cellWidthPx * inv.numColumns)
494 + (cellLayoutBorderSpacingPx * (inv.numColumns - 1))
495 + (desiredWorkspaceLeftRightMarginPx * 2);
496 // We do not subtract padding here, as we also scale the workspace padding if needed.
497 scaleX = availableWidthPx / usedWidth;
498 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700499 }
Jon Mirandae126d722021-02-25 10:45:20 -0500500
501 if (shouldScale) {
502 float scale = Math.min(scaleX, scaleY);
503 updateIconSize(scale, res);
504 extraHeight = Math.max(0, maxHeight - getCellLayoutHeight());
505 }
506
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700507 updateAvailableFolderCellDimensions(res);
Jon Miranda228877d2021-02-09 11:05:00 -0500508 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700509 }
510
Jon Mirandae126d722021-02-25 10:45:20 -0500511 private int getCellLayoutHeight() {
512 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacingPx * (inv.numRows - 1));
513 }
514
Jon Miranda6f7e9702019-09-16 14:44:14 -0700515 /**
516 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
517 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
518 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
519 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800520 public void updateIconSize(float scale, Resources res) {
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400521 iconScale = scale;
522
Jon Miranda18751b62017-07-31 17:25:27 -0700523 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800524 final boolean isVerticalLayout = isVerticalBarLayout();
Andras Kloczl6057cb92021-04-07 13:45:17 +0200525 float invIconSizeDp = isLandscape ? inv.landscapeIconSize : inv.iconSize;
Sunny Goyal35c7b192021-04-20 16:51:10 -0700526 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
Andras Kloczl6057cb92021-04-07 13:45:17 +0200527 float invIconTextSizeSp = isLandscape ? inv.landscapeIconTextSize : inv.iconTextSize;
Sunny Goyal35c7b192021-04-20 16:51:10 -0700528 iconTextSizePx = (int) (Utilities.pxFromSp(invIconTextSizeSp, mMetrics) * scale);
Jon Miranda09660722017-06-14 14:20:14 -0700529 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * scale);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700530
Jon Mirandae126d722021-02-25 10:45:20 -0500531 setCellLayoutBorderSpacing((int) (cellLayoutBorderSpacingOriginalPx * scale));
532
533 if (isScalableGrid) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700534 cellWidthPx = pxFromDp(inv.minCellWidth, mMetrics, scale);
535 cellHeightPx = pxFromDp(inv.minCellHeight, mMetrics, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500536 int cellContentHeight = iconSizePx + iconDrawablePaddingPx
537 + Utilities.calculateTextHeight(iconTextSizePx);
538 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
539 desiredWorkspaceLeftRightMarginPx = (int) (desiredWorkspaceLeftRightOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -0500540 } else {
Jon Mirandae126d722021-02-25 10:45:20 -0500541 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda228877d2021-02-09 11:05:00 -0500542 cellHeightPx = iconSizePx + iconDrawablePaddingPx
543 + Utilities.calculateTextHeight(iconTextSizePx);
544 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
545 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
546 && !isMultiWindowMode) {
547 // Ensures that the label is closer to its corresponding icon. This is not an issue
548 // with vertical bar layout or multi-window mode since the issue is handled
549 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
550 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
551 iconDrawablePaddingPx = cellPaddingY;
552 }
Jon Miranda846455e2017-10-02 14:58:52 -0700553 }
Jon Miranda18751b62017-07-31 17:25:27 -0700554
Sunny Goyalae190ff2020-04-14 00:19:01 +0000555 // All apps
556 if (allAppsHasDifferentNumColumns()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700557 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize, mMetrics);
558 allAppsIconTextSizePx = Utilities.pxFromSp(inv.allAppsIconTextSize, mMetrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000559 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Jon Miranda941375e2021-03-31 13:10:45 -0400560 autoResizeAllAppsCells();
Sunny Goyalae190ff2020-04-14 00:19:01 +0000561 } else {
562 allAppsIconSizePx = iconSizePx;
563 allAppsIconTextSizePx = iconTextSizePx;
564 allAppsIconDrawablePaddingPx = iconDrawablePaddingPx;
565 allAppsCellHeightPx = getCellSize().y;
566 }
567 allAppsCellWidthPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700568
Jon Miranda941375e2021-03-31 13:10:45 -0400569 if (isVerticalLayout) {
570 hideWorkspaceLabelsIfNotEnoughSpace();
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700571 }
Winson Chungb3800242013-10-24 11:01:54 -0700572
Winson Chungb3800242013-10-24 11:01:54 -0700573 // Hotseat
Sunny Goyal07b69292018-01-08 14:19:34 -0800574 if (isVerticalLayout) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700575 hotseatBarSizePx = iconSizePx + hotseatBarSidePaddingStartPx
576 + hotseatBarSidePaddingEndPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700577 }
Jon Miranda5044c352017-08-09 11:37:59 -0700578 hotseatCellHeightPx = iconSizePx;
Winson Chungb3800242013-10-24 11:01:54 -0700579
Sunny Goyal07b69292018-01-08 14:19:34 -0800580 if (!isVerticalLayout) {
Jon Miranda18751b62017-07-31 17:25:27 -0700581 int expectedWorkspaceHeight = availableHeightPx - hotseatBarSizePx
Tony Wickham5edf9e22020-03-27 20:06:52 -0700582 - workspacePageIndicatorHeight - edgeMarginPx;
Sunny Goyal47328fd2016-05-25 18:56:41 -0700583 float minRequiredHeight = dropTargetBarSizePx + workspaceSpringLoadedBottomSpace;
584 workspaceSpringLoadShrinkFactor = Math.min(
585 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f,
586 1 - (minRequiredHeight / expectedWorkspaceHeight));
587 } else {
588 workspaceSpringLoadShrinkFactor =
589 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
590 }
591
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700592 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -0700593 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
594 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Winson Chung0f785722015-04-08 10:27:49 -0700595 }
596
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700597 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700598 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700599
Jon Mirandae126d722021-02-25 10:45:20 -0500600 final int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_height);
601
Jon Mirandac1b23992016-12-13 08:57:36 -0800602 // Don't let the folder get too close to the edges of the screen.
Jon Miranda1786df32018-09-25 13:05:23 -0700603 int folderMargin = edgeMarginPx * 2;
Sunny Goyal07b69292018-01-08 14:19:34 -0800604 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -0800605
606 // Check if the icons fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -0500607 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Jon Miranda823da222021-03-23 08:08:45 -0400608 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacingPx);
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800609 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderBottomPanelSize
Jon Mirandae126d722021-02-25 10:45:20 -0500610 - folderMargin - folderContentPaddingTop;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800611 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -0800612
613 // Check if the icons fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -0500614 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Jon Miranda823da222021-03-23 08:08:45 -0400615 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacingPx);
Jon Mirandae126d722021-02-25 10:45:20 -0500616 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin
617 - folderContentPaddingLeftRight * 2;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800618 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -0800619
620 float scale = Math.min(scaleX, scaleY);
621 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700622 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700623 }
624 }
625
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700626 private void updateFolderCellSize(float scale, Resources res) {
Jon Mirandae126d722021-02-25 10:45:20 -0500627 float invIconSizeDp = isVerticalBarLayout() ? inv.landscapeIconSize : inv.iconSize;
Sunny Goyal35c7b192021-04-20 16:51:10 -0700628 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
629 folderChildTextSizePx = pxFromDp(inv.iconTextSize, mMetrics, scale);
Jon Mirandae126d722021-02-25 10:45:20 -0500630 folderLabelTextSizePx = (int) (folderChildTextSizePx * folderLabelTextScale);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700631
632 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700633
Jon Miranda823da222021-03-23 08:08:45 -0400634 if (isScalableGrid) {
635 folderCellWidthPx = (int) (cellWidthPx * scale);
636 folderCellHeightPx = (int) (cellHeightPx * scale);
637
638 int borderSpacing = (int) (cellLayoutBorderSpacingOriginalPx * scale);
639 folderCellLayoutBorderSpacingPx = borderSpacing;
640 folderContentPaddingLeftRight = borderSpacing;
641 folderContentPaddingTop = borderSpacing;
642 } else {
643 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
644 * scale);
645 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
646 * scale);
647
648 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
649 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
650 }
651
Jonathan Miranda9ad87462017-07-26 17:41:02 +0000652 folderChildDrawablePaddingPx = Math.max(0,
653 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700654 }
655
Winson1f064272016-07-18 17:18:02 -0700656 public void updateInsets(Rect insets) {
657 mInsets.set(insets);
Sunny Goyal07b69292018-01-08 14:19:34 -0800658 updateWorkspacePadding();
Winson1f064272016-07-18 17:18:02 -0700659 }
660
Sunny Goyalae6e3182019-04-30 12:04:37 -0700661 /**
662 * The current device insets. This is generally same as the insets being dispatched to
663 * {@link Insettable} elements, but can differ if the element is using a different profile.
664 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800665 public Rect getInsets() {
666 return mInsets;
667 }
668
Sunny Goyal756cd262015-08-20 12:33:21 -0700669 public Point getCellSize() {
Jon Miranda6f7e9702019-09-16 14:44:14 -0700670 return getCellSize(inv.numColumns, inv.numRows);
671 }
672
673 private Point getCellSize(int numColumns, int numRows) {
Sunny Goyal756cd262015-08-20 12:33:21 -0700674 Point result = new Point();
675 // Since we are only concerned with the overall padding, layout direction does
676 // not matter.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700677 Point padding = getTotalWorkspacePadding();
Jon Miranda18751b62017-07-31 17:25:27 -0700678 result.x = calculateCellWidth(availableWidthPx - padding.x
Jon Miranda228877d2021-02-09 11:05:00 -0500679 - cellLayoutPaddingLeftRightPx * 2, cellLayoutBorderSpacingPx, numColumns);
Jon Miranda18751b62017-07-31 17:25:27 -0700680 result.y = calculateCellHeight(availableHeightPx - padding.y
Jon Miranda228877d2021-02-09 11:05:00 -0500681 - cellLayoutBottomPaddingPx, cellLayoutBorderSpacingPx, numRows);
Sunny Goyal756cd262015-08-20 12:33:21 -0700682 return result;
683 }
684
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700685 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -0800686 updateWorkspacePadding();
687 return new Point(workspacePadding.left + workspacePadding.right,
688 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700689 }
690
691 /**
Sunny Goyal07b69292018-01-08 14:19:34 -0800692 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
693 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700694 */
Sunny Goyal07b69292018-01-08 14:19:34 -0800695 private void updateWorkspacePadding() {
696 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -0700697 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -0800698 padding.top = 0;
699 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800700 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700701 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -0700702 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -0700703 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -0700704 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700705 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -0700706 }
Winson Chungb3800242013-10-24 11:01:54 -0700707 } else {
Tony Wickhama29a0462021-03-02 12:28:25 -0800708 int hotseatTop = isTaskbarPresent ? taskbarSize : hotseatBarSizePx;
709 int paddingBottom = hotseatTop + workspacePageIndicatorHeight
Jon Miranda228877d2021-02-09 11:05:00 -0500710 + workspaceBottomPadding - mWorkspacePageIndicatorOverlapWorkspace;
Sunny Goyalc6205602015-05-21 20:46:33 -0700711 if (isTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700712 // Pad the left and right of the workspace to ensure consistent spacing
713 // between all icons
Tony Wickhamd6b40372015-09-23 18:37:57 -0700714 // The amount of screen space available for left/right padding.
Sunny Goyal228153d2018-01-04 15:35:22 -0800715 int availablePaddingX = Math.max(0, widthPx - ((inv.numColumns * cellWidthPx) +
Sunny Goyalf5440cb2016-12-14 15:13:00 -0800716 ((inv.numColumns - 1) * cellWidthPx)));
Tony Wickhamd6b40372015-09-23 18:37:57 -0700717 availablePaddingX = (int) Math.min(availablePaddingX,
Sunny Goyal07b69292018-01-08 14:19:34 -0800718 widthPx * MAX_HORIZONTAL_PADDING_PERCENT);
Tony Wickhama29a0462021-03-02 12:28:25 -0800719 int hotseatVerticalPadding = isTaskbarPresent ? 0
720 : hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700721 int availablePaddingY = Math.max(0, heightPx - edgeMarginPx - paddingBottom
Tony Wickhama29a0462021-03-02 12:28:25 -0800722 - (2 * inv.numRows * cellHeightPx) - hotseatVerticalPadding);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700723 padding.set(availablePaddingX / 2, edgeMarginPx + availablePaddingY / 2,
Tony Wickhamd6b40372015-09-23 18:37:57 -0700724 availablePaddingX / 2, paddingBottom + availablePaddingY / 2);
Andras Kloczl8e57cce2021-02-11 23:51:19 +0100725
726 if (FeatureFlags.ENABLE_TWO_PANEL_HOME.get()) {
727 padding.set(0, padding.top, 0, padding.bottom);
728 }
Winson Chungb3800242013-10-24 11:01:54 -0700729 } else {
730 // Pad the top and bottom of the workspace with search/hotseat bar sizes
Winson1f064272016-07-18 17:18:02 -0700731 padding.set(desiredWorkspaceLeftRightMarginPx,
Jon Mirandae126d722021-02-25 10:45:20 -0500732 workspaceTopPadding + (isScalableGrid ? 0 : edgeMarginPx),
Winson1f064272016-07-18 17:18:02 -0700733 desiredWorkspaceLeftRightMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700734 paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -0700735 }
736 }
Winson Chungb3800242013-10-24 11:01:54 -0700737 }
738
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700739 public Rect getHotseatLayoutPadding() {
740 if (isVerticalBarLayout()) {
741 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700742 mHotseatPadding.set(mInsets.left + hotseatBarSidePaddingStartPx,
743 mInsets.top, hotseatBarSidePaddingEndPx, mInsets.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700744 } else {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700745 mHotseatPadding.set(hotseatBarSidePaddingEndPx, mInsets.top,
746 mInsets.right + hotseatBarSidePaddingStartPx, mInsets.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700747 }
748 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700749 // We want the edges of the hotseat to line up with the edges of the workspace, but the
750 // icons in the hotseat are a different size, and so don't line up perfectly. To account
751 // for this, we pad the left and right of the hotseat with half of the difference of a
752 // workspace cell vs a hotseat cell.
753 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700754 float hotseatCellWidth = (float) widthPx / inv.numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700755 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
756 mHotseatPadding.set(
Sunny Goyal786940a2020-06-02 02:31:31 -0700757 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingLeftRightPx
758 + mInsets.left,
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700759 hotseatBarTopPaddingPx,
Sunny Goyal786940a2020-06-02 02:31:31 -0700760 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx
761 + mInsets.right,
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700762 hotseatBarBottomPaddingPx + mInsets.bottom + cellLayoutBottomPaddingPx);
763 }
764 return mHotseatPadding;
765 }
766
Winsonfadbe8f2016-07-22 16:35:37 -0700767 /**
768 * @return the bounds for which the open folders should be contained within
769 */
770 public Rect getAbsoluteOpenFolderBounds() {
771 if (isVerticalBarLayout()) {
772 // Folders should only appear right of the drop target bar and left of the hotseat
773 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
774 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -0700775 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700776 mInsets.top + availableHeightPx);
777 } else {
778 // Folders should only appear below the drop target bar and above the hotseat
Tony Wickhamae72b462021-03-10 16:18:40 -0800779 int hotseatTop = isTaskbarPresent ? taskbarSize : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -0800780 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700781 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -0800782 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -0800783 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -0700784 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -0700785 }
786 }
787
Jon Miranda228877d2021-02-09 11:05:00 -0500788 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
789 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -0700790 }
Jon Miranda228877d2021-02-09 11:05:00 -0500791 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
792 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -0700793 }
794
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700795 /**
Tony Wickham55616cd2015-09-23 14:55:17 -0700796 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
797 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
798 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700799 */
Tony Wickhamab946a12015-09-16 15:38:16 -0700800 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -0700801 return isLandscape && transposeLayoutWithOrientation;
802 }
803
Sunny Goyal59d086c2018-05-07 17:31:40 -0700804 /**
Jon Miranda6f7e9702019-09-16 14:44:14 -0700805 * Returns true when the number of workspace columns and all apps columns differs.
806 */
807 private boolean allAppsHasDifferentNumColumns() {
808 return inv.numAllAppsColumns != inv.numColumns;
809 }
810
811 /**
Sunny Goyal59d086c2018-05-07 17:31:40 -0700812 * Updates orientation information and returns true if it has changed from the previous value.
813 */
Winson Chung13c1c2c2019-09-06 11:46:19 -0700814 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -0700815 if (isVerticalBarLayout()) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700816 boolean isSeascape = DisplayController.INSTANCE.get(context)
817 .getInfo().rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -0700818 if (mIsSeascape != isSeascape) {
819 mIsSeascape = isSeascape;
820 return true;
821 }
822 }
823 return false;
824 }
825
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800826 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -0700827 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800828 }
829
Sunny Goyal07b69292018-01-08 14:19:34 -0800830 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyalc6205602015-05-21 20:46:33 -0700831 return isVerticalBarLayout() || isLargeTablet;
Winson Chungb3800242013-10-24 11:01:54 -0700832 }
833
Sunny Goyalc13403c2016-11-18 23:44:48 -0800834 public int getCellHeight(@ContainerType int containerType) {
835 switch (containerType) {
836 case CellLayout.WORKSPACE:
837 return cellHeightPx;
838 case CellLayout.FOLDER:
839 return folderCellHeightPx;
840 case CellLayout.HOTSEAT:
841 return hotseatCellHeightPx;
842 default:
843 // ??
844 return 0;
845 }
846 }
Sunny Goyal13178ac2016-04-04 16:35:22 -0700847
Jon Miranda58561d42021-03-17 10:51:54 -0400848 private String pxToDpStr(String name, float value) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700849 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)";
Jon Miranda58561d42021-03-17 10:51:54 -0400850 }
851
852 public void dump(String prefix, PrintWriter writer) {
853 writer.println(prefix + "DeviceProfile:");
Sunny Goyal35c7b192021-04-20 16:51:10 -0700854 writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
Jon Miranda58561d42021-03-17 10:51:54 -0400855
856 writer.println(prefix + "\tisTablet:" + isTablet);
857 writer.println(prefix + "\tisLargeTablet:" + isLargeTablet);
858 writer.println(prefix + "\tisPhone:" + isPhone);
859 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
860 + transposeLayoutWithOrientation);
861
862 writer.println(prefix + "\tisLandscape:" + isLandscape);
863 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
864
865 writer.println(prefix + pxToDpStr("windowX", windowX));
866 writer.println(prefix + pxToDpStr("windowY", windowY));
867 writer.println(prefix + pxToDpStr("widthPx", widthPx));
868 writer.println(prefix + pxToDpStr("heightPx", heightPx));
869
870 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
871 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
872
873 writer.println(prefix + "\taspectRatio:" + aspectRatio);
874
875 writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
876
877 writer.println(prefix + "\tinv.minCellWidth:" + inv.minCellWidth + "dp");
878 writer.println(prefix + "\tinv.minCellHeight:" + inv.minCellHeight + "dp");
879
880 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
881 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
882
883 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
884 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
885
886 writer.println(prefix + "\tinv.iconSize:" + inv.iconSize + "dp");
887 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
888 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
889 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
890
891 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
892 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
893 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
894 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
895 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
896 folderChildDrawablePaddingPx));
Jon Miranda823da222021-03-23 08:08:45 -0400897 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacingPx",
898 folderCellLayoutBorderSpacingPx));
Jon Miranda58561d42021-03-17 10:51:54 -0400899
900 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacingPx",
901 cellLayoutBorderSpacingPx));
902 writer.println(prefix + pxToDpStr("desiredWorkspaceLeftRightMarginPx",
903 desiredWorkspaceLeftRightMarginPx));
904
905 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
906 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
907 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
908 allAppsIconDrawablePaddingPx));
909 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
910
911 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
912 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
913 writer.println(prefix + pxToDpStr("hotseatBarTopPaddingPx", hotseatBarTopPaddingPx));
914 writer.println(prefix + pxToDpStr("hotseatBarBottomPaddingPx", hotseatBarBottomPaddingPx));
915 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
916 hotseatBarSidePaddingStartPx));
917 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
918 hotseatBarSidePaddingEndPx));
919
920 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
921
922 writer.println(prefix + pxToDpStr("taskbarSize", taskbarSize));
923 writer.println(prefix + pxToDpStr("nonOverlappingTaskbarInset",
924 nonOverlappingTaskbarInset));
925
926 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
927 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
928 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
929 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
930
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400931 writer.println(prefix + pxToDpStr("scaleToFit", iconScale));
Jon Miranda58561d42021-03-17 10:51:54 -0400932 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400933
934 if (inv.devicePaddings != null) {
935 int unscaledExtraSpace = (int) (extraSpace / iconScale);
936 writer.println(prefix + pxToDpStr("maxEmptySpace",
937 inv.devicePaddings.getDevicePadding(unscaledExtraSpace).getMaxEmptySpacePx()));
938 }
Jon Miranda58561d42021-03-17 10:51:54 -0400939 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
940 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
941 writer.println(prefix + pxToDpStr("extraHotseatBottomPadding", extraHotseatBottomPadding));
942 }
943
Sunny Goyalfd58da62020-08-11 12:06:49 -0700944 private static Context getContext(Context c, Info info, int orientation) {
Sunny Goyal1890f672020-04-30 12:28:00 -0700945 Configuration config = new Configuration(c.getResources().getConfiguration());
946 config.orientation = orientation;
Sunny Goyal35c7b192021-04-20 16:51:10 -0700947 config.densityDpi = info.densityDpi;
Sunny Goyal1890f672020-04-30 12:28:00 -0700948 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700949 }
Sunny Goyalfde55052018-02-01 14:46:13 -0800950
951 /**
952 * Callback when a component changes the DeviceProfile associated with it, as a result of
953 * configuration change
954 */
955 public interface OnDeviceProfileChangeListener {
956
957 /**
958 * Called when the device profile is reassigned. Note that for layout and measurements, it
959 * is sufficient to listen for inset changes. Use this callback when you need to perform
960 * a one time operation.
961 */
962 void onDeviceProfileChanged(DeviceProfile dp);
963 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700964
965 public static class Builder {
966 private Context mContext;
967 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -0700968 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700969
Sunny Goyal0addbf02020-04-28 14:17:35 -0700970 private final Point mWindowPosition = new Point();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700971 private Point mMinSize, mMaxSize;
972 private int mWidth, mHeight;
973
974 private boolean mIsLandscape;
975 private boolean mIsMultiWindowMode = false;
976 private boolean mTransposeLayoutWithOrientation;
977
Sunny Goyalfd58da62020-08-11 12:06:49 -0700978 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700979 mContext = context;
980 mInv = inv;
981 mInfo = info;
982 mTransposeLayoutWithOrientation = context.getResources()
983 .getBoolean(R.bool.hotseat_transpose_layout_with_orientation);
Winson Chung8e64bba2021-04-20 13:26:26 -0700984 if (TestProtocol.sDebugTracing) {
985 Log.d(TestProtocol.LAUNCHER_NOT_TRANSPOSED,
986 "transposeLayout=" + mTransposeLayoutWithOrientation);
987 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700988 }
989
990 public Builder setSizeRange(Point minSize, Point maxSize) {
991 mMinSize = minSize;
992 mMaxSize = maxSize;
993 return this;
994 }
995
996 public Builder setSize(int width, int height) {
997 mWidth = width;
998 mHeight = height;
999 mIsLandscape = mWidth > mHeight;
Winson Chung8e64bba2021-04-20 13:26:26 -07001000 if (TestProtocol.sDebugTracing) {
1001 Log.d(TestProtocol.LAUNCHER_NOT_TRANSPOSED,
1002 "isLandscape=" + mIsLandscape + " w=" + mWidth + " h=" + mHeight);
1003 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001004 return this;
1005 }
1006
1007 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1008 mIsMultiWindowMode = isMultiWindowMode;
1009 return this;
1010 }
1011
Sunny Goyal0addbf02020-04-28 14:17:35 -07001012 /**
1013 * Sets the window position if not full-screen
1014 */
1015 public Builder setWindowPosition(int x, int y) {
1016 mWindowPosition.set(x, y);
1017 return this;
1018 }
1019
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001020 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1021 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1022 return this;
1023 }
1024
1025 public DeviceProfile build() {
1026 return new DeviceProfile(mContext, mInv, mInfo, mMinSize, mMaxSize,
1027 mWidth, mHeight, mIsLandscape, mIsMultiWindowMode,
Sunny Goyal0addbf02020-04-28 14:17:35 -07001028 mTransposeLayoutWithOrientation, mWindowPosition);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001029 }
1030 }
1031
Winson Chungb3800242013-10-24 11:01:54 -07001032}