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 | |
Thales Lima | 12d0eff | 2022-03-25 17:06:11 +0000 | [diff] [blame] | 19 | import static com.android.launcher3.InvariantDeviceProfile.INDEX_DEFAULT; |
| 20 | import static com.android.launcher3.InvariantDeviceProfile.INDEX_LANDSCAPE; |
| 21 | import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_LANDSCAPE; |
| 22 | import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_PORTRAIT; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 23 | import static com.android.launcher3.ResourceUtils.pxFromDp; |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 24 | import static com.android.launcher3.Utilities.dpiFromPx; |
Jon Miranda | af3aed0 | 2021-05-06 18:28:45 -0700 | [diff] [blame] | 25 | import static com.android.launcher3.Utilities.pxFromSp; |
Jon Miranda | 92c1b5d | 2021-07-20 13:57:16 -0700 | [diff] [blame] | 26 | import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.ICON_OVERLAP_FACTOR; |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 27 | |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 28 | import android.annotation.SuppressLint; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 29 | import android.content.Context; |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 30 | import android.content.res.Configuration; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 31 | import android.content.res.Resources; |
Sunny Goyal | 8b9919d | 2021-04-07 14:45:17 -0700 | [diff] [blame] | 32 | import android.graphics.Path; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 33 | import android.graphics.Point; |
Jon Miranda | 7ae64ff | 2016-11-21 16:18:46 -0800 | [diff] [blame] | 34 | import android.graphics.PointF; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 35 | import android.graphics.Rect; |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 36 | import android.util.DisplayMetrics; |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 37 | import android.view.Surface; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 38 | |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 39 | import com.android.launcher3.CellLayout.ContainerType; |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 40 | import com.android.launcher3.DevicePaddings.DevicePadding; |
Tony Wickham | 8912b04 | 2018-11-29 15:28:53 -0800 | [diff] [blame] | 41 | import com.android.launcher3.icons.DotRenderer; |
Sunny Goyal | 8b9919d | 2021-04-07 14:45:17 -0700 | [diff] [blame] | 42 | import com.android.launcher3.icons.GraphicsUtils; |
Hyunyoung Song | 48cb7bc | 2018-09-25 17:03:34 -0700 | [diff] [blame] | 43 | import com.android.launcher3.icons.IconNormalizer; |
Sunny Goyal | 57b2279 | 2021-05-25 14:35:01 -0700 | [diff] [blame] | 44 | import com.android.launcher3.uioverrides.ApiWrapper; |
Sunny Goyal | fd58da6 | 2020-08-11 12:06:49 -0700 | [diff] [blame] | 45 | import com.android.launcher3.util.DisplayController; |
| 46 | import com.android.launcher3.util.DisplayController.Info; |
Sunny Goyal | b46703d | 2020-05-27 17:52:03 -0700 | [diff] [blame] | 47 | import com.android.launcher3.util.WindowBounds; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 48 | |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 49 | import java.io.PrintWriter; |
Brian Isganitis | 099945b | 2022-01-31 18:15:00 -0500 | [diff] [blame] | 50 | import java.util.List; |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 51 | |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 52 | @SuppressLint("NewApi") |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 53 | public class DeviceProfile { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 54 | |
Sunny Goyal | 8b9919d | 2021-04-07 14:45:17 -0700 | [diff] [blame] | 55 | private static final int DEFAULT_DOT_SIZE = 100; |
Sunny Goyal | 57b2279 | 2021-05-25 14:35:01 -0700 | [diff] [blame] | 56 | // Ratio of empty space, qsb should take up to appear visually centered. |
Pratyush | 9afe1ea | 2021-10-13 11:13:27 +0000 | [diff] [blame] | 57 | private final float mQsbCenterFactor; |
Sunny Goyal | 1890f67 | 2020-04-30 12:28:00 -0700 | [diff] [blame] | 58 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 59 | public final InvariantDeviceProfile inv; |
Sunny Goyal | fd58da6 | 2020-08-11 12:06:49 -0700 | [diff] [blame] | 60 | private final Info mInfo; |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 61 | private final DisplayMetrics mMetrics; |
Winson Chung | be87647 | 2014-05-14 14:15:20 -0700 | [diff] [blame] | 62 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 63 | // Device properties |
| 64 | public final boolean isTablet; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 65 | public final boolean isPhone; |
| 66 | public final boolean transposeLayoutWithOrientation; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 67 | public final boolean isTwoPanels; |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 68 | public final boolean isQsbInline; |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 69 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 70 | // Device properties in current orientation |
Sunny Goyal | d792a77 | 2018-04-05 13:37:46 -0700 | [diff] [blame] | 71 | public final boolean isLandscape; |
Sunny Goyal | d70e75a | 2018-02-22 10:07:32 -0800 | [diff] [blame] | 72 | public final boolean isMultiWindowMode; |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 73 | public final boolean isGestureMode; |
Sunny Goyal | d70e75a | 2018-02-22 10:07:32 -0800 | [diff] [blame] | 74 | |
Sunny Goyal | 0addbf0 | 2020-04-28 14:17:35 -0700 | [diff] [blame] | 75 | public final int windowX; |
| 76 | public final int windowY; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 77 | public final int widthPx; |
| 78 | public final int heightPx; |
| 79 | public final int availableWidthPx; |
| 80 | public final int availableHeightPx; |
Sunny Goyal | 187b16c | 2022-03-01 16:53:23 -0800 | [diff] [blame] | 81 | public final int rotationHint; |
Jon Miranda | bba6451 | 2019-03-27 10:54:17 -0700 | [diff] [blame] | 82 | |
| 83 | public final float aspectRatio; |
| 84 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 85 | public final boolean isScalableGrid; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 86 | private final int mTypeIndex; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 87 | |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 88 | /** |
| 89 | * The maximum amount of left/right workspace padding as a percentage of the screen width. |
| 90 | * To be clear, this means that up to 7% of the screen width can be used as left padding, and |
| 91 | * 7% of the screen width can be used as right padding. |
| 92 | */ |
| 93 | private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 94 | |
Jon Miranda | 3f9bab2 | 2017-07-28 14:50:17 -0700 | [diff] [blame] | 95 | private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f; |
Jon Miranda | 80cddbc | 2021-07-22 13:51:16 -0700 | [diff] [blame] | 96 | private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f; |
Jon Miranda | 80dda30 | 2021-07-28 14:14:59 -0700 | [diff] [blame] | 97 | private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252; |
| 98 | private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268; |
Jon Miranda | 30d0aa2 | 2017-07-25 15:55:29 -0700 | [diff] [blame] | 99 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 100 | // Workspace |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 101 | public final int desiredWorkspaceHorizontalMarginOriginalPx; |
| 102 | public int desiredWorkspaceHorizontalMarginPx; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 103 | public Point cellLayoutBorderSpaceOriginalPx; |
| 104 | public Point cellLayoutBorderSpacePx; |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 105 | public Rect cellLayoutPaddingPx = new Rect(); |
| 106 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 107 | public final int edgeMarginPx; |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 108 | public float workspaceSpringLoadShrunkTop; |
| 109 | public float workspaceSpringLoadShrunkBottom; |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 110 | public final int workspaceSpringLoadedBottomSpace; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 111 | |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 112 | private final int extraSpace; |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 113 | public int workspaceTopPadding; |
| 114 | public int workspaceBottomPadding; |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 115 | public int extraHotseatBottomPadding; |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 116 | |
Tony Wickham | 5edf9e2 | 2020-03-27 20:06:52 -0700 | [diff] [blame] | 117 | // Workspace page indicator |
| 118 | public final int workspacePageIndicatorHeight; |
| 119 | private final int mWorkspacePageIndicatorOverlapWorkspace; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 120 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 121 | // Workspace icons |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 122 | public float iconScale; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 123 | public int iconSizePx; |
| 124 | public int iconTextSizePx; |
| 125 | public int iconDrawablePaddingPx; |
Winson Chung | 5f4e0fd | 2015-05-22 11:12:27 -0700 | [diff] [blame] | 126 | public int iconDrawablePaddingOriginalPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 127 | |
Jon Miranda | ab3c681 | 2021-06-28 15:42:28 -0700 | [diff] [blame] | 128 | public float cellScaleToFit; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 129 | public int cellWidthPx; |
| 130 | public int cellHeightPx; |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 131 | public int workspaceCellPaddingXPx; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 132 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 133 | public int cellYPaddingPx; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 134 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 135 | // Folder |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 136 | public float folderLabelTextScale; |
| 137 | public int folderLabelTextSizePx; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 138 | public int folderIconSizePx; |
Jon Miranda | 591e360 | 2018-03-28 11:37:00 -0700 | [diff] [blame] | 139 | public int folderIconOffsetYPx; |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 140 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 141 | // Folder content |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 142 | public Point folderCellLayoutBorderSpacePx; |
| 143 | public int folderCellLayoutBorderSpaceOriginalPx; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 144 | public int folderContentPaddingLeftRight; |
| 145 | public int folderContentPaddingTop; |
| 146 | |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 147 | // Folder cell |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 148 | public int folderCellWidthPx; |
| 149 | public int folderCellHeightPx; |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 150 | |
| 151 | // Folder child |
| 152 | public int folderChildIconSizePx; |
| 153 | public int folderChildTextSizePx; |
Sunny Goyal | baec6ff | 2016-09-14 11:26:21 -0700 | [diff] [blame] | 154 | public int folderChildDrawablePaddingPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 155 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 156 | // Hotseat |
Jon Miranda | 80cddbc | 2021-07-22 13:51:16 -0700 | [diff] [blame] | 157 | public int hotseatBarSizeExtraSpacePx; |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame] | 158 | public final int numShownHotseatIcons; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 159 | public int hotseatCellHeightPx; |
Jon Miranda | 0d28485 | 2021-06-22 14:50:55 -0700 | [diff] [blame] | 160 | private final int hotseatExtraVerticalSize; |
Thales Lima | 828875c | 2022-04-26 20:29:30 +0100 | [diff] [blame] | 161 | private final boolean areNavButtonsInline; |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 162 | // In portrait: size = height, in landscape: size = width |
| 163 | public int hotseatBarSizePx; |
Jon Miranda | 80cddbc | 2021-07-22 13:51:16 -0700 | [diff] [blame] | 164 | public int hotseatBarTopPaddingPx; |
Jon Miranda | 0d28485 | 2021-06-22 14:50:55 -0700 | [diff] [blame] | 165 | public final int hotseatBarBottomPaddingPx; |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 166 | public int springLoadedHotseatBarTopMarginPx; |
Tony Wickham | 1eeffbe | 2018-06-12 15:01:15 -0700 | [diff] [blame] | 167 | // Start is the side next to the nav bar, end is the side next to the workspace |
| 168 | public final int hotseatBarSidePaddingStartPx; |
| 169 | public final int hotseatBarSidePaddingEndPx; |
Sunny Goyal | 57b2279 | 2021-05-25 14:35:01 -0700 | [diff] [blame] | 170 | public final int hotseatQsbHeight; |
Thales Lima | dd02734 | 2022-01-07 12:54:37 +0000 | [diff] [blame] | 171 | public int hotseatBorderSpace; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 172 | |
Jon Miranda | 8bdb222 | 2021-06-23 18:10:10 -0700 | [diff] [blame] | 173 | public final float qsbBottomMarginOriginalPx; |
| 174 | public int qsbBottomMarginPx; |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 175 | public int qsbWidth; // only used when isQsbInline |
Jon Miranda | 8bdb222 | 2021-06-23 18:10:10 -0700 | [diff] [blame] | 176 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 177 | // All apps |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 178 | public Point allAppsBorderSpacePx; |
Alex Chau | b8c22e1 | 2022-02-14 18:35:58 +0000 | [diff] [blame] | 179 | public int allAppsShiftRange; |
| 180 | public int allAppsTopPadding; |
Andras Kloczl | 142b054 | 2022-03-09 21:26:02 +0000 | [diff] [blame] | 181 | public int bottomSheetTopPadding; |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 182 | public int allAppsCellHeightPx; |
Samuel Fufa | f1424a3 | 2019-10-04 15:15:19 -0700 | [diff] [blame] | 183 | public int allAppsCellWidthPx; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 184 | public int allAppsIconSizePx; |
| 185 | public int allAppsIconDrawablePaddingPx; |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 186 | public int allAppsLeftRightPadding; |
Alex Chau | 27b39b9 | 2022-01-14 18:02:18 +0000 | [diff] [blame] | 187 | public int allAppsLeftRightMargin; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 188 | public final int numShownAllAppsColumns; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 189 | public float allAppsIconTextSizePx; |
| 190 | |
Zak Cohen | 334efeb | 2021-03-19 16:42:07 -0700 | [diff] [blame] | 191 | // Overview |
Zak Cohen | 334efeb | 2021-03-19 16:42:07 -0700 | [diff] [blame] | 192 | public int overviewTaskMarginPx; |
Alex Chau | eaa6d68 | 2021-08-17 12:56:15 +0100 | [diff] [blame] | 193 | public int overviewTaskMarginGridPx; |
Alex Chau | dedbc8a | 2021-03-17 16:53:26 +0000 | [diff] [blame] | 194 | public int overviewTaskIconSizePx; |
Alex Chau | ac9df38 | 2021-08-02 19:08:41 +0100 | [diff] [blame] | 195 | public int overviewTaskIconDrawableSizePx; |
| 196 | public int overviewTaskIconDrawableSizeGridPx; |
Alex Chau | dedbc8a | 2021-03-17 16:53:26 +0000 | [diff] [blame] | 197 | public int overviewTaskThumbnailTopMarginPx; |
Alex Chau | 19c6eca | 2022-03-10 20:12:56 +0000 | [diff] [blame] | 198 | public final int overviewActionsHeight; |
Alex Chau | a2fc764 | 2022-04-21 14:20:23 +0100 | [diff] [blame] | 199 | public final int overviewActionsTopMarginPx; |
Alex Chau | 1bf0fe1 | 2021-11-30 15:32:45 +0000 | [diff] [blame] | 200 | public final int overviewActionsButtonSpacing; |
Alex Chau | 5fd9d49 | 2021-07-22 17:27:11 +0100 | [diff] [blame] | 201 | public int overviewPageSpacing; |
| 202 | public int overviewRowSpacing; |
Alex Chau | 56bd257 | 2021-11-03 18:48:18 +0000 | [diff] [blame] | 203 | public int overviewGridSideMargin; |
Zak Cohen | 334efeb | 2021-03-19 16:42:07 -0700 | [diff] [blame] | 204 | |
Jon Miranda | 7ae64ff | 2016-11-21 16:18:46 -0800 | [diff] [blame] | 205 | // Widgets |
| 206 | public final PointF appWidgetScale = new PointF(1.0f, 1.0f); |
| 207 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 208 | // Drop Target |
| 209 | public int dropTargetBarSizePx; |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 210 | public int dropTargetBarTopMarginPx; |
| 211 | public int dropTargetBarBottomMarginPx; |
Alex Chau | a02eddc | 2021-04-29 00:36:06 +0100 | [diff] [blame] | 212 | public int dropTargetDragPaddingPx; |
| 213 | public int dropTargetTextSizePx; |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 214 | public int dropTargetHorizontalPaddingPx; |
| 215 | public int dropTargetVerticalPaddingPx; |
| 216 | public int dropTargetGapPx; |
Adam Cohen | 4ae96ce | 2014-08-29 15:05:48 -0700 | [diff] [blame] | 217 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 218 | // Insets |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 219 | private final Rect mInsets = new Rect(); |
| 220 | public final Rect workspacePadding = new Rect(); |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 221 | private final Rect mHotseatPadding = new Rect(); |
Jon Miranda | 0bd63d1 | 2019-03-06 17:29:29 -0800 | [diff] [blame] | 222 | // When true, nav bar is on the left side of the screen. |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 223 | private boolean mIsSeascape; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 224 | |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 225 | // Notification dots |
Samuel Fufa | c96fa24 | 2019-09-26 23:06:32 -0700 | [diff] [blame] | 226 | public DotRenderer mDotRendererWorkSpace; |
| 227 | public DotRenderer mDotRendererAllApps; |
Tony Wickham | 9a8d11f | 2017-01-11 09:53:12 -0800 | [diff] [blame] | 228 | |
Pierre Barbier de Reuille | 578deba | 2021-09-24 13:47:44 +0100 | [diff] [blame] | 229 | // Taskbar |
Tony Wickham | 1588389 | 2021-02-12 11:24:40 -0800 | [diff] [blame] | 230 | public boolean isTaskbarPresent; |
Tony Wickham | 635e180 | 2021-07-22 14:28:04 -1000 | [diff] [blame] | 231 | // Whether Taskbar will inset the bottom of apps by taskbarSize. |
| 232 | public boolean isTaskbarPresentInApps; |
Tony Wickham | 1588389 | 2021-02-12 11:24:40 -0800 | [diff] [blame] | 233 | public int taskbarSize; |
Alex Chau | 6a7d1e2 | 2022-01-20 19:54:17 +0000 | [diff] [blame] | 234 | public int stashedTaskbarSize; |
Tony Wickham | 1588389 | 2021-02-12 11:24:40 -0800 | [diff] [blame] | 235 | |
Alex Chau | a02eddc | 2021-04-29 00:36:06 +0100 | [diff] [blame] | 236 | // DragController |
| 237 | public int flingToDeleteThresholdVelocity; |
| 238 | |
Vinit Nayak | 17c4b33 | 2021-08-05 12:54:58 -0700 | [diff] [blame] | 239 | /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */ |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 240 | DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds, |
Sunny Goyal | 0addbf0 | 2020-04-28 14:17:35 -0700 | [diff] [blame] | 241 | boolean isMultiWindowMode, boolean transposeLayoutWithOrientation, |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 242 | boolean useTwoPanels, boolean isGestureMode) { |
Sunny Goyal | fee35bb | 2015-05-11 11:38:19 -0700 | [diff] [blame] | 243 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 244 | this.inv = inv; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 245 | this.isLandscape = windowBounds.isLandscape(); |
Sunny Goyal | d70e75a | 2018-02-22 10:07:32 -0800 | [diff] [blame] | 246 | this.isMultiWindowMode = isMultiWindowMode; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 247 | this.transposeLayoutWithOrientation = transposeLayoutWithOrientation; |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 248 | this.isGestureMode = isGestureMode; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 249 | windowX = windowBounds.bounds.left; |
| 250 | windowY = windowBounds.bounds.top; |
Sunny Goyal | 187b16c | 2022-03-01 16:53:23 -0800 | [diff] [blame] | 251 | this.rotationHint = windowBounds.rotationHint; |
Alex Chau | e022755 | 2022-04-06 19:44:43 +0100 | [diff] [blame] | 252 | mInsets.set(windowBounds.insets); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 253 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 254 | isScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode; |
| 255 | |
Alex Chau | dfc8ddf | 2022-01-25 11:26:25 +0000 | [diff] [blame] | 256 | // Determine device posture. |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 257 | mInfo = info; |
Alex Chau | 2998307 | 2021-11-19 15:14:20 +0000 | [diff] [blame] | 258 | isTablet = info.isTablet(windowBounds); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 259 | isPhone = !isTablet; |
Alex Chau | 9012582 | 2021-11-17 14:16:58 +0000 | [diff] [blame] | 260 | isTwoPanels = isTablet && useTwoPanels; |
Vinit Nayak | 58c27cc | 2022-02-16 17:42:21 -0800 | [diff] [blame] | 261 | isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 262 | |
Alex Chau | dfc8ddf | 2022-01-25 11:26:25 +0000 | [diff] [blame] | 263 | // Some more constants. |
Alex Chau | 635b3ab | 2022-01-26 16:49:10 +0000 | [diff] [blame] | 264 | context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape) |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 265 | ? Configuration.ORIENTATION_LANDSCAPE |
Alex Chau | a6907dc | 2022-03-18 15:24:07 +0000 | [diff] [blame] | 266 | : Configuration.ORIENTATION_PORTRAIT, |
| 267 | windowBounds); |
Sunny Goyal | 1890f67 | 2020-04-30 12:28:00 -0700 | [diff] [blame] | 268 | final Resources res = context.getResources(); |
Alex Chau | dfc8ddf | 2022-01-25 11:26:25 +0000 | [diff] [blame] | 269 | mMetrics = res.getDisplayMetrics(); |
| 270 | |
| 271 | // Determine sizes. |
| 272 | widthPx = windowBounds.bounds.width(); |
| 273 | heightPx = windowBounds.bounds.height(); |
| 274 | availableWidthPx = windowBounds.availableSize.x; |
Alex Chau | 6a7d1e2 | 2022-01-20 19:54:17 +0000 | [diff] [blame] | 275 | availableHeightPx = windowBounds.availableSize.y; |
Alex Chau | dfc8ddf | 2022-01-25 11:26:25 +0000 | [diff] [blame] | 276 | |
| 277 | aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx); |
| 278 | boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0; |
| 279 | mQsbCenterFactor = res.getFloat(R.dimen.qsb_center_factor); |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 280 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 281 | if (isTwoPanels) { |
| 282 | if (isLandscape) { |
Thales Lima | 12d0eff | 2022-03-25 17:06:11 +0000 | [diff] [blame] | 283 | mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 284 | } else { |
Thales Lima | 12d0eff | 2022-03-25 17:06:11 +0000 | [diff] [blame] | 285 | mTypeIndex = INDEX_TWO_PANEL_PORTRAIT; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 286 | } |
| 287 | } else { |
| 288 | if (isLandscape) { |
Thales Lima | 12d0eff | 2022-03-25 17:06:11 +0000 | [diff] [blame] | 289 | mTypeIndex = INDEX_LANDSCAPE; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 290 | } else { |
Thales Lima | 12d0eff | 2022-03-25 17:06:11 +0000 | [diff] [blame] | 291 | mTypeIndex = INDEX_DEFAULT; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | |
Tony Wickham | 1588389 | 2021-02-12 11:24:40 -0800 | [diff] [blame] | 295 | if (isTaskbarPresent) { |
Tony Wickham | 1588389 | 2021-02-12 11:24:40 -0800 | [diff] [blame] | 296 | taskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_size); |
Alex Chau | 6a7d1e2 | 2022-01-20 19:54:17 +0000 | [diff] [blame] | 297 | stashedTaskbarSize = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size); |
Tony Wickham | 1588389 | 2021-02-12 11:24:40 -0800 | [diff] [blame] | 298 | } |
Tony Wickham | 1588389 | 2021-02-12 11:24:40 -0800 | [diff] [blame] | 299 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 300 | edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin); |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 301 | |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 302 | desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res); |
| 303 | desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx; |
Samuel Fufa | ee9aff9 | 2021-04-05 13:30:40 -0500 | [diff] [blame] | 304 | |
Alex Chau | e022755 | 2022-04-06 19:44:43 +0100 | [diff] [blame] | 305 | bottomSheetTopPadding = mInsets.top // statusbar height |
Andras Kloczl | 142b054 | 2022-03-09 21:26:02 +0000 | [diff] [blame] | 306 | + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding) |
| 307 | + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding |
| 308 | |
| 309 | allAppsTopPadding = isTablet ? bottomSheetTopPadding : 0; |
Alex Chau | b8c22e1 | 2022-02-14 18:35:58 +0000 | [diff] [blame] | 310 | allAppsShiftRange = isTablet |
| 311 | ? heightPx - allAppsTopPadding |
| 312 | : res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate); |
Samuel Fufa | ee9aff9 | 2021-04-05 13:30:40 -0500 | [diff] [blame] | 313 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 314 | folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale); |
| 315 | folderContentPaddingLeftRight = |
| 316 | res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right); |
| 317 | folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_content_padding_top); |
| 318 | |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 319 | cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv); |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 320 | allAppsBorderSpacePx = new Point( |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 321 | pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics), |
| 322 | pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics)); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 323 | cellLayoutBorderSpaceOriginalPx = new Point(cellLayoutBorderSpacePx); |
Thales Lima | 080d890 | 2022-03-28 15:30:29 +0100 | [diff] [blame] | 324 | folderCellLayoutBorderSpaceOriginalPx = pxFromDp(inv.folderBorderSpace, mMetrics); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 325 | folderCellLayoutBorderSpacePx = new Point(folderCellLayoutBorderSpaceOriginalPx, |
| 326 | folderCellLayoutBorderSpaceOriginalPx); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 327 | |
Tony Wickham | 5edf9e2 | 2020-03-27 20:06:52 -0700 | [diff] [blame] | 328 | workspacePageIndicatorHeight = res.getDimensionPixelSize( |
| 329 | R.dimen.workspace_page_indicator_height); |
| 330 | mWorkspacePageIndicatorOverlapWorkspace = |
| 331 | res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace); |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 332 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 333 | iconDrawablePaddingOriginalPx = |
| 334 | res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding); |
Alex Chau | a02eddc | 2021-04-29 00:36:06 +0100 | [diff] [blame] | 335 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 336 | dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size); |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 337 | dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin); |
| 338 | dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin); |
Alex Chau | a02eddc | 2021-04-29 00:36:06 +0100 | [diff] [blame] | 339 | dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding); |
| 340 | dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size); |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 341 | dropTargetHorizontalPaddingPx = res.getDimensionPixelSize( |
| 342 | R.dimen.drop_target_button_drawable_horizontal_padding); |
| 343 | dropTargetVerticalPaddingPx = res.getDimensionPixelSize( |
| 344 | R.dimen.drop_target_button_drawable_vertical_padding); |
| 345 | dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap); |
Alex Chau | a02eddc | 2021-04-29 00:36:06 +0100 | [diff] [blame] | 346 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 347 | workspaceSpringLoadedBottomSpace = |
| 348 | res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space); |
Sunny Goyal | d519052 | 2017-04-24 03:06:54 -0700 | [diff] [blame] | 349 | |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 350 | workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x); |
Jon Miranda | 0966072 | 2017-06-14 14:20:14 -0700 | [diff] [blame] | 351 | |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 352 | hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height); |
Thales Lima | 12d0eff | 2022-03-25 17:06:11 +0000 | [diff] [blame] | 353 | // Whether QSB might be inline in appropriate orientation (e.g. landscape). |
| 354 | boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT] |
| 355 | || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] |
| 356 | : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE]) |
| 357 | && hotseatQsbHeight > 0; |
| 358 | isQsbInline = inv.inlineQsb[mTypeIndex] && canQsbInline; |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 359 | |
Alex Chau | 8175da9 | 2022-03-09 11:19:47 +0000 | [diff] [blame] | 360 | // We shrink hotseat sizes regardless of orientation, if nav buttons are inline and QSB |
| 361 | // might be inline in either orientations, to keep hotseat size consistent across rotation. |
Thales Lima | 828875c | 2022-04-26 20:29:30 +0100 | [diff] [blame] | 362 | areNavButtonsInline = isTaskbarPresent && !isGestureMode; |
Alex Chau | 8175da9 | 2022-03-09 11:19:47 +0000 | [diff] [blame] | 363 | if (areNavButtonsInline && canQsbInline) { |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 364 | numShownHotseatIcons = inv.numShrunkenHotseatIcons; |
| 365 | } else { |
| 366 | numShownHotseatIcons = |
| 367 | isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons; |
| 368 | } |
| 369 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 370 | numShownAllAppsColumns = |
| 371 | isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns; |
Jon Miranda | 80cddbc | 2021-07-22 13:51:16 -0700 | [diff] [blame] | 372 | hotseatBarSizeExtraSpacePx = 0; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 373 | hotseatBarTopPaddingPx = |
| 374 | res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding); |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 375 | if (isQsbInline) { |
| 376 | hotseatBarBottomPaddingPx = res.getDimensionPixelSize(R.dimen.inline_qsb_bottom_margin); |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 377 | } else { |
| 378 | hotseatBarBottomPaddingPx = (isTallDevice ? res.getDimensionPixelSize( |
| 379 | R.dimen.dynamic_grid_hotseat_bottom_tall_padding) |
| 380 | : res.getDimensionPixelSize( |
| 381 | R.dimen.dynamic_grid_hotseat_bottom_non_tall_padding)) |
| 382 | + res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_bottom_padding); |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 383 | } |
Thales Lima | 828875c | 2022-04-26 20:29:30 +0100 | [diff] [blame] | 384 | |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 385 | springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize( |
| 386 | R.dimen.spring_loaded_hotseat_top_margin); |
Tony Wickham | 1eeffbe | 2018-06-12 15:01:15 -0700 | [diff] [blame] | 387 | hotseatBarSidePaddingEndPx = |
Sunny Goyal | 228153d | 2018-01-04 15:35:22 -0800 | [diff] [blame] | 388 | res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding); |
Jon Miranda | 3f411e7 | 2019-05-16 17:15:16 -0700 | [diff] [blame] | 389 | // Add a bit of space between nav bar and hotseat in vertical bar layout. |
Tony Wickham | 5edf9e2 | 2020-03-27 20:06:52 -0700 | [diff] [blame] | 390 | hotseatBarSidePaddingStartPx = isVerticalBarLayout() ? workspacePageIndicatorHeight : 0; |
Jon Miranda | 0d28485 | 2021-06-22 14:50:55 -0700 | [diff] [blame] | 391 | hotseatExtraVerticalSize = |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 392 | res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_extra_vertical_size); |
Thales Lima | 828875c | 2022-04-26 20:29:30 +0100 | [diff] [blame] | 393 | updateHotseatIconSize(pxFromDp(inv.iconSize[INDEX_DEFAULT], mMetrics)); |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 394 | |
Jon Miranda | 8bdb222 | 2021-06-23 18:10:10 -0700 | [diff] [blame] | 395 | qsbBottomMarginOriginalPx = isScalableGrid |
| 396 | ? res.getDimensionPixelSize(R.dimen.scalable_grid_qsb_bottom_margin) |
| 397 | : 0; |
| 398 | |
Alex Chau | 635b3ab | 2022-01-26 16:49:10 +0000 | [diff] [blame] | 399 | overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin); |
Alex Chau | eaa6d68 | 2021-08-17 12:56:15 +0100 | [diff] [blame] | 400 | overviewTaskMarginGridPx = res.getDimensionPixelSize(R.dimen.overview_task_margin_grid); |
Alex Chau | 5fd9d49 | 2021-07-22 17:27:11 +0100 | [diff] [blame] | 401 | overviewTaskIconSizePx = res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_size); |
Alex Chau | ac9df38 | 2021-08-02 19:08:41 +0100 | [diff] [blame] | 402 | overviewTaskIconDrawableSizePx = |
| 403 | res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size); |
| 404 | overviewTaskIconDrawableSizeGridPx = |
| 405 | res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid); |
Alex Chau | dedbc8a | 2021-03-17 16:53:26 +0000 | [diff] [blame] | 406 | overviewTaskThumbnailTopMarginPx = overviewTaskIconSizePx + overviewTaskMarginPx * 2; |
Alex Chau | a2fc764 | 2022-04-21 14:20:23 +0100 | [diff] [blame] | 407 | // In vertical bar, use the smaller task margin for the top regardless of mode. |
| 408 | overviewActionsTopMarginPx = isVerticalBarLayout() |
| 409 | ? overviewTaskMarginPx |
| 410 | : res.getDimensionPixelSize(R.dimen.overview_actions_top_margin); |
Alex Chau | 635b3ab | 2022-01-26 16:49:10 +0000 | [diff] [blame] | 411 | overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing); |
| 412 | overviewActionsButtonSpacing = res.getDimensionPixelSize( |
| 413 | R.dimen.overview_actions_button_spacing); |
Alex Chau | 19c6eca | 2022-03-10 20:12:56 +0000 | [diff] [blame] | 414 | overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height); |
Alex Chau | 4c98374 | 2021-12-10 13:09:53 +0000 | [diff] [blame] | 415 | // Grid task's top margin is only overviewTaskIconSizePx + overviewTaskMarginGridPx, but |
| 416 | // overviewTaskThumbnailTopMarginPx is applied to all TaskThumbnailView, so exclude the |
| 417 | // extra margin when calculating row spacing. |
| 418 | int extraTopMargin = overviewTaskThumbnailTopMarginPx - overviewTaskIconSizePx |
| 419 | - overviewTaskMarginGridPx; |
| 420 | overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing) |
| 421 | - extraTopMargin; |
Alex Chau | 635b3ab | 2022-01-26 16:49:10 +0000 | [diff] [blame] | 422 | overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin); |
Zak Cohen | 334efeb | 2021-03-19 16:42:07 -0700 | [diff] [blame] | 423 | |
Jon Miranda | 2ed276e | 2017-06-29 11:36:34 -0700 | [diff] [blame] | 424 | // Calculate all of the remaining variables. |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 425 | extraSpace = updateAvailableDimensions(res); |
Jon Miranda | 80cddbc | 2021-07-22 13:51:16 -0700 | [diff] [blame] | 426 | |
Jon Miranda | 2ed276e | 2017-06-29 11:36:34 -0700 | [diff] [blame] | 427 | // Now that we have all of the variables calculated, we can tune certain sizes. |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 428 | if (isScalableGrid && inv.devicePaddings != null) { |
| 429 | // Paddings were created assuming no scaling, so we first unscale the extra space. |
Jon Miranda | ab3c681 | 2021-06-28 15:42:28 -0700 | [diff] [blame] | 430 | int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit); |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 431 | DevicePadding padding = inv.devicePaddings.getDevicePadding(unscaledExtraSpace); |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 432 | |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 433 | int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace); |
| 434 | int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace); |
| 435 | int paddingHotseatBottom = padding.getHotseatBottomPadding(unscaledExtraSpace); |
| 436 | |
Jon Miranda | ab3c681 | 2021-06-28 15:42:28 -0700 | [diff] [blame] | 437 | workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit); |
| 438 | workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit); |
| 439 | extraHotseatBottomPadding = Math.round(paddingHotseatBottom * cellScaleToFit); |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 440 | |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 441 | hotseatBarSizePx += extraHotseatBottomPadding; |
Jon Miranda | 8bdb222 | 2021-06-23 18:10:10 -0700 | [diff] [blame] | 442 | |
Jon Miranda | ab3c681 | 2021-06-28 15:42:28 -0700 | [diff] [blame] | 443 | qsbBottomMarginPx = Math.round(qsbBottomMarginOriginalPx * cellScaleToFit); |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 444 | } else if (!isVerticalBarLayout() && isPhone && isTallDevice) { |
Jon Miranda | 3f9bab2 | 2017-07-28 14:50:17 -0700 | [diff] [blame] | 445 | // We increase the hotseat size when there is extra space. |
Jon Miranda | 80cddbc | 2021-07-22 13:51:16 -0700 | [diff] [blame] | 446 | |
Jon Miranda | 80dda30 | 2021-07-28 14:14:59 -0700 | [diff] [blame] | 447 | if (Float.compare(aspectRatio, TALLER_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0 |
| 448 | && extraSpace >= Utilities.dpToPx(TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP)) { |
| 449 | // For taller devices, we will take a piece of the extra space from each row, |
Jon Miranda | 80cddbc | 2021-07-22 13:51:16 -0700 | [diff] [blame] | 450 | // and add it to the space above and below the hotseat. |
Jon Miranda | 80dda30 | 2021-07-28 14:14:59 -0700 | [diff] [blame] | 451 | |
| 452 | // For devices with more extra space, we take a larger piece from each cell. |
| 453 | int piece = extraSpace < Utilities.dpToPx(TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP) |
Jon Miranda | a56cb84 | 2021-08-03 17:26:44 -0700 | [diff] [blame] | 454 | ? 7 : 5; |
Jon Miranda | 80dda30 | 2021-07-28 14:14:59 -0700 | [diff] [blame] | 455 | |
Jon Miranda | 80cddbc | 2021-07-22 13:51:16 -0700 | [diff] [blame] | 456 | int extraSpace = ((getCellSize().y - iconSizePx - iconDrawablePaddingPx * 2) |
Jon Miranda | 80dda30 | 2021-07-28 14:14:59 -0700 | [diff] [blame] | 457 | * inv.numRows) / piece; |
Jon Miranda | 80cddbc | 2021-07-22 13:51:16 -0700 | [diff] [blame] | 458 | |
Jon Miranda | a56cb84 | 2021-08-03 17:26:44 -0700 | [diff] [blame] | 459 | workspaceTopPadding = extraSpace / 8; |
| 460 | int halfLeftOver = (extraSpace - workspaceTopPadding) / 2; |
| 461 | hotseatBarTopPaddingPx += halfLeftOver; |
| 462 | hotseatBarSizeExtraSpacePx = halfLeftOver; |
Jon Miranda | 80cddbc | 2021-07-22 13:51:16 -0700 | [diff] [blame] | 463 | } else { |
| 464 | // ie. For a display with a large aspect ratio, we can keep the icons on the |
| 465 | // workspace in portrait mode closer together by adding more height to the hotseat. |
| 466 | // Note: This calculation was created after noticing a pattern in the design spec. |
| 467 | hotseatBarSizeExtraSpacePx = getCellSize().y - iconSizePx |
| 468 | - iconDrawablePaddingPx * 2 - workspacePageIndicatorHeight; |
| 469 | } |
| 470 | |
| 471 | updateHotseatIconSize(iconSizePx); |
Jon Miranda | 30d0aa2 | 2017-07-25 15:55:29 -0700 | [diff] [blame] | 472 | |
Jon Miranda | 3f9bab2 | 2017-07-28 14:50:17 -0700 | [diff] [blame] | 473 | // Recalculate the available dimensions using the new hotseat size. |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 474 | updateAvailableDimensions(res); |
Jon Miranda | 2ed276e | 2017-06-29 11:36:34 -0700 | [diff] [blame] | 475 | } |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 476 | |
| 477 | int cellLayoutPadding = |
| 478 | isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize( |
| 479 | R.dimen.cell_layout_padding); |
| 480 | cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding, |
| 481 | cellLayoutPadding); |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 482 | updateWorkspacePadding(); |
Tony Wickham | 1237df0 | 2017-02-24 08:59:36 -0800 | [diff] [blame] | 483 | |
Thales Lima | 828875c | 2022-04-26 20:29:30 +0100 | [diff] [blame] | 484 | // Hotseat and QSB width depends on updated cellSize and workspace padding |
| 485 | hotseatBorderSpace = calculateHotseatBorderSpace(); |
| 486 | qsbWidth = calculateQsbWidth(); |
| 487 | |
Alex Chau | a02eddc | 2021-04-29 00:36:06 +0100 | [diff] [blame] | 488 | flingToDeleteThresholdVelocity = res.getDimensionPixelSize( |
| 489 | R.dimen.drag_flingToDeleteMinVelocity); |
| 490 | |
Tony Wickham | 1237df0 | 2017-02-24 08:59:36 -0800 | [diff] [blame] | 491 | // This is done last, after iconSizePx is calculated above. |
Sunny Goyal | 8b9919d | 2021-04-07 14:45:17 -0700 | [diff] [blame] | 492 | Path dotPath = GraphicsUtils.getShapePath(DEFAULT_DOT_SIZE); |
| 493 | mDotRendererWorkSpace = new DotRenderer(iconSizePx, dotPath, DEFAULT_DOT_SIZE); |
Samuel Fufa | c96fa24 | 2019-09-26 23:06:32 -0700 | [diff] [blame] | 494 | mDotRendererAllApps = iconSizePx == allAppsIconSizePx ? mDotRendererWorkSpace : |
Sunny Goyal | 8b9919d | 2021-04-07 14:45:17 -0700 | [diff] [blame] | 495 | new DotRenderer(allAppsIconSizePx, dotPath, DEFAULT_DOT_SIZE); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 496 | } |
| 497 | |
Thales Lima | 828875c | 2022-04-26 20:29:30 +0100 | [diff] [blame] | 498 | /** |
| 499 | * QSB width is always calculated because when in 3 button nav the width doesn't follow the |
| 500 | * width of the hotseat. |
| 501 | */ |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 502 | private int calculateQsbWidth() { |
Thales Lima | 828875c | 2022-04-26 20:29:30 +0100 | [diff] [blame] | 503 | if (isQsbInline) { |
Pat Manning | b45d6c4 | 2022-05-03 14:32:06 +0100 | [diff] [blame^] | 504 | int columns = getPanelCount() * inv.numColumns; |
Thales Lima | 828875c | 2022-04-26 20:29:30 +0100 | [diff] [blame] | 505 | return getIconToIconWidthForColumns(columns) |
| 506 | - iconSizePx * numShownHotseatIcons |
| 507 | - hotseatBorderSpace * numShownHotseatIcons; |
| 508 | } else { |
| 509 | int columns = inv.hotseatColumnSpan[mTypeIndex]; |
| 510 | return getIconToIconWidthForColumns(columns); |
| 511 | } |
| 512 | } |
Thales Lima | 2903a62 | 2022-03-17 13:52:19 +0000 | [diff] [blame] | 513 | |
Thales Lima | 828875c | 2022-04-26 20:29:30 +0100 | [diff] [blame] | 514 | private int getIconToIconWidthForColumns(int columns) { |
| 515 | return columns * getCellSize().x |
| 516 | + (columns - 1) * cellLayoutBorderSpacePx.x |
| 517 | - (getCellSize().x - iconSizePx); // left and right cell space |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 518 | } |
| 519 | |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 520 | private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) { |
| 521 | if (isVerticalBarLayout()) { |
| 522 | return 0; |
| 523 | } |
| 524 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 525 | return isScalableGrid |
| 526 | ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics) |
| 527 | : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin); |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 528 | } |
| 529 | |
Jon Miranda | 0d28485 | 2021-06-22 14:50:55 -0700 | [diff] [blame] | 530 | private void updateHotseatIconSize(int hotseatIconSizePx) { |
Jon Miranda | 92c1b5d | 2021-07-20 13:57:16 -0700 | [diff] [blame] | 531 | // Ensure there is enough space for folder icons, which have a slightly larger radius. |
| 532 | hotseatCellHeightPx = (int) Math.ceil(hotseatIconSizePx * ICON_OVERLAP_FACTOR); |
Jon Miranda | 0d28485 | 2021-06-22 14:50:55 -0700 | [diff] [blame] | 533 | if (isVerticalBarLayout()) { |
| 534 | hotseatBarSizePx = hotseatIconSizePx + hotseatBarSidePaddingStartPx |
| 535 | + hotseatBarSidePaddingEndPx; |
| 536 | } else { |
| 537 | hotseatBarSizePx = hotseatIconSizePx + hotseatBarTopPaddingPx |
Jon Miranda | 80cddbc | 2021-07-22 13:51:16 -0700 | [diff] [blame] | 538 | + hotseatBarBottomPaddingPx + (isScalableGrid ? 0 : hotseatExtraVerticalSize) |
| 539 | + hotseatBarSizeExtraSpacePx; |
Jon Miranda | 0d28485 | 2021-06-22 14:50:55 -0700 | [diff] [blame] | 540 | } |
| 541 | } |
| 542 | |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 543 | private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) { |
Thales Lima | 080d890 | 2022-03-28 15:30:29 +0100 | [diff] [blame] | 544 | return getCellLayoutBorderSpace(idp, 1f); |
| 545 | |
| 546 | } |
| 547 | |
| 548 | private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) { |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 549 | if (!isScalableGrid) { |
| 550 | return new Point(0, 0); |
| 551 | } |
| 552 | |
Thales Lima | 080d890 | 2022-03-28 15:30:29 +0100 | [diff] [blame] | 553 | int horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale); |
| 554 | int verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 555 | |
| 556 | return new Point(horizontalSpacePx, verticalSpacePx); |
| 557 | } |
| 558 | |
Sunny Goyal | 69a8eec | 2021-07-22 10:02:50 -0700 | [diff] [blame] | 559 | public Info getDisplayInfo() { |
| 560 | return mInfo; |
| 561 | } |
| 562 | |
Jon Miranda | 611dba4 | 2021-03-02 14:12:13 -0500 | [diff] [blame] | 563 | /** |
| 564 | * We inset the widget padding added by the system and instead rely on the border spacing |
| 565 | * between cells to create reliable consistency between widgets |
| 566 | */ |
| 567 | public boolean shouldInsetWidgets() { |
| 568 | Rect widgetPadding = inv.defaultWidgetPadding; |
| 569 | |
Jon Miranda | 4981118 | 2021-06-03 09:52:40 -0700 | [diff] [blame] | 570 | // Check all sides to ensure that the widget won't overlap into another cell, or into |
| 571 | // status bar. |
| 572 | return workspaceTopPadding > widgetPadding.top |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 573 | && cellLayoutBorderSpacePx.x > widgetPadding.left |
| 574 | && cellLayoutBorderSpacePx.y > widgetPadding.top |
| 575 | && cellLayoutBorderSpacePx.x > widgetPadding.right |
| 576 | && cellLayoutBorderSpacePx.y > widgetPadding.bottom; |
Jon Miranda | 611dba4 | 2021-03-02 14:12:13 -0500 | [diff] [blame] | 577 | } |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 578 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 579 | public Builder toBuilder(Context context) { |
Sunny Goyal | 187b16c | 2022-03-01 16:53:23 -0800 | [diff] [blame] | 580 | WindowBounds bounds = new WindowBounds( |
| 581 | widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 582 | bounds.bounds.offsetTo(windowX, windowY); |
Alex Chau | e022755 | 2022-04-06 19:44:43 +0100 | [diff] [blame] | 583 | bounds.insets.set(mInsets); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 584 | return new Builder(context, inv, mInfo) |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 585 | .setWindowBounds(bounds) |
| 586 | .setUseTwoPanels(isTwoPanels) |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 587 | .setMultiWindowMode(isMultiWindowMode) |
| 588 | .setGestureMode(isGestureMode); |
Sunny Goyal | 1a52ef5 | 2018-01-11 10:15:03 -0800 | [diff] [blame] | 589 | } |
| 590 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 591 | public DeviceProfile copy(Context context) { |
| 592 | return toBuilder(context).build(); |
| 593 | } |
| 594 | |
| 595 | /** |
| 596 | * TODO: Move this to the builder as part of setMultiWindowMode |
| 597 | */ |
Sunny Goyal | b46703d | 2020-05-27 17:52:03 -0700 | [diff] [blame] | 598 | public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 599 | DeviceProfile profile = toBuilder(context) |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 600 | .setWindowBounds(windowBounds) |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 601 | .setMultiWindowMode(true) |
| 602 | .build(); |
Jon Miranda | 93e1f04 | 2016-11-11 14:13:04 -0800 | [diff] [blame] | 603 | |
Jon Miranda | 941375e | 2021-03-31 13:10:45 -0400 | [diff] [blame] | 604 | profile.hideWorkspaceLabelsIfNotEnoughSpace(); |
Jon Miranda | 93e1f04 | 2016-11-11 14:13:04 -0800 | [diff] [blame] | 605 | |
Jon Miranda | 7ae64ff | 2016-11-21 16:18:46 -0800 | [diff] [blame] | 606 | // We use these scales to measure and layout the widgets using their full invariant profile |
| 607 | // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans. |
| 608 | float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x; |
| 609 | float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y; |
| 610 | profile.appWidgetScale.set(appWidgetScaleX, appWidgetScaleY); |
| 611 | |
Jon Miranda | 93e1f04 | 2016-11-11 14:13:04 -0800 | [diff] [blame] | 612 | return profile; |
Jon Miranda | cc42c5b | 2016-10-27 17:15:27 -0700 | [diff] [blame] | 613 | } |
| 614 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 615 | /** |
Jon Miranda | 941375e | 2021-03-31 13:10:45 -0400 | [diff] [blame] | 616 | * Checks if there is enough space for labels on the workspace. |
| 617 | * If there is not, labels on the Workspace are hidden. |
Jon Miranda | 1091e53 | 2017-07-21 13:31:50 -0700 | [diff] [blame] | 618 | * It is important to call this method after the All Apps variables have been set. |
| 619 | */ |
Jon Miranda | 941375e | 2021-03-31 13:10:45 -0400 | [diff] [blame] | 620 | private void hideWorkspaceLabelsIfNotEnoughSpace() { |
| 621 | float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx); |
| 622 | float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx |
| 623 | - iconTextHeight; |
| 624 | |
| 625 | // We want enough space so that the text is closer to its corresponding icon. |
| 626 | if (workspaceCellPaddingY < iconTextHeight) { |
| 627 | iconTextSizePx = 0; |
| 628 | iconDrawablePaddingPx = 0; |
Jon Miranda | 92c1b5d | 2021-07-20 13:57:16 -0700 | [diff] [blame] | 629 | cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR); |
Jon Miranda | 941375e | 2021-03-31 13:10:45 -0400 | [diff] [blame] | 630 | autoResizeAllAppsCells(); |
| 631 | } |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 632 | } |
Jon Miranda | 1091e53 | 2017-07-21 13:31:50 -0700 | [diff] [blame] | 633 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 634 | /** |
| 635 | * Re-computes the all-apps cell size to be independent of workspace |
| 636 | */ |
| 637 | public void autoResizeAllAppsCells() { |
Jon Miranda | 941375e | 2021-03-31 13:10:45 -0400 | [diff] [blame] | 638 | int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx); |
| 639 | int topBottomPadding = textHeight; |
Jon Miranda | 1091e53 | 2017-07-21 13:31:50 -0700 | [diff] [blame] | 640 | allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx |
Jon Miranda | 941375e | 2021-03-31 13:10:45 -0400 | [diff] [blame] | 641 | + textHeight + (topBottomPadding * 2); |
Jon Miranda | 1091e53 | 2017-07-21 13:31:50 -0700 | [diff] [blame] | 642 | } |
| 643 | |
Thales Lima | b7ef569 | 2022-03-10 10:32:36 +0000 | [diff] [blame] | 644 | private void updateAllAppsContainerWidth(Resources res) { |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 645 | int cellLayoutHorizontalPadding = |
| 646 | (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2; |
Alex Chau | 27b39b9 | 2022-01-14 18:02:18 +0000 | [diff] [blame] | 647 | if (isTablet) { |
Thales Lima | b7ef569 | 2022-03-10 10:32:36 +0000 | [diff] [blame] | 648 | allAppsLeftRightPadding = |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 649 | res.getDimensionPixelSize(R.dimen.all_apps_bottom_sheet_horizontal_padding); |
| 650 | |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 651 | int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns) |
Thales Lima | b7ef569 | 2022-03-10 10:32:36 +0000 | [diff] [blame] | 652 | + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1)) |
Alex Chau | 27b39b9 | 2022-01-14 18:02:18 +0000 | [diff] [blame] | 653 | + allAppsLeftRightPadding * 2; |
| 654 | allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2); |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 655 | } else { |
| 656 | allAppsLeftRightPadding = |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 657 | desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding; |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 661 | /** |
| 662 | * Returns the amount of extra (or unused) vertical space. |
| 663 | */ |
| 664 | private int updateAvailableDimensions(Resources res) { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 665 | updateIconSize(1f, res); |
Winson Chung | 59a488a | 2013-12-10 12:32:14 -0800 | [diff] [blame] | 666 | |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 667 | updateWorkspacePadding(); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 668 | |
| 669 | // Check to see if the icons fit within the available height. |
Pat Manning | a2e1499 | 2022-04-22 11:29:17 +0100 | [diff] [blame] | 670 | float usedHeight = getCellLayoutHeightSpecification(); |
Pat Manning | b45d6c4 | 2022-05-03 14:32:06 +0100 | [diff] [blame^] | 671 | final int maxHeight = getCellLayoutHeight(); |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 672 | float extraHeight = Math.max(0, maxHeight - usedHeight); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 673 | float scaleY = maxHeight / usedHeight; |
| 674 | boolean shouldScale = scaleY < 1f; |
| 675 | |
| 676 | float scaleX = 1f; |
| 677 | if (isScalableGrid) { |
| 678 | // We scale to fit the cellWidth and cellHeight in the available space. |
| 679 | // The benefit of scalable grids is that we can get consistent aspect ratios between |
| 680 | // devices. |
Pat Manning | a2e1499 | 2022-04-22 11:29:17 +0100 | [diff] [blame] | 681 | float usedWidth = |
| 682 | getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 683 | // We do not subtract padding here, as we also scale the workspace padding if needed. |
| 684 | scaleX = availableWidthPx / usedWidth; |
| 685 | shouldScale = true; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 686 | } |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 687 | |
| 688 | if (shouldScale) { |
| 689 | float scale = Math.min(scaleX, scaleY); |
| 690 | updateIconSize(scale, res); |
Pat Manning | a2e1499 | 2022-04-22 11:29:17 +0100 | [diff] [blame] | 691 | extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification()); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 692 | } |
| 693 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 694 | updateAvailableFolderCellDimensions(res); |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 695 | return Math.round(extraHeight); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 696 | } |
| 697 | |
Pat Manning | a2e1499 | 2022-04-22 11:29:17 +0100 | [diff] [blame] | 698 | private int getCellLayoutHeightSpecification() { |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 699 | return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1)) |
| 700 | + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom; |
| 701 | } |
| 702 | |
Pat Manning | a2e1499 | 2022-04-22 11:29:17 +0100 | [diff] [blame] | 703 | private int getCellLayoutWidthSpecification() { |
Pat Manning | b45d6c4 | 2022-05-03 14:32:06 +0100 | [diff] [blame^] | 704 | int numColumns = getPanelCount() * inv.numColumns; |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 705 | return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1)) |
| 706 | + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 707 | } |
| 708 | |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 709 | /** |
| 710 | * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx, |
| 711 | * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants, |
| 712 | * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx. |
| 713 | */ |
Tony Wickham | 7ba547c | 2021-02-02 17:12:08 -0800 | [diff] [blame] | 714 | public void updateIconSize(float scale, Resources res) { |
Jon Miranda | ab3c681 | 2021-06-28 15:42:28 -0700 | [diff] [blame] | 715 | // Icon scale should never exceed 1, otherwise pixellation may occur. |
| 716 | iconScale = Math.min(1f, scale); |
| 717 | cellScaleToFit = scale; |
| 718 | |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 719 | // Workspace |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 720 | final boolean isVerticalLayout = isVerticalBarLayout(); |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 721 | float invIconSizeDp = inv.iconSize[mTypeIndex]; |
| 722 | float invIconTextSizeSp = inv.iconTextSize[mTypeIndex]; |
Andras Kloczl | 30fe915 | 2021-08-05 18:02:29 +0200 | [diff] [blame] | 723 | |
Jon Miranda | ab3c681 | 2021-06-28 15:42:28 -0700 | [diff] [blame] | 724 | iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, iconScale)); |
Jon Miranda | ab3c681 | 2021-06-28 15:42:28 -0700 | [diff] [blame] | 725 | iconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * iconScale); |
| 726 | iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * iconScale); |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 727 | |
Thales Lima | 080d890 | 2022-03-28 15:30:29 +0100 | [diff] [blame] | 728 | cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 729 | |
| 730 | if (isScalableGrid) { |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 731 | cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale); |
| 732 | cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 733 | int cellContentHeight = iconSizePx + iconDrawablePaddingPx |
| 734 | + Utilities.calculateTextHeight(iconTextSizePx); |
| 735 | cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2; |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 736 | desiredWorkspaceHorizontalMarginPx = |
| 737 | (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale); |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 738 | } else { |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 739 | cellWidthPx = iconSizePx + iconDrawablePaddingPx; |
Jon Miranda | 92c1b5d | 2021-07-20 13:57:16 -0700 | [diff] [blame] | 740 | cellHeightPx = (int) Math.ceil(iconSizePx * ICON_OVERLAP_FACTOR) |
| 741 | + iconDrawablePaddingPx |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 742 | + Utilities.calculateTextHeight(iconTextSizePx); |
| 743 | int cellPaddingY = (getCellSize().y - cellHeightPx) / 2; |
| 744 | if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout |
| 745 | && !isMultiWindowMode) { |
| 746 | // Ensures that the label is closer to its corresponding icon. This is not an issue |
| 747 | // with vertical bar layout or multi-window mode since the issue is handled |
| 748 | // separately with their calls to {@link #adjustToHideWorkspaceLabels}. |
| 749 | cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY); |
| 750 | iconDrawablePaddingPx = cellPaddingY; |
| 751 | } |
Jon Miranda | 846455e | 2017-10-02 14:58:52 -0700 | [diff] [blame] | 752 | } |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 753 | |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 754 | // All apps |
Brian Isganitis | 25b2ac8 | 2022-01-28 16:25:13 -0500 | [diff] [blame] | 755 | updateAllAppsIconSize(scale, res); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 756 | |
Jon Miranda | 0d28485 | 2021-06-22 14:50:55 -0700 | [diff] [blame] | 757 | updateHotseatIconSize(iconSizePx); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 758 | |
Sunny Goyal | baec6ff | 2016-09-14 11:26:21 -0700 | [diff] [blame] | 759 | // Folder icon |
Jon Miranda | 591e360 | 2018-03-28 11:37:00 -0700 | [diff] [blame] | 760 | folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx); |
| 761 | folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2; |
Winson Chung | 0f78572 | 2015-04-08 10:27:49 -0700 | [diff] [blame] | 762 | } |
| 763 | |
Thales Lima | 828875c | 2022-04-26 20:29:30 +0100 | [diff] [blame] | 764 | /** |
| 765 | * Hotseat width spans a certain number of columns on scalable grids. |
| 766 | * This method calculates the space between the icons to achieve that width. |
| 767 | */ |
| 768 | private int calculateHotseatBorderSpace() { |
| 769 | if (!isScalableGrid) return 0; |
| 770 | //TODO(http://b/228998082) remove this when 3 button spaces are fixed |
| 771 | if (areNavButtonsInline) { |
| 772 | return pxFromDp(inv.hotseatBorderSpaces[mTypeIndex], mMetrics); |
| 773 | } else { |
| 774 | int columns = inv.hotseatColumnSpan[mTypeIndex]; |
| 775 | float hotseatWidthPx = getIconToIconWidthForColumns(columns); |
| 776 | float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons; |
| 777 | return (int) (hotseatWidthPx - hotseatIconsTotalPx) / (numShownHotseatIcons - 1); |
| 778 | } |
| 779 | } |
| 780 | |
Brian Isganitis | 25b2ac8 | 2022-01-28 16:25:13 -0500 | [diff] [blame] | 781 | |
| 782 | /** |
| 783 | * Updates the iconSize for allApps* variants. |
| 784 | */ |
| 785 | public void updateAllAppsIconSize(float scale, Resources res) { |
Thales Lima | 080d890 | 2022-03-28 15:30:29 +0100 | [diff] [blame] | 786 | allAppsBorderSpacePx = new Point( |
| 787 | pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale), |
| 788 | pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale)); |
| 789 | if (isScalableGrid) { |
Brian Isganitis | 25b2ac8 | 2022-01-28 16:25:13 -0500 | [diff] [blame] | 790 | allAppsIconSizePx = |
| 791 | pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics); |
| 792 | allAppsIconTextSizePx = |
| 793 | pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics); |
| 794 | allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx; |
Thales Lima | 080d890 | 2022-03-28 15:30:29 +0100 | [diff] [blame] | 795 | // AllApps cells don't have real space between cells, |
| 796 | // so we add the border space to the cell height |
| 797 | allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics, scale) |
| 798 | + allAppsBorderSpacePx.y; |
| 799 | // but width is just the cell, |
| 800 | // the border is added in #updateAllAppsContainerWidth |
Thales Lima | b7ef569 | 2022-03-10 10:32:36 +0000 | [diff] [blame] | 801 | allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale); |
Brian Isganitis | 25b2ac8 | 2022-01-28 16:25:13 -0500 | [diff] [blame] | 802 | } else { |
| 803 | float invIconSizeDp = inv.iconSize[mTypeIndex]; |
| 804 | float invIconTextSizeSp = inv.iconTextSize[mTypeIndex]; |
| 805 | allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale)); |
| 806 | allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale); |
| 807 | allAppsIconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * scale); |
Thales Lima | b7ef569 | 2022-03-10 10:32:36 +0000 | [diff] [blame] | 808 | allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx); |
Brian Isganitis | 25b2ac8 | 2022-01-28 16:25:13 -0500 | [diff] [blame] | 809 | allAppsCellHeightPx = getCellSize().y; |
| 810 | } |
| 811 | |
Thales Lima | b7ef569 | 2022-03-10 10:32:36 +0000 | [diff] [blame] | 812 | updateAllAppsContainerWidth(res); |
Brian Isganitis | 25b2ac8 | 2022-01-28 16:25:13 -0500 | [diff] [blame] | 813 | if (isVerticalBarLayout()) { |
| 814 | hideWorkspaceLabelsIfNotEnoughSpace(); |
| 815 | } |
| 816 | } |
| 817 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 818 | private void updateAvailableFolderCellDimensions(Resources res) { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 819 | updateFolderCellSize(1f, res); |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 820 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 821 | final int folderBottomPanelSize = res.getDimensionPixelSize(R.dimen.folder_label_height); |
| 822 | |
Jon Miranda | c1b2399 | 2016-12-13 08:57:36 -0800 | [diff] [blame] | 823 | // Don't let the folder get too close to the edges of the screen. |
Jon Miranda | 1786df3 | 2018-09-25 13:05:23 -0700 | [diff] [blame] | 824 | int folderMargin = edgeMarginPx * 2; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 825 | Point totalWorkspacePadding = getTotalWorkspacePadding(); |
Jon Miranda | c1b2399 | 2016-12-13 08:57:36 -0800 | [diff] [blame] | 826 | |
| 827 | // Check if the icons fit within the available height. |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 828 | float contentUsedHeight = folderCellHeightPx * inv.numFolderRows |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 829 | + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx.y); |
Samuel Fufa | 1c8d90a | 2019-11-12 17:54:58 -0800 | [diff] [blame] | 830 | int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderBottomPanelSize |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 831 | - folderMargin - folderContentPaddingTop; |
Samuel Fufa | 1c8d90a | 2019-11-12 17:54:58 -0800 | [diff] [blame] | 832 | float scaleY = contentMaxHeight / contentUsedHeight; |
Jon Miranda | c1b2399 | 2016-12-13 08:57:36 -0800 | [diff] [blame] | 833 | |
| 834 | // Check if the icons fit within the available width. |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 835 | float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 836 | + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 837 | int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin |
| 838 | - folderContentPaddingLeftRight * 2; |
Samuel Fufa | 1c8d90a | 2019-11-12 17:54:58 -0800 | [diff] [blame] | 839 | float scaleX = contentMaxWidth / contentUsedWidth; |
Jon Miranda | c1b2399 | 2016-12-13 08:57:36 -0800 | [diff] [blame] | 840 | |
| 841 | float scale = Math.min(scaleX, scaleY); |
| 842 | if (scale < 1f) { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 843 | updateFolderCellSize(scale, res); |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 844 | } |
| 845 | } |
| 846 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 847 | private void updateFolderCellSize(float scale, Resources res) { |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 848 | float invIconSizeDp = isVerticalBarLayout() |
Thales Lima | 12d0eff | 2022-03-25 17:06:11 +0000 | [diff] [blame] | 849 | ? inv.iconSize[INDEX_LANDSCAPE] |
| 850 | : inv.iconSize[INDEX_DEFAULT]; |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 851 | folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale)); |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 852 | folderChildTextSizePx = |
Thales Lima | 12d0eff | 2022-03-25 17:06:11 +0000 | [diff] [blame] | 853 | pxFromSp(inv.iconTextSize[INDEX_DEFAULT], mMetrics, scale); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 854 | folderLabelTextSizePx = (int) (folderChildTextSizePx * folderLabelTextScale); |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 855 | |
| 856 | int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx); |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 857 | |
Jon Miranda | 823da22 | 2021-03-23 08:08:45 -0400 | [diff] [blame] | 858 | if (isScalableGrid) { |
Jon Miranda | f33f5b3 | 2021-07-22 17:15:31 -0700 | [diff] [blame] | 859 | int minWidth = folderChildIconSizePx + iconDrawablePaddingPx * 2; |
| 860 | int minHeight = folderChildIconSizePx + iconDrawablePaddingPx * 2 + textHeight; |
| 861 | |
| 862 | folderCellWidthPx = (int) Math.max(minWidth, cellWidthPx * scale); |
| 863 | folderCellHeightPx = (int) Math.max(minHeight, cellHeightPx * scale); |
Jon Miranda | 823da22 | 2021-03-23 08:08:45 -0400 | [diff] [blame] | 864 | |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 865 | int scaledSpace = (int) (folderCellLayoutBorderSpaceOriginalPx * scale); |
| 866 | folderCellLayoutBorderSpacePx = new Point(scaledSpace, scaledSpace); |
| 867 | folderContentPaddingLeftRight = scaledSpace; |
| 868 | folderContentPaddingTop = scaledSpace; |
Jon Miranda | 823da22 | 2021-03-23 08:08:45 -0400 | [diff] [blame] | 869 | } else { |
| 870 | int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding) |
| 871 | * scale); |
| 872 | int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding) |
| 873 | * scale); |
| 874 | |
| 875 | folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX; |
| 876 | folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight; |
| 877 | } |
| 878 | |
Jonathan Miranda | 9ad8746 | 2017-07-26 17:41:02 +0000 | [diff] [blame] | 879 | folderChildDrawablePaddingPx = Math.max(0, |
| 880 | (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3); |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 881 | } |
| 882 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 883 | public void updateInsets(Rect insets) { |
| 884 | mInsets.set(insets); |
| 885 | } |
| 886 | |
Sunny Goyal | ae6e318 | 2019-04-30 12:04:37 -0700 | [diff] [blame] | 887 | /** |
| 888 | * The current device insets. This is generally same as the insets being dispatched to |
| 889 | * {@link Insettable} elements, but can differ if the element is using a different profile. |
| 890 | */ |
Sunny Goyal | 1a52ef5 | 2018-01-11 10:15:03 -0800 | [diff] [blame] | 891 | public Rect getInsets() { |
| 892 | return mInsets; |
| 893 | } |
| 894 | |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 895 | public Point getCellSize() { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 896 | return getCellSize(null); |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 897 | } |
| 898 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 899 | public Point getCellSize(Point result) { |
| 900 | if (result == null) { |
| 901 | result = new Point(); |
| 902 | } |
Thales Lima | d1df5fc | 2021-09-03 18:37:19 +0100 | [diff] [blame] | 903 | |
Pat Manning | b45d6c4 | 2022-05-03 14:32:06 +0100 | [diff] [blame^] | 904 | result.x = calculateCellWidth(getShortcutAndWidgetContainerWidth(), |
| 905 | cellLayoutBorderSpacePx.x, inv.numColumns); |
| 906 | result.y = calculateCellHeight(getShortcutAndWidgetContainerHeight(), |
| 907 | cellLayoutBorderSpacePx.y, inv.numRows); |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 908 | return result; |
| 909 | } |
| 910 | |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 911 | /** |
Pat Manning | b45d6c4 | 2022-05-03 14:32:06 +0100 | [diff] [blame^] | 912 | * Gets the number of panels within the workspace. |
| 913 | */ |
| 914 | public int getPanelCount() { |
| 915 | return isTwoPanels ? 2 : 1; |
| 916 | } |
| 917 | |
| 918 | /** |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 919 | * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the |
| 920 | * bottom of the screen. |
| 921 | */ |
| 922 | public int getVerticalHotseatLastItemBottomOffset() { |
| 923 | int cellHeight = calculateCellHeight( |
| 924 | heightPx - mHotseatPadding.top - mHotseatPadding.bottom, hotseatBorderSpace, |
| 925 | numShownHotseatIcons); |
| 926 | int hotseatSize = (cellHeight * numShownHotseatIcons) |
| 927 | + (hotseatBorderSpace * (numShownHotseatIcons - 1)); |
| 928 | int extraHotseatEndSpacing = (heightPx - hotseatSize) / 2; |
| 929 | int extraIconEndSpacing = (cellHeight - iconSizePx) / 2; |
| 930 | return extraHotseatEndSpacing + extraIconEndSpacing + mHotseatPadding.bottom; |
| 931 | } |
| 932 | |
| 933 | /** |
| 934 | * Gets the scaled top of the workspace in px for the spring-loaded edit state. |
| 935 | */ |
Pat Manning | b45d6c4 | 2022-05-03 14:32:06 +0100 | [diff] [blame^] | 936 | public float getCellLayoutSpringLoadShrunkTop() { |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 937 | workspaceSpringLoadShrunkTop = mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx |
| 938 | + dropTargetBarBottomMarginPx; |
| 939 | return workspaceSpringLoadShrunkTop; |
| 940 | } |
| 941 | |
| 942 | /** |
| 943 | * Gets the scaled bottom of the workspace in px for the spring-loaded edit state. |
| 944 | */ |
Pat Manning | b45d6c4 | 2022-05-03 14:32:06 +0100 | [diff] [blame^] | 945 | private float getCellLayoutSpringLoadShrunkBottom() { |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 946 | int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx; |
| 947 | workspaceSpringLoadShrunkBottom = |
| 948 | heightPx - (isVerticalBarLayout() ? getVerticalHotseatLastItemBottomOffset() |
| 949 | : topOfHotseat); |
| 950 | return workspaceSpringLoadShrunkBottom; |
| 951 | } |
| 952 | |
Pat Manning | ea5c1d2 | 2022-04-14 10:58:16 +0100 | [diff] [blame] | 953 | /** |
| 954 | * Gets the minimum visible amount of the next workspace page when in the spring-loaded state. |
| 955 | */ |
Pat Manning | a2e1499 | 2022-04-22 11:29:17 +0100 | [diff] [blame] | 956 | private float getWorkspaceSpringLoadedMinimumNextPageVisible() { |
Pat Manning | ea5c1d2 | 2022-04-14 10:58:16 +0100 | [diff] [blame] | 957 | return getCellSize().x / 2f; |
| 958 | } |
| 959 | |
Pat Manning | a2e1499 | 2022-04-22 11:29:17 +0100 | [diff] [blame] | 960 | /** |
| 961 | * Gets the scale of the workspace for the spring-loaded edit state. |
| 962 | */ |
| 963 | public float getWorkspaceSpringLoadScale() { |
Pat Manning | b45d6c4 | 2022-05-03 14:32:06 +0100 | [diff] [blame^] | 964 | float scale = (getCellLayoutSpringLoadShrunkBottom() - getCellLayoutSpringLoadShrunkTop()) |
| 965 | / getCellLayoutHeight(); |
Pat Manning | a2e1499 | 2022-04-22 11:29:17 +0100 | [diff] [blame] | 966 | scale = Math.min(scale, 1f); |
| 967 | |
| 968 | // Reduce scale if next pages would not be visible after scaling the workspace |
| 969 | int workspaceWidth = getWorkspaceWidth(); |
| 970 | float scaledWorkspaceWidth = workspaceWidth * scale; |
| 971 | float maxAvailableWidth = |
| 972 | workspaceWidth - (2 * getWorkspaceSpringLoadedMinimumNextPageVisible()); |
| 973 | if (scaledWorkspaceWidth > maxAvailableWidth) { |
| 974 | scale *= maxAvailableWidth / scaledWorkspaceWidth; |
| 975 | } |
| 976 | return scale; |
| 977 | } |
| 978 | |
Pat Manning | b45d6c4 | 2022-05-03 14:32:06 +0100 | [diff] [blame^] | 979 | /** |
| 980 | * Gets the width of the Workspace, aka a scrollable page of the homescreen. |
| 981 | */ |
Alex Chau | 6095333 | 2021-11-24 12:41:07 +0000 | [diff] [blame] | 982 | public int getWorkspaceWidth() { |
Pat Manning | b45d6c4 | 2022-05-03 14:32:06 +0100 | [diff] [blame^] | 983 | return availableWidthPx; |
Alex Chau | 6095333 | 2021-11-24 12:41:07 +0000 | [diff] [blame] | 984 | } |
| 985 | |
Pat Manning | b45d6c4 | 2022-05-03 14:32:06 +0100 | [diff] [blame^] | 986 | /** |
| 987 | * Gets the height of the Workspace, aka a scrollable page of the homescreen. |
| 988 | */ |
| 989 | public int getWorkspaceHeight() { |
| 990 | return availableHeightPx; |
Alex Chau | 6095333 | 2021-11-24 12:41:07 +0000 | [diff] [blame] | 991 | } |
| 992 | |
Pat Manning | b45d6c4 | 2022-05-03 14:32:06 +0100 | [diff] [blame^] | 993 | /** |
| 994 | * Gets the width of a single Cell Layout, aka a single panel within a Workspace. |
| 995 | * |
| 996 | * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel |
| 997 | * layouts have two Cell Layouts per workspace. |
| 998 | */ |
| 999 | public int getCellLayoutWidth() { |
| 1000 | return (getWorkspaceWidth() - getTotalWorkspacePadding().x) / getPanelCount(); |
| 1001 | } |
| 1002 | |
| 1003 | /** |
| 1004 | * Gets the height of a single Cell Layout, aka a single panel within a Workspace. |
| 1005 | * |
| 1006 | * <p>This is the height of a Workspace, less its vertical padding. |
| 1007 | */ |
| 1008 | public int getCellLayoutHeight() { |
| 1009 | return getWorkspaceHeight() - getTotalWorkspacePadding().y; |
| 1010 | } |
| 1011 | |
| 1012 | /** |
| 1013 | * Gets the width of the container holding the shortcuts and widgets. |
| 1014 | * |
| 1015 | * <p>This is the width of one Cell Layout less its horizontal padding. |
| 1016 | */ |
| 1017 | public int getShortcutAndWidgetContainerWidth() { |
| 1018 | return getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right); |
| 1019 | } |
| 1020 | |
| 1021 | /** |
| 1022 | * Gets the height of the container holding the shortcuts and widgets. |
| 1023 | * |
| 1024 | * <p>This is the height of one Cell Layout less its vertical padding. |
| 1025 | */ |
| 1026 | public int getShortcutAndWidgetContainerHeight() { |
| 1027 | return getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom); |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 1028 | } |
| 1029 | |
Sunny Goyal | 6c2975e | 2016-07-06 09:47:56 -0700 | [diff] [blame] | 1030 | public Point getTotalWorkspacePadding() { |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 1031 | return new Point(workspacePadding.left + workspacePadding.right, |
| 1032 | workspacePadding.top + workspacePadding.bottom); |
Sunny Goyal | 6c2975e | 2016-07-06 09:47:56 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | /** |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 1036 | * Updates {@link #workspacePadding} as a result of any internal value change to reflect the |
| 1037 | * new workspace padding |
Sunny Goyal | 6c2975e | 2016-07-06 09:47:56 -0700 | [diff] [blame] | 1038 | */ |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 1039 | private void updateWorkspacePadding() { |
| 1040 | Rect padding = workspacePadding; |
Tony Wickham | 3a3517f | 2015-10-06 11:27:04 -0700 | [diff] [blame] | 1041 | if (isVerticalBarLayout()) { |
Sunny Goyal | 228153d | 2018-01-04 15:35:22 -0800 | [diff] [blame] | 1042 | padding.top = 0; |
| 1043 | padding.bottom = edgeMarginPx; |
Sunny Goyal | 7e2e67f | 2018-01-26 13:40:08 -0800 | [diff] [blame] | 1044 | if (isSeascape()) { |
Tony Wickham | 1eeffbe | 2018-06-12 15:01:15 -0700 | [diff] [blame] | 1045 | padding.left = hotseatBarSizePx; |
Tony Wickham | 5edf9e2 | 2020-03-27 20:06:52 -0700 | [diff] [blame] | 1046 | padding.right = hotseatBarSidePaddingStartPx; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 1047 | } else { |
Tony Wickham | 5edf9e2 | 2020-03-27 20:06:52 -0700 | [diff] [blame] | 1048 | padding.left = hotseatBarSidePaddingStartPx; |
Tony Wickham | 1eeffbe | 2018-06-12 15:01:15 -0700 | [diff] [blame] | 1049 | padding.right = hotseatBarSizePx; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 1050 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 1051 | } else { |
Thales Lima | 7a6752d | 2021-09-23 14:31:00 +0100 | [diff] [blame] | 1052 | // Pad the bottom of the workspace with search/hotseat bar sizes |
Tony Wickham | 21970cc | 2021-09-15 15:44:05 -0700 | [diff] [blame] | 1053 | int hotseatTop = hotseatBarSizePx; |
Tony Wickham | a29a046 | 2021-03-02 12:28:25 -0800 | [diff] [blame] | 1054 | int paddingBottom = hotseatTop + workspacePageIndicatorHeight |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 1055 | + workspaceBottomPadding - mWorkspacePageIndicatorOverlapWorkspace; |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 1056 | int paddingTop = workspaceTopPadding + (isScalableGrid ? 0 : edgeMarginPx); |
| 1057 | int paddingSide = desiredWorkspaceHorizontalMarginPx; |
Andras Kloczl | 8e57cce | 2021-02-11 23:51:19 +0100 | [diff] [blame] | 1058 | |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 1059 | padding.set(paddingSide, paddingTop, paddingSide, paddingBottom); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 1060 | } |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 1061 | insetPadding(workspacePadding, cellLayoutPaddingPx); |
| 1062 | } |
| 1063 | |
| 1064 | private void insetPadding(Rect paddings, Rect insets) { |
| 1065 | insets.left = Math.min(insets.left, paddings.left); |
| 1066 | paddings.left -= insets.left; |
| 1067 | |
| 1068 | insets.top = Math.min(insets.top, paddings.top); |
| 1069 | paddings.top -= insets.top; |
| 1070 | |
| 1071 | insets.right = Math.min(insets.right, paddings.right); |
| 1072 | paddings.right -= insets.right; |
| 1073 | |
| 1074 | insets.bottom = Math.min(insets.bottom, paddings.bottom); |
| 1075 | paddings.bottom -= insets.bottom; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
Sunny Goyal | 57b2279 | 2021-05-25 14:35:01 -0700 | [diff] [blame] | 1078 | /** |
| 1079 | * Returns the padding for hotseat view |
| 1080 | */ |
| 1081 | public Rect getHotseatLayoutPadding(Context context) { |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 1082 | if (isVerticalBarLayout()) { |
Sihua Ma | 38bb3b0 | 2022-03-21 22:20:14 -0700 | [diff] [blame] | 1083 | // The hotseat icons will be placed in the middle of the hotseat cells. |
| 1084 | // Changing the hotseatCellHeightPx is not affecting hotseat icon positions |
| 1085 | // in vertical bar layout. |
| 1086 | // Workspace icons are moved up by a small factor. The variable diffOverlapFactor |
| 1087 | // is set to account for that difference. |
| 1088 | float diffOverlapFactor = iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2; |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 1089 | int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top |
| 1090 | - diffOverlapFactor), 0); |
| 1091 | int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom |
Sihua Ma | 38bb3b0 | 2022-03-21 22:20:14 -0700 | [diff] [blame] | 1092 | + diffOverlapFactor), 0); |
| 1093 | |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 1094 | if (isSeascape()) { |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 1095 | mHotseatPadding.set(mInsets.left + hotseatBarSidePaddingStartPx, paddingTop, |
| 1096 | hotseatBarSidePaddingEndPx, paddingBottom); |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 1097 | } else { |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 1098 | mHotseatPadding.set(hotseatBarSidePaddingEndPx, paddingTop, |
| 1099 | mInsets.right + hotseatBarSidePaddingStartPx, paddingBottom); |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 1100 | } |
Sunny Goyal | 57b2279 | 2021-05-25 14:35:01 -0700 | [diff] [blame] | 1101 | } else if (isTaskbarPresent) { |
Thales Lima | 612230d | 2022-03-31 18:04:37 +0100 | [diff] [blame] | 1102 | boolean isRtl = Utilities.isRtl(context.getResources()); |
Tony Wickham | 21970cc | 2021-09-15 15:44:05 -0700 | [diff] [blame] | 1103 | int hotseatHeight = workspacePadding.bottom; |
Sunny Goyal | 57b2279 | 2021-05-25 14:35:01 -0700 | [diff] [blame] | 1104 | int taskbarOffset = getTaskbarOffsetY(); |
Thales Lima | 612230d | 2022-03-31 18:04:37 +0100 | [diff] [blame] | 1105 | // Push icons to the side |
| 1106 | int additionalQsbSpace = isQsbInline ? qsbWidth + hotseatBorderSpace : 0; |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 1107 | |
Thales Lima | 612230d | 2022-03-31 18:04:37 +0100 | [diff] [blame] | 1108 | // Center the QSB vertically with hotseat |
Thales Lima | 7d14923 | 2022-03-21 18:27:45 +0000 | [diff] [blame] | 1109 | int hotseatTopPadding = hotseatHeight - taskbarOffset - hotseatCellHeightPx; |
Sunny Goyal | 57b2279 | 2021-05-25 14:35:01 -0700 | [diff] [blame] | 1110 | |
Vinit Nayak | 8dcbde8 | 2021-07-19 12:53:28 -0700 | [diff] [blame] | 1111 | int endOffset = ApiWrapper.getHotseatEndOffset(context); |
Thales Lima | 6e7f36c | 2022-01-04 12:14:11 +0000 | [diff] [blame] | 1112 | int requiredWidth = iconSizePx * numShownHotseatIcons |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 1113 | + hotseatBorderSpace * (numShownHotseatIcons - 1) |
Thales Lima | 612230d | 2022-03-31 18:04:37 +0100 | [diff] [blame] | 1114 | + additionalQsbSpace; |
Sunny Goyal | 57b2279 | 2021-05-25 14:35:01 -0700 | [diff] [blame] | 1115 | |
Thales Lima | 612230d | 2022-03-31 18:04:37 +0100 | [diff] [blame] | 1116 | int hotseatWidth = Math.min(requiredWidth, availableWidthPx - endOffset); |
| 1117 | int sideSpacing = (availableWidthPx - hotseatWidth) / 2; |
| 1118 | mHotseatPadding.set(sideSpacing, hotseatTopPadding, sideSpacing, taskbarOffset); |
| 1119 | |
| 1120 | if (isRtl) { |
| 1121 | mHotseatPadding.right += additionalQsbSpace; |
| 1122 | } else { |
| 1123 | mHotseatPadding.left += additionalQsbSpace; |
| 1124 | } |
Sunny Goyal | 57b2279 | 2021-05-25 14:35:01 -0700 | [diff] [blame] | 1125 | |
Vinit Nayak | 8dcbde8 | 2021-07-19 12:53:28 -0700 | [diff] [blame] | 1126 | if (endOffset > sideSpacing) { |
Thales Lima | 612230d | 2022-03-31 18:04:37 +0100 | [diff] [blame] | 1127 | int diff = isRtl |
Vinit Nayak | 8dcbde8 | 2021-07-19 12:53:28 -0700 | [diff] [blame] | 1128 | ? sideSpacing - endOffset |
| 1129 | : endOffset - sideSpacing; |
| 1130 | mHotseatPadding.left -= diff; |
| 1131 | mHotseatPadding.right += diff; |
Sunny Goyal | 57b2279 | 2021-05-25 14:35:01 -0700 | [diff] [blame] | 1132 | } |
Thales Lima | 828875c | 2022-04-26 20:29:30 +0100 | [diff] [blame] | 1133 | } else if (isScalableGrid) { |
| 1134 | int sideSpacing = (availableWidthPx - qsbWidth) / 2; |
| 1135 | mHotseatPadding.set(sideSpacing, |
| 1136 | hotseatBarTopPaddingPx, |
| 1137 | sideSpacing, |
| 1138 | hotseatBarSizePx - hotseatCellHeightPx - hotseatBarTopPaddingPx |
| 1139 | + mInsets.bottom); |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 1140 | } else { |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 1141 | // We want the edges of the hotseat to line up with the edges of the workspace, but the |
| 1142 | // icons in the hotseat are a different size, and so don't line up perfectly. To account |
| 1143 | // for this, we pad the left and right of the hotseat with half of the difference of a |
| 1144 | // workspace cell vs a hotseat cell. |
| 1145 | float workspaceCellWidth = (float) widthPx / inv.numColumns; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 1146 | float hotseatCellWidth = (float) widthPx / numShownHotseatIcons; |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 1147 | int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2); |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 1148 | mHotseatPadding.set(hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left |
| 1149 | + mInsets.left, hotseatBarTopPaddingPx, |
| 1150 | hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right |
Sunny Goyal | 786940a | 2020-06-02 02:31:31 -0700 | [diff] [blame] | 1151 | + mInsets.right, |
Jon Miranda | 0d28485 | 2021-06-22 14:50:55 -0700 | [diff] [blame] | 1152 | hotseatBarSizePx - hotseatCellHeightPx - hotseatBarTopPaddingPx |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 1153 | + mInsets.bottom); |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 1154 | } |
| 1155 | return mHotseatPadding; |
| 1156 | } |
| 1157 | |
Winson | fadbe8f | 2016-07-22 16:35:37 -0700 | [diff] [blame] | 1158 | /** |
Sunny Goyal | 57b2279 | 2021-05-25 14:35:01 -0700 | [diff] [blame] | 1159 | * Returns the number of pixels the QSB is translated from the bottom of the screen. |
| 1160 | */ |
| 1161 | public int getQsbOffsetY() { |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 1162 | if (isQsbInline) { |
| 1163 | return hotseatBarBottomPaddingPx; |
| 1164 | } |
| 1165 | |
Sunny Goyal | 57b2279 | 2021-05-25 14:35:01 -0700 | [diff] [blame] | 1166 | int freeSpace = isTaskbarPresent |
| 1167 | ? workspacePadding.bottom |
| 1168 | : hotseatBarSizePx - hotseatCellHeightPx - hotseatQsbHeight; |
Jonathan Miranda | 7a273e2 | 2021-06-24 21:29:10 +0000 | [diff] [blame] | 1169 | |
Jonathan Miranda | 8f16a77 | 2021-07-23 23:10:37 +0000 | [diff] [blame] | 1170 | if (isScalableGrid && qsbBottomMarginPx > mInsets.bottom) { |
Tony Wickham | 21970cc | 2021-09-15 15:44:05 -0700 | [diff] [blame] | 1171 | // Note that taskbarSize = 0 unless isTaskbarPresent. |
| 1172 | return Math.min(qsbBottomMarginPx + taskbarSize, freeSpace); |
Jonathan Miranda | 8f16a77 | 2021-07-23 23:10:37 +0000 | [diff] [blame] | 1173 | } else { |
Pratyush | 9afe1ea | 2021-10-13 11:13:27 +0000 | [diff] [blame] | 1174 | return (int) (freeSpace * mQsbCenterFactor) |
| 1175 | + (isTaskbarPresent ? taskbarSize : mInsets.bottom); |
Jonathan Miranda | 7a273e2 | 2021-06-24 21:29:10 +0000 | [diff] [blame] | 1176 | } |
Sunny Goyal | 57b2279 | 2021-05-25 14:35:01 -0700 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | /** |
| 1180 | * Returns the number of pixels the taskbar is translated from the bottom of the screen. |
| 1181 | */ |
| 1182 | public int getTaskbarOffsetY() { |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 1183 | if (isQsbInline) { |
Thales Lima | 612230d | 2022-03-31 18:04:37 +0100 | [diff] [blame] | 1184 | return getQsbOffsetY() - (Math.abs(hotseatQsbHeight - hotseatCellHeightPx) / 2); |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 1185 | } else { |
| 1186 | return (getQsbOffsetY() - taskbarSize) / 2; |
| 1187 | } |
Sunny Goyal | 57b2279 | 2021-05-25 14:35:01 -0700 | [diff] [blame] | 1188 | } |
| 1189 | |
| 1190 | /** |
Alex Chau | a2fc764 | 2022-04-21 14:20:23 +0100 | [diff] [blame] | 1191 | * Returns the number of pixels required below OverviewActions excluding insets. |
| 1192 | */ |
| 1193 | public int getOverviewActionsClaimedSpaceBelow() { |
| 1194 | if (isTaskbarPresent && !isGestureMode) { |
| 1195 | // Align vertically to where nav buttons are. |
| 1196 | return ((taskbarSize - overviewActionsHeight) / 2) + getTaskbarOffsetY(); |
| 1197 | } |
| 1198 | |
| 1199 | return 0; |
| 1200 | } |
| 1201 | |
| 1202 | /** Gets the space that the overview actions will take, including bottom margin. */ |
| 1203 | public int getOverviewActionsClaimedSpace() { |
| 1204 | return overviewActionsTopMarginPx + overviewActionsHeight |
| 1205 | + getOverviewActionsClaimedSpaceBelow(); |
| 1206 | } |
| 1207 | |
| 1208 | /** |
Winson | fadbe8f | 2016-07-22 16:35:37 -0700 | [diff] [blame] | 1209 | * @return the bounds for which the open folders should be contained within |
| 1210 | */ |
| 1211 | public Rect getAbsoluteOpenFolderBounds() { |
| 1212 | if (isVerticalBarLayout()) { |
| 1213 | // Folders should only appear right of the drop target bar and left of the hotseat |
| 1214 | return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx, |
| 1215 | mInsets.top, |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 1216 | mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx, |
Winson | fadbe8f | 2016-07-22 16:35:37 -0700 | [diff] [blame] | 1217 | mInsets.top + availableHeightPx); |
| 1218 | } else { |
| 1219 | // Folders should only appear below the drop target bar and above the hotseat |
Tony Wickham | ae72b46 | 2021-03-10 16:18:40 -0800 | [diff] [blame] | 1220 | int hotseatTop = isTaskbarPresent ? taskbarSize : hotseatBarSizePx; |
Tony Wickham | b4b7e20 | 2018-01-12 17:39:24 -0800 | [diff] [blame] | 1221 | return new Rect(mInsets.left + edgeMarginPx, |
Winson | fadbe8f | 2016-07-22 16:35:37 -0700 | [diff] [blame] | 1222 | mInsets.top + dropTargetBarSizePx + edgeMarginPx, |
Tony Wickham | b4b7e20 | 2018-01-12 17:39:24 -0800 | [diff] [blame] | 1223 | mInsets.left + availableWidthPx - edgeMarginPx, |
Tony Wickham | ae72b46 | 2021-03-10 16:18:40 -0800 | [diff] [blame] | 1224 | mInsets.top + availableHeightPx - hotseatTop |
Tony Wickham | 5edf9e2 | 2020-03-27 20:06:52 -0700 | [diff] [blame] | 1225 | - workspacePageIndicatorHeight - edgeMarginPx); |
Winson | fadbe8f | 2016-07-22 16:35:37 -0700 | [diff] [blame] | 1226 | } |
| 1227 | } |
| 1228 | |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 1229 | public static int calculateCellWidth(int width, int borderSpacing, int countX) { |
| 1230 | return (width - ((countX - 1) * borderSpacing)) / countX; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 1231 | } |
Pierre Barbier de Reuille | 578deba | 2021-09-24 13:47:44 +0100 | [diff] [blame] | 1232 | |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 1233 | public static int calculateCellHeight(int height, int borderSpacing, int countY) { |
| 1234 | return (height - ((countY - 1) * borderSpacing)) / countY; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 1235 | } |
| 1236 | |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 1237 | /** |
Tony Wickham | 55616cd | 2015-09-23 14:55:17 -0700 | [diff] [blame] | 1238 | * When {@code true}, the device is in landscape mode and the hotseat is on the right column. |
| 1239 | * When {@code false}, either device is in portrait mode or the device is in landscape mode and |
| 1240 | * the hotseat is on the bottom row. |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 1241 | */ |
Tony Wickham | ab946a1 | 2015-09-16 15:38:16 -0700 | [diff] [blame] | 1242 | public boolean isVerticalBarLayout() { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 1243 | return isLandscape && transposeLayoutWithOrientation; |
| 1244 | } |
| 1245 | |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 1246 | /** |
| 1247 | * Updates orientation information and returns true if it has changed from the previous value. |
| 1248 | */ |
Winson Chung | 13c1c2c | 2019-09-06 11:46:19 -0700 | [diff] [blame] | 1249 | public boolean updateIsSeascape(Context context) { |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 1250 | if (isVerticalBarLayout()) { |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 1251 | boolean isSeascape = DisplayController.INSTANCE.get(context) |
| 1252 | .getInfo().rotation == Surface.ROTATION_270; |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 1253 | if (mIsSeascape != isSeascape) { |
| 1254 | mIsSeascape = isSeascape; |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 1255 | // Hotseat changing sides requires updating workspace left/right paddings |
| 1256 | updateWorkspacePadding(); |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 1257 | return true; |
| 1258 | } |
| 1259 | } |
| 1260 | return false; |
| 1261 | } |
| 1262 | |
Sunny Goyal | 7e2e67f | 2018-01-26 13:40:08 -0800 | [diff] [blame] | 1263 | public boolean isSeascape() { |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 1264 | return isVerticalBarLayout() && mIsSeascape; |
Sunny Goyal | 7e2e67f | 2018-01-26 13:40:08 -0800 | [diff] [blame] | 1265 | } |
| 1266 | |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 1267 | public boolean shouldFadeAdjacentWorkspaceScreens() { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 1268 | return isVerticalBarLayout(); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 1269 | } |
| 1270 | |
Jon Miranda | 92c1b5d | 2021-07-20 13:57:16 -0700 | [diff] [blame] | 1271 | public int getCellContentHeight(@ContainerType int containerType) { |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 1272 | switch (containerType) { |
| 1273 | case CellLayout.WORKSPACE: |
| 1274 | return cellHeightPx; |
| 1275 | case CellLayout.FOLDER: |
| 1276 | return folderCellHeightPx; |
| 1277 | case CellLayout.HOTSEAT: |
Jon Miranda | 92c1b5d | 2021-07-20 13:57:16 -0700 | [diff] [blame] | 1278 | // The hotseat is the only container where the cell height is going to be |
| 1279 | // different from the content within that cell. |
| 1280 | return iconSizePx; |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 1281 | default: |
| 1282 | // ?? |
| 1283 | return 0; |
| 1284 | } |
| 1285 | } |
Sunny Goyal | 13178ac | 2016-04-04 16:35:22 -0700 | [diff] [blame] | 1286 | |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1287 | private String pxToDpStr(String name, float value) { |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 1288 | return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)"; |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | public void dump(String prefix, PrintWriter writer) { |
| 1292 | writer.println(prefix + "DeviceProfile:"); |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 1293 | writer.println(prefix + "\t1 dp = " + mMetrics.density + " px"); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1294 | |
| 1295 | writer.println(prefix + "\tisTablet:" + isTablet); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1296 | writer.println(prefix + "\tisPhone:" + isPhone); |
| 1297 | writer.println(prefix + "\ttransposeLayoutWithOrientation:" |
| 1298 | + transposeLayoutWithOrientation); |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 1299 | writer.println(prefix + "\tisGestureMode:" + isGestureMode); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1300 | |
| 1301 | writer.println(prefix + "\tisLandscape:" + isLandscape); |
| 1302 | writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 1303 | writer.println(prefix + "\tisTwoPanels:" + isTwoPanels); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1304 | |
| 1305 | writer.println(prefix + pxToDpStr("windowX", windowX)); |
| 1306 | writer.println(prefix + pxToDpStr("windowY", windowY)); |
| 1307 | writer.println(prefix + pxToDpStr("widthPx", widthPx)); |
| 1308 | writer.println(prefix + pxToDpStr("heightPx", heightPx)); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1309 | writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx)); |
| 1310 | writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx)); |
Alex Chau | e022755 | 2022-04-06 19:44:43 +0100 | [diff] [blame] | 1311 | writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left)); |
| 1312 | writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top)); |
| 1313 | writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right)); |
| 1314 | writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom)); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1315 | |
| 1316 | writer.println(prefix + "\taspectRatio:" + aspectRatio); |
| 1317 | |
| 1318 | writer.println(prefix + "\tisScalableGrid:" + isScalableGrid); |
| 1319 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1320 | writer.println(prefix + "\tinv.numRows: " + inv.numRows); |
Alex Chau | 9fee3fd | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 1321 | writer.println(prefix + "\tinv.numColumns: " + inv.numColumns); |
| 1322 | writer.println(prefix + "\tinv.numSearchContainerColumns: " |
| 1323 | + inv.numSearchContainerColumns); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1324 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1325 | writer.println(prefix + "\tminCellSize: " + inv.minCellSize[mTypeIndex] + "dp"); |
Jon Miranda | ab3c681 | 2021-06-28 15:42:28 -0700 | [diff] [blame] | 1326 | |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1327 | writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx)); |
| 1328 | writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx)); |
| 1329 | |
| 1330 | writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x)); |
| 1331 | writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y)); |
| 1332 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1333 | writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal", |
| 1334 | cellLayoutBorderSpacePx.x)); |
| 1335 | writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical", |
| 1336 | cellLayoutBorderSpacePx.y)); |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 1337 | writer.println(prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left)); |
| 1338 | writer.println(prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top)); |
| 1339 | writer.println(prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right)); |
| 1340 | writer.println( |
| 1341 | prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom)); |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1342 | |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1343 | writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx)); |
| 1344 | writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx)); |
| 1345 | writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx)); |
| 1346 | |
| 1347 | writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx)); |
| 1348 | writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx)); |
| 1349 | writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx)); |
| 1350 | writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx)); |
| 1351 | writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx", |
| 1352 | folderChildDrawablePaddingPx)); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1353 | writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpaceOriginalPx", |
| 1354 | folderCellLayoutBorderSpaceOriginalPx)); |
| 1355 | writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx Horizontal", |
| 1356 | folderCellLayoutBorderSpacePx.x)); |
| 1357 | writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx Vertical", |
| 1358 | folderCellLayoutBorderSpacePx.y)); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1359 | |
Alex Chau | e022755 | 2022-04-06 19:44:43 +0100 | [diff] [blame] | 1360 | writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding)); |
| 1361 | |
| 1362 | writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange)); |
| 1363 | writer.println(prefix + pxToDpStr("allAppsTopPadding", allAppsTopPadding)); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1364 | writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx)); |
| 1365 | writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx)); |
| 1366 | writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx", |
| 1367 | allAppsIconDrawablePaddingPx)); |
| 1368 | writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx)); |
Alex Chau | 27b39b9 | 2022-01-14 18:02:18 +0000 | [diff] [blame] | 1369 | writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx)); |
Thales Lima | b7ef569 | 2022-03-10 10:32:36 +0000 | [diff] [blame] | 1370 | writer.println(prefix + pxToDpStr("allAppsBorderSpacePx", allAppsBorderSpacePx.x)); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 1371 | writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns); |
Alex Chau | 27b39b9 | 2022-01-14 18:02:18 +0000 | [diff] [blame] | 1372 | writer.println(prefix + pxToDpStr("allAppsLeftRightPadding", allAppsLeftRightPadding)); |
| 1373 | writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin)); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1374 | |
| 1375 | writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx)); |
Thales Lima | 828875c | 2022-04-26 20:29:30 +0100 | [diff] [blame] | 1376 | writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1377 | writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx)); |
| 1378 | writer.println(prefix + pxToDpStr("hotseatBarTopPaddingPx", hotseatBarTopPaddingPx)); |
| 1379 | writer.println(prefix + pxToDpStr("hotseatBarBottomPaddingPx", hotseatBarBottomPaddingPx)); |
| 1380 | writer.println(prefix + pxToDpStr("hotseatBarSidePaddingStartPx", |
| 1381 | hotseatBarSidePaddingStartPx)); |
| 1382 | writer.println(prefix + pxToDpStr("hotseatBarSidePaddingEndPx", |
| 1383 | hotseatBarSidePaddingEndPx)); |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 1384 | writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx", |
| 1385 | springLoadedHotseatBarTopMarginPx)); |
| 1386 | writer.println(prefix + pxToDpStr("mHotseatPadding.top", mHotseatPadding.top)); |
| 1387 | writer.println(prefix + pxToDpStr("mHotseatPadding.bottom", mHotseatPadding.bottom)); |
| 1388 | writer.println(prefix + pxToDpStr("mHotseatPadding.left", mHotseatPadding.left)); |
| 1389 | writer.println(prefix + pxToDpStr("mHotseatPadding.right", mHotseatPadding.right)); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 1390 | writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons); |
Thales Lima | 116b51a | 2022-02-03 16:19:47 +0000 | [diff] [blame] | 1391 | writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace)); |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 1392 | writer.println(prefix + "\tisQsbInline: " + isQsbInline); |
| 1393 | writer.println(prefix + pxToDpStr("qsbWidth", qsbWidth)); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1394 | |
| 1395 | writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent); |
Tony Wickham | 635e180 | 2021-07-22 14:28:04 -1000 | [diff] [blame] | 1396 | writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1397 | writer.println(prefix + pxToDpStr("taskbarSize", taskbarSize)); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1398 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1399 | writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx", |
| 1400 | desiredWorkspaceHorizontalMarginPx)); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1401 | writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left)); |
| 1402 | writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top)); |
| 1403 | writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right)); |
| 1404 | writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom)); |
| 1405 | |
Jon Miranda | ab3c681 | 2021-06-28 15:42:28 -0700 | [diff] [blame] | 1406 | writer.println(prefix + pxToDpStr("iconScale", iconScale)); |
| 1407 | writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit)); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1408 | writer.println(prefix + pxToDpStr("extraSpace", extraSpace)); |
Thales Lima | 7a6752d | 2021-09-23 14:31:00 +0100 | [diff] [blame] | 1409 | writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale)); |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 1410 | |
| 1411 | if (inv.devicePaddings != null) { |
| 1412 | int unscaledExtraSpace = (int) (extraSpace / iconScale); |
| 1413 | writer.println(prefix + pxToDpStr("maxEmptySpace", |
| 1414 | inv.devicePaddings.getDevicePadding(unscaledExtraSpace).getMaxEmptySpacePx())); |
| 1415 | } |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1416 | writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding)); |
| 1417 | writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding)); |
| 1418 | writer.println(prefix + pxToDpStr("extraHotseatBottomPadding", extraHotseatBottomPadding)); |
Alex Chau | 635b3ab | 2022-01-26 16:49:10 +0000 | [diff] [blame] | 1419 | |
| 1420 | writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx)); |
| 1421 | writer.println(prefix + pxToDpStr("overviewTaskMarginGridPx", overviewTaskMarginGridPx)); |
| 1422 | writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx)); |
| 1423 | writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx", |
| 1424 | overviewTaskIconDrawableSizePx)); |
| 1425 | writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx", |
| 1426 | overviewTaskIconDrawableSizeGridPx)); |
| 1427 | writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx", |
| 1428 | overviewTaskThumbnailTopMarginPx)); |
Alex Chau | a2fc764 | 2022-04-21 14:20:23 +0100 | [diff] [blame] | 1429 | writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx", |
| 1430 | overviewActionsTopMarginPx)); |
| 1431 | writer.println(prefix + pxToDpStr("overviewActionsHeight", |
| 1432 | overviewActionsHeight)); |
Alex Chau | 635b3ab | 2022-01-26 16:49:10 +0000 | [diff] [blame] | 1433 | writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing", |
| 1434 | overviewActionsButtonSpacing)); |
| 1435 | writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing)); |
| 1436 | writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing)); |
| 1437 | writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin)); |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 1438 | |
| 1439 | writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx)); |
| 1440 | writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx)); |
| 1441 | writer.println( |
| 1442 | prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx)); |
| 1443 | |
| 1444 | writer.println( |
| 1445 | prefix + pxToDpStr("workspaceSpringLoadShrunkTop", workspaceSpringLoadShrunkTop)); |
| 1446 | writer.println(prefix + pxToDpStr("workspaceSpringLoadShrunkBottom", |
| 1447 | workspaceSpringLoadShrunkBottom)); |
Pat Manning | a2e1499 | 2022-04-22 11:29:17 +0100 | [diff] [blame] | 1448 | writer.println( |
| 1449 | prefix + pxToDpStr("getWorkspaceSpringLoadScale()", getWorkspaceSpringLoadScale())); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1450 | } |
| 1451 | |
Alex Chau | a6907dc | 2022-03-18 15:24:07 +0000 | [diff] [blame] | 1452 | private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) { |
Sunny Goyal | 1890f67 | 2020-04-30 12:28:00 -0700 | [diff] [blame] | 1453 | Configuration config = new Configuration(c.getResources().getConfiguration()); |
| 1454 | config.orientation = orientation; |
Thales Lima | 828875c | 2022-04-26 20:29:30 +0100 | [diff] [blame] | 1455 | config.densityDpi = info.getDensityDpi(); |
Alex Chau | a6907dc | 2022-03-18 15:24:07 +0000 | [diff] [blame] | 1456 | config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds); |
Sunny Goyal | 1890f67 | 2020-04-30 12:28:00 -0700 | [diff] [blame] | 1457 | return c.createConfigurationContext(config); |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 1458 | } |
Sunny Goyal | fde5505 | 2018-02-01 14:46:13 -0800 | [diff] [blame] | 1459 | |
| 1460 | /** |
| 1461 | * Callback when a component changes the DeviceProfile associated with it, as a result of |
| 1462 | * configuration change |
| 1463 | */ |
| 1464 | public interface OnDeviceProfileChangeListener { |
| 1465 | |
| 1466 | /** |
| 1467 | * Called when the device profile is reassigned. Note that for layout and measurements, it |
| 1468 | * is sufficient to listen for inset changes. Use this callback when you need to perform |
| 1469 | * a one time operation. |
| 1470 | */ |
| 1471 | void onDeviceProfileChanged(DeviceProfile dp); |
| 1472 | } |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 1473 | |
Brian Isganitis | 099945b | 2022-01-31 18:15:00 -0500 | [diff] [blame] | 1474 | /** Allows registering listeners for {@link DeviceProfile} changes. */ |
| 1475 | public interface DeviceProfileListenable { |
| 1476 | |
| 1477 | /** The current device profile. */ |
| 1478 | DeviceProfile getDeviceProfile(); |
| 1479 | |
| 1480 | /** Registered {@link OnDeviceProfileChangeListener} instances. */ |
| 1481 | List<OnDeviceProfileChangeListener> getOnDeviceProfileChangeListeners(); |
| 1482 | |
| 1483 | /** Notifies listeners of a {@link DeviceProfile} change. */ |
| 1484 | default void dispatchDeviceProfileChanged() { |
| 1485 | DeviceProfile deviceProfile = getDeviceProfile(); |
| 1486 | List<OnDeviceProfileChangeListener> listeners = getOnDeviceProfileChangeListeners(); |
| 1487 | for (int i = listeners.size() - 1; i >= 0; i--) { |
| 1488 | listeners.get(i).onDeviceProfileChanged(deviceProfile); |
| 1489 | } |
| 1490 | } |
| 1491 | |
| 1492 | /** Register listener for {@link DeviceProfile} changes. */ |
| 1493 | default void addOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) { |
| 1494 | getOnDeviceProfileChangeListeners().add(listener); |
| 1495 | } |
| 1496 | |
| 1497 | /** Unregister listener for {@link DeviceProfile} changes. */ |
| 1498 | default void removeOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) { |
| 1499 | getOnDeviceProfileChangeListeners().remove(listener); |
| 1500 | } |
| 1501 | } |
| 1502 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 1503 | public static class Builder { |
| 1504 | private Context mContext; |
| 1505 | private InvariantDeviceProfile mInv; |
Sunny Goyal | fd58da6 | 2020-08-11 12:06:49 -0700 | [diff] [blame] | 1506 | private Info mInfo; |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 1507 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 1508 | private WindowBounds mWindowBounds; |
| 1509 | private boolean mUseTwoPanels; |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 1510 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 1511 | private boolean mIsMultiWindowMode = false; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 1512 | private Boolean mTransposeLayoutWithOrientation; |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 1513 | private Boolean mIsGestureMode; |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 1514 | |
Sunny Goyal | fd58da6 | 2020-08-11 12:06:49 -0700 | [diff] [blame] | 1515 | public Builder(Context context, InvariantDeviceProfile inv, Info info) { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 1516 | mContext = context; |
| 1517 | mInv = inv; |
| 1518 | mInfo = info; |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | public Builder setMultiWindowMode(boolean isMultiWindowMode) { |
| 1522 | mIsMultiWindowMode = isMultiWindowMode; |
| 1523 | return this; |
| 1524 | } |
| 1525 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 1526 | public Builder setUseTwoPanels(boolean useTwoPanels) { |
| 1527 | mUseTwoPanels = useTwoPanels; |
| 1528 | return this; |
| 1529 | } |
| 1530 | |
| 1531 | |
| 1532 | public Builder setWindowBounds(WindowBounds bounds) { |
| 1533 | mWindowBounds = bounds; |
Sunny Goyal | 0addbf0 | 2020-04-28 14:17:35 -0700 | [diff] [blame] | 1534 | return this; |
| 1535 | } |
| 1536 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 1537 | public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) { |
| 1538 | mTransposeLayoutWithOrientation = transposeLayoutWithOrientation; |
| 1539 | return this; |
| 1540 | } |
| 1541 | |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 1542 | public Builder setGestureMode(boolean isGestureMode) { |
| 1543 | mIsGestureMode = isGestureMode; |
| 1544 | return this; |
| 1545 | } |
| 1546 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 1547 | public DeviceProfile build() { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 1548 | if (mWindowBounds == null) { |
| 1549 | throw new IllegalArgumentException("Window bounds not set"); |
| 1550 | } |
| 1551 | if (mTransposeLayoutWithOrientation == null) { |
| 1552 | mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds); |
| 1553 | } |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 1554 | if (mIsGestureMode == null) { |
| 1555 | mIsGestureMode = DisplayController.getNavigationMode(mContext).hasGestures; |
| 1556 | } |
| 1557 | return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mIsMultiWindowMode, |
| 1558 | mTransposeLayoutWithOrientation, mUseTwoPanels, mIsGestureMode); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 1559 | } |
| 1560 | } |
| 1561 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 1562 | } |