DeviceProfile.java revision a3c74d10a7d6e2ae8520e73176f939011e726ccf
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 17package com.android.launcher3; 18 19import android.appwidget.AppWidgetHostView; 20import android.content.ComponentName; 21import android.content.Context; 22import android.content.res.Resources; 23import android.graphics.Paint; 24import android.graphics.Paint.FontMetrics; 25import android.graphics.Point; 26import android.graphics.Rect; 27import android.util.DisplayMetrics; 28import android.view.Gravity; 29import android.view.View; 30import android.view.ViewGroup; 31import android.view.ViewGroup.LayoutParams; 32import android.view.ViewGroup.MarginLayoutParams; 33import android.widget.FrameLayout; 34import android.widget.LinearLayout; 35 36public class DeviceProfile { 37 38 public final InvariantDeviceProfile inv; 39 40 // Device properties 41 public final boolean isTablet; 42 public final boolean isLargeTablet; 43 public final boolean isPhone; 44 public final boolean transposeLayoutWithOrientation; 45 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; 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; 58 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; 65 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; 78 public int iconDrawablePaddingOriginalPx; 79 80 public int cellWidthPx; 81 public int cellHeightPx; 82 83 // Folder 84 public int folderBackgroundOffset; 85 public int folderIconSizePx; 86 public int folderCellWidthPx; 87 public int folderCellHeightPx; 88 89 // Hotseat 90 public int hotseatCellWidthPx; 91 public int hotseatCellHeightPx; 92 public int hotseatIconSizePx; 93 private int normalHotseatBarHeightPx, shortHotseatBarHeightPx; 94 private int hotseatBarHeightPx; // One of the above. 95 96 // All apps 97 public int allAppsNumCols; 98 public int allAppsNumPredictiveCols; 99 public int allAppsButtonVisualSize; 100 public final int allAppsIconSizePx; 101 public final int allAppsIconTextSizePx; 102 103 // QSB 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; 109 private int searchBarSpaceHeightPx; // One of the above. 110 111 public DeviceProfile(Context context, InvariantDeviceProfile inv, 112 Point minSize, Point maxSize, 113 int width, int height, boolean isLandscape) { 114 115 this.inv = inv; 116 this.isLandscape = isLandscape; 117 118 Resources res = context.getResources(); 119 DisplayMetrics dm = res.getDisplayMetrics(); 120 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 127 transposeLayoutWithOrientation = 128 res.getBoolean(R.bool.hotseat_transpose_layout_with_orientation); 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); 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); 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); 147 overviewModeIconZoneRatio = 148 res.getInteger(R.integer.config_dynamic_grid_overview_icon_zone_percentage) / 100f; 149 iconDrawablePaddingOriginalPx = 150 res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding); 151 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); 157 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 } 168 169 // Calculate the remaining vars 170 updateAvailableDimensions(dm, res); 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; 181 allAppsButtonVisualSize = (int) (hotseatIconSizePx * (1 - padding)) - context.getResources() 182 .getDimensionPixelSize(R.dimen.all_apps_button_scale_down); 183 } 184 185 private void updateAvailableDimensions(DisplayMetrics dm, Resources res) { 186 // Check to see if the icons fit in the new available height. If not, then we need to 187 // shrink the icon size. 188 float scale = 1f; 189 int drawablePadding = iconDrawablePaddingOriginalPx; 190 updateIconSize(1f, drawablePadding, res, dm); 191 float usedHeight = (cellHeightPx * inv.numRows); 192 193 // We only care about the top and bottom workspace padding, which is not affected by RTL. 194 Rect workspacePadding = getWorkspacePadding(false /* isLayoutRtl */); 195 int maxHeight = (availableHeightPx - workspacePadding.top - workspacePadding.bottom); 196 if (usedHeight > maxHeight) { 197 scale = maxHeight / usedHeight; 198 drawablePadding = 0; 199 } 200 updateIconSize(scale, drawablePadding, res, dm); 201 } 202 203 private void updateIconSize(float scale, int drawablePadding, Resources res, 204 DisplayMetrics dm) { 205 iconSizePx = (int) (Utilities.pxFromDp(inv.iconSize, dm) * scale); 206 iconTextSizePx = (int) (Utilities.pxFromSp(inv.iconTextSize, dm) * scale); 207 iconDrawablePaddingPx = drawablePadding; 208 hotseatIconSizePx = (int) (Utilities.pxFromDp(inv.hotseatIconSize, dm) * scale); 209 210 // Search Bar 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 } 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); 238 final float scaleDps = res.getDimensionPixelSize(R.dimen.dragViewScale); 239 dragViewScale = (iconSizePx + scaleDps) / iconSizePx; 240 241 // Hotseat 242 normalHotseatBarHeightPx = iconSizePx + 4 * edgeMarginPx; 243 shortHotseatBarHeightPx = iconSizePx + 2 * edgeMarginPx; 244 hotseatCellWidthPx = iconSizePx; 245 hotseatCellHeightPx = iconSizePx; 246 247 // Folder 248 folderCellWidthPx = Math.min(cellWidthPx + 6 * edgeMarginPx, 249 (availableWidthPx - 4 * edgeMarginPx) / inv.numFolderColumns); 250 folderCellHeightPx = cellHeightPx + edgeMarginPx; 251 folderBackgroundOffset = -edgeMarginPx; 252 folderIconSizePx = iconSizePx + 2 * -folderBackgroundOffset; 253 } 254 255 /** 256 * @param recyclerViewWidth the available width of the AllAppsRecyclerView 257 */ 258 public void updateAppsViewNumCols(Resources res, int recyclerViewWidth) { 259 int appsViewLeftMarginPx = 260 res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin); 261 int allAppsCellWidthGap = 262 res.getDimensionPixelSize(R.dimen.all_apps_icon_width_gap); 263 int availableAppsWidthPx = (recyclerViewWidth > 0) ? recyclerViewWidth : availableWidthPx; 264 int numAppsCols = (availableAppsWidthPx - appsViewLeftMarginPx) / 265 (allAppsIconSizePx + allAppsCellWidthGap); 266 int numPredictiveAppCols = Math.max(inv.minAllAppsPredictionColumns, numAppsCols); 267 allAppsNumCols = numAppsCols; 268 allAppsNumPredictiveCols = numPredictiveAppCols; 269 } 270 271 /** Returns the amount of extra space to allocate to the search bar for vertical padding. */ 272 private int getSearchBarTotalVerticalPadding() { 273 return searchBarTopPaddingPx + searchBarBottomPaddingPx; 274 } 275 276 /** Returns the width and height of the search bar, ignoring any padding. */ 277 public Point getSearchBarDimensForWidgetOpts(Resources res) { 278 Rect searchBarBounds = getSearchBarBounds(Utilities.isRtl(res)); 279 if (isVerticalBarLayout()) { 280 return new Point(searchBarBounds.width(), searchBarBounds.height()); 281 } 282 int widgetInternalPadding = searchBarWidgetInternalPaddingTop + 283 searchBarWidgetInternalPaddingBottom; 284 return new Point(searchBarBounds.width(), searchBarSpaceHeightPx + widgetInternalPadding); 285 } 286 287 /** Returns the search bar bounds in the current orientation */ 288 public Rect getSearchBarBounds(boolean isLayoutRtl) { 289 Rect bounds = new Rect(); 290 if (isVerticalBarLayout()) { 291 if (isLayoutRtl) { 292 bounds.set(availableWidthPx - normalSearchBarSpaceHeightPx, edgeMarginPx, 293 availableWidthPx, availableHeightPx - edgeMarginPx); 294 } else { 295 bounds.set(0, edgeMarginPx, normalSearchBarSpaceHeightPx, 296 availableHeightPx - edgeMarginPx); 297 } 298 } else { 299 int boundsBottom = searchBarSpaceHeightPx + getSearchBarTotalVerticalPadding(); 300 if (isTablet) { 301 // Pad the left and right of the workspace to ensure consistent spacing 302 // between all icons 303 int width = getCurrentWidth(); 304 // XXX: If the icon size changes across orientations, we will have to take 305 // that into account here too. 306 int gap = (int) ((width - 2 * edgeMarginPx - 307 (inv.numColumns * cellWidthPx)) / (2 * (inv.numColumns + 1))); 308 bounds.set(edgeMarginPx + gap, 0, 309 availableWidthPx - (edgeMarginPx + gap), boundsBottom); 310 } else { 311 bounds.set(desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.left, 312 0, 313 availableWidthPx - (desiredWorkspaceLeftRightMarginPx - 314 defaultWidgetPadding.right), boundsBottom); 315 } 316 } 317 return bounds; 318 } 319 320 /** Returns the workspace padding in the specified orientation */ 321 Rect getWorkspacePadding(boolean isLayoutRtl) { 322 Rect searchBarBounds = getSearchBarBounds(isLayoutRtl); 323 Rect padding = new Rect(); 324 if (isVerticalBarLayout()) { 325 // Pad the left and right of the workspace with search/hotseat bar sizes 326 if (isLayoutRtl) { 327 padding.set(normalHotseatBarHeightPx, edgeMarginPx, 328 searchBarBounds.width(), edgeMarginPx); 329 } else { 330 padding.set(searchBarBounds.width(), edgeMarginPx, 331 normalHotseatBarHeightPx, edgeMarginPx); 332 } 333 } else { 334 int paddingTop = searchBarBounds.bottom; 335 int paddingBottom = hotseatBarHeightPx + pageIndicatorHeightPx; 336 if (isTablet) { 337 // Pad the left and right of the workspace to ensure consistent spacing 338 // between all icons 339 float gapScale = 1f + (dragViewScale - 1f) / 2f; 340 int width = getCurrentWidth(); 341 int height = getCurrentHeight(); 342 // The amount of screen space available for left/right padding. 343 int availablePaddingX = Math.max(0, width - (int) ((inv.numColumns * cellWidthPx) + 344 ((inv.numColumns - 1) * gapScale * cellWidthPx))); 345 availablePaddingX = (int) Math.min(availablePaddingX, 346 width * MAX_HORIZONTAL_PADDING_PERCENT); 347 int availablePaddingY = Math.max(0, height - paddingTop - paddingBottom 348 - (int) (2 * inv.numRows * cellHeightPx)); 349 padding.set(availablePaddingX / 2, paddingTop + availablePaddingY / 2, 350 availablePaddingX / 2, paddingBottom + availablePaddingY / 2); 351 } else { 352 // Pad the top and bottom of the workspace with search/hotseat bar sizes 353 padding.set(desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.left, 354 paddingTop, 355 desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.right, 356 paddingBottom); 357 } 358 } 359 return padding; 360 } 361 362 private int getWorkspacePageSpacing(boolean isLayoutRtl) { 363 if (isVerticalBarLayout() || isLargeTablet) { 364 // In landscape mode the page spacing is set to the default. 365 return defaultPageSpacingPx; 366 } else { 367 // In portrait, we want the pages spaced such that there is no 368 // overhang of the previous / next page into the current page viewport. 369 // We assume symmetrical padding in portrait mode. 370 return Math.max(defaultPageSpacingPx, 2 * getWorkspacePadding(isLayoutRtl).left); 371 } 372 } 373 374 int getOverviewModeButtonBarHeight() { 375 int zoneHeight = (int) (overviewModeIconZoneRatio * availableHeightPx); 376 zoneHeight = Math.min(overviewModeMaxIconZoneHeightPx, 377 Math.max(overviewModeMinIconZoneHeightPx, zoneHeight)); 378 return zoneHeight; 379 } 380 381 // The rect returned will be extended to below the system ui that covers the workspace 382 Rect getHotseatRect() { 383 if (isVerticalBarLayout()) { 384 return new Rect(availableWidthPx - normalHotseatBarHeightPx, 0, 385 Integer.MAX_VALUE, availableHeightPx); 386 } else { 387 return new Rect(0, availableHeightPx - hotseatBarHeightPx, 388 availableWidthPx, Integer.MAX_VALUE); 389 } 390 } 391 392 public static int calculateCellWidth(int width, int countX) { 393 return width / countX; 394 } 395 public static int calculateCellHeight(int height, int countY) { 396 return height / countY; 397 } 398 399 /** 400 * When {@code true}, the device is in landscape mode and the hotseat is on the right column. 401 * When {@code false}, either device is in portrait mode or the device is in landscape mode and 402 * the hotseat is on the bottom row. 403 */ 404 boolean isVerticalBarLayout() { 405 return isLandscape && transposeLayoutWithOrientation; 406 } 407 408 boolean shouldFadeAdjacentWorkspaceScreens() { 409 return isVerticalBarLayout() || isLargeTablet; 410 } 411 412 private int getVisibleChildCount(ViewGroup parent) { 413 int visibleChildren = 0; 414 for (int i = 0; i < parent.getChildCount(); i++) { 415 if (parent.getChildAt(i).getVisibility() != View.GONE) { 416 visibleChildren++; 417 } 418 } 419 return visibleChildren; 420 } 421 422 // TODO(twickham): b/25154513 423 public void setSearchBarHeight(int searchBarHeight) { 424 if (searchBarHeight == LauncherCallbacks.SEARCH_BAR_HEIGHT_TALL) { 425 hotseatBarHeightPx = shortHotseatBarHeightPx; 426 searchBarSpaceHeightPx = tallSearchBarSpaceHeightPx; 427 searchBarBottomPaddingPx = tallSearchBarBottomPaddingPx; 428 } else { 429 hotseatBarHeightPx = normalHotseatBarHeightPx; 430 searchBarSpaceHeightPx = normalSearchBarSpaceHeightPx; 431 searchBarBottomPaddingPx = normalSearchBarBottomPaddingPx; 432 } 433 } 434 435 public void layout(Launcher launcher) { 436 FrameLayout.LayoutParams lp; 437 boolean hasVerticalBarLayout = isVerticalBarLayout(); 438 final boolean isLayoutRtl = Utilities.isRtl(launcher.getResources()); 439 440 // Layout the search bar space 441 Rect searchBarBounds = getSearchBarBounds(isLayoutRtl); 442 View searchBar = launcher.getSearchDropTargetBar(); 443 lp = (FrameLayout.LayoutParams) searchBar.getLayoutParams(); 444 lp.width = searchBarBounds.width(); 445 lp.height = searchBarBounds.height(); 446 if (hasVerticalBarLayout) { 447 // Vertical search bar space -- The search bar is fixed in the layout to be on the left 448 // of the screen regardless of RTL 449 lp.gravity = Gravity.LEFT; 450 451 LinearLayout targets = (LinearLayout) searchBar.findViewById(R.id.drag_target_bar); 452 targets.setOrientation(LinearLayout.VERTICAL); 453 FrameLayout.LayoutParams targetsLp = (FrameLayout.LayoutParams) targets.getLayoutParams(); 454 targetsLp.gravity = Gravity.TOP; 455 targetsLp.height = LayoutParams.WRAP_CONTENT; 456 457 } else { 458 // Horizontal search bar space 459 lp.gravity = Gravity.TOP|Gravity.CENTER_HORIZONTAL; 460 } 461 searchBar.setLayoutParams(lp); 462 463 // Layout the workspace 464 PagedView workspace = (PagedView) launcher.findViewById(R.id.workspace); 465 lp = (FrameLayout.LayoutParams) workspace.getLayoutParams(); 466 lp.gravity = Gravity.CENTER; 467 Rect padding = getWorkspacePadding(isLayoutRtl); 468 workspace.setLayoutParams(lp); 469 workspace.setPadding(padding.left, padding.top, padding.right, padding.bottom); 470 workspace.setPageSpacing(getWorkspacePageSpacing(isLayoutRtl)); 471 472 // Layout the hotseat 473 View hotseat = launcher.findViewById(R.id.hotseat); 474 lp = (FrameLayout.LayoutParams) hotseat.getLayoutParams(); 475 // We want the edges of the hotseat to line up with the edges of the workspace, but the 476 // icons in the hotseat are a different size, and so don't line up perfectly. To account for 477 // this, we pad the left and right of the hotseat with half of the difference of a workspace 478 // cell vs a hotseat cell. 479 float workspaceCellWidth = (float) getCurrentWidth() / inv.numColumns; 480 float hotseatCellWidth = (float) getCurrentWidth() / inv.numHotseatIcons; 481 int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2); 482 if (hasVerticalBarLayout) { 483 // Vertical hotseat -- The hotseat is fixed in the layout to be on the right of the 484 // screen regardless of RTL 485 lp.gravity = Gravity.RIGHT; 486 lp.width = normalHotseatBarHeightPx; 487 lp.height = LayoutParams.MATCH_PARENT; 488 hotseat.findViewById(R.id.layout).setPadding(0, 2 * edgeMarginPx, 0, 2 * edgeMarginPx); 489 } else if (isTablet) { 490 // Pad the hotseat with the workspace padding calculated above 491 lp.gravity = Gravity.BOTTOM; 492 lp.width = LayoutParams.MATCH_PARENT; 493 lp.height = hotseatBarHeightPx; 494 hotseat.findViewById(R.id.layout).setPadding( 495 hotseatAdjustment + padding.left, 0, 496 hotseatAdjustment + padding.right, 2 * edgeMarginPx); 497 } else { 498 // For phones, layout the hotseat without any bottom margin 499 // to ensure that we have space for the folders 500 lp.gravity = Gravity.BOTTOM; 501 lp.width = LayoutParams.MATCH_PARENT; 502 lp.height = hotseatBarHeightPx; 503 hotseat.findViewById(R.id.layout).setPadding( 504 hotseatAdjustment + padding.left, 0, 505 hotseatAdjustment + padding.right, 0); 506 } 507 hotseat.setLayoutParams(lp); 508 509 // Layout the page indicators 510 View pageIndicator = launcher.findViewById(R.id.page_indicator); 511 if (pageIndicator != null) { 512 if (hasVerticalBarLayout) { 513 // Hide the page indicators when we have vertical search/hotseat 514 pageIndicator.setVisibility(View.GONE); 515 } else { 516 // Put the page indicators above the hotseat 517 lp = (FrameLayout.LayoutParams) pageIndicator.getLayoutParams(); 518 lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; 519 lp.width = LayoutParams.WRAP_CONTENT; 520 lp.height = LayoutParams.WRAP_CONTENT; 521 lp.bottomMargin = hotseatBarHeightPx; 522 pageIndicator.setLayoutParams(lp); 523 } 524 } 525 526 // Layout the Overview Mode 527 ViewGroup overviewMode = launcher.getOverviewPanel(); 528 if (overviewMode != null) { 529 int overviewButtonBarHeight = getOverviewModeButtonBarHeight(); 530 lp = (FrameLayout.LayoutParams) overviewMode.getLayoutParams(); 531 lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; 532 533 int visibleChildCount = getVisibleChildCount(overviewMode); 534 int totalItemWidth = visibleChildCount * overviewModeBarItemWidthPx; 535 int maxWidth = totalItemWidth + (visibleChildCount-1) * overviewModeBarSpacerWidthPx; 536 537 lp.width = Math.min(availableWidthPx, maxWidth); 538 lp.height = overviewButtonBarHeight; 539 overviewMode.setLayoutParams(lp); 540 541 if (lp.width > totalItemWidth && visibleChildCount > 1) { 542 // We have enough space. Lets add some margin too. 543 int margin = (lp.width - totalItemWidth) / (visibleChildCount-1); 544 View lastChild = null; 545 546 // Set margin of all visible children except the last visible child 547 for (int i = 0; i < visibleChildCount; i++) { 548 if (lastChild != null) { 549 MarginLayoutParams clp = (MarginLayoutParams) lastChild.getLayoutParams(); 550 if (isLayoutRtl) { 551 clp.leftMargin = margin; 552 } else { 553 clp.rightMargin = margin; 554 } 555 lastChild.setLayoutParams(clp); 556 lastChild = null; 557 } 558 View thisChild = overviewMode.getChildAt(i); 559 if (thisChild.getVisibility() != View.GONE) { 560 lastChild = thisChild; 561 } 562 } 563 } 564 } 565 } 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 } 578} 579