blob: 4d5bd5d95fe245839a25fb579d789c9c1ec05bda [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);
Alex Chau4e2c25a2021-02-03 16:20:04 +0000171 boolean allowRotation = context.getResources().getBoolean(R.bool.allow_rotation);
172 // Tablet UI is built with assumption that simulated landscape is disabled.
173 isTablet = allowRotation && swDPs >= TABLET_MIN_DPS;
174 isLargeTablet = isTablet && swDPs >= LARGE_TABLET_MIN_DPS;
Sunny Goyalc6205602015-05-21 20:46:33 -0700175 isPhone = !isTablet && !isLargeTablet;
Jon Mirandabba64512019-03-27 10:54:17 -0700176 aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Jon Miranda7e183c32018-06-20 11:05:27 -0700177 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
Sunny Goyalc6205602015-05-21 20:46:33 -0700178
179 // Some more constants
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700180 this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
Winson Chungb3800242013-10-24 11:01:54 -0700181
Sunny Goyal1890f672020-04-30 12:28:00 -0700182 context = getContext(context, info, isVerticalBarLayout()
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700183 ? Configuration.ORIENTATION_LANDSCAPE
184 : Configuration.ORIENTATION_PORTRAIT);
Sunny Goyal1890f672020-04-30 12:28:00 -0700185 final Resources res = context.getResources();
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700186
Winson Chungb3800242013-10-24 11:01:54 -0700187 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Jon Miranda28032002017-07-13 16:18:56 -0700188 desiredWorkspaceLeftRightMarginPx = isVerticalBarLayout() ? 0 : edgeMarginPx;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700189
Jon Miranda5eacbb72018-07-31 11:14:46 -0700190 int cellLayoutPaddingLeftRightMultiplier = !isVerticalBarLayout() && isTablet
191 ? PORTRAIT_TABLET_LEFT_RIGHT_PADDING_MULTIPLIER : 1;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700192 int cellLayoutPadding = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_padding);
193 if (isLandscape) {
194 cellLayoutPaddingLeftRightPx = 0;
195 cellLayoutBottomPaddingPx = cellLayoutPadding;
196 } else {
197 cellLayoutPaddingLeftRightPx = cellLayoutPaddingLeftRightMultiplier * cellLayoutPadding;
198 cellLayoutBottomPaddingPx = 0;
199 }
200
Tony Wickham5edf9e22020-03-27 20:06:52 -0700201 workspacePageIndicatorHeight = res.getDimensionPixelSize(
202 R.dimen.workspace_page_indicator_height);
203 mWorkspacePageIndicatorOverlapWorkspace =
204 res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700205
Winson Chungb3800242013-10-24 11:01:54 -0700206 iconDrawablePaddingOriginalPx =
207 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700208 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
209 workspaceSpringLoadedBottomSpace =
210 res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space);
Sunny Goyald5190522017-04-24 03:06:54 -0700211
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700212 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700213
Winson1f064272016-07-18 17:18:02 -0700214 hotseatBarTopPaddingPx =
215 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding);
Jon Miranda7e183c32018-06-20 11:05:27 -0700216 hotseatBarBottomPaddingPx = (isTallDevice ? 0
217 : res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_non_tall_padding))
218 + res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_padding);
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700219 hotseatBarSidePaddingEndPx =
Sunny Goyal228153d2018-01-04 15:35:22 -0800220 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda3f411e72019-05-16 17:15:16 -0700221 // Add a bit of space between nav bar and hotseat in vertical bar layout.
Tony Wickham5edf9e22020-03-27 20:06:52 -0700222 hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700223 hotseatBarSizePx = ResourceUtils.pxFromDp(inv.iconSize, mInfo.metrics)
224 + (isVerticalBarLayout()
Sunny Goyal415f1732018-11-29 10:33:47 -0800225 ? (hotseatBarSidePaddingStartPx + hotseatBarSidePaddingEndPx)
226 : (res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_extra_vertical_size)
227 + hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx));
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700228
Jon Miranda2ed276e2017-06-29 11:36:34 -0700229 // Calculate all of the remaining variables.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700230 updateAvailableDimensions(res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700231
232 // Now that we have all of the variables calculated, we can tune certain sizes.
Jon Miranda30d0aa22017-07-25 15:55:29 -0700233 if (!isVerticalBarLayout() && isPhone && isTallDevice) {
Jon Miranda3f9bab22017-07-28 14:50:17 -0700234 // We increase the hotseat size when there is extra space.
Jon Miranda2ed276e2017-06-29 11:36:34 -0700235 // ie. For a display with a large aspect ratio, we can keep the icons on the workspace
Jon Miranda3f9bab22017-07-28 14:50:17 -0700236 // in portrait mode closer together by adding more height to the hotseat.
Jon Miranda30d0aa22017-07-25 15:55:29 -0700237 // Note: This calculation was created after noticing a pattern in the design spec.
Jon Miranda7e183c32018-06-20 11:05:27 -0700238 int extraSpace = getCellSize().y - iconSizePx - iconDrawablePaddingPx * 2
Tony Wickham5edf9e22020-03-27 20:06:52 -0700239 - workspacePageIndicatorHeight;
Jon Miranda7e183c32018-06-20 11:05:27 -0700240 hotseatBarSizePx += extraSpace;
241 hotseatBarBottomPaddingPx += extraSpace;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700242
Jon Miranda3f9bab22017-07-28 14:50:17 -0700243 // Recalculate the available dimensions using the new hotseat size.
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700244 updateAvailableDimensions(res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700245 }
Sunny Goyal07b69292018-01-08 14:19:34 -0800246 updateWorkspacePadding();
Tony Wickham1237df02017-02-24 08:59:36 -0800247
248 // This is done last, after iconSizePx is calculated above.
Samuel Fufac96fa242019-09-26 23:06:32 -0700249 mDotRendererWorkSpace = new DotRenderer(iconSizePx, IconShape.getShapePath(),
Tony Wickhame1cb93f2019-05-03 11:27:32 -0700250 IconShape.DEFAULT_PATH_SIZE);
Samuel Fufac96fa242019-09-26 23:06:32 -0700251 mDotRendererAllApps = iconSizePx == allAppsIconSizePx ? mDotRendererWorkSpace :
252 new DotRenderer(allAppsIconSizePx, IconShape.getShapePath(),
253 IconShape.DEFAULT_PATH_SIZE);
Adam Cohen63f1ec02014-08-12 09:23:13 -0700254 }
255
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700256 public Builder toBuilder(Context context) {
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800257 Point size = new Point(availableWidthPx, availableHeightPx);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700258 return new Builder(context, inv, mInfo)
259 .setSizeRange(size, size)
260 .setSize(widthPx, heightPx)
Sunny Goyal0addbf02020-04-28 14:17:35 -0700261 .setWindowPosition(windowX, windowY)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700262 .setMultiWindowMode(isMultiWindowMode);
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800263 }
264
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700265 public DeviceProfile copy(Context context) {
266 return toBuilder(context).build();
267 }
268
269 /**
270 * TODO: Move this to the builder as part of setMultiWindowMode
271 */
Sunny Goyalb46703d2020-05-27 17:52:03 -0700272 public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) {
Jon Mirandaa11380d2017-08-24 11:30:03 -0700273 // We take the minimum sizes of this profile and it's multi-window variant to ensure that
274 // the system decor is always excluded.
Sunny Goyalb46703d2020-05-27 17:52:03 -0700275 Point mwSize = new Point(Math.min(availableWidthPx, windowBounds.availableSize.x),
276 Math.min(availableHeightPx, windowBounds.availableSize.y));
Jon Mirandaa11380d2017-08-24 11:30:03 -0700277
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700278 DeviceProfile profile = toBuilder(context)
279 .setSizeRange(mwSize, mwSize)
Sunny Goyalb46703d2020-05-27 17:52:03 -0700280 .setSize(windowBounds.bounds.width(), windowBounds.bounds.height())
281 .setWindowPosition(windowBounds.bounds.left, windowBounds.bounds.top)
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700282 .setMultiWindowMode(true)
283 .build();
Jon Miranda93e1f042016-11-11 14:13:04 -0800284
Jon Miranda0cd04572017-09-19 11:31:42 -0700285 // If there isn't enough vertical cell padding with the labels displayed, hide the labels.
286 float workspaceCellPaddingY = profile.getCellSize().y - profile.iconSizePx
287 - iconDrawablePaddingPx - profile.iconTextSizePx;
288 if (workspaceCellPaddingY < profile.iconDrawablePaddingPx * 2) {
289 profile.adjustToHideWorkspaceLabels();
290 }
Jon Miranda93e1f042016-11-11 14:13:04 -0800291
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800292 // We use these scales to measure and layout the widgets using their full invariant profile
293 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
294 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
295 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
296 profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY);
Sunny Goyal07b69292018-01-08 14:19:34 -0800297 profile.updateWorkspacePadding();
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800298
Jon Miranda93e1f042016-11-11 14:13:04 -0800299 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700300 }
301
Adam Cohen63f1ec02014-08-12 09:23:13 -0700302 /**
Sunny Goyalb46703d2020-05-27 17:52:03 -0700303 * Inverse of {@link #getMultiWindowProfile(Context, WindowBounds)}
Sunny Goyal2e2e2b42018-02-27 16:52:55 -0800304 * @return device profile corresponding to the current orientation in non multi-window mode.
305 */
306 public DeviceProfile getFullScreenProfile() {
307 return isLandscape ? inv.landscapeProfile : inv.portraitProfile;
308 }
309
310 /**
Jon Miranda1091e532017-07-21 13:31:50 -0700311 * Adjusts the profile so that the labels on the Workspace are hidden.
312 * It is important to call this method after the All Apps variables have been set.
313 */
314 private void adjustToHideWorkspaceLabels() {
315 iconTextSizePx = 0;
316 iconDrawablePaddingPx = 0;
317 cellHeightPx = iconSizePx;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700318 autoResizeAllAppsCells();
319 }
Jon Miranda1091e532017-07-21 13:31:50 -0700320
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700321 /**
322 * Re-computes the all-apps cell size to be independent of workspace
323 */
324 public void autoResizeAllAppsCells() {
Jon Miranda3f9bab22017-07-28 14:50:17 -0700325 int topBottomPadding = allAppsIconDrawablePaddingPx * (isVerticalBarLayout() ? 2 : 1);
Jon Miranda1091e532017-07-21 13:31:50 -0700326 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
327 + Utilities.calculateTextHeight(allAppsIconTextSizePx)
Jon Miranda3f9bab22017-07-28 14:50:17 -0700328 + topBottomPadding * 2;
Jon Miranda1091e532017-07-21 13:31:50 -0700329 }
330
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700331 private void updateAvailableDimensions(Resources res) {
332 updateIconSize(1f, res);
Winson Chung59a488a2013-12-10 12:32:14 -0800333
Jon Mirandabf7d8122016-11-03 15:29:29 -0700334 // Check to see if the icons fit within the available height. If not, then scale down.
335 float usedHeight = (cellHeightPx * inv.numRows);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700336 int maxHeight = (availableHeightPx - getTotalWorkspacePadding().y);
Winson Chungb3800242013-10-24 11:01:54 -0700337 if (usedHeight > maxHeight) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700338 float scale = maxHeight / usedHeight;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700339 updateIconSize(scale, res);
Winson Chungb3800242013-10-24 11:01:54 -0700340 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700341 updateAvailableFolderCellDimensions(res);
Winson Chungb3800242013-10-24 11:01:54 -0700342 }
343
Jon Miranda6f7e9702019-09-16 14:44:14 -0700344 /**
345 * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
346 * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
347 * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
348 */
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700349 private void updateIconSize(float scale, Resources res) {
Jon Miranda18751b62017-07-31 17:25:27 -0700350 // Workspace
Sunny Goyal07b69292018-01-08 14:19:34 -0800351 final boolean isVerticalLayout = isVerticalBarLayout();
Jon Miranda6f7e9702019-09-16 14:44:14 -0700352 float invIconSizeDp = isVerticalLayout ? inv.landscapeIconSize : inv.iconSize;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700353 iconSizePx = Math.max(1, (int) (ResourceUtils.pxFromDp(invIconSizeDp, mInfo.metrics)
354 * scale));
355 iconTextSizePx = (int) (Utilities.pxFromSp(inv.iconTextSize, mInfo.metrics) * scale);
Jon Miranda09660722017-06-14 14:20:14 -0700356 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * scale);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700357
Jon Miranda18751b62017-07-31 17:25:27 -0700358 cellHeightPx = iconSizePx + iconDrawablePaddingPx
359 + Utilities.calculateTextHeight(iconTextSizePx);
Jon Miranda846455e2017-10-02 14:58:52 -0700360 int cellYPadding = (getCellSize().y - cellHeightPx) / 2;
Sunny Goyal07b69292018-01-08 14:19:34 -0800361 if (iconDrawablePaddingPx > cellYPadding && !isVerticalLayout
Sunny Goyald70e75a2018-02-22 10:07:32 -0800362 && !isMultiWindowMode) {
Jon Miranda846455e2017-10-02 14:58:52 -0700363 // Ensures that the label is closer to its corresponding icon. This is not an issue
364 // with vertical bar layout or multi-window mode since the issue is handled separately
365 // with their calls to {@link #adjustToHideWorkspaceLabels}.
366 cellHeightPx -= (iconDrawablePaddingPx - cellYPadding);
367 iconDrawablePaddingPx = cellYPadding;
368 }
369 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700370
Sunny Goyalae190ff2020-04-14 00:19:01 +0000371 // All apps
372 if (allAppsHasDifferentNumColumns()) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700373 allAppsIconSizePx = ResourceUtils.pxFromDp(inv.allAppsIconSize, mInfo.metrics);
374 allAppsIconTextSizePx = Utilities.pxFromSp(inv.allAppsIconTextSize, mInfo.metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000375 allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
Jon Miranda35359442020-07-09 14:54:23 -0700376 // We use 4 below to ensure labels are closer to their corresponding icon.
377 allAppsCellHeightPx = Math.round(allAppsIconSizePx + allAppsIconTextSizePx
378 + (4 * allAppsIconDrawablePaddingPx));
Sunny Goyalae190ff2020-04-14 00:19:01 +0000379 } else {
380 allAppsIconSizePx = iconSizePx;
381 allAppsIconTextSizePx = iconTextSizePx;
382 allAppsIconDrawablePaddingPx = iconDrawablePaddingPx;
383 allAppsCellHeightPx = getCellSize().y;
384 }
385 allAppsCellWidthPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700386
Jon Miranda6f7e9702019-09-16 14:44:14 -0700387 if (isVerticalBarLayout()) {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700388 // Always hide the Workspace text with vertical bar layout.
Jon Miranda1091e532017-07-21 13:31:50 -0700389 adjustToHideWorkspaceLabels();
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700390 }
Winson Chungb3800242013-10-24 11:01:54 -0700391
Winson Chungb3800242013-10-24 11:01:54 -0700392 // Hotseat
Sunny Goyal07b69292018-01-08 14:19:34 -0800393 if (isVerticalLayout) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700394 hotseatBarSizePx = iconSizePx + hotseatBarSidePaddingStartPx
395 + hotseatBarSidePaddingEndPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700396 }
Jon Miranda5044c352017-08-09 11:37:59 -0700397 hotseatCellHeightPx = iconSizePx;
Winson Chungb3800242013-10-24 11:01:54 -0700398
Sunny Goyal07b69292018-01-08 14:19:34 -0800399 if (!isVerticalLayout) {
Jon Miranda18751b62017-07-31 17:25:27 -0700400 int expectedWorkspaceHeight = availableHeightPx - hotseatBarSizePx
Tony Wickham5edf9e22020-03-27 20:06:52 -0700401 - workspacePageIndicatorHeight - edgeMarginPx;
Sunny Goyal47328fd2016-05-25 18:56:41 -0700402 float minRequiredHeight = dropTargetBarSizePx + workspaceSpringLoadedBottomSpace;
403 workspaceSpringLoadShrinkFactor = Math.min(
404 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f,
405 1 - (minRequiredHeight / expectedWorkspaceHeight));
406 } else {
407 workspaceSpringLoadShrinkFactor =
408 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
409 }
410
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700411 // Folder icon
Jon Miranda591e3602018-03-28 11:37:00 -0700412 folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
413 folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;
Winson Chung0f785722015-04-08 10:27:49 -0700414 }
415
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700416 private void updateAvailableFolderCellDimensions(Resources res) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700417 int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_padding_top)
418 + res.getDimensionPixelSize(R.dimen.folder_label_padding_bottom)
419 + Utilities.calculateTextHeight(res.getDimension(R.dimen.folder_label_text_size));
420
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700421 updateFolderCellSize(1f, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700422
Jon Mirandac1b23992016-12-13 08:57:36 -0800423 // Don't let the folder get too close to the edges of the screen.
Jon Miranda1786df32018-09-25 13:05:23 -0700424 int folderMargin = edgeMarginPx * 2;
Sunny Goyal07b69292018-01-08 14:19:34 -0800425 Point totalWorkspacePadding = getTotalWorkspacePadding();
Jon Mirandac1b23992016-12-13 08:57:36 -0800426
427 // Check if the icons fit within the available height.
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800428 float contentUsedHeight = folderCellHeightPx * inv.numFolderRows;
429 int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderBottomPanelSize
430 - folderMargin;
431 float scaleY = contentMaxHeight / contentUsedHeight;
Jon Mirandac1b23992016-12-13 08:57:36 -0800432
433 // Check if the icons fit within the available width.
Samuel Fufa1c8d90a2019-11-12 17:54:58 -0800434 float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns;
435 int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin;
436 float scaleX = contentMaxWidth / contentUsedWidth;
Jon Mirandac1b23992016-12-13 08:57:36 -0800437
438 float scale = Math.min(scaleX, scaleY);
439 if (scale < 1f) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700440 updateFolderCellSize(scale, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700441 }
442 }
443
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700444 private void updateFolderCellSize(float scale, Resources res) {
445 folderChildIconSizePx = (int) (ResourceUtils.pxFromDp(inv.iconSize, mInfo.metrics) * scale);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700446 folderChildTextSizePx =
447 (int) (res.getDimensionPixelSize(R.dimen.folder_child_text_size) * scale);
448
449 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
450 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding) * scale);
451 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding) * scale);
452
Jon Mirandac1b23992016-12-13 08:57:36 -0800453 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
Jonathan Miranda9ad87462017-07-26 17:41:02 +0000454 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
455 folderChildDrawablePaddingPx = Math.max(0,
456 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700457 }
458
Winson1f064272016-07-18 17:18:02 -0700459 public void updateInsets(Rect insets) {
460 mInsets.set(insets);
Sunny Goyal07b69292018-01-08 14:19:34 -0800461 updateWorkspacePadding();
Winson1f064272016-07-18 17:18:02 -0700462 }
463
Sunny Goyalae6e3182019-04-30 12:04:37 -0700464 /**
465 * The current device insets. This is generally same as the insets being dispatched to
466 * {@link Insettable} elements, but can differ if the element is using a different profile.
467 */
Sunny Goyal1a52ef52018-01-11 10:15:03 -0800468 public Rect getInsets() {
469 return mInsets;
470 }
471
Sunny Goyal756cd262015-08-20 12:33:21 -0700472 public Point getCellSize() {
Jon Miranda6f7e9702019-09-16 14:44:14 -0700473 return getCellSize(inv.numColumns, inv.numRows);
474 }
475
476 private Point getCellSize(int numColumns, int numRows) {
Sunny Goyal756cd262015-08-20 12:33:21 -0700477 Point result = new Point();
478 // Since we are only concerned with the overall padding, layout direction does
479 // not matter.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700480 Point padding = getTotalWorkspacePadding();
Jon Miranda18751b62017-07-31 17:25:27 -0700481 result.x = calculateCellWidth(availableWidthPx - padding.x
Jon Miranda6f7e9702019-09-16 14:44:14 -0700482 - cellLayoutPaddingLeftRightPx * 2, numColumns);
Jon Miranda18751b62017-07-31 17:25:27 -0700483 result.y = calculateCellHeight(availableHeightPx - padding.y
Jon Miranda6f7e9702019-09-16 14:44:14 -0700484 - cellLayoutBottomPaddingPx, numRows);
Sunny Goyal756cd262015-08-20 12:33:21 -0700485 return result;
486 }
487
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700488 public Point getTotalWorkspacePadding() {
Sunny Goyal07b69292018-01-08 14:19:34 -0800489 updateWorkspacePadding();
490 return new Point(workspacePadding.left + workspacePadding.right,
491 workspacePadding.top + workspacePadding.bottom);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700492 }
493
494 /**
Sunny Goyal07b69292018-01-08 14:19:34 -0800495 * Updates {@link #workspacePadding} as a result of any internal value change to reflect the
496 * new workspace padding
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700497 */
Sunny Goyal07b69292018-01-08 14:19:34 -0800498 private void updateWorkspacePadding() {
499 Rect padding = workspacePadding;
Tony Wickham3a3517f2015-10-06 11:27:04 -0700500 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -0800501 padding.top = 0;
502 padding.bottom = edgeMarginPx;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800503 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700504 padding.left = hotseatBarSizePx;
Tony Wickham5edf9e22020-03-27 20:06:52 -0700505 padding.right = hotseatBarSidePaddingStartPx;
Winson1f064272016-07-18 17:18:02 -0700506 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -0700507 padding.left = hotseatBarSidePaddingStartPx;
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700508 padding.right = hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -0700509 }
Winson Chungb3800242013-10-24 11:01:54 -0700510 } else {
Tony Wickham5edf9e22020-03-27 20:06:52 -0700511 int paddingBottom = hotseatBarSizePx + workspacePageIndicatorHeight
512 - mWorkspacePageIndicatorOverlapWorkspace;
Sunny Goyalc6205602015-05-21 20:46:33 -0700513 if (isTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700514 // Pad the left and right of the workspace to ensure consistent spacing
515 // between all icons
Tony Wickhamd6b40372015-09-23 18:37:57 -0700516 // The amount of screen space available for left/right padding.
Sunny Goyal228153d2018-01-04 15:35:22 -0800517 int availablePaddingX = Math.max(0, widthPx - ((inv.numColumns * cellWidthPx) +
Sunny Goyalf5440cb2016-12-14 15:13:00 -0800518 ((inv.numColumns - 1) * cellWidthPx)));
Tony Wickhamd6b40372015-09-23 18:37:57 -0700519 availablePaddingX = (int) Math.min(availablePaddingX,
Sunny Goyal07b69292018-01-08 14:19:34 -0800520 widthPx * MAX_HORIZONTAL_PADDING_PERCENT);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700521 int availablePaddingY = Math.max(0, heightPx - edgeMarginPx - paddingBottom
Jon Mirandac1b08c52016-11-15 14:37:56 -0800522 - (2 * inv.numRows * cellHeightPx) - hotseatBarTopPaddingPx
523 - hotseatBarBottomPaddingPx);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700524 padding.set(availablePaddingX / 2, edgeMarginPx + availablePaddingY / 2,
Tony Wickhamd6b40372015-09-23 18:37:57 -0700525 availablePaddingX / 2, paddingBottom + availablePaddingY / 2);
Winson Chungb3800242013-10-24 11:01:54 -0700526 } else {
527 // Pad the top and bottom of the workspace with search/hotseat bar sizes
Winson1f064272016-07-18 17:18:02 -0700528 padding.set(desiredWorkspaceLeftRightMarginPx,
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700529 edgeMarginPx,
Winson1f064272016-07-18 17:18:02 -0700530 desiredWorkspaceLeftRightMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700531 paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -0700532 }
533 }
Winson Chungb3800242013-10-24 11:01:54 -0700534 }
535
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700536 public Rect getHotseatLayoutPadding() {
537 if (isVerticalBarLayout()) {
538 if (isSeascape()) {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700539 mHotseatPadding.set(mInsets.left + hotseatBarSidePaddingStartPx,
540 mInsets.top, hotseatBarSidePaddingEndPx, mInsets.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700541 } else {
Tony Wickham1eeffbe2018-06-12 15:01:15 -0700542 mHotseatPadding.set(hotseatBarSidePaddingEndPx, mInsets.top,
543 mInsets.right + hotseatBarSidePaddingStartPx, mInsets.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700544 }
545 } else {
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700546 // We want the edges of the hotseat to line up with the edges of the workspace, but the
547 // icons in the hotseat are a different size, and so don't line up perfectly. To account
548 // for this, we pad the left and right of the hotseat with half of the difference of a
549 // workspace cell vs a hotseat cell.
550 float workspaceCellWidth = (float) widthPx / inv.numColumns;
551 float hotseatCellWidth = (float) widthPx / inv.numHotseatIcons;
552 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
553 mHotseatPadding.set(
Sunny Goyal786940a2020-06-02 02:31:31 -0700554 hotseatAdjustment + workspacePadding.left + cellLayoutPaddingLeftRightPx
555 + mInsets.left,
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700556 hotseatBarTopPaddingPx,
Sunny Goyal786940a2020-06-02 02:31:31 -0700557 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx
558 + mInsets.right,
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700559 hotseatBarBottomPaddingPx + mInsets.bottom + cellLayoutBottomPaddingPx);
560 }
561 return mHotseatPadding;
562 }
563
Winsonfadbe8f2016-07-22 16:35:37 -0700564 /**
565 * @return the bounds for which the open folders should be contained within
566 */
567 public Rect getAbsoluteOpenFolderBounds() {
568 if (isVerticalBarLayout()) {
569 // Folders should only appear right of the drop target bar and left of the hotseat
570 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
571 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -0700572 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700573 mInsets.top + availableHeightPx);
574 } else {
575 // Folders should only appear below the drop target bar and above the hotseat
Tony Wickhamb4b7e202018-01-12 17:39:24 -0800576 return new Rect(mInsets.left + edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700577 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
Tony Wickhamb4b7e202018-01-12 17:39:24 -0800578 mInsets.left + availableWidthPx - edgeMarginPx,
Jon Miranda18751b62017-07-31 17:25:27 -0700579 mInsets.top + availableHeightPx - hotseatBarSizePx
Tony Wickham5edf9e22020-03-27 20:06:52 -0700580 - workspacePageIndicatorHeight - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -0700581 }
582 }
583
Adam Cohen2e6da152015-05-06 11:42:25 -0700584 public static int calculateCellWidth(int width, int countX) {
Winson Chungb3800242013-10-24 11:01:54 -0700585 return width / countX;
586 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700587 public static int calculateCellHeight(int height, int countY) {
Winson Chungb3800242013-10-24 11:01:54 -0700588 return height / countY;
589 }
590
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700591 /**
Tony Wickham55616cd2015-09-23 14:55:17 -0700592 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
593 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
594 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700595 */
Tony Wickhamab946a12015-09-16 15:38:16 -0700596 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -0700597 return isLandscape && transposeLayoutWithOrientation;
598 }
599
Sunny Goyal59d086c2018-05-07 17:31:40 -0700600 /**
Jon Miranda6f7e9702019-09-16 14:44:14 -0700601 * Returns true when the number of workspace columns and all apps columns differs.
602 */
603 private boolean allAppsHasDifferentNumColumns() {
604 return inv.numAllAppsColumns != inv.numColumns;
605 }
606
607 /**
Sunny Goyal59d086c2018-05-07 17:31:40 -0700608 * Updates orientation information and returns true if it has changed from the previous value.
609 */
Winson Chung13c1c2c2019-09-06 11:46:19 -0700610 public boolean updateIsSeascape(Context context) {
Sunny Goyal59d086c2018-05-07 17:31:40 -0700611 if (isVerticalBarLayout()) {
Schneider Victor-tulias954bb632021-01-27 14:03:51 -0800612 // Check an up-to-date info.
613 boolean isSeascape = DisplayController.getDefaultDisplay(context)
614 .createInfoForContext(context).rotation == Surface.ROTATION_270;
Sunny Goyal59d086c2018-05-07 17:31:40 -0700615 if (mIsSeascape != isSeascape) {
616 mIsSeascape = isSeascape;
617 return true;
618 }
619 }
620 return false;
621 }
622
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800623 public boolean isSeascape() {
Sunny Goyal59d086c2018-05-07 17:31:40 -0700624 return isVerticalBarLayout() && mIsSeascape;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -0800625 }
626
Sunny Goyal07b69292018-01-08 14:19:34 -0800627 public boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyalc6205602015-05-21 20:46:33 -0700628 return isVerticalBarLayout() || isLargeTablet;
Winson Chungb3800242013-10-24 11:01:54 -0700629 }
630
Sunny Goyalc13403c2016-11-18 23:44:48 -0800631 public int getCellHeight(@ContainerType int containerType) {
632 switch (containerType) {
633 case CellLayout.WORKSPACE:
634 return cellHeightPx;
635 case CellLayout.FOLDER:
636 return folderCellHeightPx;
637 case CellLayout.HOTSEAT:
638 return hotseatCellHeightPx;
639 default:
640 // ??
641 return 0;
642 }
643 }
Sunny Goyal13178ac2016-04-04 16:35:22 -0700644
Sunny Goyalfd58da62020-08-11 12:06:49 -0700645 private static Context getContext(Context c, Info info, int orientation) {
Sunny Goyal1890f672020-04-30 12:28:00 -0700646 Configuration config = new Configuration(c.getResources().getConfiguration());
647 config.orientation = orientation;
648 config.densityDpi = info.metrics.densityDpi;
649 return c.createConfigurationContext(config);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700650 }
Sunny Goyalfde55052018-02-01 14:46:13 -0800651
652 /**
653 * Callback when a component changes the DeviceProfile associated with it, as a result of
654 * configuration change
655 */
656 public interface OnDeviceProfileChangeListener {
657
658 /**
659 * Called when the device profile is reassigned. Note that for layout and measurements, it
660 * is sufficient to listen for inset changes. Use this callback when you need to perform
661 * a one time operation.
662 */
663 void onDeviceProfileChanged(DeviceProfile dp);
664 }
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700665
666 public static class Builder {
667 private Context mContext;
668 private InvariantDeviceProfile mInv;
Sunny Goyalfd58da62020-08-11 12:06:49 -0700669 private Info mInfo;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700670
Sunny Goyal0addbf02020-04-28 14:17:35 -0700671 private final Point mWindowPosition = new Point();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700672 private Point mMinSize, mMaxSize;
673 private int mWidth, mHeight;
674
675 private boolean mIsLandscape;
676 private boolean mIsMultiWindowMode = false;
677 private boolean mTransposeLayoutWithOrientation;
678
Sunny Goyalfd58da62020-08-11 12:06:49 -0700679 public Builder(Context context, InvariantDeviceProfile inv, Info info) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700680 mContext = context;
681 mInv = inv;
682 mInfo = info;
683 mTransposeLayoutWithOrientation = context.getResources()
684 .getBoolean(R.bool.hotseat_transpose_layout_with_orientation);
685 }
686
687 public Builder setSizeRange(Point minSize, Point maxSize) {
688 mMinSize = minSize;
689 mMaxSize = maxSize;
690 return this;
691 }
692
693 public Builder setSize(int width, int height) {
694 mWidth = width;
695 mHeight = height;
696 mIsLandscape = mWidth > mHeight;
697 return this;
698 }
699
700 public Builder setMultiWindowMode(boolean isMultiWindowMode) {
701 mIsMultiWindowMode = isMultiWindowMode;
702 return this;
703 }
704
Sunny Goyal0addbf02020-04-28 14:17:35 -0700705 /**
706 * Sets the window position if not full-screen
707 */
708 public Builder setWindowPosition(int x, int y) {
709 mWindowPosition.set(x, y);
710 return this;
711 }
712
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700713 public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) {
714 mTransposeLayoutWithOrientation = transposeLayoutWithOrientation;
715 return this;
716 }
717
718 public DeviceProfile build() {
719 return new DeviceProfile(mContext, mInv, mInfo, mMinSize, mMaxSize,
720 mWidth, mHeight, mIsLandscape, mIsMultiWindowMode,
Sunny Goyal0addbf02020-04-28 14:17:35 -0700721 mTransposeLayoutWithOrientation, mWindowPosition);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700722 }
723 }
724
Winson Chungb3800242013-10-24 11:01:54 -0700725}