blob: 3dbd4794a28faa48fac3b0564eb86bc7171e1594 [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;
230 result.allAppsIconSize = Math.min(
231 defaultDisplayOption.allAppsIconSize, myDisplayOption.allAppsIconSize);
Jon Mirandae126d722021-02-25 10:45:20 -0500232 result.minCellHeight = defaultDisplayOption.minCellHeight;
233 result.minCellWidth = defaultDisplayOption.minCellWidth;
234 result.borderSpacing = defaultDisplayOption.borderSpacing;
Jon Miranda228877d2021-02-09 11:05:00 -0500235
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700236 initGrid(context, myInfo, result);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800237 }
238
Tracy Zhou42255d22020-03-13 00:38:11 -0700239 public static String getCurrentGridName(Context context) {
Andras Kloczl8e57cce2021-02-11 23:51:19 +0100240 if (ENABLE_TWO_PANEL_HOME.get()) {
241 return ENABLE_TWO_PANEL_HOME.key;
242 }
Jon Miranda73dcc982020-12-11 14:14:46 -0800243 if (ENABLE_FOUR_COLUMNS.get()) {
244 return ENABLE_FOUR_COLUMNS.key;
245 }
Tracy Zhouc6060e62020-04-27 13:05:34 -0700246 return Utilities.isGridOptionsEnabled(context)
247 ? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null;
Tracy Zhou42255d22020-03-13 00:38:11 -0700248 }
249
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800250 /**
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800251 * Retrieve system defined or RRO overriden icon shape.
252 */
253 private static String getIconShapePath(Context context) {
254 if (CONFIG_ICON_MASK_RES_ID == 0) {
255 Log.e(TAG, "Icon mask res identifier failed to retrieve.");
256 return "";
257 }
258 return context.getResources().getString(CONFIG_ICON_MASK_RES_ID);
259 }
260
Sunny Goyaleff44f32019-01-09 17:29:49 -0800261 private String initGrid(Context context, String gridName) {
Sunny Goyalfd58da62020-08-11 12:06:49 -0700262 Info displayInfo = DisplayController.getDefaultDisplay(context).getInfo();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700263 ArrayList<DisplayOption> allOptions = getPredefinedDeviceProfiles(context, gridName);
264
265 DisplayOption displayOption = invDistWeightedInterpolate(displayInfo, allOptions);
266 initGrid(context, displayInfo, displayOption);
267 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800268 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700269
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700270 private void initGrid(
Sunny Goyalfd58da62020-08-11 12:06:49 -0700271 Context context, Info displayInfo, DisplayOption displayOption) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700272 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000273 numRows = closestProfile.numRows;
274 numColumns = closestProfile.numColumns;
275 numHotseatIcons = closestProfile.numHotseatIcons;
276 dbFile = closestProfile.dbFile;
277 defaultLayoutId = closestProfile.defaultLayoutId;
278 demoModeLayoutId = closestProfile.demoModeLayoutId;
279 numFolderRows = closestProfile.numFolderRows;
280 numFolderColumns = closestProfile.numFolderColumns;
281 numAllAppsColumns = closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500282 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400283 devicePaddingId = closestProfile.devicePaddingId;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000284
285 mExtraAttrs = closestProfile.extraAttrs;
286
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700287 iconSize = displayOption.iconSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000288 iconShapePath = getIconShapePath(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700289 landscapeIconSize = displayOption.landscapeIconSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000290 iconBitmapSize = ResourceUtils.pxFromDp(iconSize, displayInfo.metrics);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700291 iconTextSize = displayOption.iconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000292 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
293
Jon Mirandae126d722021-02-25 10:45:20 -0500294 minCellHeight = displayOption.minCellHeight;
295 minCellWidth = displayOption.minCellWidth;
296 borderSpacing = displayOption.borderSpacing;
297
Tracy Zhouc6060e62020-04-27 13:05:34 -0700298 if (Utilities.isGridOptionsEnabled(context)) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700299 allAppsIconSize = displayOption.allAppsIconSize;
300 allAppsIconTextSize = displayOption.allAppsIconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000301 } else {
302 allAppsIconSize = iconSize;
303 allAppsIconTextSize = iconTextSize;
304 }
305
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400306 if (devicePaddingId != 0) {
307 devicePaddings = new DevicePaddings(context, devicePaddingId);
308 }
309
Sunny Goyalae190ff2020-04-14 00:19:01 +0000310 // If the partner customization apk contains any grid overrides, apply them
311 // Supported overrides: numRows, numColumns, iconSize
312 applyPartnerDeviceProfileOverrides(context, displayInfo.metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700313
Winson Chung13c1c2c2019-09-06 11:46:19 -0700314 Point realSize = new Point(displayInfo.realSize);
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700315 // The real size never changes. smallSide and largeSide will remain the
Sunny Goyalc6205602015-05-21 20:46:33 -0700316 // same in any orientation.
317 int smallSide = Math.min(realSize.x, realSize.y);
318 int largeSide = Math.max(realSize.x, realSize.y);
319
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700320 DeviceProfile.Builder builder = new DeviceProfile.Builder(context, this, displayInfo)
321 .setSizeRange(new Point(displayInfo.smallestSize),
322 new Point(displayInfo.largestSize));
323
324 landscapeProfile = builder.setSize(largeSide, smallSide).build();
325 portraitProfile = builder.setSize(smallSide, largeSide).build();
Sunny Goyal6f866092016-03-17 17:04:15 -0700326
327 // We need to ensure that there is enough extra space in the wallpaper
328 // for the intended parallax effects
329 if (context.getResources().getConfiguration().smallestScreenWidthDp >= 720) {
330 defaultWallpaperSize = new Point(
331 (int) (largeSide * wallpaperTravelToScreenWidthRatio(largeSide, smallSide)),
332 largeSide);
333 } else {
334 defaultWallpaperSize = new Point(Math.max(smallSide * 2, largeSide), largeSide);
335 }
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700336
337 ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName());
338 defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
Adam Cohen2e6da152015-05-06 11:42:25 -0700339 }
340
Sunny Goyal5bc18462019-01-07 15:13:39 -0800341 @Nullable
342 public TypedValue getAttrValue(int attr) {
343 return mExtraAttrs == null ? null : mExtraAttrs.get(attr);
344 }
345
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700346 public void addOnChangeListener(OnIDPChangeListener listener) {
347 mChangeListeners.add(listener);
348 }
349
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800350 public void removeOnChangeListener(OnIDPChangeListener listener) {
351 mChangeListeners.remove(listener);
352 }
353
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800354 public void verifyConfigChangedInBackground(final Context context) {
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800355 String savedIconMaskPath = getDevicePrefs(context).getString(KEY_ICON_PATH_REF, "");
356 // Good place to check if grid size changed in themepicker when launcher was dead.
357 if (savedIconMaskPath.isEmpty()) {
358 getDevicePrefs(context).edit().putString(KEY_ICON_PATH_REF, getIconShapePath(context))
359 .apply();
360 } else if (!savedIconMaskPath.equals(getIconShapePath(context))) {
361 getDevicePrefs(context).edit().putString(KEY_ICON_PATH_REF, getIconShapePath(context))
362 .apply();
363 apply(context, CHANGE_FLAG_ICON_PARAMS);
364 }
365 }
366
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800367 public void setCurrentGrid(Context context, String gridName) {
368 Context appContext = context.getApplicationContext();
369 Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply();
Sunny Goyal6fe3eec2019-08-15 14:53:41 -0700370 MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800371 }
372
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700373 private void onConfigChanged(Context context) {
374 // Config changes, what shall we do?
375 InvariantDeviceProfile oldProfile = new InvariantDeviceProfile(this);
376
377 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700378 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700379 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700380
381 int changeFlags = 0;
382 if (numRows != oldProfile.numRows ||
383 numColumns != oldProfile.numColumns ||
384 numFolderColumns != oldProfile.numFolderColumns ||
385 numFolderRows != oldProfile.numFolderRows ||
386 numHotseatIcons != oldProfile.numHotseatIcons) {
387 changeFlags |= CHANGE_FLAG_GRID;
388 }
389
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800390 if (iconSize != oldProfile.iconSize || iconBitmapSize != oldProfile.iconBitmapSize ||
391 !iconShapePath.equals(oldProfile.iconShapePath)) {
392 changeFlags |= CHANGE_FLAG_ICON_PARAMS;
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700393 }
Sunny Goyal90e3fbc2019-01-23 16:42:43 -0800394 if (!iconShapePath.equals(oldProfile.iconShapePath)) {
Sunny Goyal905262c2019-05-03 16:50:43 -0700395 IconShape.init(context);
Sunny Goyal90e3fbc2019-01-23 16:42:43 -0800396 }
397
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800398 apply(context, changeFlags);
399 }
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700400
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800401 private void apply(Context context, int changeFlags) {
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700402 // Create a new config monitor
403 mConfigMonitor.unregister();
404 mConfigMonitor = new ConfigMonitor(context, this::onConfigChanged);
405
406 for (OnIDPChangeListener listener : mChangeListeners) {
407 listener.onIdpChanged(changeFlags, this);
408 }
409 }
410
Sunny Goyalae190ff2020-04-14 00:19:01 +0000411 static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context, String gridName) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800412 ArrayList<DisplayOption> profiles = new ArrayList<>();
Sunny Goyal819e1932016-07-07 16:43:58 -0700413 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
414 final int depth = parser.getDepth();
415 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700416 while (((type = parser.next()) != XmlPullParser.END_TAG ||
417 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800418 if ((type == XmlPullParser.START_TAG)
419 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800420
421 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser));
422 final int displayDepth = parser.getDepth();
423 while (((type = parser.next()) != XmlPullParser.END_TAG ||
424 parser.getDepth() > displayDepth)
425 && type != XmlPullParser.END_DOCUMENT) {
426 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
427 parser.getName())) {
428 profiles.add(new DisplayOption(
429 gridOption, context, Xml.asAttributeSet(parser)));
430 }
431 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700432 }
433 }
434 } catch (IOException|XmlPullParserException e) {
435 throw new RuntimeException(e);
436 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800437
Sunny Goyalae190ff2020-04-14 00:19:01 +0000438 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800439 if (!TextUtils.isEmpty(gridName)) {
440 for (DisplayOption option : profiles) {
441 if (gridName.equals(option.grid.name)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000442 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800443 }
444 }
445 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000446 if (filteredProfiles.isEmpty()) {
447 // No grid found, use the default options
448 for (DisplayOption option : profiles) {
449 if (option.canBeDefault) {
450 filteredProfiles.add(option);
451 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800452 }
453 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000454 if (filteredProfiles.isEmpty()) {
455 throw new RuntimeException("No display option with canBeDefault=true");
456 }
457 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700458 }
459
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700460 private int getLauncherIconDensity(int requiredSize) {
461 // Densities typically defined by an app.
462 int[] densityBuckets = new int[] {
463 DisplayMetrics.DENSITY_LOW,
464 DisplayMetrics.DENSITY_MEDIUM,
465 DisplayMetrics.DENSITY_TV,
466 DisplayMetrics.DENSITY_HIGH,
467 DisplayMetrics.DENSITY_XHIGH,
468 DisplayMetrics.DENSITY_XXHIGH,
469 DisplayMetrics.DENSITY_XXXHIGH
470 };
471
472 int density = DisplayMetrics.DENSITY_XXXHIGH;
473 for (int i = densityBuckets.length - 1; i >= 0; i--) {
474 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
475 / DisplayMetrics.DENSITY_DEFAULT;
476 if (expectedSize >= requiredSize) {
477 density = densityBuckets[i];
478 }
479 }
480
481 return density;
482 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700483
Adam Cohen2e6da152015-05-06 11:42:25 -0700484 /**
485 * Apply any Partner customization grid overrides.
486 *
487 * Currently we support: all apps row / column count.
488 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700489 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
490 Partner p = Partner.get(context.getPackageManager());
Adam Cohen2e6da152015-05-06 11:42:25 -0700491 if (p != null) {
492 p.applyInvariantDeviceProfileOverrides(this, dm);
493 }
494 }
495
Sunny Goyal415f1732018-11-29 10:33:47 -0800496 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700497 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700498 }
499
Sunny Goyal415f1732018-11-29 10:33:47 -0800500 @VisibleForTesting
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700501 static DisplayOption invDistWeightedInterpolate(
Sunny Goyalfd58da62020-08-11 12:06:49 -0700502 Info displayInfo, ArrayList<DisplayOption> points) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700503 Point smallestSize = new Point(displayInfo.smallestSize);
504 Point largestSize = new Point(displayInfo.largestSize);
505
506 // This guarantees that width < height
507 float width = Utilities.dpiFromPx(Math.min(smallestSize.x, smallestSize.y),
508 displayInfo.metrics);
509 float height = Utilities.dpiFromPx(Math.min(largestSize.x, largestSize.y),
510 displayInfo.metrics);
511
512 // Sort the profiles based on the closeness to the device size
513 Collections.sort(points, (a, b) ->
514 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
515 dist(width, height, b.minWidthDps, b.minHeightDps)));
516
517 GridOption closestOption = points.get(0).grid;
518 float weights = 0;
519
520 DisplayOption p = points.get(0);
521 if (dist(width, height, p.minWidthDps, p.minHeightDps) == 0) {
522 return p;
523 }
524
525 DisplayOption out = new DisplayOption(closestOption);
526 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
527 p = points.get(i);
528 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
529 weights += w;
530 out.add(new DisplayOption().add(p).multiply(w));
531 }
532 return out.multiply(1.0f / weights);
533 }
534
535 @VisibleForTesting
Sunny Goyal415f1732018-11-29 10:33:47 -0800536 static DisplayOption invDistWeightedInterpolate(float width, float height,
Sunny Goyalae190ff2020-04-14 00:19:01 +0000537 ArrayList<DisplayOption> points) {
Adam Cohen2e6da152015-05-06 11:42:25 -0700538 float weights = 0;
Adam Cohen2e6da152015-05-06 11:42:25 -0700539
Sunny Goyal415f1732018-11-29 10:33:47 -0800540 DisplayOption p = points.get(0);
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700541 if (dist(width, height, p.minWidthDps, p.minHeightDps) == 0) {
542 return p;
Adam Cohen2e6da152015-05-06 11:42:25 -0700543 }
544
Sunny Goyal415f1732018-11-29 10:33:47 -0800545 DisplayOption out = new DisplayOption();
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700546 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800547 p = points.get(i);
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700548 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
549 weights += w;
Sunny Goyal415f1732018-11-29 10:33:47 -0800550 out.add(new DisplayOption().add(p).multiply(w));
Adam Cohen2e6da152015-05-06 11:42:25 -0700551 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800552 return out.multiply(1.0f / weights);
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700553 }
554
Sunny Goyal27835952017-01-13 12:15:53 -0800555 public DeviceProfile getDeviceProfile(Context context) {
556 return context.getResources().getConfiguration().orientation
557 == Configuration.ORIENTATION_LANDSCAPE ? landscapeProfile : portraitProfile;
558 }
559
Sunny Goyal415f1732018-11-29 10:33:47 -0800560 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700561 float d = dist(x0, y0, x1, y1);
562 if (Float.compare(d, 0f) == 0) {
563 return Float.POSITIVE_INFINITY;
564 }
565 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
566 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700567
568 /**
569 * As a ratio of screen height, the total distance we want the parallax effect to span
570 * horizontally
571 */
572 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
573 float aspectRatio = width / (float) height;
574
575 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
576 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
577 // We will use these two data points to extrapolate how much the wallpaper parallax effect
578 // to span (ie travel) at any aspect ratio:
579
580 final float ASPECT_RATIO_LANDSCAPE = 16/10f;
581 final float ASPECT_RATIO_PORTRAIT = 10/16f;
582 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
583 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
584
585 // To find out the desired width at different aspect ratios, we use the following two
586 // formulas, where the coefficient on x is the aspect ratio (width/height):
587 // (16/10)x + y = 1.5
588 // (10/16)x + y = 1.2
589 // We solve for x and y and end up with a final formula:
590 final float x =
591 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
592 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
593 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
594 return x * aspectRatio + y;
595 }
596
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700597 public interface OnIDPChangeListener {
598
599 void onIdpChanged(int changeFlags, InvariantDeviceProfile profile);
600 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800601
602
Sunny Goyaleff44f32019-01-09 17:29:49 -0800603 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800604
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800605 public static final String TAG_NAME = "grid-option";
606
Sunny Goyaleff44f32019-01-09 17:29:49 -0800607 public final String name;
608 public final int numRows;
609 public final int numColumns;
Sunny Goyal415f1732018-11-29 10:33:47 -0800610
611 private final int numFolderRows;
612 private final int numFolderColumns;
613
614 private final int numHotseatIcons;
615
Tracy Zhou7df93d22020-01-27 13:44:06 -0800616 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000617 private final int numAllAppsColumns;
618
Sunny Goyal415f1732018-11-29 10:33:47 -0800619 private final int defaultLayoutId;
620 private final int demoModeLayoutId;
621
Jon Mirandae126d722021-02-25 10:45:20 -0500622 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400623 private final int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500624
Sunny Goyal5bc18462019-01-07 15:13:39 -0800625 private final SparseArray<TypedValue> extraAttrs;
626
Sunny Goyaleff44f32019-01-09 17:29:49 -0800627 public GridOption(Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800628 TypedArray a = context.obtainStyledAttributes(
629 attrs, R.styleable.GridDisplayOption);
630 name = a.getString(R.styleable.GridDisplayOption_name);
631 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
632 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
633
Tracy Zhou7df93d22020-01-27 13:44:06 -0800634 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Sunny Goyal415f1732018-11-29 10:33:47 -0800635 defaultLayoutId = a.getResourceId(
636 R.styleable.GridDisplayOption_defaultLayoutId, 0);
637 demoModeLayoutId = a.getResourceId(
638 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
639 numHotseatIcons = a.getInt(
640 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
641 numFolderRows = a.getInt(
642 R.styleable.GridDisplayOption_numFolderRows, numRows);
643 numFolderColumns = a.getInt(
644 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000645 numAllAppsColumns = a.getInt(
646 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700647
Jon Mirandae126d722021-02-25 10:45:20 -0500648 isScalable = a.getBoolean(
649 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400650 devicePaddingId = a.getResourceId(
651 R.styleable.GridDisplayOption_devicePaddingId, 0);
Jon Mirandae126d722021-02-25 10:45:20 -0500652
Sunny Goyal415f1732018-11-29 10:33:47 -0800653 a.recycle();
Sunny Goyal5bc18462019-01-07 15:13:39 -0800654
655 extraAttrs = Themes.createValueMap(context, attrs,
656 IntArray.wrap(R.styleable.GridDisplayOption));
Sunny Goyal415f1732018-11-29 10:33:47 -0800657 }
658 }
659
660 private static final class DisplayOption {
661 private final GridOption grid;
662
Sunny Goyal415f1732018-11-29 10:33:47 -0800663 private final float minWidthDps;
664 private final float minHeightDps;
665 private final boolean canBeDefault;
666
Jon Mirandae126d722021-02-25 10:45:20 -0500667 private float minCellHeight;
668 private float minCellWidth;
669 private float borderSpacing;
670
Sunny Goyal415f1732018-11-29 10:33:47 -0800671 private float iconSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800672 private float iconTextSize;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700673 private float landscapeIconSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000674 private float allAppsIconSize;
675 private float allAppsIconTextSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800676
677 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
678 this.grid = grid;
679
680 TypedArray a = context.obtainStyledAttributes(
681 attrs, R.styleable.ProfileDisplayOption);
682
Sunny Goyal415f1732018-11-29 10:33:47 -0800683 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
684 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
685 canBeDefault = a.getBoolean(
686 R.styleable.ProfileDisplayOption_canBeDefault, false);
687
Jon Mirandae126d722021-02-25 10:45:20 -0500688 minCellHeight = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightDps, 0);
689 minCellWidth = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthDps, 0);
690 borderSpacing = a.getFloat(R.styleable.ProfileDisplayOption_borderSpacingDps, 0);
691
Ryan Mitchell01b8b682019-03-28 17:01:07 -0700692 iconSize = a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800693 landscapeIconSize = a.getFloat(R.styleable.ProfileDisplayOption_landscapeIconSize,
694 iconSize);
695 iconTextSize = a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700696
Sunny Goyalae190ff2020-04-14 00:19:01 +0000697 allAppsIconSize = a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconSize,
698 iconSize);
699 allAppsIconTextSize = a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconTextSize,
700 iconTextSize);
Sunny Goyal415f1732018-11-29 10:33:47 -0800701 a.recycle();
702 }
703
704 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700705 this(null);
706 }
707
708 DisplayOption(GridOption grid) {
709 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800710 minWidthDps = 0;
711 minHeightDps = 0;
712 canBeDefault = false;
Jon Mirandae126d722021-02-25 10:45:20 -0500713 minCellHeight = 0;
714 minCellWidth = 0;
715 borderSpacing = 0;
Sunny Goyal415f1732018-11-29 10:33:47 -0800716 }
717
718 private DisplayOption multiply(float w) {
719 iconSize *= w;
720 landscapeIconSize *= w;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000721 allAppsIconSize *= w;
Sunny Goyal415f1732018-11-29 10:33:47 -0800722 iconTextSize *= w;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000723 allAppsIconTextSize *= w;
Jon Mirandae126d722021-02-25 10:45:20 -0500724 minCellHeight *= w;
725 minCellWidth *= w;
726 borderSpacing *= w;
Sunny Goyal415f1732018-11-29 10:33:47 -0800727 return this;
728 }
729
730 private DisplayOption add(DisplayOption p) {
731 iconSize += p.iconSize;
732 landscapeIconSize += p.landscapeIconSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000733 allAppsIconSize += p.allAppsIconSize;
Sunny Goyal415f1732018-11-29 10:33:47 -0800734 iconTextSize += p.iconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000735 allAppsIconTextSize += p.allAppsIconTextSize;
Jon Mirandae126d722021-02-25 10:45:20 -0500736 minCellHeight += p.minCellHeight;
737 minCellWidth += p.minCellWidth;
738 borderSpacing += p.borderSpacing;
Sunny Goyal415f1732018-11-29 10:33:47 -0800739 return this;
740 }
741 }
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700742
743 private class OverlayMonitor extends BroadcastReceiver {
744
745 private final String ACTION_OVERLAY_CHANGED = "android.intent.action.OVERLAY_CHANGED";
746
747 OverlayMonitor(Context context) {
Sunny Goyal8b0cb412019-04-22 09:01:26 -0700748 context.registerReceiver(this, getPackageFilter("android", ACTION_OVERLAY_CHANGED));
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700749 }
750
751 @Override
752 public void onReceive(Context context, Intent intent) {
753 onConfigChanged(context);
754 }
755 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000756}