blob: 153131b0bfadc35dcfdfe535c0b699a0caa88a13 [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 Miranda30d0aa22017-07-25 15:55:29 -070066 private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 1.82f;
67
Sunny Goyalc6205602015-05-21 20:46:33 -070068 // Overview mode
69 private final int overviewModeMinIconZoneHeightPx;
70 private final int overviewModeMaxIconZoneHeightPx;
71 private final int overviewModeBarItemWidthPx;
72 private final int overviewModeBarSpacerWidthPx;
73 private final float overviewModeIconZoneRatio;
Winson Chungb3800242013-10-24 11:01:54 -070074
Sunny Goyalc6205602015-05-21 20:46:33 -070075 // Workspace
Jon Miranda28032002017-07-13 16:18:56 -070076 private final int desiredWorkspaceLeftRightMarginPx;
77 public final int cellLayoutPaddingLeftRightPx;
Sunny Goyalc6205602015-05-21 20:46:33 -070078 public final int edgeMarginPx;
79 public final Rect defaultWidgetPadding;
Sunny Goyalc6205602015-05-21 20:46:33 -070080 private final int defaultPageSpacingPx;
Sunny Goyal47328fd2016-05-25 18:56:41 -070081 private final int topWorkspacePadding;
Sunny Goyal47328fd2016-05-25 18:56:41 -070082 public float workspaceSpringLoadShrinkFactor;
83 public final int workspaceSpringLoadedBottomSpace;
Sunny Goyalc6205602015-05-21 20:46:33 -070084
Winson1f064272016-07-18 17:18:02 -070085 // Page indicator
Jon Miranda2ed276e2017-06-29 11:36:34 -070086 private int pageIndicatorSizePx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070087 private final int pageIndicatorLandGutterPx;
Winson1f064272016-07-18 17:18:02 -070088 private final int pageIndicatorLandWorkspaceOffsetPx;
89
Sunny Goyalc6205602015-05-21 20:46:33 -070090 // Workspace icons
91 public int iconSizePx;
92 public int iconTextSizePx;
93 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -070094 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -070095
Adam Cohen59400422014-03-05 18:07:04 -080096 public int cellWidthPx;
97 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070098 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -080099
Sunny Goyalc6205602015-05-21 20:46:33 -0700100 // Folder
101 public int folderBackgroundOffset;
102 public int folderIconSizePx;
Adam Cohenefca0272016-02-24 19:19:06 -0800103 public int folderIconPreviewPadding;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700104
105 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700106 public int folderCellWidthPx;
107 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700108
109 // Folder child
110 public int folderChildIconSizePx;
111 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700112 public int folderChildDrawablePaddingPx;
Jon Mirandafd8fa132017-07-20 14:59:32 -0700113 public final int folderChildDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -0700114
Sunny Goyalc6205602015-05-21 20:46:33 -0700115 // Hotseat
Sunny Goyalc6205602015-05-21 20:46:33 -0700116 public int hotseatCellHeightPx;
Jon Mirandaaca21452016-09-26 14:01:56 -0700117 public int hotseatBarHeightPx;
Sunny Goyal0dc1db42017-05-17 11:34:33 -0700118 public int hotseatBarTopPaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700119 public int hotseatBarLeftNavBarRightPaddingPx;
120 public int hotseatBarRightNavBarRightPaddingPx;
Sunny Goyal0dc1db42017-05-17 11:34:33 -0700121 public int hotseatBarBottomPaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700122 public int hotseatLandLeftNavBarGutterPx;
123 public int hotseatLandRightNavBarGutterPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700124
Sunny Goyalc6205602015-05-21 20:46:33 -0700125 // All apps
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700126 public int allAppsCellHeightPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700127 public int allAppsNumCols;
128 public int allAppsNumPredictiveCols;
Sunny Goyalc6205602015-05-21 20:46:33 -0700129 public int allAppsButtonVisualSize;
Winson1f064272016-07-18 17:18:02 -0700130 public int allAppsIconSizePx;
131 public int allAppsIconDrawablePaddingPx;
132 public float allAppsIconTextSizePx;
133
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800134 // Widgets
135 public final PointF appWidgetScale = new PointF(1.0f, 1.0f);
136
Sunny Goyal47328fd2016-05-25 18:56:41 -0700137 // Drop Target
138 public int dropTargetBarSizePx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700139
Winson1f064272016-07-18 17:18:02 -0700140 // Insets
141 private Rect mInsets = new Rect();
142
143 // Listeners
144 private ArrayList<LauncherLayoutChangeListener> mListeners = new ArrayList<>();
145
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800146 // Icon badges
147 public BadgeRenderer mBadgeRenderer;
148
Sunny Goyalc6205602015-05-21 20:46:33 -0700149 public DeviceProfile(Context context, InvariantDeviceProfile inv,
150 Point minSize, Point maxSize,
151 int width, int height, boolean isLandscape) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700152
Adam Cohen2e6da152015-05-06 11:42:25 -0700153 this.inv = inv;
Sunny Goyalc6205602015-05-21 20:46:33 -0700154 this.isLandscape = isLandscape;
Winson Chungb3800242013-10-24 11:01:54 -0700155
Adam Cohen2e6da152015-05-06 11:42:25 -0700156 Resources res = context.getResources();
Winson Chungb3800242013-10-24 11:01:54 -0700157 DisplayMetrics dm = res.getDisplayMetrics();
Adam Cohen2e6da152015-05-06 11:42:25 -0700158
Sunny Goyalc6205602015-05-21 20:46:33 -0700159 // Constants from resources
160 isTablet = res.getBoolean(R.bool.is_tablet);
161 isLargeTablet = res.getBoolean(R.bool.is_large_tablet);
162 isPhone = !isTablet && !isLargeTablet;
163
164 // Some more constants
Winson Chungb3800242013-10-24 11:01:54 -0700165 transposeLayoutWithOrientation =
166 res.getBoolean(R.bool.hotseat_transpose_layout_with_orientation);
Winson Chungb3800242013-10-24 11:01:54 -0700167
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700168 context = getContext(context, isVerticalBarLayout()
169 ? Configuration.ORIENTATION_LANDSCAPE
170 : Configuration.ORIENTATION_PORTRAIT);
171 res = context.getResources();
172
173
Winson Chungb3800242013-10-24 11:01:54 -0700174 ComponentName cn = new ComponentName(context.getPackageName(),
175 this.getClass().getName());
176 defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
177 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Jon Miranda28032002017-07-13 16:18:56 -0700178 desiredWorkspaceLeftRightMarginPx = isVerticalBarLayout() ? 0 : edgeMarginPx;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700179 cellLayoutPaddingLeftRightPx =
180 res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_padding);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700181 pageIndicatorSizePx = res.getDimensionPixelSize(
182 R.dimen.dynamic_grid_min_page_indicator_size);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700183 pageIndicatorLandGutterPx = res.getDimensionPixelSize(
184 R.dimen.dynamic_grid_page_indicator_gutter_width);
Winson1f064272016-07-18 17:18:02 -0700185 pageIndicatorLandWorkspaceOffsetPx =
186 res.getDimensionPixelSize(R.dimen.all_apps_caret_workspace_offset);
Winson Chungb3800242013-10-24 11:01:54 -0700187 defaultPageSpacingPx =
188 res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_page_spacing);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700189 topWorkspacePadding =
190 res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_top_padding);
Winson Chungb3800242013-10-24 11:01:54 -0700191 overviewModeMinIconZoneHeightPx =
192 res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_min_icon_zone_height);
193 overviewModeMaxIconZoneHeightPx =
194 res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_max_icon_zone_height);
Jorim Jaggid017f882014-01-14 17:08:48 -0800195 overviewModeBarItemWidthPx =
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700196 res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_bar_item_width);
Jorim Jaggid017f882014-01-14 17:08:48 -0800197 overviewModeBarSpacerWidthPx =
198 res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_bar_spacer_width);
Winson Chungb3800242013-10-24 11:01:54 -0700199 overviewModeIconZoneRatio =
200 res.getInteger(R.integer.config_dynamic_grid_overview_icon_zone_percentage) / 100f;
Winson Chungb3800242013-10-24 11:01:54 -0700201 iconDrawablePaddingOriginalPx =
202 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700203 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
204 workspaceSpringLoadedBottomSpace =
205 res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space);
Sunny Goyald5190522017-04-24 03:06:54 -0700206
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700207 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700208
Winson1f064272016-07-18 17:18:02 -0700209 hotseatBarTopPaddingPx =
210 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding);
Sunny Goyald5190522017-04-24 03:06:54 -0700211 hotseatBarBottomPaddingPx =
212 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_padding);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700213 hotseatBarLeftNavBarRightPaddingPx = res.getDimensionPixelSize(
214 R.dimen.dynamic_grid_hotseat_land_left_nav_bar_right_padding);
215 hotseatBarRightNavBarRightPaddingPx = res.getDimensionPixelSize(
216 R.dimen.dynamic_grid_hotseat_land_right_nav_bar_right_padding);
217 hotseatBarHeightPx = isVerticalBarLayout()
218 ? res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_height)
219 : res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_height)
220 + hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx;
221
222 hotseatLandLeftNavBarGutterPx = res.getDimensionPixelSize(
223 R.dimen.dynamic_grid_hotseat_land_left_nav_bar_gutter_width);
224 hotseatLandRightNavBarGutterPx = res.getDimensionPixelSize(
225 R.dimen.dynamic_grid_hotseat_land_right_nav_bar_gutter_width);
Winson Chungb3800242013-10-24 11:01:54 -0700226
Jon Mirandafd8fa132017-07-20 14:59:32 -0700227 folderChildDrawablePaddingOriginalPx =
228 res.getDimensionPixelSize(R.dimen.folder_child_icon_drawable_padding);
229
Sunny Goyalc6205602015-05-21 20:46:33 -0700230 // Determine sizes.
231 widthPx = width;
232 heightPx = height;
233 if (isLandscape) {
234 availableWidthPx = maxSize.x;
235 availableHeightPx = minSize.y;
236 } else {
237 availableWidthPx = minSize.x;
238 availableHeightPx = maxSize.y;
239 }
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700240
Jon Miranda2ed276e2017-06-29 11:36:34 -0700241 // Calculate all of the remaining variables.
Sunny Goyalc6205602015-05-21 20:46:33 -0700242 updateAvailableDimensions(dm, res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700243
244 // Now that we have all of the variables calculated, we can tune certain sizes.
Jon Miranda30d0aa22017-07-25 15:55:29 -0700245 float aspectRatio = ((float) Math.max(availableWidthPx, availableHeightPx))
246 / Math.min(availableWidthPx, availableHeightPx);
247 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
248 if (!isVerticalBarLayout() && isPhone && isTallDevice) {
Jon Miranda2ed276e2017-06-29 11:36:34 -0700249 // We increase the page indicator size when there is extra space.
250 // ie. For a display with a large aspect ratio, we can keep the icons on the workspace
251 // in portrait mode closer together by increasing the page indicator size.
Jon Miranda30d0aa22017-07-25 15:55:29 -0700252 // Note: This calculation was created after noticing a pattern in the design spec.
253 pageIndicatorSizePx = getCellSize().y - iconSizePx - iconDrawablePaddingPx;
254
255 // Recalculate the available dimensions using the new page indicator size.
256 updateAvailableDimensions(dm, res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700257 }
258
Adam Cohen63f1ec02014-08-12 09:23:13 -0700259 computeAllAppsButtonSize(context);
Tony Wickham1237df02017-02-24 08:59:36 -0800260
261 // This is done last, after iconSizePx is calculated above.
262 mBadgeRenderer = new BadgeRenderer(context, iconSizePx);
Adam Cohen63f1ec02014-08-12 09:23:13 -0700263 }
264
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700265 DeviceProfile getMultiWindowProfile(Context context, Point mwSize) {
266 // In multi-window mode, we can have widthPx = availableWidthPx
267 // and heightPx = availableHeightPx because Launcher uses the InvariantDeviceProfiles'
268 // widthPx and heightPx values where it's needed.
Jon Miranda93e1f042016-11-11 14:13:04 -0800269 DeviceProfile profile = new DeviceProfile(context, inv, mwSize, mwSize, mwSize.x, mwSize.y,
270 isLandscape);
271
272 // Hide labels on the workspace.
Jon Miranda1091e532017-07-21 13:31:50 -0700273 profile.adjustToHideWorkspaceLabels();
Jon Miranda93e1f042016-11-11 14:13:04 -0800274
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800275 // We use these scales to measure and layout the widgets using their full invariant profile
276 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
277 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
278 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
279 profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY);
280
Jon Miranda93e1f042016-11-11 14:13:04 -0800281 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700282 }
283
Winson1f064272016-07-18 17:18:02 -0700284 public void addLauncherLayoutChangedListener(LauncherLayoutChangeListener listener) {
285 if (!mListeners.contains(listener)) {
286 mListeners.add(listener);
287 }
288 }
289
290 public void removeLauncherLayoutChangedListener(LauncherLayoutChangeListener listener) {
291 if (mListeners.contains(listener)) {
292 mListeners.remove(listener);
293 }
294 }
295
Adam Cohen63f1ec02014-08-12 09:23:13 -0700296 /**
Jon Miranda1091e532017-07-21 13:31:50 -0700297 * Adjusts the profile so that the labels on the Workspace are hidden.
298 * It is important to call this method after the All Apps variables have been set.
299 */
300 private void adjustToHideWorkspaceLabels() {
301 iconTextSizePx = 0;
302 iconDrawablePaddingPx = 0;
303 cellHeightPx = iconSizePx;
304
305 // In normal cases, All Apps cell height should equal the Workspace cell height.
306 // Since we are removing labels from the Workspace, we need to manually compute the
307 // All Apps cell height.
308 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
309 + Utilities.calculateTextHeight(allAppsIconTextSizePx)
310 // Top and bottom padding is equal to the drawable padding
311 + allAppsIconDrawablePaddingPx * 2;
312 }
313
314 /**
Adam Cohen63f1ec02014-08-12 09:23:13 -0700315 * Determine the exact visual footprint of the all apps button, taking into account scaling
316 * and internal padding of the drawable.
317 */
318 private void computeAllAppsButtonSize(Context context) {
319 Resources res = context.getResources();
320 float padding = res.getInteger(R.integer.config_allAppsButtonPaddingPercent) / 100f;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700321 allAppsButtonVisualSize = (int) (iconSizePx * (1 - padding)) - context.getResources()
Tony Wickhamd6b40372015-09-23 18:37:57 -0700322 .getDimensionPixelSize(R.dimen.all_apps_button_scale_down);
Winson Chungb3800242013-10-24 11:01:54 -0700323 }
324
Sunny Goyalc6205602015-05-21 20:46:33 -0700325 private void updateAvailableDimensions(DisplayMetrics dm, Resources res) {
Jon Miranda09660722017-06-14 14:20:14 -0700326 updateIconSize(1f, res, dm);
Winson Chung59a488a2013-12-10 12:32:14 -0800327
Jon Mirandabf7d8122016-11-03 15:29:29 -0700328 // Check to see if the icons fit within the available height. If not, then scale down.
329 float usedHeight = (cellHeightPx * inv.numRows);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700330 int maxHeight = (availableHeightPx - getTotalWorkspacePadding().y);
Winson Chungb3800242013-10-24 11:01:54 -0700331 if (usedHeight > maxHeight) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700332 float scale = maxHeight / usedHeight;
Jon Miranda09660722017-06-14 14:20:14 -0700333 updateIconSize(scale, res, dm);
Winson Chungb3800242013-10-24 11:01:54 -0700334 }
Jon Mirandabf7d8122016-11-03 15:29:29 -0700335 updateAvailableFolderCellDimensions(dm, res);
Winson Chungb3800242013-10-24 11:01:54 -0700336 }
337
Jon Miranda09660722017-06-14 14:20:14 -0700338 private void updateIconSize(float scale, Resources res, DisplayMetrics dm) {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700339 float invIconSizePx = isVerticalBarLayout() ? inv.landscapeIconSize : inv.iconSize;
340 iconSizePx = (int) (Utilities.pxFromDp(invIconSizePx, dm) * scale);
Sunny Goyala50a4192015-12-11 09:50:49 -0800341 iconTextSizePx = (int) (Utilities.pxFromSp(inv.iconTextSize, dm) * scale);
Jon Miranda09660722017-06-14 14:20:14 -0700342 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * scale);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700343
344 // All apps
345 allAppsIconTextSizePx = iconTextSizePx;
Winson1f064272016-07-18 17:18:02 -0700346 allAppsIconSizePx = iconSizePx;
347 allAppsIconDrawablePaddingPx = iconDrawablePaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700348 allAppsCellHeightPx = getCellSize().y;
349
350 if (isVerticalBarLayout()) {
351 // Always hide the Workspace text with vertical bar layout.
Jon Miranda1091e532017-07-21 13:31:50 -0700352 adjustToHideWorkspaceLabels();
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700353 }
Winson Chungb3800242013-10-24 11:01:54 -0700354
Jon Miranda09660722017-06-14 14:20:14 -0700355 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700356 cellHeightPx = iconSizePx + iconDrawablePaddingPx
357 + Utilities.calculateTextHeight(iconTextSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700358
359 // Hotseat
Jon Miranda09660722017-06-14 14:20:14 -0700360 hotseatCellHeightPx = iconSizePx + iconDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700361
Sunny Goyal47328fd2016-05-25 18:56:41 -0700362 if (!isVerticalBarLayout()) {
363 int expectedWorkspaceHeight = availableHeightPx - hotseatBarHeightPx
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700364 - pageIndicatorSizePx - topWorkspacePadding;
Sunny Goyal47328fd2016-05-25 18:56:41 -0700365 float minRequiredHeight = dropTargetBarSizePx + workspaceSpringLoadedBottomSpace;
366 workspaceSpringLoadShrinkFactor = Math.min(
367 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f,
368 1 - (minRequiredHeight / expectedWorkspaceHeight));
369 } else {
370 workspaceSpringLoadShrinkFactor =
371 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
372 }
373
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700374 // Folder icon
Jon Miranda09660722017-06-14 14:20:14 -0700375 folderBackgroundOffset = -iconDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700376 folderIconSizePx = iconSizePx + 2 * -folderBackgroundOffset;
Adam Cohenefca0272016-02-24 19:19:06 -0800377 folderIconPreviewPadding = res.getDimensionPixelSize(R.dimen.folder_preview_padding);
Winson Chung0f785722015-04-08 10:27:49 -0700378 }
379
Jon Mirandabf7d8122016-11-03 15:29:29 -0700380 private void updateAvailableFolderCellDimensions(DisplayMetrics dm, Resources res) {
381 int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_padding_top)
382 + res.getDimensionPixelSize(R.dimen.folder_label_padding_bottom)
383 + Utilities.calculateTextHeight(res.getDimension(R.dimen.folder_label_text_size));
384
Jon Mirandac1b23992016-12-13 08:57:36 -0800385 updateFolderCellSize(1f, dm, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700386
Jon Mirandac1b23992016-12-13 08:57:36 -0800387 // Don't let the folder get too close to the edges of the screen.
Jon Miranda72b5fd12017-06-25 18:06:23 -0700388 int folderMargin = edgeMarginPx;
Jon Mirandac1b23992016-12-13 08:57:36 -0800389
390 // Check if the icons fit within the available height.
391 float usedHeight = folderCellHeightPx * inv.numFolderRows + folderBottomPanelSize;
392 int maxHeight = availableHeightPx - getTotalWorkspacePadding().y - folderMargin;
393 float scaleY = maxHeight / usedHeight;
394
395 // Check if the icons fit within the available width.
396 float usedWidth = folderCellWidthPx * inv.numFolderColumns;
397 int maxWidth = availableWidthPx - getTotalWorkspacePadding().x - folderMargin;
398 float scaleX = maxWidth / usedWidth;
399
400 float scale = Math.min(scaleX, scaleY);
401 if (scale < 1f) {
402 updateFolderCellSize(scale, dm, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700403 }
404 }
405
Jon Mirandac1b23992016-12-13 08:57:36 -0800406 private void updateFolderCellSize(float scale, DisplayMetrics dm, Resources res) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700407 folderChildIconSizePx = (int) (Utilities.pxFromDp(inv.iconSize, dm) * scale);
408 folderChildTextSizePx =
409 (int) (res.getDimensionPixelSize(R.dimen.folder_child_text_size) * scale);
Jon Mirandafd8fa132017-07-20 14:59:32 -0700410 folderChildDrawablePaddingPx = (int) (folderChildDrawablePaddingOriginalPx * scale);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700411
412 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
413 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding) * scale);
414 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding) * scale);
415
Jon Mirandac1b23992016-12-13 08:57:36 -0800416 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
Jon Mirandafd8fa132017-07-20 14:59:32 -0700417 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight
418 + folderChildDrawablePaddingPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700419 }
420
Winson1f064272016-07-18 17:18:02 -0700421 public void updateInsets(Rect insets) {
422 mInsets.set(insets);
423 }
424
Winson1f064272016-07-18 17:18:02 -0700425 public void updateAppsViewNumCols() {
426 allAppsNumCols = allAppsNumPredictiveCols = inv.numColumns;
Winson Chungb3800242013-10-24 11:01:54 -0700427 }
428
Tony Wickhama3c74d12015-10-23 11:43:47 -0700429 /** Returns the width and height of the search bar, ignoring any padding. */
Sunny Goyal47328fd2016-05-25 18:56:41 -0700430 public Point getSearchBarDimensForWidgetOpts() {
Tony Wickhama3c74d12015-10-23 11:43:47 -0700431 if (isVerticalBarLayout()) {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700432 return new Point(dropTargetBarSizePx, availableHeightPx - 2 * edgeMarginPx);
Winson Chungb3800242013-10-24 11:01:54 -0700433 } else {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700434 int gap;
Sunny Goyalc6205602015-05-21 20:46:33 -0700435 if (isTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700436 // Pad the left and right of the workspace to ensure consistent spacing
437 // between all icons
Winson Chung4f3bfad2015-07-13 11:14:30 -0700438 int width = getCurrentWidth();
Winson Chungb3800242013-10-24 11:01:54 -0700439 // XXX: If the icon size changes across orientations, we will have to take
440 // that into account here too.
Sunny Goyal47328fd2016-05-25 18:56:41 -0700441 gap = ((width - 2 * edgeMarginPx
442 - (inv.numColumns * cellWidthPx)) / (2 * (inv.numColumns + 1)))
443 + edgeMarginPx;
Winson Chungb3800242013-10-24 11:01:54 -0700444 } else {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700445 gap = desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.right;
Winson Chungb3800242013-10-24 11:01:54 -0700446 }
Sunny Goyal47328fd2016-05-25 18:56:41 -0700447 return new Point(availableWidthPx - 2 * gap, dropTargetBarSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700448 }
Winson Chungb3800242013-10-24 11:01:54 -0700449 }
450
Sunny Goyal756cd262015-08-20 12:33:21 -0700451 public Point getCellSize() {
452 Point result = new Point();
453 // Since we are only concerned with the overall padding, layout direction does
454 // not matter.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700455 Point padding = getTotalWorkspacePadding();
Jon Miranda8632d9d2017-07-18 12:42:15 -0700456 int cellPadding = cellLayoutPaddingLeftRightPx * 2;
457 result.x = calculateCellWidth(availableWidthPx - padding.x - cellPadding, inv.numColumns);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700458 result.y = calculateCellHeight(availableHeightPx - padding.y, inv.numRows);
Sunny Goyal756cd262015-08-20 12:33:21 -0700459 return result;
460 }
461
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700462 public Point getTotalWorkspacePadding() {
Sunny Goyal6178f132016-07-11 17:30:03 -0700463 Rect padding = getWorkspacePadding(null);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700464 return new Point(padding.left + padding.right, padding.top + padding.bottom);
465 }
466
467 /**
468 * Returns the workspace padding in the specified orientation.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700469 */
Sunny Goyal6178f132016-07-11 17:30:03 -0700470 public Rect getWorkspacePadding(Rect recycle) {
471 Rect padding = recycle == null ? new Rect() : recycle;
Tony Wickham3a3517f2015-10-06 11:27:04 -0700472 if (isVerticalBarLayout()) {
Winson1f064272016-07-18 17:18:02 -0700473 if (mInsets.left > 0) {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700474 padding.set(mInsets.left + pageIndicatorLandGutterPx,
475 0,
476 hotseatBarHeightPx + hotseatLandLeftNavBarGutterPx
477 + hotseatBarLeftNavBarRightPaddingPx - mInsets.left,
478 edgeMarginPx);
Winson1f064272016-07-18 17:18:02 -0700479 } else {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700480 padding.set(pageIndicatorLandGutterPx,
481 0,
482 hotseatBarHeightPx + hotseatLandRightNavBarGutterPx
483 + hotseatBarRightNavBarRightPaddingPx,
484 edgeMarginPx);
Winson1f064272016-07-18 17:18:02 -0700485 }
Winson Chungb3800242013-10-24 11:01:54 -0700486 } else {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700487 int paddingBottom = hotseatBarHeightPx + pageIndicatorSizePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700488 if (isTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700489 // Pad the left and right of the workspace to ensure consistent spacing
490 // between all icons
Winson Chung4f3bfad2015-07-13 11:14:30 -0700491 int width = getCurrentWidth();
492 int height = getCurrentHeight();
Tony Wickhamd6b40372015-09-23 18:37:57 -0700493 // The amount of screen space available for left/right padding.
Sunny Goyalf5440cb2016-12-14 15:13:00 -0800494 int availablePaddingX = Math.max(0, width - ((inv.numColumns * cellWidthPx) +
495 ((inv.numColumns - 1) * cellWidthPx)));
Tony Wickhamd6b40372015-09-23 18:37:57 -0700496 availablePaddingX = (int) Math.min(availablePaddingX,
497 width * MAX_HORIZONTAL_PADDING_PERCENT);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700498 int availablePaddingY = Math.max(0, height - topWorkspacePadding - paddingBottom
Jon Mirandac1b08c52016-11-15 14:37:56 -0800499 - (2 * inv.numRows * cellHeightPx) - hotseatBarTopPaddingPx
500 - hotseatBarBottomPaddingPx);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700501 padding.set(availablePaddingX / 2, topWorkspacePadding + availablePaddingY / 2,
Tony Wickhamd6b40372015-09-23 18:37:57 -0700502 availablePaddingX / 2, paddingBottom + availablePaddingY / 2);
Winson Chungb3800242013-10-24 11:01:54 -0700503 } else {
504 // Pad the top and bottom of the workspace with search/hotseat bar sizes
Winson1f064272016-07-18 17:18:02 -0700505 padding.set(desiredWorkspaceLeftRightMarginPx,
Sunny Goyal47328fd2016-05-25 18:56:41 -0700506 topWorkspacePadding,
Winson1f064272016-07-18 17:18:02 -0700507 desiredWorkspaceLeftRightMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700508 paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -0700509 }
510 }
511 return padding;
512 }
513
Winsonfadbe8f2016-07-22 16:35:37 -0700514 /**
515 * @return the bounds for which the open folders should be contained within
516 */
517 public Rect getAbsoluteOpenFolderBounds() {
518 if (isVerticalBarLayout()) {
519 // Folders should only appear right of the drop target bar and left of the hotseat
520 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
521 mInsets.top,
522 mInsets.left + availableWidthPx - hotseatBarHeightPx - edgeMarginPx,
523 mInsets.top + availableHeightPx);
524 } else {
525 // Folders should only appear below the drop target bar and above the hotseat
526 return new Rect(mInsets.left,
527 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
528 mInsets.left + availableWidthPx,
Jon Miranda2ed276e2017-06-29 11:36:34 -0700529 mInsets.top + availableHeightPx - hotseatBarHeightPx
530 - pageIndicatorSizePx - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -0700531 }
532 }
533
Sunny Goyal47328fd2016-05-25 18:56:41 -0700534 private int getWorkspacePageSpacing() {
Tony Wickham3a3517f2015-10-06 11:27:04 -0700535 if (isVerticalBarLayout() || isLargeTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700536 // In landscape mode the page spacing is set to the default.
537 return defaultPageSpacingPx;
538 } else {
539 // In portrait, we want the pages spaced such that there is no
540 // overhang of the previous / next page into the current page viewport.
541 // We assume symmetrical padding in portrait mode.
Jon Miranda28032002017-07-13 16:18:56 -0700542 return Math.max(defaultPageSpacingPx, getWorkspacePadding(null).left + 1);
Winson Chungb3800242013-10-24 11:01:54 -0700543 }
544 }
545
Winson Chung4f7eb402015-07-10 18:00:48 -0700546 int getOverviewModeButtonBarHeight() {
Winson Chungb3800242013-10-24 11:01:54 -0700547 int zoneHeight = (int) (overviewModeIconZoneRatio * availableHeightPx);
548 zoneHeight = Math.min(overviewModeMaxIconZoneHeightPx,
549 Math.max(overviewModeMinIconZoneHeightPx, zoneHeight));
Winson Chung4f7eb402015-07-10 18:00:48 -0700550 return zoneHeight;
Winson Chungb3800242013-10-24 11:01:54 -0700551 }
552
Adam Cohen2e6da152015-05-06 11:42:25 -0700553 public static int calculateCellWidth(int width, int countX) {
Winson Chungb3800242013-10-24 11:01:54 -0700554 return width / countX;
555 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700556 public static int calculateCellHeight(int height, int countY) {
Winson Chungb3800242013-10-24 11:01:54 -0700557 return height / countY;
558 }
559
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700560 /**
Tony Wickham55616cd2015-09-23 14:55:17 -0700561 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
562 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
563 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700564 */
Tony Wickhamab946a12015-09-16 15:38:16 -0700565 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -0700566 return isLandscape && transposeLayoutWithOrientation;
567 }
568
569 boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyalc6205602015-05-21 20:46:33 -0700570 return isVerticalBarLayout() || isLargeTablet;
Winson Chungb3800242013-10-24 11:01:54 -0700571 }
572
Sunny Goyalc6205602015-05-21 20:46:33 -0700573 private int getVisibleChildCount(ViewGroup parent) {
Jorim Jaggid017f882014-01-14 17:08:48 -0800574 int visibleChildren = 0;
575 for (int i = 0; i < parent.getChildCount(); i++) {
576 if (parent.getChildAt(i).getVisibility() != View.GONE) {
577 visibleChildren++;
578 }
579 }
580 return visibleChildren;
581 }
582
Winson1f064272016-07-18 17:18:02 -0700583 public void layout(Launcher launcher, boolean notifyListeners) {
Winson Chungb3800242013-10-24 11:01:54 -0700584 FrameLayout.LayoutParams lp;
Winson Chungb3800242013-10-24 11:01:54 -0700585 boolean hasVerticalBarLayout = isVerticalBarLayout();
586
587 // Layout the search bar space
Sunny Goyal47328fd2016-05-25 18:56:41 -0700588 Point searchBarBounds = getSearchBarDimensForWidgetOpts();
589 View searchBar = launcher.getDropTargetBar();
Sunny Goyalf37a2142016-03-24 17:28:25 -0700590 lp = (FrameLayout.LayoutParams) searchBar.getLayoutParams();
Sunny Goyal47328fd2016-05-25 18:56:41 -0700591 lp.width = searchBarBounds.x;
592 lp.height = searchBarBounds.y;
Jon Miranda28032002017-07-13 16:18:56 -0700593 lp.topMargin = mInsets.top + edgeMarginPx;
Winson Chungb3800242013-10-24 11:01:54 -0700594 searchBar.setLayoutParams(lp);
595
Winson Chungb3800242013-10-24 11:01:54 -0700596 // Layout the workspace
597 PagedView workspace = (PagedView) launcher.findViewById(R.id.workspace);
Winson1f064272016-07-18 17:18:02 -0700598 Rect workspacePadding = getWorkspacePadding(null);
599 workspace.setPadding(workspacePadding.left, workspacePadding.top, workspacePadding.right,
600 workspacePadding.bottom);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700601 workspace.setPageSpacing(getWorkspacePageSpacing());
Winson Chungb3800242013-10-24 11:01:54 -0700602
603 // Layout the hotseat
Winson6231ede2016-07-20 17:21:55 -0700604 Hotseat hotseat = (Hotseat) launcher.findViewById(R.id.hotseat);
Winson Chungb3800242013-10-24 11:01:54 -0700605 lp = (FrameLayout.LayoutParams) hotseat.getLayoutParams();
Tony Wickhamd6b40372015-09-23 18:37:57 -0700606 // We want the edges of the hotseat to line up with the edges of the workspace, but the
607 // icons in the hotseat are a different size, and so don't line up perfectly. To account for
608 // this, we pad the left and right of the hotseat with half of the difference of a workspace
609 // cell vs a hotseat cell.
610 float workspaceCellWidth = (float) getCurrentWidth() / inv.numColumns;
611 float hotseatCellWidth = (float) getCurrentWidth() / inv.numHotseatIcons;
612 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Winson Chungb3800242013-10-24 11:01:54 -0700613 if (hasVerticalBarLayout) {
Winson Chungf8c6f882015-06-03 11:27:26 -0700614 // Vertical hotseat -- The hotseat is fixed in the layout to be on the right of the
615 // screen regardless of RTL
616 lp.gravity = Gravity.RIGHT;
Winson1f064272016-07-18 17:18:02 -0700617 lp.width = hotseatBarHeightPx + mInsets.left + mInsets.right;
Winson Chungb3800242013-10-24 11:01:54 -0700618 lp.height = LayoutParams.MATCH_PARENT;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700619
620 int paddingRight = mInsets.left > 0
621 ? hotseatBarLeftNavBarRightPaddingPx
622 : hotseatBarRightNavBarRightPaddingPx;
623
Jon Miranda52ff3252017-07-14 11:39:16 -0700624 hotseat.getLayout().setPadding(mInsets.left + cellLayoutPaddingLeftRightPx,
625 mInsets.top, mInsets.right + paddingRight + cellLayoutPaddingLeftRightPx,
Winson6231ede2016-07-20 17:21:55 -0700626 workspacePadding.bottom);
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;
Winson1f064272016-07-18 17:18:02 -0700631 lp.height = hotseatBarHeightPx + 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 Mirandac1b08c52016-11-15 14:37:56 -0800636 hotseatBarBottomPaddingPx + mInsets.bottom);
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;
Winson1f064272016-07-18 17:18:02 -0700642 lp.height = hotseatBarHeightPx + 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 Mirandac1b08c52016-11-15 14:37:56 -0800647 hotseatBarBottomPaddingPx + mInsets.bottom);
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;
Winson1f064272016-07-18 17:18:02 -0700666 lp.bottomMargin = hotseatBarHeightPx + 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
Winson Chungb3800242013-10-24 11:01:54 -0700671 // Layout the Overview Mode
Jorim Jaggid017f882014-01-14 17:08:48 -0800672 ViewGroup overviewMode = launcher.getOverviewPanel();
Winson Chungb3800242013-10-24 11:01:54 -0700673 if (overviewMode != null) {
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700674 int visibleChildCount = getVisibleChildCount(overviewMode);
675 int totalItemWidth = visibleChildCount * overviewModeBarItemWidthPx;
Jon Mirandadf3bc522016-11-01 16:55:56 -0700676 int maxWidth = totalItemWidth + (visibleChildCount - 1) * overviewModeBarSpacerWidthPx;
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700677
Jon Mirandadf3bc522016-11-01 16:55:56 -0700678 lp = (FrameLayout.LayoutParams) overviewMode.getLayoutParams();
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700679 lp.width = Math.min(availableWidthPx, maxWidth);
Jon Mirandadf3bc522016-11-01 16:55:56 -0700680 lp.height = getOverviewModeButtonBarHeight() + mInsets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -0700681 overviewMode.setLayoutParams(lp);
Winson1f064272016-07-18 17:18:02 -0700682 }
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700683
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700684 // Layout the AllAppsRecyclerView
685 View view = launcher.findViewById(R.id.apps_list_view);
Jon Miranda28032002017-07-13 16:18:56 -0700686 int paddingLeftRight = desiredWorkspaceLeftRightMarginPx + cellLayoutPaddingLeftRightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700687 view.setPadding(paddingLeftRight, view.getPaddingTop(), paddingLeftRight,
688 view.getPaddingBottom());
689
Winson1f064272016-07-18 17:18:02 -0700690 if (notifyListeners) {
691 for (int i = mListeners.size() - 1; i >= 0; i--) {
692 mListeners.get(i).onLauncherLayoutChanged();
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700693 }
Winson Chungb3800242013-10-24 11:01:54 -0700694 }
695 }
Winson Chung4f3bfad2015-07-13 11:14:30 -0700696
697 private int getCurrentWidth() {
698 return isLandscape
699 ? Math.max(widthPx, heightPx)
700 : Math.min(widthPx, heightPx);
701 }
702
703 private int getCurrentHeight() {
704 return isLandscape
705 ? Math.min(widthPx, heightPx)
706 : Math.max(widthPx, heightPx);
707 }
Sunny Goyal13178ac2016-04-04 16:35:22 -0700708
Sunny Goyalc13403c2016-11-18 23:44:48 -0800709 public int getCellHeight(@ContainerType int containerType) {
710 switch (containerType) {
711 case CellLayout.WORKSPACE:
712 return cellHeightPx;
713 case CellLayout.FOLDER:
714 return folderCellHeightPx;
715 case CellLayout.HOTSEAT:
716 return hotseatCellHeightPx;
717 default:
718 // ??
719 return 0;
720 }
721 }
Sunny Goyal13178ac2016-04-04 16:35:22 -0700722
Winson1f064272016-07-18 17:18:02 -0700723 /**
724 * @return the left/right paddings for all containers.
725 */
Jon Mirandac3e4e222016-11-02 16:56:52 -0700726 public final int[] getContainerPadding() {
Winson1f064272016-07-18 17:18:02 -0700727 // No paddings for portrait phone
728 if (isPhone && !isVerticalBarLayout()) {
729 return new int[] {0, 0};
Sunny Goyal13178ac2016-04-04 16:35:22 -0700730 }
Winson1f064272016-07-18 17:18:02 -0700731
Hyunyoung Song9d96fd52016-08-23 11:06:24 -0700732 // In landscape, we match the width of the workspace
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700733 Rect padding = getWorkspacePadding(null);
734 return new int[] { padding.left - mInsets.left, padding.right + mInsets.left};
Sunny Goyal13178ac2016-04-04 16:35:22 -0700735 }
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700736
Jon Miranda51f037d2016-11-07 08:37:20 -0800737 public boolean shouldIgnoreLongPressToOverview(float touchX) {
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700738 boolean inMultiWindowMode = this != inv.landscapeProfile && this != inv.portraitProfile;
Jon Miranda51f037d2016-11-07 08:37:20 -0800739 boolean touchedLhsEdge = mInsets.left == 0 && touchX < edgeMarginPx;
740 boolean touchedRhsEdge = mInsets.right == 0 && touchX > (widthPx - edgeMarginPx);
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700741 return !inMultiWindowMode && (touchedLhsEdge || touchedRhsEdge);
742 }
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700743
744 private static Context getContext(Context c, int orientation) {
745 Configuration context = new Configuration(c.getResources().getConfiguration());
746 context.orientation = orientation;
747 return c.createConfigurationContext(context);
748
749 }
Winson Chungb3800242013-10-24 11:01:54 -0700750}