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