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