DeviceProfile.java revision a72f49cfc466c5b57032405cb0e42e7140764323
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 hotseatBarHeightNormalPx, hotseatBarHeightShortPx;
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 searchBarSpaceWidthPx;
105    private int searchBarSpaceHeightNormalPx, searchBarSpaceHeightTallPx;
106    private int searchBarSpaceHeightPx; // One of the above.
107    private int searchBarHeight = LauncherCallbacks.SEARCH_BAR_HEIGHT_NORMAL;
108
109    public DeviceProfile(Context context, InvariantDeviceProfile inv,
110            Point minSize, Point maxSize,
111            int width, int height, boolean isLandscape) {
112
113        this.inv = inv;
114        this.isLandscape = isLandscape;
115
116        Resources res = context.getResources();
117        DisplayMetrics dm = res.getDisplayMetrics();
118
119        // Constants from resources
120        isTablet = res.getBoolean(R.bool.is_tablet);
121        isLargeTablet = res.getBoolean(R.bool.is_large_tablet);
122        isPhone = !isTablet && !isLargeTablet;
123
124        // Some more constants
125        transposeLayoutWithOrientation =
126                res.getBoolean(R.bool.hotseat_transpose_layout_with_orientation);
127
128        ComponentName cn = new ComponentName(context.getPackageName(),
129                this.getClass().getName());
130        defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
131        edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
132        desiredWorkspaceLeftRightMarginPx = 2 * edgeMarginPx;
133        pageIndicatorHeightPx =
134                res.getDimensionPixelSize(R.dimen.dynamic_grid_page_indicator_height);
135        defaultPageSpacingPx =
136                res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_page_spacing);
137        overviewModeMinIconZoneHeightPx =
138                res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_min_icon_zone_height);
139        overviewModeMaxIconZoneHeightPx =
140                res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_max_icon_zone_height);
141        overviewModeBarItemWidthPx =
142                res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_bar_item_width);
143        overviewModeBarSpacerWidthPx =
144                res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_bar_spacer_width);
145        overviewModeIconZoneRatio =
146                res.getInteger(R.integer.config_dynamic_grid_overview_icon_zone_percentage) / 100f;
147        iconDrawablePaddingOriginalPx =
148                res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
149
150        // AllApps uses the original non-scaled icon text size
151        allAppsIconTextSizePx = Utilities.pxFromDp(inv.iconTextSize, dm);
152
153        // AllApps uses the original non-scaled icon size
154        allAppsIconSizePx = Utilities.pxFromDp(inv.iconSize, dm);
155
156        // Determine sizes.
157        widthPx = width;
158        heightPx = height;
159        if (isLandscape) {
160            availableWidthPx = maxSize.x;
161            availableHeightPx = minSize.y;
162        } else {
163            availableWidthPx = minSize.x;
164            availableHeightPx = maxSize.y;
165        }
166
167        // Calculate the remaining vars
168        updateAvailableDimensions(dm, res);
169        computeAllAppsButtonSize(context);
170    }
171
172    /**
173     * Determine the exact visual footprint of the all apps button, taking into account scaling
174     * and internal padding of the drawable.
175     */
176    private void computeAllAppsButtonSize(Context context) {
177        Resources res = context.getResources();
178        float padding = res.getInteger(R.integer.config_allAppsButtonPaddingPercent) / 100f;
179        allAppsButtonVisualSize = (int) (hotseatIconSizePx * (1 - padding)) - context.getResources()
180                        .getDimensionPixelSize(R.dimen.all_apps_button_scale_down);
181    }
182
183    private void updateAvailableDimensions(DisplayMetrics dm, Resources res) {
184        // Check to see if the icons fit in the new available height.  If not, then we need to
185        // shrink the icon size.
186        float scale = 1f;
187        int drawablePadding = iconDrawablePaddingOriginalPx;
188        updateIconSize(1f, drawablePadding, res, dm);
189        float usedHeight = (cellHeightPx * inv.numRows);
190
191        // We only care about the top and bottom workspace padding, which is not affected by RTL.
192        Rect workspacePadding = getWorkspacePadding(false /* isLayoutRtl */);
193        int maxHeight = (availableHeightPx - workspacePadding.top - workspacePadding.bottom);
194        if (usedHeight > maxHeight) {
195            scale = maxHeight / usedHeight;
196            drawablePadding = 0;
197        }
198        updateIconSize(scale, drawablePadding, res, dm);
199    }
200
201    private void updateIconSize(float scale, int drawablePadding, Resources res,
202                                DisplayMetrics dm) {
203        iconSizePx = (int) (Utilities.pxFromDp(inv.iconSize, dm) * scale);
204        iconTextSizePx = (int) (Utilities.pxFromSp(inv.iconTextSize, dm) * scale);
205        iconDrawablePaddingPx = drawablePadding;
206        hotseatIconSizePx = (int) (Utilities.pxFromDp(inv.hotseatIconSize, dm) * scale);
207
208        // Search Bar
209        searchBarSpaceWidthPx = Math.min(widthPx,
210                res.getDimensionPixelSize(R.dimen.dynamic_grid_search_bar_max_width));
211        searchBarSpaceHeightNormalPx = getSearchBarTopOffset()
212                + res.getDimensionPixelSize(R.dimen.dynamic_grid_search_bar_height);
213        searchBarSpaceHeightTallPx = getSearchBarTopOffset()
214                + res.getDimensionPixelSize(R.dimen.dynamic_grid_search_bar_height_tall);
215
216        // Calculate the actual text height
217        Paint textPaint = new Paint();
218        textPaint.setTextSize(iconTextSizePx);
219        FontMetrics fm = textPaint.getFontMetrics();
220        cellWidthPx = iconSizePx;
221        cellHeightPx = iconSizePx + iconDrawablePaddingPx + (int) Math.ceil(fm.bottom - fm.top);
222        final float scaleDps = res.getDimensionPixelSize(R.dimen.dragViewScale);
223        dragViewScale = (iconSizePx + scaleDps) / iconSizePx;
224
225        // Hotseat
226        hotseatBarHeightNormalPx = iconSizePx + 4 * edgeMarginPx;
227        hotseatBarHeightShortPx = iconSizePx + 2 * edgeMarginPx;
228        hotseatCellWidthPx = iconSizePx;
229        hotseatCellHeightPx = iconSizePx;
230
231        // Folder
232        folderCellWidthPx = cellWidthPx + 3 * edgeMarginPx;
233        folderCellHeightPx = cellHeightPx + edgeMarginPx;
234        folderBackgroundOffset = -edgeMarginPx;
235        folderIconSizePx = iconSizePx + 2 * -folderBackgroundOffset;
236    }
237
238    /**
239     * @param recyclerViewWidth the available width of the AllAppsRecyclerView
240     */
241    public void updateAppsViewNumCols(Resources res, int recyclerViewWidth) {
242        int appsViewLeftMarginPx =
243                res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin);
244        int allAppsCellWidthGap =
245                res.getDimensionPixelSize(R.dimen.all_apps_icon_width_gap);
246        int availableAppsWidthPx = (recyclerViewWidth > 0) ? recyclerViewWidth : availableWidthPx;
247        int numAppsCols = (availableAppsWidthPx - appsViewLeftMarginPx) /
248                (allAppsIconSizePx + allAppsCellWidthGap);
249        int numPredictiveAppCols = Math.max(inv.minAllAppsPredictionColumns, numAppsCols);
250        allAppsNumCols = numAppsCols;
251        allAppsNumPredictiveCols = numPredictiveAppCols;
252    }
253
254    /** Returns the search bar top offset */
255    private int getSearchBarTopOffset() {
256        if (isTablet && !isVerticalBarLayout()) {
257            return 4 * edgeMarginPx;
258        } else {
259            return 2 * edgeMarginPx;
260        }
261    }
262
263    /** Returns the search bar bounds in the current orientation */
264    public Rect getSearchBarBounds(boolean isLayoutRtl) {
265        Rect bounds = new Rect();
266        if (isVerticalBarLayout()) {
267            if (isLayoutRtl) {
268                bounds.set(availableWidthPx - searchBarSpaceHeightNormalPx, edgeMarginPx,
269                        availableWidthPx, availableHeightPx - edgeMarginPx);
270            } else {
271                bounds.set(0, edgeMarginPx, searchBarSpaceHeightNormalPx,
272                        availableHeightPx - edgeMarginPx);
273            }
274        } else {
275            if (isTablet) {
276                // Pad the left and right of the workspace to ensure consistent spacing
277                // between all icons
278                int width = getCurrentWidth();
279                // XXX: If the icon size changes across orientations, we will have to take
280                //      that into account here too.
281                int gap = (int) ((width - 2 * edgeMarginPx -
282                        (inv.numColumns * cellWidthPx)) / (2 * (inv.numColumns + 1)));
283                bounds.set(edgeMarginPx + gap, getSearchBarTopOffset(),
284                        availableWidthPx - (edgeMarginPx + gap),
285                        searchBarSpaceHeightPx);
286            } else {
287                bounds.set(desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.left,
288                        getSearchBarTopOffset(),
289                        availableWidthPx - (desiredWorkspaceLeftRightMarginPx -
290                        defaultWidgetPadding.right), searchBarSpaceHeightPx);
291            }
292        }
293        return bounds;
294    }
295
296    public Point getCellSize() {
297        Point result = new Point();
298        // Since we are only concerned with the overall padding, layout direction does
299        // not matter.
300        Rect padding = getWorkspacePadding(false /* isLayoutRtl */ );
301        result.x = calculateCellWidth(availableWidthPx - padding.left - padding.right,
302                inv.numColumns);
303        result.y = calculateCellHeight(availableHeightPx - padding.top - padding.bottom,
304                inv.numRows);
305        return result;
306    }
307
308    /** Returns the workspace padding in the specified orientation */
309    Rect getWorkspacePadding(boolean isLayoutRtl) {
310        Rect searchBarBounds = getSearchBarBounds(isLayoutRtl);
311        Rect padding = new Rect();
312        if (isVerticalBarLayout()) {
313            // Pad the left and right of the workspace with search/hotseat bar sizes
314            if (isLayoutRtl) {
315                padding.set(hotseatBarHeightNormalPx, edgeMarginPx,
316                        searchBarBounds.width(), edgeMarginPx);
317            } else {
318                padding.set(searchBarBounds.width(), edgeMarginPx,
319                        hotseatBarHeightNormalPx, edgeMarginPx);
320            }
321        } else {
322            if (isTablet) {
323                // Pad the left and right of the workspace to ensure consistent spacing
324                // between all icons
325                float gapScale = 1f + (dragViewScale - 1f) / 2f;
326                int width = getCurrentWidth();
327                int height = getCurrentHeight();
328                int paddingTop = searchBarBounds.bottom;
329                int paddingBottom = hotseatBarHeightPx + pageIndicatorHeightPx;
330                // The amount of screen space available for left/right padding.
331                int availablePaddingX = Math.max(0, width - (int) ((inv.numColumns * cellWidthPx) +
332                        ((inv.numColumns - 1) * gapScale * cellWidthPx)));
333                availablePaddingX = (int) Math.min(availablePaddingX,
334                            width * MAX_HORIZONTAL_PADDING_PERCENT);
335                int availablePaddingY = Math.max(0, height - paddingTop - paddingBottom
336                        - (int) (2 * inv.numRows * cellHeightPx));
337                padding.set(availablePaddingX / 2, paddingTop + availablePaddingY / 2,
338                        availablePaddingX / 2, paddingBottom + availablePaddingY / 2);
339            } else {
340                // Pad the top and bottom of the workspace with search/hotseat bar sizes
341                padding.set(desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.left,
342                        searchBarBounds.bottom,
343                        desiredWorkspaceLeftRightMarginPx - defaultWidgetPadding.right,
344                        hotseatBarHeightPx + pageIndicatorHeightPx);
345            }
346        }
347        return padding;
348    }
349
350    private int getWorkspacePageSpacing(boolean isLayoutRtl) {
351        if (isVerticalBarLayout() || isLargeTablet) {
352            // In landscape mode the page spacing is set to the default.
353            return defaultPageSpacingPx;
354        } else {
355            // In portrait, we want the pages spaced such that there is no
356            // overhang of the previous / next page into the current page viewport.
357            // We assume symmetrical padding in portrait mode.
358            return Math.max(defaultPageSpacingPx, 2 * getWorkspacePadding(isLayoutRtl).left);
359        }
360    }
361
362    int getOverviewModeButtonBarHeight() {
363        int zoneHeight = (int) (overviewModeIconZoneRatio * availableHeightPx);
364        zoneHeight = Math.min(overviewModeMaxIconZoneHeightPx,
365                Math.max(overviewModeMinIconZoneHeightPx, zoneHeight));
366        return zoneHeight;
367    }
368
369    // The rect returned will be extended to below the system ui that covers the workspace
370    public boolean isInHotseatRect(int x, int y) {
371        if (isVerticalBarLayout()) {
372            return (x >= (availableWidthPx - hotseatBarHeightPx))
373                    && (y >= 0) && (y <= availableHeightPx);
374        } else {
375            return (x >= 0) && (x <= availableWidthPx)
376                    && (y >= (availableHeightPx - hotseatBarHeightPx));
377        }
378    }
379
380    public static int calculateCellWidth(int width, int countX) {
381        return width / countX;
382    }
383    public static int calculateCellHeight(int height, int countY) {
384        return height / countY;
385    }
386
387    /**
388     * When {@code true}, the device is in landscape mode and the hotseat is on the right column.
389     * When {@code false}, either device is in portrait mode or the device is in landscape mode and
390     * the hotseat is on the bottom row.
391     */
392    public boolean isVerticalBarLayout() {
393        return isLandscape && transposeLayoutWithOrientation;
394    }
395
396    boolean shouldFadeAdjacentWorkspaceScreens() {
397        return isVerticalBarLayout() || isLargeTablet;
398    }
399
400    private int getVisibleChildCount(ViewGroup parent) {
401        int visibleChildren = 0;
402        for (int i = 0; i < parent.getChildCount(); i++) {
403            if (parent.getChildAt(i).getVisibility() != View.GONE) {
404                visibleChildren++;
405            }
406        }
407        return visibleChildren;
408    }
409
410    public void layout(Launcher launcher) {
411        FrameLayout.LayoutParams lp;
412        boolean hasVerticalBarLayout = isVerticalBarLayout();
413        final boolean isLayoutRtl = Utilities.isRtl(launcher.getResources());
414
415        // Layout the search bar space
416        searchBarHeight = launcher.getSearchBarHeight();
417        if (searchBarHeight == LauncherCallbacks.SEARCH_BAR_HEIGHT_TALL) {
418            hotseatBarHeightPx = hotseatBarHeightShortPx;
419            searchBarSpaceHeightPx = searchBarSpaceHeightTallPx;
420        } else {
421            hotseatBarHeightPx = hotseatBarHeightNormalPx;
422            searchBarSpaceHeightPx = searchBarSpaceHeightNormalPx;
423        }
424        View searchBar = launcher.getSearchDropTargetBar();
425        lp = getDropTargetBarLayoutParams(hasVerticalBarLayout, searchBar, Gravity.TOP);
426        searchBar.setLayoutParams(lp);
427
428        // Layout the app info bar space
429        View appInfoBar = launcher.getAppInfoDropTargetBar();
430        lp = getDropTargetBarLayoutParams(hasVerticalBarLayout, appInfoBar, Gravity.BOTTOM);
431        lp.bottomMargin = hotseatBarHeightPx;
432        appInfoBar.setLayoutParams(lp);
433
434        // Layout the workspace
435        PagedView workspace = (PagedView) launcher.findViewById(R.id.workspace);
436        lp = (FrameLayout.LayoutParams) workspace.getLayoutParams();
437        lp.gravity = Gravity.CENTER;
438        Rect padding = getWorkspacePadding(isLayoutRtl);
439        workspace.setLayoutParams(lp);
440        workspace.setPadding(padding.left, padding.top, padding.right, padding.bottom);
441        workspace.setPageSpacing(getWorkspacePageSpacing(isLayoutRtl));
442
443        // Layout the hotseat
444        View hotseat = launcher.findViewById(R.id.hotseat);
445        lp = (FrameLayout.LayoutParams) hotseat.getLayoutParams();
446        // We want the edges of the hotseat to line up with the edges of the workspace, but the
447        // icons in the hotseat are a different size, and so don't line up perfectly. To account for
448        // this, we pad the left and right of the hotseat with half of the difference of a workspace
449        // cell vs a hotseat cell.
450        float workspaceCellWidth = (float) getCurrentWidth() / inv.numColumns;
451        float hotseatCellWidth = (float) getCurrentWidth() / inv.numHotseatIcons;
452        int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
453        if (hasVerticalBarLayout) {
454            // Vertical hotseat -- The hotseat is fixed in the layout to be on the right of the
455            //                     screen regardless of RTL
456            lp.gravity = Gravity.RIGHT;
457            lp.width = hotseatBarHeightNormalPx;
458            lp.height = LayoutParams.MATCH_PARENT;
459            hotseat.findViewById(R.id.layout).setPadding(0, 2 * edgeMarginPx, 0, 2 * edgeMarginPx);
460        } else if (isTablet) {
461            // Pad the hotseat with the workspace padding calculated above
462            lp.gravity = Gravity.BOTTOM;
463            lp.width = LayoutParams.MATCH_PARENT;
464            lp.height = hotseatBarHeightPx;
465            hotseat.findViewById(R.id.layout).setPadding(
466                    hotseatAdjustment + padding.left, 0,
467                    hotseatAdjustment + padding.right, 2 * edgeMarginPx);
468        } else {
469            // For phones, layout the hotseat without any bottom margin
470            // to ensure that we have space for the folders
471            lp.gravity = Gravity.BOTTOM;
472            lp.width = LayoutParams.MATCH_PARENT;
473            lp.height = hotseatBarHeightPx;
474            hotseat.findViewById(R.id.layout).setPadding(
475                    hotseatAdjustment + padding.left, 0,
476                    hotseatAdjustment + padding.right, 0);
477        }
478        hotseat.setLayoutParams(lp);
479
480        // Layout the page indicators
481        View pageIndicator = launcher.findViewById(R.id.page_indicator);
482        if (pageIndicator != null) {
483            if (hasVerticalBarLayout) {
484                // Hide the page indicators when we have vertical search/hotseat
485                pageIndicator.setVisibility(View.GONE);
486            } else {
487                // Put the page indicators above the hotseat
488                lp = (FrameLayout.LayoutParams) pageIndicator.getLayoutParams();
489                lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
490                lp.width = LayoutParams.WRAP_CONTENT;
491                lp.height = LayoutParams.WRAP_CONTENT;
492                lp.bottomMargin = hotseatBarHeightPx;
493                pageIndicator.setLayoutParams(lp);
494            }
495        }
496
497        // Layout the Overview Mode
498        ViewGroup overviewMode = launcher.getOverviewPanel();
499        if (overviewMode != null) {
500            lp = (FrameLayout.LayoutParams) overviewMode.getLayoutParams();
501            lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
502
503            int visibleChildCount = getVisibleChildCount(overviewMode);
504            int totalItemWidth = visibleChildCount * overviewModeBarItemWidthPx;
505            int maxWidth = totalItemWidth + (visibleChildCount-1) * overviewModeBarSpacerWidthPx;
506
507            lp.width = Math.min(availableWidthPx, maxWidth);
508            lp.height = getOverviewModeButtonBarHeight();
509            overviewMode.setLayoutParams(lp);
510
511            if (lp.width > totalItemWidth && visibleChildCount > 1) {
512                // We have enough space. Lets add some margin too.
513                int margin = (lp.width - totalItemWidth) / (visibleChildCount-1);
514                View lastChild = null;
515
516                // Set margin of all visible children except the last visible child
517                for (int i = 0; i < visibleChildCount; i++) {
518                    if (lastChild != null) {
519                        MarginLayoutParams clp = (MarginLayoutParams) lastChild.getLayoutParams();
520                        if (isLayoutRtl) {
521                            clp.leftMargin = margin;
522                        } else {
523                            clp.rightMargin = margin;
524                        }
525                        lastChild.setLayoutParams(clp);
526                        lastChild = null;
527                    }
528                    View thisChild = overviewMode.getChildAt(i);
529                    if (thisChild.getVisibility() != View.GONE) {
530                        lastChild = thisChild;
531                    }
532                }
533            }
534        }
535    }
536
537    private FrameLayout.LayoutParams getDropTargetBarLayoutParams(boolean hasVerticalBarLayout,
538            View dropTargetBar, int verticalGravity) {
539        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) dropTargetBar.getLayoutParams();
540        if (hasVerticalBarLayout) {
541            // Vertical drop target bar space -- The drop target bar is fixed in the layout to be on
542            //                                   the left of the screen regardless of RTL
543            lp.gravity = Gravity.LEFT;
544            lp.width = searchBarSpaceHeightPx;
545
546            LinearLayout targets = (LinearLayout) dropTargetBar.findViewById(R.id.drag_target_bar);
547            targets.setOrientation(LinearLayout.VERTICAL);
548            FrameLayout.LayoutParams targetsLp = (FrameLayout.LayoutParams) targets.getLayoutParams();
549            targetsLp.gravity = verticalGravity;
550            targetsLp.height = LayoutParams.WRAP_CONTENT;
551        } else {
552            // Horizontal drop target bar space
553            lp.gravity = verticalGravity;
554            lp.height = searchBarSpaceHeightPx;
555
556            LinearLayout targets = (LinearLayout) dropTargetBar.findViewById(R.id.drag_target_bar);
557            targets.getLayoutParams().width = searchBarSpaceWidthPx;
558        }
559        return lp;
560    }
561
562    private int getCurrentWidth() {
563        return isLandscape
564                ? Math.max(widthPx, heightPx)
565                : Math.min(widthPx, heightPx);
566    }
567
568    private int getCurrentHeight() {
569        return isLandscape
570                ? Math.min(widthPx, heightPx)
571                : Math.max(widthPx, heightPx);
572    }
573}
574