blob: 51b21aa795cf075636b9695e0ac0ccf15798afce [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
Winson Chungb3800242013-10-24 11:01:54 -070019import android.content.Context;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070020import android.content.res.Configuration;
Winson Chungb3800242013-10-24 11:01:54 -070021import android.content.res.Resources;
Winson Chungb3800242013-10-24 11:01:54 -070022import android.graphics.Point;
Jon Miranda7ae64ff2016-11-21 16:18:46 -080023import android.graphics.PointF;
Winson Chungb3800242013-10-24 11:01:54 -070024import android.graphics.Rect;
Sunny Goyal59d086c2018-05-07 17:31:40 -070025import android.view.Surface;
Winson Chungb3800242013-10-24 11:01:54 -070026
Sunny Goyalc13403c2016-11-18 23:44:48 -080027import com.android.launcher3.CellLayout.ContainerType;
Tony Wickhame1cb93f2019-05-03 11:27:32 -070028import com.android.launcher3.graphics.IconShape;
Tony Wickham8912b042018-11-29 15:28:53 -080029import com.android.launcher3.icons.DotRenderer;
Hyunyoung Song48cb7bc2018-09-25 17:03:34 -070030import com.android.launcher3.icons.IconNormalizer;
Winson Chung13c1c2c2019-09-06 11:46:19 -070031import com.android.launcher3.util.DefaultDisplay;
Winson1f064272016-07-18 17:18:02 -070032
Winson Chungb3800242013-10-24 11:01:54 -070033public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070034
Sunny Goyal1890f672020-04-30 12:28:00 -070035 private static final float TABLET_MIN_DPS = 600;
36 private static final float LARGE_TABLET_MIN_DPS = 720;
37
38
Adam Cohen2e6da152015-05-06 11:42:25 -070039 public final InvariantDeviceProfile inv;
Sunny Goyal0e7a3382020-04-13 17:15:05 -070040 private final DefaultDisplay.Info mInfo;
Winson Chungbe876472014-05-14 14:15:20 -070041
Sunny Goyalc6205602015-05-21 20:46:33 -070042 // Device properties
43 public final boolean isTablet;
44 public final boolean isLargeTablet;
45 public final boolean isPhone;
46 public final boolean transposeLayoutWithOrientation;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -070047
Sunny Goyalc6205602015-05-21 20:46:33 -070048 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -070049 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -080050 public final boolean isMultiWindowMode;
51
Sunny Goyal0addbf02020-04-28 14:17:35 -070052 public final int windowX;
53 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -070054 public final int widthPx;
55 public final int heightPx;
56 public final int availableWidthPx;
57 public final int availableHeightPx;
Jon Mirandabba64512019-03-27 10:54:17 -070058
59 public final float aspectRatio;
60
Tony Wickhamd6b40372015-09-23 18:37:57 -070061 /**
62 * The maximum amount of left/right workspace padding as a percentage of the screen width.
63 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
64 * 7% of the screen width can be used as right padding.
65 */
66 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -070067
Jon Miranda3f9bab22017-07-28 14:50:17 -070068 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda30d0aa22017-07-25 15:55:29 -070069
Jon Miranda5eacbb72018-07-31 11:14:46 -070070 // To evenly space the icons, increase the left/right margins for tablets in portrait mode.
71 private static final int PORTRAIT_TABLET_LEFT_RIGHT_PADDING_MULTIPLIER = 4;
72
Sunny Goyalc6205602015-05-21 20:46:33 -070073 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -080074 public final int desiredWorkspaceLeftRightMarginPx;
Jon Miranda28032002017-07-13 16:18:56 -070075 public final int cellLayoutPaddingLeftRightPx;
Jon Miranda18751b62017-07-31 17:25:27 -070076 public final int cellLayoutBottomPaddingPx;
Sunny Goyalc6205602015-05-21 20:46:33 -070077 public final int edgeMarginPx;
Sunny Goyal47328fd2016-05-25 18:56:41 -070078 public float workspaceSpringLoadShrinkFactor;
79 public final int workspaceSpringLoadedBottomSpace;
Sunny Goyalc6205602015-05-21 20:46:33 -070080
Tony Wickham5edf9e22020-03-27 20:06:52 -070081 // Workspace page indicator
82 public final int workspacePageIndicatorHeight;
83 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -070084
Sunny Goyalc6205602015-05-21 20:46:33 -070085 // Workspace icons
86 public int iconSizePx;
87 public int iconTextSizePx;
88 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -070089 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -070090
Adam Cohen59400422014-03-05 18:07:04 -080091 public int cellWidthPx;
92 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070093 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -080094
Sunny Goyalc6205602015-05-21 20:46:33 -070095 // Folder
Sunny Goyalc6205602015-05-21 20:46:33 -070096 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -070097 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -070098
99 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700100 public int folderCellWidthPx;
101 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700102
103 // Folder child
104 public int folderChildIconSizePx;
105 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700106 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700107
Sunny Goyalc6205602015-05-21 20:46:33 -0700108 // Hotseat
Sunny Goyalc6205602015-05-21 20:46:33 -0700109 public int hotseatCellHeightPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700110 // In portrait: size = height, in landscape: size = width
111 public int hotseatBarSizePx;
Sunny Goyal07b69292018-01-08 14:19:34 -0800112 public final int hotseatBarTopPaddingPx;
Jon Miranda7e183c32018-06-20 11:05:27 -0700113 public int hotseatBarBottomPaddingPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700114 // Start is the side next to the nav bar, end is the side next to the workspace
115 public final int hotseatBarSidePaddingStartPx;
116 public final int hotseatBarSidePaddingEndPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700117
Sunny Goyalc6205602015-05-21 20:46:33 -0700118 // All apps
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700119 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700120 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700121 public int allAppsIconSizePx;
122 public int allAppsIconDrawablePaddingPx;
123 public float allAppsIconTextSizePx;
124
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800125 // Widgets
126 public final PointF appWidgetScale = new PointF(1.0f, 1.0f);
127
Sunny Goyal47328fd2016-05-25 18:56:41 -0700128 // Drop Target
129 public int dropTargetBarSizePx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700130
Winson1f064272016-07-18 17:18:02 -0700131 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800132 private final Rect mInsets = new Rect();
133 public final Rect workspacePadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700134 private final Rect mHotseatPadding = new Rect();
Jon Miranda0bd63d12019-03-06 17:29:29 -0800135 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700136 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700137
Tony Wickhamf34bee82018-12-03 18:11:39 -0800138 // Notification dots
Samuel Fufac96fa242019-09-26 23:06:32 -0700139 public DotRenderer mDotRendererWorkSpace;
140 public DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800141
Sunny Goyal0addbf02020-04-28 14:17:35 -0700142 DeviceProfile(Context context, InvariantDeviceProfile inv, DefaultDisplay.Info info,
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700143 Point minSize, Point maxSize, int width, int height, boolean isLandscape,
Sunny Goyal0addbf02020-04-28 14:17:35 -0700144 boolean isMultiWindowMode, boolean transposeLayoutWithOrientation,
145 Point windowPosition) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700146
Adam Cohen2e6da152015-05-06 11:42:25 -0700147 this.inv = inv;
Sunny Goyalc6205602015-05-21 20:46:33 -0700148 this.isLandscape = isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -0800149 this.isMultiWindowMode = isMultiWindowMode;
Sunny Goyal0addbf02020-04-28 14:17:35 -0700150 windowX = windowPosition.x;
151 windowY = windowPosition.y;
Winson Chungb3800242013-10-24 11:01:54 -0700152
Jon Miranda7e183c32018-06-20 11:05:27 -0700153 // Determine sizes.
154 widthPx = width;
155 heightPx = height;
156 if (isLandscape) {
157 availableWidthPx = maxSize.x;
158 availableHeightPx = minSize.y;
159 } else {
160 availableWidthPx = minSize.x;
161 availableHeightPx = maxSize.y;
162 }
163
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700164 mInfo = info;
Adam Cohen2e6da152015-05-06 11:42:25 -0700165
Sunny Goyalc6205602015-05-21 20:46:33 -0700166 // Constants from resources
Sunny Goyal1890f672020-04-30 12:28:00 -0700167 float swDPs = Utilities.dpiFromPx(
168 Math.min(info.smallestSize.x, info.smallestSize.y), info.metrics);
169 isTablet = swDPs >= TABLET_MIN_DPS;
170 isLargeTablet = swDPs >= LARGE_TABLET_MIN_DPS;
Sunny Goyalc6205602015-05-21 20:46:33 -0700171 isPhone = !isTablet && !isLargeTablet;
Jon Mirandabba64512019-03-27 10:54:17 -0700172 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Jon Miranda7e183c32018-06-20 11:05:27 -0700173 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
Sunny Goyalc6205602015-05-21 20:46:33 -0700174
175 // Some more constants
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700176 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Winson Chungb3800242013-10-24 11:01:54 -0700177
Sunny Goyal1890f672020-04-30 12:28:00 -0700178 context = getContext(context, info, isVerticalBarLayout()
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700179 ? Configuration.ORIENTATION_LANDSCAPE
180 : Configuration.ORIENTATION_PORTRAIT);
Sunny Goyal1890f672020-04-30 12:28:00 -0700181 final Resources res = context.getResources();
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700182
Winson Chungb3800242013-10-24 11:01:54 -0700183 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Jon Miranda28032002017-07-13 16:18:56 -0700184 desiredWorkspaceLeftRightMarginPx = isVerticalBarLayout() ? 0 : edgeMarginPx;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700185
Jon Miranda5eacbb72018-07-31 11:14:46 -0700186 int cellLayoutPaddingLeftRightMultiplier = !isVerticalBarLayout() && isTablet
187 ? PORTRAIT_TABLET_LEFT_RIGHT_PADDING_MULTIPLIER : 1;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700188 int cellLayoutPadding = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_padding);
189 if (isLandscape) {
190 cellLayoutPaddingLeftRightPx = 0;
191 cellLayoutBottomPaddingPx = cellLayoutPadding;
192 } else {
193 cellLayoutPaddingLeftRightPx = cellLayoutPaddingLeftRightMultiplier * cellLayoutPadding;
194 cellLayoutBottomPaddingPx = 0;
195 }
196
Tony Wickham5edf9e22020-03-27 20:06:52 -0700197 workspacePageIndicatorHeight = res.getDimensionPixelSize(
198 R.dimen.workspace_page_indicator_height);
199 mWorkspacePageIndicatorOverlapWorkspace =
200 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700201
Winson Chungb3800242013-10-24 11:01:54 -0700202 iconDrawablePaddingOriginalPx =
203 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700204 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
205 workspaceSpringLoadedBottomSpace =
206 res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space);
Sunny Goyald5190522017-04-24 03:06:54 -0700207
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700208 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700209
Winson1f064272016-07-18 17:18:02 -0700210 hotseatBarTopPaddingPx =
211 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding);
Jon Miranda7e183c32018-06-20 11:05:27 -0700212 hotseatBarBottomPaddingPx = (isTallDevice ? 0
213 : res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_non_tall_padding))
214 + res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_padding);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700215 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800216 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700217 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700218 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700219 hotseatBarSizePx = ResourceUtils.pxFromDp(inv.iconSize, mInfo.metrics)
220 + (isVerticalBarLayout()
Sunny Goyal415f1732018-11-29 10:33:47 -0800221 ? (hotseatBarSidePaddingStartPx + hotseatBarSidePaddingEndPx)
222 : (res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_extra_vertical_size)
223 + hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx));
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700224
Jon Miranda2ed276e2017-06-29 11:36:34 -0700225 // Calculate all of the remaining variables.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700226 updateAvailableDimensions(res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700227
228 // Now that we have all of the variables calculated, we can tune certain sizes.
Jon Miranda30d0aa22017-07-25 15:55:29 -0700229 if (!isVerticalBarLayout() && isPhone && isTallDevice) {
Jon Miranda3f9bab22017-07-28 14:50:17 -0700230 // We increase the hotseat size when there is extra space.
Jon Miranda2ed276e2017-06-29 11:36:34 -0700231 // ie. For a display with a large aspect ratio, we can keep the icons on the workspace
Jon Miranda3f9bab22017-07-28 14:50:17 -0700232 // in portrait mode closer together by adding more height to the hotseat.
Jon Miranda30d0aa22017-07-25 15:55:29 -0700233 // Note: This calculation was created after noticing a pattern in the design spec.
Jon Miranda7e183c32018-06-20 11:05:27 -0700234 int extraSpace = getCellSize().y - iconSizePx - iconDrawablePaddingPx * 2
Tony Wickham5edf9e22020-03-27 20:06:52 -0700235 - workspacePageIndicatorHeight;
Jon Miranda7e183c32018-06-20 11:05:27 -0700236 hotseatBarSizePx += extraSpace;
237 hotseatBarBottomPaddingPx += extraSpace;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700238
Jon Miranda3f9bab22017-07-28 14:50:17 -0700239 // Recalculate the available dimensions using the new hotseat size.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700240 updateAvailableDimensions(res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700241 }
Sunny Goyal07b69292018-01-08 14:19:34 -0800242 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800243
244 // This is done last, after iconSizePx is calculated above.
Samuel Fufac96fa242019-09-26 23:06:32 -0700245 mDotRendererWorkSpace = new DotRenderer(iconSizePx, IconShape.getShapePath(),
Tony Wickhame1cb93f2019-05-03 11:27:32 -0700246 IconShape.DEFAULT_PATH_SIZE);
Samuel Fufac96fa242019-09-26 23:06:32 -0700247 mDotRendererAllApps = iconSizePx == allAppsIconSizePx ? mDotRendererWorkSpace :
248 new DotRenderer(allAppsIconSizePx, IconShape.getShapePath(),
249 IconShape.DEFAULT_PATH_SIZE);
Adam Cohen63f1ec02014-08-12 09:23:13 -0700250 }
251
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700252 public Builder toBuilder(Context context) {
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800253 Point size = new Point(availableWidthPx, availableHeightPx);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700254 return new Builder(context, inv, mInfo)
255 .setSizeRange(size, size)
256 .setSize(widthPx, heightPx)
Sunny Goyal0addbf02020-04-28 14:17:35 -0700257 .setWindowPosition(windowX, windowY)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700258 .setMultiWindowMode(isMultiWindowMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800259 }
260
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700261 public DeviceProfile copy(Context context) {
262 return toBuilder(context).build();
263 }
264
265 /**
266 * TODO: Move this to the builder as part of setMultiWindowMode
267 */
Sunny Goyal0addbf02020-04-28 14:17:35 -0700268 public DeviceProfile getMultiWindowProfile(Context context, Rect windowPosition) {
Jon Mirandaa11380d2017-08-24 11:30:03 -0700269 // We take the minimum sizes of this profile and it's multi-window variant to ensure that
270 // the system decor is always excluded.
Sunny Goyal0addbf02020-04-28 14:17:35 -0700271 Point mwSize = new Point(Math.min(availableWidthPx, windowPosition.width()),
272 Math.min(availableHeightPx, windowPosition.height()));
Jon Mirandaa11380d2017-08-24 11:30:03 -0700273
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700274 // In multi-window mode, we can have widthPx = availableWidthPx
275 // and heightPx = availableHeightPx because Launcher uses the InvariantDeviceProfiles'
276 // widthPx and heightPx values where it's needed.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700277 DeviceProfile profile = toBuilder(context)
278 .setSizeRange(mwSize, mwSize)
279 .setSize(mwSize.x, mwSize.y)
Sunny Goyal0addbf02020-04-28 14:17:35 -0700280 .setWindowPosition(windowPosition.left, windowPosition.top)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700281 .setMultiWindowMode(true)
282 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800283
Jon Miranda0cd04572017-09-19 11:31:42 -0700284 // If there isn't enough vertical cell padding with the labels displayed, hide the labels.
285 float workspaceCellPaddingY = profile.getCellSize().y - profile.iconSizePx
286 - iconDrawablePaddingPx - profile.iconTextSizePx;
287 if (workspaceCellPaddingY < profile.iconDrawablePaddingPx * 2) {
288 profile.adjustToHideWorkspaceLabels();
289 }
Jon Miranda93e1f042016-11-11 14:13:04 -0800290
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800291 // We use these scales to measure and layout the widgets using their full invariant profile
292 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
293 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
294 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
295 profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY);
Sunny Goyal07b69292018-01-08 14:19:34 -0800296 profile.updateWorkspacePadding();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800297
Jon Miranda93e1f042016-11-11 14:13:04 -0800298 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700299 }
300
Adam Cohen63f1ec02014-08-12 09:23:13 -0700301 /**
Sunny Goyal0addbf02020-04-28 14:17:35 -0700302 * Inverse of {@link #getMultiWindowProfile(Context, Rect)}
Sunny Goyal2e2e2b42018-02-27 16:52:55 -0800303 * @return device profile corresponding to the current orientation in non multi-window mode.
304 */
305 public DeviceProfile getFullScreenProfile() {
306 return isLandscape ? inv.landscapeProfile : inv.portraitProfile;
307 }
308
309 /**
Jon Miranda1091e532017-07-21 13:31:50 -0700310 * Adjusts the profile so that the labels on the Workspace are hidden.
311 * It is important to call this method after the All Apps variables have been set.
312 */
313 private void adjustToHideWorkspaceLabels() {
314 iconTextSizePx = 0;
315 iconDrawablePaddingPx = 0;
316 cellHeightPx = iconSizePx;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700317 autoResizeAllAppsCells();
318 }
Jon Miranda1091e532017-07-21 13:31:50 -0700319
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700320 /**
321 * Re-computes the all-apps cell size to be independent of workspace
322 */
323 public void autoResizeAllAppsCells() {
Jon Miranda3f9bab22017-07-28 14:50:17 -0700324 int topBottomPadding = allAppsIconDrawablePaddingPx * (isVerticalBarLayout() ? 2 : 1);
Jon Miranda1091e532017-07-21 13:31:50 -0700325 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
326 + Utilities.calculateTextHeight(allAppsIconTextSizePx)
Jon Miranda3f9bab22017-07-28 14:50:17 -0700327 + topBottomPadding * 2;
Jon Miranda1091e532017-07-21 13:31:50 -0700328 }
329
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700330 private void updateAvailableDimensions(Resources res) {
331 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800332
Jon Mirandabf7d8122016-11-03 15:29:29 -0700333 // Check to see if the icons fit within the available height. If not, then scale down.
334 float usedHeight = (cellHeightPx * inv.numRows);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700335 int maxHeight = (availableHeightPx - getTotalWorkspacePadding().y);
Winson Chungb3800242013-10-24 11:01:54 -0700336 if (usedHeight > maxHeight) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700337 float scale = maxHeight / usedHeight;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700338 updateIconSize(scale, res);
Winson Chungb3800242013-10-24 11:01:54 -0700339 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700340 updateAvailableFolderCellDimensions(res);
Winson Chungb3800242013-10-24 11:01:54 -0700341 }
342
Jon Miranda6f7e9702019-09-16 14:44:14 -0700343 /**
344 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
345 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
346 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
347 */
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700348 private void updateIconSize(float scale, Resources res) {
Jon Miranda18751b62017-07-31 17:25:27 -0700349 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800350 final boolean isVerticalLayout = isVerticalBarLayout();
Jon Miranda6f7e9702019-09-16 14:44:14 -0700351 float invIconSizeDp = isVerticalLayout ? inv.landscapeIconSize : inv.iconSize;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700352 iconSizePx = Math.max(1, (int) (ResourceUtils.pxFromDp(invIconSizeDp, mInfo.metrics)
353 * scale));
354 iconTextSizePx = (int) (Utilities.pxFromSp(inv.iconTextSize, mInfo.metrics) * scale);
Jon Miranda09660722017-06-14 14:20:14 -0700355 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * scale);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700356
Jon Miranda18751b62017-07-31 17:25:27 -0700357 cellHeightPx = iconSizePx + iconDrawablePaddingPx
358 + Utilities.calculateTextHeight(iconTextSizePx);
Jon Miranda846455e2017-10-02 14:58:52 -0700359 int cellYPadding = (getCellSize().y - cellHeightPx) / 2;
Sunny Goyal07b69292018-01-08 14:19:34 -0800360 if (iconDrawablePaddingPx > cellYPadding && !isVerticalLayout
Sunny Goyald70e75a2018-02-22 10:07:32 -0800361 && !isMultiWindowMode) {
Jon Miranda846455e2017-10-02 14:58:52 -0700362 // Ensures that the label is closer to its corresponding icon. This is not an issue
363 // with vertical bar layout or multi-window mode since the issue is handled separately
364 // with their calls to {@link #adjustToHideWorkspaceLabels}.
365 cellHeightPx -= (iconDrawablePaddingPx - cellYPadding);
366 iconDrawablePaddingPx = cellYPadding;
367 }
368 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700369
Sunny Goyalae190ff2020-04-14 00:19:01 +0000370 // All apps
371 if (allAppsHasDifferentNumColumns()) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700372 allAppsIconSizePx = ResourceUtils.pxFromDp(inv.allAppsIconSize, mInfo.metrics);
373 allAppsIconTextSizePx = Utilities.pxFromSp(inv.allAppsIconTextSize, mInfo.metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000374 allAppsCellHeightPx = getCellSize(inv.numAllAppsColumns, inv.numAllAppsColumns).y;
375 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
376 } else {
377 allAppsIconSizePx = iconSizePx;
378 allAppsIconTextSizePx = iconTextSizePx;
379 allAppsIconDrawablePaddingPx = iconDrawablePaddingPx;
380 allAppsCellHeightPx = getCellSize().y;
381 }
382 allAppsCellWidthPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700383
Jon Miranda6f7e9702019-09-16 14:44:14 -0700384 if (isVerticalBarLayout()) {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700385 // Always hide the Workspace text with vertical bar layout.
Jon Miranda1091e532017-07-21 13:31:50 -0700386 adjustToHideWorkspaceLabels();
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700387 }
Winson Chungb3800242013-10-24 11:01:54 -0700388
Winson Chungb3800242013-10-24 11:01:54 -0700389 // Hotseat
Sunny Goyal07b69292018-01-08 14:19:34 -0800390 if (isVerticalLayout) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700391 hotseatBarSizePx = iconSizePx + hotseatBarSidePaddingStartPx
392 + hotseatBarSidePaddingEndPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700393 }
Jon Miranda5044c352017-08-09 11:37:59 -0700394 hotseatCellHeightPx = iconSizePx;
Winson Chungb3800242013-10-24 11:01:54 -0700395
Sunny Goyal07b69292018-01-08 14:19:34 -0800396 if (!isVerticalLayout) {
Jon Miranda18751b62017-07-31 17:25:27 -0700397 int expectedWorkspaceHeight = availableHeightPx - hotseatBarSizePx
Tony Wickham5edf9e22020-03-27 20:06:52 -0700398 - workspacePageIndicatorHeight - edgeMarginPx;
Sunny Goyal47328fd2016-05-25 18:56:41 -0700399 float minRequiredHeight = dropTargetBarSizePx + workspaceSpringLoadedBottomSpace;
400 workspaceSpringLoadShrinkFactor = Math.min(
401 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f,
402 1 - (minRequiredHeight / expectedWorkspaceHeight));
403 } else {
404 workspaceSpringLoadShrinkFactor =
405 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
406 }
407
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700408 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -0700409 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
410 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Winson Chung0f785722015-04-08 10:27:49 -0700411 }
412
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700413 private void updateAvailableFolderCellDimensions(Resources res) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700414 int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_padding_top)
415 + res.getDimensionPixelSize(R.dimen.folder_label_padding_bottom)
416 + Utilities.calculateTextHeight(res.getDimension(R.dimen.folder_label_text_size));
417
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700418 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700419
Jon Mirandac1b23992016-12-13 08:57:36 -0800420 // Don't let the folder get too close to the edges of the screen.
Jon Miranda1786df32018-09-25 13:05:23 -0700421 int folderMargin = edgeMarginPx * 2;
Sunny Goyal07b69292018-01-08 14:19:34 -0800422 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -0800423
424 // Check if the icons fit within the available height.
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800425 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows;
426 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderBottomPanelSize
427 - folderMargin;
428 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -0800429
430 // Check if the icons fit within the available width.
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800431 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns;
432 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin;
433 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -0800434
435 float scale = Math.min(scaleX, scaleY);
436 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700437 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700438 }
439 }
440
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700441 private void updateFolderCellSize(float scale, Resources res) {
442 folderChildIconSizePx = (int) (ResourceUtils.pxFromDp(inv.iconSize, mInfo.metrics) * scale);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700443 folderChildTextSizePx =
444 (int) (res.getDimensionPixelSize(R.dimen.folder_child_text_size) * scale);
445
446 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
447 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding) * scale);
448 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding) * scale);
449
Jon Mirandac1b23992016-12-13 08:57:36 -0800450 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
Jonathan Miranda9ad87462017-07-26 17:41:02 +0000451 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
452 folderChildDrawablePaddingPx = Math.max(0,
453 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700454 }
455
Winson1f064272016-07-18 17:18:02 -0700456 public void updateInsets(Rect insets) {
457 mInsets.set(insets);
Sunny Goyal07b69292018-01-08 14:19:34 -0800458 updateWorkspacePadding();
Winson1f064272016-07-18 17:18:02 -0700459 }
460
Sunny Goyalae6e3182019-04-30 12:04:37 -0700461 /**
462 * The current device insets. This is generally same as the insets being dispatched to
463 * {@link Insettable} elements, but can differ if the element is using a different profile.
464 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800465 public Rect getInsets() {
466 return mInsets;
467 }
468
Sunny Goyal756cd262015-08-20 12:33:21 -0700469 public Point getCellSize() {
Jon Miranda6f7e9702019-09-16 14:44:14 -0700470 return getCellSize(inv.numColumns, inv.numRows);
471 }
472
473 private Point getCellSize(int numColumns, int numRows) {
Sunny Goyal756cd262015-08-20 12:33:21 -0700474 Point result = new Point();
475 // Since we are only concerned with the overall padding, layout direction does
476 // not matter.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700477 Point padding = getTotalWorkspacePadding();
Jon Miranda18751b62017-07-31 17:25:27 -0700478 result.x = calculateCellWidth(availableWidthPx - padding.x
Jon Miranda6f7e9702019-09-16 14:44:14 -0700479 - cellLayoutPaddingLeftRightPx * 2, numColumns);
Jon Miranda18751b62017-07-31 17:25:27 -0700480 result.y = calculateCellHeight(availableHeightPx - padding.y
Jon Miranda6f7e9702019-09-16 14:44:14 -0700481 - cellLayoutBottomPaddingPx, numRows);
Sunny Goyal756cd262015-08-20 12:33:21 -0700482 return result;
483 }
484
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700485 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -0800486 updateWorkspacePadding();
487 return new Point(workspacePadding.left + workspacePadding.right,
488 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700489 }
490
491 /**
Sunny Goyal07b69292018-01-08 14:19:34 -0800492 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
493 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700494 */
Sunny Goyal07b69292018-01-08 14:19:34 -0800495 private void updateWorkspacePadding() {
496 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -0700497 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -0800498 padding.top = 0;
499 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800500 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700501 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -0700502 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -0700503 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -0700504 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700505 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -0700506 }
Winson Chungb3800242013-10-24 11:01:54 -0700507 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -0700508 int paddingBottom = hotseatBarSizePx + workspacePageIndicatorHeight
509 - mWorkspacePageIndicatorOverlapWorkspace;
Sunny Goyalc6205602015-05-21 20:46:33 -0700510 if (isTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700511 // Pad the left and right of the workspace to ensure consistent spacing
512 // between all icons
Tony Wickhamd6b40372015-09-23 18:37:57 -0700513 // The amount of screen space available for left/right padding.
Sunny Goyal228153d2018-01-04 15:35:22 -0800514 int availablePaddingX = Math.max(0, widthPx - ((inv.numColumns * cellWidthPx) +
Sunny Goyalf5440cb2016-12-14 15:13:00 -0800515 ((inv.numColumns - 1) * cellWidthPx)));
Tony Wickhamd6b40372015-09-23 18:37:57 -0700516 availablePaddingX = (int) Math.min(availablePaddingX,
Sunny Goyal07b69292018-01-08 14:19:34 -0800517 widthPx * MAX_HORIZONTAL_PADDING_PERCENT);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700518 int availablePaddingY = Math.max(0, heightPx - edgeMarginPx - paddingBottom
Jon Mirandac1b08c52016-11-15 14:37:56 -0800519 - (2 * inv.numRows * cellHeightPx) - hotseatBarTopPaddingPx
520 - hotseatBarBottomPaddingPx);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700521 padding.set(availablePaddingX / 2, edgeMarginPx + availablePaddingY / 2,
Tony Wickhamd6b40372015-09-23 18:37:57 -0700522 availablePaddingX / 2, paddingBottom + availablePaddingY / 2);
Winson Chungb3800242013-10-24 11:01:54 -0700523 } else {
524 // Pad the top and bottom of the workspace with search/hotseat bar sizes
Winson1f064272016-07-18 17:18:02 -0700525 padding.set(desiredWorkspaceLeftRightMarginPx,
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700526 edgeMarginPx,
Winson1f064272016-07-18 17:18:02 -0700527 desiredWorkspaceLeftRightMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700528 paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -0700529 }
530 }
Winson Chungb3800242013-10-24 11:01:54 -0700531 }
532
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700533 public Rect getHotseatLayoutPadding() {
534 if (isVerticalBarLayout()) {
535 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700536 mHotseatPadding.set(mInsets.left + hotseatBarSidePaddingStartPx,
537 mInsets.top, hotseatBarSidePaddingEndPx, mInsets.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700538 } else {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700539 mHotseatPadding.set(hotseatBarSidePaddingEndPx, mInsets.top,
540 mInsets.right + hotseatBarSidePaddingStartPx, mInsets.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700541 }
542 } else {
543
544 // We want the edges of the hotseat to line up with the edges of the workspace, but the
545 // icons in the hotseat are a different size, and so don't line up perfectly. To account
546 // for this, we pad the left and right of the hotseat with half of the difference of a
547 // workspace cell vs a hotseat cell.
548 float workspaceCellWidth = (float) widthPx / inv.numColumns;
549 float hotseatCellWidth = (float) widthPx / inv.numHotseatIcons;
550 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
551 mHotseatPadding.set(
552 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingLeftRightPx,
553 hotseatBarTopPaddingPx,
554 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx,
555 hotseatBarBottomPaddingPx + mInsets.bottom + cellLayoutBottomPaddingPx);
556 }
557 return mHotseatPadding;
558 }
559
Winsonfadbe8f2016-07-22 16:35:37 -0700560 /**
561 * @return the bounds for which the open folders should be contained within
562 */
563 public Rect getAbsoluteOpenFolderBounds() {
564 if (isVerticalBarLayout()) {
565 // Folders should only appear right of the drop target bar and left of the hotseat
566 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
567 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -0700568 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700569 mInsets.top + availableHeightPx);
570 } else {
571 // Folders should only appear below the drop target bar and above the hotseat
Tony Wickhamb4b7e202018-01-12 17:39:24 -0800572 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700573 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -0800574 mInsets.left + availableWidthPx - edgeMarginPx,
Jon Miranda18751b62017-07-31 17:25:27 -0700575 mInsets.top + availableHeightPx - hotseatBarSizePx
Tony Wickham5edf9e22020-03-27 20:06:52 -0700576 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -0700577 }
578 }
579
Adam Cohen2e6da152015-05-06 11:42:25 -0700580 public static int calculateCellWidth(int width, int countX) {
Winson Chungb3800242013-10-24 11:01:54 -0700581 return width / countX;
582 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700583 public static int calculateCellHeight(int height, int countY) {
Winson Chungb3800242013-10-24 11:01:54 -0700584 return height / countY;
585 }
586
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700587 /**
Tony Wickham55616cd2015-09-23 14:55:17 -0700588 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
589 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
590 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700591 */
Tony Wickhamab946a12015-09-16 15:38:16 -0700592 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -0700593 return isLandscape && transposeLayoutWithOrientation;
594 }
595
Sunny Goyal59d086c2018-05-07 17:31:40 -0700596 /**
Jon Miranda6f7e9702019-09-16 14:44:14 -0700597 * Returns true when the number of workspace columns and all apps columns differs.
598 */
599 private boolean allAppsHasDifferentNumColumns() {
600 return inv.numAllAppsColumns != inv.numColumns;
601 }
602
603 /**
Sunny Goyal59d086c2018-05-07 17:31:40 -0700604 * Updates orientation information and returns true if it has changed from the previous value.
605 */
Winson Chung13c1c2c2019-09-06 11:46:19 -0700606 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -0700607 if (isVerticalBarLayout()) {
Winson Chung13c1c2c2019-09-06 11:46:19 -0700608 boolean isSeascape = DefaultDisplay.INSTANCE.get(context).getInfo().rotation
609 == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -0700610 if (mIsSeascape != isSeascape) {
611 mIsSeascape = isSeascape;
612 return true;
613 }
614 }
615 return false;
616 }
617
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800618 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -0700619 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800620 }
621
Sunny Goyal07b69292018-01-08 14:19:34 -0800622 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyalc6205602015-05-21 20:46:33 -0700623 return isVerticalBarLayout() || isLargeTablet;
Winson Chungb3800242013-10-24 11:01:54 -0700624 }
625
Sunny Goyalc13403c2016-11-18 23:44:48 -0800626 public int getCellHeight(@ContainerType int containerType) {
627 switch (containerType) {
628 case CellLayout.WORKSPACE:
629 return cellHeightPx;
630 case CellLayout.FOLDER:
631 return folderCellHeightPx;
632 case CellLayout.HOTSEAT:
633 return hotseatCellHeightPx;
634 default:
635 // ??
636 return 0;
637 }
638 }
Sunny Goyal13178ac2016-04-04 16:35:22 -0700639
Sunny Goyal1890f672020-04-30 12:28:00 -0700640 private static Context getContext(Context c, DefaultDisplay.Info info, int orientation) {
641 Configuration config = new Configuration(c.getResources().getConfiguration());
642 config.orientation = orientation;
643 config.densityDpi = info.metrics.densityDpi;
644 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700645 }
Sunny Goyalfde55052018-02-01 14:46:13 -0800646
647 /**
648 * Callback when a component changes the DeviceProfile associated with it, as a result of
649 * configuration change
650 */
651 public interface OnDeviceProfileChangeListener {
652
653 /**
654 * Called when the device profile is reassigned. Note that for layout and measurements, it
655 * is sufficient to listen for inset changes. Use this callback when you need to perform
656 * a one time operation.
657 */
658 void onDeviceProfileChanged(DeviceProfile dp);
659 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700660
661 public static class Builder {
662 private Context mContext;
663 private InvariantDeviceProfile mInv;
664 private DefaultDisplay.Info mInfo;
665
Sunny Goyal0addbf02020-04-28 14:17:35 -0700666 private final Point mWindowPosition = new Point();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700667 private Point mMinSize, mMaxSize;
668 private int mWidth, mHeight;
669
670 private boolean mIsLandscape;
671 private boolean mIsMultiWindowMode = false;
672 private boolean mTransposeLayoutWithOrientation;
673
674 public Builder(Context context, InvariantDeviceProfile inv, DefaultDisplay.Info info) {
675 mContext = context;
676 mInv = inv;
677 mInfo = info;
678 mTransposeLayoutWithOrientation = context.getResources()
679 .getBoolean(R.bool.hotseat_transpose_layout_with_orientation);
680 }
681
682 public Builder setSizeRange(Point minSize, Point maxSize) {
683 mMinSize = minSize;
684 mMaxSize = maxSize;
685 return this;
686 }
687
688 public Builder setSize(int width, int height) {
689 mWidth = width;
690 mHeight = height;
691 mIsLandscape = mWidth > mHeight;
692 return this;
693 }
694
695 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
696 mIsMultiWindowMode = isMultiWindowMode;
697 return this;
698 }
699
Sunny Goyal0addbf02020-04-28 14:17:35 -0700700 /**
701 * Sets the window position if not full-screen
702 */
703 public Builder setWindowPosition(int x, int y) {
704 mWindowPosition.set(x, y);
705 return this;
706 }
707
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700708 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
709 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
710 return this;
711 }
712
713 public DeviceProfile build() {
714 return new DeviceProfile(mContext, mInv, mInfo, mMinSize, mMaxSize,
715 mWidth, mHeight, mIsLandscape, mIsMultiWindowMode,
Sunny Goyal0addbf02020-04-28 14:17:35 -0700716 mTransposeLayoutWithOrientation, mWindowPosition);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700717 }
718 }
719
Winson Chungb3800242013-10-24 11:01:54 -0700720}