blob: 6030e088653821b5f11ae2e71c5dfebc65cf6281 [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;
Jorim Jaggid017f882014-01-14 17:08:48 -080030import android.view.ViewGroup;
Winson Chungb3800242013-10-24 11:01:54 -070031import android.view.ViewGroup.LayoutParams;
Winson Chungb3800242013-10-24 11:01:54 -070032import android.widget.FrameLayout;
33
Sunny Goyalc13403c2016-11-18 23:44:48 -080034import com.android.launcher3.CellLayout.ContainerType;
Tony Wickham9a8d11f2017-01-11 09:53:12 -080035import com.android.launcher3.badge.BadgeRenderer;
Tony Wickhame0c33232016-02-08 11:37:04 -080036
Winson1f064272016-07-18 17:18:02 -070037import java.util.ArrayList;
38
Winson Chungb3800242013-10-24 11:01:54 -070039public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070040
Winson1f064272016-07-18 17:18:02 -070041 public interface LauncherLayoutChangeListener {
42 void onLauncherLayoutChanged();
43 }
44
Adam Cohen2e6da152015-05-06 11:42:25 -070045 public final InvariantDeviceProfile inv;
Winson Chungbe876472014-05-14 14:15:20 -070046
Sunny Goyalc6205602015-05-21 20:46:33 -070047 // Device properties
48 public final boolean isTablet;
49 public final boolean isLargeTablet;
50 public final boolean isPhone;
51 public final boolean transposeLayoutWithOrientation;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -070052
Sunny Goyalc6205602015-05-21 20:46:33 -070053 // Device properties in current orientation
54 public final boolean isLandscape;
55 public final int widthPx;
56 public final int heightPx;
57 public final int availableWidthPx;
58 public final int availableHeightPx;
Tony Wickhamd6b40372015-09-23 18:37:57 -070059 /**
60 * The maximum amount of left/right workspace padding as a percentage of the screen width.
61 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
62 * 7% of the screen width can be used as right padding.
63 */
64 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -070065
Jon Miranda3f9bab22017-07-28 14:50:17 -070066 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda30d0aa22017-07-25 15:55:29 -070067
Winson Chungb3800242013-10-24 11:01:54 -070068
Sunny Goyalc6205602015-05-21 20:46:33 -070069 // Workspace
Jon Miranda28032002017-07-13 16:18:56 -070070 private final int desiredWorkspaceLeftRightMarginPx;
71 public final int cellLayoutPaddingLeftRightPx;
Jon Miranda18751b62017-07-31 17:25:27 -070072 public final int cellLayoutBottomPaddingPx;
Sunny Goyalc6205602015-05-21 20:46:33 -070073 public final int edgeMarginPx;
74 public final Rect defaultWidgetPadding;
Sunny Goyalc6205602015-05-21 20:46:33 -070075 private final int defaultPageSpacingPx;
Sunny Goyal47328fd2016-05-25 18:56:41 -070076 private final int topWorkspacePadding;
Sunny Goyal47328fd2016-05-25 18:56:41 -070077 public float workspaceSpringLoadShrinkFactor;
78 public final int workspaceSpringLoadedBottomSpace;
Sunny Goyalc6205602015-05-21 20:46:33 -070079
Winson1f064272016-07-18 17:18:02 -070080 // Page indicator
Jon Miranda2ed276e2017-06-29 11:36:34 -070081 private int pageIndicatorSizePx;
Jon Miranda18751b62017-07-31 17:25:27 -070082 private final int pageIndicatorLandLeftNavBarGutterPx;
83 private final int pageIndicatorLandRightNavBarGutterPx;
Winson1f064272016-07-18 17:18:02 -070084 private final int pageIndicatorLandWorkspaceOffsetPx;
85
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
97 public int folderBackgroundOffset;
98 public int folderIconSizePx;
Adam Cohenefca0272016-02-24 19:19:06 -080099 public int folderIconPreviewPadding;
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 Goyal0dc1db42017-05-17 11:34:33 -0700114 public int hotseatBarTopPaddingPx;
115 public int hotseatBarBottomPaddingPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700116
117 public int hotseatBarLeftNavBarLeftPaddingPx;
118 public int hotseatBarLeftNavBarRightPaddingPx;
119
120 public int hotseatBarRightNavBarLeftPaddingPx;
121 public int hotseatBarRightNavBarRightPaddingPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700122
Sunny Goyalc6205602015-05-21 20:46:33 -0700123 // All apps
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700124 public int allAppsCellHeightPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700125 public int allAppsNumCols;
126 public int allAppsNumPredictiveCols;
Sunny Goyalc6205602015-05-21 20:46:33 -0700127 public int allAppsButtonVisualSize;
Winson1f064272016-07-18 17:18:02 -0700128 public int allAppsIconSizePx;
129 public int allAppsIconDrawablePaddingPx;
130 public float allAppsIconTextSizePx;
131
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800132 // Widgets
133 public final PointF appWidgetScale = new PointF(1.0f, 1.0f);
134
Sunny Goyal47328fd2016-05-25 18:56:41 -0700135 // Drop Target
136 public int dropTargetBarSizePx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700137
Winson1f064272016-07-18 17:18:02 -0700138 // Insets
139 private Rect mInsets = new Rect();
140
141 // Listeners
142 private ArrayList<LauncherLayoutChangeListener> mListeners = new ArrayList<>();
143
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800144 // Icon badges
145 public BadgeRenderer mBadgeRenderer;
146
Sunny Goyalc6205602015-05-21 20:46:33 -0700147 public DeviceProfile(Context context, InvariantDeviceProfile inv,
148 Point minSize, Point maxSize,
149 int width, int height, boolean isLandscape) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700150
Adam Cohen2e6da152015-05-06 11:42:25 -0700151 this.inv = inv;
Sunny Goyalc6205602015-05-21 20:46:33 -0700152 this.isLandscape = isLandscape;
Winson Chungb3800242013-10-24 11:01:54 -0700153
Adam Cohen2e6da152015-05-06 11:42:25 -0700154 Resources res = context.getResources();
Winson Chungb3800242013-10-24 11:01:54 -0700155 DisplayMetrics dm = res.getDisplayMetrics();
Adam Cohen2e6da152015-05-06 11:42:25 -0700156
Sunny Goyalc6205602015-05-21 20:46:33 -0700157 // Constants from resources
158 isTablet = res.getBoolean(R.bool.is_tablet);
159 isLargeTablet = res.getBoolean(R.bool.is_large_tablet);
160 isPhone = !isTablet && !isLargeTablet;
161
162 // Some more constants
Winson Chungb3800242013-10-24 11:01:54 -0700163 transposeLayoutWithOrientation =
164 res.getBoolean(R.bool.hotseat_transpose_layout_with_orientation);
Winson Chungb3800242013-10-24 11:01:54 -0700165
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700166 context = getContext(context, isVerticalBarLayout()
167 ? Configuration.ORIENTATION_LANDSCAPE
168 : Configuration.ORIENTATION_PORTRAIT);
169 res = context.getResources();
170
171
Winson Chungb3800242013-10-24 11:01:54 -0700172 ComponentName cn = new ComponentName(context.getPackageName(),
173 this.getClass().getName());
174 defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
175 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Jon Miranda28032002017-07-13 16:18:56 -0700176 desiredWorkspaceLeftRightMarginPx = isVerticalBarLayout() ? 0 : edgeMarginPx;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700177 cellLayoutPaddingLeftRightPx =
178 res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_padding);
Jon Miranda18751b62017-07-31 17:25:27 -0700179 cellLayoutBottomPaddingPx =
180 res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_bottom_padding);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700181 pageIndicatorSizePx = res.getDimensionPixelSize(
182 R.dimen.dynamic_grid_min_page_indicator_size);
Jon Miranda18751b62017-07-31 17:25:27 -0700183 pageIndicatorLandLeftNavBarGutterPx = res.getDimensionPixelSize(
184 R.dimen.dynamic_grid_page_indicator_land_left_nav_bar_gutter_width);
185 pageIndicatorLandRightNavBarGutterPx = res.getDimensionPixelSize(
186 R.dimen.dynamic_grid_page_indicator_land_right_nav_bar_gutter_width);
Winson1f064272016-07-18 17:18:02 -0700187 pageIndicatorLandWorkspaceOffsetPx =
188 res.getDimensionPixelSize(R.dimen.all_apps_caret_workspace_offset);
Winson Chungb3800242013-10-24 11:01:54 -0700189 defaultPageSpacingPx =
190 res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_page_spacing);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700191 topWorkspacePadding =
192 res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_top_padding);
Winson Chungb3800242013-10-24 11:01:54 -0700193 iconDrawablePaddingOriginalPx =
194 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700195 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
196 workspaceSpringLoadedBottomSpace =
197 res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space);
Sunny Goyald5190522017-04-24 03:06:54 -0700198
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700199 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700200
Winson1f064272016-07-18 17:18:02 -0700201 hotseatBarTopPaddingPx =
202 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding);
Sunny Goyald5190522017-04-24 03:06:54 -0700203 hotseatBarBottomPaddingPx =
204 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_padding);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700205 hotseatBarLeftNavBarRightPaddingPx = res.getDimensionPixelSize(
206 R.dimen.dynamic_grid_hotseat_land_left_nav_bar_right_padding);
207 hotseatBarRightNavBarRightPaddingPx = res.getDimensionPixelSize(
208 R.dimen.dynamic_grid_hotseat_land_right_nav_bar_right_padding);
Jon Miranda18751b62017-07-31 17:25:27 -0700209 hotseatBarLeftNavBarLeftPaddingPx = res.getDimensionPixelSize(
210 R.dimen.dynamic_grid_hotseat_land_left_nav_bar_left_padding);
211 hotseatBarRightNavBarLeftPaddingPx = res.getDimensionPixelSize(
212 R.dimen.dynamic_grid_hotseat_land_right_nav_bar_left_padding);
213 hotseatBarSizePx = isVerticalBarLayout()
214 ? Utilities.pxFromDp(inv.iconSize, dm)
215 : res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_size)
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700216 + hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx;
217
Sunny Goyalc6205602015-05-21 20:46:33 -0700218 // Determine sizes.
219 widthPx = width;
220 heightPx = height;
221 if (isLandscape) {
222 availableWidthPx = maxSize.x;
223 availableHeightPx = minSize.y;
224 } else {
225 availableWidthPx = minSize.x;
226 availableHeightPx = maxSize.y;
227 }
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700228
Jon Miranda2ed276e2017-06-29 11:36:34 -0700229 // Calculate all of the remaining variables.
Sunny Goyalc6205602015-05-21 20:46:33 -0700230 updateAvailableDimensions(dm, 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 Miranda3f9bab22017-07-28 14:50:17 -0700233 float aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Jon Miranda30d0aa22017-07-25 15:55:29 -0700234 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
235 if (!isVerticalBarLayout() && isPhone && isTallDevice) {
Jon Miranda3f9bab22017-07-28 14:50:17 -0700236 // We increase the hotseat size when there is extra space.
Jon Miranda2ed276e2017-06-29 11:36:34 -0700237 // ie. For a display with a large aspect ratio, we can keep the icons on the workspace
Jon Miranda3f9bab22017-07-28 14:50:17 -0700238 // in portrait mode closer together by adding more height to the hotseat.
Jon Miranda30d0aa22017-07-25 15:55:29 -0700239 // Note: This calculation was created after noticing a pattern in the design spec.
Jon Miranda3f9bab22017-07-28 14:50:17 -0700240 int extraSpace = getCellSize().y - iconSizePx - iconDrawablePaddingPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700241 hotseatBarSizePx += extraSpace - pageIndicatorSizePx;
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.
Jon Miranda30d0aa22017-07-25 15:55:29 -0700244 updateAvailableDimensions(dm, res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700245 }
246
Adam Cohen63f1ec02014-08-12 09:23:13 -0700247 computeAllAppsButtonSize(context);
Tony Wickham1237df02017-02-24 08:59:36 -0800248
249 // This is done last, after iconSizePx is calculated above.
250 mBadgeRenderer = new BadgeRenderer(context, iconSizePx);
Adam Cohen63f1ec02014-08-12 09:23:13 -0700251 }
252
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700253 DeviceProfile getMultiWindowProfile(Context context, Point mwSize) {
Jon Mirandaa11380d2017-08-24 11:30:03 -0700254 // We take the minimum sizes of this profile and it's multi-window variant to ensure that
255 // the system decor is always excluded.
256 mwSize.set(Math.min(availableWidthPx, mwSize.x), Math.min(availableHeightPx, mwSize.y));
257
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700258 // In multi-window mode, we can have widthPx = availableWidthPx
259 // and heightPx = availableHeightPx because Launcher uses the InvariantDeviceProfiles'
260 // widthPx and heightPx values where it's needed.
Jon Miranda93e1f042016-11-11 14:13:04 -0800261 DeviceProfile profile = new DeviceProfile(context, inv, mwSize, mwSize, mwSize.x, mwSize.y,
262 isLandscape);
263
Jon Miranda0cd04572017-09-19 11:31:42 -0700264 // If there isn't enough vertical cell padding with the labels displayed, hide the labels.
265 float workspaceCellPaddingY = profile.getCellSize().y - profile.iconSizePx
266 - iconDrawablePaddingPx - profile.iconTextSizePx;
267 if (workspaceCellPaddingY < profile.iconDrawablePaddingPx * 2) {
268 profile.adjustToHideWorkspaceLabels();
269 }
Jon Miranda93e1f042016-11-11 14:13:04 -0800270
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800271 // We use these scales to measure and layout the widgets using their full invariant profile
272 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
273 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
274 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
275 profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY);
276
Jon Miranda93e1f042016-11-11 14:13:04 -0800277 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700278 }
279
Winson1f064272016-07-18 17:18:02 -0700280 public void addLauncherLayoutChangedListener(LauncherLayoutChangeListener listener) {
281 if (!mListeners.contains(listener)) {
282 mListeners.add(listener);
283 }
284 }
285
286 public void removeLauncherLayoutChangedListener(LauncherLayoutChangeListener listener) {
287 if (mListeners.contains(listener)) {
288 mListeners.remove(listener);
289 }
290 }
291
Adam Cohen63f1ec02014-08-12 09:23:13 -0700292 /**
Jon Miranda1091e532017-07-21 13:31:50 -0700293 * Adjusts the profile so that the labels on the Workspace are hidden.
294 * It is important to call this method after the All Apps variables have been set.
295 */
296 private void adjustToHideWorkspaceLabels() {
297 iconTextSizePx = 0;
298 iconDrawablePaddingPx = 0;
299 cellHeightPx = iconSizePx;
300
301 // In normal cases, All Apps cell height should equal the Workspace cell height.
302 // Since we are removing labels from the Workspace, we need to manually compute the
303 // All Apps cell height.
Jon Miranda3f9bab22017-07-28 14:50:17 -0700304 int topBottomPadding = allAppsIconDrawablePaddingPx * (isVerticalBarLayout() ? 2 : 1);
Jon Miranda1091e532017-07-21 13:31:50 -0700305 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
306 + Utilities.calculateTextHeight(allAppsIconTextSizePx)
Jon Miranda3f9bab22017-07-28 14:50:17 -0700307 + topBottomPadding * 2;
Jon Miranda1091e532017-07-21 13:31:50 -0700308 }
309
310 /**
Adam Cohen63f1ec02014-08-12 09:23:13 -0700311 * Determine the exact visual footprint of the all apps button, taking into account scaling
312 * and internal padding of the drawable.
313 */
314 private void computeAllAppsButtonSize(Context context) {
315 Resources res = context.getResources();
316 float padding = res.getInteger(R.integer.config_allAppsButtonPaddingPercent) / 100f;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700317 allAppsButtonVisualSize = (int) (iconSizePx * (1 - padding)) - context.getResources()
Tony Wickhamd6b40372015-09-23 18:37:57 -0700318 .getDimensionPixelSize(R.dimen.all_apps_button_scale_down);
Winson Chungb3800242013-10-24 11:01:54 -0700319 }
320
Sunny Goyalc6205602015-05-21 20:46:33 -0700321 private void updateAvailableDimensions(DisplayMetrics dm, Resources res) {
Jon Miranda09660722017-06-14 14:20:14 -0700322 updateIconSize(1f, res, dm);
Winson Chung59a488a2013-12-10 12:32:14 -0800323
Jon Mirandabf7d8122016-11-03 15:29:29 -0700324 // Check to see if the icons fit within the available height. If not, then scale down.
325 float usedHeight = (cellHeightPx * inv.numRows);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700326 int maxHeight = (availableHeightPx - getTotalWorkspacePadding().y);
Winson Chungb3800242013-10-24 11:01:54 -0700327 if (usedHeight > maxHeight) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700328 float scale = maxHeight / usedHeight;
Jon Miranda09660722017-06-14 14:20:14 -0700329 updateIconSize(scale, res, dm);
Winson Chungb3800242013-10-24 11:01:54 -0700330 }
Jon Mirandabf7d8122016-11-03 15:29:29 -0700331 updateAvailableFolderCellDimensions(dm, res);
Winson Chungb3800242013-10-24 11:01:54 -0700332 }
333
Jon Miranda09660722017-06-14 14:20:14 -0700334 private void updateIconSize(float scale, Resources res, DisplayMetrics dm) {
Jon Miranda18751b62017-07-31 17:25:27 -0700335 // Workspace
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700336 float invIconSizePx = isVerticalBarLayout() ? inv.landscapeIconSize : inv.iconSize;
337 iconSizePx = (int) (Utilities.pxFromDp(invIconSizePx, dm) * scale);
Sunny Goyala50a4192015-12-11 09:50:49 -0800338 iconTextSizePx = (int) (Utilities.pxFromSp(inv.iconTextSize, dm) * scale);
Jon Miranda09660722017-06-14 14:20:14 -0700339 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * scale);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700340
Jon Miranda18751b62017-07-31 17:25:27 -0700341 cellHeightPx = iconSizePx + iconDrawablePaddingPx
342 + Utilities.calculateTextHeight(iconTextSizePx);
Jon Miranda846455e2017-10-02 14:58:52 -0700343 int cellYPadding = (getCellSize().y - cellHeightPx) / 2;
344 if (iconDrawablePaddingPx > cellYPadding && !isVerticalBarLayout()
345 && !inMultiWindowMode()) {
346 // Ensures that the label is closer to its corresponding icon. This is not an issue
347 // with vertical bar layout or multi-window mode since the issue is handled separately
348 // with their calls to {@link #adjustToHideWorkspaceLabels}.
349 cellHeightPx -= (iconDrawablePaddingPx - cellYPadding);
350 iconDrawablePaddingPx = cellYPadding;
351 }
352 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700353
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700354 // All apps
355 allAppsIconTextSizePx = iconTextSizePx;
Winson1f064272016-07-18 17:18:02 -0700356 allAppsIconSizePx = iconSizePx;
357 allAppsIconDrawablePaddingPx = iconDrawablePaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700358 allAppsCellHeightPx = getCellSize().y;
359
360 if (isVerticalBarLayout()) {
361 // Always hide the Workspace text with vertical bar layout.
Jon Miranda1091e532017-07-21 13:31:50 -0700362 adjustToHideWorkspaceLabels();
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700363 }
Winson Chungb3800242013-10-24 11:01:54 -0700364
Winson Chungb3800242013-10-24 11:01:54 -0700365 // Hotseat
Jon Miranda18751b62017-07-31 17:25:27 -0700366 if (isVerticalBarLayout()) {
367 hotseatBarSizePx = iconSizePx;
368 }
Jon Miranda5044c352017-08-09 11:37:59 -0700369 hotseatCellHeightPx = iconSizePx;
Winson Chungb3800242013-10-24 11:01:54 -0700370
Sunny Goyal47328fd2016-05-25 18:56:41 -0700371 if (!isVerticalBarLayout()) {
Jon Miranda18751b62017-07-31 17:25:27 -0700372 int expectedWorkspaceHeight = availableHeightPx - hotseatBarSizePx
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700373 - pageIndicatorSizePx - topWorkspacePadding;
Sunny Goyal47328fd2016-05-25 18:56:41 -0700374 float minRequiredHeight = dropTargetBarSizePx + workspaceSpringLoadedBottomSpace;
375 workspaceSpringLoadShrinkFactor = Math.min(
376 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f,
377 1 - (minRequiredHeight / expectedWorkspaceHeight));
378 } else {
379 workspaceSpringLoadShrinkFactor =
380 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
381 }
382
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700383 // Folder icon
Jon Miranda09660722017-06-14 14:20:14 -0700384 folderBackgroundOffset = -iconDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700385 folderIconSizePx = iconSizePx + 2 * -folderBackgroundOffset;
Adam Cohenefca0272016-02-24 19:19:06 -0800386 folderIconPreviewPadding = res.getDimensionPixelSize(R.dimen.folder_preview_padding);
Winson Chung0f785722015-04-08 10:27:49 -0700387 }
388
Jon Mirandabf7d8122016-11-03 15:29:29 -0700389 private void updateAvailableFolderCellDimensions(DisplayMetrics dm, Resources res) {
390 int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_padding_top)
391 + res.getDimensionPixelSize(R.dimen.folder_label_padding_bottom)
392 + Utilities.calculateTextHeight(res.getDimension(R.dimen.folder_label_text_size));
393
Jon Mirandac1b23992016-12-13 08:57:36 -0800394 updateFolderCellSize(1f, dm, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700395
Jon Mirandac1b23992016-12-13 08:57:36 -0800396 // Don't let the folder get too close to the edges of the screen.
Jon Miranda72b5fd12017-06-25 18:06:23 -0700397 int folderMargin = edgeMarginPx;
Jon Mirandac1b23992016-12-13 08:57:36 -0800398
399 // Check if the icons fit within the available height.
400 float usedHeight = folderCellHeightPx * inv.numFolderRows + folderBottomPanelSize;
401 int maxHeight = availableHeightPx - getTotalWorkspacePadding().y - folderMargin;
402 float scaleY = maxHeight / usedHeight;
403
404 // Check if the icons fit within the available width.
405 float usedWidth = folderCellWidthPx * inv.numFolderColumns;
406 int maxWidth = availableWidthPx - getTotalWorkspacePadding().x - folderMargin;
407 float scaleX = maxWidth / usedWidth;
408
409 float scale = Math.min(scaleX, scaleY);
410 if (scale < 1f) {
411 updateFolderCellSize(scale, dm, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700412 }
413 }
414
Jon Mirandac1b23992016-12-13 08:57:36 -0800415 private void updateFolderCellSize(float scale, DisplayMetrics dm, Resources res) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700416 folderChildIconSizePx = (int) (Utilities.pxFromDp(inv.iconSize, dm) * scale);
417 folderChildTextSizePx =
418 (int) (res.getDimensionPixelSize(R.dimen.folder_child_text_size) * scale);
419
420 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
421 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding) * scale);
422 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding) * scale);
423
Jon Mirandac1b23992016-12-13 08:57:36 -0800424 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
Jonathan Miranda9ad87462017-07-26 17:41:02 +0000425 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
426 folderChildDrawablePaddingPx = Math.max(0,
427 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700428 }
429
Winson1f064272016-07-18 17:18:02 -0700430 public void updateInsets(Rect insets) {
431 mInsets.set(insets);
432 }
433
Winson1f064272016-07-18 17:18:02 -0700434 public void updateAppsViewNumCols() {
435 allAppsNumCols = allAppsNumPredictiveCols = inv.numColumns;
Winson Chungb3800242013-10-24 11:01:54 -0700436 }
437
Tony Wickhama3c74d12015-10-23 11:43:47 -0700438 /** Returns the width and height of the search bar, ignoring any padding. */
Sunny Goyal47328fd2016-05-25 18:56:41 -0700439 public Point getSearchBarDimensForWidgetOpts() {
Tony Wickhama3c74d12015-10-23 11:43:47 -0700440 if (isVerticalBarLayout()) {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700441 return new Point(dropTargetBarSizePx, availableHeightPx - 2 * edgeMarginPx);
Winson Chungb3800242013-10-24 11:01:54 -0700442 } else {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700443 int gap;
Sunny Goyalc6205602015-05-21 20:46:33 -0700444 if (isTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700445 // Pad the left and right of the workspace to ensure consistent spacing
446 // between all icons
Winson Chung4f3bfad2015-07-13 11:14:30 -0700447 int width = getCurrentWidth();
Winson Chungb3800242013-10-24 11:01:54 -0700448 // XXX: If the icon size changes across orientations, we will have to take
449 // that into account here too.
Sunny Goyal47328fd2016-05-25 18:56:41 -0700450 gap = ((width - 2 * edgeMarginPx
451 - (inv.numColumns * cellWidthPx)) / (2 * (inv.numColumns + 1)))
452 + edgeMarginPx;
Winson Chungb3800242013-10-24 11:01:54 -0700453 } else {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700454 gap = desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.right;
Winson Chungb3800242013-10-24 11:01:54 -0700455 }
Sunny Goyal47328fd2016-05-25 18:56:41 -0700456 return new Point(availableWidthPx - 2 * gap, dropTargetBarSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700457 }
Winson Chungb3800242013-10-24 11:01:54 -0700458 }
459
Sunny Goyal756cd262015-08-20 12:33:21 -0700460 public Point getCellSize() {
461 Point result = new Point();
462 // Since we are only concerned with the overall padding, layout direction does
463 // not matter.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700464 Point padding = getTotalWorkspacePadding();
Jon Miranda18751b62017-07-31 17:25:27 -0700465 result.x = calculateCellWidth(availableWidthPx - padding.x
466 - cellLayoutPaddingLeftRightPx * 2, inv.numColumns);
467 result.y = calculateCellHeight(availableHeightPx - padding.y
468 - cellLayoutBottomPaddingPx, inv.numRows);
Sunny Goyal756cd262015-08-20 12:33:21 -0700469 return result;
470 }
471
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700472 public Point getTotalWorkspacePadding() {
Sunny Goyal6178f132016-07-11 17:30:03 -0700473 Rect padding = getWorkspacePadding(null);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700474 return new Point(padding.left + padding.right, padding.top + padding.bottom);
475 }
476
477 /**
478 * Returns the workspace padding in the specified orientation.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700479 */
Sunny Goyal6178f132016-07-11 17:30:03 -0700480 public Rect getWorkspacePadding(Rect recycle) {
481 Rect padding = recycle == null ? new Rect() : recycle;
Tony Wickham3a3517f2015-10-06 11:27:04 -0700482 if (isVerticalBarLayout()) {
Winson1f064272016-07-18 17:18:02 -0700483 if (mInsets.left > 0) {
Jon Miranda18751b62017-07-31 17:25:27 -0700484 padding.set(mInsets.left + pageIndicatorLandLeftNavBarGutterPx,
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700485 0,
Jon Miranda18751b62017-07-31 17:25:27 -0700486 hotseatBarSizePx + hotseatBarLeftNavBarRightPaddingPx
487 + hotseatBarLeftNavBarLeftPaddingPx
488 - mInsets.left,
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700489 edgeMarginPx);
Winson1f064272016-07-18 17:18:02 -0700490 } else {
Jon Miranda18751b62017-07-31 17:25:27 -0700491 padding.set(pageIndicatorLandRightNavBarGutterPx,
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700492 0,
Jon Miranda18751b62017-07-31 17:25:27 -0700493 hotseatBarSizePx + hotseatBarRightNavBarRightPaddingPx
494 + hotseatBarRightNavBarLeftPaddingPx,
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700495 edgeMarginPx);
Winson1f064272016-07-18 17:18:02 -0700496 }
Winson Chungb3800242013-10-24 11:01:54 -0700497 } else {
Jon Miranda18751b62017-07-31 17:25:27 -0700498 int paddingBottom = hotseatBarSizePx + pageIndicatorSizePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700499 if (isTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700500 // Pad the left and right of the workspace to ensure consistent spacing
501 // between all icons
Winson Chung4f3bfad2015-07-13 11:14:30 -0700502 int width = getCurrentWidth();
503 int height = getCurrentHeight();
Tony Wickhamd6b40372015-09-23 18:37:57 -0700504 // The amount of screen space available for left/right padding.
Sunny Goyalf5440cb2016-12-14 15:13:00 -0800505 int availablePaddingX = Math.max(0, width - ((inv.numColumns * cellWidthPx) +
506 ((inv.numColumns - 1) * cellWidthPx)));
Tony Wickhamd6b40372015-09-23 18:37:57 -0700507 availablePaddingX = (int) Math.min(availablePaddingX,
508 width * MAX_HORIZONTAL_PADDING_PERCENT);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700509 int availablePaddingY = Math.max(0, height - topWorkspacePadding - paddingBottom
Jon Mirandac1b08c52016-11-15 14:37:56 -0800510 - (2 * inv.numRows * cellHeightPx) - hotseatBarTopPaddingPx
511 - hotseatBarBottomPaddingPx);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700512 padding.set(availablePaddingX / 2, topWorkspacePadding + availablePaddingY / 2,
Tony Wickhamd6b40372015-09-23 18:37:57 -0700513 availablePaddingX / 2, paddingBottom + availablePaddingY / 2);
Winson Chungb3800242013-10-24 11:01:54 -0700514 } else {
515 // Pad the top and bottom of the workspace with search/hotseat bar sizes
Winson1f064272016-07-18 17:18:02 -0700516 padding.set(desiredWorkspaceLeftRightMarginPx,
Sunny Goyal47328fd2016-05-25 18:56:41 -0700517 topWorkspacePadding,
Winson1f064272016-07-18 17:18:02 -0700518 desiredWorkspaceLeftRightMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700519 paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -0700520 }
521 }
522 return padding;
523 }
524
Winsonfadbe8f2016-07-22 16:35:37 -0700525 /**
526 * @return the bounds for which the open folders should be contained within
527 */
528 public Rect getAbsoluteOpenFolderBounds() {
529 if (isVerticalBarLayout()) {
530 // Folders should only appear right of the drop target bar and left of the hotseat
531 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
532 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -0700533 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700534 mInsets.top + availableHeightPx);
535 } else {
536 // Folders should only appear below the drop target bar and above the hotseat
537 return new Rect(mInsets.left,
538 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
539 mInsets.left + availableWidthPx,
Jon Miranda18751b62017-07-31 17:25:27 -0700540 mInsets.top + availableHeightPx - hotseatBarSizePx
Jon Miranda2ed276e2017-06-29 11:36:34 -0700541 - pageIndicatorSizePx - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -0700542 }
543 }
544
Sunny Goyal47328fd2016-05-25 18:56:41 -0700545 private int getWorkspacePageSpacing() {
Tony Wickham3a3517f2015-10-06 11:27:04 -0700546 if (isVerticalBarLayout() || isLargeTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700547 // In landscape mode the page spacing is set to the default.
548 return defaultPageSpacingPx;
549 } else {
550 // In portrait, we want the pages spaced such that there is no
551 // overhang of the previous / next page into the current page viewport.
552 // We assume symmetrical padding in portrait mode.
Jon Miranda28032002017-07-13 16:18:56 -0700553 return Math.max(defaultPageSpacingPx, getWorkspacePadding(null).left + 1);
Winson Chungb3800242013-10-24 11:01:54 -0700554 }
555 }
556
Adam Cohen2e6da152015-05-06 11:42:25 -0700557 public static int calculateCellWidth(int width, int countX) {
Winson Chungb3800242013-10-24 11:01:54 -0700558 return width / countX;
559 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700560 public static int calculateCellHeight(int height, int countY) {
Winson Chungb3800242013-10-24 11:01:54 -0700561 return height / countY;
562 }
563
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700564 /**
Tony Wickham55616cd2015-09-23 14:55:17 -0700565 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
566 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
567 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700568 */
Tony Wickhamab946a12015-09-16 15:38:16 -0700569 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -0700570 return isLandscape && transposeLayoutWithOrientation;
571 }
572
573 boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyalc6205602015-05-21 20:46:33 -0700574 return isVerticalBarLayout() || isLargeTablet;
Winson Chungb3800242013-10-24 11:01:54 -0700575 }
576
Winson1f064272016-07-18 17:18:02 -0700577 public void layout(Launcher launcher, boolean notifyListeners) {
Winson Chungb3800242013-10-24 11:01:54 -0700578 FrameLayout.LayoutParams lp;
Winson Chungb3800242013-10-24 11:01:54 -0700579 boolean hasVerticalBarLayout = isVerticalBarLayout();
580
581 // Layout the search bar space
Sunny Goyal47328fd2016-05-25 18:56:41 -0700582 Point searchBarBounds = getSearchBarDimensForWidgetOpts();
583 View searchBar = launcher.getDropTargetBar();
Sunny Goyalf37a2142016-03-24 17:28:25 -0700584 lp = (FrameLayout.LayoutParams) searchBar.getLayoutParams();
Sunny Goyal47328fd2016-05-25 18:56:41 -0700585 lp.width = searchBarBounds.x;
586 lp.height = searchBarBounds.y;
Jon Miranda28032002017-07-13 16:18:56 -0700587 lp.topMargin = mInsets.top + edgeMarginPx;
Winson Chungb3800242013-10-24 11:01:54 -0700588 searchBar.setLayoutParams(lp);
589
Winson Chungb3800242013-10-24 11:01:54 -0700590 // Layout the workspace
591 PagedView workspace = (PagedView) launcher.findViewById(R.id.workspace);
Winson1f064272016-07-18 17:18:02 -0700592 Rect workspacePadding = getWorkspacePadding(null);
593 workspace.setPadding(workspacePadding.left, workspacePadding.top, workspacePadding.right,
594 workspacePadding.bottom);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700595 workspace.setPageSpacing(getWorkspacePageSpacing());
Winson Chungb3800242013-10-24 11:01:54 -0700596
597 // Layout the hotseat
Winson6231ede2016-07-20 17:21:55 -0700598 Hotseat hotseat = (Hotseat) launcher.findViewById(R.id.hotseat);
Winson Chungb3800242013-10-24 11:01:54 -0700599 lp = (FrameLayout.LayoutParams) hotseat.getLayoutParams();
Tony Wickhamd6b40372015-09-23 18:37:57 -0700600 // We want the edges of the hotseat to line up with the edges of the workspace, but the
601 // icons in the hotseat are a different size, and so don't line up perfectly. To account for
602 // this, we pad the left and right of the hotseat with half of the difference of a workspace
603 // cell vs a hotseat cell.
604 float workspaceCellWidth = (float) getCurrentWidth() / inv.numColumns;
605 float hotseatCellWidth = (float) getCurrentWidth() / inv.numHotseatIcons;
606 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Winson Chungb3800242013-10-24 11:01:54 -0700607 if (hasVerticalBarLayout) {
Winson Chungf8c6f882015-06-03 11:27:26 -0700608 // Vertical hotseat -- The hotseat is fixed in the layout to be on the right of the
609 // screen regardless of RTL
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700610 int paddingRight = mInsets.left > 0
611 ? hotseatBarLeftNavBarRightPaddingPx
612 : hotseatBarRightNavBarRightPaddingPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700613 int paddingLeft = mInsets.left > 0
614 ? hotseatBarLeftNavBarLeftPaddingPx
615 : hotseatBarRightNavBarLeftPaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700616
Jon Miranda18751b62017-07-31 17:25:27 -0700617 lp.gravity = Gravity.RIGHT;
618 lp.width = hotseatBarSizePx + mInsets.left + mInsets.right
619 + paddingLeft + paddingRight;
620 lp.height = LayoutParams.MATCH_PARENT;
621
622 hotseat.getLayout().setPadding(mInsets.left + cellLayoutPaddingLeftRightPx
623 + paddingLeft,
624 mInsets.top,
625 mInsets.right + cellLayoutPaddingLeftRightPx + paddingRight,
626 workspacePadding.bottom + cellLayoutBottomPaddingPx);
Sunny Goyalc6205602015-05-21 20:46:33 -0700627 } else if (isTablet) {
Winson Chung59a488a2013-12-10 12:32:14 -0800628 // Pad the hotseat with the workspace padding calculated above
Winson Chungb3800242013-10-24 11:01:54 -0700629 lp.gravity = Gravity.BOTTOM;
630 lp.width = LayoutParams.MATCH_PARENT;
Jon Miranda18751b62017-07-31 17:25:27 -0700631 lp.height = hotseatBarSizePx + mInsets.bottom;
Jon Miranda52ff3252017-07-14 11:39:16 -0700632 hotseat.getLayout().setPadding(hotseatAdjustment + workspacePadding.left
633 + cellLayoutPaddingLeftRightPx,
634 hotseatBarTopPaddingPx,
635 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx,
Jon Miranda18751b62017-07-31 17:25:27 -0700636 hotseatBarBottomPaddingPx + mInsets.bottom + cellLayoutBottomPaddingPx);
Winson Chungb3800242013-10-24 11:01:54 -0700637 } else {
638 // For phones, layout the hotseat without any bottom margin
639 // to ensure that we have space for the folders
640 lp.gravity = Gravity.BOTTOM;
641 lp.width = LayoutParams.MATCH_PARENT;
Jon Miranda18751b62017-07-31 17:25:27 -0700642 lp.height = hotseatBarSizePx + mInsets.bottom;
Jon Miranda52ff3252017-07-14 11:39:16 -0700643 hotseat.getLayout().setPadding(hotseatAdjustment + workspacePadding.left
644 + cellLayoutPaddingLeftRightPx,
645 hotseatBarTopPaddingPx,
646 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx,
Jon Miranda18751b62017-07-31 17:25:27 -0700647 hotseatBarBottomPaddingPx + mInsets.bottom + cellLayoutBottomPaddingPx);
Winson Chungb3800242013-10-24 11:01:54 -0700648 }
649 hotseat.setLayoutParams(lp);
650
651 // Layout the page indicators
652 View pageIndicator = launcher.findViewById(R.id.page_indicator);
653 if (pageIndicator != null) {
Hyunyoung Song7d2fc812016-06-15 12:51:30 -0700654 lp = (FrameLayout.LayoutParams) pageIndicator.getLayoutParams();
Winson1f064272016-07-18 17:18:02 -0700655 if (isVerticalBarLayout()) {
656 if (mInsets.left > 0) {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700657 lp.leftMargin = mInsets.left;
658 } else {
659 lp.leftMargin = pageIndicatorLandWorkspaceOffsetPx;
Winson1f064272016-07-18 17:18:02 -0700660 }
661 lp.bottomMargin = workspacePadding.bottom;
662 } else {
Winson Chungb3800242013-10-24 11:01:54 -0700663 // Put the page indicators above the hotseat
Winson Chungb3800242013-10-24 11:01:54 -0700664 lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700665 lp.height = pageIndicatorSizePx;
Jon Miranda18751b62017-07-31 17:25:27 -0700666 lp.bottomMargin = hotseatBarSizePx + mInsets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -0700667 }
Hyunyoung Song7d2fc812016-06-15 12:51:30 -0700668 pageIndicator.setLayoutParams(lp);
Winson Chungb3800242013-10-24 11:01:54 -0700669 }
670
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700671 // Layout the AllAppsRecyclerView
672 View view = launcher.findViewById(R.id.apps_list_view);
Jon Miranda28032002017-07-13 16:18:56 -0700673 int paddingLeftRight = desiredWorkspaceLeftRightMarginPx + cellLayoutPaddingLeftRightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700674 view.setPadding(paddingLeftRight, view.getPaddingTop(), paddingLeftRight,
675 view.getPaddingBottom());
676
Winson1f064272016-07-18 17:18:02 -0700677 if (notifyListeners) {
678 for (int i = mListeners.size() - 1; i >= 0; i--) {
679 mListeners.get(i).onLauncherLayoutChanged();
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700680 }
Winson Chungb3800242013-10-24 11:01:54 -0700681 }
682 }
Winson Chung4f3bfad2015-07-13 11:14:30 -0700683
684 private int getCurrentWidth() {
685 return isLandscape
686 ? Math.max(widthPx, heightPx)
687 : Math.min(widthPx, heightPx);
688 }
689
690 private int getCurrentHeight() {
691 return isLandscape
692 ? Math.min(widthPx, heightPx)
693 : Math.max(widthPx, heightPx);
694 }
Sunny Goyal13178ac2016-04-04 16:35:22 -0700695
Sunny Goyalc13403c2016-11-18 23:44:48 -0800696 public int getCellHeight(@ContainerType int containerType) {
697 switch (containerType) {
698 case CellLayout.WORKSPACE:
699 return cellHeightPx;
700 case CellLayout.FOLDER:
701 return folderCellHeightPx;
702 case CellLayout.HOTSEAT:
703 return hotseatCellHeightPx;
704 default:
705 // ??
706 return 0;
707 }
708 }
Sunny Goyal13178ac2016-04-04 16:35:22 -0700709
Winson1f064272016-07-18 17:18:02 -0700710 /**
711 * @return the left/right paddings for all containers.
712 */
Jon Mirandac3e4e222016-11-02 16:56:52 -0700713 public final int[] getContainerPadding() {
Winson1f064272016-07-18 17:18:02 -0700714 // No paddings for portrait phone
715 if (isPhone && !isVerticalBarLayout()) {
716 return new int[] {0, 0};
Sunny Goyal13178ac2016-04-04 16:35:22 -0700717 }
Winson1f064272016-07-18 17:18:02 -0700718
Hyunyoung Song9d96fd52016-08-23 11:06:24 -0700719 // In landscape, we match the width of the workspace
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700720 Rect padding = getWorkspacePadding(null);
721 return new int[] { padding.left - mInsets.left, padding.right + mInsets.left};
Sunny Goyal13178ac2016-04-04 16:35:22 -0700722 }
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700723
Jon Miranda846455e2017-10-02 14:58:52 -0700724 public boolean inMultiWindowMode() {
725 return this != inv.landscapeProfile && this != inv.portraitProfile;
726 }
727
Jon Miranda51f037d2016-11-07 08:37:20 -0800728 public boolean shouldIgnoreLongPressToOverview(float touchX) {
Jon Miranda51f037d2016-11-07 08:37:20 -0800729 boolean touchedLhsEdge = mInsets.left == 0 && touchX < edgeMarginPx;
730 boolean touchedRhsEdge = mInsets.right == 0 && touchX > (widthPx - edgeMarginPx);
Jon Miranda846455e2017-10-02 14:58:52 -0700731 return !inMultiWindowMode() && (touchedLhsEdge || touchedRhsEdge);
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700732 }
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700733
734 private static Context getContext(Context c, int orientation) {
735 Configuration context = new Configuration(c.getResources().getConfiguration());
736 context.orientation = orientation;
737 return c.createConfigurationContext(context);
738
739 }
Winson Chungb3800242013-10-24 11:01:54 -0700740}