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