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