blob: dae4f3b8dd7977c1e1f4dc2af004a5340031eb8e [file] [log] [blame]
Winson Chungb3800242013-10-24 11:01:54 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.launcher3;
18
Jon Mirandae126d722021-02-25 10:45:20 -050019import static com.android.launcher3.ResourceUtils.pxFromDp;
Jon Miranda58561d42021-03-17 10:51:54 -040020import static com.android.launcher3.Utilities.dpiFromPx;
Jon Miranda228877d2021-02-09 11:05:00 -050021
Winson Chungb3800242013-10-24 11:01:54 -070022import android.content.Context;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070023import android.content.res.Configuration;
Winson Chungb3800242013-10-24 11:01:54 -070024import android.content.res.Resources;
Winson Chungb3800242013-10-24 11:01:54 -070025import android.graphics.Point;
Jon Miranda7ae64ff2016-11-21 16:18:46 -080026import android.graphics.PointF;
Winson Chungb3800242013-10-24 11:01:54 -070027import android.graphics.Rect;
Winson Chung8e64bba2021-04-20 13:26:26 -070028import android.util.Log;
Sunny Goyal59d086c2018-05-07 17:31:40 -070029import android.view.Surface;
Tony Wickham15883892021-02-12 11:24:40 -080030import android.view.WindowInsets;
31import android.view.WindowManager;
Winson Chungb3800242013-10-24 11:01:54 -070032
Sunny Goyalc13403c2016-11-18 23:44:48 -080033import com.android.launcher3.CellLayout.ContainerType;
Jon Miranda228877d2021-02-09 11:05:00 -050034import com.android.launcher3.DevicePaddings.DevicePadding;
Tony Wickham15883892021-02-12 11:24:40 -080035import com.android.launcher3.config.FeatureFlags;
Tony Wickhame1cb93f2019-05-03 11:27:32 -070036import com.android.launcher3.graphics.IconShape;
Tony Wickham8912b042018-11-29 15:28:53 -080037import com.android.launcher3.icons.DotRenderer;
Hyunyoung Song48cb7bc2018-09-25 17:03:34 -070038import com.android.launcher3.icons.IconNormalizer;
Winson Chung8e64bba2021-04-20 13:26:26 -070039import com.android.launcher3.testing.TestProtocol;
Sunny Goyalfd58da62020-08-11 12:06:49 -070040import com.android.launcher3.util.DisplayController;
41import com.android.launcher3.util.DisplayController.Info;
Sunny Goyalb46703d2020-05-27 17:52:03 -070042import com.android.launcher3.util.WindowBounds;
Winson1f064272016-07-18 17:18:02 -070043
Jon Miranda58561d42021-03-17 10:51:54 -040044import java.io.PrintWriter;
45
Winson Chungb3800242013-10-24 11:01:54 -070046public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070047
Sunny Goyal1890f672020-04-30 12:28:00 -070048 private static final float TABLET_MIN_DPS = 600;
49 private static final float LARGE_TABLET_MIN_DPS = 720;
50
51
Adam Cohen2e6da152015-05-06 11:42:25 -070052 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070053 private final Info mInfo;
Winson Chungbe876472014-05-14 14:15:20 -070054
Sunny Goyalc6205602015-05-21 20:46:33 -070055 // Device properties
56 public final boolean isTablet;
57 public final boolean isLargeTablet;
58 public final boolean isPhone;
59 public final boolean transposeLayoutWithOrientation;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -070060
Sunny Goyalc6205602015-05-21 20:46:33 -070061 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -070062 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -080063 public final boolean isMultiWindowMode;
64
Sunny Goyal0addbf02020-04-28 14:17:35 -070065 public final int windowX;
66 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -070067 public final int widthPx;
68 public final int heightPx;
69 public final int availableWidthPx;
70 public final int availableHeightPx;
Jon Mirandabba64512019-03-27 10:54:17 -070071
72 public final float aspectRatio;
73
Jon Mirandae126d722021-02-25 10:45:20 -050074 public final boolean isScalableGrid;
75
Tony Wickhamd6b40372015-09-23 18:37:57 -070076 /**
77 * The maximum amount of left/right workspace padding as a percentage of the screen width.
78 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
79 * 7% of the screen width can be used as right padding.
80 */
81 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -070082
Jon Miranda3f9bab22017-07-28 14:50:17 -070083 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda30d0aa22017-07-25 15:55:29 -070084
Jon Miranda5eacbb72018-07-31 11:14:46 -070085 // To evenly space the icons, increase the left/right margins for tablets in portrait mode.
86 private static final int PORTRAIT_TABLET_LEFT_RIGHT_PADDING_MULTIPLIER = 4;
87
Sunny Goyalc6205602015-05-21 20:46:33 -070088 // Workspace
Jon Mirandae126d722021-02-25 10:45:20 -050089 public final int desiredWorkspaceLeftRightOriginalPx;
90 public int desiredWorkspaceLeftRightMarginPx;
91 public final int cellLayoutBorderSpacingOriginalPx;
92 public int cellLayoutBorderSpacingPx;
Jon Miranda28032002017-07-13 16:18:56 -070093 public final int cellLayoutPaddingLeftRightPx;
Jon Miranda18751b62017-07-31 17:25:27 -070094 public final int cellLayoutBottomPaddingPx;
Sunny Goyalc6205602015-05-21 20:46:33 -070095 public final int edgeMarginPx;
Sunny Goyal47328fd2016-05-25 18:56:41 -070096 public float workspaceSpringLoadShrinkFactor;
97 public final int workspaceSpringLoadedBottomSpace;
Sunny Goyalc6205602015-05-21 20:46:33 -070098
Jon Miranda58561d42021-03-17 10:51:54 -040099 private final int extraSpace;
Jon Miranda228877d2021-02-09 11:05:00 -0500100 public int workspaceTopPadding;
101 public int workspaceBottomPadding;
Jon Miranda58561d42021-03-17 10:51:54 -0400102 public int extraHotseatBottomPadding;
Jon Miranda228877d2021-02-09 11:05:00 -0500103
Tony Wickham5edf9e22020-03-27 20:06:52 -0700104 // Workspace page indicator
105 public final int workspacePageIndicatorHeight;
106 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -0700107
Sunny Goyalc6205602015-05-21 20:46:33 -0700108 // Workspace icons
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400109 public float iconScale;
Sunny Goyalc6205602015-05-21 20:46:33 -0700110 public int iconSizePx;
111 public int iconTextSizePx;
112 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700113 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -0700114
Adam Cohen59400422014-03-05 18:07:04 -0800115 public int cellWidthPx;
116 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700117 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800118
Jon Mirandae126d722021-02-25 10:45:20 -0500119 public int cellYPaddingPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500120
Sunny Goyalc6205602015-05-21 20:46:33 -0700121 // Folder
Jon Mirandae126d722021-02-25 10:45:20 -0500122 public float folderLabelTextScale;
123 public int folderLabelTextSizePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700124 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -0700125 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700126
Jon Mirandae126d722021-02-25 10:45:20 -0500127 // Folder content
Jon Miranda823da222021-03-23 08:08:45 -0400128 public int folderCellLayoutBorderSpacingPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500129 public int folderContentPaddingLeftRight;
130 public int folderContentPaddingTop;
131
Jon Mirandabf7d8122016-11-03 15:29:29 -0700132 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700133 public int folderCellWidthPx;
134 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700135
136 // Folder child
137 public int folderChildIconSizePx;
138 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700139 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700140
Sunny Goyalc6205602015-05-21 20:46:33 -0700141 // Hotseat
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700142 public final int numShownHotseatIcons;
Sunny Goyalc6205602015-05-21 20:46:33 -0700143 public int hotseatCellHeightPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700144 // In portrait: size = height, in landscape: size = width
145 public int hotseatBarSizePx;
Sunny Goyal07b69292018-01-08 14:19:34 -0800146 public final int hotseatBarTopPaddingPx;
Jon Miranda7e183c32018-06-20 11:05:27 -0700147 public int hotseatBarBottomPaddingPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700148 // Start is the side next to the nav bar, end is the side next to the workspace
149 public final int hotseatBarSidePaddingStartPx;
150 public final int hotseatBarSidePaddingEndPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700151
Sunny Goyalc6205602015-05-21 20:46:33 -0700152 // All apps
Samuel Fufaee9aff92021-04-05 13:30:40 -0500153 public int allAppsOpenVerticalTranslate;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700154 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700155 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700156 public int allAppsIconSizePx;
157 public int allAppsIconDrawablePaddingPx;
158 public float allAppsIconTextSizePx;
159
Zak Cohen334efeb2021-03-19 16:42:07 -0700160 // Overview
Zak Cohen334efeb2021-03-19 16:42:07 -0700161 public int overviewTaskMarginPx;
Alex Chaudedbc8a2021-03-17 16:53:26 +0000162 public int overviewTaskIconSizePx;
163 public int overviewTaskThumbnailTopMarginPx;
Zak Cohen334efeb2021-03-19 16:42:07 -0700164
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800165 // Widgets
166 public final PointF appWidgetScale = new PointF(1.0f, 1.0f);
167
Sunny Goyal47328fd2016-05-25 18:56:41 -0700168 // Drop Target
169 public int dropTargetBarSizePx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700170
Winson1f064272016-07-18 17:18:02 -0700171 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800172 private final Rect mInsets = new Rect();
173 public final Rect workspacePadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700174 private final Rect mHotseatPadding = new Rect();
Jon Miranda0bd63d12019-03-06 17:29:29 -0800175 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700176 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700177
Tony Wickhamf34bee82018-12-03 18:11:39 -0800178 // Notification dots
Samuel Fufac96fa242019-09-26 23:06:32 -0700179 public DotRenderer mDotRendererWorkSpace;
180 public DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800181
Tony Wickham15883892021-02-12 11:24:40 -0800182 // Taskbar
183 public boolean isTaskbarPresent;
184 public int taskbarSize;
Tony Wickham145b7fd2021-03-11 10:03:12 -0800185 // How much of the bottom inset is due to Taskbar rather than other system elements.
186 public int nonOverlappingTaskbarInset;
Tony Wickham15883892021-02-12 11:24:40 -0800187
Sunny Goyalfd58da62020-08-11 12:06:49 -0700188 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info,
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700189 Point minSize, Point maxSize, int width, int height, boolean isLandscape,
Sunny Goyal0addbf02020-04-28 14:17:35 -0700190 boolean isMultiWindowMode, boolean transposeLayoutWithOrientation,
191 Point windowPosition) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700192
Adam Cohen2e6da152015-05-06 11:42:25 -0700193 this.inv = inv;
Sunny Goyalc6205602015-05-21 20:46:33 -0700194 this.isLandscape = isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -0800195 this.isMultiWindowMode = isMultiWindowMode;
Jon Mirandae126d722021-02-25 10:45:20 -0500196 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Sunny Goyal0addbf02020-04-28 14:17:35 -0700197 windowX = windowPosition.x;
198 windowY = windowPosition.y;
Winson Chungb3800242013-10-24 11:01:54 -0700199
Jon Mirandae126d722021-02-25 10:45:20 -0500200 isScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
201
Jon Miranda7e183c32018-06-20 11:05:27 -0700202 // Determine sizes.
203 widthPx = width;
204 heightPx = height;
Tony Wickham15883892021-02-12 11:24:40 -0800205 int nonFinalAvailableHeightPx;
Jon Miranda7e183c32018-06-20 11:05:27 -0700206 if (isLandscape) {
207 availableWidthPx = maxSize.x;
Tony Wickham15883892021-02-12 11:24:40 -0800208 nonFinalAvailableHeightPx = minSize.y;
Jon Miranda7e183c32018-06-20 11:05:27 -0700209 } else {
210 availableWidthPx = minSize.x;
Tony Wickham15883892021-02-12 11:24:40 -0800211 nonFinalAvailableHeightPx = maxSize.y;
Jon Miranda7e183c32018-06-20 11:05:27 -0700212 }
213
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700214 mInfo = info;
Adam Cohen2e6da152015-05-06 11:42:25 -0700215
Sunny Goyalc6205602015-05-21 20:46:33 -0700216 // Constants from resources
Jon Miranda58561d42021-03-17 10:51:54 -0400217 float swDPs = dpiFromPx(Math.min(info.smallestSize.x, info.smallestSize.y), info.metrics);
Alex Chau4e2c25a2021-02-03 16:20:04 +0000218 boolean allowRotation = context.getResources().getBoolean(R.bool.allow_rotation);
219 // Tablet UI is built with assumption that simulated landscape is disabled.
220 isTablet = allowRotation && swDPs >= TABLET_MIN_DPS;
221 isLargeTablet = isTablet && swDPs >= LARGE_TABLET_MIN_DPS;
Sunny Goyalc6205602015-05-21 20:46:33 -0700222 isPhone = !isTablet && !isLargeTablet;
Jon Mirandabba64512019-03-27 10:54:17 -0700223 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Jon Miranda7e183c32018-06-20 11:05:27 -0700224 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
Sunny Goyalc6205602015-05-21 20:46:33 -0700225
226 // Some more constants
Sunny Goyal1890f672020-04-30 12:28:00 -0700227 context = getContext(context, info, isVerticalBarLayout()
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700228 ? Configuration.ORIENTATION_LANDSCAPE
229 : Configuration.ORIENTATION_PORTRAIT);
Sunny Goyal1890f672020-04-30 12:28:00 -0700230 final Resources res = context.getResources();
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700231
Tony Wickham15883892021-02-12 11:24:40 -0800232 isTaskbarPresent = isTablet && FeatureFlags.ENABLE_TASKBAR.get();
233 if (isTaskbarPresent) {
234 // Taskbar will be added later, but provides bottom insets that we should subtract
235 // from availableHeightPx.
236 taskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_size);
237 WindowInsets windowInsets = DisplayController.INSTANCE.get(context).getHolder(mInfo.id)
238 .getDisplayContext().getSystemService(WindowManager.class)
239 .getCurrentWindowMetrics().getWindowInsets();
Tony Wickham145b7fd2021-03-11 10:03:12 -0800240 nonOverlappingTaskbarInset =
Tony Wickham15883892021-02-12 11:24:40 -0800241 taskbarSize - windowInsets.getSystemWindowInsetBottom();
242 if (nonOverlappingTaskbarInset > 0) {
243 nonFinalAvailableHeightPx -= nonOverlappingTaskbarInset;
244 }
245 }
246 availableHeightPx = nonFinalAvailableHeightPx;
247
Winson Chungb3800242013-10-24 11:01:54 -0700248 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700249
Jon Mirandae126d722021-02-25 10:45:20 -0500250 desiredWorkspaceLeftRightMarginPx = isVerticalBarLayout() ? 0 : isScalableGrid
251 ? res.getDimensionPixelSize(R.dimen.scalable_grid_left_right_margin)
252 : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin);
253 desiredWorkspaceLeftRightOriginalPx = desiredWorkspaceLeftRightMarginPx;
254
Samuel Fufaee9aff92021-04-05 13:30:40 -0500255
256 allAppsOpenVerticalTranslate = res.getDimensionPixelSize(
257 R.dimen.all_apps_open_vertical_translate);
258
Jon Mirandae126d722021-02-25 10:45:20 -0500259 folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
260 folderContentPaddingLeftRight =
261 res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
262 folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_content_padding_top);
263
264 setCellLayoutBorderSpacing(pxFromDp(inv.borderSpacing, mInfo.metrics, 1f));
265 cellLayoutBorderSpacingOriginalPx = cellLayoutBorderSpacingPx;
Jon Miranda823da222021-03-23 08:08:45 -0400266 folderCellLayoutBorderSpacingPx = cellLayoutBorderSpacingPx;
Jon Mirandae126d722021-02-25 10:45:20 -0500267
Jon Miranda5eacbb72018-07-31 11:14:46 -0700268 int cellLayoutPaddingLeftRightMultiplier = !isVerticalBarLayout() && isTablet
269 ? PORTRAIT_TABLET_LEFT_RIGHT_PADDING_MULTIPLIER : 1;
Jon Mirandae126d722021-02-25 10:45:20 -0500270 int cellLayoutPadding = isScalableGrid
271 ? 0
272 : res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_padding);
Andras Kloczl8e57cce2021-02-11 23:51:19 +0100273
274 if (FeatureFlags.ENABLE_TWO_PANEL_HOME.get() && isTablet) {
275 cellLayoutPaddingLeftRightPx =
276 res.getDimensionPixelSize(R.dimen.two_panel_home_side_padding);
277 cellLayoutBottomPaddingPx = 0;
278 } else if (isLandscape) {
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700279 cellLayoutPaddingLeftRightPx = 0;
280 cellLayoutBottomPaddingPx = cellLayoutPadding;
281 } else {
282 cellLayoutPaddingLeftRightPx = cellLayoutPaddingLeftRightMultiplier * cellLayoutPadding;
283 cellLayoutBottomPaddingPx = 0;
284 }
285
Tony Wickham5edf9e22020-03-27 20:06:52 -0700286 workspacePageIndicatorHeight = res.getDimensionPixelSize(
287 R.dimen.workspace_page_indicator_height);
288 mWorkspacePageIndicatorOverlapWorkspace =
289 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700290
Winson Chungb3800242013-10-24 11:01:54 -0700291 iconDrawablePaddingOriginalPx =
292 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700293 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
294 workspaceSpringLoadedBottomSpace =
295 res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space);
Sunny Goyald5190522017-04-24 03:06:54 -0700296
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700297 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700298
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700299 numShownHotseatIcons = inv.numShownHotseatIcons;
Winson1f064272016-07-18 17:18:02 -0700300 hotseatBarTopPaddingPx =
301 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding);
Jon Miranda7e183c32018-06-20 11:05:27 -0700302 hotseatBarBottomPaddingPx = (isTallDevice ? 0
303 : res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_non_tall_padding))
304 + res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_padding);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700305 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800306 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700307 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700308 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Jon Miranda228877d2021-02-09 11:05:00 -0500309 int hotseatExtraVerticalSize =
310 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_extra_vertical_size);
Jon Mirandae126d722021-02-25 10:45:20 -0500311 hotseatBarSizePx = pxFromDp(inv.iconSize, mInfo.metrics, 1f)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700312 + (isVerticalBarLayout()
Sunny Goyal415f1732018-11-29 10:33:47 -0800313 ? (hotseatBarSidePaddingStartPx + hotseatBarSidePaddingEndPx)
Jon Miranda228877d2021-02-09 11:05:00 -0500314 : (hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx
Jon Mirandae126d722021-02-25 10:45:20 -0500315 + (isScalableGrid ? 0 : hotseatExtraVerticalSize)));
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700316
Zak Cohen334efeb2021-03-19 16:42:07 -0700317 overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin);
Alex Chaudedbc8a2021-03-17 16:53:26 +0000318 overviewTaskIconSizePx =
319 isTablet && FeatureFlags.ENABLE_OVERVIEW_GRID.get() ? res.getDimensionPixelSize(
320 R.dimen.task_thumbnail_icon_size_grid) : res.getDimensionPixelSize(
321 R.dimen.task_thumbnail_icon_size);
322 overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx * 2;
Zak Cohen334efeb2021-03-19 16:42:07 -0700323
Jon Miranda2ed276e2017-06-29 11:36:34 -0700324 // Calculate all of the remaining variables.
Jon Miranda58561d42021-03-17 10:51:54 -0400325 extraSpace = updateAvailableDimensions(res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700326 // Now that we have all of the variables calculated, we can tune certain sizes.
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400327 if (isScalableGrid && inv.devicePaddings != null) {
328 // Paddings were created assuming no scaling, so we first unscale the extra space.
329 int unscaledExtraSpace = (int) (extraSpace / iconScale);
330 DevicePadding padding = inv.devicePaddings.getDevicePadding(unscaledExtraSpace);
Jon Miranda228877d2021-02-09 11:05:00 -0500331
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400332 int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace);
333 int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace);
334 int paddingHotseatBottom = padding.getHotseatBottomPadding(unscaledExtraSpace);
335
336 workspaceTopPadding = Math.round(paddingWorkspaceTop * iconScale);
337 workspaceBottomPadding = Math.round(paddingWorkspaceBottom * iconScale);
338 extraHotseatBottomPadding = Math.round(paddingHotseatBottom * iconScale);
339
Jon Miranda58561d42021-03-17 10:51:54 -0400340 hotseatBarSizePx += extraHotseatBottomPadding;
341 hotseatBarBottomPaddingPx += extraHotseatBottomPadding;
Jon Miranda228877d2021-02-09 11:05:00 -0500342 } else if (!isVerticalBarLayout() && isPhone && isTallDevice) {
Jon Miranda3f9bab22017-07-28 14:50:17 -0700343 // We increase the hotseat size when there is extra space.
Jon Miranda2ed276e2017-06-29 11:36:34 -0700344 // ie. For a display with a large aspect ratio, we can keep the icons on the workspace
Jon Miranda3f9bab22017-07-28 14:50:17 -0700345 // in portrait mode closer together by adding more height to the hotseat.
Jon Miranda30d0aa22017-07-25 15:55:29 -0700346 // Note: This calculation was created after noticing a pattern in the design spec.
Jon Miranda58561d42021-03-17 10:51:54 -0400347 int extraSpace = getCellSize().y - iconSizePx - iconDrawablePaddingPx * 2
Tony Wickham5edf9e22020-03-27 20:06:52 -0700348 - workspacePageIndicatorHeight;
Jon Miranda7e183c32018-06-20 11:05:27 -0700349 hotseatBarSizePx += extraSpace;
350 hotseatBarBottomPaddingPx += extraSpace;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700351
Jon Miranda3f9bab22017-07-28 14:50:17 -0700352 // Recalculate the available dimensions using the new hotseat size.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700353 updateAvailableDimensions(res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700354 }
Sunny Goyal07b69292018-01-08 14:19:34 -0800355 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800356
357 // This is done last, after iconSizePx is calculated above.
Samuel Fufac96fa242019-09-26 23:06:32 -0700358 mDotRendererWorkSpace = new DotRenderer(iconSizePx, IconShape.getShapePath(),
Tony Wickhame1cb93f2019-05-03 11:27:32 -0700359 IconShape.DEFAULT_PATH_SIZE);
Samuel Fufac96fa242019-09-26 23:06:32 -0700360 mDotRendererAllApps = iconSizePx == allAppsIconSizePx ? mDotRendererWorkSpace :
361 new DotRenderer(allAppsIconSizePx, IconShape.getShapePath(),
362 IconShape.DEFAULT_PATH_SIZE);
Adam Cohen63f1ec02014-08-12 09:23:13 -0700363 }
364
Jon Mirandae126d722021-02-25 10:45:20 -0500365 private void setCellLayoutBorderSpacing(int borderSpacing) {
Jon Miranda823da222021-03-23 08:08:45 -0400366 cellLayoutBorderSpacingPx = isScalableGrid ? borderSpacing : 0;
Jon Mirandae126d722021-02-25 10:45:20 -0500367 }
368
Jon Miranda611dba42021-03-02 14:12:13 -0500369 /**
370 * We inset the widget padding added by the system and instead rely on the border spacing
371 * between cells to create reliable consistency between widgets
372 */
373 public boolean shouldInsetWidgets() {
374 Rect widgetPadding = inv.defaultWidgetPadding;
375
376 // Check all sides to ensure that the widget won't overlap into another cell.
377 return cellLayoutBorderSpacingPx > widgetPadding.left
378 && cellLayoutBorderSpacingPx > widgetPadding.top
379 && cellLayoutBorderSpacingPx > widgetPadding.right
380 && cellLayoutBorderSpacingPx > widgetPadding.bottom;
381 }
Jon Mirandae126d722021-02-25 10:45:20 -0500382
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700383 public Builder toBuilder(Context context) {
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800384 Point size = new Point(availableWidthPx, availableHeightPx);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700385 return new Builder(context, inv, mInfo)
386 .setSizeRange(size, size)
387 .setSize(widthPx, heightPx)
Sunny Goyal0addbf02020-04-28 14:17:35 -0700388 .setWindowPosition(windowX, windowY)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700389 .setMultiWindowMode(isMultiWindowMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800390 }
391
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700392 public DeviceProfile copy(Context context) {
393 return toBuilder(context).build();
394 }
395
396 /**
397 * TODO: Move this to the builder as part of setMultiWindowMode
398 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700399 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Jon Mirandaa11380d2017-08-24 11:30:03 -0700400 // We take the minimum sizes of this profile and it's multi-window variant to ensure that
401 // the system decor is always excluded.
Sunny Goyalb46703d2020-05-27 17:52:03 -0700402 Point mwSize = new Point(Math.min(availableWidthPx, windowBounds.availableSize.x),
403 Math.min(availableHeightPx, windowBounds.availableSize.y));
Jon Mirandaa11380d2017-08-24 11:30:03 -0700404
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700405 DeviceProfile profile = toBuilder(context)
406 .setSizeRange(mwSize, mwSize)
Sunny Goyalb46703d2020-05-27 17:52:03 -0700407 .setSize(windowBounds.bounds.width(), windowBounds.bounds.height())
408 .setWindowPosition(windowBounds.bounds.left, windowBounds.bounds.top)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700409 .setMultiWindowMode(true)
410 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800411
Jon Miranda941375e2021-03-31 13:10:45 -0400412 profile.hideWorkspaceLabelsIfNotEnoughSpace();
Jon Miranda93e1f042016-11-11 14:13:04 -0800413
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800414 // We use these scales to measure and layout the widgets using their full invariant profile
415 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
416 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
417 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
418 profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY);
Sunny Goyal07b69292018-01-08 14:19:34 -0800419 profile.updateWorkspacePadding();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800420
Jon Miranda93e1f042016-11-11 14:13:04 -0800421 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700422 }
423
Adam Cohen63f1ec02014-08-12 09:23:13 -0700424 /**
Sunny Goyalb46703d2020-05-27 17:52:03 -0700425 * Inverse of {@link #getMultiWindowProfile(Context, WindowBounds)}
Sunny Goyal2e2e2b42018-02-27 16:52:55 -0800426 * @return device profile corresponding to the current orientation in non multi-window mode.
427 */
428 public DeviceProfile getFullScreenProfile() {
429 return isLandscape ? inv.landscapeProfile : inv.portraitProfile;
430 }
431
432 /**
Jon Miranda941375e2021-03-31 13:10:45 -0400433 * Checks if there is enough space for labels on the workspace.
434 * If there is not, labels on the Workspace are hidden.
Jon Miranda1091e532017-07-21 13:31:50 -0700435 * It is important to call this method after the All Apps variables have been set.
436 */
Jon Miranda941375e2021-03-31 13:10:45 -0400437 private void hideWorkspaceLabelsIfNotEnoughSpace() {
438 float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx);
439 float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx
440 - iconTextHeight;
441
442 // We want enough space so that the text is closer to its corresponding icon.
443 if (workspaceCellPaddingY < iconTextHeight) {
444 iconTextSizePx = 0;
445 iconDrawablePaddingPx = 0;
446 cellHeightPx = iconSizePx;
447 autoResizeAllAppsCells();
448 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700449 }
Jon Miranda1091e532017-07-21 13:31:50 -0700450
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700451 /**
452 * Re-computes the all-apps cell size to be independent of workspace
453 */
454 public void autoResizeAllAppsCells() {
Jon Miranda941375e2021-03-31 13:10:45 -0400455 int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx);
456 int topBottomPadding = textHeight;
Jon Miranda1091e532017-07-21 13:31:50 -0700457 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
Jon Miranda941375e2021-03-31 13:10:45 -0400458 + textHeight + (topBottomPadding * 2);
Jon Miranda1091e532017-07-21 13:31:50 -0700459 }
460
Jon Miranda228877d2021-02-09 11:05:00 -0500461 /**
462 * Returns the amount of extra (or unused) vertical space.
463 */
464 private int updateAvailableDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700465 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800466
Jon Mirandae126d722021-02-25 10:45:20 -0500467 Point workspacePadding = getTotalWorkspacePadding();
468
469 // Check to see if the icons fit within the available height.
470 float usedHeight = getCellLayoutHeight();
471 final int maxHeight = availableHeightPx - workspacePadding.y;
Jon Miranda228877d2021-02-09 11:05:00 -0500472 float extraHeight = Math.max(0, maxHeight - usedHeight);
Jon Mirandae126d722021-02-25 10:45:20 -0500473 float scaleY = maxHeight / usedHeight;
474 boolean shouldScale = scaleY < 1f;
475
476 float scaleX = 1f;
477 if (isScalableGrid) {
478 // We scale to fit the cellWidth and cellHeight in the available space.
479 // The benefit of scalable grids is that we can get consistent aspect ratios between
480 // devices.
481 float usedWidth = (cellWidthPx * inv.numColumns)
482 + (cellLayoutBorderSpacingPx * (inv.numColumns - 1))
483 + (desiredWorkspaceLeftRightMarginPx * 2);
484 // We do not subtract padding here, as we also scale the workspace padding if needed.
485 scaleX = availableWidthPx / usedWidth;
486 shouldScale = true;
Winson Chungb3800242013-10-24 11:01:54 -0700487 }
Jon Mirandae126d722021-02-25 10:45:20 -0500488
489 if (shouldScale) {
490 float scale = Math.min(scaleX, scaleY);
491 updateIconSize(scale, res);
492 extraHeight = Math.max(0, maxHeight - getCellLayoutHeight());
493 }
494
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700495 updateAvailableFolderCellDimensions(res);
Jon Miranda228877d2021-02-09 11:05:00 -0500496 return Math.round(extraHeight);
Winson Chungb3800242013-10-24 11:01:54 -0700497 }
498
Jon Mirandae126d722021-02-25 10:45:20 -0500499 private int getCellLayoutHeight() {
500 return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacingPx * (inv.numRows - 1));
501 }
502
Jon Miranda6f7e9702019-09-16 14:44:14 -0700503 /**
504 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
505 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
506 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
507 */
Tony Wickham7ba547c2021-02-02 17:12:08 -0800508 public void updateIconSize(float scale, Resources res) {
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400509 iconScale = scale;
510
Jon Miranda18751b62017-07-31 17:25:27 -0700511 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800512 final boolean isVerticalLayout = isVerticalBarLayout();
Andras Kloczl6057cb92021-04-07 13:45:17 +0200513 float invIconSizeDp = isLandscape ? inv.landscapeIconSize : inv.iconSize;
Jon Mirandae126d722021-02-25 10:45:20 -0500514 iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mInfo.metrics, scale));
Andras Kloczl6057cb92021-04-07 13:45:17 +0200515 float invIconTextSizeSp = isLandscape ? inv.landscapeIconTextSize : inv.iconTextSize;
516 iconTextSizePx = (int) (Utilities.pxFromSp(invIconTextSizeSp, mInfo.metrics) * scale);
Jon Miranda09660722017-06-14 14:20:14 -0700517 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * scale);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700518
Jon Mirandae126d722021-02-25 10:45:20 -0500519 setCellLayoutBorderSpacing((int) (cellLayoutBorderSpacingOriginalPx * scale));
520
521 if (isScalableGrid) {
522 cellWidthPx = pxFromDp(inv.minCellWidth, mInfo.metrics, scale);
523 cellHeightPx = pxFromDp(inv.minCellHeight, mInfo.metrics, scale);
524 int cellContentHeight = iconSizePx + iconDrawablePaddingPx
525 + Utilities.calculateTextHeight(iconTextSizePx);
526 cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2;
527 desiredWorkspaceLeftRightMarginPx = (int) (desiredWorkspaceLeftRightOriginalPx * scale);
Jon Miranda228877d2021-02-09 11:05:00 -0500528 } else {
Jon Mirandae126d722021-02-25 10:45:20 -0500529 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda228877d2021-02-09 11:05:00 -0500530 cellHeightPx = iconSizePx + iconDrawablePaddingPx
531 + Utilities.calculateTextHeight(iconTextSizePx);
532 int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
533 if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
534 && !isMultiWindowMode) {
535 // Ensures that the label is closer to its corresponding icon. This is not an issue
536 // with vertical bar layout or multi-window mode since the issue is handled
537 // separately with their calls to {@link #adjustToHideWorkspaceLabels}.
538 cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY);
539 iconDrawablePaddingPx = cellPaddingY;
540 }
Jon Miranda846455e2017-10-02 14:58:52 -0700541 }
Jon Miranda18751b62017-07-31 17:25:27 -0700542
Sunny Goyalae190ff2020-04-14 00:19:01 +0000543 // All apps
544 if (allAppsHasDifferentNumColumns()) {
Jon Mirandae126d722021-02-25 10:45:20 -0500545 allAppsIconSizePx = pxFromDp(inv.allAppsIconSize, mInfo.metrics);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700546 allAppsIconTextSizePx = Utilities.pxFromSp(inv.allAppsIconTextSize, mInfo.metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000547 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Jon Miranda941375e2021-03-31 13:10:45 -0400548 autoResizeAllAppsCells();
Sunny Goyalae190ff2020-04-14 00:19:01 +0000549 } else {
550 allAppsIconSizePx = iconSizePx;
551 allAppsIconTextSizePx = iconTextSizePx;
552 allAppsIconDrawablePaddingPx = iconDrawablePaddingPx;
553 allAppsCellHeightPx = getCellSize().y;
554 }
555 allAppsCellWidthPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700556
Jon Miranda941375e2021-03-31 13:10:45 -0400557 if (isVerticalLayout) {
558 hideWorkspaceLabelsIfNotEnoughSpace();
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700559 }
Winson Chungb3800242013-10-24 11:01:54 -0700560
Winson Chungb3800242013-10-24 11:01:54 -0700561 // Hotseat
Sunny Goyal07b69292018-01-08 14:19:34 -0800562 if (isVerticalLayout) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700563 hotseatBarSizePx = iconSizePx + hotseatBarSidePaddingStartPx
564 + hotseatBarSidePaddingEndPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700565 }
Jon Miranda5044c352017-08-09 11:37:59 -0700566 hotseatCellHeightPx = iconSizePx;
Winson Chungb3800242013-10-24 11:01:54 -0700567
Sunny Goyal07b69292018-01-08 14:19:34 -0800568 if (!isVerticalLayout) {
Jon Miranda18751b62017-07-31 17:25:27 -0700569 int expectedWorkspaceHeight = availableHeightPx - hotseatBarSizePx
Tony Wickham5edf9e22020-03-27 20:06:52 -0700570 - workspacePageIndicatorHeight - edgeMarginPx;
Sunny Goyal47328fd2016-05-25 18:56:41 -0700571 float minRequiredHeight = dropTargetBarSizePx + workspaceSpringLoadedBottomSpace;
572 workspaceSpringLoadShrinkFactor = Math.min(
573 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f,
574 1 - (minRequiredHeight / expectedWorkspaceHeight));
575 } else {
576 workspaceSpringLoadShrinkFactor =
577 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
578 }
579
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700580 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -0700581 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
582 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Winson Chung0f785722015-04-08 10:27:49 -0700583 }
584
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700585 private void updateAvailableFolderCellDimensions(Resources res) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700586 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700587
Jon Mirandae126d722021-02-25 10:45:20 -0500588 final int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_height);
589
Jon Mirandac1b23992016-12-13 08:57:36 -0800590 // Don't let the folder get too close to the edges of the screen.
Jon Miranda1786df32018-09-25 13:05:23 -0700591 int folderMargin = edgeMarginPx * 2;
Sunny Goyal07b69292018-01-08 14:19:34 -0800592 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -0800593
594 // Check if the icons fit within the available height.
Jon Miranda228877d2021-02-09 11:05:00 -0500595 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
Jon Miranda823da222021-03-23 08:08:45 -0400596 + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacingPx);
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800597 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderBottomPanelSize
Jon Mirandae126d722021-02-25 10:45:20 -0500598 - folderMargin - folderContentPaddingTop;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800599 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -0800600
601 // Check if the icons fit within the available width.
Jon Miranda228877d2021-02-09 11:05:00 -0500602 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
Jon Miranda823da222021-03-23 08:08:45 -0400603 + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacingPx);
Jon Mirandae126d722021-02-25 10:45:20 -0500604 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin
605 - folderContentPaddingLeftRight * 2;
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800606 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -0800607
608 float scale = Math.min(scaleX, scaleY);
609 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700610 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700611 }
612 }
613
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700614 private void updateFolderCellSize(float scale, Resources res) {
Jon Mirandae126d722021-02-25 10:45:20 -0500615 float invIconSizeDp = isVerticalBarLayout() ? inv.landscapeIconSize : inv.iconSize;
616 folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mInfo.metrics, scale));
617 folderChildTextSizePx = pxFromDp(inv.iconTextSize, mInfo.metrics, scale);
618 folderLabelTextSizePx = (int) (folderChildTextSizePx * folderLabelTextScale);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700619
620 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700621
Jon Miranda823da222021-03-23 08:08:45 -0400622 if (isScalableGrid) {
623 folderCellWidthPx = (int) (cellWidthPx * scale);
624 folderCellHeightPx = (int) (cellHeightPx * scale);
625
626 int borderSpacing = (int) (cellLayoutBorderSpacingOriginalPx * scale);
627 folderCellLayoutBorderSpacingPx = borderSpacing;
628 folderContentPaddingLeftRight = borderSpacing;
629 folderContentPaddingTop = borderSpacing;
630 } else {
631 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
632 * scale);
633 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding)
634 * scale);
635
636 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
637 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
638 }
639
Jonathan Miranda9ad87462017-07-26 17:41:02 +0000640 folderChildDrawablePaddingPx = Math.max(0,
641 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700642 }
643
Winson1f064272016-07-18 17:18:02 -0700644 public void updateInsets(Rect insets) {
645 mInsets.set(insets);
Sunny Goyal07b69292018-01-08 14:19:34 -0800646 updateWorkspacePadding();
Winson1f064272016-07-18 17:18:02 -0700647 }
648
Sunny Goyalae6e3182019-04-30 12:04:37 -0700649 /**
650 * The current device insets. This is generally same as the insets being dispatched to
651 * {@link Insettable} elements, but can differ if the element is using a different profile.
652 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800653 public Rect getInsets() {
654 return mInsets;
655 }
656
Sunny Goyal756cd262015-08-20 12:33:21 -0700657 public Point getCellSize() {
Jon Miranda6f7e9702019-09-16 14:44:14 -0700658 return getCellSize(inv.numColumns, inv.numRows);
659 }
660
661 private Point getCellSize(int numColumns, int numRows) {
Sunny Goyal756cd262015-08-20 12:33:21 -0700662 Point result = new Point();
663 // Since we are only concerned with the overall padding, layout direction does
664 // not matter.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700665 Point padding = getTotalWorkspacePadding();
Jon Miranda18751b62017-07-31 17:25:27 -0700666 result.x = calculateCellWidth(availableWidthPx - padding.x
Jon Miranda228877d2021-02-09 11:05:00 -0500667 - cellLayoutPaddingLeftRightPx * 2, cellLayoutBorderSpacingPx, numColumns);
Jon Miranda18751b62017-07-31 17:25:27 -0700668 result.y = calculateCellHeight(availableHeightPx - padding.y
Jon Miranda228877d2021-02-09 11:05:00 -0500669 - cellLayoutBottomPaddingPx, cellLayoutBorderSpacingPx, numRows);
Sunny Goyal756cd262015-08-20 12:33:21 -0700670 return result;
671 }
672
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700673 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -0800674 updateWorkspacePadding();
675 return new Point(workspacePadding.left + workspacePadding.right,
676 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700677 }
678
679 /**
Sunny Goyal07b69292018-01-08 14:19:34 -0800680 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
681 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700682 */
Sunny Goyal07b69292018-01-08 14:19:34 -0800683 private void updateWorkspacePadding() {
684 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -0700685 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -0800686 padding.top = 0;
687 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800688 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700689 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -0700690 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -0700691 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -0700692 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700693 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -0700694 }
Winson Chungb3800242013-10-24 11:01:54 -0700695 } else {
Tony Wickhama29a0462021-03-02 12:28:25 -0800696 int hotseatTop = isTaskbarPresent ? taskbarSize : hotseatBarSizePx;
697 int paddingBottom = hotseatTop + workspacePageIndicatorHeight
Jon Miranda228877d2021-02-09 11:05:00 -0500698 + workspaceBottomPadding - mWorkspacePageIndicatorOverlapWorkspace;
Sunny Goyalc6205602015-05-21 20:46:33 -0700699 if (isTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700700 // Pad the left and right of the workspace to ensure consistent spacing
701 // between all icons
Tony Wickhamd6b40372015-09-23 18:37:57 -0700702 // The amount of screen space available for left/right padding.
Sunny Goyal228153d2018-01-04 15:35:22 -0800703 int availablePaddingX = Math.max(0, widthPx - ((inv.numColumns * cellWidthPx) +
Sunny Goyalf5440cb2016-12-14 15:13:00 -0800704 ((inv.numColumns - 1) * cellWidthPx)));
Tony Wickhamd6b40372015-09-23 18:37:57 -0700705 availablePaddingX = (int) Math.min(availablePaddingX,
Sunny Goyal07b69292018-01-08 14:19:34 -0800706 widthPx * MAX_HORIZONTAL_PADDING_PERCENT);
Tony Wickhama29a0462021-03-02 12:28:25 -0800707 int hotseatVerticalPadding = isTaskbarPresent ? 0
708 : hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700709 int availablePaddingY = Math.max(0, heightPx - edgeMarginPx - paddingBottom
Tony Wickhama29a0462021-03-02 12:28:25 -0800710 - (2 * inv.numRows * cellHeightPx) - hotseatVerticalPadding);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700711 padding.set(availablePaddingX / 2, edgeMarginPx + availablePaddingY / 2,
Tony Wickhamd6b40372015-09-23 18:37:57 -0700712 availablePaddingX / 2, paddingBottom + availablePaddingY / 2);
Andras Kloczl8e57cce2021-02-11 23:51:19 +0100713
714 if (FeatureFlags.ENABLE_TWO_PANEL_HOME.get()) {
715 padding.set(0, padding.top, 0, padding.bottom);
716 }
Winson Chungb3800242013-10-24 11:01:54 -0700717 } else {
718 // Pad the top and bottom of the workspace with search/hotseat bar sizes
Winson1f064272016-07-18 17:18:02 -0700719 padding.set(desiredWorkspaceLeftRightMarginPx,
Jon Mirandae126d722021-02-25 10:45:20 -0500720 workspaceTopPadding + (isScalableGrid ? 0 : edgeMarginPx),
Winson1f064272016-07-18 17:18:02 -0700721 desiredWorkspaceLeftRightMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700722 paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -0700723 }
724 }
Winson Chungb3800242013-10-24 11:01:54 -0700725 }
726
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700727 public Rect getHotseatLayoutPadding() {
728 if (isVerticalBarLayout()) {
729 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700730 mHotseatPadding.set(mInsets.left + hotseatBarSidePaddingStartPx,
731 mInsets.top, hotseatBarSidePaddingEndPx, mInsets.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700732 } else {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700733 mHotseatPadding.set(hotseatBarSidePaddingEndPx, mInsets.top,
734 mInsets.right + hotseatBarSidePaddingStartPx, mInsets.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700735 }
736 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700737 // We want the edges of the hotseat to line up with the edges of the workspace, but the
738 // icons in the hotseat are a different size, and so don't line up perfectly. To account
739 // for this, we pad the left and right of the hotseat with half of the difference of a
740 // workspace cell vs a hotseat cell.
741 float workspaceCellWidth = (float) widthPx / inv.numColumns;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700742 float hotseatCellWidth = (float) widthPx / inv.numShownHotseatIcons;
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700743 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
744 mHotseatPadding.set(
Sunny Goyal786940a2020-06-02 02:31:31 -0700745 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingLeftRightPx
746 + mInsets.left,
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700747 hotseatBarTopPaddingPx,
Sunny Goyal786940a2020-06-02 02:31:31 -0700748 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx
749 + mInsets.right,
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700750 hotseatBarBottomPaddingPx + mInsets.bottom + cellLayoutBottomPaddingPx);
751 }
752 return mHotseatPadding;
753 }
754
Winsonfadbe8f2016-07-22 16:35:37 -0700755 /**
756 * @return the bounds for which the open folders should be contained within
757 */
758 public Rect getAbsoluteOpenFolderBounds() {
759 if (isVerticalBarLayout()) {
760 // Folders should only appear right of the drop target bar and left of the hotseat
761 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
762 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -0700763 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700764 mInsets.top + availableHeightPx);
765 } else {
766 // Folders should only appear below the drop target bar and above the hotseat
Tony Wickhamae72b462021-03-10 16:18:40 -0800767 int hotseatTop = isTaskbarPresent ? taskbarSize : hotseatBarSizePx;
Tony Wickhamb4b7e202018-01-12 17:39:24 -0800768 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700769 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -0800770 mInsets.left + availableWidthPx - edgeMarginPx,
Tony Wickhamae72b462021-03-10 16:18:40 -0800771 mInsets.top + availableHeightPx - hotseatTop
Tony Wickham5edf9e22020-03-27 20:06:52 -0700772 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -0700773 }
774 }
775
Jon Miranda228877d2021-02-09 11:05:00 -0500776 public static int calculateCellWidth(int width, int borderSpacing, int countX) {
777 return (width - ((countX - 1) * borderSpacing)) / countX;
Winson Chungb3800242013-10-24 11:01:54 -0700778 }
Jon Miranda228877d2021-02-09 11:05:00 -0500779 public static int calculateCellHeight(int height, int borderSpacing, int countY) {
780 return (height - ((countY - 1) * borderSpacing)) / countY;
Winson Chungb3800242013-10-24 11:01:54 -0700781 }
782
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700783 /**
Tony Wickham55616cd2015-09-23 14:55:17 -0700784 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
785 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
786 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700787 */
Tony Wickhamab946a12015-09-16 15:38:16 -0700788 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -0700789 return isLandscape && transposeLayoutWithOrientation;
790 }
791
Sunny Goyal59d086c2018-05-07 17:31:40 -0700792 /**
Jon Miranda6f7e9702019-09-16 14:44:14 -0700793 * Returns true when the number of workspace columns and all apps columns differs.
794 */
795 private boolean allAppsHasDifferentNumColumns() {
796 return inv.numAllAppsColumns != inv.numColumns;
797 }
798
799 /**
Sunny Goyal59d086c2018-05-07 17:31:40 -0700800 * Updates orientation information and returns true if it has changed from the previous value.
801 */
Winson Chung13c1c2c2019-09-06 11:46:19 -0700802 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -0700803 if (isVerticalBarLayout()) {
Schneider Victor-tulias954bb632021-01-27 14:03:51 -0800804 // Check an up-to-date info.
Alex Chaud25e87a2021-02-12 12:12:56 +0000805 DisplayController.Info displayInfo = DisplayController.getDefaultDisplay(context)
806 .createInfoForContext(context);
807 if (displayInfo == null) {
808 return false;
809 }
810
811 boolean isSeascape = displayInfo.rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -0700812 if (mIsSeascape != isSeascape) {
813 mIsSeascape = isSeascape;
814 return true;
815 }
816 }
817 return false;
818 }
819
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800820 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -0700821 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800822 }
823
Sunny Goyal07b69292018-01-08 14:19:34 -0800824 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyalc6205602015-05-21 20:46:33 -0700825 return isVerticalBarLayout() || isLargeTablet;
Winson Chungb3800242013-10-24 11:01:54 -0700826 }
827
Sunny Goyalc13403c2016-11-18 23:44:48 -0800828 public int getCellHeight(@ContainerType int containerType) {
829 switch (containerType) {
830 case CellLayout.WORKSPACE:
831 return cellHeightPx;
832 case CellLayout.FOLDER:
833 return folderCellHeightPx;
834 case CellLayout.HOTSEAT:
835 return hotseatCellHeightPx;
836 default:
837 // ??
838 return 0;
839 }
840 }
Sunny Goyal13178ac2016-04-04 16:35:22 -0700841
Jon Miranda58561d42021-03-17 10:51:54 -0400842 private String pxToDpStr(String name, float value) {
843 return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mInfo.metrics) + "dp)";
844 }
845
846 public void dump(String prefix, PrintWriter writer) {
847 writer.println(prefix + "DeviceProfile:");
848 writer.println(prefix + "\t1 dp = " + mInfo.metrics.density + " px");
849
850 writer.println(prefix + "\tisTablet:" + isTablet);
851 writer.println(prefix + "\tisLargeTablet:" + isLargeTablet);
852 writer.println(prefix + "\tisPhone:" + isPhone);
853 writer.println(prefix + "\ttransposeLayoutWithOrientation:"
854 + transposeLayoutWithOrientation);
855
856 writer.println(prefix + "\tisLandscape:" + isLandscape);
857 writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
858
859 writer.println(prefix + pxToDpStr("windowX", windowX));
860 writer.println(prefix + pxToDpStr("windowY", windowY));
861 writer.println(prefix + pxToDpStr("widthPx", widthPx));
862 writer.println(prefix + pxToDpStr("heightPx", heightPx));
863
864 writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
865 writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
866
867 writer.println(prefix + "\taspectRatio:" + aspectRatio);
868
869 writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
870
871 writer.println(prefix + "\tinv.minCellWidth:" + inv.minCellWidth + "dp");
872 writer.println(prefix + "\tinv.minCellHeight:" + inv.minCellHeight + "dp");
873
874 writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx));
875 writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx));
876
877 writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x));
878 writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y));
879
880 writer.println(prefix + "\tinv.iconSize:" + inv.iconSize + "dp");
881 writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx));
882 writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx));
883 writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx));
884
885 writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx));
886 writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx));
887 writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx));
888 writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx));
889 writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx",
890 folderChildDrawablePaddingPx));
Jon Miranda823da222021-03-23 08:08:45 -0400891 writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacingPx",
892 folderCellLayoutBorderSpacingPx));
Jon Miranda58561d42021-03-17 10:51:54 -0400893
894 writer.println(prefix + pxToDpStr("cellLayoutBorderSpacingPx",
895 cellLayoutBorderSpacingPx));
896 writer.println(prefix + pxToDpStr("desiredWorkspaceLeftRightMarginPx",
897 desiredWorkspaceLeftRightMarginPx));
898
899 writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx));
900 writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx));
901 writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx",
902 allAppsIconDrawablePaddingPx));
903 writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx));
904
905 writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx));
906 writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx));
907 writer.println(prefix + pxToDpStr("hotseatBarTopPaddingPx", hotseatBarTopPaddingPx));
908 writer.println(prefix + pxToDpStr("hotseatBarBottomPaddingPx", hotseatBarBottomPaddingPx));
909 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx",
910 hotseatBarSidePaddingStartPx));
911 writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx",
912 hotseatBarSidePaddingEndPx));
913
914 writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent);
915
916 writer.println(prefix + pxToDpStr("taskbarSize", taskbarSize));
917 writer.println(prefix + pxToDpStr("nonOverlappingTaskbarInset",
918 nonOverlappingTaskbarInset));
919
920 writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left));
921 writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top));
922 writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right));
923 writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom));
924
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400925 writer.println(prefix + pxToDpStr("scaleToFit", iconScale));
Jon Miranda58561d42021-03-17 10:51:54 -0400926 writer.println(prefix + pxToDpStr("extraSpace", extraSpace));
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400927
928 if (inv.devicePaddings != null) {
929 int unscaledExtraSpace = (int) (extraSpace / iconScale);
930 writer.println(prefix + pxToDpStr("maxEmptySpace",
931 inv.devicePaddings.getDevicePadding(unscaledExtraSpace).getMaxEmptySpacePx()));
932 }
Jon Miranda58561d42021-03-17 10:51:54 -0400933 writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding));
934 writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding));
935 writer.println(prefix + pxToDpStr("extraHotseatBottomPadding", extraHotseatBottomPadding));
936 }
937
Sunny Goyalfd58da62020-08-11 12:06:49 -0700938 private static Context getContext(Context c, Info info, int orientation) {
Sunny Goyal1890f672020-04-30 12:28:00 -0700939 Configuration config = new Configuration(c.getResources().getConfiguration());
940 config.orientation = orientation;
941 config.densityDpi = info.metrics.densityDpi;
942 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700943 }
Sunny Goyalfde55052018-02-01 14:46:13 -0800944
945 /**
946 * Callback when a component changes the DeviceProfile associated with it, as a result of
947 * configuration change
948 */
949 public interface OnDeviceProfileChangeListener {
950
951 /**
952 * Called when the device profile is reassigned. Note that for layout and measurements, it
953 * is sufficient to listen for inset changes. Use this callback when you need to perform
954 * a one time operation.
955 */
956 void onDeviceProfileChanged(DeviceProfile dp);
957 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700958
959 public static class Builder {
960 private Context mContext;
961 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -0700962 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700963
Sunny Goyal0addbf02020-04-28 14:17:35 -0700964 private final Point mWindowPosition = new Point();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700965 private Point mMinSize, mMaxSize;
966 private int mWidth, mHeight;
967
968 private boolean mIsLandscape;
969 private boolean mIsMultiWindowMode = false;
970 private boolean mTransposeLayoutWithOrientation;
971
Sunny Goyalfd58da62020-08-11 12:06:49 -0700972 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700973 mContext = context;
974 mInv = inv;
975 mInfo = info;
976 mTransposeLayoutWithOrientation = context.getResources()
977 .getBoolean(R.bool.hotseat_transpose_layout_with_orientation);
Winson Chung8e64bba2021-04-20 13:26:26 -0700978 if (TestProtocol.sDebugTracing) {
979 Log.d(TestProtocol.LAUNCHER_NOT_TRANSPOSED,
980 "transposeLayout=" + mTransposeLayoutWithOrientation);
981 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700982 }
983
984 public Builder setSizeRange(Point minSize, Point maxSize) {
985 mMinSize = minSize;
986 mMaxSize = maxSize;
987 return this;
988 }
989
990 public Builder setSize(int width, int height) {
991 mWidth = width;
992 mHeight = height;
993 mIsLandscape = mWidth > mHeight;
Winson Chung8e64bba2021-04-20 13:26:26 -0700994 if (TestProtocol.sDebugTracing) {
995 Log.d(TestProtocol.LAUNCHER_NOT_TRANSPOSED,
996 "isLandscape=" + mIsLandscape + " w=" + mWidth + " h=" + mHeight);
997 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700998 return this;
999 }
1000
1001 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
1002 mIsMultiWindowMode = isMultiWindowMode;
1003 return this;
1004 }
1005
Sunny Goyal0addbf02020-04-28 14:17:35 -07001006 /**
1007 * Sets the window position if not full-screen
1008 */
1009 public Builder setWindowPosition(int x, int y) {
1010 mWindowPosition.set(x, y);
1011 return this;
1012 }
1013
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001014 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
1015 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
1016 return this;
1017 }
1018
1019 public DeviceProfile build() {
1020 return new DeviceProfile(mContext, mInv, mInfo, mMinSize, mMaxSize,
1021 mWidth, mHeight, mIsLandscape, mIsMultiWindowMode,
Sunny Goyal0addbf02020-04-28 14:17:35 -07001022 mTransposeLayoutWithOrientation, mWindowPosition);
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001023 }
1024 }
1025
Winson Chungb3800242013-10-24 11:01:54 -07001026}