blob: a2bd201fd872404aaaff2d6ca2a99dc4fb78cce0 [file] [log] [blame]
Adam Cohen2e6da152015-05-06 11:42:25 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.launcher3;
18
Sunny Goyal19ff7282021-04-22 10:12:54 -070019import static com.android.launcher3.Utilities.dpiFromPx;
Tracy Zhoued5f3082020-04-20 01:13:26 -070020import static com.android.launcher3.Utilities.getPointString;
Andras Kloczl8e57cce2021-02-11 23:51:19 +010021import static com.android.launcher3.config.FeatureFlags.ENABLE_TWO_PANEL_HOME;
Sunny Goyal35c7b192021-04-20 16:51:10 -070022import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY;
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;
Sunny Goyal58fa4b62019-03-22 16:23:25 -070035import android.graphics.Rect;
Sunny Goyal415f1732018-11-29 10:33:47 -080036import android.text.TextUtils;
37import android.util.AttributeSet;
Adam Cohen2e6da152015-05-06 11:42:25 -070038import android.util.DisplayMetrics;
Sunny Goyal5bc18462019-01-07 15:13:39 -080039import android.util.SparseArray;
40import android.util.TypedValue;
Sunny Goyal819e1932016-07-07 16:43:58 -070041import android.util.Xml;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080042import android.view.Display;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070043
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070044import androidx.annotation.Nullable;
45import androidx.annotation.VisibleForTesting;
46
Sunny Goyalfd58da62020-08-11 12:06:49 -070047import com.android.launcher3.util.DisplayController;
48import com.android.launcher3.util.DisplayController.Info;
Sunny Goyal5bc18462019-01-07 15:13:39 -080049import com.android.launcher3.util.IntArray;
Sunny Goyald0e360a2018-06-29 14:40:18 -070050import com.android.launcher3.util.MainThreadInitializedObject;
Sunny Goyal5bc18462019-01-07 15:13:39 -080051import com.android.launcher3.util.Themes;
Sunny Goyal19ff7282021-04-22 10:12:54 -070052import com.android.launcher3.util.WindowBounds;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070053
Sunny Goyal819e1932016-07-07 16:43:58 -070054import org.xmlpull.v1.XmlPullParser;
55import org.xmlpull.v1.XmlPullParserException;
56
57import java.io.IOException;
Adam Cohen2e6da152015-05-06 11:42:25 -070058import java.util.ArrayList;
Sunny Goyal6d55f662019-01-02 12:13:43 -080059import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070060import java.util.List;
Adam Cohen2e6da152015-05-06 11:42:25 -070061
62public class InvariantDeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070063
Hyunyoung Songc55a3502018-12-04 15:43:16 -080064 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070065 // We do not need any synchronization for this variable as its only written on UI thread.
66 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070067 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070068
Tracy Zhoued5f3082020-04-20 01:13:26 -070069 public static final String KEY_MIGRATION_SRC_WORKSPACE_SIZE = "migration_src_workspace_size";
70 public static final String KEY_MIGRATION_SRC_HOTSEAT_COUNT = "migration_src_hotseat_count";
71
Sunny Goyal19ff7282021-04-22 10:12:54 -070072 private static final int DEFAULT_TRUE = -1;
73 private static final int DEFAULT_SPLIT_DISPLAY = 2;
74
Hyunyoung Songc55a3502018-12-04 15:43:16 -080075 private static final String KEY_IDP_GRID_NAME = "idp_grid_name";
Sunny Goyal415f1732018-11-29 10:33:47 -080076
Sunny Goyal53d7ee42015-05-22 12:25:45 -070077 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
78
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070079 // Constants that affects the interpolation curve between statically defined device profile
80 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080081 private static final float KNEARESTNEIGHBOR = 3;
82 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -070083
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070084 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080085 private static final float WEIGHT_EFFICIENT = 100000f;
86
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070087 /**
88 * Number of icons per row and column in the workspace.
89 */
Adam Cohen2e6da152015-05-06 11:42:25 -070090 public int numRows;
91 public int numColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070092
93 /**
94 * Number of icons per row and column in the folder.
95 */
Adam Cohen2e6da152015-05-06 11:42:25 -070096 public int numFolderRows;
97 public int numFolderColumns;
Sunny Goyalfc218302015-09-17 14:59:10 -070098 public float iconSize;
Jon Mirandab28c4fc2017-06-20 10:58:36 -070099 public float landscapeIconSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200100 public float landscapeIconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700101 public int iconBitmapSize;
102 public int fillResIconDpi;
103 public float iconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000104 public float allAppsIconSize;
105 public float allAppsIconTextSize;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700106
Jon Mirandae126d722021-02-25 10:45:20 -0500107 public float minCellHeight;
108 public float minCellWidth;
109 public float borderSpacing;
110
Sunny Goyal5bc18462019-01-07 15:13:39 -0800111 private SparseArray<TypedValue> mExtraAttrs;
112
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700113 /**
114 * Number of icons inside the hotseat area.
115 */
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700116 protected int numShownHotseatIcons;
117
118 /**
119 * Number of icons inside the hotseat area that is stored in the database. This is greater than
120 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
121 * sizes that share the same DB.
122 */
123 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700124
Jon Miranda6f7e9702019-09-16 14:44:14 -0700125 /**
126 * Number of columns in the all apps list.
127 */
128 public int numAllAppsColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700129 public int numDatabaseAllAppsColumns;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700130
Jon Mirandae126d722021-02-25 10:45:20 -0500131 /**
132 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
133 */
134 protected boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400135 public int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500136
Tracy Zhou7df93d22020-01-27 13:44:06 -0800137 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800138 public int defaultLayoutId;
Adam Cohen27824492017-09-22 17:10:55 -0700139 int demoModeLayoutId;
Adam Cohen2e6da152015-05-06 11:42:25 -0700140
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000141 /**
142 * An immutable list of supported profiles.
143 */
144 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700145
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400146 @Nullable public DevicePaddings devicePaddings;
Jon Miranda228877d2021-02-09 11:05:00 -0500147
Sunny Goyal6f866092016-03-17 17:04:15 -0700148 public Point defaultWallpaperSize;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700149 public Rect defaultWidgetPadding;
Sunny Goyal6f866092016-03-17 17:04:15 -0700150
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700151 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700152
Sunny Goyalf633ef52018-03-13 09:57:05 -0700153 @VisibleForTesting
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700154 public InvariantDeviceProfile() {}
Adam Cohen2e6da152015-05-06 11:42:25 -0700155
Sunny Goyalf633ef52018-03-13 09:57:05 -0700156 private InvariantDeviceProfile(InvariantDeviceProfile p) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800157 numRows = p.numRows;
158 numColumns = p.numColumns;
159 numFolderRows = p.numFolderRows;
160 numFolderColumns = p.numFolderColumns;
161 iconSize = p.iconSize;
162 landscapeIconSize = p.landscapeIconSize;
Tony Wickham9459f312020-06-15 13:30:20 -0500163 iconBitmapSize = p.iconBitmapSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800164 iconTextSize = p.iconTextSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200165 landscapeIconTextSize = p.landscapeIconTextSize;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700166 numShownHotseatIcons = p.numShownHotseatIcons;
167 numDatabaseHotseatIcons = p.numDatabaseHotseatIcons;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700168 numAllAppsColumns = p.numAllAppsColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700169 numDatabaseAllAppsColumns = p.numDatabaseAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500170 isScalable = p.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400171 devicePaddingId = p.devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500172 minCellHeight = p.minCellHeight;
173 minCellWidth = p.minCellWidth;
174 borderSpacing = p.borderSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800175 dbFile = p.dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000176 allAppsIconSize = p.allAppsIconSize;
177 allAppsIconTextSize = p.allAppsIconTextSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800178 defaultLayoutId = p.defaultLayoutId;
179 demoModeLayoutId = p.demoModeLayoutId;
Sunny Goyal5bc18462019-01-07 15:13:39 -0800180 mExtraAttrs = p.mExtraAttrs;
Jon Miranda228877d2021-02-09 11:05:00 -0500181 devicePaddings = p.devicePaddings;
Adam Cohen2e6da152015-05-06 11:42:25 -0700182 }
183
Sunny Goyalbbf01842015-10-08 07:41:15 -0700184 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700185 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700186 String gridName = getCurrentGridName(context);
187 String newGridName = initGrid(context, gridName);
188 if (!newGridName.equals(gridName)) {
189 Utilities.getPrefs(context).edit().putString(KEY_IDP_GRID_NAME, newGridName).apply();
190 }
Tracy Zhoued5f3082020-04-20 01:13:26 -0700191 Utilities.getPrefs(context).edit()
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700192 .putInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, numDatabaseHotseatIcons)
Tracy Zhoued5f3082020-04-20 01:13:26 -0700193 .putString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, getPointString(numColumns, numRows))
194 .apply();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700195
Sunny Goyal35c7b192021-04-20 16:51:10 -0700196 DisplayController.INSTANCE.get(context).addChangeListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100197 (displayContext, info, flags) -> {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700198 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS)) != 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
223 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Sunny Goyal35c7b192021-04-20 16:51:10 -0700224 DisplayController.INSTANCE.get(context).getInfo(),
Sunny Goyal19ff7282021-04-22 10:12:54 -0700225 getPredefinedDeviceProfiles(context, gridName, false), false);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700226
Alex Chau417bd722021-01-26 15:22:18 +0000227 Info myInfo = new Info(context, display);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700228 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Sunny Goyal19ff7282021-04-22 10:12:54 -0700229 myInfo, getPredefinedDeviceProfiles(context, gridName, false), false);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700230
231 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
232 .add(myDisplayOption);
233 result.iconSize = defaultDisplayOption.iconSize;
234 result.landscapeIconSize = defaultDisplayOption.landscapeIconSize;
Alex Chau7c439722021-03-24 11:32:44 +0000235 if (defaultDisplayOption.allAppsIconSize < myDisplayOption.allAppsIconSize) {
236 result.allAppsIconSize = defaultDisplayOption.allAppsIconSize;
Alex Chau7c439722021-03-24 11:32:44 +0000237 } else {
238 result.allAppsIconSize = myDisplayOption.allAppsIconSize;
Alex Chau7c439722021-03-24 11:32:44 +0000239 }
Jon Mirandae126d722021-02-25 10:45:20 -0500240 result.minCellHeight = defaultDisplayOption.minCellHeight;
241 result.minCellWidth = defaultDisplayOption.minCellWidth;
242 result.borderSpacing = defaultDisplayOption.borderSpacing;
Jon Miranda228877d2021-02-09 11:05:00 -0500243
Sunny Goyal19ff7282021-04-22 10:12:54 -0700244 initGrid(context, myInfo, result, false);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800245 }
246
Tracy Zhou42255d22020-03-13 00:38:11 -0700247 public static String getCurrentGridName(Context context) {
Tracy Zhouc6060e62020-04-27 13:05:34 -0700248 return Utilities.isGridOptionsEnabled(context)
249 ? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null;
Tracy Zhou42255d22020-03-13 00:38:11 -0700250 }
251
Sunny Goyaleff44f32019-01-09 17:29:49 -0800252 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700253 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Pat Manning67094bf2021-05-26 12:38:13 +0000254 // Each screen has two profiles (portrait/landscape), so devices with four or more
255 // supported profiles implies two or more internal displays.
256 boolean isSplitDisplay =
257 displayInfo.supportedBounds.size() >= 4 && ENABLE_TWO_PANEL_HOME.get();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700258
259 ArrayList<DisplayOption> allOptions =
260 getPredefinedDeviceProfiles(context, gridName, isSplitDisplay);
261 DisplayOption displayOption =
262 invDistWeightedInterpolate(displayInfo, allOptions, isSplitDisplay);
263 initGrid(context, displayInfo, displayOption, isSplitDisplay);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700264 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800265 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700266
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700267 private void initGrid(
Sunny Goyal19ff7282021-04-22 10:12:54 -0700268 Context context, Info displayInfo, DisplayOption displayOption,
269 boolean isSplitDisplay) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700270 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700271 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000272 numRows = closestProfile.numRows;
273 numColumns = closestProfile.numColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000274 dbFile = closestProfile.dbFile;
275 defaultLayoutId = closestProfile.defaultLayoutId;
276 demoModeLayoutId = closestProfile.demoModeLayoutId;
277 numFolderRows = closestProfile.numFolderRows;
278 numFolderColumns = closestProfile.numFolderColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500279 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400280 devicePaddingId = closestProfile.devicePaddingId;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000281
282 mExtraAttrs = closestProfile.extraAttrs;
283
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700284 iconSize = displayOption.iconSize;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700285 landscapeIconSize = displayOption.landscapeIconSize;
Sunny Goyal35c7b192021-04-20 16:51:10 -0700286 iconBitmapSize = ResourceUtils.pxFromDp(iconSize, metrics);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700287 iconTextSize = displayOption.iconTextSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200288 landscapeIconTextSize = displayOption.landscapeIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000289 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
290
Jon Mirandae126d722021-02-25 10:45:20 -0500291 minCellHeight = displayOption.minCellHeight;
292 minCellWidth = displayOption.minCellWidth;
293 borderSpacing = displayOption.borderSpacing;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700294
295 numShownHotseatIcons = closestProfile.numHotseatIcons;
296 numDatabaseHotseatIcons = isSplitDisplay
297 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
298
299 numAllAppsColumns = closestProfile.numAllAppsColumns;
300 numDatabaseAllAppsColumns = isSplitDisplay
301 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500302
Tracy Zhouc6060e62020-04-27 13:05:34 -0700303 if (Utilities.isGridOptionsEnabled(context)) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700304 allAppsIconSize = displayOption.allAppsIconSize;
305 allAppsIconTextSize = displayOption.allAppsIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000306 } else {
307 allAppsIconSize = iconSize;
308 allAppsIconTextSize = iconTextSize;
309 }
310
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400311 if (devicePaddingId != 0) {
312 devicePaddings = new DevicePaddings(context, devicePaddingId);
313 }
314
Sunny Goyalae190ff2020-04-14 00:19:01 +0000315 // If the partner customization apk contains any grid overrides, apply them
316 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700317 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700318
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000319 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700320 defaultWallpaperSize = new Point(displayInfo.currentSize);
321 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000322 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Sunny Goyal19ff7282021-04-22 10:12:54 -0700323 .setUseTwoPanels(isSplitDisplay)
324 .setWindowBounds(bounds).build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700325
Sunny Goyal19ff7282021-04-22 10:12:54 -0700326 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
327 int displayWidth = bounds.bounds.width();
328 int displayHeight = bounds.bounds.height();
329 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700330
Sunny Goyal19ff7282021-04-22 10:12:54 -0700331 // We need to ensure that there is enough extra space in the wallpaper
332 // for the intended parallax effects
333 float parallaxFactor =
334 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.densityDpi) < 720
335 ? 2
336 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
337 defaultWallpaperSize.x =
338 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700339 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000340 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700341
342 ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName());
343 defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
Adam Cohen2e6da152015-05-06 11:42:25 -0700344 }
345
Sunny Goyal5bc18462019-01-07 15:13:39 -0800346 @Nullable
347 public TypedValue getAttrValue(int attr) {
348 return mExtraAttrs == null ? null : mExtraAttrs.get(attr);
349 }
350
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700351 public void addOnChangeListener(OnIDPChangeListener listener) {
352 mChangeListeners.add(listener);
353 }
354
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800355 public void removeOnChangeListener(OnIDPChangeListener listener) {
356 mChangeListeners.remove(listener);
357 }
358
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800359
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800360 public void setCurrentGrid(Context context, String gridName) {
361 Context appContext = context.getApplicationContext();
362 Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply();
Sunny Goyal6fe3eec2019-08-15 14:53:41 -0700363 MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800364 }
365
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700366 private void onConfigChanged(Context context) {
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700367 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700368 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700369 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700370
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700371 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyalb47172b2021-05-03 19:59:51 -0700372 listener.onIdpChanged(this);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700373 }
374 }
375
Sunny Goyal19ff7282021-04-22 10:12:54 -0700376 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(
377 Context context, String gridName, boolean isSplitDisplay) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800378 ArrayList<DisplayOption> profiles = new ArrayList<>();
Sunny Goyal819e1932016-07-07 16:43:58 -0700379 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
380 final int depth = parser.getDepth();
381 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700382 while (((type = parser.next()) != XmlPullParser.END_TAG ||
383 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800384 if ((type == XmlPullParser.START_TAG)
385 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800386
387 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
388 final int displayDepth = parser.getDepth();
389 while (((type = parser.next()) != XmlPullParser.END_TAG ||
390 parser.getDepth() > displayDepth)
391 && type != XmlPullParser.END_DOCUMENT) {
392 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
393 parser.getName())) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700394 profiles.add(new DisplayOption(gridOption, context,
395 Xml.asAttributeSet(parser),
396 isSplitDisplay ? DEFAULT_SPLIT_DISPLAY : DEFAULT_TRUE));
Sunny Goyal415f1732018-11-29 10:33:47 -0800397 }
398 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700399 }
400 }
401 } catch (IOException|XmlPullParserException e) {
402 throw new RuntimeException(e);
403 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800404
Sunny Goyalae190ff2020-04-14 00:19:01 +0000405 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800406 if (!TextUtils.isEmpty(gridName)) {
407 for (DisplayOption option : profiles) {
408 if (gridName.equals(option.grid.name)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000409 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800410 }
411 }
412 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000413 if (filteredProfiles.isEmpty()) {
414 // No grid found, use the default options
415 for (DisplayOption option : profiles) {
416 if (option.canBeDefault) {
417 filteredProfiles.add(option);
418 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800419 }
420 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000421 if (filteredProfiles.isEmpty()) {
422 throw new RuntimeException("No display option with canBeDefault=true");
423 }
424 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700425 }
426
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700427 private int getLauncherIconDensity(int requiredSize) {
428 // Densities typically defined by an app.
429 int[] densityBuckets = new int[] {
430 DisplayMetrics.DENSITY_LOW,
431 DisplayMetrics.DENSITY_MEDIUM,
432 DisplayMetrics.DENSITY_TV,
433 DisplayMetrics.DENSITY_HIGH,
434 DisplayMetrics.DENSITY_XHIGH,
435 DisplayMetrics.DENSITY_XXHIGH,
436 DisplayMetrics.DENSITY_XXXHIGH
437 };
438
439 int density = DisplayMetrics.DENSITY_XXXHIGH;
440 for (int i = densityBuckets.length - 1; i >= 0; i--) {
441 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
442 / DisplayMetrics.DENSITY_DEFAULT;
443 if (expectedSize >= requiredSize) {
444 density = densityBuckets[i];
445 }
446 }
447
448 return density;
449 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700450
Adam Cohen2e6da152015-05-06 11:42:25 -0700451 /**
452 * Apply any Partner customization grid overrides.
453 *
454 * Currently we support: all apps row / column count.
455 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700456 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
457 Partner p = Partner.get(context.getPackageManager());
Adam Cohen2e6da152015-05-06 11:42:25 -0700458 if (p != null) {
459 p.applyInvariantDeviceProfileOverrides(this, dm);
460 }
461 }
462
Sunny Goyal415f1732018-11-29 10:33:47 -0800463 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700464 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700465 }
466
Sunny Goyal19ff7282021-04-22 10:12:54 -0700467 private static DisplayOption invDistWeightedInterpolate(
468 Info displayInfo, ArrayList<DisplayOption> points, boolean isSplitDisplay) {
469 int minWidthPx = Integer.MAX_VALUE;
470 int minHeightPx = Integer.MAX_VALUE;
471 for (WindowBounds bounds : displayInfo.supportedBounds) {
472 boolean isTablet = displayInfo.isTablet(bounds);
473 if (isTablet && isSplitDisplay) {
474 // For split displays, take half width per page
475 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
476 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700477
Sunny Goyal19ff7282021-04-22 10:12:54 -0700478 } else if (!isTablet && bounds.isLandscape()) {
479 // We will use transposed layout in this case
480 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
481 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
482 } else {
483 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
484 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
485 }
486 }
487
488 float width = dpiFromPx(minWidthPx, displayInfo.densityDpi);
489 float height = dpiFromPx(minHeightPx, displayInfo.densityDpi);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700490
491 // Sort the profiles based on the closeness to the device size
492 Collections.sort(points, (a, b) ->
493 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
494 dist(width, height, b.minWidthDps, b.minHeightDps)));
495
496 GridOption closestOption = points.get(0).grid;
497 float weights = 0;
498
499 DisplayOption p = points.get(0);
500 if (dist(width, height, p.minWidthDps, p.minHeightDps) == 0) {
501 return p;
502 }
503
504 DisplayOption out = new DisplayOption(closestOption);
505 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
506 p = points.get(i);
507 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
508 weights += w;
509 out.add(new DisplayOption().add(p).multiply(w));
510 }
511 return out.multiply(1.0f / weights);
512 }
513
Sunny Goyal27835952017-01-13 12:15:53 -0800514 public DeviceProfile getDeviceProfile(Context context) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700515 Resources res = context.getResources();
516 Configuration config = context.getResources().getConfiguration();
517
518 float availableWidth = config.screenWidthDp * res.getDisplayMetrics().density;
519 float availableHeight = config.screenHeightDp * res.getDisplayMetrics().density;
520
Sunny Goyal19ff7282021-04-22 10:12:54 -0700521 DeviceProfile bestMatch = supportedProfiles.get(0);
522 float minDiff = Float.MAX_VALUE;
523
524 for (DeviceProfile profile : supportedProfiles) {
525 float diff = Math.abs(profile.availableWidthPx - availableWidth)
526 + Math.abs(profile.availableHeightPx - availableHeight);
527 if (diff < minDiff) {
528 minDiff = diff;
529 bestMatch = profile;
530 }
531 }
532 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800533 }
534
Sunny Goyal415f1732018-11-29 10:33:47 -0800535 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700536 float d = dist(x0, y0, x1, y1);
537 if (Float.compare(d, 0f) == 0) {
538 return Float.POSITIVE_INFINITY;
539 }
540 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
541 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700542
543 /**
544 * As a ratio of screen height, the total distance we want the parallax effect to span
545 * horizontally
546 */
547 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
548 float aspectRatio = width / (float) height;
549
550 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
551 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
552 // We will use these two data points to extrapolate how much the wallpaper parallax effect
553 // to span (ie travel) at any aspect ratio:
554
555 final float ASPECT_RATIO_LANDSCAPE = 16/10f;
556 final float ASPECT_RATIO_PORTRAIT = 10/16f;
557 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
558 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
559
560 // To find out the desired width at different aspect ratios, we use the following two
561 // formulas, where the coefficient on x is the aspect ratio (width/height):
562 // (16/10)x + y = 1.5
563 // (10/16)x + y = 1.2
564 // We solve for x and y and end up with a final formula:
565 final float x =
566 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
567 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
568 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
569 return x * aspectRatio + y;
570 }
571
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700572 public interface OnIDPChangeListener {
573
Sunny Goyalb47172b2021-05-03 19:59:51 -0700574 /**
575 * Called when the device provide changes
576 */
577 void onIdpChanged(InvariantDeviceProfile profile);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700578 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800579
580
Sunny Goyaleff44f32019-01-09 17:29:49 -0800581 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800582
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800583 public static final String TAG_NAME = "grid-option";
584
Sunny Goyaleff44f32019-01-09 17:29:49 -0800585 public final String name;
586 public final int numRows;
587 public final int numColumns;
Sunny Goyal415f1732018-11-29 10:33:47 -0800588
589 private final int numFolderRows;
590 private final int numFolderColumns;
591
Sunny Goyal19ff7282021-04-22 10:12:54 -0700592 private final int numAllAppsColumns;
593 private final int numDatabaseAllAppsColumns;
594 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700595 private final int numDatabaseHotseatIcons;
Sunny Goyal415f1732018-11-29 10:33:47 -0800596
Tracy Zhou7df93d22020-01-27 13:44:06 -0800597 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000598
Sunny Goyal415f1732018-11-29 10:33:47 -0800599 private final int defaultLayoutId;
600 private final int demoModeLayoutId;
601
Jon Mirandae126d722021-02-25 10:45:20 -0500602 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400603 private final int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500604
Sunny Goyal5bc18462019-01-07 15:13:39 -0800605 private final SparseArray<TypedValue> extraAttrs;
606
Sunny Goyaleff44f32019-01-09 17:29:49 -0800607 public GridOption(Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800608 TypedArray a = context.obtainStyledAttributes(
609 attrs, R.styleable.GridDisplayOption);
610 name = a.getString(R.styleable.GridDisplayOption_name);
611 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
612 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
613
Tracy Zhou7df93d22020-01-27 13:44:06 -0800614 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Sunny Goyal415f1732018-11-29 10:33:47 -0800615 defaultLayoutId = a.getResourceId(
616 R.styleable.GridDisplayOption_defaultLayoutId, 0);
617 demoModeLayoutId = a.getResourceId(
618 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700619
620 numAllAppsColumns = a.getInt(
621 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
622 numDatabaseAllAppsColumns = a.getInt(
623 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
624
625 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800626 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700627 numDatabaseHotseatIcons = a.getInt(
628 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
629
Sunny Goyal415f1732018-11-29 10:33:47 -0800630 numFolderRows = a.getInt(
631 R.styleable.GridDisplayOption_numFolderRows, numRows);
632 numFolderColumns = a.getInt(
633 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700634
Jon Mirandae126d722021-02-25 10:45:20 -0500635 isScalable = a.getBoolean(
636 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400637 devicePaddingId = a.getResourceId(
638 R.styleable.GridDisplayOption_devicePaddingId, 0);
Jon Mirandae126d722021-02-25 10:45:20 -0500639
Sunny Goyal415f1732018-11-29 10:33:47 -0800640 a.recycle();
Sunny Goyal5bc18462019-01-07 15:13:39 -0800641 extraAttrs = Themes.createValueMap(context, attrs,
642 IntArray.wrap(R.styleable.GridDisplayOption));
Sunny Goyal415f1732018-11-29 10:33:47 -0800643 }
644 }
645
Sunny Goyal19ff7282021-04-22 10:12:54 -0700646 @VisibleForTesting
647 static final class DisplayOption {
648
649 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800650
Sunny Goyal415f1732018-11-29 10:33:47 -0800651 private final float minWidthDps;
652 private final float minHeightDps;
653 private final boolean canBeDefault;
654
Jon Mirandae126d722021-02-25 10:45:20 -0500655 private float minCellHeight;
656 private float minCellWidth;
657 private float borderSpacing;
658
Sunny Goyal415f1732018-11-29 10:33:47 -0800659 private float iconSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800660 private float iconTextSize;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700661 private float landscapeIconSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200662 private float landscapeIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000663 private float allAppsIconSize;
664 private float allAppsIconTextSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800665
Sunny Goyal19ff7282021-04-22 10:12:54 -0700666 DisplayOption(GridOption grid, Context context, AttributeSet attrs, int defaultFlagValue) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800667 this.grid = grid;
668
669 TypedArray a = context.obtainStyledAttributes(
670 attrs, R.styleable.ProfileDisplayOption);
671
Sunny Goyal415f1732018-11-29 10:33:47 -0800672 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
673 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700674
675 canBeDefault = a.getInt(R.styleable.ProfileDisplayOption_canBeDefault, 0)
676 == defaultFlagValue;
Sunny Goyal415f1732018-11-29 10:33:47 -0800677
Jon Mirandae126d722021-02-25 10:45:20 -0500678 minCellHeight = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightDps, 0);
679 minCellWidth = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthDps, 0);
680 borderSpacing = a.getFloat(R.styleable.ProfileDisplayOption_borderSpacingDps, 0);
681
Ryan Mitchell01b8b682019-03-28 17:01:07 -0700682 iconSize = a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800683 landscapeIconSize = a.getFloat(R.styleable.ProfileDisplayOption_landscapeIconSize,
684 iconSize);
685 iconTextSize = a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
Andras Kloczl6057cb92021-04-07 13:45:17 +0200686 landscapeIconTextSize = a.getFloat(
687 R.styleable.ProfileDisplayOption_landscapeIconTextSize, iconTextSize);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700688
Sunny Goyalae190ff2020-04-14 00:19:01 +0000689 allAppsIconSize = a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconSize,
690 iconSize);
691 allAppsIconTextSize = a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconTextSize,
692 iconTextSize);
Sunny Goyal415f1732018-11-29 10:33:47 -0800693 a.recycle();
694 }
695
696 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700697 this(null);
698 }
699
700 DisplayOption(GridOption grid) {
701 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800702 minWidthDps = 0;
703 minHeightDps = 0;
704 canBeDefault = false;
Jon Mirandae126d722021-02-25 10:45:20 -0500705 minCellHeight = 0;
706 minCellWidth = 0;
707 borderSpacing = 0;
Sunny Goyal415f1732018-11-29 10:33:47 -0800708 }
709
710 private DisplayOption multiply(float w) {
711 iconSize *= w;
712 landscapeIconSize *= w;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000713 allAppsIconSize *= w;
Sunny Goyal415f1732018-11-29 10:33:47 -0800714 iconTextSize *= w;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200715 landscapeIconTextSize *= w;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000716 allAppsIconTextSize *= w;
Jon Mirandae126d722021-02-25 10:45:20 -0500717 minCellHeight *= w;
718 minCellWidth *= w;
719 borderSpacing *= w;
Sunny Goyal415f1732018-11-29 10:33:47 -0800720 return this;
721 }
722
723 private DisplayOption add(DisplayOption p) {
724 iconSize += p.iconSize;
725 landscapeIconSize += p.landscapeIconSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000726 allAppsIconSize += p.allAppsIconSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800727 iconTextSize += p.iconTextSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200728 landscapeIconTextSize += p.landscapeIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000729 allAppsIconTextSize += p.allAppsIconTextSize;
Jon Mirandae126d722021-02-25 10:45:20 -0500730 minCellHeight += p.minCellHeight;
731 minCellWidth += p.minCellWidth;
732 borderSpacing += p.borderSpacing;
Sunny Goyal415f1732018-11-29 10:33:47 -0800733 return this;
734 }
735 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000736}