blob: 7520be2f6e6792c81c1220f0b3430a1a742fe08b [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
74 private int desiredWorkspaceLeftRightMarginPx;
75 public final int edgeMarginPx;
76 public final Rect defaultWidgetPadding;
Sunny Goyalc6205602015-05-21 20:46:33 -070077 private final int defaultPageSpacingPx;
Sunny Goyal47328fd2016-05-25 18:56:41 -070078 private final int topWorkspacePadding;
Sunny Goyal47328fd2016-05-25 18:56:41 -070079 public float workspaceSpringLoadShrinkFactor;
80 public final int workspaceSpringLoadedBottomSpace;
Sunny Goyalc6205602015-05-21 20:46:33 -070081
Winson1f064272016-07-18 17:18:02 -070082 // Page indicator
Jon Miranda2ed276e2017-06-29 11:36:34 -070083 private int pageIndicatorSizePx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070084 private final int pageIndicatorLandGutterPx;
Winson1f064272016-07-18 17:18:02 -070085 private final int pageIndicatorLandWorkspaceOffsetPx;
86
Sunny Goyalc6205602015-05-21 20:46:33 -070087 // Workspace icons
88 public int iconSizePx;
89 public int iconTextSizePx;
90 public int iconDrawablePaddingPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -070091 public int iconDrawablePaddingOriginalPx;
Winson Chungb3800242013-10-24 11:01:54 -070092
Adam Cohen59400422014-03-05 18:07:04 -080093 public int cellWidthPx;
94 public int cellHeightPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070095 public int workspaceCellPaddingXPx;
Adam Cohen59400422014-03-05 18:07:04 -080096
Sunny Goyalc6205602015-05-21 20:46:33 -070097 // Folder
98 public int folderBackgroundOffset;
99 public int folderIconSizePx;
Adam Cohenefca0272016-02-24 19:19:06 -0800100 public int folderIconPreviewPadding;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700101
102 // Folder cell
Sunny Goyalc6205602015-05-21 20:46:33 -0700103 public int folderCellWidthPx;
104 public int folderCellHeightPx;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700105
106 // Folder child
107 public int folderChildIconSizePx;
108 public int folderChildTextSizePx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700109 public int folderChildDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700110
Sunny Goyalc6205602015-05-21 20:46:33 -0700111 // Hotseat
Sunny Goyalc6205602015-05-21 20:46:33 -0700112 public int hotseatCellHeightPx;
Jon Mirandaaca21452016-09-26 14:01:56 -0700113 public int hotseatBarHeightPx;
Sunny Goyal0dc1db42017-05-17 11:34:33 -0700114 public int hotseatBarTopPaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700115 public int hotseatBarLeftNavBarRightPaddingPx;
116 public int hotseatBarRightNavBarRightPaddingPx;
Sunny Goyal0dc1db42017-05-17 11:34:33 -0700117 public int hotseatBarBottomPaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700118 public int hotseatLandLeftNavBarGutterPx;
119 public int hotseatLandRightNavBarGutterPx;
Adam Cohen2e6da152015-05-06 11:42:25 -0700120
Sunny Goyalc6205602015-05-21 20:46:33 -0700121 // All apps
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700122 public int allAppsCellHeightPx;
Winson Chung5f4e0fd2015-05-22 11:12:27 -0700123 public int allAppsNumCols;
124 public int allAppsNumPredictiveCols;
Sunny Goyalc6205602015-05-21 20:46:33 -0700125 public int allAppsButtonVisualSize;
Winson1f064272016-07-18 17:18:02 -0700126 public int allAppsIconSizePx;
127 public int allAppsIconDrawablePaddingPx;
128 public float allAppsIconTextSizePx;
129
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800130 // Widgets
131 public final PointF appWidgetScale = new PointF(1.0f, 1.0f);
132
Sunny Goyal47328fd2016-05-25 18:56:41 -0700133 // Drop Target
134 public int dropTargetBarSizePx;
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700135
Winson1f064272016-07-18 17:18:02 -0700136 // Insets
137 private Rect mInsets = new Rect();
138
139 // Listeners
140 private ArrayList<LauncherLayoutChangeListener> mListeners = new ArrayList<>();
141
Tony Wickham9a8d11f2017-01-11 09:53:12 -0800142 // Icon badges
143 public BadgeRenderer mBadgeRenderer;
144
Sunny Goyalc6205602015-05-21 20:46:33 -0700145 public DeviceProfile(Context context, InvariantDeviceProfile inv,
146 Point minSize, Point maxSize,
147 int width, int height, boolean isLandscape) {
Sunny Goyalfee35bb2015-05-11 11:38:19 -0700148
Adam Cohen2e6da152015-05-06 11:42:25 -0700149 this.inv = inv;
Sunny Goyalc6205602015-05-21 20:46:33 -0700150 this.isLandscape = isLandscape;
Winson Chungb3800242013-10-24 11:01:54 -0700151
Adam Cohen2e6da152015-05-06 11:42:25 -0700152 Resources res = context.getResources();
Winson Chungb3800242013-10-24 11:01:54 -0700153 DisplayMetrics dm = res.getDisplayMetrics();
Adam Cohen2e6da152015-05-06 11:42:25 -0700154
Sunny Goyalc6205602015-05-21 20:46:33 -0700155 // Constants from resources
156 isTablet = res.getBoolean(R.bool.is_tablet);
157 isLargeTablet = res.getBoolean(R.bool.is_large_tablet);
158 isPhone = !isTablet && !isLargeTablet;
159
160 // Some more constants
Winson Chungb3800242013-10-24 11:01:54 -0700161 transposeLayoutWithOrientation =
162 res.getBoolean(R.bool.hotseat_transpose_layout_with_orientation);
Winson Chungb3800242013-10-24 11:01:54 -0700163
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700164 context = getContext(context, isVerticalBarLayout()
165 ? Configuration.ORIENTATION_LANDSCAPE
166 : Configuration.ORIENTATION_PORTRAIT);
167 res = context.getResources();
168
169
Winson Chungb3800242013-10-24 11:01:54 -0700170 ComponentName cn = new ComponentName(context.getPackageName(),
171 this.getClass().getName());
172 defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
173 edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
Winson1f064272016-07-18 17:18:02 -0700174 desiredWorkspaceLeftRightMarginPx = edgeMarginPx;
Jon Miranda2ed276e2017-06-29 11:36:34 -0700175 pageIndicatorSizePx = res.getDimensionPixelSize(
176 R.dimen.dynamic_grid_min_page_indicator_size);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700177 pageIndicatorLandGutterPx = res.getDimensionPixelSize(
178 R.dimen.dynamic_grid_page_indicator_gutter_width);
Winson1f064272016-07-18 17:18:02 -0700179 pageIndicatorLandWorkspaceOffsetPx =
180 res.getDimensionPixelSize(R.dimen.all_apps_caret_workspace_offset);
Winson Chungb3800242013-10-24 11:01:54 -0700181 defaultPageSpacingPx =
182 res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_page_spacing);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700183 topWorkspacePadding =
184 res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_top_padding);
Winson Chungb3800242013-10-24 11:01:54 -0700185 overviewModeMinIconZoneHeightPx =
186 res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_min_icon_zone_height);
187 overviewModeMaxIconZoneHeightPx =
188 res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_max_icon_zone_height);
Jorim Jaggid017f882014-01-14 17:08:48 -0800189 overviewModeBarItemWidthPx =
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700190 res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_bar_item_width);
Jorim Jaggid017f882014-01-14 17:08:48 -0800191 overviewModeBarSpacerWidthPx =
192 res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_bar_spacer_width);
Winson Chungb3800242013-10-24 11:01:54 -0700193 overviewModeIconZoneRatio =
194 res.getInteger(R.integer.config_dynamic_grid_overview_icon_zone_percentage) / 100f;
Winson Chungb3800242013-10-24 11:01:54 -0700195 iconDrawablePaddingOriginalPx =
196 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700197 dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
198 workspaceSpringLoadedBottomSpace =
199 res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space);
Sunny Goyald5190522017-04-24 03:06:54 -0700200
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700201 workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
Jon Miranda09660722017-06-14 14:20:14 -0700202
Winson1f064272016-07-18 17:18:02 -0700203 hotseatBarTopPaddingPx =
204 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding);
Sunny Goyald5190522017-04-24 03:06:54 -0700205 hotseatBarBottomPaddingPx =
206 res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_padding);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700207 hotseatBarLeftNavBarRightPaddingPx = res.getDimensionPixelSize(
208 R.dimen.dynamic_grid_hotseat_land_left_nav_bar_right_padding);
209 hotseatBarRightNavBarRightPaddingPx = res.getDimensionPixelSize(
210 R.dimen.dynamic_grid_hotseat_land_right_nav_bar_right_padding);
211 hotseatBarHeightPx = isVerticalBarLayout()
212 ? res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_height)
213 : res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_height)
214 + hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx;
215
216 hotseatLandLeftNavBarGutterPx = res.getDimensionPixelSize(
217 R.dimen.dynamic_grid_hotseat_land_left_nav_bar_gutter_width);
218 hotseatLandRightNavBarGutterPx = res.getDimensionPixelSize(
219 R.dimen.dynamic_grid_hotseat_land_right_nav_bar_gutter_width);
Winson Chungb3800242013-10-24 11:01:54 -0700220
Sunny Goyalc6205602015-05-21 20:46:33 -0700221 // Determine sizes.
222 widthPx = width;
223 heightPx = height;
224 if (isLandscape) {
225 availableWidthPx = maxSize.x;
226 availableHeightPx = minSize.y;
227 } else {
228 availableWidthPx = minSize.x;
229 availableHeightPx = maxSize.y;
230 }
Adam Cohen4ae96ce2014-08-29 15:05:48 -0700231
Jon Miranda2ed276e2017-06-29 11:36:34 -0700232 // Calculate all of the remaining variables.
Sunny Goyalc6205602015-05-21 20:46:33 -0700233 updateAvailableDimensions(dm, res);
Jon Miranda2ed276e2017-06-29 11:36:34 -0700234
235 // Now that we have all of the variables calculated, we can tune certain sizes.
236 if (!isVerticalBarLayout()) {
237 // We increase the page indicator size when there is extra space.
238 // ie. For a display with a large aspect ratio, we can keep the icons on the workspace
239 // in portrait mode closer together by increasing the page indicator size.
240 int newPageIndicatorSizePx = getCellSize().y - iconSizePx - iconTextSizePx
241 - iconDrawablePaddingOriginalPx;
242 if (newPageIndicatorSizePx > pageIndicatorSizePx) {
243 pageIndicatorSizePx = newPageIndicatorSizePx;
244 // Recalculate the available dimensions using the new page indicator size.
245 updateAvailableDimensions(dm, res);
246 }
247 }
248
Adam Cohen63f1ec02014-08-12 09:23:13 -0700249 computeAllAppsButtonSize(context);
Tony Wickham1237df02017-02-24 08:59:36 -0800250
251 // This is done last, after iconSizePx is calculated above.
252 mBadgeRenderer = new BadgeRenderer(context, iconSizePx);
Adam Cohen63f1ec02014-08-12 09:23:13 -0700253 }
254
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700255 DeviceProfile getMultiWindowProfile(Context context, Point mwSize) {
256 // In multi-window mode, we can have widthPx = availableWidthPx
257 // and heightPx = availableHeightPx because Launcher uses the InvariantDeviceProfiles'
258 // widthPx and heightPx values where it's needed.
Jon Miranda93e1f042016-11-11 14:13:04 -0800259 DeviceProfile profile = new DeviceProfile(context, inv, mwSize, mwSize, mwSize.x, mwSize.y,
260 isLandscape);
261
262 // Hide labels on the workspace.
263 profile.iconTextSizePx = 0;
264 profile.cellHeightPx = profile.iconSizePx + profile.iconDrawablePaddingPx
265 + Utilities.calculateTextHeight(profile.iconTextSizePx);
266
Jon Miranda7ae64ff2016-11-21 16:18:46 -0800267 // We use these scales to measure and layout the widgets using their full invariant profile
268 // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans.
269 float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x;
270 float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y;
271 profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY);
272
Jon Miranda93e1f042016-11-11 14:13:04 -0800273 return profile;
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700274 }
275
Winson1f064272016-07-18 17:18:02 -0700276 public void addLauncherLayoutChangedListener(LauncherLayoutChangeListener listener) {
277 if (!mListeners.contains(listener)) {
278 mListeners.add(listener);
279 }
280 }
281
282 public void removeLauncherLayoutChangedListener(LauncherLayoutChangeListener listener) {
283 if (mListeners.contains(listener)) {
284 mListeners.remove(listener);
285 }
286 }
287
Adam Cohen63f1ec02014-08-12 09:23:13 -0700288 /**
289 * Determine the exact visual footprint of the all apps button, taking into account scaling
290 * and internal padding of the drawable.
291 */
292 private void computeAllAppsButtonSize(Context context) {
293 Resources res = context.getResources();
294 float padding = res.getInteger(R.integer.config_allAppsButtonPaddingPercent) / 100f;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700295 allAppsButtonVisualSize = (int) (iconSizePx * (1 - padding)) - context.getResources()
Tony Wickhamd6b40372015-09-23 18:37:57 -0700296 .getDimensionPixelSize(R.dimen.all_apps_button_scale_down);
Winson Chungb3800242013-10-24 11:01:54 -0700297 }
298
Sunny Goyalc6205602015-05-21 20:46:33 -0700299 private void updateAvailableDimensions(DisplayMetrics dm, Resources res) {
Jon Miranda09660722017-06-14 14:20:14 -0700300 updateIconSize(1f, res, dm);
Winson Chung59a488a2013-12-10 12:32:14 -0800301
Jon Mirandabf7d8122016-11-03 15:29:29 -0700302 // Check to see if the icons fit within the available height. If not, then scale down.
303 float usedHeight = (cellHeightPx * inv.numRows);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700304 int maxHeight = (availableHeightPx - getTotalWorkspacePadding().y);
Winson Chungb3800242013-10-24 11:01:54 -0700305 if (usedHeight > maxHeight) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700306 float scale = maxHeight / usedHeight;
Jon Miranda09660722017-06-14 14:20:14 -0700307 updateIconSize(scale, res, dm);
Winson Chungb3800242013-10-24 11:01:54 -0700308 }
Jon Mirandabf7d8122016-11-03 15:29:29 -0700309 updateAvailableFolderCellDimensions(dm, res);
Winson Chungb3800242013-10-24 11:01:54 -0700310 }
311
Jon Miranda09660722017-06-14 14:20:14 -0700312 private void updateIconSize(float scale, Resources res, DisplayMetrics dm) {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700313 float invIconSizePx = isVerticalBarLayout() ? inv.landscapeIconSize : inv.iconSize;
314 iconSizePx = (int) (Utilities.pxFromDp(invIconSizePx, dm) * scale);
Sunny Goyala50a4192015-12-11 09:50:49 -0800315 iconTextSizePx = (int) (Utilities.pxFromSp(inv.iconTextSize, dm) * scale);
Jon Miranda09660722017-06-14 14:20:14 -0700316 iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * scale);
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700317
318 // All apps
319 allAppsIconTextSizePx = iconTextSizePx;
Winson1f064272016-07-18 17:18:02 -0700320 allAppsIconSizePx = iconSizePx;
321 allAppsIconDrawablePaddingPx = iconDrawablePaddingPx;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700322 allAppsCellHeightPx = getCellSize().y;
323
324 if (isVerticalBarLayout()) {
325 // Always hide the Workspace text with vertical bar layout.
326 iconTextSizePx = 0;
327 allAppsCellHeightPx += Utilities.calculateTextHeight(allAppsIconTextSizePx);
328 }
Winson Chungb3800242013-10-24 11:01:54 -0700329
Jon Miranda09660722017-06-14 14:20:14 -0700330 cellWidthPx = iconSizePx + iconDrawablePaddingPx;
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700331 cellHeightPx = iconSizePx + iconDrawablePaddingPx
332 + Utilities.calculateTextHeight(iconTextSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700333
334 // Hotseat
Jon Miranda09660722017-06-14 14:20:14 -0700335 hotseatCellHeightPx = iconSizePx + iconDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700336
Sunny Goyal47328fd2016-05-25 18:56:41 -0700337 if (!isVerticalBarLayout()) {
338 int expectedWorkspaceHeight = availableHeightPx - hotseatBarHeightPx
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700339 - pageIndicatorSizePx - topWorkspacePadding;
Sunny Goyal47328fd2016-05-25 18:56:41 -0700340 float minRequiredHeight = dropTargetBarSizePx + workspaceSpringLoadedBottomSpace;
341 workspaceSpringLoadShrinkFactor = Math.min(
342 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f,
343 1 - (minRequiredHeight / expectedWorkspaceHeight));
344 } else {
345 workspaceSpringLoadShrinkFactor =
346 res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
347 }
348
Sunny Goyalbaec6ff2016-09-14 11:26:21 -0700349 // Folder icon
Jon Miranda09660722017-06-14 14:20:14 -0700350 folderBackgroundOffset = -iconDrawablePaddingPx;
Winson Chungb3800242013-10-24 11:01:54 -0700351 folderIconSizePx = iconSizePx + 2 * -folderBackgroundOffset;
Adam Cohenefca0272016-02-24 19:19:06 -0800352 folderIconPreviewPadding = res.getDimensionPixelSize(R.dimen.folder_preview_padding);
Winson Chung0f785722015-04-08 10:27:49 -0700353 }
354
Jon Mirandabf7d8122016-11-03 15:29:29 -0700355 private void updateAvailableFolderCellDimensions(DisplayMetrics dm, Resources res) {
356 int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_padding_top)
357 + res.getDimensionPixelSize(R.dimen.folder_label_padding_bottom)
358 + Utilities.calculateTextHeight(res.getDimension(R.dimen.folder_label_text_size));
359
Jon Mirandac1b23992016-12-13 08:57:36 -0800360 updateFolderCellSize(1f, dm, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700361
Jon Mirandac1b23992016-12-13 08:57:36 -0800362 // Don't let the folder get too close to the edges of the screen.
Jon Miranda72b5fd12017-06-25 18:06:23 -0700363 int folderMargin = edgeMarginPx;
Jon Mirandac1b23992016-12-13 08:57:36 -0800364
365 // Check if the icons fit within the available height.
366 float usedHeight = folderCellHeightPx * inv.numFolderRows + folderBottomPanelSize;
367 int maxHeight = availableHeightPx - getTotalWorkspacePadding().y - folderMargin;
368 float scaleY = maxHeight / usedHeight;
369
370 // Check if the icons fit within the available width.
371 float usedWidth = folderCellWidthPx * inv.numFolderColumns;
372 int maxWidth = availableWidthPx - getTotalWorkspacePadding().x - folderMargin;
373 float scaleX = maxWidth / usedWidth;
374
375 float scale = Math.min(scaleX, scaleY);
376 if (scale < 1f) {
377 updateFolderCellSize(scale, dm, res);
Jon Mirandabf7d8122016-11-03 15:29:29 -0700378 }
379 }
380
Jon Mirandac1b23992016-12-13 08:57:36 -0800381 private void updateFolderCellSize(float scale, DisplayMetrics dm, Resources res) {
Jon Mirandabf7d8122016-11-03 15:29:29 -0700382 folderChildIconSizePx = (int) (Utilities.pxFromDp(inv.iconSize, dm) * scale);
383 folderChildTextSizePx =
384 (int) (res.getDimensionPixelSize(R.dimen.folder_child_text_size) * scale);
385
386 int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
387 int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding) * scale);
388 int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding) * scale);
389
Jon Mirandac1b23992016-12-13 08:57:36 -0800390 folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
391 folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
Jon Mirandabf7d8122016-11-03 15:29:29 -0700392 folderChildDrawablePaddingPx = Math.max(0,
393 (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3);
394 }
395
Winson1f064272016-07-18 17:18:02 -0700396 public void updateInsets(Rect insets) {
397 mInsets.set(insets);
398 }
399
Winson1f064272016-07-18 17:18:02 -0700400 public void updateAppsViewNumCols() {
401 allAppsNumCols = allAppsNumPredictiveCols = inv.numColumns;
Winson Chungb3800242013-10-24 11:01:54 -0700402 }
403
Tony Wickhama3c74d12015-10-23 11:43:47 -0700404 /** Returns the width and height of the search bar, ignoring any padding. */
Sunny Goyal47328fd2016-05-25 18:56:41 -0700405 public Point getSearchBarDimensForWidgetOpts() {
Tony Wickhama3c74d12015-10-23 11:43:47 -0700406 if (isVerticalBarLayout()) {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700407 return new Point(dropTargetBarSizePx, availableHeightPx - 2 * edgeMarginPx);
Winson Chungb3800242013-10-24 11:01:54 -0700408 } else {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700409 int gap;
Sunny Goyalc6205602015-05-21 20:46:33 -0700410 if (isTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700411 // Pad the left and right of the workspace to ensure consistent spacing
412 // between all icons
Winson Chung4f3bfad2015-07-13 11:14:30 -0700413 int width = getCurrentWidth();
Winson Chungb3800242013-10-24 11:01:54 -0700414 // XXX: If the icon size changes across orientations, we will have to take
415 // that into account here too.
Sunny Goyal47328fd2016-05-25 18:56:41 -0700416 gap = ((width - 2 * edgeMarginPx
417 - (inv.numColumns * cellWidthPx)) / (2 * (inv.numColumns + 1)))
418 + edgeMarginPx;
Winson Chungb3800242013-10-24 11:01:54 -0700419 } else {
Sunny Goyal47328fd2016-05-25 18:56:41 -0700420 gap = desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.right;
Winson Chungb3800242013-10-24 11:01:54 -0700421 }
Sunny Goyal47328fd2016-05-25 18:56:41 -0700422 return new Point(availableWidthPx - 2 * gap, dropTargetBarSizePx);
Winson Chungb3800242013-10-24 11:01:54 -0700423 }
Winson Chungb3800242013-10-24 11:01:54 -0700424 }
425
Sunny Goyal756cd262015-08-20 12:33:21 -0700426 public Point getCellSize() {
427 Point result = new Point();
428 // Since we are only concerned with the overall padding, layout direction does
429 // not matter.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700430 Point padding = getTotalWorkspacePadding();
431 result.x = calculateCellWidth(availableWidthPx - padding.x, inv.numColumns);
432 result.y = calculateCellHeight(availableHeightPx - padding.y, inv.numRows);
Sunny Goyal756cd262015-08-20 12:33:21 -0700433 return result;
434 }
435
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700436 public Point getTotalWorkspacePadding() {
Sunny Goyal6178f132016-07-11 17:30:03 -0700437 Rect padding = getWorkspacePadding(null);
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700438 return new Point(padding.left + padding.right, padding.top + padding.bottom);
439 }
440
441 /**
442 * Returns the workspace padding in the specified orientation.
Sunny Goyal6c2975e2016-07-06 09:47:56 -0700443 */
Sunny Goyal6178f132016-07-11 17:30:03 -0700444 public Rect getWorkspacePadding(Rect recycle) {
445 Rect padding = recycle == null ? new Rect() : recycle;
Tony Wickham3a3517f2015-10-06 11:27:04 -0700446 if (isVerticalBarLayout()) {
Winson1f064272016-07-18 17:18:02 -0700447 if (mInsets.left > 0) {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700448 padding.set(mInsets.left + pageIndicatorLandGutterPx,
449 0,
450 hotseatBarHeightPx + hotseatLandLeftNavBarGutterPx
451 + hotseatBarLeftNavBarRightPaddingPx - mInsets.left,
452 edgeMarginPx);
Winson1f064272016-07-18 17:18:02 -0700453 } else {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700454 padding.set(pageIndicatorLandGutterPx,
455 0,
456 hotseatBarHeightPx + hotseatLandRightNavBarGutterPx
457 + hotseatBarRightNavBarRightPaddingPx,
458 edgeMarginPx);
Winson1f064272016-07-18 17:18:02 -0700459 }
Winson Chungb3800242013-10-24 11:01:54 -0700460 } else {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700461 int paddingBottom = hotseatBarHeightPx + pageIndicatorSizePx;
Sunny Goyalc6205602015-05-21 20:46:33 -0700462 if (isTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700463 // Pad the left and right of the workspace to ensure consistent spacing
464 // between all icons
Winson Chung4f3bfad2015-07-13 11:14:30 -0700465 int width = getCurrentWidth();
466 int height = getCurrentHeight();
Tony Wickhamd6b40372015-09-23 18:37:57 -0700467 // The amount of screen space available for left/right padding.
Sunny Goyalf5440cb2016-12-14 15:13:00 -0800468 int availablePaddingX = Math.max(0, width - ((inv.numColumns * cellWidthPx) +
469 ((inv.numColumns - 1) * cellWidthPx)));
Tony Wickhamd6b40372015-09-23 18:37:57 -0700470 availablePaddingX = (int) Math.min(availablePaddingX,
471 width * MAX_HORIZONTAL_PADDING_PERCENT);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700472 int availablePaddingY = Math.max(0, height - topWorkspacePadding - paddingBottom
Jon Mirandac1b08c52016-11-15 14:37:56 -0800473 - (2 * inv.numRows * cellHeightPx) - hotseatBarTopPaddingPx
474 - hotseatBarBottomPaddingPx);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700475 padding.set(availablePaddingX / 2, topWorkspacePadding + availablePaddingY / 2,
Tony Wickhamd6b40372015-09-23 18:37:57 -0700476 availablePaddingX / 2, paddingBottom + availablePaddingY / 2);
Winson Chungb3800242013-10-24 11:01:54 -0700477 } else {
478 // Pad the top and bottom of the workspace with search/hotseat bar sizes
Winson1f064272016-07-18 17:18:02 -0700479 padding.set(desiredWorkspaceLeftRightMarginPx,
Sunny Goyal47328fd2016-05-25 18:56:41 -0700480 topWorkspacePadding,
Winson1f064272016-07-18 17:18:02 -0700481 desiredWorkspaceLeftRightMarginPx,
Winsonfadbe8f2016-07-22 16:35:37 -0700482 paddingBottom);
Winson Chungb3800242013-10-24 11:01:54 -0700483 }
484 }
485 return padding;
486 }
487
Winsonfadbe8f2016-07-22 16:35:37 -0700488 /**
489 * @return the bounds for which the open folders should be contained within
490 */
491 public Rect getAbsoluteOpenFolderBounds() {
492 if (isVerticalBarLayout()) {
493 // Folders should only appear right of the drop target bar and left of the hotseat
494 return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
495 mInsets.top,
496 mInsets.left + availableWidthPx - hotseatBarHeightPx - edgeMarginPx,
497 mInsets.top + availableHeightPx);
498 } else {
499 // Folders should only appear below the drop target bar and above the hotseat
500 return new Rect(mInsets.left,
501 mInsets.top + dropTargetBarSizePx + edgeMarginPx,
502 mInsets.left + availableWidthPx,
Jon Miranda2ed276e2017-06-29 11:36:34 -0700503 mInsets.top + availableHeightPx - hotseatBarHeightPx
504 - pageIndicatorSizePx - edgeMarginPx);
Winsonfadbe8f2016-07-22 16:35:37 -0700505 }
506 }
507
Sunny Goyal47328fd2016-05-25 18:56:41 -0700508 private int getWorkspacePageSpacing() {
Tony Wickham3a3517f2015-10-06 11:27:04 -0700509 if (isVerticalBarLayout() || isLargeTablet) {
Winson Chungb3800242013-10-24 11:01:54 -0700510 // In landscape mode the page spacing is set to the default.
511 return defaultPageSpacingPx;
512 } else {
513 // In portrait, we want the pages spaced such that there is no
514 // overhang of the previous / next page into the current page viewport.
515 // We assume symmetrical padding in portrait mode.
Jon Miranda72b5fd12017-06-25 18:06:23 -0700516 return Math.max(defaultPageSpacingPx, getWorkspacePadding(null).left / 2 + 1);
Winson Chungb3800242013-10-24 11:01:54 -0700517 }
518 }
519
Winson Chung4f7eb402015-07-10 18:00:48 -0700520 int getOverviewModeButtonBarHeight() {
Winson Chungb3800242013-10-24 11:01:54 -0700521 int zoneHeight = (int) (overviewModeIconZoneRatio * availableHeightPx);
522 zoneHeight = Math.min(overviewModeMaxIconZoneHeightPx,
523 Math.max(overviewModeMinIconZoneHeightPx, zoneHeight));
Winson Chung4f7eb402015-07-10 18:00:48 -0700524 return zoneHeight;
Winson Chungb3800242013-10-24 11:01:54 -0700525 }
526
Adam Cohen2e6da152015-05-06 11:42:25 -0700527 public static int calculateCellWidth(int width, int countX) {
Winson Chungb3800242013-10-24 11:01:54 -0700528 return width / countX;
529 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700530 public static int calculateCellHeight(int height, int countY) {
Winson Chungb3800242013-10-24 11:01:54 -0700531 return height / countY;
532 }
533
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700534 /**
Tony Wickham55616cd2015-09-23 14:55:17 -0700535 * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
536 * When {@code false}, either device is in portrait mode or the device is in landscape mode and
537 * the hotseat is on the bottom row.
Hyunyoung Song18bfaaf2015-03-17 11:32:21 -0700538 */
Tony Wickhamab946a12015-09-16 15:38:16 -0700539 public boolean isVerticalBarLayout() {
Winson Chungb3800242013-10-24 11:01:54 -0700540 return isLandscape && transposeLayoutWithOrientation;
541 }
542
543 boolean shouldFadeAdjacentWorkspaceScreens() {
Sunny Goyalc6205602015-05-21 20:46:33 -0700544 return isVerticalBarLayout() || isLargeTablet;
Winson Chungb3800242013-10-24 11:01:54 -0700545 }
546
Sunny Goyalc6205602015-05-21 20:46:33 -0700547 private int getVisibleChildCount(ViewGroup parent) {
Jorim Jaggid017f882014-01-14 17:08:48 -0800548 int visibleChildren = 0;
549 for (int i = 0; i < parent.getChildCount(); i++) {
550 if (parent.getChildAt(i).getVisibility() != View.GONE) {
551 visibleChildren++;
552 }
553 }
554 return visibleChildren;
555 }
556
Winson1f064272016-07-18 17:18:02 -0700557 public void layout(Launcher launcher, boolean notifyListeners) {
Winson Chungb3800242013-10-24 11:01:54 -0700558 FrameLayout.LayoutParams lp;
Winson Chungb3800242013-10-24 11:01:54 -0700559 boolean hasVerticalBarLayout = isVerticalBarLayout();
560
561 // Layout the search bar space
Sunny Goyal47328fd2016-05-25 18:56:41 -0700562 Point searchBarBounds = getSearchBarDimensForWidgetOpts();
563 View searchBar = launcher.getDropTargetBar();
Sunny Goyalf37a2142016-03-24 17:28:25 -0700564 lp = (FrameLayout.LayoutParams) searchBar.getLayoutParams();
Sunny Goyal47328fd2016-05-25 18:56:41 -0700565 lp.width = searchBarBounds.x;
566 lp.height = searchBarBounds.y;
Jon Miranda09660722017-06-14 14:20:14 -0700567 lp.topMargin = mInsets.top + edgeMarginPx / 2;
Winson Chungb3800242013-10-24 11:01:54 -0700568 searchBar.setLayoutParams(lp);
569
Winson Chungb3800242013-10-24 11:01:54 -0700570 // Layout the workspace
571 PagedView workspace = (PagedView) launcher.findViewById(R.id.workspace);
Winson1f064272016-07-18 17:18:02 -0700572 Rect workspacePadding = getWorkspacePadding(null);
573 workspace.setPadding(workspacePadding.left, workspacePadding.top, workspacePadding.right,
574 workspacePadding.bottom);
Sunny Goyal47328fd2016-05-25 18:56:41 -0700575 workspace.setPageSpacing(getWorkspacePageSpacing());
Winson Chungb3800242013-10-24 11:01:54 -0700576
577 // Layout the hotseat
Winson6231ede2016-07-20 17:21:55 -0700578 Hotseat hotseat = (Hotseat) launcher.findViewById(R.id.hotseat);
Winson Chungb3800242013-10-24 11:01:54 -0700579 lp = (FrameLayout.LayoutParams) hotseat.getLayoutParams();
Tony Wickhamd6b40372015-09-23 18:37:57 -0700580 // We want the edges of the hotseat to line up with the edges of the workspace, but the
581 // icons in the hotseat are a different size, and so don't line up perfectly. To account for
582 // this, we pad the left and right of the hotseat with half of the difference of a workspace
583 // cell vs a hotseat cell.
584 float workspaceCellWidth = (float) getCurrentWidth() / inv.numColumns;
585 float hotseatCellWidth = (float) getCurrentWidth() / inv.numHotseatIcons;
586 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
Winson Chungb3800242013-10-24 11:01:54 -0700587 if (hasVerticalBarLayout) {
Winson Chungf8c6f882015-06-03 11:27:26 -0700588 // Vertical hotseat -- The hotseat is fixed in the layout to be on the right of the
589 // screen regardless of RTL
590 lp.gravity = Gravity.RIGHT;
Winson1f064272016-07-18 17:18:02 -0700591 lp.width = hotseatBarHeightPx + mInsets.left + mInsets.right;
Winson Chungb3800242013-10-24 11:01:54 -0700592 lp.height = LayoutParams.MATCH_PARENT;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700593
594 int paddingRight = mInsets.left > 0
595 ? hotseatBarLeftNavBarRightPaddingPx
596 : hotseatBarRightNavBarRightPaddingPx;
597
598 hotseat.getLayout().setPadding(mInsets.left, mInsets.top, mInsets.right + paddingRight,
Winson6231ede2016-07-20 17:21:55 -0700599 workspacePadding.bottom);
Sunny Goyalc6205602015-05-21 20:46:33 -0700600 } else if (isTablet) {
Winson Chung59a488a2013-12-10 12:32:14 -0800601 // Pad the hotseat with the workspace padding calculated above
Winson Chungb3800242013-10-24 11:01:54 -0700602 lp.gravity = Gravity.BOTTOM;
603 lp.width = LayoutParams.MATCH_PARENT;
Winson1f064272016-07-18 17:18:02 -0700604 lp.height = hotseatBarHeightPx + mInsets.bottom;
Winson6231ede2016-07-20 17:21:55 -0700605 hotseat.getLayout().setPadding(hotseatAdjustment + workspacePadding.left,
606 hotseatBarTopPaddingPx, hotseatAdjustment + workspacePadding.right,
Jon Mirandac1b08c52016-11-15 14:37:56 -0800607 hotseatBarBottomPaddingPx + mInsets.bottom);
Winson Chungb3800242013-10-24 11:01:54 -0700608 } else {
609 // For phones, layout the hotseat without any bottom margin
610 // to ensure that we have space for the folders
611 lp.gravity = Gravity.BOTTOM;
612 lp.width = LayoutParams.MATCH_PARENT;
Winson1f064272016-07-18 17:18:02 -0700613 lp.height = hotseatBarHeightPx + mInsets.bottom;
Winson6231ede2016-07-20 17:21:55 -0700614 hotseat.getLayout().setPadding(hotseatAdjustment + workspacePadding.left,
615 hotseatBarTopPaddingPx, hotseatAdjustment + workspacePadding.right,
Jon Mirandac1b08c52016-11-15 14:37:56 -0800616 hotseatBarBottomPaddingPx + mInsets.bottom);
Winson Chungb3800242013-10-24 11:01:54 -0700617 }
618 hotseat.setLayoutParams(lp);
619
620 // Layout the page indicators
621 View pageIndicator = launcher.findViewById(R.id.page_indicator);
622 if (pageIndicator != null) {
Hyunyoung Song7d2fc812016-06-15 12:51:30 -0700623 lp = (FrameLayout.LayoutParams) pageIndicator.getLayoutParams();
Winson1f064272016-07-18 17:18:02 -0700624 if (isVerticalBarLayout()) {
625 if (mInsets.left > 0) {
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700626 lp.leftMargin = mInsets.left;
627 } else {
628 lp.leftMargin = pageIndicatorLandWorkspaceOffsetPx;
Winson1f064272016-07-18 17:18:02 -0700629 }
630 lp.bottomMargin = workspacePadding.bottom;
631 } else {
Winson Chungb3800242013-10-24 11:01:54 -0700632 // Put the page indicators above the hotseat
Winson Chungb3800242013-10-24 11:01:54 -0700633 lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700634 lp.height = pageIndicatorSizePx;
Winson1f064272016-07-18 17:18:02 -0700635 lp.bottomMargin = hotseatBarHeightPx + mInsets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -0700636 }
Hyunyoung Song7d2fc812016-06-15 12:51:30 -0700637 pageIndicator.setLayoutParams(lp);
Winson Chungb3800242013-10-24 11:01:54 -0700638 }
639
Winson Chungb3800242013-10-24 11:01:54 -0700640 // Layout the Overview Mode
Jorim Jaggid017f882014-01-14 17:08:48 -0800641 ViewGroup overviewMode = launcher.getOverviewPanel();
Winson Chungb3800242013-10-24 11:01:54 -0700642 if (overviewMode != null) {
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700643 int visibleChildCount = getVisibleChildCount(overviewMode);
644 int totalItemWidth = visibleChildCount * overviewModeBarItemWidthPx;
Jon Mirandadf3bc522016-11-01 16:55:56 -0700645 int maxWidth = totalItemWidth + (visibleChildCount - 1) * overviewModeBarSpacerWidthPx;
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700646
Jon Mirandadf3bc522016-11-01 16:55:56 -0700647 lp = (FrameLayout.LayoutParams) overviewMode.getLayoutParams();
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700648 lp.width = Math.min(availableWidthPx, maxWidth);
Jon Mirandadf3bc522016-11-01 16:55:56 -0700649 lp.height = getOverviewModeButtonBarHeight() + mInsets.bottom;
Winson Chungb3800242013-10-24 11:01:54 -0700650 overviewMode.setLayoutParams(lp);
Winson1f064272016-07-18 17:18:02 -0700651 }
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700652
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700653 // Layout the AllAppsRecyclerView
654 View view = launcher.findViewById(R.id.apps_list_view);
655 int paddingLeftRight = hasVerticalBarLayout ? 0 : edgeMarginPx;
656 view.setPadding(paddingLeftRight, view.getPaddingTop(), paddingLeftRight,
657 view.getPaddingBottom());
658
Winson1f064272016-07-18 17:18:02 -0700659 if (notifyListeners) {
660 for (int i = mListeners.size() - 1; i >= 0; i--) {
661 mListeners.get(i).onLauncherLayoutChanged();
Sunny Goyal8dfe2da2014-10-24 16:26:52 -0700662 }
Winson Chungb3800242013-10-24 11:01:54 -0700663 }
664 }
Winson Chung4f3bfad2015-07-13 11:14:30 -0700665
666 private int getCurrentWidth() {
667 return isLandscape
668 ? Math.max(widthPx, heightPx)
669 : Math.min(widthPx, heightPx);
670 }
671
672 private int getCurrentHeight() {
673 return isLandscape
674 ? Math.min(widthPx, heightPx)
675 : Math.max(widthPx, heightPx);
676 }
Sunny Goyal13178ac2016-04-04 16:35:22 -0700677
Sunny Goyalc13403c2016-11-18 23:44:48 -0800678 public int getCellHeight(@ContainerType int containerType) {
679 switch (containerType) {
680 case CellLayout.WORKSPACE:
681 return cellHeightPx;
682 case CellLayout.FOLDER:
683 return folderCellHeightPx;
684 case CellLayout.HOTSEAT:
685 return hotseatCellHeightPx;
686 default:
687 // ??
688 return 0;
689 }
690 }
Sunny Goyal13178ac2016-04-04 16:35:22 -0700691
Winson1f064272016-07-18 17:18:02 -0700692 /**
693 * @return the left/right paddings for all containers.
694 */
Jon Mirandac3e4e222016-11-02 16:56:52 -0700695 public final int[] getContainerPadding() {
Winson1f064272016-07-18 17:18:02 -0700696 // No paddings for portrait phone
697 if (isPhone && !isVerticalBarLayout()) {
698 return new int[] {0, 0};
Sunny Goyal13178ac2016-04-04 16:35:22 -0700699 }
Winson1f064272016-07-18 17:18:02 -0700700
Hyunyoung Song9d96fd52016-08-23 11:06:24 -0700701 // In landscape, we match the width of the workspace
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700702 Rect padding = getWorkspacePadding(null);
703 return new int[] { padding.left - mInsets.left, padding.right + mInsets.left};
Sunny Goyal13178ac2016-04-04 16:35:22 -0700704 }
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700705
Jon Miranda51f037d2016-11-07 08:37:20 -0800706 public boolean shouldIgnoreLongPressToOverview(float touchX) {
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700707 boolean inMultiWindowMode = this != inv.landscapeProfile && this != inv.portraitProfile;
Jon Miranda51f037d2016-11-07 08:37:20 -0800708 boolean touchedLhsEdge = mInsets.left == 0 && touchX < edgeMarginPx;
709 boolean touchedRhsEdge = mInsets.right == 0 && touchX > (widthPx - edgeMarginPx);
Jon Mirandacc42c5b2016-10-27 17:15:27 -0700710 return !inMultiWindowMode && (touchedLhsEdge || touchedRhsEdge);
711 }
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700712
713 private static Context getContext(Context c, int orientation) {
714 Configuration context = new Configuration(c.getResources().getConfiguration());
715 context.orientation = orientation;
716 return c.createConfigurationContext(context);
717
718 }
Winson Chungb3800242013-10-24 11:01:54 -0700719}