Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.launcher3; |
| 18 | |
| 19 | import android.appwidget.AppWidgetHostView; |
| 20 | import android.content.ComponentName; |
| 21 | import android.content.Context; |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 22 | import android.content.res.Configuration; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 23 | import android.content.res.Resources; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 24 | import android.graphics.Point; |
Jon Miranda | 7ae64ff | 2016-11-21 16:18:46 -0800 | [diff] [blame] | 25 | import android.graphics.PointF; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 26 | import android.graphics.Rect; |
| 27 | import android.util.DisplayMetrics; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 28 | |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 29 | import com.android.launcher3.CellLayout.ContainerType; |
Tony Wickham | 9a8d11f | 2017-01-11 09:53:12 -0800 | [diff] [blame] | 30 | import com.android.launcher3.badge.BadgeRenderer; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 31 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 32 | public class DeviceProfile { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 33 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 34 | public final InvariantDeviceProfile inv; |
Winson Chung | be87647 | 2014-05-14 14:15:20 -0700 | [diff] [blame] | 35 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 36 | // Device properties |
| 37 | public final boolean isTablet; |
| 38 | public final boolean isLargeTablet; |
| 39 | public final boolean isPhone; |
| 40 | public final boolean transposeLayoutWithOrientation; |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 41 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 42 | // Device properties in current orientation |
| 43 | public final boolean isLandscape; |
| 44 | public final int widthPx; |
| 45 | public final int heightPx; |
| 46 | public final int availableWidthPx; |
| 47 | public final int availableHeightPx; |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 48 | /** |
| 49 | * The maximum amount of left/right workspace padding as a percentage of the screen width. |
| 50 | * To be clear, this means that up to 7% of the screen width can be used as left padding, and |
| 51 | * 7% of the screen width can be used as right padding. |
| 52 | */ |
| 53 | private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 54 | |
Jon Miranda | 3f9bab2 | 2017-07-28 14:50:17 -0700 | [diff] [blame] | 55 | private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f; |
Jon Miranda | 30d0aa2 | 2017-07-25 15:55:29 -0700 | [diff] [blame] | 56 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 57 | // Workspace |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 58 | public final int desiredWorkspaceLeftRightMarginPx; |
Jon Miranda | 2803200 | 2017-07-13 16:18:56 -0700 | [diff] [blame] | 59 | public final int cellLayoutPaddingLeftRightPx; |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 60 | public final int cellLayoutBottomPaddingPx; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 61 | public final int edgeMarginPx; |
| 62 | public final Rect defaultWidgetPadding; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 63 | public final int defaultPageSpacingPx; |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 64 | private final int topWorkspacePadding; |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 65 | public float workspaceSpringLoadShrinkFactor; |
| 66 | public final int workspaceSpringLoadedBottomSpace; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 67 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 68 | // Page indicator |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 69 | public final int pageIndicatorSizePx; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 70 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 71 | // Workspace icons |
| 72 | public int iconSizePx; |
| 73 | public int iconTextSizePx; |
| 74 | public int iconDrawablePaddingPx; |
Winson Chung | 5f4e0fd | 2015-05-22 11:12:27 -0700 | [diff] [blame] | 75 | public int iconDrawablePaddingOriginalPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 76 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 77 | public int cellWidthPx; |
| 78 | public int cellHeightPx; |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 79 | public int workspaceCellPaddingXPx; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 80 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 81 | // Folder |
| 82 | public int folderBackgroundOffset; |
| 83 | public int folderIconSizePx; |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 84 | public int folderIconPreviewPadding; |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 85 | |
| 86 | // Folder cell |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 87 | public int folderCellWidthPx; |
| 88 | public int folderCellHeightPx; |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 89 | |
| 90 | // Folder child |
| 91 | public int folderChildIconSizePx; |
| 92 | public int folderChildTextSizePx; |
Sunny Goyal | baec6ff | 2016-09-14 11:26:21 -0700 | [diff] [blame] | 93 | public int folderChildDrawablePaddingPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 94 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 95 | // Hotseat |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 96 | public int hotseatCellHeightPx; |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 97 | // In portrait: size = height, in landscape: size = width |
| 98 | public int hotseatBarSizePx; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 99 | public final int hotseatBarTopPaddingPx; |
| 100 | public final int hotseatBarBottomPaddingPx; |
| 101 | public final int hotseatBarSidePaddingPx; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 102 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 103 | // All apps |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 104 | public int allAppsCellHeightPx; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 105 | public int allAppsIconSizePx; |
| 106 | public int allAppsIconDrawablePaddingPx; |
| 107 | public float allAppsIconTextSizePx; |
| 108 | |
Jon Miranda | 7ae64ff | 2016-11-21 16:18:46 -0800 | [diff] [blame] | 109 | // Widgets |
| 110 | public final PointF appWidgetScale = new PointF(1.0f, 1.0f); |
| 111 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 112 | // Drop Target |
| 113 | public int dropTargetBarSizePx; |
Adam Cohen | 4ae96ce | 2014-08-29 15:05:48 -0700 | [diff] [blame] | 114 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 115 | // Insets |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 116 | private final Rect mInsets = new Rect(); |
| 117 | public final Rect workspacePadding = new Rect(); |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 118 | |
Tony Wickham | 9a8d11f | 2017-01-11 09:53:12 -0800 | [diff] [blame] | 119 | // Icon badges |
| 120 | public BadgeRenderer mBadgeRenderer; |
| 121 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 122 | public DeviceProfile(Context context, InvariantDeviceProfile inv, |
| 123 | Point minSize, Point maxSize, |
| 124 | int width, int height, boolean isLandscape) { |
Sunny Goyal | fee35bb | 2015-05-11 11:38:19 -0700 | [diff] [blame] | 125 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 126 | this.inv = inv; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 127 | this.isLandscape = isLandscape; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 128 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 129 | Resources res = context.getResources(); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 130 | DisplayMetrics dm = res.getDisplayMetrics(); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 131 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 132 | // Constants from resources |
| 133 | isTablet = res.getBoolean(R.bool.is_tablet); |
| 134 | isLargeTablet = res.getBoolean(R.bool.is_large_tablet); |
| 135 | isPhone = !isTablet && !isLargeTablet; |
| 136 | |
| 137 | // Some more constants |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 138 | transposeLayoutWithOrientation = |
| 139 | res.getBoolean(R.bool.hotseat_transpose_layout_with_orientation); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 140 | |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 141 | context = getContext(context, isVerticalBarLayout() |
| 142 | ? Configuration.ORIENTATION_LANDSCAPE |
| 143 | : Configuration.ORIENTATION_PORTRAIT); |
| 144 | res = context.getResources(); |
| 145 | |
| 146 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 147 | ComponentName cn = new ComponentName(context.getPackageName(), |
| 148 | this.getClass().getName()); |
| 149 | defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null); |
| 150 | edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin); |
Jon Miranda | 2803200 | 2017-07-13 16:18:56 -0700 | [diff] [blame] | 151 | desiredWorkspaceLeftRightMarginPx = isVerticalBarLayout() ? 0 : edgeMarginPx; |
Jon Miranda | 30d0aa2 | 2017-07-25 15:55:29 -0700 | [diff] [blame] | 152 | cellLayoutPaddingLeftRightPx = |
| 153 | res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_padding); |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 154 | cellLayoutBottomPaddingPx = |
| 155 | res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_bottom_padding); |
Jon Miranda | 2ed276e | 2017-06-29 11:36:34 -0700 | [diff] [blame] | 156 | pageIndicatorSizePx = res.getDimensionPixelSize( |
| 157 | R.dimen.dynamic_grid_min_page_indicator_size); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 158 | defaultPageSpacingPx = |
| 159 | res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_page_spacing); |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 160 | topWorkspacePadding = |
| 161 | res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_top_padding); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 162 | iconDrawablePaddingOriginalPx = |
| 163 | res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding); |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 164 | dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size); |
| 165 | workspaceSpringLoadedBottomSpace = |
| 166 | res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space); |
Sunny Goyal | d519052 | 2017-04-24 03:06:54 -0700 | [diff] [blame] | 167 | |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 168 | workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x); |
Jon Miranda | 0966072 | 2017-06-14 14:20:14 -0700 | [diff] [blame] | 169 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 170 | hotseatBarTopPaddingPx = |
| 171 | res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding); |
Sunny Goyal | d519052 | 2017-04-24 03:06:54 -0700 | [diff] [blame] | 172 | hotseatBarBottomPaddingPx = |
| 173 | res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_padding); |
Sunny Goyal | 228153d | 2018-01-04 15:35:22 -0800 | [diff] [blame] | 174 | hotseatBarSidePaddingPx = |
| 175 | res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding); |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 176 | hotseatBarSizePx = isVerticalBarLayout() |
| 177 | ? Utilities.pxFromDp(inv.iconSize, dm) |
| 178 | : res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_size) |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 179 | + hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx; |
| 180 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 181 | // Determine sizes. |
| 182 | widthPx = width; |
| 183 | heightPx = height; |
| 184 | if (isLandscape) { |
| 185 | availableWidthPx = maxSize.x; |
| 186 | availableHeightPx = minSize.y; |
| 187 | } else { |
| 188 | availableWidthPx = minSize.x; |
| 189 | availableHeightPx = maxSize.y; |
| 190 | } |
Adam Cohen | 4ae96ce | 2014-08-29 15:05:48 -0700 | [diff] [blame] | 191 | |
Jon Miranda | 2ed276e | 2017-06-29 11:36:34 -0700 | [diff] [blame] | 192 | // Calculate all of the remaining variables. |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 193 | updateAvailableDimensions(dm, res); |
Jon Miranda | 2ed276e | 2017-06-29 11:36:34 -0700 | [diff] [blame] | 194 | |
| 195 | // Now that we have all of the variables calculated, we can tune certain sizes. |
Jon Miranda | 3f9bab2 | 2017-07-28 14:50:17 -0700 | [diff] [blame] | 196 | float aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx); |
Jon Miranda | 30d0aa2 | 2017-07-25 15:55:29 -0700 | [diff] [blame] | 197 | boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0; |
| 198 | if (!isVerticalBarLayout() && isPhone && isTallDevice) { |
Jon Miranda | 3f9bab2 | 2017-07-28 14:50:17 -0700 | [diff] [blame] | 199 | // We increase the hotseat size when there is extra space. |
Jon Miranda | 2ed276e | 2017-06-29 11:36:34 -0700 | [diff] [blame] | 200 | // ie. For a display with a large aspect ratio, we can keep the icons on the workspace |
Jon Miranda | 3f9bab2 | 2017-07-28 14:50:17 -0700 | [diff] [blame] | 201 | // in portrait mode closer together by adding more height to the hotseat. |
Jon Miranda | 30d0aa2 | 2017-07-25 15:55:29 -0700 | [diff] [blame] | 202 | // Note: This calculation was created after noticing a pattern in the design spec. |
Jon Miranda | 3f9bab2 | 2017-07-28 14:50:17 -0700 | [diff] [blame] | 203 | int extraSpace = getCellSize().y - iconSizePx - iconDrawablePaddingPx; |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 204 | hotseatBarSizePx += extraSpace - pageIndicatorSizePx; |
Jon Miranda | 30d0aa2 | 2017-07-25 15:55:29 -0700 | [diff] [blame] | 205 | |
Jon Miranda | 3f9bab2 | 2017-07-28 14:50:17 -0700 | [diff] [blame] | 206 | // Recalculate the available dimensions using the new hotseat size. |
Jon Miranda | 30d0aa2 | 2017-07-25 15:55:29 -0700 | [diff] [blame] | 207 | updateAvailableDimensions(dm, res); |
Jon Miranda | 2ed276e | 2017-06-29 11:36:34 -0700 | [diff] [blame] | 208 | } |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 209 | updateWorkspacePadding(); |
Tony Wickham | 1237df0 | 2017-02-24 08:59:36 -0800 | [diff] [blame] | 210 | |
| 211 | // This is done last, after iconSizePx is calculated above. |
Sunny Goyal | 179249d | 2017-12-19 16:49:24 -0800 | [diff] [blame] | 212 | mBadgeRenderer = new BadgeRenderer(iconSizePx); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Sunny Goyal | 1a52ef5 | 2018-01-11 10:15:03 -0800 | [diff] [blame] | 215 | public DeviceProfile copy(Context context) { |
| 216 | Point size = new Point(availableWidthPx, availableHeightPx); |
| 217 | return new DeviceProfile(context, inv, size, size, widthPx, heightPx, isLandscape); |
| 218 | } |
| 219 | |
Jon Miranda | cc42c5b | 2016-10-27 17:15:27 -0700 | [diff] [blame] | 220 | DeviceProfile getMultiWindowProfile(Context context, Point mwSize) { |
Jon Miranda | a11380d | 2017-08-24 11:30:03 -0700 | [diff] [blame] | 221 | // We take the minimum sizes of this profile and it's multi-window variant to ensure that |
| 222 | // the system decor is always excluded. |
| 223 | mwSize.set(Math.min(availableWidthPx, mwSize.x), Math.min(availableHeightPx, mwSize.y)); |
| 224 | |
Jon Miranda | cc42c5b | 2016-10-27 17:15:27 -0700 | [diff] [blame] | 225 | // In multi-window mode, we can have widthPx = availableWidthPx |
| 226 | // and heightPx = availableHeightPx because Launcher uses the InvariantDeviceProfiles' |
| 227 | // widthPx and heightPx values where it's needed. |
Jon Miranda | 93e1f04 | 2016-11-11 14:13:04 -0800 | [diff] [blame] | 228 | DeviceProfile profile = new DeviceProfile(context, inv, mwSize, mwSize, mwSize.x, mwSize.y, |
| 229 | isLandscape); |
| 230 | |
Jon Miranda | 0cd0457 | 2017-09-19 11:31:42 -0700 | [diff] [blame] | 231 | // If there isn't enough vertical cell padding with the labels displayed, hide the labels. |
| 232 | float workspaceCellPaddingY = profile.getCellSize().y - profile.iconSizePx |
| 233 | - iconDrawablePaddingPx - profile.iconTextSizePx; |
| 234 | if (workspaceCellPaddingY < profile.iconDrawablePaddingPx * 2) { |
| 235 | profile.adjustToHideWorkspaceLabels(); |
| 236 | } |
Jon Miranda | 93e1f04 | 2016-11-11 14:13:04 -0800 | [diff] [blame] | 237 | |
Jon Miranda | 7ae64ff | 2016-11-21 16:18:46 -0800 | [diff] [blame] | 238 | // We use these scales to measure and layout the widgets using their full invariant profile |
| 239 | // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans. |
| 240 | float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x; |
| 241 | float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y; |
| 242 | profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY); |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 243 | profile.updateWorkspacePadding(); |
Jon Miranda | 7ae64ff | 2016-11-21 16:18:46 -0800 | [diff] [blame] | 244 | |
Jon Miranda | 93e1f04 | 2016-11-11 14:13:04 -0800 | [diff] [blame] | 245 | return profile; |
Jon Miranda | cc42c5b | 2016-10-27 17:15:27 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 248 | /** |
Jon Miranda | 1091e53 | 2017-07-21 13:31:50 -0700 | [diff] [blame] | 249 | * Adjusts the profile so that the labels on the Workspace are hidden. |
| 250 | * It is important to call this method after the All Apps variables have been set. |
| 251 | */ |
| 252 | private void adjustToHideWorkspaceLabels() { |
| 253 | iconTextSizePx = 0; |
| 254 | iconDrawablePaddingPx = 0; |
| 255 | cellHeightPx = iconSizePx; |
| 256 | |
| 257 | // In normal cases, All Apps cell height should equal the Workspace cell height. |
| 258 | // Since we are removing labels from the Workspace, we need to manually compute the |
| 259 | // All Apps cell height. |
Jon Miranda | 3f9bab2 | 2017-07-28 14:50:17 -0700 | [diff] [blame] | 260 | int topBottomPadding = allAppsIconDrawablePaddingPx * (isVerticalBarLayout() ? 2 : 1); |
Jon Miranda | 1091e53 | 2017-07-21 13:31:50 -0700 | [diff] [blame] | 261 | allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx |
| 262 | + Utilities.calculateTextHeight(allAppsIconTextSizePx) |
Jon Miranda | 3f9bab2 | 2017-07-28 14:50:17 -0700 | [diff] [blame] | 263 | + topBottomPadding * 2; |
Jon Miranda | 1091e53 | 2017-07-21 13:31:50 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 266 | private void updateAvailableDimensions(DisplayMetrics dm, Resources res) { |
Jon Miranda | 0966072 | 2017-06-14 14:20:14 -0700 | [diff] [blame] | 267 | updateIconSize(1f, res, dm); |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 268 | |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 269 | // Check to see if the icons fit within the available height. If not, then scale down. |
| 270 | float usedHeight = (cellHeightPx * inv.numRows); |
Sunny Goyal | 6c2975e | 2016-07-06 09:47:56 -0700 | [diff] [blame] | 271 | int maxHeight = (availableHeightPx - getTotalWorkspacePadding().y); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 272 | if (usedHeight > maxHeight) { |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 273 | float scale = maxHeight / usedHeight; |
Jon Miranda | 0966072 | 2017-06-14 14:20:14 -0700 | [diff] [blame] | 274 | updateIconSize(scale, res, dm); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 275 | } |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 276 | updateAvailableFolderCellDimensions(dm, res); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Jon Miranda | 0966072 | 2017-06-14 14:20:14 -0700 | [diff] [blame] | 279 | private void updateIconSize(float scale, Resources res, DisplayMetrics dm) { |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 280 | // Workspace |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 281 | final boolean isVerticalLayout = isVerticalBarLayout(); |
| 282 | float invIconSizePx = isVerticalLayout ? inv.landscapeIconSize : inv.iconSize; |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 283 | iconSizePx = (int) (Utilities.pxFromDp(invIconSizePx, dm) * scale); |
Sunny Goyal | a50a419 | 2015-12-11 09:50:49 -0800 | [diff] [blame] | 284 | iconTextSizePx = (int) (Utilities.pxFromSp(inv.iconTextSize, dm) * scale); |
Jon Miranda | 0966072 | 2017-06-14 14:20:14 -0700 | [diff] [blame] | 285 | iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * scale); |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 286 | |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 287 | cellHeightPx = iconSizePx + iconDrawablePaddingPx |
| 288 | + Utilities.calculateTextHeight(iconTextSizePx); |
Jon Miranda | 846455e | 2017-10-02 14:58:52 -0700 | [diff] [blame] | 289 | int cellYPadding = (getCellSize().y - cellHeightPx) / 2; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 290 | if (iconDrawablePaddingPx > cellYPadding && !isVerticalLayout |
Jon Miranda | 846455e | 2017-10-02 14:58:52 -0700 | [diff] [blame] | 291 | && !inMultiWindowMode()) { |
| 292 | // Ensures that the label is closer to its corresponding icon. This is not an issue |
| 293 | // with vertical bar layout or multi-window mode since the issue is handled separately |
| 294 | // with their calls to {@link #adjustToHideWorkspaceLabels}. |
| 295 | cellHeightPx -= (iconDrawablePaddingPx - cellYPadding); |
| 296 | iconDrawablePaddingPx = cellYPadding; |
| 297 | } |
| 298 | cellWidthPx = iconSizePx + iconDrawablePaddingPx; |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 299 | |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 300 | // All apps |
| 301 | allAppsIconTextSizePx = iconTextSizePx; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 302 | allAppsIconSizePx = iconSizePx; |
| 303 | allAppsIconDrawablePaddingPx = iconDrawablePaddingPx; |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 304 | allAppsCellHeightPx = getCellSize().y; |
| 305 | |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 306 | if (isVerticalLayout) { |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 307 | // Always hide the Workspace text with vertical bar layout. |
Jon Miranda | 1091e53 | 2017-07-21 13:31:50 -0700 | [diff] [blame] | 308 | adjustToHideWorkspaceLabels(); |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 309 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 310 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 311 | // Hotseat |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 312 | if (isVerticalLayout) { |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 313 | hotseatBarSizePx = iconSizePx; |
| 314 | } |
Jon Miranda | 5044c35 | 2017-08-09 11:37:59 -0700 | [diff] [blame] | 315 | hotseatCellHeightPx = iconSizePx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 316 | |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 317 | if (!isVerticalLayout) { |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 318 | int expectedWorkspaceHeight = availableHeightPx - hotseatBarSizePx |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 319 | - pageIndicatorSizePx - topWorkspacePadding; |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 320 | float minRequiredHeight = dropTargetBarSizePx + workspaceSpringLoadedBottomSpace; |
| 321 | workspaceSpringLoadShrinkFactor = Math.min( |
| 322 | res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f, |
| 323 | 1 - (minRequiredHeight / expectedWorkspaceHeight)); |
| 324 | } else { |
| 325 | workspaceSpringLoadShrinkFactor = |
| 326 | res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f; |
| 327 | } |
| 328 | |
Sunny Goyal | baec6ff | 2016-09-14 11:26:21 -0700 | [diff] [blame] | 329 | // Folder icon |
Jon Miranda | 0966072 | 2017-06-14 14:20:14 -0700 | [diff] [blame] | 330 | folderBackgroundOffset = -iconDrawablePaddingPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 331 | folderIconSizePx = iconSizePx + 2 * -folderBackgroundOffset; |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 332 | folderIconPreviewPadding = res.getDimensionPixelSize(R.dimen.folder_preview_padding); |
Winson Chung | 0f78572 | 2015-04-08 10:27:49 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 335 | private void updateAvailableFolderCellDimensions(DisplayMetrics dm, Resources res) { |
| 336 | int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_padding_top) |
| 337 | + res.getDimensionPixelSize(R.dimen.folder_label_padding_bottom) |
| 338 | + Utilities.calculateTextHeight(res.getDimension(R.dimen.folder_label_text_size)); |
| 339 | |
Jon Miranda | c1b2399 | 2016-12-13 08:57:36 -0800 | [diff] [blame] | 340 | updateFolderCellSize(1f, dm, res); |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 341 | |
Jon Miranda | c1b2399 | 2016-12-13 08:57:36 -0800 | [diff] [blame] | 342 | // Don't let the folder get too close to the edges of the screen. |
Jon Miranda | 72b5fd1 | 2017-06-25 18:06:23 -0700 | [diff] [blame] | 343 | int folderMargin = edgeMarginPx; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 344 | Point totalWorkspacePadding = getTotalWorkspacePadding(); |
Jon Miranda | c1b2399 | 2016-12-13 08:57:36 -0800 | [diff] [blame] | 345 | |
| 346 | // Check if the icons fit within the available height. |
| 347 | float usedHeight = folderCellHeightPx * inv.numFolderRows + folderBottomPanelSize; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 348 | int maxHeight = availableHeightPx - totalWorkspacePadding.y - folderMargin; |
Jon Miranda | c1b2399 | 2016-12-13 08:57:36 -0800 | [diff] [blame] | 349 | float scaleY = maxHeight / usedHeight; |
| 350 | |
| 351 | // Check if the icons fit within the available width. |
| 352 | float usedWidth = folderCellWidthPx * inv.numFolderColumns; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 353 | int maxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin; |
Jon Miranda | c1b2399 | 2016-12-13 08:57:36 -0800 | [diff] [blame] | 354 | float scaleX = maxWidth / usedWidth; |
| 355 | |
| 356 | float scale = Math.min(scaleX, scaleY); |
| 357 | if (scale < 1f) { |
| 358 | updateFolderCellSize(scale, dm, res); |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | |
Jon Miranda | c1b2399 | 2016-12-13 08:57:36 -0800 | [diff] [blame] | 362 | private void updateFolderCellSize(float scale, DisplayMetrics dm, Resources res) { |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 363 | folderChildIconSizePx = (int) (Utilities.pxFromDp(inv.iconSize, dm) * scale); |
| 364 | folderChildTextSizePx = |
| 365 | (int) (res.getDimensionPixelSize(R.dimen.folder_child_text_size) * scale); |
| 366 | |
| 367 | int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx); |
| 368 | int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding) * scale); |
| 369 | int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding) * scale); |
| 370 | |
Jon Miranda | c1b2399 | 2016-12-13 08:57:36 -0800 | [diff] [blame] | 371 | folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX; |
Jonathan Miranda | 9ad8746 | 2017-07-26 17:41:02 +0000 | [diff] [blame] | 372 | folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight; |
| 373 | folderChildDrawablePaddingPx = Math.max(0, |
| 374 | (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3); |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 377 | public void updateInsets(Rect insets) { |
| 378 | mInsets.set(insets); |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 379 | updateWorkspacePadding(); |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Sunny Goyal | 1a52ef5 | 2018-01-11 10:15:03 -0800 | [diff] [blame] | 382 | public Rect getInsets() { |
| 383 | return mInsets; |
| 384 | } |
| 385 | |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 386 | public Point getCellSize() { |
| 387 | Point result = new Point(); |
| 388 | // Since we are only concerned with the overall padding, layout direction does |
| 389 | // not matter. |
Sunny Goyal | 6c2975e | 2016-07-06 09:47:56 -0700 | [diff] [blame] | 390 | Point padding = getTotalWorkspacePadding(); |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 391 | result.x = calculateCellWidth(availableWidthPx - padding.x |
| 392 | - cellLayoutPaddingLeftRightPx * 2, inv.numColumns); |
| 393 | result.y = calculateCellHeight(availableHeightPx - padding.y |
| 394 | - cellLayoutBottomPaddingPx, inv.numRows); |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 395 | return result; |
| 396 | } |
| 397 | |
Sunny Goyal | 6c2975e | 2016-07-06 09:47:56 -0700 | [diff] [blame] | 398 | public Point getTotalWorkspacePadding() { |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 399 | updateWorkspacePadding(); |
| 400 | return new Point(workspacePadding.left + workspacePadding.right, |
| 401 | workspacePadding.top + workspacePadding.bottom); |
Sunny Goyal | 6c2975e | 2016-07-06 09:47:56 -0700 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | /** |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 405 | * Updates {@link #workspacePadding} as a result of any internal value change to reflect the |
| 406 | * new workspace padding |
Sunny Goyal | 6c2975e | 2016-07-06 09:47:56 -0700 | [diff] [blame] | 407 | */ |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 408 | private void updateWorkspacePadding() { |
| 409 | Rect padding = workspacePadding; |
Tony Wickham | 3a3517f | 2015-10-06 11:27:04 -0700 | [diff] [blame] | 410 | if (isVerticalBarLayout()) { |
Sunny Goyal | 228153d | 2018-01-04 15:35:22 -0800 | [diff] [blame] | 411 | padding.top = 0; |
| 412 | padding.bottom = edgeMarginPx; |
| 413 | padding.left = hotseatBarSidePaddingPx; |
| 414 | padding.right = hotseatBarSidePaddingPx; |
Sunny Goyal | 7e2e67f | 2018-01-26 13:40:08 -0800 | [diff] [blame^] | 415 | if (isSeascape()) { |
Sunny Goyal | 228153d | 2018-01-04 15:35:22 -0800 | [diff] [blame] | 416 | padding.left += hotseatBarSizePx; |
| 417 | padding.right += pageIndicatorSizePx; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 418 | } else { |
Sunny Goyal | 228153d | 2018-01-04 15:35:22 -0800 | [diff] [blame] | 419 | padding.left += pageIndicatorSizePx; |
| 420 | padding.right += hotseatBarSizePx; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 421 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 422 | } else { |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 423 | int paddingBottom = hotseatBarSizePx + pageIndicatorSizePx; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 424 | if (isTablet) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 425 | // Pad the left and right of the workspace to ensure consistent spacing |
| 426 | // between all icons |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 427 | // The amount of screen space available for left/right padding. |
Sunny Goyal | 228153d | 2018-01-04 15:35:22 -0800 | [diff] [blame] | 428 | int availablePaddingX = Math.max(0, widthPx - ((inv.numColumns * cellWidthPx) + |
Sunny Goyal | f5440cb | 2016-12-14 15:13:00 -0800 | [diff] [blame] | 429 | ((inv.numColumns - 1) * cellWidthPx))); |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 430 | availablePaddingX = (int) Math.min(availablePaddingX, |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 431 | widthPx * MAX_HORIZONTAL_PADDING_PERCENT); |
Sunny Goyal | 228153d | 2018-01-04 15:35:22 -0800 | [diff] [blame] | 432 | int availablePaddingY = Math.max(0, heightPx - topWorkspacePadding - paddingBottom |
Jon Miranda | c1b08c5 | 2016-11-15 14:37:56 -0800 | [diff] [blame] | 433 | - (2 * inv.numRows * cellHeightPx) - hotseatBarTopPaddingPx |
| 434 | - hotseatBarBottomPaddingPx); |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 435 | padding.set(availablePaddingX / 2, topWorkspacePadding + availablePaddingY / 2, |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 436 | availablePaddingX / 2, paddingBottom + availablePaddingY / 2); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 437 | } else { |
| 438 | // Pad the top and bottom of the workspace with search/hotseat bar sizes |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 439 | padding.set(desiredWorkspaceLeftRightMarginPx, |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 440 | topWorkspacePadding, |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 441 | desiredWorkspaceLeftRightMarginPx, |
Winson | fadbe8f | 2016-07-22 16:35:37 -0700 | [diff] [blame] | 442 | paddingBottom); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 443 | } |
| 444 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Winson | fadbe8f | 2016-07-22 16:35:37 -0700 | [diff] [blame] | 447 | /** |
| 448 | * @return the bounds for which the open folders should be contained within |
| 449 | */ |
| 450 | public Rect getAbsoluteOpenFolderBounds() { |
| 451 | if (isVerticalBarLayout()) { |
| 452 | // Folders should only appear right of the drop target bar and left of the hotseat |
| 453 | return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx, |
| 454 | mInsets.top, |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 455 | mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx, |
Winson | fadbe8f | 2016-07-22 16:35:37 -0700 | [diff] [blame] | 456 | mInsets.top + availableHeightPx); |
| 457 | } else { |
| 458 | // Folders should only appear below the drop target bar and above the hotseat |
Tony Wickham | b4b7e20 | 2018-01-12 17:39:24 -0800 | [diff] [blame] | 459 | return new Rect(mInsets.left + edgeMarginPx, |
Winson | fadbe8f | 2016-07-22 16:35:37 -0700 | [diff] [blame] | 460 | mInsets.top + dropTargetBarSizePx + edgeMarginPx, |
Tony Wickham | b4b7e20 | 2018-01-12 17:39:24 -0800 | [diff] [blame] | 461 | mInsets.left + availableWidthPx - edgeMarginPx, |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 462 | mInsets.top + availableHeightPx - hotseatBarSizePx |
Jon Miranda | 2ed276e | 2017-06-29 11:36:34 -0700 | [diff] [blame] | 463 | - pageIndicatorSizePx - edgeMarginPx); |
Winson | fadbe8f | 2016-07-22 16:35:37 -0700 | [diff] [blame] | 464 | } |
| 465 | } |
| 466 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 467 | public static int calculateCellWidth(int width, int countX) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 468 | return width / countX; |
| 469 | } |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 470 | public static int calculateCellHeight(int height, int countY) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 471 | return height / countY; |
| 472 | } |
| 473 | |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 474 | /** |
Tony Wickham | 55616cd | 2015-09-23 14:55:17 -0700 | [diff] [blame] | 475 | * When {@code true}, the device is in landscape mode and the hotseat is on the right column. |
| 476 | * When {@code false}, either device is in portrait mode or the device is in landscape mode and |
| 477 | * the hotseat is on the bottom row. |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 478 | */ |
Tony Wickham | ab946a1 | 2015-09-16 15:38:16 -0700 | [diff] [blame] | 479 | public boolean isVerticalBarLayout() { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 480 | return isLandscape && transposeLayoutWithOrientation; |
| 481 | } |
| 482 | |
Sunny Goyal | 7e2e67f | 2018-01-26 13:40:08 -0800 | [diff] [blame^] | 483 | public boolean isSeascape() { |
| 484 | // TODO: This might not hold true for multi window mode, use configuration insead. |
| 485 | return isVerticalBarLayout() && mInsets.left > mInsets.right; |
| 486 | } |
| 487 | |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 488 | public boolean shouldFadeAdjacentWorkspaceScreens() { |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 489 | return isVerticalBarLayout() || isLargeTablet; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 492 | public int getCellHeight(@ContainerType int containerType) { |
| 493 | switch (containerType) { |
| 494 | case CellLayout.WORKSPACE: |
| 495 | return cellHeightPx; |
| 496 | case CellLayout.FOLDER: |
| 497 | return folderCellHeightPx; |
| 498 | case CellLayout.HOTSEAT: |
| 499 | return hotseatCellHeightPx; |
| 500 | default: |
| 501 | // ?? |
| 502 | return 0; |
| 503 | } |
| 504 | } |
Sunny Goyal | 13178ac | 2016-04-04 16:35:22 -0700 | [diff] [blame] | 505 | |
Jon Miranda | 846455e | 2017-10-02 14:58:52 -0700 | [diff] [blame] | 506 | public boolean inMultiWindowMode() { |
| 507 | return this != inv.landscapeProfile && this != inv.portraitProfile; |
| 508 | } |
| 509 | |
Jon Miranda | 51f037d | 2016-11-07 08:37:20 -0800 | [diff] [blame] | 510 | public boolean shouldIgnoreLongPressToOverview(float touchX) { |
Jon Miranda | 51f037d | 2016-11-07 08:37:20 -0800 | [diff] [blame] | 511 | boolean touchedLhsEdge = mInsets.left == 0 && touchX < edgeMarginPx; |
| 512 | boolean touchedRhsEdge = mInsets.right == 0 && touchX > (widthPx - edgeMarginPx); |
Jon Miranda | 846455e | 2017-10-02 14:58:52 -0700 | [diff] [blame] | 513 | return !inMultiWindowMode() && (touchedLhsEdge || touchedRhsEdge); |
Jon Miranda | cc42c5b | 2016-10-27 17:15:27 -0700 | [diff] [blame] | 514 | } |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 515 | |
| 516 | private static Context getContext(Context c, int orientation) { |
| 517 | Configuration context = new Configuration(c.getResources().getConfiguration()); |
| 518 | context.orientation = orientation; |
| 519 | return c.createConfigurationContext(context); |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 520 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 521 | } |