blob: 754e988da65dd83544c6e130f91615ec43ad7b17 [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
Hyunyoung Songc55a3502018-12-04 15:43:16 -080019import static com.android.launcher3.Utilities.getDevicePrefs;
Tracy Zhoued5f3082020-04-20 01:13:26 -070020import static com.android.launcher3.Utilities.getPointString;
Jon Miranda73dcc982020-12-11 14:14:46 -080021import static com.android.launcher3.config.FeatureFlags.ENABLE_FOUR_COLUMNS;
Andras Kloczl8e57cce2021-02-11 23:51:19 +010022import static com.android.launcher3.config.FeatureFlags.ENABLE_TWO_PANEL_HOME;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080023import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
Sunny Goyal8b0cb412019-04-22 09:01:26 -070024import static com.android.launcher3.util.PackageManagerHelper.getPackageFilter;
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;
Hyunyoung Songe11eb472019-03-19 15:05:21 -070028import android.content.BroadcastReceiver;
Sunny Goyal58fa4b62019-03-22 16:23:25 -070029import android.content.ComponentName;
Adam Cohen2e6da152015-05-06 11:42:25 -070030import android.content.Context;
Hyunyoung Songe11eb472019-03-19 15:05:21 -070031import android.content.Intent;
Sunny Goyal27835952017-01-13 12:15:53 -080032import android.content.res.Configuration;
Hyunyoung Songc55a3502018-12-04 15:43:16 -080033import android.content.res.Resources;
Sunny Goyal819e1932016-07-07 16:43:58 -070034import android.content.res.TypedArray;
35import android.content.res.XmlResourceParser;
Adam Cohen2e6da152015-05-06 11:42:25 -070036import android.graphics.Point;
Sunny Goyal58fa4b62019-03-22 16:23:25 -070037import android.graphics.Rect;
Sunny Goyal415f1732018-11-29 10:33:47 -080038import android.text.TextUtils;
39import android.util.AttributeSet;
Adam Cohen2e6da152015-05-06 11:42:25 -070040import android.util.DisplayMetrics;
Sunny Goyal87dc48b2018-10-12 11:42:33 -070041import android.util.Log;
Sunny Goyal5bc18462019-01-07 15:13:39 -080042import android.util.SparseArray;
43import android.util.TypedValue;
Sunny Goyal819e1932016-07-07 16:43:58 -070044import android.util.Xml;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080045import android.view.Display;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070046
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070047import androidx.annotation.Nullable;
48import androidx.annotation.VisibleForTesting;
49
Sunny Goyal905262c2019-05-03 16:50:43 -070050import com.android.launcher3.graphics.IconShape;
Sunny Goyald0e360a2018-06-29 14:40:18 -070051import com.android.launcher3.util.ConfigMonitor;
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;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070057
Sunny Goyal819e1932016-07-07 16:43:58 -070058import org.xmlpull.v1.XmlPullParser;
59import org.xmlpull.v1.XmlPullParserException;
60
61import java.io.IOException;
Adam Cohen2e6da152015-05-06 11:42:25 -070062import java.util.ArrayList;
Sunny Goyal6d55f662019-01-02 12:13:43 -080063import java.util.Collections;
Adam Cohen2e6da152015-05-06 11:42:25 -070064
65public class InvariantDeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070066
Hyunyoung Songc55a3502018-12-04 15:43:16 -080067 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070068 // We do not need any synchronization for this variable as its only written on UI thread.
69 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070070 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070071
Tracy Zhoued5f3082020-04-20 01:13:26 -070072 public static final String KEY_MIGRATION_SRC_WORKSPACE_SIZE = "migration_src_workspace_size";
73 public static final String KEY_MIGRATION_SRC_HOTSEAT_COUNT = "migration_src_hotseat_count";
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
Sunny Goyal87dc48b2018-10-12 11:42:33 -070079 public static final int CHANGE_FLAG_GRID = 1 << 0;
Hyunyoung Songc55a3502018-12-04 15:43:16 -080080 public static final int CHANGE_FLAG_ICON_PARAMS = 1 << 1;
81
82 public static final String KEY_ICON_PATH_REF = "pref_icon_shape_path";
Sunny Goyal87dc48b2018-10-12 11:42:33 -070083
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070084 // Constants that affects the interpolation curve between statically defined device profile
85 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080086 private static final float KNEARESTNEIGHBOR = 3;
87 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -070088
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070089 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080090 private static final float WEIGHT_EFFICIENT = 100000f;
91
92 private static final int CONFIG_ICON_MASK_RES_ID = Resources.getSystem().getIdentifier(
93 "config_icon_mask", "string", "android");
Adam Cohen2e6da152015-05-06 11:42:25 -070094
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070095 /**
96 * Number of icons per row and column in the workspace.
97 */
Adam Cohen2e6da152015-05-06 11:42:25 -070098 public int numRows;
99 public int numColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700100
101 /**
102 * Number of icons per row and column in the folder.
103 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700104 public int numFolderRows;
105 public int numFolderColumns;
Sunny Goyalfc218302015-09-17 14:59:10 -0700106 public float iconSize;
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800107 public String iconShapePath;
Jon Mirandab28c4fc2017-06-20 10:58:36 -0700108 public float landscapeIconSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700109 public int iconBitmapSize;
110 public int fillResIconDpi;
111 public float iconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000112 public float allAppsIconSize;
113 public float allAppsIconTextSize;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700114
Jon Mirandae126d722021-02-25 10:45:20 -0500115 public float minCellHeight;
116 public float minCellWidth;
117 public float borderSpacing;
118
Sunny Goyal5bc18462019-01-07 15:13:39 -0800119 private SparseArray<TypedValue> mExtraAttrs;
120
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700121 /**
122 * Number of icons inside the hotseat area.
123 */
Sunny Goyalf862a262015-12-14 14:27:38 -0800124 public int numHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700125
Jon Miranda6f7e9702019-09-16 14:44:14 -0700126 /**
127 * Number of columns in the all apps list.
128 */
129 public int numAllAppsColumns;
130
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
cuijiaxingabda8d72017-03-20 09:51:36 -0700141 public DeviceProfile landscapeProfile;
142 public DeviceProfile portraitProfile;
Sunny Goyalc6205602015-05-21 20:46:33 -0700143
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400144 @Nullable public DevicePaddings devicePaddings;
Jon Miranda228877d2021-02-09 11:05:00 -0500145
Sunny Goyal6f866092016-03-17 17:04:15 -0700146 public Point defaultWallpaperSize;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700147 public Rect defaultWidgetPadding;
Sunny Goyal6f866092016-03-17 17:04:15 -0700148
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700149 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
150 private ConfigMonitor mConfigMonitor;
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700151 private OverlayMonitor mOverlayMonitor;
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;
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800162 iconShapePath = p.iconShapePath;
Sunny Goyal415f1732018-11-29 10:33:47 -0800163 landscapeIconSize = p.landscapeIconSize;
Tony Wickham9459f312020-06-15 13:30:20 -0500164 iconBitmapSize = p.iconBitmapSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800165 iconTextSize = p.iconTextSize;
166 numHotseatIcons = p.numHotseatIcons;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700167 numAllAppsColumns = p.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500168 isScalable = p.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400169 devicePaddingId = p.devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500170 minCellHeight = p.minCellHeight;
171 minCellWidth = p.minCellWidth;
172 borderSpacing = p.borderSpacing;
Tracy Zhou7df93d22020-01-27 13:44:06 -0800173 dbFile = p.dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000174 allAppsIconSize = p.allAppsIconSize;
175 allAppsIconTextSize = p.allAppsIconTextSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800176 defaultLayoutId = p.defaultLayoutId;
177 demoModeLayoutId = p.demoModeLayoutId;
Sunny Goyal5bc18462019-01-07 15:13:39 -0800178 mExtraAttrs = p.mExtraAttrs;
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700179 mOverlayMonitor = p.mOverlayMonitor;
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()
191 .putInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, numHotseatIcons)
192 .putString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, getPointString(numColumns, numRows))
193 .apply();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700194
Sunny Goyalead22a52021-02-02 23:21:55 -0800195 mConfigMonitor = new ConfigMonitor(context, this::onConfigChanged);
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700196 mOverlayMonitor = new OverlayMonitor(context);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700197 }
198
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700199 /**
200 * This constructor should NOT have any monitors by design.
201 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800202 public InvariantDeviceProfile(Context context, String gridName) {
203 String newName = initGrid(context, gridName);
204 if (newName == null || !newName.equals(gridName)) {
205 throw new IllegalArgumentException("Unknown grid name");
206 }
207 }
208
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700209 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800210 * This constructor should NOT have any monitors by design.
211 */
212 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700213 // Ensure that the main device profile is initialized
214 InvariantDeviceProfile originalProfile = INSTANCE.get(context);
215 String gridName = getCurrentGridName(context);
216
217 // Get the display info based on default display and interpolate it to existing display
218 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Sunny Goyalfd58da62020-08-11 12:06:49 -0700219 DisplayController.getDefaultDisplay(context).getInfo(),
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700220 getPredefinedDeviceProfiles(context, gridName));
221
Alex Chau417bd722021-01-26 15:22:18 +0000222 Info myInfo = new Info(context, display);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700223 DisplayOption myDisplayOption = invDistWeightedInterpolate(
224 myInfo, getPredefinedDeviceProfiles(context, gridName));
225
226 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
227 .add(myDisplayOption);
228 result.iconSize = defaultDisplayOption.iconSize;
229 result.landscapeIconSize = defaultDisplayOption.landscapeIconSize;
Alex Chau7c439722021-03-24 11:32:44 +0000230 if (defaultDisplayOption.allAppsIconSize < myDisplayOption.allAppsIconSize) {
231 result.allAppsIconSize = defaultDisplayOption.allAppsIconSize;
232 result.numAllAppsColumns = defaultDisplayOption.numAllAppsColumns;
233 } else {
234 result.allAppsIconSize = myDisplayOption.allAppsIconSize;
235 result.numAllAppsColumns = myDisplayOption.numAllAppsColumns;
236 }
Jon Mirandae126d722021-02-25 10:45:20 -0500237 result.minCellHeight = defaultDisplayOption.minCellHeight;
238 result.minCellWidth = defaultDisplayOption.minCellWidth;
239 result.borderSpacing = defaultDisplayOption.borderSpacing;
Jon Miranda228877d2021-02-09 11:05:00 -0500240
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700241 initGrid(context, myInfo, result);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800242 }
243
Tracy Zhou42255d22020-03-13 00:38:11 -0700244 public static String getCurrentGridName(Context context) {
Andras Kloczl8e57cce2021-02-11 23:51:19 +0100245 if (ENABLE_TWO_PANEL_HOME.get()) {
246 return ENABLE_TWO_PANEL_HOME.key;
247 }
Jon Miranda73dcc982020-12-11 14:14:46 -0800248 if (ENABLE_FOUR_COLUMNS.get()) {
249 return ENABLE_FOUR_COLUMNS.key;
250 }
Tracy Zhouc6060e62020-04-27 13:05:34 -0700251 return Utilities.isGridOptionsEnabled(context)
252 ? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null;
Tracy Zhou42255d22020-03-13 00:38:11 -0700253 }
254
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800255 /**
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800256 * Retrieve system defined or RRO overriden icon shape.
257 */
258 private static String getIconShapePath(Context context) {
259 if (CONFIG_ICON_MASK_RES_ID == 0) {
260 Log.e(TAG, "Icon mask res identifier failed to retrieve.");
261 return "";
262 }
263 return context.getResources().getString(CONFIG_ICON_MASK_RES_ID);
264 }
265
Sunny Goyaleff44f32019-01-09 17:29:49 -0800266 private String initGrid(Context context, String gridName) {
Sunny Goyalfd58da62020-08-11 12:06:49 -0700267 Info displayInfo = DisplayController.getDefaultDisplay(context).getInfo();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700268 ArrayList<DisplayOption> allOptions = getPredefinedDeviceProfiles(context, gridName);
269
270 DisplayOption displayOption = invDistWeightedInterpolate(displayInfo, allOptions);
271 initGrid(context, displayInfo, displayOption);
272 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800273 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700274
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700275 private void initGrid(
Sunny Goyalfd58da62020-08-11 12:06:49 -0700276 Context context, Info displayInfo, DisplayOption displayOption) {
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;
280 numHotseatIcons = closestProfile.numHotseatIcons;
281 dbFile = closestProfile.dbFile;
282 defaultLayoutId = closestProfile.defaultLayoutId;
283 demoModeLayoutId = closestProfile.demoModeLayoutId;
284 numFolderRows = closestProfile.numFolderRows;
285 numFolderColumns = closestProfile.numFolderColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500286 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400287 devicePaddingId = closestProfile.devicePaddingId;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000288
289 mExtraAttrs = closestProfile.extraAttrs;
290
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700291 iconSize = displayOption.iconSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000292 iconShapePath = getIconShapePath(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700293 landscapeIconSize = displayOption.landscapeIconSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000294 iconBitmapSize = ResourceUtils.pxFromDp(iconSize, displayInfo.metrics);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700295 iconTextSize = displayOption.iconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000296 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
297
Jon Mirandae126d722021-02-25 10:45:20 -0500298 minCellHeight = displayOption.minCellHeight;
299 minCellWidth = displayOption.minCellWidth;
300 borderSpacing = displayOption.borderSpacing;
Alex Chau7c439722021-03-24 11:32:44 +0000301 numAllAppsColumns = Math.round(displayOption.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
317 applyPartnerDeviceProfileOverrides(context, displayInfo.metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700318
Winson Chung13c1c2c2019-09-06 11:46:19 -0700319 Point realSize = new Point(displayInfo.realSize);
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700320 // The real size never changes. smallSide and largeSide will remain the
Sunny Goyalc6205602015-05-21 20:46:33 -0700321 // same in any orientation.
322 int smallSide = Math.min(realSize.x, realSize.y);
323 int largeSide = Math.max(realSize.x, realSize.y);
324
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700325 DeviceProfile.Builder builder = new DeviceProfile.Builder(context, this, displayInfo)
326 .setSizeRange(new Point(displayInfo.smallestSize),
327 new Point(displayInfo.largestSize));
328
329 landscapeProfile = builder.setSize(largeSide, smallSide).build();
330 portraitProfile = builder.setSize(smallSide, largeSide).build();
Sunny Goyal6f866092016-03-17 17:04:15 -0700331
332 // We need to ensure that there is enough extra space in the wallpaper
333 // for the intended parallax effects
334 if (context.getResources().getConfiguration().smallestScreenWidthDp >= 720) {
335 defaultWallpaperSize = new Point(
336 (int) (largeSide * wallpaperTravelToScreenWidthRatio(largeSide, smallSide)),
337 largeSide);
338 } else {
339 defaultWallpaperSize = new Point(Math.max(smallSide * 2, largeSide), largeSide);
340 }
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 public void verifyConfigChangedInBackground(final Context context) {
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800360 String savedIconMaskPath = getDevicePrefs(context).getString(KEY_ICON_PATH_REF, "");
361 // Good place to check if grid size changed in themepicker when launcher was dead.
362 if (savedIconMaskPath.isEmpty()) {
363 getDevicePrefs(context).edit().putString(KEY_ICON_PATH_REF, getIconShapePath(context))
364 .apply();
365 } else if (!savedIconMaskPath.equals(getIconShapePath(context))) {
366 getDevicePrefs(context).edit().putString(KEY_ICON_PATH_REF, getIconShapePath(context))
367 .apply();
368 apply(context, CHANGE_FLAG_ICON_PARAMS);
369 }
370 }
371
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800372 public void setCurrentGrid(Context context, String gridName) {
373 Context appContext = context.getApplicationContext();
374 Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply();
Sunny Goyal6fe3eec2019-08-15 14:53:41 -0700375 MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800376 }
377
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700378 private void onConfigChanged(Context context) {
379 // Config changes, what shall we do?
380 InvariantDeviceProfile oldProfile = new InvariantDeviceProfile(this);
381
382 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700383 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700384 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700385
386 int changeFlags = 0;
387 if (numRows != oldProfile.numRows ||
388 numColumns != oldProfile.numColumns ||
389 numFolderColumns != oldProfile.numFolderColumns ||
390 numFolderRows != oldProfile.numFolderRows ||
391 numHotseatIcons != oldProfile.numHotseatIcons) {
392 changeFlags |= CHANGE_FLAG_GRID;
393 }
394
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800395 if (iconSize != oldProfile.iconSize || iconBitmapSize != oldProfile.iconBitmapSize ||
396 !iconShapePath.equals(oldProfile.iconShapePath)) {
397 changeFlags |= CHANGE_FLAG_ICON_PARAMS;
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700398 }
Sunny Goyal90e3fbc2019-01-23 16:42:43 -0800399 if (!iconShapePath.equals(oldProfile.iconShapePath)) {
Sunny Goyal905262c2019-05-03 16:50:43 -0700400 IconShape.init(context);
Sunny Goyal90e3fbc2019-01-23 16:42:43 -0800401 }
402
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800403 apply(context, changeFlags);
404 }
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700405
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800406 private void apply(Context context, int changeFlags) {
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700407 // Create a new config monitor
408 mConfigMonitor.unregister();
409 mConfigMonitor = new ConfigMonitor(context, this::onConfigChanged);
410
411 for (OnIDPChangeListener listener : mChangeListeners) {
412 listener.onIdpChanged(changeFlags, this);
413 }
414 }
415
Sunny Goyalae190ff2020-04-14 00:19:01 +0000416 static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context, String gridName) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800417 ArrayList<DisplayOption> profiles = new ArrayList<>();
Sunny Goyal819e1932016-07-07 16:43:58 -0700418 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
419 final int depth = parser.getDepth();
420 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700421 while (((type = parser.next()) != XmlPullParser.END_TAG ||
422 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800423 if ((type == XmlPullParser.START_TAG)
424 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800425
426 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
427 final int displayDepth = parser.getDepth();
428 while (((type = parser.next()) != XmlPullParser.END_TAG ||
429 parser.getDepth() > displayDepth)
430 && type != XmlPullParser.END_DOCUMENT) {
431 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
432 parser.getName())) {
433 profiles.add(new DisplayOption(
434 gridOption, context, Xml.asAttributeSet(parser)));
435 }
436 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700437 }
438 }
439 } catch (IOException|XmlPullParserException e) {
440 throw new RuntimeException(e);
441 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800442
Sunny Goyalae190ff2020-04-14 00:19:01 +0000443 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800444 if (!TextUtils.isEmpty(gridName)) {
445 for (DisplayOption option : profiles) {
446 if (gridName.equals(option.grid.name)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000447 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800448 }
449 }
450 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000451 if (filteredProfiles.isEmpty()) {
452 // No grid found, use the default options
453 for (DisplayOption option : profiles) {
454 if (option.canBeDefault) {
455 filteredProfiles.add(option);
456 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800457 }
458 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000459 if (filteredProfiles.isEmpty()) {
460 throw new RuntimeException("No display option with canBeDefault=true");
461 }
462 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700463 }
464
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700465 private int getLauncherIconDensity(int requiredSize) {
466 // Densities typically defined by an app.
467 int[] densityBuckets = new int[] {
468 DisplayMetrics.DENSITY_LOW,
469 DisplayMetrics.DENSITY_MEDIUM,
470 DisplayMetrics.DENSITY_TV,
471 DisplayMetrics.DENSITY_HIGH,
472 DisplayMetrics.DENSITY_XHIGH,
473 DisplayMetrics.DENSITY_XXHIGH,
474 DisplayMetrics.DENSITY_XXXHIGH
475 };
476
477 int density = DisplayMetrics.DENSITY_XXXHIGH;
478 for (int i = densityBuckets.length - 1; i >= 0; i--) {
479 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
480 / DisplayMetrics.DENSITY_DEFAULT;
481 if (expectedSize >= requiredSize) {
482 density = densityBuckets[i];
483 }
484 }
485
486 return density;
487 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700488
Adam Cohen2e6da152015-05-06 11:42:25 -0700489 /**
490 * Apply any Partner customization grid overrides.
491 *
492 * Currently we support: all apps row / column count.
493 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700494 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
495 Partner p = Partner.get(context.getPackageManager());
Adam Cohen2e6da152015-05-06 11:42:25 -0700496 if (p != null) {
497 p.applyInvariantDeviceProfileOverrides(this, dm);
498 }
499 }
500
Sunny Goyal415f1732018-11-29 10:33:47 -0800501 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700502 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700503 }
504
Sunny Goyal415f1732018-11-29 10:33:47 -0800505 @VisibleForTesting
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700506 static DisplayOption invDistWeightedInterpolate(
Sunny Goyalfd58da62020-08-11 12:06:49 -0700507 Info displayInfo, ArrayList<DisplayOption> points) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700508 Point smallestSize = new Point(displayInfo.smallestSize);
509 Point largestSize = new Point(displayInfo.largestSize);
510
511 // This guarantees that width < height
512 float width = Utilities.dpiFromPx(Math.min(smallestSize.x, smallestSize.y),
513 displayInfo.metrics);
514 float height = Utilities.dpiFromPx(Math.min(largestSize.x, largestSize.y),
515 displayInfo.metrics);
516
517 // Sort the profiles based on the closeness to the device size
518 Collections.sort(points, (a, b) ->
519 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
520 dist(width, height, b.minWidthDps, b.minHeightDps)));
521
522 GridOption closestOption = points.get(0).grid;
523 float weights = 0;
524
525 DisplayOption p = points.get(0);
526 if (dist(width, height, p.minWidthDps, p.minHeightDps) == 0) {
527 return p;
528 }
529
530 DisplayOption out = new DisplayOption(closestOption);
531 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
532 p = points.get(i);
533 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
534 weights += w;
535 out.add(new DisplayOption().add(p).multiply(w));
536 }
537 return out.multiply(1.0f / weights);
538 }
539
540 @VisibleForTesting
Sunny Goyal415f1732018-11-29 10:33:47 -0800541 static DisplayOption invDistWeightedInterpolate(float width, float height,
Sunny Goyalae190ff2020-04-14 00:19:01 +0000542 ArrayList<DisplayOption> points) {
Adam Cohen2e6da152015-05-06 11:42:25 -0700543 float weights = 0;
Adam Cohen2e6da152015-05-06 11:42:25 -0700544
Sunny Goyal415f1732018-11-29 10:33:47 -0800545 DisplayOption p = points.get(0);
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700546 if (dist(width, height, p.minWidthDps, p.minHeightDps) == 0) {
547 return p;
Adam Cohen2e6da152015-05-06 11:42:25 -0700548 }
549
Sunny Goyal415f1732018-11-29 10:33:47 -0800550 DisplayOption out = new DisplayOption();
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700551 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800552 p = points.get(i);
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700553 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
554 weights += w;
Sunny Goyal415f1732018-11-29 10:33:47 -0800555 out.add(new DisplayOption().add(p).multiply(w));
Adam Cohen2e6da152015-05-06 11:42:25 -0700556 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800557 return out.multiply(1.0f / weights);
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700558 }
559
Sunny Goyal27835952017-01-13 12:15:53 -0800560 public DeviceProfile getDeviceProfile(Context context) {
561 return context.getResources().getConfiguration().orientation
562 == Configuration.ORIENTATION_LANDSCAPE ? landscapeProfile : portraitProfile;
563 }
564
Sunny Goyal415f1732018-11-29 10:33:47 -0800565 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700566 float d = dist(x0, y0, x1, y1);
567 if (Float.compare(d, 0f) == 0) {
568 return Float.POSITIVE_INFINITY;
569 }
570 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
571 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700572
573 /**
574 * As a ratio of screen height, the total distance we want the parallax effect to span
575 * horizontally
576 */
577 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
578 float aspectRatio = width / (float) height;
579
580 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
581 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
582 // We will use these two data points to extrapolate how much the wallpaper parallax effect
583 // to span (ie travel) at any aspect ratio:
584
585 final float ASPECT_RATIO_LANDSCAPE = 16/10f;
586 final float ASPECT_RATIO_PORTRAIT = 10/16f;
587 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
588 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
589
590 // To find out the desired width at different aspect ratios, we use the following two
591 // formulas, where the coefficient on x is the aspect ratio (width/height):
592 // (16/10)x + y = 1.5
593 // (10/16)x + y = 1.2
594 // We solve for x and y and end up with a final formula:
595 final float x =
596 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
597 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
598 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
599 return x * aspectRatio + y;
600 }
601
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700602 public interface OnIDPChangeListener {
603
604 void onIdpChanged(int changeFlags, InvariantDeviceProfile profile);
605 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800606
607
Sunny Goyaleff44f32019-01-09 17:29:49 -0800608 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800609
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800610 public static final String TAG_NAME = "grid-option";
611
Sunny Goyaleff44f32019-01-09 17:29:49 -0800612 public final String name;
613 public final int numRows;
614 public final int numColumns;
Sunny Goyal415f1732018-11-29 10:33:47 -0800615
616 private final int numFolderRows;
617 private final int numFolderColumns;
618
619 private final int numHotseatIcons;
620
Tracy Zhou7df93d22020-01-27 13:44:06 -0800621 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000622
Sunny Goyal415f1732018-11-29 10:33:47 -0800623 private final int defaultLayoutId;
624 private final int demoModeLayoutId;
625
Jon Mirandae126d722021-02-25 10:45:20 -0500626 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400627 private final int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500628
Jon Mirandaec1277e2021-03-25 10:41:54 -0400629 public final boolean visible;
630
Sunny Goyal5bc18462019-01-07 15:13:39 -0800631 private final SparseArray<TypedValue> extraAttrs;
632
Sunny Goyaleff44f32019-01-09 17:29:49 -0800633 public GridOption(Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800634 TypedArray a = context.obtainStyledAttributes(
635 attrs, R.styleable.GridDisplayOption);
636 name = a.getString(R.styleable.GridDisplayOption_name);
637 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
638 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
639
Tracy Zhou7df93d22020-01-27 13:44:06 -0800640 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Sunny Goyal415f1732018-11-29 10:33:47 -0800641 defaultLayoutId = a.getResourceId(
642 R.styleable.GridDisplayOption_defaultLayoutId, 0);
643 demoModeLayoutId = a.getResourceId(
644 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
645 numHotseatIcons = a.getInt(
646 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
647 numFolderRows = a.getInt(
648 R.styleable.GridDisplayOption_numFolderRows, numRows);
649 numFolderColumns = a.getInt(
650 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700651
Jon Mirandae126d722021-02-25 10:45:20 -0500652 isScalable = a.getBoolean(
653 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400654 devicePaddingId = a.getResourceId(
655 R.styleable.GridDisplayOption_devicePaddingId, 0);
Jon Mirandae126d722021-02-25 10:45:20 -0500656
Jon Mirandaec1277e2021-03-25 10:41:54 -0400657 visible = a.getBoolean(R.styleable.GridDisplayOption_visible, true);
658
Sunny Goyal415f1732018-11-29 10:33:47 -0800659 a.recycle();
Sunny Goyal5bc18462019-01-07 15:13:39 -0800660
661 extraAttrs = Themes.createValueMap(context, attrs,
662 IntArray.wrap(R.styleable.GridDisplayOption));
Sunny Goyal415f1732018-11-29 10:33:47 -0800663 }
664 }
665
666 private static final class DisplayOption {
667 private final GridOption grid;
668
Sunny Goyal415f1732018-11-29 10:33:47 -0800669 private final float minWidthDps;
670 private final float minHeightDps;
671 private final boolean canBeDefault;
672
Alex Chau7c439722021-03-24 11:32:44 +0000673 private float numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500674 private float minCellHeight;
675 private float minCellWidth;
676 private float borderSpacing;
677
Sunny Goyal415f1732018-11-29 10:33:47 -0800678 private float iconSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800679 private float iconTextSize;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700680 private float landscapeIconSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000681 private float allAppsIconSize;
682 private float allAppsIconTextSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800683
684 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
685 this.grid = grid;
686
687 TypedArray a = context.obtainStyledAttributes(
688 attrs, R.styleable.ProfileDisplayOption);
689
Sunny Goyal415f1732018-11-29 10:33:47 -0800690 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
691 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
692 canBeDefault = a.getBoolean(
693 R.styleable.ProfileDisplayOption_canBeDefault, false);
Alex Chau7c439722021-03-24 11:32:44 +0000694 numAllAppsColumns = a.getInt(R.styleable.ProfileDisplayOption_numAllAppsColumns,
695 grid.numColumns);
Sunny Goyal415f1732018-11-29 10:33:47 -0800696
Jon Mirandae126d722021-02-25 10:45:20 -0500697 minCellHeight = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightDps, 0);
698 minCellWidth = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthDps, 0);
699 borderSpacing = a.getFloat(R.styleable.ProfileDisplayOption_borderSpacingDps, 0);
700
Ryan Mitchell01b8b682019-03-28 17:01:07 -0700701 iconSize = a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800702 landscapeIconSize = a.getFloat(R.styleable.ProfileDisplayOption_landscapeIconSize,
703 iconSize);
704 iconTextSize = a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700705
Sunny Goyalae190ff2020-04-14 00:19:01 +0000706 allAppsIconSize = a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconSize,
707 iconSize);
708 allAppsIconTextSize = a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconTextSize,
709 iconTextSize);
Sunny Goyal415f1732018-11-29 10:33:47 -0800710 a.recycle();
711 }
712
713 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700714 this(null);
715 }
716
717 DisplayOption(GridOption grid) {
718 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800719 minWidthDps = 0;
720 minHeightDps = 0;
721 canBeDefault = false;
Alex Chau7c439722021-03-24 11:32:44 +0000722 numAllAppsColumns = 0;
Jon Mirandae126d722021-02-25 10:45:20 -0500723 minCellHeight = 0;
724 minCellWidth = 0;
725 borderSpacing = 0;
Sunny Goyal415f1732018-11-29 10:33:47 -0800726 }
727
728 private DisplayOption multiply(float w) {
Alex Chau7c439722021-03-24 11:32:44 +0000729 numAllAppsColumns *= w;
Sunny Goyal415f1732018-11-29 10:33:47 -0800730 iconSize *= w;
731 landscapeIconSize *= w;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000732 allAppsIconSize *= w;
Sunny Goyal415f1732018-11-29 10:33:47 -0800733 iconTextSize *= w;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000734 allAppsIconTextSize *= w;
Jon Mirandae126d722021-02-25 10:45:20 -0500735 minCellHeight *= w;
736 minCellWidth *= w;
737 borderSpacing *= w;
Sunny Goyal415f1732018-11-29 10:33:47 -0800738 return this;
739 }
740
741 private DisplayOption add(DisplayOption p) {
Alex Chau7c439722021-03-24 11:32:44 +0000742 numAllAppsColumns += p.numAllAppsColumns;
Sunny Goyal415f1732018-11-29 10:33:47 -0800743 iconSize += p.iconSize;
744 landscapeIconSize += p.landscapeIconSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000745 allAppsIconSize += p.allAppsIconSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800746 iconTextSize += p.iconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000747 allAppsIconTextSize += p.allAppsIconTextSize;
Jon Mirandae126d722021-02-25 10:45:20 -0500748 minCellHeight += p.minCellHeight;
749 minCellWidth += p.minCellWidth;
750 borderSpacing += p.borderSpacing;
Sunny Goyal415f1732018-11-29 10:33:47 -0800751 return this;
752 }
753 }
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700754
755 private class OverlayMonitor extends BroadcastReceiver {
756
757 private final String ACTION_OVERLAY_CHANGED = "android.intent.action.OVERLAY_CHANGED";
758
759 OverlayMonitor(Context context) {
Sunny Goyal8b0cb412019-04-22 09:01:26 -0700760 context.registerReceiver(this, getPackageFilter("android", ACTION_OVERLAY_CHANGED));
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700761 }
762
763 @Override
764 public void onReceive(Context context, Intent intent) {
765 onConfigChanged(context);
766 }
767 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000768}