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 | |
Kateryna Ivanova | 7120373 | 2023-05-24 15:09:00 +0000 | [diff] [blame] | 19 | import static com.android.app.animation.Interpolators.LINEAR; |
Jordan Silva | f2402e2 | 2023-10-26 19:53:16 +0100 | [diff] [blame] | 20 | import static com.android.launcher3.Flags.enableOverviewIconMenu; |
Thales Lima | 12d0eff | 2022-03-25 17:06:11 +0000 | [diff] [blame] | 21 | import static com.android.launcher3.InvariantDeviceProfile.INDEX_DEFAULT; |
| 22 | import static com.android.launcher3.InvariantDeviceProfile.INDEX_LANDSCAPE; |
| 23 | import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_LANDSCAPE; |
| 24 | import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_PORTRAIT; |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 25 | import static com.android.launcher3.Utilities.dpiFromPx; |
Jon Miranda | af3aed0 | 2021-05-06 18:28:45 -0700 | [diff] [blame] | 26 | import static com.android.launcher3.Utilities.pxFromSp; |
Alex Chau | ab800f7 | 2022-12-13 17:46:06 +0000 | [diff] [blame] | 27 | import static com.android.launcher3.config.FeatureFlags.ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH; |
Jon Miranda | 92c1b5d | 2021-07-20 13:57:16 -0700 | [diff] [blame] | 28 | import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.ICON_OVERLAP_FACTOR; |
Sunny Goyal | 65190ae | 2022-08-02 14:16:26 -0700 | [diff] [blame] | 29 | import static com.android.launcher3.icons.GraphicsUtils.getShapePath; |
Jon Miranda | 95f4472 | 2023-06-06 19:48:19 -0700 | [diff] [blame] | 30 | import static com.android.launcher3.icons.IconNormalizer.ICON_VISIBLE_AREA_FACTOR; |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 31 | import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURCE_HANDLE; |
Pat Manning | 5f74bfd | 2022-07-20 12:08:54 +0100 | [diff] [blame] | 32 | import static com.android.launcher3.testing.shared.ResourceUtils.pxFromDp; |
Thales Lima | 7eee74b | 2023-03-16 16:00:55 -0300 | [diff] [blame] | 33 | import static com.android.launcher3.testing.shared.ResourceUtils.roundPxValueFromFloat; |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 34 | |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 35 | import android.annotation.SuppressLint; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 36 | import android.content.Context; |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 37 | import android.content.res.Configuration; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 38 | import android.content.res.Resources; |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 39 | import android.content.res.TypedArray; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 40 | import android.graphics.Point; |
Jon Miranda | 7ae64ff | 2016-11-21 16:18:46 -0800 | [diff] [blame] | 41 | import android.graphics.PointF; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 42 | import android.graphics.Rect; |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 43 | import android.util.DisplayMetrics; |
Sunny Goyal | 65190ae | 2022-08-02 14:16:26 -0700 | [diff] [blame] | 44 | import android.util.SparseArray; |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 45 | import android.view.Surface; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 46 | |
Sunny Goyal | 65190ae | 2022-08-02 14:16:26 -0700 | [diff] [blame] | 47 | import androidx.annotation.NonNull; |
Sihua Ma | e04aa20 | 2022-07-18 12:43:56 -0700 | [diff] [blame] | 48 | import androidx.annotation.Nullable; |
Jon Miranda | 9c478b6 | 2023-03-23 21:38:49 -0700 | [diff] [blame] | 49 | import androidx.core.content.res.ResourcesCompat; |
Sunny Goyal | 65190ae | 2022-08-02 14:16:26 -0700 | [diff] [blame] | 50 | |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 51 | import com.android.launcher3.CellLayout.ContainerType; |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 52 | import com.android.launcher3.DevicePaddings.DevicePadding; |
Alex Chau | d67ddc4 | 2022-09-30 18:15:56 +0100 | [diff] [blame] | 53 | import com.android.launcher3.config.FeatureFlags; |
Tony Wickham | 8912b04 | 2018-11-29 15:28:53 -0800 | [diff] [blame] | 54 | import com.android.launcher3.icons.DotRenderer; |
Hyunyoung Song | 48cb7bc | 2018-09-25 17:03:34 -0700 | [diff] [blame] | 55 | import com.android.launcher3.icons.IconNormalizer; |
Sihua Ma | e04aa20 | 2022-07-18 12:43:56 -0700 | [diff] [blame] | 56 | import com.android.launcher3.model.data.ItemInfo; |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 57 | import com.android.launcher3.responsive.CalculatedCellSpec; |
Thales Lima | f8bfb03 | 2023-07-24 15:08:05 +0100 | [diff] [blame] | 58 | import com.android.launcher3.responsive.CalculatedHotseatSpec; |
Jordan Silva | f2402e2 | 2023-10-26 19:53:16 +0100 | [diff] [blame] | 59 | import com.android.launcher3.responsive.CalculatedResponsiveSpec; |
| 60 | import com.android.launcher3.responsive.HotseatSpecsProvider; |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 61 | import com.android.launcher3.responsive.ResponsiveCellSpecsProvider; |
Jordan Silva | f2402e2 | 2023-10-26 19:53:16 +0100 | [diff] [blame] | 62 | import com.android.launcher3.responsive.ResponsiveSpec.Companion.ResponsiveSpecType; |
| 63 | import com.android.launcher3.responsive.ResponsiveSpec.DimensionType; |
| 64 | import com.android.launcher3.responsive.ResponsiveSpecsProvider; |
Sunny Goyal | 57b2279 | 2021-05-25 14:35:01 -0700 | [diff] [blame] | 65 | import com.android.launcher3.uioverrides.ApiWrapper; |
Thales Lima | 24ceca6 | 2023-09-25 16:21:17 -0700 | [diff] [blame] | 66 | import com.android.launcher3.util.CellContentDimensions; |
Sunny Goyal | fd58da6 | 2020-08-11 12:06:49 -0700 | [diff] [blame] | 67 | import com.android.launcher3.util.DisplayController; |
| 68 | import com.android.launcher3.util.DisplayController.Info; |
Thales Lima | 2759aa3 | 2023-06-05 16:25:45 +0100 | [diff] [blame] | 69 | import com.android.launcher3.util.IconSizeSteps; |
Thales Lima | c98b781 | 2023-04-14 15:04:23 +0100 | [diff] [blame] | 70 | import com.android.launcher3.util.ResourceHelper; |
Sunny Goyal | b46703d | 2020-05-27 17:52:03 -0700 | [diff] [blame] | 71 | import com.android.launcher3.util.WindowBounds; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 72 | |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 73 | import java.io.PrintWriter; |
Alex Chau | e818bcb | 2022-09-02 17:27:11 +0100 | [diff] [blame] | 74 | import java.util.Locale; |
Jon Miranda | 2b25ded | 2023-02-02 14:48:45 -0800 | [diff] [blame] | 75 | import java.util.function.Consumer; |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 76 | |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 77 | @SuppressLint("NewApi") |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 78 | public class DeviceProfile { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 79 | |
Sunny Goyal | 8b9919d | 2021-04-07 14:45:17 -0700 | [diff] [blame] | 80 | private static final int DEFAULT_DOT_SIZE = 100; |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 81 | private static final float MIN_FOLDER_TEXT_SIZE_SP = 16f; |
Sunny Goyal | 6c304b1 | 2023-04-10 12:03:04 -0700 | [diff] [blame] | 82 | private static final float MIN_WIDGET_PADDING_DP = 6f; |
Alex Chau | 206ede9 | 2022-08-01 17:46:12 +0100 | [diff] [blame] | 83 | |
Sihua Ma | e04aa20 | 2022-07-18 12:43:56 -0700 | [diff] [blame] | 84 | public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f); |
| 85 | public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE; |
Jordan Silva | f2402e2 | 2023-10-26 19:53:16 +0100 | [diff] [blame] | 86 | public static final Consumer<DeviceProfile> DEFAULT_DIMENSION_PROVIDER = dp -> { |
| 87 | }; |
Sihua Ma | e04aa20 | 2022-07-18 12:43:56 -0700 | [diff] [blame] | 88 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 89 | public final InvariantDeviceProfile inv; |
Sunny Goyal | fd58da6 | 2020-08-11 12:06:49 -0700 | [diff] [blame] | 90 | private final Info mInfo; |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 91 | private final DisplayMetrics mMetrics; |
Thales Lima | 2759aa3 | 2023-06-05 16:25:45 +0100 | [diff] [blame] | 92 | private final IconSizeSteps mIconSizeSteps; |
Winson Chung | be87647 | 2014-05-14 14:15:20 -0700 | [diff] [blame] | 93 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 94 | // Device properties |
| 95 | public final boolean isTablet; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 96 | public final boolean isPhone; |
| 97 | public final boolean transposeLayoutWithOrientation; |
Alex Chau | ab800f7 | 2022-12-13 17:46:06 +0000 | [diff] [blame] | 98 | public final boolean isMultiDisplay; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 99 | public final boolean isTwoPanels; |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 100 | public final boolean isQsbInline; |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 101 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 102 | // Device properties in current orientation |
Sunny Goyal | d792a77 | 2018-04-05 13:37:46 -0700 | [diff] [blame] | 103 | public final boolean isLandscape; |
Sunny Goyal | d70e75a | 2018-02-22 10:07:32 -0800 | [diff] [blame] | 104 | public final boolean isMultiWindowMode; |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 105 | public final boolean isGestureMode; |
Sunny Goyal | d70e75a | 2018-02-22 10:07:32 -0800 | [diff] [blame] | 106 | |
Winson Chung | 104a4c8 | 2023-11-08 18:56:15 +0000 | [diff] [blame] | 107 | public final boolean isLeftRightSplit; |
| 108 | |
Sunny Goyal | 0addbf0 | 2020-04-28 14:17:35 -0700 | [diff] [blame] | 109 | public final int windowX; |
| 110 | public final int windowY; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 111 | public final int widthPx; |
| 112 | public final int heightPx; |
| 113 | public final int availableWidthPx; |
| 114 | public final int availableHeightPx; |
Sunny Goyal | 187b16c | 2022-03-01 16:53:23 -0800 | [diff] [blame] | 115 | public final int rotationHint; |
Jon Miranda | bba6451 | 2019-03-27 10:54:17 -0700 | [diff] [blame] | 116 | |
| 117 | public final float aspectRatio; |
| 118 | |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 119 | private final boolean mIsScalableGrid; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 120 | private final int mTypeIndex; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 121 | |
Thales Lima | c98b781 | 2023-04-14 15:04:23 +0100 | [diff] [blame] | 122 | // Responsive grid |
| 123 | private final boolean mIsResponsiveGrid; |
Jordan Silva | 8f7986a | 2023-11-08 12:11:25 +0000 | [diff] [blame] | 124 | private CalculatedResponsiveSpec mResponsiveWorkspaceWidthSpec; |
| 125 | private CalculatedResponsiveSpec mResponsiveWorkspaceHeightSpec; |
| 126 | private CalculatedResponsiveSpec mResponsiveAllAppsWidthSpec; |
| 127 | private CalculatedResponsiveSpec mResponsiveAllAppsHeightSpec; |
Jordan Silva | f2402e2 | 2023-10-26 19:53:16 +0100 | [diff] [blame] | 128 | private CalculatedResponsiveSpec mResponsiveFolderWidthSpec; |
| 129 | private CalculatedResponsiveSpec mResponsiveFolderHeightSpec; |
Thales Lima | f8bfb03 | 2023-07-24 15:08:05 +0100 | [diff] [blame] | 130 | private CalculatedHotseatSpec mResponsiveHotseatSpec; |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 131 | private CalculatedCellSpec mResponsiveWorkspaceCellSpec; |
| 132 | private CalculatedCellSpec mResponsiveAllAppsCellSpec; |
Thales Lima | c98b781 | 2023-04-14 15:04:23 +0100 | [diff] [blame] | 133 | |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 134 | /** |
| 135 | * The maximum amount of left/right workspace padding as a percentage of the screen width. |
| 136 | * To be clear, this means that up to 7% of the screen width can be used as left padding, and |
| 137 | * 7% of the screen width can be used as right padding. |
| 138 | */ |
| 139 | private static final float MAX_HORIZONTAL_PADDING_PERCENT = 0.14f; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 140 | |
Jon Miranda | 3f9bab2 | 2017-07-28 14:50:17 -0700 | [diff] [blame] | 141 | private static final float TALL_DEVICE_ASPECT_RATIO_THRESHOLD = 2.0f; |
Jon Miranda | 80cddbc | 2021-07-22 13:51:16 -0700 | [diff] [blame] | 142 | private static final float TALLER_DEVICE_ASPECT_RATIO_THRESHOLD = 2.15f; |
Jon Miranda | 80dda30 | 2021-07-28 14:14:59 -0700 | [diff] [blame] | 143 | private static final float TALL_DEVICE_EXTRA_SPACE_THRESHOLD_DP = 252; |
| 144 | private static final float TALL_DEVICE_MORE_EXTRA_SPACE_THRESHOLD_DP = 268; |
Jon Miranda | 30d0aa2 | 2017-07-25 15:55:29 -0700 | [diff] [blame] | 145 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 146 | // Workspace |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 147 | public final int desiredWorkspaceHorizontalMarginOriginalPx; |
| 148 | public int desiredWorkspaceHorizontalMarginPx; |
Alex Chau | 51da219 | 2022-05-20 13:32:10 +0100 | [diff] [blame] | 149 | public int gridVisualizationPaddingX; |
| 150 | public int gridVisualizationPaddingY; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 151 | public Point cellLayoutBorderSpaceOriginalPx; |
| 152 | public Point cellLayoutBorderSpacePx; |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 153 | public Rect cellLayoutPaddingPx = new Rect(); |
| 154 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 155 | public final int edgeMarginPx; |
Alex Chau | 0c4e11b | 2022-07-08 18:41:36 +0100 | [diff] [blame] | 156 | public final float workspaceContentScale; |
Alex Chau | 906d882 | 2022-05-23 10:42:25 +0100 | [diff] [blame] | 157 | public final int workspaceSpringLoadedMinNextPageVisiblePx; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 158 | |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 159 | private final int extraSpace; |
Thales Lima | 171ee66 | 2022-11-22 15:52:49 +0000 | [diff] [blame] | 160 | private int maxEmptySpace; |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 161 | public int workspaceTopPadding; |
| 162 | public int workspaceBottomPadding; |
| 163 | |
Tony Wickham | 5edf9e2 | 2020-03-27 20:06:52 -0700 | [diff] [blame] | 164 | // Workspace page indicator |
| 165 | public final int workspacePageIndicatorHeight; |
| 166 | private final int mWorkspacePageIndicatorOverlapWorkspace; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 167 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 168 | // Workspace icons |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 169 | public float iconScale; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 170 | public int iconSizePx; |
| 171 | public int iconTextSizePx; |
| 172 | public int iconDrawablePaddingPx; |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 173 | private int mIconDrawablePaddingOriginalPx; |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 174 | public boolean iconCenterVertically; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 175 | |
Jon Miranda | ab3c681 | 2021-06-28 15:42:28 -0700 | [diff] [blame] | 176 | public float cellScaleToFit; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 177 | public int cellWidthPx; |
| 178 | public int cellHeightPx; |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 179 | public int workspaceCellPaddingXPx; |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 180 | |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 181 | public int cellYPaddingPx = -1; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 182 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 183 | // Folder |
Thales Lima | 1faa4ed | 2023-12-01 16:48:19 +0000 | [diff] [blame] | 184 | public final int numFolderRows; |
| 185 | public final int numFolderColumns; |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 186 | public final float folderLabelTextScale; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 187 | public int folderLabelTextSizePx; |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 188 | public int folderFooterHeightPx; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 189 | public int folderIconSizePx; |
Jon Miranda | 591e360 | 2018-03-28 11:37:00 -0700 | [diff] [blame] | 190 | public int folderIconOffsetYPx; |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 191 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 192 | // Folder content |
Jordan Silva | 637f4eb | 2023-06-13 11:21:53 +0100 | [diff] [blame] | 193 | public Point folderCellLayoutBorderSpacePx; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 194 | public int folderContentPaddingLeftRight; |
| 195 | public int folderContentPaddingTop; |
| 196 | |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 197 | // Folder cell |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 198 | public int folderCellWidthPx; |
| 199 | public int folderCellHeightPx; |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 200 | |
| 201 | // Folder child |
| 202 | public int folderChildIconSizePx; |
| 203 | public int folderChildTextSizePx; |
Sunny Goyal | baec6ff | 2016-09-14 11:26:21 -0700 | [diff] [blame] | 204 | public int folderChildDrawablePaddingPx; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 205 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 206 | // Hotseat |
Thales Lima | 9938c2f | 2022-07-25 14:38:16 +0100 | [diff] [blame] | 207 | public int numShownHotseatIcons; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 208 | public int hotseatCellHeightPx; |
Pat Manning | 26f70f7 | 2022-07-07 13:50:39 +0100 | [diff] [blame] | 209 | public final boolean areNavButtonsInline; |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 210 | // In portrait: size = height, in landscape: size = width |
| 211 | public int hotseatBarSizePx; |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 212 | public int hotseatBarBottomSpacePx; |
Pat Manning | 26f70f7 | 2022-07-07 13:50:39 +0100 | [diff] [blame] | 213 | public int hotseatBarEndOffset; |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 214 | public int hotseatQsbSpace; |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 215 | public int springLoadedHotseatBarTopMarginPx; |
Thales Lima | 8e11d53 | 2023-08-31 13:40:26 +0000 | [diff] [blame] | 216 | // These 2 values are only used for isVerticalBar |
| 217 | // Padding between edge of screen and hotseat |
| 218 | public final int mHotseatBarEdgePaddingPx; |
| 219 | // Space between hotseat and workspace (not used in responsive) |
| 220 | public final int mHotseatBarWorkspaceSpacePx; |
Alex Chau | 206ede9 | 2022-08-01 17:46:12 +0100 | [diff] [blame] | 221 | public int hotseatQsbWidth; // only used when isQsbInline |
Sunny Goyal | 57b2279 | 2021-05-25 14:35:01 -0700 | [diff] [blame] | 222 | public final int hotseatQsbHeight; |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 223 | public final int hotseatQsbVisualHeight; |
| 224 | private final int hotseatQsbShadowHeight; |
Thales Lima | dd02734 | 2022-01-07 12:54:37 +0000 | [diff] [blame] | 225 | public int hotseatBorderSpace; |
Thales Lima | ffc68b0 | 2023-01-09 16:20:23 +0000 | [diff] [blame] | 226 | private final int mMinHotseatIconSpacePx; |
| 227 | private final int mMinHotseatQsbWidthPx; |
| 228 | private final int mMaxHotseatIconSpacePx; |
Jon Miranda | e17a949 | 2023-03-08 16:42:20 -0800 | [diff] [blame] | 229 | public final int inlineNavButtonsEndSpacingPx; |
Liran Binyamin | a833af3 | 2023-08-02 16:30:27 -0400 | [diff] [blame] | 230 | // Space required for the bubble bar between the hotseat and the edge of the screen. If there's |
| 231 | // not enough space, the hotseat will adjust itself for the bubble bar. |
| 232 | private final int mBubbleBarSpaceThresholdPx; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 233 | |
Alex Chau | 3d2c062 | 2022-09-01 21:28:14 +0100 | [diff] [blame] | 234 | // Bottom sheets |
| 235 | public int bottomSheetTopPadding; |
| 236 | public int bottomSheetOpenDuration; |
| 237 | public int bottomSheetCloseDuration; |
| 238 | public float bottomSheetWorkspaceScale; |
| 239 | public float bottomSheetDepth; |
| 240 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 241 | // All apps |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 242 | public Point allAppsBorderSpacePx; |
Alex Chau | b8c22e1 | 2022-02-14 18:35:58 +0000 | [diff] [blame] | 243 | public int allAppsShiftRange; |
Thales Lima | b433c9c | 2023-10-30 12:24:05 +0000 | [diff] [blame] | 244 | public Rect allAppsPadding = new Rect(); |
Alex Chau | 3d2c062 | 2022-09-01 21:28:14 +0100 | [diff] [blame] | 245 | public int allAppsOpenDuration; |
| 246 | public int allAppsCloseDuration; |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 247 | public int allAppsCellHeightPx; |
Samuel Fufa | f1424a3 | 2019-10-04 15:15:19 -0700 | [diff] [blame] | 248 | public int allAppsCellWidthPx; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 249 | public int allAppsIconSizePx; |
| 250 | public int allAppsIconDrawablePaddingPx; |
Alex Chau | 27b39b9 | 2022-01-14 18:02:18 +0000 | [diff] [blame] | 251 | public int allAppsLeftRightMargin; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 252 | public final int numShownAllAppsColumns; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 253 | public float allAppsIconTextSizePx; |
| 254 | |
Zak Cohen | 334efeb | 2021-03-19 16:42:07 -0700 | [diff] [blame] | 255 | // Overview |
Zak Cohen | 334efeb | 2021-03-19 16:42:07 -0700 | [diff] [blame] | 256 | public int overviewTaskMarginPx; |
Alex Chau | dedbc8a | 2021-03-17 16:53:26 +0000 | [diff] [blame] | 257 | public int overviewTaskIconSizePx; |
Alex Chau | ac9df38 | 2021-08-02 19:08:41 +0100 | [diff] [blame] | 258 | public int overviewTaskIconDrawableSizePx; |
| 259 | public int overviewTaskIconDrawableSizeGridPx; |
Pat Manning | 1695cc7 | 2023-07-05 11:45:13 +0100 | [diff] [blame] | 260 | public int overviewTaskIconAppChipMenuDrawableSizePx; |
Alex Chau | dedbc8a | 2021-03-17 16:53:26 +0000 | [diff] [blame] | 261 | public int overviewTaskThumbnailTopMarginPx; |
Alex Chau | 19c6eca | 2022-03-10 20:12:56 +0000 | [diff] [blame] | 262 | public final int overviewActionsHeight; |
Alex Chau | a2fc764 | 2022-04-21 14:20:23 +0100 | [diff] [blame] | 263 | public final int overviewActionsTopMarginPx; |
Alex Chau | 1bf0fe1 | 2021-11-30 15:32:45 +0000 | [diff] [blame] | 264 | public final int overviewActionsButtonSpacing; |
Alex Chau | 5fd9d49 | 2021-07-22 17:27:11 +0100 | [diff] [blame] | 265 | public int overviewPageSpacing; |
| 266 | public int overviewRowSpacing; |
Alex Chau | 56bd257 | 2021-11-03 18:48:18 +0000 | [diff] [blame] | 267 | public int overviewGridSideMargin; |
Zak Cohen | 334efeb | 2021-03-19 16:42:07 -0700 | [diff] [blame] | 268 | |
Jeremy Sim | 0ac4708 | 2022-10-10 13:59:40 -0700 | [diff] [blame] | 269 | // Split staging |
| 270 | public int splitPlaceholderInset; |
| 271 | |
Jon Miranda | 7ae64ff | 2016-11-21 16:18:46 -0800 | [diff] [blame] | 272 | // Widgets |
Sihua Ma | e04aa20 | 2022-07-18 12:43:56 -0700 | [diff] [blame] | 273 | private final ViewScaleProvider mViewScaleProvider; |
Jon Miranda | 7ae64ff | 2016-11-21 16:18:46 -0800 | [diff] [blame] | 274 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 275 | // Drop Target |
| 276 | public int dropTargetBarSizePx; |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 277 | public int dropTargetBarTopMarginPx; |
| 278 | public int dropTargetBarBottomMarginPx; |
Alex Chau | a02eddc | 2021-04-29 00:36:06 +0100 | [diff] [blame] | 279 | public int dropTargetDragPaddingPx; |
| 280 | public int dropTargetTextSizePx; |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 281 | public int dropTargetHorizontalPaddingPx; |
| 282 | public int dropTargetVerticalPaddingPx; |
| 283 | public int dropTargetGapPx; |
Alex Chau | 5b01930 | 2022-05-23 10:42:25 +0100 | [diff] [blame] | 284 | public int dropTargetButtonWorkspaceEdgeGapPx; |
Adam Cohen | 4ae96ce | 2014-08-29 15:05:48 -0700 | [diff] [blame] | 285 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 286 | // Insets |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 287 | private final Rect mInsets = new Rect(); |
| 288 | public final Rect workspacePadding = new Rect(); |
Sunny Goyal | 6c304b1 | 2023-04-10 12:03:04 -0700 | [diff] [blame] | 289 | // Additional padding added to the widget inside its cellSpace. It is applied outside |
| 290 | // the widgetView, such that the actual view size is same as the widget size. |
| 291 | public final Rect widgetPadding = new Rect(); |
| 292 | |
Jon Miranda | 0bd63d1 | 2019-03-06 17:29:29 -0800 | [diff] [blame] | 293 | // When true, nav bar is on the left side of the screen. |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 294 | private boolean mIsSeascape; |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 295 | |
Tony Wickham | f34bee8 | 2018-12-03 18:11:39 -0800 | [diff] [blame] | 296 | // Notification dots |
Sunny Goyal | 65190ae | 2022-08-02 14:16:26 -0700 | [diff] [blame] | 297 | public final DotRenderer mDotRendererWorkSpace; |
| 298 | public final DotRenderer mDotRendererAllApps; |
Tony Wickham | 9a8d11f | 2017-01-11 09:53:12 -0800 | [diff] [blame] | 299 | |
Pierre Barbier de Reuille | 578deba | 2021-09-24 13:47:44 +0100 | [diff] [blame] | 300 | // Taskbar |
Tony Wickham | 1588389 | 2021-02-12 11:24:40 -0800 | [diff] [blame] | 301 | public boolean isTaskbarPresent; |
Tony Wickham | 635e180 | 2021-07-22 14:28:04 -1000 | [diff] [blame] | 302 | // Whether Taskbar will inset the bottom of apps by taskbarSize. |
| 303 | public boolean isTaskbarPresentInApps; |
Jon Miranda | 9c478b6 | 2023-03-23 21:38:49 -0700 | [diff] [blame] | 304 | public final int taskbarHeight; |
| 305 | public final int stashedTaskbarHeight; |
| 306 | public final int taskbarBottomMargin; |
| 307 | public final int taskbarIconSize; |
Uwais Ashraf | aa7fa88 | 2023-10-10 21:36:06 +0000 | [diff] [blame] | 308 | private final int mTransientTaskbarClaimedSpace; |
Jon Miranda | 04f0510 | 2023-04-04 12:16:31 -0700 | [diff] [blame] | 309 | // If true, used to layout taskbar in 3 button navigation mode. |
| 310 | public final boolean startAlignTaskbar; |
Thales Lima | e956640 | 2023-08-30 16:35:12 +0100 | [diff] [blame] | 311 | public final boolean isTransientTaskbar; |
Alex Chau | a02eddc | 2021-04-29 00:36:06 +0100 | [diff] [blame] | 312 | // DragController |
| 313 | public int flingToDeleteThresholdVelocity; |
| 314 | |
Vinit Nayak | 17c4b33 | 2021-08-05 12:54:58 -0700 | [diff] [blame] | 315 | /** TODO: Once we fully migrate to staged split, remove "isMultiWindowMode" */ |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 316 | DeviceProfile(Context context, InvariantDeviceProfile inv, Info info, WindowBounds windowBounds, |
Sunny Goyal | 65190ae | 2022-08-02 14:16:26 -0700 | [diff] [blame] | 317 | SparseArray<DotRenderer> dotRendererCache, boolean isMultiWindowMode, |
Alex Chau | ab800f7 | 2022-12-13 17:46:06 +0000 | [diff] [blame] | 318 | boolean transposeLayoutWithOrientation, boolean isMultiDisplay, boolean isGestureMode, |
Jon Miranda | 2b25ded | 2023-02-02 14:48:45 -0800 | [diff] [blame] | 319 | @NonNull final ViewScaleProvider viewScaleProvider, |
Jagrut Desai | 3a7d139 | 2023-09-06 15:56:19 -0700 | [diff] [blame] | 320 | @NonNull final Consumer<DeviceProfile> dimensionOverrideProvider, |
| 321 | boolean isTransientTaskbar) { |
Sunny Goyal | fee35bb | 2015-05-11 11:38:19 -0700 | [diff] [blame] | 322 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 323 | this.inv = inv; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 324 | this.isLandscape = windowBounds.isLandscape(); |
Sunny Goyal | d70e75a | 2018-02-22 10:07:32 -0800 | [diff] [blame] | 325 | this.isMultiWindowMode = isMultiWindowMode; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 326 | this.transposeLayoutWithOrientation = transposeLayoutWithOrientation; |
Alex Chau | ab800f7 | 2022-12-13 17:46:06 +0000 | [diff] [blame] | 327 | this.isMultiDisplay = isMultiDisplay; |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 328 | this.isGestureMode = isGestureMode; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 329 | windowX = windowBounds.bounds.left; |
| 330 | windowY = windowBounds.bounds.top; |
Sunny Goyal | 187b16c | 2022-03-01 16:53:23 -0800 | [diff] [blame] | 331 | this.rotationHint = windowBounds.rotationHint; |
Alex Chau | e022755 | 2022-04-06 19:44:43 +0100 | [diff] [blame] | 332 | mInsets.set(windowBounds.insets); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 333 | |
Thales Lima | c98b781 | 2023-04-14 15:04:23 +0100 | [diff] [blame] | 334 | // TODO(b/241386436): shouldn't change any launcher behaviour |
Thales Lima | abfe364 | 2023-05-24 18:08:53 +0100 | [diff] [blame] | 335 | mIsResponsiveGrid = inv.workspaceSpecsId != INVALID_RESOURCE_HANDLE |
Jordan Silva | 637f4eb | 2023-06-13 11:21:53 +0100 | [diff] [blame] | 336 | && inv.allAppsSpecsId != INVALID_RESOURCE_HANDLE |
Thales Lima | f8bfb03 | 2023-07-24 15:08:05 +0100 | [diff] [blame] | 337 | && inv.folderSpecsId != INVALID_RESOURCE_HANDLE |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 338 | && inv.hotseatSpecsId != INVALID_RESOURCE_HANDLE |
| 339 | && inv.workspaceCellSpecsId != INVALID_RESOURCE_HANDLE |
| 340 | && inv.allAppsCellSpecsId != INVALID_RESOURCE_HANDLE; |
Thales Lima | ec5abba | 2023-04-05 16:33:50 +0100 | [diff] [blame] | 341 | |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 342 | mIsScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode; |
Alex Chau | dfc8ddf | 2022-01-25 11:26:25 +0000 | [diff] [blame] | 343 | // Determine device posture. |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 344 | mInfo = info; |
Alex Chau | 2998307 | 2021-11-19 15:14:20 +0000 | [diff] [blame] | 345 | isTablet = info.isTablet(windowBounds); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 346 | isPhone = !isTablet; |
Alex Chau | ab800f7 | 2022-12-13 17:46:06 +0000 | [diff] [blame] | 347 | isTwoPanels = isTablet && isMultiDisplay; |
Vinit Nayak | 58c27cc | 2022-02-16 17:42:21 -0800 | [diff] [blame] | 348 | isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 349 | |
Alex Chau | dfc8ddf | 2022-01-25 11:26:25 +0000 | [diff] [blame] | 350 | // Some more constants. |
Alex Chau | 635b3ab | 2022-01-26 16:49:10 +0000 | [diff] [blame] | 351 | context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape) |
Brandon Dayauon | 07ca884 | 2022-04-27 10:52:28 -0700 | [diff] [blame] | 352 | ? Configuration.ORIENTATION_LANDSCAPE |
| 353 | : Configuration.ORIENTATION_PORTRAIT, |
Alex Chau | a6907dc | 2022-03-18 15:24:07 +0000 | [diff] [blame] | 354 | windowBounds); |
Sunny Goyal | 1890f67 | 2020-04-30 12:28:00 -0700 | [diff] [blame] | 355 | final Resources res = context.getResources(); |
Alex Chau | dfc8ddf | 2022-01-25 11:26:25 +0000 | [diff] [blame] | 356 | mMetrics = res.getDisplayMetrics(); |
| 357 | |
Charlie Anderson | 7bb1097 | 2023-11-22 13:35:30 -0800 | [diff] [blame] | 358 | mIconSizeSteps = new IconSizeSteps(res); |
Thales Lima | 2759aa3 | 2023-06-05 16:25:45 +0100 | [diff] [blame] | 359 | |
Alex Chau | dfc8ddf | 2022-01-25 11:26:25 +0000 | [diff] [blame] | 360 | // Determine sizes. |
| 361 | widthPx = windowBounds.bounds.width(); |
| 362 | heightPx = windowBounds.bounds.height(); |
| 363 | availableWidthPx = windowBounds.availableSize.x; |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 364 | availableHeightPx = windowBounds.availableSize.y; |
Alex Chau | dfc8ddf | 2022-01-25 11:26:25 +0000 | [diff] [blame] | 365 | |
| 366 | aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx); |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 367 | if (isTwoPanels) { |
| 368 | if (isLandscape) { |
Thales Lima | 12d0eff | 2022-03-25 17:06:11 +0000 | [diff] [blame] | 369 | mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 370 | } else { |
Thales Lima | 12d0eff | 2022-03-25 17:06:11 +0000 | [diff] [blame] | 371 | mTypeIndex = INDEX_TWO_PANEL_PORTRAIT; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 372 | } |
| 373 | } else { |
| 374 | if (isLandscape) { |
Thales Lima | 12d0eff | 2022-03-25 17:06:11 +0000 | [diff] [blame] | 375 | mTypeIndex = INDEX_LANDSCAPE; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 376 | } else { |
Thales Lima | 12d0eff | 2022-03-25 17:06:11 +0000 | [diff] [blame] | 377 | mTypeIndex = INDEX_DEFAULT; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | |
Jagrut Desai | 3a7d139 | 2023-09-06 15:56:19 -0700 | [diff] [blame] | 381 | this.isTransientTaskbar = isTransientTaskbar; |
Uwais Ashraf | aa7fa88 | 2023-10-10 21:36:06 +0000 | [diff] [blame] | 382 | int transientTaskbarIconSize = pxFromDp(inv.transientTaskbarIconSize[mTypeIndex], mMetrics); |
| 383 | int transientTaskbarBottomMargin = |
| 384 | res.getDimensionPixelSize(R.dimen.transient_taskbar_bottom_margin); |
| 385 | int transientTaskbarHeight = |
| 386 | Math.round((transientTaskbarIconSize * ICON_VISIBLE_AREA_FACTOR) |
Jordan Silva | f2402e2 | 2023-10-26 19:53:16 +0100 | [diff] [blame] | 387 | + (2 * res.getDimensionPixelSize(R.dimen.transient_taskbar_padding))); |
Uwais Ashraf | aa7fa88 | 2023-10-10 21:36:06 +0000 | [diff] [blame] | 388 | mTransientTaskbarClaimedSpace = transientTaskbarHeight + 2 * transientTaskbarBottomMargin; |
| 389 | |
Uwais Ashraf | 3602d17 | 2023-09-15 11:36:32 +0000 | [diff] [blame] | 390 | if (!isTaskbarPresent) { |
| 391 | taskbarIconSize = taskbarHeight = stashedTaskbarHeight = taskbarBottomMargin = 0; |
| 392 | startAlignTaskbar = false; |
| 393 | } else if (isTransientTaskbar) { |
Uwais Ashraf | aa7fa88 | 2023-10-10 21:36:06 +0000 | [diff] [blame] | 394 | taskbarIconSize = transientTaskbarIconSize; |
| 395 | taskbarHeight = transientTaskbarHeight; |
Jon Miranda | 9c478b6 | 2023-03-23 21:38:49 -0700 | [diff] [blame] | 396 | stashedTaskbarHeight = |
| 397 | res.getDimensionPixelSize(R.dimen.transient_taskbar_stashed_height); |
Uwais Ashraf | aa7fa88 | 2023-10-10 21:36:06 +0000 | [diff] [blame] | 398 | taskbarBottomMargin = transientTaskbarBottomMargin; |
Jon Miranda | 04f0510 | 2023-04-04 12:16:31 -0700 | [diff] [blame] | 399 | startAlignTaskbar = false; |
Jon Miranda | 9c478b6 | 2023-03-23 21:38:49 -0700 | [diff] [blame] | 400 | } else { |
| 401 | taskbarIconSize = pxFromDp(ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size), |
| 402 | mMetrics); |
| 403 | taskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_size); |
| 404 | stashedTaskbarHeight = res.getDimensionPixelSize(R.dimen.taskbar_stashed_size); |
| 405 | taskbarBottomMargin = 0; |
Jon Miranda | 04f0510 | 2023-04-04 12:16:31 -0700 | [diff] [blame] | 406 | startAlignTaskbar = inv.startAlignTaskbar[mTypeIndex]; |
Tony Wickham | 1588389 | 2021-02-12 11:24:40 -0800 | [diff] [blame] | 407 | } |
Tony Wickham | 1588389 | 2021-02-12 11:24:40 -0800 | [diff] [blame] | 408 | |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 409 | edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin); |
Alex Chau | 0c4e11b | 2022-07-08 18:41:36 +0100 | [diff] [blame] | 410 | workspaceContentScale = res.getFloat(R.dimen.workspace_content_scale); |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 411 | |
Alex Chau | 51da219 | 2022-05-20 13:32:10 +0100 | [diff] [blame] | 412 | gridVisualizationPaddingX = res.getDimensionPixelSize( |
| 413 | R.dimen.grid_visualization_horizontal_cell_spacing); |
| 414 | gridVisualizationPaddingY = res.getDimensionPixelSize( |
| 415 | R.dimen.grid_visualization_vertical_cell_spacing); |
Samuel Fufa | ee9aff9 | 2021-04-05 13:30:40 -0500 | [diff] [blame] | 416 | |
Alex Chau | e022755 | 2022-04-06 19:44:43 +0100 | [diff] [blame] | 417 | bottomSheetTopPadding = mInsets.top // statusbar height |
Andras Kloczl | 142b054 | 2022-03-09 21:26:02 +0000 | [diff] [blame] | 418 | + res.getDimensionPixelSize(R.dimen.bottom_sheet_extra_top_padding) |
| 419 | + (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding |
Alex Chau | 3d2c062 | 2022-09-01 21:28:14 +0100 | [diff] [blame] | 420 | bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration); |
| 421 | bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration); |
| 422 | if (isTablet) { |
| 423 | bottomSheetWorkspaceScale = workspaceContentScale; |
Alex Chau | ab800f7 | 2022-12-13 17:46:06 +0000 | [diff] [blame] | 424 | if (isMultiDisplay && !ENABLE_MULTI_DISPLAY_PARTIAL_DEPTH.get()) { |
| 425 | // TODO(b/259893832): Revert to use maxWallpaperScale to calculate bottomSheetDepth |
| 426 | // when screen recorder bug is fixed. |
| 427 | bottomSheetDepth = 1f; |
| 428 | } else { |
| 429 | // The goal is to set wallpaper to zoom at workspaceContentScale when in AllApps. |
| 430 | // When depth is 0, wallpaper zoom is set to maxWallpaperScale. |
| 431 | // When depth is 1, wallpaper zoom is set to 1. |
| 432 | // For depth to achieve zoom set to maxWallpaperScale * workspaceContentScale: |
| 433 | float maxWallpaperScale = res.getFloat(R.dimen.config_wallpaperMaxScale); |
| 434 | bottomSheetDepth = Utilities.mapToRange(maxWallpaperScale * workspaceContentScale, |
| 435 | maxWallpaperScale, 1f, 0f, 1f, LINEAR); |
| 436 | } |
Alex Chau | 3d2c062 | 2022-09-01 21:28:14 +0100 | [diff] [blame] | 437 | } else { |
| 438 | bottomSheetWorkspaceScale = 1f; |
| 439 | bottomSheetDepth = 0f; |
| 440 | } |
Andras Kloczl | 142b054 | 2022-03-09 21:26:02 +0000 | [diff] [blame] | 441 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 442 | folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale); |
Thales Lima | 1faa4ed | 2023-12-01 16:48:19 +0000 | [diff] [blame] | 443 | numFolderRows = inv.numFolderRows[mTypeIndex]; |
| 444 | numFolderColumns = inv.numFolderColumns[mTypeIndex]; |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 445 | |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 446 | if (mIsScalableGrid && inv.folderStyle != INVALID_RESOURCE_HANDLE) { |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 447 | TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle, |
Thales Lima | d852d65 | 2023-01-17 14:01:13 +0000 | [diff] [blame] | 448 | R.styleable.FolderStyle); |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 449 | // These are re-set in #updateFolderCellSize if the grid is not scalable |
| 450 | folderCellHeightPx = folderStyle.getDimensionPixelSize( |
Thales Lima | d852d65 | 2023-01-17 14:01:13 +0000 | [diff] [blame] | 451 | R.styleable.FolderStyle_folderCellHeight, 0); |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 452 | folderCellWidthPx = folderStyle.getDimensionPixelSize( |
Thales Lima | d852d65 | 2023-01-17 14:01:13 +0000 | [diff] [blame] | 453 | R.styleable.FolderStyle_folderCellWidth, 0); |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 454 | |
| 455 | folderContentPaddingTop = folderStyle.getDimensionPixelSize( |
Thales Lima | d852d65 | 2023-01-17 14:01:13 +0000 | [diff] [blame] | 456 | R.styleable.FolderStyle_folderTopPadding, 0); |
Jordan Silva | 637f4eb | 2023-06-13 11:21:53 +0100 | [diff] [blame] | 457 | |
| 458 | int gutter = folderStyle.getDimensionPixelSize( |
Thales Lima | d852d65 | 2023-01-17 14:01:13 +0000 | [diff] [blame] | 459 | R.styleable.FolderStyle_folderBorderSpace, 0); |
Jordan Silva | 637f4eb | 2023-06-13 11:21:53 +0100 | [diff] [blame] | 460 | folderCellLayoutBorderSpacePx = new Point(gutter, gutter); |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 461 | folderFooterHeightPx = folderStyle.getDimensionPixelSize( |
Thales Lima | d852d65 | 2023-01-17 14:01:13 +0000 | [diff] [blame] | 462 | R.styleable.FolderStyle_folderFooterHeight, 0); |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 463 | folderStyle.recycle(); |
Jordan Silva | 637f4eb | 2023-06-13 11:21:53 +0100 | [diff] [blame] | 464 | } else if (!mIsResponsiveGrid) { |
| 465 | folderCellLayoutBorderSpacePx = new Point(0, 0); |
Thales Lima | 7eee74b | 2023-03-16 16:00:55 -0300 | [diff] [blame] | 466 | folderFooterHeightPx = res.getDimensionPixelSize(R.dimen.folder_footer_height_default); |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 467 | folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default); |
| 468 | } |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 469 | |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 470 | allAppsBorderSpacePx = new Point( |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 471 | pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics), |
| 472 | pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics)); |
Thales Lima | e9273ea | 2023-01-26 12:33:52 +0000 | [diff] [blame] | 473 | setupAllAppsStyle(context); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 474 | |
Tony Wickham | 5edf9e2 | 2020-03-27 20:06:52 -0700 | [diff] [blame] | 475 | workspacePageIndicatorHeight = res.getDimensionPixelSize( |
| 476 | R.dimen.workspace_page_indicator_height); |
| 477 | mWorkspacePageIndicatorOverlapWorkspace = |
| 478 | res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace); |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 479 | |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 480 | if (!mIsResponsiveGrid) { |
| 481 | TypedArray cellStyle; |
| 482 | if (inv.cellStyle != INVALID_RESOURCE_HANDLE) { |
| 483 | cellStyle = context.obtainStyledAttributes(inv.cellStyle, |
| 484 | R.styleable.CellStyle); |
| 485 | } else { |
| 486 | cellStyle = context.obtainStyledAttributes(R.style.CellStyleDefault, |
| 487 | R.styleable.CellStyle); |
| 488 | } |
| 489 | mIconDrawablePaddingOriginalPx = cellStyle.getDimensionPixelSize( |
| 490 | R.styleable.CellStyle_iconDrawablePadding, 0); |
| 491 | cellStyle.recycle(); |
Thales Lima | d852d65 | 2023-01-17 14:01:13 +0000 | [diff] [blame] | 492 | } |
Alex Chau | a02eddc | 2021-04-29 00:36:06 +0100 | [diff] [blame] | 493 | |
Sunny Goyal | 47328fd | 2016-05-25 18:56:41 -0700 | [diff] [blame] | 494 | dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size); |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 495 | dropTargetBarTopMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_top_margin); |
| 496 | dropTargetBarBottomMarginPx = res.getDimensionPixelSize(R.dimen.drop_target_bottom_margin); |
Alex Chau | a02eddc | 2021-04-29 00:36:06 +0100 | [diff] [blame] | 497 | dropTargetDragPaddingPx = res.getDimensionPixelSize(R.dimen.drop_target_drag_padding); |
| 498 | dropTargetTextSizePx = res.getDimensionPixelSize(R.dimen.drop_target_text_size); |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 499 | dropTargetHorizontalPaddingPx = res.getDimensionPixelSize( |
| 500 | R.dimen.drop_target_button_drawable_horizontal_padding); |
| 501 | dropTargetVerticalPaddingPx = res.getDimensionPixelSize( |
| 502 | R.dimen.drop_target_button_drawable_vertical_padding); |
| 503 | dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap); |
Alex Chau | 5b01930 | 2022-05-23 10:42:25 +0100 | [diff] [blame] | 504 | dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize( |
| 505 | R.dimen.drop_target_button_workspace_edge_gap); |
Alex Chau | a02eddc | 2021-04-29 00:36:06 +0100 | [diff] [blame] | 506 | |
Alex Chau | 906d882 | 2022-05-23 10:42:25 +0100 | [diff] [blame] | 507 | workspaceSpringLoadedMinNextPageVisiblePx = res.getDimensionPixelSize( |
| 508 | R.dimen.dynamic_grid_spring_loaded_min_next_space_visible); |
Sunny Goyal | d519052 | 2017-04-24 03:06:54 -0700 | [diff] [blame] | 509 | |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 510 | workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x); |
Jon Miranda | 0966072 | 2017-06-14 14:20:14 -0700 | [diff] [blame] | 511 | |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 512 | hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height); |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 513 | hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height); |
| 514 | hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight; |
| 515 | |
Thales Lima | 12d0eff | 2022-03-25 17:06:11 +0000 | [diff] [blame] | 516 | // Whether QSB might be inline in appropriate orientation (e.g. landscape). |
| 517 | boolean canQsbInline = (isTwoPanels ? inv.inlineQsb[INDEX_TWO_PANEL_PORTRAIT] |
| 518 | || inv.inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] |
| 519 | : inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE]) |
| 520 | && hotseatQsbHeight > 0; |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 521 | isQsbInline = mIsScalableGrid && inv.inlineQsb[mTypeIndex] && canQsbInline; |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 522 | |
Thales Lima | 425f682 | 2022-05-10 13:44:58 -0300 | [diff] [blame] | 523 | areNavButtonsInline = isTaskbarPresent && !isGestureMode; |
Thales Lima | 9938c2f | 2022-07-25 14:38:16 +0100 | [diff] [blame] | 524 | numShownHotseatIcons = |
| 525 | isTwoPanels ? inv.numDatabaseHotseatIcons : inv.numShownHotseatIcons; |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 526 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 527 | numShownAllAppsColumns = |
| 528 | isTwoPanels ? inv.numDatabaseAllAppsColumns : inv.numAllAppsColumns; |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 529 | |
Thales Lima | 8e11d53 | 2023-08-31 13:40:26 +0000 | [diff] [blame] | 530 | int hotseatBarBottomSpace; |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 531 | int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin); |
Thales Lima | f8bfb03 | 2023-07-24 15:08:05 +0100 | [diff] [blame] | 532 | |
| 533 | if (mIsResponsiveGrid) { |
Jordan Silva | f2402e2 | 2023-10-26 19:53:16 +0100 | [diff] [blame] | 534 | float responsiveAspectRatio = (float) widthPx / heightPx; |
| 535 | HotseatSpecsProvider hotseatSpecsProvider = |
| 536 | HotseatSpecsProvider.create(new ResourceHelper(context, |
Thales Lima | f8bfb03 | 2023-07-24 15:08:05 +0100 | [diff] [blame] | 537 | isTwoPanels ? inv.hotseatSpecsTwoPanelId : inv.hotseatSpecsId)); |
Thales Lima | 8e11d53 | 2023-08-31 13:40:26 +0000 | [diff] [blame] | 538 | mResponsiveHotseatSpec = |
Jordan Silva | f2402e2 | 2023-10-26 19:53:16 +0100 | [diff] [blame] | 539 | isVerticalBarLayout() ? hotseatSpecsProvider.getCalculatedSpec( |
| 540 | responsiveAspectRatio, DimensionType.WIDTH, widthPx) |
| 541 | : hotseatSpecsProvider.getCalculatedSpec(responsiveAspectRatio, |
| 542 | DimensionType.HEIGHT, heightPx); |
Thales Lima | f8bfb03 | 2023-07-24 15:08:05 +0100 | [diff] [blame] | 543 | hotseatQsbSpace = mResponsiveHotseatSpec.getHotseatQsbSpace(); |
Thales Lima | 8e11d53 | 2023-08-31 13:40:26 +0000 | [diff] [blame] | 544 | hotseatBarBottomSpace = |
| 545 | isVerticalBarLayout() ? 0 : mResponsiveHotseatSpec.getEdgePadding(); |
| 546 | mHotseatBarEdgePaddingPx = |
| 547 | isVerticalBarLayout() ? mResponsiveHotseatSpec.getEdgePadding() : 0; |
| 548 | mHotseatBarWorkspaceSpacePx = 0; |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 549 | |
| 550 | ResponsiveCellSpecsProvider workspaceCellSpecs = ResponsiveCellSpecsProvider.create( |
| 551 | new ResourceHelper(context, |
| 552 | isTwoPanels ? inv.workspaceCellSpecsTwoPanelId |
| 553 | : inv.workspaceCellSpecsId)); |
| 554 | mResponsiveWorkspaceCellSpec = workspaceCellSpecs.getCalculatedSpec( |
| 555 | responsiveAspectRatio, heightPx); |
Thales Lima | f8bfb03 | 2023-07-24 15:08:05 +0100 | [diff] [blame] | 556 | } else { |
| 557 | hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics); |
Thales Lima | 8e11d53 | 2023-08-31 13:40:26 +0000 | [diff] [blame] | 558 | hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics); |
| 559 | mHotseatBarEdgePaddingPx = |
| 560 | isVerticalBarLayout() ? workspacePageIndicatorHeight : 0; |
| 561 | mHotseatBarWorkspaceSpacePx = |
| 562 | res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_side_padding); |
Thales Lima | f8bfb03 | 2023-07-24 15:08:05 +0100 | [diff] [blame] | 563 | } |
| 564 | |
Thales Lima | 8e11d53 | 2023-08-31 13:40:26 +0000 | [diff] [blame] | 565 | if (!isVerticalBarLayout()) { |
| 566 | // Have a little space between the inset and the QSB |
| 567 | if (mInsets.bottom + minQsbMargin > hotseatBarBottomSpace) { |
| 568 | int availableSpace = hotseatQsbSpace - (mInsets.bottom - hotseatBarBottomSpace); |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 569 | |
Thales Lima | 8e11d53 | 2023-08-31 13:40:26 +0000 | [diff] [blame] | 570 | // Only change the spaces if there is space |
| 571 | if (availableSpace > 0) { |
| 572 | // Make sure there is enough space between hotseat/QSB and QSB/navBar |
| 573 | if (availableSpace < minQsbMargin * 2) { |
| 574 | minQsbMargin = availableSpace / 2; |
| 575 | hotseatQsbSpace = minQsbMargin; |
| 576 | } else { |
| 577 | hotseatQsbSpace -= minQsbMargin; |
| 578 | } |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 579 | } |
Thales Lima | 8e11d53 | 2023-08-31 13:40:26 +0000 | [diff] [blame] | 580 | hotseatBarBottomSpacePx = mInsets.bottom + minQsbMargin; |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 581 | |
Thales Lima | 8e11d53 | 2023-08-31 13:40:26 +0000 | [diff] [blame] | 582 | } else { |
| 583 | hotseatBarBottomSpacePx = hotseatBarBottomSpace; |
| 584 | } |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 585 | } |
Thales Lima | 425f682 | 2022-05-10 13:44:58 -0300 | [diff] [blame] | 586 | |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 587 | springLoadedHotseatBarTopMarginPx = res.getDimensionPixelSize( |
| 588 | R.dimen.spring_loaded_hotseat_top_margin); |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 589 | |
| 590 | if (mIsResponsiveGrid) { |
| 591 | updateHotseatSizes(mResponsiveWorkspaceCellSpec.getIconSize()); |
| 592 | } else { |
| 593 | updateHotseatSizes(pxFromDp(inv.iconSize[mTypeIndex], mMetrics)); |
| 594 | } |
| 595 | |
Vinit Nayak | 8a3d055 | 2022-08-05 10:43:29 -0700 | [diff] [blame] | 596 | if (areNavButtonsInline && !isPhone) { |
Jon Miranda | e17a949 | 2023-03-08 16:42:20 -0800 | [diff] [blame] | 597 | inlineNavButtonsEndSpacingPx = |
Thales Lima | ffc68b0 | 2023-01-09 16:20:23 +0000 | [diff] [blame] | 598 | res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing); |
Pat Manning | 26f70f7 | 2022-07-07 13:50:39 +0100 | [diff] [blame] | 599 | /* |
| 600 | * 3 nav buttons + |
Vinit Nayak | c729317 | 2022-07-18 16:41:50 -0700 | [diff] [blame] | 601 | * Spacing between nav buttons + |
Thales Lima | 6a59006 | 2022-11-22 15:52:49 +0000 | [diff] [blame] | 602 | * Space at the end for contextual buttons |
Pat Manning | 26f70f7 | 2022-07-07 13:50:39 +0100 | [diff] [blame] | 603 | */ |
| 604 | hotseatBarEndOffset = 3 * res.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size) |
Vinit Nayak | c729317 | 2022-07-18 16:41:50 -0700 | [diff] [blame] | 605 | + 2 * res.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween) |
Jon Miranda | e17a949 | 2023-03-08 16:42:20 -0800 | [diff] [blame] | 606 | + inlineNavButtonsEndSpacingPx; |
Pat Manning | 26f70f7 | 2022-07-07 13:50:39 +0100 | [diff] [blame] | 607 | } else { |
Jon Miranda | e17a949 | 2023-03-08 16:42:20 -0800 | [diff] [blame] | 608 | inlineNavButtonsEndSpacingPx = 0; |
Pat Manning | 26f70f7 | 2022-07-07 13:50:39 +0100 | [diff] [blame] | 609 | hotseatBarEndOffset = 0; |
| 610 | } |
Jon Miranda | 8bdb222 | 2021-06-23 18:10:10 -0700 | [diff] [blame] | 611 | |
Liran Binyamin | a833af3 | 2023-08-02 16:30:27 -0400 | [diff] [blame] | 612 | mBubbleBarSpaceThresholdPx = |
| 613 | res.getDimensionPixelSize(R.dimen.bubblebar_hotseat_adjustment_threshold); |
| 614 | |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 615 | // Needs to be calculated after hotseatBarSizePx is correct, |
| 616 | // for the available height to be correct |
| 617 | if (mIsResponsiveGrid) { |
Thales Lima | 2759aa3 | 2023-06-05 16:25:45 +0100 | [diff] [blame] | 618 | int availableResponsiveWidth = |
| 619 | availableWidthPx - (isVerticalBarLayout() ? hotseatBarSizePx : 0); |
Jordan Silva | 376036a | 2023-11-08 15:56:40 +0000 | [diff] [blame] | 620 | int numWorkspaceColumns = getPanelCount() * inv.numColumns; |
Thales Lima | 8e11d53 | 2023-08-31 13:40:26 +0000 | [diff] [blame] | 621 | // don't use availableHeightPx because it subtracts mInsets.bottom |
| 622 | int availableResponsiveHeight = heightPx - mInsets.top |
Jordan Silva | f2402e2 | 2023-10-26 19:53:16 +0100 | [diff] [blame] | 623 | - (isVerticalBarLayout() ? 0 : hotseatBarSizePx); |
| 624 | float responsiveAspectRatio = (float) widthPx / heightPx; |
Thales Lima | abfe364 | 2023-05-24 18:08:53 +0100 | [diff] [blame] | 625 | |
Jordan Silva | f2402e2 | 2023-10-26 19:53:16 +0100 | [diff] [blame] | 626 | ResponsiveSpecsProvider workspaceSpecs = ResponsiveSpecsProvider.create( |
Jordan Silva | 575c3bd | 2023-07-21 12:00:43 +0100 | [diff] [blame] | 627 | new ResourceHelper(context, |
Jordan Silva | f2402e2 | 2023-10-26 19:53:16 +0100 | [diff] [blame] | 628 | isTwoPanels ? inv.workspaceSpecsTwoPanelId : inv.workspaceSpecsId), |
| 629 | ResponsiveSpecType.Workspace); |
Jordan Silva | 8f7986a | 2023-11-08 12:11:25 +0000 | [diff] [blame] | 630 | mResponsiveWorkspaceWidthSpec = workspaceSpecs.getCalculatedSpec(responsiveAspectRatio, |
Jordan Silva | 376036a | 2023-11-08 15:56:40 +0000 | [diff] [blame] | 631 | DimensionType.WIDTH, numWorkspaceColumns, availableResponsiveWidth); |
Jordan Silva | 8f7986a | 2023-11-08 12:11:25 +0000 | [diff] [blame] | 632 | mResponsiveWorkspaceHeightSpec = workspaceSpecs.getCalculatedSpec(responsiveAspectRatio, |
Jordan Silva | f2402e2 | 2023-10-26 19:53:16 +0100 | [diff] [blame] | 633 | DimensionType.HEIGHT, inv.numRows, availableResponsiveHeight); |
Jordan Silva | 637f4eb | 2023-06-13 11:21:53 +0100 | [diff] [blame] | 634 | |
Jordan Silva | f2402e2 | 2023-10-26 19:53:16 +0100 | [diff] [blame] | 635 | ResponsiveSpecsProvider allAppsSpecs = ResponsiveSpecsProvider.create( |
Jordan Silva | 575c3bd | 2023-07-21 12:00:43 +0100 | [diff] [blame] | 636 | new ResourceHelper(context, |
Jordan Silva | f2402e2 | 2023-10-26 19:53:16 +0100 | [diff] [blame] | 637 | isTwoPanels ? inv.allAppsSpecsTwoPanelId : inv.allAppsSpecsId), |
| 638 | ResponsiveSpecType.AllApps); |
Jordan Silva | 8f7986a | 2023-11-08 12:11:25 +0000 | [diff] [blame] | 639 | mResponsiveAllAppsWidthSpec = allAppsSpecs.getCalculatedSpec(responsiveAspectRatio, |
Jordan Silva | 8b3fa14 | 2023-11-13 21:31:38 +0000 | [diff] [blame] | 640 | DimensionType.WIDTH, numShownAllAppsColumns, availableWidthPx, |
Jordan Silva | 8f7986a | 2023-11-08 12:11:25 +0000 | [diff] [blame] | 641 | mResponsiveWorkspaceWidthSpec); |
| 642 | mResponsiveAllAppsHeightSpec = allAppsSpecs.getCalculatedSpec(responsiveAspectRatio, |
Jordan Silva | 2de6a27 | 2024-01-04 14:44:20 -0300 | [diff] [blame] | 643 | DimensionType.HEIGHT, inv.numAllAppsRowsForCellHeightCalculation, |
| 644 | heightPx - mInsets.top, mResponsiveWorkspaceHeightSpec); |
Jordan Silva | f2402e2 | 2023-10-26 19:53:16 +0100 | [diff] [blame] | 645 | |
| 646 | ResponsiveSpecsProvider folderSpecs = ResponsiveSpecsProvider.create( |
| 647 | new ResourceHelper(context, |
| 648 | isTwoPanels ? inv.folderSpecsTwoPanelId : inv.folderSpecsId), |
| 649 | ResponsiveSpecType.Folder); |
| 650 | mResponsiveFolderWidthSpec = folderSpecs.getCalculatedSpec(responsiveAspectRatio, |
Thales Lima | 1faa4ed | 2023-12-01 16:48:19 +0000 | [diff] [blame] | 651 | DimensionType.WIDTH, numFolderColumns, |
Jordan Silva | 8f7986a | 2023-11-08 12:11:25 +0000 | [diff] [blame] | 652 | mResponsiveWorkspaceWidthSpec.getAvailableSpace(), |
| 653 | mResponsiveWorkspaceWidthSpec); |
Jordan Silva | f2402e2 | 2023-10-26 19:53:16 +0100 | [diff] [blame] | 654 | mResponsiveFolderHeightSpec = folderSpecs.getCalculatedSpec(responsiveAspectRatio, |
Thales Lima | 1faa4ed | 2023-12-01 16:48:19 +0000 | [diff] [blame] | 655 | DimensionType.HEIGHT, numFolderRows, |
Jordan Silva | 8f7986a | 2023-11-08 12:11:25 +0000 | [diff] [blame] | 656 | mResponsiveWorkspaceHeightSpec.getAvailableSpace(), |
| 657 | mResponsiveWorkspaceHeightSpec); |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 658 | |
| 659 | ResponsiveCellSpecsProvider allAppsCellSpecs = ResponsiveCellSpecsProvider.create( |
| 660 | new ResourceHelper(context, |
| 661 | isTwoPanels ? inv.allAppsCellSpecsTwoPanelId |
| 662 | : inv.allAppsCellSpecsId)); |
| 663 | mResponsiveAllAppsCellSpec = allAppsCellSpecs.getCalculatedSpec( |
| 664 | responsiveAspectRatio, |
| 665 | mResponsiveAllAppsHeightSpec.getAvailableSpace(), |
| 666 | mResponsiveWorkspaceCellSpec); |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | desiredWorkspaceHorizontalMarginPx = getHorizontalMarginPx(inv, res); |
| 670 | desiredWorkspaceHorizontalMarginOriginalPx = desiredWorkspaceHorizontalMarginPx; |
| 671 | |
Alex Chau | 635b3ab | 2022-01-26 16:49:10 +0000 | [diff] [blame] | 672 | overviewTaskMarginPx = res.getDimensionPixelSize(R.dimen.overview_task_margin); |
Pat Manning | 1695cc7 | 2023-07-05 11:45:13 +0100 | [diff] [blame] | 673 | overviewTaskIconSizePx = enableOverviewIconMenu() ? res.getDimensionPixelSize( |
| 674 | R.dimen.task_thumbnail_icon_menu_drawable_touch_size) : res.getDimensionPixelSize( |
| 675 | R.dimen.task_thumbnail_icon_size); |
Alex Chau | ac9df38 | 2021-08-02 19:08:41 +0100 | [diff] [blame] | 676 | overviewTaskIconDrawableSizePx = |
| 677 | res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size); |
| 678 | overviewTaskIconDrawableSizeGridPx = |
| 679 | res.getDimensionPixelSize(R.dimen.task_thumbnail_icon_drawable_size_grid); |
Pat Manning | 1695cc7 | 2023-07-05 11:45:13 +0100 | [diff] [blame] | 680 | overviewTaskIconAppChipMenuDrawableSizePx = res.getDimensionPixelSize( |
| 681 | R.dimen.task_thumbnail_icon_menu_drawable_size); |
| 682 | overviewTaskThumbnailTopMarginPx = |
| 683 | enableOverviewIconMenu() ? 0 : overviewTaskIconSizePx + overviewTaskMarginPx; |
Andy Wickham | bc3bac4 | 2023-08-07 16:02:23 -0700 | [diff] [blame] | 684 | // Don't add margin with floating search bar to minimize risk of overlapping. |
| 685 | overviewActionsTopMarginPx = FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get() ? 0 |
| 686 | : res.getDimensionPixelSize(R.dimen.overview_actions_top_margin); |
Alex Chau | 635b3ab | 2022-01-26 16:49:10 +0000 | [diff] [blame] | 687 | overviewPageSpacing = res.getDimensionPixelSize(R.dimen.overview_page_spacing); |
| 688 | overviewActionsButtonSpacing = res.getDimensionPixelSize( |
| 689 | R.dimen.overview_actions_button_spacing); |
Andy Wickham | bc3bac4 | 2023-08-07 16:02:23 -0700 | [diff] [blame] | 690 | overviewActionsHeight = res.getDimensionPixelSize(R.dimen.overview_actions_height); |
Jeremy Sim | 1cfe6d4 | 2022-07-15 14:40:38 -0700 | [diff] [blame] | 691 | overviewRowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing); |
Alex Chau | 635b3ab | 2022-01-26 16:49:10 +0000 | [diff] [blame] | 692 | overviewGridSideMargin = res.getDimensionPixelSize(R.dimen.overview_grid_side_margin); |
Zak Cohen | 334efeb | 2021-03-19 16:42:07 -0700 | [diff] [blame] | 693 | |
Jeremy Sim | 0ac4708 | 2022-10-10 13:59:40 -0700 | [diff] [blame] | 694 | splitPlaceholderInset = res.getDimensionPixelSize(R.dimen.split_placeholder_inset); |
Winson Chung | 104a4c8 | 2023-11-08 18:56:15 +0000 | [diff] [blame] | 695 | // We need to use the full window bounds for split determination because on near-square |
| 696 | // devices, the available bounds (bounds minus insets) may actually be in landscape while |
| 697 | // actually portrait |
| 698 | int leftRightSplitPortraitResId = Resources.getSystem().getIdentifier( |
| 699 | "config_leftRightSplitInPortrait", "bool", "android"); |
| 700 | boolean allowLeftRightSplitInPortrait = |
| 701 | com.android.wm.shell.Flags.enableLeftRightSplitInPortrait() |
| 702 | && leftRightSplitPortraitResId > 0 |
| 703 | && res.getBoolean(leftRightSplitPortraitResId); |
| 704 | if (allowLeftRightSplitInPortrait && isTablet) { |
| 705 | isLeftRightSplit = !isLandscape; |
| 706 | } else { |
| 707 | isLeftRightSplit = isLandscape; |
| 708 | } |
Jeremy Sim | 0ac4708 | 2022-10-10 13:59:40 -0700 | [diff] [blame] | 709 | |
Jon Miranda | 2ed276e | 2017-06-29 11:36:34 -0700 | [diff] [blame] | 710 | // Calculate all of the remaining variables. |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 711 | extraSpace = updateAvailableDimensions(res); |
Jon Miranda | 80cddbc | 2021-07-22 13:51:16 -0700 | [diff] [blame] | 712 | |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 713 | calculateAndSetWorkspaceVerticalPadding(context, inv, extraSpace); |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 714 | |
| 715 | int cellLayoutPadding = |
| 716 | isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize( |
| 717 | R.dimen.cell_layout_padding); |
| 718 | cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding, |
| 719 | cellLayoutPadding); |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 720 | updateWorkspacePadding(); |
Tony Wickham | 1237df0 | 2017-02-24 08:59:36 -0800 | [diff] [blame] | 721 | |
Thales Lima | 7eee74b | 2023-03-16 16:00:55 -0300 | [diff] [blame] | 722 | // Folder scaling requires correct workspace paddings |
| 723 | updateAvailableFolderCellDimensions(res); |
| 724 | |
Thales Lima | ffc68b0 | 2023-01-09 16:20:23 +0000 | [diff] [blame] | 725 | mMinHotseatIconSpacePx = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space); |
| 726 | mMinHotseatQsbWidthPx = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width); |
| 727 | mMaxHotseatIconSpacePx = areNavButtonsInline |
Thales Lima | 6a59006 | 2022-11-22 15:52:49 +0000 | [diff] [blame] | 728 | ? res.getDimensionPixelSize(R.dimen.max_hotseat_icon_space) : Integer.MAX_VALUE; |
Thales Lima | 425f682 | 2022-05-10 13:44:58 -0300 | [diff] [blame] | 729 | // Hotseat and QSB width depends on updated cellSize and workspace padding |
Thales Lima | 6a59006 | 2022-11-22 15:52:49 +0000 | [diff] [blame] | 730 | recalculateHotseatWidthAndBorderSpace(); |
Alex Chau | 206ede9 | 2022-08-01 17:46:12 +0100 | [diff] [blame] | 731 | |
Jordan Silva | 3646a1b | 2023-08-02 13:52:52 +0100 | [diff] [blame] | 732 | if (mIsResponsiveGrid && isVerticalBarLayout()) { |
| 733 | hotseatBorderSpace = cellLayoutBorderSpacePx.y; |
| 734 | } |
| 735 | |
Alex Chau | 206ede9 | 2022-08-01 17:46:12 +0100 | [diff] [blame] | 736 | if (isTablet) { |
Andy Wickham | 99d7d4f | 2023-11-15 08:09:09 +0000 | [diff] [blame] | 737 | allAppsPadding.top = mInsets.top; |
| 738 | allAppsShiftRange = heightPx; |
Alex Chau | 206ede9 | 2022-08-01 17:46:12 +0100 | [diff] [blame] | 739 | } else { |
Thales Lima | b433c9c | 2023-10-30 12:24:05 +0000 | [diff] [blame] | 740 | allAppsPadding.top = 0; |
Alex Chau | 206ede9 | 2022-08-01 17:46:12 +0100 | [diff] [blame] | 741 | allAppsShiftRange = |
| 742 | res.getDimensionPixelSize(R.dimen.all_apps_starting_vertical_translate); |
| 743 | } |
Alex Chau | 3d2c062 | 2022-09-01 21:28:14 +0100 | [diff] [blame] | 744 | allAppsOpenDuration = res.getInteger(R.integer.config_allAppsOpenDuration); |
| 745 | allAppsCloseDuration = res.getInteger(R.integer.config_allAppsCloseDuration); |
Thales Lima | 425f682 | 2022-05-10 13:44:58 -0300 | [diff] [blame] | 746 | |
Alex Chau | a02eddc | 2021-04-29 00:36:06 +0100 | [diff] [blame] | 747 | flingToDeleteThresholdVelocity = res.getDimensionPixelSize( |
| 748 | R.dimen.drag_flingToDeleteMinVelocity); |
| 749 | |
Sihua Ma | e04aa20 | 2022-07-18 12:43:56 -0700 | [diff] [blame] | 750 | mViewScaleProvider = viewScaleProvider; |
| 751 | |
Jon Miranda | 2b25ded | 2023-02-02 14:48:45 -0800 | [diff] [blame] | 752 | dimensionOverrideProvider.accept(this); |
| 753 | |
Tony Wickham | 1237df0 | 2017-02-24 08:59:36 -0800 | [diff] [blame] | 754 | // This is done last, after iconSizePx is calculated above. |
Sunny Goyal | 799e120 | 2023-02-09 10:54:28 -0800 | [diff] [blame] | 755 | mDotRendererWorkSpace = createDotRenderer(context, iconSizePx, dotRendererCache); |
| 756 | mDotRendererAllApps = createDotRenderer(context, allAppsIconSizePx, dotRendererCache); |
Sunny Goyal | 65190ae | 2022-08-02 14:16:26 -0700 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | private static DotRenderer createDotRenderer( |
Sunny Goyal | 799e120 | 2023-02-09 10:54:28 -0800 | [diff] [blame] | 760 | @NonNull Context context, int size, @NonNull SparseArray<DotRenderer> cache) { |
Sunny Goyal | 65190ae | 2022-08-02 14:16:26 -0700 | [diff] [blame] | 761 | DotRenderer renderer = cache.get(size); |
| 762 | if (renderer == null) { |
Sunny Goyal | 799e120 | 2023-02-09 10:54:28 -0800 | [diff] [blame] | 763 | renderer = new DotRenderer(size, getShapePath(context, DEFAULT_DOT_SIZE), |
| 764 | DEFAULT_DOT_SIZE); |
Sunny Goyal | 65190ae | 2022-08-02 14:16:26 -0700 | [diff] [blame] | 765 | cache.put(size, renderer); |
| 766 | } |
| 767 | return renderer; |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 768 | } |
| 769 | |
Thales Lima | 425f682 | 2022-05-10 13:44:58 -0300 | [diff] [blame] | 770 | /** |
Fengjiang Li | 6c59082 | 2023-09-25 15:04:57 -0700 | [diff] [blame] | 771 | * Return maximum of all apps row count displayed on screen. Note that 1) Partially displayed |
| 772 | * row is counted as 1 row, and 2) we don't exclude the space of floating search bar. This |
| 773 | * method is used for calculating number of {@link BubbleTextView} we need to pre-inflate. Thus |
| 774 | * reasonable over estimation is fine. |
| 775 | */ |
| 776 | public int getMaxAllAppsRowCount() { |
Thales Lima | b433c9c | 2023-10-30 12:24:05 +0000 | [diff] [blame] | 777 | return (int) (Math.ceil((availableHeightPx - allAppsPadding.top) |
Fengjiang Li | 6c59082 | 2023-09-25 15:04:57 -0700 | [diff] [blame] | 778 | / (float) allAppsCellHeightPx)); |
| 779 | } |
| 780 | |
| 781 | /** |
Thales Lima | 425f682 | 2022-05-10 13:44:58 -0300 | [diff] [blame] | 782 | * QSB width is always calculated because when in 3 button nav the width doesn't follow the |
| 783 | * width of the hotseat. |
| 784 | */ |
Thales Lima | 9938c2f | 2022-07-25 14:38:16 +0100 | [diff] [blame] | 785 | private int calculateQsbWidth(int hotseatBorderSpace) { |
fbaron | e69b6f4 | 2023-12-18 13:20:34 -0800 | [diff] [blame] | 786 | int iconExtraSpacePx = iconSizePx - getIconVisibleSizePx(iconSizePx); |
Thales Lima | 425f682 | 2022-05-10 13:44:58 -0300 | [diff] [blame] | 787 | if (isQsbInline) { |
Alex Chau | 906d882 | 2022-05-23 10:42:25 +0100 | [diff] [blame] | 788 | int columns = getPanelCount() * inv.numColumns; |
Thales Lima | 425f682 | 2022-05-10 13:44:58 -0300 | [diff] [blame] | 789 | return getIconToIconWidthForColumns(columns) |
| 790 | - iconSizePx * numShownHotseatIcons |
fbaron | e69b6f4 | 2023-12-18 13:20:34 -0800 | [diff] [blame] | 791 | - hotseatBorderSpace * numShownHotseatIcons |
| 792 | - iconExtraSpacePx; |
Thales Lima | 425f682 | 2022-05-10 13:44:58 -0300 | [diff] [blame] | 793 | } else { |
| 794 | int columns = inv.hotseatColumnSpan[mTypeIndex]; |
fbaron | e69b6f4 | 2023-12-18 13:20:34 -0800 | [diff] [blame] | 795 | return getIconToIconWidthForColumns(columns) - iconExtraSpacePx; |
Thales Lima | 425f682 | 2022-05-10 13:44:58 -0300 | [diff] [blame] | 796 | } |
| 797 | } |
Thales Lima | 2903a62 | 2022-03-17 13:52:19 +0000 | [diff] [blame] | 798 | |
Thales Lima | 425f682 | 2022-05-10 13:44:58 -0300 | [diff] [blame] | 799 | private int getIconToIconWidthForColumns(int columns) { |
| 800 | return columns * getCellSize().x |
| 801 | + (columns - 1) * cellLayoutBorderSpacePx.x |
Thales Lima | 1e8b45f | 2022-08-25 11:50:59 -0400 | [diff] [blame] | 802 | - getCellHorizontalSpace(); |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 803 | } |
| 804 | |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 805 | private int getHorizontalMarginPx(InvariantDeviceProfile idp, Resources res) { |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 806 | if (mIsResponsiveGrid) { |
Jordan Silva | 8f7986a | 2023-11-08 12:11:25 +0000 | [diff] [blame] | 807 | return mResponsiveWorkspaceWidthSpec.getStartPaddingPx(); |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 808 | } |
| 809 | |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 810 | if (isVerticalBarLayout()) { |
| 811 | return 0; |
| 812 | } |
| 813 | |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 814 | return mIsScalableGrid |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 815 | ? pxFromDp(idp.horizontalMargin[mTypeIndex], mMetrics) |
| 816 | : res.getDimensionPixelSize(R.dimen.dynamic_grid_left_right_margin); |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 817 | } |
| 818 | |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 819 | private void calculateAndSetWorkspaceVerticalPadding(Context context, |
| 820 | InvariantDeviceProfile inv, |
| 821 | int extraSpace) { |
| 822 | if (mIsResponsiveGrid) { |
Jordan Silva | 8f7986a | 2023-11-08 12:11:25 +0000 | [diff] [blame] | 823 | workspaceTopPadding = mResponsiveWorkspaceHeightSpec.getStartPaddingPx(); |
| 824 | workspaceBottomPadding = mResponsiveWorkspaceHeightSpec.getEndPaddingPx(); |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 825 | } else if (mIsScalableGrid && inv.devicePaddingId != INVALID_RESOURCE_HANDLE) { |
| 826 | // Paddings were created assuming no scaling, so we first unscale the extra space. |
| 827 | int unscaledExtraSpace = (int) (extraSpace / cellScaleToFit); |
| 828 | DevicePaddings devicePaddings = new DevicePaddings(context, inv.devicePaddingId); |
| 829 | DevicePadding padding = devicePaddings.getDevicePadding(unscaledExtraSpace); |
| 830 | maxEmptySpace = padding.getMaxEmptySpacePx(); |
| 831 | |
| 832 | int paddingWorkspaceTop = padding.getWorkspaceTopPadding(unscaledExtraSpace); |
| 833 | int paddingWorkspaceBottom = padding.getWorkspaceBottomPadding(unscaledExtraSpace); |
| 834 | |
| 835 | workspaceTopPadding = Math.round(paddingWorkspaceTop * cellScaleToFit); |
| 836 | workspaceBottomPadding = Math.round(paddingWorkspaceBottom * cellScaleToFit); |
| 837 | } |
| 838 | } |
| 839 | |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 840 | /** Updates hotseatCellHeightPx and hotseatBarSizePx */ |
| 841 | private void updateHotseatSizes(int hotseatIconSizePx) { |
Jon Miranda | 92c1b5d | 2021-07-20 13:57:16 -0700 | [diff] [blame] | 842 | // Ensure there is enough space for folder icons, which have a slightly larger radius. |
Jordan Silva | 3646a1b | 2023-08-02 13:52:52 +0100 | [diff] [blame] | 843 | hotseatCellHeightPx = getIconSizeWithOverlap(hotseatIconSizePx); |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 844 | |
Jon Miranda | 0d28485 | 2021-06-22 14:50:55 -0700 | [diff] [blame] | 845 | if (isVerticalBarLayout()) { |
Thales Lima | 8e11d53 | 2023-08-31 13:40:26 +0000 | [diff] [blame] | 846 | hotseatBarSizePx = hotseatIconSizePx + mHotseatBarEdgePaddingPx |
| 847 | + mHotseatBarWorkspaceSpacePx; |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 848 | } else if (isQsbInline) { |
| 849 | hotseatBarSizePx = Math.max(hotseatIconSizePx, hotseatQsbVisualHeight) |
| 850 | + hotseatBarBottomSpacePx; |
Jon Miranda | 0d28485 | 2021-06-22 14:50:55 -0700 | [diff] [blame] | 851 | } else { |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 852 | hotseatBarSizePx = hotseatIconSizePx |
| 853 | + hotseatQsbSpace |
| 854 | + hotseatQsbVisualHeight |
| 855 | + hotseatBarBottomSpacePx; |
Jon Miranda | 0d28485 | 2021-06-22 14:50:55 -0700 | [diff] [blame] | 856 | } |
| 857 | } |
| 858 | |
Thales Lima | 6a59006 | 2022-11-22 15:52:49 +0000 | [diff] [blame] | 859 | /** |
| 860 | * Calculates the width of the hotseat, changing spaces between the icons and removing icons if |
| 861 | * necessary. |
| 862 | */ |
| 863 | public void recalculateHotseatWidthAndBorderSpace() { |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 864 | if (!mIsScalableGrid) return; |
Thales Lima | 6a59006 | 2022-11-22 15:52:49 +0000 | [diff] [blame] | 865 | |
| 866 | int columns = inv.hotseatColumnSpan[mTypeIndex]; |
| 867 | float hotseatWidthPx = getIconToIconWidthForColumns(columns); |
| 868 | hotseatBorderSpace = calculateHotseatBorderSpace(hotseatWidthPx, /* numExtraBorder= */ 0); |
Thales Lima | 9938c2f | 2022-07-25 14:38:16 +0100 | [diff] [blame] | 869 | hotseatQsbWidth = calculateQsbWidth(hotseatBorderSpace); |
Thales Lima | 6a59006 | 2022-11-22 15:52:49 +0000 | [diff] [blame] | 870 | // Spaces should be correct when the nav buttons are not inline |
Thales Lima | 9938c2f | 2022-07-25 14:38:16 +0100 | [diff] [blame] | 871 | if (!areNavButtonsInline) { |
| 872 | return; |
| 873 | } |
| 874 | |
Thales Lima | 6a59006 | 2022-11-22 15:52:49 +0000 | [diff] [blame] | 875 | // The side space with inline buttons should be what is defined in InvariantDeviceProfile |
Jon Miranda | e17a949 | 2023-03-08 16:42:20 -0800 | [diff] [blame] | 876 | int sideSpacePx = inlineNavButtonsEndSpacingPx; |
Thales Lima | ffc68b0 | 2023-01-09 16:20:23 +0000 | [diff] [blame] | 877 | int maxHotseatWidthPx = availableWidthPx - sideSpacePx - hotseatBarEndOffset; |
| 878 | int maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0); |
| 879 | hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx, |
Thales Lima | 6a59006 | 2022-11-22 15:52:49 +0000 | [diff] [blame] | 880 | (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1); |
Thales Lima | 9938c2f | 2022-07-25 14:38:16 +0100 | [diff] [blame] | 881 | |
Thales Lima | ffc68b0 | 2023-01-09 16:20:23 +0000 | [diff] [blame] | 882 | if (hotseatBorderSpace >= mMinHotseatIconSpacePx) { |
Thales Lima | 9938c2f | 2022-07-25 14:38:16 +0100 | [diff] [blame] | 883 | return; |
| 884 | } |
| 885 | |
| 886 | // Border space can't be less than the minimum |
Thales Lima | ffc68b0 | 2023-01-09 16:20:23 +0000 | [diff] [blame] | 887 | hotseatBorderSpace = mMinHotseatIconSpacePx; |
Thales Lima | 6a59006 | 2022-11-22 15:52:49 +0000 | [diff] [blame] | 888 | int requiredWidth = getHotseatRequiredWidth(); |
Thales Lima | 9938c2f | 2022-07-25 14:38:16 +0100 | [diff] [blame] | 889 | |
| 890 | // If there is an inline qsb, change its size |
| 891 | if (isQsbInline) { |
Thales Lima | ffc68b0 | 2023-01-09 16:20:23 +0000 | [diff] [blame] | 892 | hotseatQsbWidth -= requiredWidth - maxHotseatWidthPx; |
| 893 | if (hotseatQsbWidth >= mMinHotseatQsbWidthPx) { |
Thales Lima | 9938c2f | 2022-07-25 14:38:16 +0100 | [diff] [blame] | 894 | return; |
| 895 | } |
| 896 | |
| 897 | // QSB can't be less than the minimum |
Thales Lima | ffc68b0 | 2023-01-09 16:20:23 +0000 | [diff] [blame] | 898 | hotseatQsbWidth = mMinHotseatQsbWidthPx; |
Thales Lima | 9938c2f | 2022-07-25 14:38:16 +0100 | [diff] [blame] | 899 | } |
| 900 | |
Thales Lima | ffc68b0 | 2023-01-09 16:20:23 +0000 | [diff] [blame] | 901 | maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0); |
Thales Lima | 6a59006 | 2022-11-22 15:52:49 +0000 | [diff] [blame] | 902 | |
Thales Lima | 9938c2f | 2022-07-25 14:38:16 +0100 | [diff] [blame] | 903 | // If it still doesn't fit, start removing icons |
| 904 | do { |
| 905 | numShownHotseatIcons--; |
Thales Lima | ffc68b0 | 2023-01-09 16:20:23 +0000 | [diff] [blame] | 906 | hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx, |
Thales Lima | 6a59006 | 2022-11-22 15:52:49 +0000 | [diff] [blame] | 907 | (isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1); |
Thales Lima | ffc68b0 | 2023-01-09 16:20:23 +0000 | [diff] [blame] | 908 | } while (hotseatBorderSpace < mMinHotseatIconSpacePx && numShownHotseatIcons > 1); |
Thales Lima | 9938c2f | 2022-07-25 14:38:16 +0100 | [diff] [blame] | 909 | } |
| 910 | |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 911 | private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp) { |
Thales Lima | 080d890 | 2022-03-28 15:30:29 +0100 | [diff] [blame] | 912 | return getCellLayoutBorderSpace(idp, 1f); |
Thales Lima | 080d890 | 2022-03-28 15:30:29 +0100 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | private Point getCellLayoutBorderSpace(InvariantDeviceProfile idp, float scale) { |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 916 | int horizontalSpacePx = 0; |
| 917 | int verticalSpacePx = 0; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 918 | |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 919 | if (mIsResponsiveGrid) { |
Jordan Silva | 8f7986a | 2023-11-08 12:11:25 +0000 | [diff] [blame] | 920 | horizontalSpacePx = mResponsiveWorkspaceWidthSpec.getGutterPx(); |
| 921 | verticalSpacePx = mResponsiveWorkspaceHeightSpec.getGutterPx(); |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 922 | } else if (mIsScalableGrid) { |
| 923 | horizontalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].x, mMetrics, scale); |
| 924 | verticalSpacePx = pxFromDp(idp.borderSpaces[mTypeIndex].y, mMetrics, scale); |
| 925 | } |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 926 | |
| 927 | return new Point(horizontalSpacePx, verticalSpacePx); |
| 928 | } |
| 929 | |
Sunny Goyal | 69a8eec | 2021-07-22 10:02:50 -0700 | [diff] [blame] | 930 | public Info getDisplayInfo() { |
| 931 | return mInfo; |
| 932 | } |
| 933 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 934 | public Builder toBuilder(Context context) { |
Sunny Goyal | 187b16c | 2022-03-01 16:53:23 -0800 | [diff] [blame] | 935 | WindowBounds bounds = new WindowBounds( |
| 936 | widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 937 | bounds.bounds.offsetTo(windowX, windowY); |
Alex Chau | e022755 | 2022-04-06 19:44:43 +0100 | [diff] [blame] | 938 | bounds.insets.set(mInsets); |
Sunny Goyal | 65190ae | 2022-08-02 14:16:26 -0700 | [diff] [blame] | 939 | |
| 940 | SparseArray<DotRenderer> dotRendererCache = new SparseArray<>(); |
| 941 | dotRendererCache.put(iconSizePx, mDotRendererWorkSpace); |
| 942 | dotRendererCache.put(allAppsIconSizePx, mDotRendererAllApps); |
| 943 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 944 | return new Builder(context, inv, mInfo) |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 945 | .setWindowBounds(bounds) |
Alex Chau | ab800f7 | 2022-12-13 17:46:06 +0000 | [diff] [blame] | 946 | .setIsMultiDisplay(isMultiDisplay) |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 947 | .setMultiWindowMode(isMultiWindowMode) |
Sunny Goyal | 65190ae | 2022-08-02 14:16:26 -0700 | [diff] [blame] | 948 | .setDotRendererCache(dotRendererCache) |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 949 | .setGestureMode(isGestureMode); |
Sunny Goyal | 1a52ef5 | 2018-01-11 10:15:03 -0800 | [diff] [blame] | 950 | } |
| 951 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 952 | public DeviceProfile copy(Context context) { |
| 953 | return toBuilder(context).build(); |
| 954 | } |
| 955 | |
| 956 | /** |
| 957 | * TODO: Move this to the builder as part of setMultiWindowMode |
| 958 | */ |
Sunny Goyal | b46703d | 2020-05-27 17:52:03 -0700 | [diff] [blame] | 959 | public DeviceProfile getMultiWindowProfile(Context context, WindowBounds windowBounds) { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 960 | DeviceProfile profile = toBuilder(context) |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 961 | .setWindowBounds(windowBounds) |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 962 | .setMultiWindowMode(true) |
| 963 | .build(); |
Jon Miranda | 93e1f04 | 2016-11-11 14:13:04 -0800 | [diff] [blame] | 964 | |
Jon Miranda | 7ae64ff | 2016-11-21 16:18:46 -0800 | [diff] [blame] | 965 | // We use these scales to measure and layout the widgets using their full invariant profile |
| 966 | // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans. |
| 967 | float appWidgetScaleX = (float) profile.getCellSize().x / getCellSize().x; |
| 968 | float appWidgetScaleY = (float) profile.getCellSize().y / getCellSize().y; |
Sihua Ma | e04aa20 | 2022-07-18 12:43:56 -0700 | [diff] [blame] | 969 | if (appWidgetScaleX != 1 || appWidgetScaleY != 1) { |
| 970 | final PointF p = new PointF(appWidgetScaleX, appWidgetScaleY); |
| 971 | profile = profile.toBuilder(context) |
| 972 | .setViewScaleProvider(i -> p) |
| 973 | .build(); |
| 974 | } |
| 975 | |
| 976 | profile.hideWorkspaceLabelsIfNotEnoughSpace(); |
Jon Miranda | 7ae64ff | 2016-11-21 16:18:46 -0800 | [diff] [blame] | 977 | |
Jon Miranda | 93e1f04 | 2016-11-11 14:13:04 -0800 | [diff] [blame] | 978 | return profile; |
Jon Miranda | cc42c5b | 2016-10-27 17:15:27 -0700 | [diff] [blame] | 979 | } |
| 980 | |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 981 | /** |
Jon Miranda | 941375e | 2021-03-31 13:10:45 -0400 | [diff] [blame] | 982 | * Checks if there is enough space for labels on the workspace. |
| 983 | * If there is not, labels on the Workspace are hidden. |
Jon Miranda | 1091e53 | 2017-07-21 13:31:50 -0700 | [diff] [blame] | 984 | * It is important to call this method after the All Apps variables have been set. |
| 985 | */ |
Jon Miranda | 941375e | 2021-03-31 13:10:45 -0400 | [diff] [blame] | 986 | private void hideWorkspaceLabelsIfNotEnoughSpace() { |
| 987 | float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx); |
| 988 | float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx |
| 989 | - iconTextHeight; |
| 990 | |
| 991 | // We want enough space so that the text is closer to its corresponding icon. |
| 992 | if (workspaceCellPaddingY < iconTextHeight) { |
| 993 | iconTextSizePx = 0; |
| 994 | iconDrawablePaddingPx = 0; |
Jordan Silva | 3646a1b | 2023-08-02 13:52:52 +0100 | [diff] [blame] | 995 | cellHeightPx = getIconSizeWithOverlap(iconSizePx); |
Jon Miranda | 941375e | 2021-03-31 13:10:45 -0400 | [diff] [blame] | 996 | autoResizeAllAppsCells(); |
| 997 | } |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 998 | } |
Jon Miranda | 1091e53 | 2017-07-21 13:31:50 -0700 | [diff] [blame] | 999 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 1000 | /** |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 1001 | * Returns the amount of extra (or unused) vertical space. |
| 1002 | */ |
| 1003 | private int updateAvailableDimensions(Resources res) { |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 1004 | iconCenterVertically = mIsScalableGrid || mIsResponsiveGrid; |
| 1005 | |
| 1006 | if (mIsResponsiveGrid) { |
Jordan Silva | 15cacd5 | 2023-11-28 14:32:05 +0000 | [diff] [blame] | 1007 | iconSizePx = mResponsiveWorkspaceCellSpec.getIconSize(); |
| 1008 | iconTextSizePx = mResponsiveWorkspaceCellSpec.getIconTextSize(); |
| 1009 | mIconDrawablePaddingOriginalPx = mResponsiveWorkspaceCellSpec.getIconDrawablePadding(); |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 1010 | updateIconSize(1f, res); |
| 1011 | updateWorkspacePadding(); |
| 1012 | return 0; |
| 1013 | } |
| 1014 | |
Alex Chau | a68164d | 2022-12-15 16:16:03 +0000 | [diff] [blame] | 1015 | float invIconSizeDp = inv.iconSize[mTypeIndex]; |
| 1016 | float invIconTextSizeSp = inv.iconTextSize[mTypeIndex]; |
| 1017 | iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics)); |
| 1018 | iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics); |
| 1019 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 1020 | updateIconSize(1f, res); |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 1021 | updateWorkspacePadding(); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 1022 | |
| 1023 | // Check to see if the icons fit within the available height. |
Pat Manning | a2e1499 | 2022-04-22 11:29:17 +0100 | [diff] [blame] | 1024 | float usedHeight = getCellLayoutHeightSpecification(); |
Pat Manning | 25d5334 | 2022-05-10 09:58:49 +0000 | [diff] [blame] | 1025 | final int maxHeight = getCellLayoutHeight(); |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 1026 | float extraHeight = Math.max(0, maxHeight - usedHeight); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 1027 | float scaleY = maxHeight / usedHeight; |
| 1028 | boolean shouldScale = scaleY < 1f; |
| 1029 | |
| 1030 | float scaleX = 1f; |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 1031 | if (mIsScalableGrid) { |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 1032 | // We scale to fit the cellWidth and cellHeight in the available space. |
| 1033 | // The benefit of scalable grids is that we can get consistent aspect ratios between |
| 1034 | // devices. |
Pat Manning | a2e1499 | 2022-04-22 11:29:17 +0100 | [diff] [blame] | 1035 | float usedWidth = |
| 1036 | getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 1037 | // We do not subtract padding here, as we also scale the workspace padding if needed. |
| 1038 | scaleX = availableWidthPx / usedWidth; |
| 1039 | shouldScale = true; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 1040 | } |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 1041 | |
| 1042 | if (shouldScale) { |
| 1043 | float scale = Math.min(scaleX, scaleY); |
| 1044 | updateIconSize(scale, res); |
Pat Manning | a2e1499 | 2022-04-22 11:29:17 +0100 | [diff] [blame] | 1045 | extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification()); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 1046 | } |
| 1047 | |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 1048 | return Math.round(extraHeight); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
Pat Manning | a2e1499 | 2022-04-22 11:29:17 +0100 | [diff] [blame] | 1051 | private int getCellLayoutHeightSpecification() { |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 1052 | return (cellHeightPx * inv.numRows) + (cellLayoutBorderSpacePx.y * (inv.numRows - 1)) |
| 1053 | + cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom; |
| 1054 | } |
| 1055 | |
Pat Manning | a2e1499 | 2022-04-22 11:29:17 +0100 | [diff] [blame] | 1056 | private int getCellLayoutWidthSpecification() { |
Pat Manning | 25d5334 | 2022-05-10 09:58:49 +0000 | [diff] [blame] | 1057 | int numColumns = getPanelCount() * inv.numColumns; |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 1058 | return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1)) |
| 1059 | + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 1060 | } |
| 1061 | |
Jordan Silva | 376036a | 2023-11-08 15:56:40 +0000 | [diff] [blame] | 1062 | private int getNormalizedIconDrawablePadding(int iconSizePx, int iconDrawablePadding) { |
fbaron | e69b6f4 | 2023-12-18 13:20:34 -0800 | [diff] [blame] | 1063 | return Math.max(0, iconDrawablePadding |
| 1064 | - ((iconSizePx - getIconVisibleSizePx(iconSizePx)) / 2)); |
Jordan Silva | 376036a | 2023-11-08 15:56:40 +0000 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | private int getNormalizedIconDrawablePadding() { |
| 1068 | return getNormalizedIconDrawablePadding(iconSizePx, mIconDrawablePaddingOriginalPx); |
Thales Lima | 93ee8fc | 2023-06-05 17:07:11 +0100 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | private int getNormalizedFolderChildDrawablePaddingPx(int textHeight) { |
| 1072 | // TODO(b/235886078): workaround needed because of this bug |
| 1073 | // Icons are 10% larger on XML than their visual size, |
| 1074 | // so remove that extra space to get labels closer to the correct padding |
| 1075 | int drawablePadding = (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3; |
| 1076 | |
fbaron | e69b6f4 | 2023-12-18 13:20:34 -0800 | [diff] [blame] | 1077 | int iconSizeDiff = folderChildIconSizePx - getIconVisibleSizePx(folderChildIconSizePx); |
Thales Lima | 93ee8fc | 2023-06-05 17:07:11 +0100 | [diff] [blame] | 1078 | return Math.max(0, drawablePadding - iconSizeDiff / 2); |
| 1079 | } |
| 1080 | |
Jordan Silva | 3646a1b | 2023-08-02 13:52:52 +0100 | [diff] [blame] | 1081 | private int getIconSizeWithOverlap(int iconSize) { |
| 1082 | return (int) Math.ceil(iconSize * ICON_OVERLAP_FACTOR); |
| 1083 | } |
| 1084 | |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 1085 | /** |
| 1086 | * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx, |
| 1087 | * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants, |
| 1088 | * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx. |
| 1089 | */ |
Tony Wickham | 7ba547c | 2021-02-02 17:12:08 -0800 | [diff] [blame] | 1090 | public void updateIconSize(float scale, Resources res) { |
Jon Miranda | ab3c681 | 2021-06-28 15:42:28 -0700 | [diff] [blame] | 1091 | // Icon scale should never exceed 1, otherwise pixellation may occur. |
| 1092 | iconScale = Math.min(1f, scale); |
| 1093 | cellScaleToFit = scale; |
| 1094 | |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 1095 | // Workspace |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 1096 | final boolean isVerticalLayout = isVerticalBarLayout(); |
Thales Lima | 080d890 | 2022-03-28 15:30:29 +0100 | [diff] [blame] | 1097 | cellLayoutBorderSpacePx = getCellLayoutBorderSpace(inv, scale); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 1098 | |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 1099 | if (mIsResponsiveGrid) { |
Jordan Silva | 8f7986a | 2023-11-08 12:11:25 +0000 | [diff] [blame] | 1100 | cellWidthPx = mResponsiveWorkspaceWidthSpec.getCellSizePx(); |
| 1101 | cellHeightPx = mResponsiveWorkspaceHeightSpec.getCellSizePx(); |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 1102 | |
Thales Lima | 2759aa3 | 2023-06-05 16:25:45 +0100 | [diff] [blame] | 1103 | if (cellWidthPx < iconSizePx) { |
| 1104 | // get a smaller icon size |
| 1105 | iconSizePx = mIconSizeSteps.getIconSmallerThan(cellWidthPx); |
Thales Lima | 2759aa3 | 2023-06-05 16:25:45 +0100 | [diff] [blame] | 1106 | } |
| 1107 | |
Jordan Silva | dd61268 | 2024-01-08 11:38:13 -0300 | [diff] [blame] | 1108 | if (isVerticalLayout) { |
| 1109 | iconDrawablePaddingPx = 0; |
| 1110 | iconTextSizePx = 0; |
| 1111 | } else { |
| 1112 | iconDrawablePaddingPx = getNormalizedIconDrawablePadding(); |
| 1113 | } |
Thales Lima | 93ee8fc | 2023-06-05 17:07:11 +0100 | [diff] [blame] | 1114 | |
Thales Lima | 24ceca6 | 2023-09-25 16:21:17 -0700 | [diff] [blame] | 1115 | CellContentDimensions cellContentDimensions = new CellContentDimensions(iconSizePx, |
| 1116 | iconDrawablePaddingPx, |
| 1117 | iconTextSizePx); |
Jordan Silva | dd61268 | 2024-01-08 11:38:13 -0300 | [diff] [blame] | 1118 | int cellContentHeight = cellContentDimensions.resizeToFitCellHeight(cellHeightPx, |
| 1119 | mIconSizeSteps); |
Thales Lima | 24ceca6 | 2023-09-25 16:21:17 -0700 | [diff] [blame] | 1120 | iconSizePx = cellContentDimensions.getIconSizePx(); |
| 1121 | iconDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx(); |
| 1122 | iconTextSizePx = cellContentDimensions.getIconTextSizePx(); |
Thales Lima | 2759aa3 | 2023-06-05 16:25:45 +0100 | [diff] [blame] | 1123 | |
Jordan Silva | dd61268 | 2024-01-08 11:38:13 -0300 | [diff] [blame] | 1124 | if (isVerticalLayout) { |
| 1125 | cellYPaddingPx = Math.max(0, getCellSize().y - getIconSizeWithOverlap(iconSizePx)) |
| 1126 | / 2; |
| 1127 | } else { |
| 1128 | cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2; |
| 1129 | } |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 1130 | } else if (mIsScalableGrid) { |
Thales Lima | 93ee8fc | 2023-06-05 17:07:11 +0100 | [diff] [blame] | 1131 | iconDrawablePaddingPx = (int) (getNormalizedIconDrawablePadding() * iconScale); |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1132 | cellWidthPx = pxFromDp(inv.minCellSize[mTypeIndex].x, mMetrics, scale); |
| 1133 | cellHeightPx = pxFromDp(inv.minCellSize[mTypeIndex].y, mMetrics, scale); |
Alex Chau | be75313 | 2022-12-09 16:46:54 +0000 | [diff] [blame] | 1134 | |
| 1135 | if (cellWidthPx < iconSizePx) { |
| 1136 | // If cellWidth no longer fit iconSize, reduce borderSpace to make cellWidth bigger. |
| 1137 | int numColumns = getPanelCount() * inv.numColumns; |
| 1138 | int numBorders = numColumns - 1; |
| 1139 | int extraWidthRequired = (iconSizePx - cellWidthPx) * numColumns; |
| 1140 | if (cellLayoutBorderSpacePx.x * numBorders >= extraWidthRequired) { |
| 1141 | cellWidthPx = iconSizePx; |
| 1142 | cellLayoutBorderSpacePx.x -= extraWidthRequired / numBorders; |
| 1143 | } else { |
| 1144 | // If it still doesn't fit, set borderSpace to 0 and distribute the space for |
| 1145 | // cellWidth, and reduce iconSize. |
| 1146 | cellWidthPx = (cellWidthPx * numColumns |
| 1147 | + cellLayoutBorderSpacePx.x * numBorders) / numColumns; |
| 1148 | iconSizePx = Math.min(iconSizePx, cellWidthPx); |
| 1149 | cellLayoutBorderSpacePx.x = 0; |
| 1150 | } |
| 1151 | } |
| 1152 | |
Thales Lima | 93ee8fc | 2023-06-05 17:07:11 +0100 | [diff] [blame] | 1153 | int cellTextAndPaddingHeight = |
| 1154 | iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx); |
Alex Chau | be75313 | 2022-12-09 16:46:54 +0000 | [diff] [blame] | 1155 | int cellContentHeight = iconSizePx + cellTextAndPaddingHeight; |
| 1156 | if (cellHeightPx < cellContentHeight) { |
| 1157 | // If cellHeight no longer fit iconSize, reduce borderSpace to make cellHeight |
| 1158 | // bigger. |
| 1159 | int numBorders = inv.numRows - 1; |
| 1160 | int extraHeightRequired = (cellContentHeight - cellHeightPx) * inv.numRows; |
| 1161 | if (cellLayoutBorderSpacePx.y * numBorders >= extraHeightRequired) { |
| 1162 | cellHeightPx = cellContentHeight; |
| 1163 | cellLayoutBorderSpacePx.y -= extraHeightRequired / numBorders; |
| 1164 | } else { |
Alex Chau | 06f36e8 | 2023-01-06 10:50:54 +0000 | [diff] [blame] | 1165 | // If it still doesn't fit, set borderSpace to 0 to recover space. |
Alex Chau | be75313 | 2022-12-09 16:46:54 +0000 | [diff] [blame] | 1166 | cellHeightPx = (cellHeightPx * inv.numRows |
| 1167 | + cellLayoutBorderSpacePx.y * numBorders) / inv.numRows; |
Alex Chau | be75313 | 2022-12-09 16:46:54 +0000 | [diff] [blame] | 1168 | cellLayoutBorderSpacePx.y = 0; |
Alex Chau | 06f36e8 | 2023-01-06 10:50:54 +0000 | [diff] [blame] | 1169 | // Reduce iconDrawablePaddingPx to make cellContentHeight smaller. |
| 1170 | int cellContentWithoutPadding = cellContentHeight - iconDrawablePaddingPx; |
| 1171 | if (cellContentWithoutPadding <= cellHeightPx) { |
| 1172 | iconDrawablePaddingPx = cellContentHeight - cellHeightPx; |
| 1173 | } else { |
| 1174 | // If it still doesn't fit, set iconDrawablePaddingPx to 0 to recover space, |
| 1175 | // then proportional reduce iconSizePx and iconTextSizePx to fit. |
| 1176 | iconDrawablePaddingPx = 0; |
| 1177 | float ratio = cellHeightPx / (float) cellContentWithoutPadding; |
| 1178 | iconSizePx = (int) (iconSizePx * ratio); |
| 1179 | iconTextSizePx = (int) (iconTextSizePx * ratio); |
| 1180 | } |
| 1181 | cellTextAndPaddingHeight = |
| 1182 | iconDrawablePaddingPx + Utilities.calculateTextHeight(iconTextSizePx); |
Alex Chau | be75313 | 2022-12-09 16:46:54 +0000 | [diff] [blame] | 1183 | } |
| 1184 | cellContentHeight = iconSizePx + cellTextAndPaddingHeight; |
| 1185 | } |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 1186 | cellYPaddingPx = Math.max(0, cellHeightPx - cellContentHeight) / 2; |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 1187 | desiredWorkspaceHorizontalMarginPx = |
| 1188 | (int) (desiredWorkspaceHorizontalMarginOriginalPx * scale); |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 1189 | } else { |
Thales Lima | 93ee8fc | 2023-06-05 17:07:11 +0100 | [diff] [blame] | 1190 | iconDrawablePaddingPx = (int) (getNormalizedIconDrawablePadding() * iconScale); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 1191 | cellWidthPx = iconSizePx + iconDrawablePaddingPx; |
Jordan Silva | 3646a1b | 2023-08-02 13:52:52 +0100 | [diff] [blame] | 1192 | cellHeightPx = getIconSizeWithOverlap(iconSizePx) |
Jon Miranda | 92c1b5d | 2021-07-20 13:57:16 -0700 | [diff] [blame] | 1193 | + iconDrawablePaddingPx |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 1194 | + Utilities.calculateTextHeight(iconTextSizePx); |
| 1195 | int cellPaddingY = (getCellSize().y - cellHeightPx) / 2; |
| 1196 | if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout |
| 1197 | && !isMultiWindowMode) { |
| 1198 | // Ensures that the label is closer to its corresponding icon. This is not an issue |
| 1199 | // with vertical bar layout or multi-window mode since the issue is handled |
| 1200 | // separately with their calls to {@link #adjustToHideWorkspaceLabels}. |
| 1201 | cellHeightPx -= (iconDrawablePaddingPx - cellPaddingY); |
| 1202 | iconDrawablePaddingPx = cellPaddingY; |
| 1203 | } |
Jon Miranda | 846455e | 2017-10-02 14:58:52 -0700 | [diff] [blame] | 1204 | } |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 1205 | |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 1206 | // All apps |
Thales Lima | abfe364 | 2023-05-24 18:08:53 +0100 | [diff] [blame] | 1207 | if (mIsResponsiveGrid) { |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 1208 | updateAllAppsWithResponsiveMeasures(); |
Thales Lima | abfe364 | 2023-05-24 18:08:53 +0100 | [diff] [blame] | 1209 | } else { |
| 1210 | updateAllAppsIconSize(scale, res); |
| 1211 | } |
| 1212 | updateAllAppsContainerWidth(); |
Jordan Silva | dd61268 | 2024-01-08 11:38:13 -0300 | [diff] [blame] | 1213 | if (isVerticalLayout && !mIsResponsiveGrid) { |
Thales Lima | abfe364 | 2023-05-24 18:08:53 +0100 | [diff] [blame] | 1214 | hideWorkspaceLabelsIfNotEnoughSpace(); |
| 1215 | } |
Brandon Dayauon | 3cdb32c | 2023-08-22 21:26:37 -0700 | [diff] [blame] | 1216 | if (FeatureFlags.enableTwolineAllapps()) { |
| 1217 | // Add extra textHeight to the existing allAppsCellHeight. |
| 1218 | allAppsCellHeightPx += Utilities.calculateTextHeight(allAppsIconTextSizePx); |
| 1219 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 1220 | |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 1221 | updateHotseatSizes(iconSizePx); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 1222 | |
Sunny Goyal | baec6ff | 2016-09-14 11:26:21 -0700 | [diff] [blame] | 1223 | // Folder icon |
Jon Miranda | 591e360 | 2018-03-28 11:37:00 -0700 | [diff] [blame] | 1224 | folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx); |
| 1225 | folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2; |
Sunny Goyal | 6c304b1 | 2023-04-10 12:03:04 -0700 | [diff] [blame] | 1226 | |
| 1227 | // Update widget padding: |
| 1228 | float minSpacing = pxFromDp(MIN_WIDGET_PADDING_DP, mMetrics); |
| 1229 | if (cellLayoutBorderSpacePx.x < minSpacing |
| 1230 | || cellLayoutBorderSpacePx.y < minSpacing) { |
| 1231 | widgetPadding.left = widgetPadding.right = |
| 1232 | Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.x)); |
| 1233 | widgetPadding.top = widgetPadding.bottom = |
| 1234 | Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.y)); |
| 1235 | } else { |
| 1236 | widgetPadding.setEmpty(); |
| 1237 | } |
Winson Chung | 0f78572 | 2015-04-08 10:27:49 -0700 | [diff] [blame] | 1238 | } |
| 1239 | |
Thales Lima | 425f682 | 2022-05-10 13:44:58 -0300 | [diff] [blame] | 1240 | /** |
Thales Lima | 6a59006 | 2022-11-22 15:52:49 +0000 | [diff] [blame] | 1241 | * This method calculates the space between the icons to achieve a certain width. |
Thales Lima | 425f682 | 2022-05-10 13:44:58 -0300 | [diff] [blame] | 1242 | */ |
Thales Lima | 6a59006 | 2022-11-22 15:52:49 +0000 | [diff] [blame] | 1243 | private int calculateHotseatBorderSpace(float hotseatWidthPx, int numExtraBorder) { |
Jordan Silva | d922718 | 2023-08-17 15:53:59 +0100 | [diff] [blame] | 1244 | int numBorders = (numShownHotseatIcons - 1 + numExtraBorder); |
| 1245 | if (numBorders <= 0) return 0; |
| 1246 | |
Thales Lima | 9938c2f | 2022-07-25 14:38:16 +0100 | [diff] [blame] | 1247 | float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons; |
Jordan Silva | d922718 | 2023-08-17 15:53:59 +0100 | [diff] [blame] | 1248 | int hotseatBorderSpacePx = (int) (hotseatWidthPx - hotseatIconsTotalPx) / numBorders; |
Thales Lima | ffc68b0 | 2023-01-09 16:20:23 +0000 | [diff] [blame] | 1249 | return Math.min(hotseatBorderSpacePx, mMaxHotseatIconSpacePx); |
Thales Lima | 425f682 | 2022-05-10 13:44:58 -0300 | [diff] [blame] | 1250 | } |
| 1251 | |
Brian Isganitis | 25b2ac8 | 2022-01-28 16:25:13 -0500 | [diff] [blame] | 1252 | /** |
| 1253 | * Updates the iconSize for allApps* variants. |
| 1254 | */ |
Brian Isganitis | a9a7811 | 2022-05-23 18:11:47 -0700 | [diff] [blame] | 1255 | private void updateAllAppsIconSize(float scale, Resources res) { |
Thales Lima | 080d890 | 2022-03-28 15:30:29 +0100 | [diff] [blame] | 1256 | allAppsBorderSpacePx = new Point( |
| 1257 | pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].x, mMetrics, scale), |
| 1258 | pxFromDp(inv.allAppsBorderSpaces[mTypeIndex].y, mMetrics, scale)); |
Brandon Dayauon | 07ca884 | 2022-04-27 10:52:28 -0700 | [diff] [blame] | 1259 | // AllApps cells don't have real space between cells, |
| 1260 | // so we add the border space to the cell height |
Alex Chau | be75313 | 2022-12-09 16:46:54 +0000 | [diff] [blame] | 1261 | allAppsCellHeightPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].y, mMetrics) |
Brandon Dayauon | 07ca884 | 2022-04-27 10:52:28 -0700 | [diff] [blame] | 1262 | + allAppsBorderSpacePx.y; |
| 1263 | // but width is just the cell, |
| 1264 | // the border is added in #updateAllAppsContainerWidth |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 1265 | if (mIsScalableGrid) { |
Alex Chau | be75313 | 2022-12-09 16:46:54 +0000 | [diff] [blame] | 1266 | allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics); |
| 1267 | allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics); |
Thales Lima | 93ee8fc | 2023-06-05 17:07:11 +0100 | [diff] [blame] | 1268 | allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding(); |
Brandon Dayauon | 7a8a9ed | 2022-06-06 14:32:22 -0700 | [diff] [blame] | 1269 | allAppsCellWidthPx = pxFromDp(inv.allAppsCellSize[mTypeIndex].x, mMetrics, scale); |
Alex Chau | be75313 | 2022-12-09 16:46:54 +0000 | [diff] [blame] | 1270 | |
| 1271 | if (allAppsCellWidthPx < allAppsIconSizePx) { |
| 1272 | // If allAppsCellWidth no longer fit allAppsIconSize, reduce allAppsBorderSpace to |
| 1273 | // make allAppsCellWidth bigger. |
| 1274 | int numBorders = inv.numAllAppsColumns - 1; |
| 1275 | int extraWidthRequired = |
| 1276 | (allAppsIconSizePx - allAppsCellWidthPx) * inv.numAllAppsColumns; |
| 1277 | if (allAppsBorderSpacePx.x * numBorders >= extraWidthRequired) { |
| 1278 | allAppsCellWidthPx = allAppsIconSizePx; |
| 1279 | allAppsBorderSpacePx.x -= extraWidthRequired / numBorders; |
| 1280 | } else { |
| 1281 | // If it still doesn't fit, set allAppsBorderSpace to 0 and distribute the space |
| 1282 | // for allAppsCellWidth, and reduce allAppsIconSize. |
| 1283 | allAppsCellWidthPx = (allAppsCellWidthPx * inv.numAllAppsColumns |
| 1284 | + allAppsBorderSpacePx.x * numBorders) / inv.numAllAppsColumns; |
| 1285 | allAppsIconSizePx = Math.min(allAppsIconSizePx, allAppsCellWidthPx); |
| 1286 | allAppsBorderSpacePx.x = 0; |
| 1287 | } |
| 1288 | } |
| 1289 | |
| 1290 | int cellContentHeight = allAppsIconSizePx |
| 1291 | + Utilities.calculateTextHeight(allAppsIconTextSizePx) + allAppsBorderSpacePx.y; |
| 1292 | if (allAppsCellHeightPx < cellContentHeight) { |
| 1293 | // Increase allAppsCellHeight to fit its content. |
| 1294 | allAppsCellHeightPx = cellContentHeight; |
| 1295 | } |
Brian Isganitis | 25b2ac8 | 2022-01-28 16:25:13 -0500 | [diff] [blame] | 1296 | } else { |
Brandon Dayauon | 07ca884 | 2022-04-27 10:52:28 -0700 | [diff] [blame] | 1297 | float invIconSizeDp = inv.allAppsIconSize[mTypeIndex]; |
| 1298 | float invIconTextSizeSp = inv.allAppsIconTextSize[mTypeIndex]; |
Brian Isganitis | 25b2ac8 | 2022-01-28 16:25:13 -0500 | [diff] [blame] | 1299 | allAppsIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale)); |
| 1300 | allAppsIconTextSizePx = (int) (pxFromSp(invIconTextSizeSp, mMetrics) * scale); |
Brandon Dayauon | 07ca884 | 2022-04-27 10:52:28 -0700 | [diff] [blame] | 1301 | allAppsIconDrawablePaddingPx = |
| 1302 | res.getDimensionPixelSize(R.dimen.all_apps_icon_drawable_padding); |
Brandon Dayauon | 7a8a9ed | 2022-06-06 14:32:22 -0700 | [diff] [blame] | 1303 | allAppsCellWidthPx = allAppsIconSizePx + (2 * allAppsIconDrawablePaddingPx); |
Brian Isganitis | 25b2ac8 | 2022-01-28 16:25:13 -0500 | [diff] [blame] | 1304 | } |
Thales Lima | abfe364 | 2023-05-24 18:08:53 +0100 | [diff] [blame] | 1305 | } |
Brian Isganitis | 25b2ac8 | 2022-01-28 16:25:13 -0500 | [diff] [blame] | 1306 | |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 1307 | private void updateAllAppsWithResponsiveMeasures() { |
| 1308 | allAppsIconSizePx = mResponsiveAllAppsCellSpec.getIconSize(); |
| 1309 | allAppsIconTextSizePx = mResponsiveAllAppsCellSpec.getIconTextSize(); |
| 1310 | allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding(allAppsIconSizePx, |
| 1311 | mResponsiveAllAppsCellSpec.getIconDrawablePadding()); |
Thales Lima | abfe364 | 2023-05-24 18:08:53 +0100 | [diff] [blame] | 1312 | allAppsBorderSpacePx = new Point( |
Jordan Silva | 8f7986a | 2023-11-08 12:11:25 +0000 | [diff] [blame] | 1313 | mResponsiveAllAppsWidthSpec.getGutterPx(), |
| 1314 | mResponsiveAllAppsHeightSpec.getGutterPx() |
Thales Lima | abfe364 | 2023-05-24 18:08:53 +0100 | [diff] [blame] | 1315 | ); |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 1316 | allAppsCellHeightPx = mResponsiveAllAppsHeightSpec.getCellSizePx(); |
Jordan Silva | 8f7986a | 2023-11-08 12:11:25 +0000 | [diff] [blame] | 1317 | allAppsCellWidthPx = mResponsiveAllAppsWidthSpec.getCellSizePx(); |
Thales Lima | a25cd90 | 2023-11-01 12:00:32 +0000 | [diff] [blame] | 1318 | |
| 1319 | // This workaround is needed to align AllApps icons with Workspace icons |
| 1320 | // since AllApps doesn't have borders between cells |
| 1321 | int halfBorder = allAppsBorderSpacePx.x / 2; |
Jordan Silva | 8f7986a | 2023-11-08 12:11:25 +0000 | [diff] [blame] | 1322 | allAppsPadding.left = mResponsiveAllAppsWidthSpec.getStartPaddingPx() - halfBorder; |
| 1323 | allAppsPadding.right = mResponsiveAllAppsWidthSpec.getEndPaddingPx() - halfBorder; |
Jordan Silva | 376036a | 2023-11-08 15:56:40 +0000 | [diff] [blame] | 1324 | |
Jordan Silva | 376036a | 2023-11-08 15:56:40 +0000 | [diff] [blame] | 1325 | |
| 1326 | // Reduce the size of the app icon if it doesn't fit |
| 1327 | if (allAppsCellWidthPx < allAppsIconSizePx) { |
| 1328 | // get a smaller icon size |
| 1329 | allAppsIconSizePx = mIconSizeSteps.getIconSmallerThan(allAppsCellWidthPx); |
| 1330 | } |
| 1331 | |
| 1332 | CellContentDimensions cellContentDimensions = new CellContentDimensions( |
| 1333 | allAppsIconSizePx, allAppsIconDrawablePaddingPx, (int) allAppsIconTextSizePx); |
| 1334 | |
| 1335 | if (allAppsCellHeightPx < cellContentDimensions.getCellContentHeight()) { |
| 1336 | if (isVerticalBarLayout()) { |
Jordan Silva | 2de6a27 | 2024-01-04 14:44:20 -0300 | [diff] [blame] | 1337 | if (allAppsCellHeightPx < allAppsIconSizePx) { |
Jordan Silva | 376036a | 2023-11-08 15:56:40 +0000 | [diff] [blame] | 1338 | cellContentDimensions.setIconSizePx( |
| 1339 | mIconSizeSteps.getIconSmallerThan(allAppsCellHeightPx)); |
| 1340 | } |
| 1341 | } else { |
| 1342 | cellContentDimensions.resizeToFitCellHeight(allAppsCellHeightPx, |
| 1343 | mIconSizeSteps); |
| 1344 | } |
| 1345 | allAppsIconSizePx = cellContentDimensions.getIconSizePx(); |
| 1346 | allAppsIconDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx(); |
| 1347 | allAppsIconTextSizePx = cellContentDimensions.getIconTextSizePx(); |
| 1348 | } |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 1349 | |
| 1350 | allAppsCellHeightPx += mResponsiveAllAppsHeightSpec.getGutterPx(); |
Jordan Silva | dd61268 | 2024-01-08 11:38:13 -0300 | [diff] [blame] | 1351 | |
| 1352 | if (isVerticalBarLayout()) { |
| 1353 | autoResizeAllAppsCells(); |
| 1354 | } |
Thales Lima | abfe364 | 2023-05-24 18:08:53 +0100 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | /** |
| 1358 | * Re-computes the all-apps cell size to be independent of workspace |
| 1359 | */ |
| 1360 | public void autoResizeAllAppsCells() { |
| 1361 | int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx); |
| 1362 | int topBottomPadding = textHeight; |
| 1363 | allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx |
| 1364 | + textHeight + (topBottomPadding * 2); |
| 1365 | } |
| 1366 | |
| 1367 | private void updateAllAppsContainerWidth() { |
| 1368 | int cellLayoutHorizontalPadding = |
| 1369 | (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2; |
| 1370 | if (isTablet) { |
| 1371 | int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns) |
| 1372 | + (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1)) |
Thales Lima | b433c9c | 2023-10-30 12:24:05 +0000 | [diff] [blame] | 1373 | + allAppsPadding.left + allAppsPadding.right; |
Thales Lima | abfe364 | 2023-05-24 18:08:53 +0100 | [diff] [blame] | 1374 | allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2); |
Thales Lima | a25cd90 | 2023-11-01 12:00:32 +0000 | [diff] [blame] | 1375 | } else if (!mIsResponsiveGrid) { |
Thales Lima | b433c9c | 2023-10-30 12:24:05 +0000 | [diff] [blame] | 1376 | allAppsPadding.left = allAppsPadding.right = |
Thales Lima | abfe364 | 2023-05-24 18:08:53 +0100 | [diff] [blame] | 1377 | Math.max(0, desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding |
| 1378 | - (allAppsBorderSpacePx.x / 2)); |
Brian Isganitis | 25b2ac8 | 2022-01-28 16:25:13 -0500 | [diff] [blame] | 1379 | } |
| 1380 | } |
| 1381 | |
Thales Lima | abfe364 | 2023-05-24 18:08:53 +0100 | [diff] [blame] | 1382 | private void setupAllAppsStyle(Context context) { |
| 1383 | TypedArray allAppsStyle = context.obtainStyledAttributes( |
| 1384 | inv.allAppsStyle != INVALID_RESOURCE_HANDLE ? inv.allAppsStyle |
| 1385 | : R.style.AllAppsStyleDefault, R.styleable.AllAppsStyle); |
| 1386 | |
Thales Lima | b433c9c | 2023-10-30 12:24:05 +0000 | [diff] [blame] | 1387 | allAppsPadding.left = allAppsPadding.right = allAppsStyle.getDimensionPixelSize( |
Thales Lima | abfe364 | 2023-05-24 18:08:53 +0100 | [diff] [blame] | 1388 | R.styleable.AllAppsStyle_horizontalPadding, 0); |
| 1389 | allAppsStyle.recycle(); |
| 1390 | } |
| 1391 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 1392 | private void updateAvailableFolderCellDimensions(Resources res) { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 1393 | updateFolderCellSize(1f, res); |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 1394 | |
Jordan Silva | 637f4eb | 2023-06-13 11:21:53 +0100 | [diff] [blame] | 1395 | // Responsive grid doesn't need to scale the folder |
| 1396 | if (mIsResponsiveGrid) return; |
| 1397 | |
Thales Lima | 7eee74b | 2023-03-16 16:00:55 -0300 | [diff] [blame] | 1398 | // For usability we can't have the folder use the whole width of the screen |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 1399 | Point totalWorkspacePadding = getTotalWorkspacePadding(); |
Jon Miranda | c1b2399 | 2016-12-13 08:57:36 -0800 | [diff] [blame] | 1400 | |
Thales Lima | 7eee74b | 2023-03-16 16:00:55 -0300 | [diff] [blame] | 1401 | // Check if the folder fit within the available height. |
Thales Lima | 1faa4ed | 2023-12-01 16:48:19 +0000 | [diff] [blame] | 1402 | float contentUsedHeight = folderCellHeightPx * numFolderRows |
| 1403 | + ((numFolderRows - 1) * folderCellLayoutBorderSpacePx.y) |
Thales Lima | 7eee74b | 2023-03-16 16:00:55 -0300 | [diff] [blame] | 1404 | + folderFooterHeightPx |
| 1405 | + folderContentPaddingTop; |
| 1406 | int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y; |
Samuel Fufa | 1c8d90a | 2019-11-12 17:54:58 -0800 | [diff] [blame] | 1407 | float scaleY = contentMaxHeight / contentUsedHeight; |
Jon Miranda | c1b2399 | 2016-12-13 08:57:36 -0800 | [diff] [blame] | 1408 | |
Thales Lima | 7eee74b | 2023-03-16 16:00:55 -0300 | [diff] [blame] | 1409 | // Check if the folder fit within the available width. |
Thales Lima | 1faa4ed | 2023-12-01 16:48:19 +0000 | [diff] [blame] | 1410 | float contentUsedWidth = folderCellWidthPx * numFolderColumns |
| 1411 | + ((numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x) |
Thales Lima | 7eee74b | 2023-03-16 16:00:55 -0300 | [diff] [blame] | 1412 | + folderContentPaddingLeftRight * 2; |
| 1413 | int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x; |
Samuel Fufa | 1c8d90a | 2019-11-12 17:54:58 -0800 | [diff] [blame] | 1414 | float scaleX = contentMaxWidth / contentUsedWidth; |
Jon Miranda | c1b2399 | 2016-12-13 08:57:36 -0800 | [diff] [blame] | 1415 | |
| 1416 | float scale = Math.min(scaleX, scaleY); |
| 1417 | if (scale < 1f) { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 1418 | updateFolderCellSize(scale, res); |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 1419 | } |
| 1420 | } |
| 1421 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 1422 | private void updateFolderCellSize(float scale, Resources res) { |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 1423 | int minLabelTextSize = pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale); |
Jordan Silva | 637f4eb | 2023-06-13 11:21:53 +0100 | [diff] [blame] | 1424 | if (mIsResponsiveGrid) { |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 1425 | folderChildIconSizePx = mResponsiveWorkspaceCellSpec.getIconSize(); |
| 1426 | folderChildTextSizePx = mResponsiveWorkspaceCellSpec.getIconTextSize(); |
| 1427 | folderLabelTextSizePx = Math.max(minLabelTextSize, |
| 1428 | (int) (folderChildTextSizePx * folderLabelTextScale)); |
| 1429 | int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx); |
| 1430 | |
Jordan Silva | 637f4eb | 2023-06-13 11:21:53 +0100 | [diff] [blame] | 1431 | folderCellWidthPx = mResponsiveFolderWidthSpec.getCellSizePx(); |
Jordan Silva | 637f4eb | 2023-06-13 11:21:53 +0100 | [diff] [blame] | 1432 | folderCellHeightPx = mResponsiveFolderHeightSpec.getCellSizePx(); |
| 1433 | folderContentPaddingTop = mResponsiveFolderHeightSpec.getStartPaddingPx(); |
| 1434 | folderFooterHeightPx = mResponsiveFolderHeightSpec.getEndPaddingPx(); |
| 1435 | |
| 1436 | folderCellLayoutBorderSpacePx = new Point(mResponsiveFolderWidthSpec.getGutterPx(), |
Thales Lima | 4cfd950 | 2023-07-10 14:01:28 +0100 | [diff] [blame] | 1437 | mResponsiveFolderHeightSpec.getGutterPx()); |
Jordan Silva | 637f4eb | 2023-06-13 11:21:53 +0100 | [diff] [blame] | 1438 | |
| 1439 | folderContentPaddingLeftRight = mResponsiveFolderWidthSpec.getStartPaddingPx(); |
Jordan Silva | 12fae11 | 2023-06-26 12:51:01 +0100 | [diff] [blame] | 1440 | |
| 1441 | // Reduce icon width if it's wider than the expected folder cell width |
| 1442 | if (folderCellWidthPx < folderChildIconSizePx) { |
| 1443 | folderChildIconSizePx = mIconSizeSteps.getIconSmallerThan(folderCellWidthPx); |
| 1444 | } |
| 1445 | |
| 1446 | // Recalculating padding and cell height |
Jordan Silva | 3e5688a | 2023-12-05 15:12:29 -0300 | [diff] [blame] | 1447 | folderChildDrawablePaddingPx = mResponsiveWorkspaceCellSpec.getIconDrawablePadding(); |
Jordan Silva | 12fae11 | 2023-06-26 12:51:01 +0100 | [diff] [blame] | 1448 | |
Thales Lima | e9b5e14 | 2023-11-04 17:10:13 +0000 | [diff] [blame] | 1449 | CellContentDimensions cellContentDimensions = new CellContentDimensions( |
| 1450 | folderChildIconSizePx, |
| 1451 | folderChildDrawablePaddingPx, |
| 1452 | folderChildTextSizePx); |
| 1453 | cellContentDimensions.resizeToFitCellHeight(folderCellHeightPx, mIconSizeSteps); |
| 1454 | folderChildIconSizePx = cellContentDimensions.getIconSizePx(); |
| 1455 | folderChildDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx(); |
| 1456 | folderChildTextSizePx = cellContentDimensions.getIconTextSizePx(); |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 1457 | folderLabelTextSizePx = Math.max(minLabelTextSize, |
Jordan Silva | 9a3bd8f | 2023-11-16 18:33:28 +0000 | [diff] [blame] | 1458 | (int) (folderChildTextSizePx * folderLabelTextScale)); |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 1459 | return; |
| 1460 | } |
| 1461 | |
| 1462 | float invIconSizeDp = inv.iconSize[mTypeIndex]; |
| 1463 | float invIconTextSizeDp = inv.iconTextSize[mTypeIndex]; |
| 1464 | folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale)); |
| 1465 | folderChildTextSizePx = pxFromSp(invIconTextSizeDp, mMetrics, scale); |
| 1466 | folderLabelTextSizePx = Math.max(minLabelTextSize, |
| 1467 | (int) (folderChildTextSizePx * folderLabelTextScale)); |
| 1468 | int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx); |
| 1469 | |
| 1470 | if (mIsScalableGrid) { |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 1471 | if (inv.folderStyle == INVALID_RESOURCE_HANDLE) { |
Thales Lima | 7eee74b | 2023-03-16 16:00:55 -0300 | [diff] [blame] | 1472 | folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale); |
| 1473 | folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale); |
| 1474 | } else { |
| 1475 | folderCellWidthPx = roundPxValueFromFloat(folderCellWidthPx * scale); |
| 1476 | folderCellHeightPx = roundPxValueFromFloat(folderCellHeightPx * scale); |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 1477 | } |
Charlie Anderson | 7bb1097 | 2023-11-22 13:35:30 -0800 | [diff] [blame] | 1478 | // Recalculating padding and cell height |
| 1479 | folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight); |
| 1480 | |
| 1481 | CellContentDimensions cellContentDimensions = new CellContentDimensions( |
| 1482 | folderChildIconSizePx, |
| 1483 | folderChildDrawablePaddingPx, |
| 1484 | folderChildTextSizePx); |
| 1485 | cellContentDimensions.resizeToFitCellHeight(folderCellHeightPx, mIconSizeSteps); |
| 1486 | folderChildIconSizePx = cellContentDimensions.getIconSizePx(); |
| 1487 | folderChildDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx(); |
| 1488 | folderChildTextSizePx = cellContentDimensions.getIconTextSizePx(); |
Jon Miranda | f33f5b3 | 2021-07-22 17:15:31 -0700 | [diff] [blame] | 1489 | |
Thales Lima | 7eee74b | 2023-03-16 16:00:55 -0300 | [diff] [blame] | 1490 | folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale); |
Jordan Silva | 637f4eb | 2023-06-13 11:21:53 +0100 | [diff] [blame] | 1491 | folderCellLayoutBorderSpacePx = new Point( |
| 1492 | roundPxValueFromFloat(folderCellLayoutBorderSpacePx.x * scale), |
| 1493 | roundPxValueFromFloat(folderCellLayoutBorderSpacePx.y * scale) |
| 1494 | ); |
Thales Lima | 7eee74b | 2023-03-16 16:00:55 -0300 | [diff] [blame] | 1495 | folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale); |
Jordan Silva | 637f4eb | 2023-06-13 11:21:53 +0100 | [diff] [blame] | 1496 | folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx.x; |
Jon Miranda | 823da22 | 2021-03-23 08:08:45 -0400 | [diff] [blame] | 1497 | } else { |
| 1498 | int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding) |
| 1499 | * scale); |
| 1500 | int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding) |
| 1501 | * scale); |
| 1502 | |
| 1503 | folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX; |
| 1504 | folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight; |
Thales Lima | 7eee74b | 2023-03-16 16:00:55 -0300 | [diff] [blame] | 1505 | folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale); |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 1506 | folderContentPaddingLeftRight = |
| 1507 | res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right); |
| 1508 | folderFooterHeightPx = |
Thales Lima | 7eee74b | 2023-03-16 16:00:55 -0300 | [diff] [blame] | 1509 | roundPxValueFromFloat( |
| 1510 | res.getDimensionPixelSize(R.dimen.folder_footer_height_default) |
| 1511 | * scale); |
| 1512 | |
Jordan Silva | 12fae11 | 2023-06-26 12:51:01 +0100 | [diff] [blame] | 1513 | folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight); |
Jon Miranda | 823da22 | 2021-03-23 08:08:45 -0400 | [diff] [blame] | 1514 | } |
Jon Miranda | bf7d812 | 2016-11-03 15:29:29 -0700 | [diff] [blame] | 1515 | } |
| 1516 | |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 1517 | public void updateInsets(Rect insets) { |
| 1518 | mInsets.set(insets); |
| 1519 | } |
| 1520 | |
Sunny Goyal | ae6e318 | 2019-04-30 12:04:37 -0700 | [diff] [blame] | 1521 | /** |
| 1522 | * The current device insets. This is generally same as the insets being dispatched to |
| 1523 | * {@link Insettable} elements, but can differ if the element is using a different profile. |
| 1524 | */ |
Sunny Goyal | 1a52ef5 | 2018-01-11 10:15:03 -0800 | [diff] [blame] | 1525 | public Rect getInsets() { |
| 1526 | return mInsets; |
| 1527 | } |
| 1528 | |
Sunny Goyal | 756cd26 | 2015-08-20 12:33:21 -0700 | [diff] [blame] | 1529 | public Point getCellSize() { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 1530 | return getCellSize(null); |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 1531 | } |
| 1532 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 1533 | public Point getCellSize(Point result) { |
| 1534 | if (result == null) { |
| 1535 | result = new Point(); |
| 1536 | } |
Thales Lima | d1df5fc | 2021-09-03 18:37:19 +0100 | [diff] [blame] | 1537 | |
Pat Manning | 25d5334 | 2022-05-10 09:58:49 +0000 | [diff] [blame] | 1538 | int shortcutAndWidgetContainerWidth = |
| 1539 | getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right); |
| 1540 | result.x = calculateCellWidth(shortcutAndWidgetContainerWidth, cellLayoutBorderSpacePx.x, |
| 1541 | inv.numColumns); |
| 1542 | int shortcutAndWidgetContainerHeight = |
| 1543 | getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom); |
| 1544 | result.y = calculateCellHeight(shortcutAndWidgetContainerHeight, cellLayoutBorderSpacePx.y, |
| 1545 | inv.numRows); |
Sunny Goyal | 3e8a04b | 2022-05-09 19:31:45 +0000 | [diff] [blame] | 1546 | return result; |
Pat Manning | b45d6c4 | 2022-05-03 14:32:06 +0100 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | /** |
Thales Lima | 1e8b45f | 2022-08-25 11:50:59 -0400 | [diff] [blame] | 1550 | * Returns the left and right space on the cell, which is the cell width - icon size |
| 1551 | */ |
| 1552 | public int getCellHorizontalSpace() { |
| 1553 | return getCellSize().x - iconSizePx; |
| 1554 | } |
| 1555 | |
| 1556 | /** |
Pat Manning | 25d5334 | 2022-05-10 09:58:49 +0000 | [diff] [blame] | 1557 | * Gets the number of panels within the workspace. |
| 1558 | */ |
| 1559 | public int getPanelCount() { |
| 1560 | return isTwoPanels ? 2 : 1; |
| 1561 | } |
| 1562 | |
| 1563 | /** |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 1564 | * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the |
| 1565 | * bottom of the screen. |
| 1566 | */ |
Pat Manning | 5f74bfd | 2022-07-20 12:08:54 +0100 | [diff] [blame] | 1567 | private int getVerticalHotseatLastItemBottomOffset(Context context) { |
| 1568 | Rect hotseatBarPadding = getHotseatLayoutPadding(context); |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 1569 | int cellHeight = calculateCellHeight( |
Pat Manning | 5f74bfd | 2022-07-20 12:08:54 +0100 | [diff] [blame] | 1570 | heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace, |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 1571 | numShownHotseatIcons); |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 1572 | int extraIconEndSpacing = (cellHeight - iconSizePx) / 2; |
Pat Manning | 5f74bfd | 2022-07-20 12:08:54 +0100 | [diff] [blame] | 1573 | return extraIconEndSpacing + hotseatBarPadding.bottom; |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | /** |
| 1577 | * Gets the scaled top of the workspace in px for the spring-loaded edit state. |
| 1578 | */ |
Pat Manning | 25d5334 | 2022-05-10 09:58:49 +0000 | [diff] [blame] | 1579 | public float getCellLayoutSpringLoadShrunkTop() { |
Pat Manning | 5f74bfd | 2022-07-20 12:08:54 +0100 | [diff] [blame] | 1580 | return mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 1581 | + dropTargetBarBottomMarginPx; |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | /** |
| 1585 | * Gets the scaled bottom of the workspace in px for the spring-loaded edit state. |
| 1586 | */ |
Pat Manning | 5f74bfd | 2022-07-20 12:08:54 +0100 | [diff] [blame] | 1587 | public float getCellLayoutSpringLoadShrunkBottom(Context context) { |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 1588 | int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx; |
Pat Manning | 5f74bfd | 2022-07-20 12:08:54 +0100 | [diff] [blame] | 1589 | return heightPx - (isVerticalBarLayout() |
| 1590 | ? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat); |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 1591 | } |
| 1592 | |
Pat Manning | ea5c1d2 | 2022-04-14 10:58:16 +0100 | [diff] [blame] | 1593 | /** |
Pat Manning | a2e1499 | 2022-04-22 11:29:17 +0100 | [diff] [blame] | 1594 | * Gets the scale of the workspace for the spring-loaded edit state. |
| 1595 | */ |
Pat Manning | 5f74bfd | 2022-07-20 12:08:54 +0100 | [diff] [blame] | 1596 | public float getWorkspaceSpringLoadScale(Context context) { |
| 1597 | float scale = |
| 1598 | (getCellLayoutSpringLoadShrunkBottom(context) - getCellLayoutSpringLoadShrunkTop()) |
| 1599 | / getCellLayoutHeight(); |
Pat Manning | a2e1499 | 2022-04-22 11:29:17 +0100 | [diff] [blame] | 1600 | scale = Math.min(scale, 1f); |
| 1601 | |
Pat Manning | e63dd25 | 2022-08-02 16:15:29 +0100 | [diff] [blame] | 1602 | // Reduce scale if next pages would not be visible after scaling the workspace. |
Pat Manning | 25d5334 | 2022-05-10 09:58:49 +0000 | [diff] [blame] | 1603 | int workspaceWidth = availableWidthPx; |
Pat Manning | a2e1499 | 2022-04-22 11:29:17 +0100 | [diff] [blame] | 1604 | float scaledWorkspaceWidth = workspaceWidth * scale; |
Alex Chau | 906d882 | 2022-05-23 10:42:25 +0100 | [diff] [blame] | 1605 | float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx); |
Pat Manning | a2e1499 | 2022-04-22 11:29:17 +0100 | [diff] [blame] | 1606 | if (scaledWorkspaceWidth > maxAvailableWidth) { |
| 1607 | scale *= maxAvailableWidth / scaledWorkspaceWidth; |
| 1608 | } |
| 1609 | return scale; |
| 1610 | } |
| 1611 | |
Pat Manning | 25d5334 | 2022-05-10 09:58:49 +0000 | [diff] [blame] | 1612 | /** |
| 1613 | * Gets the width of a single Cell Layout, aka a single panel within a Workspace. |
| 1614 | * |
| 1615 | * <p>This is the width of a Workspace, less its horizontal padding. Note that two-panel |
| 1616 | * layouts have two Cell Layouts per workspace. |
| 1617 | */ |
| 1618 | public int getCellLayoutWidth() { |
| 1619 | return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount(); |
Alex Chau | 6095333 | 2021-11-24 12:41:07 +0000 | [diff] [blame] | 1620 | } |
| 1621 | |
Pat Manning | 25d5334 | 2022-05-10 09:58:49 +0000 | [diff] [blame] | 1622 | /** |
| 1623 | * Gets the height of a single Cell Layout, aka a single panel within a Workspace. |
| 1624 | * |
| 1625 | * <p>This is the height of a Workspace, less its vertical padding. |
| 1626 | */ |
| 1627 | public int getCellLayoutHeight() { |
| 1628 | return availableHeightPx - getTotalWorkspacePadding().y; |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 1629 | } |
| 1630 | |
Sunny Goyal | 6c2975e | 2016-07-06 09:47:56 -0700 | [diff] [blame] | 1631 | public Point getTotalWorkspacePadding() { |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 1632 | return new Point(workspacePadding.left + workspacePadding.right, |
| 1633 | workspacePadding.top + workspacePadding.bottom); |
Sunny Goyal | 6c2975e | 2016-07-06 09:47:56 -0700 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | /** |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 1637 | * Updates {@link #workspacePadding} as a result of any internal value change to reflect the |
| 1638 | * new workspace padding |
Sunny Goyal | 6c2975e | 2016-07-06 09:47:56 -0700 | [diff] [blame] | 1639 | */ |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 1640 | private void updateWorkspacePadding() { |
| 1641 | Rect padding = workspacePadding; |
Tony Wickham | 3a3517f | 2015-10-06 11:27:04 -0700 | [diff] [blame] | 1642 | if (isVerticalBarLayout()) { |
Jordan Silva | 3646a1b | 2023-08-02 13:52:52 +0100 | [diff] [blame] | 1643 | if (mIsResponsiveGrid) { |
Jordan Silva | 8f7986a | 2023-11-08 12:11:25 +0000 | [diff] [blame] | 1644 | padding.top = mResponsiveWorkspaceHeightSpec.getStartPaddingPx(); |
Thales Lima | 8e11d53 | 2023-08-31 13:40:26 +0000 | [diff] [blame] | 1645 | padding.bottom = Math.max(0, |
Jordan Silva | 8f7986a | 2023-11-08 12:11:25 +0000 | [diff] [blame] | 1646 | mResponsiveWorkspaceHeightSpec.getEndPaddingPx() - mInsets.bottom); |
Jordan Silva | 3646a1b | 2023-08-02 13:52:52 +0100 | [diff] [blame] | 1647 | if (isSeascape()) { |
Jordan Silva | 8f7986a | 2023-11-08 12:11:25 +0000 | [diff] [blame] | 1648 | padding.left = |
| 1649 | hotseatBarSizePx + mResponsiveWorkspaceWidthSpec.getEndPaddingPx(); |
| 1650 | padding.right = mResponsiveWorkspaceWidthSpec.getStartPaddingPx(); |
Jordan Silva | 3646a1b | 2023-08-02 13:52:52 +0100 | [diff] [blame] | 1651 | } else { |
Jordan Silva | 8f7986a | 2023-11-08 12:11:25 +0000 | [diff] [blame] | 1652 | padding.left = mResponsiveWorkspaceWidthSpec.getStartPaddingPx(); |
| 1653 | padding.right = |
| 1654 | hotseatBarSizePx + mResponsiveWorkspaceWidthSpec.getEndPaddingPx(); |
Jordan Silva | 3646a1b | 2023-08-02 13:52:52 +0100 | [diff] [blame] | 1655 | } |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 1656 | } else { |
Jordan Silva | 3646a1b | 2023-08-02 13:52:52 +0100 | [diff] [blame] | 1657 | padding.top = 0; |
| 1658 | padding.bottom = edgeMarginPx; |
| 1659 | if (isSeascape()) { |
| 1660 | padding.left = hotseatBarSizePx; |
Thales Lima | 8e11d53 | 2023-08-31 13:40:26 +0000 | [diff] [blame] | 1661 | padding.right = mHotseatBarEdgePaddingPx; |
Jordan Silva | 3646a1b | 2023-08-02 13:52:52 +0100 | [diff] [blame] | 1662 | } else { |
Thales Lima | 8e11d53 | 2023-08-31 13:40:26 +0000 | [diff] [blame] | 1663 | padding.left = mHotseatBarEdgePaddingPx; |
Jordan Silva | 3646a1b | 2023-08-02 13:52:52 +0100 | [diff] [blame] | 1664 | padding.right = hotseatBarSizePx; |
| 1665 | } |
Winson | 1f06427 | 2016-07-18 17:18:02 -0700 | [diff] [blame] | 1666 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 1667 | } else { |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 1668 | // Pad the bottom of the workspace with hotseat bar |
| 1669 | // and leave a bit of space in case a widget go all the way down |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 1670 | int paddingBottom = hotseatBarSizePx + workspaceBottomPadding - mInsets.bottom; |
| 1671 | if (!mIsResponsiveGrid) { |
| 1672 | paddingBottom += |
| 1673 | workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace; |
| 1674 | } |
| 1675 | int paddingTop = workspaceTopPadding + (mIsScalableGrid ? 0 : edgeMarginPx); |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 1676 | int paddingSide = desiredWorkspaceHorizontalMarginPx; |
Andras Kloczl | 8e57cce | 2021-02-11 23:51:19 +0100 | [diff] [blame] | 1677 | |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 1678 | padding.set(paddingSide, paddingTop, paddingSide, paddingBottom); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 1679 | } |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 1680 | insetPadding(workspacePadding, cellLayoutPaddingPx); |
| 1681 | } |
| 1682 | |
| 1683 | private void insetPadding(Rect paddings, Rect insets) { |
| 1684 | insets.left = Math.min(insets.left, paddings.left); |
| 1685 | paddings.left -= insets.left; |
| 1686 | |
| 1687 | insets.top = Math.min(insets.top, paddings.top); |
| 1688 | paddings.top -= insets.top; |
| 1689 | |
| 1690 | insets.right = Math.min(insets.right, paddings.right); |
| 1691 | paddings.right -= insets.right; |
| 1692 | |
| 1693 | insets.bottom = Math.min(insets.bottom, paddings.bottom); |
| 1694 | paddings.bottom -= insets.bottom; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 1695 | } |
| 1696 | |
Liran Binyamin | a833af3 | 2023-08-02 16:30:27 -0400 | [diff] [blame] | 1697 | |
| 1698 | /** |
| 1699 | * Returns the new border space that should be used between hotseat icons after adjusting it to |
| 1700 | * the bubble bar. |
| 1701 | * |
| 1702 | * <p>If there's no adjustment needed, this method returns {@code 0}. |
| 1703 | */ |
| 1704 | public float getHotseatAdjustedBorderSpaceForBubbleBar(Context context) { |
| 1705 | // only need to adjust when QSB is on top of the hotseat. |
| 1706 | if (isQsbInline) { |
| 1707 | return 0; |
| 1708 | } |
| 1709 | |
| 1710 | // no need to adjust if there's enough space for the bubble bar to the right of the hotseat. |
| 1711 | if (getHotseatLayoutPadding(context).right > mBubbleBarSpaceThresholdPx) { |
| 1712 | return 0; |
| 1713 | } |
| 1714 | |
| 1715 | // The adjustment is shrinking the hotseat's width by 1 icon on either side. |
| 1716 | int iconsWidth = |
| 1717 | iconSizePx * numShownHotseatIcons + hotseatBorderSpace * (numShownHotseatIcons - 1); |
| 1718 | int newWidth = iconsWidth - 2 * iconSizePx; |
| 1719 | // Evenly space the icons within the boundaries of the new width. |
| 1720 | return (float) (newWidth - iconSizePx * numShownHotseatIcons) / (numShownHotseatIcons - 1); |
| 1721 | } |
| 1722 | |
Sunny Goyal | 57b2279 | 2021-05-25 14:35:01 -0700 | [diff] [blame] | 1723 | /** |
| 1724 | * Returns the padding for hotseat view |
| 1725 | */ |
| 1726 | public Rect getHotseatLayoutPadding(Context context) { |
Pat Manning | 5f74bfd | 2022-07-20 12:08:54 +0100 | [diff] [blame] | 1727 | Rect hotseatBarPadding = new Rect(); |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 1728 | if (isVerticalBarLayout()) { |
Sihua Ma | 38bb3b0 | 2022-03-21 22:20:14 -0700 | [diff] [blame] | 1729 | // The hotseat icons will be placed in the middle of the hotseat cells. |
| 1730 | // Changing the hotseatCellHeightPx is not affecting hotseat icon positions |
| 1731 | // in vertical bar layout. |
| 1732 | // Workspace icons are moved up by a small factor. The variable diffOverlapFactor |
| 1733 | // is set to account for that difference. |
Jordan Silva | 3646a1b | 2023-08-02 13:52:52 +0100 | [diff] [blame] | 1734 | float diffOverlapFactor = mIsResponsiveGrid ? 0 |
| 1735 | : iconSizePx * (ICON_OVERLAP_FACTOR - 1) / 2; |
| 1736 | |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 1737 | int paddingTop = Math.max((int) (mInsets.top + cellLayoutPaddingPx.top |
| 1738 | - diffOverlapFactor), 0); |
| 1739 | int paddingBottom = Math.max((int) (mInsets.bottom + cellLayoutPaddingPx.bottom |
Sihua Ma | 38bb3b0 | 2022-03-21 22:20:14 -0700 | [diff] [blame] | 1740 | + diffOverlapFactor), 0); |
| 1741 | |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 1742 | if (isSeascape()) { |
Thales Lima | 8e11d53 | 2023-08-31 13:40:26 +0000 | [diff] [blame] | 1743 | hotseatBarPadding.set(mInsets.left + mHotseatBarEdgePaddingPx, paddingTop, |
| 1744 | mHotseatBarWorkspaceSpacePx, paddingBottom); |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 1745 | } else { |
Thales Lima | 8e11d53 | 2023-08-31 13:40:26 +0000 | [diff] [blame] | 1746 | hotseatBarPadding.set(mHotseatBarWorkspaceSpacePx, paddingTop, |
| 1747 | mInsets.right + mHotseatBarEdgePaddingPx, paddingBottom); |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 1748 | } |
Sunny Goyal | 57b2279 | 2021-05-25 14:35:01 -0700 | [diff] [blame] | 1749 | } else if (isTaskbarPresent) { |
Alex Chau | 51da219 | 2022-05-20 13:32:10 +0100 | [diff] [blame] | 1750 | // Center the QSB vertically with hotseat |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 1751 | int hotseatBarBottomPadding = getHotseatBarBottomPadding(); |
| 1752 | int hotseatBarTopPadding = |
| 1753 | hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx; |
Alex Chau | 51da219 | 2022-05-20 13:32:10 +0100 | [diff] [blame] | 1754 | |
Thales Lima | 6a59006 | 2022-11-22 15:52:49 +0000 | [diff] [blame] | 1755 | int hotseatWidth = getHotseatRequiredWidth(); |
Helen Cheuk | e76291f | 2023-02-14 17:11:05 +0000 | [diff] [blame] | 1756 | int startSpacing; |
| 1757 | int endSpacing; |
Thales Lima | 6a59006 | 2022-11-22 15:52:49 +0000 | [diff] [blame] | 1758 | // Hotseat aligns to the left with nav buttons |
| 1759 | if (hotseatBarEndOffset > 0) { |
Jon Miranda | e17a949 | 2023-03-08 16:42:20 -0800 | [diff] [blame] | 1760 | startSpacing = inlineNavButtonsEndSpacingPx; |
Helen Cheuk | e76291f | 2023-02-14 17:11:05 +0000 | [diff] [blame] | 1761 | endSpacing = availableWidthPx - hotseatWidth - startSpacing + hotseatBorderSpace; |
| 1762 | } else { |
| 1763 | startSpacing = (availableWidthPx - hotseatWidth) / 2; |
| 1764 | endSpacing = startSpacing; |
Thales Lima | 6a59006 | 2022-11-22 15:52:49 +0000 | [diff] [blame] | 1765 | } |
Helen Cheuk | e76291f | 2023-02-14 17:11:05 +0000 | [diff] [blame] | 1766 | startSpacing += getAdditionalQsbSpace(); |
Thales Lima | 612230d | 2022-03-31 18:04:37 +0100 | [diff] [blame] | 1767 | |
Helen Cheuk | e76291f | 2023-02-14 17:11:05 +0000 | [diff] [blame] | 1768 | hotseatBarPadding.top = hotseatBarTopPadding; |
| 1769 | hotseatBarPadding.bottom = hotseatBarBottomPadding; |
Alex Chau | 51da219 | 2022-05-20 13:32:10 +0100 | [diff] [blame] | 1770 | boolean isRtl = Utilities.isRtl(context.getResources()); |
Thales Lima | 612230d | 2022-03-31 18:04:37 +0100 | [diff] [blame] | 1771 | if (isRtl) { |
Helen Cheuk | e76291f | 2023-02-14 17:11:05 +0000 | [diff] [blame] | 1772 | hotseatBarPadding.left = endSpacing; |
| 1773 | hotseatBarPadding.right = startSpacing; |
Thales Lima | 612230d | 2022-03-31 18:04:37 +0100 | [diff] [blame] | 1774 | } else { |
Helen Cheuk | e76291f | 2023-02-14 17:11:05 +0000 | [diff] [blame] | 1775 | hotseatBarPadding.left = startSpacing; |
| 1776 | hotseatBarPadding.right = endSpacing; |
Thales Lima | 612230d | 2022-03-31 18:04:37 +0100 | [diff] [blame] | 1777 | } |
Helen Cheuk | e76291f | 2023-02-14 17:11:05 +0000 | [diff] [blame] | 1778 | |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 1779 | } else if (mIsScalableGrid) { |
fbaron | e69b6f4 | 2023-12-18 13:20:34 -0800 | [diff] [blame] | 1780 | int iconExtraSpacePx = iconSizePx - getIconVisibleSizePx(iconSizePx); |
| 1781 | int sideSpacing = (availableWidthPx - (hotseatQsbWidth + iconExtraSpacePx)) / 2; |
Pat Manning | 5f74bfd | 2022-07-20 12:08:54 +0100 | [diff] [blame] | 1782 | hotseatBarPadding.set(sideSpacing, |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 1783 | 0, |
Thales Lima | 425f682 | 2022-05-10 13:44:58 -0300 | [diff] [blame] | 1784 | sideSpacing, |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 1785 | getHotseatBarBottomPadding()); |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 1786 | } else { |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 1787 | // We want the edges of the hotseat to line up with the edges of the workspace, but the |
| 1788 | // icons in the hotseat are a different size, and so don't line up perfectly. To account |
| 1789 | // for this, we pad the left and right of the hotseat with half of the difference of a |
| 1790 | // workspace cell vs a hotseat cell. |
| 1791 | float workspaceCellWidth = (float) widthPx / inv.numColumns; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 1792 | float hotseatCellWidth = (float) widthPx / numShownHotseatIcons; |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 1793 | int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2); |
Pat Manning | 5f74bfd | 2022-07-20 12:08:54 +0100 | [diff] [blame] | 1794 | hotseatBarPadding.set( |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 1795 | hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left |
| 1796 | + mInsets.left, |
| 1797 | 0, |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 1798 | hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right |
Sunny Goyal | 786940a | 2020-06-02 02:31:31 -0700 | [diff] [blame] | 1799 | + mInsets.right, |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 1800 | getHotseatBarBottomPadding()); |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 1801 | } |
Pat Manning | 5f74bfd | 2022-07-20 12:08:54 +0100 | [diff] [blame] | 1802 | return hotseatBarPadding; |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
Andy Wickham | bd9a180 | 2023-06-08 16:33:15 -0700 | [diff] [blame] | 1805 | /** The margin between the edge of all apps and the edge of the first icon. */ |
Thales Lima | b433c9c | 2023-10-30 12:24:05 +0000 | [diff] [blame] | 1806 | public int getAllAppsIconStartMargin(Context context) { |
Andy Wickham | bd9a180 | 2023-06-08 16:33:15 -0700 | [diff] [blame] | 1807 | int allAppsSpacing; |
| 1808 | if (isVerticalBarLayout()) { |
| 1809 | // On phones, the landscape layout uses a different setup. |
| 1810 | allAppsSpacing = workspacePadding.left + workspacePadding.right; |
| 1811 | } else { |
Thales Lima | b433c9c | 2023-10-30 12:24:05 +0000 | [diff] [blame] | 1812 | allAppsSpacing = |
| 1813 | allAppsPadding.left + allAppsPadding.right + allAppsLeftRightMargin * 2; |
Andy Wickham | bd9a180 | 2023-06-08 16:33:15 -0700 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | int cellWidth = DeviceProfile.calculateCellWidth( |
| 1817 | availableWidthPx - allAppsSpacing, |
| 1818 | 0 /* borderSpace */, |
| 1819 | numShownAllAppsColumns); |
fbaron | e69b6f4 | 2023-12-18 13:20:34 -0800 | [diff] [blame] | 1820 | int iconAlignmentMargin = (cellWidth - getIconVisibleSizePx(allAppsIconSizePx)) / 2; |
Thales Lima | b433c9c | 2023-10-30 12:24:05 +0000 | [diff] [blame] | 1821 | |
| 1822 | return (Utilities.isRtl(context.getResources()) ? allAppsPadding.right |
| 1823 | : allAppsPadding.left) + iconAlignmentMargin; |
Andy Wickham | bd9a180 | 2023-06-08 16:33:15 -0700 | [diff] [blame] | 1824 | } |
| 1825 | |
fbaron | e69b6f4 | 2023-12-18 13:20:34 -0800 | [diff] [blame] | 1826 | /** |
| 1827 | * TODO(b/235886078): workaround needed because of this bug |
| 1828 | * Icons are 10% larger on XML than their visual size, so remove that extra space to get |
| 1829 | * some dimensions correct. |
| 1830 | * |
| 1831 | * When this bug is resolved this method will no longer be needed and we would be able to |
| 1832 | * replace all instances where this method is called with iconSizePx. |
| 1833 | */ |
| 1834 | private int getIconVisibleSizePx(int iconSizePx) { |
| 1835 | return Math.round(ICON_VISIBLE_AREA_FACTOR * iconSizePx); |
| 1836 | } |
| 1837 | |
Thales Lima | 9938c2f | 2022-07-25 14:38:16 +0100 | [diff] [blame] | 1838 | private int getAdditionalQsbSpace() { |
| 1839 | return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0; |
| 1840 | } |
| 1841 | |
| 1842 | /** |
| 1843 | * Calculate how much space the hotseat needs to be shown completely |
| 1844 | */ |
| 1845 | private int getHotseatRequiredWidth() { |
| 1846 | int additionalQsbSpace = getAdditionalQsbSpace(); |
| 1847 | return iconSizePx * numShownHotseatIcons |
Thales Lima | 6a59006 | 2022-11-22 15:52:49 +0000 | [diff] [blame] | 1848 | + hotseatBorderSpace * (numShownHotseatIcons - (areNavButtonsInline ? 0 : 1)) |
Thales Lima | 9938c2f | 2022-07-25 14:38:16 +0100 | [diff] [blame] | 1849 | + additionalQsbSpace; |
| 1850 | } |
| 1851 | |
Winson | fadbe8f | 2016-07-22 16:35:37 -0700 | [diff] [blame] | 1852 | /** |
Sunny Goyal | 57b2279 | 2021-05-25 14:35:01 -0700 | [diff] [blame] | 1853 | * Returns the number of pixels the QSB is translated from the bottom of the screen. |
| 1854 | */ |
| 1855 | public int getQsbOffsetY() { |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 1856 | if (isQsbInline) { |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 1857 | return getHotseatBarBottomPadding() - ((hotseatQsbHeight - hotseatCellHeightPx) / 2); |
| 1858 | } else if (isTaskbarPresent) { // QSB on top |
| 1859 | return hotseatBarSizePx - hotseatQsbHeight + hotseatQsbShadowHeight; |
Jonathan Miranda | 8f16a77 | 2021-07-23 23:10:37 +0000 | [diff] [blame] | 1860 | } else { |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 1861 | return hotseatBarBottomSpacePx - hotseatQsbShadowHeight; |
Jonathan Miranda | 7a273e2 | 2021-06-24 21:29:10 +0000 | [diff] [blame] | 1862 | } |
Sunny Goyal | 57b2279 | 2021-05-25 14:35:01 -0700 | [diff] [blame] | 1863 | } |
| 1864 | |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 1865 | /** |
| 1866 | * Returns the number of pixels the hotseat is translated from the bottom of the screen. |
| 1867 | */ |
| 1868 | private int getHotseatBarBottomPadding() { |
| 1869 | if (isTaskbarPresent) { // QSB on top or inline |
| 1870 | return hotseatBarBottomSpacePx - (Math.abs(hotseatCellHeightPx - iconSizePx) / 2); |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 1871 | } else { |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 1872 | return hotseatBarSizePx - hotseatCellHeightPx; |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 1873 | } |
Sunny Goyal | 57b2279 | 2021-05-25 14:35:01 -0700 | [diff] [blame] | 1874 | } |
| 1875 | |
| 1876 | /** |
Alex Chau | 51da219 | 2022-05-20 13:32:10 +0100 | [diff] [blame] | 1877 | * Returns the number of pixels the taskbar is translated from the bottom of the screen. |
| 1878 | */ |
| 1879 | public int getTaskbarOffsetY() { |
Jon Miranda | 9c478b6 | 2023-03-23 21:38:49 -0700 | [diff] [blame] | 1880 | int taskbarIconBottomSpace = (taskbarHeight - iconSizePx) / 2; |
Alex Chau | 51da219 | 2022-05-20 13:32:10 +0100 | [diff] [blame] | 1881 | int launcherIconBottomSpace = |
| 1882 | Math.min((hotseatCellHeightPx - iconSizePx) / 2, gridVisualizationPaddingY); |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 1883 | return getHotseatBarBottomPadding() + launcherIconBottomSpace - taskbarIconBottomSpace; |
Alex Chau | 51da219 | 2022-05-20 13:32:10 +0100 | [diff] [blame] | 1884 | } |
| 1885 | |
Uwais Ashraf | aa7fa88 | 2023-10-10 21:36:06 +0000 | [diff] [blame] | 1886 | /** Returns the number of pixels required below OverviewActions. */ |
Alex Chau | a2fc764 | 2022-04-21 14:20:23 +0100 | [diff] [blame] | 1887 | public int getOverviewActionsClaimedSpaceBelow() { |
Uwais Ashraf | aa7fa88 | 2023-10-10 21:36:06 +0000 | [diff] [blame] | 1888 | return isTaskbarPresent ? mTransientTaskbarClaimedSpace : mInsets.bottom; |
Alex Chau | a2fc764 | 2022-04-21 14:20:23 +0100 | [diff] [blame] | 1889 | } |
| 1890 | |
| 1891 | /** Gets the space that the overview actions will take, including bottom margin. */ |
| 1892 | public int getOverviewActionsClaimedSpace() { |
Alex Chau | 4989f4f | 2023-10-11 14:08:22 +0000 | [diff] [blame] | 1893 | int overviewActionsSpace = isTablet && Flags.enableGridOnlyOverview() |
Pat Manning | 7b8f766 | 2023-01-18 14:48:30 +0000 | [diff] [blame] | 1894 | ? 0 |
| 1895 | : (overviewActionsTopMarginPx + overviewActionsHeight); |
| 1896 | return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow(); |
Alex Chau | a2fc764 | 2022-04-21 14:20:23 +0100 | [diff] [blame] | 1897 | } |
| 1898 | |
| 1899 | /** |
Sihua Ma | e04aa20 | 2022-07-18 12:43:56 -0700 | [diff] [blame] | 1900 | * Takes the View and return the scales of width and height depending on the DeviceProfile |
| 1901 | * specifications |
| 1902 | * |
| 1903 | * @param itemInfo The tag of the widget view |
| 1904 | * @return A PointF instance with the x set to be the scale of width, and y being the scale of |
| 1905 | * height |
| 1906 | */ |
| 1907 | @NonNull |
| 1908 | public PointF getAppWidgetScale(@Nullable final ItemInfo itemInfo) { |
| 1909 | return mViewScaleProvider.getScaleFromItemInfo(itemInfo); |
| 1910 | } |
| 1911 | |
| 1912 | /** |
Winson | fadbe8f | 2016-07-22 16:35:37 -0700 | [diff] [blame] | 1913 | * @return the bounds for which the open folders should be contained within |
| 1914 | */ |
| 1915 | public Rect getAbsoluteOpenFolderBounds() { |
| 1916 | if (isVerticalBarLayout()) { |
| 1917 | // Folders should only appear right of the drop target bar and left of the hotseat |
| 1918 | return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx, |
| 1919 | mInsets.top, |
Jon Miranda | 18751b6 | 2017-07-31 17:25:27 -0700 | [diff] [blame] | 1920 | mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx, |
Winson | fadbe8f | 2016-07-22 16:35:37 -0700 | [diff] [blame] | 1921 | mInsets.top + availableHeightPx); |
| 1922 | } else { |
| 1923 | // Folders should only appear below the drop target bar and above the hotseat |
Jon Miranda | 9c478b6 | 2023-03-23 21:38:49 -0700 | [diff] [blame] | 1924 | int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx; |
Tony Wickham | b4b7e20 | 2018-01-12 17:39:24 -0800 | [diff] [blame] | 1925 | return new Rect(mInsets.left + edgeMarginPx, |
Winson | fadbe8f | 2016-07-22 16:35:37 -0700 | [diff] [blame] | 1926 | mInsets.top + dropTargetBarSizePx + edgeMarginPx, |
Tony Wickham | b4b7e20 | 2018-01-12 17:39:24 -0800 | [diff] [blame] | 1927 | mInsets.left + availableWidthPx - edgeMarginPx, |
Tony Wickham | ae72b46 | 2021-03-10 16:18:40 -0800 | [diff] [blame] | 1928 | mInsets.top + availableHeightPx - hotseatTop |
Tony Wickham | 5edf9e2 | 2020-03-27 20:06:52 -0700 | [diff] [blame] | 1929 | - workspacePageIndicatorHeight - edgeMarginPx); |
Winson | fadbe8f | 2016-07-22 16:35:37 -0700 | [diff] [blame] | 1930 | } |
| 1931 | } |
| 1932 | |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 1933 | public static int calculateCellWidth(int width, int borderSpacing, int countX) { |
| 1934 | return (width - ((countX - 1) * borderSpacing)) / countX; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 1935 | } |
Pierre Barbier de Reuille | 578deba | 2021-09-24 13:47:44 +0100 | [diff] [blame] | 1936 | |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 1937 | public static int calculateCellHeight(int height, int borderSpacing, int countY) { |
| 1938 | return (height - ((countY - 1) * borderSpacing)) / countY; |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 1939 | } |
| 1940 | |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 1941 | /** |
Tony Wickham | 55616cd | 2015-09-23 14:55:17 -0700 | [diff] [blame] | 1942 | * When {@code true}, the device is in landscape mode and the hotseat is on the right column. |
| 1943 | * When {@code false}, either device is in portrait mode or the device is in landscape mode and |
| 1944 | * the hotseat is on the bottom row. |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 1945 | */ |
Tony Wickham | ab946a1 | 2015-09-16 15:38:16 -0700 | [diff] [blame] | 1946 | public boolean isVerticalBarLayout() { |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 1947 | return isLandscape && transposeLayoutWithOrientation; |
| 1948 | } |
| 1949 | |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 1950 | /** |
| 1951 | * Updates orientation information and returns true if it has changed from the previous value. |
| 1952 | */ |
Winson Chung | 13c1c2c | 2019-09-06 11:46:19 -0700 | [diff] [blame] | 1953 | public boolean updateIsSeascape(Context context) { |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 1954 | if (isVerticalBarLayout()) { |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 1955 | boolean isSeascape = DisplayController.INSTANCE.get(context) |
| 1956 | .getInfo().rotation == Surface.ROTATION_270; |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 1957 | if (mIsSeascape != isSeascape) { |
| 1958 | mIsSeascape = isSeascape; |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 1959 | // Hotseat changing sides requires updating workspace left/right paddings |
| 1960 | updateWorkspacePadding(); |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 1961 | return true; |
| 1962 | } |
| 1963 | } |
| 1964 | return false; |
| 1965 | } |
| 1966 | |
Sunny Goyal | 7e2e67f | 2018-01-26 13:40:08 -0800 | [diff] [blame] | 1967 | public boolean isSeascape() { |
Sunny Goyal | 59d086c | 2018-05-07 17:31:40 -0700 | [diff] [blame] | 1968 | return isVerticalBarLayout() && mIsSeascape; |
Sunny Goyal | 7e2e67f | 2018-01-26 13:40:08 -0800 | [diff] [blame] | 1969 | } |
| 1970 | |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 1971 | public boolean shouldFadeAdjacentWorkspaceScreens() { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 1972 | return isVerticalBarLayout(); |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 1973 | } |
| 1974 | |
Jon Miranda | 92c1b5d | 2021-07-20 13:57:16 -0700 | [diff] [blame] | 1975 | public int getCellContentHeight(@ContainerType int containerType) { |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 1976 | switch (containerType) { |
| 1977 | case CellLayout.WORKSPACE: |
| 1978 | return cellHeightPx; |
| 1979 | case CellLayout.FOLDER: |
| 1980 | return folderCellHeightPx; |
| 1981 | case CellLayout.HOTSEAT: |
Jon Miranda | 92c1b5d | 2021-07-20 13:57:16 -0700 | [diff] [blame] | 1982 | // The hotseat is the only container where the cell height is going to be |
| 1983 | // different from the content within that cell. |
| 1984 | return iconSizePx; |
Sunny Goyal | c13403c | 2016-11-18 23:44:48 -0800 | [diff] [blame] | 1985 | default: |
| 1986 | // ?? |
| 1987 | return 0; |
| 1988 | } |
| 1989 | } |
Sunny Goyal | 13178ac | 2016-04-04 16:35:22 -0700 | [diff] [blame] | 1990 | |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1991 | private String pxToDpStr(String name, float value) { |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 1992 | return "\t" + name + ": " + value + "px (" + dpiFromPx(value, mMetrics.densityDpi) + "dp)"; |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 1993 | } |
| 1994 | |
Alex Chau | e818bcb | 2022-09-02 17:27:11 +0100 | [diff] [blame] | 1995 | private String dpPointFToString(String name, PointF value) { |
| 1996 | return String.format(Locale.ENGLISH, "\t%s: PointF(%.1f, %.1f)dp", name, value.x, value.y); |
| 1997 | } |
| 1998 | |
Pat Manning | 5f74bfd | 2022-07-20 12:08:54 +0100 | [diff] [blame] | 1999 | /** Dumps various DeviceProfile variables to the specified writer. */ |
| 2000 | public void dump(Context context, String prefix, PrintWriter writer) { |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2001 | writer.println(prefix + "DeviceProfile:"); |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 2002 | writer.println(prefix + "\t1 dp = " + mMetrics.density + " px"); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2003 | |
| 2004 | writer.println(prefix + "\tisTablet:" + isTablet); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2005 | writer.println(prefix + "\tisPhone:" + isPhone); |
| 2006 | writer.println(prefix + "\ttransposeLayoutWithOrientation:" |
| 2007 | + transposeLayoutWithOrientation); |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 2008 | writer.println(prefix + "\tisGestureMode:" + isGestureMode); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2009 | |
| 2010 | writer.println(prefix + "\tisLandscape:" + isLandscape); |
| 2011 | writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 2012 | writer.println(prefix + "\tisTwoPanels:" + isTwoPanels); |
Winson Chung | 104a4c8 | 2023-11-08 18:56:15 +0000 | [diff] [blame] | 2013 | writer.println(prefix + "\tisLeftRightSplit:" + isLeftRightSplit); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2014 | |
| 2015 | writer.println(prefix + pxToDpStr("windowX", windowX)); |
| 2016 | writer.println(prefix + pxToDpStr("windowY", windowY)); |
| 2017 | writer.println(prefix + pxToDpStr("widthPx", widthPx)); |
| 2018 | writer.println(prefix + pxToDpStr("heightPx", heightPx)); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2019 | writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx)); |
| 2020 | writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx)); |
Alex Chau | e022755 | 2022-04-06 19:44:43 +0100 | [diff] [blame] | 2021 | writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left)); |
| 2022 | writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top)); |
| 2023 | writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right)); |
| 2024 | writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom)); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2025 | |
| 2026 | writer.println(prefix + "\taspectRatio:" + aspectRatio); |
| 2027 | |
Thales Lima | c98b781 | 2023-04-14 15:04:23 +0100 | [diff] [blame] | 2028 | writer.println(prefix + "\tisResponsiveGrid:" + mIsResponsiveGrid); |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 2029 | writer.println(prefix + "\tisScalableGrid:" + mIsScalableGrid); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2030 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 2031 | writer.println(prefix + "\tinv.numRows: " + inv.numRows); |
Alex Chau | 9fee3fd | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 2032 | writer.println(prefix + "\tinv.numColumns: " + inv.numColumns); |
| 2033 | writer.println(prefix + "\tinv.numSearchContainerColumns: " |
| 2034 | + inv.numSearchContainerColumns); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2035 | |
Alex Chau | e818bcb | 2022-09-02 17:27:11 +0100 | [diff] [blame] | 2036 | writer.println(prefix + dpPointFToString("minCellSize", inv.minCellSize[mTypeIndex])); |
Jon Miranda | ab3c681 | 2021-06-28 15:42:28 -0700 | [diff] [blame] | 2037 | |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2038 | writer.println(prefix + pxToDpStr("cellWidthPx", cellWidthPx)); |
| 2039 | writer.println(prefix + pxToDpStr("cellHeightPx", cellHeightPx)); |
| 2040 | |
| 2041 | writer.println(prefix + pxToDpStr("getCellSize().x", getCellSize().x)); |
| 2042 | writer.println(prefix + pxToDpStr("getCellSize().y", getCellSize().y)); |
| 2043 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 2044 | writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Horizontal", |
| 2045 | cellLayoutBorderSpacePx.x)); |
| 2046 | writer.println(prefix + pxToDpStr("cellLayoutBorderSpacePx Vertical", |
| 2047 | cellLayoutBorderSpacePx.y)); |
Pat Manning | 5f74bfd | 2022-07-20 12:08:54 +0100 | [diff] [blame] | 2048 | writer.println( |
| 2049 | prefix + pxToDpStr("cellLayoutPaddingPx.left", cellLayoutPaddingPx.left)); |
| 2050 | writer.println( |
| 2051 | prefix + pxToDpStr("cellLayoutPaddingPx.top", cellLayoutPaddingPx.top)); |
| 2052 | writer.println( |
| 2053 | prefix + pxToDpStr("cellLayoutPaddingPx.right", cellLayoutPaddingPx.right)); |
Pat Manning | 08610ca | 2022-04-05 21:03:16 +0100 | [diff] [blame] | 2054 | writer.println( |
| 2055 | prefix + pxToDpStr("cellLayoutPaddingPx.bottom", cellLayoutPaddingPx.bottom)); |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 2056 | |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2057 | writer.println(prefix + pxToDpStr("iconSizePx", iconSizePx)); |
| 2058 | writer.println(prefix + pxToDpStr("iconTextSizePx", iconTextSizePx)); |
| 2059 | writer.println(prefix + pxToDpStr("iconDrawablePaddingPx", iconDrawablePaddingPx)); |
| 2060 | |
Thales Lima | 1faa4ed | 2023-12-01 16:48:19 +0000 | [diff] [blame] | 2061 | writer.println(prefix + "\tnumFolderRows: " + numFolderRows); |
| 2062 | writer.println(prefix + "\tnumFolderColumns: " + numFolderColumns); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2063 | writer.println(prefix + pxToDpStr("folderCellWidthPx", folderCellWidthPx)); |
| 2064 | writer.println(prefix + pxToDpStr("folderCellHeightPx", folderCellHeightPx)); |
| 2065 | writer.println(prefix + pxToDpStr("folderChildIconSizePx", folderChildIconSizePx)); |
| 2066 | writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx)); |
| 2067 | writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx", |
| 2068 | folderChildDrawablePaddingPx)); |
Jordan Silva | 637f4eb | 2023-06-13 11:21:53 +0100 | [diff] [blame] | 2069 | writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.x", |
| 2070 | folderCellLayoutBorderSpacePx.x)); |
| 2071 | writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacePx.y", |
| 2072 | folderCellLayoutBorderSpacePx.y)); |
Thales Lima | a08a443 | 2022-08-09 09:55:17 +0100 | [diff] [blame] | 2073 | writer.println(prefix + pxToDpStr("folderContentPaddingLeftRight", |
| 2074 | folderContentPaddingLeftRight)); |
| 2075 | writer.println(prefix + pxToDpStr("folderTopPadding", folderContentPaddingTop)); |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 2076 | writer.println(prefix + pxToDpStr("folderFooterHeight", folderFooterHeightPx)); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2077 | |
Alex Chau | e022755 | 2022-04-06 19:44:43 +0100 | [diff] [blame] | 2078 | writer.println(prefix + pxToDpStr("bottomSheetTopPadding", bottomSheetTopPadding)); |
Alex Chau | 3d2c062 | 2022-09-01 21:28:14 +0100 | [diff] [blame] | 2079 | writer.println(prefix + "\tbottomSheetOpenDuration: " + bottomSheetOpenDuration); |
| 2080 | writer.println(prefix + "\tbottomSheetCloseDuration: " + bottomSheetCloseDuration); |
| 2081 | writer.println(prefix + "\tbottomSheetWorkspaceScale: " + bottomSheetWorkspaceScale); |
| 2082 | writer.println(prefix + "\tbottomSheetDepth: " + bottomSheetDepth); |
Alex Chau | e022755 | 2022-04-06 19:44:43 +0100 | [diff] [blame] | 2083 | |
| 2084 | writer.println(prefix + pxToDpStr("allAppsShiftRange", allAppsShiftRange)); |
Alex Chau | 3d2c062 | 2022-09-01 21:28:14 +0100 | [diff] [blame] | 2085 | writer.println(prefix + "\tallAppsOpenDuration: " + allAppsOpenDuration); |
| 2086 | writer.println(prefix + "\tallAppsCloseDuration: " + allAppsCloseDuration); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2087 | writer.println(prefix + pxToDpStr("allAppsIconSizePx", allAppsIconSizePx)); |
| 2088 | writer.println(prefix + pxToDpStr("allAppsIconTextSizePx", allAppsIconTextSizePx)); |
| 2089 | writer.println(prefix + pxToDpStr("allAppsIconDrawablePaddingPx", |
| 2090 | allAppsIconDrawablePaddingPx)); |
| 2091 | writer.println(prefix + pxToDpStr("allAppsCellHeightPx", allAppsCellHeightPx)); |
Alex Chau | 27b39b9 | 2022-01-14 18:02:18 +0000 | [diff] [blame] | 2092 | writer.println(prefix + pxToDpStr("allAppsCellWidthPx", allAppsCellWidthPx)); |
Pat Manning | 26f70f7 | 2022-07-07 13:50:39 +0100 | [diff] [blame] | 2093 | writer.println(prefix + pxToDpStr("allAppsBorderSpacePxX", allAppsBorderSpacePx.x)); |
| 2094 | writer.println(prefix + pxToDpStr("allAppsBorderSpacePxY", allAppsBorderSpacePx.y)); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 2095 | writer.println(prefix + "\tnumShownAllAppsColumns: " + numShownAllAppsColumns); |
Thales Lima | b433c9c | 2023-10-30 12:24:05 +0000 | [diff] [blame] | 2096 | writer.println(prefix + pxToDpStr("allAppsPadding.top", allAppsPadding.top)); |
| 2097 | writer.println(prefix + pxToDpStr("allAppsPadding.left", allAppsPadding.left)); |
| 2098 | writer.println(prefix + pxToDpStr("allAppsPadding.right", allAppsPadding.right)); |
Alex Chau | 27b39b9 | 2022-01-14 18:02:18 +0000 | [diff] [blame] | 2099 | writer.println(prefix + pxToDpStr("allAppsLeftRightMargin", allAppsLeftRightMargin)); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2100 | |
| 2101 | writer.println(prefix + pxToDpStr("hotseatBarSizePx", hotseatBarSizePx)); |
Thales Lima | 425f682 | 2022-05-10 13:44:58 -0300 | [diff] [blame] | 2102 | writer.println(prefix + "\tinv.hotseatColumnSpan: " + inv.hotseatColumnSpan[mTypeIndex]); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2103 | writer.println(prefix + pxToDpStr("hotseatCellHeightPx", hotseatCellHeightPx)); |
Alex Chau | 62572c0 | 2022-07-25 18:36:37 +0000 | [diff] [blame] | 2104 | writer.println(prefix + pxToDpStr("hotseatBarBottomSpacePx", hotseatBarBottomSpacePx)); |
Thales Lima | 8e11d53 | 2023-08-31 13:40:26 +0000 | [diff] [blame] | 2105 | writer.println(prefix + pxToDpStr("mHotseatBarEdgePaddingPx", |
| 2106 | mHotseatBarEdgePaddingPx)); |
| 2107 | writer.println(prefix + pxToDpStr("mHotseatBarWorkspaceSpacePx", |
| 2108 | mHotseatBarWorkspaceSpacePx)); |
Pat Manning | 26f70f7 | 2022-07-07 13:50:39 +0100 | [diff] [blame] | 2109 | writer.println(prefix + pxToDpStr("hotseatBarEndOffset", hotseatBarEndOffset)); |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 2110 | writer.println(prefix + pxToDpStr("hotseatQsbSpace", hotseatQsbSpace)); |
| 2111 | writer.println(prefix + pxToDpStr("hotseatQsbHeight", hotseatQsbHeight)); |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 2112 | writer.println(prefix + pxToDpStr("springLoadedHotseatBarTopMarginPx", |
| 2113 | springLoadedHotseatBarTopMarginPx)); |
Pat Manning | 5f74bfd | 2022-07-20 12:08:54 +0100 | [diff] [blame] | 2114 | Rect hotseatLayoutPadding = getHotseatLayoutPadding(context); |
| 2115 | writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).top", |
| 2116 | hotseatLayoutPadding.top)); |
| 2117 | writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).bottom", |
| 2118 | hotseatLayoutPadding.bottom)); |
| 2119 | writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).left", |
| 2120 | hotseatLayoutPadding.left)); |
| 2121 | writer.println(prefix + pxToDpStr("getHotseatLayoutPadding(context).right", |
| 2122 | hotseatLayoutPadding.right)); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 2123 | writer.println(prefix + "\tnumShownHotseatIcons: " + numShownHotseatIcons); |
Thales Lima | 116b51a | 2022-02-03 16:19:47 +0000 | [diff] [blame] | 2124 | writer.println(prefix + pxToDpStr("hotseatBorderSpace", hotseatBorderSpace)); |
Thales Lima | a101290 | 2022-01-13 17:58:42 +0000 | [diff] [blame] | 2125 | writer.println(prefix + "\tisQsbInline: " + isQsbInline); |
Alex Chau | 206ede9 | 2022-08-01 17:46:12 +0100 | [diff] [blame] | 2126 | writer.println(prefix + pxToDpStr("hotseatQsbWidth", hotseatQsbWidth)); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2127 | |
| 2128 | writer.println(prefix + "\tisTaskbarPresent:" + isTaskbarPresent); |
Tony Wickham | 635e180 | 2021-07-22 14:28:04 -1000 | [diff] [blame] | 2129 | writer.println(prefix + "\tisTaskbarPresentInApps:" + isTaskbarPresentInApps); |
Jon Miranda | 9c478b6 | 2023-03-23 21:38:49 -0700 | [diff] [blame] | 2130 | writer.println(prefix + pxToDpStr("taskbarHeight", taskbarHeight)); |
| 2131 | writer.println(prefix + pxToDpStr("stashedTaskbarHeight", stashedTaskbarHeight)); |
| 2132 | writer.println(prefix + pxToDpStr("taskbarBottomMargin", taskbarBottomMargin)); |
| 2133 | writer.println(prefix + pxToDpStr("taskbarIconSize", taskbarIconSize)); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2134 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 2135 | writer.println(prefix + pxToDpStr("desiredWorkspaceHorizontalMarginPx", |
| 2136 | desiredWorkspaceHorizontalMarginPx)); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2137 | writer.println(prefix + pxToDpStr("workspacePadding.left", workspacePadding.left)); |
| 2138 | writer.println(prefix + pxToDpStr("workspacePadding.top", workspacePadding.top)); |
| 2139 | writer.println(prefix + pxToDpStr("workspacePadding.right", workspacePadding.right)); |
Alex Chau | 62572c0 | 2022-07-25 18:36:37 +0000 | [diff] [blame] | 2140 | writer.println(prefix + pxToDpStr("workspacePadding.bottom", workspacePadding.bottom)); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2141 | |
Jon Miranda | ab3c681 | 2021-06-28 15:42:28 -0700 | [diff] [blame] | 2142 | writer.println(prefix + pxToDpStr("iconScale", iconScale)); |
| 2143 | writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit)); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2144 | writer.println(prefix + pxToDpStr("extraSpace", extraSpace)); |
Alex Chau | 62572c0 | 2022-07-25 18:36:37 +0000 | [diff] [blame] | 2145 | writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale)); |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 2146 | |
Thales Lima | 171ee66 | 2022-11-22 15:52:49 +0000 | [diff] [blame] | 2147 | writer.println(prefix + pxToDpStr("maxEmptySpace", maxEmptySpace)); |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2148 | writer.println(prefix + pxToDpStr("workspaceTopPadding", workspaceTopPadding)); |
| 2149 | writer.println(prefix + pxToDpStr("workspaceBottomPadding", workspaceBottomPadding)); |
Alex Chau | 635b3ab | 2022-01-26 16:49:10 +0000 | [diff] [blame] | 2150 | |
| 2151 | writer.println(prefix + pxToDpStr("overviewTaskMarginPx", overviewTaskMarginPx)); |
Alex Chau | 635b3ab | 2022-01-26 16:49:10 +0000 | [diff] [blame] | 2152 | writer.println(prefix + pxToDpStr("overviewTaskIconSizePx", overviewTaskIconSizePx)); |
| 2153 | writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizePx", |
| 2154 | overviewTaskIconDrawableSizePx)); |
| 2155 | writer.println(prefix + pxToDpStr("overviewTaskIconDrawableSizeGridPx", |
| 2156 | overviewTaskIconDrawableSizeGridPx)); |
Pat Manning | 1695cc7 | 2023-07-05 11:45:13 +0100 | [diff] [blame] | 2157 | writer.println(prefix + pxToDpStr("overviewTaskIconAppChipMenuDrawableSizePx", |
| 2158 | overviewTaskIconAppChipMenuDrawableSizePx)); |
Alex Chau | 635b3ab | 2022-01-26 16:49:10 +0000 | [diff] [blame] | 2159 | writer.println(prefix + pxToDpStr("overviewTaskThumbnailTopMarginPx", |
| 2160 | overviewTaskThumbnailTopMarginPx)); |
Alex Chau | a2fc764 | 2022-04-21 14:20:23 +0100 | [diff] [blame] | 2161 | writer.println(prefix + pxToDpStr("overviewActionsTopMarginPx", |
| 2162 | overviewActionsTopMarginPx)); |
| 2163 | writer.println(prefix + pxToDpStr("overviewActionsHeight", |
| 2164 | overviewActionsHeight)); |
Alex Chau | 1b276a1 | 2022-12-19 14:01:36 +0000 | [diff] [blame] | 2165 | writer.println(prefix + pxToDpStr("overviewActionsClaimedSpaceBelow", |
| 2166 | getOverviewActionsClaimedSpaceBelow())); |
Alex Chau | 635b3ab | 2022-01-26 16:49:10 +0000 | [diff] [blame] | 2167 | writer.println(prefix + pxToDpStr("overviewActionsButtonSpacing", |
| 2168 | overviewActionsButtonSpacing)); |
| 2169 | writer.println(prefix + pxToDpStr("overviewPageSpacing", overviewPageSpacing)); |
| 2170 | writer.println(prefix + pxToDpStr("overviewRowSpacing", overviewRowSpacing)); |
| 2171 | writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin)); |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 2172 | |
Alex Chau | 62572c0 | 2022-07-25 18:36:37 +0000 | [diff] [blame] | 2173 | writer.println(prefix + pxToDpStr("dropTargetBarTopMarginPx", dropTargetBarTopMarginPx)); |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 2174 | writer.println(prefix + pxToDpStr("dropTargetBarSizePx", dropTargetBarSizePx)); |
Alex Chau | 62572c0 | 2022-07-25 18:36:37 +0000 | [diff] [blame] | 2175 | writer.println( |
| 2176 | prefix + pxToDpStr("dropTargetBarBottomMarginPx", dropTargetBarBottomMarginPx)); |
Pat Manning | de25c0d | 2022-04-05 19:11:26 +0100 | [diff] [blame] | 2177 | |
Pat Manning | 5f74bfd | 2022-07-20 12:08:54 +0100 | [diff] [blame] | 2178 | writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkTop()", |
| 2179 | getCellLayoutSpringLoadShrunkTop())); |
| 2180 | writer.println(prefix + pxToDpStr("getCellLayoutSpringLoadShrunkBottom()", |
| 2181 | getCellLayoutSpringLoadShrunkBottom(context))); |
Alex Chau | 906d882 | 2022-05-23 10:42:25 +0100 | [diff] [blame] | 2182 | writer.println(prefix + pxToDpStr("workspaceSpringLoadedMinNextPageVisiblePx", |
| 2183 | workspaceSpringLoadedMinNextPageVisiblePx)); |
Pat Manning | 5f74bfd | 2022-07-20 12:08:54 +0100 | [diff] [blame] | 2184 | writer.println(prefix + pxToDpStr("getWorkspaceSpringLoadScale()", |
| 2185 | getWorkspaceSpringLoadScale(context))); |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 2186 | writer.println(prefix + pxToDpStr("getCellLayoutHeight()", getCellLayoutHeight())); |
| 2187 | writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth())); |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 2188 | if (mIsResponsiveGrid) { |
Jordan Silva | 8f7986a | 2023-11-08 12:11:25 +0000 | [diff] [blame] | 2189 | writer.println(prefix + "\tmResponsiveWorkspaceHeightSpec:" |
| 2190 | + mResponsiveWorkspaceHeightSpec.toString()); |
| 2191 | writer.println(prefix + "\tmResponsiveWorkspaceWidthSpec:" |
| 2192 | + mResponsiveWorkspaceWidthSpec.toString()); |
| 2193 | writer.println(prefix + "\tmResponsiveAllAppsHeightSpec:" |
| 2194 | + mResponsiveAllAppsHeightSpec.toString()); |
| 2195 | writer.println(prefix + "\tmResponsiveAllAppsWidthSpec:" |
| 2196 | + mResponsiveAllAppsWidthSpec.toString()); |
Jordan Silva | 637f4eb | 2023-06-13 11:21:53 +0100 | [diff] [blame] | 2197 | writer.println(prefix + "\tmResponsiveFolderHeightSpec:" + mResponsiveFolderHeightSpec); |
| 2198 | writer.println(prefix + "\tmResponsiveFolderWidthSpec:" + mResponsiveFolderWidthSpec); |
Thales Lima | f8bfb03 | 2023-07-24 15:08:05 +0100 | [diff] [blame] | 2199 | writer.println(prefix + "\tmResponsiveHotseatSpec:" + mResponsiveHotseatSpec); |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 2200 | writer.println(prefix + "\tmResponsiveWorkspaceCellSpec:" |
| 2201 | + mResponsiveWorkspaceCellSpec); |
| 2202 | writer.println(prefix + "\tmResponsiveAllAppsCellSpec:" + mResponsiveAllAppsCellSpec); |
Thales Lima | 7945649 | 2023-05-23 11:32:22 +0100 | [diff] [blame] | 2203 | } |
Jon Miranda | 58561d4 | 2021-03-17 10:51:54 -0400 | [diff] [blame] | 2204 | } |
| 2205 | |
Nicolo' Mazzucato | cb7bd50 | 2023-01-16 19:46:30 +0000 | [diff] [blame] | 2206 | /** Returns a reduced representation of this DeviceProfile. */ |
| 2207 | public String toSmallString() { |
| 2208 | return "isTablet:" + isTablet + ", " |
| 2209 | + "isMultiDisplay:" + isMultiDisplay + ", " |
| 2210 | + "widthPx:" + widthPx + ", " |
| 2211 | + "heightPx:" + heightPx + ", " |
| 2212 | + "insets:" + mInsets + ", " |
| 2213 | + "rotationHint:" + rotationHint; |
| 2214 | } |
| 2215 | |
Alex Chau | a6907dc | 2022-03-18 15:24:07 +0000 | [diff] [blame] | 2216 | private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) { |
Sunny Goyal | 1890f67 | 2020-04-30 12:28:00 -0700 | [diff] [blame] | 2217 | Configuration config = new Configuration(c.getResources().getConfiguration()); |
| 2218 | config.orientation = orientation; |
Thales Lima | 425f682 | 2022-05-10 13:44:58 -0300 | [diff] [blame] | 2219 | config.densityDpi = info.getDensityDpi(); |
Alex Chau | a6907dc | 2022-03-18 15:24:07 +0000 | [diff] [blame] | 2220 | config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds); |
Sunny Goyal | 1890f67 | 2020-04-30 12:28:00 -0700 | [diff] [blame] | 2221 | return c.createConfigurationContext(config); |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 2222 | } |
Sunny Goyal | fde5505 | 2018-02-01 14:46:13 -0800 | [diff] [blame] | 2223 | |
| 2224 | /** |
| 2225 | * Callback when a component changes the DeviceProfile associated with it, as a result of |
| 2226 | * configuration change |
| 2227 | */ |
| 2228 | public interface OnDeviceProfileChangeListener { |
| 2229 | |
| 2230 | /** |
| 2231 | * Called when the device profile is reassigned. Note that for layout and measurements, it |
| 2232 | * is sufficient to listen for inset changes. Use this callback when you need to perform |
| 2233 | * a one time operation. |
| 2234 | */ |
| 2235 | void onDeviceProfileChanged(DeviceProfile dp); |
| 2236 | } |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 2237 | |
Sihua Ma | e04aa20 | 2022-07-18 12:43:56 -0700 | [diff] [blame] | 2238 | /** |
| 2239 | * Handler that deals with ItemInfo of the views for the DeviceProfile |
| 2240 | */ |
| 2241 | @FunctionalInterface |
| 2242 | public interface ViewScaleProvider { |
| 2243 | /** |
| 2244 | * Get the scales from the view |
| 2245 | * |
| 2246 | * @param itemInfo The tag of the widget view |
| 2247 | * @return PointF instance containing the scale information, or null if using the default |
| 2248 | * app widget scale of this device profile. |
| 2249 | */ |
| 2250 | @NonNull |
| 2251 | PointF getScaleFromItemInfo(@Nullable ItemInfo itemInfo); |
| 2252 | } |
| 2253 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 2254 | public static class Builder { |
| 2255 | private Context mContext; |
| 2256 | private InvariantDeviceProfile mInv; |
Sunny Goyal | fd58da6 | 2020-08-11 12:06:49 -0700 | [diff] [blame] | 2257 | private Info mInfo; |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 2258 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 2259 | private WindowBounds mWindowBounds; |
Alex Chau | ab800f7 | 2022-12-13 17:46:06 +0000 | [diff] [blame] | 2260 | private boolean mIsMultiDisplay; |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 2261 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 2262 | private boolean mIsMultiWindowMode = false; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 2263 | private Boolean mTransposeLayoutWithOrientation; |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 2264 | private Boolean mIsGestureMode; |
Sihua Ma | e04aa20 | 2022-07-18 12:43:56 -0700 | [diff] [blame] | 2265 | private ViewScaleProvider mViewScaleProvider = null; |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 2266 | |
Sunny Goyal | 65190ae | 2022-08-02 14:16:26 -0700 | [diff] [blame] | 2267 | private SparseArray<DotRenderer> mDotRendererCache; |
| 2268 | |
Jon Miranda | 2b25ded | 2023-02-02 14:48:45 -0800 | [diff] [blame] | 2269 | private Consumer<DeviceProfile> mOverrideProvider; |
| 2270 | |
Jagrut Desai | 3a7d139 | 2023-09-06 15:56:19 -0700 | [diff] [blame] | 2271 | private boolean mIsTransientTaskbar; |
| 2272 | |
Sunny Goyal | fd58da6 | 2020-08-11 12:06:49 -0700 | [diff] [blame] | 2273 | public Builder(Context context, InvariantDeviceProfile inv, Info info) { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 2274 | mContext = context; |
| 2275 | mInv = inv; |
| 2276 | mInfo = info; |
Jagrut Desai | 3a7d139 | 2023-09-06 15:56:19 -0700 | [diff] [blame] | 2277 | mIsTransientTaskbar = info.isTransientTaskbar(); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 2278 | } |
| 2279 | |
| 2280 | public Builder setMultiWindowMode(boolean isMultiWindowMode) { |
| 2281 | mIsMultiWindowMode = isMultiWindowMode; |
| 2282 | return this; |
| 2283 | } |
| 2284 | |
Alex Chau | ab800f7 | 2022-12-13 17:46:06 +0000 | [diff] [blame] | 2285 | public Builder setIsMultiDisplay(boolean isMultiDisplay) { |
| 2286 | mIsMultiDisplay = isMultiDisplay; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 2287 | return this; |
| 2288 | } |
| 2289 | |
Sunny Goyal | 65190ae | 2022-08-02 14:16:26 -0700 | [diff] [blame] | 2290 | public Builder setDotRendererCache(SparseArray<DotRenderer> dotRendererCache) { |
| 2291 | mDotRendererCache = dotRendererCache; |
| 2292 | return this; |
| 2293 | } |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 2294 | |
| 2295 | public Builder setWindowBounds(WindowBounds bounds) { |
| 2296 | mWindowBounds = bounds; |
Sunny Goyal | 0addbf0 | 2020-04-28 14:17:35 -0700 | [diff] [blame] | 2297 | return this; |
| 2298 | } |
| 2299 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 2300 | public Builder setTransposeLayoutWithOrientation(boolean transposeLayoutWithOrientation) { |
| 2301 | mTransposeLayoutWithOrientation = transposeLayoutWithOrientation; |
| 2302 | return this; |
| 2303 | } |
| 2304 | |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 2305 | public Builder setGestureMode(boolean isGestureMode) { |
| 2306 | mIsGestureMode = isGestureMode; |
| 2307 | return this; |
| 2308 | } |
| 2309 | |
Jon Miranda | 2b25ded | 2023-02-02 14:48:45 -0800 | [diff] [blame] | 2310 | public Builder withDimensionsOverride(Consumer<DeviceProfile> overrideProvider) { |
| 2311 | mOverrideProvider = overrideProvider; |
| 2312 | return this; |
| 2313 | } |
| 2314 | |
Sihua Ma | e04aa20 | 2022-07-18 12:43:56 -0700 | [diff] [blame] | 2315 | /** |
| 2316 | * Set the viewScaleProvider for the builder |
| 2317 | * |
| 2318 | * @param viewScaleProvider The viewScaleProvider to be set for the |
Thales Lima | e9273ea | 2023-01-26 12:33:52 +0000 | [diff] [blame] | 2319 | * DeviceProfile |
Sihua Ma | e04aa20 | 2022-07-18 12:43:56 -0700 | [diff] [blame] | 2320 | * @return This builder |
| 2321 | */ |
| 2322 | @NonNull |
| 2323 | public Builder setViewScaleProvider(@Nullable ViewScaleProvider viewScaleProvider) { |
| 2324 | mViewScaleProvider = viewScaleProvider; |
| 2325 | return this; |
| 2326 | } |
| 2327 | |
Jagrut Desai | 3a7d139 | 2023-09-06 15:56:19 -0700 | [diff] [blame] | 2328 | /** |
| 2329 | * Set the isTransientTaskbar for the builder |
| 2330 | * @return This Builder |
| 2331 | */ |
| 2332 | public Builder setIsTransientTaskbar(boolean isTransientTaskbar) { |
| 2333 | mIsTransientTaskbar = isTransientTaskbar; |
| 2334 | return this; |
| 2335 | } |
| 2336 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 2337 | public DeviceProfile build() { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 2338 | if (mWindowBounds == null) { |
| 2339 | throw new IllegalArgumentException("Window bounds not set"); |
| 2340 | } |
| 2341 | if (mTransposeLayoutWithOrientation == null) { |
| 2342 | mTransposeLayoutWithOrientation = !mInfo.isTablet(mWindowBounds); |
| 2343 | } |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 2344 | if (mIsGestureMode == null) { |
Alex Chau | e818bcb | 2022-09-02 17:27:11 +0100 | [diff] [blame] | 2345 | mIsGestureMode = mInfo.navigationMode.hasGestures; |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 2346 | } |
Sunny Goyal | 65190ae | 2022-08-02 14:16:26 -0700 | [diff] [blame] | 2347 | if (mDotRendererCache == null) { |
| 2348 | mDotRendererCache = new SparseArray<>(); |
| 2349 | } |
Sihua Ma | e04aa20 | 2022-07-18 12:43:56 -0700 | [diff] [blame] | 2350 | if (mViewScaleProvider == null) { |
| 2351 | mViewScaleProvider = DEFAULT_PROVIDER; |
| 2352 | } |
Jon Miranda | 2b25ded | 2023-02-02 14:48:45 -0800 | [diff] [blame] | 2353 | if (mOverrideProvider == null) { |
| 2354 | mOverrideProvider = DEFAULT_DIMENSION_PROVIDER; |
| 2355 | } |
Sunny Goyal | 65190ae | 2022-08-02 14:16:26 -0700 | [diff] [blame] | 2356 | return new DeviceProfile(mContext, mInv, mInfo, mWindowBounds, mDotRendererCache, |
Alex Chau | ab800f7 | 2022-12-13 17:46:06 +0000 | [diff] [blame] | 2357 | mIsMultiWindowMode, mTransposeLayoutWithOrientation, mIsMultiDisplay, |
Jagrut Desai | 3a7d139 | 2023-09-06 15:56:19 -0700 | [diff] [blame] | 2358 | mIsGestureMode, mViewScaleProvider, mOverrideProvider, mIsTransientTaskbar); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 2359 | } |
| 2360 | } |
Winson Chung | b380024 | 2013-10-24 11:01:54 -0700 | [diff] [blame] | 2361 | } |