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; |
| 22 | import android.content.res.Configuration; |
| 23 | import android.content.res.Resources; |
| 24 | import android.graphics.Paint; |
| 25 | import android.graphics.Paint.FontMetrics; |
| 26 | import android.graphics.Point; |
| 27 | import android.graphics.PointF; |
| 28 | import android.graphics.Rect; |
| 29 | import android.util.DisplayMetrics; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame^] | 30 | import android.util.TypedValue; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 31 | import android.view.Display; |
| 32 | import android.view.Gravity; |
| 33 | import android.view.Surface; |
| 34 | import android.view.View; |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 35 | import android.view.ViewGroup; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 36 | import android.view.ViewGroup.LayoutParams; |
Sunny Goyal | 8dfe2da | 2014-10-24 16:26:52 -0700 | [diff] [blame] | 37 | import android.view.ViewGroup.MarginLayoutParams; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 38 | import android.view.WindowManager; |
| 39 | import android.widget.FrameLayout; |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 40 | import android.widget.LinearLayout; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 41 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 42 | import com.android.launcher3.util.Thunk; |
| 43 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 44 | import java.util.ArrayList; |
| 45 | import java.util.Collections; |
| 46 | import java.util.Comparator; |
| 47 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 48 | public class DeviceProfile { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame^] | 49 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 50 | public static interface DeviceProfileCallbacks { |
| 51 | public void onAvailableSizeChanged(DeviceProfile grid); |
| 52 | } |
| 53 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame^] | 54 | public final InvariantDeviceProfile inv; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 55 | private int iconDrawablePaddingOriginalPx; |
Winson Chung | be87647 | 2014-05-14 14:15:20 -0700 | [diff] [blame] | 56 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 57 | boolean isLandscape; |
Hyunyoung Song | 4b69f2c | 2015-05-11 14:55:07 -0700 | [diff] [blame] | 58 | public boolean isTablet; |
| 59 | public boolean isLargeTablet; |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 60 | public boolean isLayoutRtl; |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 61 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 62 | boolean transposeLayoutWithOrientation; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 63 | int desiredWorkspaceLeftRightMarginPx; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 64 | public int edgeMarginPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 65 | Rect defaultWidgetPadding; |
| 66 | |
| 67 | int widthPx; |
| 68 | int heightPx; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 69 | public int availableWidthPx; |
| 70 | public int availableHeightPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 71 | int defaultPageSpacingPx; |
| 72 | |
| 73 | int overviewModeMinIconZoneHeightPx; |
| 74 | int overviewModeMaxIconZoneHeightPx; |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 75 | int overviewModeBarItemWidthPx; |
| 76 | int overviewModeBarSpacerWidthPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 77 | float overviewModeIconZoneRatio; |
| 78 | float overviewModeScaleFactor; |
| 79 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 80 | public int cellWidthPx; |
| 81 | public int cellHeightPx; |
| 82 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 83 | int iconDrawablePaddingPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 84 | int allAppsCellWidthPx; |
| 85 | int allAppsCellHeightPx; |
| 86 | int allAppsCellPaddingPx; |
| 87 | int folderBackgroundOffset; |
| 88 | int folderIconSizePx; |
| 89 | int folderCellWidthPx; |
| 90 | int folderCellHeightPx; |
| 91 | int hotseatCellWidthPx; |
| 92 | int hotseatCellHeightPx; |
| 93 | int hotseatIconSizePx; |
| 94 | int hotseatBarHeightPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 95 | int allAppsNumRows; |
| 96 | int allAppsNumCols; |
Winson Chung | 93f98ea | 2015-03-10 16:28:47 -0700 | [diff] [blame] | 97 | int appsViewNumCols; |
Winson Chung | 208ed75 | 2015-05-12 19:05:30 -0700 | [diff] [blame] | 98 | int appsViewNumPredictiveCols; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 99 | int searchBarSpaceWidthPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 100 | int searchBarSpaceHeightPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 101 | int pageIndicatorHeightPx; |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 102 | int allAppsButtonVisualSize; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 103 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame^] | 104 | int iconSizePx; |
| 105 | public int iconTextSizePx; |
| 106 | int allAppsIconSizePx; |
| 107 | int allAppsIconTextSizePx; |
| 108 | |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 109 | float dragViewScale; |
| 110 | |
Adam Cohen | 4ae96ce | 2014-08-29 15:05:48 -0700 | [diff] [blame] | 111 | int allAppsShortEdgeCount = -1; |
| 112 | int allAppsLongEdgeCount = -1; |
| 113 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 114 | private ArrayList<DeviceProfileCallbacks> mCallbacks = new ArrayList<DeviceProfileCallbacks>(); |
| 115 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame^] | 116 | public DeviceProfile(Context context, InvariantDeviceProfile inv) { |
| 117 | // Determine the dynamic grid properties |
| 118 | WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); |
| 119 | Display display = wm.getDefaultDisplay(); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 120 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame^] | 121 | Point realSize = new Point(); |
| 122 | display.getRealSize(realSize); |
| 123 | DisplayMetrics dm = new DisplayMetrics(); |
| 124 | display.getMetrics(dm); |
Sunny Goyal | fee35bb | 2015-05-11 11:38:19 -0700 | [diff] [blame] | 125 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame^] | 126 | this.inv = inv; |
| 127 | init(context, realSize.x, realSize.y, dm.widthPixels, dm.heightPixels); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame^] | 130 | private void init(Context context, int wPx, int hPx, int awPx, int ahPx) { |
| 131 | Resources res = context.getResources(); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 132 | DisplayMetrics dm = res.getDisplayMetrics(); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame^] | 133 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 134 | transposeLayoutWithOrientation = |
| 135 | res.getBoolean(R.bool.hotseat_transpose_layout_with_orientation); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 136 | |
| 137 | ComponentName cn = new ComponentName(context.getPackageName(), |
| 138 | this.getClass().getName()); |
| 139 | defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null); |
| 140 | edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin); |
| 141 | desiredWorkspaceLeftRightMarginPx = 2 * edgeMarginPx; |
| 142 | pageIndicatorHeightPx = |
| 143 | res.getDimensionPixelSize(R.dimen.dynamic_grid_page_indicator_height); |
| 144 | defaultPageSpacingPx = |
| 145 | res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_page_spacing); |
| 146 | allAppsCellPaddingPx = |
| 147 | res.getDimensionPixelSize(R.dimen.dynamic_grid_all_apps_cell_padding); |
| 148 | overviewModeMinIconZoneHeightPx = |
| 149 | res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_min_icon_zone_height); |
| 150 | overviewModeMaxIconZoneHeightPx = |
| 151 | res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_max_icon_zone_height); |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 152 | overviewModeBarItemWidthPx = |
| 153 | res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_bar_item_width); |
| 154 | overviewModeBarSpacerWidthPx = |
| 155 | res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_bar_spacer_width); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 156 | overviewModeIconZoneRatio = |
| 157 | res.getInteger(R.integer.config_dynamic_grid_overview_icon_zone_percentage) / 100f; |
| 158 | overviewModeScaleFactor = |
| 159 | res.getInteger(R.integer.config_dynamic_grid_overview_scale_percentage) / 100f; |
| 160 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 161 | iconDrawablePaddingOriginalPx = |
| 162 | res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 163 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame^] | 164 | // AllApps uses the original non-scaled icon text size |
| 165 | allAppsIconTextSizePx = Utilities.pxFromDp(inv.iconTextSize, dm); |
| 166 | |
| 167 | // AllApps uses the original non-scaled icon size |
| 168 | allAppsIconSizePx = Utilities.pxFromDp(inv.iconSize, dm); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 169 | |
Adam Cohen | 4ae96ce | 2014-08-29 15:05:48 -0700 | [diff] [blame] | 170 | // If the partner customization apk contains any grid overrides, apply them |
| 171 | applyPartnerDeviceProfileOverrides(context, dm); |
| 172 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 173 | // Calculate the remaining vars |
| 174 | updateFromConfiguration(context, res, wPx, hPx, awPx, ahPx); |
| 175 | updateAvailableDimensions(context); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 176 | computeAllAppsButtonSize(context); |
| 177 | } |
| 178 | |
| 179 | /** |
Adam Cohen | 4ae96ce | 2014-08-29 15:05:48 -0700 | [diff] [blame] | 180 | * Apply any Partner customization grid overrides. |
| 181 | * |
| 182 | * Currently we support: all apps row / column count. |
| 183 | */ |
| 184 | private void applyPartnerDeviceProfileOverrides(Context ctx, DisplayMetrics dm) { |
| 185 | Partner p = Partner.get(ctx.getPackageManager()); |
| 186 | if (p != null) { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame^] | 187 | p.applyDeviceProfileOverrides(this); |
Adam Cohen | 4ae96ce | 2014-08-29 15:05:48 -0700 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | |
| 191 | /** |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 192 | * Determine the exact visual footprint of the all apps button, taking into account scaling |
| 193 | * and internal padding of the drawable. |
| 194 | */ |
| 195 | private void computeAllAppsButtonSize(Context context) { |
| 196 | Resources res = context.getResources(); |
| 197 | float padding = res.getInteger(R.integer.config_allAppsButtonPaddingPercent) / 100f; |
| 198 | LauncherAppState app = LauncherAppState.getInstance(); |
| 199 | allAppsButtonVisualSize = (int) (hotseatIconSizePx * (1 - padding)); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | void addCallback(DeviceProfileCallbacks cb) { |
| 203 | mCallbacks.add(cb); |
| 204 | cb.onAvailableSizeChanged(this); |
| 205 | } |
| 206 | void removeCallback(DeviceProfileCallbacks cb) { |
| 207 | mCallbacks.remove(cb); |
| 208 | } |
| 209 | |
| 210 | private int getDeviceOrientation(Context context) { |
| 211 | WindowManager windowManager = (WindowManager) |
| 212 | context.getSystemService(Context.WINDOW_SERVICE); |
| 213 | Resources resources = context.getResources(); |
| 214 | DisplayMetrics dm = resources.getDisplayMetrics(); |
| 215 | Configuration config = resources.getConfiguration(); |
| 216 | int rotation = windowManager.getDefaultDisplay().getRotation(); |
| 217 | |
| 218 | boolean isLandscape = (config.orientation == Configuration.ORIENTATION_LANDSCAPE) && |
| 219 | (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180); |
| 220 | boolean isRotatedPortrait = (config.orientation == Configuration.ORIENTATION_PORTRAIT) && |
| 221 | (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270); |
| 222 | if (isLandscape || isRotatedPortrait) { |
| 223 | return CellLayout.LANDSCAPE; |
| 224 | } else { |
| 225 | return CellLayout.PORTRAIT; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | private void updateAvailableDimensions(Context context) { |
| 230 | WindowManager windowManager = (WindowManager) |
| 231 | context.getSystemService(Context.WINDOW_SERVICE); |
| 232 | Display display = windowManager.getDefaultDisplay(); |
| 233 | Resources resources = context.getResources(); |
| 234 | DisplayMetrics dm = resources.getDisplayMetrics(); |
| 235 | Configuration config = resources.getConfiguration(); |
| 236 | |
| 237 | // There are three possible configurations that the dynamic grid accounts for, portrait, |
| 238 | // landscape with the nav bar at the bottom, and landscape with the nav bar at the side. |
| 239 | // To prevent waiting for fitSystemWindows(), we make the observation that in landscape, |
| 240 | // the height is the smallest height (either with the nav bar at the bottom or to the |
| 241 | // side) and otherwise, the height is simply the largest possible height for a portrait |
| 242 | // device. |
| 243 | Point size = new Point(); |
| 244 | Point smallestSize = new Point(); |
| 245 | Point largestSize = new Point(); |
| 246 | display.getSize(size); |
| 247 | display.getCurrentSizeRange(smallestSize, largestSize); |
| 248 | availableWidthPx = size.x; |
| 249 | if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) { |
| 250 | availableHeightPx = smallestSize.y; |
| 251 | } else { |
| 252 | availableHeightPx = largestSize.y; |
| 253 | } |
| 254 | |
| 255 | // Check to see if the icons fit in the new available height. If not, then we need to |
| 256 | // shrink the icon size. |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 257 | float scale = 1f; |
| 258 | int drawablePadding = iconDrawablePaddingOriginalPx; |
| 259 | updateIconSize(1f, drawablePadding, resources, dm); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame^] | 260 | float usedHeight = (cellHeightPx * inv.numRows); |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 261 | |
| 262 | Rect workspacePadding = getWorkspacePadding(); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 263 | int maxHeight = (availableHeightPx - workspacePadding.top - workspacePadding.bottom); |
| 264 | if (usedHeight > maxHeight) { |
| 265 | scale = maxHeight / usedHeight; |
| 266 | drawablePadding = 0; |
| 267 | } |
| 268 | updateIconSize(scale, drawablePadding, resources, dm); |
| 269 | |
| 270 | // Make the callbacks |
| 271 | for (DeviceProfileCallbacks cb : mCallbacks) { |
| 272 | cb.onAvailableSizeChanged(this); |
| 273 | } |
| 274 | } |
| 275 | |
Winson Chung | 93f98ea | 2015-03-10 16:28:47 -0700 | [diff] [blame] | 276 | private void updateIconSize(float scale, int drawablePadding, Resources res, |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 277 | DisplayMetrics dm) { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame^] | 278 | iconSizePx = (int) (Utilities.pxFromDp(inv.iconSize, dm) * scale); |
| 279 | iconTextSizePx = (int) (Utilities.pxFromSp(inv.iconTextSize, dm) * scale); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 280 | iconDrawablePaddingPx = drawablePadding; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame^] | 281 | hotseatIconSizePx = (int) (Utilities.pxFromDp(inv.hotseatIconSize, dm) * scale); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 282 | |
| 283 | // Search Bar |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 284 | searchBarSpaceWidthPx = Math.min(widthPx, |
Winson Chung | 93f98ea | 2015-03-10 16:28:47 -0700 | [diff] [blame] | 285 | res.getDimensionPixelSize(R.dimen.dynamic_grid_search_bar_max_width)); |
Sunny Goyal | 594d76d | 2014-11-06 10:12:54 -0800 | [diff] [blame] | 286 | searchBarSpaceHeightPx = getSearchBarTopOffset() |
Winson Chung | 93f98ea | 2015-03-10 16:28:47 -0700 | [diff] [blame] | 287 | + res.getDimensionPixelSize(R.dimen.dynamic_grid_search_bar_height); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 288 | |
| 289 | // Calculate the actual text height |
| 290 | Paint textPaint = new Paint(); |
| 291 | textPaint.setTextSize(iconTextSizePx); |
| 292 | FontMetrics fm = textPaint.getFontMetrics(); |
| 293 | cellWidthPx = iconSizePx; |
| 294 | cellHeightPx = iconSizePx + iconDrawablePaddingPx + (int) Math.ceil(fm.bottom - fm.top); |
Winson Chung | 93f98ea | 2015-03-10 16:28:47 -0700 | [diff] [blame] | 295 | final float scaleDps = res.getDimensionPixelSize(R.dimen.dragViewScale); |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 296 | dragViewScale = (iconSizePx + scaleDps) / iconSizePx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 297 | |
| 298 | // Hotseat |
| 299 | hotseatBarHeightPx = iconSizePx + 4 * edgeMarginPx; |
| 300 | hotseatCellWidthPx = iconSizePx; |
| 301 | hotseatCellHeightPx = iconSizePx; |
| 302 | |
| 303 | // Folder |
| 304 | folderCellWidthPx = cellWidthPx + 3 * edgeMarginPx; |
| 305 | folderCellHeightPx = cellHeightPx + edgeMarginPx; |
| 306 | folderBackgroundOffset = -edgeMarginPx; |
| 307 | folderIconSizePx = iconSizePx + 2 * -folderBackgroundOffset; |
| 308 | |
| 309 | // All Apps |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 310 | allAppsCellWidthPx = allAppsIconSizePx; |
Winson Chung | 208ed75 | 2015-05-12 19:05:30 -0700 | [diff] [blame] | 311 | allAppsCellHeightPx = allAppsIconSizePx + drawablePadding + allAppsIconTextSizePx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 312 | int maxLongEdgeCellCount = |
Winson Chung | 93f98ea | 2015-03-10 16:28:47 -0700 | [diff] [blame] | 313 | res.getInteger(R.integer.config_dynamic_grid_max_long_edge_cell_count); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 314 | int maxShortEdgeCellCount = |
Winson Chung | 93f98ea | 2015-03-10 16:28:47 -0700 | [diff] [blame] | 315 | res.getInteger(R.integer.config_dynamic_grid_max_short_edge_cell_count); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 316 | int minEdgeCellCount = |
Winson Chung | 93f98ea | 2015-03-10 16:28:47 -0700 | [diff] [blame] | 317 | res.getInteger(R.integer.config_dynamic_grid_min_edge_cell_count); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 318 | int maxRows = (isLandscape ? maxShortEdgeCellCount : maxLongEdgeCellCount); |
| 319 | int maxCols = (isLandscape ? maxLongEdgeCellCount : maxShortEdgeCellCount); |
| 320 | |
Adam Cohen | 4ae96ce | 2014-08-29 15:05:48 -0700 | [diff] [blame] | 321 | if (allAppsShortEdgeCount > 0 && allAppsLongEdgeCount > 0) { |
| 322 | allAppsNumRows = isLandscape ? allAppsShortEdgeCount : allAppsLongEdgeCount; |
| 323 | allAppsNumCols = isLandscape ? allAppsLongEdgeCount : allAppsShortEdgeCount; |
| 324 | } else { |
| 325 | allAppsNumRows = (availableHeightPx - pageIndicatorHeightPx) / |
| 326 | (allAppsCellHeightPx + allAppsCellPaddingPx); |
| 327 | allAppsNumRows = Math.max(minEdgeCellCount, Math.min(maxRows, allAppsNumRows)); |
Winson Chung | 93f98ea | 2015-03-10 16:28:47 -0700 | [diff] [blame] | 328 | allAppsNumCols = (availableWidthPx) / (allAppsCellWidthPx + allAppsCellPaddingPx); |
Adam Cohen | 4ae96ce | 2014-08-29 15:05:48 -0700 | [diff] [blame] | 329 | allAppsNumCols = Math.max(minEdgeCellCount, Math.min(maxCols, allAppsNumCols)); |
| 330 | } |
Winson Chung | 93f98ea | 2015-03-10 16:28:47 -0700 | [diff] [blame] | 331 | |
Winson Chung | 0f78572 | 2015-04-08 10:27:49 -0700 | [diff] [blame] | 332 | int appsContainerViewWidthPx = res.getDimensionPixelSize(R.dimen.apps_container_width); |
| 333 | updateAppsViewNumCols(res, appsContainerViewWidthPx); |
| 334 | } |
| 335 | |
| 336 | public boolean updateAppsViewNumCols(Resources res, int containerWidth) { |
Winson Chung | 93f98ea | 2015-03-10 16:28:47 -0700 | [diff] [blame] | 337 | int appsViewLeftMarginPx = |
| 338 | res.getDimensionPixelSize(R.dimen.apps_grid_view_start_margin); |
Winson Chung | 0f78572 | 2015-04-08 10:27:49 -0700 | [diff] [blame] | 339 | int availableAppsWidthPx = (containerWidth > 0) ? containerWidth : availableWidthPx; |
Winson Chung | 208ed75 | 2015-05-12 19:05:30 -0700 | [diff] [blame] | 340 | int numAppsCols = (availableAppsWidthPx - appsViewLeftMarginPx) / |
Winson Chung | bd80853 | 2015-04-08 11:07:53 -0700 | [diff] [blame] | 341 | (allAppsCellWidthPx + 2 * allAppsCellPaddingPx); |
Winson Chung | c2af7f9 | 2015-05-14 13:15:29 -0700 | [diff] [blame] | 342 | int numPredictiveAppCols = isPhone() ? 4 : numAppsCols; |
Winson Chung | 208ed75 | 2015-05-12 19:05:30 -0700 | [diff] [blame] | 343 | if ((numAppsCols != appsViewNumCols) || |
| 344 | (numPredictiveAppCols != appsViewNumPredictiveCols)) { |
| 345 | appsViewNumCols = numAppsCols; |
| 346 | appsViewNumPredictiveCols = numPredictiveAppCols; |
Winson Chung | 0f78572 | 2015-04-08 10:27:49 -0700 | [diff] [blame] | 347 | return true; |
| 348 | } |
| 349 | return false; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | void updateFromConfiguration(Context context, Resources resources, int wPx, int hPx, |
| 353 | int awPx, int ahPx) { |
Winson Chung | 42b3c06 | 2013-12-04 12:09:59 -0800 | [diff] [blame] | 354 | Configuration configuration = resources.getConfiguration(); |
| 355 | isLandscape = (configuration.orientation == Configuration.ORIENTATION_LANDSCAPE); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 356 | isTablet = resources.getBoolean(R.bool.is_tablet); |
| 357 | isLargeTablet = resources.getBoolean(R.bool.is_large_tablet); |
Sunny Goyal | 7066003 | 2015-05-14 00:07:08 -0700 | [diff] [blame] | 358 | isLayoutRtl = Utilities.isRtl(resources); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 359 | widthPx = wPx; |
| 360 | heightPx = hPx; |
| 361 | availableWidthPx = awPx; |
| 362 | availableHeightPx = ahPx; |
| 363 | |
| 364 | updateAvailableDimensions(context); |
| 365 | } |
| 366 | |
Winson Chung | 69e04ea | 2013-12-02 14:43:44 -0800 | [diff] [blame] | 367 | /** Returns the search bar top offset */ |
| 368 | int getSearchBarTopOffset() { |
| 369 | if (isTablet() && !isVerticalBarLayout()) { |
| 370 | return 4 * edgeMarginPx; |
| 371 | } else { |
| 372 | return 2 * edgeMarginPx; |
| 373 | } |
| 374 | } |
| 375 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 376 | /** Returns the search bar bounds in the current orientation */ |
| 377 | Rect getSearchBarBounds() { |
| 378 | return getSearchBarBounds(isLandscape ? CellLayout.LANDSCAPE : CellLayout.PORTRAIT); |
| 379 | } |
| 380 | /** Returns the search bar bounds in the specified orientation */ |
| 381 | Rect getSearchBarBounds(int orientation) { |
| 382 | Rect bounds = new Rect(); |
| 383 | if (orientation == CellLayout.LANDSCAPE && |
| 384 | transposeLayoutWithOrientation) { |
Winson Chung | 42b3c06 | 2013-12-04 12:09:59 -0800 | [diff] [blame] | 385 | if (isLayoutRtl) { |
| 386 | bounds.set(availableWidthPx - searchBarSpaceHeightPx, edgeMarginPx, |
| 387 | availableWidthPx, availableHeightPx - edgeMarginPx); |
| 388 | } else { |
| 389 | bounds.set(0, edgeMarginPx, searchBarSpaceHeightPx, |
| 390 | availableHeightPx - edgeMarginPx); |
| 391 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 392 | } else { |
| 393 | if (isTablet()) { |
| 394 | // Pad the left and right of the workspace to ensure consistent spacing |
| 395 | // between all icons |
| 396 | int width = (orientation == CellLayout.LANDSCAPE) |
| 397 | ? Math.max(widthPx, heightPx) |
| 398 | : Math.min(widthPx, heightPx); |
| 399 | // XXX: If the icon size changes across orientations, we will have to take |
| 400 | // that into account here too. |
| 401 | int gap = (int) ((width - 2 * edgeMarginPx - |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame^] | 402 | (inv.numColumns * cellWidthPx)) / (2 * (inv.numColumns + 1))); |
Winson Chung | 2cb2471 | 2013-12-02 15:00:39 -0800 | [diff] [blame] | 403 | bounds.set(edgeMarginPx + gap, getSearchBarTopOffset(), |
| 404 | availableWidthPx - (edgeMarginPx + gap), |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 405 | searchBarSpaceHeightPx); |
| 406 | } else { |
Winson Chung | 2cb2471 | 2013-12-02 15:00:39 -0800 | [diff] [blame] | 407 | bounds.set(desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.left, |
| 408 | getSearchBarTopOffset(), |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 409 | availableWidthPx - (desiredWorkspaceLeftRightMarginPx - |
| 410 | defaultWidgetPadding.right), searchBarSpaceHeightPx); |
| 411 | } |
| 412 | } |
| 413 | return bounds; |
| 414 | } |
| 415 | |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 416 | /** Returns the bounds of the workspace page indicators. */ |
| 417 | Rect getWorkspacePageIndicatorBounds(Rect insets) { |
| 418 | Rect workspacePadding = getWorkspacePadding(); |
Winson Chung | 205cd77 | 2014-01-15 14:31:59 -0800 | [diff] [blame] | 419 | if (isLandscape && transposeLayoutWithOrientation) { |
| 420 | if (isLayoutRtl) { |
| 421 | return new Rect(workspacePadding.left, workspacePadding.top, |
| 422 | workspacePadding.left + pageIndicatorHeightPx, |
| 423 | heightPx - workspacePadding.bottom - insets.bottom); |
| 424 | } else { |
| 425 | int pageIndicatorLeft = widthPx - workspacePadding.right; |
| 426 | return new Rect(pageIndicatorLeft, workspacePadding.top, |
| 427 | pageIndicatorLeft + pageIndicatorHeightPx, |
| 428 | heightPx - workspacePadding.bottom - insets.bottom); |
| 429 | } |
| 430 | } else { |
| 431 | int pageIndicatorTop = heightPx - insets.bottom - workspacePadding.bottom; |
| 432 | return new Rect(workspacePadding.left, pageIndicatorTop, |
| 433 | widthPx - workspacePadding.right, pageIndicatorTop + pageIndicatorHeightPx); |
| 434 | } |
Winson Chung | a694524 | 2014-01-08 14:04:34 -0800 | [diff] [blame] | 435 | } |
| 436 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 437 | public int getWorkspaceGridHeight() { |
| 438 | Rect p = getWorkspacePadding(); |
| 439 | return availableHeightPx - p.top - p.bottom; |
| 440 | } |
| 441 | |
| 442 | public int getWorkspaceGridWidth() { |
| 443 | Rect p = getWorkspacePadding(); |
| 444 | return availableWidthPx - p.left - p.right; |
| 445 | } |
| 446 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 447 | /** Returns the workspace padding in the specified orientation */ |
| 448 | Rect getWorkspacePadding() { |
| 449 | return getWorkspacePadding(isLandscape ? CellLayout.LANDSCAPE : CellLayout.PORTRAIT); |
| 450 | } |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame^] | 451 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 452 | Rect getWorkspacePadding(int orientation) { |
| 453 | Rect searchBarBounds = getSearchBarBounds(orientation); |
| 454 | Rect padding = new Rect(); |
| 455 | if (orientation == CellLayout.LANDSCAPE && |
| 456 | transposeLayoutWithOrientation) { |
| 457 | // 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] | 458 | if (isLayoutRtl) { |
| 459 | padding.set(hotseatBarHeightPx, edgeMarginPx, |
| 460 | searchBarBounds.width(), edgeMarginPx); |
| 461 | } else { |
| 462 | padding.set(searchBarBounds.width(), edgeMarginPx, |
| 463 | hotseatBarHeightPx, edgeMarginPx); |
| 464 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 465 | } else { |
| 466 | if (isTablet()) { |
| 467 | // Pad the left and right of the workspace to ensure consistent spacing |
| 468 | // between all icons |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 469 | float gapScale = 1f + (dragViewScale - 1f) / 2f; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 470 | int width = (orientation == CellLayout.LANDSCAPE) |
| 471 | ? Math.max(widthPx, heightPx) |
| 472 | : Math.min(widthPx, heightPx); |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 473 | int height = (orientation != CellLayout.LANDSCAPE) |
| 474 | ? Math.max(widthPx, heightPx) |
| 475 | : Math.min(widthPx, heightPx); |
| 476 | int paddingTop = searchBarBounds.bottom; |
| 477 | int paddingBottom = hotseatBarHeightPx + pageIndicatorHeightPx; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame^] | 478 | int availableWidth = Math.max(0, width - (int) ((inv.numColumns * cellWidthPx) + |
| 479 | (inv.numColumns * gapScale * cellWidthPx))); |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 480 | int availableHeight = Math.max(0, height - paddingTop - paddingBottom |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame^] | 481 | - (int) (2 * inv.numRows * cellHeightPx)); |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 482 | padding.set(availableWidth / 2, paddingTop + availableHeight / 2, |
| 483 | availableWidth / 2, paddingBottom + availableHeight / 2); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 484 | } else { |
| 485 | // Pad the top and bottom of the workspace with search/hotseat bar sizes |
| 486 | padding.set(desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.left, |
| 487 | searchBarBounds.bottom, |
| 488 | desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.right, |
| 489 | hotseatBarHeightPx + pageIndicatorHeightPx); |
| 490 | } |
| 491 | } |
| 492 | return padding; |
| 493 | } |
| 494 | |
| 495 | int getWorkspacePageSpacing(int orientation) { |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 496 | if ((orientation == CellLayout.LANDSCAPE && |
| 497 | transposeLayoutWithOrientation) || isLargeTablet()) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 498 | // In landscape mode the page spacing is set to the default. |
| 499 | return defaultPageSpacingPx; |
| 500 | } else { |
| 501 | // In portrait, we want the pages spaced such that there is no |
| 502 | // overhang of the previous / next page into the current page viewport. |
| 503 | // We assume symmetrical padding in portrait mode. |
Adam Cohen | efb31e3 | 2014-01-16 16:07:50 -0800 | [diff] [blame] | 504 | return Math.max(defaultPageSpacingPx, 2 * getWorkspacePadding().left); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 505 | } |
| 506 | } |
| 507 | |
| 508 | Rect getOverviewModeButtonBarRect() { |
| 509 | int zoneHeight = (int) (overviewModeIconZoneRatio * availableHeightPx); |
| 510 | zoneHeight = Math.min(overviewModeMaxIconZoneHeightPx, |
| 511 | Math.max(overviewModeMinIconZoneHeightPx, zoneHeight)); |
| 512 | return new Rect(0, availableHeightPx - zoneHeight, 0, availableHeightPx); |
| 513 | } |
| 514 | |
| 515 | float getOverviewModeScale() { |
| 516 | Rect workspacePadding = getWorkspacePadding(); |
| 517 | Rect overviewBar = getOverviewModeButtonBarRect(); |
| 518 | int pageSpace = availableHeightPx - workspacePadding.top - workspacePadding.bottom; |
| 519 | return (overviewModeScaleFactor * (pageSpace - overviewBar.height())) / pageSpace; |
| 520 | } |
| 521 | |
| 522 | // The rect returned will be extended to below the system ui that covers the workspace |
| 523 | Rect getHotseatRect() { |
| 524 | if (isVerticalBarLayout()) { |
| 525 | return new Rect(availableWidthPx - hotseatBarHeightPx, 0, |
| 526 | Integer.MAX_VALUE, availableHeightPx); |
| 527 | } else { |
| 528 | return new Rect(0, availableHeightPx - hotseatBarHeightPx, |
| 529 | availableWidthPx, Integer.MAX_VALUE); |
| 530 | } |
| 531 | } |
| 532 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame^] | 533 | public static int calculateCellWidth(int width, int countX) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 534 | return width / countX; |
| 535 | } |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame^] | 536 | public static int calculateCellHeight(int height, int countY) { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 537 | return height / countY; |
| 538 | } |
| 539 | |
| 540 | boolean isPhone() { |
| 541 | return !isTablet && !isLargeTablet; |
| 542 | } |
| 543 | boolean isTablet() { |
| 544 | return isTablet; |
| 545 | } |
| 546 | boolean isLargeTablet() { |
| 547 | return isLargeTablet; |
| 548 | } |
| 549 | |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 550 | /** |
| 551 | * When {@code true}, hotseat is on the bottom row when in landscape mode. |
| 552 | * If {@code false}, hotseat is on the right column when in landscape mode. |
| 553 | */ |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 554 | boolean isVerticalBarLayout() { |
| 555 | return isLandscape && transposeLayoutWithOrientation; |
| 556 | } |
| 557 | |
| 558 | boolean shouldFadeAdjacentWorkspaceScreens() { |
| 559 | return isVerticalBarLayout() || isLargeTablet(); |
| 560 | } |
| 561 | |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 562 | int getVisibleChildCount(ViewGroup parent) { |
| 563 | int visibleChildren = 0; |
| 564 | for (int i = 0; i < parent.getChildCount(); i++) { |
| 565 | if (parent.getChildAt(i).getVisibility() != View.GONE) { |
| 566 | visibleChildren++; |
| 567 | } |
| 568 | } |
| 569 | return visibleChildren; |
| 570 | } |
| 571 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 572 | public void layout(Launcher launcher) { |
| 573 | FrameLayout.LayoutParams lp; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 574 | boolean hasVerticalBarLayout = isVerticalBarLayout(); |
| 575 | |
| 576 | // Layout the search bar space |
| 577 | View searchBar = launcher.getSearchBar(); |
| 578 | lp = (FrameLayout.LayoutParams) searchBar.getLayoutParams(); |
| 579 | if (hasVerticalBarLayout) { |
Winson Chung | 69e04ea | 2013-12-02 14:43:44 -0800 | [diff] [blame] | 580 | // Vertical search bar space |
Sunny Goyal | d9cc780 | 2015-04-23 14:47:19 -0700 | [diff] [blame] | 581 | lp.gravity = Gravity.LEFT; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 582 | lp.width = searchBarSpaceHeightPx; |
Adam Cohen | 24ce0b3 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 583 | |
| 584 | LinearLayout targets = (LinearLayout) searchBar.findViewById(R.id.drag_target_bar); |
| 585 | targets.setOrientation(LinearLayout.VERTICAL); |
Sunny Goyal | d9cc780 | 2015-04-23 14:47:19 -0700 | [diff] [blame] | 586 | FrameLayout.LayoutParams targetsLp = (FrameLayout.LayoutParams) targets.getLayoutParams(); |
| 587 | targetsLp.gravity = Gravity.TOP; |
| 588 | targetsLp.height = LayoutParams.WRAP_CONTENT; |
| 589 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 590 | } else { |
Winson Chung | 69e04ea | 2013-12-02 14:43:44 -0800 | [diff] [blame] | 591 | // Horizontal search bar space |
Sunny Goyal | d9cc780 | 2015-04-23 14:47:19 -0700 | [diff] [blame] | 592 | lp.gravity = Gravity.TOP; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 593 | lp.height = searchBarSpaceHeightPx; |
Sunny Goyal | d9cc780 | 2015-04-23 14:47:19 -0700 | [diff] [blame] | 594 | |
| 595 | LinearLayout targets = (LinearLayout) searchBar.findViewById(R.id.drag_target_bar); |
| 596 | targets.getLayoutParams().width = searchBarSpaceWidthPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 597 | } |
| 598 | searchBar.setLayoutParams(lp); |
| 599 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 600 | // Layout the workspace |
| 601 | PagedView workspace = (PagedView) launcher.findViewById(R.id.workspace); |
| 602 | lp = (FrameLayout.LayoutParams) workspace.getLayoutParams(); |
| 603 | lp.gravity = Gravity.CENTER; |
| 604 | int orientation = isLandscape ? CellLayout.LANDSCAPE : CellLayout.PORTRAIT; |
| 605 | Rect padding = getWorkspacePadding(orientation); |
| 606 | workspace.setLayoutParams(lp); |
| 607 | workspace.setPadding(padding.left, padding.top, padding.right, padding.bottom); |
| 608 | workspace.setPageSpacing(getWorkspacePageSpacing(orientation)); |
| 609 | |
| 610 | // Layout the hotseat |
| 611 | View hotseat = launcher.findViewById(R.id.hotseat); |
| 612 | lp = (FrameLayout.LayoutParams) hotseat.getLayoutParams(); |
| 613 | if (hasVerticalBarLayout) { |
| 614 | // Vertical hotseat |
Winson Chung | 42b3c06 | 2013-12-04 12:09:59 -0800 | [diff] [blame] | 615 | lp.gravity = Gravity.END; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 616 | lp.width = hotseatBarHeightPx; |
| 617 | lp.height = LayoutParams.MATCH_PARENT; |
| 618 | hotseat.findViewById(R.id.layout).setPadding(0, 2 * edgeMarginPx, 0, 2 * edgeMarginPx); |
| 619 | } else if (isTablet()) { |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 620 | // Pad the hotseat with the workspace padding calculated above |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 621 | lp.gravity = Gravity.BOTTOM; |
| 622 | lp.width = LayoutParams.MATCH_PARENT; |
| 623 | lp.height = hotseatBarHeightPx; |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 624 | hotseat.setPadding(edgeMarginPx + padding.left, 0, |
| 625 | edgeMarginPx + padding.right, |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 626 | 2 * edgeMarginPx); |
| 627 | } else { |
| 628 | // For phones, layout the hotseat without any bottom margin |
| 629 | // to ensure that we have space for the folders |
| 630 | lp.gravity = Gravity.BOTTOM; |
| 631 | lp.width = LayoutParams.MATCH_PARENT; |
| 632 | lp.height = hotseatBarHeightPx; |
Sunny Goyal | e0bca38 | 2015-04-06 18:39:22 +0000 | [diff] [blame] | 633 | hotseat.findViewById(R.id.layout).setPadding(2 * edgeMarginPx, 0, |
| 634 | 2 * edgeMarginPx, 0); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 635 | } |
| 636 | hotseat.setLayoutParams(lp); |
| 637 | |
| 638 | // Layout the page indicators |
| 639 | View pageIndicator = launcher.findViewById(R.id.page_indicator); |
| 640 | if (pageIndicator != null) { |
| 641 | if (hasVerticalBarLayout) { |
| 642 | // Hide the page indicators when we have vertical search/hotseat |
| 643 | pageIndicator.setVisibility(View.GONE); |
| 644 | } else { |
| 645 | // Put the page indicators above the hotseat |
| 646 | lp = (FrameLayout.LayoutParams) pageIndicator.getLayoutParams(); |
| 647 | lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 648 | lp.width = LayoutParams.WRAP_CONTENT; |
| 649 | lp.height = LayoutParams.WRAP_CONTENT; |
| 650 | lp.bottomMargin = hotseatBarHeightPx; |
| 651 | pageIndicator.setLayoutParams(lp); |
| 652 | } |
| 653 | } |
| 654 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 655 | // Layout the Overview Mode |
Jorim Jaggi | d017f88 | 2014-01-14 17:08:48 -0800 | [diff] [blame] | 656 | ViewGroup overviewMode = launcher.getOverviewPanel(); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 657 | if (overviewMode != null) { |
| 658 | Rect r = getOverviewModeButtonBarRect(); |
| 659 | lp = (FrameLayout.LayoutParams) overviewMode.getLayoutParams(); |
| 660 | lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
Sunny Goyal | 8dfe2da | 2014-10-24 16:26:52 -0700 | [diff] [blame] | 661 | |
| 662 | int visibleChildCount = getVisibleChildCount(overviewMode); |
| 663 | int totalItemWidth = visibleChildCount * overviewModeBarItemWidthPx; |
| 664 | int maxWidth = totalItemWidth + (visibleChildCount-1) * overviewModeBarSpacerWidthPx; |
| 665 | |
| 666 | lp.width = Math.min(availableWidthPx, maxWidth); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 667 | lp.height = r.height(); |
| 668 | overviewMode.setLayoutParams(lp); |
Sunny Goyal | 8dfe2da | 2014-10-24 16:26:52 -0700 | [diff] [blame] | 669 | |
| 670 | if (lp.width > totalItemWidth && visibleChildCount > 1) { |
| 671 | // We have enough space. Lets add some margin too. |
| 672 | int margin = (lp.width - totalItemWidth) / (visibleChildCount-1); |
| 673 | View lastChild = null; |
| 674 | |
| 675 | // Set margin of all visible children except the last visible child |
| 676 | for (int i = 0; i < visibleChildCount; i++) { |
| 677 | if (lastChild != null) { |
| 678 | MarginLayoutParams clp = (MarginLayoutParams) lastChild.getLayoutParams(); |
| 679 | if (isLayoutRtl) { |
| 680 | clp.leftMargin = margin; |
| 681 | } else { |
| 682 | clp.rightMargin = margin; |
| 683 | } |
| 684 | lastChild.setLayoutParams(clp); |
| 685 | lastChild = null; |
| 686 | } |
| 687 | View thisChild = overviewMode.getChildAt(i); |
| 688 | if (thisChild.getVisibility() != View.GONE) { |
| 689 | lastChild = thisChild; |
| 690 | } |
| 691 | } |
| 692 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 693 | } |
| 694 | } |
| 695 | } |