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