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