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