blob: ca5d8e7462f32dda1f125d18e9d2fdfca1b94d6b [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
Sunny Goyalc6205602015-05-21 20:46:33 -070066 // Overview mode
67 private final int overviewModeMinIconZoneHeightPx;
68 private final int overviewModeMaxIconZoneHeightPx;
69 private final int overviewModeBarItemWidthPx;
70 private final int overviewModeBarSpacerWidthPx;
71 private final float overviewModeIconZoneRatio;
Winson Chungb3800242013-10-24 11:01:54 -070072
Sunny Goyalc6205602015-05-21 20:46:33 -070073 // Workspace
Jon Miranda28032002017-07-13 16:18:56 -070074 private final int desiredWorkspaceLeftRightMarginPx;
75 public final int cellLayoutPaddingLeftRightPx;
Sunny Goyalc6205602015-05-21 20:46:33 -070076 public final int edgeMarginPx;
77 public final Rect defaultWidgetPadding;
Sunny Goyalc6205602015-05-21 20:46:33 -070078 private final int defaultPageSpacingPx;
Sunny Goyal47328fd2016-05-25 18:56:41 -070079 private final int topWorkspacePadding;
Sunny Goyal47328fd2016-05-25 18:56:41 -070080 public float workspaceSpringLoadShrinkFactor;
81 public final int workspaceSpringLoadedBottomSpace;
Sunny Goyalc6205602015-05-21 20:46:33 -070082
Winson1f064272016-07-18 17:18:02 -070083 // Page indicator
Jon Miranda2ed276e2017-06-29 11:36:34 -070084 private int pageIndicatorSizePx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070085 private final int pageIndicatorLandGutterPx;
Winson1f064272016-07-18 17:18:02 -070086 private final int pageIndicatorLandWorkspaceOffsetPx;
87
Sunny Goyalc6205602015-05-21 20:46:33 -070088 // Workspace icons
89 public int iconSizePx;
90 public int iconTextSizePx;
91 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -070092 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -070093
Adam Cohen59400422014-03-05 18:07:04 -080094 public int cellWidthPx;
95 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070096 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -080097
Sunny Goyalc6205602015-05-21 20:46:33 -070098 // Folder
99 public int folderBackgroundOffset;
100 public int folderIconSizePx;
Adam Cohenefca0272016-02-24 19:19:06 -0800101 public int folderIconPreviewPadding;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700102
103 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700104 public int folderCellWidthPx;
105 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700106
107 // Folder child
108 public int folderChildIconSizePx;
109 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700110 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700111
Sunny Goyalc6205602015-05-21 20:46:33 -0700112 // Hotseat
Sunny Goyalc6205602015-05-21 20:46:33 -0700113 public int hotseatCellHeightPx;
Jon Mirandaaca21452016-09-26 14:01:56 -0700114 public int hotseatBarHeightPx;
Sunny Goyal0dc1db42017-05-17 11:34:33 -0700115 public int hotseatBarTopPaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700116 public int hotseatBarLeftNavBarRightPaddingPx;
117 public int hotseatBarRightNavBarRightPaddingPx;
Sunny Goyal0dc1db42017-05-17 11:34:33 -0700118 public int hotseatBarBottomPaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700119 public int hotseatLandLeftNavBarGutterPx;
120 public int hotseatLandRightNavBarGutterPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700121
Sunny Goyalc6205602015-05-21 20:46:33 -0700122 // All apps
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700123 public int allAppsCellHeightPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700124 public int allAppsNumCols;
125 public int allAppsNumPredictiveCols;
Sunny Goyalc6205602015-05-21 20:46:33 -0700126 public int allAppsButtonVisualSize;
Winson1f064272016-07-18 17:18:02 -0700127 public int allAppsIconSizePx;
128 public int allAppsIconDrawablePaddingPx;
129 public float allAppsIconTextSizePx;
130
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800131 // Widgets
132 public final PointF appWidgetScale = new PointF(1.0f, 1.0f);
133
Sunny Goyal47328fd2016-05-25 18:56:41 -0700134 // Drop Target
135 public int dropTargetBarSizePx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700136
Winson1f064272016-07-18 17:18:02 -0700137 // Insets
138 private Rect mInsets = new Rect();
139
140 // Listeners
141 private ArrayList<LauncherLayoutChangeListener> mListeners = new ArrayList<>();
142
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800143 // Icon badges
144 public BadgeRenderer mBadgeRenderer;
145
Sunny Goyalc6205602015-05-21 20:46:33 -0700146 public DeviceProfile(Context context, InvariantDeviceProfile inv,
147 Point minSize, Point maxSize,
148 int width, int height, boolean isLandscape) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700149
Adam Cohen2e6da152015-05-06 11:42:25 -0700150 this.inv = inv;
Sunny Goyalc6205602015-05-21 20:46:33 -0700151 this.isLandscape = isLandscape;
Winson Chungb3800242013-10-24 11:01:54 -0700152
Adam Cohen2e6da152015-05-06 11:42:25 -0700153 Resources res = context.getResources();
Winson Chungb3800242013-10-24 11:01:54 -0700154 DisplayMetrics dm = res.getDisplayMetrics();
Adam Cohen2e6da152015-05-06 11:42:25 -0700155
Sunny Goyalc6205602015-05-21 20:46:33 -0700156 // Constants from resources
157 isTablet = res.getBoolean(R.bool.is_tablet);
158 isLargeTablet = res.getBoolean(R.bool.is_large_tablet);
159 isPhone = !isTablet && !isLargeTablet;
160
161 // Some more constants
Winson Chungb3800242013-10-24 11:01:54 -0700162 transposeLayoutWithOrientation =
163 res.getBoolean(R.bool.hotseat_transpose_layout_with_orientation);
Winson Chungb3800242013-10-24 11:01:54 -0700164
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700165 context = getContext(context, isVerticalBarLayout()
166 ? Configuration.ORIENTATION_LANDSCAPE
167 : Configuration.ORIENTATION_PORTRAIT);
168 res = context.getResources();
169
170
Winson Chungb3800242013-10-24 11:01:54 -0700171 ComponentName cn = new ComponentName(context.getPackageName(),
172 this.getClass().getName());
173 defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
174 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Jon Miranda28032002017-07-13 16:18:56 -0700175 desiredWorkspaceLeftRightMarginPx = isVerticalBarLayout() ? 0 : edgeMarginPx;
176 cellLayoutPaddingLeftRightPx = isVerticalBarLayout() ? 0 : edgeMarginPx;
Jon Miranda2ed276e2017-06-29 11:36:34 -0700177 pageIndicatorSizePx = res.getDimensionPixelSize(
178 R.dimen.dynamic_grid_min_page_indicator_size);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700179 pageIndicatorLandGutterPx = res.getDimensionPixelSize(
180 R.dimen.dynamic_grid_page_indicator_gutter_width);
Winson1f064272016-07-18 17:18:02 -0700181 pageIndicatorLandWorkspaceOffsetPx =
182 res.getDimensionPixelSize(R.dimen.all_apps_caret_workspace_offset);
Winson Chungb3800242013-10-24 11:01:54 -0700183 defaultPageSpacingPx =
184 res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_page_spacing);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700185 topWorkspacePadding =
186 res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_top_padding);
Winson Chungb3800242013-10-24 11:01:54 -0700187 overviewModeMinIconZoneHeightPx =
188 res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_min_icon_zone_height);
189 overviewModeMaxIconZoneHeightPx =
190 res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_max_icon_zone_height);
Jorim Jaggid017f882014-01-14 17:08:48 -0800191 overviewModeBarItemWidthPx =
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700192 res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_bar_item_width);
Jorim Jaggid017f882014-01-14 17:08:48 -0800193 overviewModeBarSpacerWidthPx =
194 res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_bar_spacer_width);
Winson Chungb3800242013-10-24 11:01:54 -0700195 overviewModeIconZoneRatio =
196 res.getInteger(R.integer.config_dynamic_grid_overview_icon_zone_percentage) / 100f;
Winson Chungb3800242013-10-24 11:01:54 -0700197 iconDrawablePaddingOriginalPx =
198 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700199 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
200 workspaceSpringLoadedBottomSpace =
201 res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space);
Sunny Goyald5190522017-04-24 03:06:54 -0700202
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700203 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700204
Winson1f064272016-07-18 17:18:02 -0700205 hotseatBarTopPaddingPx =
206 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding);
Sunny Goyald5190522017-04-24 03:06:54 -0700207 hotseatBarBottomPaddingPx =
208 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_padding);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700209 hotseatBarLeftNavBarRightPaddingPx = res.getDimensionPixelSize(
210 R.dimen.dynamic_grid_hotseat_land_left_nav_bar_right_padding);
211 hotseatBarRightNavBarRightPaddingPx = res.getDimensionPixelSize(
212 R.dimen.dynamic_grid_hotseat_land_right_nav_bar_right_padding);
213 hotseatBarHeightPx = isVerticalBarLayout()
214 ? res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_height)
215 : res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_height)
216 + hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx;
217
218 hotseatLandLeftNavBarGutterPx = res.getDimensionPixelSize(
219 R.dimen.dynamic_grid_hotseat_land_left_nav_bar_gutter_width);
220 hotseatLandRightNavBarGutterPx = res.getDimensionPixelSize(
221 R.dimen.dynamic_grid_hotseat_land_right_nav_bar_gutter_width);
Winson Chungb3800242013-10-24 11:01:54 -0700222
Sunny Goyalc6205602015-05-21 20:46:33 -0700223 // Determine sizes.
224 widthPx = width;
225 heightPx = height;
226 if (isLandscape) {
227 availableWidthPx = maxSize.x;
228 availableHeightPx = minSize.y;
229 } else {
230 availableWidthPx = minSize.x;
231 availableHeightPx = maxSize.y;
232 }
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700233
Jon Miranda2ed276e2017-06-29 11:36:34 -0700234 // Calculate all of the remaining variables.
Sunny Goyalc6205602015-05-21 20:46:33 -0700235 updateAvailableDimensions(dm, res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700236
237 // Now that we have all of the variables calculated, we can tune certain sizes.
238 if (!isVerticalBarLayout()) {
239 // We increase the page indicator size when there is extra space.
240 // ie. For a display with a large aspect ratio, we can keep the icons on the workspace
241 // in portrait mode closer together by increasing the page indicator size.
242 int newPageIndicatorSizePx = getCellSize().y - iconSizePx - iconTextSizePx
243 - iconDrawablePaddingOriginalPx;
244 if (newPageIndicatorSizePx > pageIndicatorSizePx) {
245 pageIndicatorSizePx = newPageIndicatorSizePx;
246 // Recalculate the available dimensions using the new page indicator size.
247 updateAvailableDimensions(dm, res);
248 }
249 }
250
Adam Cohen63f1ec02014-08-12 09:23:13 -0700251 computeAllAppsButtonSize(context);
Tony Wickham1237df02017-02-24 08:59:36 -0800252
253 // This is done last, after iconSizePx is calculated above.
254 mBadgeRenderer = new BadgeRenderer(context, iconSizePx);
Adam Cohen63f1ec02014-08-12 09:23:13 -0700255 }
256
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700257 DeviceProfile getMultiWindowProfile(Context context, Point mwSize) {
258 // In multi-window mode, we can have widthPx = availableWidthPx
259 // and heightPx = availableHeightPx because Launcher uses the InvariantDeviceProfiles'
260 // widthPx and heightPx values where it's needed.
Jon Miranda93e1f042016-11-11 14:13:04 -0800261 DeviceProfile profile = new DeviceProfile(context, inv, mwSize, mwSize, mwSize.x, mwSize.y,
262 isLandscape);
263
264 // Hide labels on the workspace.
265 profile.iconTextSizePx = 0;
266 profile.cellHeightPx = profile.iconSizePx + profile.iconDrawablePaddingPx
267 + Utilities.calculateTextHeight(profile.iconTextSizePx);
268
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800269 // We use these scales to measure and layout the widgets using their full invariant profile
270 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
271 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
272 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
273 profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY);
274
Jon Miranda93e1f042016-11-11 14:13:04 -0800275 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700276 }
277
Winson1f064272016-07-18 17:18:02 -0700278 public void addLauncherLayoutChangedListener(LauncherLayoutChangeListener listener) {
279 if (!mListeners.contains(listener)) {
280 mListeners.add(listener);
281 }
282 }
283
284 public void removeLauncherLayoutChangedListener(LauncherLayoutChangeListener listener) {
285 if (mListeners.contains(listener)) {
286 mListeners.remove(listener);
287 }
288 }
289
Adam Cohen63f1ec02014-08-12 09:23:13 -0700290 /**
291 * Determine the exact visual footprint of the all apps button, taking into account scaling
292 * and internal padding of the drawable.
293 */
294 private void computeAllAppsButtonSize(Context context) {
295 Resources res = context.getResources();
296 float padding = res.getInteger(R.integer.config_allAppsButtonPaddingPercent) / 100f;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700297 allAppsButtonVisualSize = (int) (iconSizePx * (1 - padding)) - context.getResources()
Tony Wickhamd6b40372015-09-23 18:37:57 -0700298 .getDimensionPixelSize(R.dimen.all_apps_button_scale_down);
Winson Chungb3800242013-10-24 11:01:54 -0700299 }
300
Sunny Goyalc6205602015-05-21 20:46:33 -0700301 private void updateAvailableDimensions(DisplayMetrics dm, Resources res) {
Jon Miranda09660722017-06-14 14:20:14 -0700302 updateIconSize(1f, res, dm);
Winson Chung59a488a2013-12-10 12:32:14 -0800303
Jon Mirandabf7d8122016-11-03 15:29:29 -0700304 // Check to see if the icons fit within the available height. If not, then scale down.
305 float usedHeight = (cellHeightPx * inv.numRows);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700306 int maxHeight = (availableHeightPx - getTotalWorkspacePadding().y);
Winson Chungb3800242013-10-24 11:01:54 -0700307 if (usedHeight > maxHeight) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700308 float scale = maxHeight / usedHeight;
Jon Miranda09660722017-06-14 14:20:14 -0700309 updateIconSize(scale, res, dm);
Winson Chungb3800242013-10-24 11:01:54 -0700310 }
Jon Mirandabf7d8122016-11-03 15:29:29 -0700311 updateAvailableFolderCellDimensions(dm, res);
Winson Chungb3800242013-10-24 11:01:54 -0700312 }
313
Jon Miranda09660722017-06-14 14:20:14 -0700314 private void updateIconSize(float scale, Resources res, DisplayMetrics dm) {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700315 float invIconSizePx = isVerticalBarLayout() ? inv.landscapeIconSize : inv.iconSize;
316 iconSizePx = (int) (Utilities.pxFromDp(invIconSizePx, dm) * scale);
Sunny Goyala50a4192015-12-11 09:50:49 -0800317 iconTextSizePx = (int) (Utilities.pxFromSp(inv.iconTextSize, dm) * scale);
Jon Miranda09660722017-06-14 14:20:14 -0700318 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * scale);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700319
320 // All apps
321 allAppsIconTextSizePx = iconTextSizePx;
Winson1f064272016-07-18 17:18:02 -0700322 allAppsIconSizePx = iconSizePx;
323 allAppsIconDrawablePaddingPx = iconDrawablePaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700324 allAppsCellHeightPx = getCellSize().y;
325
326 if (isVerticalBarLayout()) {
327 // Always hide the Workspace text with vertical bar layout.
328 iconTextSizePx = 0;
Jon Miranda4e358272017-07-07 10:05:33 -0700329 iconDrawablePaddingPx = 0;
330
331 // Manually compute all apps cell height since workspace cells have less content.
332 allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx
333 + Utilities.calculateTextHeight(allAppsIconTextSizePx)
334 // Top and bottom padding is equal to the drawable padding
335 + allAppsIconDrawablePaddingPx * 2;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700336 }
Winson Chungb3800242013-10-24 11:01:54 -0700337
Jon Miranda09660722017-06-14 14:20:14 -0700338 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700339 cellHeightPx = iconSizePx + iconDrawablePaddingPx
340 + Utilities.calculateTextHeight(iconTextSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700341
342 // Hotseat
Jon Miranda09660722017-06-14 14:20:14 -0700343 hotseatCellHeightPx = iconSizePx + iconDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700344
Sunny Goyal47328fd2016-05-25 18:56:41 -0700345 if (!isVerticalBarLayout()) {
346 int expectedWorkspaceHeight = availableHeightPx - hotseatBarHeightPx
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700347 - pageIndicatorSizePx - topWorkspacePadding;
Sunny Goyal47328fd2016-05-25 18:56:41 -0700348 float minRequiredHeight = dropTargetBarSizePx + workspaceSpringLoadedBottomSpace;
349 workspaceSpringLoadShrinkFactor = Math.min(
350 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f,
351 1 - (minRequiredHeight / expectedWorkspaceHeight));
352 } else {
353 workspaceSpringLoadShrinkFactor =
354 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
355 }
356
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700357 // Folder icon
Jon Miranda09660722017-06-14 14:20:14 -0700358 folderBackgroundOffset = -iconDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700359 folderIconSizePx = iconSizePx + 2 * -folderBackgroundOffset;
Adam Cohenefca0272016-02-24 19:19:06 -0800360 folderIconPreviewPadding = res.getDimensionPixelSize(R.dimen.folder_preview_padding);
Winson Chung0f785722015-04-08 10:27:49 -0700361 }
362
Jon Mirandabf7d8122016-11-03 15:29:29 -0700363 private void updateAvailableFolderCellDimensions(DisplayMetrics dm, Resources res) {
364 int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_padding_top)
365 + res.getDimensionPixelSize(R.dimen.folder_label_padding_bottom)
366 + Utilities.calculateTextHeight(res.getDimension(R.dimen.folder_label_text_size));
367
Jon Mirandac1b23992016-12-13 08:57:36 -0800368 updateFolderCellSize(1f, dm, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700369
Jon Mirandac1b23992016-12-13 08:57:36 -0800370 // Don't let the folder get too close to the edges of the screen.
Jon Miranda72b5fd12017-06-25 18:06:23 -0700371 int folderMargin = edgeMarginPx;
Jon Mirandac1b23992016-12-13 08:57:36 -0800372
373 // Check if the icons fit within the available height.
374 float usedHeight = folderCellHeightPx * inv.numFolderRows + folderBottomPanelSize;
375 int maxHeight = availableHeightPx - getTotalWorkspacePadding().y - folderMargin;
376 float scaleY = maxHeight / usedHeight;
377
378 // Check if the icons fit within the available width.
379 float usedWidth = folderCellWidthPx * inv.numFolderColumns;
380 int maxWidth = availableWidthPx - getTotalWorkspacePadding().x - folderMargin;
381 float scaleX = maxWidth / usedWidth;
382
383 float scale = Math.min(scaleX, scaleY);
384 if (scale < 1f) {
385 updateFolderCellSize(scale, dm, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700386 }
387 }
388
Jon Mirandac1b23992016-12-13 08:57:36 -0800389 private void updateFolderCellSize(float scale, DisplayMetrics dm, Resources res) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700390 folderChildIconSizePx = (int) (Utilities.pxFromDp(inv.iconSize, dm) * scale);
391 folderChildTextSizePx =
392 (int) (res.getDimensionPixelSize(R.dimen.folder_child_text_size) * scale);
393
394 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
395 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding) * scale);
396 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding) * scale);
397
Jon Mirandac1b23992016-12-13 08:57:36 -0800398 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
399 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700400 folderChildDrawablePaddingPx = Math.max(0,
401 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
402 }
403
Winson1f064272016-07-18 17:18:02 -0700404 public void updateInsets(Rect insets) {
405 mInsets.set(insets);
406 }
407
Winson1f064272016-07-18 17:18:02 -0700408 public void updateAppsViewNumCols() {
409 allAppsNumCols = allAppsNumPredictiveCols = inv.numColumns;
Winson Chungb3800242013-10-24 11:01:54 -0700410 }
411
Tony Wickhama3c74d12015-10-23 11:43:47 -0700412 /** Returns the width and height of the search bar, ignoring any padding. */
Sunny Goyal47328fd2016-05-25 18:56:41 -0700413 public Point getSearchBarDimensForWidgetOpts() {
Tony Wickhama3c74d12015-10-23 11:43:47 -0700414 if (isVerticalBarLayout()) {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700415 return new Point(dropTargetBarSizePx, availableHeightPx - 2 * edgeMarginPx);
Winson Chungb3800242013-10-24 11:01:54 -0700416 } else {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700417 int gap;
Sunny Goyalc6205602015-05-21 20:46:33 -0700418 if (isTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700419 // Pad the left and right of the workspace to ensure consistent spacing
420 // between all icons
Winson Chung4f3bfad2015-07-13 11:14:30 -0700421 int width = getCurrentWidth();
Winson Chungb3800242013-10-24 11:01:54 -0700422 // XXX: If the icon size changes across orientations, we will have to take
423 // that into account here too.
Sunny Goyal47328fd2016-05-25 18:56:41 -0700424 gap = ((width - 2 * edgeMarginPx
425 - (inv.numColumns * cellWidthPx)) / (2 * (inv.numColumns + 1)))
426 + edgeMarginPx;
Winson Chungb3800242013-10-24 11:01:54 -0700427 } else {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700428 gap = desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.right;
Winson Chungb3800242013-10-24 11:01:54 -0700429 }
Sunny Goyal47328fd2016-05-25 18:56:41 -0700430 return new Point(availableWidthPx - 2 * gap, dropTargetBarSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700431 }
Winson Chungb3800242013-10-24 11:01:54 -0700432 }
433
Sunny Goyal756cd262015-08-20 12:33:21 -0700434 public Point getCellSize() {
435 Point result = new Point();
436 // Since we are only concerned with the overall padding, layout direction does
437 // not matter.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700438 Point padding = getTotalWorkspacePadding();
439 result.x = calculateCellWidth(availableWidthPx - padding.x, inv.numColumns);
440 result.y = calculateCellHeight(availableHeightPx - padding.y, inv.numRows);
Sunny Goyal756cd262015-08-20 12:33:21 -0700441 return result;
442 }
443
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700444 public Point getTotalWorkspacePadding() {
Sunny Goyal6178f132016-07-11 17:30:03 -0700445 Rect padding = getWorkspacePadding(null);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700446 return new Point(padding.left + padding.right, padding.top + padding.bottom);
447 }
448
449 /**
450 * Returns the workspace padding in the specified orientation.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700451 */
Sunny Goyal6178f132016-07-11 17:30:03 -0700452 public Rect getWorkspacePadding(Rect recycle) {
453 Rect padding = recycle == null ? new Rect() : recycle;
Tony Wickham3a3517f2015-10-06 11:27:04 -0700454 if (isVerticalBarLayout()) {
Winson1f064272016-07-18 17:18:02 -0700455 if (mInsets.left > 0) {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700456 padding.set(mInsets.left + pageIndicatorLandGutterPx,
457 0,
458 hotseatBarHeightPx + hotseatLandLeftNavBarGutterPx
459 + hotseatBarLeftNavBarRightPaddingPx - mInsets.left,
460 edgeMarginPx);
Winson1f064272016-07-18 17:18:02 -0700461 } else {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700462 padding.set(pageIndicatorLandGutterPx,
463 0,
464 hotseatBarHeightPx + hotseatLandRightNavBarGutterPx
465 + hotseatBarRightNavBarRightPaddingPx,
466 edgeMarginPx);
Winson1f064272016-07-18 17:18:02 -0700467 }
Winson Chungb3800242013-10-24 11:01:54 -0700468 } else {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700469 int paddingBottom = hotseatBarHeightPx + pageIndicatorSizePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700470 if (isTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700471 // Pad the left and right of the workspace to ensure consistent spacing
472 // between all icons
Winson Chung4f3bfad2015-07-13 11:14:30 -0700473 int width = getCurrentWidth();
474 int height = getCurrentHeight();
Tony Wickhamd6b40372015-09-23 18:37:57 -0700475 // The amount of screen space available for left/right padding.
Sunny Goyalf5440cb2016-12-14 15:13:00 -0800476 int availablePaddingX = Math.max(0, width - ((inv.numColumns * cellWidthPx) +
477 ((inv.numColumns - 1) * cellWidthPx)));
Tony Wickhamd6b40372015-09-23 18:37:57 -0700478 availablePaddingX = (int) Math.min(availablePaddingX,
479 width * MAX_HORIZONTAL_PADDING_PERCENT);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700480 int availablePaddingY = Math.max(0, height - topWorkspacePadding - paddingBottom
Jon Mirandac1b08c52016-11-15 14:37:56 -0800481 - (2 * inv.numRows * cellHeightPx) - hotseatBarTopPaddingPx
482 - hotseatBarBottomPaddingPx);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700483 padding.set(availablePaddingX / 2, topWorkspacePadding + availablePaddingY / 2,
Tony Wickhamd6b40372015-09-23 18:37:57 -0700484 availablePaddingX / 2, paddingBottom + availablePaddingY / 2);
Winson Chungb3800242013-10-24 11:01:54 -0700485 } else {
486 // Pad the top and bottom of the workspace with search/hotseat bar sizes
Winson1f064272016-07-18 17:18:02 -0700487 padding.set(desiredWorkspaceLeftRightMarginPx,
Sunny Goyal47328fd2016-05-25 18:56:41 -0700488 topWorkspacePadding,
Winson1f064272016-07-18 17:18:02 -0700489 desiredWorkspaceLeftRightMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700490 paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -0700491 }
492 }
493 return padding;
494 }
495
Winsonfadbe8f2016-07-22 16:35:37 -0700496 /**
497 * @return the bounds for which the open folders should be contained within
498 */
499 public Rect getAbsoluteOpenFolderBounds() {
500 if (isVerticalBarLayout()) {
501 // Folders should only appear right of the drop target bar and left of the hotseat
502 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
503 mInsets.top,
504 mInsets.left + availableWidthPx - hotseatBarHeightPx - edgeMarginPx,
505 mInsets.top + availableHeightPx);
506 } else {
507 // Folders should only appear below the drop target bar and above the hotseat
508 return new Rect(mInsets.left,
509 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
510 mInsets.left + availableWidthPx,
Jon Miranda2ed276e2017-06-29 11:36:34 -0700511 mInsets.top + availableHeightPx - hotseatBarHeightPx
512 - pageIndicatorSizePx - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -0700513 }
514 }
515
Sunny Goyal47328fd2016-05-25 18:56:41 -0700516 private int getWorkspacePageSpacing() {
Tony Wickham3a3517f2015-10-06 11:27:04 -0700517 if (isVerticalBarLayout() || isLargeTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700518 // In landscape mode the page spacing is set to the default.
519 return defaultPageSpacingPx;
520 } else {
521 // In portrait, we want the pages spaced such that there is no
522 // overhang of the previous / next page into the current page viewport.
523 // We assume symmetrical padding in portrait mode.
Jon Miranda28032002017-07-13 16:18:56 -0700524 return Math.max(defaultPageSpacingPx, getWorkspacePadding(null).left + 1);
Winson Chungb3800242013-10-24 11:01:54 -0700525 }
526 }
527
Winson Chung4f7eb402015-07-10 18:00:48 -0700528 int getOverviewModeButtonBarHeight() {
Winson Chungb3800242013-10-24 11:01:54 -0700529 int zoneHeight = (int) (overviewModeIconZoneRatio * availableHeightPx);
530 zoneHeight = Math.min(overviewModeMaxIconZoneHeightPx,
531 Math.max(overviewModeMinIconZoneHeightPx, zoneHeight));
Winson Chung4f7eb402015-07-10 18:00:48 -0700532 return zoneHeight;
Winson Chungb3800242013-10-24 11:01:54 -0700533 }
534
Adam Cohen2e6da152015-05-06 11:42:25 -0700535 public static int calculateCellWidth(int width, int countX) {
Winson Chungb3800242013-10-24 11:01:54 -0700536 return width / countX;
537 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700538 public static int calculateCellHeight(int height, int countY) {
Winson Chungb3800242013-10-24 11:01:54 -0700539 return height / countY;
540 }
541
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700542 /**
Tony Wickham55616cd2015-09-23 14:55:17 -0700543 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
544 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
545 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700546 */
Tony Wickhamab946a12015-09-16 15:38:16 -0700547 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -0700548 return isLandscape && transposeLayoutWithOrientation;
549 }
550
551 boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyalc6205602015-05-21 20:46:33 -0700552 return isVerticalBarLayout() || isLargeTablet;
Winson Chungb3800242013-10-24 11:01:54 -0700553 }
554
Sunny Goyalc6205602015-05-21 20:46:33 -0700555 private int getVisibleChildCount(ViewGroup parent) {
Jorim Jaggid017f882014-01-14 17:08:48 -0800556 int visibleChildren = 0;
557 for (int i = 0; i < parent.getChildCount(); i++) {
558 if (parent.getChildAt(i).getVisibility() != View.GONE) {
559 visibleChildren++;
560 }
561 }
562 return visibleChildren;
563 }
564
Winson1f064272016-07-18 17:18:02 -0700565 public void layout(Launcher launcher, boolean notifyListeners) {
Winson Chungb3800242013-10-24 11:01:54 -0700566 FrameLayout.LayoutParams lp;
Winson Chungb3800242013-10-24 11:01:54 -0700567 boolean hasVerticalBarLayout = isVerticalBarLayout();
568
569 // Layout the search bar space
Sunny Goyal47328fd2016-05-25 18:56:41 -0700570 Point searchBarBounds = getSearchBarDimensForWidgetOpts();
571 View searchBar = launcher.getDropTargetBar();
Sunny Goyalf37a2142016-03-24 17:28:25 -0700572 lp = (FrameLayout.LayoutParams) searchBar.getLayoutParams();
Sunny Goyal47328fd2016-05-25 18:56:41 -0700573 lp.width = searchBarBounds.x;
574 lp.height = searchBarBounds.y;
Jon Miranda28032002017-07-13 16:18:56 -0700575 lp.topMargin = mInsets.top + edgeMarginPx;
Winson Chungb3800242013-10-24 11:01:54 -0700576 searchBar.setLayoutParams(lp);
577
Winson Chungb3800242013-10-24 11:01:54 -0700578 // Layout the workspace
579 PagedView workspace = (PagedView) launcher.findViewById(R.id.workspace);
Winson1f064272016-07-18 17:18:02 -0700580 Rect workspacePadding = getWorkspacePadding(null);
581 workspace.setPadding(workspacePadding.left, workspacePadding.top, workspacePadding.right,
582 workspacePadding.bottom);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700583 workspace.setPageSpacing(getWorkspacePageSpacing());
Winson Chungb3800242013-10-24 11:01:54 -0700584
585 // Layout the hotseat
Winson6231ede2016-07-20 17:21:55 -0700586 Hotseat hotseat = (Hotseat) launcher.findViewById(R.id.hotseat);
Winson Chungb3800242013-10-24 11:01:54 -0700587 lp = (FrameLayout.LayoutParams) hotseat.getLayoutParams();
Tony Wickhamd6b40372015-09-23 18:37:57 -0700588 // We want the edges of the hotseat to line up with the edges of the workspace, but the
589 // icons in the hotseat are a different size, and so don't line up perfectly. To account for
590 // this, we pad the left and right of the hotseat with half of the difference of a workspace
591 // cell vs a hotseat cell.
592 float workspaceCellWidth = (float) getCurrentWidth() / inv.numColumns;
593 float hotseatCellWidth = (float) getCurrentWidth() / inv.numHotseatIcons;
594 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Winson Chungb3800242013-10-24 11:01:54 -0700595 if (hasVerticalBarLayout) {
Winson Chungf8c6f882015-06-03 11:27:26 -0700596 // Vertical hotseat -- The hotseat is fixed in the layout to be on the right of the
597 // screen regardless of RTL
598 lp.gravity = Gravity.RIGHT;
Winson1f064272016-07-18 17:18:02 -0700599 lp.width = hotseatBarHeightPx + mInsets.left + mInsets.right;
Winson Chungb3800242013-10-24 11:01:54 -0700600 lp.height = LayoutParams.MATCH_PARENT;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700601
602 int paddingRight = mInsets.left > 0
603 ? hotseatBarLeftNavBarRightPaddingPx
604 : hotseatBarRightNavBarRightPaddingPx;
605
Jon Miranda52ff3252017-07-14 11:39:16 -0700606 hotseat.getLayout().setPadding(mInsets.left + cellLayoutPaddingLeftRightPx,
607 mInsets.top, mInsets.right + paddingRight + cellLayoutPaddingLeftRightPx,
Winson6231ede2016-07-20 17:21:55 -0700608 workspacePadding.bottom);
Sunny Goyalc6205602015-05-21 20:46:33 -0700609 } else if (isTablet) {
Winson Chung59a488a2013-12-10 12:32:14 -0800610 // Pad the hotseat with the workspace padding calculated above
Winson Chungb3800242013-10-24 11:01:54 -0700611 lp.gravity = Gravity.BOTTOM;
612 lp.width = LayoutParams.MATCH_PARENT;
Winson1f064272016-07-18 17:18:02 -0700613 lp.height = hotseatBarHeightPx + mInsets.bottom;
Jon Miranda52ff3252017-07-14 11:39:16 -0700614 hotseat.getLayout().setPadding(hotseatAdjustment + workspacePadding.left
615 + cellLayoutPaddingLeftRightPx,
616 hotseatBarTopPaddingPx,
617 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx,
Jon Mirandac1b08c52016-11-15 14:37:56 -0800618 hotseatBarBottomPaddingPx + mInsets.bottom);
Winson Chungb3800242013-10-24 11:01:54 -0700619 } else {
620 // For phones, layout the hotseat without any bottom margin
621 // to ensure that we have space for the folders
622 lp.gravity = Gravity.BOTTOM;
623 lp.width = LayoutParams.MATCH_PARENT;
Winson1f064272016-07-18 17:18:02 -0700624 lp.height = hotseatBarHeightPx + mInsets.bottom;
Jon Miranda52ff3252017-07-14 11:39:16 -0700625 hotseat.getLayout().setPadding(hotseatAdjustment + workspacePadding.left
626 + cellLayoutPaddingLeftRightPx,
627 hotseatBarTopPaddingPx,
628 hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx,
Jon Mirandac1b08c52016-11-15 14:37:56 -0800629 hotseatBarBottomPaddingPx + mInsets.bottom);
Winson Chungb3800242013-10-24 11:01:54 -0700630 }
631 hotseat.setLayoutParams(lp);
632
633 // Layout the page indicators
634 View pageIndicator = launcher.findViewById(R.id.page_indicator);
635 if (pageIndicator != null) {
Hyunyoung Song7d2fc812016-06-15 12:51:30 -0700636 lp = (FrameLayout.LayoutParams) pageIndicator.getLayoutParams();
Winson1f064272016-07-18 17:18:02 -0700637 if (isVerticalBarLayout()) {
638 if (mInsets.left > 0) {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700639 lp.leftMargin = mInsets.left;
640 } else {
641 lp.leftMargin = pageIndicatorLandWorkspaceOffsetPx;
Winson1f064272016-07-18 17:18:02 -0700642 }
643 lp.bottomMargin = workspacePadding.bottom;
644 } else {
Winson Chungb3800242013-10-24 11:01:54 -0700645 // Put the page indicators above the hotseat
Winson Chungb3800242013-10-24 11:01:54 -0700646 lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700647 lp.height = pageIndicatorSizePx;
Winson1f064272016-07-18 17:18:02 -0700648 lp.bottomMargin = hotseatBarHeightPx + mInsets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -0700649 }
Hyunyoung Song7d2fc812016-06-15 12:51:30 -0700650 pageIndicator.setLayoutParams(lp);
Winson Chungb3800242013-10-24 11:01:54 -0700651 }
652
Winson Chungb3800242013-10-24 11:01:54 -0700653 // Layout the Overview Mode
Jorim Jaggid017f882014-01-14 17:08:48 -0800654 ViewGroup overviewMode = launcher.getOverviewPanel();
Winson Chungb3800242013-10-24 11:01:54 -0700655 if (overviewMode != null) {
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700656 int visibleChildCount = getVisibleChildCount(overviewMode);
657 int totalItemWidth = visibleChildCount * overviewModeBarItemWidthPx;
Jon Mirandadf3bc522016-11-01 16:55:56 -0700658 int maxWidth = totalItemWidth + (visibleChildCount - 1) * overviewModeBarSpacerWidthPx;
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700659
Jon Mirandadf3bc522016-11-01 16:55:56 -0700660 lp = (FrameLayout.LayoutParams) overviewMode.getLayoutParams();
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700661 lp.width = Math.min(availableWidthPx, maxWidth);
Jon Mirandadf3bc522016-11-01 16:55:56 -0700662 lp.height = getOverviewModeButtonBarHeight() + mInsets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -0700663 overviewMode.setLayoutParams(lp);
Winson1f064272016-07-18 17:18:02 -0700664 }
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700665
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700666 // Layout the AllAppsRecyclerView
667 View view = launcher.findViewById(R.id.apps_list_view);
Jon Miranda28032002017-07-13 16:18:56 -0700668 int paddingLeftRight = desiredWorkspaceLeftRightMarginPx + cellLayoutPaddingLeftRightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700669 view.setPadding(paddingLeftRight, view.getPaddingTop(), paddingLeftRight,
670 view.getPaddingBottom());
671
Winson1f064272016-07-18 17:18:02 -0700672 if (notifyListeners) {
673 for (int i = mListeners.size() - 1; i >= 0; i--) {
674 mListeners.get(i).onLauncherLayoutChanged();
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700675 }
Winson Chungb3800242013-10-24 11:01:54 -0700676 }
677 }
Winson Chung4f3bfad2015-07-13 11:14:30 -0700678
679 private int getCurrentWidth() {
680 return isLandscape
681 ? Math.max(widthPx, heightPx)
682 : Math.min(widthPx, heightPx);
683 }
684
685 private int getCurrentHeight() {
686 return isLandscape
687 ? Math.min(widthPx, heightPx)
688 : Math.max(widthPx, heightPx);
689 }
Sunny Goyal13178ac2016-04-04 16:35:22 -0700690
Sunny Goyalc13403c2016-11-18 23:44:48 -0800691 public int getCellHeight(@ContainerType int containerType) {
692 switch (containerType) {
693 case CellLayout.WORKSPACE:
694 return cellHeightPx;
695 case CellLayout.FOLDER:
696 return folderCellHeightPx;
697 case CellLayout.HOTSEAT:
698 return hotseatCellHeightPx;
699 default:
700 // ??
701 return 0;
702 }
703 }
Sunny Goyal13178ac2016-04-04 16:35:22 -0700704
Winson1f064272016-07-18 17:18:02 -0700705 /**
706 * @return the left/right paddings for all containers.
707 */
Jon Mirandac3e4e222016-11-02 16:56:52 -0700708 public final int[] getContainerPadding() {
Winson1f064272016-07-18 17:18:02 -0700709 // No paddings for portrait phone
710 if (isPhone && !isVerticalBarLayout()) {
711 return new int[] {0, 0};
Sunny Goyal13178ac2016-04-04 16:35:22 -0700712 }
Winson1f064272016-07-18 17:18:02 -0700713
Hyunyoung Song9d96fd52016-08-23 11:06:24 -0700714 // In landscape, we match the width of the workspace
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700715 Rect padding = getWorkspacePadding(null);
716 return new int[] { padding.left - mInsets.left, padding.right + mInsets.left};
Sunny Goyal13178ac2016-04-04 16:35:22 -0700717 }
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700718
Jon Miranda51f037d2016-11-07 08:37:20 -0800719 public boolean shouldIgnoreLongPressToOverview(float touchX) {
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700720 boolean inMultiWindowMode = this != inv.landscapeProfile && this != inv.portraitProfile;
Jon Miranda51f037d2016-11-07 08:37:20 -0800721 boolean touchedLhsEdge = mInsets.left == 0 && touchX < edgeMarginPx;
722 boolean touchedRhsEdge = mInsets.right == 0 && touchX > (widthPx - edgeMarginPx);
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700723 return !inMultiWindowMode && (touchedLhsEdge || touchedRhsEdge);
724 }
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700725
726 private static Context getContext(Context c, int orientation) {
727 Configuration context = new Configuration(c.getResources().getConfiguration());
728 context.orientation = orientation;
729 return c.createConfigurationContext(context);
730
731 }
Winson Chungb3800242013-10-24 11:01:54 -0700732}