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