blob: 52b124955a83427b0d340e6b79c09be5e3aa8fe9 [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
19import android.appwidget.AppWidgetHostView;
20import android.content.ComponentName;
21import android.content.Context;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070022import android.content.res.Configuration;
Winson Chungb3800242013-10-24 11:01:54 -070023import android.content.res.Resources;
Winson Chungb3800242013-10-24 11:01:54 -070024import android.graphics.Point;
Jon Miranda7ae64ff2016-11-21 16:18:46 -080025import android.graphics.PointF;
Winson Chungb3800242013-10-24 11:01:54 -070026import android.graphics.Rect;
27import android.util.DisplayMetrics;
Winson Chungb3800242013-10-24 11:01:54 -070028import android.view.Gravity;
Winson Chungb3800242013-10-24 11:01:54 -070029import android.view.View;
30import android.view.ViewGroup.LayoutParams;
Winson Chungb3800242013-10-24 11:01:54 -070031import android.widget.FrameLayout;
32
Sunny Goyalc13403c2016-11-18 23:44:48 -080033import com.android.launcher3.CellLayout.ContainerType;
Mario Bertschlerac9408a2017-10-18 10:31:36 -070034import com.android.launcher3.allapps.AllAppsContainerView;
Tony Wickham9a8d11f2017-01-11 09:53:12 -080035import com.android.launcher3.badge.BadgeRenderer;
Sunny Goyalb532dfe2017-12-13 17:16:54 -080036import com.android.launcher3.views.AllAppsScrim;
Tony Wickhame0c33232016-02-08 11:37:04 -080037
Winson1f064272016-07-18 17:18:02 -070038import java.util.ArrayList;
39
Winson Chungb3800242013-10-24 11:01:54 -070040public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070041
Winson1f064272016-07-18 17:18:02 -070042 public interface LauncherLayoutChangeListener {
43 void onLauncherLayoutChanged();
44 }
45
Adam Cohen2e6da152015-05-06 11:42:25 -070046 public final InvariantDeviceProfile inv;
Winson Chungbe876472014-05-14 14:15:20 -070047
Sunny Goyalc6205602015-05-21 20:46:33 -070048 // Device properties
49 public final boolean isTablet;
50 public final boolean isLargeTablet;
51 public final boolean isPhone;
52 public final boolean transposeLayoutWithOrientation;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -070053
Sunny Goyalc6205602015-05-21 20:46:33 -070054 // Device properties in current orientation
55 public final boolean isLandscape;
56 public final int widthPx;
57 public final int heightPx;
58 public final int availableWidthPx;
59 public final int availableHeightPx;
Tony Wickhamd6b40372015-09-23 18:37:57 -070060 /**
61 * The maximum amount of left/right workspace padding as a percentage of the screen width.
62 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
63 * 7% of the screen width can be used as right padding.
64 */
65 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -070066
Jon Miranda3f9bab22017-07-28 14:50:17 -070067 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda30d0aa22017-07-25 15:55:29 -070068
Winson Chungb3800242013-10-24 11:01:54 -070069
Sunny Goyalc6205602015-05-21 20:46:33 -070070 // Workspace
Jon Miranda28032002017-07-13 16:18:56 -070071 private final int desiredWorkspaceLeftRightMarginPx;
72 public final int cellLayoutPaddingLeftRightPx;
Jon Miranda18751b62017-07-31 17:25:27 -070073 public final int cellLayoutBottomPaddingPx;
Sunny Goyalc6205602015-05-21 20:46:33 -070074 public final int edgeMarginPx;
75 public final Rect defaultWidgetPadding;
Sunny Goyalc6205602015-05-21 20:46:33 -070076 private final int defaultPageSpacingPx;
Sunny Goyal47328fd2016-05-25 18:56:41 -070077 private final int topWorkspacePadding;
Sunny Goyal47328fd2016-05-25 18:56:41 -070078 public float workspaceSpringLoadShrinkFactor;
79 public final int workspaceSpringLoadedBottomSpace;
Sunny Goyalc6205602015-05-21 20:46:33 -070080
Winson1f064272016-07-18 17:18:02 -070081 // Page indicator
Jon Miranda2ed276e2017-06-29 11:36:34 -070082 private int pageIndicatorSizePx;
Winson1f064272016-07-18 17:18:02 -070083
Sunny Goyalc6205602015-05-21 20:46:33 -070084 // Workspace icons
85 public int iconSizePx;
86 public int iconTextSizePx;
87 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -070088 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -070089
Adam Cohen59400422014-03-05 18:07:04 -080090 public int cellWidthPx;
91 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070092 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -080093
Sunny Goyalc6205602015-05-21 20:46:33 -070094 // Folder
95 public int folderBackgroundOffset;
96 public int folderIconSizePx;
Adam Cohenefca0272016-02-24 19:19:06 -080097 public int folderIconPreviewPadding;
Jon Mirandabf7d8122016-11-03 15:29:29 -070098
99 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700100 public int folderCellWidthPx;
101 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700102
103 // Folder child
104 public int folderChildIconSizePx;
105 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700106 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700107
Sunny Goyalc6205602015-05-21 20:46:33 -0700108 // Hotseat
Sunny Goyalc6205602015-05-21 20:46:33 -0700109 public int hotseatCellHeightPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700110 // In portrait: size = height, in landscape: size = width
111 public int hotseatBarSizePx;
Sunny Goyal0dc1db42017-05-17 11:34:33 -0700112 public int hotseatBarTopPaddingPx;
113 public int hotseatBarBottomPaddingPx;
Sunny Goyal228153d2018-01-04 15:35:22 -0800114 public int hotseatBarSidePaddingPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700115
Sunny Goyalc6205602015-05-21 20:46:33 -0700116 // All apps
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700117 public int allAppsCellHeightPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700118 public int allAppsNumCols;
119 public int allAppsNumPredictiveCols;
Sunny Goyalc6205602015-05-21 20:46:33 -0700120 public int allAppsButtonVisualSize;
Winson1f064272016-07-18 17:18:02 -0700121 public int allAppsIconSizePx;
122 public int allAppsIconDrawablePaddingPx;
123 public float allAppsIconTextSizePx;
124
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800125 // Widgets
126 public final PointF appWidgetScale = new PointF(1.0f, 1.0f);
127
Sunny Goyal47328fd2016-05-25 18:56:41 -0700128 // Drop Target
129 public int dropTargetBarSizePx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700130
Winson1f064272016-07-18 17:18:02 -0700131 // Insets
132 private Rect mInsets = new Rect();
133
134 // Listeners
135 private ArrayList<LauncherLayoutChangeListener> mListeners = new ArrayList<>();
136
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800137 // Icon badges
138 public BadgeRenderer mBadgeRenderer;
139
Sunny Goyalc6205602015-05-21 20:46:33 -0700140 public DeviceProfile(Context context, InvariantDeviceProfile inv,
141 Point minSize, Point maxSize,
142 int width, int height, boolean isLandscape) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700143
Adam Cohen2e6da152015-05-06 11:42:25 -0700144 this.inv = inv;
Sunny Goyalc6205602015-05-21 20:46:33 -0700145 this.isLandscape = isLandscape;
Winson Chungb3800242013-10-24 11:01:54 -0700146
Adam Cohen2e6da152015-05-06 11:42:25 -0700147 Resources res = context.getResources();
Winson Chungb3800242013-10-24 11:01:54 -0700148 DisplayMetrics dm = res.getDisplayMetrics();
Adam Cohen2e6da152015-05-06 11:42:25 -0700149
Sunny Goyalc6205602015-05-21 20:46:33 -0700150 // Constants from resources
151 isTablet = res.getBoolean(R.bool.is_tablet);
152 isLargeTablet = res.getBoolean(R.bool.is_large_tablet);
153 isPhone = !isTablet && !isLargeTablet;
154
155 // Some more constants
Winson Chungb3800242013-10-24 11:01:54 -0700156 transposeLayoutWithOrientation =
157 res.getBoolean(R.bool.hotseat_transpose_layout_with_orientation);
Winson Chungb3800242013-10-24 11:01:54 -0700158
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700159 context = getContext(context, isVerticalBarLayout()
160 ? Configuration.ORIENTATION_LANDSCAPE
161 : Configuration.ORIENTATION_PORTRAIT);
162 res = context.getResources();
163
164
Winson Chungb3800242013-10-24 11:01:54 -0700165 ComponentName cn = new ComponentName(context.getPackageName(),
166 this.getClass().getName());
167 defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
168 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Jon Miranda28032002017-07-13 16:18:56 -0700169 desiredWorkspaceLeftRightMarginPx = isVerticalBarLayout() ? 0 : edgeMarginPx;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700170 cellLayoutPaddingLeftRightPx =
171 res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_padding);
Jon Miranda18751b62017-07-31 17:25:27 -0700172 cellLayoutBottomPaddingPx =
173 res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_bottom_padding);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700174 pageIndicatorSizePx = res.getDimensionPixelSize(
175 R.dimen.dynamic_grid_min_page_indicator_size);
Winson Chungb3800242013-10-24 11:01:54 -0700176 defaultPageSpacingPx =
177 res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_page_spacing);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700178 topWorkspacePadding =
179 res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_top_padding);
Winson Chungb3800242013-10-24 11:01:54 -0700180 iconDrawablePaddingOriginalPx =
181 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700182 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
183 workspaceSpringLoadedBottomSpace =
184 res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space);
Sunny Goyald5190522017-04-24 03:06:54 -0700185
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700186 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700187
Winson1f064272016-07-18 17:18:02 -0700188 hotseatBarTopPaddingPx =
189 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding);
Sunny Goyald5190522017-04-24 03:06:54 -0700190 hotseatBarBottomPaddingPx =
191 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_padding);
Sunny Goyal228153d2018-01-04 15:35:22 -0800192 hotseatBarSidePaddingPx =
193 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding);
Jon Miranda18751b62017-07-31 17:25:27 -0700194 hotseatBarSizePx = isVerticalBarLayout()
195 ? Utilities.pxFromDp(inv.iconSize, dm)
196 : res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_size)
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700197 + hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx;
198
Sunny Goyalc6205602015-05-21 20:46:33 -0700199 // Determine sizes.
200 widthPx = width;
201 heightPx = height;
202 if (isLandscape) {
203 availableWidthPx = maxSize.x;
204 availableHeightPx = minSize.y;
205 } else {
206 availableWidthPx = minSize.x;
207 availableHeightPx = maxSize.y;
208 }
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700209
Jon Miranda2ed276e2017-06-29 11:36:34 -0700210 // Calculate all of the remaining variables.
Sunny Goyalc6205602015-05-21 20:46:33 -0700211 updateAvailableDimensions(dm, res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700212
213 // Now that we have all of the variables calculated, we can tune certain sizes.
Jon Miranda3f9bab22017-07-28 14:50:17 -0700214 float aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Jon Miranda30d0aa22017-07-25 15:55:29 -0700215 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
216 if (!isVerticalBarLayout() && isPhone && isTallDevice) {
Jon Miranda3f9bab22017-07-28 14:50:17 -0700217 // We increase the hotseat size when there is extra space.
Jon Miranda2ed276e2017-06-29 11:36:34 -0700218 // ie. For a display with a large aspect ratio, we can keep the icons on the workspace
Jon Miranda3f9bab22017-07-28 14:50:17 -0700219 // in portrait mode closer together by adding more height to the hotseat.
Jon Miranda30d0aa22017-07-25 15:55:29 -0700220 // Note: This calculation was created after noticing a pattern in the design spec.
Jon Miranda3f9bab22017-07-28 14:50:17 -0700221 int extraSpace = getCellSize().y - iconSizePx - iconDrawablePaddingPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700222 hotseatBarSizePx += extraSpace - pageIndicatorSizePx;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700223
Jon Miranda3f9bab22017-07-28 14:50:17 -0700224 // Recalculate the available dimensions using the new hotseat size.
Jon Miranda30d0aa22017-07-25 15:55:29 -0700225 updateAvailableDimensions(dm, res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700226 }
227
Adam Cohen63f1ec02014-08-12 09:23:13 -0700228 computeAllAppsButtonSize(context);
Tony Wickham1237df02017-02-24 08:59:36 -0800229
230 // This is done last, after iconSizePx is calculated above.
Sunny Goyal179249d2017-12-19 16:49:24 -0800231 mBadgeRenderer = new BadgeRenderer(iconSizePx);
Adam Cohen63f1ec02014-08-12 09:23:13 -0700232 }
233
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700234 DeviceProfile getMultiWindowProfile(Context context, Point mwSize) {
Jon Mirandaa11380d2017-08-24 11:30:03 -0700235 // We take the minimum sizes of this profile and it's multi-window variant to ensure that
236 // the system decor is always excluded.
237 mwSize.set(Math.min(availableWidthPx, mwSize.x), Math.min(availableHeightPx, mwSize.y));
238
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700239 // In multi-window mode, we can have widthPx = availableWidthPx
240 // and heightPx = availableHeightPx because Launcher uses the InvariantDeviceProfiles'
241 // widthPx and heightPx values where it's needed.
Jon Miranda93e1f042016-11-11 14:13:04 -0800242 DeviceProfile profile = new DeviceProfile(context, inv, mwSize, mwSize, mwSize.x, mwSize.y,
243 isLandscape);
244
Jon Miranda0cd04572017-09-19 11:31:42 -0700245 // If there isn't enough vertical cell padding with the labels displayed, hide the labels.
246 float workspaceCellPaddingY = profile.getCellSize().y - profile.iconSizePx
247 - iconDrawablePaddingPx - profile.iconTextSizePx;
248 if (workspaceCellPaddingY < profile.iconDrawablePaddingPx * 2) {
249 profile.adjustToHideWorkspaceLabels();
250 }
Jon Miranda93e1f042016-11-11 14:13:04 -0800251
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800252 // We use these scales to measure and layout the widgets using their full invariant profile
253 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
254 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
255 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
256 profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY);
257
Jon Miranda93e1f042016-11-11 14:13:04 -0800258 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700259 }
260
Winson1f064272016-07-18 17:18:02 -0700261 public void addLauncherLayoutChangedListener(LauncherLayoutChangeListener listener) {
262 if (!mListeners.contains(listener)) {
263 mListeners.add(listener);
264 }
265 }
266
267 public void removeLauncherLayoutChangedListener(LauncherLayoutChangeListener listener) {
268 if (mListeners.contains(listener)) {
269 mListeners.remove(listener);
270 }
271 }
272
Adam Cohen63f1ec02014-08-12 09:23:13 -0700273 /**
Jon Miranda1091e532017-07-21 13:31:50 -0700274 * Adjusts the profile so that the labels on the Workspace are hidden.
275 * It is important to call this method after the All Apps variables have been set.
276 */
277 private void adjustToHideWorkspaceLabels() {
278 iconTextSizePx = 0;
279 iconDrawablePaddingPx = 0;
280 cellHeightPx = iconSizePx;
281
282 // In normal cases, All Apps cell height should equal the Workspace cell height.
283 // Since we are removing labels from the Workspace, we need to manually compute the
284 // All Apps cell height.
Jon Miranda3f9bab22017-07-28 14:50:17 -0700285 int topBottomPadding = allAppsIconDrawablePaddingPx * (isVerticalBarLayout() ? 2 : 1);
Jon Miranda1091e532017-07-21 13:31:50 -0700286 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
287 + Utilities.calculateTextHeight(allAppsIconTextSizePx)
Jon Miranda3f9bab22017-07-28 14:50:17 -0700288 + topBottomPadding * 2;
Jon Miranda1091e532017-07-21 13:31:50 -0700289 }
290
291 /**
Adam Cohen63f1ec02014-08-12 09:23:13 -0700292 * Determine the exact visual footprint of the all apps button, taking into account scaling
293 * and internal padding of the drawable.
294 */
295 private void computeAllAppsButtonSize(Context context) {
296 Resources res = context.getResources();
297 float padding = res.getInteger(R.integer.config_allAppsButtonPaddingPercent) / 100f;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700298 allAppsButtonVisualSize = (int) (iconSizePx * (1 - padding)) - context.getResources()
Tony Wickhamd6b40372015-09-23 18:37:57 -0700299 .getDimensionPixelSize(R.dimen.all_apps_button_scale_down);
Winson Chungb3800242013-10-24 11:01:54 -0700300 }
301
Sunny Goyalc6205602015-05-21 20:46:33 -0700302 private void updateAvailableDimensions(DisplayMetrics dm, Resources res) {
Jon Miranda09660722017-06-14 14:20:14 -0700303 updateIconSize(1f, res, dm);
Winson Chung59a488a2013-12-10 12:32:14 -0800304
Jon Mirandabf7d8122016-11-03 15:29:29 -0700305 // Check to see if the icons fit within the available height. If not, then scale down.
306 float usedHeight = (cellHeightPx * inv.numRows);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700307 int maxHeight = (availableHeightPx - getTotalWorkspacePadding().y);
Winson Chungb3800242013-10-24 11:01:54 -0700308 if (usedHeight > maxHeight) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700309 float scale = maxHeight / usedHeight;
Jon Miranda09660722017-06-14 14:20:14 -0700310 updateIconSize(scale, res, dm);
Winson Chungb3800242013-10-24 11:01:54 -0700311 }
Jon Mirandabf7d8122016-11-03 15:29:29 -0700312 updateAvailableFolderCellDimensions(dm, res);
Winson Chungb3800242013-10-24 11:01:54 -0700313 }
314
Jon Miranda09660722017-06-14 14:20:14 -0700315 private void updateIconSize(float scale, Resources res, DisplayMetrics dm) {
Jon Miranda18751b62017-07-31 17:25:27 -0700316 // Workspace
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700317 float invIconSizePx = isVerticalBarLayout() ? inv.landscapeIconSize : inv.iconSize;
318 iconSizePx = (int) (Utilities.pxFromDp(invIconSizePx, dm) * scale);
Sunny Goyala50a4192015-12-11 09:50:49 -0800319 iconTextSizePx = (int) (Utilities.pxFromSp(inv.iconTextSize, dm) * scale);
Jon Miranda09660722017-06-14 14:20:14 -0700320 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * scale);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700321
Jon Miranda18751b62017-07-31 17:25:27 -0700322 cellHeightPx = iconSizePx + iconDrawablePaddingPx
323 + Utilities.calculateTextHeight(iconTextSizePx);
Jon Miranda846455e2017-10-02 14:58:52 -0700324 int cellYPadding = (getCellSize().y - cellHeightPx) / 2;
325 if (iconDrawablePaddingPx > cellYPadding && !isVerticalBarLayout()
326 && !inMultiWindowMode()) {
327 // Ensures that the label is closer to its corresponding icon. This is not an issue
328 // with vertical bar layout or multi-window mode since the issue is handled separately
329 // with their calls to {@link #adjustToHideWorkspaceLabels}.
330 cellHeightPx -= (iconDrawablePaddingPx - cellYPadding);
331 iconDrawablePaddingPx = cellYPadding;
332 }
333 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700334
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700335 // All apps
336 allAppsIconTextSizePx = iconTextSizePx;
Winson1f064272016-07-18 17:18:02 -0700337 allAppsIconSizePx = iconSizePx;
338 allAppsIconDrawablePaddingPx = iconDrawablePaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700339 allAppsCellHeightPx = getCellSize().y;
340
341 if (isVerticalBarLayout()) {
342 // Always hide the Workspace text with vertical bar layout.
Jon Miranda1091e532017-07-21 13:31:50 -0700343 adjustToHideWorkspaceLabels();
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700344 }
Winson Chungb3800242013-10-24 11:01:54 -0700345
Winson Chungb3800242013-10-24 11:01:54 -0700346 // Hotseat
Jon Miranda18751b62017-07-31 17:25:27 -0700347 if (isVerticalBarLayout()) {
348 hotseatBarSizePx = iconSizePx;
349 }
Jon Miranda5044c352017-08-09 11:37:59 -0700350 hotseatCellHeightPx = iconSizePx;
Winson Chungb3800242013-10-24 11:01:54 -0700351
Sunny Goyal47328fd2016-05-25 18:56:41 -0700352 if (!isVerticalBarLayout()) {
Jon Miranda18751b62017-07-31 17:25:27 -0700353 int expectedWorkspaceHeight = availableHeightPx - hotseatBarSizePx
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700354 - pageIndicatorSizePx - topWorkspacePadding;
Sunny Goyal47328fd2016-05-25 18:56:41 -0700355 float minRequiredHeight = dropTargetBarSizePx + workspaceSpringLoadedBottomSpace;
356 workspaceSpringLoadShrinkFactor = Math.min(
357 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f,
358 1 - (minRequiredHeight / expectedWorkspaceHeight));
359 } else {
360 workspaceSpringLoadShrinkFactor =
361 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
362 }
363
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700364 // Folder icon
Jon Miranda09660722017-06-14 14:20:14 -0700365 folderBackgroundOffset = -iconDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700366 folderIconSizePx = iconSizePx + 2 * -folderBackgroundOffset;
Adam Cohenefca0272016-02-24 19:19:06 -0800367 folderIconPreviewPadding = res.getDimensionPixelSize(R.dimen.folder_preview_padding);
Winson Chung0f785722015-04-08 10:27:49 -0700368 }
369
Jon Mirandabf7d8122016-11-03 15:29:29 -0700370 private void updateAvailableFolderCellDimensions(DisplayMetrics dm, Resources res) {
371 int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_padding_top)
372 + res.getDimensionPixelSize(R.dimen.folder_label_padding_bottom)
373 + Utilities.calculateTextHeight(res.getDimension(R.dimen.folder_label_text_size));
374
Jon Mirandac1b23992016-12-13 08:57:36 -0800375 updateFolderCellSize(1f, dm, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700376
Jon Mirandac1b23992016-12-13 08:57:36 -0800377 // Don't let the folder get too close to the edges of the screen.
Jon Miranda72b5fd12017-06-25 18:06:23 -0700378 int folderMargin = edgeMarginPx;
Jon Mirandac1b23992016-12-13 08:57:36 -0800379
380 // Check if the icons fit within the available height.
381 float usedHeight = folderCellHeightPx * inv.numFolderRows + folderBottomPanelSize;
382 int maxHeight = availableHeightPx - getTotalWorkspacePadding().y - folderMargin;
383 float scaleY = maxHeight / usedHeight;
384
385 // Check if the icons fit within the available width.
386 float usedWidth = folderCellWidthPx * inv.numFolderColumns;
387 int maxWidth = availableWidthPx - getTotalWorkspacePadding().x - folderMargin;
388 float scaleX = maxWidth / usedWidth;
389
390 float scale = Math.min(scaleX, scaleY);
391 if (scale < 1f) {
392 updateFolderCellSize(scale, dm, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700393 }
394 }
395
Jon Mirandac1b23992016-12-13 08:57:36 -0800396 private void updateFolderCellSize(float scale, DisplayMetrics dm, Resources res) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700397 folderChildIconSizePx = (int) (Utilities.pxFromDp(inv.iconSize, dm) * scale);
398 folderChildTextSizePx =
399 (int) (res.getDimensionPixelSize(R.dimen.folder_child_text_size) * scale);
400
401 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
402 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding) * scale);
403 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding) * scale);
404
Jon Mirandac1b23992016-12-13 08:57:36 -0800405 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
Jonathan Miranda9ad87462017-07-26 17:41:02 +0000406 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
407 folderChildDrawablePaddingPx = Math.max(0,
408 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700409 }
410
Winson1f064272016-07-18 17:18:02 -0700411 public void updateInsets(Rect insets) {
412 mInsets.set(insets);
413 }
414
Winson1f064272016-07-18 17:18:02 -0700415 public void updateAppsViewNumCols() {
416 allAppsNumCols = allAppsNumPredictiveCols = inv.numColumns;
Winson Chungb3800242013-10-24 11:01:54 -0700417 }
418
Tony Wickhama3c74d12015-10-23 11:43:47 -0700419 /** Returns the width and height of the search bar, ignoring any padding. */
Sunny Goyal47328fd2016-05-25 18:56:41 -0700420 public Point getSearchBarDimensForWidgetOpts() {
Tony Wickhama3c74d12015-10-23 11:43:47 -0700421 if (isVerticalBarLayout()) {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700422 return new Point(dropTargetBarSizePx, availableHeightPx - 2 * edgeMarginPx);
Winson Chungb3800242013-10-24 11:01:54 -0700423 } else {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700424 int gap;
Sunny Goyalc6205602015-05-21 20:46:33 -0700425 if (isTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700426 // Pad the left and right of the workspace to ensure consistent spacing
427 // between all icons
Winson Chungb3800242013-10-24 11:01:54 -0700428 // XXX: If the icon size changes across orientations, we will have to take
429 // that into account here too.
Sunny Goyal228153d2018-01-04 15:35:22 -0800430 gap = ((widthPx - 2 * edgeMarginPx
Sunny Goyal47328fd2016-05-25 18:56:41 -0700431 - (inv.numColumns * cellWidthPx)) / (2 * (inv.numColumns + 1)))
432 + edgeMarginPx;
Winson Chungb3800242013-10-24 11:01:54 -0700433 } else {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700434 gap = desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.right;
Winson Chungb3800242013-10-24 11:01:54 -0700435 }
Sunny Goyal47328fd2016-05-25 18:56:41 -0700436 return new Point(availableWidthPx - 2 * gap, dropTargetBarSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700437 }
Winson Chungb3800242013-10-24 11:01:54 -0700438 }
439
Sunny Goyal756cd262015-08-20 12:33:21 -0700440 public Point getCellSize() {
441 Point result = new Point();
442 // Since we are only concerned with the overall padding, layout direction does
443 // not matter.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700444 Point padding = getTotalWorkspacePadding();
Jon Miranda18751b62017-07-31 17:25:27 -0700445 result.x = calculateCellWidth(availableWidthPx - padding.x
446 - cellLayoutPaddingLeftRightPx * 2, inv.numColumns);
447 result.y = calculateCellHeight(availableHeightPx - padding.y
448 - cellLayoutBottomPaddingPx, inv.numRows);
Sunny Goyal756cd262015-08-20 12:33:21 -0700449 return result;
450 }
451
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700452 public Point getTotalWorkspacePadding() {
Sunny Goyal6178f132016-07-11 17:30:03 -0700453 Rect padding = getWorkspacePadding(null);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700454 return new Point(padding.left + padding.right, padding.top + padding.bottom);
455 }
456
457 /**
458 * Returns the workspace padding in the specified orientation.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700459 */
Sunny Goyal6178f132016-07-11 17:30:03 -0700460 public Rect getWorkspacePadding(Rect recycle) {
461 Rect padding = recycle == null ? new Rect() : recycle;
Tony Wickham3a3517f2015-10-06 11:27:04 -0700462 if (isVerticalBarLayout()) {
Sunny Goyal228153d2018-01-04 15:35:22 -0800463 padding.top = 0;
464 padding.bottom = edgeMarginPx;
465 padding.left = hotseatBarSidePaddingPx;
466 padding.right = hotseatBarSidePaddingPx;
467 if (mInsets.left > mInsets.right) {
468 padding.left += hotseatBarSizePx;
469 padding.right += pageIndicatorSizePx;
Winson1f064272016-07-18 17:18:02 -0700470 } else {
Sunny Goyal228153d2018-01-04 15:35:22 -0800471 padding.left += pageIndicatorSizePx;
472 padding.right += hotseatBarSizePx;
Winson1f064272016-07-18 17:18:02 -0700473 }
Winson Chungb3800242013-10-24 11:01:54 -0700474 } else {
Jon Miranda18751b62017-07-31 17:25:27 -0700475 int paddingBottom = hotseatBarSizePx + pageIndicatorSizePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700476 if (isTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700477 // Pad the left and right of the workspace to ensure consistent spacing
478 // between all icons
Tony Wickhamd6b40372015-09-23 18:37:57 -0700479 // The amount of screen space available for left/right padding.
Sunny Goyal228153d2018-01-04 15:35:22 -0800480 int availablePaddingX = Math.max(0, widthPx - ((inv.numColumns * cellWidthPx) +
Sunny Goyalf5440cb2016-12-14 15:13:00 -0800481 ((inv.numColumns - 1) * cellWidthPx)));
Tony Wickhamd6b40372015-09-23 18:37:57 -0700482 availablePaddingX = (int) Math.min(availablePaddingX,
Sunny Goyal228153d2018-01-04 15:35:22 -0800483 widthPx * MAX_HORIZONTAL_PADDING_PERCENT);
484 int availablePaddingY = Math.max(0, heightPx - topWorkspacePadding - paddingBottom
Jon Mirandac1b08c52016-11-15 14:37:56 -0800485 - (2 * inv.numRows * cellHeightPx) - hotseatBarTopPaddingPx
486 - hotseatBarBottomPaddingPx);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700487 padding.set(availablePaddingX / 2, topWorkspacePadding + availablePaddingY / 2,
Tony Wickhamd6b40372015-09-23 18:37:57 -0700488 availablePaddingX / 2, paddingBottom + availablePaddingY / 2);
Winson Chungb3800242013-10-24 11:01:54 -0700489 } else {
490 // Pad the top and bottom of the workspace with search/hotseat bar sizes
Winson1f064272016-07-18 17:18:02 -0700491 padding.set(desiredWorkspaceLeftRightMarginPx,
Sunny Goyal47328fd2016-05-25 18:56:41 -0700492 topWorkspacePadding,
Winson1f064272016-07-18 17:18:02 -0700493 desiredWorkspaceLeftRightMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700494 paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -0700495 }
496 }
497 return padding;
498 }
499
Winsonfadbe8f2016-07-22 16:35:37 -0700500 /**
501 * @return the bounds for which the open folders should be contained within
502 */
503 public Rect getAbsoluteOpenFolderBounds() {
504 if (isVerticalBarLayout()) {
505 // Folders should only appear right of the drop target bar and left of the hotseat
506 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
507 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -0700508 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700509 mInsets.top + availableHeightPx);
510 } else {
511 // Folders should only appear below the drop target bar and above the hotseat
512 return new Rect(mInsets.left,
513 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
514 mInsets.left + availableWidthPx,
Jon Miranda18751b62017-07-31 17:25:27 -0700515 mInsets.top + availableHeightPx - hotseatBarSizePx
Jon Miranda2ed276e2017-06-29 11:36:34 -0700516 - pageIndicatorSizePx - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -0700517 }
518 }
519
Sunny Goyal47328fd2016-05-25 18:56:41 -0700520 private int getWorkspacePageSpacing() {
Tony Wickham3a3517f2015-10-06 11:27:04 -0700521 if (isVerticalBarLayout() || isLargeTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700522 // In landscape mode the page spacing is set to the default.
523 return defaultPageSpacingPx;
524 } else {
525 // In portrait, we want the pages spaced such that there is no
526 // overhang of the previous / next page into the current page viewport.
527 // We assume symmetrical padding in portrait mode.
Jon Miranda28032002017-07-13 16:18:56 -0700528 return Math.max(defaultPageSpacingPx, getWorkspacePadding(null).left + 1);
Winson Chungb3800242013-10-24 11:01:54 -0700529 }
530 }
531
Adam Cohen2e6da152015-05-06 11:42:25 -0700532 public static int calculateCellWidth(int width, int countX) {
Winson Chungb3800242013-10-24 11:01:54 -0700533 return width / countX;
534 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700535 public static int calculateCellHeight(int height, int countY) {
Winson Chungb3800242013-10-24 11:01:54 -0700536 return height / countY;
537 }
538
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700539 /**
Tony Wickham55616cd2015-09-23 14:55:17 -0700540 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
541 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
542 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700543 */
Tony Wickhamab946a12015-09-16 15:38:16 -0700544 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -0700545 return isLandscape && transposeLayoutWithOrientation;
546 }
547
548 boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyalc6205602015-05-21 20:46:33 -0700549 return isVerticalBarLayout() || isLargeTablet;
Winson Chungb3800242013-10-24 11:01:54 -0700550 }
551
Sunny Goyal228153d2018-01-04 15:35:22 -0800552 private static void setLayoutGravity(View v, int gravity) {
553 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) v.getLayoutParams();
554 lp.gravity = gravity;
555 v.setLayoutParams(lp);
556 }
557
Winson1f064272016-07-18 17:18:02 -0700558 public void layout(Launcher launcher, boolean notifyListeners) {
Winson Chungb3800242013-10-24 11:01:54 -0700559 FrameLayout.LayoutParams lp;
Winson Chungb3800242013-10-24 11:01:54 -0700560 boolean hasVerticalBarLayout = isVerticalBarLayout();
561
562 // Layout the search bar space
Sunny Goyal47328fd2016-05-25 18:56:41 -0700563 Point searchBarBounds = getSearchBarDimensForWidgetOpts();
564 View searchBar = launcher.getDropTargetBar();
Sunny Goyalf37a2142016-03-24 17:28:25 -0700565 lp = (FrameLayout.LayoutParams) searchBar.getLayoutParams();
Sunny Goyal47328fd2016-05-25 18:56:41 -0700566 lp.width = searchBarBounds.x;
567 lp.height = searchBarBounds.y;
Jon Miranda28032002017-07-13 16:18:56 -0700568 lp.topMargin = mInsets.top + edgeMarginPx;
Winson Chungb3800242013-10-24 11:01:54 -0700569 searchBar.setLayoutParams(lp);
570
Winson Chungb3800242013-10-24 11:01:54 -0700571 // Layout the workspace
Sunny Goyalb532dfe2017-12-13 17:16:54 -0800572 PagedView workspace = launcher.getWorkspace();
Winson1f064272016-07-18 17:18:02 -0700573 Rect workspacePadding = getWorkspacePadding(null);
574 workspace.setPadding(workspacePadding.left, workspacePadding.top, workspacePadding.right,
575 workspacePadding.bottom);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700576 workspace.setPageSpacing(getWorkspacePageSpacing());
Winson Chungb3800242013-10-24 11:01:54 -0700577
Sunny Goyalb532dfe2017-12-13 17:16:54 -0800578 AllAppsScrim allAppsScrim = launcher.findViewById(R.id.all_apps_scrim);
579
Winson Chungb3800242013-10-24 11:01:54 -0700580 // Layout the hotseat
Sunny Goyalb532dfe2017-12-13 17:16:54 -0800581 Hotseat hotseat = launcher.getHotseat();
Winson Chungb3800242013-10-24 11:01:54 -0700582 lp = (FrameLayout.LayoutParams) hotseat.getLayoutParams();
Tony Wickhamd6b40372015-09-23 18:37:57 -0700583 // We want the edges of the hotseat to line up with the edges of the workspace, but the
584 // icons in the hotseat are a different size, and so don't line up perfectly. To account for
585 // this, we pad the left and right of the hotseat with half of the difference of a workspace
586 // cell vs a hotseat cell.
Sunny Goyal228153d2018-01-04 15:35:22 -0800587 float workspaceCellWidth = (float) widthPx / inv.numColumns;
588 float hotseatCellWidth = (float) widthPx / inv.numHotseatIcons;
Tony Wickhamd6b40372015-09-23 18:37:57 -0700589 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Sunny Goyalb532dfe2017-12-13 17:16:54 -0800590 float scrimMargin = launcher.getResources().getDimension(R.dimen.all_apps_scrim_margin);
591
Winson Chungb3800242013-10-24 11:01:54 -0700592 if (hasVerticalBarLayout) {
Sunny Goyal228153d2018-01-04 15:35:22 -0800593 // Vertical hotseat, on left or right based on the insets
Jon Miranda18751b62017-07-31 17:25:27 -0700594 lp.height = LayoutParams.MATCH_PARENT;
Sunny Goyal228153d2018-01-04 15:35:22 -0800595 if (mInsets.left > mInsets.right) {
596 lp.gravity = Gravity.LEFT;
597 lp.width = hotseatBarSizePx + mInsets.left + hotseatBarSidePaddingPx;
598 hotseat.getLayout().setPadding(
599 mInsets.left, mInsets.top, hotseatBarSidePaddingPx, mInsets.bottom);
Jon Miranda18751b62017-07-31 17:25:27 -0700600
Sunny Goyal228153d2018-01-04 15:35:22 -0800601 setLayoutGravity(launcher.getDropTargetBar(), Gravity.RIGHT);
602 } else {
603 lp.gravity = Gravity.RIGHT;
604 lp.width = hotseatBarSizePx + mInsets.right + hotseatBarSidePaddingPx;
605 hotseat.getLayout().setPadding(
606 hotseatBarSidePaddingPx, mInsets.top, mInsets.right, mInsets.bottom);
607
608 setLayoutGravity(launcher.getDropTargetBar(), Gravity.LEFT);
609 }
610
Sunny Goyalc6205602015-05-21 20:46:33 -0700611 } else if (isTablet) {
Winson Chung59a488a2013-12-10 12:32:14 -0800612 // Pad the hotseat with the workspace padding calculated above
Winson Chungb3800242013-10-24 11:01:54 -0700613 lp.gravity = Gravity.BOTTOM;
614 lp.width = LayoutParams.MATCH_PARENT;
Jon Miranda18751b62017-07-31 17:25:27 -0700615 lp.height = hotseatBarSizePx + mInsets.bottom;
Sunny Goyalb532dfe2017-12-13 17:16:54 -0800616 allAppsScrim.setDrawRegion(lp.height + scrimMargin);
617
Jon Miranda52ff3252017-07-14 11:39:16 -0700618 hotseat.getLayout().setPadding(hotseatAdjustment + workspacePadding.left
619 + cellLayoutPaddingLeftRightPx,
620 hotseatBarTopPaddingPx,
621 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx,
Jon Miranda18751b62017-07-31 17:25:27 -0700622 hotseatBarBottomPaddingPx + mInsets.bottom + cellLayoutBottomPaddingPx);
Winson Chungb3800242013-10-24 11:01:54 -0700623 } else {
624 // For phones, layout the hotseat without any bottom margin
625 // to ensure that we have space for the folders
626 lp.gravity = Gravity.BOTTOM;
627 lp.width = LayoutParams.MATCH_PARENT;
Jon Miranda18751b62017-07-31 17:25:27 -0700628 lp.height = hotseatBarSizePx + mInsets.bottom;
Sunny Goyalb532dfe2017-12-13 17:16:54 -0800629 allAppsScrim.setDrawRegion(lp.height + scrimMargin);
630
Jon Miranda52ff3252017-07-14 11:39:16 -0700631 hotseat.getLayout().setPadding(hotseatAdjustment + workspacePadding.left
632 + cellLayoutPaddingLeftRightPx,
633 hotseatBarTopPaddingPx,
634 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx,
Jon Miranda18751b62017-07-31 17:25:27 -0700635 hotseatBarBottomPaddingPx + mInsets.bottom + cellLayoutBottomPaddingPx);
Winson Chungb3800242013-10-24 11:01:54 -0700636 }
637 hotseat.setLayoutParams(lp);
638
639 // Layout the page indicators
640 View pageIndicator = launcher.findViewById(R.id.page_indicator);
641 if (pageIndicator != null) {
Hyunyoung Song7d2fc812016-06-15 12:51:30 -0700642 lp = (FrameLayout.LayoutParams) pageIndicator.getLayoutParams();
Sunny Goyal228153d2018-01-04 15:35:22 -0800643 if (hasVerticalBarLayout) {
644 if (mInsets.left > mInsets.right) {
645 lp.leftMargin = hotseatBarSidePaddingPx;
646 lp.rightMargin = mInsets.right;
647 lp.gravity = Gravity.RIGHT | Gravity.BOTTOM;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700648 } else {
Sunny Goyal228153d2018-01-04 15:35:22 -0800649 lp.leftMargin = mInsets.left;
650 lp.rightMargin = hotseatBarSidePaddingPx;
651 lp.gravity = Gravity.LEFT | Gravity.BOTTOM;
Winson1f064272016-07-18 17:18:02 -0700652 }
653 lp.bottomMargin = workspacePadding.bottom;
654 } else {
Winson Chungb3800242013-10-24 11:01:54 -0700655 // Put the page indicators above the hotseat
Winson Chungb3800242013-10-24 11:01:54 -0700656 lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700657 lp.height = pageIndicatorSizePx;
Jon Miranda18751b62017-07-31 17:25:27 -0700658 lp.bottomMargin = hotseatBarSizePx + mInsets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -0700659 }
Hyunyoung Song7d2fc812016-06-15 12:51:30 -0700660 pageIndicator.setLayoutParams(lp);
Winson Chungb3800242013-10-24 11:01:54 -0700661 }
662
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700663 // Layout the AllAppsRecyclerView
Mario Bertschlerac9408a2017-10-18 10:31:36 -0700664 AllAppsContainerView appsView = launcher.findViewById(R.id.apps_view);
Jon Miranda28032002017-07-13 16:18:56 -0700665 int paddingLeftRight = desiredWorkspaceLeftRightMarginPx + cellLayoutPaddingLeftRightPx;
Mario Bertschlerac9408a2017-10-18 10:31:36 -0700666 appsView.setRecyclerViewSidePadding(paddingLeftRight, paddingLeftRight);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700667
Winson1f064272016-07-18 17:18:02 -0700668 if (notifyListeners) {
669 for (int i = mListeners.size() - 1; i >= 0; i--) {
670 mListeners.get(i).onLauncherLayoutChanged();
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700671 }
Winson Chungb3800242013-10-24 11:01:54 -0700672 }
673 }
Winson Chung4f3bfad2015-07-13 11:14:30 -0700674
Sunny Goyalc13403c2016-11-18 23:44:48 -0800675 public int getCellHeight(@ContainerType int containerType) {
676 switch (containerType) {
677 case CellLayout.WORKSPACE:
678 return cellHeightPx;
679 case CellLayout.FOLDER:
680 return folderCellHeightPx;
681 case CellLayout.HOTSEAT:
682 return hotseatCellHeightPx;
683 default:
684 // ??
685 return 0;
686 }
687 }
Sunny Goyal13178ac2016-04-04 16:35:22 -0700688
Jon Miranda846455e2017-10-02 14:58:52 -0700689 public boolean inMultiWindowMode() {
690 return this != inv.landscapeProfile && this != inv.portraitProfile;
691 }
692
Jon Miranda51f037d2016-11-07 08:37:20 -0800693 public boolean shouldIgnoreLongPressToOverview(float touchX) {
Jon Miranda51f037d2016-11-07 08:37:20 -0800694 boolean touchedLhsEdge = mInsets.left == 0 && touchX < edgeMarginPx;
695 boolean touchedRhsEdge = mInsets.right == 0 && touchX > (widthPx - edgeMarginPx);
Jon Miranda846455e2017-10-02 14:58:52 -0700696 return !inMultiWindowMode() && (touchedLhsEdge || touchedRhsEdge);
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700697 }
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700698
699 private static Context getContext(Context c, int orientation) {
700 Configuration context = new Configuration(c.getResources().getConfiguration());
701 context.orientation = orientation;
702 return c.createConfigurationContext(context);
703
704 }
Winson Chungb3800242013-10-24 11:01:54 -0700705}