blob: db788ed3a4d4a9bbc55d11522c540708e126ecf9 [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
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;
Jon Miranda18751b62017-07-31 17:25:27 -070078 public final int cellLayoutBottomPaddingPx;
Sunny Goyalc6205602015-05-21 20:46:33 -070079 public final int edgeMarginPx;
80 public final Rect defaultWidgetPadding;
Sunny Goyalc6205602015-05-21 20:46:33 -070081 private final int defaultPageSpacingPx;
Sunny Goyal47328fd2016-05-25 18:56:41 -070082 private final int topWorkspacePadding;
Sunny Goyal47328fd2016-05-25 18:56:41 -070083 public float workspaceSpringLoadShrinkFactor;
84 public final int workspaceSpringLoadedBottomSpace;
Sunny Goyalc6205602015-05-21 20:46:33 -070085
Winson1f064272016-07-18 17:18:02 -070086 // Page indicator
Jon Miranda2ed276e2017-06-29 11:36:34 -070087 private int pageIndicatorSizePx;
Jon Miranda18751b62017-07-31 17:25:27 -070088 private final int pageIndicatorLandLeftNavBarGutterPx;
89 private final int pageIndicatorLandRightNavBarGutterPx;
Winson1f064272016-07-18 17:18:02 -070090 private final int pageIndicatorLandWorkspaceOffsetPx;
91
Sunny Goyalc6205602015-05-21 20:46:33 -070092 // Workspace icons
93 public int iconSizePx;
94 public int iconTextSizePx;
95 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -070096 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -070097
Adam Cohen59400422014-03-05 18:07:04 -080098 public int cellWidthPx;
99 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700100 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -0800101
Sunny Goyalc6205602015-05-21 20:46:33 -0700102 // Folder
103 public int folderBackgroundOffset;
104 public int folderIconSizePx;
Adam Cohenefca0272016-02-24 19:19:06 -0800105 public int folderIconPreviewPadding;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700106
107 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700108 public int folderCellWidthPx;
109 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700110
111 // Folder child
112 public int folderChildIconSizePx;
113 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700114 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700115
Sunny Goyalc6205602015-05-21 20:46:33 -0700116 // Hotseat
Sunny Goyalc6205602015-05-21 20:46:33 -0700117 public int hotseatCellHeightPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700118 // In portrait: size = height, in landscape: size = width
119 public int hotseatBarSizePx;
Sunny Goyal0dc1db42017-05-17 11:34:33 -0700120 public int hotseatBarTopPaddingPx;
121 public int hotseatBarBottomPaddingPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700122
123 public int hotseatBarLeftNavBarLeftPaddingPx;
124 public int hotseatBarLeftNavBarRightPaddingPx;
125
126 public int hotseatBarRightNavBarLeftPaddingPx;
127 public int hotseatBarRightNavBarRightPaddingPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700128
Sunny Goyalc6205602015-05-21 20:46:33 -0700129 // All apps
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700130 public int allAppsCellHeightPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700131 public int allAppsNumCols;
132 public int allAppsNumPredictiveCols;
Sunny Goyalc6205602015-05-21 20:46:33 -0700133 public int allAppsButtonVisualSize;
Winson1f064272016-07-18 17:18:02 -0700134 public int allAppsIconSizePx;
135 public int allAppsIconDrawablePaddingPx;
136 public float allAppsIconTextSizePx;
137
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800138 // Widgets
139 public final PointF appWidgetScale = new PointF(1.0f, 1.0f);
140
Sunny Goyal47328fd2016-05-25 18:56:41 -0700141 // Drop Target
142 public int dropTargetBarSizePx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700143
Winson1f064272016-07-18 17:18:02 -0700144 // Insets
145 private Rect mInsets = new Rect();
146
147 // Listeners
148 private ArrayList<LauncherLayoutChangeListener> mListeners = new ArrayList<>();
149
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800150 // Icon badges
151 public BadgeRenderer mBadgeRenderer;
152
Sunny Goyalc6205602015-05-21 20:46:33 -0700153 public DeviceProfile(Context context, InvariantDeviceProfile inv,
154 Point minSize, Point maxSize,
155 int width, int height, boolean isLandscape) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700156
Adam Cohen2e6da152015-05-06 11:42:25 -0700157 this.inv = inv;
Sunny Goyalc6205602015-05-21 20:46:33 -0700158 this.isLandscape = isLandscape;
Winson Chungb3800242013-10-24 11:01:54 -0700159
Adam Cohen2e6da152015-05-06 11:42:25 -0700160 Resources res = context.getResources();
Winson Chungb3800242013-10-24 11:01:54 -0700161 DisplayMetrics dm = res.getDisplayMetrics();
Adam Cohen2e6da152015-05-06 11:42:25 -0700162
Sunny Goyalc6205602015-05-21 20:46:33 -0700163 // Constants from resources
164 isTablet = res.getBoolean(R.bool.is_tablet);
165 isLargeTablet = res.getBoolean(R.bool.is_large_tablet);
166 isPhone = !isTablet && !isLargeTablet;
167
168 // Some more constants
Winson Chungb3800242013-10-24 11:01:54 -0700169 transposeLayoutWithOrientation =
170 res.getBoolean(R.bool.hotseat_transpose_layout_with_orientation);
Winson Chungb3800242013-10-24 11:01:54 -0700171
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700172 context = getContext(context, isVerticalBarLayout()
173 ? Configuration.ORIENTATION_LANDSCAPE
174 : Configuration.ORIENTATION_PORTRAIT);
175 res = context.getResources();
176
177
Winson Chungb3800242013-10-24 11:01:54 -0700178 ComponentName cn = new ComponentName(context.getPackageName(),
179 this.getClass().getName());
180 defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
181 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Jon Miranda28032002017-07-13 16:18:56 -0700182 desiredWorkspaceLeftRightMarginPx = isVerticalBarLayout() ? 0 : edgeMarginPx;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700183 cellLayoutPaddingLeftRightPx =
184 res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_padding);
Jon Miranda18751b62017-07-31 17:25:27 -0700185 cellLayoutBottomPaddingPx =
186 res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_bottom_padding);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700187 pageIndicatorSizePx = res.getDimensionPixelSize(
188 R.dimen.dynamic_grid_min_page_indicator_size);
Jon Miranda18751b62017-07-31 17:25:27 -0700189 pageIndicatorLandLeftNavBarGutterPx = res.getDimensionPixelSize(
190 R.dimen.dynamic_grid_page_indicator_land_left_nav_bar_gutter_width);
191 pageIndicatorLandRightNavBarGutterPx = res.getDimensionPixelSize(
192 R.dimen.dynamic_grid_page_indicator_land_right_nav_bar_gutter_width);
Winson1f064272016-07-18 17:18:02 -0700193 pageIndicatorLandWorkspaceOffsetPx =
194 res.getDimensionPixelSize(R.dimen.all_apps_caret_workspace_offset);
Winson Chungb3800242013-10-24 11:01:54 -0700195 defaultPageSpacingPx =
196 res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_page_spacing);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700197 topWorkspacePadding =
198 res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_top_padding);
Winson Chungb3800242013-10-24 11:01:54 -0700199 overviewModeMinIconZoneHeightPx =
200 res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_min_icon_zone_height);
201 overviewModeMaxIconZoneHeightPx =
202 res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_max_icon_zone_height);
Jorim Jaggid017f882014-01-14 17:08:48 -0800203 overviewModeBarItemWidthPx =
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700204 res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_bar_item_width);
Jorim Jaggid017f882014-01-14 17:08:48 -0800205 overviewModeBarSpacerWidthPx =
206 res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_bar_spacer_width);
Winson Chungb3800242013-10-24 11:01:54 -0700207 overviewModeIconZoneRatio =
208 res.getInteger(R.integer.config_dynamic_grid_overview_icon_zone_percentage) / 100f;
Winson Chungb3800242013-10-24 11:01:54 -0700209 iconDrawablePaddingOriginalPx =
210 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700211 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
212 workspaceSpringLoadedBottomSpace =
213 res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space);
Sunny Goyald5190522017-04-24 03:06:54 -0700214
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700215 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700216
Winson1f064272016-07-18 17:18:02 -0700217 hotseatBarTopPaddingPx =
218 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding);
Sunny Goyald5190522017-04-24 03:06:54 -0700219 hotseatBarBottomPaddingPx =
220 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_padding);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700221 hotseatBarLeftNavBarRightPaddingPx = res.getDimensionPixelSize(
222 R.dimen.dynamic_grid_hotseat_land_left_nav_bar_right_padding);
223 hotseatBarRightNavBarRightPaddingPx = res.getDimensionPixelSize(
224 R.dimen.dynamic_grid_hotseat_land_right_nav_bar_right_padding);
Jon Miranda18751b62017-07-31 17:25:27 -0700225 hotseatBarLeftNavBarLeftPaddingPx = res.getDimensionPixelSize(
226 R.dimen.dynamic_grid_hotseat_land_left_nav_bar_left_padding);
227 hotseatBarRightNavBarLeftPaddingPx = res.getDimensionPixelSize(
228 R.dimen.dynamic_grid_hotseat_land_right_nav_bar_left_padding);
229 hotseatBarSizePx = isVerticalBarLayout()
230 ? Utilities.pxFromDp(inv.iconSize, dm)
231 : res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_size)
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700232 + hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx;
233
Sunny Goyalc6205602015-05-21 20:46:33 -0700234 // Determine sizes.
235 widthPx = width;
236 heightPx = height;
237 if (isLandscape) {
238 availableWidthPx = maxSize.x;
239 availableHeightPx = minSize.y;
240 } else {
241 availableWidthPx = minSize.x;
242 availableHeightPx = maxSize.y;
243 }
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700244
Jon Miranda2ed276e2017-06-29 11:36:34 -0700245 // Calculate all of the remaining variables.
Sunny Goyalc6205602015-05-21 20:46:33 -0700246 updateAvailableDimensions(dm, res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700247
248 // Now that we have all of the variables calculated, we can tune certain sizes.
Jon Miranda3f9bab22017-07-28 14:50:17 -0700249 float aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Jon Miranda30d0aa22017-07-25 15:55:29 -0700250 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
251 if (!isVerticalBarLayout() && isPhone && isTallDevice) {
Jon Miranda3f9bab22017-07-28 14:50:17 -0700252 // We increase the hotseat size when there is extra space.
Jon Miranda2ed276e2017-06-29 11:36:34 -0700253 // ie. For a display with a large aspect ratio, we can keep the icons on the workspace
Jon Miranda3f9bab22017-07-28 14:50:17 -0700254 // in portrait mode closer together by adding more height to the hotseat.
Jon Miranda30d0aa22017-07-25 15:55:29 -0700255 // Note: This calculation was created after noticing a pattern in the design spec.
Jon Miranda3f9bab22017-07-28 14:50:17 -0700256 int extraSpace = getCellSize().y - iconSizePx - iconDrawablePaddingPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700257 hotseatBarSizePx += extraSpace - pageIndicatorSizePx;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700258
Jon Miranda3f9bab22017-07-28 14:50:17 -0700259 // Recalculate the available dimensions using the new hotseat size.
Jon Miranda30d0aa22017-07-25 15:55:29 -0700260 updateAvailableDimensions(dm, res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700261 }
262
Adam Cohen63f1ec02014-08-12 09:23:13 -0700263 computeAllAppsButtonSize(context);
Tony Wickham1237df02017-02-24 08:59:36 -0800264
265 // This is done last, after iconSizePx is calculated above.
266 mBadgeRenderer = new BadgeRenderer(context, iconSizePx);
Adam Cohen63f1ec02014-08-12 09:23:13 -0700267 }
268
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700269 DeviceProfile getMultiWindowProfile(Context context, Point mwSize) {
Jon Mirandaa11380d2017-08-24 11:30:03 -0700270 // We take the minimum sizes of this profile and it's multi-window variant to ensure that
271 // the system decor is always excluded.
272 mwSize.set(Math.min(availableWidthPx, mwSize.x), Math.min(availableHeightPx, mwSize.y));
273
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700274 // In multi-window mode, we can have widthPx = availableWidthPx
275 // and heightPx = availableHeightPx because Launcher uses the InvariantDeviceProfiles'
276 // widthPx and heightPx values where it's needed.
Jon Miranda93e1f042016-11-11 14:13:04 -0800277 DeviceProfile profile = new DeviceProfile(context, inv, mwSize, mwSize, mwSize.x, mwSize.y,
278 isLandscape);
279
280 // Hide labels on the workspace.
Jon Miranda1091e532017-07-21 13:31:50 -0700281 profile.adjustToHideWorkspaceLabels();
Jon Miranda93e1f042016-11-11 14:13:04 -0800282
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800283 // We use these scales to measure and layout the widgets using their full invariant profile
284 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
285 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
286 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
287 profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY);
288
Jon Miranda93e1f042016-11-11 14:13:04 -0800289 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700290 }
291
Winson1f064272016-07-18 17:18:02 -0700292 public void addLauncherLayoutChangedListener(LauncherLayoutChangeListener listener) {
293 if (!mListeners.contains(listener)) {
294 mListeners.add(listener);
295 }
296 }
297
298 public void removeLauncherLayoutChangedListener(LauncherLayoutChangeListener listener) {
299 if (mListeners.contains(listener)) {
300 mListeners.remove(listener);
301 }
302 }
303
Adam Cohen63f1ec02014-08-12 09:23:13 -0700304 /**
Jon Miranda1091e532017-07-21 13:31:50 -0700305 * Adjusts the profile so that the labels on the Workspace are hidden.
306 * It is important to call this method after the All Apps variables have been set.
307 */
308 private void adjustToHideWorkspaceLabels() {
309 iconTextSizePx = 0;
310 iconDrawablePaddingPx = 0;
311 cellHeightPx = iconSizePx;
312
313 // In normal cases, All Apps cell height should equal the Workspace cell height.
314 // Since we are removing labels from the Workspace, we need to manually compute the
315 // All Apps cell height.
Jon Miranda3f9bab22017-07-28 14:50:17 -0700316 int topBottomPadding = allAppsIconDrawablePaddingPx * (isVerticalBarLayout() ? 2 : 1);
Jon Miranda1091e532017-07-21 13:31:50 -0700317 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
318 + Utilities.calculateTextHeight(allAppsIconTextSizePx)
Jon Miranda3f9bab22017-07-28 14:50:17 -0700319 + topBottomPadding * 2;
Jon Miranda1091e532017-07-21 13:31:50 -0700320 }
321
322 /**
Adam Cohen63f1ec02014-08-12 09:23:13 -0700323 * Determine the exact visual footprint of the all apps button, taking into account scaling
324 * and internal padding of the drawable.
325 */
326 private void computeAllAppsButtonSize(Context context) {
327 Resources res = context.getResources();
328 float padding = res.getInteger(R.integer.config_allAppsButtonPaddingPercent) / 100f;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700329 allAppsButtonVisualSize = (int) (iconSizePx * (1 - padding)) - context.getResources()
Tony Wickhamd6b40372015-09-23 18:37:57 -0700330 .getDimensionPixelSize(R.dimen.all_apps_button_scale_down);
Winson Chungb3800242013-10-24 11:01:54 -0700331 }
332
Sunny Goyalc6205602015-05-21 20:46:33 -0700333 private void updateAvailableDimensions(DisplayMetrics dm, Resources res) {
Jon Miranda09660722017-06-14 14:20:14 -0700334 updateIconSize(1f, res, dm);
Winson Chung59a488a2013-12-10 12:32:14 -0800335
Jon Mirandabf7d8122016-11-03 15:29:29 -0700336 // Check to see if the icons fit within the available height. If not, then scale down.
337 float usedHeight = (cellHeightPx * inv.numRows);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700338 int maxHeight = (availableHeightPx - getTotalWorkspacePadding().y);
Winson Chungb3800242013-10-24 11:01:54 -0700339 if (usedHeight > maxHeight) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700340 float scale = maxHeight / usedHeight;
Jon Miranda09660722017-06-14 14:20:14 -0700341 updateIconSize(scale, res, dm);
Winson Chungb3800242013-10-24 11:01:54 -0700342 }
Jon Mirandabf7d8122016-11-03 15:29:29 -0700343 updateAvailableFolderCellDimensions(dm, res);
Winson Chungb3800242013-10-24 11:01:54 -0700344 }
345
Jon Miranda09660722017-06-14 14:20:14 -0700346 private void updateIconSize(float scale, Resources res, DisplayMetrics dm) {
Jon Miranda18751b62017-07-31 17:25:27 -0700347 // Workspace
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700348 float invIconSizePx = isVerticalBarLayout() ? inv.landscapeIconSize : inv.iconSize;
349 iconSizePx = (int) (Utilities.pxFromDp(invIconSizePx, dm) * scale);
Sunny Goyala50a4192015-12-11 09:50:49 -0800350 iconTextSizePx = (int) (Utilities.pxFromSp(inv.iconTextSize, dm) * scale);
Jon Miranda09660722017-06-14 14:20:14 -0700351 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * scale);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700352
Jon Miranda18751b62017-07-31 17:25:27 -0700353 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
354 cellHeightPx = iconSizePx + iconDrawablePaddingPx
355 + Utilities.calculateTextHeight(iconTextSizePx);
356
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700357 // All apps
358 allAppsIconTextSizePx = iconTextSizePx;
Winson1f064272016-07-18 17:18:02 -0700359 allAppsIconSizePx = iconSizePx;
360 allAppsIconDrawablePaddingPx = iconDrawablePaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700361 allAppsCellHeightPx = getCellSize().y;
362
363 if (isVerticalBarLayout()) {
364 // Always hide the Workspace text with vertical bar layout.
Jon Miranda1091e532017-07-21 13:31:50 -0700365 adjustToHideWorkspaceLabels();
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700366 }
Winson Chungb3800242013-10-24 11:01:54 -0700367
Winson Chungb3800242013-10-24 11:01:54 -0700368 // Hotseat
Jon Miranda18751b62017-07-31 17:25:27 -0700369 if (isVerticalBarLayout()) {
370 hotseatBarSizePx = iconSizePx;
371 }
Jon Miranda5044c352017-08-09 11:37:59 -0700372 hotseatCellHeightPx = iconSizePx;
Winson Chungb3800242013-10-24 11:01:54 -0700373
Sunny Goyal47328fd2016-05-25 18:56:41 -0700374 if (!isVerticalBarLayout()) {
Jon Miranda18751b62017-07-31 17:25:27 -0700375 int expectedWorkspaceHeight = availableHeightPx - hotseatBarSizePx
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700376 - pageIndicatorSizePx - topWorkspacePadding;
Sunny Goyal47328fd2016-05-25 18:56:41 -0700377 float minRequiredHeight = dropTargetBarSizePx + workspaceSpringLoadedBottomSpace;
378 workspaceSpringLoadShrinkFactor = Math.min(
379 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f,
380 1 - (minRequiredHeight / expectedWorkspaceHeight));
381 } else {
382 workspaceSpringLoadShrinkFactor =
383 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
384 }
385
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700386 // Folder icon
Jon Miranda09660722017-06-14 14:20:14 -0700387 folderBackgroundOffset = -iconDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700388 folderIconSizePx = iconSizePx + 2 * -folderBackgroundOffset;
Adam Cohenefca0272016-02-24 19:19:06 -0800389 folderIconPreviewPadding = res.getDimensionPixelSize(R.dimen.folder_preview_padding);
Winson Chung0f785722015-04-08 10:27:49 -0700390 }
391
Jon Mirandabf7d8122016-11-03 15:29:29 -0700392 private void updateAvailableFolderCellDimensions(DisplayMetrics dm, Resources res) {
393 int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_padding_top)
394 + res.getDimensionPixelSize(R.dimen.folder_label_padding_bottom)
395 + Utilities.calculateTextHeight(res.getDimension(R.dimen.folder_label_text_size));
396
Jon Mirandac1b23992016-12-13 08:57:36 -0800397 updateFolderCellSize(1f, dm, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700398
Jon Mirandac1b23992016-12-13 08:57:36 -0800399 // Don't let the folder get too close to the edges of the screen.
Jon Miranda72b5fd12017-06-25 18:06:23 -0700400 int folderMargin = edgeMarginPx;
Jon Mirandac1b23992016-12-13 08:57:36 -0800401
402 // Check if the icons fit within the available height.
403 float usedHeight = folderCellHeightPx * inv.numFolderRows + folderBottomPanelSize;
404 int maxHeight = availableHeightPx - getTotalWorkspacePadding().y - folderMargin;
405 float scaleY = maxHeight / usedHeight;
406
407 // Check if the icons fit within the available width.
408 float usedWidth = folderCellWidthPx * inv.numFolderColumns;
409 int maxWidth = availableWidthPx - getTotalWorkspacePadding().x - folderMargin;
410 float scaleX = maxWidth / usedWidth;
411
412 float scale = Math.min(scaleX, scaleY);
413 if (scale < 1f) {
414 updateFolderCellSize(scale, dm, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700415 }
416 }
417
Jon Mirandac1b23992016-12-13 08:57:36 -0800418 private void updateFolderCellSize(float scale, DisplayMetrics dm, Resources res) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700419 folderChildIconSizePx = (int) (Utilities.pxFromDp(inv.iconSize, dm) * scale);
420 folderChildTextSizePx =
421 (int) (res.getDimensionPixelSize(R.dimen.folder_child_text_size) * scale);
422
423 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
424 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding) * scale);
425 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding) * scale);
426
Jon Mirandac1b23992016-12-13 08:57:36 -0800427 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
Jonathan Miranda9ad87462017-07-26 17:41:02 +0000428 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
429 folderChildDrawablePaddingPx = Math.max(0,
430 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700431 }
432
Winson1f064272016-07-18 17:18:02 -0700433 public void updateInsets(Rect insets) {
434 mInsets.set(insets);
435 }
436
Winson1f064272016-07-18 17:18:02 -0700437 public void updateAppsViewNumCols() {
438 allAppsNumCols = allAppsNumPredictiveCols = inv.numColumns;
Winson Chungb3800242013-10-24 11:01:54 -0700439 }
440
Tony Wickhama3c74d12015-10-23 11:43:47 -0700441 /** Returns the width and height of the search bar, ignoring any padding. */
Sunny Goyal47328fd2016-05-25 18:56:41 -0700442 public Point getSearchBarDimensForWidgetOpts() {
Tony Wickhama3c74d12015-10-23 11:43:47 -0700443 if (isVerticalBarLayout()) {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700444 return new Point(dropTargetBarSizePx, availableHeightPx - 2 * edgeMarginPx);
Winson Chungb3800242013-10-24 11:01:54 -0700445 } else {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700446 int gap;
Sunny Goyalc6205602015-05-21 20:46:33 -0700447 if (isTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700448 // Pad the left and right of the workspace to ensure consistent spacing
449 // between all icons
Winson Chung4f3bfad2015-07-13 11:14:30 -0700450 int width = getCurrentWidth();
Winson Chungb3800242013-10-24 11:01:54 -0700451 // XXX: If the icon size changes across orientations, we will have to take
452 // that into account here too.
Sunny Goyal47328fd2016-05-25 18:56:41 -0700453 gap = ((width - 2 * edgeMarginPx
454 - (inv.numColumns * cellWidthPx)) / (2 * (inv.numColumns + 1)))
455 + edgeMarginPx;
Winson Chungb3800242013-10-24 11:01:54 -0700456 } else {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700457 gap = desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.right;
Winson Chungb3800242013-10-24 11:01:54 -0700458 }
Sunny Goyal47328fd2016-05-25 18:56:41 -0700459 return new Point(availableWidthPx - 2 * gap, dropTargetBarSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700460 }
Winson Chungb3800242013-10-24 11:01:54 -0700461 }
462
Sunny Goyal756cd262015-08-20 12:33:21 -0700463 public Point getCellSize() {
464 Point result = new Point();
465 // Since we are only concerned with the overall padding, layout direction does
466 // not matter.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700467 Point padding = getTotalWorkspacePadding();
Jon Miranda18751b62017-07-31 17:25:27 -0700468 result.x = calculateCellWidth(availableWidthPx - padding.x
469 - cellLayoutPaddingLeftRightPx * 2, inv.numColumns);
470 result.y = calculateCellHeight(availableHeightPx - padding.y
471 - cellLayoutBottomPaddingPx, inv.numRows);
Sunny Goyal756cd262015-08-20 12:33:21 -0700472 return result;
473 }
474
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700475 public Point getTotalWorkspacePadding() {
Sunny Goyal6178f132016-07-11 17:30:03 -0700476 Rect padding = getWorkspacePadding(null);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700477 return new Point(padding.left + padding.right, padding.top + padding.bottom);
478 }
479
480 /**
481 * Returns the workspace padding in the specified orientation.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700482 */
Sunny Goyal6178f132016-07-11 17:30:03 -0700483 public Rect getWorkspacePadding(Rect recycle) {
484 Rect padding = recycle == null ? new Rect() : recycle;
Tony Wickham3a3517f2015-10-06 11:27:04 -0700485 if (isVerticalBarLayout()) {
Winson1f064272016-07-18 17:18:02 -0700486 if (mInsets.left > 0) {
Jon Miranda18751b62017-07-31 17:25:27 -0700487 padding.set(mInsets.left + pageIndicatorLandLeftNavBarGutterPx,
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700488 0,
Jon Miranda18751b62017-07-31 17:25:27 -0700489 hotseatBarSizePx + hotseatBarLeftNavBarRightPaddingPx
490 + hotseatBarLeftNavBarLeftPaddingPx
491 - mInsets.left,
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700492 edgeMarginPx);
Winson1f064272016-07-18 17:18:02 -0700493 } else {
Jon Miranda18751b62017-07-31 17:25:27 -0700494 padding.set(pageIndicatorLandRightNavBarGutterPx,
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700495 0,
Jon Miranda18751b62017-07-31 17:25:27 -0700496 hotseatBarSizePx + hotseatBarRightNavBarRightPaddingPx
497 + hotseatBarRightNavBarLeftPaddingPx,
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700498 edgeMarginPx);
Winson1f064272016-07-18 17:18:02 -0700499 }
Winson Chungb3800242013-10-24 11:01:54 -0700500 } else {
Jon Miranda18751b62017-07-31 17:25:27 -0700501 int paddingBottom = hotseatBarSizePx + pageIndicatorSizePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700502 if (isTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700503 // Pad the left and right of the workspace to ensure consistent spacing
504 // between all icons
Winson Chung4f3bfad2015-07-13 11:14:30 -0700505 int width = getCurrentWidth();
506 int height = getCurrentHeight();
Tony Wickhamd6b40372015-09-23 18:37:57 -0700507 // The amount of screen space available for left/right padding.
Sunny Goyalf5440cb2016-12-14 15:13:00 -0800508 int availablePaddingX = Math.max(0, width - ((inv.numColumns * cellWidthPx) +
509 ((inv.numColumns - 1) * cellWidthPx)));
Tony Wickhamd6b40372015-09-23 18:37:57 -0700510 availablePaddingX = (int) Math.min(availablePaddingX,
511 width * MAX_HORIZONTAL_PADDING_PERCENT);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700512 int availablePaddingY = Math.max(0, height - topWorkspacePadding - paddingBottom
Jon Mirandac1b08c52016-11-15 14:37:56 -0800513 - (2 * inv.numRows * cellHeightPx) - hotseatBarTopPaddingPx
514 - hotseatBarBottomPaddingPx);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700515 padding.set(availablePaddingX / 2, topWorkspacePadding + availablePaddingY / 2,
Tony Wickhamd6b40372015-09-23 18:37:57 -0700516 availablePaddingX / 2, paddingBottom + availablePaddingY / 2);
Winson Chungb3800242013-10-24 11:01:54 -0700517 } else {
518 // Pad the top and bottom of the workspace with search/hotseat bar sizes
Winson1f064272016-07-18 17:18:02 -0700519 padding.set(desiredWorkspaceLeftRightMarginPx,
Sunny Goyal47328fd2016-05-25 18:56:41 -0700520 topWorkspacePadding,
Winson1f064272016-07-18 17:18:02 -0700521 desiredWorkspaceLeftRightMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700522 paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -0700523 }
524 }
525 return padding;
526 }
527
Winsonfadbe8f2016-07-22 16:35:37 -0700528 /**
529 * @return the bounds for which the open folders should be contained within
530 */
531 public Rect getAbsoluteOpenFolderBounds() {
532 if (isVerticalBarLayout()) {
533 // Folders should only appear right of the drop target bar and left of the hotseat
534 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
535 mInsets.top,
Jon Miranda18751b62017-07-31 17:25:27 -0700536 mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700537 mInsets.top + availableHeightPx);
538 } else {
539 // Folders should only appear below the drop target bar and above the hotseat
540 return new Rect(mInsets.left,
541 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
542 mInsets.left + availableWidthPx,
Jon Miranda18751b62017-07-31 17:25:27 -0700543 mInsets.top + availableHeightPx - hotseatBarSizePx
Jon Miranda2ed276e2017-06-29 11:36:34 -0700544 - pageIndicatorSizePx - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -0700545 }
546 }
547
Sunny Goyal47328fd2016-05-25 18:56:41 -0700548 private int getWorkspacePageSpacing() {
Tony Wickham3a3517f2015-10-06 11:27:04 -0700549 if (isVerticalBarLayout() || isLargeTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700550 // In landscape mode the page spacing is set to the default.
551 return defaultPageSpacingPx;
552 } else {
553 // In portrait, we want the pages spaced such that there is no
554 // overhang of the previous / next page into the current page viewport.
555 // We assume symmetrical padding in portrait mode.
Jon Miranda28032002017-07-13 16:18:56 -0700556 return Math.max(defaultPageSpacingPx, getWorkspacePadding(null).left + 1);
Winson Chungb3800242013-10-24 11:01:54 -0700557 }
558 }
559
Winson Chung4f7eb402015-07-10 18:00:48 -0700560 int getOverviewModeButtonBarHeight() {
Winson Chungb3800242013-10-24 11:01:54 -0700561 int zoneHeight = (int) (overviewModeIconZoneRatio * availableHeightPx);
562 zoneHeight = Math.min(overviewModeMaxIconZoneHeightPx,
563 Math.max(overviewModeMinIconZoneHeightPx, zoneHeight));
Winson Chung4f7eb402015-07-10 18:00:48 -0700564 return zoneHeight;
Winson Chungb3800242013-10-24 11:01:54 -0700565 }
566
Adam Cohen2e6da152015-05-06 11:42:25 -0700567 public static int calculateCellWidth(int width, int countX) {
Winson Chungb3800242013-10-24 11:01:54 -0700568 return width / countX;
569 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700570 public static int calculateCellHeight(int height, int countY) {
Winson Chungb3800242013-10-24 11:01:54 -0700571 return height / countY;
572 }
573
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700574 /**
Tony Wickham55616cd2015-09-23 14:55:17 -0700575 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
576 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
577 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700578 */
Tony Wickhamab946a12015-09-16 15:38:16 -0700579 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -0700580 return isLandscape && transposeLayoutWithOrientation;
581 }
582
583 boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyalc6205602015-05-21 20:46:33 -0700584 return isVerticalBarLayout() || isLargeTablet;
Winson Chungb3800242013-10-24 11:01:54 -0700585 }
586
Sunny Goyalc6205602015-05-21 20:46:33 -0700587 private int getVisibleChildCount(ViewGroup parent) {
Jorim Jaggid017f882014-01-14 17:08:48 -0800588 int visibleChildren = 0;
589 for (int i = 0; i < parent.getChildCount(); i++) {
590 if (parent.getChildAt(i).getVisibility() != View.GONE) {
591 visibleChildren++;
592 }
593 }
594 return visibleChildren;
595 }
596
Winson1f064272016-07-18 17:18:02 -0700597 public void layout(Launcher launcher, boolean notifyListeners) {
Winson Chungb3800242013-10-24 11:01:54 -0700598 FrameLayout.LayoutParams lp;
Winson Chungb3800242013-10-24 11:01:54 -0700599 boolean hasVerticalBarLayout = isVerticalBarLayout();
600
601 // Layout the search bar space
Sunny Goyal47328fd2016-05-25 18:56:41 -0700602 Point searchBarBounds = getSearchBarDimensForWidgetOpts();
603 View searchBar = launcher.getDropTargetBar();
Sunny Goyalf37a2142016-03-24 17:28:25 -0700604 lp = (FrameLayout.LayoutParams) searchBar.getLayoutParams();
Sunny Goyal47328fd2016-05-25 18:56:41 -0700605 lp.width = searchBarBounds.x;
606 lp.height = searchBarBounds.y;
Jon Miranda28032002017-07-13 16:18:56 -0700607 lp.topMargin = mInsets.top + edgeMarginPx;
Winson Chungb3800242013-10-24 11:01:54 -0700608 searchBar.setLayoutParams(lp);
609
Winson Chungb3800242013-10-24 11:01:54 -0700610 // Layout the workspace
611 PagedView workspace = (PagedView) launcher.findViewById(R.id.workspace);
Winson1f064272016-07-18 17:18:02 -0700612 Rect workspacePadding = getWorkspacePadding(null);
613 workspace.setPadding(workspacePadding.left, workspacePadding.top, workspacePadding.right,
614 workspacePadding.bottom);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700615 workspace.setPageSpacing(getWorkspacePageSpacing());
Winson Chungb3800242013-10-24 11:01:54 -0700616
617 // Layout the hotseat
Winson6231ede2016-07-20 17:21:55 -0700618 Hotseat hotseat = (Hotseat) launcher.findViewById(R.id.hotseat);
Winson Chungb3800242013-10-24 11:01:54 -0700619 lp = (FrameLayout.LayoutParams) hotseat.getLayoutParams();
Tony Wickhamd6b40372015-09-23 18:37:57 -0700620 // We want the edges of the hotseat to line up with the edges of the workspace, but the
621 // icons in the hotseat are a different size, and so don't line up perfectly. To account for
622 // this, we pad the left and right of the hotseat with half of the difference of a workspace
623 // cell vs a hotseat cell.
624 float workspaceCellWidth = (float) getCurrentWidth() / inv.numColumns;
625 float hotseatCellWidth = (float) getCurrentWidth() / inv.numHotseatIcons;
626 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Winson Chungb3800242013-10-24 11:01:54 -0700627 if (hasVerticalBarLayout) {
Winson Chungf8c6f882015-06-03 11:27:26 -0700628 // Vertical hotseat -- The hotseat is fixed in the layout to be on the right of the
629 // screen regardless of RTL
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700630 int paddingRight = mInsets.left > 0
631 ? hotseatBarLeftNavBarRightPaddingPx
632 : hotseatBarRightNavBarRightPaddingPx;
Jon Miranda18751b62017-07-31 17:25:27 -0700633 int paddingLeft = mInsets.left > 0
634 ? hotseatBarLeftNavBarLeftPaddingPx
635 : hotseatBarRightNavBarLeftPaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700636
Jon Miranda18751b62017-07-31 17:25:27 -0700637 lp.gravity = Gravity.RIGHT;
638 lp.width = hotseatBarSizePx + mInsets.left + mInsets.right
639 + paddingLeft + paddingRight;
640 lp.height = LayoutParams.MATCH_PARENT;
641
642 hotseat.getLayout().setPadding(mInsets.left + cellLayoutPaddingLeftRightPx
643 + paddingLeft,
644 mInsets.top,
645 mInsets.right + cellLayoutPaddingLeftRightPx + paddingRight,
646 workspacePadding.bottom + cellLayoutBottomPaddingPx);
Sunny Goyalc6205602015-05-21 20:46:33 -0700647 } else if (isTablet) {
Winson Chung59a488a2013-12-10 12:32:14 -0800648 // Pad the hotseat with the workspace padding calculated above
Winson Chungb3800242013-10-24 11:01:54 -0700649 lp.gravity = Gravity.BOTTOM;
650 lp.width = LayoutParams.MATCH_PARENT;
Jon Miranda18751b62017-07-31 17:25:27 -0700651 lp.height = hotseatBarSizePx + mInsets.bottom;
Jon Miranda52ff3252017-07-14 11:39:16 -0700652 hotseat.getLayout().setPadding(hotseatAdjustment + workspacePadding.left
653 + cellLayoutPaddingLeftRightPx,
654 hotseatBarTopPaddingPx,
655 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx,
Jon Miranda18751b62017-07-31 17:25:27 -0700656 hotseatBarBottomPaddingPx + mInsets.bottom + cellLayoutBottomPaddingPx);
Winson Chungb3800242013-10-24 11:01:54 -0700657 } else {
658 // For phones, layout the hotseat without any bottom margin
659 // to ensure that we have space for the folders
660 lp.gravity = Gravity.BOTTOM;
661 lp.width = LayoutParams.MATCH_PARENT;
Jon Miranda18751b62017-07-31 17:25:27 -0700662 lp.height = hotseatBarSizePx + mInsets.bottom;
Jon Miranda52ff3252017-07-14 11:39:16 -0700663 hotseat.getLayout().setPadding(hotseatAdjustment + workspacePadding.left
664 + cellLayoutPaddingLeftRightPx,
665 hotseatBarTopPaddingPx,
666 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx,
Jon Miranda18751b62017-07-31 17:25:27 -0700667 hotseatBarBottomPaddingPx + mInsets.bottom + cellLayoutBottomPaddingPx);
Winson Chungb3800242013-10-24 11:01:54 -0700668 }
669 hotseat.setLayoutParams(lp);
670
671 // Layout the page indicators
672 View pageIndicator = launcher.findViewById(R.id.page_indicator);
673 if (pageIndicator != null) {
Hyunyoung Song7d2fc812016-06-15 12:51:30 -0700674 lp = (FrameLayout.LayoutParams) pageIndicator.getLayoutParams();
Winson1f064272016-07-18 17:18:02 -0700675 if (isVerticalBarLayout()) {
676 if (mInsets.left > 0) {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700677 lp.leftMargin = mInsets.left;
678 } else {
679 lp.leftMargin = pageIndicatorLandWorkspaceOffsetPx;
Winson1f064272016-07-18 17:18:02 -0700680 }
681 lp.bottomMargin = workspacePadding.bottom;
682 } else {
Winson Chungb3800242013-10-24 11:01:54 -0700683 // Put the page indicators above the hotseat
Winson Chungb3800242013-10-24 11:01:54 -0700684 lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700685 lp.height = pageIndicatorSizePx;
Jon Miranda18751b62017-07-31 17:25:27 -0700686 lp.bottomMargin = hotseatBarSizePx + mInsets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -0700687 }
Hyunyoung Song7d2fc812016-06-15 12:51:30 -0700688 pageIndicator.setLayoutParams(lp);
Winson Chungb3800242013-10-24 11:01:54 -0700689 }
690
Winson Chungb3800242013-10-24 11:01:54 -0700691 // Layout the Overview Mode
Jorim Jaggid017f882014-01-14 17:08:48 -0800692 ViewGroup overviewMode = launcher.getOverviewPanel();
Winson Chungb3800242013-10-24 11:01:54 -0700693 if (overviewMode != null) {
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700694 int visibleChildCount = getVisibleChildCount(overviewMode);
695 int totalItemWidth = visibleChildCount * overviewModeBarItemWidthPx;
Jon Mirandadf3bc522016-11-01 16:55:56 -0700696 int maxWidth = totalItemWidth + (visibleChildCount - 1) * overviewModeBarSpacerWidthPx;
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700697
Jon Mirandadf3bc522016-11-01 16:55:56 -0700698 lp = (FrameLayout.LayoutParams) overviewMode.getLayoutParams();
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700699 lp.width = Math.min(availableWidthPx, maxWidth);
Jon Mirandadf3bc522016-11-01 16:55:56 -0700700 lp.height = getOverviewModeButtonBarHeight() + mInsets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -0700701 overviewMode.setLayoutParams(lp);
Winson1f064272016-07-18 17:18:02 -0700702 }
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700703
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700704 // Layout the AllAppsRecyclerView
705 View view = launcher.findViewById(R.id.apps_list_view);
Jon Miranda28032002017-07-13 16:18:56 -0700706 int paddingLeftRight = desiredWorkspaceLeftRightMarginPx + cellLayoutPaddingLeftRightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700707 view.setPadding(paddingLeftRight, view.getPaddingTop(), paddingLeftRight,
708 view.getPaddingBottom());
709
Winson1f064272016-07-18 17:18:02 -0700710 if (notifyListeners) {
711 for (int i = mListeners.size() - 1; i >= 0; i--) {
712 mListeners.get(i).onLauncherLayoutChanged();
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700713 }
Winson Chungb3800242013-10-24 11:01:54 -0700714 }
715 }
Winson Chung4f3bfad2015-07-13 11:14:30 -0700716
717 private int getCurrentWidth() {
718 return isLandscape
719 ? Math.max(widthPx, heightPx)
720 : Math.min(widthPx, heightPx);
721 }
722
723 private int getCurrentHeight() {
724 return isLandscape
725 ? Math.min(widthPx, heightPx)
726 : Math.max(widthPx, heightPx);
727 }
Sunny Goyal13178ac2016-04-04 16:35:22 -0700728
Sunny Goyalc13403c2016-11-18 23:44:48 -0800729 public int getCellHeight(@ContainerType int containerType) {
730 switch (containerType) {
731 case CellLayout.WORKSPACE:
732 return cellHeightPx;
733 case CellLayout.FOLDER:
734 return folderCellHeightPx;
735 case CellLayout.HOTSEAT:
736 return hotseatCellHeightPx;
737 default:
738 // ??
739 return 0;
740 }
741 }
Sunny Goyal13178ac2016-04-04 16:35:22 -0700742
Winson1f064272016-07-18 17:18:02 -0700743 /**
744 * @return the left/right paddings for all containers.
745 */
Jon Mirandac3e4e222016-11-02 16:56:52 -0700746 public final int[] getContainerPadding() {
Winson1f064272016-07-18 17:18:02 -0700747 // No paddings for portrait phone
748 if (isPhone && !isVerticalBarLayout()) {
749 return new int[] {0, 0};
Sunny Goyal13178ac2016-04-04 16:35:22 -0700750 }
Winson1f064272016-07-18 17:18:02 -0700751
Hyunyoung Song9d96fd52016-08-23 11:06:24 -0700752 // In landscape, we match the width of the workspace
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700753 Rect padding = getWorkspacePadding(null);
754 return new int[] { padding.left - mInsets.left, padding.right + mInsets.left};
Sunny Goyal13178ac2016-04-04 16:35:22 -0700755 }
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700756
Jon Miranda51f037d2016-11-07 08:37:20 -0800757 public boolean shouldIgnoreLongPressToOverview(float touchX) {
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700758 boolean inMultiWindowMode = this != inv.landscapeProfile && this != inv.portraitProfile;
Jon Miranda51f037d2016-11-07 08:37:20 -0800759 boolean touchedLhsEdge = mInsets.left == 0 && touchX < edgeMarginPx;
760 boolean touchedRhsEdge = mInsets.right == 0 && touchX > (widthPx - edgeMarginPx);
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700761 return !inMultiWindowMode && (touchedLhsEdge || touchedRhsEdge);
762 }
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700763
764 private static Context getContext(Context c, int orientation) {
765 Configuration context = new Configuration(c.getResources().getConfiguration());
766 context.orientation = orientation;
767 return c.createConfigurationContext(context);
768
769 }
Winson Chungb3800242013-10-24 11:01:54 -0700770}