blob: 318dde1ecc2a64010189027225cbd25128bc500d [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 Goyal87dc48b2018-10-12 11:42:33 -070039import android.util.Log;
Sunny Goyal5bc18462019-01-07 15:13:39 -080040import android.util.SparseArray;
41import android.util.TypedValue;
Sunny Goyal819e1932016-07-07 16:43:58 -070042import android.util.Xml;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080043import android.view.Display;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070044
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070045import androidx.annotation.Nullable;
46import androidx.annotation.VisibleForTesting;
47
Winson Chung8e64bba2021-04-20 13:26:26 -070048import com.android.launcher3.testing.TestProtocol;
Sunny Goyalfd58da62020-08-11 12:06:49 -070049import com.android.launcher3.util.DisplayController;
50import com.android.launcher3.util.DisplayController.Info;
Sunny Goyal5bc18462019-01-07 15:13:39 -080051import com.android.launcher3.util.IntArray;
Sunny Goyald0e360a2018-06-29 14:40:18 -070052import com.android.launcher3.util.MainThreadInitializedObject;
Sunny Goyal5bc18462019-01-07 15:13:39 -080053import com.android.launcher3.util.Themes;
Sunny Goyal19ff7282021-04-22 10:12:54 -070054import com.android.launcher3.util.WindowBounds;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070055
Sunny Goyal819e1932016-07-07 16:43:58 -070056import org.xmlpull.v1.XmlPullParser;
57import org.xmlpull.v1.XmlPullParserException;
58
59import java.io.IOException;
Adam Cohen2e6da152015-05-06 11:42:25 -070060import java.util.ArrayList;
Sunny Goyal6d55f662019-01-02 12:13:43 -080061import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070062import java.util.List;
Adam Cohen2e6da152015-05-06 11:42:25 -070063
64public class InvariantDeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070065
Hyunyoung Songc55a3502018-12-04 15:43:16 -080066 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070067 // We do not need any synchronization for this variable as its only written on UI thread.
68 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070069 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070070
Tracy Zhoued5f3082020-04-20 01:13:26 -070071 public static final String KEY_MIGRATION_SRC_WORKSPACE_SIZE = "migration_src_workspace_size";
72 public static final String KEY_MIGRATION_SRC_HOTSEAT_COUNT = "migration_src_hotseat_count";
73
Sunny Goyal19ff7282021-04-22 10:12:54 -070074 private static final int DEFAULT_TRUE = -1;
75 private static final int DEFAULT_SPLIT_DISPLAY = 2;
76
Hyunyoung Songc55a3502018-12-04 15:43:16 -080077 private static final String KEY_IDP_GRID_NAME = "idp_grid_name";
Sunny Goyal415f1732018-11-29 10:33:47 -080078
Sunny Goyal53d7ee42015-05-22 12:25:45 -070079 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
80
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070081 // Constants that affects the interpolation curve between statically defined device profile
82 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080083 private static final float KNEARESTNEIGHBOR = 3;
84 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -070085
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070086 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080087 private static final float WEIGHT_EFFICIENT = 100000f;
88
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070089 /**
90 * Number of icons per row and column in the workspace.
91 */
Adam Cohen2e6da152015-05-06 11:42:25 -070092 public int numRows;
93 public int numColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070094
95 /**
96 * Number of icons per row and column in the folder.
97 */
Adam Cohen2e6da152015-05-06 11:42:25 -070098 public int numFolderRows;
99 public int numFolderColumns;
Sunny Goyalfc218302015-09-17 14:59:10 -0700100 public float iconSize;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700101 public float landscapeIconSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200102 public float landscapeIconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700103 public int iconBitmapSize;
104 public int fillResIconDpi;
105 public float iconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000106 public float allAppsIconSize;
107 public float allAppsIconTextSize;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700108
Jon Mirandae126d722021-02-25 10:45:20 -0500109 public float minCellHeight;
110 public float minCellWidth;
111 public float borderSpacing;
112
Sunny Goyal5bc18462019-01-07 15:13:39 -0800113 private SparseArray<TypedValue> mExtraAttrs;
114
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700115 /**
116 * Number of icons inside the hotseat area.
117 */
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700118 protected int numShownHotseatIcons;
119
120 /**
121 * Number of icons inside the hotseat area that is stored in the database. This is greater than
122 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
123 * sizes that share the same DB.
124 */
125 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700126
Jon Miranda6f7e9702019-09-16 14:44:14 -0700127 /**
128 * Number of columns in the all apps list.
129 */
130 public int numAllAppsColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700131 public int numDatabaseAllAppsColumns;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700132
Jon Mirandae126d722021-02-25 10:45:20 -0500133 /**
134 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
135 */
136 protected boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400137 public int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500138
Tracy Zhou7df93d22020-01-27 13:44:06 -0800139 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800140 public int defaultLayoutId;
Adam Cohen27824492017-09-22 17:10:55 -0700141 int demoModeLayoutId;
Adam Cohen2e6da152015-05-06 11:42:25 -0700142
Sunny Goyal19ff7282021-04-22 10:12:54 -0700143 public final List<DeviceProfile> supportedProfiles = new ArrayList<>();
Sunny Goyalc6205602015-05-21 20:46:33 -0700144
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400145 @Nullable public DevicePaddings devicePaddings;
Jon Miranda228877d2021-02-09 11:05:00 -0500146
Sunny Goyal6f866092016-03-17 17:04:15 -0700147 public Point defaultWallpaperSize;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700148 public Rect defaultWidgetPadding;
Sunny Goyal6f866092016-03-17 17:04:15 -0700149
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700150 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700151
Sunny Goyalf633ef52018-03-13 09:57:05 -0700152 @VisibleForTesting
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700153 public InvariantDeviceProfile() {}
Adam Cohen2e6da152015-05-06 11:42:25 -0700154
Sunny Goyalf633ef52018-03-13 09:57:05 -0700155 private InvariantDeviceProfile(InvariantDeviceProfile p) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800156 numRows = p.numRows;
157 numColumns = p.numColumns;
158 numFolderRows = p.numFolderRows;
159 numFolderColumns = p.numFolderColumns;
160 iconSize = p.iconSize;
161 landscapeIconSize = p.landscapeIconSize;
Tony Wickham9459f312020-06-15 13:30:20 -0500162 iconBitmapSize = p.iconBitmapSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800163 iconTextSize = p.iconTextSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200164 landscapeIconTextSize = p.landscapeIconTextSize;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700165 numShownHotseatIcons = p.numShownHotseatIcons;
166 numDatabaseHotseatIcons = p.numDatabaseHotseatIcons;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700167 numAllAppsColumns = p.numAllAppsColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700168 numDatabaseAllAppsColumns = p.numDatabaseAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500169 isScalable = p.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400170 devicePaddingId = p.devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500171 minCellHeight = p.minCellHeight;
172 minCellWidth = p.minCellWidth;
173 borderSpacing = p.borderSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800174 dbFile = p.dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000175 allAppsIconSize = p.allAppsIconSize;
176 allAppsIconTextSize = p.allAppsIconTextSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800177 defaultLayoutId = p.defaultLayoutId;
178 demoModeLayoutId = p.demoModeLayoutId;
Sunny Goyal5bc18462019-01-07 15:13:39 -0800179 mExtraAttrs = p.mExtraAttrs;
Jon Miranda228877d2021-02-09 11:05:00 -0500180 devicePaddings = p.devicePaddings;
Adam Cohen2e6da152015-05-06 11:42:25 -0700181 }
182
Sunny Goyalbbf01842015-10-08 07:41:15 -0700183 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700184 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700185 String gridName = getCurrentGridName(context);
186 String newGridName = initGrid(context, gridName);
187 if (!newGridName.equals(gridName)) {
188 Utilities.getPrefs(context).edit().putString(KEY_IDP_GRID_NAME, newGridName).apply();
189 }
Tracy Zhoued5f3082020-04-20 01:13:26 -0700190 Utilities.getPrefs(context).edit()
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700191 .putInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, numDatabaseHotseatIcons)
Tracy Zhoued5f3082020-04-20 01:13:26 -0700192 .putString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, getPointString(numColumns, numRows))
193 .apply();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700194
Sunny Goyal35c7b192021-04-20 16:51:10 -0700195 DisplayController.INSTANCE.get(context).addChangeListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100196 (displayContext, info, flags) -> {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700197 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100198 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700199 }
200 });
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700201 }
202
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700203 /**
204 * This constructor should NOT have any monitors by design.
205 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800206 public InvariantDeviceProfile(Context context, String gridName) {
207 String newName = initGrid(context, gridName);
208 if (newName == null || !newName.equals(gridName)) {
209 throw new IllegalArgumentException("Unknown grid name");
210 }
211 }
212
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700213 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800214 * This constructor should NOT have any monitors by design.
215 */
216 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700217 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100218 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700219 String gridName = getCurrentGridName(context);
220
221 // Get the display info based on default display and interpolate it to existing display
222 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Sunny Goyal35c7b192021-04-20 16:51:10 -0700223 DisplayController.INSTANCE.get(context).getInfo(),
Sunny Goyal19ff7282021-04-22 10:12:54 -0700224 getPredefinedDeviceProfiles(context, gridName, false), false);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700225
Alex Chau417bd722021-01-26 15:22:18 +0000226 Info myInfo = new Info(context, display);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700227 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Sunny Goyal19ff7282021-04-22 10:12:54 -0700228 myInfo, getPredefinedDeviceProfiles(context, gridName, false), false);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700229
230 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
231 .add(myDisplayOption);
232 result.iconSize = defaultDisplayOption.iconSize;
233 result.landscapeIconSize = defaultDisplayOption.landscapeIconSize;
Alex Chau7c439722021-03-24 11:32:44 +0000234 if (defaultDisplayOption.allAppsIconSize < myDisplayOption.allAppsIconSize) {
235 result.allAppsIconSize = defaultDisplayOption.allAppsIconSize;
Alex Chau7c439722021-03-24 11:32:44 +0000236 } else {
237 result.allAppsIconSize = myDisplayOption.allAppsIconSize;
Alex Chau7c439722021-03-24 11:32:44 +0000238 }
Jon Mirandae126d722021-02-25 10:45:20 -0500239 result.minCellHeight = defaultDisplayOption.minCellHeight;
240 result.minCellWidth = defaultDisplayOption.minCellWidth;
241 result.borderSpacing = defaultDisplayOption.borderSpacing;
Jon Miranda228877d2021-02-09 11:05:00 -0500242
Sunny Goyal19ff7282021-04-22 10:12:54 -0700243 initGrid(context, myInfo, result, false);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800244 }
245
Tracy Zhou42255d22020-03-13 00:38:11 -0700246 public static String getCurrentGridName(Context context) {
Tracy Zhouc6060e62020-04-27 13:05:34 -0700247 return Utilities.isGridOptionsEnabled(context)
248 ? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null;
Tracy Zhou42255d22020-03-13 00:38:11 -0700249 }
250
Sunny Goyaleff44f32019-01-09 17:29:49 -0800251 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700252 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700253 // Determine if we have split display
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700254
Sunny Goyal19ff7282021-04-22 10:12:54 -0700255 boolean isTablet = false, isPhone = false;
256 for (WindowBounds bounds : displayInfo.supportedBounds) {
257 if (displayInfo.isTablet(bounds)) {
258 isTablet = true;
259 } else {
260 isPhone = true;
261 }
262 }
263 boolean isSplitDisplay = isPhone && isTablet && ENABLE_TWO_PANEL_HOME.get();
264
265 ArrayList<DisplayOption> allOptions =
266 getPredefinedDeviceProfiles(context, gridName, isSplitDisplay);
267 DisplayOption displayOption =
268 invDistWeightedInterpolate(displayInfo, allOptions, isSplitDisplay);
269 initGrid(context, displayInfo, displayOption, isSplitDisplay);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700270 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800271 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700272
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700273 private void initGrid(
Sunny Goyal19ff7282021-04-22 10:12:54 -0700274 Context context, Info displayInfo, DisplayOption displayOption,
275 boolean isSplitDisplay) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700276 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700277 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000278 numRows = closestProfile.numRows;
279 numColumns = closestProfile.numColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000280 dbFile = closestProfile.dbFile;
281 defaultLayoutId = closestProfile.defaultLayoutId;
282 demoModeLayoutId = closestProfile.demoModeLayoutId;
283 numFolderRows = closestProfile.numFolderRows;
284 numFolderColumns = closestProfile.numFolderColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500285 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400286 devicePaddingId = closestProfile.devicePaddingId;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000287
288 mExtraAttrs = closestProfile.extraAttrs;
289
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700290 iconSize = displayOption.iconSize;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700291 landscapeIconSize = displayOption.landscapeIconSize;
Sunny Goyal35c7b192021-04-20 16:51:10 -0700292 iconBitmapSize = ResourceUtils.pxFromDp(iconSize, metrics);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700293 iconTextSize = displayOption.iconTextSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200294 landscapeIconTextSize = displayOption.landscapeIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000295 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
296
Jon Mirandae126d722021-02-25 10:45:20 -0500297 minCellHeight = displayOption.minCellHeight;
298 minCellWidth = displayOption.minCellWidth;
299 borderSpacing = displayOption.borderSpacing;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700300
301 numShownHotseatIcons = closestProfile.numHotseatIcons;
302 numDatabaseHotseatIcons = isSplitDisplay
303 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
304
305 numAllAppsColumns = closestProfile.numAllAppsColumns;
306 numDatabaseAllAppsColumns = isSplitDisplay
307 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500308
Tracy Zhouc6060e62020-04-27 13:05:34 -0700309 if (Utilities.isGridOptionsEnabled(context)) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700310 allAppsIconSize = displayOption.allAppsIconSize;
311 allAppsIconTextSize = displayOption.allAppsIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000312 } else {
313 allAppsIconSize = iconSize;
314 allAppsIconTextSize = iconTextSize;
315 }
316
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400317 if (devicePaddingId != 0) {
318 devicePaddings = new DevicePaddings(context, devicePaddingId);
319 }
320
Sunny Goyalae190ff2020-04-14 00:19:01 +0000321 // If the partner customization apk contains any grid overrides, apply them
322 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700323 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700324
Sunny Goyal19ff7282021-04-22 10:12:54 -0700325 supportedProfiles.clear();
326 defaultWallpaperSize = new Point(displayInfo.currentSize);
327 for (WindowBounds bounds : displayInfo.supportedBounds) {
328 supportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
329 .setUseTwoPanels(isSplitDisplay)
330 .setWindowBounds(bounds).build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700331
Sunny Goyal19ff7282021-04-22 10:12:54 -0700332 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
333 int displayWidth = bounds.bounds.width();
334 int displayHeight = bounds.bounds.height();
335 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700336
Sunny Goyal19ff7282021-04-22 10:12:54 -0700337 // We need to ensure that there is enough extra space in the wallpaper
338 // for the intended parallax effects
339 float parallaxFactor =
340 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.densityDpi) < 720
341 ? 2
342 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
343 defaultWallpaperSize.x =
344 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700345 }
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700346
347 ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName());
348 defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
Adam Cohen2e6da152015-05-06 11:42:25 -0700349 }
350
Sunny Goyal5bc18462019-01-07 15:13:39 -0800351 @Nullable
352 public TypedValue getAttrValue(int attr) {
353 return mExtraAttrs == null ? null : mExtraAttrs.get(attr);
354 }
355
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700356 public void addOnChangeListener(OnIDPChangeListener listener) {
357 mChangeListeners.add(listener);
358 }
359
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800360 public void removeOnChangeListener(OnIDPChangeListener listener) {
361 mChangeListeners.remove(listener);
362 }
363
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800364
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800365 public void setCurrentGrid(Context context, String gridName) {
366 Context appContext = context.getApplicationContext();
367 Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply();
Sunny Goyal6fe3eec2019-08-15 14:53:41 -0700368 MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800369 }
370
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700371 private void onConfigChanged(Context context) {
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700372 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700373 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700374 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700375
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700376 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyalb47172b2021-05-03 19:59:51 -0700377 listener.onIdpChanged(this);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700378 }
379 }
380
Sunny Goyal19ff7282021-04-22 10:12:54 -0700381 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(
382 Context context, String gridName, boolean isSplitDisplay) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800383 ArrayList<DisplayOption> profiles = new ArrayList<>();
Sunny Goyal819e1932016-07-07 16:43:58 -0700384 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
385 final int depth = parser.getDepth();
386 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700387 while (((type = parser.next()) != XmlPullParser.END_TAG ||
388 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800389 if ((type == XmlPullParser.START_TAG)
390 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800391
392 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
393 final int displayDepth = parser.getDepth();
394 while (((type = parser.next()) != XmlPullParser.END_TAG ||
395 parser.getDepth() > displayDepth)
396 && type != XmlPullParser.END_DOCUMENT) {
397 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
398 parser.getName())) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700399 profiles.add(new DisplayOption(gridOption, context,
400 Xml.asAttributeSet(parser),
401 isSplitDisplay ? DEFAULT_SPLIT_DISPLAY : DEFAULT_TRUE));
Sunny Goyal415f1732018-11-29 10:33:47 -0800402 }
403 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700404 }
405 }
406 } catch (IOException|XmlPullParserException e) {
407 throw new RuntimeException(e);
408 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800409
Sunny Goyalae190ff2020-04-14 00:19:01 +0000410 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800411 if (!TextUtils.isEmpty(gridName)) {
412 for (DisplayOption option : profiles) {
413 if (gridName.equals(option.grid.name)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000414 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800415 }
416 }
417 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000418 if (filteredProfiles.isEmpty()) {
419 // No grid found, use the default options
420 for (DisplayOption option : profiles) {
421 if (option.canBeDefault) {
422 filteredProfiles.add(option);
423 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800424 }
425 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000426 if (filteredProfiles.isEmpty()) {
427 throw new RuntimeException("No display option with canBeDefault=true");
428 }
429 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700430 }
431
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700432 private int getLauncherIconDensity(int requiredSize) {
433 // Densities typically defined by an app.
434 int[] densityBuckets = new int[] {
435 DisplayMetrics.DENSITY_LOW,
436 DisplayMetrics.DENSITY_MEDIUM,
437 DisplayMetrics.DENSITY_TV,
438 DisplayMetrics.DENSITY_HIGH,
439 DisplayMetrics.DENSITY_XHIGH,
440 DisplayMetrics.DENSITY_XXHIGH,
441 DisplayMetrics.DENSITY_XXXHIGH
442 };
443
444 int density = DisplayMetrics.DENSITY_XXXHIGH;
445 for (int i = densityBuckets.length - 1; i >= 0; i--) {
446 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
447 / DisplayMetrics.DENSITY_DEFAULT;
448 if (expectedSize >= requiredSize) {
449 density = densityBuckets[i];
450 }
451 }
452
453 return density;
454 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700455
Adam Cohen2e6da152015-05-06 11:42:25 -0700456 /**
457 * Apply any Partner customization grid overrides.
458 *
459 * Currently we support: all apps row / column count.
460 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700461 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
462 Partner p = Partner.get(context.getPackageManager());
Adam Cohen2e6da152015-05-06 11:42:25 -0700463 if (p != null) {
464 p.applyInvariantDeviceProfileOverrides(this, dm);
465 }
466 }
467
Sunny Goyal415f1732018-11-29 10:33:47 -0800468 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700469 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700470 }
471
Sunny Goyal19ff7282021-04-22 10:12:54 -0700472 private static DisplayOption invDistWeightedInterpolate(
473 Info displayInfo, ArrayList<DisplayOption> points, boolean isSplitDisplay) {
474 int minWidthPx = Integer.MAX_VALUE;
475 int minHeightPx = Integer.MAX_VALUE;
476 for (WindowBounds bounds : displayInfo.supportedBounds) {
477 boolean isTablet = displayInfo.isTablet(bounds);
478 if (isTablet && isSplitDisplay) {
479 // For split displays, take half width per page
480 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
481 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700482
Sunny Goyal19ff7282021-04-22 10:12:54 -0700483 } else if (!isTablet && bounds.isLandscape()) {
484 // We will use transposed layout in this case
485 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
486 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
487 } else {
488 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
489 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
490 }
491 }
492
493 float width = dpiFromPx(minWidthPx, displayInfo.densityDpi);
494 float height = dpiFromPx(minHeightPx, displayInfo.densityDpi);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700495
496 // Sort the profiles based on the closeness to the device size
497 Collections.sort(points, (a, b) ->
498 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
499 dist(width, height, b.minWidthDps, b.minHeightDps)));
500
501 GridOption closestOption = points.get(0).grid;
502 float weights = 0;
503
504 DisplayOption p = points.get(0);
505 if (dist(width, height, p.minWidthDps, p.minHeightDps) == 0) {
506 return p;
507 }
508
509 DisplayOption out = new DisplayOption(closestOption);
510 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
511 p = points.get(i);
512 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
513 weights += w;
514 out.add(new DisplayOption().add(p).multiply(w));
515 }
516 return out.multiply(1.0f / weights);
517 }
518
Sunny Goyal27835952017-01-13 12:15:53 -0800519 public DeviceProfile getDeviceProfile(Context context) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700520 Resources res = context.getResources();
521 Configuration config = context.getResources().getConfiguration();
522
523 float availableWidth = config.screenWidthDp * res.getDisplayMetrics().density;
524 float availableHeight = config.screenHeightDp * res.getDisplayMetrics().density;
525
Sunny Goyal19ff7282021-04-22 10:12:54 -0700526 DeviceProfile bestMatch = supportedProfiles.get(0);
527 float minDiff = Float.MAX_VALUE;
528
529 for (DeviceProfile profile : supportedProfiles) {
530 float diff = Math.abs(profile.availableWidthPx - availableWidth)
531 + Math.abs(profile.availableHeightPx - availableHeight);
532 if (diff < minDiff) {
533 minDiff = diff;
534 bestMatch = profile;
535 }
536 }
537 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800538 }
539
Sunny Goyal415f1732018-11-29 10:33:47 -0800540 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700541 float d = dist(x0, y0, x1, y1);
542 if (Float.compare(d, 0f) == 0) {
543 return Float.POSITIVE_INFINITY;
544 }
545 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
546 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700547
548 /**
549 * As a ratio of screen height, the total distance we want the parallax effect to span
550 * horizontally
551 */
552 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
553 float aspectRatio = width / (float) height;
554
555 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
556 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
557 // We will use these two data points to extrapolate how much the wallpaper parallax effect
558 // to span (ie travel) at any aspect ratio:
559
560 final float ASPECT_RATIO_LANDSCAPE = 16/10f;
561 final float ASPECT_RATIO_PORTRAIT = 10/16f;
562 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
563 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
564
565 // To find out the desired width at different aspect ratios, we use the following two
566 // formulas, where the coefficient on x is the aspect ratio (width/height):
567 // (16/10)x + y = 1.5
568 // (10/16)x + y = 1.2
569 // We solve for x and y and end up with a final formula:
570 final float x =
571 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
572 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
573 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
574 return x * aspectRatio + y;
575 }
576
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700577 public interface OnIDPChangeListener {
578
Sunny Goyalb47172b2021-05-03 19:59:51 -0700579 /**
580 * Called when the device provide changes
581 */
582 void onIdpChanged(InvariantDeviceProfile profile);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700583 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800584
585
Sunny Goyaleff44f32019-01-09 17:29:49 -0800586 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800587
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800588 public static final String TAG_NAME = "grid-option";
589
Sunny Goyaleff44f32019-01-09 17:29:49 -0800590 public final String name;
591 public final int numRows;
592 public final int numColumns;
Sunny Goyal415f1732018-11-29 10:33:47 -0800593
594 private final int numFolderRows;
595 private final int numFolderColumns;
596
Sunny Goyal19ff7282021-04-22 10:12:54 -0700597 private final int numAllAppsColumns;
598 private final int numDatabaseAllAppsColumns;
599 private final int numHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700600 private final int numDatabaseHotseatIcons;
Sunny Goyal415f1732018-11-29 10:33:47 -0800601
Tracy Zhou7df93d22020-01-27 13:44:06 -0800602 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000603
Sunny Goyal415f1732018-11-29 10:33:47 -0800604 private final int defaultLayoutId;
605 private final int demoModeLayoutId;
606
Jon Mirandae126d722021-02-25 10:45:20 -0500607 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400608 private final int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500609
Sunny Goyal5bc18462019-01-07 15:13:39 -0800610 private final SparseArray<TypedValue> extraAttrs;
611
Sunny Goyaleff44f32019-01-09 17:29:49 -0800612 public GridOption(Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800613 TypedArray a = context.obtainStyledAttributes(
614 attrs, R.styleable.GridDisplayOption);
615 name = a.getString(R.styleable.GridDisplayOption_name);
616 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
617 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
618
Tracy Zhou7df93d22020-01-27 13:44:06 -0800619 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Sunny Goyal415f1732018-11-29 10:33:47 -0800620 defaultLayoutId = a.getResourceId(
621 R.styleable.GridDisplayOption_defaultLayoutId, 0);
622 demoModeLayoutId = a.getResourceId(
623 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700624
625 numAllAppsColumns = a.getInt(
626 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
627 numDatabaseAllAppsColumns = a.getInt(
628 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
629
630 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800631 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700632 numDatabaseHotseatIcons = a.getInt(
633 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
634
Sunny Goyal415f1732018-11-29 10:33:47 -0800635 numFolderRows = a.getInt(
636 R.styleable.GridDisplayOption_numFolderRows, numRows);
637 numFolderColumns = a.getInt(
638 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700639
Jon Mirandae126d722021-02-25 10:45:20 -0500640 isScalable = a.getBoolean(
641 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400642 devicePaddingId = a.getResourceId(
643 R.styleable.GridDisplayOption_devicePaddingId, 0);
Jon Mirandae126d722021-02-25 10:45:20 -0500644
Sunny Goyal415f1732018-11-29 10:33:47 -0800645 a.recycle();
Sunny Goyal5bc18462019-01-07 15:13:39 -0800646 extraAttrs = Themes.createValueMap(context, attrs,
647 IntArray.wrap(R.styleable.GridDisplayOption));
Sunny Goyal415f1732018-11-29 10:33:47 -0800648 }
649 }
650
Sunny Goyal19ff7282021-04-22 10:12:54 -0700651 @VisibleForTesting
652 static final class DisplayOption {
653
654 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800655
Sunny Goyal415f1732018-11-29 10:33:47 -0800656 private final float minWidthDps;
657 private final float minHeightDps;
658 private final boolean canBeDefault;
659
Jon Mirandae126d722021-02-25 10:45:20 -0500660 private float minCellHeight;
661 private float minCellWidth;
662 private float borderSpacing;
663
Sunny Goyal415f1732018-11-29 10:33:47 -0800664 private float iconSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800665 private float iconTextSize;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700666 private float landscapeIconSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200667 private float landscapeIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000668 private float allAppsIconSize;
669 private float allAppsIconTextSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800670
Sunny Goyal19ff7282021-04-22 10:12:54 -0700671 DisplayOption(GridOption grid, Context context, AttributeSet attrs, int defaultFlagValue) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800672 this.grid = grid;
673
674 TypedArray a = context.obtainStyledAttributes(
675 attrs, R.styleable.ProfileDisplayOption);
676
Sunny Goyal415f1732018-11-29 10:33:47 -0800677 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
678 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700679
680 canBeDefault = a.getInt(R.styleable.ProfileDisplayOption_canBeDefault, 0)
681 == defaultFlagValue;
Sunny Goyal415f1732018-11-29 10:33:47 -0800682
Jon Mirandae126d722021-02-25 10:45:20 -0500683 minCellHeight = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightDps, 0);
684 minCellWidth = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthDps, 0);
685 borderSpacing = a.getFloat(R.styleable.ProfileDisplayOption_borderSpacingDps, 0);
686
Ryan Mitchell01b8b682019-03-28 17:01:07 -0700687 iconSize = a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800688 landscapeIconSize = a.getFloat(R.styleable.ProfileDisplayOption_landscapeIconSize,
689 iconSize);
690 iconTextSize = a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
Andras Kloczl6057cb92021-04-07 13:45:17 +0200691 landscapeIconTextSize = a.getFloat(
692 R.styleable.ProfileDisplayOption_landscapeIconTextSize, iconTextSize);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700693
Sunny Goyalae190ff2020-04-14 00:19:01 +0000694 allAppsIconSize = a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconSize,
695 iconSize);
696 allAppsIconTextSize = a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconTextSize,
697 iconTextSize);
Sunny Goyal415f1732018-11-29 10:33:47 -0800698 a.recycle();
699 }
700
701 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700702 this(null);
703 }
704
705 DisplayOption(GridOption grid) {
706 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800707 minWidthDps = 0;
708 minHeightDps = 0;
709 canBeDefault = false;
Jon Mirandae126d722021-02-25 10:45:20 -0500710 minCellHeight = 0;
711 minCellWidth = 0;
712 borderSpacing = 0;
Sunny Goyal415f1732018-11-29 10:33:47 -0800713 }
714
715 private DisplayOption multiply(float w) {
716 iconSize *= w;
717 landscapeIconSize *= w;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000718 allAppsIconSize *= w;
Sunny Goyal415f1732018-11-29 10:33:47 -0800719 iconTextSize *= w;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200720 landscapeIconTextSize *= w;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000721 allAppsIconTextSize *= w;
Jon Mirandae126d722021-02-25 10:45:20 -0500722 minCellHeight *= w;
723 minCellWidth *= w;
724 borderSpacing *= w;
Sunny Goyal415f1732018-11-29 10:33:47 -0800725 return this;
726 }
727
728 private DisplayOption add(DisplayOption p) {
729 iconSize += p.iconSize;
730 landscapeIconSize += p.landscapeIconSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000731 allAppsIconSize += p.allAppsIconSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800732 iconTextSize += p.iconTextSize;
Andras Kloczl6057cb92021-04-07 13:45:17 +0200733 landscapeIconTextSize += p.landscapeIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000734 allAppsIconTextSize += p.allAppsIconTextSize;
Jon Mirandae126d722021-02-25 10:45:20 -0500735 minCellHeight += p.minCellHeight;
736 minCellWidth += p.minCellWidth;
737 borderSpacing += p.borderSpacing;
Sunny Goyal415f1732018-11-29 10:33:47 -0800738 return this;
739 }
740 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000741}