blob: 6ddaf29db87c5ec0cabcbf1de1ac3588e8edf141 [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;
Tony Wickham9a8d11f2017-01-11 09:53:12 -080034import com.android.launcher3.badge.BadgeRenderer;
Tony Wickhame0c33232016-02-08 11:37:04 -080035
Winson1f064272016-07-18 17:18:02 -070036import java.util.ArrayList;
37
Winson Chungb3800242013-10-24 11:01:54 -070038public class DeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070039
Winson1f064272016-07-18 17:18:02 -070040 public interface LauncherLayoutChangeListener {
41 void onLauncherLayoutChanged();
42 }
43
Adam Cohen2e6da152015-05-06 11:42:25 -070044 public final InvariantDeviceProfile inv;
Winson Chungbe876472014-05-14 14:15:20 -070045
Sunny Goyalc6205602015-05-21 20:46:33 -070046 // Device properties
47 public final boolean isTablet;
48 public final boolean isLargeTablet;
49 public final boolean isPhone;
50 public final boolean transposeLayoutWithOrientation;
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -070051
Sunny Goyalc6205602015-05-21 20:46:33 -070052 // Device properties in current orientation
53 public final boolean isLandscape;
54 public final int widthPx;
55 public final int heightPx;
56 public final int availableWidthPx;
57 public final int availableHeightPx;
Tony Wickhamd6b40372015-09-23 18:37:57 -070058 /**
59 * The maximum amount of left/right workspace padding as a percentage of the screen width.
60 * To be clear, this means that up to 7% of the screen width can be used as left padding, and
61 * 7% of the screen width can be used as right padding.
62 */
63 private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f;
Winson Chungb3800242013-10-24 11:01:54 -070064
Jon Miranda3f9bab22017-07-28 14:50:17 -070065 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f;
Jon Miranda30d0aa22017-07-25 15:55:29 -070066
Winson Chungb3800242013-10-24 11:01:54 -070067
Sunny Goyalc6205602015-05-21 20:46:33 -070068 // Workspace
Jon Miranda28032002017-07-13 16:18:56 -070069 private final int desiredWorkspaceLeftRightMarginPx;
70 public final int cellLayoutPaddingLeftRightPx;
Jon Miranda18751b62017-07-31 17:25:27 -070071 public final int cellLayoutBottomPaddingPx;
Sunny Goyalc6205602015-05-21 20:46:33 -070072 public final int edgeMarginPx;
73 public final Rect defaultWidgetPadding;
Sunny Goyalc6205602015-05-21 20:46:33 -070074 private final int defaultPageSpacingPx;
Sunny Goyal47328fd2016-05-25 18:56:41 -070075 private final int topWorkspacePadding;
Sunny Goyal47328fd2016-05-25 18:56:41 -070076 public float workspaceSpringLoadShrinkFactor;
77 public final int workspaceSpringLoadedBottomSpace;
Sunny Goyalc6205602015-05-21 20:46:33 -070078
Winson1f064272016-07-18 17:18:02 -070079 // Page indicator
Jon Miranda2ed276e2017-06-29 11:36:34 -070080 private int pageIndicatorSizePx;
Jon Miranda18751b62017-07-31 17:25:27 -070081 private final int pageIndicatorLandLeftNavBarGutterPx;
82 private final int pageIndicatorLandRightNavBarGutterPx;
Winson1f064272016-07-18 17:18:02 -070083 private final int pageIndicatorLandWorkspaceOffsetPx;
84
Sunny Goyalc6205602015-05-21 20:46:33 -070085 // Workspace icons
86 public int iconSizePx;
87 public int iconTextSizePx;
88 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -070089 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -070090
Adam Cohen59400422014-03-05 18:07:04 -080091 public int cellWidthPx;
92 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070093 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -080094
Sunny Goyalc6205602015-05-21 20:46:33 -070095 // Folder
96 public int folderBackgroundOffset;
97 public int folderIconSizePx;
Adam Cohenefca0272016-02-24 19:19:06 -080098 public int folderIconPreviewPadding;
Jon Mirandabf7d8122016-11-03 15:29:29 -070099
100 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700101 public int folderCellWidthPx;
102 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700103
104 // Folder child
105 public int folderChildIconSizePx;
106 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700107 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700108
Sunny Goyalc6205602015-05-21 20:46:33 -0700109 // Hotseat
Sunny Goyalc6205602015-05-21 20:46:33 -0700110 public int hotseatCellHeightPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700111 // In portrait: size = height, in landscape: size = width
112 public int hotseatBarSizePx;
Sunny Goyal0dc1db42017-05-17 11:34:33 -0700113 public int hotseatBarTopPaddingPx;
114 public int hotseatBarBottomPaddingPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700115
116 public int hotseatBarLeftNavBarLeftPaddingPx;
117 public int hotseatBarLeftNavBarRightPaddingPx;
118
119 public int hotseatBarRightNavBarLeftPaddingPx;
120 public int hotseatBarRightNavBarRightPaddingPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700121
Sunny Goyalc6205602015-05-21 20:46:33 -0700122 // All apps
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700123 public int allAppsCellHeightPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700124 public int allAppsNumCols;
125 public int allAppsNumPredictiveCols;
Sunny Goyalc6205602015-05-21 20:46:33 -0700126 public int allAppsButtonVisualSize;
Winson1f064272016-07-18 17:18:02 -0700127 public int allAppsIconSizePx;
128 public int allAppsIconDrawablePaddingPx;
129 public float allAppsIconTextSizePx;
130
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800131 // Widgets
132 public final PointF appWidgetScale = new PointF(1.0f, 1.0f);
133
Sunny Goyal47328fd2016-05-25 18:56:41 -0700134 // Drop Target
135 public int dropTargetBarSizePx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700136
Winson1f064272016-07-18 17:18:02 -0700137 // Insets
138 private Rect mInsets = new Rect();
139
140 // Listeners
141 private ArrayList<LauncherLayoutChangeListener> mListeners = new ArrayList<>();
142
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800143 // Icon badges
144 public BadgeRenderer mBadgeRenderer;
145
Sunny Goyalc6205602015-05-21 20:46:33 -0700146 public DeviceProfile(Context context, InvariantDeviceProfile inv,
147 Point minSize, Point maxSize,
148 int width, int height, boolean isLandscape) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700149
Adam Cohen2e6da152015-05-06 11:42:25 -0700150 this.inv = inv;
Sunny Goyalc6205602015-05-21 20:46:33 -0700151 this.isLandscape = isLandscape;
Winson Chungb3800242013-10-24 11:01:54 -0700152
Adam Cohen2e6da152015-05-06 11:42:25 -0700153 Resources res = context.getResources();
Winson Chungb3800242013-10-24 11:01:54 -0700154 DisplayMetrics dm = res.getDisplayMetrics();
Adam Cohen2e6da152015-05-06 11:42:25 -0700155
Sunny Goyalc6205602015-05-21 20:46:33 -0700156 // Constants from resources
157 isTablet = res.getBoolean(R.bool.is_tablet);
158 isLargeTablet = res.getBoolean(R.bool.is_large_tablet);
159 isPhone = !isTablet && !isLargeTablet;
160
161 // Some more constants
Winson Chungb3800242013-10-24 11:01:54 -0700162 transposeLayoutWithOrientation =
163 res.getBoolean(R.bool.hotseat_transpose_layout_with_orientation);
Winson Chungb3800242013-10-24 11:01:54 -0700164
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700165 context = getContext(context, isVerticalBarLayout()
166 ? Configuration.ORIENTATION_LANDSCAPE
167 : Configuration.ORIENTATION_PORTRAIT);
168 res = context.getResources();
169
170
Winson Chungb3800242013-10-24 11:01:54 -0700171 ComponentName cn = new ComponentName(context.getPackageName(),
172 this.getClass().getName());
173 defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
174 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Jon Miranda28032002017-07-13 16:18:56 -0700175 desiredWorkspaceLeftRightMarginPx = isVerticalBarLayout() ? 0 : edgeMarginPx;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700176 cellLayoutPaddingLeftRightPx =
177 res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_padding);
Jon Miranda18751b62017-07-31 17:25:27 -0700178 cellLayoutBottomPaddingPx =
179 res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_bottom_padding);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700180 pageIndicatorSizePx = res.getDimensionPixelSize(
181 R.dimen.dynamic_grid_min_page_indicator_size);
Jon Miranda18751b62017-07-31 17:25:27 -0700182 pageIndicatorLandLeftNavBarGutterPx = res.getDimensionPixelSize(
183 R.dimen.dynamic_grid_page_indicator_land_left_nav_bar_gutter_width);
184 pageIndicatorLandRightNavBarGutterPx = res.getDimensionPixelSize(
185 R.dimen.dynamic_grid_page_indicator_land_right_nav_bar_gutter_width);
Winson1f064272016-07-18 17:18:02 -0700186 pageIndicatorLandWorkspaceOffsetPx =
187 res.getDimensionPixelSize(R.dimen.all_apps_caret_workspace_offset);
Winson Chungb3800242013-10-24 11:01:54 -0700188 defaultPageSpacingPx =
189 res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_page_spacing);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700190 topWorkspacePadding =
191 res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_top_padding);
Winson Chungb3800242013-10-24 11:01:54 -0700192 iconDrawablePaddingOriginalPx =
193 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700194 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
195 workspaceSpringLoadedBottomSpace =
196 res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space);
Sunny Goyald5190522017-04-24 03:06:54 -0700197
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700198 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700199
Winson1f064272016-07-18 17:18:02 -0700200 hotseatBarTopPaddingPx =
201 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding);
Sunny Goyald5190522017-04-24 03:06:54 -0700202 hotseatBarBottomPaddingPx =
203 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_padding);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700204 hotseatBarLeftNavBarRightPaddingPx = res.getDimensionPixelSize(
205 R.dimen.dynamic_grid_hotseat_land_left_nav_bar_right_padding);
206 hotseatBarRightNavBarRightPaddingPx = res.getDimensionPixelSize(
207 R.dimen.dynamic_grid_hotseat_land_right_nav_bar_right_padding);
Jon Miranda18751b62017-07-31 17:25:27 -0700208 hotseatBarLeftNavBarLeftPaddingPx = res.getDimensionPixelSize(
209 R.dimen.dynamic_grid_hotseat_land_left_nav_bar_left_padding);
210 hotseatBarRightNavBarLeftPaddingPx = res.getDimensionPixelSize(
211 R.dimen.dynamic_grid_hotseat_land_right_nav_bar_left_padding);
212 hotseatBarSizePx = isVerticalBarLayout()
213 ? Utilities.pxFromDp(inv.iconSize, dm)
214 : res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_size)
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700215 + hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx;
216
Sunny Goyalc6205602015-05-21 20:46:33 -0700217 // Determine sizes.
218 widthPx = width;
219 heightPx = height;
220 if (isLandscape) {
221 availableWidthPx = maxSize.x;
222 availableHeightPx = minSize.y;
223 } else {
224 availableWidthPx = minSize.x;
225 availableHeightPx = maxSize.y;
226 }
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700227
Jon Miranda2ed276e2017-06-29 11:36:34 -0700228 // Calculate all of the remaining variables.
Sunny Goyalc6205602015-05-21 20:46:33 -0700229 updateAvailableDimensions(dm, res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700230
231 // Now that we have all of the variables calculated, we can tune certain sizes.
Jon Miranda3f9bab22017-07-28 14:50:17 -0700232 float aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Jon Miranda30d0aa22017-07-25 15:55:29 -0700233 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
234 if (!isVerticalBarLayout() && isPhone && isTallDevice) {
Jon Miranda3f9bab22017-07-28 14:50:17 -0700235 // We increase the hotseat size when there is extra space.
Jon Miranda2ed276e2017-06-29 11:36:34 -0700236 // ie. For a display with a large aspect ratio, we can keep the icons on the workspace
Jon Miranda3f9bab22017-07-28 14:50:17 -0700237 // in portrait mode closer together by adding more height to the hotseat.
Jon Miranda30d0aa22017-07-25 15:55:29 -0700238 // Note: This calculation was created after noticing a pattern in the design spec.
Jon Miranda3f9bab22017-07-28 14:50:17 -0700239 int extraSpace = getCellSize().y - iconSizePx - iconDrawablePaddingPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700240 hotseatBarSizePx += extraSpace - pageIndicatorSizePx;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700241
Jon Miranda3f9bab22017-07-28 14:50:17 -0700242 // Recalculate the available dimensions using the new hotseat size.
Jon Miranda30d0aa22017-07-25 15:55:29 -0700243 updateAvailableDimensions(dm, res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700244 }
245
Adam Cohen63f1ec02014-08-12 09:23:13 -0700246 computeAllAppsButtonSize(context);
Tony Wickham1237df02017-02-24 08:59:36 -0800247
248 // This is done last, after iconSizePx is calculated above.
249 mBadgeRenderer = new BadgeRenderer(context, iconSizePx);
Adam Cohen63f1ec02014-08-12 09:23:13 -0700250 }
251
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700252 DeviceProfile getMultiWindowProfile(Context context, Point mwSize) {
Jon Mirandaa11380d2017-08-24 11:30:03 -0700253 // We take the minimum sizes of this profile and it's multi-window variant to ensure that
254 // the system decor is always excluded.
255 mwSize.set(Math.min(availableWidthPx, mwSize.x), Math.min(availableHeightPx, mwSize.y));
256
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700257 // In multi-window mode, we can have widthPx = availableWidthPx
258 // and heightPx = availableHeightPx because Launcher uses the InvariantDeviceProfiles'
259 // widthPx and heightPx values where it's needed.
Jon Miranda93e1f042016-11-11 14:13:04 -0800260 DeviceProfile profile = new DeviceProfile(context, inv, mwSize, mwSize, mwSize.x, mwSize.y,
261 isLandscape);
262
Jon Miranda0cd04572017-09-19 11:31:42 -0700263 // If there isn't enough vertical cell padding with the labels displayed, hide the labels.
264 float workspaceCellPaddingY = profile.getCellSize().y - profile.iconSizePx
265 - iconDrawablePaddingPx - profile.iconTextSizePx;
266 if (workspaceCellPaddingY < profile.iconDrawablePaddingPx * 2) {
267 profile.adjustToHideWorkspaceLabels();
268 }
Jon Miranda93e1f042016-11-11 14:13:04 -0800269
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800270 // We use these scales to measure and layout the widgets using their full invariant profile
271 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
272 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
273 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
274 profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY);
275
Jon Miranda93e1f042016-11-11 14:13:04 -0800276 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700277 }
278
Winson1f064272016-07-18 17:18:02 -0700279 public void addLauncherLayoutChangedListener(LauncherLayoutChangeListener listener) {
280 if (!mListeners.contains(listener)) {
281 mListeners.add(listener);
282 }
283 }
284
285 public void removeLauncherLayoutChangedListener(LauncherLayoutChangeListener listener) {
286 if (mListeners.contains(listener)) {
287 mListeners.remove(listener);
288 }
289 }
290
Adam Cohen63f1ec02014-08-12 09:23:13 -0700291 /**
Jon Miranda1091e532017-07-21 13:31:50 -0700292 * Adjusts the profile so that the labels on the Workspace are hidden.
293 * It is important to call this method after the All Apps variables have been set.
294 */
295 private void adjustToHideWorkspaceLabels() {
296 iconTextSizePx = 0;
297 iconDrawablePaddingPx = 0;
298 cellHeightPx = iconSizePx;
299
300 // In normal cases, All Apps cell height should equal the Workspace cell height.
301 // Since we are removing labels from the Workspace, we need to manually compute the
302 // All Apps cell height.
Jon Miranda3f9bab22017-07-28 14:50:17 -0700303 int topBottomPadding = allAppsIconDrawablePaddingPx * (isVerticalBarLayout() ? 2 : 1);
Jon Miranda1091e532017-07-21 13:31:50 -0700304 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
305 + Utilities.calculateTextHeight(allAppsIconTextSizePx)
Jon Miranda3f9bab22017-07-28 14:50:17 -0700306 + topBottomPadding * 2;
Jon Miranda1091e532017-07-21 13:31:50 -0700307 }
308
309 /**
Adam Cohen63f1ec02014-08-12 09:23:13 -0700310 * Determine the exact visual footprint of the all apps button, taking into account scaling
311 * and internal padding of the drawable.
312 */
313 private void computeAllAppsButtonSize(Context context) {
314 Resources res = context.getResources();
315 float padding = res.getInteger(R.integer.config_allAppsButtonPaddingPercent) / 100f;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700316 allAppsButtonVisualSize = (int) (iconSizePx * (1 - padding)) - context.getResources()
Tony Wickhamd6b40372015-09-23 18:37:57 -0700317 .getDimensionPixelSize(R.dimen.all_apps_button_scale_down);
Winson Chungb3800242013-10-24 11:01:54 -0700318 }
319
Sunny Goyalc6205602015-05-21 20:46:33 -0700320 private void updateAvailableDimensions(DisplayMetrics dm, Resources res) {
Jon Miranda09660722017-06-14 14:20:14 -0700321 updateIconSize(1f, res, dm);
Winson Chung59a488a2013-12-10 12:32:14 -0800322
Jon Mirandabf7d8122016-11-03 15:29:29 -0700323 // Check to see if the icons fit within the available height. If not, then scale down.
324 float usedHeight = (cellHeightPx * inv.numRows);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700325 int maxHeight = (availableHeightPx - getTotalWorkspacePadding().y);
Winson Chungb3800242013-10-24 11:01:54 -0700326 if (usedHeight > maxHeight) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700327 float scale = maxHeight / usedHeight;
Jon Miranda09660722017-06-14 14:20:14 -0700328 updateIconSize(scale, res, dm);
Winson Chungb3800242013-10-24 11:01:54 -0700329 }
Jon Mirandabf7d8122016-11-03 15:29:29 -0700330 updateAvailableFolderCellDimensions(dm, res);
Winson Chungb3800242013-10-24 11:01:54 -0700331 }
332
Jon Miranda09660722017-06-14 14:20:14 -0700333 private void updateIconSize(float scale, Resources res, DisplayMetrics dm) {
Jon Miranda18751b62017-07-31 17:25:27 -0700334 // Workspace
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700335 float invIconSizePx = isVerticalBarLayout() ? inv.landscapeIconSize : inv.iconSize;
336 iconSizePx = (int) (Utilities.pxFromDp(invIconSizePx, dm) * scale);
Sunny Goyala50a4192015-12-11 09:50:49 -0800337 iconTextSizePx = (int) (Utilities.pxFromSp(inv.iconTextSize, dm) * scale);
Jon Miranda09660722017-06-14 14:20:14 -0700338 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * scale);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700339
Jon Miranda18751b62017-07-31 17:25:27 -0700340 cellHeightPx = iconSizePx + iconDrawablePaddingPx
341 + Utilities.calculateTextHeight(iconTextSizePx);
Jon Miranda846455e2017-10-02 14:58:52 -0700342 int cellYPadding = (getCellSize().y - cellHeightPx) / 2;
343 if (iconDrawablePaddingPx > cellYPadding && !isVerticalBarLayout()
344 && !inMultiWindowMode()) {
345 // Ensures that the label is closer to its corresponding icon. This is not an issue
346 // with vertical bar layout or multi-window mode since the issue is handled separately
347 // with their calls to {@link #adjustToHideWorkspaceLabels}.
348 cellHeightPx -= (iconDrawablePaddingPx - cellYPadding);
349 iconDrawablePaddingPx = cellYPadding;
350 }
351 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700352
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700353 // All apps
354 allAppsIconTextSizePx = iconTextSizePx;
Winson1f064272016-07-18 17:18:02 -0700355 allAppsIconSizePx = iconSizePx;
356 allAppsIconDrawablePaddingPx = iconDrawablePaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700357 allAppsCellHeightPx = getCellSize().y;
358
359 if (isVerticalBarLayout()) {
360 // Always hide the Workspace text with vertical bar layout.
Jon Miranda1091e532017-07-21 13:31:50 -0700361 adjustToHideWorkspaceLabels();
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700362 }
Winson Chungb3800242013-10-24 11:01:54 -0700363
Winson Chungb3800242013-10-24 11:01:54 -0700364 // Hotseat
Jon Miranda18751b62017-07-31 17:25:27 -0700365 if (isVerticalBarLayout()) {
366 hotseatBarSizePx = iconSizePx;
367 }
Jon Miranda5044c352017-08-09 11:37:59 -0700368 hotseatCellHeightPx = iconSizePx;
Winson Chungb3800242013-10-24 11:01:54 -0700369
Sunny Goyal47328fd2016-05-25 18:56:41 -0700370 if (!isVerticalBarLayout()) {
Jon Miranda18751b62017-07-31 17:25:27 -0700371 int expectedWorkspaceHeight = availableHeightPx - hotseatBarSizePx
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700372 - pageIndicatorSizePx - topWorkspacePadding;
Sunny Goyal47328fd2016-05-25 18:56:41 -0700373 float minRequiredHeight = dropTargetBarSizePx + workspaceSpringLoadedBottomSpace;
374 workspaceSpringLoadShrinkFactor = Math.min(
375 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f,
376 1 - (minRequiredHeight / expectedWorkspaceHeight));
377 } else {
378 workspaceSpringLoadShrinkFactor =
379 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
380 }
381
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700382 // Folder icon
Jon Miranda09660722017-06-14 14:20:14 -0700383 folderBackgroundOffset = -iconDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700384 folderIconSizePx = iconSizePx + 2 * -folderBackgroundOffset;
Adam Cohenefca0272016-02-24 19:19:06 -0800385 folderIconPreviewPadding = res.getDimensionPixelSize(R.dimen.folder_preview_padding);
Winson Chung0f785722015-04-08 10:27:49 -0700386 }
387
Jon Mirandabf7d8122016-11-03 15:29:29 -0700388 private void updateAvailableFolderCellDimensions(DisplayMetrics dm, Resources res) {
389 int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_padding_top)
390 + res.getDimensionPixelSize(R.dimen.folder_label_padding_bottom)
391 + Utilities.calculateTextHeight(res.getDimension(R.dimen.folder_label_text_size));
392
Jon Mirandac1b23992016-12-13 08:57:36 -0800393 updateFolderCellSize(1f, dm, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700394
Jon Mirandac1b23992016-12-13 08:57:36 -0800395 // Don't let the folder get too close to the edges of the screen.
Jon Miranda72b5fd12017-06-25 18:06:23 -0700396 int folderMargin = edgeMarginPx;
Jon Mirandac1b23992016-12-13 08:57:36 -0800397
398 // Check if the icons fit within the available height.
399 float usedHeight = folderCellHeightPx * inv.numFolderRows + folderBottomPanelSize;
400 int maxHeight = availableHeightPx - getTotalWorkspacePadding().y - folderMargin;
401 float scaleY = maxHeight / usedHeight;
402
403 // Check if the icons fit within the available width.
404 float usedWidth = folderCellWidthPx * inv.numFolderColumns;
405 int maxWidth = availableWidthPx - getTotalWorkspacePadding().x - folderMargin;
406 float scaleX = maxWidth / usedWidth;
407
408 float scale = Math.min(scaleX, scaleY);
409 if (scale < 1f) {
410 updateFolderCellSize(scale, dm, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700411 }
412 }
413
Jon Mirandac1b23992016-12-13 08:57:36 -0800414 private void updateFolderCellSize(float scale, DisplayMetrics dm, Resources res) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700415 folderChildIconSizePx = (int) (Utilities.pxFromDp(inv.iconSize, dm) * scale);
416 folderChildTextSizePx =
417 (int) (res.getDimensionPixelSize(R.dimen.folder_child_text_size) * scale);
418
419 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
420 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding) * scale);
421 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding) * scale);
422
Jon Mirandac1b23992016-12-13 08:57:36 -0800423 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
Jonathan Miranda9ad87462017-07-26 17:41:02 +0000424 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
425 folderChildDrawablePaddingPx = Math.max(0,
426 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700427 }
428
Winson1f064272016-07-18 17:18:02 -0700429 public void updateInsets(Rect insets) {
430 mInsets.set(insets);
431 }
432
Winson1f064272016-07-18 17:18:02 -0700433 public void updateAppsViewNumCols() {
434 allAppsNumCols = allAppsNumPredictiveCols = inv.numColumns;
Winson Chungb3800242013-10-24 11:01:54 -0700435 }
436
Tony Wickhama3c74d12015-10-23 11:43:47 -0700437 /** Returns the width and height of the search bar, ignoring any padding. */
Sunny Goyal47328fd2016-05-25 18:56:41 -0700438 public Point getSearchBarDimensForWidgetOpts() {
Tony Wickhama3c74d12015-10-23 11:43:47 -0700439 if (isVerticalBarLayout()) {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700440 return new Point(dropTargetBarSizePx, availableHeightPx - 2 * edgeMarginPx);
Winson Chungb3800242013-10-24 11:01:54 -0700441 } else {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700442 int gap;
Sunny Goyalc6205602015-05-21 20:46:33 -0700443 if (isTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700444 // Pad the left and right of the workspace to ensure consistent spacing
445 // between all icons
Winson Chung4f3bfad2015-07-13 11:14:30 -0700446 int width = getCurrentWidth();
Winson Chungb3800242013-10-24 11:01:54 -0700447 // XXX: If the icon size changes across orientations, we will have to take
448 // that into account here too.
Sunny Goyal47328fd2016-05-25 18:56:41 -0700449 gap = ((width - 2 * edgeMarginPx
450 - (inv.numColumns * cellWidthPx)) / (2 * (inv.numColumns + 1)))
451 + edgeMarginPx;
Winson Chungb3800242013-10-24 11:01:54 -0700452 } else {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700453 gap = desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.right;
Winson Chungb3800242013-10-24 11:01:54 -0700454 }
Sunny Goyal47328fd2016-05-25 18:56:41 -0700455 return new Point(availableWidthPx - 2 * gap, dropTargetBarSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700456 }
Winson Chungb3800242013-10-24 11:01:54 -0700457 }
458
Sunny Goyal756cd262015-08-20 12:33:21 -0700459 public Point getCellSize() {
460 Point result = new Point();
461 // Since we are only concerned with the overall padding, layout direction does
462 // not matter.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700463 Point padding = getTotalWorkspacePadding();
Jon Miranda18751b62017-07-31 17:25:27 -0700464 result.x = calculateCellWidth(availableWidthPx - padding.x
465 - cellLayoutPaddingLeftRightPx * 2, inv.numColumns);
466 result.y = calculateCellHeight(availableHeightPx - padding.y
467 - cellLayoutBottomPaddingPx, inv.numRows);
Sunny Goyal756cd262015-08-20 12:33:21 -0700468 return result;
469 }
470
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700471 public Point getTotalWorkspacePadding() {
Sunny Goyal6178f132016-07-11 17:30:03 -0700472 Rect padding = getWorkspacePadding(null);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700473 return new Point(padding.left + padding.right, padding.top + padding.bottom);
474 }
475
476 /**
477 * Returns the workspace padding in the specified orientation.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700478 */
Sunny Goyal6178f132016-07-11 17:30:03 -0700479 public Rect getWorkspacePadding(Rect recycle) {
480 Rect padding = recycle == null ? new Rect() : recycle;
Tony Wickham3a3517f2015-10-06 11:27:04 -0700481 if (isVerticalBarLayout()) {
Winson1f064272016-07-18 17:18:02 -0700482 if (mInsets.left > 0) {
Jon Miranda18751b62017-07-31 17:25:27 -0700483 padding.set(mInsets.left + pageIndicatorLandLeftNavBarGutterPx,
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700484 0,
Jon Miranda18751b62017-07-31 17:25:27 -0700485 hotseatBarSizePx + hotseatBarLeftNavBarRightPaddingPx
486 + hotseatBarLeftNavBarLeftPaddingPx
487 - mInsets.left,
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700488 edgeMarginPx);
Winson1f064272016-07-18 17:18:02 -0700489 } else {
Jon Miranda18751b62017-07-31 17:25:27 -0700490 padding.set(pageIndicatorLandRightNavBarGutterPx,
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700491 0,
Jon Miranda18751b62017-07-31 17:25:27 -0700492 hotseatBarSizePx + hotseatBarRightNavBarRightPaddingPx
493 + hotseatBarRightNavBarLeftPaddingPx,
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700494 edgeMarginPx);
Winson1f064272016-07-18 17:18:02 -0700495 }
Winson Chungb3800242013-10-24 11:01:54 -0700496 } else {
Jon Miranda18751b62017-07-31 17:25:27 -0700497 int paddingBottom = hotseatBarSizePx + pageIndicatorSizePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700498 if (isTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700499 // Pad the left and right of the workspace to ensure consistent spacing
500 // between all icons
Winson Chung4f3bfad2015-07-13 11:14:30 -0700501 int width = getCurrentWidth();
502 int height = getCurrentHeight();
Tony Wickhamd6b40372015-09-23 18:37:57 -0700503 // The amount of screen space available for left/right padding.
Sunny Goyalf5440cb2016-12-14 15:13:00 -0800504 int availablePaddingX = Math.max(0, width - ((inv.numColumns * cellWidthPx) +
505 ((inv.numColumns - 1) * cellWidthPx)));
Tony Wickhamd6b40372015-09-23 18:37:57 -0700506 availablePaddingX = (int) Math.min(availablePaddingX,
507 width * MAX_HORIZONTAL_PADDING_PERCENT);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700508 int availablePaddingY = Math.max(0, height - topWorkspacePadding - paddingBottom
Jon Mirandac1b08c52016-11-15 14:37:56 -0800509 - (2 * inv.numRows * cellHeightPx) - hotseatBarTopPaddingPx
510 - hotseatBarBottomPaddingPx);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700511 padding.set(availablePaddingX / 2, topWorkspacePadding + availablePaddingY / 2,
Tony Wickhamd6b40372015-09-23 18:37:57 -0700512 availablePaddingX / 2, paddingBottom + availablePaddingY / 2);
Winson Chungb3800242013-10-24 11:01:54 -0700513 } else {
514 // Pad the top and bottom of the workspace with search/hotseat bar sizes
Winson1f064272016-07-18 17:18:02 -0700515 padding.set(desiredWorkspaceLeftRightMarginPx,
Sunny Goyal47328fd2016-05-25 18:56:41 -0700516 topWorkspacePadding,
Winson1f064272016-07-18 17:18:02 -0700517 desiredWorkspaceLeftRightMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700518 paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -0700519 }
520 }
521 return padding;
522 }
523
Winsonfadbe8f2016-07-22 16:35:37 -0700524 /**
525 * @return the bounds for which the open folders should be contained within
526 */
527 public Rect getAbsoluteOpenFolderBounds() {
528 if (isVerticalBarLayout()) {
529 // Folders should only appear right of the drop target bar and left of the hotseat
530 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
531 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -0700532 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700533 mInsets.top + availableHeightPx);
534 } else {
535 // Folders should only appear below the drop target bar and above the hotseat
536 return new Rect(mInsets.left,
537 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
538 mInsets.left + availableWidthPx,
Jon Miranda18751b62017-07-31 17:25:27 -0700539 mInsets.top + availableHeightPx - hotseatBarSizePx
Jon Miranda2ed276e2017-06-29 11:36:34 -0700540 - pageIndicatorSizePx - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -0700541 }
542 }
543
Sunny Goyal47328fd2016-05-25 18:56:41 -0700544 private int getWorkspacePageSpacing() {
Tony Wickham3a3517f2015-10-06 11:27:04 -0700545 if (isVerticalBarLayout() || isLargeTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700546 // In landscape mode the page spacing is set to the default.
547 return defaultPageSpacingPx;
548 } else {
549 // In portrait, we want the pages spaced such that there is no
550 // overhang of the previous / next page into the current page viewport.
551 // We assume symmetrical padding in portrait mode.
Jon Miranda28032002017-07-13 16:18:56 -0700552 return Math.max(defaultPageSpacingPx, getWorkspacePadding(null).left + 1);
Winson Chungb3800242013-10-24 11:01:54 -0700553 }
554 }
555
Adam Cohen2e6da152015-05-06 11:42:25 -0700556 public static int calculateCellWidth(int width, int countX) {
Winson Chungb3800242013-10-24 11:01:54 -0700557 return width / countX;
558 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700559 public static int calculateCellHeight(int height, int countY) {
Winson Chungb3800242013-10-24 11:01:54 -0700560 return height / countY;
561 }
562
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700563 /**
Tony Wickham55616cd2015-09-23 14:55:17 -0700564 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
565 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
566 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700567 */
Tony Wickhamab946a12015-09-16 15:38:16 -0700568 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -0700569 return isLandscape && transposeLayoutWithOrientation;
570 }
571
572 boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyalc6205602015-05-21 20:46:33 -0700573 return isVerticalBarLayout() || isLargeTablet;
Winson Chungb3800242013-10-24 11:01:54 -0700574 }
575
Winson1f064272016-07-18 17:18:02 -0700576 public void layout(Launcher launcher, boolean notifyListeners) {
Winson Chungb3800242013-10-24 11:01:54 -0700577 FrameLayout.LayoutParams lp;
Winson Chungb3800242013-10-24 11:01:54 -0700578 boolean hasVerticalBarLayout = isVerticalBarLayout();
579
580 // Layout the search bar space
Sunny Goyal47328fd2016-05-25 18:56:41 -0700581 Point searchBarBounds = getSearchBarDimensForWidgetOpts();
582 View searchBar = launcher.getDropTargetBar();
Sunny Goyalf37a2142016-03-24 17:28:25 -0700583 lp = (FrameLayout.LayoutParams) searchBar.getLayoutParams();
Sunny Goyal47328fd2016-05-25 18:56:41 -0700584 lp.width = searchBarBounds.x;
585 lp.height = searchBarBounds.y;
Jon Miranda28032002017-07-13 16:18:56 -0700586 lp.topMargin = mInsets.top + edgeMarginPx;
Winson Chungb3800242013-10-24 11:01:54 -0700587 searchBar.setLayoutParams(lp);
588
Winson Chungb3800242013-10-24 11:01:54 -0700589 // Layout the workspace
590 PagedView workspace = (PagedView) launcher.findViewById(R.id.workspace);
Winson1f064272016-07-18 17:18:02 -0700591 Rect workspacePadding = getWorkspacePadding(null);
592 workspace.setPadding(workspacePadding.left, workspacePadding.top, workspacePadding.right,
593 workspacePadding.bottom);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700594 workspace.setPageSpacing(getWorkspacePageSpacing());
Winson Chungb3800242013-10-24 11:01:54 -0700595
596 // Layout the hotseat
Winson6231ede2016-07-20 17:21:55 -0700597 Hotseat hotseat = (Hotseat) launcher.findViewById(R.id.hotseat);
Winson Chungb3800242013-10-24 11:01:54 -0700598 lp = (FrameLayout.LayoutParams) hotseat.getLayoutParams();
Tony Wickhamd6b40372015-09-23 18:37:57 -0700599 // We want the edges of the hotseat to line up with the edges of the workspace, but the
600 // icons in the hotseat are a different size, and so don't line up perfectly. To account for
601 // this, we pad the left and right of the hotseat with half of the difference of a workspace
602 // cell vs a hotseat cell.
603 float workspaceCellWidth = (float) getCurrentWidth() / inv.numColumns;
604 float hotseatCellWidth = (float) getCurrentWidth() / inv.numHotseatIcons;
605 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Winson Chungb3800242013-10-24 11:01:54 -0700606 if (hasVerticalBarLayout) {
Winson Chungf8c6f882015-06-03 11:27:26 -0700607 // Vertical hotseat -- The hotseat is fixed in the layout to be on the right of the
608 // screen regardless of RTL
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700609 int paddingRight = mInsets.left > 0
610 ? hotseatBarLeftNavBarRightPaddingPx
611 : hotseatBarRightNavBarRightPaddingPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700612 int paddingLeft = mInsets.left > 0
613 ? hotseatBarLeftNavBarLeftPaddingPx
614 : hotseatBarRightNavBarLeftPaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700615
Jon Miranda18751b62017-07-31 17:25:27 -0700616 lp.gravity = Gravity.RIGHT;
617 lp.width = hotseatBarSizePx + mInsets.left + mInsets.right
618 + paddingLeft + paddingRight;
619 lp.height = LayoutParams.MATCH_PARENT;
620
621 hotseat.getLayout().setPadding(mInsets.left + cellLayoutPaddingLeftRightPx
622 + paddingLeft,
623 mInsets.top,
624 mInsets.right + cellLayoutPaddingLeftRightPx + paddingRight,
625 workspacePadding.bottom + cellLayoutBottomPaddingPx);
Sunny Goyalc6205602015-05-21 20:46:33 -0700626 } else if (isTablet) {
Winson Chung59a488a2013-12-10 12:32:14 -0800627 // Pad the hotseat with the workspace padding calculated above
Winson Chungb3800242013-10-24 11:01:54 -0700628 lp.gravity = Gravity.BOTTOM;
629 lp.width = LayoutParams.MATCH_PARENT;
Jon Miranda18751b62017-07-31 17:25:27 -0700630 lp.height = hotseatBarSizePx + mInsets.bottom;
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 } else {
637 // For phones, layout the hotseat without any bottom margin
638 // to ensure that we have space for the folders
639 lp.gravity = Gravity.BOTTOM;
640 lp.width = LayoutParams.MATCH_PARENT;
Jon Miranda18751b62017-07-31 17:25:27 -0700641 lp.height = hotseatBarSizePx + mInsets.bottom;
Jon Miranda52ff3252017-07-14 11:39:16 -0700642 hotseat.getLayout().setPadding(hotseatAdjustment + workspacePadding.left
643 + cellLayoutPaddingLeftRightPx,
644 hotseatBarTopPaddingPx,
645 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx,
Jon Miranda18751b62017-07-31 17:25:27 -0700646 hotseatBarBottomPaddingPx + mInsets.bottom + cellLayoutBottomPaddingPx);
Winson Chungb3800242013-10-24 11:01:54 -0700647 }
648 hotseat.setLayoutParams(lp);
649
650 // Layout the page indicators
651 View pageIndicator = launcher.findViewById(R.id.page_indicator);
652 if (pageIndicator != null) {
Hyunyoung Song7d2fc812016-06-15 12:51:30 -0700653 lp = (FrameLayout.LayoutParams) pageIndicator.getLayoutParams();
Winson1f064272016-07-18 17:18:02 -0700654 if (isVerticalBarLayout()) {
655 if (mInsets.left > 0) {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700656 lp.leftMargin = mInsets.left;
657 } else {
658 lp.leftMargin = pageIndicatorLandWorkspaceOffsetPx;
Winson1f064272016-07-18 17:18:02 -0700659 }
660 lp.bottomMargin = workspacePadding.bottom;
661 } else {
Winson Chungb3800242013-10-24 11:01:54 -0700662 // Put the page indicators above the hotseat
Winson Chungb3800242013-10-24 11:01:54 -0700663 lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700664 lp.height = pageIndicatorSizePx;
Jon Miranda18751b62017-07-31 17:25:27 -0700665 lp.bottomMargin = hotseatBarSizePx + mInsets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -0700666 }
Hyunyoung Song7d2fc812016-06-15 12:51:30 -0700667 pageIndicator.setLayoutParams(lp);
Winson Chungb3800242013-10-24 11:01:54 -0700668 }
669
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700670 // Layout the AllAppsRecyclerView
671 View view = launcher.findViewById(R.id.apps_list_view);
Jon Miranda28032002017-07-13 16:18:56 -0700672 int paddingLeftRight = desiredWorkspaceLeftRightMarginPx + cellLayoutPaddingLeftRightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700673 view.setPadding(paddingLeftRight, view.getPaddingTop(), paddingLeftRight,
674 view.getPaddingBottom());
675
Winson1f064272016-07-18 17:18:02 -0700676 if (notifyListeners) {
677 for (int i = mListeners.size() - 1; i >= 0; i--) {
678 mListeners.get(i).onLauncherLayoutChanged();
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700679 }
Winson Chungb3800242013-10-24 11:01:54 -0700680 }
681 }
Winson Chung4f3bfad2015-07-13 11:14:30 -0700682
Winson Chungb63b44c2017-11-10 17:54:44 -0800683 public int getCurrentWidth() {
Winson Chung4f3bfad2015-07-13 11:14:30 -0700684 return isLandscape
685 ? Math.max(widthPx, heightPx)
686 : Math.min(widthPx, heightPx);
687 }
688
Winson Chungb63b44c2017-11-10 17:54:44 -0800689 public int getCurrentHeight() {
Winson Chung4f3bfad2015-07-13 11:14:30 -0700690 return isLandscape
691 ? Math.min(widthPx, heightPx)
692 : Math.max(widthPx, heightPx);
693 }
Sunny Goyal13178ac2016-04-04 16:35:22 -0700694
Sunny Goyalc13403c2016-11-18 23:44:48 -0800695 public int getCellHeight(@ContainerType int containerType) {
696 switch (containerType) {
697 case CellLayout.WORKSPACE:
698 return cellHeightPx;
699 case CellLayout.FOLDER:
700 return folderCellHeightPx;
701 case CellLayout.HOTSEAT:
702 return hotseatCellHeightPx;
703 default:
704 // ??
705 return 0;
706 }
707 }
Sunny Goyal13178ac2016-04-04 16:35:22 -0700708
Winson1f064272016-07-18 17:18:02 -0700709 /**
710 * @return the left/right paddings for all containers.
711 */
Jon Mirandac3e4e222016-11-02 16:56:52 -0700712 public final int[] getContainerPadding() {
Winson1f064272016-07-18 17:18:02 -0700713 // No paddings for portrait phone
714 if (isPhone && !isVerticalBarLayout()) {
715 return new int[] {0, 0};
Sunny Goyal13178ac2016-04-04 16:35:22 -0700716 }
Winson1f064272016-07-18 17:18:02 -0700717
Hyunyoung Song9d96fd52016-08-23 11:06:24 -0700718 // In landscape, we match the width of the workspace
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700719 Rect padding = getWorkspacePadding(null);
720 return new int[] { padding.left - mInsets.left, padding.right + mInsets.left};
Sunny Goyal13178ac2016-04-04 16:35:22 -0700721 }
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700722
Jon Miranda846455e2017-10-02 14:58:52 -0700723 public boolean inMultiWindowMode() {
724 return this != inv.landscapeProfile && this != inv.portraitProfile;
725 }
726
Jon Miranda51f037d2016-11-07 08:37:20 -0800727 public boolean shouldIgnoreLongPressToOverview(float touchX) {
Jon Miranda51f037d2016-11-07 08:37:20 -0800728 boolean touchedLhsEdge = mInsets.left == 0 && touchX < edgeMarginPx;
729 boolean touchedRhsEdge = mInsets.right == 0 && touchX > (widthPx - edgeMarginPx);
Jon Miranda846455e2017-10-02 14:58:52 -0700730 return !inMultiWindowMode() && (touchedLhsEdge || touchedRhsEdge);
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700731 }
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700732
733 private static Context getContext(Context c, int orientation) {
734 Configuration context = new Configuration(c.getResources().getConfiguration());
735 context.orientation = orientation;
736 return c.createConfigurationContext(context);
737
738 }
Winson Chungb3800242013-10-24 11:01:54 -0700739}