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; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 22 | import android.content.res.Resources; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 23 | import android.graphics.Point; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 24 | import android.graphics.Rect; |
| 25 | import android.util.DisplayMetrics; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 26 | import android.view.Gravity; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 27 | import android.view.View; |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 28 | import android.view.ViewGroup; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 29 | import android.view.ViewGroup.LayoutParams; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 30 | import android.widget.FrameLayout; |
| 31 | |
Tony Wickham | e0c3323 | 2016-02-08 11:37:04 -0800 | [diff] [blame] | 32 | import com.android.launcher3.config.FeatureFlags; |
| 33 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 34 | import java.util.ArrayList; |
| 35 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 36 | public class DeviceProfile { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 37 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 38 | public interface LauncherLayoutChangeListener { |
| 39 | void onLauncherLayoutChanged(); |
| 40 | } |
| 41 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 42 | public final InvariantDeviceProfile inv; |
Winson Chung | be87647 | 2014-05-14 14:15:20 -0700 | [diff] [blame] | 43 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 44 | // Device properties |
| 45 | public final boolean isTablet; |
| 46 | public final boolean isLargeTablet; |
| 47 | public final boolean isPhone; |
| 48 | public final boolean transposeLayoutWithOrientation; |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 49 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 50 | // Device properties in current orientation |
| 51 | public final boolean isLandscape; |
| 52 | public final int widthPx; |
| 53 | public final int heightPx; |
| 54 | public final int availableWidthPx; |
| 55 | public final int availableHeightPx; |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 56 | /** |
| 57 | * The maximum amount of left/right workspace padding as a percentage of the screen width. |
| 58 | * To be clear, this means that up to 7% of the screen width can be used as left padding, and |
| 59 | * 7% of the screen width can be used as right padding. |
| 60 | */ |
| 61 | private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 62 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 63 | // Overview mode |
| 64 | private final int overviewModeMinIconZoneHeightPx; |
| 65 | private final int overviewModeMaxIconZoneHeightPx; |
| 66 | private final int overviewModeBarItemWidthPx; |
| 67 | private final int overviewModeBarSpacerWidthPx; |
| 68 | private final float overviewModeIconZoneRatio; |
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 |
| 71 | private int desiredWorkspaceLeftRightMarginPx; |
| 72 | public final int edgeMarginPx; |
| 73 | public final Rect defaultWidgetPadding; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 74 | private final int defaultPageSpacingPx; |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 75 | private final int topWorkspacePadding; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 76 | private float dragViewScale; |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 77 | public float workspaceSpringLoadShrinkFactor; |
| 78 | public final int workspaceSpringLoadedBottomSpace; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 79 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 80 | // Page indicator |
| 81 | private final int pageIndicatorHeightPx; |
| 82 | private final int pageIndicatorLandGutterLeftNavBarPx; |
| 83 | private final int pageIndicatorLandGutterRightNavBarPx; |
| 84 | private final int pageIndicatorLandWorkspaceOffsetPx; |
| 85 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 86 | // Workspace icons |
| 87 | public int iconSizePx; |
| 88 | public int iconTextSizePx; |
| 89 | public int iconDrawablePaddingPx; |
Winson Chung | 5f4e0fd | 2015-05-22 11:12:27 -0700 | [diff] [blame] | 90 | public int iconDrawablePaddingOriginalPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 91 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 92 | public int cellWidthPx; |
| 93 | public int cellHeightPx; |
| 94 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 95 | // Folder |
| 96 | public int folderBackgroundOffset; |
| 97 | public int folderIconSizePx; |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 98 | public int folderIconPreviewPadding; |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 99 | |
| 100 | // Folder cell |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 101 | public int folderCellWidthPx; |
| 102 | public int folderCellHeightPx; |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 103 | |
| 104 | // Folder child |
| 105 | public int folderChildIconSizePx; |
| 106 | public int folderChildTextSizePx; |
Sunny Goyal | baec6ff | 2016-09-14 11:26:21 -0700 | [diff] [blame] | 107 | public int folderChildDrawablePaddingPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 108 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 109 | // Hotseat |
| 110 | public int hotseatCellWidthPx; |
| 111 | public int hotseatCellHeightPx; |
| 112 | public int hotseatIconSizePx; |
Jon Miranda | aca2145 | 2016-09-26 14:01:56 -0700 | [diff] [blame] | 113 | public int hotseatBarHeightPx; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 114 | private int hotseatBarTopPaddingPx; |
| 115 | private int hotseatLandGutterPx; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 116 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 117 | // All apps |
Winson Chung | 5f4e0fd | 2015-05-22 11:12:27 -0700 | [diff] [blame] | 118 | public int allAppsNumCols; |
| 119 | public int allAppsNumPredictiveCols; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 120 | public int allAppsButtonVisualSize; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 121 | public int allAppsIconSizePx; |
| 122 | public int allAppsIconDrawablePaddingPx; |
| 123 | public float allAppsIconTextSizePx; |
| 124 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 125 | // Drop Target |
| 126 | public int dropTargetBarSizePx; |
Adam Cohen | 4ae96ce | 2014-08-29 15:05:48 -0700 | [diff] [blame] | 127 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 128 | // Insets |
| 129 | private Rect mInsets = new Rect(); |
| 130 | |
| 131 | // Listeners |
| 132 | private ArrayList<LauncherLayoutChangeListener> mListeners = new ArrayList<>(); |
| 133 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 134 | public DeviceProfile(Context context, InvariantDeviceProfile inv, |
| 135 | Point minSize, Point maxSize, |
| 136 | int width, int height, boolean isLandscape) { |
Sunny Goyal | fee35bb | 2015-05-11 11:38:19 -0700 | [diff] [blame] | 137 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 138 | this.inv = inv; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 139 | this.isLandscape = isLandscape; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 140 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 141 | Resources res = context.getResources(); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 142 | DisplayMetrics dm = res.getDisplayMetrics(); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 143 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 144 | // Constants from resources |
| 145 | isTablet = res.getBoolean(R.bool.is_tablet); |
| 146 | isLargeTablet = res.getBoolean(R.bool.is_large_tablet); |
| 147 | isPhone = !isTablet && !isLargeTablet; |
| 148 | |
| 149 | // Some more constants |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 150 | transposeLayoutWithOrientation = |
| 151 | res.getBoolean(R.bool.hotseat_transpose_layout_with_orientation); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 152 | |
| 153 | ComponentName cn = new ComponentName(context.getPackageName(), |
| 154 | this.getClass().getName()); |
| 155 | defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null); |
| 156 | edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin); |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 157 | desiredWorkspaceLeftRightMarginPx = edgeMarginPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 158 | pageIndicatorHeightPx = |
| 159 | res.getDimensionPixelSize(R.dimen.dynamic_grid_page_indicator_height); |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 160 | pageIndicatorLandGutterLeftNavBarPx = res.getDimensionPixelSize( |
| 161 | R.dimen.dynamic_grid_page_indicator_gutter_width_left_nav_bar); |
| 162 | pageIndicatorLandWorkspaceOffsetPx = |
| 163 | res.getDimensionPixelSize(R.dimen.all_apps_caret_workspace_offset); |
| 164 | pageIndicatorLandGutterRightNavBarPx = res.getDimensionPixelSize( |
| 165 | R.dimen.dynamic_grid_page_indicator_gutter_width_right_nav_bar); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 166 | defaultPageSpacingPx = |
| 167 | res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_page_spacing); |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 168 | topWorkspacePadding = |
| 169 | res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_top_padding); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 170 | overviewModeMinIconZoneHeightPx = |
| 171 | res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_min_icon_zone_height); |
| 172 | overviewModeMaxIconZoneHeightPx = |
| 173 | res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_max_icon_zone_height); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 174 | overviewModeBarItemWidthPx = |
| 175 | res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_bar_item_width); |
| 176 | overviewModeBarSpacerWidthPx = |
| 177 | res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_bar_spacer_width); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 178 | overviewModeIconZoneRatio = |
| 179 | res.getInteger(R.integer.config_dynamic_grid_overview_icon_zone_percentage) / 100f; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 180 | iconDrawablePaddingOriginalPx = |
| 181 | res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding); |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 182 | dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size); |
| 183 | workspaceSpringLoadedBottomSpace = |
| 184 | res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space); |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 185 | hotseatBarHeightPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_height); |
| 186 | hotseatBarTopPaddingPx = |
| 187 | res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding); |
| 188 | hotseatLandGutterPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_gutter_width); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 189 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 190 | // Determine sizes. |
| 191 | widthPx = width; |
| 192 | heightPx = height; |
| 193 | if (isLandscape) { |
| 194 | availableWidthPx = maxSize.x; |
| 195 | availableHeightPx = minSize.y; |
| 196 | } else { |
| 197 | availableWidthPx = minSize.x; |
| 198 | availableHeightPx = maxSize.y; |
| 199 | } |
Adam Cohen | 4ae96ce | 2014-08-29 15:05:48 -0700 | [diff] [blame] | 200 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 201 | // Calculate the remaining vars |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 202 | updateAvailableDimensions(dm, res); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 203 | computeAllAppsButtonSize(context); |
| 204 | } |
| 205 | |
Jon Miranda | cc42c5b | 2016-10-27 17:15:27 -0700 | [diff] [blame] | 206 | DeviceProfile getMultiWindowProfile(Context context, Point mwSize) { |
| 207 | // In multi-window mode, we can have widthPx = availableWidthPx |
| 208 | // and heightPx = availableHeightPx because Launcher uses the InvariantDeviceProfiles' |
| 209 | // widthPx and heightPx values where it's needed. |
Jon Miranda | 93e1f04 | 2016-11-11 14:13:04 -0800 | [diff] [blame^] | 210 | DeviceProfile profile = new DeviceProfile(context, inv, mwSize, mwSize, mwSize.x, mwSize.y, |
| 211 | isLandscape); |
| 212 | |
| 213 | // Hide labels on the workspace. |
| 214 | profile.iconTextSizePx = 0; |
| 215 | profile.cellHeightPx = profile.iconSizePx + profile.iconDrawablePaddingPx |
| 216 | + Utilities.calculateTextHeight(profile.iconTextSizePx); |
| 217 | |
| 218 | return profile; |
Jon Miranda | cc42c5b | 2016-10-27 17:15:27 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 221 | public void addLauncherLayoutChangedListener(LauncherLayoutChangeListener listener) { |
| 222 | if (!mListeners.contains(listener)) { |
| 223 | mListeners.add(listener); |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | public void removeLauncherLayoutChangedListener(LauncherLayoutChangeListener listener) { |
| 228 | if (mListeners.contains(listener)) { |
| 229 | mListeners.remove(listener); |
| 230 | } |
| 231 | } |
| 232 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 233 | /** |
| 234 | * Determine the exact visual footprint of the all apps button, taking into account scaling |
| 235 | * and internal padding of the drawable. |
| 236 | */ |
| 237 | private void computeAllAppsButtonSize(Context context) { |
| 238 | Resources res = context.getResources(); |
| 239 | float padding = res.getInteger(R.integer.config_allAppsButtonPaddingPercent) / 100f; |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 240 | allAppsButtonVisualSize = (int) (hotseatIconSizePx * (1 - padding)) - context.getResources() |
| 241 | .getDimensionPixelSize(R.dimen.all_apps_button_scale_down); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 244 | private void updateAvailableDimensions(DisplayMetrics dm, Resources res) { |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 245 | updateIconSize(1f, iconDrawablePaddingOriginalPx, res, dm); |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 246 | |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 247 | // Check to see if the icons fit within the available height. If not, then scale down. |
| 248 | float usedHeight = (cellHeightPx * inv.numRows); |
Sunny Goyal | 6c2975e | 2016-07-06 09:47:56 -0700 | [diff] [blame] | 249 | int maxHeight = (availableHeightPx - getTotalWorkspacePadding().y); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 250 | if (usedHeight > maxHeight) { |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 251 | float scale = maxHeight / usedHeight; |
| 252 | updateIconSize(scale, 0, res, dm); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 253 | } |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 254 | |
| 255 | updateAvailableFolderCellDimensions(dm, res); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Winson Chung | 93f98ea | 2015-03-10 16:28:47 -0700 | [diff] [blame] | 258 | private void updateIconSize(float scale, int drawablePadding, Resources res, |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 259 | DisplayMetrics dm) { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 260 | iconSizePx = (int) (Utilities.pxFromDp(inv.iconSize, dm) * scale); |
Sunny Goyal | a50a419 | 2015-12-11 09:50:49 -0800 | [diff] [blame] | 261 | iconTextSizePx = (int) (Utilities.pxFromSp(inv.iconTextSize, dm) * scale); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 262 | iconDrawablePaddingPx = drawablePadding; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 263 | hotseatIconSizePx = (int) (Utilities.pxFromDp(inv.hotseatIconSize, dm) * scale); |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 264 | allAppsIconSizePx = iconSizePx; |
| 265 | allAppsIconDrawablePaddingPx = iconDrawablePaddingPx; |
| 266 | allAppsIconTextSizePx = iconTextSizePx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 267 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 268 | cellWidthPx = iconSizePx; |
Sunny Goyal | baec6ff | 2016-09-14 11:26:21 -0700 | [diff] [blame] | 269 | cellHeightPx = iconSizePx + iconDrawablePaddingPx |
| 270 | + Utilities.calculateTextHeight(iconTextSizePx); |
Tony Wickham | e0c3323 | 2016-02-08 11:37:04 -0800 | [diff] [blame] | 271 | final float scaleDps = !FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND ? 0f |
| 272 | : res.getDimensionPixelSize(R.dimen.dragViewScale); |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 273 | dragViewScale = (iconSizePx + scaleDps) / iconSizePx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 274 | |
| 275 | // Hotseat |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 276 | hotseatCellWidthPx = iconSizePx; |
| 277 | hotseatCellHeightPx = iconSizePx; |
| 278 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 279 | if (!isVerticalBarLayout()) { |
| 280 | int expectedWorkspaceHeight = availableHeightPx - hotseatBarHeightPx |
| 281 | - pageIndicatorHeightPx - topWorkspacePadding; |
| 282 | float minRequiredHeight = dropTargetBarSizePx + workspaceSpringLoadedBottomSpace; |
| 283 | workspaceSpringLoadShrinkFactor = Math.min( |
| 284 | res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f, |
| 285 | 1 - (minRequiredHeight / expectedWorkspaceHeight)); |
| 286 | } else { |
| 287 | workspaceSpringLoadShrinkFactor = |
| 288 | res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f; |
| 289 | } |
| 290 | |
Sunny Goyal | baec6ff | 2016-09-14 11:26:21 -0700 | [diff] [blame] | 291 | // Folder icon |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 292 | folderBackgroundOffset = -edgeMarginPx; |
| 293 | folderIconSizePx = iconSizePx + 2 * -folderBackgroundOffset; |
Adam Cohen | efca027 | 2016-02-24 19:19:06 -0800 | [diff] [blame] | 294 | folderIconPreviewPadding = res.getDimensionPixelSize(R.dimen.folder_preview_padding); |
Winson Chung | 0f78572 | 2015-04-08 10:27:49 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 297 | private void updateAvailableFolderCellDimensions(DisplayMetrics dm, Resources res) { |
| 298 | int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_padding_top) |
| 299 | + res.getDimensionPixelSize(R.dimen.folder_label_padding_bottom) |
| 300 | + Utilities.calculateTextHeight(res.getDimension(R.dimen.folder_label_text_size)); |
| 301 | |
| 302 | updateFolderCellSize(1f, dm, res, folderBottomPanelSize); |
| 303 | |
| 304 | // Check to see if the icons fit within the available height. If not, then scale down. |
| 305 | float usedHeight = (folderCellHeightPx * inv.numFolderRows) + folderBottomPanelSize; |
| 306 | int maxHeight = availableHeightPx - getTotalWorkspacePadding().y - (2 * edgeMarginPx); |
| 307 | if (usedHeight > maxHeight) { |
| 308 | float scale = maxHeight / usedHeight; |
| 309 | updateFolderCellSize(scale, dm, res, folderBottomPanelSize); |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | private void updateFolderCellSize(float scale, DisplayMetrics dm, Resources res, |
| 314 | int folderBottomPanelSize) { |
| 315 | folderChildIconSizePx = (int) (Utilities.pxFromDp(inv.iconSize, dm) * scale); |
| 316 | folderChildTextSizePx = |
| 317 | (int) (res.getDimensionPixelSize(R.dimen.folder_child_text_size) * scale); |
| 318 | |
| 319 | int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx); |
| 320 | int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding) * scale); |
| 321 | int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding) * scale); |
| 322 | |
| 323 | // Don't let the folder get too close to the edges of the screen. |
| 324 | folderCellWidthPx = Math.min(folderChildIconSizePx + 2 * cellPaddingX, |
| 325 | (availableWidthPx - 4 * edgeMarginPx) / inv.numFolderColumns); |
| 326 | folderCellHeightPx = Math.min(folderChildIconSizePx + 2 * cellPaddingY + textHeight, |
| 327 | (availableHeightPx - 4 * edgeMarginPx - folderBottomPanelSize) / inv.numFolderRows); |
| 328 | folderChildDrawablePaddingPx = Math.max(0, |
| 329 | (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3); |
| 330 | } |
| 331 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 332 | public void updateInsets(Rect insets) { |
| 333 | mInsets.set(insets); |
| 334 | } |
| 335 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 336 | public void updateAppsViewNumCols() { |
| 337 | allAppsNumCols = allAppsNumPredictiveCols = inv.numColumns; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 340 | /** Returns the width and height of the search bar, ignoring any padding. */ |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 341 | public Point getSearchBarDimensForWidgetOpts() { |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 342 | if (isVerticalBarLayout()) { |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 343 | return new Point(dropTargetBarSizePx, availableHeightPx - 2 * edgeMarginPx); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 344 | } else { |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 345 | int gap; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 346 | if (isTablet) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 347 | // Pad the left and right of the workspace to ensure consistent spacing |
| 348 | // between all icons |
Winson Chung | 4f3bfad | 2015-07-13 11:14:30 -0700 | [diff] [blame] | 349 | int width = getCurrentWidth(); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 350 | // XXX: If the icon size changes across orientations, we will have to take |
| 351 | // that into account here too. |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 352 | gap = ((width - 2 * edgeMarginPx |
| 353 | - (inv.numColumns * cellWidthPx)) / (2 * (inv.numColumns + 1))) |
| 354 | + edgeMarginPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 355 | } else { |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 356 | gap = desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.right; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 357 | } |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 358 | return new Point(availableWidthPx - 2 * gap, dropTargetBarSizePx); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 359 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 362 | public Point getCellSize() { |
| 363 | Point result = new Point(); |
| 364 | // Since we are only concerned with the overall padding, layout direction does |
| 365 | // not matter. |
Sunny Goyal | 6c2975e | 2016-07-06 09:47:56 -0700 | [diff] [blame] | 366 | Point padding = getTotalWorkspacePadding(); |
| 367 | result.x = calculateCellWidth(availableWidthPx - padding.x, inv.numColumns); |
| 368 | result.y = calculateCellHeight(availableHeightPx - padding.y, inv.numRows); |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 369 | return result; |
| 370 | } |
| 371 | |
Sunny Goyal | 6c2975e | 2016-07-06 09:47:56 -0700 | [diff] [blame] | 372 | public Point getTotalWorkspacePadding() { |
Sunny Goyal | 6178f13 | 2016-07-11 17:30:03 -0700 | [diff] [blame] | 373 | Rect padding = getWorkspacePadding(null); |
Sunny Goyal | 6c2975e | 2016-07-06 09:47:56 -0700 | [diff] [blame] | 374 | return new Point(padding.left + padding.right, padding.top + padding.bottom); |
| 375 | } |
| 376 | |
| 377 | /** |
| 378 | * Returns the workspace padding in the specified orientation. |
| 379 | * Note that it assumes that while in verticalBarLayout, the nav bar is on the right, as such |
| 380 | * this value is not reliable. |
| 381 | * Use {@link #getTotalWorkspacePadding()} instead. |
| 382 | */ |
Sunny Goyal | 6178f13 | 2016-07-11 17:30:03 -0700 | [diff] [blame] | 383 | public Rect getWorkspacePadding(Rect recycle) { |
| 384 | Rect padding = recycle == null ? new Rect() : recycle; |
Tony Wickham | 3a3517f | 2015-10-06 11:27:04 -0700 | [diff] [blame] | 385 | if (isVerticalBarLayout()) { |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 386 | if (mInsets.left > 0) { |
| 387 | padding.set(mInsets.left + pageIndicatorLandGutterLeftNavBarPx, 0, |
| 388 | hotseatBarHeightPx + hotseatLandGutterPx - mInsets.left, 2 * edgeMarginPx); |
| 389 | } else { |
| 390 | padding.set(pageIndicatorLandGutterRightNavBarPx, 0, |
| 391 | hotseatBarHeightPx + hotseatLandGutterPx, 2 * edgeMarginPx); |
| 392 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 393 | } else { |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 394 | int paddingBottom = hotseatBarHeightPx + pageIndicatorHeightPx; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 395 | if (isTablet) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 396 | // Pad the left and right of the workspace to ensure consistent spacing |
| 397 | // between all icons |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 398 | float gapScale = 1f + (dragViewScale - 1f) / 2f; |
Winson Chung | 4f3bfad | 2015-07-13 11:14:30 -0700 | [diff] [blame] | 399 | int width = getCurrentWidth(); |
| 400 | int height = getCurrentHeight(); |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 401 | // The amount of screen space available for left/right padding. |
| 402 | int availablePaddingX = Math.max(0, width - (int) ((inv.numColumns * cellWidthPx) + |
| 403 | ((inv.numColumns - 1) * gapScale * cellWidthPx))); |
| 404 | availablePaddingX = (int) Math.min(availablePaddingX, |
| 405 | width * MAX_HORIZONTAL_PADDING_PERCENT); |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 406 | int availablePaddingY = Math.max(0, height - topWorkspacePadding - paddingBottom |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 407 | - (int) (2 * inv.numRows * cellHeightPx)); |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 408 | padding.set(availablePaddingX / 2, topWorkspacePadding + availablePaddingY / 2, |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 409 | availablePaddingX / 2, paddingBottom + availablePaddingY / 2); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 410 | } else { |
| 411 | // Pad the top and bottom of the workspace with search/hotseat bar sizes |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 412 | padding.set(desiredWorkspaceLeftRightMarginPx, |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 413 | topWorkspacePadding, |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 414 | desiredWorkspaceLeftRightMarginPx, |
Winson | fadbe8f | 2016-07-22 16:35:37 -0700 | [diff] [blame] | 415 | paddingBottom); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 416 | } |
| 417 | } |
| 418 | return padding; |
| 419 | } |
| 420 | |
Winson | fadbe8f | 2016-07-22 16:35:37 -0700 | [diff] [blame] | 421 | /** |
| 422 | * @return the bounds for which the open folders should be contained within |
| 423 | */ |
| 424 | public Rect getAbsoluteOpenFolderBounds() { |
| 425 | if (isVerticalBarLayout()) { |
| 426 | // Folders should only appear right of the drop target bar and left of the hotseat |
| 427 | return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx, |
| 428 | mInsets.top, |
| 429 | mInsets.left + availableWidthPx - hotseatBarHeightPx - edgeMarginPx, |
| 430 | mInsets.top + availableHeightPx); |
| 431 | } else { |
| 432 | // Folders should only appear below the drop target bar and above the hotseat |
| 433 | return new Rect(mInsets.left, |
| 434 | mInsets.top + dropTargetBarSizePx + edgeMarginPx, |
| 435 | mInsets.left + availableWidthPx, |
| 436 | mInsets.top + availableHeightPx - hotseatBarHeightPx - pageIndicatorHeightPx - |
| 437 | edgeMarginPx); |
| 438 | } |
| 439 | } |
| 440 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 441 | private int getWorkspacePageSpacing() { |
Tony Wickham | 3a3517f | 2015-10-06 11:27:04 -0700 | [diff] [blame] | 442 | if (isVerticalBarLayout() || isLargeTablet) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 443 | // In landscape mode the page spacing is set to the default. |
| 444 | return defaultPageSpacingPx; |
| 445 | } else { |
| 446 | // In portrait, we want the pages spaced such that there is no |
| 447 | // overhang of the previous / next page into the current page viewport. |
| 448 | // We assume symmetrical padding in portrait mode. |
Winson | 11439c5 | 2016-07-20 14:25:07 -0700 | [diff] [blame] | 449 | return Math.max(defaultPageSpacingPx, getWorkspacePadding(null).left + 1); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 450 | } |
| 451 | } |
| 452 | |
Winson Chung | 4f7eb40 | 2015-07-10 18:00:48 -0700 | [diff] [blame] | 453 | int getOverviewModeButtonBarHeight() { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 454 | int zoneHeight = (int) (overviewModeIconZoneRatio * availableHeightPx); |
| 455 | zoneHeight = Math.min(overviewModeMaxIconZoneHeightPx, |
| 456 | Math.max(overviewModeMinIconZoneHeightPx, zoneHeight)); |
Winson Chung | 4f7eb40 | 2015-07-10 18:00:48 -0700 | [diff] [blame] | 457 | return zoneHeight; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 460 | public static int calculateCellWidth(int width, int countX) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 461 | return width / countX; |
| 462 | } |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 463 | public static int calculateCellHeight(int height, int countY) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 464 | return height / countY; |
| 465 | } |
| 466 | |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 467 | /** |
Tony Wickham | 55616cd | 2015-09-23 14:55:17 -0700 | [diff] [blame] | 468 | * When {@code true}, the device is in landscape mode and the hotseat is on the right column. |
| 469 | * When {@code false}, either device is in portrait mode or the device is in landscape mode and |
| 470 | * the hotseat is on the bottom row. |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 471 | */ |
Tony Wickham | ab946a1 | 2015-09-16 15:38:16 -0700 | [diff] [blame] | 472 | public boolean isVerticalBarLayout() { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 473 | return isLandscape && transposeLayoutWithOrientation; |
| 474 | } |
| 475 | |
| 476 | boolean shouldFadeAdjacentWorkspaceScreens() { |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 477 | return isVerticalBarLayout() || isLargeTablet; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 480 | private int getVisibleChildCount(ViewGroup parent) { |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 481 | int visibleChildren = 0; |
| 482 | for (int i = 0; i < parent.getChildCount(); i++) { |
| 483 | if (parent.getChildAt(i).getVisibility() != View.GONE) { |
| 484 | visibleChildren++; |
| 485 | } |
| 486 | } |
| 487 | return visibleChildren; |
| 488 | } |
| 489 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 490 | public void layout(Launcher launcher, boolean notifyListeners) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 491 | FrameLayout.LayoutParams lp; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 492 | boolean hasVerticalBarLayout = isVerticalBarLayout(); |
| 493 | |
| 494 | // Layout the search bar space |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 495 | Point searchBarBounds = getSearchBarDimensForWidgetOpts(); |
| 496 | View searchBar = launcher.getDropTargetBar(); |
Sunny Goyal | f37a214 | 2016-03-24 17:28:25 -0700 | [diff] [blame] | 497 | lp = (FrameLayout.LayoutParams) searchBar.getLayoutParams(); |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 498 | lp.width = searchBarBounds.x; |
| 499 | lp.height = searchBarBounds.y; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 500 | lp.topMargin = mInsets.top + edgeMarginPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 501 | searchBar.setLayoutParams(lp); |
| 502 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 503 | // Layout the workspace |
| 504 | PagedView workspace = (PagedView) launcher.findViewById(R.id.workspace); |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 505 | Rect workspacePadding = getWorkspacePadding(null); |
| 506 | workspace.setPadding(workspacePadding.left, workspacePadding.top, workspacePadding.right, |
| 507 | workspacePadding.bottom); |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 508 | workspace.setPageSpacing(getWorkspacePageSpacing()); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 509 | |
Sunny Goyal | 6178f13 | 2016-07-11 17:30:03 -0700 | [diff] [blame] | 510 | View qsbContainer = launcher.getQsbContainer(); |
| 511 | lp = (FrameLayout.LayoutParams) qsbContainer.getLayoutParams(); |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 512 | lp.topMargin = mInsets.top + workspacePadding.top; |
Sunny Goyal | 6178f13 | 2016-07-11 17:30:03 -0700 | [diff] [blame] | 513 | qsbContainer.setLayoutParams(lp); |
| 514 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 515 | // Layout the hotseat |
Winson | 6231ede | 2016-07-20 17:21:55 -0700 | [diff] [blame] | 516 | Hotseat hotseat = (Hotseat) launcher.findViewById(R.id.hotseat); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 517 | lp = (FrameLayout.LayoutParams) hotseat.getLayoutParams(); |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 518 | // We want the edges of the hotseat to line up with the edges of the workspace, but the |
| 519 | // icons in the hotseat are a different size, and so don't line up perfectly. To account for |
| 520 | // this, we pad the left and right of the hotseat with half of the difference of a workspace |
| 521 | // cell vs a hotseat cell. |
| 522 | float workspaceCellWidth = (float) getCurrentWidth() / inv.numColumns; |
| 523 | float hotseatCellWidth = (float) getCurrentWidth() / inv.numHotseatIcons; |
| 524 | int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 525 | if (hasVerticalBarLayout) { |
Winson Chung | f8c6f88 | 2015-06-03 11:27:26 -0700 | [diff] [blame] | 526 | // Vertical hotseat -- The hotseat is fixed in the layout to be on the right of the |
| 527 | // screen regardless of RTL |
| 528 | lp.gravity = Gravity.RIGHT; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 529 | lp.width = hotseatBarHeightPx + mInsets.left + mInsets.right; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 530 | lp.height = LayoutParams.MATCH_PARENT; |
Winson | 6231ede | 2016-07-20 17:21:55 -0700 | [diff] [blame] | 531 | hotseat.getLayout().setPadding(mInsets.left, mInsets.top, mInsets.right, |
| 532 | workspacePadding.bottom); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 533 | } else if (isTablet) { |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 534 | // Pad the hotseat with the workspace padding calculated above |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 535 | lp.gravity = Gravity.BOTTOM; |
| 536 | lp.width = LayoutParams.MATCH_PARENT; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 537 | lp.height = hotseatBarHeightPx + mInsets.bottom; |
Winson | 6231ede | 2016-07-20 17:21:55 -0700 | [diff] [blame] | 538 | hotseat.getLayout().setPadding(hotseatAdjustment + workspacePadding.left, |
| 539 | hotseatBarTopPaddingPx, hotseatAdjustment + workspacePadding.right, |
| 540 | mInsets.bottom); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 541 | } else { |
| 542 | // For phones, layout the hotseat without any bottom margin |
| 543 | // to ensure that we have space for the folders |
| 544 | lp.gravity = Gravity.BOTTOM; |
| 545 | lp.width = LayoutParams.MATCH_PARENT; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 546 | lp.height = hotseatBarHeightPx + mInsets.bottom; |
Winson | 6231ede | 2016-07-20 17:21:55 -0700 | [diff] [blame] | 547 | hotseat.getLayout().setPadding(hotseatAdjustment + workspacePadding.left, |
| 548 | hotseatBarTopPaddingPx, hotseatAdjustment + workspacePadding.right, |
| 549 | mInsets.bottom); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 550 | } |
| 551 | hotseat.setLayoutParams(lp); |
| 552 | |
| 553 | // Layout the page indicators |
| 554 | View pageIndicator = launcher.findViewById(R.id.page_indicator); |
| 555 | if (pageIndicator != null) { |
Hyunyoung Song | 7d2fc81 | 2016-06-15 12:51:30 -0700 | [diff] [blame] | 556 | lp = (FrameLayout.LayoutParams) pageIndicator.getLayoutParams(); |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 557 | if (isVerticalBarLayout()) { |
| 558 | if (mInsets.left > 0) { |
| 559 | lp.leftMargin = mInsets.left + pageIndicatorLandGutterLeftNavBarPx - |
| 560 | lp.width - pageIndicatorLandWorkspaceOffsetPx; |
| 561 | } else if (mInsets.right > 0) { |
| 562 | lp.leftMargin = pageIndicatorLandGutterRightNavBarPx - lp.width - |
| 563 | pageIndicatorLandWorkspaceOffsetPx; |
| 564 | } |
| 565 | lp.bottomMargin = workspacePadding.bottom; |
| 566 | } else { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 567 | // Put the page indicators above the hotseat |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 568 | lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 569 | lp.height = pageIndicatorHeightPx; |
| 570 | lp.bottomMargin = hotseatBarHeightPx + mInsets.bottom; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 571 | } |
Hyunyoung Song | 7d2fc81 | 2016-06-15 12:51:30 -0700 | [diff] [blame] | 572 | pageIndicator.setLayoutParams(lp); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 573 | } |
| 574 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 575 | // Layout the Overview Mode |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 576 | ViewGroup overviewMode = launcher.getOverviewPanel(); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 577 | if (overviewMode != null) { |
Sunny Goyal | 8dfe2da | 2014-10-24 16:26:52 -0700 | [diff] [blame] | 578 | int visibleChildCount = getVisibleChildCount(overviewMode); |
| 579 | int totalItemWidth = visibleChildCount * overviewModeBarItemWidthPx; |
Jon Miranda | df3bc52 | 2016-11-01 16:55:56 -0700 | [diff] [blame] | 580 | int maxWidth = totalItemWidth + (visibleChildCount - 1) * overviewModeBarSpacerWidthPx; |
Sunny Goyal | 8dfe2da | 2014-10-24 16:26:52 -0700 | [diff] [blame] | 581 | |
Jon Miranda | df3bc52 | 2016-11-01 16:55:56 -0700 | [diff] [blame] | 582 | lp = (FrameLayout.LayoutParams) overviewMode.getLayoutParams(); |
Sunny Goyal | 8dfe2da | 2014-10-24 16:26:52 -0700 | [diff] [blame] | 583 | lp.width = Math.min(availableWidthPx, maxWidth); |
Jon Miranda | df3bc52 | 2016-11-01 16:55:56 -0700 | [diff] [blame] | 584 | lp.height = getOverviewModeButtonBarHeight() + mInsets.bottom; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 585 | overviewMode.setLayoutParams(lp); |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 586 | } |
Sunny Goyal | 8dfe2da | 2014-10-24 16:26:52 -0700 | [diff] [blame] | 587 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 588 | if (notifyListeners) { |
| 589 | for (int i = mListeners.size() - 1; i >= 0; i--) { |
| 590 | mListeners.get(i).onLauncherLayoutChanged(); |
Sunny Goyal | 8dfe2da | 2014-10-24 16:26:52 -0700 | [diff] [blame] | 591 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 592 | } |
| 593 | } |
Winson Chung | 4f3bfad | 2015-07-13 11:14:30 -0700 | [diff] [blame] | 594 | |
| 595 | private int getCurrentWidth() { |
| 596 | return isLandscape |
| 597 | ? Math.max(widthPx, heightPx) |
| 598 | : Math.min(widthPx, heightPx); |
| 599 | } |
| 600 | |
| 601 | private int getCurrentHeight() { |
| 602 | return isLandscape |
| 603 | ? Math.min(widthPx, heightPx) |
| 604 | : Math.max(widthPx, heightPx); |
| 605 | } |
Sunny Goyal | 13178ac | 2016-04-04 16:35:22 -0700 | [diff] [blame] | 606 | |
| 607 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 608 | /** |
| 609 | * @return the left/right paddings for all containers. |
| 610 | */ |
Jon Miranda | c3e4e22 | 2016-11-02 16:56:52 -0700 | [diff] [blame] | 611 | public final int[] getContainerPadding() { |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 612 | // No paddings for portrait phone |
| 613 | if (isPhone && !isVerticalBarLayout()) { |
| 614 | return new int[] {0, 0}; |
Sunny Goyal | 13178ac | 2016-04-04 16:35:22 -0700 | [diff] [blame] | 615 | } |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 616 | |
Hyunyoung Song | 9d96fd5 | 2016-08-23 11:06:24 -0700 | [diff] [blame] | 617 | // In landscape, we match the width of the workspace |
| 618 | int padding = (pageIndicatorLandGutterRightNavBarPx + |
| 619 | hotseatBarHeightPx + hotseatLandGutterPx + mInsets.left) / 2; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 620 | return new int[]{ padding, padding }; |
Sunny Goyal | 13178ac | 2016-04-04 16:35:22 -0700 | [diff] [blame] | 621 | } |
Jon Miranda | cc42c5b | 2016-10-27 17:15:27 -0700 | [diff] [blame] | 622 | |
Jon Miranda | 51f037d | 2016-11-07 08:37:20 -0800 | [diff] [blame] | 623 | public boolean shouldIgnoreLongPressToOverview(float touchX) { |
Jon Miranda | cc42c5b | 2016-10-27 17:15:27 -0700 | [diff] [blame] | 624 | boolean inMultiWindowMode = this != inv.landscapeProfile && this != inv.portraitProfile; |
Jon Miranda | 51f037d | 2016-11-07 08:37:20 -0800 | [diff] [blame] | 625 | boolean touchedLhsEdge = mInsets.left == 0 && touchX < edgeMarginPx; |
| 626 | boolean touchedRhsEdge = mInsets.right == 0 && touchX > (widthPx - edgeMarginPx); |
Jon Miranda | cc42c5b | 2016-10-27 17:15:27 -0700 | [diff] [blame] | 627 | return !inMultiWindowMode && (touchedLhsEdge || touchedRhsEdge); |
| 628 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 629 | } |