blob: f681d75eefa7e49371dcd69684ca72e0800dda64 [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;
Sunny Goyalfd58da62020-08-11 12:06:49 -070031import com.android.launcher3.util.DisplayController;
32import com.android.launcher3.util.DisplayController.Info;
Sunny Goyalb46703d2020-05-27 17:52:03 -070033import com.android.launcher3.util.WindowBounds;
Winson1f064272016-07-18 17:18:02 -070034
Winson Chungb3800242013-10-24 11:01:54 -070035public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070036
Sunny Goyal1890f672020-04-30 12:28:00 -070037 private static final float TABLET_MIN_DPS = 600;
38 private static final float LARGE_TABLET_MIN_DPS = 720;
39
40
Adam Cohen2e6da152015-05-06 11:42:25 -070041 public final InvariantDeviceProfile inv;
Sunny Goyalfd58da62020-08-11 12:06:49 -070042 private final Info mInfo;
Winson Chungbe876472014-05-14 14:15:20 -070043
Sunny Goyalc6205602015-05-21 20:46:33 -070044 // Device properties
45 public final boolean isTablet;
46 public final boolean isLargeTablet;
47 public final boolean isPhone;
48 public final boolean transposeLayoutWithOrientation;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -070049
Sunny Goyalc6205602015-05-21 20:46:33 -070050 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -070051 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -080052 public final boolean isMultiWindowMode;
53
Sunny Goyal0addbf02020-04-28 14:17:35 -070054 public final int windowX;
55 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -070056 public final int widthPx;
57 public final int heightPx;
58 public final int availableWidthPx;
59 public final int availableHeightPx;
Jon Mirandabba64512019-03-27 10:54:17 -070060
61 public final float aspectRatio;
62
Tony Wickhamd6b40372015-09-23 18:37:57 -070063 /**
64 * The maximum amount of left/right workspace padding as a percentage of the screen width.
65 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
66 * 7% of the screen width can be used as right padding.
67 */
68 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -070069
Jon Miranda3f9bab22017-07-28 14:50:17 -070070 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda30d0aa22017-07-25 15:55:29 -070071
Jon Miranda5eacbb72018-07-31 11:14:46 -070072 // To evenly space the icons, increase the left/right margins for tablets in portrait mode.
73 private static final int PORTRAIT_TABLET_LEFT_RIGHT_PADDING_MULTIPLIER = 4;
74
Sunny Goyalc6205602015-05-21 20:46:33 -070075 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -080076 public final int desiredWorkspaceLeftRightMarginPx;
Jon Miranda28032002017-07-13 16:18:56 -070077 public final int cellLayoutPaddingLeftRightPx;
Jon Miranda18751b62017-07-31 17:25:27 -070078 public final int cellLayoutBottomPaddingPx;
Sunny Goyalc6205602015-05-21 20:46:33 -070079 public final int edgeMarginPx;
Sunny Goyal47328fd2016-05-25 18:56:41 -070080 public float workspaceSpringLoadShrinkFactor;
81 public final int workspaceSpringLoadedBottomSpace;
Sunny Goyalc6205602015-05-21 20:46:33 -070082
Tony Wickham5edf9e22020-03-27 20:06:52 -070083 // Workspace page indicator
84 public final int workspacePageIndicatorHeight;
85 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -070086
Sunny Goyalc6205602015-05-21 20:46:33 -070087 // Workspace icons
88 public int iconSizePx;
89 public int iconTextSizePx;
90 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -070091 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -070092
Adam Cohen59400422014-03-05 18:07:04 -080093 public int cellWidthPx;
94 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070095 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -080096
Sunny Goyalc6205602015-05-21 20:46:33 -070097 // Folder
Sunny Goyalc6205602015-05-21 20:46:33 -070098 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -070099 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700100
101 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700102 public int folderCellWidthPx;
103 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700104
105 // Folder child
106 public int folderChildIconSizePx;
107 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700108 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700109
Sunny Goyalc6205602015-05-21 20:46:33 -0700110 // Hotseat
Sunny Goyalc6205602015-05-21 20:46:33 -0700111 public int hotseatCellHeightPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700112 // In portrait: size = height, in landscape: size = width
113 public int hotseatBarSizePx;
Sunny Goyal07b69292018-01-08 14:19:34 -0800114 public final int hotseatBarTopPaddingPx;
Jon Miranda7e183c32018-06-20 11:05:27 -0700115 public int hotseatBarBottomPaddingPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700116 // Start is the side next to the nav bar, end is the side next to the workspace
117 public final int hotseatBarSidePaddingStartPx;
118 public final int hotseatBarSidePaddingEndPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700119
Sunny Goyalc6205602015-05-21 20:46:33 -0700120 // All apps
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700121 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700122 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700123 public int allAppsIconSizePx;
124 public int allAppsIconDrawablePaddingPx;
125 public float allAppsIconTextSizePx;
126
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800127 // Widgets
128 public final PointF appWidgetScale = new PointF(1.0f, 1.0f);
129
Sunny Goyal47328fd2016-05-25 18:56:41 -0700130 // Drop Target
131 public int dropTargetBarSizePx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700132
Winson1f064272016-07-18 17:18:02 -0700133 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800134 private final Rect mInsets = new Rect();
135 public final Rect workspacePadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700136 private final Rect mHotseatPadding = new Rect();
Jon Miranda0bd63d12019-03-06 17:29:29 -0800137 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700138 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700139
Tony Wickhamf34bee82018-12-03 18:11:39 -0800140 // Notification dots
Samuel Fufac96fa242019-09-26 23:06:32 -0700141 public DotRenderer mDotRendererWorkSpace;
142 public DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800143
Sunny Goyalfd58da62020-08-11 12:06:49 -0700144 DeviceProfile(Context context, InvariantDeviceProfile inv, Info info,
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700145 Point minSize, Point maxSize, int width, int height, boolean isLandscape,
Sunny Goyal0addbf02020-04-28 14:17:35 -0700146 boolean isMultiWindowMode, boolean transposeLayoutWithOrientation,
147 Point windowPosition) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700148
Adam Cohen2e6da152015-05-06 11:42:25 -0700149 this.inv = inv;
Sunny Goyalc6205602015-05-21 20:46:33 -0700150 this.isLandscape = isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -0800151 this.isMultiWindowMode = isMultiWindowMode;
Sunny Goyal0addbf02020-04-28 14:17:35 -0700152 windowX = windowPosition.x;
153 windowY = windowPosition.y;
Winson Chungb3800242013-10-24 11:01:54 -0700154
Jon Miranda7e183c32018-06-20 11:05:27 -0700155 // Determine sizes.
156 widthPx = width;
157 heightPx = height;
158 if (isLandscape) {
159 availableWidthPx = maxSize.x;
160 availableHeightPx = minSize.y;
161 } else {
162 availableWidthPx = minSize.x;
163 availableHeightPx = maxSize.y;
164 }
165
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700166 mInfo = info;
Adam Cohen2e6da152015-05-06 11:42:25 -0700167
Sunny Goyalc6205602015-05-21 20:46:33 -0700168 // Constants from resources
Sunny Goyal1890f672020-04-30 12:28:00 -0700169 float swDPs = Utilities.dpiFromPx(
170 Math.min(info.smallestSize.x, info.smallestSize.y), info.metrics);
171 isTablet = swDPs >= TABLET_MIN_DPS;
172 isLargeTablet = swDPs >= LARGE_TABLET_MIN_DPS;
Sunny Goyalc6205602015-05-21 20:46:33 -0700173 isPhone = !isTablet && !isLargeTablet;
Jon Mirandabba64512019-03-27 10:54:17 -0700174 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Jon Miranda7e183c32018-06-20 11:05:27 -0700175 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
Sunny Goyalc6205602015-05-21 20:46:33 -0700176
177 // Some more constants
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700178 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Winson Chungb3800242013-10-24 11:01:54 -0700179
Sunny Goyal1890f672020-04-30 12:28:00 -0700180 context = getContext(context, info, isVerticalBarLayout()
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700181 ? Configuration.ORIENTATION_LANDSCAPE
182 : Configuration.ORIENTATION_PORTRAIT);
Sunny Goyal1890f672020-04-30 12:28:00 -0700183 final Resources res = context.getResources();
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700184
Winson Chungb3800242013-10-24 11:01:54 -0700185 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Jon Miranda28032002017-07-13 16:18:56 -0700186 desiredWorkspaceLeftRightMarginPx = isVerticalBarLayout() ? 0 : edgeMarginPx;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700187
Jon Miranda5eacbb72018-07-31 11:14:46 -0700188 int cellLayoutPaddingLeftRightMultiplier = !isVerticalBarLayout() && isTablet
189 ? PORTRAIT_TABLET_LEFT_RIGHT_PADDING_MULTIPLIER : 1;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700190 int cellLayoutPadding = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_padding);
191 if (isLandscape) {
192 cellLayoutPaddingLeftRightPx = 0;
193 cellLayoutBottomPaddingPx = cellLayoutPadding;
194 } else {
195 cellLayoutPaddingLeftRightPx = cellLayoutPaddingLeftRightMultiplier * cellLayoutPadding;
196 cellLayoutBottomPaddingPx = 0;
197 }
198
Tony Wickham5edf9e22020-03-27 20:06:52 -0700199 workspacePageIndicatorHeight = res.getDimensionPixelSize(
200 R.dimen.workspace_page_indicator_height);
201 mWorkspacePageIndicatorOverlapWorkspace =
202 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700203
Winson Chungb3800242013-10-24 11:01:54 -0700204 iconDrawablePaddingOriginalPx =
205 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700206 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
207 workspaceSpringLoadedBottomSpace =
208 res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space);
Sunny Goyald5190522017-04-24 03:06:54 -0700209
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700210 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700211
Winson1f064272016-07-18 17:18:02 -0700212 hotseatBarTopPaddingPx =
213 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding);
Jon Miranda7e183c32018-06-20 11:05:27 -0700214 hotseatBarBottomPaddingPx = (isTallDevice ? 0
215 : res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_non_tall_padding))
216 + res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_padding);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700217 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800218 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700219 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700220 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700221 hotseatBarSizePx = ResourceUtils.pxFromDp(inv.iconSize, mInfo.metrics)
222 + (isVerticalBarLayout()
Sunny Goyal415f1732018-11-29 10:33:47 -0800223 ? (hotseatBarSidePaddingStartPx + hotseatBarSidePaddingEndPx)
224 : (res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_extra_vertical_size)
225 + hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx));
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700226
Jon Miranda2ed276e2017-06-29 11:36:34 -0700227 // Calculate all of the remaining variables.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700228 updateAvailableDimensions(res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700229
230 // Now that we have all of the variables calculated, we can tune certain sizes.
Jon Miranda30d0aa22017-07-25 15:55:29 -0700231 if (!isVerticalBarLayout() && isPhone && isTallDevice) {
Jon Miranda3f9bab22017-07-28 14:50:17 -0700232 // We increase the hotseat size when there is extra space.
Jon Miranda2ed276e2017-06-29 11:36:34 -0700233 // ie. For a display with a large aspect ratio, we can keep the icons on the workspace
Jon Miranda3f9bab22017-07-28 14:50:17 -0700234 // in portrait mode closer together by adding more height to the hotseat.
Jon Miranda30d0aa22017-07-25 15:55:29 -0700235 // Note: This calculation was created after noticing a pattern in the design spec.
Jon Miranda7e183c32018-06-20 11:05:27 -0700236 int extraSpace = getCellSize().y - iconSizePx - iconDrawablePaddingPx * 2
Tony Wickham5edf9e22020-03-27 20:06:52 -0700237 - workspacePageIndicatorHeight;
Jon Miranda7e183c32018-06-20 11:05:27 -0700238 hotseatBarSizePx += extraSpace;
239 hotseatBarBottomPaddingPx += extraSpace;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700240
Jon Miranda3f9bab22017-07-28 14:50:17 -0700241 // Recalculate the available dimensions using the new hotseat size.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700242 updateAvailableDimensions(res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700243 }
Sunny Goyal07b69292018-01-08 14:19:34 -0800244 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800245
246 // This is done last, after iconSizePx is calculated above.
Samuel Fufac96fa242019-09-26 23:06:32 -0700247 mDotRendererWorkSpace = new DotRenderer(iconSizePx, IconShape.getShapePath(),
Tony Wickhame1cb93f2019-05-03 11:27:32 -0700248 IconShape.DEFAULT_PATH_SIZE);
Samuel Fufac96fa242019-09-26 23:06:32 -0700249 mDotRendererAllApps = iconSizePx == allAppsIconSizePx ? mDotRendererWorkSpace :
250 new DotRenderer(allAppsIconSizePx, IconShape.getShapePath(),
251 IconShape.DEFAULT_PATH_SIZE);
Adam Cohen63f1ec02014-08-12 09:23:13 -0700252 }
253
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700254 public Builder toBuilder(Context context) {
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800255 Point size = new Point(availableWidthPx, availableHeightPx);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700256 return new Builder(context, inv, mInfo)
257 .setSizeRange(size, size)
258 .setSize(widthPx, heightPx)
Sunny Goyal0addbf02020-04-28 14:17:35 -0700259 .setWindowPosition(windowX, windowY)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700260 .setMultiWindowMode(isMultiWindowMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800261 }
262
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700263 public DeviceProfile copy(Context context) {
264 return toBuilder(context).build();
265 }
266
267 /**
268 * TODO: Move this to the builder as part of setMultiWindowMode
269 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700270 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Jon Mirandaa11380d2017-08-24 11:30:03 -0700271 // We take the minimum sizes of this profile and it's multi-window variant to ensure that
272 // the system decor is always excluded.
Sunny Goyalb46703d2020-05-27 17:52:03 -0700273 Point mwSize = new Point(Math.min(availableWidthPx, windowBounds.availableSize.x),
274 Math.min(availableHeightPx, windowBounds.availableSize.y));
Jon Mirandaa11380d2017-08-24 11:30:03 -0700275
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700276 DeviceProfile profile = toBuilder(context)
277 .setSizeRange(mwSize, mwSize)
Sunny Goyalb46703d2020-05-27 17:52:03 -0700278 .setSize(windowBounds.bounds.width(), windowBounds.bounds.height())
279 .setWindowPosition(windowBounds.bounds.left, windowBounds.bounds.top)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700280 .setMultiWindowMode(true)
281 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800282
Jon Miranda0cd04572017-09-19 11:31:42 -0700283 // If there isn't enough vertical cell padding with the labels displayed, hide the labels.
284 float workspaceCellPaddingY = profile.getCellSize().y - profile.iconSizePx
285 - iconDrawablePaddingPx - profile.iconTextSizePx;
286 if (workspaceCellPaddingY < profile.iconDrawablePaddingPx * 2) {
287 profile.adjustToHideWorkspaceLabels();
288 }
Jon Miranda93e1f042016-11-11 14:13:04 -0800289
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800290 // We use these scales to measure and layout the widgets using their full invariant profile
291 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
292 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
293 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
294 profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY);
Sunny Goyal07b69292018-01-08 14:19:34 -0800295 profile.updateWorkspacePadding();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800296
Jon Miranda93e1f042016-11-11 14:13:04 -0800297 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700298 }
299
Adam Cohen63f1ec02014-08-12 09:23:13 -0700300 /**
Sunny Goyalb46703d2020-05-27 17:52:03 -0700301 * Inverse of {@link #getMultiWindowProfile(Context, WindowBounds)}
Sunny Goyal2e2e2b42018-02-27 16:52:55 -0800302 * @return device profile corresponding to the current orientation in non multi-window mode.
303 */
304 public DeviceProfile getFullScreenProfile() {
305 return isLandscape ? inv.landscapeProfile : inv.portraitProfile;
306 }
307
308 /**
Jon Miranda1091e532017-07-21 13:31:50 -0700309 * Adjusts the profile so that the labels on the Workspace are hidden.
310 * It is important to call this method after the All Apps variables have been set.
311 */
312 private void adjustToHideWorkspaceLabels() {
313 iconTextSizePx = 0;
314 iconDrawablePaddingPx = 0;
315 cellHeightPx = iconSizePx;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700316 autoResizeAllAppsCells();
317 }
Jon Miranda1091e532017-07-21 13:31:50 -0700318
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700319 /**
320 * Re-computes the all-apps cell size to be independent of workspace
321 */
322 public void autoResizeAllAppsCells() {
Jon Miranda3f9bab22017-07-28 14:50:17 -0700323 int topBottomPadding = allAppsIconDrawablePaddingPx * (isVerticalBarLayout() ? 2 : 1);
Jon Miranda1091e532017-07-21 13:31:50 -0700324 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
325 + Utilities.calculateTextHeight(allAppsIconTextSizePx)
Jon Miranda3f9bab22017-07-28 14:50:17 -0700326 + topBottomPadding * 2;
Jon Miranda1091e532017-07-21 13:31:50 -0700327 }
328
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700329 private void updateAvailableDimensions(Resources res) {
330 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800331
Jon Mirandabf7d8122016-11-03 15:29:29 -0700332 // Check to see if the icons fit within the available height. If not, then scale down.
333 float usedHeight = (cellHeightPx * inv.numRows);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700334 int maxHeight = (availableHeightPx - getTotalWorkspacePadding().y);
Winson Chungb3800242013-10-24 11:01:54 -0700335 if (usedHeight > maxHeight) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700336 float scale = maxHeight / usedHeight;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700337 updateIconSize(scale, res);
Winson Chungb3800242013-10-24 11:01:54 -0700338 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700339 updateAvailableFolderCellDimensions(res);
Winson Chungb3800242013-10-24 11:01:54 -0700340 }
341
Jon Miranda6f7e9702019-09-16 14:44:14 -0700342 /**
343 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
344 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
345 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
346 */
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700347 private void updateIconSize(float scale, Resources res) {
Jon Miranda18751b62017-07-31 17:25:27 -0700348 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800349 final boolean isVerticalLayout = isVerticalBarLayout();
Jon Miranda6f7e9702019-09-16 14:44:14 -0700350 float invIconSizeDp = isVerticalLayout ? inv.landscapeIconSize : inv.iconSize;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700351 iconSizePx = Math.max(1, (int) (ResourceUtils.pxFromDp(invIconSizeDp, mInfo.metrics)
352 * scale));
353 iconTextSizePx = (int) (Utilities.pxFromSp(inv.iconTextSize, mInfo.metrics) * scale);
Jon Miranda09660722017-06-14 14:20:14 -0700354 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * scale);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700355
Jon Miranda18751b62017-07-31 17:25:27 -0700356 cellHeightPx = iconSizePx + iconDrawablePaddingPx
357 + Utilities.calculateTextHeight(iconTextSizePx);
Jon Miranda846455e2017-10-02 14:58:52 -0700358 int cellYPadding = (getCellSize().y - cellHeightPx) / 2;
Sunny Goyal07b69292018-01-08 14:19:34 -0800359 if (iconDrawablePaddingPx > cellYPadding && !isVerticalLayout
Sunny Goyald70e75a2018-02-22 10:07:32 -0800360 && !isMultiWindowMode) {
Jon Miranda846455e2017-10-02 14:58:52 -0700361 // Ensures that the label is closer to its corresponding icon. This is not an issue
362 // with vertical bar layout or multi-window mode since the issue is handled separately
363 // with their calls to {@link #adjustToHideWorkspaceLabels}.
364 cellHeightPx -= (iconDrawablePaddingPx - cellYPadding);
365 iconDrawablePaddingPx = cellYPadding;
366 }
367 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700368
Sunny Goyalae190ff2020-04-14 00:19:01 +0000369 // All apps
370 if (allAppsHasDifferentNumColumns()) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700371 allAppsIconSizePx = ResourceUtils.pxFromDp(inv.allAppsIconSize, mInfo.metrics);
372 allAppsIconTextSizePx = Utilities.pxFromSp(inv.allAppsIconTextSize, mInfo.metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000373 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Jon Miranda35359442020-07-09 14:54:23 -0700374 // We use 4 below to ensure labels are closer to their corresponding icon.
375 allAppsCellHeightPx = Math.round(allAppsIconSizePx + allAppsIconTextSizePx
376 + (4 * allAppsIconDrawablePaddingPx));
Sunny Goyalae190ff2020-04-14 00:19:01 +0000377 } else {
378 allAppsIconSizePx = iconSizePx;
379 allAppsIconTextSizePx = iconTextSizePx;
380 allAppsIconDrawablePaddingPx = iconDrawablePaddingPx;
381 allAppsCellHeightPx = getCellSize().y;
382 }
383 allAppsCellWidthPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700384
Jon Miranda6f7e9702019-09-16 14:44:14 -0700385 if (isVerticalBarLayout()) {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700386 // Always hide the Workspace text with vertical bar layout.
Jon Miranda1091e532017-07-21 13:31:50 -0700387 adjustToHideWorkspaceLabels();
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700388 }
Winson Chungb3800242013-10-24 11:01:54 -0700389
Winson Chungb3800242013-10-24 11:01:54 -0700390 // Hotseat
Sunny Goyal07b69292018-01-08 14:19:34 -0800391 if (isVerticalLayout) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700392 hotseatBarSizePx = iconSizePx + hotseatBarSidePaddingStartPx
393 + hotseatBarSidePaddingEndPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700394 }
Jon Miranda5044c352017-08-09 11:37:59 -0700395 hotseatCellHeightPx = iconSizePx;
Winson Chungb3800242013-10-24 11:01:54 -0700396
Sunny Goyal07b69292018-01-08 14:19:34 -0800397 if (!isVerticalLayout) {
Jon Miranda18751b62017-07-31 17:25:27 -0700398 int expectedWorkspaceHeight = availableHeightPx - hotseatBarSizePx
Tony Wickham5edf9e22020-03-27 20:06:52 -0700399 - workspacePageIndicatorHeight - edgeMarginPx;
Sunny Goyal47328fd2016-05-25 18:56:41 -0700400 float minRequiredHeight = dropTargetBarSizePx + workspaceSpringLoadedBottomSpace;
401 workspaceSpringLoadShrinkFactor = Math.min(
402 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f,
403 1 - (minRequiredHeight / expectedWorkspaceHeight));
404 } else {
405 workspaceSpringLoadShrinkFactor =
406 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
407 }
408
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700409 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -0700410 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
411 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Winson Chung0f785722015-04-08 10:27:49 -0700412 }
413
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700414 private void updateAvailableFolderCellDimensions(Resources res) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700415 int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_padding_top)
416 + res.getDimensionPixelSize(R.dimen.folder_label_padding_bottom)
417 + Utilities.calculateTextHeight(res.getDimension(R.dimen.folder_label_text_size));
418
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700419 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700420
Jon Mirandac1b23992016-12-13 08:57:36 -0800421 // Don't let the folder get too close to the edges of the screen.
Jon Miranda1786df32018-09-25 13:05:23 -0700422 int folderMargin = edgeMarginPx * 2;
Sunny Goyal07b69292018-01-08 14:19:34 -0800423 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -0800424
425 // Check if the icons fit within the available height.
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800426 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows;
427 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderBottomPanelSize
428 - folderMargin;
429 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -0800430
431 // Check if the icons fit within the available width.
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800432 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns;
433 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin;
434 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -0800435
436 float scale = Math.min(scaleX, scaleY);
437 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700438 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700439 }
440 }
441
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700442 private void updateFolderCellSize(float scale, Resources res) {
443 folderChildIconSizePx = (int) (ResourceUtils.pxFromDp(inv.iconSize, mInfo.metrics) * scale);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700444 folderChildTextSizePx =
445 (int) (res.getDimensionPixelSize(R.dimen.folder_child_text_size) * scale);
446
447 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
448 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding) * scale);
449 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding) * scale);
450
Jon Mirandac1b23992016-12-13 08:57:36 -0800451 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
Jonathan Miranda9ad87462017-07-26 17:41:02 +0000452 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
453 folderChildDrawablePaddingPx = Math.max(0,
454 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700455 }
456
Winson1f064272016-07-18 17:18:02 -0700457 public void updateInsets(Rect insets) {
458 mInsets.set(insets);
Sunny Goyal07b69292018-01-08 14:19:34 -0800459 updateWorkspacePadding();
Winson1f064272016-07-18 17:18:02 -0700460 }
461
Sunny Goyalae6e3182019-04-30 12:04:37 -0700462 /**
463 * The current device insets. This is generally same as the insets being dispatched to
464 * {@link Insettable} elements, but can differ if the element is using a different profile.
465 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800466 public Rect getInsets() {
467 return mInsets;
468 }
469
Sunny Goyal756cd262015-08-20 12:33:21 -0700470 public Point getCellSize() {
Jon Miranda6f7e9702019-09-16 14:44:14 -0700471 return getCellSize(inv.numColumns, inv.numRows);
472 }
473
474 private Point getCellSize(int numColumns, int numRows) {
Sunny Goyal756cd262015-08-20 12:33:21 -0700475 Point result = new Point();
476 // Since we are only concerned with the overall padding, layout direction does
477 // not matter.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700478 Point padding = getTotalWorkspacePadding();
Jon Miranda18751b62017-07-31 17:25:27 -0700479 result.x = calculateCellWidth(availableWidthPx - padding.x
Jon Miranda6f7e9702019-09-16 14:44:14 -0700480 - cellLayoutPaddingLeftRightPx * 2, numColumns);
Jon Miranda18751b62017-07-31 17:25:27 -0700481 result.y = calculateCellHeight(availableHeightPx - padding.y
Jon Miranda6f7e9702019-09-16 14:44:14 -0700482 - cellLayoutBottomPaddingPx, numRows);
Sunny Goyal756cd262015-08-20 12:33:21 -0700483 return result;
484 }
485
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700486 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -0800487 updateWorkspacePadding();
488 return new Point(workspacePadding.left + workspacePadding.right,
489 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700490 }
491
492 /**
Sunny Goyal07b69292018-01-08 14:19:34 -0800493 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
494 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700495 */
Sunny Goyal07b69292018-01-08 14:19:34 -0800496 private void updateWorkspacePadding() {
497 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -0700498 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -0800499 padding.top = 0;
500 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800501 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700502 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -0700503 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -0700504 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -0700505 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700506 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -0700507 }
Winson Chungb3800242013-10-24 11:01:54 -0700508 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -0700509 int paddingBottom = hotseatBarSizePx + workspacePageIndicatorHeight
510 - mWorkspacePageIndicatorOverlapWorkspace;
Sunny Goyalc6205602015-05-21 20:46:33 -0700511 if (isTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700512 // Pad the left and right of the workspace to ensure consistent spacing
513 // between all icons
Tony Wickhamd6b40372015-09-23 18:37:57 -0700514 // The amount of screen space available for left/right padding.
Sunny Goyal228153d2018-01-04 15:35:22 -0800515 int availablePaddingX = Math.max(0, widthPx - ((inv.numColumns * cellWidthPx) +
Sunny Goyalf5440cb2016-12-14 15:13:00 -0800516 ((inv.numColumns - 1) * cellWidthPx)));
Tony Wickhamd6b40372015-09-23 18:37:57 -0700517 availablePaddingX = (int) Math.min(availablePaddingX,
Sunny Goyal07b69292018-01-08 14:19:34 -0800518 widthPx * MAX_HORIZONTAL_PADDING_PERCENT);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700519 int availablePaddingY = Math.max(0, heightPx - edgeMarginPx - paddingBottom
Jon Mirandac1b08c52016-11-15 14:37:56 -0800520 - (2 * inv.numRows * cellHeightPx) - hotseatBarTopPaddingPx
521 - hotseatBarBottomPaddingPx);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700522 padding.set(availablePaddingX / 2, edgeMarginPx + availablePaddingY / 2,
Tony Wickhamd6b40372015-09-23 18:37:57 -0700523 availablePaddingX / 2, paddingBottom + availablePaddingY / 2);
Winson Chungb3800242013-10-24 11:01:54 -0700524 } else {
525 // Pad the top and bottom of the workspace with search/hotseat bar sizes
Winson1f064272016-07-18 17:18:02 -0700526 padding.set(desiredWorkspaceLeftRightMarginPx,
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700527 edgeMarginPx,
Winson1f064272016-07-18 17:18:02 -0700528 desiredWorkspaceLeftRightMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700529 paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -0700530 }
531 }
Winson Chungb3800242013-10-24 11:01:54 -0700532 }
533
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700534 public Rect getHotseatLayoutPadding() {
535 if (isVerticalBarLayout()) {
536 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700537 mHotseatPadding.set(mInsets.left + hotseatBarSidePaddingStartPx,
538 mInsets.top, hotseatBarSidePaddingEndPx, mInsets.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700539 } else {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700540 mHotseatPadding.set(hotseatBarSidePaddingEndPx, mInsets.top,
541 mInsets.right + hotseatBarSidePaddingStartPx, mInsets.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700542 }
543 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700544 // 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(
Sunny Goyal786940a2020-06-02 02:31:31 -0700552 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingLeftRightPx
553 + mInsets.left,
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700554 hotseatBarTopPaddingPx,
Sunny Goyal786940a2020-06-02 02:31:31 -0700555 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx
556 + mInsets.right,
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700557 hotseatBarBottomPaddingPx + mInsets.bottom + cellLayoutBottomPaddingPx);
558 }
559 return mHotseatPadding;
560 }
561
Winsonfadbe8f2016-07-22 16:35:37 -0700562 /**
563 * @return the bounds for which the open folders should be contained within
564 */
565 public Rect getAbsoluteOpenFolderBounds() {
566 if (isVerticalBarLayout()) {
567 // Folders should only appear right of the drop target bar and left of the hotseat
568 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
569 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -0700570 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700571 mInsets.top + availableHeightPx);
572 } else {
573 // Folders should only appear below the drop target bar and above the hotseat
Tony Wickhamb4b7e202018-01-12 17:39:24 -0800574 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700575 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -0800576 mInsets.left + availableWidthPx - edgeMarginPx,
Jon Miranda18751b62017-07-31 17:25:27 -0700577 mInsets.top + availableHeightPx - hotseatBarSizePx
Tony Wickham5edf9e22020-03-27 20:06:52 -0700578 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -0700579 }
580 }
581
Adam Cohen2e6da152015-05-06 11:42:25 -0700582 public static int calculateCellWidth(int width, int countX) {
Winson Chungb3800242013-10-24 11:01:54 -0700583 return width / countX;
584 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700585 public static int calculateCellHeight(int height, int countY) {
Winson Chungb3800242013-10-24 11:01:54 -0700586 return height / countY;
587 }
588
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700589 /**
Tony Wickham55616cd2015-09-23 14:55:17 -0700590 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
591 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
592 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700593 */
Tony Wickhamab946a12015-09-16 15:38:16 -0700594 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -0700595 return isLandscape && transposeLayoutWithOrientation;
596 }
597
Sunny Goyal59d086c2018-05-07 17:31:40 -0700598 /**
Jon Miranda6f7e9702019-09-16 14:44:14 -0700599 * Returns true when the number of workspace columns and all apps columns differs.
600 */
601 private boolean allAppsHasDifferentNumColumns() {
602 return inv.numAllAppsColumns != inv.numColumns;
603 }
604
605 /**
Sunny Goyal59d086c2018-05-07 17:31:40 -0700606 * Updates orientation information and returns true if it has changed from the previous value.
607 */
Winson Chung13c1c2c2019-09-06 11:46:19 -0700608 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -0700609 if (isVerticalBarLayout()) {
Schneider Victor-tulias954bb632021-01-27 14:03:51 -0800610 // Check an up-to-date info.
611 boolean isSeascape = DisplayController.getDefaultDisplay(context)
612 .createInfoForContext(context).rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -0700613 if (mIsSeascape != isSeascape) {
614 mIsSeascape = isSeascape;
615 return true;
616 }
617 }
618 return false;
619 }
620
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800621 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -0700622 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800623 }
624
Sunny Goyal07b69292018-01-08 14:19:34 -0800625 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyalc6205602015-05-21 20:46:33 -0700626 return isVerticalBarLayout() || isLargeTablet;
Winson Chungb3800242013-10-24 11:01:54 -0700627 }
628
Sunny Goyalc13403c2016-11-18 23:44:48 -0800629 public int getCellHeight(@ContainerType int containerType) {
630 switch (containerType) {
631 case CellLayout.WORKSPACE:
632 return cellHeightPx;
633 case CellLayout.FOLDER:
634 return folderCellHeightPx;
635 case CellLayout.HOTSEAT:
636 return hotseatCellHeightPx;
637 default:
638 // ??
639 return 0;
640 }
641 }
Sunny Goyal13178ac2016-04-04 16:35:22 -0700642
Sunny Goyalfd58da62020-08-11 12:06:49 -0700643 private static Context getContext(Context c, Info info, int orientation) {
Sunny Goyal1890f672020-04-30 12:28:00 -0700644 Configuration config = new Configuration(c.getResources().getConfiguration());
645 config.orientation = orientation;
646 config.densityDpi = info.metrics.densityDpi;
647 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700648 }
Sunny Goyalfde55052018-02-01 14:46:13 -0800649
650 /**
651 * Callback when a component changes the DeviceProfile associated with it, as a result of
652 * configuration change
653 */
654 public interface OnDeviceProfileChangeListener {
655
656 /**
657 * Called when the device profile is reassigned. Note that for layout and measurements, it
658 * is sufficient to listen for inset changes. Use this callback when you need to perform
659 * a one time operation.
660 */
661 void onDeviceProfileChanged(DeviceProfile dp);
662 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700663
664 public static class Builder {
665 private Context mContext;
666 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -0700667 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700668
Sunny Goyal0addbf02020-04-28 14:17:35 -0700669 private final Point mWindowPosition = new Point();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700670 private Point mMinSize, mMaxSize;
671 private int mWidth, mHeight;
672
673 private boolean mIsLandscape;
674 private boolean mIsMultiWindowMode = false;
675 private boolean mTransposeLayoutWithOrientation;
676
Sunny Goyalfd58da62020-08-11 12:06:49 -0700677 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700678 mContext = context;
679 mInv = inv;
680 mInfo = info;
681 mTransposeLayoutWithOrientation = context.getResources()
682 .getBoolean(R.bool.hotseat_transpose_layout_with_orientation);
683 }
684
685 public Builder setSizeRange(Point minSize, Point maxSize) {
686 mMinSize = minSize;
687 mMaxSize = maxSize;
688 return this;
689 }
690
691 public Builder setSize(int width, int height) {
692 mWidth = width;
693 mHeight = height;
694 mIsLandscape = mWidth > mHeight;
695 return this;
696 }
697
698 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
699 mIsMultiWindowMode = isMultiWindowMode;
700 return this;
701 }
702
Sunny Goyal0addbf02020-04-28 14:17:35 -0700703 /**
704 * Sets the window position if not full-screen
705 */
706 public Builder setWindowPosition(int x, int y) {
707 mWindowPosition.set(x, y);
708 return this;
709 }
710
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700711 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
712 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
713 return this;
714 }
715
716 public DeviceProfile build() {
717 return new DeviceProfile(mContext, mInv, mInfo, mMinSize, mMaxSize,
718 mWidth, mHeight, mIsLandscape, mIsMultiWindowMode,
Sunny Goyal0addbf02020-04-28 14:17:35 -0700719 mTransposeLayoutWithOrientation, mWindowPosition);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700720 }
721 }
722
Winson Chungb3800242013-10-24 11:01:54 -0700723}