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