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