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