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