blob: 0373eefd09f5a5070667c16723fa9e217026fdfd [file] [log] [blame]
Adam Cohen2e6da152015-05-06 11:42:25 -07001/*
Thales Lima1de4d552021-10-13 16:13:25 +01002 * Copyright (C) 2021 The Android Open Source Project
Adam Cohen2e6da152015-05-06 11:42:25 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.launcher3;
18
Sunny Goyal19ff7282021-04-22 10:12:54 -070019import static com.android.launcher3.Utilities.dpiFromPx;
Andras Kloczl8e57cce2021-02-11 23:51:19 +010020import static com.android.launcher3.config.FeatureFlags.ENABLE_TWO_PANEL_HOME;
Sunny Goyal35c7b192021-04-20 16:51:10 -070021import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY;
Alex Chau6ed408f2022-03-04 12:58:05 +000022import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE;
Sunny Goyal19ff7282021-04-22 10:12:54 -070023import static com.android.launcher3.util.DisplayController.CHANGE_SUPPORTED_BOUNDS;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080024import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
Sunny Goyal87dc48b2018-10-12 11:42:33 -070025
Sunny Goyalc6205602015-05-21 20:46:33 -070026import android.annotation.TargetApi;
Sunny Goyal58fa4b62019-03-22 16:23:25 -070027import android.appwidget.AppWidgetHostView;
Sunny Goyal58fa4b62019-03-22 16:23:25 -070028import android.content.ComponentName;
Adam Cohen2e6da152015-05-06 11:42:25 -070029import android.content.Context;
Sunny Goyal27835952017-01-13 12:15:53 -080030import android.content.res.Configuration;
Hyunyoung Songc55a3502018-12-04 15:43:16 -080031import android.content.res.Resources;
Sunny Goyal819e1932016-07-07 16:43:58 -070032import android.content.res.TypedArray;
33import android.content.res.XmlResourceParser;
Adam Cohen2e6da152015-05-06 11:42:25 -070034import android.graphics.Point;
Thales Lima78d00ad2021-09-30 11:29:06 +010035import android.graphics.PointF;
Sunny Goyal58fa4b62019-03-22 16:23:25 -070036import android.graphics.Rect;
Sunny Goyal415f1732018-11-29 10:33:47 -080037import android.text.TextUtils;
38import android.util.AttributeSet;
Adam Cohen2e6da152015-05-06 11:42:25 -070039import android.util.DisplayMetrics;
Thales Lima7ec83822021-08-05 13:32:10 +010040import android.util.Log;
Sunny Goyal5bc18462019-01-07 15:13:39 -080041import android.util.SparseArray;
42import android.util.TypedValue;
Sunny Goyal819e1932016-07-07 16:43:58 -070043import android.util.Xml;
Sunny Goyal9c2b9602020-01-07 13:07:55 -080044import android.view.Display;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070045
Alex Chau1c883d82021-12-01 18:43:10 +000046import androidx.annotation.IntDef;
Sunny Goyal6fe3eec2019-08-15 14:53:41 -070047import androidx.annotation.Nullable;
48import androidx.annotation.VisibleForTesting;
49
Sunny Goyal68031ca2021-08-02 12:23:44 -070050import com.android.launcher3.model.DeviceGridState;
Alex Chau238aaee2021-10-06 16:15:24 +010051import com.android.launcher3.provider.RestoreDbTask;
Sunny Goyalfd58da62020-08-11 12:06:49 -070052import com.android.launcher3.util.DisplayController;
53import com.android.launcher3.util.DisplayController.Info;
Sunny Goyal5bc18462019-01-07 15:13:39 -080054import com.android.launcher3.util.IntArray;
Sunny Goyald0e360a2018-06-29 14:40:18 -070055import com.android.launcher3.util.MainThreadInitializedObject;
Sunny Goyal5bc18462019-01-07 15:13:39 -080056import com.android.launcher3.util.Themes;
Sunny Goyal19ff7282021-04-22 10:12:54 -070057import com.android.launcher3.util.WindowBounds;
Sunny Goyal187b16c2022-03-01 16:53:23 -080058import com.android.launcher3.util.window.WindowManagerProxy;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070059
Sunny Goyal819e1932016-07-07 16:43:58 -070060import org.xmlpull.v1.XmlPullParser;
61import org.xmlpull.v1.XmlPullParserException;
62
63import java.io.IOException;
Alex Chaud3e8cc42022-05-03 17:45:34 +010064import java.io.PrintWriter;
65import java.io.StringWriter;
Alex Chau1c883d82021-12-01 18:43:10 +000066import java.lang.annotation.Retention;
67import java.lang.annotation.RetentionPolicy;
Adam Cohen2e6da152015-05-06 11:42:25 -070068import java.util.ArrayList;
Sunny Goyal6e6f7992021-08-24 16:23:29 -070069import java.util.Arrays;
Sunny Goyal6d55f662019-01-02 12:13:43 -080070import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070071import java.util.List;
Adam Cohen2e6da152015-05-06 11:42:25 -070072
73public class InvariantDeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070074
Hyunyoung Songc55a3502018-12-04 15:43:16 -080075 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070076 // We do not need any synchronization for this variable as its only written on UI thread.
77 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070078 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070079
Alex Chau1c883d82021-12-01 18:43:10 +000080 @Retention(RetentionPolicy.SOURCE)
81 @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET})
82 public @interface DeviceType{}
83 public static final int TYPE_PHONE = 0;
84 public static final int TYPE_MULTI_DISPLAY = 1;
85 public static final int TYPE_TABLET = 2;
86
Hyunyoung Songc55a3502018-12-04 15:43:16 -080087 private static final String KEY_IDP_GRID_NAME = "idp_grid_name";
Sunny Goyal415f1732018-11-29 10:33:47 -080088
Sunny Goyal53d7ee42015-05-22 12:25:45 -070089 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
90
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070091 // Constants that affects the interpolation curve between statically defined device profile
92 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080093 private static final float KNEARESTNEIGHBOR = 3;
94 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -070095
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070096 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080097 private static final float WEIGHT_EFFICIENT = 100000f;
98
Thales Lima83bedbf2021-10-05 17:47:39 +010099 // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different
100 // constraints
Thales Limabb7d3882021-12-22 12:56:29 +0000101 static final int COUNT_SIZES = 4;
Thales Lima83bedbf2021-10-05 17:47:39 +0100102 static final int INDEX_DEFAULT = 0;
103 static final int INDEX_LANDSCAPE = 1;
104 static final int INDEX_TWO_PANEL_PORTRAIT = 2;
105 static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
Thales Lima83bedbf2021-10-05 17:47:39 +0100106
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700107 /**
108 * Number of icons per row and column in the workspace.
109 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700110 public int numRows;
111 public int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000112 public int numSearchContainerColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700113
114 /**
115 * Number of icons per row and column in the folder.
116 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700117 public int numFolderRows;
118 public int numFolderColumns;
Thales Lima83bedbf2021-10-05 17:47:39 +0100119 public float[] iconSize;
120 public float[] iconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700121 public int iconBitmapSize;
122 public int fillResIconDpi;
Alex Chau1c883d82021-12-01 18:43:10 +0000123 public @DeviceType int deviceType;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700124
Thales Lima83bedbf2021-10-05 17:47:39 +0100125 public PointF[] minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100126
Thales Lima83bedbf2021-10-05 17:47:39 +0100127 public PointF[] borderSpaces;
Thales Lima78d00ad2021-09-30 11:29:06 +0100128 public float folderBorderSpace;
Thales Lima6e7f36c2022-01-04 12:14:11 +0000129 public float[] hotseatBorderSpaces;
Thales Lima828875c2022-04-26 20:29:30 +0100130 public int[] hotseatColumnSpan;
Thales Lima78d00ad2021-09-30 11:29:06 +0100131
Thales Lima83bedbf2021-10-05 17:47:39 +0100132 public float[] horizontalMargin;
Jon Mirandae126d722021-02-25 10:45:20 -0500133
Thales Limab7ef5692022-03-10 10:32:36 +0000134 public PointF[] allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000135 public float[] allAppsIconSize;
136 public float[] allAppsIconTextSize;
137 public PointF[] allAppsBorderSpaces;
138
Sunny Goyal5bc18462019-01-07 15:13:39 -0800139 private SparseArray<TypedValue> mExtraAttrs;
140
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700141 /**
142 * Number of icons inside the hotseat area.
143 */
Jon Mirandafd48b0c2022-01-31 16:25:22 -0800144 public int numShownHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700145
146 /**
Alex Chau6ed408f2022-03-04 12:58:05 +0000147 * Number of icons inside the hotseat area when using 3 buttons navigation.
148 */
149 public int numShrunkenHotseatIcons;
150
151 /**
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700152 * Number of icons inside the hotseat area that is stored in the database. This is greater than
153 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
154 * sizes that share the same DB.
155 */
156 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700157
Jon Miranda6f7e9702019-09-16 14:44:14 -0700158 /**
159 * Number of columns in the all apps list.
160 */
161 public int numAllAppsColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700162 public int numDatabaseAllAppsColumns;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700163
Jon Mirandae126d722021-02-25 10:45:20 -0500164 /**
165 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
166 */
167 protected boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400168 public int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500169
Tracy Zhou7df93d22020-01-27 13:44:06 -0800170 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800171 public int defaultLayoutId;
Adam Cohen27824492017-09-22 17:10:55 -0700172 int demoModeLayoutId;
Thales Lima12d0eff2022-03-25 17:06:11 +0000173 boolean[] inlineQsb = new boolean[COUNT_SIZES];
Adam Cohen2e6da152015-05-06 11:42:25 -0700174
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000175 /**
176 * An immutable list of supported profiles.
177 */
178 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700179
sfufa@google.comde013292021-09-21 18:22:44 -0700180 @Nullable
181 public DevicePaddings devicePaddings;
Jon Miranda228877d2021-02-09 11:05:00 -0500182
Sunny Goyal6f866092016-03-17 17:04:15 -0700183 public Point defaultWallpaperSize;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700184 public Rect defaultWidgetPadding;
Sunny Goyal6f866092016-03-17 17:04:15 -0700185
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700186 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700187
Sunny Goyalf633ef52018-03-13 09:57:05 -0700188 @VisibleForTesting
Sunny Goyal187b16c2022-03-01 16:53:23 -0800189 public InvariantDeviceProfile() { }
Adam Cohen2e6da152015-05-06 11:42:25 -0700190
Sunny Goyalbbf01842015-10-08 07:41:15 -0700191 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700192 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700193 String gridName = getCurrentGridName(context);
194 String newGridName = initGrid(context, gridName);
195 if (!newGridName.equals(gridName)) {
196 Utilities.getPrefs(context).edit().putString(KEY_IDP_GRID_NAME, newGridName).apply();
197 }
Sunny Goyal68031ca2021-08-02 12:23:44 -0700198 new DeviceGridState(this).writeToPrefs(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700199
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700200 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100201 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000202 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
203 | CHANGE_NAVIGATION_MODE)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100204 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700205 }
206 });
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700207 }
208
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700209 /**
210 * This constructor should NOT have any monitors by design.
211 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800212 public InvariantDeviceProfile(Context context, String gridName) {
213 String newName = initGrid(context, gridName);
214 if (newName == null || !newName.equals(gridName)) {
215 throw new IllegalArgumentException("Unknown grid name");
216 }
217 }
218
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700219 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800220 * This constructor should NOT have any monitors by design.
221 */
222 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700223 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100224 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700225 String gridName = getCurrentGridName(context);
226
227 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000228 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
229 @DeviceType int defaultDeviceType = getDeviceType(defaultInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700230 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000231 defaultInfo,
232 getPredefinedDeviceProfiles(context, gridName, defaultDeviceType,
233 /*allowDisabledGrid=*/false),
234 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700235
Alex Chau417bd722021-01-26 15:22:18 +0000236 Info myInfo = new Info(context, display);
Alex Chau1c883d82021-12-01 18:43:10 +0000237 @DeviceType int deviceType = getDeviceType(myInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700238 DisplayOption myDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000239 myInfo,
240 getPredefinedDeviceProfiles(context, gridName, deviceType,
241 /*allowDisabledGrid=*/false),
242 deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700243
244 DisplayOption result = new DisplayOption(defaultDisplayOption.grid)
245 .add(myDisplayOption);
Thales Lima83bedbf2021-10-05 17:47:39 +0100246 result.iconSizes[INDEX_DEFAULT] =
247 defaultDisplayOption.iconSizes[INDEX_DEFAULT];
248 for (int i = 1; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700249 result.iconSizes[i] = Math.min(
250 defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]);
Alex Chau7c439722021-03-24 11:32:44 +0000251 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700252
Thales Lima83bedbf2021-10-05 17:47:39 +0100253 System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0,
254 COUNT_SIZES);
255 System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0,
256 COUNT_SIZES);
Thales Lima12d0eff2022-03-25 17:06:11 +0000257 System.arraycopy(defaultDisplayOption.inlineQsb, 0, result.inlineQsb, 0,
258 COUNT_SIZES);
Jon Miranda228877d2021-02-09 11:05:00 -0500259
Alex Chau1c883d82021-12-01 18:43:10 +0000260 initGrid(context, myInfo, result, deviceType);
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800261 }
262
Alex Chau238aaee2021-10-06 16:15:24 +0100263 /**
264 * Reinitialize the current grid after a restore, where some grids might now be disabled.
265 */
266 public void reinitializeAfterRestore(Context context) {
Alex Chau29a96ad2022-02-10 13:12:20 +0000267 String currentGridName = getCurrentGridName(context);
Alex Chau238aaee2021-10-06 16:15:24 +0100268 String currentDbFile = dbFile;
Alex Chau29a96ad2022-02-10 13:12:20 +0000269 String newGridName = initGrid(context, currentGridName);
270 String newDbFile = dbFile;
271 if (!newDbFile.equals(currentDbFile)) {
272 Log.d(TAG, "Restored grid is disabled : " + currentGridName
Alex Chau238aaee2021-10-06 16:15:24 +0100273 + ", migrating to: " + newGridName
274 + ", removing all other grid db files");
275 for (String gridDbFile : LauncherFiles.GRID_DB_FILES) {
276 if (gridDbFile.equals(currentDbFile)) {
277 continue;
278 }
279 if (context.getDatabasePath(gridDbFile).delete()) {
280 Log.d(TAG, "Removed old grid db file: " + gridDbFile);
281 }
282 }
Alex Chau29a96ad2022-02-10 13:12:20 +0000283 setCurrentGrid(context, newGridName);
Alex Chau238aaee2021-10-06 16:15:24 +0100284 }
285 }
286
Alex Chau1c883d82021-12-01 18:43:10 +0000287 private static @DeviceType int getDeviceType(Info displayInfo) {
Sunny Goyal187b16c2022-03-01 16:53:23 -0800288 int flagPhone = 1 << 0;
289 int flagTablet = 1 << 1;
290
291 int type = displayInfo.supportedBounds.stream()
292 .mapToInt(bounds -> displayInfo.isTablet(bounds) ? flagTablet : flagPhone)
293 .reduce(0, (a, b) -> a | b);
294 if ((type == (flagPhone | flagTablet)) && ENABLE_TWO_PANEL_HOME.get()) {
295 // device has profiles supporting both phone and table modes
Alex Chau1c883d82021-12-01 18:43:10 +0000296 return TYPE_MULTI_DISPLAY;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800297 } else if (type == flagTablet) {
Alex Chau1c883d82021-12-01 18:43:10 +0000298 return TYPE_TABLET;
299 } else {
300 return TYPE_PHONE;
301 }
302 }
303
Tracy Zhou42255d22020-03-13 00:38:11 -0700304 public static String getCurrentGridName(Context context) {
Tracy Zhouc6060e62020-04-27 13:05:34 -0700305 return Utilities.isGridOptionsEnabled(context)
306 ? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null;
Tracy Zhou42255d22020-03-13 00:38:11 -0700307 }
308
Sunny Goyaleff44f32019-01-09 17:29:49 -0800309 private String initGrid(Context context, String gridName) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700310 Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();
Alex Chau1c883d82021-12-01 18:43:10 +0000311 @DeviceType int deviceType = getDeviceType(displayInfo);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700312
313 ArrayList<DisplayOption> allOptions =
Alex Chau1c883d82021-12-01 18:43:10 +0000314 getPredefinedDeviceProfiles(context, gridName, deviceType,
Alex Chau238aaee2021-10-06 16:15:24 +0100315 RestoreDbTask.isPending(context));
Sunny Goyal19ff7282021-04-22 10:12:54 -0700316 DisplayOption displayOption =
Alex Chau1c883d82021-12-01 18:43:10 +0000317 invDistWeightedInterpolate(displayInfo, allOptions, deviceType);
318 initGrid(context, displayInfo, displayOption, deviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700319 return displayOption.grid.name;
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800320 }
Adam Cohen2e6da152015-05-06 11:42:25 -0700321
Alex Chau1c883d82021-12-01 18:43:10 +0000322 private void initGrid(Context context, Info displayInfo, DisplayOption displayOption,
323 @DeviceType int deviceType) {
Sunny Goyal35c7b192021-04-20 16:51:10 -0700324 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700325 GridOption closestProfile = displayOption.grid;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000326 numRows = closestProfile.numRows;
327 numColumns = closestProfile.numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000328 numSearchContainerColumns = closestProfile.numSearchContainerColumns;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000329 dbFile = closestProfile.dbFile;
330 defaultLayoutId = closestProfile.defaultLayoutId;
331 demoModeLayoutId = closestProfile.demoModeLayoutId;
332 numFolderRows = closestProfile.numFolderRows;
333 numFolderColumns = closestProfile.numFolderColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500334 isScalable = closestProfile.isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400335 devicePaddingId = closestProfile.devicePaddingId;
Alex Chau1c883d82021-12-01 18:43:10 +0000336 this.deviceType = deviceType;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000337
338 mExtraAttrs = closestProfile.extraAttrs;
339
Thales Lima83bedbf2021-10-05 17:47:39 +0100340 iconSize = displayOption.iconSizes;
Thales Lima6e0005a2021-10-27 15:53:41 +0100341 float maxIconSize = iconSize[0];
342 for (int i = 1; i < iconSize.length; i++) {
343 maxIconSize = Math.max(maxIconSize, iconSize[i]);
344 }
345 iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics);
Sunny Goyalae190ff2020-04-14 00:19:01 +0000346 fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
347
Thales Lima83bedbf2021-10-05 17:47:39 +0100348 iconTextSize = displayOption.textSizes;
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700349
Thales Lima83bedbf2021-10-05 17:47:39 +0100350 minCellSize = displayOption.minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100351
Thales Lima83bedbf2021-10-05 17:47:39 +0100352 borderSpaces = displayOption.borderSpaces;
Thales Lima78d00ad2021-09-30 11:29:06 +0100353 folderBorderSpace = displayOption.folderBorderSpace;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700354
Thales Limad90faab2021-09-21 17:18:47 +0100355 horizontalMargin = displayOption.horizontalMargin;
Thales Limad90faab2021-09-21 17:18:47 +0100356
Sunny Goyal19ff7282021-04-22 10:12:54 -0700357 numShownHotseatIcons = closestProfile.numHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000358 numShrunkenHotseatIcons = closestProfile.numShrunkenHotseatIcons;
Alex Chau1c883d82021-12-01 18:43:10 +0000359 numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700360 ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons;
Thales Lima6e7f36c2022-01-04 12:14:11 +0000361 hotseatBorderSpaces = displayOption.hotseatBorderSpaces;
Thales Lima828875c2022-04-26 20:29:30 +0100362 hotseatColumnSpan = displayOption.hotseatColumnSpan;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700363
364 numAllAppsColumns = closestProfile.numAllAppsColumns;
Alex Chau1c883d82021-12-01 18:43:10 +0000365 numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
Sunny Goyal19ff7282021-04-22 10:12:54 -0700366 ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
Jon Mirandae126d722021-02-25 10:45:20 -0500367
Thales Limab7ef5692022-03-10 10:32:36 +0000368 allAppsCellSize = displayOption.allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000369 allAppsBorderSpaces = displayOption.allAppsBorderSpaces;
370 allAppsIconSize = displayOption.allAppsIconSizes;
371 allAppsIconTextSize = displayOption.allAppsIconTextSizes;
Thales Lima83bedbf2021-10-05 17:47:39 +0100372 if (!Utilities.isGridOptionsEnabled(context)) {
Thales Limabb7d3882021-12-22 12:56:29 +0000373 allAppsIconSize = iconSize;
374 allAppsIconTextSize = iconTextSize;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000375 }
376
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400377 if (devicePaddingId != 0) {
378 devicePaddings = new DevicePaddings(context, devicePaddingId);
379 }
380
Thales Lima12d0eff2022-03-25 17:06:11 +0000381 inlineQsb = displayOption.inlineQsb;
382
Sunny Goyalae190ff2020-04-14 00:19:01 +0000383 // If the partner customization apk contains any grid overrides, apply them
384 // Supported overrides: numRows, numColumns, iconSize
Sunny Goyal35c7b192021-04-20 16:51:10 -0700385 applyPartnerDeviceProfileOverrides(context, metrics);
Sunny Goyalc6205602015-05-21 20:46:33 -0700386
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000387 final List<DeviceProfile> localSupportedProfiles = new ArrayList<>();
Sunny Goyal19ff7282021-04-22 10:12:54 -0700388 defaultWallpaperSize = new Point(displayInfo.currentSize);
389 for (WindowBounds bounds : displayInfo.supportedBounds) {
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000390 localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo)
Alex Chau1c883d82021-12-01 18:43:10 +0000391 .setUseTwoPanels(deviceType == TYPE_MULTI_DISPLAY)
Alex Chau6ed408f2022-03-04 12:58:05 +0000392 .setWindowBounds(bounds)
393 .build());
Sunny Goyalc6205602015-05-21 20:46:33 -0700394
Sunny Goyal19ff7282021-04-22 10:12:54 -0700395 // Wallpaper size should be the maximum of the all possible sizes Launcher expects
396 int displayWidth = bounds.bounds.width();
397 int displayHeight = bounds.bounds.height();
398 defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700399
Sunny Goyal19ff7282021-04-22 10:12:54 -0700400 // We need to ensure that there is enough extra space in the wallpaper
401 // for the intended parallax effects
402 float parallaxFactor =
Thales Lima828875c2022-04-26 20:29:30 +0100403 dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.getDensityDpi())
404 < 720
Sunny Goyal19ff7282021-04-22 10:12:54 -0700405 ? 2
406 : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight);
407 defaultWallpaperSize.x =
408 Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth));
Sunny Goyal6f866092016-03-17 17:04:15 -0700409 }
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000410 supportedProfiles = Collections.unmodifiableList(localSupportedProfiles);
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700411
412 ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName());
413 defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
Adam Cohen2e6da152015-05-06 11:42:25 -0700414 }
415
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700416 public void addOnChangeListener(OnIDPChangeListener listener) {
417 mChangeListeners.add(listener);
418 }
419
Hyunyoung Songb4d1ca42019-01-08 17:15:16 -0800420 public void removeOnChangeListener(OnIDPChangeListener listener) {
421 mChangeListeners.remove(listener);
422 }
423
Hyunyoung Songc55a3502018-12-04 15:43:16 -0800424
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800425 public void setCurrentGrid(Context context, String gridName) {
426 Context appContext = context.getApplicationContext();
427 Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply();
Sunny Goyal6fe3eec2019-08-15 14:53:41 -0700428 MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext));
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800429 }
430
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700431 private Object[] toModelState() {
sfufa@google.comde013292021-09-21 18:22:44 -0700432 return new Object[]{
Alex Chau9fee3fd2021-12-01 18:43:10 +0000433 numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
434 iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile};
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700435 }
436
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700437 private void onConfigChanged(Context context) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700438 Object[] oldState = toModelState();
439
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700440 // Re-init grid
Tracy Zhouc6060e62020-04-27 13:05:34 -0700441 String gridName = getCurrentGridName(context);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700442 initGrid(context, gridName);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700443
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700444 boolean modelPropsChanged = !Arrays.equals(oldState, toModelState());
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700445 for (OnIDPChangeListener listener : mChangeListeners) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700446 listener.onIdpChanged(modelPropsChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700447 }
448 }
449
Alex Chau1c883d82021-12-01 18:43:10 +0000450 private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context,
451 String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800452 ArrayList<DisplayOption> profiles = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100453
Alex Chau1c883d82021-12-01 18:43:10 +0000454 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700455 final int depth = parser.getDepth();
456 int type;
Sunny Goyal819e1932016-07-07 16:43:58 -0700457 while (((type = parser.next()) != XmlPullParser.END_TAG ||
458 parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800459 if ((type == XmlPullParser.START_TAG)
460 && GridOption.TAG_NAME.equals(parser.getName())) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800461
Alex Chau1c883d82021-12-01 18:43:10 +0000462 GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser),
463 deviceType);
Alex Chau238aaee2021-10-06 16:15:24 +0100464 if (gridOption.isEnabled || allowDisabledGrid) {
Thales Lima7ec83822021-08-05 13:32:10 +0100465 final int displayDepth = parser.getDepth();
466 while (((type = parser.next()) != XmlPullParser.END_TAG
467 || parser.getDepth() > displayDepth)
468 && type != XmlPullParser.END_DOCUMENT) {
469 if ((type == XmlPullParser.START_TAG) && "display-option".equals(
470 parser.getName())) {
471 profiles.add(new DisplayOption(gridOption, context,
Thales Lima1de4d552021-10-13 16:13:25 +0100472 Xml.asAttributeSet(parser)));
Thales Lima7ec83822021-08-05 13:32:10 +0100473 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800474 }
475 }
Sunny Goyal819e1932016-07-07 16:43:58 -0700476 }
477 }
sfufa@google.comde013292021-09-21 18:22:44 -0700478 } catch (IOException | XmlPullParserException e) {
Sunny Goyal819e1932016-07-07 16:43:58 -0700479 throw new RuntimeException(e);
480 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800481
Sunny Goyalae190ff2020-04-14 00:19:01 +0000482 ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
Sunny Goyal415f1732018-11-29 10:33:47 -0800483 if (!TextUtils.isEmpty(gridName)) {
484 for (DisplayOption option : profiles) {
Alex Chau238aaee2021-10-06 16:15:24 +0100485 if (gridName.equals(option.grid.name)
486 && (option.grid.isEnabled || allowDisabledGrid)) {
Sunny Goyalae190ff2020-04-14 00:19:01 +0000487 filteredProfiles.add(option);
Sunny Goyal415f1732018-11-29 10:33:47 -0800488 }
489 }
490 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000491 if (filteredProfiles.isEmpty()) {
492 // No grid found, use the default options
493 for (DisplayOption option : profiles) {
494 if (option.canBeDefault) {
495 filteredProfiles.add(option);
496 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800497 }
498 }
Sunny Goyalae190ff2020-04-14 00:19:01 +0000499 if (filteredProfiles.isEmpty()) {
500 throw new RuntimeException("No display option with canBeDefault=true");
501 }
502 return filteredProfiles;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700503 }
504
Thales Lima7ec83822021-08-05 13:32:10 +0100505 /**
506 * @return all the grid options that can be shown on the device
507 */
508 public List<GridOption> parseAllGridOptions(Context context) {
509 List<GridOption> result = new ArrayList<>();
Thales Lima1de4d552021-10-13 16:13:25 +0100510
Alex Chau1c883d82021-12-01 18:43:10 +0000511 try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
Thales Lima7ec83822021-08-05 13:32:10 +0100512 final int depth = parser.getDepth();
513 int type;
514 while (((type = parser.next()) != XmlPullParser.END_TAG
515 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
516 if ((type == XmlPullParser.START_TAG)
517 && GridOption.TAG_NAME.equals(parser.getName())) {
518 GridOption option =
Alex Chau1c883d82021-12-01 18:43:10 +0000519 new GridOption(context, Xml.asAttributeSet(parser), deviceType);
Thales Lima7ec83822021-08-05 13:32:10 +0100520 if (option.isEnabled) {
521 result.add(option);
522 }
523 }
524 }
525 } catch (IOException | XmlPullParserException e) {
526 Log.e(TAG, "Error parsing device profile", e);
527 return Collections.emptyList();
528 }
529 return result;
530 }
531
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700532 private int getLauncherIconDensity(int requiredSize) {
533 // Densities typically defined by an app.
sfufa@google.comde013292021-09-21 18:22:44 -0700534 int[] densityBuckets = new int[]{
Sunny Goyal53d7ee42015-05-22 12:25:45 -0700535 DisplayMetrics.DENSITY_LOW,
536 DisplayMetrics.DENSITY_MEDIUM,
537 DisplayMetrics.DENSITY_TV,
538 DisplayMetrics.DENSITY_HIGH,
539 DisplayMetrics.DENSITY_XHIGH,
540 DisplayMetrics.DENSITY_XXHIGH,
541 DisplayMetrics.DENSITY_XXXHIGH
542 };
543
544 int density = DisplayMetrics.DENSITY_XXXHIGH;
545 for (int i = densityBuckets.length - 1; i >= 0; i--) {
546 float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i]
547 / DisplayMetrics.DENSITY_DEFAULT;
548 if (expectedSize >= requiredSize) {
549 density = densityBuckets[i];
550 }
551 }
552
553 return density;
554 }
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700555
Adam Cohen2e6da152015-05-06 11:42:25 -0700556 /**
557 * Apply any Partner customization grid overrides.
558 *
559 * Currently we support: all apps row / column count.
560 */
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700561 private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) {
562 Partner p = Partner.get(context.getPackageManager());
Adam Cohen2e6da152015-05-06 11:42:25 -0700563 if (p != null) {
564 p.applyInvariantDeviceProfileOverrides(this, dm);
565 }
566 }
567
Sunny Goyal415f1732018-11-29 10:33:47 -0800568 private static float dist(float x0, float y0, float x1, float y1) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700569 return (float) Math.hypot(x1 - x0, y1 - y0);
Adam Cohen2e6da152015-05-06 11:42:25 -0700570 }
571
Sunny Goyal19ff7282021-04-22 10:12:54 -0700572 private static DisplayOption invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000573 Info displayInfo, ArrayList<DisplayOption> points, @DeviceType int deviceType) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700574 int minWidthPx = Integer.MAX_VALUE;
575 int minHeightPx = Integer.MAX_VALUE;
576 for (WindowBounds bounds : displayInfo.supportedBounds) {
577 boolean isTablet = displayInfo.isTablet(bounds);
Alex Chau1c883d82021-12-01 18:43:10 +0000578 if (isTablet && deviceType == TYPE_MULTI_DISPLAY) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700579 // For split displays, take half width per page
580 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2);
581 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700582
Sunny Goyal19ff7282021-04-22 10:12:54 -0700583 } else if (!isTablet && bounds.isLandscape()) {
584 // We will use transposed layout in this case
585 minWidthPx = Math.min(minWidthPx, bounds.availableSize.y);
586 minHeightPx = Math.min(minHeightPx, bounds.availableSize.x);
587 } else {
588 minWidthPx = Math.min(minWidthPx, bounds.availableSize.x);
589 minHeightPx = Math.min(minHeightPx, bounds.availableSize.y);
590 }
591 }
592
Thales Lima828875c2022-04-26 20:29:30 +0100593 float width = dpiFromPx(minWidthPx, displayInfo.getDensityDpi());
594 float height = dpiFromPx(minHeightPx, displayInfo.getDensityDpi());
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700595
596 // Sort the profiles based on the closeness to the device size
597 Collections.sort(points, (a, b) ->
598 Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps),
599 dist(width, height, b.minWidthDps, b.minHeightDps)));
600
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700601 DisplayOption closestPoint = points.get(0);
602 GridOption closestOption = closestPoint.grid;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700603 float weights = 0;
604
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700605 if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) {
606 return closestPoint;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700607 }
608
609 DisplayOption out = new DisplayOption(closestOption);
610 for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700611 DisplayOption p = points.get(i);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700612 float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
613 weights += w;
614 out.add(new DisplayOption().add(p).multiply(w));
615 }
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700616 out.multiply(1.0f / weights);
617
Thales Lima6e0005a2021-10-27 15:53:41 +0100618 // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700619 // predefined size to avoid cache invalidation
Thales Lima6e0005a2021-10-27 15:53:41 +0100620 for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) {
621 out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700622 }
623
624 return out;
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700625 }
626
Sunny Goyal27835952017-01-13 12:15:53 -0800627 public DeviceProfile getDeviceProfile(Context context) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700628 Resources res = context.getResources();
629 Configuration config = context.getResources().getConfiguration();
630
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400631 float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density;
632 float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density;
Alex Chaud3e8cc42022-05-03 17:45:34 +0100633 int rotation = WindowManagerProxy.INSTANCE.get(context).getRotation(context);
634
635 if (Utilities.IS_DEBUG_DEVICE) {
636 StringWriter stringWriter = new StringWriter();
637 PrintWriter printWriter = new PrintWriter(stringWriter);
638 DisplayController.INSTANCE.get(context).dump(printWriter);
639 printWriter.flush();
640 Log.d("b/231312158", "getDeviceProfile -"
641 + "\nconfig: " + config
642 + "\ndisplayMetrics: " + res.getDisplayMetrics()
643 + "\nrotation: " + rotation
644 + "\n" + stringWriter.toString(),
645 new Exception());
646 }
647 return getBestMatch(screenWidth, screenHeight, rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400648 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700649
Sunny Goyal187b16c2022-03-01 16:53:23 -0800650 /**
651 * Returns the device profile matching the provided screen configuration
652 */
653 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700654 DeviceProfile bestMatch = supportedProfiles.get(0);
655 float minDiff = Float.MAX_VALUE;
656
657 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400658 float diff = Math.abs(profile.widthPx - screenWidth)
659 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700660 if (diff < minDiff) {
661 minDiff = diff;
662 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800663 } else if (diff == minDiff && profile.rotationHint == rotation) {
664 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700665 }
666 }
667 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800668 }
669
Sunny Goyal415f1732018-11-29 10:33:47 -0800670 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700671 float d = dist(x0, y0, x1, y1);
672 if (Float.compare(d, 0f) == 0) {
673 return Float.POSITIVE_INFINITY;
674 }
675 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
676 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700677
678 /**
679 * As a ratio of screen height, the total distance we want the parallax effect to span
680 * horizontally
681 */
682 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
683 float aspectRatio = width / (float) height;
684
685 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
686 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
687 // We will use these two data points to extrapolate how much the wallpaper parallax effect
688 // to span (ie travel) at any aspect ratio:
689
sfufa@google.comde013292021-09-21 18:22:44 -0700690 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
691 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700692 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
693 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
694
695 // To find out the desired width at different aspect ratios, we use the following two
696 // formulas, where the coefficient on x is the aspect ratio (width/height):
697 // (16/10)x + y = 1.5
698 // (10/16)x + y = 1.2
699 // We solve for x and y and end up with a final formula:
700 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700701 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
702 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700703 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
704 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
705 return x * aspectRatio + y;
706 }
707
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700708 public interface OnIDPChangeListener {
709
Sunny Goyalb47172b2021-05-03 19:59:51 -0700710 /**
711 * Called when the device provide changes
712 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700713 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700714 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800715
716
Sunny Goyaleff44f32019-01-09 17:29:49 -0800717 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800718
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800719 public static final String TAG_NAME = "grid-option";
720
Alex Chau1c883d82021-12-01 18:43:10 +0000721 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
722 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
723 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
724 private static final int DEVICE_CATEGORY_ALL =
725 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
726
Sunny Goyaleff44f32019-01-09 17:29:49 -0800727 public final String name;
728 public final int numRows;
729 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000730 public final int numSearchContainerColumns;
Thales Lima7ec83822021-08-05 13:32:10 +0100731 public final boolean isEnabled;
Sunny Goyal415f1732018-11-29 10:33:47 -0800732
733 private final int numFolderRows;
734 private final int numFolderColumns;
735
Sunny Goyal19ff7282021-04-22 10:12:54 -0700736 private final int numAllAppsColumns;
737 private final int numDatabaseAllAppsColumns;
738 private final int numHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000739 private final int numShrunkenHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700740 private final int numDatabaseHotseatIcons;
Sunny Goyal415f1732018-11-29 10:33:47 -0800741
Tracy Zhou7df93d22020-01-27 13:44:06 -0800742 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000743
Sunny Goyal415f1732018-11-29 10:33:47 -0800744 private final int defaultLayoutId;
745 private final int demoModeLayoutId;
746
Jon Mirandae126d722021-02-25 10:45:20 -0500747 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400748 private final int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500749
Sunny Goyal5bc18462019-01-07 15:13:39 -0800750 private final SparseArray<TypedValue> extraAttrs;
751
Alex Chau1c883d82021-12-01 18:43:10 +0000752 public GridOption(Context context, AttributeSet attrs, @DeviceType int deviceType) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800753 TypedArray a = context.obtainStyledAttributes(
754 attrs, R.styleable.GridDisplayOption);
755 name = a.getString(R.styleable.GridDisplayOption_name);
756 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
757 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000758 numSearchContainerColumns = a.getInt(
759 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal415f1732018-11-29 10:33:47 -0800760
Tracy Zhou7df93d22020-01-27 13:44:06 -0800761 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Alex Chau1c883d82021-12-01 18:43:10 +0000762 defaultLayoutId = a.getResourceId(deviceType == TYPE_MULTI_DISPLAY && a.hasValue(
Alex Chau1e448462021-08-13 21:48:35 +0100763 R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId)
764 ? R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId
765 : R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800766 demoModeLayoutId = a.getResourceId(
767 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700768
769 numAllAppsColumns = a.getInt(
770 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
771 numDatabaseAllAppsColumns = a.getInt(
772 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
773
774 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800775 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Alex Chau6ed408f2022-03-04 12:58:05 +0000776 numShrunkenHotseatIcons = a.getInt(
777 R.styleable.GridDisplayOption_numShrunkenHotseatIcons, numHotseatIcons / 2);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700778 numDatabaseHotseatIcons = a.getInt(
779 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
780
Sunny Goyal415f1732018-11-29 10:33:47 -0800781 numFolderRows = a.getInt(
782 R.styleable.GridDisplayOption_numFolderRows, numRows);
783 numFolderColumns = a.getInt(
784 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700785
Jon Mirandae126d722021-02-25 10:45:20 -0500786 isScalable = a.getBoolean(
787 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400788 devicePaddingId = a.getResourceId(
789 R.styleable.GridDisplayOption_devicePaddingId, 0);
Jon Mirandae126d722021-02-25 10:45:20 -0500790
Alex Chau1c883d82021-12-01 18:43:10 +0000791 int deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
792 DEVICE_CATEGORY_ALL);
793 isEnabled = (deviceType == TYPE_PHONE
794 && ((deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE))
795 || (deviceType == TYPE_TABLET
796 && ((deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET))
797 || (deviceType == TYPE_MULTI_DISPLAY
798 && ((deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
799 == DEVICE_CATEGORY_MULTI_DISPLAY));
Thales Lima7ec83822021-08-05 13:32:10 +0100800
Sunny Goyal415f1732018-11-29 10:33:47 -0800801 a.recycle();
Sunny Goyal5bc18462019-01-07 15:13:39 -0800802 extraAttrs = Themes.createValueMap(context, attrs,
803 IntArray.wrap(R.styleable.GridDisplayOption));
Sunny Goyal415f1732018-11-29 10:33:47 -0800804 }
805 }
806
Sunny Goyal19ff7282021-04-22 10:12:54 -0700807 @VisibleForTesting
808 static final class DisplayOption {
Thales Lima12d0eff2022-03-25 17:06:11 +0000809 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
810 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
811 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
812 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
813 private static final int DONT_INLINE_QSB = 0;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700814
815 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800816
Sunny Goyal415f1732018-11-29 10:33:47 -0800817 private final float minWidthDps;
818 private final float minHeightDps;
819 private final boolean canBeDefault;
Thales Lima12d0eff2022-03-25 17:06:11 +0000820 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800821
Thales Lima83bedbf2021-10-05 17:47:39 +0100822 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +0100823
824 private float folderBorderSpace;
825 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +0100826 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Lima828875c2022-04-26 20:29:30 +0100827 //TODO(http://b/228998082) remove this when 3 button spaces are fixed
Thales Lima6e7f36c2022-01-04 12:14:11 +0000828 private final float[] hotseatBorderSpaces = new float[COUNT_SIZES];
Thales Lima828875c2022-04-26 20:29:30 +0100829 private final int[] hotseatColumnSpan = new int[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +0100830
Thales Lima78d00ad2021-09-30 11:29:06 +0100831 private final float[] iconSizes = new float[COUNT_SIZES];
832 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800833
Thales Limab7ef5692022-03-10 10:32:36 +0000834 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +0000835 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
836 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
837 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
838
Thales Lima1de4d552021-10-13 16:13:25 +0100839 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800840 this.grid = grid;
841
Thales Lima1de4d552021-10-13 16:13:25 +0100842 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -0800843
Sunny Goyal415f1732018-11-29 10:33:47 -0800844 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
845 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700846
Thales Lima1de4d552021-10-13 16:13:25 +0100847 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -0800848
Thales Lima12d0eff2022-03-25 17:06:11 +0000849 int inlineForRotation = a.getInt(R.styleable.ProfileDisplayOption_inlineQsb,
850 DONT_INLINE_QSB);
851 inlineQsb[INDEX_DEFAULT] =
852 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
853 inlineQsb[INDEX_LANDSCAPE] =
854 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
855 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
856 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
857 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
858 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
859 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
860 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
861
Thales Lima83bedbf2021-10-05 17:47:39 +0100862 float x;
863 float y;
864
Thales Lima85c942f2021-12-31 13:04:20 +0000865 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
866 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +0100867 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +0000868
869 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
870 minCellSize[INDEX_DEFAULT].x);
871 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
872 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100873 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100874
Thales Lima85c942f2021-12-31 13:04:20 +0000875 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100876 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +0000877 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100878 minCellSize[INDEX_DEFAULT].y);
879 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
880
Thales Lima85c942f2021-12-31 13:04:20 +0000881 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100882 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +0000883 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100884 minCellSize[INDEX_DEFAULT].y);
885 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +0100886
Thales Lima85c942f2021-12-31 13:04:20 +0000887 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +0000888 float borderSpaceLandscape = a.getFloat(
889 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +0000890 float borderSpaceTwoPanelPortrait = a.getFloat(
891 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
892 float borderSpaceTwoPanelLandscape = a.getFloat(
893 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +0100894
Thales Lima85c942f2021-12-31 13:04:20 +0000895 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
896 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +0100897 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +0000898
899 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
900 borderSpaceLandscape);
901 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
902 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100903 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
904
905 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000906 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
907 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +0100908 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000909 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
910 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +0100911 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
912
913 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000914 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
915 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100916 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000917 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
918 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100919 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
920
Thales Limabb7d3882021-12-22 12:56:29 +0000921 folderBorderSpace = borderSpace;
922
Thales Limab7ef5692022-03-10 10:32:36 +0000923 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
924 minCellSize[INDEX_DEFAULT].x);
925 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
926 minCellSize[INDEX_DEFAULT].y);
927 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
928
929 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
930 allAppsCellSize[INDEX_DEFAULT].x);
931 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
932 allAppsCellSize[INDEX_DEFAULT].y);
933 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
934
935 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
936 allAppsCellSize[INDEX_DEFAULT].x);
937 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
938 allAppsCellSize[INDEX_DEFAULT].y);
939 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
940
941 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
942 allAppsCellSize[INDEX_DEFAULT].x);
943 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
944 allAppsCellSize[INDEX_DEFAULT].y);
945 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
946
Thales Lima080d8902022-03-28 15:30:29 +0100947 float allAppsBorderSpace = a.getFloat(
948 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
949 float allAppsBorderSpaceLandscape = a.getFloat(
950 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
951 allAppsBorderSpace);
952 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +0000953 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +0100954 allAppsBorderSpace);
955 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +0000956 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +0100957 allAppsBorderSpace);
958
959 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
960 allAppsBorderSpace);
961 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
962 allAppsBorderSpace);
963 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
964
965 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
966 allAppsBorderSpaceLandscape);
967 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
968 allAppsBorderSpaceLandscape);
969 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
970
971 x = a.getFloat(
972 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
973 allAppsBorderSpaceTwoPanelPortrait);
974 y = a.getFloat(
975 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
976 allAppsBorderSpaceTwoPanelPortrait);
977 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
978
979 x = a.getFloat(
980 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
981 allAppsBorderSpaceTwoPanelLandscape);
982 y = a.getFloat(
983 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
984 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +0000985 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -0500986
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700987 iconSizes[INDEX_DEFAULT] =
988 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
989 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +0000990 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700991 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700992 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +0000993 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700994 iconSizes[INDEX_DEFAULT]);
995 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +0000996 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100997 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700998
Thales Limabb7d3882021-12-22 12:56:29 +0000999 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
1000 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
1001 allAppsIconSizes[INDEX_LANDSCAPE] = allAppsIconSizes[INDEX_DEFAULT];
1002 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1003 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1004 allAppsIconSizes[INDEX_DEFAULT]);
1005 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1006 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1007 allAppsIconSizes[INDEX_DEFAULT]);
1008
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001009 textSizes[INDEX_DEFAULT] =
1010 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1011 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001012 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001013 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001014 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001015 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001016 textSizes[INDEX_DEFAULT]);
1017 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001018 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001019 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001020
Thales Limabb7d3882021-12-22 12:56:29 +00001021 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1022 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1023 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1024 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1025 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1026 allAppsIconTextSizes[INDEX_DEFAULT]);
1027 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1028 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1029 allAppsIconTextSizes[INDEX_DEFAULT]);
1030
Thales Lima83bedbf2021-10-05 17:47:39 +01001031 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1032 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001033 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1034 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1035 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001036 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001037 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001038 horizontalMargin[INDEX_DEFAULT]);
1039 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001040 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001041 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001042
Thales Lima6e7f36c2022-01-04 12:14:11 +00001043 hotseatBorderSpaces[INDEX_DEFAULT] = a.getFloat(
1044 R.styleable.ProfileDisplayOption_hotseatBorderSpace, borderSpace);
Thales Limadd027342022-01-07 12:54:37 +00001045 hotseatBorderSpaces[INDEX_LANDSCAPE] = a.getFloat(
1046 R.styleable.ProfileDisplayOption_hotseatBorderSpaceLandscape,
1047 hotseatBorderSpaces[INDEX_DEFAULT]);
Thales Lima6e7f36c2022-01-04 12:14:11 +00001048 hotseatBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1049 R.styleable.ProfileDisplayOption_hotseatBorderSpaceTwoPanelLandscape,
1050 hotseatBorderSpaces[INDEX_DEFAULT]);
1051 hotseatBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1052 R.styleable.ProfileDisplayOption_hotseatBorderSpaceTwoPanelPortrait,
1053 hotseatBorderSpaces[INDEX_DEFAULT]);
1054
Thales Lima828875c2022-04-26 20:29:30 +01001055 hotseatColumnSpan[INDEX_DEFAULT] = a.getInt(
1056 R.styleable.ProfileDisplayOption_hotseatColumnSpan, grid.numColumns);
1057 hotseatColumnSpan[INDEX_LANDSCAPE] = a.getInt(
1058 R.styleable.ProfileDisplayOption_hotseatColumnSpanLandscape, grid.numColumns);
1059 hotseatColumnSpan[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
1060 R.styleable.ProfileDisplayOption_hotseatColumnSpanTwoPanelLandscape,
1061 grid.numColumns);
1062 hotseatColumnSpan[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
1063 R.styleable.ProfileDisplayOption_hotseatColumnSpanTwoPanelPortrait,
1064 grid.numColumns);
1065
Sunny Goyal415f1732018-11-29 10:33:47 -08001066 a.recycle();
1067 }
1068
1069 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001070 this(null);
1071 }
1072
1073 DisplayOption(GridOption grid) {
1074 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001075 minWidthDps = 0;
1076 minHeightDps = 0;
1077 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001078 for (int i = 0; i < COUNT_SIZES; i++) {
1079 iconSizes[i] = 0;
1080 textSizes[i] = 0;
1081 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001082 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001083 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001084 allAppsIconSizes[i] = 0;
1085 allAppsIconTextSizes[i] = 0;
1086 allAppsBorderSpaces[i] = new PointF();
Thales Lima12d0eff2022-03-25 17:06:11 +00001087 inlineQsb[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001088 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001089 }
1090
1091 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001092 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001093 iconSizes[i] *= w;
1094 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001095 borderSpaces[i].x *= w;
1096 borderSpaces[i].y *= w;
1097 minCellSize[i].x *= w;
1098 minCellSize[i].y *= w;
1099 horizontalMargin[i] *= w;
Thales Lima6e7f36c2022-01-04 12:14:11 +00001100 hotseatBorderSpaces[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001101 allAppsCellSize[i].x *= w;
1102 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001103 allAppsIconSizes[i] *= w;
1104 allAppsIconTextSizes[i] *= w;
1105 allAppsBorderSpaces[i].x *= w;
1106 allAppsBorderSpaces[i].y *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001107 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001108
1109 folderBorderSpace *= w;
1110
Sunny Goyal415f1732018-11-29 10:33:47 -08001111 return this;
1112 }
1113
1114 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001115 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001116 iconSizes[i] += p.iconSizes[i];
1117 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001118 borderSpaces[i].x += p.borderSpaces[i].x;
1119 borderSpaces[i].y += p.borderSpaces[i].y;
1120 minCellSize[i].x += p.minCellSize[i].x;
1121 minCellSize[i].y += p.minCellSize[i].y;
1122 horizontalMargin[i] += p.horizontalMargin[i];
Thales Lima6e7f36c2022-01-04 12:14:11 +00001123 hotseatBorderSpaces[i] += p.hotseatBorderSpaces[i];
Thales Lima828875c2022-04-26 20:29:30 +01001124 hotseatColumnSpan[i] = p.hotseatColumnSpan[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001125 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1126 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001127 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1128 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1129 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1130 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Thales Lima12d0eff2022-03-25 17:06:11 +00001131 inlineQsb[i] |= p.inlineQsb[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001132 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001133
1134 folderBorderSpace += p.folderBorderSpace;
1135
Sunny Goyal415f1732018-11-29 10:33:47 -08001136 return this;
1137 }
1138 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001139}