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