blob: 25fd643b118254e6c0aef8db6079d3c2453892eb [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
Sunny Goyal19ff7282021-04-22 10:12:54 -070019import static com.android.launcher3.Utilities.dpiFromPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +010020import static com.android.launcher3.config.FeatureFlags.ENABLE_TWO_PANEL_HOME;
Sunny Goyal35c7b192021-04-20 16:51:10 -070021import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY;
Alex Chau6ed408f2022-03-04 12:58:05 +000022import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE;
Sunny Goyal19ff7282021-04-22 10:12:54 -070023import static com.android.launcher3.util.DisplayController.CHANGE_SUPPORTED_BOUNDS;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080024import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
Sunny Goyal87dc48b2018-10-12 11:42:33 -070025
Sunny Goyalc6205602015-05-21 20:46:33 -070026import android.annotation.TargetApi;
Sunny Goyal58fa4b62019-03-22 16:23:25 -070027import android.appwidget.AppWidgetHostView;
Sunny Goyal58fa4b62019-03-22 16:23:25 -070028import android.content.ComponentName;
Adam Cohen2e6da152015-05-06 11:42:25 -070029import android.content.Context;
Sunny Goyal27835952017-01-13 12:15:53 -080030import android.content.res.Configuration;
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;
Sunny Goyal58fa4b62019-03-22 16:23:25 -070036import android.graphics.Rect;
Sunny Goyal415f1732018-11-29 10:33:47 -080037import android.text.TextUtils;
38import android.util.AttributeSet;
Adam Cohen2e6da152015-05-06 11:42:25 -070039import android.util.DisplayMetrics;
Thales Lima7ec83822021-08-05 13:32:10 +010040import android.util.Log;
Sunny Goyal5bc18462019-01-07 15:13:39 -080041import android.util.SparseArray;
42import android.util.TypedValue;
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
Alex Chau1c883d82021-12-01 18:43:10 +000046import androidx.annotation.IntDef;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070047import androidx.annotation.Nullable;
48import androidx.annotation.VisibleForTesting;
49
Sunny Goyal68031ca2021-08-02 12:23:44 -070050import com.android.launcher3.model.DeviceGridState;
Alex Chau238aaee2021-10-06 16:15:24 +010051import com.android.launcher3.provider.RestoreDbTask;
Sunny Goyalfd58da62020-08-11 12:06:49 -070052import com.android.launcher3.util.DisplayController;
53import com.android.launcher3.util.DisplayController.Info;
Sunny Goyal5bc18462019-01-07 15:13:39 -080054import com.android.launcher3.util.IntArray;
Sunny Goyald0e360a2018-06-29 14:40:18 -070055import com.android.launcher3.util.MainThreadInitializedObject;
Sunny Goyal5bc18462019-01-07 15:13:39 -080056import com.android.launcher3.util.Themes;
Sunny Goyal19ff7282021-04-22 10:12:54 -070057import com.android.launcher3.util.WindowBounds;
Sunny Goyal187b16c2022-03-01 16:53:23 -080058import com.android.launcher3.util.window.WindowManagerProxy;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070059
Sunny Goyal819e1932016-07-07 16:43:58 -070060import org.xmlpull.v1.XmlPullParser;
61import org.xmlpull.v1.XmlPullParserException;
62
63import java.io.IOException;
Alex Chau1c883d82021-12-01 18:43:10 +000064import java.lang.annotation.Retention;
65import java.lang.annotation.RetentionPolicy;
Adam Cohen2e6da152015-05-06 11:42:25 -070066import java.util.ArrayList;
Sunny Goyal6e6f7992021-08-24 16:23:29 -070067import java.util.Arrays;
Sunny Goyal6d55f662019-01-02 12:13:43 -080068import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070069import java.util.List;
Adam Cohen2e6da152015-05-06 11:42:25 -070070
71public class InvariantDeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070072
Hyunyoung Songc55a3502018-12-04 15:43:16 -080073 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070074 // We do not need any synchronization for this variable as its only written on UI thread.
75 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070076 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070077
Alex Chau1c883d82021-12-01 18:43:10 +000078 @Retention(RetentionPolicy.SOURCE)
79 @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET})
80 public @interface DeviceType{}
81 public static final int TYPE_PHONE = 0;
82 public static final int TYPE_MULTI_DISPLAY = 1;
83 public static final int TYPE_TABLET = 2;
84
Hyunyoung Songc55a3502018-12-04 15:43:16 -080085 private static final String KEY_IDP_GRID_NAME = "idp_grid_name";
Sunny Goyal415f1732018-11-29 10:33:47 -080086
Sunny Goyal53d7ee42015-05-22 12:25:45 -070087 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
88
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070089 // Constants that affects the interpolation curve between statically defined device profile
90 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080091 private static final float KNEARESTNEIGHBOR = 3;
92 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -070093
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070094 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080095 private static final float WEIGHT_EFFICIENT = 100000f;
96
Thales Lima83bedbf2021-10-05 17:47:39 +010097 // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different
98 // constraints
Thales Limabb7d3882021-12-22 12:56:29 +000099 static final int COUNT_SIZES = 4;
Thales Lima83bedbf2021-10-05 17:47:39 +0100100 static final int INDEX_DEFAULT = 0;
101 static final int INDEX_LANDSCAPE = 1;
102 static final int INDEX_TWO_PANEL_PORTRAIT = 2;
103 static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
Thales Lima83bedbf2021-10-05 17:47:39 +0100104
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700105 /**
106 * Number of icons per row and column in the workspace.
107 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700108 public int numRows;
109 public int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000110 public int numSearchContainerColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700111
112 /**
113 * Number of icons per row and column in the folder.
114 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700115 public int numFolderRows;
116 public int numFolderColumns;
Thales Lima83bedbf2021-10-05 17:47:39 +0100117 public float[] iconSize;
118 public float[] iconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700119 public int iconBitmapSize;
120 public int fillResIconDpi;
Alex Chau1c883d82021-12-01 18:43:10 +0000121 public @DeviceType int deviceType;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700122
Thales Lima83bedbf2021-10-05 17:47:39 +0100123 public PointF[] minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100124
Thales Lima83bedbf2021-10-05 17:47:39 +0100125 public PointF[] borderSpaces;
Thales Lima78d00ad2021-09-30 11:29:06 +0100126 public float folderBorderSpace;
Thales Lima6e7f36c2022-01-04 12:14:11 +0000127 public float[] hotseatBorderSpaces;
Thales Lima78d00ad2021-09-30 11:29:06 +0100128
Thales Lima83bedbf2021-10-05 17:47:39 +0100129 public float[] horizontalMargin;
Jon Mirandae126d722021-02-25 10:45:20 -0500130
Thales Limabb7d3882021-12-22 12:56:29 +0000131 public float[] allAppsIconSize;
132 public float[] allAppsIconTextSize;
133 public PointF[] allAppsBorderSpaces;
134
Sunny Goyal5bc18462019-01-07 15:13:39 -0800135 private SparseArray<TypedValue> mExtraAttrs;
136
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700137 /**
138 * Number of icons inside the hotseat area.
139 */
Jon Mirandafd48b0c2022-01-31 16:25:22 -0800140 public int numShownHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700141
142 /**
Alex Chau6ed408f2022-03-04 12:58:05 +0000143 * Number of icons inside the hotseat area when using 3 buttons navigation.
144 */
145 public int numShrunkenHotseatIcons;
146
147 /**
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700148 * Number of icons inside the hotseat area that is stored in the database. This is greater than
149 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
150 * sizes that share the same DB.
151 */
152 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700153
Jon Miranda6f7e9702019-09-16 14:44:14 -0700154 /**
155 * Number of columns in the all apps list.
156 */
157 public int numAllAppsColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700158 public int numDatabaseAllAppsColumns;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700159
Jon Mirandae126d722021-02-25 10:45:20 -0500160 /**
161 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
162 */
163 protected boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400164 public int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500165
Tracy Zhou7df93d22020-01-27 13:44:06 -0800166 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800167 public int defaultLayoutId;
Adam Cohen27824492017-09-22 17:10:55 -0700168 int demoModeLayoutId;
Adam Cohen2e6da152015-05-06 11:42:25 -0700169
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000170 /**
171 * An immutable list of supported profiles.
172 */
173 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700174
sfufa@google.comde013292021-09-21 18:22:44 -0700175 @Nullable
176 public DevicePaddings devicePaddings;
Jon Miranda228877d2021-02-09 11:05:00 -0500177
Sunny Goyal6f866092016-03-17 17:04:15 -0700178 public Point defaultWallpaperSize;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700179 public Rect defaultWidgetPadding;
Sunny Goyal6f866092016-03-17 17:04:15 -0700180
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700181 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700182
Sunny Goyalf633ef52018-03-13 09:57:05 -0700183 @VisibleForTesting
Sunny Goyal187b16c2022-03-01 16:53:23 -0800184 public InvariantDeviceProfile() { }
Adam Cohen2e6da152015-05-06 11:42:25 -0700185
Sunny Goyalbbf01842015-10-08 07:41:15 -0700186 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700187 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700188 String gridName = getCurrentGridName(context);
189 String newGridName = initGrid(context, gridName);
190 if (!newGridName.equals(gridName)) {
191 Utilities.getPrefs(context).edit().putString(KEY_IDP_GRID_NAME, newGridName).apply();
192 }
Sunny Goyal68031ca2021-08-02 12:23:44 -0700193 new DeviceGridState(this).writeToPrefs(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700194
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700195 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100196 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000197 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
198 | CHANGE_NAVIGATION_MODE)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100199 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700200 }
201 });
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700202 }
203
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700204 /**
205 * This constructor should NOT have any monitors by design.
206 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800207 public InvariantDeviceProfile(Context context, String gridName) {
208 String newName = initGrid(context, gridName);
209 if (newName == null || !newName.equals(gridName)) {
210 throw new IllegalArgumentException("Unknown grid name");
211 }
212 }
213
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700214 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800215 * This constructor should NOT have any monitors by design.
216 */
217 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700218 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100219 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700220 String gridName = getCurrentGridName(context);
221
222 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000223 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
224 @DeviceType int defaultDeviceType = getDeviceType(defaultInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700225 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000226 defaultInfo,
227 getPredefinedDeviceProfiles(context, gridName, defaultDeviceType,
228 /*allowDisabledGrid=*/false),
229 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700230
Alex Chau417bd722021-01-26 15:22:18 +0000231 Info myInfo = new Info(context, display);
Alex Chau1c883d82021-12-01 18:43:10 +0000232 @DeviceType int deviceType = getDeviceType(myInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700233 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000234 myInfo,
235 getPredefinedDeviceProfiles(context, gridName, deviceType,
236 /*allowDisabledGrid=*/false),
237 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700238
239 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
240 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100241 result.iconSizes[INDEX_DEFAULT] =
242 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
243 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700244 result.iconSizes[i] = Math.min(
245 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000246 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700247
Thales Lima83bedbf2021-10-05 17:47:39 +0100248 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
249 COUNT_SIZES);
250 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
251 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500252
Alex Chau1c883d82021-12-01 18:43:10 +0000253 initGrid(context, myInfo, result, deviceType);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800254 }
255
Alex Chau238aaee2021-10-06 16:15:24 +0100256 /**
257 * Reinitialize the current grid after a restore, where some grids might now be disabled.
258 */
259 public void reinitializeAfterRestore(Context context) {
Alex Chau29a96ad2022-02-10 13:12:20 +0000260 String currentGridName = getCurrentGridName(context);
Alex Chau238aaee2021-10-06 16:15:24 +0100261 String currentDbFile = dbFile;
Alex Chau29a96ad2022-02-10 13:12:20 +0000262 String newGridName = initGrid(context, currentGridName);
263 String newDbFile = dbFile;
264 if (!newDbFile.equals(currentDbFile)) {
265 Log.d(TAG, "Restored grid is disabled : " + currentGridName
Alex Chau238aaee2021-10-06 16:15:24 +0100266 + ", migrating to: " + newGridName
267 + ", removing all other grid db files");
268 for (String gridDbFile : LauncherFiles.GRID_DB_FILES) {
269 if (gridDbFile.equals(currentDbFile)) {
270 continue;
271 }
272 if (context.getDatabasePath(gridDbFile).delete()) {
273 Log.d(TAG, "Removed old grid db file: " + gridDbFile);
274 }
275 }
Alex Chau29a96ad2022-02-10 13:12:20 +0000276 setCurrentGrid(context, newGridName);
Alex Chau238aaee2021-10-06 16:15:24 +0100277 }
278 }
279
Alex Chau1c883d82021-12-01 18:43:10 +0000280 private static @DeviceType int getDeviceType(Info displayInfo) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800281 int flagPhone = 1 << 0;
282 int flagTablet = 1 << 1;
283
284 int type = displayInfo.supportedBounds.stream()
285 .mapToInt(bounds -> displayInfo.isTablet(bounds) ? flagTablet : flagPhone)
286 .reduce(0, (a, b) -> a | b);
287 if ((type == (flagPhone | flagTablet)) && ENABLE_TWO_PANEL_HOME.get()) {
288 // device has profiles supporting both phone and table modes
Alex Chau1c883d82021-12-01 18:43:10 +0000289 return TYPE_MULTI_DISPLAY;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800290 } else if (type == flagTablet) {
Alex Chau1c883d82021-12-01 18:43:10 +0000291 return TYPE_TABLET;
292 } else {
293 return TYPE_PHONE;
294 }
295 }
296
Tracy Zhou42255d22020-03-13 00:38:11 -0700297 public static String getCurrentGridName(Context context) {
Tracy Zhouc6060e62020-04-27 13:05:34 -0700298 return Utilities.isGridOptionsEnabled(context)
299 ? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null;
Tracy Zhou42255d22020-03-13 00:38:11 -0700300 }
301
Sunny Goyaleff44f32019-01-09 17:29:49 -0800302 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700303 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Alex Chau1c883d82021-12-01 18:43:10 +0000304 @DeviceType int deviceType = getDeviceType(displayInfo);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700305
306 ArrayList<DisplayOption> allOptions =
Alex Chau1c883d82021-12-01 18:43:10 +0000307 getPredefinedDeviceProfiles(context, gridName, deviceType,
Alex Chau238aaee2021-10-06 16:15:24 +0100308 RestoreDbTask.isPending(context));
Sunny Goyal19ff7282021-04-22 10:12:54 -0700309 DisplayOption displayOption =
Alex Chau1c883d82021-12-01 18:43:10 +0000310 invDistWeightedInterpolate(displayInfo, allOptions, deviceType);
311 initGrid(context, displayInfo, displayOption, deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700312 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800313 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700314
Alex Chau1c883d82021-12-01 18:43:10 +0000315 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption,
316 @DeviceType int deviceType) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700317 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700318 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000319 numRows = closestProfile.numRows;
320 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000321 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000322 dbFile = closestProfile.dbFile;
323 defaultLayoutId = closestProfile.defaultLayoutId;
324 demoModeLayoutId = closestProfile.demoModeLayoutId;
325 numFolderRows = closestProfile.numFolderRows;
326 numFolderColumns = closestProfile.numFolderColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500327 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400328 devicePaddingId = closestProfile.devicePaddingId;
Alex Chau1c883d82021-12-01 18:43:10 +0000329 this.deviceType = deviceType;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000330
331 mExtraAttrs = closestProfile.extraAttrs;
332
Thales Lima83bedbf2021-10-05 17:47:39 +0100333 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100334 float maxIconSize = iconSize[0];
335 for (int i = 1; i < iconSize.length; i++) {
336 maxIconSize = Math.max(maxIconSize, iconSize[i]);
337 }
338 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000339 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
340
Thales Lima83bedbf2021-10-05 17:47:39 +0100341 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700342
Thales Lima83bedbf2021-10-05 17:47:39 +0100343 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100344
Thales Lima83bedbf2021-10-05 17:47:39 +0100345 borderSpaces = displayOption.borderSpaces;
Thales Lima78d00ad2021-09-30 11:29:06 +0100346 folderBorderSpace = displayOption.folderBorderSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700347
Thales Limad90faab2021-09-21 17:18:47 +0100348 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100349
Sunny Goyal19ff7282021-04-22 10:12:54 -0700350 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000351 numShrunkenHotseatIcons = closestProfile.numShrunkenHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000352 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700353 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Lima6e7f36c2022-01-04 12:14:11 +0000354 hotseatBorderSpaces = displayOption.hotseatBorderSpaces;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700355
356 numAllAppsColumns = closestProfile.numAllAppsColumns;
Alex Chau1c883d82021-12-01 18:43:10 +0000357 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700358 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500359
Thales Limabb7d3882021-12-22 12:56:29 +0000360 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
361 allAppsIconSize = displayOption.allAppsIconSizes;
362 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Thales Lima83bedbf2021-10-05 17:47:39 +0100363 if (!Utilities.isGridOptionsEnabled(context)) {
Thales Limabb7d3882021-12-22 12:56:29 +0000364 allAppsIconSize = iconSize;
365 allAppsIconTextSize = iconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000366 }
367
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400368 if (devicePaddingId != 0) {
369 devicePaddings = new DevicePaddings(context, devicePaddingId);
370 }
371
Sunny Goyalae190ff2020-04-14 00:19:01 +0000372 // If the partner customization apk contains any grid overrides, apply them
373 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700374 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700375
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000376 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700377 defaultWallpaperSize = new Point(displayInfo.currentSize);
378 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000379 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chau1c883d82021-12-01 18:43:10 +0000380 .setUseTwoPanels(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000381 .setWindowBounds(bounds)
382 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700383
Sunny Goyal19ff7282021-04-22 10:12:54 -0700384 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
385 int displayWidth = bounds.bounds.width();
386 int displayHeight = bounds.bounds.height();
387 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700388
Sunny Goyal19ff7282021-04-22 10:12:54 -0700389 // We need to ensure that there is enough extra space in the wallpaper
390 // for the intended parallax effects
391 float parallaxFactor =
392 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.densityDpi) < 720
393 ? 2
394 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
395 defaultWallpaperSize.x =
396 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700397 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000398 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700399
400 ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName());
401 defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
Adam Cohen2e6da152015-05-06 11:42:25 -0700402 }
403
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700404 public void addOnChangeListener(OnIDPChangeListener listener) {
405 mChangeListeners.add(listener);
406 }
407
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800408 public void removeOnChangeListener(OnIDPChangeListener listener) {
409 mChangeListeners.remove(listener);
410 }
411
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800412
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800413 public void setCurrentGrid(Context context, String gridName) {
414 Context appContext = context.getApplicationContext();
415 Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply();
Sunny Goyal6fe3eec2019-08-15 14:53:41 -0700416 MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800417 }
418
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700419 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700420 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000421 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
422 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700423 }
424
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700425 private void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700426 Object[] oldState = toModelState();
427
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700428 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700429 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700430 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700431
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700432 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700433 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700434 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700435 }
436 }
437
Alex Chau1c883d82021-12-01 18:43:10 +0000438 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context,
439 String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800440 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100441
Alex Chau1c883d82021-12-01 18:43:10 +0000442 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700443 final int depth = parser.getDepth();
444 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700445 while (((type = parser.next()) != XmlPullParser.END_TAG ||
446 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800447 if ((type == XmlPullParser.START_TAG)
448 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800449
Alex Chau1c883d82021-12-01 18:43:10 +0000450 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser),
451 deviceType);
Alex Chau238aaee2021-10-06 16:15:24 +0100452 if (gridOption.isEnabled || allowDisabledGrid) {
Thales Lima7ec83822021-08-05 13:32:10 +0100453 final int displayDepth = parser.getDepth();
454 while (((type = parser.next()) != XmlPullParser.END_TAG
455 || parser.getDepth() > displayDepth)
456 && type != XmlPullParser.END_DOCUMENT) {
457 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
458 parser.getName())) {
459 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100460 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100461 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800462 }
463 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700464 }
465 }
sfufa@google.comde013292021-09-21 18:22:44 -0700466 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700467 throw new RuntimeException(e);
468 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800469
Sunny Goyalae190ff2020-04-14 00:19:01 +0000470 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800471 if (!TextUtils.isEmpty(gridName)) {
472 for (DisplayOption option : profiles) {
Alex Chau238aaee2021-10-06 16:15:24 +0100473 if (gridName.equals(option.grid.name)
474 && (option.grid.isEnabled || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000475 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800476 }
477 }
478 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000479 if (filteredProfiles.isEmpty()) {
480 // No grid found, use the default options
481 for (DisplayOption option : profiles) {
482 if (option.canBeDefault) {
483 filteredProfiles.add(option);
484 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800485 }
486 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000487 if (filteredProfiles.isEmpty()) {
488 throw new RuntimeException("No display option with canBeDefault=true");
489 }
490 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700491 }
492
Thales Lima7ec83822021-08-05 13:32:10 +0100493 /**
494 * @return all the grid options that can be shown on the device
495 */
496 public List<GridOption> parseAllGridOptions(Context context) {
497 List<GridOption> result = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100498
Alex Chau1c883d82021-12-01 18:43:10 +0000499 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100500 final int depth = parser.getDepth();
501 int type;
502 while (((type = parser.next()) != XmlPullParser.END_TAG
503 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
504 if ((type == XmlPullParser.START_TAG)
505 && GridOption.TAG_NAME.equals(parser.getName())) {
506 GridOption option =
Alex Chau1c883d82021-12-01 18:43:10 +0000507 new GridOption(context, Xml.asAttributeSet(parser), deviceType);
Thales Lima7ec83822021-08-05 13:32:10 +0100508 if (option.isEnabled) {
509 result.add(option);
510 }
511 }
512 }
513 } catch (IOException | XmlPullParserException e) {
514 Log.e(TAG, "Error parsing device profile", e);
515 return Collections.emptyList();
516 }
517 return result;
518 }
519
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700520 private int getLauncherIconDensity(int requiredSize) {
521 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700522 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700523 DisplayMetrics.DENSITY_LOW,
524 DisplayMetrics.DENSITY_MEDIUM,
525 DisplayMetrics.DENSITY_TV,
526 DisplayMetrics.DENSITY_HIGH,
527 DisplayMetrics.DENSITY_XHIGH,
528 DisplayMetrics.DENSITY_XXHIGH,
529 DisplayMetrics.DENSITY_XXXHIGH
530 };
531
532 int density = DisplayMetrics.DENSITY_XXXHIGH;
533 for (int i = densityBuckets.length - 1; i >= 0; i--) {
534 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
535 / DisplayMetrics.DENSITY_DEFAULT;
536 if (expectedSize >= requiredSize) {
537 density = densityBuckets[i];
538 }
539 }
540
541 return density;
542 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700543
Adam Cohen2e6da152015-05-06 11:42:25 -0700544 /**
545 * Apply any Partner customization grid overrides.
546 *
547 * Currently we support: all apps row / column count.
548 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700549 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
550 Partner p = Partner.get(context.getPackageManager());
Adam Cohen2e6da152015-05-06 11:42:25 -0700551 if (p != null) {
552 p.applyInvariantDeviceProfileOverrides(this, dm);
553 }
554 }
555
Sunny Goyal415f1732018-11-29 10:33:47 -0800556 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700557 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700558 }
559
Sunny Goyal19ff7282021-04-22 10:12:54 -0700560 private static DisplayOption invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000561 Info displayInfo, ArrayList<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700562 int minWidthPx = Integer.MAX_VALUE;
563 int minHeightPx = Integer.MAX_VALUE;
564 for (WindowBounds bounds : displayInfo.supportedBounds) {
565 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000566 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700567 // For split displays, take half width per page
568 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
569 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700570
Sunny Goyal19ff7282021-04-22 10:12:54 -0700571 } else if (!isTablet && bounds.isLandscape()) {
572 // We will use transposed layout in this case
573 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
574 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
575 } else {
576 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
577 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
578 }
579 }
580
581 float width = dpiFromPx(minWidthPx, displayInfo.densityDpi);
582 float height = dpiFromPx(minHeightPx, displayInfo.densityDpi);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700583
584 // Sort the profiles based on the closeness to the device size
585 Collections.sort(points, (a, b) ->
586 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
587 dist(width, height, b.minWidthDps, b.minHeightDps)));
588
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700589 DisplayOption closestPoint = points.get(0);
590 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700591 float weights = 0;
592
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700593 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
594 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700595 }
596
597 DisplayOption out = new DisplayOption(closestOption);
598 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700599 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700600 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
601 weights += w;
602 out.add(new DisplayOption().add(p).multiply(w));
603 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700604 out.multiply(1.0f / weights);
605
Thales Lima6e0005a2021-10-27 15:53:41 +0100606 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700607 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100608 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
609 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700610 }
611
612 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700613 }
614
Sunny Goyal27835952017-01-13 12:15:53 -0800615 public DeviceProfile getDeviceProfile(Context context) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700616 Resources res = context.getResources();
617 Configuration config = context.getResources().getConfiguration();
618
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400619 float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density;
620 float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800621 return getBestMatch(screenWidth, screenHeight,
622 WindowManagerProxy.INSTANCE.get(context).getRotation(context));
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400623 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700624
Sunny Goyal187b16c2022-03-01 16:53:23 -0800625 /**
626 * Returns the device profile matching the provided screen configuration
627 */
628 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700629 DeviceProfile bestMatch = supportedProfiles.get(0);
630 float minDiff = Float.MAX_VALUE;
631
632 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400633 float diff = Math.abs(profile.widthPx - screenWidth)
634 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700635 if (diff < minDiff) {
636 minDiff = diff;
637 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800638 } else if (diff == minDiff && profile.rotationHint == rotation) {
639 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700640 }
641 }
642 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800643 }
644
Sunny Goyal415f1732018-11-29 10:33:47 -0800645 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700646 float d = dist(x0, y0, x1, y1);
647 if (Float.compare(d, 0f) == 0) {
648 return Float.POSITIVE_INFINITY;
649 }
650 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
651 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700652
653 /**
654 * As a ratio of screen height, the total distance we want the parallax effect to span
655 * horizontally
656 */
657 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
658 float aspectRatio = width / (float) height;
659
660 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
661 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
662 // We will use these two data points to extrapolate how much the wallpaper parallax effect
663 // to span (ie travel) at any aspect ratio:
664
sfufa@google.comde013292021-09-21 18:22:44 -0700665 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
666 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700667 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
668 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
669
670 // To find out the desired width at different aspect ratios, we use the following two
671 // formulas, where the coefficient on x is the aspect ratio (width/height):
672 // (16/10)x + y = 1.5
673 // (10/16)x + y = 1.2
674 // We solve for x and y and end up with a final formula:
675 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700676 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
677 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700678 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
679 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
680 return x * aspectRatio + y;
681 }
682
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700683 public interface OnIDPChangeListener {
684
Sunny Goyalb47172b2021-05-03 19:59:51 -0700685 /**
686 * Called when the device provide changes
687 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700688 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700689 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800690
691
Sunny Goyaleff44f32019-01-09 17:29:49 -0800692 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800693
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800694 public static final String TAG_NAME = "grid-option";
695
Alex Chau1c883d82021-12-01 18:43:10 +0000696 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
697 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
698 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
699 private static final int DEVICE_CATEGORY_ALL =
700 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
701
Sunny Goyaleff44f32019-01-09 17:29:49 -0800702 public final String name;
703 public final int numRows;
704 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000705 public final int numSearchContainerColumns;
Thales Lima7ec83822021-08-05 13:32:10 +0100706 public final boolean isEnabled;
Sunny Goyal415f1732018-11-29 10:33:47 -0800707
708 private final int numFolderRows;
709 private final int numFolderColumns;
710
Sunny Goyal19ff7282021-04-22 10:12:54 -0700711 private final int numAllAppsColumns;
712 private final int numDatabaseAllAppsColumns;
713 private final int numHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000714 private final int numShrunkenHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700715 private final int numDatabaseHotseatIcons;
Sunny Goyal415f1732018-11-29 10:33:47 -0800716
Tracy Zhou7df93d22020-01-27 13:44:06 -0800717 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000718
Sunny Goyal415f1732018-11-29 10:33:47 -0800719 private final int defaultLayoutId;
720 private final int demoModeLayoutId;
721
Jon Mirandae126d722021-02-25 10:45:20 -0500722 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400723 private final int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500724
Sunny Goyal5bc18462019-01-07 15:13:39 -0800725 private final SparseArray<TypedValue> extraAttrs;
726
Alex Chau1c883d82021-12-01 18:43:10 +0000727 public GridOption(Context context, AttributeSet attrs, @DeviceType int deviceType) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800728 TypedArray a = context.obtainStyledAttributes(
729 attrs, R.styleable.GridDisplayOption);
730 name = a.getString(R.styleable.GridDisplayOption_name);
731 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
732 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000733 numSearchContainerColumns = a.getInt(
734 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal415f1732018-11-29 10:33:47 -0800735
Tracy Zhou7df93d22020-01-27 13:44:06 -0800736 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Alex Chau1c883d82021-12-01 18:43:10 +0000737 defaultLayoutId = a.getResourceId(deviceType == TYPE_MULTI_DISPLAY && a.hasValue(
Alex Chau1e448462021-08-13 21:48:35 +0100738 R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId)
739 ? R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId
740 : R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800741 demoModeLayoutId = a.getResourceId(
742 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700743
744 numAllAppsColumns = a.getInt(
745 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
746 numDatabaseAllAppsColumns = a.getInt(
747 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
748
749 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800750 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Alex Chau6ed408f2022-03-04 12:58:05 +0000751 numShrunkenHotseatIcons = a.getInt(
752 R.styleable.GridDisplayOption_numShrunkenHotseatIcons, numHotseatIcons / 2);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700753 numDatabaseHotseatIcons = a.getInt(
754 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
755
Sunny Goyal415f1732018-11-29 10:33:47 -0800756 numFolderRows = a.getInt(
757 R.styleable.GridDisplayOption_numFolderRows, numRows);
758 numFolderColumns = a.getInt(
759 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700760
Jon Mirandae126d722021-02-25 10:45:20 -0500761 isScalable = a.getBoolean(
762 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400763 devicePaddingId = a.getResourceId(
764 R.styleable.GridDisplayOption_devicePaddingId, 0);
Jon Mirandae126d722021-02-25 10:45:20 -0500765
Alex Chau1c883d82021-12-01 18:43:10 +0000766 int deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
767 DEVICE_CATEGORY_ALL);
768 isEnabled = (deviceType == TYPE_PHONE
769 && ((deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE))
770 || (deviceType == TYPE_TABLET
771 && ((deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET))
772 || (deviceType == TYPE_MULTI_DISPLAY
773 && ((deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
774 == DEVICE_CATEGORY_MULTI_DISPLAY));
Thales Lima7ec83822021-08-05 13:32:10 +0100775
Sunny Goyal415f1732018-11-29 10:33:47 -0800776 a.recycle();
Sunny Goyal5bc18462019-01-07 15:13:39 -0800777 extraAttrs = Themes.createValueMap(context, attrs,
778 IntArray.wrap(R.styleable.GridDisplayOption));
Sunny Goyal415f1732018-11-29 10:33:47 -0800779 }
780 }
781
Sunny Goyal19ff7282021-04-22 10:12:54 -0700782 @VisibleForTesting
783 static final class DisplayOption {
784
785 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800786
Sunny Goyal415f1732018-11-29 10:33:47 -0800787 private final float minWidthDps;
788 private final float minHeightDps;
789 private final boolean canBeDefault;
790
Thales Lima83bedbf2021-10-05 17:47:39 +0100791 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +0100792
793 private float folderBorderSpace;
794 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +0100795 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Lima6e7f36c2022-01-04 12:14:11 +0000796 private final float[] hotseatBorderSpaces = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +0100797
Thales Lima78d00ad2021-09-30 11:29:06 +0100798 private final float[] iconSizes = new float[COUNT_SIZES];
799 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800800
Thales Limabb7d3882021-12-22 12:56:29 +0000801 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
802 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
803 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
804
Thales Lima1de4d552021-10-13 16:13:25 +0100805 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800806 this.grid = grid;
807
Thales Lima1de4d552021-10-13 16:13:25 +0100808 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -0800809
Sunny Goyal415f1732018-11-29 10:33:47 -0800810 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
811 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700812
Thales Lima1de4d552021-10-13 16:13:25 +0100813 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -0800814
Thales Lima83bedbf2021-10-05 17:47:39 +0100815 float x;
816 float y;
817
Thales Lima85c942f2021-12-31 13:04:20 +0000818 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
819 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +0100820 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +0000821
822 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
823 minCellSize[INDEX_DEFAULT].x);
824 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
825 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100826 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100827
Thales Lima85c942f2021-12-31 13:04:20 +0000828 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100829 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +0000830 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100831 minCellSize[INDEX_DEFAULT].y);
832 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
833
Thales Lima85c942f2021-12-31 13:04:20 +0000834 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100835 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +0000836 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100837 minCellSize[INDEX_DEFAULT].y);
838 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +0100839
Thales Lima85c942f2021-12-31 13:04:20 +0000840 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
841 float borderSpaceTwoPanelPortrait = a.getFloat(
842 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
843 float borderSpaceTwoPanelLandscape = a.getFloat(
844 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +0100845
Thales Lima85c942f2021-12-31 13:04:20 +0000846 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
847 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +0100848 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
849 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
850
851 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000852 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
853 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +0100854 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000855 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
856 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +0100857 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
858
859 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000860 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
861 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100862 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000863 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
864 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100865 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
866
Thales Limabb7d3882021-12-22 12:56:29 +0000867 folderBorderSpace = borderSpace;
868
Thales Lima85c942f2021-12-31 13:04:20 +0000869 x = y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpace,
Thales Lima78d00ad2021-09-30 11:29:06 +0100870 borderSpace);
Thales Limabb7d3882021-12-22 12:56:29 +0000871 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
872 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
873 x = y = a.getFloat(
874 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
875 allAppsBorderSpaces[INDEX_DEFAULT].x);
876 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
877 x = y = a.getFloat(
878 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
879 allAppsBorderSpaces[INDEX_DEFAULT].x);
880 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -0500881
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700882 iconSizes[INDEX_DEFAULT] =
883 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
884 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +0000885 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700886 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700887 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +0000888 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700889 iconSizes[INDEX_DEFAULT]);
890 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +0000891 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100892 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700893
Thales Limabb7d3882021-12-22 12:56:29 +0000894 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
895 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
896 allAppsIconSizes[INDEX_LANDSCAPE] = allAppsIconSizes[INDEX_DEFAULT];
897 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
898 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
899 allAppsIconSizes[INDEX_DEFAULT]);
900 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
901 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
902 allAppsIconSizes[INDEX_DEFAULT]);
903
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700904 textSizes[INDEX_DEFAULT] =
905 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
906 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +0000907 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700908 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700909 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +0000910 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700911 textSizes[INDEX_DEFAULT]);
912 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +0000913 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100914 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700915
Thales Limabb7d3882021-12-22 12:56:29 +0000916 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
917 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
918 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
919 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
920 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
921 allAppsIconTextSizes[INDEX_DEFAULT]);
922 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
923 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
924 allAppsIconTextSizes[INDEX_DEFAULT]);
925
Thales Lima83bedbf2021-10-05 17:47:39 +0100926 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
927 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +0000928 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
929 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
930 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +0100931 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000932 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100933 horizontalMargin[INDEX_DEFAULT]);
934 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000935 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100936 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +0100937
Thales Lima6e7f36c2022-01-04 12:14:11 +0000938 hotseatBorderSpaces[INDEX_DEFAULT] = a.getFloat(
939 R.styleable.ProfileDisplayOption_hotseatBorderSpace, borderSpace);
Thales Limadd027342022-01-07 12:54:37 +0000940 hotseatBorderSpaces[INDEX_LANDSCAPE] = a.getFloat(
941 R.styleable.ProfileDisplayOption_hotseatBorderSpaceLandscape,
942 hotseatBorderSpaces[INDEX_DEFAULT]);
Thales Lima6e7f36c2022-01-04 12:14:11 +0000943 hotseatBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
944 R.styleable.ProfileDisplayOption_hotseatBorderSpaceTwoPanelLandscape,
945 hotseatBorderSpaces[INDEX_DEFAULT]);
946 hotseatBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
947 R.styleable.ProfileDisplayOption_hotseatBorderSpaceTwoPanelPortrait,
948 hotseatBorderSpaces[INDEX_DEFAULT]);
949
Sunny Goyal415f1732018-11-29 10:33:47 -0800950 a.recycle();
951 }
952
953 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700954 this(null);
955 }
956
957 DisplayOption(GridOption grid) {
958 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800959 minWidthDps = 0;
960 minHeightDps = 0;
961 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +0100962 for (int i = 0; i < COUNT_SIZES; i++) {
963 iconSizes[i] = 0;
964 textSizes[i] = 0;
965 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +0100966 minCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +0000967 allAppsIconSizes[i] = 0;
968 allAppsIconTextSizes[i] = 0;
969 allAppsBorderSpaces[i] = new PointF();
Thales Lima78d00ad2021-09-30 11:29:06 +0100970 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800971 }
972
973 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100974 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700975 iconSizes[i] *= w;
976 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +0100977 borderSpaces[i].x *= w;
978 borderSpaces[i].y *= w;
979 minCellSize[i].x *= w;
980 minCellSize[i].y *= w;
981 horizontalMargin[i] *= w;
Thales Lima6e7f36c2022-01-04 12:14:11 +0000982 hotseatBorderSpaces[i] *= w;
Thales Limabb7d3882021-12-22 12:56:29 +0000983 allAppsIconSizes[i] *= w;
984 allAppsIconTextSizes[i] *= w;
985 allAppsBorderSpaces[i].x *= w;
986 allAppsBorderSpaces[i].y *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700987 }
Thales Lima78d00ad2021-09-30 11:29:06 +0100988
989 folderBorderSpace *= w;
990
Sunny Goyal415f1732018-11-29 10:33:47 -0800991 return this;
992 }
993
994 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100995 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700996 iconSizes[i] += p.iconSizes[i];
997 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +0100998 borderSpaces[i].x += p.borderSpaces[i].x;
999 borderSpaces[i].y += p.borderSpaces[i].y;
1000 minCellSize[i].x += p.minCellSize[i].x;
1001 minCellSize[i].y += p.minCellSize[i].y;
1002 horizontalMargin[i] += p.horizontalMargin[i];
Thales Lima6e7f36c2022-01-04 12:14:11 +00001003 hotseatBorderSpaces[i] += p.hotseatBorderSpaces[i];
Thales Limabb7d3882021-12-22 12:56:29 +00001004 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1005 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1006 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1007 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001008 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001009
1010 folderBorderSpace += p.folderBorderSpace;
1011
Sunny Goyal415f1732018-11-29 10:33:47 -08001012 return this;
1013 }
1014 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001015}