blob: 6dfb1901e4f61b2905f752349945793102c806b9 [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;
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;
Winson Chungb3800242013-10-24 11:01:54 -0700113
Sunny Goyalc6205602015-05-21 20:46:33 -0700114 // Hotseat
Sunny Goyalc6205602015-05-21 20:46:33 -0700115 public int hotseatCellHeightPx;
Jon Mirandaaca21452016-09-26 14:01:56 -0700116 public int hotseatBarHeightPx;
Sunny Goyal0dc1db42017-05-17 11:34:33 -0700117 public int hotseatBarTopPaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700118 public int hotseatBarLeftNavBarRightPaddingPx;
119 public int hotseatBarRightNavBarRightPaddingPx;
Sunny Goyal0dc1db42017-05-17 11:34:33 -0700120 public int hotseatBarBottomPaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700121 public int hotseatLandLeftNavBarGutterPx;
122 public int hotseatLandRightNavBarGutterPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700123
Sunny Goyalc6205602015-05-21 20:46:33 -0700124 // All apps
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700125 public int allAppsCellHeightPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700126 public int allAppsNumCols;
127 public int allAppsNumPredictiveCols;
Sunny Goyalc6205602015-05-21 20:46:33 -0700128 public int allAppsButtonVisualSize;
Winson1f064272016-07-18 17:18:02 -0700129 public int allAppsIconSizePx;
130 public int allAppsIconDrawablePaddingPx;
131 public float allAppsIconTextSizePx;
132
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800133 // Widgets
134 public final PointF appWidgetScale = new PointF(1.0f, 1.0f);
135
Sunny Goyal47328fd2016-05-25 18:56:41 -0700136 // Drop Target
137 public int dropTargetBarSizePx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700138
Winson1f064272016-07-18 17:18:02 -0700139 // Insets
140 private Rect mInsets = new Rect();
141
142 // Listeners
143 private ArrayList<LauncherLayoutChangeListener> mListeners = new ArrayList<>();
144
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800145 // Icon badges
146 public BadgeRenderer mBadgeRenderer;
147
Sunny Goyalc6205602015-05-21 20:46:33 -0700148 public DeviceProfile(Context context, InvariantDeviceProfile inv,
149 Point minSize, Point maxSize,
150 int width, int height, boolean isLandscape) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700151
Adam Cohen2e6da152015-05-06 11:42:25 -0700152 this.inv = inv;
Sunny Goyalc6205602015-05-21 20:46:33 -0700153 this.isLandscape = isLandscape;
Winson Chungb3800242013-10-24 11:01:54 -0700154
Adam Cohen2e6da152015-05-06 11:42:25 -0700155 Resources res = context.getResources();
Winson Chungb3800242013-10-24 11:01:54 -0700156 DisplayMetrics dm = res.getDisplayMetrics();
Adam Cohen2e6da152015-05-06 11:42:25 -0700157
Sunny Goyalc6205602015-05-21 20:46:33 -0700158 // Constants from resources
159 isTablet = res.getBoolean(R.bool.is_tablet);
160 isLargeTablet = res.getBoolean(R.bool.is_large_tablet);
161 isPhone = !isTablet && !isLargeTablet;
162
163 // Some more constants
Winson Chungb3800242013-10-24 11:01:54 -0700164 transposeLayoutWithOrientation =
165 res.getBoolean(R.bool.hotseat_transpose_layout_with_orientation);
Winson Chungb3800242013-10-24 11:01:54 -0700166
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700167 context = getContext(context, isVerticalBarLayout()
168 ? Configuration.ORIENTATION_LANDSCAPE
169 : Configuration.ORIENTATION_PORTRAIT);
170 res = context.getResources();
171
172
Winson Chungb3800242013-10-24 11:01:54 -0700173 ComponentName cn = new ComponentName(context.getPackageName(),
174 this.getClass().getName());
175 defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
176 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Jon Miranda28032002017-07-13 16:18:56 -0700177 desiredWorkspaceLeftRightMarginPx = isVerticalBarLayout() ? 0 : edgeMarginPx;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700178 cellLayoutPaddingLeftRightPx =
179 res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_padding);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700180 pageIndicatorSizePx = res.getDimensionPixelSize(
181 R.dimen.dynamic_grid_min_page_indicator_size);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700182 pageIndicatorLandGutterPx = res.getDimensionPixelSize(
183 R.dimen.dynamic_grid_page_indicator_gutter_width);
Winson1f064272016-07-18 17:18:02 -0700184 pageIndicatorLandWorkspaceOffsetPx =
185 res.getDimensionPixelSize(R.dimen.all_apps_caret_workspace_offset);
Winson Chungb3800242013-10-24 11:01:54 -0700186 defaultPageSpacingPx =
187 res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_page_spacing);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700188 topWorkspacePadding =
189 res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_top_padding);
Winson Chungb3800242013-10-24 11:01:54 -0700190 overviewModeMinIconZoneHeightPx =
191 res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_min_icon_zone_height);
192 overviewModeMaxIconZoneHeightPx =
193 res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_max_icon_zone_height);
Jorim Jaggid017f882014-01-14 17:08:48 -0800194 overviewModeBarItemWidthPx =
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700195 res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_bar_item_width);
Jorim Jaggid017f882014-01-14 17:08:48 -0800196 overviewModeBarSpacerWidthPx =
197 res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_bar_spacer_width);
Winson Chungb3800242013-10-24 11:01:54 -0700198 overviewModeIconZoneRatio =
199 res.getInteger(R.integer.config_dynamic_grid_overview_icon_zone_percentage) / 100f;
Winson Chungb3800242013-10-24 11:01:54 -0700200 iconDrawablePaddingOriginalPx =
201 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700202 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
203 workspaceSpringLoadedBottomSpace =
204 res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space);
Sunny Goyald5190522017-04-24 03:06:54 -0700205
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700206 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700207
Winson1f064272016-07-18 17:18:02 -0700208 hotseatBarTopPaddingPx =
209 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding);
Sunny Goyald5190522017-04-24 03:06:54 -0700210 hotseatBarBottomPaddingPx =
211 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_padding);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700212 hotseatBarLeftNavBarRightPaddingPx = res.getDimensionPixelSize(
213 R.dimen.dynamic_grid_hotseat_land_left_nav_bar_right_padding);
214 hotseatBarRightNavBarRightPaddingPx = res.getDimensionPixelSize(
215 R.dimen.dynamic_grid_hotseat_land_right_nav_bar_right_padding);
216 hotseatBarHeightPx = isVerticalBarLayout()
217 ? res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_height)
218 : res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_height)
219 + hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx;
220
221 hotseatLandLeftNavBarGutterPx = res.getDimensionPixelSize(
222 R.dimen.dynamic_grid_hotseat_land_left_nav_bar_gutter_width);
223 hotseatLandRightNavBarGutterPx = res.getDimensionPixelSize(
224 R.dimen.dynamic_grid_hotseat_land_right_nav_bar_gutter_width);
Winson Chungb3800242013-10-24 11:01:54 -0700225
Sunny Goyalc6205602015-05-21 20:46:33 -0700226 // Determine sizes.
227 widthPx = width;
228 heightPx = height;
229 if (isLandscape) {
230 availableWidthPx = maxSize.x;
231 availableHeightPx = minSize.y;
232 } else {
233 availableWidthPx = minSize.x;
234 availableHeightPx = maxSize.y;
235 }
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700236
Jon Miranda2ed276e2017-06-29 11:36:34 -0700237 // Calculate all of the remaining variables.
Sunny Goyalc6205602015-05-21 20:46:33 -0700238 updateAvailableDimensions(dm, res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700239
240 // Now that we have all of the variables calculated, we can tune certain sizes.
Jon Miranda3f9bab22017-07-28 14:50:17 -0700241 float aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
Jon Miranda30d0aa22017-07-25 15:55:29 -0700242 boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
243 if (!isVerticalBarLayout() && isPhone && isTallDevice) {
Jon Miranda3f9bab22017-07-28 14:50:17 -0700244 // We increase the hotseat size when there is extra space.
Jon Miranda2ed276e2017-06-29 11:36:34 -0700245 // ie. For a display with a large aspect ratio, we can keep the icons on the workspace
Jon Miranda3f9bab22017-07-28 14:50:17 -0700246 // in portrait mode closer together by adding more height to the hotseat.
Jon Miranda30d0aa22017-07-25 15:55:29 -0700247 // Note: This calculation was created after noticing a pattern in the design spec.
Jon Miranda3f9bab22017-07-28 14:50:17 -0700248 int extraSpace = getCellSize().y - iconSizePx - iconDrawablePaddingPx;
249 hotseatBarHeightPx += extraSpace - pageIndicatorSizePx;
Jon Miranda30d0aa22017-07-25 15:55:29 -0700250
Jon Miranda3f9bab22017-07-28 14:50:17 -0700251 // Recalculate the available dimensions using the new hotseat size.
Jon Miranda30d0aa22017-07-25 15:55:29 -0700252 updateAvailableDimensions(dm, res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700253 }
254
Adam Cohen63f1ec02014-08-12 09:23:13 -0700255 computeAllAppsButtonSize(context);
Tony Wickham1237df02017-02-24 08:59:36 -0800256
257 // This is done last, after iconSizePx is calculated above.
258 mBadgeRenderer = new BadgeRenderer(context, iconSizePx);
Adam Cohen63f1ec02014-08-12 09:23:13 -0700259 }
260
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700261 DeviceProfile getMultiWindowProfile(Context context, Point mwSize) {
262 // In multi-window mode, we can have widthPx = availableWidthPx
263 // and heightPx = availableHeightPx because Launcher uses the InvariantDeviceProfiles'
264 // widthPx and heightPx values where it's needed.
Jon Miranda93e1f042016-11-11 14:13:04 -0800265 DeviceProfile profile = new DeviceProfile(context, inv, mwSize, mwSize, mwSize.x, mwSize.y,
266 isLandscape);
267
268 // Hide labels on the workspace.
Jon Miranda1091e532017-07-21 13:31:50 -0700269 profile.adjustToHideWorkspaceLabels();
Jon Miranda93e1f042016-11-11 14:13:04 -0800270
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800271 // We use these scales to measure and layout the widgets using their full invariant profile
272 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
273 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
274 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
275 profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY);
276
Jon Miranda93e1f042016-11-11 14:13:04 -0800277 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700278 }
279
Winson1f064272016-07-18 17:18:02 -0700280 public void addLauncherLayoutChangedListener(LauncherLayoutChangeListener listener) {
281 if (!mListeners.contains(listener)) {
282 mListeners.add(listener);
283 }
284 }
285
286 public void removeLauncherLayoutChangedListener(LauncherLayoutChangeListener listener) {
287 if (mListeners.contains(listener)) {
288 mListeners.remove(listener);
289 }
290 }
291
Adam Cohen63f1ec02014-08-12 09:23:13 -0700292 /**
Jon Miranda1091e532017-07-21 13:31:50 -0700293 * Adjusts the profile so that the labels on the Workspace are hidden.
294 * It is important to call this method after the All Apps variables have been set.
295 */
296 private void adjustToHideWorkspaceLabels() {
297 iconTextSizePx = 0;
298 iconDrawablePaddingPx = 0;
299 cellHeightPx = iconSizePx;
300
301 // In normal cases, All Apps cell height should equal the Workspace cell height.
302 // Since we are removing labels from the Workspace, we need to manually compute the
303 // All Apps cell height.
Jon Miranda3f9bab22017-07-28 14:50:17 -0700304 int topBottomPadding = allAppsIconDrawablePaddingPx * (isVerticalBarLayout() ? 2 : 1);
Jon Miranda1091e532017-07-21 13:31:50 -0700305 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
306 + Utilities.calculateTextHeight(allAppsIconTextSizePx)
Jon Miranda3f9bab22017-07-28 14:50:17 -0700307 + topBottomPadding * 2;
Jon Miranda1091e532017-07-21 13:31:50 -0700308 }
309
310 /**
Adam Cohen63f1ec02014-08-12 09:23:13 -0700311 * Determine the exact visual footprint of the all apps button, taking into account scaling
312 * and internal padding of the drawable.
313 */
314 private void computeAllAppsButtonSize(Context context) {
315 Resources res = context.getResources();
316 float padding = res.getInteger(R.integer.config_allAppsButtonPaddingPercent) / 100f;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700317 allAppsButtonVisualSize = (int) (iconSizePx * (1 - padding)) - context.getResources()
Tony Wickhamd6b40372015-09-23 18:37:57 -0700318 .getDimensionPixelSize(R.dimen.all_apps_button_scale_down);
Winson Chungb3800242013-10-24 11:01:54 -0700319 }
320
Sunny Goyalc6205602015-05-21 20:46:33 -0700321 private void updateAvailableDimensions(DisplayMetrics dm, Resources res) {
Jon Miranda09660722017-06-14 14:20:14 -0700322 updateIconSize(1f, res, dm);
Winson Chung59a488a2013-12-10 12:32:14 -0800323
Jon Mirandabf7d8122016-11-03 15:29:29 -0700324 // Check to see if the icons fit within the available height. If not, then scale down.
325 float usedHeight = (cellHeightPx * inv.numRows);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700326 int maxHeight = (availableHeightPx - getTotalWorkspacePadding().y);
Winson Chungb3800242013-10-24 11:01:54 -0700327 if (usedHeight > maxHeight) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700328 float scale = maxHeight / usedHeight;
Jon Miranda09660722017-06-14 14:20:14 -0700329 updateIconSize(scale, res, dm);
Winson Chungb3800242013-10-24 11:01:54 -0700330 }
Jon Mirandabf7d8122016-11-03 15:29:29 -0700331 updateAvailableFolderCellDimensions(dm, res);
Winson Chungb3800242013-10-24 11:01:54 -0700332 }
333
Jon Miranda09660722017-06-14 14:20:14 -0700334 private void updateIconSize(float scale, Resources res, DisplayMetrics dm) {
Jon 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
340 // All apps
341 allAppsIconTextSizePx = iconTextSizePx;
Winson1f064272016-07-18 17:18:02 -0700342 allAppsIconSizePx = iconSizePx;
343 allAppsIconDrawablePaddingPx = iconDrawablePaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700344 allAppsCellHeightPx = getCellSize().y;
345
346 if (isVerticalBarLayout()) {
347 // Always hide the Workspace text with vertical bar layout.
Jon Miranda1091e532017-07-21 13:31:50 -0700348 adjustToHideWorkspaceLabels();
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700349 }
Winson Chungb3800242013-10-24 11:01:54 -0700350
Jon Miranda09660722017-06-14 14:20:14 -0700351 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700352 cellHeightPx = iconSizePx + iconDrawablePaddingPx
353 + Utilities.calculateTextHeight(iconTextSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700354
355 // Hotseat
Jon Miranda09660722017-06-14 14:20:14 -0700356 hotseatCellHeightPx = iconSizePx + iconDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700357
Sunny Goyal47328fd2016-05-25 18:56:41 -0700358 if (!isVerticalBarLayout()) {
359 int expectedWorkspaceHeight = availableHeightPx - hotseatBarHeightPx
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700360 - pageIndicatorSizePx - topWorkspacePadding;
Sunny Goyal47328fd2016-05-25 18:56:41 -0700361 float minRequiredHeight = dropTargetBarSizePx + workspaceSpringLoadedBottomSpace;
362 workspaceSpringLoadShrinkFactor = Math.min(
363 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f,
364 1 - (minRequiredHeight / expectedWorkspaceHeight));
365 } else {
366 workspaceSpringLoadShrinkFactor =
367 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
368 }
369
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700370 // Folder icon
Jon Miranda09660722017-06-14 14:20:14 -0700371 folderBackgroundOffset = -iconDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700372 folderIconSizePx = iconSizePx + 2 * -folderBackgroundOffset;
Adam Cohenefca0272016-02-24 19:19:06 -0800373 folderIconPreviewPadding = res.getDimensionPixelSize(R.dimen.folder_preview_padding);
Winson Chung0f785722015-04-08 10:27:49 -0700374 }
375
Jon Mirandabf7d8122016-11-03 15:29:29 -0700376 private void updateAvailableFolderCellDimensions(DisplayMetrics dm, Resources res) {
377 int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_padding_top)
378 + res.getDimensionPixelSize(R.dimen.folder_label_padding_bottom)
379 + Utilities.calculateTextHeight(res.getDimension(R.dimen.folder_label_text_size));
380
Jon Mirandac1b23992016-12-13 08:57:36 -0800381 updateFolderCellSize(1f, dm, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700382
Jon Mirandac1b23992016-12-13 08:57:36 -0800383 // Don't let the folder get too close to the edges of the screen.
Jon Miranda72b5fd12017-06-25 18:06:23 -0700384 int folderMargin = edgeMarginPx;
Jon Mirandac1b23992016-12-13 08:57:36 -0800385
386 // Check if the icons fit within the available height.
387 float usedHeight = folderCellHeightPx * inv.numFolderRows + folderBottomPanelSize;
388 int maxHeight = availableHeightPx - getTotalWorkspacePadding().y - folderMargin;
389 float scaleY = maxHeight / usedHeight;
390
391 // Check if the icons fit within the available width.
392 float usedWidth = folderCellWidthPx * inv.numFolderColumns;
393 int maxWidth = availableWidthPx - getTotalWorkspacePadding().x - folderMargin;
394 float scaleX = maxWidth / usedWidth;
395
396 float scale = Math.min(scaleX, scaleY);
397 if (scale < 1f) {
398 updateFolderCellSize(scale, dm, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700399 }
400 }
401
Jon Mirandac1b23992016-12-13 08:57:36 -0800402 private void updateFolderCellSize(float scale, DisplayMetrics dm, Resources res) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700403 folderChildIconSizePx = (int) (Utilities.pxFromDp(inv.iconSize, dm) * scale);
404 folderChildTextSizePx =
405 (int) (res.getDimensionPixelSize(R.dimen.folder_child_text_size) * scale);
406
407 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
408 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding) * scale);
409 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding) * scale);
410
Jon Mirandac1b23992016-12-13 08:57:36 -0800411 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
Jonathan Miranda9ad87462017-07-26 17:41:02 +0000412 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
413 folderChildDrawablePaddingPx = Math.max(0,
414 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700415 }
416
Winson1f064272016-07-18 17:18:02 -0700417 public void updateInsets(Rect insets) {
418 mInsets.set(insets);
419 }
420
Winson1f064272016-07-18 17:18:02 -0700421 public void updateAppsViewNumCols() {
422 allAppsNumCols = allAppsNumPredictiveCols = inv.numColumns;
Winson Chungb3800242013-10-24 11:01:54 -0700423 }
424
Tony Wickhama3c74d12015-10-23 11:43:47 -0700425 /** Returns the width and height of the search bar, ignoring any padding. */
Sunny Goyal47328fd2016-05-25 18:56:41 -0700426 public Point getSearchBarDimensForWidgetOpts() {
Tony Wickhama3c74d12015-10-23 11:43:47 -0700427 if (isVerticalBarLayout()) {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700428 return new Point(dropTargetBarSizePx, availableHeightPx - 2 * edgeMarginPx);
Winson Chungb3800242013-10-24 11:01:54 -0700429 } else {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700430 int gap;
Sunny Goyalc6205602015-05-21 20:46:33 -0700431 if (isTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700432 // Pad the left and right of the workspace to ensure consistent spacing
433 // between all icons
Winson Chung4f3bfad2015-07-13 11:14:30 -0700434 int width = getCurrentWidth();
Winson Chungb3800242013-10-24 11:01:54 -0700435 // XXX: If the icon size changes across orientations, we will have to take
436 // that into account here too.
Sunny Goyal47328fd2016-05-25 18:56:41 -0700437 gap = ((width - 2 * edgeMarginPx
438 - (inv.numColumns * cellWidthPx)) / (2 * (inv.numColumns + 1)))
439 + edgeMarginPx;
Winson Chungb3800242013-10-24 11:01:54 -0700440 } else {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700441 gap = desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.right;
Winson Chungb3800242013-10-24 11:01:54 -0700442 }
Sunny Goyal47328fd2016-05-25 18:56:41 -0700443 return new Point(availableWidthPx - 2 * gap, dropTargetBarSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700444 }
Winson Chungb3800242013-10-24 11:01:54 -0700445 }
446
Sunny Goyal756cd262015-08-20 12:33:21 -0700447 public Point getCellSize() {
448 Point result = new Point();
449 // Since we are only concerned with the overall padding, layout direction does
450 // not matter.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700451 Point padding = getTotalWorkspacePadding();
Jon Miranda8632d9d2017-07-18 12:42:15 -0700452 int cellPadding = cellLayoutPaddingLeftRightPx * 2;
453 result.x = calculateCellWidth(availableWidthPx - padding.x - cellPadding, inv.numColumns);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700454 result.y = calculateCellHeight(availableHeightPx - padding.y, inv.numRows);
Sunny Goyal756cd262015-08-20 12:33:21 -0700455 return result;
456 }
457
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700458 public Point getTotalWorkspacePadding() {
Sunny Goyal6178f132016-07-11 17:30:03 -0700459 Rect padding = getWorkspacePadding(null);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700460 return new Point(padding.left + padding.right, padding.top + padding.bottom);
461 }
462
463 /**
464 * Returns the workspace padding in the specified orientation.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700465 */
Sunny Goyal6178f132016-07-11 17:30:03 -0700466 public Rect getWorkspacePadding(Rect recycle) {
467 Rect padding = recycle == null ? new Rect() : recycle;
Tony Wickham3a3517f2015-10-06 11:27:04 -0700468 if (isVerticalBarLayout()) {
Winson1f064272016-07-18 17:18:02 -0700469 if (mInsets.left > 0) {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700470 padding.set(mInsets.left + pageIndicatorLandGutterPx,
471 0,
472 hotseatBarHeightPx + hotseatLandLeftNavBarGutterPx
473 + hotseatBarLeftNavBarRightPaddingPx - mInsets.left,
474 edgeMarginPx);
Winson1f064272016-07-18 17:18:02 -0700475 } else {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700476 padding.set(pageIndicatorLandGutterPx,
477 0,
478 hotseatBarHeightPx + hotseatLandRightNavBarGutterPx
479 + hotseatBarRightNavBarRightPaddingPx,
480 edgeMarginPx);
Winson1f064272016-07-18 17:18:02 -0700481 }
Winson Chungb3800242013-10-24 11:01:54 -0700482 } else {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700483 int paddingBottom = hotseatBarHeightPx + pageIndicatorSizePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700484 if (isTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700485 // Pad the left and right of the workspace to ensure consistent spacing
486 // between all icons
Winson Chung4f3bfad2015-07-13 11:14:30 -0700487 int width = getCurrentWidth();
488 int height = getCurrentHeight();
Tony Wickhamd6b40372015-09-23 18:37:57 -0700489 // The amount of screen space available for left/right padding.
Sunny Goyalf5440cb2016-12-14 15:13:00 -0800490 int availablePaddingX = Math.max(0, width - ((inv.numColumns * cellWidthPx) +
491 ((inv.numColumns - 1) * cellWidthPx)));
Tony Wickhamd6b40372015-09-23 18:37:57 -0700492 availablePaddingX = (int) Math.min(availablePaddingX,
493 width * MAX_HORIZONTAL_PADDING_PERCENT);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700494 int availablePaddingY = Math.max(0, height - topWorkspacePadding - paddingBottom
Jon Mirandac1b08c52016-11-15 14:37:56 -0800495 - (2 * inv.numRows * cellHeightPx) - hotseatBarTopPaddingPx
496 - hotseatBarBottomPaddingPx);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700497 padding.set(availablePaddingX / 2, topWorkspacePadding + availablePaddingY / 2,
Tony Wickhamd6b40372015-09-23 18:37:57 -0700498 availablePaddingX / 2, paddingBottom + availablePaddingY / 2);
Winson Chungb3800242013-10-24 11:01:54 -0700499 } else {
500 // Pad the top and bottom of the workspace with search/hotseat bar sizes
Winson1f064272016-07-18 17:18:02 -0700501 padding.set(desiredWorkspaceLeftRightMarginPx,
Sunny Goyal47328fd2016-05-25 18:56:41 -0700502 topWorkspacePadding,
Winson1f064272016-07-18 17:18:02 -0700503 desiredWorkspaceLeftRightMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700504 paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -0700505 }
506 }
507 return padding;
508 }
509
Winsonfadbe8f2016-07-22 16:35:37 -0700510 /**
511 * @return the bounds for which the open folders should be contained within
512 */
513 public Rect getAbsoluteOpenFolderBounds() {
514 if (isVerticalBarLayout()) {
515 // Folders should only appear right of the drop target bar and left of the hotseat
516 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
517 mInsets.top,
518 mInsets.left + availableWidthPx - hotseatBarHeightPx - edgeMarginPx,
519 mInsets.top + availableHeightPx);
520 } else {
521 // Folders should only appear below the drop target bar and above the hotseat
522 return new Rect(mInsets.left,
523 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
524 mInsets.left + availableWidthPx,
Jon Miranda2ed276e2017-06-29 11:36:34 -0700525 mInsets.top + availableHeightPx - hotseatBarHeightPx
526 - pageIndicatorSizePx - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -0700527 }
528 }
529
Sunny Goyal47328fd2016-05-25 18:56:41 -0700530 private int getWorkspacePageSpacing() {
Tony Wickham3a3517f2015-10-06 11:27:04 -0700531 if (isVerticalBarLayout() || isLargeTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700532 // In landscape mode the page spacing is set to the default.
533 return defaultPageSpacingPx;
534 } else {
535 // In portrait, we want the pages spaced such that there is no
536 // overhang of the previous / next page into the current page viewport.
537 // We assume symmetrical padding in portrait mode.
Jon Miranda28032002017-07-13 16:18:56 -0700538 return Math.max(defaultPageSpacingPx, getWorkspacePadding(null).left + 1);
Winson Chungb3800242013-10-24 11:01:54 -0700539 }
540 }
541
Winson Chung4f7eb402015-07-10 18:00:48 -0700542 int getOverviewModeButtonBarHeight() {
Winson Chungb3800242013-10-24 11:01:54 -0700543 int zoneHeight = (int) (overviewModeIconZoneRatio * availableHeightPx);
544 zoneHeight = Math.min(overviewModeMaxIconZoneHeightPx,
545 Math.max(overviewModeMinIconZoneHeightPx, zoneHeight));
Winson Chung4f7eb402015-07-10 18:00:48 -0700546 return zoneHeight;
Winson Chungb3800242013-10-24 11:01:54 -0700547 }
548
Adam Cohen2e6da152015-05-06 11:42:25 -0700549 public static int calculateCellWidth(int width, int countX) {
Winson Chungb3800242013-10-24 11:01:54 -0700550 return width / countX;
551 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700552 public static int calculateCellHeight(int height, int countY) {
Winson Chungb3800242013-10-24 11:01:54 -0700553 return height / countY;
554 }
555
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700556 /**
Tony Wickham55616cd2015-09-23 14:55:17 -0700557 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
558 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
559 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700560 */
Tony Wickhamab946a12015-09-16 15:38:16 -0700561 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -0700562 return isLandscape && transposeLayoutWithOrientation;
563 }
564
565 boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyalc6205602015-05-21 20:46:33 -0700566 return isVerticalBarLayout() || isLargeTablet;
Winson Chungb3800242013-10-24 11:01:54 -0700567 }
568
Sunny Goyalc6205602015-05-21 20:46:33 -0700569 private int getVisibleChildCount(ViewGroup parent) {
Jorim Jaggid017f882014-01-14 17:08:48 -0800570 int visibleChildren = 0;
571 for (int i = 0; i < parent.getChildCount(); i++) {
572 if (parent.getChildAt(i).getVisibility() != View.GONE) {
573 visibleChildren++;
574 }
575 }
576 return visibleChildren;
577 }
578
Winson1f064272016-07-18 17:18:02 -0700579 public void layout(Launcher launcher, boolean notifyListeners) {
Winson Chungb3800242013-10-24 11:01:54 -0700580 FrameLayout.LayoutParams lp;
Winson Chungb3800242013-10-24 11:01:54 -0700581 boolean hasVerticalBarLayout = isVerticalBarLayout();
582
583 // Layout the search bar space
Sunny Goyal47328fd2016-05-25 18:56:41 -0700584 Point searchBarBounds = getSearchBarDimensForWidgetOpts();
585 View searchBar = launcher.getDropTargetBar();
Sunny Goyalf37a2142016-03-24 17:28:25 -0700586 lp = (FrameLayout.LayoutParams) searchBar.getLayoutParams();
Sunny Goyal47328fd2016-05-25 18:56:41 -0700587 lp.width = searchBarBounds.x;
588 lp.height = searchBarBounds.y;
Jon Miranda28032002017-07-13 16:18:56 -0700589 lp.topMargin = mInsets.top + edgeMarginPx;
Winson Chungb3800242013-10-24 11:01:54 -0700590 searchBar.setLayoutParams(lp);
591
Winson Chungb3800242013-10-24 11:01:54 -0700592 // Layout the workspace
593 PagedView workspace = (PagedView) launcher.findViewById(R.id.workspace);
Winson1f064272016-07-18 17:18:02 -0700594 Rect workspacePadding = getWorkspacePadding(null);
595 workspace.setPadding(workspacePadding.left, workspacePadding.top, workspacePadding.right,
596 workspacePadding.bottom);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700597 workspace.setPageSpacing(getWorkspacePageSpacing());
Winson Chungb3800242013-10-24 11:01:54 -0700598
599 // Layout the hotseat
Winson6231ede2016-07-20 17:21:55 -0700600 Hotseat hotseat = (Hotseat) launcher.findViewById(R.id.hotseat);
Winson Chungb3800242013-10-24 11:01:54 -0700601 lp = (FrameLayout.LayoutParams) hotseat.getLayoutParams();
Tony Wickhamd6b40372015-09-23 18:37:57 -0700602 // We want the edges of the hotseat to line up with the edges of the workspace, but the
603 // icons in the hotseat are a different size, and so don't line up perfectly. To account for
604 // this, we pad the left and right of the hotseat with half of the difference of a workspace
605 // cell vs a hotseat cell.
606 float workspaceCellWidth = (float) getCurrentWidth() / inv.numColumns;
607 float hotseatCellWidth = (float) getCurrentWidth() / inv.numHotseatIcons;
608 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Winson Chungb3800242013-10-24 11:01:54 -0700609 if (hasVerticalBarLayout) {
Winson Chungf8c6f882015-06-03 11:27:26 -0700610 // Vertical hotseat -- The hotseat is fixed in the layout to be on the right of the
611 // screen regardless of RTL
612 lp.gravity = Gravity.RIGHT;
Winson1f064272016-07-18 17:18:02 -0700613 lp.width = hotseatBarHeightPx + mInsets.left + mInsets.right;
Winson Chungb3800242013-10-24 11:01:54 -0700614 lp.height = LayoutParams.MATCH_PARENT;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700615
616 int paddingRight = mInsets.left > 0
617 ? hotseatBarLeftNavBarRightPaddingPx
618 : hotseatBarRightNavBarRightPaddingPx;
619
Jon Miranda52ff3252017-07-14 11:39:16 -0700620 hotseat.getLayout().setPadding(mInsets.left + cellLayoutPaddingLeftRightPx,
621 mInsets.top, mInsets.right + paddingRight + cellLayoutPaddingLeftRightPx,
Winson6231ede2016-07-20 17:21:55 -0700622 workspacePadding.bottom);
Sunny Goyalc6205602015-05-21 20:46:33 -0700623 } else if (isTablet) {
Winson Chung59a488a2013-12-10 12:32:14 -0800624 // Pad the hotseat with the workspace padding calculated above
Winson Chungb3800242013-10-24 11:01:54 -0700625 lp.gravity = Gravity.BOTTOM;
626 lp.width = LayoutParams.MATCH_PARENT;
Winson1f064272016-07-18 17:18:02 -0700627 lp.height = hotseatBarHeightPx + mInsets.bottom;
Jon Miranda52ff3252017-07-14 11:39:16 -0700628 hotseat.getLayout().setPadding(hotseatAdjustment + workspacePadding.left
629 + cellLayoutPaddingLeftRightPx,
630 hotseatBarTopPaddingPx,
631 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx,
Jon Mirandac1b08c52016-11-15 14:37:56 -0800632 hotseatBarBottomPaddingPx + mInsets.bottom);
Winson Chungb3800242013-10-24 11:01:54 -0700633 } else {
634 // For phones, layout the hotseat without any bottom margin
635 // to ensure that we have space for the folders
636 lp.gravity = Gravity.BOTTOM;
637 lp.width = LayoutParams.MATCH_PARENT;
Winson1f064272016-07-18 17:18:02 -0700638 lp.height = hotseatBarHeightPx + mInsets.bottom;
Jon Miranda52ff3252017-07-14 11:39:16 -0700639 hotseat.getLayout().setPadding(hotseatAdjustment + workspacePadding.left
640 + cellLayoutPaddingLeftRightPx,
641 hotseatBarTopPaddingPx,
642 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx,
Jon Mirandac1b08c52016-11-15 14:37:56 -0800643 hotseatBarBottomPaddingPx + mInsets.bottom);
Winson Chungb3800242013-10-24 11:01:54 -0700644 }
645 hotseat.setLayoutParams(lp);
646
647 // Layout the page indicators
648 View pageIndicator = launcher.findViewById(R.id.page_indicator);
649 if (pageIndicator != null) {
Hyunyoung Song7d2fc812016-06-15 12:51:30 -0700650 lp = (FrameLayout.LayoutParams) pageIndicator.getLayoutParams();
Winson1f064272016-07-18 17:18:02 -0700651 if (isVerticalBarLayout()) {
652 if (mInsets.left > 0) {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700653 lp.leftMargin = mInsets.left;
654 } else {
655 lp.leftMargin = pageIndicatorLandWorkspaceOffsetPx;
Winson1f064272016-07-18 17:18:02 -0700656 }
657 lp.bottomMargin = workspacePadding.bottom;
658 } else {
Winson Chungb3800242013-10-24 11:01:54 -0700659 // Put the page indicators above the hotseat
Winson Chungb3800242013-10-24 11:01:54 -0700660 lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700661 lp.height = pageIndicatorSizePx;
Winson1f064272016-07-18 17:18:02 -0700662 lp.bottomMargin = hotseatBarHeightPx + mInsets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -0700663 }
Hyunyoung Song7d2fc812016-06-15 12:51:30 -0700664 pageIndicator.setLayoutParams(lp);
Winson Chungb3800242013-10-24 11:01:54 -0700665 }
666
Winson Chungb3800242013-10-24 11:01:54 -0700667 // Layout the Overview Mode
Jorim Jaggid017f882014-01-14 17:08:48 -0800668 ViewGroup overviewMode = launcher.getOverviewPanel();
Winson Chungb3800242013-10-24 11:01:54 -0700669 if (overviewMode != null) {
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700670 int visibleChildCount = getVisibleChildCount(overviewMode);
671 int totalItemWidth = visibleChildCount * overviewModeBarItemWidthPx;
Jon Mirandadf3bc522016-11-01 16:55:56 -0700672 int maxWidth = totalItemWidth + (visibleChildCount - 1) * overviewModeBarSpacerWidthPx;
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700673
Jon Mirandadf3bc522016-11-01 16:55:56 -0700674 lp = (FrameLayout.LayoutParams) overviewMode.getLayoutParams();
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700675 lp.width = Math.min(availableWidthPx, maxWidth);
Jon Mirandadf3bc522016-11-01 16:55:56 -0700676 lp.height = getOverviewModeButtonBarHeight() + mInsets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -0700677 overviewMode.setLayoutParams(lp);
Winson1f064272016-07-18 17:18:02 -0700678 }
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700679
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700680 // Layout the AllAppsRecyclerView
681 View view = launcher.findViewById(R.id.apps_list_view);
Jon Miranda28032002017-07-13 16:18:56 -0700682 int paddingLeftRight = desiredWorkspaceLeftRightMarginPx + cellLayoutPaddingLeftRightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700683 view.setPadding(paddingLeftRight, view.getPaddingTop(), paddingLeftRight,
684 view.getPaddingBottom());
685
Winson1f064272016-07-18 17:18:02 -0700686 if (notifyListeners) {
687 for (int i = mListeners.size() - 1; i >= 0; i--) {
688 mListeners.get(i).onLauncherLayoutChanged();
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700689 }
Winson Chungb3800242013-10-24 11:01:54 -0700690 }
691 }
Winson Chung4f3bfad2015-07-13 11:14:30 -0700692
693 private int getCurrentWidth() {
694 return isLandscape
695 ? Math.max(widthPx, heightPx)
696 : Math.min(widthPx, heightPx);
697 }
698
699 private int getCurrentHeight() {
700 return isLandscape
701 ? Math.min(widthPx, heightPx)
702 : Math.max(widthPx, heightPx);
703 }
Sunny Goyal13178ac2016-04-04 16:35:22 -0700704
Sunny Goyalc13403c2016-11-18 23:44:48 -0800705 public int getCellHeight(@ContainerType int containerType) {
706 switch (containerType) {
707 case CellLayout.WORKSPACE:
708 return cellHeightPx;
709 case CellLayout.FOLDER:
710 return folderCellHeightPx;
711 case CellLayout.HOTSEAT:
712 return hotseatCellHeightPx;
713 default:
714 // ??
715 return 0;
716 }
717 }
Sunny Goyal13178ac2016-04-04 16:35:22 -0700718
Winson1f064272016-07-18 17:18:02 -0700719 /**
720 * @return the left/right paddings for all containers.
721 */
Jon Mirandac3e4e222016-11-02 16:56:52 -0700722 public final int[] getContainerPadding() {
Winson1f064272016-07-18 17:18:02 -0700723 // No paddings for portrait phone
724 if (isPhone && !isVerticalBarLayout()) {
725 return new int[] {0, 0};
Sunny Goyal13178ac2016-04-04 16:35:22 -0700726 }
Winson1f064272016-07-18 17:18:02 -0700727
Hyunyoung Song9d96fd52016-08-23 11:06:24 -0700728 // In landscape, we match the width of the workspace
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700729 Rect padding = getWorkspacePadding(null);
730 return new int[] { padding.left - mInsets.left, padding.right + mInsets.left};
Sunny Goyal13178ac2016-04-04 16:35:22 -0700731 }
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700732
Jon Miranda51f037d2016-11-07 08:37:20 -0800733 public boolean shouldIgnoreLongPressToOverview(float touchX) {
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700734 boolean inMultiWindowMode = this != inv.landscapeProfile && this != inv.portraitProfile;
Jon Miranda51f037d2016-11-07 08:37:20 -0800735 boolean touchedLhsEdge = mInsets.left == 0 && touchX < edgeMarginPx;
736 boolean touchedRhsEdge = mInsets.right == 0 && touchX > (widthPx - edgeMarginPx);
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700737 return !inMultiWindowMode && (touchedLhsEdge || touchedRhsEdge);
738 }
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700739
740 private static Context getContext(Context c, int orientation) {
741 Configuration context = new Configuration(c.getResources().getConfiguration());
742 context.orientation = orientation;
743 return c.createConfigurationContext(context);
744
745 }
Winson Chungb3800242013-10-24 11:01:54 -0700746}