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 | import android.view.Gravity; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 29 | import android.view.View; |
| 30 | import android.view.ViewGroup.LayoutParams; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 31 | import android.widget.FrameLayout; |
| 32 | |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 33 | import com.android.launcher3.CellLayout.ContainerType; |
Mario Bertschler | ac9408a | 2017-10-18 10:31:36 -0700 | [diff] [blame] | 34 | import com.android.launcher3.allapps.AllAppsContainerView; |
Tony Wickham | 9a8d11f | 2017-01-11 09:53:12 -0800 | [diff] [blame] | 35 | import com.android.launcher3.badge.BadgeRenderer; |
Sunny Goyal | b532dfe | 2017-12-13 17:16:54 -0800 | [diff] [blame] | 36 | import com.android.launcher3.views.AllAppsScrim; |
Tony Wickham | e0c3323 | 2016-02-08 11:37:04 -0800 | [diff] [blame] | 37 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 38 | import java.util.ArrayList; |
| 39 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 40 | public class DeviceProfile { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 41 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 42 | public interface LauncherLayoutChangeListener { |
| 43 | void onLauncherLayoutChanged(); |
| 44 | } |
| 45 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 46 | public final InvariantDeviceProfile inv; |
Winson Chung | be87647 | 2014-05-14 14:15:20 -0700 | [diff] [blame] | 47 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 48 | // Device properties |
| 49 | public final boolean isTablet; |
| 50 | public final boolean isLargeTablet; |
| 51 | public final boolean isPhone; |
| 52 | public final boolean transposeLayoutWithOrientation; |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 53 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 54 | // Device properties in current orientation |
| 55 | public final boolean isLandscape; |
| 56 | public final int widthPx; |
| 57 | public final int heightPx; |
| 58 | public final int availableWidthPx; |
| 59 | public final int availableHeightPx; |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 60 | /** |
| 61 | * The maximum amount of left/right workspace padding as a percentage of the screen width. |
| 62 | * To be clear, this means that up to 7% of the screen width can be used as left padding, and |
| 63 | * 7% of the screen width can be used as right padding. |
| 64 | */ |
| 65 | private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 66 | |
Jon Miranda | 3f9bab2 | 2017-07-28 14:50:17 -0700 | [diff] [blame] | 67 | private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f; |
Jon Miranda | 30d0aa2 | 2017-07-25 15:55:29 -0700 | [diff] [blame] | 68 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 69 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 70 | // Workspace |
Jon Miranda | 2803200 | 2017-07-13 16:18:56 -0700 | [diff] [blame] | 71 | private final int desiredWorkspaceLeftRightMarginPx; |
| 72 | public final int cellLayoutPaddingLeftRightPx; |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 73 | public final int cellLayoutBottomPaddingPx; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 74 | public final int edgeMarginPx; |
| 75 | public final Rect defaultWidgetPadding; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 76 | private final int defaultPageSpacingPx; |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 77 | private final int topWorkspacePadding; |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 78 | public float workspaceSpringLoadShrinkFactor; |
| 79 | public final int workspaceSpringLoadedBottomSpace; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 80 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 81 | // Page indicator |
Jon Miranda | 2ed276e | 2017-06-29 11:36:34 -0700 | [diff] [blame] | 82 | private int pageIndicatorSizePx; |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 83 | private final int pageIndicatorLandLeftNavBarGutterPx; |
| 84 | private final int pageIndicatorLandRightNavBarGutterPx; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 85 | private final int pageIndicatorLandWorkspaceOffsetPx; |
| 86 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 87 | // Workspace icons |
| 88 | public int iconSizePx; |
| 89 | public int iconTextSizePx; |
| 90 | public int iconDrawablePaddingPx; |
Winson Chung | 5f4e0fd | 2015-05-22 11:12:27 -0700 | [diff] [blame] | 91 | public int iconDrawablePaddingOriginalPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 92 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 93 | public int cellWidthPx; |
| 94 | public int cellHeightPx; |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 95 | public int workspaceCellPaddingXPx; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 96 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 97 | // Folder |
| 98 | public int folderBackgroundOffset; |
| 99 | public int folderIconSizePx; |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 100 | public int folderIconPreviewPadding; |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 101 | |
| 102 | // Folder cell |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 103 | public int folderCellWidthPx; |
| 104 | public int folderCellHeightPx; |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 105 | |
| 106 | // Folder child |
| 107 | public int folderChildIconSizePx; |
| 108 | public int folderChildTextSizePx; |
Sunny Goyal | baec6ff | 2016-09-14 11:26:21 -0700 | [diff] [blame] | 109 | public int folderChildDrawablePaddingPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 110 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 111 | // Hotseat |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 112 | public int hotseatCellHeightPx; |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 113 | // In portrait: size = height, in landscape: size = width |
| 114 | public int hotseatBarSizePx; |
Sunny Goyal | 0dc1db4 | 2017-05-17 11:34:33 -0700 | [diff] [blame] | 115 | public int hotseatBarTopPaddingPx; |
| 116 | public int hotseatBarBottomPaddingPx; |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 117 | |
| 118 | public int hotseatBarLeftNavBarLeftPaddingPx; |
| 119 | public int hotseatBarLeftNavBarRightPaddingPx; |
| 120 | |
| 121 | public int hotseatBarRightNavBarLeftPaddingPx; |
| 122 | public int hotseatBarRightNavBarRightPaddingPx; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 123 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 124 | // All apps |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 125 | public int allAppsCellHeightPx; |
Winson Chung | 5f4e0fd | 2015-05-22 11:12:27 -0700 | [diff] [blame] | 126 | public int allAppsNumCols; |
| 127 | public int allAppsNumPredictiveCols; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 128 | public int allAppsButtonVisualSize; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 129 | public int allAppsIconSizePx; |
| 130 | public int allAppsIconDrawablePaddingPx; |
| 131 | public float allAppsIconTextSizePx; |
| 132 | |
Jon Miranda | 7ae64ff | 2016-11-21 16:18:46 -0800 | [diff] [blame] | 133 | // Widgets |
| 134 | public final PointF appWidgetScale = new PointF(1.0f, 1.0f); |
| 135 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 136 | // Drop Target |
| 137 | public int dropTargetBarSizePx; |
Adam Cohen | 4ae96ce | 2014-08-29 15:05:48 -0700 | [diff] [blame] | 138 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 139 | // Insets |
| 140 | private Rect mInsets = new Rect(); |
| 141 | |
| 142 | // Listeners |
| 143 | private ArrayList<LauncherLayoutChangeListener> mListeners = new ArrayList<>(); |
| 144 | |
Tony Wickham | 9a8d11f | 2017-01-11 09:53:12 -0800 | [diff] [blame] | 145 | // Icon badges |
| 146 | public BadgeRenderer mBadgeRenderer; |
| 147 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 148 | public DeviceProfile(Context context, InvariantDeviceProfile inv, |
| 149 | Point minSize, Point maxSize, |
| 150 | int width, int height, boolean isLandscape) { |
Sunny Goyal | fee35bb | 2015-05-11 11:38:19 -0700 | [diff] [blame] | 151 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 152 | this.inv = inv; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 153 | this.isLandscape = isLandscape; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 154 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 155 | Resources res = context.getResources(); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 156 | DisplayMetrics dm = res.getDisplayMetrics(); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 157 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 158 | // Constants from resources |
| 159 | isTablet = res.getBoolean(R.bool.is_tablet); |
| 160 | isLargeTablet = res.getBoolean(R.bool.is_large_tablet); |
| 161 | isPhone = !isTablet && !isLargeTablet; |
| 162 | |
| 163 | // Some more constants |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 164 | transposeLayoutWithOrientation = |
| 165 | res.getBoolean(R.bool.hotseat_transpose_layout_with_orientation); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 166 | |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 167 | context = getContext(context, isVerticalBarLayout() |
| 168 | ? Configuration.ORIENTATION_LANDSCAPE |
| 169 | : Configuration.ORIENTATION_PORTRAIT); |
| 170 | res = context.getResources(); |
| 171 | |
| 172 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 173 | ComponentName cn = new ComponentName(context.getPackageName(), |
| 174 | this.getClass().getName()); |
| 175 | defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null); |
| 176 | edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin); |
Jon Miranda | 2803200 | 2017-07-13 16:18:56 -0700 | [diff] [blame] | 177 | desiredWorkspaceLeftRightMarginPx = isVerticalBarLayout() ? 0 : edgeMarginPx; |
Jon Miranda | 30d0aa2 | 2017-07-25 15:55:29 -0700 | [diff] [blame] | 178 | cellLayoutPaddingLeftRightPx = |
| 179 | res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_padding); |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 180 | cellLayoutBottomPaddingPx = |
| 181 | res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_bottom_padding); |
Jon Miranda | 2ed276e | 2017-06-29 11:36:34 -0700 | [diff] [blame] | 182 | pageIndicatorSizePx = res.getDimensionPixelSize( |
| 183 | R.dimen.dynamic_grid_min_page_indicator_size); |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 184 | pageIndicatorLandLeftNavBarGutterPx = res.getDimensionPixelSize( |
| 185 | R.dimen.dynamic_grid_page_indicator_land_left_nav_bar_gutter_width); |
| 186 | pageIndicatorLandRightNavBarGutterPx = res.getDimensionPixelSize( |
| 187 | R.dimen.dynamic_grid_page_indicator_land_right_nav_bar_gutter_width); |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 188 | pageIndicatorLandWorkspaceOffsetPx = |
| 189 | res.getDimensionPixelSize(R.dimen.all_apps_caret_workspace_offset); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 190 | defaultPageSpacingPx = |
| 191 | res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_page_spacing); |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 192 | topWorkspacePadding = |
| 193 | res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_top_padding); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 194 | iconDrawablePaddingOriginalPx = |
| 195 | res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding); |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 196 | dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size); |
| 197 | workspaceSpringLoadedBottomSpace = |
| 198 | res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space); |
Sunny Goyal | d519052 | 2017-04-24 03:06:54 -0700 | [diff] [blame] | 199 | |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 200 | workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x); |
Jon Miranda | 0966072 | 2017-06-14 14:20:14 -0700 | [diff] [blame] | 201 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 202 | hotseatBarTopPaddingPx = |
| 203 | res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding); |
Sunny Goyal | d519052 | 2017-04-24 03:06:54 -0700 | [diff] [blame] | 204 | hotseatBarBottomPaddingPx = |
| 205 | res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_padding); |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 206 | hotseatBarLeftNavBarRightPaddingPx = res.getDimensionPixelSize( |
| 207 | R.dimen.dynamic_grid_hotseat_land_left_nav_bar_right_padding); |
| 208 | hotseatBarRightNavBarRightPaddingPx = res.getDimensionPixelSize( |
| 209 | R.dimen.dynamic_grid_hotseat_land_right_nav_bar_right_padding); |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 210 | hotseatBarLeftNavBarLeftPaddingPx = res.getDimensionPixelSize( |
| 211 | R.dimen.dynamic_grid_hotseat_land_left_nav_bar_left_padding); |
| 212 | hotseatBarRightNavBarLeftPaddingPx = res.getDimensionPixelSize( |
| 213 | R.dimen.dynamic_grid_hotseat_land_right_nav_bar_left_padding); |
| 214 | hotseatBarSizePx = isVerticalBarLayout() |
| 215 | ? Utilities.pxFromDp(inv.iconSize, dm) |
| 216 | : res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_size) |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 217 | + hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx; |
| 218 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 219 | // Determine sizes. |
| 220 | widthPx = width; |
| 221 | heightPx = height; |
| 222 | if (isLandscape) { |
| 223 | availableWidthPx = maxSize.x; |
| 224 | availableHeightPx = minSize.y; |
| 225 | } else { |
| 226 | availableWidthPx = minSize.x; |
| 227 | availableHeightPx = maxSize.y; |
| 228 | } |
Adam Cohen | 4ae96ce | 2014-08-29 15:05:48 -0700 | [diff] [blame] | 229 | |
Jon Miranda | 2ed276e | 2017-06-29 11:36:34 -0700 | [diff] [blame] | 230 | // Calculate all of the remaining variables. |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 231 | updateAvailableDimensions(dm, res); |
Jon Miranda | 2ed276e | 2017-06-29 11:36:34 -0700 | [diff] [blame] | 232 | |
| 233 | // 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] | 234 | float aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx); |
Jon Miranda | 30d0aa2 | 2017-07-25 15:55:29 -0700 | [diff] [blame] | 235 | boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0; |
| 236 | if (!isVerticalBarLayout() && isPhone && isTallDevice) { |
Jon Miranda | 3f9bab2 | 2017-07-28 14:50:17 -0700 | [diff] [blame] | 237 | // We increase the hotseat size when there is extra space. |
Jon Miranda | 2ed276e | 2017-06-29 11:36:34 -0700 | [diff] [blame] | 238 | // 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] | 239 | // in portrait mode closer together by adding more height to the hotseat. |
Jon Miranda | 30d0aa2 | 2017-07-25 15:55:29 -0700 | [diff] [blame] | 240 | // 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] | 241 | int extraSpace = getCellSize().y - iconSizePx - iconDrawablePaddingPx; |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 242 | hotseatBarSizePx += extraSpace - pageIndicatorSizePx; |
Jon Miranda | 30d0aa2 | 2017-07-25 15:55:29 -0700 | [diff] [blame] | 243 | |
Jon Miranda | 3f9bab2 | 2017-07-28 14:50:17 -0700 | [diff] [blame] | 244 | // Recalculate the available dimensions using the new hotseat size. |
Jon Miranda | 30d0aa2 | 2017-07-25 15:55:29 -0700 | [diff] [blame] | 245 | updateAvailableDimensions(dm, res); |
Jon Miranda | 2ed276e | 2017-06-29 11:36:34 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 248 | computeAllAppsButtonSize(context); |
Tony Wickham | 1237df0 | 2017-02-24 08:59:36 -0800 | [diff] [blame] | 249 | |
| 250 | // This is done last, after iconSizePx is calculated above. |
| 251 | mBadgeRenderer = new BadgeRenderer(context, iconSizePx); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Jon Miranda | cc42c5b | 2016-10-27 17:15:27 -0700 | [diff] [blame] | 254 | DeviceProfile getMultiWindowProfile(Context context, Point mwSize) { |
Jon Miranda | a11380d | 2017-08-24 11:30:03 -0700 | [diff] [blame] | 255 | // We take the minimum sizes of this profile and it's multi-window variant to ensure that |
| 256 | // the system decor is always excluded. |
| 257 | mwSize.set(Math.min(availableWidthPx, mwSize.x), Math.min(availableHeightPx, mwSize.y)); |
| 258 | |
Jon Miranda | cc42c5b | 2016-10-27 17:15:27 -0700 | [diff] [blame] | 259 | // In multi-window mode, we can have widthPx = availableWidthPx |
| 260 | // and heightPx = availableHeightPx because Launcher uses the InvariantDeviceProfiles' |
| 261 | // widthPx and heightPx values where it's needed. |
Jon Miranda | 93e1f04 | 2016-11-11 14:13:04 -0800 | [diff] [blame] | 262 | DeviceProfile profile = new DeviceProfile(context, inv, mwSize, mwSize, mwSize.x, mwSize.y, |
| 263 | isLandscape); |
| 264 | |
Jon Miranda | 0cd0457 | 2017-09-19 11:31:42 -0700 | [diff] [blame] | 265 | // If there isn't enough vertical cell padding with the labels displayed, hide the labels. |
| 266 | float workspaceCellPaddingY = profile.getCellSize().y - profile.iconSizePx |
| 267 | - iconDrawablePaddingPx - profile.iconTextSizePx; |
| 268 | if (workspaceCellPaddingY < profile.iconDrawablePaddingPx * 2) { |
| 269 | profile.adjustToHideWorkspaceLabels(); |
| 270 | } |
Jon Miranda | 93e1f04 | 2016-11-11 14:13:04 -0800 | [diff] [blame] | 271 | |
Jon Miranda | 7ae64ff | 2016-11-21 16:18:46 -0800 | [diff] [blame] | 272 | // We use these scales to measure and layout the widgets using their full invariant profile |
| 273 | // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans. |
| 274 | float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x; |
| 275 | float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y; |
| 276 | profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY); |
| 277 | |
Jon Miranda | 93e1f04 | 2016-11-11 14:13:04 -0800 | [diff] [blame] | 278 | return profile; |
Jon Miranda | cc42c5b | 2016-10-27 17:15:27 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 281 | public void addLauncherLayoutChangedListener(LauncherLayoutChangeListener listener) { |
| 282 | if (!mListeners.contains(listener)) { |
| 283 | mListeners.add(listener); |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | public void removeLauncherLayoutChangedListener(LauncherLayoutChangeListener listener) { |
| 288 | if (mListeners.contains(listener)) { |
| 289 | mListeners.remove(listener); |
| 290 | } |
| 291 | } |
| 292 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 293 | /** |
Jon Miranda | 1091e53 | 2017-07-21 13:31:50 -0700 | [diff] [blame] | 294 | * Adjusts the profile so that the labels on the Workspace are hidden. |
| 295 | * It is important to call this method after the All Apps variables have been set. |
| 296 | */ |
| 297 | private void adjustToHideWorkspaceLabels() { |
| 298 | iconTextSizePx = 0; |
| 299 | iconDrawablePaddingPx = 0; |
| 300 | cellHeightPx = iconSizePx; |
| 301 | |
| 302 | // In normal cases, All Apps cell height should equal the Workspace cell height. |
| 303 | // Since we are removing labels from the Workspace, we need to manually compute the |
| 304 | // All Apps cell height. |
Jon Miranda | 3f9bab2 | 2017-07-28 14:50:17 -0700 | [diff] [blame] | 305 | int topBottomPadding = allAppsIconDrawablePaddingPx * (isVerticalBarLayout() ? 2 : 1); |
Jon Miranda | 1091e53 | 2017-07-21 13:31:50 -0700 | [diff] [blame] | 306 | allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx |
| 307 | + Utilities.calculateTextHeight(allAppsIconTextSizePx) |
Jon Miranda | 3f9bab2 | 2017-07-28 14:50:17 -0700 | [diff] [blame] | 308 | + topBottomPadding * 2; |
Jon Miranda | 1091e53 | 2017-07-21 13:31:50 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | /** |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 312 | * Determine the exact visual footprint of the all apps button, taking into account scaling |
| 313 | * and internal padding of the drawable. |
| 314 | */ |
| 315 | private void computeAllAppsButtonSize(Context context) { |
| 316 | Resources res = context.getResources(); |
| 317 | float padding = res.getInteger(R.integer.config_allAppsButtonPaddingPercent) / 100f; |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 318 | allAppsButtonVisualSize = (int) (iconSizePx * (1 - padding)) - context.getResources() |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 319 | .getDimensionPixelSize(R.dimen.all_apps_button_scale_down); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 322 | private void updateAvailableDimensions(DisplayMetrics dm, Resources res) { |
Jon Miranda | 0966072 | 2017-06-14 14:20:14 -0700 | [diff] [blame] | 323 | updateIconSize(1f, res, dm); |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 324 | |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 325 | // Check to see if the icons fit within the available height. If not, then scale down. |
| 326 | float usedHeight = (cellHeightPx * inv.numRows); |
Sunny Goyal | 6c2975e | 2016-07-06 09:47:56 -0700 | [diff] [blame] | 327 | int maxHeight = (availableHeightPx - getTotalWorkspacePadding().y); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 328 | if (usedHeight > maxHeight) { |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 329 | float scale = maxHeight / usedHeight; |
Jon Miranda | 0966072 | 2017-06-14 14:20:14 -0700 | [diff] [blame] | 330 | updateIconSize(scale, res, dm); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 331 | } |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 332 | updateAvailableFolderCellDimensions(dm, res); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Jon Miranda | 0966072 | 2017-06-14 14:20:14 -0700 | [diff] [blame] | 335 | private void updateIconSize(float scale, Resources res, DisplayMetrics dm) { |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 336 | // Workspace |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 337 | float invIconSizePx = isVerticalBarLayout() ? inv.landscapeIconSize : inv.iconSize; |
| 338 | iconSizePx = (int) (Utilities.pxFromDp(invIconSizePx, dm) * scale); |
Sunny Goyal | a50a419 | 2015-12-11 09:50:49 -0800 | [diff] [blame] | 339 | iconTextSizePx = (int) (Utilities.pxFromSp(inv.iconTextSize, dm) * scale); |
Jon Miranda | 0966072 | 2017-06-14 14:20:14 -0700 | [diff] [blame] | 340 | iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * scale); |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 341 | |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 342 | cellHeightPx = iconSizePx + iconDrawablePaddingPx |
| 343 | + Utilities.calculateTextHeight(iconTextSizePx); |
Jon Miranda | 846455e | 2017-10-02 14:58:52 -0700 | [diff] [blame] | 344 | int cellYPadding = (getCellSize().y - cellHeightPx) / 2; |
| 345 | if (iconDrawablePaddingPx > cellYPadding && !isVerticalBarLayout() |
| 346 | && !inMultiWindowMode()) { |
| 347 | // Ensures that the label is closer to its corresponding icon. This is not an issue |
| 348 | // with vertical bar layout or multi-window mode since the issue is handled separately |
| 349 | // with their calls to {@link #adjustToHideWorkspaceLabels}. |
| 350 | cellHeightPx -= (iconDrawablePaddingPx - cellYPadding); |
| 351 | iconDrawablePaddingPx = cellYPadding; |
| 352 | } |
| 353 | cellWidthPx = iconSizePx + iconDrawablePaddingPx; |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 354 | |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 355 | // All apps |
| 356 | allAppsIconTextSizePx = iconTextSizePx; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 357 | allAppsIconSizePx = iconSizePx; |
| 358 | allAppsIconDrawablePaddingPx = iconDrawablePaddingPx; |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 359 | allAppsCellHeightPx = getCellSize().y; |
| 360 | |
| 361 | if (isVerticalBarLayout()) { |
| 362 | // Always hide the Workspace text with vertical bar layout. |
Jon Miranda | 1091e53 | 2017-07-21 13:31:50 -0700 | [diff] [blame] | 363 | adjustToHideWorkspaceLabels(); |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 364 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 365 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 366 | // Hotseat |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 367 | if (isVerticalBarLayout()) { |
| 368 | hotseatBarSizePx = iconSizePx; |
| 369 | } |
Jon Miranda | 5044c35 | 2017-08-09 11:37:59 -0700 | [diff] [blame] | 370 | hotseatCellHeightPx = iconSizePx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 371 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 372 | if (!isVerticalBarLayout()) { |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 373 | int expectedWorkspaceHeight = availableHeightPx - hotseatBarSizePx |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 374 | - pageIndicatorSizePx - topWorkspacePadding; |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 375 | float minRequiredHeight = dropTargetBarSizePx + workspaceSpringLoadedBottomSpace; |
| 376 | workspaceSpringLoadShrinkFactor = Math.min( |
| 377 | res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f, |
| 378 | 1 - (minRequiredHeight / expectedWorkspaceHeight)); |
| 379 | } else { |
| 380 | workspaceSpringLoadShrinkFactor = |
| 381 | res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f; |
| 382 | } |
| 383 | |
Sunny Goyal | baec6ff | 2016-09-14 11:26:21 -0700 | [diff] [blame] | 384 | // Folder icon |
Jon Miranda | 0966072 | 2017-06-14 14:20:14 -0700 | [diff] [blame] | 385 | folderBackgroundOffset = -iconDrawablePaddingPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 386 | folderIconSizePx = iconSizePx + 2 * -folderBackgroundOffset; |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 387 | folderIconPreviewPadding = res.getDimensionPixelSize(R.dimen.folder_preview_padding); |
Winson Chung | 0f78572 | 2015-04-08 10:27:49 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 390 | private void updateAvailableFolderCellDimensions(DisplayMetrics dm, Resources res) { |
| 391 | int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_padding_top) |
| 392 | + res.getDimensionPixelSize(R.dimen.folder_label_padding_bottom) |
| 393 | + Utilities.calculateTextHeight(res.getDimension(R.dimen.folder_label_text_size)); |
| 394 | |
Jon Miranda | c1b2399 | 2016-12-13 08:57:36 -0800 | [diff] [blame] | 395 | updateFolderCellSize(1f, dm, res); |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 396 | |
Jon Miranda | c1b2399 | 2016-12-13 08:57:36 -0800 | [diff] [blame] | 397 | // 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] | 398 | int folderMargin = edgeMarginPx; |
Jon Miranda | c1b2399 | 2016-12-13 08:57:36 -0800 | [diff] [blame] | 399 | |
| 400 | // Check if the icons fit within the available height. |
| 401 | float usedHeight = folderCellHeightPx * inv.numFolderRows + folderBottomPanelSize; |
| 402 | int maxHeight = availableHeightPx - getTotalWorkspacePadding().y - folderMargin; |
| 403 | float scaleY = maxHeight / usedHeight; |
| 404 | |
| 405 | // Check if the icons fit within the available width. |
| 406 | float usedWidth = folderCellWidthPx * inv.numFolderColumns; |
| 407 | int maxWidth = availableWidthPx - getTotalWorkspacePadding().x - folderMargin; |
| 408 | float scaleX = maxWidth / usedWidth; |
| 409 | |
| 410 | float scale = Math.min(scaleX, scaleY); |
| 411 | if (scale < 1f) { |
| 412 | updateFolderCellSize(scale, dm, res); |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 413 | } |
| 414 | } |
| 415 | |
Jon Miranda | c1b2399 | 2016-12-13 08:57:36 -0800 | [diff] [blame] | 416 | private void updateFolderCellSize(float scale, DisplayMetrics dm, Resources res) { |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 417 | folderChildIconSizePx = (int) (Utilities.pxFromDp(inv.iconSize, dm) * scale); |
| 418 | folderChildTextSizePx = |
| 419 | (int) (res.getDimensionPixelSize(R.dimen.folder_child_text_size) * scale); |
| 420 | |
| 421 | int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx); |
| 422 | int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding) * scale); |
| 423 | int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding) * scale); |
| 424 | |
Jon Miranda | c1b2399 | 2016-12-13 08:57:36 -0800 | [diff] [blame] | 425 | folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX; |
Jonathan Miranda | 9ad8746 | 2017-07-26 17:41:02 +0000 | [diff] [blame] | 426 | folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight; |
| 427 | folderChildDrawablePaddingPx = Math.max(0, |
| 428 | (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3); |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 431 | public void updateInsets(Rect insets) { |
| 432 | mInsets.set(insets); |
| 433 | } |
| 434 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 435 | public void updateAppsViewNumCols() { |
| 436 | allAppsNumCols = allAppsNumPredictiveCols = inv.numColumns; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 439 | /** Returns the width and height of the search bar, ignoring any padding. */ |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 440 | public Point getSearchBarDimensForWidgetOpts() { |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 441 | if (isVerticalBarLayout()) { |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 442 | return new Point(dropTargetBarSizePx, availableHeightPx - 2 * edgeMarginPx); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 443 | } else { |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 444 | int gap; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 445 | if (isTablet) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 446 | // Pad the left and right of the workspace to ensure consistent spacing |
| 447 | // between all icons |
Winson Chung | 4f3bfad | 2015-07-13 11:14:30 -0700 | [diff] [blame] | 448 | int width = getCurrentWidth(); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 449 | // XXX: If the icon size changes across orientations, we will have to take |
| 450 | // that into account here too. |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 451 | gap = ((width - 2 * edgeMarginPx |
| 452 | - (inv.numColumns * cellWidthPx)) / (2 * (inv.numColumns + 1))) |
| 453 | + edgeMarginPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 454 | } else { |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 455 | gap = desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.right; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 456 | } |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 457 | return new Point(availableWidthPx - 2 * gap, dropTargetBarSizePx); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 458 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 461 | public Point getCellSize() { |
| 462 | Point result = new Point(); |
| 463 | // Since we are only concerned with the overall padding, layout direction does |
| 464 | // not matter. |
Sunny Goyal | 6c2975e | 2016-07-06 09:47:56 -0700 | [diff] [blame] | 465 | Point padding = getTotalWorkspacePadding(); |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 466 | result.x = calculateCellWidth(availableWidthPx - padding.x |
| 467 | - cellLayoutPaddingLeftRightPx * 2, inv.numColumns); |
| 468 | result.y = calculateCellHeight(availableHeightPx - padding.y |
| 469 | - cellLayoutBottomPaddingPx, inv.numRows); |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 470 | return result; |
| 471 | } |
| 472 | |
Sunny Goyal | 6c2975e | 2016-07-06 09:47:56 -0700 | [diff] [blame] | 473 | public Point getTotalWorkspacePadding() { |
Sunny Goyal | 6178f13 | 2016-07-11 17:30:03 -0700 | [diff] [blame] | 474 | Rect padding = getWorkspacePadding(null); |
Sunny Goyal | 6c2975e | 2016-07-06 09:47:56 -0700 | [diff] [blame] | 475 | return new Point(padding.left + padding.right, padding.top + padding.bottom); |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * Returns the workspace padding in the specified orientation. |
Sunny Goyal | 6c2975e | 2016-07-06 09:47:56 -0700 | [diff] [blame] | 480 | */ |
Sunny Goyal | 6178f13 | 2016-07-11 17:30:03 -0700 | [diff] [blame] | 481 | public Rect getWorkspacePadding(Rect recycle) { |
| 482 | Rect padding = recycle == null ? new Rect() : recycle; |
Tony Wickham | 3a3517f | 2015-10-06 11:27:04 -0700 | [diff] [blame] | 483 | if (isVerticalBarLayout()) { |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 484 | if (mInsets.left > 0) { |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 485 | padding.set(mInsets.left + pageIndicatorLandLeftNavBarGutterPx, |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 486 | 0, |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 487 | hotseatBarSizePx + hotseatBarLeftNavBarRightPaddingPx |
| 488 | + hotseatBarLeftNavBarLeftPaddingPx |
| 489 | - mInsets.left, |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 490 | edgeMarginPx); |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 491 | } else { |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 492 | padding.set(pageIndicatorLandRightNavBarGutterPx, |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 493 | 0, |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 494 | hotseatBarSizePx + hotseatBarRightNavBarRightPaddingPx |
| 495 | + hotseatBarRightNavBarLeftPaddingPx, |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 496 | edgeMarginPx); |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 497 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 498 | } else { |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 499 | int paddingBottom = hotseatBarSizePx + pageIndicatorSizePx; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 500 | if (isTablet) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 501 | // Pad the left and right of the workspace to ensure consistent spacing |
| 502 | // between all icons |
Winson Chung | 4f3bfad | 2015-07-13 11:14:30 -0700 | [diff] [blame] | 503 | int width = getCurrentWidth(); |
| 504 | int height = getCurrentHeight(); |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 505 | // The amount of screen space available for left/right padding. |
Sunny Goyal | f5440cb | 2016-12-14 15:13:00 -0800 | [diff] [blame] | 506 | int availablePaddingX = Math.max(0, width - ((inv.numColumns * cellWidthPx) + |
| 507 | ((inv.numColumns - 1) * cellWidthPx))); |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 508 | availablePaddingX = (int) Math.min(availablePaddingX, |
| 509 | width * MAX_HORIZONTAL_PADDING_PERCENT); |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 510 | int availablePaddingY = Math.max(0, height - topWorkspacePadding - paddingBottom |
Jon Miranda | c1b08c5 | 2016-11-15 14:37:56 -0800 | [diff] [blame] | 511 | - (2 * inv.numRows * cellHeightPx) - hotseatBarTopPaddingPx |
| 512 | - hotseatBarBottomPaddingPx); |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 513 | padding.set(availablePaddingX / 2, topWorkspacePadding + availablePaddingY / 2, |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 514 | availablePaddingX / 2, paddingBottom + availablePaddingY / 2); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 515 | } else { |
| 516 | // Pad the top and bottom of the workspace with search/hotseat bar sizes |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 517 | padding.set(desiredWorkspaceLeftRightMarginPx, |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 518 | topWorkspacePadding, |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 519 | desiredWorkspaceLeftRightMarginPx, |
Winson | fadbe8f | 2016-07-22 16:35:37 -0700 | [diff] [blame] | 520 | paddingBottom); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 521 | } |
| 522 | } |
| 523 | return padding; |
| 524 | } |
| 525 | |
Winson | fadbe8f | 2016-07-22 16:35:37 -0700 | [diff] [blame] | 526 | /** |
| 527 | * @return the bounds for which the open folders should be contained within |
| 528 | */ |
| 529 | public Rect getAbsoluteOpenFolderBounds() { |
| 530 | if (isVerticalBarLayout()) { |
| 531 | // Folders should only appear right of the drop target bar and left of the hotseat |
| 532 | return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx, |
| 533 | mInsets.top, |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 534 | mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx, |
Winson | fadbe8f | 2016-07-22 16:35:37 -0700 | [diff] [blame] | 535 | mInsets.top + availableHeightPx); |
| 536 | } else { |
| 537 | // Folders should only appear below the drop target bar and above the hotseat |
| 538 | return new Rect(mInsets.left, |
| 539 | mInsets.top + dropTargetBarSizePx + edgeMarginPx, |
| 540 | mInsets.left + availableWidthPx, |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 541 | mInsets.top + availableHeightPx - hotseatBarSizePx |
Jon Miranda | 2ed276e | 2017-06-29 11:36:34 -0700 | [diff] [blame] | 542 | - pageIndicatorSizePx - edgeMarginPx); |
Winson | fadbe8f | 2016-07-22 16:35:37 -0700 | [diff] [blame] | 543 | } |
| 544 | } |
| 545 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 546 | private int getWorkspacePageSpacing() { |
Tony Wickham | 3a3517f | 2015-10-06 11:27:04 -0700 | [diff] [blame] | 547 | if (isVerticalBarLayout() || isLargeTablet) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 548 | // In landscape mode the page spacing is set to the default. |
| 549 | return defaultPageSpacingPx; |
| 550 | } else { |
| 551 | // In portrait, we want the pages spaced such that there is no |
| 552 | // overhang of the previous / next page into the current page viewport. |
| 553 | // We assume symmetrical padding in portrait mode. |
Jon Miranda | 2803200 | 2017-07-13 16:18:56 -0700 | [diff] [blame] | 554 | return Math.max(defaultPageSpacingPx, getWorkspacePadding(null).left + 1); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 555 | } |
| 556 | } |
| 557 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 558 | public static int calculateCellWidth(int width, int countX) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 559 | return width / countX; |
| 560 | } |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 561 | public static int calculateCellHeight(int height, int countY) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 562 | return height / countY; |
| 563 | } |
| 564 | |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 565 | /** |
Tony Wickham | 55616cd | 2015-09-23 14:55:17 -0700 | [diff] [blame] | 566 | * When {@code true}, the device is in landscape mode and the hotseat is on the right column. |
| 567 | * When {@code false}, either device is in portrait mode or the device is in landscape mode and |
| 568 | * the hotseat is on the bottom row. |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 569 | */ |
Tony Wickham | ab946a1 | 2015-09-16 15:38:16 -0700 | [diff] [blame] | 570 | public boolean isVerticalBarLayout() { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 571 | return isLandscape && transposeLayoutWithOrientation; |
| 572 | } |
| 573 | |
| 574 | boolean shouldFadeAdjacentWorkspaceScreens() { |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 575 | return isVerticalBarLayout() || isLargeTablet; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 576 | } |
| 577 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 578 | public void layout(Launcher launcher, boolean notifyListeners) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 579 | FrameLayout.LayoutParams lp; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 580 | boolean hasVerticalBarLayout = isVerticalBarLayout(); |
| 581 | |
| 582 | // Layout the search bar space |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 583 | Point searchBarBounds = getSearchBarDimensForWidgetOpts(); |
| 584 | View searchBar = launcher.getDropTargetBar(); |
Sunny Goyal | f37a214 | 2016-03-24 17:28:25 -0700 | [diff] [blame] | 585 | lp = (FrameLayout.LayoutParams) searchBar.getLayoutParams(); |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 586 | lp.width = searchBarBounds.x; |
| 587 | lp.height = searchBarBounds.y; |
Jon Miranda | 2803200 | 2017-07-13 16:18:56 -0700 | [diff] [blame] | 588 | lp.topMargin = mInsets.top + edgeMarginPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 589 | searchBar.setLayoutParams(lp); |
| 590 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 591 | // Layout the workspace |
Sunny Goyal | b532dfe | 2017-12-13 17:16:54 -0800 | [diff] [blame] | 592 | PagedView workspace = launcher.getWorkspace(); |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 593 | Rect workspacePadding = getWorkspacePadding(null); |
| 594 | workspace.setPadding(workspacePadding.left, workspacePadding.top, workspacePadding.right, |
| 595 | workspacePadding.bottom); |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 596 | workspace.setPageSpacing(getWorkspacePageSpacing()); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 597 | |
Sunny Goyal | b532dfe | 2017-12-13 17:16:54 -0800 | [diff] [blame] | 598 | AllAppsScrim allAppsScrim = launcher.findViewById(R.id.all_apps_scrim); |
| 599 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 600 | // Layout the hotseat |
Sunny Goyal | b532dfe | 2017-12-13 17:16:54 -0800 | [diff] [blame] | 601 | Hotseat hotseat = launcher.getHotseat(); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 602 | lp = (FrameLayout.LayoutParams) hotseat.getLayoutParams(); |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 603 | // We want the edges of the hotseat to line up with the edges of the workspace, but the |
| 604 | // icons in the hotseat are a different size, and so don't line up perfectly. To account for |
| 605 | // this, we pad the left and right of the hotseat with half of the difference of a workspace |
| 606 | // cell vs a hotseat cell. |
| 607 | float workspaceCellWidth = (float) getCurrentWidth() / inv.numColumns; |
| 608 | float hotseatCellWidth = (float) getCurrentWidth() / inv.numHotseatIcons; |
| 609 | int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2); |
Sunny Goyal | b532dfe | 2017-12-13 17:16:54 -0800 | [diff] [blame] | 610 | float scrimMargin = launcher.getResources().getDimension(R.dimen.all_apps_scrim_margin); |
| 611 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 612 | if (hasVerticalBarLayout) { |
Winson Chung | f8c6f88 | 2015-06-03 11:27:26 -0700 | [diff] [blame] | 613 | // Vertical hotseat -- The hotseat is fixed in the layout to be on the right of the |
| 614 | // screen regardless of RTL |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 615 | int paddingRight = mInsets.left > 0 |
| 616 | ? hotseatBarLeftNavBarRightPaddingPx |
| 617 | : hotseatBarRightNavBarRightPaddingPx; |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 618 | int paddingLeft = mInsets.left > 0 |
| 619 | ? hotseatBarLeftNavBarLeftPaddingPx |
| 620 | : hotseatBarRightNavBarLeftPaddingPx; |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 621 | |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 622 | lp.gravity = Gravity.RIGHT; |
| 623 | lp.width = hotseatBarSizePx + mInsets.left + mInsets.right |
| 624 | + paddingLeft + paddingRight; |
| 625 | lp.height = LayoutParams.MATCH_PARENT; |
| 626 | |
| 627 | hotseat.getLayout().setPadding(mInsets.left + cellLayoutPaddingLeftRightPx |
| 628 | + paddingLeft, |
| 629 | mInsets.top, |
| 630 | mInsets.right + cellLayoutPaddingLeftRightPx + paddingRight, |
| 631 | workspacePadding.bottom + cellLayoutBottomPaddingPx); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 632 | } else if (isTablet) { |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 633 | // Pad the hotseat with the workspace padding calculated above |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 634 | lp.gravity = Gravity.BOTTOM; |
| 635 | lp.width = LayoutParams.MATCH_PARENT; |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 636 | lp.height = hotseatBarSizePx + mInsets.bottom; |
Sunny Goyal | b532dfe | 2017-12-13 17:16:54 -0800 | [diff] [blame] | 637 | allAppsScrim.setDrawRegion(lp.height + scrimMargin); |
| 638 | |
Jon Miranda | 52ff325 | 2017-07-14 11:39:16 -0700 | [diff] [blame] | 639 | hotseat.getLayout().setPadding(hotseatAdjustment + workspacePadding.left |
| 640 | + cellLayoutPaddingLeftRightPx, |
| 641 | hotseatBarTopPaddingPx, |
| 642 | hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx, |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 643 | hotseatBarBottomPaddingPx + mInsets.bottom + cellLayoutBottomPaddingPx); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 644 | } else { |
| 645 | // For phones, layout the hotseat without any bottom margin |
| 646 | // to ensure that we have space for the folders |
| 647 | lp.gravity = Gravity.BOTTOM; |
| 648 | lp.width = LayoutParams.MATCH_PARENT; |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 649 | lp.height = hotseatBarSizePx + mInsets.bottom; |
Sunny Goyal | b532dfe | 2017-12-13 17:16:54 -0800 | [diff] [blame] | 650 | allAppsScrim.setDrawRegion(lp.height + scrimMargin); |
| 651 | |
Jon Miranda | 52ff325 | 2017-07-14 11:39:16 -0700 | [diff] [blame] | 652 | hotseat.getLayout().setPadding(hotseatAdjustment + workspacePadding.left |
| 653 | + cellLayoutPaddingLeftRightPx, |
| 654 | hotseatBarTopPaddingPx, |
| 655 | hotseatAdjustment + workspacePadding.right + cellLayoutPaddingLeftRightPx, |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 656 | hotseatBarBottomPaddingPx + mInsets.bottom + cellLayoutBottomPaddingPx); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 657 | } |
| 658 | hotseat.setLayoutParams(lp); |
| 659 | |
| 660 | // Layout the page indicators |
| 661 | View pageIndicator = launcher.findViewById(R.id.page_indicator); |
| 662 | if (pageIndicator != null) { |
Hyunyoung Song | 7d2fc81 | 2016-06-15 12:51:30 -0700 | [diff] [blame] | 663 | lp = (FrameLayout.LayoutParams) pageIndicator.getLayoutParams(); |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 664 | if (isVerticalBarLayout()) { |
| 665 | if (mInsets.left > 0) { |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 666 | lp.leftMargin = mInsets.left; |
| 667 | } else { |
| 668 | lp.leftMargin = pageIndicatorLandWorkspaceOffsetPx; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 669 | } |
| 670 | lp.bottomMargin = workspacePadding.bottom; |
| 671 | } else { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 672 | // Put the page indicators above the hotseat |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 673 | lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 674 | lp.height = pageIndicatorSizePx; |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 675 | lp.bottomMargin = hotseatBarSizePx + mInsets.bottom; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 676 | } |
Hyunyoung Song | 7d2fc81 | 2016-06-15 12:51:30 -0700 | [diff] [blame] | 677 | pageIndicator.setLayoutParams(lp); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 680 | // Layout the AllAppsRecyclerView |
Mario Bertschler | ac9408a | 2017-10-18 10:31:36 -0700 | [diff] [blame] | 681 | AllAppsContainerView appsView = launcher.findViewById(R.id.apps_view); |
Jon Miranda | 2803200 | 2017-07-13 16:18:56 -0700 | [diff] [blame] | 682 | int paddingLeftRight = desiredWorkspaceLeftRightMarginPx + cellLayoutPaddingLeftRightPx; |
Mario Bertschler | ac9408a | 2017-10-18 10:31:36 -0700 | [diff] [blame] | 683 | appsView.setRecyclerViewSidePadding(paddingLeftRight, paddingLeftRight); |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 684 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 685 | if (notifyListeners) { |
| 686 | for (int i = mListeners.size() - 1; i >= 0; i--) { |
| 687 | mListeners.get(i).onLauncherLayoutChanged(); |
Sunny Goyal | 8dfe2da | 2014-10-24 16:26:52 -0700 | [diff] [blame] | 688 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 689 | } |
| 690 | } |
Winson Chung | 4f3bfad | 2015-07-13 11:14:30 -0700 | [diff] [blame] | 691 | |
Winson Chung | b63b44c | 2017-11-10 17:54:44 -0800 | [diff] [blame] | 692 | public int getCurrentWidth() { |
Winson Chung | 4f3bfad | 2015-07-13 11:14:30 -0700 | [diff] [blame] | 693 | return isLandscape |
| 694 | ? Math.max(widthPx, heightPx) |
| 695 | : Math.min(widthPx, heightPx); |
| 696 | } |
| 697 | |
Winson Chung | b63b44c | 2017-11-10 17:54:44 -0800 | [diff] [blame] | 698 | public int getCurrentHeight() { |
Winson Chung | 4f3bfad | 2015-07-13 11:14:30 -0700 | [diff] [blame] | 699 | return isLandscape |
| 700 | ? Math.min(widthPx, heightPx) |
| 701 | : Math.max(widthPx, heightPx); |
| 702 | } |
Sunny Goyal | 13178ac | 2016-04-04 16:35:22 -0700 | [diff] [blame] | 703 | |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 704 | public int getCellHeight(@ContainerType int containerType) { |
| 705 | switch (containerType) { |
| 706 | case CellLayout.WORKSPACE: |
| 707 | return cellHeightPx; |
| 708 | case CellLayout.FOLDER: |
| 709 | return folderCellHeightPx; |
| 710 | case CellLayout.HOTSEAT: |
| 711 | return hotseatCellHeightPx; |
| 712 | default: |
| 713 | // ?? |
| 714 | return 0; |
| 715 | } |
| 716 | } |
Sunny Goyal | 13178ac | 2016-04-04 16:35:22 -0700 | [diff] [blame] | 717 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 718 | /** |
| 719 | * @return the left/right paddings for all containers. |
| 720 | */ |
Jon Miranda | c3e4e22 | 2016-11-02 16:56:52 -0700 | [diff] [blame] | 721 | public final int[] getContainerPadding() { |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 722 | // No paddings for portrait phone |
| 723 | if (isPhone && !isVerticalBarLayout()) { |
| 724 | return new int[] {0, 0}; |
Sunny Goyal | 13178ac | 2016-04-04 16:35:22 -0700 | [diff] [blame] | 725 | } |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 726 | |
Hyunyoung Song | 9d96fd5 | 2016-08-23 11:06:24 -0700 | [diff] [blame] | 727 | // In landscape, we match the width of the workspace |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 728 | Rect padding = getWorkspacePadding(null); |
| 729 | return new int[] { padding.left - mInsets.left, padding.right + mInsets.left}; |
Sunny Goyal | 13178ac | 2016-04-04 16:35:22 -0700 | [diff] [blame] | 730 | } |
Jon Miranda | cc42c5b | 2016-10-27 17:15:27 -0700 | [diff] [blame] | 731 | |
Jon Miranda | 846455e | 2017-10-02 14:58:52 -0700 | [diff] [blame] | 732 | public boolean inMultiWindowMode() { |
| 733 | return this != inv.landscapeProfile && this != inv.portraitProfile; |
| 734 | } |
| 735 | |
Jon Miranda | 51f037d | 2016-11-07 08:37:20 -0800 | [diff] [blame] | 736 | public boolean shouldIgnoreLongPressToOverview(float touchX) { |
Jon Miranda | 51f037d | 2016-11-07 08:37:20 -0800 | [diff] [blame] | 737 | boolean touchedLhsEdge = mInsets.left == 0 && touchX < edgeMarginPx; |
| 738 | boolean touchedRhsEdge = mInsets.right == 0 && touchX > (widthPx - edgeMarginPx); |
Jon Miranda | 846455e | 2017-10-02 14:58:52 -0700 | [diff] [blame] | 739 | return !inMultiWindowMode() && (touchedLhsEdge || touchedRhsEdge); |
Jon Miranda | cc42c5b | 2016-10-27 17:15:27 -0700 | [diff] [blame] | 740 | } |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 741 | |
| 742 | private static Context getContext(Context c, int orientation) { |
| 743 | Configuration context = new Configuration(c.getResources().getConfiguration()); |
| 744 | context.orientation = orientation; |
| 745 | return c.createConfigurationContext(context); |
| 746 | |
| 747 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 748 | } |