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