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; |
Sunny Goyal | 8dfe2da | 2014-10-24 16:26:52 -0700 | [diff] [blame] | 32 | import android.view.ViewGroup.MarginLayoutParams; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 33 | import android.widget.FrameLayout; |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 34 | import android.widget.LinearLayout; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 35 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 36 | public class DeviceProfile { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 37 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 38 | public final InvariantDeviceProfile inv; |
Winson Chung | be87647 | 2014-05-14 14:15:20 -0700 | [diff] [blame] | 39 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 40 | // Device properties |
| 41 | public final boolean isTablet; |
| 42 | public final boolean isLargeTablet; |
| 43 | public final boolean isPhone; |
| 44 | public final boolean transposeLayoutWithOrientation; |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 45 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 46 | // Device properties in current orientation |
| 47 | public final boolean isLandscape; |
| 48 | public final int widthPx; |
| 49 | public final int heightPx; |
| 50 | public final int availableWidthPx; |
| 51 | public final int availableHeightPx; |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 52 | /** |
| 53 | * The maximum amount of left/right workspace padding as a percentage of the screen width. |
| 54 | * To be clear, this means that up to 7% of the screen width can be used as left padding, and |
| 55 | * 7% of the screen width can be used as right padding. |
| 56 | */ |
| 57 | private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 58 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 59 | // Overview mode |
| 60 | private final int overviewModeMinIconZoneHeightPx; |
| 61 | private final int overviewModeMaxIconZoneHeightPx; |
| 62 | private final int overviewModeBarItemWidthPx; |
| 63 | private final int overviewModeBarSpacerWidthPx; |
| 64 | private final float overviewModeIconZoneRatio; |
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 | // Workspace |
| 67 | private int desiredWorkspaceLeftRightMarginPx; |
| 68 | public final int edgeMarginPx; |
| 69 | public final Rect defaultWidgetPadding; |
| 70 | private final int pageIndicatorHeightPx; |
| 71 | private final int defaultPageSpacingPx; |
| 72 | private float dragViewScale; |
| 73 | |
| 74 | // Workspace icons |
| 75 | public int iconSizePx; |
| 76 | public int iconTextSizePx; |
| 77 | public int iconDrawablePaddingPx; |
Winson Chung | 5f4e0fd | 2015-05-22 11:12:27 -0700 | [diff] [blame] | 78 | public int iconDrawablePaddingOriginalPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 79 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 80 | public int cellWidthPx; |
| 81 | public int cellHeightPx; |
| 82 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 83 | // Folder |
| 84 | public int folderBackgroundOffset; |
| 85 | public int folderIconSizePx; |
| 86 | public int folderCellWidthPx; |
| 87 | public int folderCellHeightPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 88 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 89 | // Hotseat |
| 90 | public int hotseatCellWidthPx; |
| 91 | public int hotseatCellHeightPx; |
| 92 | public int hotseatIconSizePx; |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 93 | private int normalHotseatBarHeightPx, shortHotseatBarHeightPx; |
Tony Wickham | 55616cd | 2015-09-23 14:55:17 -0700 | [diff] [blame] | 94 | private int hotseatBarHeightPx; // One of the above. |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 95 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 96 | // All apps |
Winson Chung | 5f4e0fd | 2015-05-22 11:12:27 -0700 | [diff] [blame] | 97 | public int allAppsNumCols; |
| 98 | public int allAppsNumPredictiveCols; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 99 | public int allAppsButtonVisualSize; |
| 100 | public final int allAppsIconSizePx; |
| 101 | public final int allAppsIconTextSizePx; |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 102 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 103 | // QSB |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 104 | private int searchBarWidgetInternalPaddingTop, searchBarWidgetInternalPaddingBottom; |
| 105 | private int searchBarTopPaddingPx; |
| 106 | private int normalSearchBarBottomPaddingPx, tallSearchBarBottomPaddingPx; |
| 107 | private int searchBarBottomPaddingPx; // One of the above. |
| 108 | private int normalSearchBarSpaceHeightPx, tallSearchBarSpaceHeightPx; |
Tony Wickham | 55616cd | 2015-09-23 14:55:17 -0700 | [diff] [blame] | 109 | private int searchBarSpaceHeightPx; // One of the above. |
Adam Cohen | 4ae96ce | 2014-08-29 15:05:48 -0700 | [diff] [blame] | 110 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 111 | public DeviceProfile(Context context, InvariantDeviceProfile inv, |
| 112 | Point minSize, Point maxSize, |
| 113 | int width, int height, boolean isLandscape) { |
Sunny Goyal | fee35bb | 2015-05-11 11:38:19 -0700 | [diff] [blame] | 114 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 115 | this.inv = inv; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 116 | this.isLandscape = isLandscape; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 117 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 118 | Resources res = context.getResources(); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 119 | DisplayMetrics dm = res.getDisplayMetrics(); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 120 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 121 | // Constants from resources |
| 122 | isTablet = res.getBoolean(R.bool.is_tablet); |
| 123 | isLargeTablet = res.getBoolean(R.bool.is_large_tablet); |
| 124 | isPhone = !isTablet && !isLargeTablet; |
| 125 | |
| 126 | // Some more constants |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 127 | transposeLayoutWithOrientation = |
| 128 | res.getBoolean(R.bool.hotseat_transpose_layout_with_orientation); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 129 | |
| 130 | ComponentName cn = new ComponentName(context.getPackageName(), |
| 131 | this.getClass().getName()); |
| 132 | defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null); |
| 133 | edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin); |
| 134 | desiredWorkspaceLeftRightMarginPx = 2 * edgeMarginPx; |
| 135 | pageIndicatorHeightPx = |
| 136 | res.getDimensionPixelSize(R.dimen.dynamic_grid_page_indicator_height); |
| 137 | defaultPageSpacingPx = |
| 138 | res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_page_spacing); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 139 | overviewModeMinIconZoneHeightPx = |
| 140 | res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_min_icon_zone_height); |
| 141 | overviewModeMaxIconZoneHeightPx = |
| 142 | res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_max_icon_zone_height); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 143 | overviewModeBarItemWidthPx = |
| 144 | res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_bar_item_width); |
| 145 | overviewModeBarSpacerWidthPx = |
| 146 | res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_bar_spacer_width); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 147 | overviewModeIconZoneRatio = |
| 148 | res.getInteger(R.integer.config_dynamic_grid_overview_icon_zone_percentage) / 100f; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 149 | iconDrawablePaddingOriginalPx = |
| 150 | res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 151 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 152 | // AllApps uses the original non-scaled icon text size |
| 153 | allAppsIconTextSizePx = Utilities.pxFromDp(inv.iconTextSize, dm); |
| 154 | |
| 155 | // AllApps uses the original non-scaled icon size |
| 156 | allAppsIconSizePx = Utilities.pxFromDp(inv.iconSize, dm); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 157 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 158 | // Determine sizes. |
| 159 | widthPx = width; |
| 160 | heightPx = height; |
| 161 | if (isLandscape) { |
| 162 | availableWidthPx = maxSize.x; |
| 163 | availableHeightPx = minSize.y; |
| 164 | } else { |
| 165 | availableWidthPx = minSize.x; |
| 166 | availableHeightPx = maxSize.y; |
| 167 | } |
Adam Cohen | 4ae96ce | 2014-08-29 15:05:48 -0700 | [diff] [blame] | 168 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 169 | // Calculate the remaining vars |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 170 | updateAvailableDimensions(dm, res); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 171 | computeAllAppsButtonSize(context); |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Determine the exact visual footprint of the all apps button, taking into account scaling |
| 176 | * and internal padding of the drawable. |
| 177 | */ |
| 178 | private void computeAllAppsButtonSize(Context context) { |
| 179 | Resources res = context.getResources(); |
| 180 | float padding = res.getInteger(R.integer.config_allAppsButtonPaddingPercent) / 100f; |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 181 | allAppsButtonVisualSize = (int) (hotseatIconSizePx * (1 - padding)) - context.getResources() |
| 182 | .getDimensionPixelSize(R.dimen.all_apps_button_scale_down); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 185 | private void updateAvailableDimensions(DisplayMetrics dm, Resources res) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 186 | // Check to see if the icons fit in the new available height. If not, then we need to |
| 187 | // shrink the icon size. |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 188 | float scale = 1f; |
| 189 | int drawablePadding = iconDrawablePaddingOriginalPx; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 190 | updateIconSize(1f, drawablePadding, res, dm); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 191 | float usedHeight = (cellHeightPx * inv.numRows); |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 192 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 193 | // We only care about the top and bottom workspace padding, which is not affected by RTL. |
| 194 | Rect workspacePadding = getWorkspacePadding(false /* isLayoutRtl */); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 195 | int maxHeight = (availableHeightPx - workspacePadding.top - workspacePadding.bottom); |
| 196 | if (usedHeight > maxHeight) { |
| 197 | scale = maxHeight / usedHeight; |
| 198 | drawablePadding = 0; |
| 199 | } |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 200 | updateIconSize(scale, drawablePadding, res, dm); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 201 | } |
| 202 | |
Winson Chung | 93f98ea | 2015-03-10 16:28:47 -0700 | [diff] [blame] | 203 | private void updateIconSize(float scale, int drawablePadding, Resources res, |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 204 | DisplayMetrics dm) { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 205 | iconSizePx = (int) (Utilities.pxFromDp(inv.iconSize, dm) * scale); |
| 206 | iconTextSizePx = (int) (Utilities.pxFromSp(inv.iconTextSize, dm) * scale); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 207 | iconDrawablePaddingPx = drawablePadding; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 208 | hotseatIconSizePx = (int) (Utilities.pxFromDp(inv.hotseatIconSize, dm) * scale); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 209 | |
| 210 | // Search Bar |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 211 | normalSearchBarSpaceHeightPx = res.getDimensionPixelSize( |
| 212 | R.dimen.dynamic_grid_search_bar_height); |
| 213 | tallSearchBarSpaceHeightPx = res.getDimensionPixelSize( |
| 214 | R.dimen.dynamic_grid_search_bar_height_tall); |
| 215 | searchBarWidgetInternalPaddingTop = res.getDimensionPixelSize( |
| 216 | R.dimen.qsb_internal_padding_top); |
| 217 | searchBarWidgetInternalPaddingBottom = res.getDimensionPixelSize( |
| 218 | R.dimen.qsb_internal_padding_bottom); |
| 219 | if (isTablet && !isVerticalBarLayout()) { |
| 220 | searchBarTopPaddingPx = searchBarWidgetInternalPaddingTop; |
| 221 | normalSearchBarBottomPaddingPx = searchBarWidgetInternalPaddingBottom + |
| 222 | res.getDimensionPixelSize(R.dimen.dynamic_grid_search_bar_bottom_padding_tablet); |
| 223 | tallSearchBarBottomPaddingPx = normalSearchBarBottomPaddingPx; |
| 224 | } else { |
| 225 | searchBarTopPaddingPx = searchBarWidgetInternalPaddingTop; |
| 226 | normalSearchBarBottomPaddingPx = searchBarWidgetInternalPaddingBottom + |
| 227 | res.getDimensionPixelSize(R.dimen.dynamic_grid_search_bar_bottom_padding); |
| 228 | tallSearchBarBottomPaddingPx = searchBarWidgetInternalPaddingBottom + |
| 229 | res.getDimensionPixelSize(R.dimen.dynamic_grid_search_bar_bottom_padding_short); |
| 230 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 231 | |
| 232 | // Calculate the actual text height |
| 233 | Paint textPaint = new Paint(); |
| 234 | textPaint.setTextSize(iconTextSizePx); |
| 235 | FontMetrics fm = textPaint.getFontMetrics(); |
| 236 | cellWidthPx = iconSizePx; |
| 237 | cellHeightPx = iconSizePx + iconDrawablePaddingPx + (int) Math.ceil(fm.bottom - fm.top); |
Winson Chung | 93f98ea | 2015-03-10 16:28:47 -0700 | [diff] [blame] | 238 | final float scaleDps = res.getDimensionPixelSize(R.dimen.dragViewScale); |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 239 | dragViewScale = (iconSizePx + scaleDps) / iconSizePx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 240 | |
| 241 | // Hotseat |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 242 | normalHotseatBarHeightPx = iconSizePx + 4 * edgeMarginPx; |
| 243 | shortHotseatBarHeightPx = iconSizePx + 2 * edgeMarginPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 244 | hotseatCellWidthPx = iconSizePx; |
| 245 | hotseatCellHeightPx = iconSizePx; |
| 246 | |
| 247 | // Folder |
Tony Wickham | 6159c24 | 2015-11-13 18:07:18 +0000 | [diff] [blame^] | 248 | int folderCellPadding = isTablet || isLandscape ? 6 * edgeMarginPx : 3 * edgeMarginPx; |
| 249 | // Don't let the folder get too close to the edges of the screen. |
| 250 | folderCellWidthPx = Math.min(cellWidthPx + folderCellPadding, |
Tony Wickham | a295048 | 2015-10-12 15:57:23 -0700 | [diff] [blame] | 251 | (availableWidthPx - 4 * edgeMarginPx) / inv.numFolderColumns); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 252 | folderCellHeightPx = cellHeightPx + edgeMarginPx; |
| 253 | folderBackgroundOffset = -edgeMarginPx; |
| 254 | folderIconSizePx = iconSizePx + 2 * -folderBackgroundOffset; |
Winson Chung | 0f78572 | 2015-04-08 10:27:49 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Winson Chung | ef7f874 | 2015-06-04 17:18:17 -0700 | [diff] [blame] | 257 | /** |
| 258 | * @param recyclerViewWidth the available width of the AllAppsRecyclerView |
| 259 | */ |
| 260 | public void updateAppsViewNumCols(Resources res, int recyclerViewWidth) { |
Winson Chung | 93f98ea | 2015-03-10 16:28:47 -0700 | [diff] [blame] | 261 | int appsViewLeftMarginPx = |
Winson Chung | 5f4e0fd | 2015-05-22 11:12:27 -0700 | [diff] [blame] | 262 | res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin); |
Winson Chung | 2c6e5cc | 2015-06-01 14:38:24 -0700 | [diff] [blame] | 263 | int allAppsCellWidthGap = |
| 264 | res.getDimensionPixelSize(R.dimen.all_apps_icon_width_gap); |
Winson Chung | ef7f874 | 2015-06-04 17:18:17 -0700 | [diff] [blame] | 265 | int availableAppsWidthPx = (recyclerViewWidth > 0) ? recyclerViewWidth : availableWidthPx; |
Winson Chung | 208ed75 | 2015-05-12 19:05:30 -0700 | [diff] [blame] | 266 | int numAppsCols = (availableAppsWidthPx - appsViewLeftMarginPx) / |
Winson Chung | 2c6e5cc | 2015-06-01 14:38:24 -0700 | [diff] [blame] | 267 | (allAppsIconSizePx + allAppsCellWidthGap); |
| 268 | int numPredictiveAppCols = Math.max(inv.minAllAppsPredictionColumns, numAppsCols); |
Winson Chung | ef7f874 | 2015-06-04 17:18:17 -0700 | [diff] [blame] | 269 | allAppsNumCols = numAppsCols; |
| 270 | allAppsNumPredictiveCols = numPredictiveAppCols; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 273 | /** Returns the amount of extra space to allocate to the search bar for vertical padding. */ |
| 274 | private int getSearchBarTotalVerticalPadding() { |
| 275 | return searchBarTopPaddingPx + searchBarBottomPaddingPx; |
| 276 | } |
| 277 | |
| 278 | /** Returns the width and height of the search bar, ignoring any padding. */ |
| 279 | public Point getSearchBarDimensForWidgetOpts(Resources res) { |
| 280 | Rect searchBarBounds = getSearchBarBounds(Utilities.isRtl(res)); |
| 281 | if (isVerticalBarLayout()) { |
| 282 | return new Point(searchBarBounds.width(), searchBarBounds.height()); |
Winson Chung | 69e04ea | 2013-12-02 14:43:44 -0800 | [diff] [blame] | 283 | } |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 284 | int widgetInternalPadding = searchBarWidgetInternalPaddingTop + |
| 285 | searchBarWidgetInternalPaddingBottom; |
| 286 | return new Point(searchBarBounds.width(), searchBarSpaceHeightPx + widgetInternalPadding); |
Winson Chung | 69e04ea | 2013-12-02 14:43:44 -0800 | [diff] [blame] | 287 | } |
| 288 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 289 | /** Returns the search bar bounds in the current orientation */ |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 290 | public Rect getSearchBarBounds(boolean isLayoutRtl) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 291 | Rect bounds = new Rect(); |
Tony Wickham | 3a3517f | 2015-10-06 11:27:04 -0700 | [diff] [blame] | 292 | if (isVerticalBarLayout()) { |
Winson Chung | 42b3c06 | 2013-12-04 12:09:59 -0800 | [diff] [blame] | 293 | if (isLayoutRtl) { |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 294 | bounds.set(availableWidthPx - normalSearchBarSpaceHeightPx, edgeMarginPx, |
Winson Chung | 42b3c06 | 2013-12-04 12:09:59 -0800 | [diff] [blame] | 295 | availableWidthPx, availableHeightPx - edgeMarginPx); |
| 296 | } else { |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 297 | bounds.set(0, edgeMarginPx, normalSearchBarSpaceHeightPx, |
Winson Chung | 42b3c06 | 2013-12-04 12:09:59 -0800 | [diff] [blame] | 298 | availableHeightPx - edgeMarginPx); |
| 299 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 300 | } else { |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 301 | int boundsBottom = searchBarSpaceHeightPx + getSearchBarTotalVerticalPadding(); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 302 | if (isTablet) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 303 | // Pad the left and right of the workspace to ensure consistent spacing |
| 304 | // between all icons |
Winson Chung | 4f3bfad | 2015-07-13 11:14:30 -0700 | [diff] [blame] | 305 | int width = getCurrentWidth(); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 306 | // XXX: If the icon size changes across orientations, we will have to take |
| 307 | // that into account here too. |
| 308 | int gap = (int) ((width - 2 * edgeMarginPx - |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 309 | (inv.numColumns * cellWidthPx)) / (2 * (inv.numColumns + 1))); |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 310 | bounds.set(edgeMarginPx + gap, 0, |
| 311 | availableWidthPx - (edgeMarginPx + gap), boundsBottom); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 312 | } else { |
Winson Chung | 2cb2471 | 2013-12-02 15:00:39 -0800 | [diff] [blame] | 313 | bounds.set(desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.left, |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 314 | 0, |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 315 | availableWidthPx - (desiredWorkspaceLeftRightMarginPx - |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 316 | defaultWidgetPadding.right), boundsBottom); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | return bounds; |
| 320 | } |
| 321 | |
| 322 | /** Returns the workspace padding in the specified orientation */ |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 323 | Rect getWorkspacePadding(boolean isLayoutRtl) { |
| 324 | Rect searchBarBounds = getSearchBarBounds(isLayoutRtl); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 325 | Rect padding = new Rect(); |
Tony Wickham | 3a3517f | 2015-10-06 11:27:04 -0700 | [diff] [blame] | 326 | if (isVerticalBarLayout()) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 327 | // Pad the left and right of the workspace with search/hotseat bar sizes |
Winson Chung | 42b3c06 | 2013-12-04 12:09:59 -0800 | [diff] [blame] | 328 | if (isLayoutRtl) { |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 329 | padding.set(normalHotseatBarHeightPx, edgeMarginPx, |
Winson Chung | 42b3c06 | 2013-12-04 12:09:59 -0800 | [diff] [blame] | 330 | searchBarBounds.width(), edgeMarginPx); |
| 331 | } else { |
| 332 | padding.set(searchBarBounds.width(), edgeMarginPx, |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 333 | normalHotseatBarHeightPx, edgeMarginPx); |
Winson Chung | 42b3c06 | 2013-12-04 12:09:59 -0800 | [diff] [blame] | 334 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 335 | } else { |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 336 | int paddingTop = searchBarBounds.bottom; |
| 337 | int paddingBottom = hotseatBarHeightPx + pageIndicatorHeightPx; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 338 | if (isTablet) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 339 | // Pad the left and right of the workspace to ensure consistent spacing |
| 340 | // between all icons |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 341 | float gapScale = 1f + (dragViewScale - 1f) / 2f; |
Winson Chung | 4f3bfad | 2015-07-13 11:14:30 -0700 | [diff] [blame] | 342 | int width = getCurrentWidth(); |
| 343 | int height = getCurrentHeight(); |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 344 | // The amount of screen space available for left/right padding. |
| 345 | int availablePaddingX = Math.max(0, width - (int) ((inv.numColumns * cellWidthPx) + |
| 346 | ((inv.numColumns - 1) * gapScale * cellWidthPx))); |
| 347 | availablePaddingX = (int) Math.min(availablePaddingX, |
| 348 | width * MAX_HORIZONTAL_PADDING_PERCENT); |
| 349 | int availablePaddingY = Math.max(0, height - paddingTop - paddingBottom |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 350 | - (int) (2 * inv.numRows * cellHeightPx)); |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 351 | padding.set(availablePaddingX / 2, paddingTop + availablePaddingY / 2, |
| 352 | availablePaddingX / 2, paddingBottom + availablePaddingY / 2); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 353 | } else { |
| 354 | // Pad the top and bottom of the workspace with search/hotseat bar sizes |
| 355 | padding.set(desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.left, |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 356 | paddingTop, |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 357 | desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.right, |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 358 | paddingBottom); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | return padding; |
| 362 | } |
| 363 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 364 | private int getWorkspacePageSpacing(boolean isLayoutRtl) { |
Tony Wickham | 3a3517f | 2015-10-06 11:27:04 -0700 | [diff] [blame] | 365 | if (isVerticalBarLayout() || isLargeTablet) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 366 | // In landscape mode the page spacing is set to the default. |
| 367 | return defaultPageSpacingPx; |
| 368 | } else { |
| 369 | // In portrait, we want the pages spaced such that there is no |
| 370 | // overhang of the previous / next page into the current page viewport. |
| 371 | // We assume symmetrical padding in portrait mode. |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 372 | return Math.max(defaultPageSpacingPx, 2 * getWorkspacePadding(isLayoutRtl).left); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 373 | } |
| 374 | } |
| 375 | |
Winson Chung | 4f7eb40 | 2015-07-10 18:00:48 -0700 | [diff] [blame] | 376 | int getOverviewModeButtonBarHeight() { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 377 | int zoneHeight = (int) (overviewModeIconZoneRatio * availableHeightPx); |
| 378 | zoneHeight = Math.min(overviewModeMaxIconZoneHeightPx, |
| 379 | Math.max(overviewModeMinIconZoneHeightPx, zoneHeight)); |
Winson Chung | 4f7eb40 | 2015-07-10 18:00:48 -0700 | [diff] [blame] | 380 | return zoneHeight; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | // The rect returned will be extended to below the system ui that covers the workspace |
| 384 | Rect getHotseatRect() { |
| 385 | if (isVerticalBarLayout()) { |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 386 | return new Rect(availableWidthPx - normalHotseatBarHeightPx, 0, |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 387 | Integer.MAX_VALUE, availableHeightPx); |
| 388 | } else { |
| 389 | return new Rect(0, availableHeightPx - hotseatBarHeightPx, |
| 390 | availableWidthPx, Integer.MAX_VALUE); |
| 391 | } |
| 392 | } |
| 393 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 394 | public static int calculateCellWidth(int width, int countX) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 395 | return width / countX; |
| 396 | } |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 397 | public static int calculateCellHeight(int height, int countY) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 398 | return height / countY; |
| 399 | } |
| 400 | |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 401 | /** |
Tony Wickham | 55616cd | 2015-09-23 14:55:17 -0700 | [diff] [blame] | 402 | * When {@code true}, the device is in landscape mode and the hotseat is on the right column. |
| 403 | * When {@code false}, either device is in portrait mode or the device is in landscape mode and |
| 404 | * the hotseat is on the bottom row. |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 405 | */ |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 406 | boolean isVerticalBarLayout() { |
| 407 | return isLandscape && transposeLayoutWithOrientation; |
| 408 | } |
| 409 | |
| 410 | boolean shouldFadeAdjacentWorkspaceScreens() { |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 411 | return isVerticalBarLayout() || isLargeTablet; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 414 | private int getVisibleChildCount(ViewGroup parent) { |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 415 | int visibleChildren = 0; |
| 416 | for (int i = 0; i < parent.getChildCount(); i++) { |
| 417 | if (parent.getChildAt(i).getVisibility() != View.GONE) { |
| 418 | visibleChildren++; |
| 419 | } |
| 420 | } |
| 421 | return visibleChildren; |
| 422 | } |
| 423 | |
Tony Wickham | eef4432 | 2015-10-20 13:24:36 -0700 | [diff] [blame] | 424 | // TODO(twickham): b/25154513 |
| 425 | public void setSearchBarHeight(int searchBarHeight) { |
| 426 | if (searchBarHeight == LauncherCallbacks.SEARCH_BAR_HEIGHT_TALL) { |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 427 | hotseatBarHeightPx = shortHotseatBarHeightPx; |
| 428 | searchBarSpaceHeightPx = tallSearchBarSpaceHeightPx; |
| 429 | searchBarBottomPaddingPx = tallSearchBarBottomPaddingPx; |
Tony Wickham | eef4432 | 2015-10-20 13:24:36 -0700 | [diff] [blame] | 430 | } else { |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 431 | hotseatBarHeightPx = normalHotseatBarHeightPx; |
| 432 | searchBarSpaceHeightPx = normalSearchBarSpaceHeightPx; |
| 433 | searchBarBottomPaddingPx = normalSearchBarBottomPaddingPx; |
Tony Wickham | eef4432 | 2015-10-20 13:24:36 -0700 | [diff] [blame] | 434 | } |
| 435 | } |
| 436 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 437 | public void layout(Launcher launcher) { |
| 438 | FrameLayout.LayoutParams lp; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 439 | boolean hasVerticalBarLayout = isVerticalBarLayout(); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 440 | final boolean isLayoutRtl = Utilities.isRtl(launcher.getResources()); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 441 | |
| 442 | // Layout the search bar space |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 443 | Rect searchBarBounds = getSearchBarBounds(isLayoutRtl); |
Winson Chung | 006ee26 | 2015-08-03 14:40:11 -0700 | [diff] [blame] | 444 | View searchBar = launcher.getSearchDropTargetBar(); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 445 | lp = (FrameLayout.LayoutParams) searchBar.getLayoutParams(); |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 446 | lp.width = searchBarBounds.width(); |
| 447 | lp.height = searchBarBounds.height(); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 448 | if (hasVerticalBarLayout) { |
Winson Chung | f8c6f88 | 2015-06-03 11:27:26 -0700 | [diff] [blame] | 449 | // Vertical search bar space -- The search bar is fixed in the layout to be on the left |
| 450 | // of the screen regardless of RTL |
Sunny Goyal | d9cc780 | 2015-04-23 14:47:19 -0700 | [diff] [blame] | 451 | lp.gravity = Gravity.LEFT; |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 452 | |
| 453 | LinearLayout targets = (LinearLayout) searchBar.findViewById(R.id.drag_target_bar); |
| 454 | targets.setOrientation(LinearLayout.VERTICAL); |
Sunny Goyal | d9cc780 | 2015-04-23 14:47:19 -0700 | [diff] [blame] | 455 | FrameLayout.LayoutParams targetsLp = (FrameLayout.LayoutParams) targets.getLayoutParams(); |
| 456 | targetsLp.gravity = Gravity.TOP; |
| 457 | targetsLp.height = LayoutParams.WRAP_CONTENT; |
| 458 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 459 | } else { |
Winson Chung | 69e04ea | 2013-12-02 14:43:44 -0800 | [diff] [blame] | 460 | // Horizontal search bar space |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 461 | lp.gravity = Gravity.TOP|Gravity.CENTER_HORIZONTAL; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 462 | } |
| 463 | searchBar.setLayoutParams(lp); |
| 464 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 465 | // Layout the workspace |
| 466 | PagedView workspace = (PagedView) launcher.findViewById(R.id.workspace); |
| 467 | lp = (FrameLayout.LayoutParams) workspace.getLayoutParams(); |
| 468 | lp.gravity = Gravity.CENTER; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 469 | Rect padding = getWorkspacePadding(isLayoutRtl); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 470 | workspace.setLayoutParams(lp); |
| 471 | workspace.setPadding(padding.left, padding.top, padding.right, padding.bottom); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 472 | workspace.setPageSpacing(getWorkspacePageSpacing(isLayoutRtl)); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 473 | |
| 474 | // Layout the hotseat |
| 475 | View hotseat = launcher.findViewById(R.id.hotseat); |
| 476 | lp = (FrameLayout.LayoutParams) hotseat.getLayoutParams(); |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 477 | // We want the edges of the hotseat to line up with the edges of the workspace, but the |
| 478 | // icons in the hotseat are a different size, and so don't line up perfectly. To account for |
| 479 | // this, we pad the left and right of the hotseat with half of the difference of a workspace |
| 480 | // cell vs a hotseat cell. |
| 481 | float workspaceCellWidth = (float) getCurrentWidth() / inv.numColumns; |
| 482 | float hotseatCellWidth = (float) getCurrentWidth() / inv.numHotseatIcons; |
| 483 | int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 484 | if (hasVerticalBarLayout) { |
Winson Chung | f8c6f88 | 2015-06-03 11:27:26 -0700 | [diff] [blame] | 485 | // Vertical hotseat -- The hotseat is fixed in the layout to be on the right of the |
| 486 | // screen regardless of RTL |
| 487 | lp.gravity = Gravity.RIGHT; |
Tony Wickham | a3c74d1 | 2015-10-23 11:43:47 -0700 | [diff] [blame] | 488 | lp.width = normalHotseatBarHeightPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 489 | lp.height = LayoutParams.MATCH_PARENT; |
| 490 | hotseat.findViewById(R.id.layout).setPadding(0, 2 * edgeMarginPx, 0, 2 * edgeMarginPx); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 491 | } else if (isTablet) { |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 492 | // Pad the hotseat with the workspace padding calculated above |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 493 | lp.gravity = Gravity.BOTTOM; |
| 494 | lp.width = LayoutParams.MATCH_PARENT; |
| 495 | lp.height = hotseatBarHeightPx; |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 496 | hotseat.findViewById(R.id.layout).setPadding( |
| 497 | hotseatAdjustment + padding.left, 0, |
| 498 | hotseatAdjustment + padding.right, 2 * edgeMarginPx); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 499 | } else { |
| 500 | // For phones, layout the hotseat without any bottom margin |
| 501 | // to ensure that we have space for the folders |
| 502 | lp.gravity = Gravity.BOTTOM; |
| 503 | lp.width = LayoutParams.MATCH_PARENT; |
| 504 | lp.height = hotseatBarHeightPx; |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 505 | hotseat.findViewById(R.id.layout).setPadding( |
| 506 | hotseatAdjustment + padding.left, 0, |
| 507 | hotseatAdjustment + padding.right, 0); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 508 | } |
| 509 | hotseat.setLayoutParams(lp); |
| 510 | |
| 511 | // Layout the page indicators |
| 512 | View pageIndicator = launcher.findViewById(R.id.page_indicator); |
| 513 | if (pageIndicator != null) { |
| 514 | if (hasVerticalBarLayout) { |
| 515 | // Hide the page indicators when we have vertical search/hotseat |
| 516 | pageIndicator.setVisibility(View.GONE); |
| 517 | } else { |
| 518 | // Put the page indicators above the hotseat |
| 519 | lp = (FrameLayout.LayoutParams) pageIndicator.getLayoutParams(); |
| 520 | lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 521 | lp.width = LayoutParams.WRAP_CONTENT; |
| 522 | lp.height = LayoutParams.WRAP_CONTENT; |
| 523 | lp.bottomMargin = hotseatBarHeightPx; |
| 524 | pageIndicator.setLayoutParams(lp); |
| 525 | } |
| 526 | } |
| 527 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 528 | // Layout the Overview Mode |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 529 | ViewGroup overviewMode = launcher.getOverviewPanel(); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 530 | if (overviewMode != null) { |
Winson Chung | 4f7eb40 | 2015-07-10 18:00:48 -0700 | [diff] [blame] | 531 | int overviewButtonBarHeight = getOverviewModeButtonBarHeight(); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 532 | lp = (FrameLayout.LayoutParams) overviewMode.getLayoutParams(); |
| 533 | lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
Sunny Goyal | 8dfe2da | 2014-10-24 16:26:52 -0700 | [diff] [blame] | 534 | |
| 535 | int visibleChildCount = getVisibleChildCount(overviewMode); |
| 536 | int totalItemWidth = visibleChildCount * overviewModeBarItemWidthPx; |
| 537 | int maxWidth = totalItemWidth + (visibleChildCount-1) * overviewModeBarSpacerWidthPx; |
| 538 | |
| 539 | lp.width = Math.min(availableWidthPx, maxWidth); |
Winson Chung | 4f7eb40 | 2015-07-10 18:00:48 -0700 | [diff] [blame] | 540 | lp.height = overviewButtonBarHeight; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 541 | overviewMode.setLayoutParams(lp); |
Sunny Goyal | 8dfe2da | 2014-10-24 16:26:52 -0700 | [diff] [blame] | 542 | |
| 543 | if (lp.width > totalItemWidth && visibleChildCount > 1) { |
| 544 | // We have enough space. Lets add some margin too. |
| 545 | int margin = (lp.width - totalItemWidth) / (visibleChildCount-1); |
| 546 | View lastChild = null; |
| 547 | |
| 548 | // Set margin of all visible children except the last visible child |
| 549 | for (int i = 0; i < visibleChildCount; i++) { |
| 550 | if (lastChild != null) { |
| 551 | MarginLayoutParams clp = (MarginLayoutParams) lastChild.getLayoutParams(); |
| 552 | if (isLayoutRtl) { |
| 553 | clp.leftMargin = margin; |
| 554 | } else { |
| 555 | clp.rightMargin = margin; |
| 556 | } |
| 557 | lastChild.setLayoutParams(clp); |
| 558 | lastChild = null; |
| 559 | } |
| 560 | View thisChild = overviewMode.getChildAt(i); |
| 561 | if (thisChild.getVisibility() != View.GONE) { |
| 562 | lastChild = thisChild; |
| 563 | } |
| 564 | } |
| 565 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 566 | } |
| 567 | } |
Winson Chung | 4f3bfad | 2015-07-13 11:14:30 -0700 | [diff] [blame] | 568 | |
| 569 | private int getCurrentWidth() { |
| 570 | return isLandscape |
| 571 | ? Math.max(widthPx, heightPx) |
| 572 | : Math.min(widthPx, heightPx); |
| 573 | } |
| 574 | |
| 575 | private int getCurrentHeight() { |
| 576 | return isLandscape |
| 577 | ? Math.min(widthPx, heightPx) |
| 578 | : Math.max(widthPx, heightPx); |
| 579 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 580 | } |