DeviceProfile.java revision 258797318a99eb1ad4019f9863c69e34ef47a1ff
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 float allAppsIconTextSizeSp;
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        allAppsIconTextSizeSp = inv.iconTextSize;
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.pxFromDp(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        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,
251                (availableWidthPx - 4 * edgeMarginPx) / inv.numFolderColumns);
252        folderCellHeightPx = cellHeightPx + edgeMarginPx;
253        folderBackgroundOffset = -edgeMarginPx;
254        folderIconSizePx = iconSizePx + 2 * -folderBackgroundOffset;
255    }
256
257    /**
258     * @param recyclerViewWidth the available width of the AllAppsRecyclerView
259     */
260    public void updateAppsViewNumCols(Resources res, int recyclerViewWidth) {
261        int appsViewLeftMarginPx =
262                res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin);
263        int allAppsCellWidthGap =
264                res.getDimensionPixelSize(R.dimen.all_apps_icon_width_gap);
265        int availableAppsWidthPx = (recyclerViewWidth > 0) ? recyclerViewWidth : availableWidthPx;
266        int numAppsCols = (availableAppsWidthPx - appsViewLeftMarginPx) /
267                (allAppsIconSizePx + allAppsCellWidthGap);
268        int numPredictiveAppCols = Math.max(inv.minAllAppsPredictionColumns, numAppsCols);
269        allAppsNumCols = numAppsCols;
270        allAppsNumPredictiveCols = numPredictiveAppCols;
271    }
272
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());
283        }
284        int widgetInternalPadding = searchBarWidgetInternalPaddingTop +
285                searchBarWidgetInternalPaddingBottom;
286        return new Point(searchBarBounds.width(), searchBarSpaceHeightPx + widgetInternalPadding);
287    }
288
289    /** Returns the search bar bounds in the current orientation */
290    public Rect getSearchBarBounds(boolean isLayoutRtl) {
291        Rect bounds = new Rect();
292        if (isVerticalBarLayout()) {
293            if (isLayoutRtl) {
294                bounds.set(availableWidthPx - normalSearchBarSpaceHeightPx, edgeMarginPx,
295                        availableWidthPx, availableHeightPx - edgeMarginPx);
296            } else {
297                bounds.set(0, edgeMarginPx, normalSearchBarSpaceHeightPx,
298                        availableHeightPx - edgeMarginPx);
299            }
300        } else {
301            int boundsBottom = searchBarSpaceHeightPx + getSearchBarTotalVerticalPadding();
302            if (isTablet) {
303                // Pad the left and right of the workspace to ensure consistent spacing
304                // between all icons
305                int width = getCurrentWidth();
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 -
309                        (inv.numColumns * cellWidthPx)) / (2 * (inv.numColumns + 1)));
310                bounds.set(edgeMarginPx + gap, 0,
311                        availableWidthPx - (edgeMarginPx + gap), boundsBottom);
312            } else {
313                bounds.set(desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.left,
314                        0,
315                        availableWidthPx - (desiredWorkspaceLeftRightMarginPx -
316                        defaultWidgetPadding.right), boundsBottom);
317            }
318        }
319        return bounds;
320    }
321
322    public Point getCellSize() {
323        Point result = new Point();
324        // Since we are only concerned with the overall padding, layout direction does
325        // not matter.
326        Rect padding = getWorkspacePadding(false /* isLayoutRtl */ );
327        result.x = calculateCellWidth(availableWidthPx - padding.left - padding.right,
328                inv.numColumns);
329        result.y = calculateCellHeight(availableHeightPx - padding.top - padding.bottom,
330                inv.numRows);
331        return result;
332    }
333
334    /** Returns the workspace padding in the specified orientation */
335    Rect getWorkspacePadding(boolean isLayoutRtl) {
336        Rect searchBarBounds = getSearchBarBounds(isLayoutRtl);
337        Rect padding = new Rect();
338        if (isVerticalBarLayout()) {
339            // Pad the left and right of the workspace with search/hotseat bar sizes
340            if (isLayoutRtl) {
341                padding.set(normalHotseatBarHeightPx, edgeMarginPx,
342                        searchBarBounds.width(), edgeMarginPx);
343            } else {
344                padding.set(searchBarBounds.width(), edgeMarginPx,
345                        normalHotseatBarHeightPx, edgeMarginPx);
346            }
347        } else {
348            int paddingTop = searchBarBounds.bottom;
349            int paddingBottom = hotseatBarHeightPx + pageIndicatorHeightPx;
350            if (isTablet) {
351                // Pad the left and right of the workspace to ensure consistent spacing
352                // between all icons
353                float gapScale = 1f + (dragViewScale - 1f) / 2f;
354                int width = getCurrentWidth();
355                int height = getCurrentHeight();
356                // The amount of screen space available for left/right padding.
357                int availablePaddingX = Math.max(0, width - (int) ((inv.numColumns * cellWidthPx) +
358                        ((inv.numColumns - 1) * gapScale * cellWidthPx)));
359                availablePaddingX = (int) Math.min(availablePaddingX,
360                            width * MAX_HORIZONTAL_PADDING_PERCENT);
361                int availablePaddingY = Math.max(0, height - paddingTop - paddingBottom
362                        - (int) (2 * inv.numRows * cellHeightPx));
363                padding.set(availablePaddingX / 2, paddingTop + availablePaddingY / 2,
364                        availablePaddingX / 2, paddingBottom + availablePaddingY / 2);
365            } else {
366                // Pad the top and bottom of the workspace with search/hotseat bar sizes
367                padding.set(desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.left,
368                        paddingTop,
369                        desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.right,
370                        paddingBottom);
371            }
372        }
373        return padding;
374    }
375
376    private int getWorkspacePageSpacing(boolean isLayoutRtl) {
377        if (isVerticalBarLayout() || isLargeTablet) {
378            // In landscape mode the page spacing is set to the default.
379            return defaultPageSpacingPx;
380        } else {
381            // In portrait, we want the pages spaced such that there is no
382            // overhang of the previous / next page into the current page viewport.
383            // We assume symmetrical padding in portrait mode.
384            return Math.max(defaultPageSpacingPx, 2 * getWorkspacePadding(isLayoutRtl).left);
385        }
386    }
387
388    int getOverviewModeButtonBarHeight() {
389        int zoneHeight = (int) (overviewModeIconZoneRatio * availableHeightPx);
390        zoneHeight = Math.min(overviewModeMaxIconZoneHeightPx,
391                Math.max(overviewModeMinIconZoneHeightPx, zoneHeight));
392        return zoneHeight;
393    }
394
395    // The rect returned will be extended to below the system ui that covers the workspace
396    public boolean isInHotseatRect(int x, int y) {
397        if (isVerticalBarLayout()) {
398            return (x >= (availableWidthPx - hotseatBarHeightPx))
399                    && (y >= 0) && (y <= availableHeightPx);
400        } else {
401            return (x >= 0) && (x <= availableWidthPx)
402                    && (y >= (availableHeightPx - hotseatBarHeightPx));
403        }
404    }
405
406    public static int calculateCellWidth(int width, int countX) {
407        return width / countX;
408    }
409    public static int calculateCellHeight(int height, int countY) {
410        return height / countY;
411    }
412
413    /**
414     * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
415     * When {@code false}, either device is in portrait mode or the device is in landscape mode and
416     * the hotseat is on the bottom row.
417     */
418    public boolean isVerticalBarLayout() {
419        return isLandscape && transposeLayoutWithOrientation;
420    }
421
422    boolean shouldFadeAdjacentWorkspaceScreens() {
423        return isVerticalBarLayout() || isLargeTablet;
424    }
425
426    private int getVisibleChildCount(ViewGroup parent) {
427        int visibleChildren = 0;
428        for (int i = 0; i < parent.getChildCount(); i++) {
429            if (parent.getChildAt(i).getVisibility() != View.GONE) {
430                visibleChildren++;
431            }
432        }
433        return visibleChildren;
434    }
435
436    // TODO(twickham): b/25154513
437    public void setSearchBarHeight(int searchBarHeight) {
438        if (searchBarHeight == LauncherCallbacks.SEARCH_BAR_HEIGHT_TALL) {
439            hotseatBarHeightPx = shortHotseatBarHeightPx;
440            searchBarSpaceHeightPx = tallSearchBarSpaceHeightPx;
441            searchBarBottomPaddingPx = tallSearchBarBottomPaddingPx;
442        } else {
443            hotseatBarHeightPx = normalHotseatBarHeightPx;
444            searchBarSpaceHeightPx = normalSearchBarSpaceHeightPx;
445            searchBarBottomPaddingPx = normalSearchBarBottomPaddingPx;
446        }
447    }
448
449    public void layout(Launcher launcher) {
450        FrameLayout.LayoutParams lp;
451        boolean hasVerticalBarLayout = isVerticalBarLayout();
452        final boolean isLayoutRtl = Utilities.isRtl(launcher.getResources());
453
454        // Layout the search bar space
455        Rect searchBarBounds = getSearchBarBounds(isLayoutRtl);
456        View searchBar = launcher.getSearchDropTargetBar();
457        lp = getDropTargetBarLayoutParams(hasVerticalBarLayout, searchBar, Gravity.TOP);
458        lp.width = searchBarBounds.width();
459        lp.height = searchBarBounds.height();
460        searchBar.setLayoutParams(lp);
461
462        // Layout the app info bar space
463        View appInfoBar = launcher.getAppInfoDropTargetBar();
464        lp = getDropTargetBarLayoutParams(hasVerticalBarLayout, appInfoBar, Gravity.BOTTOM);
465        lp.bottomMargin = hotseatBarHeightPx;
466        appInfoBar.setLayoutParams(lp);
467
468        // Layout the workspace
469        PagedView workspace = (PagedView) launcher.findViewById(R.id.workspace);
470        lp = (FrameLayout.LayoutParams) workspace.getLayoutParams();
471        lp.gravity = Gravity.CENTER;
472        Rect padding = getWorkspacePadding(isLayoutRtl);
473        workspace.setLayoutParams(lp);
474        workspace.setPadding(padding.left, padding.top, padding.right, padding.bottom);
475        workspace.setPageSpacing(getWorkspacePageSpacing(isLayoutRtl));
476
477        // Layout the hotseat
478        View hotseat = launcher.findViewById(R.id.hotseat);
479        lp = (FrameLayout.LayoutParams) hotseat.getLayoutParams();
480        // We want the edges of the hotseat to line up with the edges of the workspace, but the
481        // icons in the hotseat are a different size, and so don't line up perfectly. To account for
482        // this, we pad the left and right of the hotseat with half of the difference of a workspace
483        // cell vs a hotseat cell.
484        float workspaceCellWidth = (float) getCurrentWidth() / inv.numColumns;
485        float hotseatCellWidth = (float) getCurrentWidth() / inv.numHotseatIcons;
486        int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
487        if (hasVerticalBarLayout) {
488            // Vertical hotseat -- The hotseat is fixed in the layout to be on the right of the
489            //                     screen regardless of RTL
490            lp.gravity = Gravity.RIGHT;
491            lp.width = normalHotseatBarHeightPx;
492            lp.height = LayoutParams.MATCH_PARENT;
493            hotseat.findViewById(R.id.layout).setPadding(0, 2 * edgeMarginPx, 0, 2 * edgeMarginPx);
494        } else if (isTablet) {
495            // Pad the hotseat with the workspace padding calculated above
496            lp.gravity = Gravity.BOTTOM;
497            lp.width = LayoutParams.MATCH_PARENT;
498            lp.height = hotseatBarHeightPx;
499            hotseat.findViewById(R.id.layout).setPadding(
500                    hotseatAdjustment + padding.left, 0,
501                    hotseatAdjustment + padding.right, 2 * edgeMarginPx);
502        } else {
503            // For phones, layout the hotseat without any bottom margin
504            // to ensure that we have space for the folders
505            lp.gravity = Gravity.BOTTOM;
506            lp.width = LayoutParams.MATCH_PARENT;
507            lp.height = hotseatBarHeightPx;
508            hotseat.findViewById(R.id.layout).setPadding(
509                    hotseatAdjustment + padding.left, 0,
510                    hotseatAdjustment + padding.right, 0);
511        }
512        hotseat.setLayoutParams(lp);
513
514        // Layout the page indicators
515        View pageIndicator = launcher.findViewById(R.id.page_indicator);
516        if (pageIndicator != null) {
517            if (hasVerticalBarLayout) {
518                // Hide the page indicators when we have vertical search/hotseat
519                pageIndicator.setVisibility(View.GONE);
520            } else {
521                // Put the page indicators above the hotseat
522                lp = (FrameLayout.LayoutParams) pageIndicator.getLayoutParams();
523                lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
524                lp.width = LayoutParams.WRAP_CONTENT;
525                lp.height = LayoutParams.WRAP_CONTENT;
526                lp.bottomMargin = hotseatBarHeightPx;
527                pageIndicator.setLayoutParams(lp);
528            }
529        }
530
531        // Layout the Overview Mode
532        ViewGroup overviewMode = launcher.getOverviewPanel();
533        if (overviewMode != null) {
534            lp = (FrameLayout.LayoutParams) overviewMode.getLayoutParams();
535            lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
536
537            int visibleChildCount = getVisibleChildCount(overviewMode);
538            int totalItemWidth = visibleChildCount * overviewModeBarItemWidthPx;
539            int maxWidth = totalItemWidth + (visibleChildCount-1) * overviewModeBarSpacerWidthPx;
540
541            lp.width = Math.min(availableWidthPx, maxWidth);
542            lp.height = getOverviewModeButtonBarHeight();
543            overviewMode.setLayoutParams(lp);
544
545            if (lp.width > totalItemWidth && visibleChildCount > 1) {
546                // We have enough space. Lets add some margin too.
547                int margin = (lp.width - totalItemWidth) / (visibleChildCount-1);
548                View lastChild = null;
549
550                // Set margin of all visible children except the last visible child
551                for (int i = 0; i < visibleChildCount; i++) {
552                    if (lastChild != null) {
553                        MarginLayoutParams clp = (MarginLayoutParams) lastChild.getLayoutParams();
554                        if (isLayoutRtl) {
555                            clp.leftMargin = margin;
556                        } else {
557                            clp.rightMargin = margin;
558                        }
559                        lastChild.setLayoutParams(clp);
560                        lastChild = null;
561                    }
562                    View thisChild = overviewMode.getChildAt(i);
563                    if (thisChild.getVisibility() != View.GONE) {
564                        lastChild = thisChild;
565                    }
566                }
567            }
568        }
569    }
570
571    private FrameLayout.LayoutParams getDropTargetBarLayoutParams(boolean hasVerticalBarLayout,
572            View dropTargetBar, int verticalGravity) {
573        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) dropTargetBar.getLayoutParams();
574        if (hasVerticalBarLayout) {
575            // Vertical drop target bar space -- The drop target bar is fixed in the layout to be on
576            //                                   the left of the screen regardless of RTL
577            lp.gravity = Gravity.LEFT;
578            lp.width = normalSearchBarSpaceHeightPx;
579
580            LinearLayout targets = (LinearLayout) dropTargetBar.findViewById(R.id.drag_target_bar);
581            targets.setOrientation(LinearLayout.VERTICAL);
582            FrameLayout.LayoutParams targetsLp = (FrameLayout.LayoutParams) targets.getLayoutParams();
583            targetsLp.gravity = verticalGravity;
584            targetsLp.height = LayoutParams.WRAP_CONTENT;
585        } else {
586            // Horizontal drop target bar space
587            lp.gravity = verticalGravity | Gravity.CENTER_HORIZONTAL;
588            lp.height = searchBarSpaceHeightPx;
589        }
590        return lp;
591    }
592
593    private int getCurrentWidth() {
594        return isLandscape
595                ? Math.max(widthPx, heightPx)
596                : Math.min(widthPx, heightPx);
597    }
598
599    private int getCurrentHeight() {
600        return isLandscape
601                ? Math.min(widthPx, heightPx)
602                : Math.max(widthPx, heightPx);
603    }
604}
605