blob: ece6540d3df85f8ee28f6c5100448750fada9e14 [file] [log] [blame]
Adam Cohen2e6da152015-05-06 11:42:25 -07001/*
Thales Lima1de4d552021-10-13 16:13:25 +01002 * Copyright (C) 2021 The Android Open Source Project
Adam Cohen2e6da152015-05-06 11:42:25 -07003 *
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
17package com.android.launcher3;
18
Stefan Andonian4c9612b2023-02-22 00:00:03 +000019import static com.android.launcher3.LauncherPrefs.GRID_NAME;
Sunny Goyal19ff7282021-04-22 10:12:54 -070020import static com.android.launcher3.Utilities.dpiFromPx;
Thales Limab35faed2022-09-05 16:30:01 -030021import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURCE_HANDLE;
Sunny Goyal35c7b192021-04-20 16:51:10 -070022import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY;
Jagrut Desai2e8ca872024-04-17 15:27:30 -070023import static com.android.launcher3.util.DisplayController.CHANGE_DESKTOP_MODE;
Alex Chau6ed408f2022-03-04 12:58:05 +000024import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE;
Sunny Goyal19ff7282021-04-22 10:12:54 -070025import static com.android.launcher3.util.DisplayController.CHANGE_SUPPORTED_BOUNDS;
Jagrut Desai3a7d1392023-09-06 15:56:19 -070026import static com.android.launcher3.util.DisplayController.CHANGE_TASKBAR_PINNING;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080027import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
Sunny Goyal87dc48b2018-10-12 11:42:33 -070028
Sunny Goyalc6205602015-05-21 20:46:33 -070029import android.annotation.TargetApi;
Adam Cohen2e6da152015-05-06 11:42:25 -070030import android.content.Context;
Hyunyoung Songc55a3502018-12-04 15:43:16 -080031import android.content.res.Resources;
Sunny Goyal819e1932016-07-07 16:43:58 -070032import android.content.res.TypedArray;
33import android.content.res.XmlResourceParser;
Adam Cohen2e6da152015-05-06 11:42:25 -070034import android.graphics.Point;
Thales Lima78d00ad2021-09-30 11:29:06 +010035import android.graphics.PointF;
Alex Chauc09a98a2023-11-14 12:51:42 +000036import android.graphics.Rect;
Brandon Dayauon51db65e2024-10-23 15:07:37 -070037import android.os.Trace;
Sunny Goyal415f1732018-11-29 10:33:47 -080038import android.text.TextUtils;
39import android.util.AttributeSet;
Adam Cohen2e6da152015-05-06 11:42:25 -070040import android.util.DisplayMetrics;
Thales Lima7ec83822021-08-05 13:32:10 +010041import android.util.Log;
Sunny Goyal5bc18462019-01-07 15:13:39 -080042import android.util.SparseArray;
Sunny Goyal819e1932016-07-07 16:43:58 -070043import android.util.Xml;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080044import android.view.Display;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070045
Thales Limab35faed2022-09-05 16:30:01 -030046import androidx.annotation.DimenRes;
Alex Chau1c883d82021-12-01 18:43:10 +000047import androidx.annotation.IntDef;
Thales Limab35faed2022-09-05 16:30:01 -030048import androidx.annotation.StyleRes;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070049import androidx.annotation.VisibleForTesting;
Thales Limaae0d7ef2022-11-16 15:53:43 +000050import androidx.annotation.XmlRes;
Thales Limab8c05952022-05-23 16:58:38 +010051import androidx.core.content.res.ResourcesCompat;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070052
Thales Limaec5abba2023-04-05 16:33:50 +010053import com.android.launcher3.config.FeatureFlags;
Sunny Goyal65190ae2022-08-02 14:16:26 -070054import com.android.launcher3.icons.DotRenderer;
Charlie Andersonc9d11e82023-08-02 11:41:55 -040055import com.android.launcher3.logging.FileLog;
Sunny Goyal68031ca2021-08-02 12:23:44 -070056import com.android.launcher3.model.DeviceGridState;
Alex Chau238aaee2021-10-06 16:15:24 +010057import com.android.launcher3.provider.RestoreDbTask;
vadimtf6ef8792022-07-26 13:54:31 -070058import com.android.launcher3.testing.shared.ResourceUtils;
Sunny Goyalfd58da62020-08-11 12:06:49 -070059import com.android.launcher3.util.DisplayController;
60import com.android.launcher3.util.DisplayController.Info;
Stefan Andonian5bd9a222023-02-23 00:58:33 +000061import com.android.launcher3.util.LockedUserState;
Sunny Goyald0e360a2018-06-29 14:40:18 -070062import com.android.launcher3.util.MainThreadInitializedObject;
Sunny Goyal3e58eea2022-11-14 14:30:07 -080063import com.android.launcher3.util.Partner;
Sunny Goyal10fa0162024-04-21 00:13:35 -070064import com.android.launcher3.util.SafeCloseable;
Sunny Goyal19ff7282021-04-22 10:12:54 -070065import com.android.launcher3.util.WindowBounds;
Sunny Goyal187b16c2022-03-01 16:53:23 -080066import com.android.launcher3.util.window.WindowManagerProxy;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070067
Sunny Goyal819e1932016-07-07 16:43:58 -070068import org.xmlpull.v1.XmlPullParser;
69import org.xmlpull.v1.XmlPullParserException;
70
71import java.io.IOException;
Alex Chau1c883d82021-12-01 18:43:10 +000072import java.lang.annotation.Retention;
73import java.lang.annotation.RetentionPolicy;
Adam Cohen2e6da152015-05-06 11:42:25 -070074import java.util.ArrayList;
Sunny Goyal6e6f7992021-08-24 16:23:29 -070075import java.util.Arrays;
Sunny Goyal6d55f662019-01-02 12:13:43 -080076import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070077import java.util.List;
Sebastián Francoad46eb72024-03-11 20:56:57 +000078import java.util.Objects;
Sunny Goyal076e04b2023-04-03 12:38:30 -070079import java.util.stream.Collectors;
Adam Cohen2e6da152015-05-06 11:42:25 -070080
Sunny Goyal10fa0162024-04-21 00:13:35 -070081public class InvariantDeviceProfile implements SafeCloseable {
Adam Cohen2e6da152015-05-06 11:42:25 -070082
Hyunyoung Songc55a3502018-12-04 15:43:16 -080083 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070084 // We do not need any synchronization for this variable as its only written on UI thread.
85 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070086 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070087
Alex Chau1c883d82021-12-01 18:43:10 +000088 @Retention(RetentionPolicy.SOURCE)
89 @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET})
Thales Limab8c05952022-05-23 16:58:38 +010090 public @interface DeviceType {}
91
Alex Chau1c883d82021-12-01 18:43:10 +000092 public static final int TYPE_PHONE = 0;
93 public static final int TYPE_MULTI_DISPLAY = 1;
94 public static final int TYPE_TABLET = 2;
95
Sunny Goyal53d7ee42015-05-22 12:25:45 -070096 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
97
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070098 // Constants that affects the interpolation curve between statically defined device profile
99 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800100 private static final float KNEARESTNEIGHBOR = 3;
101 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -0700102
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700103 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800104 private static final float WEIGHT_EFFICIENT = 100000f;
105
Thales Lima83bedbf2021-10-05 17:47:39 +0100106 // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different
107 // constraints
Thales Limabb7d3882021-12-22 12:56:29 +0000108 static final int COUNT_SIZES = 4;
Thales Lima83bedbf2021-10-05 17:47:39 +0100109 static final int INDEX_DEFAULT = 0;
110 static final int INDEX_LANDSCAPE = 1;
111 static final int INDEX_TWO_PANEL_PORTRAIT = 2;
112 static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
Thales Lima83bedbf2021-10-05 17:47:39 +0100113
Thales Limaec5abba2023-04-05 16:33:50 +0100114 /** These resources are used to override the device profile */
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800115 private static final String RES_GRID_NUM_ROWS = "grid_num_rows";
116 private static final String RES_GRID_NUM_COLUMNS = "grid_num_columns";
117 private static final String RES_GRID_ICON_SIZE_DP = "grid_icon_size_dp";
118
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700119 /**
120 * Number of icons per row and column in the workspace.
121 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700122 public int numRows;
123 public int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000124 public int numSearchContainerColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700125
126 /**
127 * Number of icons per row and column in the folder.
128 */
Thales Lima1faa4ed2023-12-01 16:48:19 +0000129 public int[] numFolderRows;
130 public int[] numFolderColumns;
Thales Lima83bedbf2021-10-05 17:47:39 +0100131 public float[] iconSize;
132 public float[] iconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700133 public int iconBitmapSize;
134 public int fillResIconDpi;
Alex Chau1c883d82021-12-01 18:43:10 +0000135 public @DeviceType int deviceType;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700136
Thales Lima83bedbf2021-10-05 17:47:39 +0100137 public PointF[] minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100138
Thales Lima83bedbf2021-10-05 17:47:39 +0100139 public PointF[] borderSpaces;
Thales Limab35faed2022-09-05 16:30:01 -0300140 public @DimenRes int inlineNavButtonsEndSpacing;
Thales Lima78d00ad2021-09-30 11:29:06 +0100141
Thales Limab35faed2022-09-05 16:30:01 -0300142 public @StyleRes int folderStyle;
Thales Limaa08a4432022-08-09 09:55:17 +0100143
Thales Limad852d652023-01-17 14:01:13 +0000144 public @StyleRes int cellStyle;
145
Thales Lima83bedbf2021-10-05 17:47:39 +0100146 public float[] horizontalMargin;
Jon Mirandae126d722021-02-25 10:45:20 -0500147
Thales Limab7ef5692022-03-10 10:32:36 +0000148 public PointF[] allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000149 public float[] allAppsIconSize;
150 public float[] allAppsIconTextSize;
151 public PointF[] allAppsBorderSpaces;
152
Jon Miranda9c478b62023-03-23 21:38:49 -0700153 public float[] transientTaskbarIconSize;
154
Jon Miranda04f05102023-04-04 12:16:31 -0700155 public boolean[] startAlignTaskbar;
156
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700157 /**
158 * Number of icons inside the hotseat area.
159 */
Jon Mirandafd48b0c2022-01-31 16:25:22 -0800160 public int numShownHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700161
162 /**
163 * Number of icons inside the hotseat area that is stored in the database. This is greater than
164 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
165 * sizes that share the same DB.
166 */
167 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700168
Thales Limab8c05952022-05-23 16:58:38 +0100169 public float[] hotseatBarBottomSpace;
170 public float[] hotseatQsbSpace;
Thales Lima425f6822022-05-10 13:44:58 -0300171
Jon Miranda6f7e9702019-09-16 14:44:14 -0700172 /**
173 * Number of columns in the all apps list.
174 */
175 public int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300176 public int numAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700177 public int numDatabaseAllAppsColumns;
Thales Limae9273ea2023-01-26 12:33:52 +0000178 public @StyleRes int allAppsStyle;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700179
Jon Mirandae126d722021-02-25 10:45:20 -0500180 /**
181 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
182 */
183 protected boolean isScalable;
Thales Limaae0d7ef2022-11-16 15:53:43 +0000184 @XmlRes
185 public int devicePaddingId = INVALID_RESOURCE_HANDLE;
Thales Limaec5abba2023-04-05 16:33:50 +0100186 @XmlRes
187 public int workspaceSpecsId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +0100188 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100189 public int workspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
190 @XmlRes
Thales Limaabfe3642023-05-24 18:08:53 +0100191 public int allAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100192 @XmlRes
Jordan Silva575c3bd2023-07-21 12:00:43 +0100193 public int allAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
194 @XmlRes
Jordan Silva637f4eb2023-06-13 11:21:53 +0100195 public int folderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100196 @XmlRes
197 public int folderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000198 @XmlRes
Thales Limaf8bfb032023-07-24 15:08:05 +0100199 public int hotseatSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000200 @XmlRes
Thales Limaf8bfb032023-07-24 15:08:05 +0100201 public int hotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000202 @XmlRes
203 public int workspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
204 @XmlRes
205 public int workspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
206 @XmlRes
207 public int allAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
208 @XmlRes
209 public int allAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jon Mirandae126d722021-02-25 10:45:20 -0500210
Tracy Zhou7df93d22020-01-27 13:44:06 -0800211 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800212 public int defaultLayoutId;
Sunny Goyal1ae46ca2023-04-10 15:28:59 -0700213 public int demoModeLayoutId;
Thales Lima9938c2f2022-07-25 14:38:16 +0100214 public boolean[] inlineQsb = new boolean[COUNT_SIZES];
Adam Cohen2e6da152015-05-06 11:42:25 -0700215
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000216 /**
217 * An immutable list of supported profiles.
218 */
219 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700220
Sunny Goyal6f866092016-03-17 17:04:15 -0700221 public Point defaultWallpaperSize;
222
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700223 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700224
Sunny Goyalf633ef52018-03-13 09:57:05 -0700225 @VisibleForTesting
Sunny Goyal187b16c2022-03-01 16:53:23 -0800226 public InvariantDeviceProfile() { }
Adam Cohen2e6da152015-05-06 11:42:25 -0700227
Sunny Goyalbbf01842015-10-08 07:41:15 -0700228 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700229 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700230 String gridName = getCurrentGridName(context);
231 String newGridName = initGrid(context, gridName);
232 if (!newGridName.equals(gridName)) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000233 LauncherPrefs.get(context).put(GRID_NAME, newGridName);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700234 }
Sunny Goyal10fa0162024-04-21 00:13:35 -0700235 LockedUserState.get(context).runOnUserUnlocked(() ->
236 new DeviceGridState(this).writeToPrefs(context));
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700237
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700238 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100239 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000240 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
Jagrut Desai2e8ca872024-04-17 15:27:30 -0700241 | CHANGE_NAVIGATION_MODE | CHANGE_TASKBAR_PINNING
242 | CHANGE_DESKTOP_MODE)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100243 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700244 }
245 });
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700246 }
247
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700248 /**
249 * This constructor should NOT have any monitors by design.
250 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800251 public InvariantDeviceProfile(Context context, String gridName) {
252 String newName = initGrid(context, gridName);
253 if (newName == null || !newName.equals(gridName)) {
Andy Wickham99d7d4f2023-11-15 08:09:09 +0000254 throw new IllegalArgumentException("Unknown grid name: " + gridName);
Sunny Goyaleff44f32019-01-09 17:29:49 -0800255 }
256 }
257
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700258 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800259 * This constructor should NOT have any monitors by design.
260 */
261 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700262 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100263 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700264 String gridName = getCurrentGridName(context);
265
266 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000267 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
Sunny Goyal25c42762024-04-16 19:31:31 -0700268 @DeviceType int defaultDeviceType = defaultInfo.getDeviceType();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700269 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000270 defaultInfo,
271 getPredefinedDeviceProfiles(context, gridName, defaultDeviceType,
272 /*allowDisabledGrid=*/false),
273 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700274
Alex Chau661f02d2022-06-07 14:03:43 +0100275 Context displayContext = context.createDisplayContext(display);
276 Info myInfo = new Info(displayContext);
Sunny Goyal25c42762024-04-16 19:31:31 -0700277 @DeviceType int deviceType = myInfo.getDeviceType();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700278 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000279 myInfo,
280 getPredefinedDeviceProfiles(context, gridName, deviceType,
281 /*allowDisabledGrid=*/false),
282 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700283
284 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
285 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100286 result.iconSizes[INDEX_DEFAULT] =
287 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
288 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700289 result.iconSizes[i] = Math.min(
290 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000291 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700292
Thales Lima83bedbf2021-10-05 17:47:39 +0100293 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
294 COUNT_SIZES);
295 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
296 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500297
Alex Chau1c883d82021-12-01 18:43:10 +0000298 initGrid(context, myInfo, result, deviceType);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800299 }
300
Sunny Goyal10fa0162024-04-21 00:13:35 -0700301 @Override
302 public void close() {
303 DisplayController.INSTANCE.executeIfCreated(dc -> dc.setPriorityListener(null));
304 }
305
Alex Chau238aaee2021-10-06 16:15:24 +0100306 /**
307 * Reinitialize the current grid after a restore, where some grids might now be disabled.
308 */
309 public void reinitializeAfterRestore(Context context) {
Alex Chau29a96ad2022-02-10 13:12:20 +0000310 String currentGridName = getCurrentGridName(context);
Alex Chau238aaee2021-10-06 16:15:24 +0100311 String currentDbFile = dbFile;
Alex Chau29a96ad2022-02-10 13:12:20 +0000312 String newGridName = initGrid(context, currentGridName);
313 String newDbFile = dbFile;
Charlie Andersonc61288e2023-09-21 11:53:50 -0400314 FileLog.d(TAG, "Reinitializing grid after restore."
315 + " currentGridName=" + currentGridName
316 + ", currentDbFile=" + currentDbFile
317 + ", newGridName=" + newGridName
318 + ", newDbFile=" + newDbFile);
Alex Chau29a96ad2022-02-10 13:12:20 +0000319 if (!newDbFile.equals(currentDbFile)) {
Charlie Andersonc9d11e82023-08-02 11:41:55 -0400320 FileLog.d(TAG, "Restored grid is disabled : " + currentGridName
Alex Chau238aaee2021-10-06 16:15:24 +0100321 + ", migrating to: " + newGridName
322 + ", removing all other grid db files");
323 for (String gridDbFile : LauncherFiles.GRID_DB_FILES) {
324 if (gridDbFile.equals(currentDbFile)) {
325 continue;
326 }
327 if (context.getDatabasePath(gridDbFile).delete()) {
Charlie Andersonc9d11e82023-08-02 11:41:55 -0400328 FileLog.d(TAG, "Removed old grid db file: " + gridDbFile);
Alex Chau238aaee2021-10-06 16:15:24 +0100329 }
330 }
Alex Chau29a96ad2022-02-10 13:12:20 +0000331 setCurrentGrid(context, newGridName);
Alex Chau238aaee2021-10-06 16:15:24 +0100332 }
333 }
334
Tracy Zhou42255d22020-03-13 00:38:11 -0700335 public static String getCurrentGridName(Context context) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000336 return LauncherPrefs.get(context).get(GRID_NAME);
Tracy Zhou42255d22020-03-13 00:38:11 -0700337 }
338
Sunny Goyaleff44f32019-01-09 17:29:49 -0800339 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700340 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Sunny Goyal25c42762024-04-16 19:31:31 -0700341 @DeviceType int deviceType = displayInfo.getDeviceType();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700342
343 ArrayList<DisplayOption> allOptions =
Alex Chau1c883d82021-12-01 18:43:10 +0000344 getPredefinedDeviceProfiles(context, gridName, deviceType,
Alex Chau238aaee2021-10-06 16:15:24 +0100345 RestoreDbTask.isPending(context));
Sunny Goyal19ff7282021-04-22 10:12:54 -0700346 DisplayOption displayOption =
Alex Chau1c883d82021-12-01 18:43:10 +0000347 invDistWeightedInterpolate(displayInfo, allOptions, deviceType);
348 initGrid(context, displayInfo, displayOption, deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700349 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800350 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700351
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700352 /**
353 * @deprecated This is a temporary solution because on the backup and restore case we modify the
354 * IDP, this resets it. b/332974074
355 */
356 @Deprecated
357 public void reset(Context context) {
fbaronb633b9a2024-09-23 18:35:29 -0700358 initGrid(context, getDefaultGridName(context));
Sebastian Francodf7d2b02024-04-04 15:12:18 -0700359 }
360
Thales Limab67bfa72022-11-02 15:30:11 +0000361 @VisibleForTesting
362 public static String getDefaultGridName(Context context) {
363 return new InvariantDeviceProfile().initGrid(context, null);
364 }
365
Alex Chau1c883d82021-12-01 18:43:10 +0000366 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption,
367 @DeviceType int deviceType) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700368 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700369 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000370 numRows = closestProfile.numRows;
371 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000372 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000373 dbFile = closestProfile.dbFile;
374 defaultLayoutId = closestProfile.defaultLayoutId;
375 demoModeLayoutId = closestProfile.demoModeLayoutId;
Thales Limab35faed2022-09-05 16:30:01 -0300376
Sunny Goyalae190ff2020-04-14 00:19:01 +0000377 numFolderRows = closestProfile.numFolderRows;
378 numFolderColumns = closestProfile.numFolderColumns;
Thales Limab35faed2022-09-05 16:30:01 -0300379 folderStyle = closestProfile.folderStyle;
380
Thales Limad852d652023-01-17 14:01:13 +0000381 cellStyle = closestProfile.cellStyle;
382
Jon Mirandae126d722021-02-25 10:45:20 -0500383 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400384 devicePaddingId = closestProfile.devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100385 workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100386 workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100387 allAppsSpecsId = closestProfile.mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100388 allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100389 folderSpecsId = closestProfile.mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100390 folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100391 hotseatSpecsId = closestProfile.mHotseatSpecsId;
392 hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000393 workspaceCellSpecsId = closestProfile.mWorkspaceCellSpecsId;
394 workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId;
395 allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId;
396 allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId;
Jordan Silva2de6a272024-01-04 14:44:20 -0300397 numAllAppsRowsForCellHeightCalculation =
398 closestProfile.mNumAllAppsRowsForCellHeightCalculation;
Alex Chau1c883d82021-12-01 18:43:10 +0000399 this.deviceType = deviceType;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000400
Vinit Nayakc7293172022-07-18 16:41:50 -0700401 inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
402
Thales Lima83bedbf2021-10-05 17:47:39 +0100403 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100404 float maxIconSize = iconSize[0];
405 for (int i = 1; i < iconSize.length; i++) {
406 maxIconSize = Math.max(maxIconSize, iconSize[i]);
407 }
408 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000409 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
410
Thales Lima83bedbf2021-10-05 17:47:39 +0100411 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700412
Thales Lima83bedbf2021-10-05 17:47:39 +0100413 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100414
Thales Lima83bedbf2021-10-05 17:47:39 +0100415 borderSpaces = displayOption.borderSpaces;
Thales Limaa08a4432022-08-09 09:55:17 +0100416
Thales Limad90faab2021-09-21 17:18:47 +0100417 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100418
Sunny Goyal19ff7282021-04-22 10:12:54 -0700419 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000420 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700421 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100422 hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace;
423 hotseatQsbSpace = displayOption.hotseatQsbSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700424
Thales Limae9273ea2023-01-26 12:33:52 +0000425 allAppsStyle = closestProfile.allAppsStyle;
426
Sunny Goyal19ff7282021-04-22 10:12:54 -0700427 numAllAppsColumns = closestProfile.numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300428
Alex Chau1c883d82021-12-01 18:43:10 +0000429 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700430 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500431
Thales Limab7ef5692022-03-10 10:32:36 +0000432 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000433 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
434 allAppsIconSize = displayOption.allAppsIconSizes;
435 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000436
Thales Lima11af7bc2022-08-12 15:24:54 +0100437 inlineQsb = closestProfile.inlineQsb;
Thales Lima12d0eff2022-03-25 17:06:11 +0000438
Jon Miranda9c478b62023-03-23 21:38:49 -0700439 transientTaskbarIconSize = displayOption.transientTaskbarIconSize;
440
Jon Miranda04f05102023-04-04 12:16:31 -0700441 startAlignTaskbar = displayOption.startAlignTaskbar;
442
Sunny Goyalae190ff2020-04-14 00:19:01 +0000443 // If the partner customization apk contains any grid overrides, apply them
444 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700445 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700446
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000447 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700448 defaultWallpaperSize = new Point(displayInfo.currentSize);
Sunny Goyal65190ae2022-08-02 14:16:26 -0700449 SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700450 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000451 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chauab800f72022-12-13 17:46:06 +0000452 .setIsMultiDisplay(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000453 .setWindowBounds(bounds)
Sunny Goyal65190ae2022-08-02 14:16:26 -0700454 .setDotRendererCache(dotRendererCache)
Alex Chau6ed408f2022-03-04 12:58:05 +0000455 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700456
Sunny Goyal19ff7282021-04-22 10:12:54 -0700457 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
458 int displayWidth = bounds.bounds.width();
459 int displayHeight = bounds.bounds.height();
460 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700461
Sunny Goyal19ff7282021-04-22 10:12:54 -0700462 // We need to ensure that there is enough extra space in the wallpaper
463 // for the intended parallax effects
464 float parallaxFactor =
Thales Lima425f6822022-05-10 13:44:58 -0300465 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
466 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700467 ? 2
468 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
469 defaultWallpaperSize.x =
470 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700471 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000472 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700473
Thales Lima6a590062022-11-22 15:52:49 +0000474 int numMinShownHotseatIconsForTablet = supportedProfiles
475 .stream()
476 .filter(deviceProfile -> deviceProfile.isTablet)
477 .mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
478 .min()
479 .orElse(0);
480
481 supportedProfiles
482 .stream()
483 .filter(deviceProfile -> deviceProfile.isTablet)
484 .forEach(deviceProfile -> {
485 deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
486 deviceProfile.recalculateHotseatWidthAndBorderSpace();
487 });
Adam Cohen2e6da152015-05-06 11:42:25 -0700488 }
489
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700490 public void addOnChangeListener(OnIDPChangeListener listener) {
491 mChangeListeners.add(listener);
492 }
493
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800494 public void removeOnChangeListener(OnIDPChangeListener listener) {
495 mChangeListeners.remove(listener);
496 }
497
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800498
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800499 public void setCurrentGrid(Context context, String gridName) {
Stefan Andonian4c9612b2023-02-22 00:00:03 +0000500 LauncherPrefs.get(context).put(GRID_NAME, gridName);
Brandon Dayauon51db65e2024-10-23 15:07:37 -0700501 MAIN_EXECUTOR.execute(() -> {
502 Trace.beginSection("InvariantDeviceProfile#setCurrentGrid");
503 onConfigChanged(context.getApplicationContext());
504 Trace.endSection();
505 });
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800506 }
507
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700508 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700509 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000510 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
511 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700512 }
513
Pat Manning24cec692023-10-13 10:36:57 +0000514 /** Updates IDP using the provided context. Notifies listeners of change. */
515 @VisibleForTesting
516 public void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700517 Object[] oldState = toModelState();
518
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700519 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700520 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700521 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700522
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700523 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700524 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700525 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700526 }
527 }
528
Alex Chau1c883d82021-12-01 18:43:10 +0000529 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context,
530 String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800531 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100532
Alex Chau1c883d82021-12-01 18:43:10 +0000533 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700534 final int depth = parser.getDepth();
535 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700536 while (((type = parser.next()) != XmlPullParser.END_TAG ||
537 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800538 if ((type == XmlPullParser.START_TAG)
539 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800540
Sunny Goyal076e04b2023-04-03 12:38:30 -0700541 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
542 if (gridOption.isEnabled(deviceType) || allowDisabledGrid) {
Thales Lima7ec83822021-08-05 13:32:10 +0100543 final int displayDepth = parser.getDepth();
544 while (((type = parser.next()) != XmlPullParser.END_TAG
545 || parser.getDepth() > displayDepth)
546 && type != XmlPullParser.END_DOCUMENT) {
547 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
548 parser.getName())) {
549 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100550 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100551 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800552 }
553 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700554 }
555 }
sfufa@google.comde013292021-09-21 18:22:44 -0700556 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700557 throw new RuntimeException(e);
558 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800559
Sunny Goyalae190ff2020-04-14 00:19:01 +0000560 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800561 if (!TextUtils.isEmpty(gridName)) {
562 for (DisplayOption option : profiles) {
Alex Chau238aaee2021-10-06 16:15:24 +0100563 if (gridName.equals(option.grid.name)
Sunny Goyal076e04b2023-04-03 12:38:30 -0700564 && (option.grid.isEnabled(deviceType) || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000565 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800566 }
567 }
568 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000569 if (filteredProfiles.isEmpty()) {
570 // No grid found, use the default options
571 for (DisplayOption option : profiles) {
572 if (option.canBeDefault) {
573 filteredProfiles.add(option);
574 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800575 }
576 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000577 if (filteredProfiles.isEmpty()) {
578 throw new RuntimeException("No display option with canBeDefault=true");
579 }
580 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700581 }
582
Thales Lima7ec83822021-08-05 13:32:10 +0100583 /**
Sebastián Francoad46eb72024-03-11 20:56:57 +0000584 * Returns the GridOption associated to the given file name or null if the fileName is not
585 * supported.
586 * Ej, launcher.db -> "normal grid", launcher_4_by_4.db -> "practical grid"
587 */
588 public GridOption getGridOptionFromFileName(Context context, String fileName) {
589 return parseAllGridOptions(context).stream()
590 .filter(gridOption -> Objects.equals(gridOption.dbFile, fileName))
591 .findFirst()
592 .orElse(null);
593 }
594
595 /**
596 * Returns the name of the given size on the current device or empty string if the size is not
597 * supported. Ej. 4x4 -> normal, 5x4 -> practical, etc.
598 * (Note: the name of the grid can be different for the same grid size depending of
599 * the values of the InvariantDeviceProfile)
600 *
601 */
602 public String getGridNameFromSize(Context context, Point size) {
603 return parseAllGridOptions(context).stream()
604 .filter(gridOption -> gridOption.numColumns == size.x
605 && gridOption.numRows == size.y)
606 .map(gridOption -> gridOption.name)
607 .findFirst()
608 .orElse("");
609 }
610
611 /**
612 * Returns the grid option for the given gridName on the current device (Note: the gridOption
613 * be different for the same gridName depending on the values of the InvariantDeviceProfile).
614 */
615 public GridOption getGridOptionFromName(Context context, String gridName) {
616 return parseAllGridOptions(context).stream()
617 .filter(gridOption -> Objects.equals(gridOption.name, gridName))
618 .findFirst()
619 .orElse(null);
620 }
621
622 /**
Thales Lima7ec83822021-08-05 13:32:10 +0100623 * @return all the grid options that can be shown on the device
624 */
625 public List<GridOption> parseAllGridOptions(Context context) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700626 return parseAllDefinedGridOptions(context)
627 .stream()
628 .filter(go -> go.isEnabled(deviceType))
629 .collect(Collectors.toList());
630 }
631
632 /**
633 * @return all the grid options that can be shown on the device
634 */
635 public static List<GridOption> parseAllDefinedGridOptions(Context context) {
Thales Lima7ec83822021-08-05 13:32:10 +0100636 List<GridOption> result = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100637
Alex Chau1c883d82021-12-01 18:43:10 +0000638 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100639 final int depth = parser.getDepth();
640 int type;
641 while (((type = parser.next()) != XmlPullParser.END_TAG
642 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
643 if ((type == XmlPullParser.START_TAG)
644 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal076e04b2023-04-03 12:38:30 -0700645 result.add(new GridOption(context, Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100646 }
647 }
648 } catch (IOException | XmlPullParserException e) {
649 Log.e(TAG, "Error parsing device profile", e);
650 return Collections.emptyList();
651 }
652 return result;
653 }
654
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700655 private int getLauncherIconDensity(int requiredSize) {
656 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700657 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700658 DisplayMetrics.DENSITY_LOW,
659 DisplayMetrics.DENSITY_MEDIUM,
660 DisplayMetrics.DENSITY_TV,
661 DisplayMetrics.DENSITY_HIGH,
662 DisplayMetrics.DENSITY_XHIGH,
663 DisplayMetrics.DENSITY_XXHIGH,
664 DisplayMetrics.DENSITY_XXXHIGH
665 };
666
667 int density = DisplayMetrics.DENSITY_XXXHIGH;
668 for (int i = densityBuckets.length - 1; i >= 0; i--) {
669 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
670 / DisplayMetrics.DENSITY_DEFAULT;
671 if (expectedSize >= requiredSize) {
672 density = densityBuckets[i];
673 }
674 }
675
676 return density;
677 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700678
Adam Cohen2e6da152015-05-06 11:42:25 -0700679 /**
680 * Apply any Partner customization grid overrides.
681 *
682 * Currently we support: all apps row / column count.
683 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700684 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
685 Partner p = Partner.get(context.getPackageManager());
Sunny Goyal3e58eea2022-11-14 14:30:07 -0800686 if (p == null) {
687 return;
688 }
689 try {
690 int numRows = p.getIntValue(RES_GRID_NUM_ROWS, -1);
691 int numColumns = p.getIntValue(RES_GRID_NUM_COLUMNS, -1);
692 float iconSizePx = p.getDimenValue(RES_GRID_ICON_SIZE_DP, -1);
693
694 if (numRows > 0 && numColumns > 0) {
695 this.numRows = numRows;
696 this.numColumns = numColumns;
697 }
698 if (iconSizePx > 0) {
699 this.iconSize[InvariantDeviceProfile.INDEX_DEFAULT] =
700 Utilities.dpiFromPx(iconSizePx, dm.densityDpi);
701 }
702 } catch (Resources.NotFoundException ex) {
703 Log.e(TAG, "Invalid Partner grid resource!", ex);
Adam Cohen2e6da152015-05-06 11:42:25 -0700704 }
705 }
706
Sunny Goyal415f1732018-11-29 10:33:47 -0800707 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700708 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700709 }
710
Sunny Goyal19ff7282021-04-22 10:12:54 -0700711 private static DisplayOption invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000712 Info displayInfo, ArrayList<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700713 int minWidthPx = Integer.MAX_VALUE;
714 int minHeightPx = Integer.MAX_VALUE;
715 for (WindowBounds bounds : displayInfo.supportedBounds) {
716 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000717 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700718 // For split displays, take half width per page
719 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
720 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700721
Sunny Goyal19ff7282021-04-22 10:12:54 -0700722 } else if (!isTablet && bounds.isLandscape()) {
723 // We will use transposed layout in this case
724 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
725 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
726 } else {
727 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
728 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
729 }
730 }
731
Thales Lima425f6822022-05-10 13:44:58 -0300732 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
733 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700734
735 // Sort the profiles based on the closeness to the device size
736 Collections.sort(points, (a, b) ->
737 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
738 dist(width, height, b.minWidthDps, b.minHeightDps)));
739
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700740 DisplayOption closestPoint = points.get(0);
741 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700742 float weights = 0;
743
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700744 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
745 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700746 }
747
748 DisplayOption out = new DisplayOption(closestOption);
749 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700750 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700751 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
752 weights += w;
753 out.add(new DisplayOption().add(p).multiply(w));
754 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700755 out.multiply(1.0f / weights);
756
Thales Lima6e0005a2021-10-27 15:53:41 +0100757 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700758 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100759 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
760 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700761 }
762
763 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700764 }
765
Sunny Goyal27835952017-01-13 12:15:53 -0800766 public DeviceProfile getDeviceProfile(Context context) {
Alex Chauc09a98a2023-11-14 12:51:42 +0000767 WindowManagerProxy windowManagerProxy = WindowManagerProxy.INSTANCE.get(context);
768 Rect bounds = windowManagerProxy.getCurrentBounds(context);
769 int rotation = windowManagerProxy.getRotation(context);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700770
Alex Chauc09a98a2023-11-14 12:51:42 +0000771 return getBestMatch(bounds.width(), bounds.height(), rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400772 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700773
Sunny Goyal187b16c2022-03-01 16:53:23 -0800774 /**
775 * Returns the device profile matching the provided screen configuration
776 */
777 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700778 DeviceProfile bestMatch = supportedProfiles.get(0);
779 float minDiff = Float.MAX_VALUE;
780
781 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400782 float diff = Math.abs(profile.widthPx - screenWidth)
783 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700784 if (diff < minDiff) {
785 minDiff = diff;
786 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800787 } else if (diff == minDiff && profile.rotationHint == rotation) {
788 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700789 }
790 }
791 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800792 }
793
Sunny Goyal415f1732018-11-29 10:33:47 -0800794 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700795 float d = dist(x0, y0, x1, y1);
796 if (Float.compare(d, 0f) == 0) {
797 return Float.POSITIVE_INFINITY;
798 }
799 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
800 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700801
802 /**
803 * As a ratio of screen height, the total distance we want the parallax effect to span
804 * horizontally
805 */
806 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
807 float aspectRatio = width / (float) height;
808
809 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
810 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
811 // We will use these two data points to extrapolate how much the wallpaper parallax effect
812 // to span (ie travel) at any aspect ratio:
813
sfufa@google.comde013292021-09-21 18:22:44 -0700814 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
815 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700816 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
817 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
818
819 // To find out the desired width at different aspect ratios, we use the following two
820 // formulas, where the coefficient on x is the aspect ratio (width/height):
821 // (16/10)x + y = 1.5
822 // (10/16)x + y = 1.2
823 // We solve for x and y and end up with a final formula:
824 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700825 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
826 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700827 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
828 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
829 return x * aspectRatio + y;
830 }
831
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700832 public interface OnIDPChangeListener {
833
Sunny Goyalb47172b2021-05-03 19:59:51 -0700834 /**
835 * Called when the device provide changes
836 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700837 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700838 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800839
840
Sunny Goyaleff44f32019-01-09 17:29:49 -0800841 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800842
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800843 public static final String TAG_NAME = "grid-option";
844
Alex Chau1c883d82021-12-01 18:43:10 +0000845 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
846 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
847 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
848 private static final int DEVICE_CATEGORY_ALL =
849 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
850
Thales Lima11af7bc2022-08-12 15:24:54 +0100851 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
852 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
853 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
854 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
855 private static final int DONT_INLINE_QSB = 0;
856
Sunny Goyaleff44f32019-01-09 17:29:49 -0800857 public final String name;
858 public final int numRows;
859 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000860 public final int numSearchContainerColumns;
Sunny Goyal076e04b2023-04-03 12:38:30 -0700861 public final int deviceCategory;
Sunny Goyal415f1732018-11-29 10:33:47 -0800862
Thales Lima1faa4ed2023-12-01 16:48:19 +0000863 private final int[] numFolderRows = new int[COUNT_SIZES];
864 private final int[] numFolderColumns = new int[COUNT_SIZES];
Thales Limab35faed2022-09-05 16:30:01 -0300865 private final @StyleRes int folderStyle;
Thales Limad852d652023-01-17 14:01:13 +0000866 private final @StyleRes int cellStyle;
Sunny Goyal415f1732018-11-29 10:33:47 -0800867
Thales Limae9273ea2023-01-26 12:33:52 +0000868 private final @StyleRes int allAppsStyle;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700869 private final int numAllAppsColumns;
Jordan Silva2de6a272024-01-04 14:44:20 -0300870 private final int mNumAllAppsRowsForCellHeightCalculation;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700871 private final int numDatabaseAllAppsColumns;
872 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700873 private final int numDatabaseHotseatIcons;
Thales Limab8c05952022-05-23 16:58:38 +0100874
Thales Lima11af7bc2022-08-12 15:24:54 +0100875 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
876
Thales Limab35faed2022-09-05 16:30:01 -0300877 private @DimenRes int inlineNavButtonsEndSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800878 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000879
Sunny Goyal415f1732018-11-29 10:33:47 -0800880 private final int defaultLayoutId;
881 private final int demoModeLayoutId;
882
Jon Mirandae126d722021-02-25 10:45:20 -0500883 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400884 private final int devicePaddingId;
Thales Limaec5abba2023-04-05 16:33:50 +0100885 private final int mWorkspaceSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100886 private final int mWorkspaceSpecsTwoPanelId;
Thales Limaabfe3642023-05-24 18:08:53 +0100887 private final int mAllAppsSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100888 private final int mAllAppsSpecsTwoPanelId;
Jordan Silva637f4eb2023-06-13 11:21:53 +0100889 private final int mFolderSpecsId;
Jordan Silva575c3bd2023-07-21 12:00:43 +0100890 private final int mFolderSpecsTwoPanelId;
Thales Limaf8bfb032023-07-24 15:08:05 +0100891 private final int mHotseatSpecsId;
892 private final int mHotseatSpecsTwoPanelId;
Jordan Silva999dd2a2023-11-17 19:31:43 +0000893 private final int mWorkspaceCellSpecsId;
894 private final int mWorkspaceCellSpecsTwoPanelId;
895 private final int mAllAppsCellSpecsId;
896 private final int mAllAppsCellSpecsTwoPanelId;
Jon Mirandae126d722021-02-25 10:45:20 -0500897
Sunny Goyal076e04b2023-04-03 12:38:30 -0700898 public GridOption(Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800899 TypedArray a = context.obtainStyledAttributes(
900 attrs, R.styleable.GridDisplayOption);
901 name = a.getString(R.styleable.GridDisplayOption_name);
902 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
903 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000904 numSearchContainerColumns = a.getInt(
905 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal415f1732018-11-29 10:33:47 -0800906
Tracy Zhou7df93d22020-01-27 13:44:06 -0800907 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Alex Chau766cd2b2022-07-06 17:15:21 +0100908 defaultLayoutId = a.getResourceId(
909 R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800910 demoModeLayoutId = a.getResourceId(
911 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700912
Thales Limae9273ea2023-01-26 12:33:52 +0000913 allAppsStyle = a.getResourceId(R.styleable.GridDisplayOption_allAppsStyle,
914 R.style.AllAppsStyleDefault);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700915 numAllAppsColumns = a.getInt(
916 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
917 numDatabaseAllAppsColumns = a.getInt(
918 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
919
920 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800921 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700922 numDatabaseHotseatIcons = a.getInt(
923 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Limab8c05952022-05-23 16:58:38 +0100924
Vinit Nayakc7293172022-07-18 16:41:50 -0700925 inlineNavButtonsEndSpacing =
926 a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
Thales Limaec5abba2023-04-05 16:33:50 +0100927 R.dimen.taskbar_button_margin_default);
Thales Limab35faed2022-09-05 16:30:01 -0300928
Thales Lima1faa4ed2023-12-01 16:48:19 +0000929 numFolderRows[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800930 R.styleable.GridDisplayOption_numFolderRows, numRows);
Thales Lima1faa4ed2023-12-01 16:48:19 +0000931 numFolderColumns[INDEX_DEFAULT] = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800932 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700933
Thales Lima1faa4ed2023-12-01 16:48:19 +0000934 if (FeatureFlags.enableResponsiveWorkspace()) {
935 numFolderRows[INDEX_LANDSCAPE] = a.getInt(
936 R.styleable.GridDisplayOption_numFolderRowsLandscape,
937 numFolderRows[INDEX_DEFAULT]);
938 numFolderColumns[INDEX_LANDSCAPE] = a.getInt(
939 R.styleable.GridDisplayOption_numFolderColumnsLandscape,
940 numFolderColumns[INDEX_DEFAULT]);
941 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
942 R.styleable.GridDisplayOption_numFolderRowsTwoPanelPortrait,
943 numFolderRows[INDEX_DEFAULT]);
944 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
945 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelPortrait,
946 numFolderColumns[INDEX_DEFAULT]);
947 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
948 R.styleable.GridDisplayOption_numFolderRowsTwoPanelLandscape,
949 numFolderRows[INDEX_DEFAULT]);
950 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
951 R.styleable.GridDisplayOption_numFolderColumnsTwoPanelLandscape,
952 numFolderColumns[INDEX_DEFAULT]);
953 } else {
954 numFolderRows[INDEX_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
955 numFolderColumns[INDEX_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
956 numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = numFolderRows[INDEX_DEFAULT];
957 numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = numFolderColumns[INDEX_DEFAULT];
958 numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = numFolderRows[INDEX_DEFAULT];
959 numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT];
960 }
961
Thales Limab35faed2022-09-05 16:30:01 -0300962 folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle,
963 INVALID_RESOURCE_HANDLE);
964
Thales Limad852d652023-01-17 14:01:13 +0000965 cellStyle = a.getResourceId(R.styleable.GridDisplayOption_cellStyle,
966 R.style.CellStyleDefault);
967
Jon Mirandae126d722021-02-25 10:45:20 -0500968 isScalable = a.getBoolean(
969 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400970 devicePaddingId = a.getResourceId(
Thales Limaae0d7ef2022-11-16 15:53:43 +0000971 R.styleable.GridDisplayOption_devicePaddingId, INVALID_RESOURCE_HANDLE);
Sunny Goyal076e04b2023-04-03 12:38:30 -0700972 deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
Alex Chau1c883d82021-12-01 18:43:10 +0000973 DEVICE_CATEGORY_ALL);
Thales Lima7ec83822021-08-05 13:32:10 +0100974
Thales Limaca31b612023-09-14 14:25:26 +0100975 if (FeatureFlags.enableResponsiveWorkspace()) {
Thales Limaec5abba2023-04-05 16:33:50 +0100976 mWorkspaceSpecsId = a.getResourceId(
977 R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100978 mWorkspaceSpecsTwoPanelId = a.getResourceId(
979 R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300980 mWorkspaceSpecsId);
Thales Limaabfe3642023-05-24 18:08:53 +0100981 mAllAppsSpecsId = a.getResourceId(
982 R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100983 mAllAppsSpecsTwoPanelId = a.getResourceId(
984 R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300985 mAllAppsSpecsId);
Jordan Silva637f4eb2023-06-13 11:21:53 +0100986 mFolderSpecsId = a.getResourceId(
987 R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE);
Jordan Silva575c3bd2023-07-21 12:00:43 +0100988 mFolderSpecsTwoPanelId = a.getResourceId(
989 R.styleable.GridDisplayOption_folderSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300990 mFolderSpecsId);
Thales Limaf8bfb032023-07-24 15:08:05 +0100991 mHotseatSpecsId = a.getResourceId(
992 R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE);
993 mHotseatSpecsTwoPanelId = a.getResourceId(
994 R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -0300995 mHotseatSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +0000996 mWorkspaceCellSpecsId = a.getResourceId(
997 R.styleable.GridDisplayOption_workspaceCellSpecsId,
998 INVALID_RESOURCE_HANDLE);
999 mWorkspaceCellSpecsTwoPanelId = a.getResourceId(
1000 R.styleable.GridDisplayOption_workspaceCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001001 mWorkspaceCellSpecsId);
Jordan Silva999dd2a2023-11-17 19:31:43 +00001002 mAllAppsCellSpecsId = a.getResourceId(
1003 R.styleable.GridDisplayOption_allAppsCellSpecsId,
1004 INVALID_RESOURCE_HANDLE);
1005 mAllAppsCellSpecsTwoPanelId = a.getResourceId(
1006 R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId,
Jordan Silvad29f0642024-01-10 15:11:26 -03001007 mAllAppsCellSpecsId);
Jordan Silva2de6a272024-01-04 14:44:20 -03001008 mNumAllAppsRowsForCellHeightCalculation = a.getInt(
1009 R.styleable.GridDisplayOption_numAllAppsRowsForCellHeightCalculation,
1010 numRows);
Thales Limaec5abba2023-04-05 16:33:50 +01001011 } else {
1012 mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001013 mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaabfe3642023-05-24 18:08:53 +01001014 mAllAppsSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001015 mAllAppsSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva637f4eb2023-06-13 11:21:53 +01001016 mFolderSpecsId = INVALID_RESOURCE_HANDLE;
Jordan Silva575c3bd2023-07-21 12:00:43 +01001017 mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Thales Limaf8bfb032023-07-24 15:08:05 +01001018 mHotseatSpecsId = INVALID_RESOURCE_HANDLE;
1019 mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva999dd2a2023-11-17 19:31:43 +00001020 mWorkspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
1021 mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
1022 mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
1023 mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
Jordan Silva2de6a272024-01-04 14:44:20 -03001024 mNumAllAppsRowsForCellHeightCalculation = numRows;
Thales Limaec5abba2023-04-05 16:33:50 +01001025 }
1026
Thales Lima11af7bc2022-08-12 15:24:54 +01001027 int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
1028 DONT_INLINE_QSB);
1029 inlineQsb[INDEX_DEFAULT] =
1030 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
1031 inlineQsb[INDEX_LANDSCAPE] =
1032 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
1033 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
1034 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
1035 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
1036 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
1037 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
1038 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
1039
Sunny Goyal415f1732018-11-29 10:33:47 -08001040 a.recycle();
Sunny Goyal076e04b2023-04-03 12:38:30 -07001041 }
1042
1043 public boolean isEnabled(@DeviceType int deviceType) {
1044 switch (deviceType) {
1045 case TYPE_PHONE:
1046 return (deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE;
1047 case TYPE_TABLET:
1048 return (deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET;
1049 case TYPE_MULTI_DISPLAY:
1050 return (deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
1051 == DEVICE_CATEGORY_MULTI_DISPLAY;
1052 default:
1053 return false;
1054 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001055 }
1056 }
1057
Sunny Goyal19ff7282021-04-22 10:12:54 -07001058 @VisibleForTesting
1059 static final class DisplayOption {
Sunny Goyal19ff7282021-04-22 10:12:54 -07001060 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001061
Sunny Goyal415f1732018-11-29 10:33:47 -08001062 private final float minWidthDps;
1063 private final float minHeightDps;
1064 private final boolean canBeDefault;
1065
Thales Lima83bedbf2021-10-05 17:47:39 +01001066 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +01001067
Thales Lima78d00ad2021-09-30 11:29:06 +01001068 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +01001069 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Limab8c05952022-05-23 16:58:38 +01001070 private final float[] hotseatBarBottomSpace = new float[COUNT_SIZES];
1071 private final float[] hotseatQsbSpace = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +01001072
Thales Lima78d00ad2021-09-30 11:29:06 +01001073 private final float[] iconSizes = new float[COUNT_SIZES];
1074 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -08001075
Thales Limab7ef5692022-03-10 10:32:36 +00001076 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +00001077 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
1078 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
1079 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
1080
Jon Miranda9c478b62023-03-23 21:38:49 -07001081 private final float[] transientTaskbarIconSize = new float[COUNT_SIZES];
1082
Jon Miranda04f05102023-04-04 12:16:31 -07001083 private final boolean[] startAlignTaskbar = new boolean[COUNT_SIZES];
1084
Thales Lima1de4d552021-10-13 16:13:25 +01001085 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -08001086 this.grid = grid;
1087
Jon Miranda9c478b62023-03-23 21:38:49 -07001088 Resources res = context.getResources();
1089
Thales Lima1de4d552021-10-13 16:13:25 +01001090 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -08001091
Sunny Goyal415f1732018-11-29 10:33:47 -08001092 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
1093 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -07001094
Thales Lima1de4d552021-10-13 16:13:25 +01001095 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -08001096
Thales Lima83bedbf2021-10-05 17:47:39 +01001097 float x;
1098 float y;
1099
Thales Lima85c942f2021-12-31 13:04:20 +00001100 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
1101 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +01001102 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +00001103
1104 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
1105 minCellSize[INDEX_DEFAULT].x);
1106 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
1107 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001108 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +01001109
Thales Lima85c942f2021-12-31 13:04:20 +00001110 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001111 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001112 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001113 minCellSize[INDEX_DEFAULT].y);
1114 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1115
Thales Lima85c942f2021-12-31 13:04:20 +00001116 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001117 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +00001118 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001119 minCellSize[INDEX_DEFAULT].y);
1120 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +01001121
Thales Lima85c942f2021-12-31 13:04:20 +00001122 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +00001123 float borderSpaceLandscape = a.getFloat(
1124 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +00001125 float borderSpaceTwoPanelPortrait = a.getFloat(
1126 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
1127 float borderSpaceTwoPanelLandscape = a.getFloat(
1128 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001129
Thales Lima85c942f2021-12-31 13:04:20 +00001130 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
1131 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +01001132 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +00001133
1134 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
1135 borderSpaceLandscape);
1136 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
1137 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001138 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1139
1140 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001141 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
1142 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001143 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001144 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
1145 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +01001146 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1147
1148 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001149 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
1150 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001151 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001152 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
1153 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +01001154 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1155
Thales Limab7ef5692022-03-10 10:32:36 +00001156 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
1157 minCellSize[INDEX_DEFAULT].x);
1158 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
1159 minCellSize[INDEX_DEFAULT].y);
1160 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
1161
1162 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
1163 allAppsCellSize[INDEX_DEFAULT].x);
1164 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
1165 allAppsCellSize[INDEX_DEFAULT].y);
1166 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
1167
1168 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
1169 allAppsCellSize[INDEX_DEFAULT].x);
1170 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
1171 allAppsCellSize[INDEX_DEFAULT].y);
1172 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1173
1174 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
1175 allAppsCellSize[INDEX_DEFAULT].x);
1176 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
1177 allAppsCellSize[INDEX_DEFAULT].y);
1178 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
1179
Thales Lima080d8902022-03-28 15:30:29 +01001180 float allAppsBorderSpace = a.getFloat(
1181 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
1182 float allAppsBorderSpaceLandscape = a.getFloat(
1183 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
1184 allAppsBorderSpace);
1185 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001186 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +01001187 allAppsBorderSpace);
1188 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +00001189 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +01001190 allAppsBorderSpace);
1191
1192 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
1193 allAppsBorderSpace);
1194 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
1195 allAppsBorderSpace);
1196 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
1197
1198 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
1199 allAppsBorderSpaceLandscape);
1200 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
1201 allAppsBorderSpaceLandscape);
1202 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
1203
1204 x = a.getFloat(
1205 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
1206 allAppsBorderSpaceTwoPanelPortrait);
1207 y = a.getFloat(
1208 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
1209 allAppsBorderSpaceTwoPanelPortrait);
1210 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
1211
1212 x = a.getFloat(
1213 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
1214 allAppsBorderSpaceTwoPanelLandscape);
1215 y = a.getFloat(
1216 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
1217 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +00001218 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -05001219
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001220 iconSizes[INDEX_DEFAULT] =
1221 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
1222 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001223 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001224 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001225 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001226 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001227 iconSizes[INDEX_DEFAULT]);
1228 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001229 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001230 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -07001231
Thales Limabb7d3882021-12-22 12:56:29 +00001232 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1233 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
Thales Lima1fb075d2022-08-10 10:47:50 +01001234 allAppsIconSizes[INDEX_LANDSCAPE] = a.getFloat(
1235 R.styleable.ProfileDisplayOption_allAppsIconSizeLandscape,
Thales Limaed8c69b2022-08-17 12:21:21 -04001236 allAppsIconSizes[INDEX_DEFAULT]);
Thales Limabb7d3882021-12-22 12:56:29 +00001237 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1238 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1239 allAppsIconSizes[INDEX_DEFAULT]);
1240 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1241 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1242 allAppsIconSizes[INDEX_DEFAULT]);
1243
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001244 textSizes[INDEX_DEFAULT] =
1245 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1246 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001247 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001248 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001249 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001250 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001251 textSizes[INDEX_DEFAULT]);
1252 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001253 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001254 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001255
Thales Limabb7d3882021-12-22 12:56:29 +00001256 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1257 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1258 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1259 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1260 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1261 allAppsIconTextSizes[INDEX_DEFAULT]);
1262 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1263 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1264 allAppsIconTextSizes[INDEX_DEFAULT]);
1265
Thales Lima83bedbf2021-10-05 17:47:39 +01001266 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1267 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001268 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1269 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1270 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001271 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001272 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001273 horizontalMargin[INDEX_DEFAULT]);
1274 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001275 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001276 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001277
Thales Limab8c05952022-05-23 16:58:38 +01001278 hotseatBarBottomSpace[INDEX_DEFAULT] = a.getFloat(
1279 R.styleable.ProfileDisplayOption_hotseatBarBottomSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001280 ResourcesCompat.getFloat(res, R.dimen.hotseat_bar_bottom_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001281 hotseatBarBottomSpace[INDEX_LANDSCAPE] = a.getFloat(
1282 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceLandscape,
1283 hotseatBarBottomSpace[INDEX_DEFAULT]);
1284 hotseatBarBottomSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1285 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelLandscape,
1286 hotseatBarBottomSpace[INDEX_DEFAULT]);
1287 hotseatBarBottomSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1288 R.styleable.ProfileDisplayOption_hotseatBarBottomSpaceTwoPanelPortrait,
1289 hotseatBarBottomSpace[INDEX_DEFAULT]);
1290
1291 hotseatQsbSpace[INDEX_DEFAULT] = a.getFloat(
1292 R.styleable.ProfileDisplayOption_hotseatQsbSpace,
Jon Miranda9c478b62023-03-23 21:38:49 -07001293 ResourcesCompat.getFloat(res, R.dimen.hotseat_qsb_space_default));
Thales Limab8c05952022-05-23 16:58:38 +01001294 hotseatQsbSpace[INDEX_LANDSCAPE] = a.getFloat(
1295 R.styleable.ProfileDisplayOption_hotseatQsbSpaceLandscape,
1296 hotseatQsbSpace[INDEX_DEFAULT]);
1297 hotseatQsbSpace[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1298 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelLandscape,
1299 hotseatQsbSpace[INDEX_DEFAULT]);
1300 hotseatQsbSpace[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1301 R.styleable.ProfileDisplayOption_hotseatQsbSpaceTwoPanelPortrait,
1302 hotseatQsbSpace[INDEX_DEFAULT]);
1303
Jon Miranda9c478b62023-03-23 21:38:49 -07001304 transientTaskbarIconSize[INDEX_DEFAULT] = a.getFloat(
1305 R.styleable.ProfileDisplayOption_transientTaskbarIconSize,
1306 ResourcesCompat.getFloat(res, R.dimen.taskbar_icon_size));
1307 transientTaskbarIconSize[INDEX_LANDSCAPE] = a.getFloat(
1308 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeLandscape,
1309 transientTaskbarIconSize[INDEX_DEFAULT]);
1310 transientTaskbarIconSize[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1311 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelLandscape,
1312 transientTaskbarIconSize[INDEX_DEFAULT]);
1313 transientTaskbarIconSize[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1314 R.styleable.ProfileDisplayOption_transientTaskbarIconSizeTwoPanelPortrait,
Jon Miranda4d74ad32023-03-27 16:31:11 -07001315 transientTaskbarIconSize[INDEX_DEFAULT]);
Jon Miranda9c478b62023-03-23 21:38:49 -07001316
Jon Miranda04f05102023-04-04 12:16:31 -07001317 startAlignTaskbar[INDEX_DEFAULT] = a.getBoolean(
1318 R.styleable.ProfileDisplayOption_startAlignTaskbar, false);
1319 startAlignTaskbar[INDEX_LANDSCAPE] = a.getBoolean(
1320 R.styleable.ProfileDisplayOption_startAlignTaskbarLandscape,
1321 startAlignTaskbar[INDEX_DEFAULT]);
1322 startAlignTaskbar[INDEX_TWO_PANEL_LANDSCAPE] = a.getBoolean(
1323 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelLandscape,
1324 startAlignTaskbar[INDEX_LANDSCAPE]);
1325 startAlignTaskbar[INDEX_TWO_PANEL_PORTRAIT] = a.getBoolean(
1326 R.styleable.ProfileDisplayOption_startAlignTaskbarTwoPanelPortrait,
1327 startAlignTaskbar[INDEX_DEFAULT]);
1328
Sunny Goyal415f1732018-11-29 10:33:47 -08001329 a.recycle();
1330 }
1331
1332 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001333 this(null);
1334 }
1335
1336 DisplayOption(GridOption grid) {
1337 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001338 minWidthDps = 0;
1339 minHeightDps = 0;
1340 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001341 for (int i = 0; i < COUNT_SIZES; i++) {
1342 iconSizes[i] = 0;
1343 textSizes[i] = 0;
1344 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001345 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001346 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001347 allAppsIconSizes[i] = 0;
1348 allAppsIconTextSizes[i] = 0;
1349 allAppsBorderSpaces[i] = new PointF();
Jon Miranda9c478b62023-03-23 21:38:49 -07001350 transientTaskbarIconSize[i] = 0;
Jon Miranda04f05102023-04-04 12:16:31 -07001351 startAlignTaskbar[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001352 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001353 }
1354
1355 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001356 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001357 iconSizes[i] *= w;
1358 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001359 borderSpaces[i].x *= w;
1360 borderSpaces[i].y *= w;
1361 minCellSize[i].x *= w;
1362 minCellSize[i].y *= w;
1363 horizontalMargin[i] *= w;
Thales Limab8c05952022-05-23 16:58:38 +01001364 hotseatBarBottomSpace[i] *= w;
1365 hotseatQsbSpace[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001366 allAppsCellSize[i].x *= w;
1367 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001368 allAppsIconSizes[i] *= w;
1369 allAppsIconTextSizes[i] *= w;
1370 allAppsBorderSpaces[i].x *= w;
1371 allAppsBorderSpaces[i].y *= w;
Jon Miranda9c478b62023-03-23 21:38:49 -07001372 transientTaskbarIconSize[i] *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001373 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001374
Sunny Goyal415f1732018-11-29 10:33:47 -08001375 return this;
1376 }
1377
1378 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001379 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001380 iconSizes[i] += p.iconSizes[i];
1381 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001382 borderSpaces[i].x += p.borderSpaces[i].x;
1383 borderSpaces[i].y += p.borderSpaces[i].y;
1384 minCellSize[i].x += p.minCellSize[i].x;
1385 minCellSize[i].y += p.minCellSize[i].y;
1386 horizontalMargin[i] += p.horizontalMargin[i];
Thales Limab8c05952022-05-23 16:58:38 +01001387 hotseatBarBottomSpace[i] += p.hotseatBarBottomSpace[i];
1388 hotseatQsbSpace[i] += p.hotseatQsbSpace[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001389 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1390 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001391 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1392 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1393 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1394 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Jon Miranda9c478b62023-03-23 21:38:49 -07001395 transientTaskbarIconSize[i] += p.transientTaskbarIconSize[i];
Jon Miranda04f05102023-04-04 12:16:31 -07001396 startAlignTaskbar[i] |= p.startAlignTaskbar[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001397 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001398
Sunny Goyal415f1732018-11-29 10:33:47 -08001399 return this;
1400 }
1401 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001402}