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