Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 1 | /* |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame] | 2 | * Copyright (C) 2021 The Android Open Source Project |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 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 | |
Sebastian Franco | 9e4c99b | 2024-10-02 15:16:37 -0700 | [diff] [blame] | 19 | import static com.android.launcher3.LauncherPrefs.FIXED_LANDSCAPE_MODE; |
Stefan Andonian | 4c9612b | 2023-02-22 00:00:03 +0000 | [diff] [blame] | 20 | import static com.android.launcher3.LauncherPrefs.GRID_NAME; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 21 | import static com.android.launcher3.Utilities.dpiFromPx; |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 22 | import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURCE_HANDLE; |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 23 | import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY; |
Jagrut Desai | 2e8ca87 | 2024-04-17 15:27:30 -0700 | [diff] [blame] | 24 | import static com.android.launcher3.util.DisplayController.CHANGE_DESKTOP_MODE; |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 25 | import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 26 | import static com.android.launcher3.util.DisplayController.CHANGE_SUPPORTED_BOUNDS; |
Jagrut Desai | 3a7d139 | 2023-09-06 15:56:19 -0700 | [diff] [blame] | 27 | import static com.android.launcher3.util.DisplayController.CHANGE_TASKBAR_PINNING; |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 28 | import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 29 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 30 | import android.annotation.TargetApi; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 31 | import android.content.Context; |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 32 | import android.content.res.Resources; |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 33 | import android.content.res.TypedArray; |
| 34 | import android.content.res.XmlResourceParser; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 35 | import android.graphics.Point; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 36 | import android.graphics.PointF; |
Alex Chau | c09a98a | 2023-11-14 12:51:42 +0000 | [diff] [blame] | 37 | import android.graphics.Rect; |
Brandon Dayauon | 51db65e | 2024-10-23 15:07:37 -0700 | [diff] [blame] | 38 | import android.os.Trace; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 39 | import android.text.TextUtils; |
| 40 | import android.util.AttributeSet; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 41 | import android.util.DisplayMetrics; |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 42 | import android.util.Log; |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 43 | import android.util.SparseArray; |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 44 | import android.util.Xml; |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 45 | import android.view.Display; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 46 | |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 47 | import androidx.annotation.DimenRes; |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 48 | import androidx.annotation.IntDef; |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 49 | import androidx.annotation.StyleRes; |
Sunny Goyal | 6fe3eec | 2019-08-15 14:53:41 -0700 | [diff] [blame] | 50 | import androidx.annotation.VisibleForTesting; |
Thales Lima | ae0d7ef | 2022-11-16 15:53:43 +0000 | [diff] [blame] | 51 | import androidx.annotation.XmlRes; |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 52 | import androidx.core.content.res.ResourcesCompat; |
Sunny Goyal | 6fe3eec | 2019-08-15 14:53:41 -0700 | [diff] [blame] | 53 | |
Thales Lima | ec5abba | 2023-04-05 16:33:50 +0100 | [diff] [blame] | 54 | import com.android.launcher3.config.FeatureFlags; |
Sunny Goyal | 65190ae | 2022-08-02 14:16:26 -0700 | [diff] [blame] | 55 | import com.android.launcher3.icons.DotRenderer; |
Sunny Goyal | 68031ca | 2021-08-02 12:23:44 -0700 | [diff] [blame] | 56 | import com.android.launcher3.model.DeviceGridState; |
Alex Chau | 238aaee | 2021-10-06 16:15:24 +0100 | [diff] [blame] | 57 | import com.android.launcher3.provider.RestoreDbTask; |
vadimt | f6ef879 | 2022-07-26 13:54:31 -0700 | [diff] [blame] | 58 | import com.android.launcher3.testing.shared.ResourceUtils; |
Sunny Goyal | fd58da6 | 2020-08-11 12:06:49 -0700 | [diff] [blame] | 59 | import com.android.launcher3.util.DisplayController; |
| 60 | import com.android.launcher3.util.DisplayController.Info; |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 61 | import com.android.launcher3.util.MainThreadInitializedObject; |
Sunny Goyal | 3e58eea | 2022-11-14 14:30:07 -0800 | [diff] [blame] | 62 | import com.android.launcher3.util.Partner; |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 63 | import com.android.launcher3.util.ResourceHelper; |
Sunny Goyal | 10fa016 | 2024-04-21 00:13:35 -0700 | [diff] [blame] | 64 | import com.android.launcher3.util.SafeCloseable; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 65 | import com.android.launcher3.util.WindowBounds; |
Sunny Goyal | 187b16c | 2022-03-01 16:53:23 -0800 | [diff] [blame] | 66 | import com.android.launcher3.util.window.WindowManagerProxy; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 67 | |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 68 | import org.xmlpull.v1.XmlPullParser; |
| 69 | import org.xmlpull.v1.XmlPullParserException; |
| 70 | |
| 71 | import java.io.IOException; |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 72 | import java.lang.annotation.Retention; |
| 73 | import java.lang.annotation.RetentionPolicy; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 74 | import java.util.ArrayList; |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 75 | import java.util.Arrays; |
Sunny Goyal | 6d55f66 | 2019-01-02 12:13:43 -0800 | [diff] [blame] | 76 | import java.util.Collections; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 77 | import java.util.List; |
Sebastián Franco | ad46eb7 | 2024-03-11 20:56:57 +0000 | [diff] [blame] | 78 | import java.util.Objects; |
Sunny Goyal | 076e04b | 2023-04-03 12:38:30 -0700 | [diff] [blame] | 79 | import java.util.stream.Collectors; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 80 | |
Sunny Goyal | 10fa016 | 2024-04-21 00:13:35 -0700 | [diff] [blame] | 81 | public class InvariantDeviceProfile implements SafeCloseable { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 82 | |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 83 | public static final String TAG = "IDP"; |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 84 | // We do not need any synchronization for this variable as its only written on UI thread. |
| 85 | public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE = |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 86 | new MainThreadInitializedObject<>(InvariantDeviceProfile::new); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 87 | |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 88 | @Retention(RetentionPolicy.SOURCE) |
| 89 | @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET}) |
Sebastian Franco | 9e4c99b | 2024-10-02 15:16:37 -0700 | [diff] [blame] | 90 | public @interface DeviceType { |
| 91 | } |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 92 | |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 93 | public static final int TYPE_PHONE = 0; |
| 94 | public static final int TYPE_MULTI_DISPLAY = 1; |
| 95 | public static final int TYPE_TABLET = 2; |
| 96 | |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 97 | private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48; |
| 98 | |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 99 | // Constants that affects the interpolation curve between statically defined device profile |
| 100 | // buckets. |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 101 | private static final float KNEARESTNEIGHBOR = 3; |
| 102 | private static final float WEIGHT_POWER = 5; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 103 | |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 104 | // used to offset float not being able to express extremely small weights in extreme cases. |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 105 | private static final float WEIGHT_EFFICIENT = 100000f; |
| 106 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 107 | // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different |
| 108 | // constraints |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 109 | static final int COUNT_SIZES = 4; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 110 | static final int INDEX_DEFAULT = 0; |
| 111 | static final int INDEX_LANDSCAPE = 1; |
| 112 | static final int INDEX_TWO_PANEL_PORTRAIT = 2; |
| 113 | static final int INDEX_TWO_PANEL_LANDSCAPE = 3; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 114 | |
Thales Lima | ec5abba | 2023-04-05 16:33:50 +0100 | [diff] [blame] | 115 | /** These resources are used to override the device profile */ |
Sunny Goyal | 3e58eea | 2022-11-14 14:30:07 -0800 | [diff] [blame] | 116 | private static final String RES_GRID_NUM_ROWS = "grid_num_rows"; |
| 117 | private static final String RES_GRID_NUM_COLUMNS = "grid_num_columns"; |
| 118 | private static final String RES_GRID_ICON_SIZE_DP = "grid_icon_size_dp"; |
| 119 | |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 120 | /** |
| 121 | * Number of icons per row and column in the workspace. |
| 122 | */ |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 123 | public int numRows; |
| 124 | public int numColumns; |
Alex Chau | 9fee3fd | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 125 | public int numSearchContainerColumns; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 126 | |
| 127 | /** |
| 128 | * Number of icons per row and column in the folder. |
| 129 | */ |
Thales Lima | 1faa4ed | 2023-12-01 16:48:19 +0000 | [diff] [blame] | 130 | public int[] numFolderRows; |
| 131 | public int[] numFolderColumns; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 132 | public float[] iconSize; |
| 133 | public float[] iconTextSize; |
Sunny Goyal | fc21830 | 2015-09-17 14:59:10 -0700 | [diff] [blame] | 134 | public int iconBitmapSize; |
| 135 | public int fillResIconDpi; |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 136 | public @DeviceType int deviceType; |
Federico Baron | 56307d2 | 2024-11-06 18:48:48 +0000 | [diff] [blame] | 137 | public Info displayInfo; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 138 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 139 | public PointF[] minCellSize; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 140 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 141 | public PointF[] borderSpaces; |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 142 | public @DimenRes int inlineNavButtonsEndSpacing; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 143 | |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 144 | public @StyleRes int folderStyle; |
Thales Lima | a08a443 | 2022-08-09 09:55:17 +0100 | [diff] [blame] | 145 | |
Thales Lima | d852d65 | 2023-01-17 14:01:13 +0000 | [diff] [blame] | 146 | public @StyleRes int cellStyle; |
| 147 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 148 | public float[] horizontalMargin; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 149 | |
Thales Lima | b7ef569 | 2022-03-10 10:32:36 +0000 | [diff] [blame] | 150 | public PointF[] allAppsCellSize; |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 151 | public float[] allAppsIconSize; |
| 152 | public float[] allAppsIconTextSize; |
| 153 | public PointF[] allAppsBorderSpaces; |
| 154 | |
Jon Miranda | 9c478b6 | 2023-03-23 21:38:49 -0700 | [diff] [blame] | 155 | public float[] transientTaskbarIconSize; |
| 156 | |
Jon Miranda | 04f0510 | 2023-04-04 12:16:31 -0700 | [diff] [blame] | 157 | public boolean[] startAlignTaskbar; |
| 158 | |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 159 | /** |
| 160 | * Number of icons inside the hotseat area. |
| 161 | */ |
Jon Miranda | fd48b0c | 2022-01-31 16:25:22 -0800 | [diff] [blame] | 162 | public int numShownHotseatIcons; |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame] | 163 | |
| 164 | /** |
| 165 | * Number of icons inside the hotseat area that is stored in the database. This is greater than |
| 166 | * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat |
| 167 | * sizes that share the same DB. |
| 168 | */ |
| 169 | public int numDatabaseHotseatIcons; |
Adam Cohen | 2782449 | 2017-09-22 17:10:55 -0700 | [diff] [blame] | 170 | |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 171 | public float[] hotseatBarBottomSpace; |
| 172 | public float[] hotseatQsbSpace; |
Thales Lima | 425f682 | 2022-05-10 13:44:58 -0300 | [diff] [blame] | 173 | |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 174 | /** |
| 175 | * Number of columns in the all apps list. |
| 176 | */ |
| 177 | public int numAllAppsColumns; |
Jordan Silva | 2de6a27 | 2024-01-04 14:44:20 -0300 | [diff] [blame] | 178 | public int numAllAppsRowsForCellHeightCalculation; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 179 | public int numDatabaseAllAppsColumns; |
Thales Lima | e9273ea | 2023-01-26 12:33:52 +0000 | [diff] [blame] | 180 | public @StyleRes int allAppsStyle; |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 181 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 182 | /** |
| 183 | * Do not query directly. see {@link DeviceProfile#isScalableGrid}. |
| 184 | */ |
| 185 | protected boolean isScalable; |
Thales Lima | ae0d7ef | 2022-11-16 15:53:43 +0000 | [diff] [blame] | 186 | @XmlRes |
| 187 | public int devicePaddingId = INVALID_RESOURCE_HANDLE; |
Thales Lima | ec5abba | 2023-04-05 16:33:50 +0100 | [diff] [blame] | 188 | @XmlRes |
| 189 | public int workspaceSpecsId = INVALID_RESOURCE_HANDLE; |
Thales Lima | abfe364 | 2023-05-24 18:08:53 +0100 | [diff] [blame] | 190 | @XmlRes |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 191 | public int gridSizeSpecsId = INVALID_RESOURCE_HANDLE;; |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 192 | @XmlRes |
Jordan Silva | 575c3bd | 2023-07-21 12:00:43 +0100 | [diff] [blame] | 193 | public int workspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; |
| 194 | @XmlRes |
Thales Lima | abfe364 | 2023-05-24 18:08:53 +0100 | [diff] [blame] | 195 | public int allAppsSpecsId = INVALID_RESOURCE_HANDLE; |
Jordan Silva | 637f4eb | 2023-06-13 11:21:53 +0100 | [diff] [blame] | 196 | @XmlRes |
Jordan Silva | 575c3bd | 2023-07-21 12:00:43 +0100 | [diff] [blame] | 197 | public int allAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; |
| 198 | @XmlRes |
Jordan Silva | 637f4eb | 2023-06-13 11:21:53 +0100 | [diff] [blame] | 199 | public int folderSpecsId = INVALID_RESOURCE_HANDLE; |
Jordan Silva | 575c3bd | 2023-07-21 12:00:43 +0100 | [diff] [blame] | 200 | @XmlRes |
| 201 | public int folderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 202 | @XmlRes |
Thales Lima | f8bfb03 | 2023-07-24 15:08:05 +0100 | [diff] [blame] | 203 | public int hotseatSpecsId = INVALID_RESOURCE_HANDLE; |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 204 | @XmlRes |
Thales Lima | f8bfb03 | 2023-07-24 15:08:05 +0100 | [diff] [blame] | 205 | public int hotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 206 | @XmlRes |
| 207 | public int workspaceCellSpecsId = INVALID_RESOURCE_HANDLE; |
| 208 | @XmlRes |
| 209 | public int workspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; |
| 210 | @XmlRes |
| 211 | public int allAppsCellSpecsId = INVALID_RESOURCE_HANDLE; |
| 212 | @XmlRes |
| 213 | public int allAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 214 | |
Sebastian Franco | 9e4c99b | 2024-10-02 15:16:37 -0700 | [diff] [blame] | 215 | |
| 216 | /** |
| 217 | * Fixed landscape mode is the landscape on the phones. |
| 218 | */ |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 219 | public boolean isFixedLandscape = false; |
Sebastian Franco | 9e4c99b | 2024-10-02 15:16:37 -0700 | [diff] [blame] | 220 | private LauncherPrefChangeListener mLandscapeModePreferenceListener; |
| 221 | |
Tracy Zhou | 7df93d2 | 2020-01-27 13:44:06 -0800 | [diff] [blame] | 222 | public String dbFile; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 223 | public int defaultLayoutId; |
Sunny Goyal | 1ae46ca | 2023-04-10 15:28:59 -0700 | [diff] [blame] | 224 | public int demoModeLayoutId; |
Thales Lima | 9938c2f | 2022-07-25 14:38:16 +0100 | [diff] [blame] | 225 | public boolean[] inlineQsb = new boolean[COUNT_SIZES]; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 226 | |
Pinyao Ting | 9cd63c9 | 2021-06-16 17:51:39 +0000 | [diff] [blame] | 227 | /** |
| 228 | * An immutable list of supported profiles. |
| 229 | */ |
| 230 | public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 231 | |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 232 | public Point defaultWallpaperSize; |
| 233 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 234 | private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>(); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 235 | |
Sunny Goyal | f633ef5 | 2018-03-13 09:57:05 -0700 | [diff] [blame] | 236 | @VisibleForTesting |
Sebastian Franco | 9e4c99b | 2024-10-02 15:16:37 -0700 | [diff] [blame] | 237 | public InvariantDeviceProfile() { |
| 238 | } |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 239 | |
Sunny Goyal | bbf0184 | 2015-10-08 07:41:15 -0700 | [diff] [blame] | 240 | @TargetApi(23) |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 241 | private InvariantDeviceProfile(Context context) { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 242 | String gridName = getCurrentGridName(context); |
| 243 | String newGridName = initGrid(context, gridName); |
| 244 | if (!newGridName.equals(gridName)) { |
Stefan Andonian | 4c9612b | 2023-02-22 00:00:03 +0000 | [diff] [blame] | 245 | LauncherPrefs.get(context).put(GRID_NAME, newGridName); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Tracy Zhou | c8beebf | 2021-09-23 10:18:11 -0700 | [diff] [blame] | 248 | DisplayController.INSTANCE.get(context).setPriorityListener( |
Alex Chau | fd6d942 | 2021-04-22 19:10:21 +0100 | [diff] [blame] | 249 | (displayContext, info, flags) -> { |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 250 | if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS |
Jagrut Desai | 2e8ca87 | 2024-04-17 15:27:30 -0700 | [diff] [blame] | 251 | | CHANGE_NAVIGATION_MODE | CHANGE_TASKBAR_PINNING |
| 252 | | CHANGE_DESKTOP_MODE)) != 0) { |
Alex Chau | fd6d942 | 2021-04-22 19:10:21 +0100 | [diff] [blame] | 253 | onConfigChanged(displayContext); |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 254 | } |
| 255 | }); |
Sebastian Franco | 9e4c99b | 2024-10-02 15:16:37 -0700 | [diff] [blame] | 256 | if (Flags.oneGridSpecs()) { |
| 257 | mLandscapeModePreferenceListener = (String s) -> { |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 258 | if (isFixedLandscape != FIXED_LANDSCAPE_MODE.get(context)) { |
| 259 | MAIN_EXECUTOR.execute(() -> { |
| 260 | Trace.beginSection("InvariantDeviceProfile#setFixedLandscape"); |
| 261 | onConfigChanged(context.getApplicationContext()); |
| 262 | Trace.endSection(); |
| 263 | }); |
Sebastian Franco | 9e4c99b | 2024-10-02 15:16:37 -0700 | [diff] [blame] | 264 | } |
| 265 | }; |
| 266 | LauncherPrefs.INSTANCE.get(context).addListener( |
| 267 | mLandscapeModePreferenceListener, |
| 268 | FIXED_LANDSCAPE_MODE |
| 269 | ); |
| 270 | } |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Hyunyoung Song | e11eb47 | 2019-03-19 15:05:21 -0700 | [diff] [blame] | 273 | /** |
| 274 | * This constructor should NOT have any monitors by design. |
| 275 | */ |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 276 | public InvariantDeviceProfile(Context context, String gridName) { |
| 277 | String newName = initGrid(context, gridName); |
| 278 | if (newName == null || !newName.equals(gridName)) { |
Andy Wickham | 99d7d4f | 2023-11-15 08:09:09 +0000 | [diff] [blame] | 279 | throw new IllegalArgumentException("Unknown grid name: " + gridName); |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 283 | /** |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 284 | * This constructor should NOT have any monitors by design. |
| 285 | */ |
| 286 | public InvariantDeviceProfile(Context context, Display display) { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 287 | // Ensure that the main device profile is initialized |
Alex Chau | fd6d942 | 2021-04-22 19:10:21 +0100 | [diff] [blame] | 288 | INSTANCE.get(context); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 289 | String gridName = getCurrentGridName(context); |
| 290 | |
| 291 | // Get the display info based on default display and interpolate it to existing display |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 292 | Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo(); |
Sunny Goyal | 25c4276 | 2024-04-16 19:31:31 -0700 | [diff] [blame] | 293 | @DeviceType int defaultDeviceType = defaultInfo.getDeviceType(); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 294 | DisplayOption defaultDisplayOption = invDistWeightedInterpolate( |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 295 | defaultInfo, |
Sebastian Franco | 9e4c99b | 2024-10-02 15:16:37 -0700 | [diff] [blame] | 296 | getPredefinedDeviceProfiles( |
| 297 | context, |
| 298 | gridName, |
| 299 | defaultInfo, |
| 300 | /*allowDisabledGrid=*/false, |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 301 | FIXED_LANDSCAPE_MODE.get(context) |
Sebastian Franco | 9e4c99b | 2024-10-02 15:16:37 -0700 | [diff] [blame] | 302 | ), |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 303 | defaultDeviceType); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 304 | |
Alex Chau | 661f02d | 2022-06-07 14:03:43 +0100 | [diff] [blame] | 305 | Context displayContext = context.createDisplayContext(display); |
| 306 | Info myInfo = new Info(displayContext); |
Sunny Goyal | 25c4276 | 2024-04-16 19:31:31 -0700 | [diff] [blame] | 307 | @DeviceType int deviceType = myInfo.getDeviceType(); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 308 | DisplayOption myDisplayOption = invDistWeightedInterpolate( |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 309 | myInfo, |
Sebastian Franco | 9e4c99b | 2024-10-02 15:16:37 -0700 | [diff] [blame] | 310 | getPredefinedDeviceProfiles( |
| 311 | context, |
| 312 | gridName, |
| 313 | myInfo, |
| 314 | /*allowDisabledGrid=*/false, |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 315 | FIXED_LANDSCAPE_MODE.get(context) |
Sebastian Franco | 9e4c99b | 2024-10-02 15:16:37 -0700 | [diff] [blame] | 316 | ), |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 317 | deviceType); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 318 | |
| 319 | DisplayOption result = new DisplayOption(defaultDisplayOption.grid) |
| 320 | .add(myDisplayOption); |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 321 | result.iconSizes[INDEX_DEFAULT] = |
| 322 | defaultDisplayOption.iconSizes[INDEX_DEFAULT]; |
| 323 | for (int i = 1; i < COUNT_SIZES; i++) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 324 | result.iconSizes[i] = Math.min( |
| 325 | defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]); |
Alex Chau | 7c43972 | 2021-03-24 11:32:44 +0000 | [diff] [blame] | 326 | } |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 327 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 328 | System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0, |
| 329 | COUNT_SIZES); |
| 330 | System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0, |
| 331 | COUNT_SIZES); |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 332 | |
Federico Baron | 56307d2 | 2024-11-06 18:48:48 +0000 | [diff] [blame] | 333 | initGrid(context, myInfo, result); |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 334 | } |
| 335 | |
Sunny Goyal | 10fa016 | 2024-04-21 00:13:35 -0700 | [diff] [blame] | 336 | @Override |
| 337 | public void close() { |
| 338 | DisplayController.INSTANCE.executeIfCreated(dc -> dc.setPriorityListener(null)); |
Sebastian Franco | 9e4c99b | 2024-10-02 15:16:37 -0700 | [diff] [blame] | 339 | if (mLandscapeModePreferenceListener != null) { |
| 340 | LauncherPrefs.INSTANCE.executeIfCreated( |
| 341 | lp -> lp.removeListener(mLandscapeModePreferenceListener, FIXED_LANDSCAPE_MODE) |
| 342 | ); |
| 343 | } |
Sunny Goyal | 10fa016 | 2024-04-21 00:13:35 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Tracy Zhou | 42255d2 | 2020-03-13 00:38:11 -0700 | [diff] [blame] | 346 | public static String getCurrentGridName(Context context) { |
Stefan Andonian | 4c9612b | 2023-02-22 00:00:03 +0000 | [diff] [blame] | 347 | return LauncherPrefs.get(context).get(GRID_NAME); |
Tracy Zhou | 42255d2 | 2020-03-13 00:38:11 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 350 | private String initGrid(Context context, String gridName) { |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 351 | Info displayInfo = DisplayController.INSTANCE.get(context).getInfo(); |
Sebastian Franco | 9e4c99b | 2024-10-02 15:16:37 -0700 | [diff] [blame] | 352 | List<DisplayOption> allOptions = getPredefinedDeviceProfiles( |
| 353 | context, |
| 354 | gridName, |
| 355 | displayInfo, |
| 356 | RestoreDbTask.isPending(context), |
| 357 | FIXED_LANDSCAPE_MODE.get(context) |
| 358 | ); |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 359 | |
| 360 | // Filter out options that don't have the same number of columns as the grid |
| 361 | DeviceGridState deviceGridState = new DeviceGridState(context); |
| 362 | List<DisplayOption> allOptionsFilteredByColCount = |
| 363 | filterByColumnCount(allOptions, deviceGridState.getColumns()); |
| 364 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 365 | DisplayOption displayOption = |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 366 | invDistWeightedInterpolate(displayInfo, allOptionsFilteredByColCount.isEmpty() |
Sebastian Franco | 9e4c99b | 2024-10-02 15:16:37 -0700 | [diff] [blame] | 367 | ? new ArrayList<>(allOptions) |
| 368 | : new ArrayList<>(allOptionsFilteredByColCount), |
Federico Baron | 56307d2 | 2024-11-06 18:48:48 +0000 | [diff] [blame] | 369 | displayInfo.getDeviceType()); |
| 370 | initGrid(context, displayInfo, displayOption); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 371 | return displayOption.grid.name; |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 372 | } |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 373 | |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 374 | private List<DisplayOption> filterByColumnCount( |
| 375 | List<DisplayOption> allOptions, int numColumns) { |
| 376 | return allOptions.stream().filter( |
| 377 | option -> option.grid.numColumns == numColumns).toList(); |
| 378 | } |
| 379 | |
Sebastian Franco | df7d2b0 | 2024-04-04 15:12:18 -0700 | [diff] [blame] | 380 | /** |
| 381 | * @deprecated This is a temporary solution because on the backup and restore case we modify the |
| 382 | * IDP, this resets it. b/332974074 |
| 383 | */ |
| 384 | @Deprecated |
| 385 | public void reset(Context context) { |
fbaron | b633b9a | 2024-09-23 18:35:29 -0700 | [diff] [blame] | 386 | initGrid(context, getDefaultGridName(context)); |
Sebastian Franco | df7d2b0 | 2024-04-04 15:12:18 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Thales Lima | b67bfa7 | 2022-11-02 15:30:11 +0000 | [diff] [blame] | 389 | @VisibleForTesting |
| 390 | public static String getDefaultGridName(Context context) { |
| 391 | return new InvariantDeviceProfile().initGrid(context, null); |
| 392 | } |
| 393 | |
Federico Baron | 56307d2 | 2024-11-06 18:48:48 +0000 | [diff] [blame] | 394 | private void initGrid(Context context, Info displayInfo, DisplayOption displayOption) { |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 395 | DisplayMetrics metrics = context.getResources().getDisplayMetrics(); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 396 | GridOption closestProfile = displayOption.grid; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 397 | numRows = closestProfile.numRows; |
| 398 | numColumns = closestProfile.numColumns; |
Alex Chau | 9fee3fd | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 399 | numSearchContainerColumns = closestProfile.numSearchContainerColumns; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 400 | dbFile = closestProfile.dbFile; |
| 401 | defaultLayoutId = closestProfile.defaultLayoutId; |
| 402 | demoModeLayoutId = closestProfile.demoModeLayoutId; |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 403 | |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 404 | numFolderRows = closestProfile.numFolderRows; |
| 405 | numFolderColumns = closestProfile.numFolderColumns; |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 406 | folderStyle = closestProfile.folderStyle; |
| 407 | |
Thales Lima | d852d65 | 2023-01-17 14:01:13 +0000 | [diff] [blame] | 408 | cellStyle = closestProfile.cellStyle; |
| 409 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 410 | isScalable = closestProfile.isScalable; |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 411 | devicePaddingId = closestProfile.devicePaddingId; |
Thales Lima | ec5abba | 2023-04-05 16:33:50 +0100 | [diff] [blame] | 412 | workspaceSpecsId = closestProfile.mWorkspaceSpecsId; |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 413 | gridSizeSpecsId = closestProfile.mGridSizeSpecsId; |
Jordan Silva | 575c3bd | 2023-07-21 12:00:43 +0100 | [diff] [blame] | 414 | workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId; |
Thales Lima | abfe364 | 2023-05-24 18:08:53 +0100 | [diff] [blame] | 415 | allAppsSpecsId = closestProfile.mAllAppsSpecsId; |
Jordan Silva | 575c3bd | 2023-07-21 12:00:43 +0100 | [diff] [blame] | 416 | allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId; |
Jordan Silva | 637f4eb | 2023-06-13 11:21:53 +0100 | [diff] [blame] | 417 | folderSpecsId = closestProfile.mFolderSpecsId; |
Jordan Silva | 575c3bd | 2023-07-21 12:00:43 +0100 | [diff] [blame] | 418 | folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId; |
Thales Lima | f8bfb03 | 2023-07-24 15:08:05 +0100 | [diff] [blame] | 419 | hotseatSpecsId = closestProfile.mHotseatSpecsId; |
| 420 | hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId; |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 421 | workspaceCellSpecsId = closestProfile.mWorkspaceCellSpecsId; |
| 422 | workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId; |
| 423 | allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId; |
| 424 | allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId; |
Jordan Silva | 2de6a27 | 2024-01-04 14:44:20 -0300 | [diff] [blame] | 425 | numAllAppsRowsForCellHeightCalculation = |
| 426 | closestProfile.mNumAllAppsRowsForCellHeightCalculation; |
Federico Baron | 56307d2 | 2024-11-06 18:48:48 +0000 | [diff] [blame] | 427 | this.deviceType = displayInfo.getDeviceType(); |
| 428 | this.displayInfo = displayInfo; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 429 | |
Vinit Nayak | c729317 | 2022-07-18 16:41:50 -0700 | [diff] [blame] | 430 | inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing; |
| 431 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 432 | iconSize = displayOption.iconSizes; |
Thales Lima | 6e0005a | 2021-10-27 15:53:41 +0100 | [diff] [blame] | 433 | float maxIconSize = iconSize[0]; |
| 434 | for (int i = 1; i < iconSize.length; i++) { |
| 435 | maxIconSize = Math.max(maxIconSize, iconSize[i]); |
| 436 | } |
| 437 | iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics); |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 438 | fillResIconDpi = getLauncherIconDensity(iconBitmapSize); |
| 439 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 440 | iconTextSize = displayOption.textSizes; |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 441 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 442 | minCellSize = displayOption.minCellSize; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 443 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 444 | borderSpaces = displayOption.borderSpaces; |
Thales Lima | a08a443 | 2022-08-09 09:55:17 +0100 | [diff] [blame] | 445 | |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 446 | horizontalMargin = displayOption.horizontalMargin; |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 447 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 448 | numShownHotseatIcons = closestProfile.numHotseatIcons; |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 449 | numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 450 | ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons; |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 451 | hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace; |
| 452 | hotseatQsbSpace = displayOption.hotseatQsbSpace; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 453 | |
Thales Lima | e9273ea | 2023-01-26 12:33:52 +0000 | [diff] [blame] | 454 | allAppsStyle = closestProfile.allAppsStyle; |
| 455 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 456 | numAllAppsColumns = closestProfile.numAllAppsColumns; |
Jordan Silva | 2de6a27 | 2024-01-04 14:44:20 -0300 | [diff] [blame] | 457 | |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 458 | numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 459 | ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 460 | |
Thales Lima | b7ef569 | 2022-03-10 10:32:36 +0000 | [diff] [blame] | 461 | allAppsCellSize = displayOption.allAppsCellSize; |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 462 | allAppsBorderSpaces = displayOption.allAppsBorderSpaces; |
| 463 | allAppsIconSize = displayOption.allAppsIconSizes; |
| 464 | allAppsIconTextSize = displayOption.allAppsIconTextSizes; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 465 | |
Thales Lima | 11af7bc | 2022-08-12 15:24:54 +0100 | [diff] [blame] | 466 | inlineQsb = closestProfile.inlineQsb; |
Thales Lima | 12d0eff | 2022-03-25 17:06:11 +0000 | [diff] [blame] | 467 | |
Jon Miranda | 9c478b6 | 2023-03-23 21:38:49 -0700 | [diff] [blame] | 468 | transientTaskbarIconSize = displayOption.transientTaskbarIconSize; |
| 469 | |
Jon Miranda | 04f0510 | 2023-04-04 12:16:31 -0700 | [diff] [blame] | 470 | startAlignTaskbar = displayOption.startAlignTaskbar; |
| 471 | |
Sebastian Franco | 9e4c99b | 2024-10-02 15:16:37 -0700 | [diff] [blame] | 472 | // Fixed Landscape mode |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 473 | isFixedLandscape = closestProfile.mIsFixedLandscape; |
Sebastian Franco | 9e4c99b | 2024-10-02 15:16:37 -0700 | [diff] [blame] | 474 | |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 475 | // If the partner customization apk contains any grid overrides, apply them |
| 476 | // Supported overrides: numRows, numColumns, iconSize |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 477 | applyPartnerDeviceProfileOverrides(context, metrics); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 478 | |
Pinyao Ting | 9cd63c9 | 2021-06-16 17:51:39 +0000 | [diff] [blame] | 479 | final List<DeviceProfile> localSupportedProfiles = new ArrayList<>(); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 480 | defaultWallpaperSize = new Point(displayInfo.currentSize); |
Sunny Goyal | 65190ae | 2022-08-02 14:16:26 -0700 | [diff] [blame] | 481 | SparseArray<DotRenderer> dotRendererCache = new SparseArray<>(); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 482 | for (WindowBounds bounds : displayInfo.supportedBounds) { |
Pinyao Ting | 9cd63c9 | 2021-06-16 17:51:39 +0000 | [diff] [blame] | 483 | localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo) |
Alex Chau | ab800f7 | 2022-12-13 17:46:06 +0000 | [diff] [blame] | 484 | .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY) |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 485 | .setWindowBounds(bounds) |
Sunny Goyal | 65190ae | 2022-08-02 14:16:26 -0700 | [diff] [blame] | 486 | .setDotRendererCache(dotRendererCache) |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 487 | .build()); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 488 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 489 | // Wallpaper size should be the maximum of the all possible sizes Launcher expects |
| 490 | int displayWidth = bounds.bounds.width(); |
| 491 | int displayHeight = bounds.bounds.height(); |
| 492 | defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 493 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 494 | // We need to ensure that there is enough extra space in the wallpaper |
| 495 | // for the intended parallax effects |
| 496 | float parallaxFactor = |
Thales Lima | 425f682 | 2022-05-10 13:44:58 -0300 | [diff] [blame] | 497 | dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi()) |
| 498 | < 720 |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 499 | ? 2 |
| 500 | : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight); |
| 501 | defaultWallpaperSize.x = |
| 502 | Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth)); |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 503 | } |
Pinyao Ting | 9cd63c9 | 2021-06-16 17:51:39 +0000 | [diff] [blame] | 504 | supportedProfiles = Collections.unmodifiableList(localSupportedProfiles); |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 505 | |
Thales Lima | 6a59006 | 2022-11-22 15:52:49 +0000 | [diff] [blame] | 506 | int numMinShownHotseatIconsForTablet = supportedProfiles |
| 507 | .stream() |
| 508 | .filter(deviceProfile -> deviceProfile.isTablet) |
| 509 | .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons) |
| 510 | .min() |
| 511 | .orElse(0); |
| 512 | |
| 513 | supportedProfiles |
| 514 | .stream() |
| 515 | .filter(deviceProfile -> deviceProfile.isTablet) |
| 516 | .forEach(deviceProfile -> { |
| 517 | deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet; |
| 518 | deviceProfile.recalculateHotseatWidthAndBorderSpace(); |
| 519 | }); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 522 | public void addOnChangeListener(OnIDPChangeListener listener) { |
| 523 | mChangeListeners.add(listener); |
| 524 | } |
| 525 | |
Hyunyoung Song | b4d1ca4 | 2019-01-08 17:15:16 -0800 | [diff] [blame] | 526 | public void removeOnChangeListener(OnIDPChangeListener listener) { |
| 527 | mChangeListeners.remove(listener); |
| 528 | } |
| 529 | |
Sebastian Franco | 9e4c99b | 2024-10-02 15:16:37 -0700 | [diff] [blame] | 530 | /** |
| 531 | * Updates the current grid, this triggers a new IDP, reloads the database and triggers a grid |
| 532 | * migration. |
| 533 | */ |
| 534 | public void setCurrentGrid(Context context, String newGridName) { |
| 535 | LauncherPrefs.get(context).put(GRID_NAME, newGridName); |
Brandon Dayauon | 51db65e | 2024-10-23 15:07:37 -0700 | [diff] [blame] | 536 | MAIN_EXECUTOR.execute(() -> { |
| 537 | Trace.beginSection("InvariantDeviceProfile#setCurrentGrid"); |
| 538 | onConfigChanged(context.getApplicationContext()); |
| 539 | Trace.endSection(); |
| 540 | }); |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 541 | } |
| 542 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 543 | private Object[] toModelState() { |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 544 | return new Object[]{ |
Alex Chau | 9fee3fd | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 545 | numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons, |
| 546 | iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile}; |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 547 | } |
| 548 | |
Pat Manning | 24cec69 | 2023-10-13 10:36:57 +0000 | [diff] [blame] | 549 | /** Updates IDP using the provided context. Notifies listeners of change. */ |
| 550 | @VisibleForTesting |
| 551 | public void onConfigChanged(Context context) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 552 | Object[] oldState = toModelState(); |
| 553 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 554 | // Re-init grid |
Tracy Zhou | c6060e6 | 2020-04-27 13:05:34 -0700 | [diff] [blame] | 555 | String gridName = getCurrentGridName(context); |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 556 | initGrid(context, gridName); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 557 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 558 | boolean modelPropsChanged = !Arrays.equals(oldState, toModelState()); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 559 | for (OnIDPChangeListener listener : mChangeListeners) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 560 | listener.onIdpChanged(modelPropsChanged); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 561 | } |
| 562 | } |
| 563 | |
Sebastian Franco | 9e4c99b | 2024-10-02 15:16:37 -0700 | [diff] [blame] | 564 | private static boolean firstGridFilter(GridOption gridOption, int deviceType, |
| 565 | boolean allowDisabledGrid, boolean isFixedLandscapeMode) { |
| 566 | return (gridOption.isEnabled(deviceType) || allowDisabledGrid) |
fbaron | c1b68f4 | 2024-11-08 18:10:46 -0800 | [diff] [blame] | 567 | && gridOption.filterByFlag(deviceType, isFixedLandscapeMode); |
Sebastian Franco | 9e4c99b | 2024-10-02 15:16:37 -0700 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | private static List<DisplayOption> getPredefinedDeviceProfiles( |
| 571 | Context context, |
| 572 | String gridName, |
| 573 | Info displayInfo, |
| 574 | boolean allowDisabledGrid, |
| 575 | boolean isFixedLandscapeMode |
| 576 | ) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 577 | ArrayList<DisplayOption> profiles = new ArrayList<>(); |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame] | 578 | |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 579 | try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) { |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 580 | final int depth = parser.getDepth(); |
| 581 | int type; |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 582 | while (((type = parser.next()) != XmlPullParser.END_TAG || |
| 583 | parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 584 | if ((type == XmlPullParser.START_TAG) |
| 585 | && GridOption.TAG_NAME.equals(parser.getName())) { |
Federico Baron | 56307d2 | 2024-11-06 18:48:48 +0000 | [diff] [blame] | 586 | GridOption gridOption = new GridOption( |
| 587 | context, Xml.asAttributeSet(parser), displayInfo); |
Sebastian Franco | 9e4c99b | 2024-10-02 15:16:37 -0700 | [diff] [blame] | 588 | if (firstGridFilter(gridOption, displayInfo.getDeviceType(), allowDisabledGrid, |
| 589 | isFixedLandscapeMode)) { |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 590 | final int displayDepth = parser.getDepth(); |
| 591 | while (((type = parser.next()) != XmlPullParser.END_TAG |
| 592 | || parser.getDepth() > displayDepth) |
| 593 | && type != XmlPullParser.END_DOCUMENT) { |
| 594 | if ((type == XmlPullParser.START_TAG) && "display-option".equals( |
| 595 | parser.getName())) { |
| 596 | profiles.add(new DisplayOption(gridOption, context, |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame] | 597 | Xml.asAttributeSet(parser))); |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 598 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 599 | } |
| 600 | } |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 601 | } |
| 602 | } |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 603 | } catch (IOException | XmlPullParserException e) { |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 604 | throw new RuntimeException(e); |
| 605 | } |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 606 | ArrayList<DisplayOption> filteredProfiles = new ArrayList<>(); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 607 | if (!TextUtils.isEmpty(gridName)) { |
| 608 | for (DisplayOption option : profiles) { |
Federico Baron | 56307d2 | 2024-11-06 18:48:48 +0000 | [diff] [blame] | 609 | if (gridName.equals(option.grid.name) && (option.grid.isEnabled( |
| 610 | displayInfo.getDeviceType()) || allowDisabledGrid)) { |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 611 | filteredProfiles.add(option); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 612 | } |
| 613 | } |
| 614 | } |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 615 | if (filteredProfiles.isEmpty() && TextUtils.isEmpty(gridName)) { |
| 616 | // Use the default options since gridName is empty and there's no valid grids. |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 617 | for (DisplayOption option : profiles) { |
| 618 | if (option.canBeDefault) { |
| 619 | filteredProfiles.add(option); |
| 620 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 621 | } |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 622 | } else if (filteredProfiles.isEmpty()) { |
| 623 | // In this case we had a grid selected but we couldn't find it. |
| 624 | filteredProfiles.addAll(profiles); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 625 | } |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 626 | if (filteredProfiles.isEmpty()) { |
| 627 | throw new RuntimeException("No display option with canBeDefault=true"); |
| 628 | } |
| 629 | return filteredProfiles; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 630 | } |
| 631 | |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 632 | /** |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 633 | * Parses through the xml to find GridSize specs. Then calls findBestGridSize to get the |
| 634 | * correct grid size for this GridOption. |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 635 | * |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 636 | * @return the result of {@link #findBestGridSize(List, int, int)}. |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 637 | */ |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 638 | private static GridSize getGridSize(ResourceHelper resourceHelper, Context context, |
Federico Baron | 56307d2 | 2024-11-06 18:48:48 +0000 | [diff] [blame] | 639 | Info displayInfo) { |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 640 | ArrayList<GridSize> gridSizes = new ArrayList<>(); |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 641 | |
| 642 | try (XmlResourceParser parser = resourceHelper.getXml()) { |
| 643 | final int depth = parser.getDepth(); |
| 644 | int type; |
| 645 | while (((type = parser.next()) != XmlPullParser.END_TAG |
| 646 | || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { |
| 647 | if ((type == XmlPullParser.START_TAG) |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 648 | && "GridSize".equals(parser.getName())) { |
| 649 | gridSizes.add(new GridSize(context, Xml.asAttributeSet(parser))); |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 650 | } |
| 651 | } |
| 652 | } catch (IOException | XmlPullParserException e) { |
| 653 | throw new RuntimeException(e); |
| 654 | } |
| 655 | |
fbaron | 4935834 | 2024-11-22 17:38:56 -0800 | [diff] [blame] | 656 | // Finds the min width and height in dp for all displays. |
| 657 | int[] dimens = findMinWidthAndHeightDpForDevice(displayInfo); |
| 658 | |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 659 | return findBestGridSize(gridSizes, dimens[0], dimens[1]); |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | /** |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 663 | * @return the biggest grid size that fits the display dimensions. |
| 664 | * If no best grid size is found, return null. |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 665 | */ |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 666 | private static GridSize findBestGridSize(List<GridSize> list, int minWidthDp, |
fbaron | 4935834 | 2024-11-22 17:38:56 -0800 | [diff] [blame] | 667 | int minHeightDp) { |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 668 | GridSize selectedGridSize = null; |
| 669 | for (GridSize item: list) { |
fbaron | 4935834 | 2024-11-22 17:38:56 -0800 | [diff] [blame] | 670 | if (minWidthDp >= item.mMinDeviceWidthDp && minHeightDp >= item.mMinDeviceHeightDp) { |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 671 | if (selectedGridSize == null |
| 672 | || (selectedGridSize.mNumColumns <= item.mNumColumns |
| 673 | && selectedGridSize.mNumRows <= item.mNumRows)) { |
| 674 | selectedGridSize = item; |
fbaron | 4935834 | 2024-11-22 17:38:56 -0800 | [diff] [blame] | 675 | } |
| 676 | } |
| 677 | } |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 678 | return selectedGridSize; |
fbaron | 4935834 | 2024-11-22 17:38:56 -0800 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | private static int[] findMinWidthAndHeightDpForDevice(Info displayInfo) { |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 682 | int minWidthPx = Integer.MAX_VALUE; |
| 683 | int minHeightPx = Integer.MAX_VALUE; |
| 684 | for (WindowBounds bounds : displayInfo.supportedBounds) { |
| 685 | boolean isTablet = displayInfo.isTablet(bounds); |
Federico Baron | 56307d2 | 2024-11-06 18:48:48 +0000 | [diff] [blame] | 686 | if (isTablet && displayInfo.getDeviceType() == TYPE_MULTI_DISPLAY) { |
fbaron | 4935834 | 2024-11-22 17:38:56 -0800 | [diff] [blame] | 687 | // For split displays, take half width per page. |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 688 | minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2); |
| 689 | minHeightPx = Math.min(minHeightPx, bounds.availableSize.y); |
| 690 | } else if (!isTablet && bounds.isLandscape()) { |
fbaron | 4935834 | 2024-11-22 17:38:56 -0800 | [diff] [blame] | 691 | // We will use transposed layout in this case. |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 692 | minWidthPx = Math.min(minWidthPx, bounds.availableSize.y); |
| 693 | minHeightPx = Math.min(minHeightPx, bounds.availableSize.x); |
| 694 | } else { |
| 695 | minWidthPx = Math.min(minWidthPx, bounds.availableSize.x); |
| 696 | minHeightPx = Math.min(minHeightPx, bounds.availableSize.y); |
| 697 | } |
| 698 | } |
| 699 | |
fbaron | 4935834 | 2024-11-22 17:38:56 -0800 | [diff] [blame] | 700 | int minWidthDp = (int) dpiFromPx(minWidthPx, DisplayMetrics.DENSITY_DEVICE_STABLE); |
| 701 | int minHeightDp = (int) dpiFromPx(minHeightPx, DisplayMetrics.DENSITY_DEVICE_STABLE); |
| 702 | |
| 703 | return new int[]{minWidthDp, minHeightDp}; |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | /** |
Sebastián Franco | ad46eb7 | 2024-03-11 20:56:57 +0000 | [diff] [blame] | 707 | * Returns the GridOption associated to the given file name or null if the fileName is not |
| 708 | * supported. |
| 709 | * Ej, launcher.db -> "normal grid", launcher_4_by_4.db -> "practical grid" |
| 710 | */ |
| 711 | public GridOption getGridOptionFromFileName(Context context, String fileName) { |
| 712 | return parseAllGridOptions(context).stream() |
| 713 | .filter(gridOption -> Objects.equals(gridOption.dbFile, fileName)) |
| 714 | .findFirst() |
| 715 | .orElse(null); |
| 716 | } |
| 717 | |
| 718 | /** |
| 719 | * Returns the name of the given size on the current device or empty string if the size is not |
| 720 | * supported. Ej. 4x4 -> normal, 5x4 -> practical, etc. |
| 721 | * (Note: the name of the grid can be different for the same grid size depending of |
| 722 | * the values of the InvariantDeviceProfile) |
Sebastián Franco | ad46eb7 | 2024-03-11 20:56:57 +0000 | [diff] [blame] | 723 | */ |
| 724 | public String getGridNameFromSize(Context context, Point size) { |
| 725 | return parseAllGridOptions(context).stream() |
| 726 | .filter(gridOption -> gridOption.numColumns == size.x |
| 727 | && gridOption.numRows == size.y) |
| 728 | .map(gridOption -> gridOption.name) |
| 729 | .findFirst() |
| 730 | .orElse(""); |
| 731 | } |
| 732 | |
| 733 | /** |
| 734 | * Returns the grid option for the given gridName on the current device (Note: the gridOption |
| 735 | * be different for the same gridName depending on the values of the InvariantDeviceProfile). |
| 736 | */ |
| 737 | public GridOption getGridOptionFromName(Context context, String gridName) { |
| 738 | return parseAllGridOptions(context).stream() |
| 739 | .filter(gridOption -> Objects.equals(gridOption.name, gridName)) |
| 740 | .findFirst() |
| 741 | .orElse(null); |
| 742 | } |
| 743 | |
| 744 | /** |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 745 | * @return all the grid options that can be shown on the device |
| 746 | */ |
| 747 | public List<GridOption> parseAllGridOptions(Context context) { |
Federico Baron | 56307d2 | 2024-11-06 18:48:48 +0000 | [diff] [blame] | 748 | return parseAllDefinedGridOptions(context, displayInfo) |
Sunny Goyal | 076e04b | 2023-04-03 12:38:30 -0700 | [diff] [blame] | 749 | .stream() |
| 750 | .filter(go -> go.isEnabled(deviceType)) |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 751 | .filter(go -> go.filterByFlag(deviceType, isFixedLandscape)) |
Sunny Goyal | 076e04b | 2023-04-03 12:38:30 -0700 | [diff] [blame] | 752 | .collect(Collectors.toList()); |
| 753 | } |
| 754 | |
| 755 | /** |
| 756 | * @return all the grid options that can be shown on the device |
| 757 | */ |
Federico Baron | 56307d2 | 2024-11-06 18:48:48 +0000 | [diff] [blame] | 758 | public static List<GridOption> parseAllDefinedGridOptions(Context context, Info displayInfo) { |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 759 | List<GridOption> result = new ArrayList<>(); |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 760 | try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) { |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 761 | final int depth = parser.getDepth(); |
| 762 | int type; |
| 763 | while (((type = parser.next()) != XmlPullParser.END_TAG |
| 764 | || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { |
| 765 | if ((type == XmlPullParser.START_TAG) |
| 766 | && GridOption.TAG_NAME.equals(parser.getName())) { |
Federico Baron | 56307d2 | 2024-11-06 18:48:48 +0000 | [diff] [blame] | 767 | result.add(new GridOption(context, Xml.asAttributeSet(parser), displayInfo)); |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 768 | } |
| 769 | } |
| 770 | } catch (IOException | XmlPullParserException e) { |
| 771 | Log.e(TAG, "Error parsing device profile", e); |
| 772 | return Collections.emptyList(); |
| 773 | } |
| 774 | return result; |
| 775 | } |
| 776 | |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 777 | private int getLauncherIconDensity(int requiredSize) { |
| 778 | // Densities typically defined by an app. |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 779 | int[] densityBuckets = new int[]{ |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 780 | DisplayMetrics.DENSITY_LOW, |
| 781 | DisplayMetrics.DENSITY_MEDIUM, |
| 782 | DisplayMetrics.DENSITY_TV, |
| 783 | DisplayMetrics.DENSITY_HIGH, |
| 784 | DisplayMetrics.DENSITY_XHIGH, |
| 785 | DisplayMetrics.DENSITY_XXHIGH, |
| 786 | DisplayMetrics.DENSITY_XXXHIGH |
| 787 | }; |
| 788 | |
| 789 | int density = DisplayMetrics.DENSITY_XXXHIGH; |
| 790 | for (int i = densityBuckets.length - 1; i >= 0; i--) { |
| 791 | float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i] |
| 792 | / DisplayMetrics.DENSITY_DEFAULT; |
| 793 | if (expectedSize >= requiredSize) { |
| 794 | density = densityBuckets[i]; |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | return density; |
| 799 | } |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 800 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 801 | /** |
| 802 | * Apply any Partner customization grid overrides. |
| 803 | * |
| 804 | * Currently we support: all apps row / column count. |
| 805 | */ |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 806 | private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) { |
| 807 | Partner p = Partner.get(context.getPackageManager()); |
Sunny Goyal | 3e58eea | 2022-11-14 14:30:07 -0800 | [diff] [blame] | 808 | if (p == null) { |
| 809 | return; |
| 810 | } |
| 811 | try { |
| 812 | int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1); |
| 813 | int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1); |
| 814 | float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1); |
| 815 | |
| 816 | if (numRows > 0 && numColumns > 0) { |
| 817 | this.numRows = numRows; |
| 818 | this.numColumns = numColumns; |
| 819 | } |
| 820 | if (iconSizePx > 0) { |
| 821 | this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] = |
| 822 | Utilities.dpiFromPx(iconSizePx, dm.densityDpi); |
| 823 | } |
| 824 | } catch (Resources.NotFoundException ex) { |
| 825 | Log.e(TAG, "Invalid Partner grid resource!", ex); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 829 | private static float dist(float x0, float y0, float x1, float y1) { |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 830 | return (float) Math.hypot(x1 - x0, y1 - y0); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 831 | } |
| 832 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 833 | private static DisplayOption invDistWeightedInterpolate( |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 834 | Info displayInfo, List<DisplayOption> points, @DeviceType int deviceType) { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 835 | int minWidthPx = Integer.MAX_VALUE; |
| 836 | int minHeightPx = Integer.MAX_VALUE; |
| 837 | for (WindowBounds bounds : displayInfo.supportedBounds) { |
| 838 | boolean isTablet = displayInfo.isTablet(bounds); |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 839 | if (isTablet && deviceType == TYPE_MULTI_DISPLAY) { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 840 | // For split displays, take half width per page |
| 841 | minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2); |
| 842 | minHeightPx = Math.min(minHeightPx, bounds.availableSize.y); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 843 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 844 | } else if (!isTablet && bounds.isLandscape()) { |
| 845 | // We will use transposed layout in this case |
| 846 | minWidthPx = Math.min(minWidthPx, bounds.availableSize.y); |
| 847 | minHeightPx = Math.min(minHeightPx, bounds.availableSize.x); |
| 848 | } else { |
| 849 | minWidthPx = Math.min(minWidthPx, bounds.availableSize.x); |
| 850 | minHeightPx = Math.min(minHeightPx, bounds.availableSize.y); |
| 851 | } |
| 852 | } |
| 853 | |
Thales Lima | 425f682 | 2022-05-10 13:44:58 -0300 | [diff] [blame] | 854 | float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi()); |
| 855 | float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi()); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 856 | |
| 857 | // Sort the profiles based on the closeness to the device size |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 858 | points.sort((a, b) -> |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 859 | Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps), |
| 860 | dist(width, height, b.minWidthDps, b.minHeightDps))); |
| 861 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 862 | DisplayOption closestPoint = points.get(0); |
| 863 | GridOption closestOption = closestPoint.grid; |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 864 | float weights = 0; |
| 865 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 866 | if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) { |
| 867 | return closestPoint; |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | DisplayOption out = new DisplayOption(closestOption); |
| 871 | for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 872 | DisplayOption p = points.get(i); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 873 | float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER); |
| 874 | weights += w; |
| 875 | out.add(new DisplayOption().add(p).multiply(w)); |
| 876 | } |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 877 | out.multiply(1.0f / weights); |
| 878 | |
Thales Lima | 6e0005a | 2021-10-27 15:53:41 +0100 | [diff] [blame] | 879 | // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 880 | // predefined size to avoid cache invalidation |
Thales Lima | 6e0005a | 2021-10-27 15:53:41 +0100 | [diff] [blame] | 881 | for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) { |
| 882 | out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]); |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | return out; |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 886 | } |
| 887 | |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 888 | public DeviceProfile getDeviceProfile(Context context) { |
Alex Chau | c09a98a | 2023-11-14 12:51:42 +0000 | [diff] [blame] | 889 | WindowManagerProxy windowManagerProxy = WindowManagerProxy.INSTANCE.get(context); |
| 890 | Rect bounds = windowManagerProxy.getCurrentBounds(context); |
| 891 | int rotation = windowManagerProxy.getRotation(context); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 892 | |
Alex Chau | c09a98a | 2023-11-14 12:51:42 +0000 | [diff] [blame] | 893 | return getBestMatch(bounds.width(), bounds.height(), rotation); |
Sunny Goyal | 3e9a29c | 2021-09-07 15:53:09 -0400 | [diff] [blame] | 894 | } |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 895 | |
Sunny Goyal | 187b16c | 2022-03-01 16:53:23 -0800 | [diff] [blame] | 896 | /** |
| 897 | * Returns the device profile matching the provided screen configuration |
| 898 | */ |
| 899 | public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 900 | DeviceProfile bestMatch = supportedProfiles.get(0); |
| 901 | float minDiff = Float.MAX_VALUE; |
| 902 | |
| 903 | for (DeviceProfile profile : supportedProfiles) { |
Sunny Goyal | 3e9a29c | 2021-09-07 15:53:09 -0400 | [diff] [blame] | 904 | float diff = Math.abs(profile.widthPx - screenWidth) |
| 905 | + Math.abs(profile.heightPx - screenHeight); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 906 | if (diff < minDiff) { |
| 907 | minDiff = diff; |
| 908 | bestMatch = profile; |
Sunny Goyal | 187b16c | 2022-03-01 16:53:23 -0800 | [diff] [blame] | 909 | } else if (diff == minDiff && profile.rotationHint == rotation) { |
| 910 | bestMatch = profile; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 911 | } |
| 912 | } |
| 913 | return bestMatch; |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 914 | } |
| 915 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 916 | private static float weight(float x0, float y0, float x1, float y1, float pow) { |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 917 | float d = dist(x0, y0, x1, y1); |
| 918 | if (Float.compare(d, 0f) == 0) { |
| 919 | return Float.POSITIVE_INFINITY; |
| 920 | } |
| 921 | return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow)); |
| 922 | } |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 923 | |
| 924 | /** |
| 925 | * As a ratio of screen height, the total distance we want the parallax effect to span |
| 926 | * horizontally |
| 927 | */ |
| 928 | private static float wallpaperTravelToScreenWidthRatio(int width, int height) { |
| 929 | float aspectRatio = width / (float) height; |
| 930 | |
| 931 | // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width |
| 932 | // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width |
| 933 | // We will use these two data points to extrapolate how much the wallpaper parallax effect |
| 934 | // to span (ie travel) at any aspect ratio: |
| 935 | |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 936 | final float ASPECT_RATIO_LANDSCAPE = 16 / 10f; |
| 937 | final float ASPECT_RATIO_PORTRAIT = 10 / 16f; |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 938 | final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f; |
| 939 | final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f; |
| 940 | |
| 941 | // To find out the desired width at different aspect ratios, we use the following two |
| 942 | // formulas, where the coefficient on x is the aspect ratio (width/height): |
| 943 | // (16/10)x + y = 1.5 |
| 944 | // (10/16)x + y = 1.2 |
| 945 | // We solve for x and y and end up with a final formula: |
| 946 | final float x = |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 947 | (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE |
| 948 | - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) / |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 949 | (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT); |
| 950 | final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT; |
| 951 | return x * aspectRatio + y; |
| 952 | } |
| 953 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 954 | public interface OnIDPChangeListener { |
| 955 | |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 956 | /** |
| 957 | * Called when the device provide changes |
| 958 | */ |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 959 | void onIdpChanged(boolean modelPropertiesChanged); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 960 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 961 | |
| 962 | |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 963 | public static final class GridOption { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 964 | |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 965 | public static final String TAG_NAME = "grid-option"; |
| 966 | |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 967 | private static final int DEVICE_CATEGORY_PHONE = 1 << 0; |
| 968 | private static final int DEVICE_CATEGORY_TABLET = 1 << 1; |
| 969 | private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2; |
| 970 | private static final int DEVICE_CATEGORY_ALL = |
| 971 | DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY; |
| 972 | |
Thales Lima | 11af7bc | 2022-08-12 15:24:54 +0100 | [diff] [blame] | 973 | private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0; |
| 974 | private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1; |
| 975 | private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2; |
| 976 | private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3; |
| 977 | private static final int DONT_INLINE_QSB = 0; |
| 978 | |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 979 | public final String name; |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 980 | public final String title; |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 981 | public final int numRows; |
| 982 | public final int numColumns; |
Alex Chau | 9fee3fd | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 983 | public final int numSearchContainerColumns; |
Sunny Goyal | 076e04b | 2023-04-03 12:38:30 -0700 | [diff] [blame] | 984 | public final int deviceCategory; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 985 | |
Thales Lima | 1faa4ed | 2023-12-01 16:48:19 +0000 | [diff] [blame] | 986 | private final int[] numFolderRows = new int[COUNT_SIZES]; |
| 987 | private final int[] numFolderColumns = new int[COUNT_SIZES]; |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 988 | private final @StyleRes int folderStyle; |
Thales Lima | d852d65 | 2023-01-17 14:01:13 +0000 | [diff] [blame] | 989 | private final @StyleRes int cellStyle; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 990 | |
Thales Lima | e9273ea | 2023-01-26 12:33:52 +0000 | [diff] [blame] | 991 | private final @StyleRes int allAppsStyle; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 992 | private final int numAllAppsColumns; |
Jordan Silva | 2de6a27 | 2024-01-04 14:44:20 -0300 | [diff] [blame] | 993 | private final int mNumAllAppsRowsForCellHeightCalculation; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 994 | private final int numDatabaseAllAppsColumns; |
| 995 | private final int numHotseatIcons; |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame] | 996 | private final int numDatabaseHotseatIcons; |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 997 | |
Thales Lima | 11af7bc | 2022-08-12 15:24:54 +0100 | [diff] [blame] | 998 | private final boolean[] inlineQsb = new boolean[COUNT_SIZES]; |
| 999 | |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 1000 | private @DimenRes int inlineNavButtonsEndSpacing; |
Tracy Zhou | 7df93d2 | 2020-01-27 13:44:06 -0800 | [diff] [blame] | 1001 | private final String dbFile; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 1002 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1003 | private final int defaultLayoutId; |
| 1004 | private final int demoModeLayoutId; |
| 1005 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 1006 | private final boolean isScalable; |
fbaron | 49f7df0 | 2024-11-05 16:15:19 -0800 | [diff] [blame] | 1007 | private final boolean mIsDualGrid; |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 1008 | private final int devicePaddingId; |
Thales Lima | ec5abba | 2023-04-05 16:33:50 +0100 | [diff] [blame] | 1009 | private final int mWorkspaceSpecsId; |
Jordan Silva | 575c3bd | 2023-07-21 12:00:43 +0100 | [diff] [blame] | 1010 | private final int mWorkspaceSpecsTwoPanelId; |
Thales Lima | abfe364 | 2023-05-24 18:08:53 +0100 | [diff] [blame] | 1011 | private final int mAllAppsSpecsId; |
Jordan Silva | 575c3bd | 2023-07-21 12:00:43 +0100 | [diff] [blame] | 1012 | private final int mAllAppsSpecsTwoPanelId; |
Jordan Silva | 637f4eb | 2023-06-13 11:21:53 +0100 | [diff] [blame] | 1013 | private final int mFolderSpecsId; |
Jordan Silva | 575c3bd | 2023-07-21 12:00:43 +0100 | [diff] [blame] | 1014 | private final int mFolderSpecsTwoPanelId; |
Thales Lima | f8bfb03 | 2023-07-24 15:08:05 +0100 | [diff] [blame] | 1015 | private final int mHotseatSpecsId; |
| 1016 | private final int mHotseatSpecsTwoPanelId; |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 1017 | private final int mWorkspaceCellSpecsId; |
| 1018 | private final int mWorkspaceCellSpecsTwoPanelId; |
| 1019 | private final int mAllAppsCellSpecsId; |
| 1020 | private final int mAllAppsCellSpecsTwoPanelId; |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 1021 | private final int mGridSizeSpecsId; |
Sebastian Franco | 9e4c99b | 2024-10-02 15:16:37 -0700 | [diff] [blame] | 1022 | private final boolean mIsFixedLandscape; |
fbaron | 6c91ef9 | 2024-11-12 22:22:43 -0800 | [diff] [blame] | 1023 | private final boolean mIsOldGrid; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 1024 | |
Federico Baron | 56307d2 | 2024-11-06 18:48:48 +0000 | [diff] [blame] | 1025 | public GridOption(Context context, AttributeSet attrs, Info displayInfo) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1026 | TypedArray a = context.obtainStyledAttributes( |
| 1027 | attrs, R.styleable.GridDisplayOption); |
| 1028 | name = a.getString(R.styleable.GridDisplayOption_name); |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 1029 | title = a.getString(R.styleable.GridDisplayOption_title); |
| 1030 | deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory, |
| 1031 | DEVICE_CATEGORY_ALL); |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 1032 | mGridSizeSpecsId = a.getResourceId( |
| 1033 | R.styleable.GridDisplayOption_gridSizeSpecsId, INVALID_RESOURCE_HANDLE); |
fbaron | 49f7df0 | 2024-11-05 16:15:19 -0800 | [diff] [blame] | 1034 | mIsDualGrid = a.getBoolean(R.styleable.GridDisplayOption_isDualGrid, false); |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 1035 | if (mGridSizeSpecsId != INVALID_RESOURCE_HANDLE) { |
| 1036 | ResourceHelper resourceHelper = new ResourceHelper(context, mGridSizeSpecsId); |
| 1037 | GridSize gridSize = getGridSize(resourceHelper, context, displayInfo); |
| 1038 | numColumns = gridSize.mNumColumns; |
| 1039 | numRows = gridSize.mNumRows; |
| 1040 | dbFile = gridSize.mDbFile; |
| 1041 | defaultLayoutId = gridSize.mDefaultLayoutId; |
| 1042 | demoModeLayoutId = gridSize.mDemoModeLayoutId; |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 1043 | } else { |
| 1044 | numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0); |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 1045 | numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0); |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 1046 | dbFile = a.getString(R.styleable.GridDisplayOption_dbFile); |
fbaron | c1b68f4 | 2024-11-08 18:10:46 -0800 | [diff] [blame] | 1047 | defaultLayoutId = a.getResourceId( |
| 1048 | R.styleable.GridDisplayOption_defaultLayoutId, 0); |
| 1049 | demoModeLayoutId = a.getResourceId( |
| 1050 | R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId); |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 1051 | } |
| 1052 | |
Alex Chau | 9fee3fd | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 1053 | numSearchContainerColumns = a.getInt( |
| 1054 | R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 1055 | |
Thales Lima | e9273ea | 2023-01-26 12:33:52 +0000 | [diff] [blame] | 1056 | allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle, |
| 1057 | R.style.AllAppsStyleDefault); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 1058 | numAllAppsColumns = a.getInt( |
| 1059 | R.styleable.GridDisplayOption_numAllAppsColumns, numColumns); |
| 1060 | numDatabaseAllAppsColumns = a.getInt( |
| 1061 | R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns); |
| 1062 | |
| 1063 | numHotseatIcons = a.getInt( |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1064 | R.styleable.GridDisplayOption_numHotseatIcons, numColumns); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 1065 | numDatabaseHotseatIcons = a.getInt( |
| 1066 | R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons); |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 1067 | |
Vinit Nayak | c729317 | 2022-07-18 16:41:50 -0700 | [diff] [blame] | 1068 | inlineNavButtonsEndSpacing = |
| 1069 | a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing, |
Thales Lima | ec5abba | 2023-04-05 16:33:50 +0100 | [diff] [blame] | 1070 | R.dimen.taskbar_button_margin_default); |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 1071 | |
Thales Lima | 1faa4ed | 2023-12-01 16:48:19 +0000 | [diff] [blame] | 1072 | numFolderRows[INDEX_DEFAULT] = a.getInt( |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1073 | R.styleable.GridDisplayOption_numFolderRows, numRows); |
Thales Lima | 1faa4ed | 2023-12-01 16:48:19 +0000 | [diff] [blame] | 1074 | numFolderColumns[INDEX_DEFAULT] = a.getInt( |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1075 | R.styleable.GridDisplayOption_numFolderColumns, numColumns); |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 1076 | |
Thales Lima | 1faa4ed | 2023-12-01 16:48:19 +0000 | [diff] [blame] | 1077 | if (FeatureFlags.enableResponsiveWorkspace()) { |
| 1078 | numFolderRows[INDEX_LANDSCAPE] = a.getInt( |
| 1079 | R.styleable.GridDisplayOption_numFolderRowsLandscape, |
| 1080 | numFolderRows[INDEX_DEFAULT]); |
| 1081 | numFolderColumns[INDEX_LANDSCAPE] = a.getInt( |
| 1082 | R.styleable.GridDisplayOption_numFolderColumnsLandscape, |
| 1083 | numFolderColumns[INDEX_DEFAULT]); |
| 1084 | numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = a.getInt( |
| 1085 | R.styleable.GridDisplayOption_numFolderRowsTwoPanelPortrait, |
| 1086 | numFolderRows[INDEX_DEFAULT]); |
| 1087 | numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = a.getInt( |
| 1088 | R.styleable.GridDisplayOption_numFolderColumnsTwoPanelPortrait, |
| 1089 | numFolderColumns[INDEX_DEFAULT]); |
| 1090 | numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt( |
| 1091 | R.styleable.GridDisplayOption_numFolderRowsTwoPanelLandscape, |
| 1092 | numFolderRows[INDEX_DEFAULT]); |
| 1093 | numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt( |
| 1094 | R.styleable.GridDisplayOption_numFolderColumnsTwoPanelLandscape, |
| 1095 | numFolderColumns[INDEX_DEFAULT]); |
| 1096 | } else { |
| 1097 | numFolderRows[INDEX_LANDSCAPE] = numFolderRows[INDEX_DEFAULT]; |
| 1098 | numFolderColumns[INDEX_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT]; |
| 1099 | numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = numFolderRows[INDEX_DEFAULT]; |
| 1100 | numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = numFolderColumns[INDEX_DEFAULT]; |
| 1101 | numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = numFolderRows[INDEX_DEFAULT]; |
| 1102 | numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT]; |
| 1103 | } |
| 1104 | |
Thales Lima | b35faed | 2022-09-05 16:30:01 -0300 | [diff] [blame] | 1105 | folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle, |
| 1106 | INVALID_RESOURCE_HANDLE); |
| 1107 | |
Thales Lima | d852d65 | 2023-01-17 14:01:13 +0000 | [diff] [blame] | 1108 | cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle, |
| 1109 | R.style.CellStyleDefault); |
| 1110 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 1111 | isScalable = a.getBoolean( |
| 1112 | R.styleable.GridDisplayOption_isScalable, false); |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 1113 | devicePaddingId = a.getResourceId( |
Thales Lima | ae0d7ef | 2022-11-16 15:53:43 +0000 | [diff] [blame] | 1114 | R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE); |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 1115 | |
Thales Lima | ca31b61 | 2023-09-14 14:25:26 +0100 | [diff] [blame] | 1116 | if (FeatureFlags.enableResponsiveWorkspace()) { |
Thales Lima | ec5abba | 2023-04-05 16:33:50 +0100 | [diff] [blame] | 1117 | mWorkspaceSpecsId = a.getResourceId( |
| 1118 | R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE); |
Jordan Silva | 575c3bd | 2023-07-21 12:00:43 +0100 | [diff] [blame] | 1119 | mWorkspaceSpecsTwoPanelId = a.getResourceId( |
| 1120 | R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId, |
Jordan Silva | d29f064 | 2024-01-10 15:11:26 -0300 | [diff] [blame] | 1121 | mWorkspaceSpecsId); |
Thales Lima | abfe364 | 2023-05-24 18:08:53 +0100 | [diff] [blame] | 1122 | mAllAppsSpecsId = a.getResourceId( |
| 1123 | R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE); |
Jordan Silva | 575c3bd | 2023-07-21 12:00:43 +0100 | [diff] [blame] | 1124 | mAllAppsSpecsTwoPanelId = a.getResourceId( |
| 1125 | R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId, |
Jordan Silva | d29f064 | 2024-01-10 15:11:26 -0300 | [diff] [blame] | 1126 | mAllAppsSpecsId); |
Jordan Silva | 637f4eb | 2023-06-13 11:21:53 +0100 | [diff] [blame] | 1127 | mFolderSpecsId = a.getResourceId( |
| 1128 | R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE); |
Jordan Silva | 575c3bd | 2023-07-21 12:00:43 +0100 | [diff] [blame] | 1129 | mFolderSpecsTwoPanelId = a.getResourceId( |
| 1130 | R.styleable.GridDisplayOption_folderSpecsTwoPanelId, |
Jordan Silva | d29f064 | 2024-01-10 15:11:26 -0300 | [diff] [blame] | 1131 | mFolderSpecsId); |
Thales Lima | f8bfb03 | 2023-07-24 15:08:05 +0100 | [diff] [blame] | 1132 | mHotseatSpecsId = a.getResourceId( |
| 1133 | R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE); |
| 1134 | mHotseatSpecsTwoPanelId = a.getResourceId( |
| 1135 | R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId, |
Jordan Silva | d29f064 | 2024-01-10 15:11:26 -0300 | [diff] [blame] | 1136 | mHotseatSpecsId); |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 1137 | mWorkspaceCellSpecsId = a.getResourceId( |
| 1138 | R.styleable.GridDisplayOption_workspaceCellSpecsId, |
| 1139 | INVALID_RESOURCE_HANDLE); |
| 1140 | mWorkspaceCellSpecsTwoPanelId = a.getResourceId( |
| 1141 | R.styleable.GridDisplayOption_workspaceCellSpecsTwoPanelId, |
Jordan Silva | d29f064 | 2024-01-10 15:11:26 -0300 | [diff] [blame] | 1142 | mWorkspaceCellSpecsId); |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 1143 | mAllAppsCellSpecsId = a.getResourceId( |
| 1144 | R.styleable.GridDisplayOption_allAppsCellSpecsId, |
| 1145 | INVALID_RESOURCE_HANDLE); |
| 1146 | mAllAppsCellSpecsTwoPanelId = a.getResourceId( |
| 1147 | R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId, |
Jordan Silva | d29f064 | 2024-01-10 15:11:26 -0300 | [diff] [blame] | 1148 | mAllAppsCellSpecsId); |
Jordan Silva | 2de6a27 | 2024-01-04 14:44:20 -0300 | [diff] [blame] | 1149 | mNumAllAppsRowsForCellHeightCalculation = a.getInt( |
| 1150 | R.styleable.GridDisplayOption_numAllAppsRowsForCellHeightCalculation, |
| 1151 | numRows); |
Thales Lima | ec5abba | 2023-04-05 16:33:50 +0100 | [diff] [blame] | 1152 | } else { |
| 1153 | mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE; |
Jordan Silva | 575c3bd | 2023-07-21 12:00:43 +0100 | [diff] [blame] | 1154 | mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; |
Thales Lima | abfe364 | 2023-05-24 18:08:53 +0100 | [diff] [blame] | 1155 | mAllAppsSpecsId = INVALID_RESOURCE_HANDLE; |
Jordan Silva | 575c3bd | 2023-07-21 12:00:43 +0100 | [diff] [blame] | 1156 | mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; |
Jordan Silva | 637f4eb | 2023-06-13 11:21:53 +0100 | [diff] [blame] | 1157 | mFolderSpecsId = INVALID_RESOURCE_HANDLE; |
Jordan Silva | 575c3bd | 2023-07-21 12:00:43 +0100 | [diff] [blame] | 1158 | mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; |
Thales Lima | f8bfb03 | 2023-07-24 15:08:05 +0100 | [diff] [blame] | 1159 | mHotseatSpecsId = INVALID_RESOURCE_HANDLE; |
| 1160 | mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; |
Jordan Silva | 999dd2a | 2023-11-17 19:31:43 +0000 | [diff] [blame] | 1161 | mWorkspaceCellSpecsId = INVALID_RESOURCE_HANDLE; |
| 1162 | mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; |
| 1163 | mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE; |
| 1164 | mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; |
Jordan Silva | 2de6a27 | 2024-01-04 14:44:20 -0300 | [diff] [blame] | 1165 | mNumAllAppsRowsForCellHeightCalculation = numRows; |
Thales Lima | ec5abba | 2023-04-05 16:33:50 +0100 | [diff] [blame] | 1166 | } |
| 1167 | |
Sebastian Franco | 9e4c99b | 2024-10-02 15:16:37 -0700 | [diff] [blame] | 1168 | mIsFixedLandscape = a.getBoolean(R.styleable.GridDisplayOption_isFixedLandscape, false); |
fbaron | 6c91ef9 | 2024-11-12 22:22:43 -0800 | [diff] [blame] | 1169 | mIsOldGrid = a.getBoolean(R.styleable.GridDisplayOption_isOldGrid, false); |
Sebastian Franco | 9e4c99b | 2024-10-02 15:16:37 -0700 | [diff] [blame] | 1170 | |
Thales Lima | 11af7bc | 2022-08-12 15:24:54 +0100 | [diff] [blame] | 1171 | int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb, |
| 1172 | DONT_INLINE_QSB); |
| 1173 | inlineQsb[INDEX_DEFAULT] = |
| 1174 | (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT; |
| 1175 | inlineQsb[INDEX_LANDSCAPE] = |
| 1176 | (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE; |
| 1177 | inlineQsb[INDEX_TWO_PANEL_PORTRAIT] = |
| 1178 | (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT) |
| 1179 | == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT; |
| 1180 | inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] = |
| 1181 | (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE) |
| 1182 | == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE; |
| 1183 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1184 | a.recycle(); |
Sunny Goyal | 076e04b | 2023-04-03 12:38:30 -0700 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | public boolean isEnabled(@DeviceType int deviceType) { |
| 1188 | switch (deviceType) { |
| 1189 | case TYPE_PHONE: |
| 1190 | return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE; |
| 1191 | case TYPE_TABLET: |
| 1192 | return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET; |
| 1193 | case TYPE_MULTI_DISPLAY: |
| 1194 | return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY) |
| 1195 | == DEVICE_CATEGORY_MULTI_DISPLAY; |
| 1196 | default: |
| 1197 | return false; |
| 1198 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1199 | } |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 1200 | |
fbaron | 6c91ef9 | 2024-11-12 22:22:43 -0800 | [diff] [blame] | 1201 | /** |
| 1202 | * Returns true if the grid option should be used given the flags that are toggled on/off. |
| 1203 | */ |
fbaron | c1b68f4 | 2024-11-08 18:10:46 -0800 | [diff] [blame] | 1204 | public boolean filterByFlag(int deviceType, boolean isFixedLandscape) { |
fbaron | 49f7df0 | 2024-11-05 16:15:19 -0800 | [diff] [blame] | 1205 | if (deviceType == TYPE_TABLET) { |
| 1206 | return Flags.oneGridRotationHandling() == mIsDualGrid; |
| 1207 | } |
fbaron | c1b68f4 | 2024-11-08 18:10:46 -0800 | [diff] [blame] | 1208 | |
fbaron | 6c91ef9 | 2024-11-12 22:22:43 -0800 | [diff] [blame] | 1209 | // Here we return true if fixed landscape mode should be on. |
| 1210 | if (mIsFixedLandscape || isFixedLandscape) { |
| 1211 | return mIsFixedLandscape && isFixedLandscape && Flags.oneGridSpecs(); |
fbaron | c1b68f4 | 2024-11-08 18:10:46 -0800 | [diff] [blame] | 1212 | } |
| 1213 | |
fbaron | 6c91ef9 | 2024-11-12 22:22:43 -0800 | [diff] [blame] | 1214 | // Here we return true if we want to show the new grids. |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 1215 | if (mGridSizeSpecsId != INVALID_RESOURCE_HANDLE) { |
fbaron | 6c91ef9 | 2024-11-12 22:22:43 -0800 | [diff] [blame] | 1216 | return Flags.oneGridSpecs(); |
| 1217 | } |
| 1218 | |
| 1219 | // Here we return true if we want to show the old grids. |
| 1220 | if (mIsOldGrid) { |
| 1221 | return !Flags.oneGridSpecs(); |
| 1222 | } |
| 1223 | |
| 1224 | return true; |
fbaron | 49f7df0 | 2024-11-05 16:15:19 -0800 | [diff] [blame] | 1225 | } |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 1226 | } |
| 1227 | |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 1228 | public static final class GridSize { |
| 1229 | final int mNumRows; |
| 1230 | final int mNumColumns; |
| 1231 | final float mMinDeviceWidthDp; |
| 1232 | final float mMinDeviceHeightDp; |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 1233 | final String mDbFile; |
fbaron | c1b68f4 | 2024-11-08 18:10:46 -0800 | [diff] [blame] | 1234 | final int mDefaultLayoutId; |
| 1235 | final int mDemoModeLayoutId; |
| 1236 | |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 1237 | |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 1238 | GridSize(Context context, AttributeSet attrs) { |
| 1239 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GridSize); |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 1240 | |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 1241 | mNumRows = (int) a.getFloat(R.styleable.GridSize_numGridRows, 0); |
| 1242 | mNumColumns = (int) a.getFloat(R.styleable.GridSize_numGridColumns, 0); |
| 1243 | mMinDeviceWidthDp = a.getFloat(R.styleable.GridSize_minDeviceWidthDp, 0); |
| 1244 | mMinDeviceHeightDp = a.getFloat(R.styleable.GridSize_minDeviceHeightDp, 0); |
| 1245 | mDbFile = a.getString(R.styleable.GridSize_dbFile); |
fbaron | c1b68f4 | 2024-11-08 18:10:46 -0800 | [diff] [blame] | 1246 | mDefaultLayoutId = a.getResourceId( |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 1247 | R.styleable.GridSize_defaultLayoutId, 0); |
fbaron | c1b68f4 | 2024-11-08 18:10:46 -0800 | [diff] [blame] | 1248 | mDemoModeLayoutId = a.getResourceId( |
fbaron | d1cd8c2 | 2024-11-26 10:13:36 -0800 | [diff] [blame^] | 1249 | R.styleable.GridSize_demoModeLayoutId, mDefaultLayoutId); |
fbaron | ebc10c9 | 2024-09-03 12:51:41 -0700 | [diff] [blame] | 1250 | |
| 1251 | a.recycle(); |
| 1252 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1253 | } |
| 1254 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 1255 | @VisibleForTesting |
| 1256 | static final class DisplayOption { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 1257 | public final GridOption grid; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1258 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1259 | private final float minWidthDps; |
| 1260 | private final float minHeightDps; |
| 1261 | private final boolean canBeDefault; |
| 1262 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1263 | private final PointF[] minCellSize = new PointF[COUNT_SIZES]; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1264 | |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1265 | private final PointF[] borderSpaces = new PointF[COUNT_SIZES]; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1266 | private final float[] horizontalMargin = new float[COUNT_SIZES]; |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 1267 | private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES]; |
| 1268 | private final float[] hotseatQsbSpace = new float[COUNT_SIZES]; |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 1269 | |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1270 | private final float[] iconSizes = new float[COUNT_SIZES]; |
| 1271 | private final float[] textSizes = new float[COUNT_SIZES]; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1272 | |
Thales Lima | b7ef569 | 2022-03-10 10:32:36 +0000 | [diff] [blame] | 1273 | private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES]; |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 1274 | private final float[] allAppsIconSizes = new float[COUNT_SIZES]; |
| 1275 | private final float[] allAppsIconTextSizes = new float[COUNT_SIZES]; |
| 1276 | private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES]; |
| 1277 | |
Jon Miranda | 9c478b6 | 2023-03-23 21:38:49 -0700 | [diff] [blame] | 1278 | private final float[] transientTaskbarIconSize = new float[COUNT_SIZES]; |
| 1279 | |
Jon Miranda | 04f0510 | 2023-04-04 12:16:31 -0700 | [diff] [blame] | 1280 | private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES]; |
| 1281 | |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame] | 1282 | DisplayOption(GridOption grid, Context context, AttributeSet attrs) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1283 | this.grid = grid; |
| 1284 | |
Jon Miranda | 9c478b6 | 2023-03-23 21:38:49 -0700 | [diff] [blame] | 1285 | Resources res = context.getResources(); |
| 1286 | |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame] | 1287 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1288 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1289 | minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0); |
| 1290 | minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 1291 | |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame] | 1292 | canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1293 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1294 | float x; |
| 1295 | float y; |
| 1296 | |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1297 | x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0); |
| 1298 | y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0); |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1299 | minCellSize[INDEX_DEFAULT] = new PointF(x, y); |
Thales Lima | dd02734 | 2022-01-07 12:54:37 +0000 | [diff] [blame] | 1300 | |
| 1301 | x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape, |
| 1302 | minCellSize[INDEX_DEFAULT].x); |
| 1303 | y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape, |
| 1304 | minCellSize[INDEX_DEFAULT].y); |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1305 | minCellSize[INDEX_LANDSCAPE] = new PointF(x, y); |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1306 | |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1307 | x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1308 | minCellSize[INDEX_DEFAULT].x); |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1309 | y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1310 | minCellSize[INDEX_DEFAULT].y); |
| 1311 | minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y); |
| 1312 | |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1313 | x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1314 | minCellSize[INDEX_DEFAULT].x); |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1315 | y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1316 | minCellSize[INDEX_DEFAULT].y); |
| 1317 | minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1318 | |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1319 | float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0); |
Thales Lima | 44cc3a2 | 2022-03-18 14:28:24 +0000 | [diff] [blame] | 1320 | float borderSpaceLandscape = a.getFloat( |
| 1321 | R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace); |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1322 | float borderSpaceTwoPanelPortrait = a.getFloat( |
| 1323 | R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace); |
| 1324 | float borderSpaceTwoPanelLandscape = a.getFloat( |
| 1325 | R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1326 | |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1327 | x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace); |
| 1328 | y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1329 | borderSpaces[INDEX_DEFAULT] = new PointF(x, y); |
Thales Lima | 44cc3a2 | 2022-03-18 14:28:24 +0000 | [diff] [blame] | 1330 | |
| 1331 | x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal, |
| 1332 | borderSpaceLandscape); |
| 1333 | y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical, |
| 1334 | borderSpaceLandscape); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1335 | borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y); |
| 1336 | |
| 1337 | x = a.getFloat( |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1338 | R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal, |
| 1339 | borderSpaceTwoPanelPortrait); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1340 | y = a.getFloat( |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1341 | R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical, |
| 1342 | borderSpaceTwoPanelPortrait); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1343 | borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y); |
| 1344 | |
| 1345 | x = a.getFloat( |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1346 | R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal, |
| 1347 | borderSpaceTwoPanelLandscape); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1348 | y = a.getFloat( |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1349 | R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical, |
| 1350 | borderSpaceTwoPanelLandscape); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1351 | borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y); |
| 1352 | |
Thales Lima | b7ef569 | 2022-03-10 10:32:36 +0000 | [diff] [blame] | 1353 | x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth, |
| 1354 | minCellSize[INDEX_DEFAULT].x); |
| 1355 | y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight, |
| 1356 | minCellSize[INDEX_DEFAULT].y); |
| 1357 | allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y); |
| 1358 | |
| 1359 | x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape, |
| 1360 | allAppsCellSize[INDEX_DEFAULT].x); |
| 1361 | y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape, |
| 1362 | allAppsCellSize[INDEX_DEFAULT].y); |
| 1363 | allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y); |
| 1364 | |
| 1365 | x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait, |
| 1366 | allAppsCellSize[INDEX_DEFAULT].x); |
| 1367 | y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait, |
| 1368 | allAppsCellSize[INDEX_DEFAULT].y); |
| 1369 | allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y); |
| 1370 | |
| 1371 | x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape, |
| 1372 | allAppsCellSize[INDEX_DEFAULT].x); |
| 1373 | y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape, |
| 1374 | allAppsCellSize[INDEX_DEFAULT].y); |
| 1375 | allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y); |
| 1376 | |
Thales Lima | 080d890 | 2022-03-28 15:30:29 +0100 | [diff] [blame] | 1377 | float allAppsBorderSpace = a.getFloat( |
| 1378 | R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace); |
| 1379 | float allAppsBorderSpaceLandscape = a.getFloat( |
| 1380 | R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape, |
| 1381 | allAppsBorderSpace); |
| 1382 | float allAppsBorderSpaceTwoPanelPortrait = a.getFloat( |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 1383 | R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait, |
Thales Lima | 080d890 | 2022-03-28 15:30:29 +0100 | [diff] [blame] | 1384 | allAppsBorderSpace); |
| 1385 | float allAppsBorderSpaceTwoPanelLandscape = a.getFloat( |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 1386 | R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape, |
Thales Lima | 080d890 | 2022-03-28 15:30:29 +0100 | [diff] [blame] | 1387 | allAppsBorderSpace); |
| 1388 | |
| 1389 | x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal, |
| 1390 | allAppsBorderSpace); |
| 1391 | y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical, |
| 1392 | allAppsBorderSpace); |
| 1393 | allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y); |
| 1394 | |
| 1395 | x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal, |
| 1396 | allAppsBorderSpaceLandscape); |
| 1397 | y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical, |
| 1398 | allAppsBorderSpaceLandscape); |
| 1399 | allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y); |
| 1400 | |
| 1401 | x = a.getFloat( |
| 1402 | R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal, |
| 1403 | allAppsBorderSpaceTwoPanelPortrait); |
| 1404 | y = a.getFloat( |
| 1405 | R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical, |
| 1406 | allAppsBorderSpaceTwoPanelPortrait); |
| 1407 | allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y); |
| 1408 | |
| 1409 | x = a.getFloat( |
| 1410 | R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal, |
| 1411 | allAppsBorderSpaceTwoPanelLandscape); |
| 1412 | y = a.getFloat( |
| 1413 | R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical, |
| 1414 | allAppsBorderSpaceTwoPanelLandscape); |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 1415 | allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 1416 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 1417 | iconSizes[INDEX_DEFAULT] = |
| 1418 | a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0); |
| 1419 | iconSizes[INDEX_LANDSCAPE] = |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1420 | a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape, |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 1421 | iconSizes[INDEX_DEFAULT]); |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 1422 | iconSizes[INDEX_TWO_PANEL_PORTRAIT] = |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1423 | a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait, |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 1424 | iconSizes[INDEX_DEFAULT]); |
| 1425 | iconSizes[INDEX_TWO_PANEL_LANDSCAPE] = |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1426 | a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1427 | iconSizes[INDEX_DEFAULT]); |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 1428 | |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 1429 | allAppsIconSizes[INDEX_DEFAULT] = a.getFloat( |
| 1430 | R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]); |
Thales Lima | 1fb075d | 2022-08-10 10:47:50 +0100 | [diff] [blame] | 1431 | allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat( |
| 1432 | R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape, |
Thales Lima | ed8c69b | 2022-08-17 12:21:21 -0400 | [diff] [blame] | 1433 | allAppsIconSizes[INDEX_DEFAULT]); |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 1434 | allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat( |
| 1435 | R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait, |
| 1436 | allAppsIconSizes[INDEX_DEFAULT]); |
| 1437 | allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat( |
| 1438 | R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape, |
| 1439 | allAppsIconSizes[INDEX_DEFAULT]); |
| 1440 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 1441 | textSizes[INDEX_DEFAULT] = |
| 1442 | a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0); |
| 1443 | textSizes[INDEX_LANDSCAPE] = |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1444 | a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape, |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 1445 | textSizes[INDEX_DEFAULT]); |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 1446 | textSizes[INDEX_TWO_PANEL_PORTRAIT] = |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1447 | a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait, |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 1448 | textSizes[INDEX_DEFAULT]); |
| 1449 | textSizes[INDEX_TWO_PANEL_LANDSCAPE] = |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1450 | a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1451 | textSizes[INDEX_DEFAULT]); |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 1452 | |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 1453 | allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat( |
| 1454 | R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]); |
| 1455 | allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT]; |
| 1456 | allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat( |
| 1457 | R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait, |
| 1458 | allAppsIconTextSizes[INDEX_DEFAULT]); |
| 1459 | allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat( |
| 1460 | R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape, |
| 1461 | allAppsIconTextSizes[INDEX_DEFAULT]); |
| 1462 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1463 | horizontalMargin[INDEX_DEFAULT] = a.getFloat( |
| 1464 | R.styleable.ProfileDisplayOption_horizontalMargin, 0); |
Thales Lima | dd02734 | 2022-01-07 12:54:37 +0000 | [diff] [blame] | 1465 | horizontalMargin[INDEX_LANDSCAPE] = a.getFloat( |
| 1466 | R.styleable.ProfileDisplayOption_horizontalMarginLandscape, |
| 1467 | horizontalMargin[INDEX_DEFAULT]); |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1468 | horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat( |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1469 | R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1470 | horizontalMargin[INDEX_DEFAULT]); |
| 1471 | horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat( |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1472 | R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1473 | horizontalMargin[INDEX_DEFAULT]); |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 1474 | |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 1475 | hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat( |
| 1476 | R.styleable.ProfileDisplayOption_hotseatBarBottomSpace, |
Jon Miranda | 9c478b6 | 2023-03-23 21:38:49 -0700 | [diff] [blame] | 1477 | ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default)); |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 1478 | hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat( |
| 1479 | R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape, |
| 1480 | hotseatBarBottomSpace[INDEX_DEFAULT]); |
| 1481 | hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat( |
| 1482 | R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape, |
| 1483 | hotseatBarBottomSpace[INDEX_DEFAULT]); |
| 1484 | hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat( |
| 1485 | R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait, |
| 1486 | hotseatBarBottomSpace[INDEX_DEFAULT]); |
| 1487 | |
| 1488 | hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat( |
| 1489 | R.styleable.ProfileDisplayOption_hotseatQsbSpace, |
Jon Miranda | 9c478b6 | 2023-03-23 21:38:49 -0700 | [diff] [blame] | 1490 | ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default)); |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 1491 | hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat( |
| 1492 | R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape, |
| 1493 | hotseatQsbSpace[INDEX_DEFAULT]); |
| 1494 | hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat( |
| 1495 | R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape, |
| 1496 | hotseatQsbSpace[INDEX_DEFAULT]); |
| 1497 | hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat( |
| 1498 | R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait, |
| 1499 | hotseatQsbSpace[INDEX_DEFAULT]); |
| 1500 | |
Jon Miranda | 9c478b6 | 2023-03-23 21:38:49 -0700 | [diff] [blame] | 1501 | transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat( |
| 1502 | R.styleable.ProfileDisplayOption_transientTaskbarIconSize, |
| 1503 | ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size)); |
| 1504 | transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat( |
| 1505 | R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape, |
| 1506 | transientTaskbarIconSize[INDEX_DEFAULT]); |
| 1507 | transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat( |
| 1508 | R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape, |
| 1509 | transientTaskbarIconSize[INDEX_DEFAULT]); |
| 1510 | transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat( |
| 1511 | R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait, |
Jon Miranda | 4d74ad3 | 2023-03-27 16:31:11 -0700 | [diff] [blame] | 1512 | transientTaskbarIconSize[INDEX_DEFAULT]); |
Jon Miranda | 9c478b6 | 2023-03-23 21:38:49 -0700 | [diff] [blame] | 1513 | |
Jon Miranda | 04f0510 | 2023-04-04 12:16:31 -0700 | [diff] [blame] | 1514 | startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean( |
| 1515 | R.styleable.ProfileDisplayOption_startAlignTaskbar, false); |
| 1516 | startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean( |
| 1517 | R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape, |
| 1518 | startAlignTaskbar[INDEX_DEFAULT]); |
| 1519 | startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean( |
| 1520 | R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape, |
| 1521 | startAlignTaskbar[INDEX_LANDSCAPE]); |
| 1522 | startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean( |
| 1523 | R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait, |
| 1524 | startAlignTaskbar[INDEX_DEFAULT]); |
| 1525 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1526 | a.recycle(); |
| 1527 | } |
| 1528 | |
| 1529 | DisplayOption() { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 1530 | this(null); |
| 1531 | } |
| 1532 | |
| 1533 | DisplayOption(GridOption grid) { |
| 1534 | this.grid = grid; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1535 | minWidthDps = 0; |
| 1536 | minHeightDps = 0; |
| 1537 | canBeDefault = false; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1538 | for (int i = 0; i < COUNT_SIZES; i++) { |
| 1539 | iconSizes[i] = 0; |
| 1540 | textSizes[i] = 0; |
| 1541 | borderSpaces[i] = new PointF(); |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1542 | minCellSize[i] = new PointF(); |
Thales Lima | b7ef569 | 2022-03-10 10:32:36 +0000 | [diff] [blame] | 1543 | allAppsCellSize[i] = new PointF(); |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 1544 | allAppsIconSizes[i] = 0; |
| 1545 | allAppsIconTextSizes[i] = 0; |
| 1546 | allAppsBorderSpaces[i] = new PointF(); |
Jon Miranda | 9c478b6 | 2023-03-23 21:38:49 -0700 | [diff] [blame] | 1547 | transientTaskbarIconSize[i] = 0; |
Jon Miranda | 04f0510 | 2023-04-04 12:16:31 -0700 | [diff] [blame] | 1548 | startAlignTaskbar[i] = false; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1549 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | private DisplayOption multiply(float w) { |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1553 | for (int i = 0; i < COUNT_SIZES; i++) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 1554 | iconSizes[i] *= w; |
| 1555 | textSizes[i] *= w; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1556 | borderSpaces[i].x *= w; |
| 1557 | borderSpaces[i].y *= w; |
| 1558 | minCellSize[i].x *= w; |
| 1559 | minCellSize[i].y *= w; |
| 1560 | horizontalMargin[i] *= w; |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 1561 | hotseatBarBottomSpace[i] *= w; |
| 1562 | hotseatQsbSpace[i] *= w; |
Thales Lima | b7ef569 | 2022-03-10 10:32:36 +0000 | [diff] [blame] | 1563 | allAppsCellSize[i].x *= w; |
| 1564 | allAppsCellSize[i].y *= w; |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 1565 | allAppsIconSizes[i] *= w; |
| 1566 | allAppsIconTextSizes[i] *= w; |
| 1567 | allAppsBorderSpaces[i].x *= w; |
| 1568 | allAppsBorderSpaces[i].y *= w; |
Jon Miranda | 9c478b6 | 2023-03-23 21:38:49 -0700 | [diff] [blame] | 1569 | transientTaskbarIconSize[i] *= w; |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 1570 | } |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1571 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1572 | return this; |
| 1573 | } |
| 1574 | |
| 1575 | private DisplayOption add(DisplayOption p) { |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1576 | for (int i = 0; i < COUNT_SIZES; i++) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 1577 | iconSizes[i] += p.iconSizes[i]; |
| 1578 | textSizes[i] += p.textSizes[i]; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1579 | borderSpaces[i].x += p.borderSpaces[i].x; |
| 1580 | borderSpaces[i].y += p.borderSpaces[i].y; |
| 1581 | minCellSize[i].x += p.minCellSize[i].x; |
| 1582 | minCellSize[i].y += p.minCellSize[i].y; |
| 1583 | horizontalMargin[i] += p.horizontalMargin[i]; |
Thales Lima | b8c0595 | 2022-05-23 16:58:38 +0100 | [diff] [blame] | 1584 | hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i]; |
| 1585 | hotseatQsbSpace[i] += p.hotseatQsbSpace[i]; |
Thales Lima | b7ef569 | 2022-03-10 10:32:36 +0000 | [diff] [blame] | 1586 | allAppsCellSize[i].x += p.allAppsCellSize[i].x; |
| 1587 | allAppsCellSize[i].y += p.allAppsCellSize[i].y; |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 1588 | allAppsIconSizes[i] += p.allAppsIconSizes[i]; |
| 1589 | allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i]; |
| 1590 | allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x; |
| 1591 | allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y; |
Jon Miranda | 9c478b6 | 2023-03-23 21:38:49 -0700 | [diff] [blame] | 1592 | transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i]; |
Jon Miranda | 04f0510 | 2023-04-04 12:16:31 -0700 | [diff] [blame] | 1593 | startAlignTaskbar[i] |= p.startAlignTaskbar[i]; |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 1594 | } |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1595 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1596 | return this; |
| 1597 | } |
| 1598 | } |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 1599 | } |