blob: 886c6573d7ffc4a57c27e01e714f3eea3d39455b [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;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070058
Sunny Goyal819e1932016-07-07 16:43:58 -070059import org.xmlpull.v1.XmlPullParser;
60import org.xmlpull.v1.XmlPullParserException;
61
62import java.io.IOException;
Alex Chau1c883d82021-12-01 18:43:10 +000063import java.lang.annotation.Retention;
64import java.lang.annotation.RetentionPolicy;
Adam Cohen2e6da152015-05-06 11:42:25 -070065import java.util.ArrayList;
Sunny Goyal6e6f7992021-08-24 16:23:29 -070066import java.util.Arrays;
Sunny Goyal6d55f662019-01-02 12:13:43 -080067import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070068import java.util.List;
Adam Cohen2e6da152015-05-06 11:42:25 -070069
70public class InvariantDeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070071
Hyunyoung Songc55a3502018-12-04 15:43:16 -080072 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070073 // We do not need any synchronization for this variable as its only written on UI thread.
74 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070075 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070076
Alex Chau1c883d82021-12-01 18:43:10 +000077 @Retention(RetentionPolicy.SOURCE)
78 @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET})
79 public @interface DeviceType{}
80 public static final int TYPE_PHONE = 0;
81 public static final int TYPE_MULTI_DISPLAY = 1;
82 public static final int TYPE_TABLET = 2;
83
Hyunyoung Songc55a3502018-12-04 15:43:16 -080084 private static final String KEY_IDP_GRID_NAME = "idp_grid_name";
Sunny Goyal415f1732018-11-29 10:33:47 -080085
Sunny Goyal53d7ee42015-05-22 12:25:45 -070086 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
87
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070088 // Constants that affects the interpolation curve between statically defined device profile
89 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080090 private static final float KNEARESTNEIGHBOR = 3;
91 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -070092
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070093 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080094 private static final float WEIGHT_EFFICIENT = 100000f;
95
Thales Lima83bedbf2021-10-05 17:47:39 +010096 // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different
97 // constraints
Thales Limabb7d3882021-12-22 12:56:29 +000098 static final int COUNT_SIZES = 4;
Thales Lima83bedbf2021-10-05 17:47:39 +010099 static final int INDEX_DEFAULT = 0;
100 static final int INDEX_LANDSCAPE = 1;
101 static final int INDEX_TWO_PANEL_PORTRAIT = 2;
102 static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
Thales Lima83bedbf2021-10-05 17:47:39 +0100103
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700104 /**
105 * Number of icons per row and column in the workspace.
106 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700107 public int numRows;
108 public int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000109 public int numSearchContainerColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700110
111 /**
112 * Number of icons per row and column in the folder.
113 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700114 public int numFolderRows;
115 public int numFolderColumns;
Thales Lima83bedbf2021-10-05 17:47:39 +0100116 public float[] iconSize;
117 public float[] iconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700118 public int iconBitmapSize;
119 public int fillResIconDpi;
Alex Chau1c883d82021-12-01 18:43:10 +0000120 public @DeviceType int deviceType;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700121
Thales Lima83bedbf2021-10-05 17:47:39 +0100122 public PointF[] minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100123
Thales Lima83bedbf2021-10-05 17:47:39 +0100124 public PointF[] borderSpaces;
Thales Lima78d00ad2021-09-30 11:29:06 +0100125 public float folderBorderSpace;
Thales Lima6e7f36c2022-01-04 12:14:11 +0000126 public float[] hotseatBorderSpaces;
Thales Lima78d00ad2021-09-30 11:29:06 +0100127
Thales Lima83bedbf2021-10-05 17:47:39 +0100128 public float[] horizontalMargin;
Jon Mirandae126d722021-02-25 10:45:20 -0500129
Thales Limabb7d3882021-12-22 12:56:29 +0000130 public float[] allAppsIconSize;
131 public float[] allAppsIconTextSize;
132 public PointF[] allAppsBorderSpaces;
133
Sunny Goyal5bc18462019-01-07 15:13:39 -0800134 private SparseArray<TypedValue> mExtraAttrs;
135
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700136 /**
137 * Number of icons inside the hotseat area.
138 */
Jon Mirandafd48b0c2022-01-31 16:25:22 -0800139 public int numShownHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700140
141 /**
Alex Chau6ed408f2022-03-04 12:58:05 +0000142 * Number of icons inside the hotseat area when using 3 buttons navigation.
143 */
144 public int numShrunkenHotseatIcons;
145
146 /**
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700147 * Number of icons inside the hotseat area that is stored in the database. This is greater than
148 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
149 * sizes that share the same DB.
150 */
151 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700152
Jon Miranda6f7e9702019-09-16 14:44:14 -0700153 /**
154 * Number of columns in the all apps list.
155 */
156 public int numAllAppsColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700157 public int numDatabaseAllAppsColumns;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700158
Jon Mirandae126d722021-02-25 10:45:20 -0500159 /**
160 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
161 */
162 protected boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400163 public int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500164
Tracy Zhou7df93d22020-01-27 13:44:06 -0800165 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800166 public int defaultLayoutId;
Adam Cohen27824492017-09-22 17:10:55 -0700167 int demoModeLayoutId;
Adam Cohen2e6da152015-05-06 11:42:25 -0700168
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000169 /**
170 * An immutable list of supported profiles.
171 */
172 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700173
sfufa@google.comde013292021-09-21 18:22:44 -0700174 @Nullable
175 public DevicePaddings devicePaddings;
Jon Miranda228877d2021-02-09 11:05:00 -0500176
Sunny Goyal6f866092016-03-17 17:04:15 -0700177 public Point defaultWallpaperSize;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700178 public Rect defaultWidgetPadding;
Sunny Goyal6f866092016-03-17 17:04:15 -0700179
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700180 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700181
Sunny Goyalf633ef52018-03-13 09:57:05 -0700182 @VisibleForTesting
sfufa@google.comde013292021-09-21 18:22:44 -0700183 public InvariantDeviceProfile() {
184 }
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) {
281 // Each screen has two profiles (portrait/landscape), so devices with four or more
282 // supported profiles implies two or more internal displays.
283 if (displayInfo.supportedBounds.size() >= 4 && ENABLE_TWO_PANEL_HOME.get()) {
284 return TYPE_MULTI_DISPLAY;
285 } else if (displayInfo.supportedBounds.stream().allMatch(displayInfo::isTablet)) {
286 return TYPE_TABLET;
287 } else {
288 return TYPE_PHONE;
289 }
290 }
291
Tracy Zhou42255d22020-03-13 00:38:11 -0700292 public static String getCurrentGridName(Context context) {
Tracy Zhouc6060e62020-04-27 13:05:34 -0700293 return Utilities.isGridOptionsEnabled(context)
294 ? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null;
Tracy Zhou42255d22020-03-13 00:38:11 -0700295 }
296
Sunny Goyaleff44f32019-01-09 17:29:49 -0800297 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700298 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Alex Chau1c883d82021-12-01 18:43:10 +0000299 @DeviceType int deviceType = getDeviceType(displayInfo);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700300
301 ArrayList<DisplayOption> allOptions =
Alex Chau1c883d82021-12-01 18:43:10 +0000302 getPredefinedDeviceProfiles(context, gridName, deviceType,
Alex Chau238aaee2021-10-06 16:15:24 +0100303 RestoreDbTask.isPending(context));
Sunny Goyal19ff7282021-04-22 10:12:54 -0700304 DisplayOption displayOption =
Alex Chau1c883d82021-12-01 18:43:10 +0000305 invDistWeightedInterpolate(displayInfo, allOptions, deviceType);
306 initGrid(context, displayInfo, displayOption, deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700307 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800308 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700309
Alex Chau1c883d82021-12-01 18:43:10 +0000310 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption,
311 @DeviceType int deviceType) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700312 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700313 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000314 numRows = closestProfile.numRows;
315 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000316 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000317 dbFile = closestProfile.dbFile;
318 defaultLayoutId = closestProfile.defaultLayoutId;
319 demoModeLayoutId = closestProfile.demoModeLayoutId;
320 numFolderRows = closestProfile.numFolderRows;
321 numFolderColumns = closestProfile.numFolderColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500322 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400323 devicePaddingId = closestProfile.devicePaddingId;
Alex Chau1c883d82021-12-01 18:43:10 +0000324 this.deviceType = deviceType;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000325
326 mExtraAttrs = closestProfile.extraAttrs;
327
Thales Lima83bedbf2021-10-05 17:47:39 +0100328 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100329 float maxIconSize = iconSize[0];
330 for (int i = 1; i < iconSize.length; i++) {
331 maxIconSize = Math.max(maxIconSize, iconSize[i]);
332 }
333 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000334 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
335
Thales Lima83bedbf2021-10-05 17:47:39 +0100336 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700337
Thales Lima83bedbf2021-10-05 17:47:39 +0100338 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100339
Thales Lima83bedbf2021-10-05 17:47:39 +0100340 borderSpaces = displayOption.borderSpaces;
Thales Lima78d00ad2021-09-30 11:29:06 +0100341 folderBorderSpace = displayOption.folderBorderSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700342
Thales Limad90faab2021-09-21 17:18:47 +0100343 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100344
Sunny Goyal19ff7282021-04-22 10:12:54 -0700345 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000346 numShrunkenHotseatIcons = closestProfile.numShrunkenHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000347 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700348 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Lima6e7f36c2022-01-04 12:14:11 +0000349 hotseatBorderSpaces = displayOption.hotseatBorderSpaces;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700350
351 numAllAppsColumns = closestProfile.numAllAppsColumns;
Alex Chau1c883d82021-12-01 18:43:10 +0000352 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700353 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500354
Thales Limabb7d3882021-12-22 12:56:29 +0000355 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
356 allAppsIconSize = displayOption.allAppsIconSizes;
357 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Thales Lima83bedbf2021-10-05 17:47:39 +0100358 if (!Utilities.isGridOptionsEnabled(context)) {
Thales Limabb7d3882021-12-22 12:56:29 +0000359 allAppsIconSize = iconSize;
360 allAppsIconTextSize = iconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000361 }
362
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400363 if (devicePaddingId != 0) {
364 devicePaddings = new DevicePaddings(context, devicePaddingId);
365 }
366
Sunny Goyalae190ff2020-04-14 00:19:01 +0000367 // If the partner customization apk contains any grid overrides, apply them
368 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700369 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700370
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000371 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700372 defaultWallpaperSize = new Point(displayInfo.currentSize);
373 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000374 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chau1c883d82021-12-01 18:43:10 +0000375 .setUseTwoPanels(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000376 .setWindowBounds(bounds)
377 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700378
Sunny Goyal19ff7282021-04-22 10:12:54 -0700379 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
380 int displayWidth = bounds.bounds.width();
381 int displayHeight = bounds.bounds.height();
382 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700383
Sunny Goyal19ff7282021-04-22 10:12:54 -0700384 // We need to ensure that there is enough extra space in the wallpaper
385 // for the intended parallax effects
386 float parallaxFactor =
387 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.densityDpi) < 720
388 ? 2
389 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
390 defaultWallpaperSize.x =
391 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700392 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000393 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700394
395 ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName());
396 defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
Adam Cohen2e6da152015-05-06 11:42:25 -0700397 }
398
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700399 public void addOnChangeListener(OnIDPChangeListener listener) {
400 mChangeListeners.add(listener);
401 }
402
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800403 public void removeOnChangeListener(OnIDPChangeListener listener) {
404 mChangeListeners.remove(listener);
405 }
406
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800407
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800408 public void setCurrentGrid(Context context, String gridName) {
409 Context appContext = context.getApplicationContext();
410 Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply();
Sunny Goyal6fe3eec2019-08-15 14:53:41 -0700411 MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800412 }
413
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700414 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700415 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000416 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
417 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700418 }
419
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700420 private void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700421 Object[] oldState = toModelState();
422
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700423 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700424 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700425 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700426
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700427 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700428 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700429 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700430 }
431 }
432
Alex Chau1c883d82021-12-01 18:43:10 +0000433 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context,
434 String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800435 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100436
Alex Chau1c883d82021-12-01 18:43:10 +0000437 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700438 final int depth = parser.getDepth();
439 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700440 while (((type = parser.next()) != XmlPullParser.END_TAG ||
441 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800442 if ((type == XmlPullParser.START_TAG)
443 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800444
Alex Chau1c883d82021-12-01 18:43:10 +0000445 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser),
446 deviceType);
Alex Chau238aaee2021-10-06 16:15:24 +0100447 if (gridOption.isEnabled || allowDisabledGrid) {
Thales Lima7ec83822021-08-05 13:32:10 +0100448 final int displayDepth = parser.getDepth();
449 while (((type = parser.next()) != XmlPullParser.END_TAG
450 || parser.getDepth() > displayDepth)
451 && type != XmlPullParser.END_DOCUMENT) {
452 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
453 parser.getName())) {
454 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100455 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100456 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800457 }
458 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700459 }
460 }
sfufa@google.comde013292021-09-21 18:22:44 -0700461 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700462 throw new RuntimeException(e);
463 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800464
Sunny Goyalae190ff2020-04-14 00:19:01 +0000465 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800466 if (!TextUtils.isEmpty(gridName)) {
467 for (DisplayOption option : profiles) {
Alex Chau238aaee2021-10-06 16:15:24 +0100468 if (gridName.equals(option.grid.name)
469 && (option.grid.isEnabled || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000470 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800471 }
472 }
473 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000474 if (filteredProfiles.isEmpty()) {
475 // No grid found, use the default options
476 for (DisplayOption option : profiles) {
477 if (option.canBeDefault) {
478 filteredProfiles.add(option);
479 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800480 }
481 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000482 if (filteredProfiles.isEmpty()) {
483 throw new RuntimeException("No display option with canBeDefault=true");
484 }
485 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700486 }
487
Thales Lima7ec83822021-08-05 13:32:10 +0100488 /**
489 * @return all the grid options that can be shown on the device
490 */
491 public List<GridOption> parseAllGridOptions(Context context) {
492 List<GridOption> result = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100493
Alex Chau1c883d82021-12-01 18:43:10 +0000494 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100495 final int depth = parser.getDepth();
496 int type;
497 while (((type = parser.next()) != XmlPullParser.END_TAG
498 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
499 if ((type == XmlPullParser.START_TAG)
500 && GridOption.TAG_NAME.equals(parser.getName())) {
501 GridOption option =
Alex Chau1c883d82021-12-01 18:43:10 +0000502 new GridOption(context, Xml.asAttributeSet(parser), deviceType);
Thales Lima7ec83822021-08-05 13:32:10 +0100503 if (option.isEnabled) {
504 result.add(option);
505 }
506 }
507 }
508 } catch (IOException | XmlPullParserException e) {
509 Log.e(TAG, "Error parsing device profile", e);
510 return Collections.emptyList();
511 }
512 return result;
513 }
514
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700515 private int getLauncherIconDensity(int requiredSize) {
516 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700517 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700518 DisplayMetrics.DENSITY_LOW,
519 DisplayMetrics.DENSITY_MEDIUM,
520 DisplayMetrics.DENSITY_TV,
521 DisplayMetrics.DENSITY_HIGH,
522 DisplayMetrics.DENSITY_XHIGH,
523 DisplayMetrics.DENSITY_XXHIGH,
524 DisplayMetrics.DENSITY_XXXHIGH
525 };
526
527 int density = DisplayMetrics.DENSITY_XXXHIGH;
528 for (int i = densityBuckets.length - 1; i >= 0; i--) {
529 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
530 / DisplayMetrics.DENSITY_DEFAULT;
531 if (expectedSize >= requiredSize) {
532 density = densityBuckets[i];
533 }
534 }
535
536 return density;
537 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700538
Adam Cohen2e6da152015-05-06 11:42:25 -0700539 /**
540 * Apply any Partner customization grid overrides.
541 *
542 * Currently we support: all apps row / column count.
543 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700544 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
545 Partner p = Partner.get(context.getPackageManager());
Adam Cohen2e6da152015-05-06 11:42:25 -0700546 if (p != null) {
547 p.applyInvariantDeviceProfileOverrides(this, dm);
548 }
549 }
550
Sunny Goyal415f1732018-11-29 10:33:47 -0800551 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700552 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700553 }
554
Sunny Goyal19ff7282021-04-22 10:12:54 -0700555 private static DisplayOption invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000556 Info displayInfo, ArrayList<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700557 int minWidthPx = Integer.MAX_VALUE;
558 int minHeightPx = Integer.MAX_VALUE;
559 for (WindowBounds bounds : displayInfo.supportedBounds) {
560 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000561 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700562 // For split displays, take half width per page
563 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
564 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700565
Sunny Goyal19ff7282021-04-22 10:12:54 -0700566 } else if (!isTablet && bounds.isLandscape()) {
567 // We will use transposed layout in this case
568 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
569 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
570 } else {
571 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
572 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
573 }
574 }
575
576 float width = dpiFromPx(minWidthPx, displayInfo.densityDpi);
577 float height = dpiFromPx(minHeightPx, displayInfo.densityDpi);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700578
579 // Sort the profiles based on the closeness to the device size
580 Collections.sort(points, (a, b) ->
581 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
582 dist(width, height, b.minWidthDps, b.minHeightDps)));
583
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700584 DisplayOption closestPoint = points.get(0);
585 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700586 float weights = 0;
587
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700588 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
589 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700590 }
591
592 DisplayOption out = new DisplayOption(closestOption);
593 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700594 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700595 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
596 weights += w;
597 out.add(new DisplayOption().add(p).multiply(w));
598 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700599 out.multiply(1.0f / weights);
600
Thales Lima6e0005a2021-10-27 15:53:41 +0100601 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700602 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100603 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
604 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700605 }
606
607 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700608 }
609
Sunny Goyal27835952017-01-13 12:15:53 -0800610 public DeviceProfile getDeviceProfile(Context context) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700611 Resources res = context.getResources();
612 Configuration config = context.getResources().getConfiguration();
613
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400614 float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density;
615 float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density;
616 return getBestMatch(screenWidth, screenHeight);
617 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700618
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400619 public DeviceProfile getBestMatch(float screenWidth, float screenHeight) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700620 DeviceProfile bestMatch = supportedProfiles.get(0);
621 float minDiff = Float.MAX_VALUE;
622
623 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400624 float diff = Math.abs(profile.widthPx - screenWidth)
625 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700626 if (diff < minDiff) {
627 minDiff = diff;
628 bestMatch = profile;
629 }
630 }
631 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800632 }
633
Sunny Goyal415f1732018-11-29 10:33:47 -0800634 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700635 float d = dist(x0, y0, x1, y1);
636 if (Float.compare(d, 0f) == 0) {
637 return Float.POSITIVE_INFINITY;
638 }
639 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
640 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700641
642 /**
643 * As a ratio of screen height, the total distance we want the parallax effect to span
644 * horizontally
645 */
646 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
647 float aspectRatio = width / (float) height;
648
649 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
650 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
651 // We will use these two data points to extrapolate how much the wallpaper parallax effect
652 // to span (ie travel) at any aspect ratio:
653
sfufa@google.comde013292021-09-21 18:22:44 -0700654 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
655 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700656 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
657 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
658
659 // To find out the desired width at different aspect ratios, we use the following two
660 // formulas, where the coefficient on x is the aspect ratio (width/height):
661 // (16/10)x + y = 1.5
662 // (10/16)x + y = 1.2
663 // We solve for x and y and end up with a final formula:
664 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700665 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
666 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700667 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
668 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
669 return x * aspectRatio + y;
670 }
671
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700672 public interface OnIDPChangeListener {
673
Sunny Goyalb47172b2021-05-03 19:59:51 -0700674 /**
675 * Called when the device provide changes
676 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700677 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700678 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800679
680
Sunny Goyaleff44f32019-01-09 17:29:49 -0800681 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800682
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800683 public static final String TAG_NAME = "grid-option";
684
Alex Chau1c883d82021-12-01 18:43:10 +0000685 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
686 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
687 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
688 private static final int DEVICE_CATEGORY_ALL =
689 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
690
Sunny Goyaleff44f32019-01-09 17:29:49 -0800691 public final String name;
692 public final int numRows;
693 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000694 public final int numSearchContainerColumns;
Thales Lima7ec83822021-08-05 13:32:10 +0100695 public final boolean isEnabled;
Sunny Goyal415f1732018-11-29 10:33:47 -0800696
697 private final int numFolderRows;
698 private final int numFolderColumns;
699
Sunny Goyal19ff7282021-04-22 10:12:54 -0700700 private final int numAllAppsColumns;
701 private final int numDatabaseAllAppsColumns;
702 private final int numHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000703 private final int numShrunkenHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700704 private final int numDatabaseHotseatIcons;
Sunny Goyal415f1732018-11-29 10:33:47 -0800705
Tracy Zhou7df93d22020-01-27 13:44:06 -0800706 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000707
Sunny Goyal415f1732018-11-29 10:33:47 -0800708 private final int defaultLayoutId;
709 private final int demoModeLayoutId;
710
Jon Mirandae126d722021-02-25 10:45:20 -0500711 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400712 private final int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500713
Sunny Goyal5bc18462019-01-07 15:13:39 -0800714 private final SparseArray<TypedValue> extraAttrs;
715
Alex Chau1c883d82021-12-01 18:43:10 +0000716 public GridOption(Context context, AttributeSet attrs, @DeviceType int deviceType) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800717 TypedArray a = context.obtainStyledAttributes(
718 attrs, R.styleable.GridDisplayOption);
719 name = a.getString(R.styleable.GridDisplayOption_name);
720 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
721 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000722 numSearchContainerColumns = a.getInt(
723 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal415f1732018-11-29 10:33:47 -0800724
Tracy Zhou7df93d22020-01-27 13:44:06 -0800725 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Alex Chau1c883d82021-12-01 18:43:10 +0000726 defaultLayoutId = a.getResourceId(deviceType == TYPE_MULTI_DISPLAY && a.hasValue(
Alex Chau1e448462021-08-13 21:48:35 +0100727 R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId)
728 ? R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId
729 : R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800730 demoModeLayoutId = a.getResourceId(
731 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700732
733 numAllAppsColumns = a.getInt(
734 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
735 numDatabaseAllAppsColumns = a.getInt(
736 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
737
738 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800739 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Alex Chau6ed408f2022-03-04 12:58:05 +0000740 numShrunkenHotseatIcons = a.getInt(
741 R.styleable.GridDisplayOption_numShrunkenHotseatIcons, numHotseatIcons / 2);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700742 numDatabaseHotseatIcons = a.getInt(
743 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
744
Sunny Goyal415f1732018-11-29 10:33:47 -0800745 numFolderRows = a.getInt(
746 R.styleable.GridDisplayOption_numFolderRows, numRows);
747 numFolderColumns = a.getInt(
748 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700749
Jon Mirandae126d722021-02-25 10:45:20 -0500750 isScalable = a.getBoolean(
751 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400752 devicePaddingId = a.getResourceId(
753 R.styleable.GridDisplayOption_devicePaddingId, 0);
Jon Mirandae126d722021-02-25 10:45:20 -0500754
Alex Chau1c883d82021-12-01 18:43:10 +0000755 int deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
756 DEVICE_CATEGORY_ALL);
757 isEnabled = (deviceType == TYPE_PHONE
758 && ((deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE))
759 || (deviceType == TYPE_TABLET
760 && ((deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET))
761 || (deviceType == TYPE_MULTI_DISPLAY
762 && ((deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
763 == DEVICE_CATEGORY_MULTI_DISPLAY));
Thales Lima7ec83822021-08-05 13:32:10 +0100764
Sunny Goyal415f1732018-11-29 10:33:47 -0800765 a.recycle();
Sunny Goyal5bc18462019-01-07 15:13:39 -0800766 extraAttrs = Themes.createValueMap(context, attrs,
767 IntArray.wrap(R.styleable.GridDisplayOption));
Sunny Goyal415f1732018-11-29 10:33:47 -0800768 }
769 }
770
Sunny Goyal19ff7282021-04-22 10:12:54 -0700771 @VisibleForTesting
772 static final class DisplayOption {
773
774 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800775
Sunny Goyal415f1732018-11-29 10:33:47 -0800776 private final float minWidthDps;
777 private final float minHeightDps;
778 private final boolean canBeDefault;
779
Thales Lima83bedbf2021-10-05 17:47:39 +0100780 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +0100781
782 private float folderBorderSpace;
783 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +0100784 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Lima6e7f36c2022-01-04 12:14:11 +0000785 private final float[] hotseatBorderSpaces = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +0100786
Thales Lima78d00ad2021-09-30 11:29:06 +0100787 private final float[] iconSizes = new float[COUNT_SIZES];
788 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800789
Thales Limabb7d3882021-12-22 12:56:29 +0000790 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
791 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
792 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
793
Thales Lima1de4d552021-10-13 16:13:25 +0100794 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800795 this.grid = grid;
796
Thales Lima1de4d552021-10-13 16:13:25 +0100797 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -0800798
Sunny Goyal415f1732018-11-29 10:33:47 -0800799 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
800 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700801
Thales Lima1de4d552021-10-13 16:13:25 +0100802 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -0800803
Thales Lima83bedbf2021-10-05 17:47:39 +0100804 float x;
805 float y;
806
Thales Lima85c942f2021-12-31 13:04:20 +0000807 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
808 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +0100809 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +0000810
811 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
812 minCellSize[INDEX_DEFAULT].x);
813 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
814 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100815 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100816
Thales Lima85c942f2021-12-31 13:04:20 +0000817 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100818 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +0000819 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100820 minCellSize[INDEX_DEFAULT].y);
821 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
822
Thales Lima85c942f2021-12-31 13:04:20 +0000823 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100824 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +0000825 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100826 minCellSize[INDEX_DEFAULT].y);
827 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +0100828
Thales Lima85c942f2021-12-31 13:04:20 +0000829 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
830 float borderSpaceTwoPanelPortrait = a.getFloat(
831 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
832 float borderSpaceTwoPanelLandscape = a.getFloat(
833 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +0100834
Thales Lima85c942f2021-12-31 13:04:20 +0000835 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
836 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +0100837 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
838 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
839
840 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000841 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
842 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +0100843 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000844 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
845 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +0100846 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
847
848 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000849 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
850 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100851 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000852 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
853 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100854 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
855
Thales Limabb7d3882021-12-22 12:56:29 +0000856 folderBorderSpace = borderSpace;
857
Thales Lima85c942f2021-12-31 13:04:20 +0000858 x = y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpace,
Thales Lima78d00ad2021-09-30 11:29:06 +0100859 borderSpace);
Thales Limabb7d3882021-12-22 12:56:29 +0000860 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
861 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
862 x = y = a.getFloat(
863 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
864 allAppsBorderSpaces[INDEX_DEFAULT].x);
865 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
866 x = y = a.getFloat(
867 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
868 allAppsBorderSpaces[INDEX_DEFAULT].x);
869 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -0500870
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700871 iconSizes[INDEX_DEFAULT] =
872 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
873 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +0000874 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700875 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700876 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +0000877 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700878 iconSizes[INDEX_DEFAULT]);
879 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +0000880 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100881 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700882
Thales Limabb7d3882021-12-22 12:56:29 +0000883 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
884 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
885 allAppsIconSizes[INDEX_LANDSCAPE] = allAppsIconSizes[INDEX_DEFAULT];
886 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
887 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
888 allAppsIconSizes[INDEX_DEFAULT]);
889 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
890 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
891 allAppsIconSizes[INDEX_DEFAULT]);
892
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700893 textSizes[INDEX_DEFAULT] =
894 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
895 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +0000896 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700897 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700898 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +0000899 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700900 textSizes[INDEX_DEFAULT]);
901 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +0000902 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100903 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700904
Thales Limabb7d3882021-12-22 12:56:29 +0000905 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
906 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
907 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
908 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
909 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
910 allAppsIconTextSizes[INDEX_DEFAULT]);
911 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
912 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
913 allAppsIconTextSizes[INDEX_DEFAULT]);
914
Thales Lima83bedbf2021-10-05 17:47:39 +0100915 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
916 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +0000917 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
918 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
919 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +0100920 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000921 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100922 horizontalMargin[INDEX_DEFAULT]);
923 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000924 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100925 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +0100926
Thales Lima6e7f36c2022-01-04 12:14:11 +0000927 hotseatBorderSpaces[INDEX_DEFAULT] = a.getFloat(
928 R.styleable.ProfileDisplayOption_hotseatBorderSpace, borderSpace);
Thales Limadd027342022-01-07 12:54:37 +0000929 hotseatBorderSpaces[INDEX_LANDSCAPE] = a.getFloat(
930 R.styleable.ProfileDisplayOption_hotseatBorderSpaceLandscape,
931 hotseatBorderSpaces[INDEX_DEFAULT]);
Thales Lima6e7f36c2022-01-04 12:14:11 +0000932 hotseatBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
933 R.styleable.ProfileDisplayOption_hotseatBorderSpaceTwoPanelLandscape,
934 hotseatBorderSpaces[INDEX_DEFAULT]);
935 hotseatBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
936 R.styleable.ProfileDisplayOption_hotseatBorderSpaceTwoPanelPortrait,
937 hotseatBorderSpaces[INDEX_DEFAULT]);
938
Sunny Goyal415f1732018-11-29 10:33:47 -0800939 a.recycle();
940 }
941
942 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700943 this(null);
944 }
945
946 DisplayOption(GridOption grid) {
947 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800948 minWidthDps = 0;
949 minHeightDps = 0;
950 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +0100951 for (int i = 0; i < COUNT_SIZES; i++) {
952 iconSizes[i] = 0;
953 textSizes[i] = 0;
954 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +0100955 minCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +0000956 allAppsIconSizes[i] = 0;
957 allAppsIconTextSizes[i] = 0;
958 allAppsBorderSpaces[i] = new PointF();
Thales Lima78d00ad2021-09-30 11:29:06 +0100959 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800960 }
961
962 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100963 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700964 iconSizes[i] *= w;
965 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +0100966 borderSpaces[i].x *= w;
967 borderSpaces[i].y *= w;
968 minCellSize[i].x *= w;
969 minCellSize[i].y *= w;
970 horizontalMargin[i] *= w;
Thales Lima6e7f36c2022-01-04 12:14:11 +0000971 hotseatBorderSpaces[i] *= w;
Thales Limabb7d3882021-12-22 12:56:29 +0000972 allAppsIconSizes[i] *= w;
973 allAppsIconTextSizes[i] *= w;
974 allAppsBorderSpaces[i].x *= w;
975 allAppsBorderSpaces[i].y *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700976 }
Thales Lima78d00ad2021-09-30 11:29:06 +0100977
978 folderBorderSpace *= w;
979
Sunny Goyal415f1732018-11-29 10:33:47 -0800980 return this;
981 }
982
983 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +0100984 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700985 iconSizes[i] += p.iconSizes[i];
986 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +0100987 borderSpaces[i].x += p.borderSpaces[i].x;
988 borderSpaces[i].y += p.borderSpaces[i].y;
989 minCellSize[i].x += p.minCellSize[i].x;
990 minCellSize[i].y += p.minCellSize[i].y;
991 horizontalMargin[i] += p.horizontalMargin[i];
Thales Lima6e7f36c2022-01-04 12:14:11 +0000992 hotseatBorderSpaces[i] += p.hotseatBorderSpaces[i];
Thales Limabb7d3882021-12-22 12:56:29 +0000993 allAppsIconSizes[i] += p.allAppsIconSizes[i];
994 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
995 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
996 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700997 }
Thales Lima78d00ad2021-09-30 11:29:06 +0100998
999 folderBorderSpace += p.folderBorderSpace;
1000
Sunny Goyal415f1732018-11-29 10:33:47 -08001001 return this;
1002 }
1003 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001004}