blob: e3cd0bd181a5c8f643a42e8c8e38618a7d246973 [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 allAppsCellHeightPx = getCellSize(inv.numAllAppsColumns, inv.numAllAppsColumns).y;
373 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
374 } else {
375 allAppsIconSizePx = iconSizePx;
376 allAppsIconTextSizePx = iconTextSizePx;
377 allAppsIconDrawablePaddingPx = iconDrawablePaddingPx;
378 allAppsCellHeightPx = getCellSize().y;
379 }
380 allAppsCellWidthPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700381
Jon Miranda6f7e9702019-09-16 14:44:14 -0700382 if (isVerticalBarLayout()) {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700383 // Always hide the Workspace text with vertical bar layout.
Jon Miranda1091e532017-07-21 13:31:50 -0700384 adjustToHideWorkspaceLabels();
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700385 }
Winson Chungb3800242013-10-24 11:01:54 -0700386
Winson Chungb3800242013-10-24 11:01:54 -0700387 // Hotseat
Sunny Goyal07b69292018-01-08 14:19:34 -0800388 if (isVerticalLayout) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700389 hotseatBarSizePx = iconSizePx + hotseatBarSidePaddingStartPx
390 + hotseatBarSidePaddingEndPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700391 }
Jon Miranda5044c352017-08-09 11:37:59 -0700392 hotseatCellHeightPx = iconSizePx;
Winson Chungb3800242013-10-24 11:01:54 -0700393
Sunny Goyal07b69292018-01-08 14:19:34 -0800394 if (!isVerticalLayout) {
Jon Miranda18751b62017-07-31 17:25:27 -0700395 int expectedWorkspaceHeight = availableHeightPx - hotseatBarSizePx
Tony Wickham5edf9e22020-03-27 20:06:52 -0700396 - workspacePageIndicatorHeight - edgeMarginPx;
Sunny Goyal47328fd2016-05-25 18:56:41 -0700397 float minRequiredHeight = dropTargetBarSizePx + workspaceSpringLoadedBottomSpace;
398 workspaceSpringLoadShrinkFactor = Math.min(
399 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f,
400 1 - (minRequiredHeight / expectedWorkspaceHeight));
401 } else {
402 workspaceSpringLoadShrinkFactor =
403 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
404 }
405
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700406 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -0700407 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
408 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Winson Chung0f785722015-04-08 10:27:49 -0700409 }
410
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700411 private void updateAvailableFolderCellDimensions(Resources res) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700412 int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_padding_top)
413 + res.getDimensionPixelSize(R.dimen.folder_label_padding_bottom)
414 + Utilities.calculateTextHeight(res.getDimension(R.dimen.folder_label_text_size));
415
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700416 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700417
Jon Mirandac1b23992016-12-13 08:57:36 -0800418 // Don't let the folder get too close to the edges of the screen.
Jon Miranda1786df32018-09-25 13:05:23 -0700419 int folderMargin = edgeMarginPx * 2;
Sunny Goyal07b69292018-01-08 14:19:34 -0800420 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -0800421
422 // Check if the icons fit within the available height.
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800423 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows;
424 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderBottomPanelSize
425 - folderMargin;
426 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -0800427
428 // Check if the icons fit within the available width.
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800429 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns;
430 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin;
431 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -0800432
433 float scale = Math.min(scaleX, scaleY);
434 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700435 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700436 }
437 }
438
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700439 private void updateFolderCellSize(float scale, Resources res) {
440 folderChildIconSizePx = (int) (ResourceUtils.pxFromDp(inv.iconSize, mInfo.metrics) * scale);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700441 folderChildTextSizePx =
442 (int) (res.getDimensionPixelSize(R.dimen.folder_child_text_size) * scale);
443
444 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
445 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding) * scale);
446 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding) * scale);
447
Jon Mirandac1b23992016-12-13 08:57:36 -0800448 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
Jonathan Miranda9ad87462017-07-26 17:41:02 +0000449 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
450 folderChildDrawablePaddingPx = Math.max(0,
451 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700452 }
453
Winson1f064272016-07-18 17:18:02 -0700454 public void updateInsets(Rect insets) {
455 mInsets.set(insets);
Sunny Goyal07b69292018-01-08 14:19:34 -0800456 updateWorkspacePadding();
Winson1f064272016-07-18 17:18:02 -0700457 }
458
Sunny Goyalae6e3182019-04-30 12:04:37 -0700459 /**
460 * The current device insets. This is generally same as the insets being dispatched to
461 * {@link Insettable} elements, but can differ if the element is using a different profile.
462 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800463 public Rect getInsets() {
464 return mInsets;
465 }
466
Sunny Goyal756cd262015-08-20 12:33:21 -0700467 public Point getCellSize() {
Jon Miranda6f7e9702019-09-16 14:44:14 -0700468 return getCellSize(inv.numColumns, inv.numRows);
469 }
470
471 private Point getCellSize(int numColumns, int numRows) {
Sunny Goyal756cd262015-08-20 12:33:21 -0700472 Point result = new Point();
473 // Since we are only concerned with the overall padding, layout direction does
474 // not matter.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700475 Point padding = getTotalWorkspacePadding();
Jon Miranda18751b62017-07-31 17:25:27 -0700476 result.x = calculateCellWidth(availableWidthPx - padding.x
Jon Miranda6f7e9702019-09-16 14:44:14 -0700477 - cellLayoutPaddingLeftRightPx * 2, numColumns);
Jon Miranda18751b62017-07-31 17:25:27 -0700478 result.y = calculateCellHeight(availableHeightPx - padding.y
Jon Miranda6f7e9702019-09-16 14:44:14 -0700479 - cellLayoutBottomPaddingPx, numRows);
Sunny Goyal756cd262015-08-20 12:33:21 -0700480 return result;
481 }
482
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700483 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -0800484 updateWorkspacePadding();
485 return new Point(workspacePadding.left + workspacePadding.right,
486 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700487 }
488
489 /**
Sunny Goyal07b69292018-01-08 14:19:34 -0800490 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
491 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700492 */
Sunny Goyal07b69292018-01-08 14:19:34 -0800493 private void updateWorkspacePadding() {
494 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -0700495 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -0800496 padding.top = 0;
497 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800498 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700499 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -0700500 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -0700501 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -0700502 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700503 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -0700504 }
Winson Chungb3800242013-10-24 11:01:54 -0700505 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -0700506 int paddingBottom = hotseatBarSizePx + workspacePageIndicatorHeight
507 - mWorkspacePageIndicatorOverlapWorkspace;
Sunny Goyalc6205602015-05-21 20:46:33 -0700508 if (isTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700509 // Pad the left and right of the workspace to ensure consistent spacing
510 // between all icons
Tony Wickhamd6b40372015-09-23 18:37:57 -0700511 // The amount of screen space available for left/right padding.
Sunny Goyal228153d2018-01-04 15:35:22 -0800512 int availablePaddingX = Math.max(0, widthPx - ((inv.numColumns * cellWidthPx) +
Sunny Goyalf5440cb2016-12-14 15:13:00 -0800513 ((inv.numColumns - 1) * cellWidthPx)));
Tony Wickhamd6b40372015-09-23 18:37:57 -0700514 availablePaddingX = (int) Math.min(availablePaddingX,
Sunny Goyal07b69292018-01-08 14:19:34 -0800515 widthPx * MAX_HORIZONTAL_PADDING_PERCENT);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700516 int availablePaddingY = Math.max(0, heightPx - edgeMarginPx - paddingBottom
Jon Mirandac1b08c52016-11-15 14:37:56 -0800517 - (2 * inv.numRows * cellHeightPx) - hotseatBarTopPaddingPx
518 - hotseatBarBottomPaddingPx);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700519 padding.set(availablePaddingX / 2, edgeMarginPx + availablePaddingY / 2,
Tony Wickhamd6b40372015-09-23 18:37:57 -0700520 availablePaddingX / 2, paddingBottom + availablePaddingY / 2);
Winson Chungb3800242013-10-24 11:01:54 -0700521 } else {
522 // Pad the top and bottom of the workspace with search/hotseat bar sizes
Winson1f064272016-07-18 17:18:02 -0700523 padding.set(desiredWorkspaceLeftRightMarginPx,
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700524 edgeMarginPx,
Winson1f064272016-07-18 17:18:02 -0700525 desiredWorkspaceLeftRightMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700526 paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -0700527 }
528 }
Winson Chungb3800242013-10-24 11:01:54 -0700529 }
530
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700531 public Rect getHotseatLayoutPadding() {
532 if (isVerticalBarLayout()) {
533 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700534 mHotseatPadding.set(mInsets.left + hotseatBarSidePaddingStartPx,
535 mInsets.top, hotseatBarSidePaddingEndPx, mInsets.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700536 } else {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700537 mHotseatPadding.set(hotseatBarSidePaddingEndPx, mInsets.top,
538 mInsets.right + hotseatBarSidePaddingStartPx, mInsets.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700539 }
540 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700541 // We want the edges of the hotseat to line up with the edges of the workspace, but the
542 // icons in the hotseat are a different size, and so don't line up perfectly. To account
543 // for this, we pad the left and right of the hotseat with half of the difference of a
544 // workspace cell vs a hotseat cell.
545 float workspaceCellWidth = (float) widthPx / inv.numColumns;
546 float hotseatCellWidth = (float) widthPx / inv.numHotseatIcons;
547 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
548 mHotseatPadding.set(
Sunny Goyal786940a2020-06-02 02:31:31 -0700549 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingLeftRightPx
550 + mInsets.left,
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700551 hotseatBarTopPaddingPx,
Sunny Goyal786940a2020-06-02 02:31:31 -0700552 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx
553 + mInsets.right,
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700554 hotseatBarBottomPaddingPx + mInsets.bottom + cellLayoutBottomPaddingPx);
555 }
556 return mHotseatPadding;
557 }
558
Winsonfadbe8f2016-07-22 16:35:37 -0700559 /**
560 * @return the bounds for which the open folders should be contained within
561 */
562 public Rect getAbsoluteOpenFolderBounds() {
563 if (isVerticalBarLayout()) {
564 // Folders should only appear right of the drop target bar and left of the hotseat
565 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
566 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -0700567 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700568 mInsets.top + availableHeightPx);
569 } else {
570 // Folders should only appear below the drop target bar and above the hotseat
Tony Wickhamb4b7e202018-01-12 17:39:24 -0800571 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700572 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -0800573 mInsets.left + availableWidthPx - edgeMarginPx,
Jon Miranda18751b62017-07-31 17:25:27 -0700574 mInsets.top + availableHeightPx - hotseatBarSizePx
Tony Wickham5edf9e22020-03-27 20:06:52 -0700575 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -0700576 }
577 }
578
Adam Cohen2e6da152015-05-06 11:42:25 -0700579 public static int calculateCellWidth(int width, int countX) {
Winson Chungb3800242013-10-24 11:01:54 -0700580 return width / countX;
581 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700582 public static int calculateCellHeight(int height, int countY) {
Winson Chungb3800242013-10-24 11:01:54 -0700583 return height / countY;
584 }
585
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700586 /**
Tony Wickham55616cd2015-09-23 14:55:17 -0700587 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
588 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
589 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700590 */
Tony Wickhamab946a12015-09-16 15:38:16 -0700591 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -0700592 return isLandscape && transposeLayoutWithOrientation;
593 }
594
Sunny Goyal59d086c2018-05-07 17:31:40 -0700595 /**
Jon Miranda6f7e9702019-09-16 14:44:14 -0700596 * Returns true when the number of workspace columns and all apps columns differs.
597 */
598 private boolean allAppsHasDifferentNumColumns() {
599 return inv.numAllAppsColumns != inv.numColumns;
600 }
601
602 /**
Sunny Goyal59d086c2018-05-07 17:31:40 -0700603 * Updates orientation information and returns true if it has changed from the previous value.
604 */
Winson Chung13c1c2c2019-09-06 11:46:19 -0700605 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -0700606 if (isVerticalBarLayout()) {
Winson Chung13c1c2c2019-09-06 11:46:19 -0700607 boolean isSeascape = DefaultDisplay.INSTANCE.get(context).getInfo().rotation
608 == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -0700609 if (mIsSeascape != isSeascape) {
610 mIsSeascape = isSeascape;
611 return true;
612 }
613 }
614 return false;
615 }
616
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800617 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -0700618 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800619 }
620
Sunny Goyal07b69292018-01-08 14:19:34 -0800621 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyalc6205602015-05-21 20:46:33 -0700622 return isVerticalBarLayout() || isLargeTablet;
Winson Chungb3800242013-10-24 11:01:54 -0700623 }
624
Sunny Goyalc13403c2016-11-18 23:44:48 -0800625 public int getCellHeight(@ContainerType int containerType) {
626 switch (containerType) {
627 case CellLayout.WORKSPACE:
628 return cellHeightPx;
629 case CellLayout.FOLDER:
630 return folderCellHeightPx;
631 case CellLayout.HOTSEAT:
632 return hotseatCellHeightPx;
633 default:
634 // ??
635 return 0;
636 }
637 }
Sunny Goyal13178ac2016-04-04 16:35:22 -0700638
Sunny Goyal1890f672020-04-30 12:28:00 -0700639 private static Context getContext(Context c, DefaultDisplay.Info info, int orientation) {
640 Configuration config = new Configuration(c.getResources().getConfiguration());
641 config.orientation = orientation;
642 config.densityDpi = info.metrics.densityDpi;
643 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700644 }
Sunny Goyalfde55052018-02-01 14:46:13 -0800645
646 /**
647 * Callback when a component changes the DeviceProfile associated with it, as a result of
648 * configuration change
649 */
650 public interface OnDeviceProfileChangeListener {
651
652 /**
653 * Called when the device profile is reassigned. Note that for layout and measurements, it
654 * is sufficient to listen for inset changes. Use this callback when you need to perform
655 * a one time operation.
656 */
657 void onDeviceProfileChanged(DeviceProfile dp);
658 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700659
660 public static class Builder {
661 private Context mContext;
662 private InvariantDeviceProfile mInv;
663 private DefaultDisplay.Info mInfo;
664
Sunny Goyal0addbf02020-04-28 14:17:35 -0700665 private final Point mWindowPosition = new Point();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700666 private Point mMinSize, mMaxSize;
667 private int mWidth, mHeight;
668
669 private boolean mIsLandscape;
670 private boolean mIsMultiWindowMode = false;
671 private boolean mTransposeLayoutWithOrientation;
672
673 public Builder(Context context, InvariantDeviceProfile inv, DefaultDisplay.Info info) {
674 mContext = context;
675 mInv = inv;
676 mInfo = info;
677 mTransposeLayoutWithOrientation = context.getResources()
678 .getBoolean(R.bool.hotseat_transpose_layout_with_orientation);
679 }
680
681 public Builder setSizeRange(Point minSize, Point maxSize) {
682 mMinSize = minSize;
683 mMaxSize = maxSize;
684 return this;
685 }
686
687 public Builder setSize(int width, int height) {
688 mWidth = width;
689 mHeight = height;
690 mIsLandscape = mWidth > mHeight;
691 return this;
692 }
693
694 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
695 mIsMultiWindowMode = isMultiWindowMode;
696 return this;
697 }
698
Sunny Goyal0addbf02020-04-28 14:17:35 -0700699 /**
700 * Sets the window position if not full-screen
701 */
702 public Builder setWindowPosition(int x, int y) {
703 mWindowPosition.set(x, y);
704 return this;
705 }
706
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700707 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
708 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
709 return this;
710 }
711
712 public DeviceProfile build() {
713 return new DeviceProfile(mContext, mInv, mInfo, mMinSize, mMaxSize,
714 mWidth, mHeight, mIsLandscape, mIsMultiWindowMode,
Sunny Goyal0addbf02020-04-28 14:17:35 -0700715 mTransposeLayoutWithOrientation, mWindowPosition);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700716 }
717 }
718
Winson Chungb3800242013-10-24 11:01:54 -0700719}