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