blob: 49caa93e6122cd1dcdc7a82cfd87c085a0ab0240 [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;
Sunny Goyalb46703d2020-05-27 17:52:03 -070032import com.android.launcher3.util.WindowBounds;
Winson1f064272016-07-18 17:18:02 -070033
Winson Chungb3800242013-10-24 11:01:54 -070034public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070035
Sunny Goyal1890f672020-04-30 12:28:00 -070036 private static final float TABLET_MIN_DPS = 600;
37 private static final float LARGE_TABLET_MIN_DPS = 720;
38
39
Adam Cohen2e6da152015-05-06 11:42:25 -070040 public final InvariantDeviceProfile inv;
Sunny Goyal0e7a3382020-04-13 17:15:05 -070041 private final DefaultDisplay.Info mInfo;
Winson Chungbe876472014-05-14 14:15:20 -070042
Sunny Goyalc6205602015-05-21 20:46:33 -070043 // Device properties
44 public final boolean isTablet;
45 public final boolean isLargeTablet;
46 public final boolean isPhone;
47 public final boolean transposeLayoutWithOrientation;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -070048
Sunny Goyalc6205602015-05-21 20:46:33 -070049 // Device properties in current orientation
Sunny Goyald792a772018-04-05 13:37:46 -070050 public final boolean isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -080051 public final boolean isMultiWindowMode;
52
Sunny Goyal0addbf02020-04-28 14:17:35 -070053 public final int windowX;
54 public final int windowY;
Sunny Goyalc6205602015-05-21 20:46:33 -070055 public final int widthPx;
56 public final int heightPx;
57 public final int availableWidthPx;
58 public final int availableHeightPx;
Jon Mirandabba64512019-03-27 10:54:17 -070059
60 public final float aspectRatio;
61
Tony Wickhamd6b40372015-09-23 18:37:57 -070062 /**
63 * The maximum amount of left/right workspace padding as a percentage of the screen width.
64 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
65 * 7% of the screen width can be used as right padding.
66 */
67 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -070068
Jon Miranda3f9bab22017-07-28 14:50:17 -070069 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda30d0aa22017-07-25 15:55:29 -070070
Jon Miranda5eacbb72018-07-31 11:14:46 -070071 // To evenly space the icons, increase the left/right margins for tablets in portrait mode.
72 private static final int PORTRAIT_TABLET_LEFT_RIGHT_PADDING_MULTIPLIER = 4;
73
Sunny Goyalc6205602015-05-21 20:46:33 -070074 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -080075 public final int desiredWorkspaceLeftRightMarginPx;
Jon Miranda28032002017-07-13 16:18:56 -070076 public final int cellLayoutPaddingLeftRightPx;
Jon Miranda18751b62017-07-31 17:25:27 -070077 public final int cellLayoutBottomPaddingPx;
Sunny Goyalc6205602015-05-21 20:46:33 -070078 public final int edgeMarginPx;
Sunny Goyal47328fd2016-05-25 18:56:41 -070079 public float workspaceSpringLoadShrinkFactor;
80 public final int workspaceSpringLoadedBottomSpace;
Sunny Goyalc6205602015-05-21 20:46:33 -070081
Tony Wickham5edf9e22020-03-27 20:06:52 -070082 // Workspace page indicator
83 public final int workspacePageIndicatorHeight;
84 private final int mWorkspacePageIndicatorOverlapWorkspace;
Winson1f064272016-07-18 17:18:02 -070085
Sunny Goyalc6205602015-05-21 20:46:33 -070086 // Workspace icons
87 public int iconSizePx;
88 public int iconTextSizePx;
89 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -070090 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -070091
Adam Cohen59400422014-03-05 18:07:04 -080092 public int cellWidthPx;
93 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070094 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -080095
Sunny Goyalc6205602015-05-21 20:46:33 -070096 // Folder
Sunny Goyalc6205602015-05-21 20:46:33 -070097 public int folderIconSizePx;
Jon Miranda591e3602018-03-28 11:37:00 -070098 public int folderIconOffsetYPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -070099
100 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700101 public int folderCellWidthPx;
102 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700103
104 // Folder child
105 public int folderChildIconSizePx;
106 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700107 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700108
Sunny Goyalc6205602015-05-21 20:46:33 -0700109 // Hotseat
Sunny Goyalc6205602015-05-21 20:46:33 -0700110 public int hotseatCellHeightPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700111 // In portrait: size = height, in landscape: size = width
112 public int hotseatBarSizePx;
Sunny Goyal07b69292018-01-08 14:19:34 -0800113 public final int hotseatBarTopPaddingPx;
Jon Miranda7e183c32018-06-20 11:05:27 -0700114 public int hotseatBarBottomPaddingPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700115 // Start is the side next to the nav bar, end is the side next to the workspace
116 public final int hotseatBarSidePaddingStartPx;
117 public final int hotseatBarSidePaddingEndPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700118
Sunny Goyalc6205602015-05-21 20:46:33 -0700119 // All apps
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700120 public int allAppsCellHeightPx;
Samuel Fufaf1424a32019-10-04 15:15:19 -0700121 public int allAppsCellWidthPx;
Winson1f064272016-07-18 17:18:02 -0700122 public int allAppsIconSizePx;
123 public int allAppsIconDrawablePaddingPx;
124 public float allAppsIconTextSizePx;
125
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800126 // Widgets
127 public final PointF appWidgetScale = new PointF(1.0f, 1.0f);
128
Sunny Goyal47328fd2016-05-25 18:56:41 -0700129 // Drop Target
130 public int dropTargetBarSizePx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700131
Winson1f064272016-07-18 17:18:02 -0700132 // Insets
Sunny Goyal07b69292018-01-08 14:19:34 -0800133 private final Rect mInsets = new Rect();
134 public final Rect workspacePadding = new Rect();
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700135 private final Rect mHotseatPadding = new Rect();
Jon Miranda0bd63d12019-03-06 17:29:29 -0800136 // When true, nav bar is on the left side of the screen.
Sunny Goyal59d086c2018-05-07 17:31:40 -0700137 private boolean mIsSeascape;
Winson1f064272016-07-18 17:18:02 -0700138
Tony Wickhamf34bee82018-12-03 18:11:39 -0800139 // Notification dots
Samuel Fufac96fa242019-09-26 23:06:32 -0700140 public DotRenderer mDotRendererWorkSpace;
141 public DotRenderer mDotRendererAllApps;
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800142
Sunny Goyal0addbf02020-04-28 14:17:35 -0700143 DeviceProfile(Context context, InvariantDeviceProfile inv, DefaultDisplay.Info info,
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700144 Point minSize, Point maxSize, int width, int height, boolean isLandscape,
Sunny Goyal0addbf02020-04-28 14:17:35 -0700145 boolean isMultiWindowMode, boolean transposeLayoutWithOrientation,
146 Point windowPosition) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700147
Adam Cohen2e6da152015-05-06 11:42:25 -0700148 this.inv = inv;
Sunny Goyalc6205602015-05-21 20:46:33 -0700149 this.isLandscape = isLandscape;
Sunny Goyald70e75a2018-02-22 10:07:32 -0800150 this.isMultiWindowMode = isMultiWindowMode;
Sunny Goyal0addbf02020-04-28 14:17:35 -0700151 windowX = windowPosition.x;
152 windowY = windowPosition.y;
Winson Chungb3800242013-10-24 11:01:54 -0700153
Jon Miranda7e183c32018-06-20 11:05:27 -0700154 // Determine sizes.
155 widthPx = width;
156 heightPx = height;
157 if (isLandscape) {
158 availableWidthPx = maxSize.x;
159 availableHeightPx = minSize.y;
160 } else {
161 availableWidthPx = minSize.x;
162 availableHeightPx = maxSize.y;
163 }
164
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700165 mInfo = info;
Adam Cohen2e6da152015-05-06 11:42:25 -0700166
Sunny Goyalc6205602015-05-21 20:46:33 -0700167 // Constants from resources
Sunny Goyal1890f672020-04-30 12:28:00 -0700168 float swDPs = Utilities.dpiFromPx(
169 Math.min(info.smallestSize.x, info.smallestSize.y), info.metrics);
170 isTablet = swDPs >= TABLET_MIN_DPS;
171 isLargeTablet = swDPs >= LARGE_TABLET_MIN_DPS;
Sunny Goyalc6205602015-05-21 20:46:33 -0700172 isPhone = !isTablet && !isLargeTablet;
Jon Mirandabba64512019-03-27 10:54:17 -0700173 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Jon Miranda7e183c32018-06-20 11:05:27 -0700174 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
Sunny Goyalc6205602015-05-21 20:46:33 -0700175
176 // Some more constants
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700177 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Winson Chungb3800242013-10-24 11:01:54 -0700178
Sunny Goyal1890f672020-04-30 12:28:00 -0700179 context = getContext(context, info, isVerticalBarLayout()
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700180 ? Configuration.ORIENTATION_LANDSCAPE
181 : Configuration.ORIENTATION_PORTRAIT);
Sunny Goyal1890f672020-04-30 12:28:00 -0700182 final Resources res = context.getResources();
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700183
Winson Chungb3800242013-10-24 11:01:54 -0700184 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Jon Miranda28032002017-07-13 16:18:56 -0700185 desiredWorkspaceLeftRightMarginPx = isVerticalBarLayout() ? 0 : edgeMarginPx;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700186
Jon Miranda5eacbb72018-07-31 11:14:46 -0700187 int cellLayoutPaddingLeftRightMultiplier = !isVerticalBarLayout() && isTablet
188 ? PORTRAIT_TABLET_LEFT_RIGHT_PADDING_MULTIPLIER : 1;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700189 int cellLayoutPadding = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_padding);
190 if (isLandscape) {
191 cellLayoutPaddingLeftRightPx = 0;
192 cellLayoutBottomPaddingPx = cellLayoutPadding;
193 } else {
194 cellLayoutPaddingLeftRightPx = cellLayoutPaddingLeftRightMultiplier * cellLayoutPadding;
195 cellLayoutBottomPaddingPx = 0;
196 }
197
Tony Wickham5edf9e22020-03-27 20:06:52 -0700198 workspacePageIndicatorHeight = res.getDimensionPixelSize(
199 R.dimen.workspace_page_indicator_height);
200 mWorkspacePageIndicatorOverlapWorkspace =
201 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700202
Winson Chungb3800242013-10-24 11:01:54 -0700203 iconDrawablePaddingOriginalPx =
204 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700205 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
206 workspaceSpringLoadedBottomSpace =
207 res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space);
Sunny Goyald5190522017-04-24 03:06:54 -0700208
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700209 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700210
Winson1f064272016-07-18 17:18:02 -0700211 hotseatBarTopPaddingPx =
212 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding);
Jon Miranda7e183c32018-06-20 11:05:27 -0700213 hotseatBarBottomPaddingPx = (isTallDevice ? 0
214 : res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_non_tall_padding))
215 + res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_padding);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700216 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800217 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700218 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700219 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700220 hotseatBarSizePx = ResourceUtils.pxFromDp(inv.iconSize, mInfo.metrics)
221 + (isVerticalBarLayout()
Sunny Goyal415f1732018-11-29 10:33:47 -0800222 ? (hotseatBarSidePaddingStartPx + hotseatBarSidePaddingEndPx)
223 : (res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_extra_vertical_size)
224 + hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx));
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700225
Jon Miranda2ed276e2017-06-29 11:36:34 -0700226 // Calculate all of the remaining variables.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700227 updateAvailableDimensions(res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700228
229 // Now that we have all of the variables calculated, we can tune certain sizes.
Jon Miranda30d0aa22017-07-25 15:55:29 -0700230 if (!isVerticalBarLayout() && isPhone && isTallDevice) {
Jon Miranda3f9bab22017-07-28 14:50:17 -0700231 // We increase the hotseat size when there is extra space.
Jon Miranda2ed276e2017-06-29 11:36:34 -0700232 // ie. For a display with a large aspect ratio, we can keep the icons on the workspace
Jon Miranda3f9bab22017-07-28 14:50:17 -0700233 // in portrait mode closer together by adding more height to the hotseat.
Jon Miranda30d0aa22017-07-25 15:55:29 -0700234 // Note: This calculation was created after noticing a pattern in the design spec.
Jon Miranda7e183c32018-06-20 11:05:27 -0700235 int extraSpace = getCellSize().y - iconSizePx - iconDrawablePaddingPx * 2
Tony Wickham5edf9e22020-03-27 20:06:52 -0700236 - workspacePageIndicatorHeight;
Jon Miranda7e183c32018-06-20 11:05:27 -0700237 hotseatBarSizePx += extraSpace;
238 hotseatBarBottomPaddingPx += extraSpace;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700239
Jon Miranda3f9bab22017-07-28 14:50:17 -0700240 // Recalculate the available dimensions using the new hotseat size.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700241 updateAvailableDimensions(res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700242 }
Sunny Goyal07b69292018-01-08 14:19:34 -0800243 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800244
245 // This is done last, after iconSizePx is calculated above.
Samuel Fufac96fa242019-09-26 23:06:32 -0700246 mDotRendererWorkSpace = new DotRenderer(iconSizePx, IconShape.getShapePath(),
Tony Wickhame1cb93f2019-05-03 11:27:32 -0700247 IconShape.DEFAULT_PATH_SIZE);
Samuel Fufac96fa242019-09-26 23:06:32 -0700248 mDotRendererAllApps = iconSizePx == allAppsIconSizePx ? mDotRendererWorkSpace :
249 new DotRenderer(allAppsIconSizePx, IconShape.getShapePath(),
250 IconShape.DEFAULT_PATH_SIZE);
Adam Cohen63f1ec02014-08-12 09:23:13 -0700251 }
252
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700253 public Builder toBuilder(Context context) {
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800254 Point size = new Point(availableWidthPx, availableHeightPx);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700255 return new Builder(context, inv, mInfo)
256 .setSizeRange(size, size)
257 .setSize(widthPx, heightPx)
Sunny Goyal0addbf02020-04-28 14:17:35 -0700258 .setWindowPosition(windowX, windowY)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700259 .setMultiWindowMode(isMultiWindowMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800260 }
261
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700262 public DeviceProfile copy(Context context) {
263 return toBuilder(context).build();
264 }
265
266 /**
267 * TODO: Move this to the builder as part of setMultiWindowMode
268 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700269 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Jon Mirandaa11380d2017-08-24 11:30:03 -0700270 // We take the minimum sizes of this profile and it's multi-window variant to ensure that
271 // the system decor is always excluded.
Sunny Goyalb46703d2020-05-27 17:52:03 -0700272 Point mwSize = new Point(Math.min(availableWidthPx, windowBounds.availableSize.x),
273 Math.min(availableHeightPx, windowBounds.availableSize.y));
Jon Mirandaa11380d2017-08-24 11:30:03 -0700274
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700275 DeviceProfile profile = toBuilder(context)
276 .setSizeRange(mwSize, mwSize)
Sunny Goyalb46703d2020-05-27 17:52:03 -0700277 .setSize(windowBounds.bounds.width(), windowBounds.bounds.height())
278 .setWindowPosition(windowBounds.bounds.left, windowBounds.bounds.top)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700279 .setMultiWindowMode(true)
280 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800281
Jon Miranda0cd04572017-09-19 11:31:42 -0700282 // If there isn't enough vertical cell padding with the labels displayed, hide the labels.
283 float workspaceCellPaddingY = profile.getCellSize().y - profile.iconSizePx
284 - iconDrawablePaddingPx - profile.iconTextSizePx;
285 if (workspaceCellPaddingY < profile.iconDrawablePaddingPx * 2) {
286 profile.adjustToHideWorkspaceLabels();
287 }
Jon Miranda93e1f042016-11-11 14:13:04 -0800288
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800289 // We use these scales to measure and layout the widgets using their full invariant profile
290 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
291 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
292 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
293 profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY);
Sunny Goyal07b69292018-01-08 14:19:34 -0800294 profile.updateWorkspacePadding();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800295
Jon Miranda93e1f042016-11-11 14:13:04 -0800296 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700297 }
298
Adam Cohen63f1ec02014-08-12 09:23:13 -0700299 /**
Sunny Goyalb46703d2020-05-27 17:52:03 -0700300 * Inverse of {@link #getMultiWindowProfile(Context, WindowBounds)}
Sunny Goyal2e2e2b42018-02-27 16:52:55 -0800301 * @return device profile corresponding to the current orientation in non multi-window mode.
302 */
303 public DeviceProfile getFullScreenProfile() {
304 return isLandscape ? inv.landscapeProfile : inv.portraitProfile;
305 }
306
307 /**
Jon Miranda1091e532017-07-21 13:31:50 -0700308 * Adjusts the profile so that the labels on the Workspace are hidden.
309 * It is important to call this method after the All Apps variables have been set.
310 */
311 private void adjustToHideWorkspaceLabels() {
312 iconTextSizePx = 0;
313 iconDrawablePaddingPx = 0;
314 cellHeightPx = iconSizePx;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700315 autoResizeAllAppsCells();
316 }
Jon Miranda1091e532017-07-21 13:31:50 -0700317
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700318 /**
319 * Re-computes the all-apps cell size to be independent of workspace
320 */
321 public void autoResizeAllAppsCells() {
Jon Miranda3f9bab22017-07-28 14:50:17 -0700322 int topBottomPadding = allAppsIconDrawablePaddingPx * (isVerticalBarLayout() ? 2 : 1);
Jon Miranda1091e532017-07-21 13:31:50 -0700323 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
324 + Utilities.calculateTextHeight(allAppsIconTextSizePx)
Jon Miranda3f9bab22017-07-28 14:50:17 -0700325 + topBottomPadding * 2;
Jon Miranda1091e532017-07-21 13:31:50 -0700326 }
327
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700328 private void updateAvailableDimensions(Resources res) {
329 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800330
Jon Mirandabf7d8122016-11-03 15:29:29 -0700331 // Check to see if the icons fit within the available height. If not, then scale down.
332 float usedHeight = (cellHeightPx * inv.numRows);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700333 int maxHeight = (availableHeightPx - getTotalWorkspacePadding().y);
Winson Chungb3800242013-10-24 11:01:54 -0700334 if (usedHeight > maxHeight) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700335 float scale = maxHeight / usedHeight;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700336 updateIconSize(scale, res);
Winson Chungb3800242013-10-24 11:01:54 -0700337 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700338 updateAvailableFolderCellDimensions(res);
Winson Chungb3800242013-10-24 11:01:54 -0700339 }
340
Jon Miranda6f7e9702019-09-16 14:44:14 -0700341 /**
342 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
343 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
344 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
345 */
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700346 private void updateIconSize(float scale, Resources res) {
Jon Miranda18751b62017-07-31 17:25:27 -0700347 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800348 final boolean isVerticalLayout = isVerticalBarLayout();
Jon Miranda6f7e9702019-09-16 14:44:14 -0700349 float invIconSizeDp = isVerticalLayout ? inv.landscapeIconSize : inv.iconSize;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700350 iconSizePx = Math.max(1, (int) (ResourceUtils.pxFromDp(invIconSizeDp, mInfo.metrics)
351 * scale));
352 iconTextSizePx = (int) (Utilities.pxFromSp(inv.iconTextSize, mInfo.metrics) * scale);
Jon Miranda09660722017-06-14 14:20:14 -0700353 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * scale);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700354
Jon Miranda18751b62017-07-31 17:25:27 -0700355 cellHeightPx = iconSizePx + iconDrawablePaddingPx
356 + Utilities.calculateTextHeight(iconTextSizePx);
Jon Miranda846455e2017-10-02 14:58:52 -0700357 int cellYPadding = (getCellSize().y - cellHeightPx) / 2;
Sunny Goyal07b69292018-01-08 14:19:34 -0800358 if (iconDrawablePaddingPx > cellYPadding && !isVerticalLayout
Sunny Goyald70e75a2018-02-22 10:07:32 -0800359 && !isMultiWindowMode) {
Jon Miranda846455e2017-10-02 14:58:52 -0700360 // Ensures that the label is closer to its corresponding icon. This is not an issue
361 // with vertical bar layout or multi-window mode since the issue is handled separately
362 // with their calls to {@link #adjustToHideWorkspaceLabels}.
363 cellHeightPx -= (iconDrawablePaddingPx - cellYPadding);
364 iconDrawablePaddingPx = cellYPadding;
365 }
366 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700367
Sunny Goyalae190ff2020-04-14 00:19:01 +0000368 // All apps
369 if (allAppsHasDifferentNumColumns()) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700370 allAppsIconSizePx = ResourceUtils.pxFromDp(inv.allAppsIconSize, mInfo.metrics);
371 allAppsIconTextSizePx = Utilities.pxFromSp(inv.allAppsIconTextSize, mInfo.metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000372 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Jon Miranda35359442020-07-09 14:54:23 -0700373 // We use 4 below to ensure labels are closer to their corresponding icon.
374 allAppsCellHeightPx = Math.round(allAppsIconSizePx + allAppsIconTextSizePx
375 + (4 * allAppsIconDrawablePaddingPx));
Sunny Goyalae190ff2020-04-14 00:19:01 +0000376 } 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 {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700543 // We want the edges of the hotseat to line up with the edges of the workspace, but the
544 // icons in the hotseat are a different size, and so don't line up perfectly. To account
545 // for this, we pad the left and right of the hotseat with half of the difference of a
546 // workspace cell vs a hotseat cell.
547 float workspaceCellWidth = (float) widthPx / inv.numColumns;
548 float hotseatCellWidth = (float) widthPx / inv.numHotseatIcons;
549 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
550 mHotseatPadding.set(
Sunny Goyal786940a2020-06-02 02:31:31 -0700551 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingLeftRightPx
552 + mInsets.left,
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700553 hotseatBarTopPaddingPx,
Sunny Goyal786940a2020-06-02 02:31:31 -0700554 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx
555 + mInsets.right,
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700556 hotseatBarBottomPaddingPx + mInsets.bottom + cellLayoutBottomPaddingPx);
557 }
558 return mHotseatPadding;
559 }
560
Winsonfadbe8f2016-07-22 16:35:37 -0700561 /**
562 * @return the bounds for which the open folders should be contained within
563 */
564 public Rect getAbsoluteOpenFolderBounds() {
565 if (isVerticalBarLayout()) {
566 // Folders should only appear right of the drop target bar and left of the hotseat
567 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
568 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -0700569 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700570 mInsets.top + availableHeightPx);
571 } else {
572 // Folders should only appear below the drop target bar and above the hotseat
Tony Wickhamb4b7e202018-01-12 17:39:24 -0800573 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700574 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -0800575 mInsets.left + availableWidthPx - edgeMarginPx,
Jon Miranda18751b62017-07-31 17:25:27 -0700576 mInsets.top + availableHeightPx - hotseatBarSizePx
Tony Wickham5edf9e22020-03-27 20:06:52 -0700577 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -0700578 }
579 }
580
Adam Cohen2e6da152015-05-06 11:42:25 -0700581 public static int calculateCellWidth(int width, int countX) {
Winson Chungb3800242013-10-24 11:01:54 -0700582 return width / countX;
583 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700584 public static int calculateCellHeight(int height, int countY) {
Winson Chungb3800242013-10-24 11:01:54 -0700585 return height / countY;
586 }
587
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700588 /**
Tony Wickham55616cd2015-09-23 14:55:17 -0700589 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
590 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
591 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700592 */
Tony Wickhamab946a12015-09-16 15:38:16 -0700593 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -0700594 return isLandscape && transposeLayoutWithOrientation;
595 }
596
Sunny Goyal59d086c2018-05-07 17:31:40 -0700597 /**
Jon Miranda6f7e9702019-09-16 14:44:14 -0700598 * Returns true when the number of workspace columns and all apps columns differs.
599 */
600 private boolean allAppsHasDifferentNumColumns() {
601 return inv.numAllAppsColumns != inv.numColumns;
602 }
603
604 /**
Sunny Goyal59d086c2018-05-07 17:31:40 -0700605 * Updates orientation information and returns true if it has changed from the previous value.
606 */
Winson Chung13c1c2c2019-09-06 11:46:19 -0700607 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -0700608 if (isVerticalBarLayout()) {
Winson Chung13c1c2c2019-09-06 11:46:19 -0700609 boolean isSeascape = DefaultDisplay.INSTANCE.get(context).getInfo().rotation
610 == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -0700611 if (mIsSeascape != isSeascape) {
612 mIsSeascape = isSeascape;
613 return true;
614 }
615 }
616 return false;
617 }
618
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800619 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -0700620 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800621 }
622
Sunny Goyal07b69292018-01-08 14:19:34 -0800623 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyalc6205602015-05-21 20:46:33 -0700624 return isVerticalBarLayout() || isLargeTablet;
Winson Chungb3800242013-10-24 11:01:54 -0700625 }
626
Sunny Goyalc13403c2016-11-18 23:44:48 -0800627 public int getCellHeight(@ContainerType int containerType) {
628 switch (containerType) {
629 case CellLayout.WORKSPACE:
630 return cellHeightPx;
631 case CellLayout.FOLDER:
632 return folderCellHeightPx;
633 case CellLayout.HOTSEAT:
634 return hotseatCellHeightPx;
635 default:
636 // ??
637 return 0;
638 }
639 }
Sunny Goyal13178ac2016-04-04 16:35:22 -0700640
Sunny Goyal1890f672020-04-30 12:28:00 -0700641 private static Context getContext(Context c, DefaultDisplay.Info info, int orientation) {
642 Configuration config = new Configuration(c.getResources().getConfiguration());
643 config.orientation = orientation;
644 config.densityDpi = info.metrics.densityDpi;
645 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700646 }
Sunny Goyalfde55052018-02-01 14:46:13 -0800647
648 /**
649 * Callback when a component changes the DeviceProfile associated with it, as a result of
650 * configuration change
651 */
652 public interface OnDeviceProfileChangeListener {
653
654 /**
655 * Called when the device profile is reassigned. Note that for layout and measurements, it
656 * is sufficient to listen for inset changes. Use this callback when you need to perform
657 * a one time operation.
658 */
659 void onDeviceProfileChanged(DeviceProfile dp);
660 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700661
662 public static class Builder {
663 private Context mContext;
664 private InvariantDeviceProfile mInv;
665 private DefaultDisplay.Info mInfo;
666
Sunny Goyal0addbf02020-04-28 14:17:35 -0700667 private final Point mWindowPosition = new Point();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700668 private Point mMinSize, mMaxSize;
669 private int mWidth, mHeight;
670
671 private boolean mIsLandscape;
672 private boolean mIsMultiWindowMode = false;
673 private boolean mTransposeLayoutWithOrientation;
674
675 public Builder(Context context, InvariantDeviceProfile inv, DefaultDisplay.Info info) {
676 mContext = context;
677 mInv = inv;
678 mInfo = info;
679 mTransposeLayoutWithOrientation = context.getResources()
680 .getBoolean(R.bool.hotseat_transpose_layout_with_orientation);
681 }
682
683 public Builder setSizeRange(Point minSize, Point maxSize) {
684 mMinSize = minSize;
685 mMaxSize = maxSize;
686 return this;
687 }
688
689 public Builder setSize(int width, int height) {
690 mWidth = width;
691 mHeight = height;
692 mIsLandscape = mWidth > mHeight;
693 return this;
694 }
695
696 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
697 mIsMultiWindowMode = isMultiWindowMode;
698 return this;
699 }
700
Sunny Goyal0addbf02020-04-28 14:17:35 -0700701 /**
702 * Sets the window position if not full-screen
703 */
704 public Builder setWindowPosition(int x, int y) {
705 mWindowPosition.set(x, y);
706 return this;
707 }
708
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700709 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
710 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
711 return this;
712 }
713
714 public DeviceProfile build() {
715 return new DeviceProfile(mContext, mInv, mInfo, mMinSize, mMaxSize,
716 mWidth, mHeight, mIsLandscape, mIsMultiWindowMode,
Sunny Goyal0addbf02020-04-28 14:17:35 -0700717 mTransposeLayoutWithOrientation, mWindowPosition);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700718 }
719 }
720
Winson Chungb3800242013-10-24 11:01:54 -0700721}