blob: dacbe9254acdff36eeedb670111015289b1786f3 [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 Chau1c883d82021-12-01 18:43:10 +000064import java.lang.annotation.Retention;
65import java.lang.annotation.RetentionPolicy;
Adam Cohen2e6da152015-05-06 11:42:25 -070066import java.util.ArrayList;
Sunny Goyal6e6f7992021-08-24 16:23:29 -070067import java.util.Arrays;
Sunny Goyal6d55f662019-01-02 12:13:43 -080068import java.util.Collections;
Sunny Goyal19ff7282021-04-22 10:12:54 -070069import java.util.List;
Adam Cohen2e6da152015-05-06 11:42:25 -070070
71public class InvariantDeviceProfile {
Adam Cohen2e6da152015-05-06 11:42:25 -070072
Hyunyoung Songc55a3502018-12-04 15:43:16 -080073 public static final String TAG = "IDP";
Sunny Goyald0e360a2018-06-29 14:40:18 -070074 // We do not need any synchronization for this variable as its only written on UI thread.
75 public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
Sunny Goyal87dc48b2018-10-12 11:42:33 -070076 new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
Adam Cohen2e6da152015-05-06 11:42:25 -070077
Alex Chau1c883d82021-12-01 18:43:10 +000078 @Retention(RetentionPolicy.SOURCE)
79 @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET})
80 public @interface DeviceType{}
81 public static final int TYPE_PHONE = 0;
82 public static final int TYPE_MULTI_DISPLAY = 1;
83 public static final int TYPE_TABLET = 2;
84
Hyunyoung Songc55a3502018-12-04 15:43:16 -080085 private static final String KEY_IDP_GRID_NAME = "idp_grid_name";
Sunny Goyal415f1732018-11-29 10:33:47 -080086
Sunny Goyal53d7ee42015-05-22 12:25:45 -070087 private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
88
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070089 // Constants that affects the interpolation curve between statically defined device profile
90 // buckets.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080091 private static final float KNEARESTNEIGHBOR = 3;
92 private static final float WEIGHT_POWER = 5;
Adam Cohen2e6da152015-05-06 11:42:25 -070093
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -070094 // used to offset float not being able to express extremely small weights in extreme cases.
Hyunyoung Songc55a3502018-12-04 15:43:16 -080095 private static final float WEIGHT_EFFICIENT = 100000f;
96
Thales Lima83bedbf2021-10-05 17:47:39 +010097 // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different
98 // constraints
Thales Limabb7d3882021-12-22 12:56:29 +000099 static final int COUNT_SIZES = 4;
Thales Lima83bedbf2021-10-05 17:47:39 +0100100 static final int INDEX_DEFAULT = 0;
101 static final int INDEX_LANDSCAPE = 1;
102 static final int INDEX_TWO_PANEL_PORTRAIT = 2;
103 static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
Thales Lima83bedbf2021-10-05 17:47:39 +0100104
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700105 /**
106 * Number of icons per row and column in the workspace.
107 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700108 public int numRows;
109 public int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000110 public int numSearchContainerColumns;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700111
112 /**
113 * Number of icons per row and column in the folder.
114 */
Adam Cohen2e6da152015-05-06 11:42:25 -0700115 public int numFolderRows;
116 public int numFolderColumns;
Thales Lima83bedbf2021-10-05 17:47:39 +0100117 public float[] iconSize;
118 public float[] iconTextSize;
Sunny Goyalfc218302015-09-17 14:59:10 -0700119 public int iconBitmapSize;
120 public int fillResIconDpi;
Alex Chau1c883d82021-12-01 18:43:10 +0000121 public @DeviceType int deviceType;
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700122
Thales Lima83bedbf2021-10-05 17:47:39 +0100123 public PointF[] minCellSize;
Thales Lima78d00ad2021-09-30 11:29:06 +0100124
Thales Lima83bedbf2021-10-05 17:47:39 +0100125 public PointF[] borderSpaces;
Thales Lima78d00ad2021-09-30 11:29:06 +0100126 public float folderBorderSpace;
Thales Lima6e7f36c2022-01-04 12:14:11 +0000127 public float[] hotseatBorderSpaces;
Thales Lima78d00ad2021-09-30 11:29:06 +0100128
Thales Lima83bedbf2021-10-05 17:47:39 +0100129 public float[] horizontalMargin;
Jon Mirandae126d722021-02-25 10:45:20 -0500130
Thales Limab7ef5692022-03-10 10:32:36 +0000131 public PointF[] allAppsCellSize;
Thales Limabb7d3882021-12-22 12:56:29 +0000132 public float[] allAppsIconSize;
133 public float[] allAppsIconTextSize;
134 public PointF[] allAppsBorderSpaces;
135
Sunny Goyal5bc18462019-01-07 15:13:39 -0800136 private SparseArray<TypedValue> mExtraAttrs;
137
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700138 /**
139 * Number of icons inside the hotseat area.
140 */
Jon Mirandafd48b0c2022-01-31 16:25:22 -0800141 public int numShownHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700142
143 /**
Alex Chau6ed408f2022-03-04 12:58:05 +0000144 * Number of icons inside the hotseat area when using 3 buttons navigation.
145 */
146 public int numShrunkenHotseatIcons;
147
148 /**
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700149 * Number of icons inside the hotseat area that is stored in the database. This is greater than
150 * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat
151 * sizes that share the same DB.
152 */
153 public int numDatabaseHotseatIcons;
Adam Cohen27824492017-09-22 17:10:55 -0700154
Thales Lima425f6822022-05-10 13:44:58 -0300155 public int[] hotseatColumnSpan;
156
Jon Miranda6f7e9702019-09-16 14:44:14 -0700157 /**
158 * Number of columns in the all apps list.
159 */
160 public int numAllAppsColumns;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700161 public int numDatabaseAllAppsColumns;
Jon Miranda6f7e9702019-09-16 14:44:14 -0700162
Jon Mirandae126d722021-02-25 10:45:20 -0500163 /**
164 * Do not query directly. see {@link DeviceProfile#isScalableGrid}.
165 */
166 protected boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400167 public int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500168
Tracy Zhou7df93d22020-01-27 13:44:06 -0800169 public String dbFile;
Sunny Goyal415f1732018-11-29 10:33:47 -0800170 public int defaultLayoutId;
Adam Cohen27824492017-09-22 17:10:55 -0700171 int demoModeLayoutId;
Thales Lima12d0eff2022-03-25 17:06:11 +0000172 boolean[] inlineQsb = new boolean[COUNT_SIZES];
Adam Cohen2e6da152015-05-06 11:42:25 -0700173
Pinyao Ting9cd63c92021-06-16 17:51:39 +0000174 /**
175 * An immutable list of supported profiles.
176 */
177 public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;
Sunny Goyalc6205602015-05-21 20:46:33 -0700178
sfufa@google.comde013292021-09-21 18:22:44 -0700179 @Nullable
180 public DevicePaddings devicePaddings;
Jon Miranda228877d2021-02-09 11:05:00 -0500181
Sunny Goyal6f866092016-03-17 17:04:15 -0700182 public Point defaultWallpaperSize;
Sunny Goyal58fa4b62019-03-22 16:23:25 -0700183 public Rect defaultWidgetPadding;
Sunny Goyal6f866092016-03-17 17:04:15 -0700184
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700185 private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700186
Sunny Goyalf633ef52018-03-13 09:57:05 -0700187 @VisibleForTesting
Sunny Goyal187b16c2022-03-01 16:53:23 -0800188 public InvariantDeviceProfile() { }
Adam Cohen2e6da152015-05-06 11:42:25 -0700189
Sunny Goyalbbf01842015-10-08 07:41:15 -0700190 @TargetApi(23)
Sunny Goyald0e360a2018-06-29 14:40:18 -0700191 private InvariantDeviceProfile(Context context) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700192 String gridName = getCurrentGridName(context);
193 String newGridName = initGrid(context, gridName);
194 if (!newGridName.equals(gridName)) {
195 Utilities.getPrefs(context).edit().putString(KEY_IDP_GRID_NAME, newGridName).apply();
196 }
Sunny Goyal68031ca2021-08-02 12:23:44 -0700197 new DeviceGridState(this).writeToPrefs(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700198
Tracy Zhouc8beebf2021-09-23 10:18:11 -0700199 DisplayController.INSTANCE.get(context).setPriorityListener(
Alex Chaufd6d9422021-04-22 19:10:21 +0100200 (displayContext, info, flags) -> {
Alex Chau6ed408f2022-03-04 12:58:05 +0000201 if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS
202 | CHANGE_NAVIGATION_MODE)) != 0) {
Alex Chaufd6d9422021-04-22 19:10:21 +0100203 onConfigChanged(displayContext);
Sunny Goyal35c7b192021-04-20 16:51:10 -0700204 }
205 });
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700206 }
207
Hyunyoung Songe11eb472019-03-19 15:05:21 -0700208 /**
209 * This constructor should NOT have any monitors by design.
210 */
Sunny Goyaleff44f32019-01-09 17:29:49 -0800211 public InvariantDeviceProfile(Context context, String gridName) {
212 String newName = initGrid(context, gridName);
213 if (newName == null || !newName.equals(gridName)) {
214 throw new IllegalArgumentException("Unknown grid name");
215 }
216 }
217
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700218 /**
Sunny Goyal9c2b9602020-01-07 13:07:55 -0800219 * This constructor should NOT have any monitors by design.
220 */
221 public InvariantDeviceProfile(Context context, Display display) {
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700222 // Ensure that the main device profile is initialized
Alex Chaufd6d9422021-04-22 19:10:21 +0100223 INSTANCE.get(context);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700224 String gridName = getCurrentGridName(context);
225
226 // Get the display info based on default display and interpolate it to existing display
Alex Chau1c883d82021-12-01 18:43:10 +0000227 Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo();
228 @DeviceType int defaultDeviceType = getDeviceType(defaultInfo);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700229 DisplayOption defaultDisplayOption = invDistWeightedInterpolate(
Alex Chau1c883d82021-12-01 18:43:10 +0000230 defaultInfo,
231 getPredefinedDeviceProfiles(context, gridName, defaultDeviceType,
232 /*allowDisabledGrid=*/false),
233 defaultDeviceType);
Sunny Goyal0e7a3382020-04-13 17:15:05 -0700234
Alex Chau661f02d2022-06-07 14:03:43 +0100235 Context displayContext = context.createDisplayContext(display);
236 Info myInfo = new Info(displayContext);
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 Lima425f6822022-05-10 13:44:58 -0300361 hotseatColumnSpan = closestProfile.hotseatColumnSpan;
Thales Lima6e7f36c2022-01-04 12:14:11 +0000362 hotseatBorderSpaces = displayOption.hotseatBorderSpaces;
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 Lima425f6822022-05-10 13:44:58 -0300403 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 Lima425f6822022-05-10 13:44:58 -0300593 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
Alex Chaud3e8cc42022-05-03 17:45:34 +0100635 return getBestMatch(screenWidth, screenHeight, rotation);
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400636 }
Sunny Goyal19ff7282021-04-22 10:12:54 -0700637
Sunny Goyal187b16c2022-03-01 16:53:23 -0800638 /**
639 * Returns the device profile matching the provided screen configuration
640 */
641 public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) {
Sunny Goyal19ff7282021-04-22 10:12:54 -0700642 DeviceProfile bestMatch = supportedProfiles.get(0);
643 float minDiff = Float.MAX_VALUE;
644
645 for (DeviceProfile profile : supportedProfiles) {
Sunny Goyal3e9a29c2021-09-07 15:53:09 -0400646 float diff = Math.abs(profile.widthPx - screenWidth)
647 + Math.abs(profile.heightPx - screenHeight);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700648 if (diff < minDiff) {
649 minDiff = diff;
650 bestMatch = profile;
Sunny Goyal187b16c2022-03-01 16:53:23 -0800651 } else if (diff == minDiff && profile.rotationHint == rotation) {
652 bestMatch = profile;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700653 }
654 }
655 return bestMatch;
Sunny Goyal27835952017-01-13 12:15:53 -0800656 }
657
Sunny Goyal415f1732018-11-29 10:33:47 -0800658 private static float weight(float x0, float y0, float x1, float y1, float pow) {
Hyunyoung Song35c3c7f2015-05-28 15:33:40 -0700659 float d = dist(x0, y0, x1, y1);
660 if (Float.compare(d, 0f) == 0) {
661 return Float.POSITIVE_INFINITY;
662 }
663 return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
664 }
Sunny Goyal6f866092016-03-17 17:04:15 -0700665
666 /**
667 * As a ratio of screen height, the total distance we want the parallax effect to span
668 * horizontally
669 */
670 private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
671 float aspectRatio = width / (float) height;
672
673 // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
674 // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
675 // We will use these two data points to extrapolate how much the wallpaper parallax effect
676 // to span (ie travel) at any aspect ratio:
677
sfufa@google.comde013292021-09-21 18:22:44 -0700678 final float ASPECT_RATIO_LANDSCAPE = 16 / 10f;
679 final float ASPECT_RATIO_PORTRAIT = 10 / 16f;
Sunny Goyal6f866092016-03-17 17:04:15 -0700680 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
681 final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
682
683 // To find out the desired width at different aspect ratios, we use the following two
684 // formulas, where the coefficient on x is the aspect ratio (width/height):
685 // (16/10)x + y = 1.5
686 // (10/16)x + y = 1.2
687 // We solve for x and y and end up with a final formula:
688 final float x =
sfufa@google.comde013292021-09-21 18:22:44 -0700689 (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE
690 - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
Sunny Goyal6f866092016-03-17 17:04:15 -0700691 (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
692 final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
693 return x * aspectRatio + y;
694 }
695
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700696 public interface OnIDPChangeListener {
697
Sunny Goyalb47172b2021-05-03 19:59:51 -0700698 /**
699 * Called when the device provide changes
700 */
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700701 void onIdpChanged(boolean modelPropertiesChanged);
Sunny Goyal87dc48b2018-10-12 11:42:33 -0700702 }
Sunny Goyal415f1732018-11-29 10:33:47 -0800703
704
Sunny Goyaleff44f32019-01-09 17:29:49 -0800705 public static final class GridOption {
Sunny Goyal415f1732018-11-29 10:33:47 -0800706
Sunny Goyal7d892ff2019-01-11 15:08:44 -0800707 public static final String TAG_NAME = "grid-option";
708
Alex Chau1c883d82021-12-01 18:43:10 +0000709 private static final int DEVICE_CATEGORY_PHONE = 1 << 0;
710 private static final int DEVICE_CATEGORY_TABLET = 1 << 1;
711 private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2;
712 private static final int DEVICE_CATEGORY_ALL =
713 DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY;
714
Sunny Goyaleff44f32019-01-09 17:29:49 -0800715 public final String name;
716 public final int numRows;
717 public final int numColumns;
Alex Chau9fee3fd2021-12-01 18:43:10 +0000718 public final int numSearchContainerColumns;
Thales Lima7ec83822021-08-05 13:32:10 +0100719 public final boolean isEnabled;
Sunny Goyal415f1732018-11-29 10:33:47 -0800720
721 private final int numFolderRows;
722 private final int numFolderColumns;
723
Sunny Goyal19ff7282021-04-22 10:12:54 -0700724 private final int numAllAppsColumns;
725 private final int numDatabaseAllAppsColumns;
726 private final int numHotseatIcons;
Alex Chau6ed408f2022-03-04 12:58:05 +0000727 private final int numShrunkenHotseatIcons;
Tony Wickhamb87f3cd2021-04-07 15:02:37 -0700728 private final int numDatabaseHotseatIcons;
Thales Lima425f6822022-05-10 13:44:58 -0300729 private final int[] hotseatColumnSpan = new int[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800730
Tracy Zhou7df93d22020-01-27 13:44:06 -0800731 private final String dbFile;
Sunny Goyalae190ff2020-04-14 00:19:01 +0000732
Sunny Goyal415f1732018-11-29 10:33:47 -0800733 private final int defaultLayoutId;
734 private final int demoModeLayoutId;
735
Jon Mirandae126d722021-02-25 10:45:20 -0500736 private final boolean isScalable;
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400737 private final int devicePaddingId;
Jon Mirandae126d722021-02-25 10:45:20 -0500738
Sunny Goyal5bc18462019-01-07 15:13:39 -0800739 private final SparseArray<TypedValue> extraAttrs;
740
Alex Chau1c883d82021-12-01 18:43:10 +0000741 public GridOption(Context context, AttributeSet attrs, @DeviceType int deviceType) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800742 TypedArray a = context.obtainStyledAttributes(
743 attrs, R.styleable.GridDisplayOption);
744 name = a.getString(R.styleable.GridDisplayOption_name);
745 numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
746 numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
Alex Chau9fee3fd2021-12-01 18:43:10 +0000747 numSearchContainerColumns = a.getInt(
748 R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);
Sunny Goyal415f1732018-11-29 10:33:47 -0800749
Tracy Zhou7df93d22020-01-27 13:44:06 -0800750 dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
Alex Chau1c883d82021-12-01 18:43:10 +0000751 defaultLayoutId = a.getResourceId(deviceType == TYPE_MULTI_DISPLAY && a.hasValue(
Alex Chau1e448462021-08-13 21:48:35 +0100752 R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId)
753 ? R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId
754 : R.styleable.GridDisplayOption_defaultLayoutId, 0);
Sunny Goyal415f1732018-11-29 10:33:47 -0800755 demoModeLayoutId = a.getResourceId(
756 R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700757
758 numAllAppsColumns = a.getInt(
759 R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
760 numDatabaseAllAppsColumns = a.getInt(
761 R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns);
762
763 numHotseatIcons = a.getInt(
Sunny Goyal415f1732018-11-29 10:33:47 -0800764 R.styleable.GridDisplayOption_numHotseatIcons, numColumns);
Alex Chau6ed408f2022-03-04 12:58:05 +0000765 numShrunkenHotseatIcons = a.getInt(
766 R.styleable.GridDisplayOption_numShrunkenHotseatIcons, numHotseatIcons / 2);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700767 numDatabaseHotseatIcons = a.getInt(
768 R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons);
Thales Lima425f6822022-05-10 13:44:58 -0300769 hotseatColumnSpan[INDEX_DEFAULT] = a.getInt(
770 R.styleable.GridDisplayOption_hotseatColumnSpan, numColumns);
771 hotseatColumnSpan[INDEX_LANDSCAPE] = a.getInt(
772 R.styleable.GridDisplayOption_hotseatColumnSpanLandscape, numColumns);
773 hotseatColumnSpan[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt(
774 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelLandscape,
775 numColumns);
776 hotseatColumnSpan[INDEX_TWO_PANEL_PORTRAIT] = a.getInt(
777 R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelPortrait,
778 numColumns);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700779
Sunny Goyal415f1732018-11-29 10:33:47 -0800780 numFolderRows = a.getInt(
781 R.styleable.GridDisplayOption_numFolderRows, numRows);
782 numFolderColumns = a.getInt(
783 R.styleable.GridDisplayOption_numFolderColumns, numColumns);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700784
Jon Mirandae126d722021-02-25 10:45:20 -0500785 isScalable = a.getBoolean(
786 R.styleable.GridDisplayOption_isScalable, false);
Jon Mirandac9e69fa2021-03-22 17:13:34 -0400787 devicePaddingId = a.getResourceId(
788 R.styleable.GridDisplayOption_devicePaddingId, 0);
Jon Mirandae126d722021-02-25 10:45:20 -0500789
Alex Chau1c883d82021-12-01 18:43:10 +0000790 int deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
791 DEVICE_CATEGORY_ALL);
792 isEnabled = (deviceType == TYPE_PHONE
793 && ((deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE))
794 || (deviceType == TYPE_TABLET
795 && ((deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET))
796 || (deviceType == TYPE_MULTI_DISPLAY
797 && ((deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY)
798 == DEVICE_CATEGORY_MULTI_DISPLAY));
Thales Lima7ec83822021-08-05 13:32:10 +0100799
Sunny Goyal415f1732018-11-29 10:33:47 -0800800 a.recycle();
Sunny Goyal5bc18462019-01-07 15:13:39 -0800801 extraAttrs = Themes.createValueMap(context, attrs,
802 IntArray.wrap(R.styleable.GridDisplayOption));
Sunny Goyal415f1732018-11-29 10:33:47 -0800803 }
804 }
805
Sunny Goyal19ff7282021-04-22 10:12:54 -0700806 @VisibleForTesting
807 static final class DisplayOption {
Thales Lima12d0eff2022-03-25 17:06:11 +0000808 private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0;
809 private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1;
810 private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2;
811 private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3;
812 private static final int DONT_INLINE_QSB = 0;
Sunny Goyal19ff7282021-04-22 10:12:54 -0700813
814 public final GridOption grid;
Sunny Goyal415f1732018-11-29 10:33:47 -0800815
Sunny Goyal415f1732018-11-29 10:33:47 -0800816 private final float minWidthDps;
817 private final float minHeightDps;
818 private final boolean canBeDefault;
Thales Lima12d0eff2022-03-25 17:06:11 +0000819 private final boolean[] inlineQsb = new boolean[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800820
Thales Lima83bedbf2021-10-05 17:47:39 +0100821 private final PointF[] minCellSize = new PointF[COUNT_SIZES];
Thales Lima78d00ad2021-09-30 11:29:06 +0100822
823 private float folderBorderSpace;
824 private final PointF[] borderSpaces = new PointF[COUNT_SIZES];
Thales Lima83bedbf2021-10-05 17:47:39 +0100825 private final float[] horizontalMargin = new float[COUNT_SIZES];
Thales Lima425f6822022-05-10 13:44:58 -0300826 //TODO(http://b/228998082) remove this when 3 button spaces are fixed
Thales Lima6e7f36c2022-01-04 12:14:11 +0000827 private final float[] hotseatBorderSpaces = new float[COUNT_SIZES];
Thales Limad90faab2021-09-21 17:18:47 +0100828
Thales Lima78d00ad2021-09-30 11:29:06 +0100829 private final float[] iconSizes = new float[COUNT_SIZES];
830 private final float[] textSizes = new float[COUNT_SIZES];
Sunny Goyal415f1732018-11-29 10:33:47 -0800831
Thales Limab7ef5692022-03-10 10:32:36 +0000832 private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES];
Thales Limabb7d3882021-12-22 12:56:29 +0000833 private final float[] allAppsIconSizes = new float[COUNT_SIZES];
834 private final float[] allAppsIconTextSizes = new float[COUNT_SIZES];
835 private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES];
836
Thales Lima1de4d552021-10-13 16:13:25 +0100837 DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
Sunny Goyal415f1732018-11-29 10:33:47 -0800838 this.grid = grid;
839
Thales Lima1de4d552021-10-13 16:13:25 +0100840 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
Sunny Goyal415f1732018-11-29 10:33:47 -0800841
Sunny Goyal415f1732018-11-29 10:33:47 -0800842 minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
843 minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
Sunny Goyal19ff7282021-04-22 10:12:54 -0700844
Thales Lima1de4d552021-10-13 16:13:25 +0100845 canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
Sunny Goyal415f1732018-11-29 10:33:47 -0800846
Thales Lima12d0eff2022-03-25 17:06:11 +0000847 int inlineForRotation = a.getInt(R.styleable.ProfileDisplayOption_inlineQsb,
848 DONT_INLINE_QSB);
849 inlineQsb[INDEX_DEFAULT] =
850 (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT;
851 inlineQsb[INDEX_LANDSCAPE] =
852 (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE;
853 inlineQsb[INDEX_TWO_PANEL_PORTRAIT] =
854 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT)
855 == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT;
856 inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] =
857 (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE)
858 == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE;
859
Thales Lima83bedbf2021-10-05 17:47:39 +0100860 float x;
861 float y;
862
Thales Lima85c942f2021-12-31 13:04:20 +0000863 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0);
864 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0);
Thales Lima83bedbf2021-10-05 17:47:39 +0100865 minCellSize[INDEX_DEFAULT] = new PointF(x, y);
Thales Limadd027342022-01-07 12:54:37 +0000866
867 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape,
868 minCellSize[INDEX_DEFAULT].x);
869 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape,
870 minCellSize[INDEX_DEFAULT].y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100871 minCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
Thales Lima83bedbf2021-10-05 17:47:39 +0100872
Thales Lima85c942f2021-12-31 13:04:20 +0000873 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100874 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +0000875 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +0100876 minCellSize[INDEX_DEFAULT].y);
877 minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
878
Thales Lima85c942f2021-12-31 13:04:20 +0000879 x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100880 minCellSize[INDEX_DEFAULT].x);
Thales Lima85c942f2021-12-31 13:04:20 +0000881 y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100882 minCellSize[INDEX_DEFAULT].y);
883 minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Thales Lima78d00ad2021-09-30 11:29:06 +0100884
Thales Lima85c942f2021-12-31 13:04:20 +0000885 float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0);
Thales Lima44cc3a22022-03-18 14:28:24 +0000886 float borderSpaceLandscape = a.getFloat(
887 R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace);
Thales Lima85c942f2021-12-31 13:04:20 +0000888 float borderSpaceTwoPanelPortrait = a.getFloat(
889 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace);
890 float borderSpaceTwoPanelLandscape = a.getFloat(
891 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +0100892
Thales Lima85c942f2021-12-31 13:04:20 +0000893 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace);
894 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace);
Thales Lima78d00ad2021-09-30 11:29:06 +0100895 borderSpaces[INDEX_DEFAULT] = new PointF(x, y);
Thales Lima44cc3a22022-03-18 14:28:24 +0000896
897 x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal,
898 borderSpaceLandscape);
899 y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical,
900 borderSpaceLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100901 borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
902
903 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000904 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal,
905 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +0100906 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000907 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical,
908 borderSpaceTwoPanelPortrait);
Thales Lima78d00ad2021-09-30 11:29:06 +0100909 borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
910
911 x = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000912 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal,
913 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100914 y = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +0000915 R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical,
916 borderSpaceTwoPanelLandscape);
Thales Lima78d00ad2021-09-30 11:29:06 +0100917 borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
918
Thales Limabb7d3882021-12-22 12:56:29 +0000919 folderBorderSpace = borderSpace;
920
Thales Limab7ef5692022-03-10 10:32:36 +0000921 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth,
922 minCellSize[INDEX_DEFAULT].x);
923 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight,
924 minCellSize[INDEX_DEFAULT].y);
925 allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y);
926
927 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape,
928 allAppsCellSize[INDEX_DEFAULT].x);
929 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape,
930 allAppsCellSize[INDEX_DEFAULT].y);
931 allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y);
932
933 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait,
934 allAppsCellSize[INDEX_DEFAULT].x);
935 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait,
936 allAppsCellSize[INDEX_DEFAULT].y);
937 allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
938
939 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape,
940 allAppsCellSize[INDEX_DEFAULT].x);
941 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape,
942 allAppsCellSize[INDEX_DEFAULT].y);
943 allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
944
Thales Lima080d8902022-03-28 15:30:29 +0100945 float allAppsBorderSpace = a.getFloat(
946 R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace);
947 float allAppsBorderSpaceLandscape = a.getFloat(
948 R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape,
949 allAppsBorderSpace);
950 float allAppsBorderSpaceTwoPanelPortrait = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +0000951 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait,
Thales Lima080d8902022-03-28 15:30:29 +0100952 allAppsBorderSpace);
953 float allAppsBorderSpaceTwoPanelLandscape = a.getFloat(
Thales Limabb7d3882021-12-22 12:56:29 +0000954 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape,
Thales Lima080d8902022-03-28 15:30:29 +0100955 allAppsBorderSpace);
956
957 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal,
958 allAppsBorderSpace);
959 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical,
960 allAppsBorderSpace);
961 allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y);
962
963 x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal,
964 allAppsBorderSpaceLandscape);
965 y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical,
966 allAppsBorderSpaceLandscape);
967 allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y);
968
969 x = a.getFloat(
970 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal,
971 allAppsBorderSpaceTwoPanelPortrait);
972 y = a.getFloat(
973 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical,
974 allAppsBorderSpaceTwoPanelPortrait);
975 allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y);
976
977 x = a.getFloat(
978 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal,
979 allAppsBorderSpaceTwoPanelLandscape);
980 y = a.getFloat(
981 R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical,
982 allAppsBorderSpaceTwoPanelLandscape);
Thales Limabb7d3882021-12-22 12:56:29 +0000983 allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y);
Jon Mirandae126d722021-02-25 10:45:20 -0500984
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700985 iconSizes[INDEX_DEFAULT] =
986 a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0);
987 iconSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +0000988 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700989 iconSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700990 iconSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +0000991 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -0700992 iconSizes[INDEX_DEFAULT]);
993 iconSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +0000994 a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +0100995 iconSizes[INDEX_DEFAULT]);
Jon Miranda6f7e9702019-09-16 14:44:14 -0700996
Thales Limabb7d3882021-12-22 12:56:29 +0000997 allAppsIconSizes[INDEX_DEFAULT] = a.getFloat(
998 R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]);
999 allAppsIconSizes[INDEX_LANDSCAPE] = allAppsIconSizes[INDEX_DEFAULT];
1000 allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1001 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait,
1002 allAppsIconSizes[INDEX_DEFAULT]);
1003 allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1004 R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape,
1005 allAppsIconSizes[INDEX_DEFAULT]);
1006
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001007 textSizes[INDEX_DEFAULT] =
1008 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
1009 textSizes[INDEX_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001010 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001011 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001012 textSizes[INDEX_TWO_PANEL_PORTRAIT] =
Thales Lima85c942f2021-12-31 13:04:20 +00001013 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait,
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001014 textSizes[INDEX_DEFAULT]);
1015 textSizes[INDEX_TWO_PANEL_LANDSCAPE] =
Thales Lima85c942f2021-12-31 13:04:20 +00001016 a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001017 textSizes[INDEX_DEFAULT]);
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001018
Thales Limabb7d3882021-12-22 12:56:29 +00001019 allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat(
1020 R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]);
1021 allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT];
1022 allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1023 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait,
1024 allAppsIconTextSizes[INDEX_DEFAULT]);
1025 allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1026 R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape,
1027 allAppsIconTextSizes[INDEX_DEFAULT]);
1028
Thales Lima83bedbf2021-10-05 17:47:39 +01001029 horizontalMargin[INDEX_DEFAULT] = a.getFloat(
1030 R.styleable.ProfileDisplayOption_horizontalMargin, 0);
Thales Limadd027342022-01-07 12:54:37 +00001031 horizontalMargin[INDEX_LANDSCAPE] = a.getFloat(
1032 R.styleable.ProfileDisplayOption_horizontalMarginLandscape,
1033 horizontalMargin[INDEX_DEFAULT]);
Thales Lima83bedbf2021-10-05 17:47:39 +01001034 horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001035 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape,
Thales Lima83bedbf2021-10-05 17:47:39 +01001036 horizontalMargin[INDEX_DEFAULT]);
1037 horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
Thales Lima85c942f2021-12-31 13:04:20 +00001038 R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait,
Thales Lima83bedbf2021-10-05 17:47:39 +01001039 horizontalMargin[INDEX_DEFAULT]);
Thales Limad90faab2021-09-21 17:18:47 +01001040
Thales Lima6e7f36c2022-01-04 12:14:11 +00001041 hotseatBorderSpaces[INDEX_DEFAULT] = a.getFloat(
1042 R.styleable.ProfileDisplayOption_hotseatBorderSpace, borderSpace);
Thales Limadd027342022-01-07 12:54:37 +00001043 hotseatBorderSpaces[INDEX_LANDSCAPE] = a.getFloat(
1044 R.styleable.ProfileDisplayOption_hotseatBorderSpaceLandscape,
1045 hotseatBorderSpaces[INDEX_DEFAULT]);
Thales Lima6e7f36c2022-01-04 12:14:11 +00001046 hotseatBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat(
1047 R.styleable.ProfileDisplayOption_hotseatBorderSpaceTwoPanelLandscape,
1048 hotseatBorderSpaces[INDEX_DEFAULT]);
1049 hotseatBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat(
1050 R.styleable.ProfileDisplayOption_hotseatBorderSpaceTwoPanelPortrait,
1051 hotseatBorderSpaces[INDEX_DEFAULT]);
1052
Sunny Goyal415f1732018-11-29 10:33:47 -08001053 a.recycle();
1054 }
1055
1056 DisplayOption() {
Sunny Goyal0e7a3382020-04-13 17:15:05 -07001057 this(null);
1058 }
1059
1060 DisplayOption(GridOption grid) {
1061 this.grid = grid;
Sunny Goyal415f1732018-11-29 10:33:47 -08001062 minWidthDps = 0;
1063 minHeightDps = 0;
1064 canBeDefault = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001065 for (int i = 0; i < COUNT_SIZES; i++) {
1066 iconSizes[i] = 0;
1067 textSizes[i] = 0;
1068 borderSpaces[i] = new PointF();
Thales Lima83bedbf2021-10-05 17:47:39 +01001069 minCellSize[i] = new PointF();
Thales Limab7ef5692022-03-10 10:32:36 +00001070 allAppsCellSize[i] = new PointF();
Thales Limabb7d3882021-12-22 12:56:29 +00001071 allAppsIconSizes[i] = 0;
1072 allAppsIconTextSizes[i] = 0;
1073 allAppsBorderSpaces[i] = new PointF();
Thales Lima12d0eff2022-03-25 17:06:11 +00001074 inlineQsb[i] = false;
Thales Lima78d00ad2021-09-30 11:29:06 +01001075 }
Sunny Goyal415f1732018-11-29 10:33:47 -08001076 }
1077
1078 private DisplayOption multiply(float w) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001079 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001080 iconSizes[i] *= w;
1081 textSizes[i] *= w;
Thales Lima83bedbf2021-10-05 17:47:39 +01001082 borderSpaces[i].x *= w;
1083 borderSpaces[i].y *= w;
1084 minCellSize[i].x *= w;
1085 minCellSize[i].y *= w;
1086 horizontalMargin[i] *= w;
Thales Lima6e7f36c2022-01-04 12:14:11 +00001087 hotseatBorderSpaces[i] *= w;
Thales Limab7ef5692022-03-10 10:32:36 +00001088 allAppsCellSize[i].x *= w;
1089 allAppsCellSize[i].y *= w;
Thales Limabb7d3882021-12-22 12:56:29 +00001090 allAppsIconSizes[i] *= w;
1091 allAppsIconTextSizes[i] *= w;
1092 allAppsBorderSpaces[i].x *= w;
1093 allAppsBorderSpaces[i].y *= w;
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001094 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001095
1096 folderBorderSpace *= w;
1097
Sunny Goyal415f1732018-11-29 10:33:47 -08001098 return this;
1099 }
1100
1101 private DisplayOption add(DisplayOption p) {
Thales Lima78d00ad2021-09-30 11:29:06 +01001102 for (int i = 0; i < COUNT_SIZES; i++) {
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001103 iconSizes[i] += p.iconSizes[i];
1104 textSizes[i] += p.textSizes[i];
Thales Lima83bedbf2021-10-05 17:47:39 +01001105 borderSpaces[i].x += p.borderSpaces[i].x;
1106 borderSpaces[i].y += p.borderSpaces[i].y;
1107 minCellSize[i].x += p.minCellSize[i].x;
1108 minCellSize[i].y += p.minCellSize[i].y;
1109 horizontalMargin[i] += p.horizontalMargin[i];
Thales Lima6e7f36c2022-01-04 12:14:11 +00001110 hotseatBorderSpaces[i] += p.hotseatBorderSpaces[i];
Thales Limab7ef5692022-03-10 10:32:36 +00001111 allAppsCellSize[i].x += p.allAppsCellSize[i].x;
1112 allAppsCellSize[i].y += p.allAppsCellSize[i].y;
Thales Limabb7d3882021-12-22 12:56:29 +00001113 allAppsIconSizes[i] += p.allAppsIconSizes[i];
1114 allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i];
1115 allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x;
1116 allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y;
Thales Lima12d0eff2022-03-25 17:06:11 +00001117 inlineQsb[i] |= p.inlineQsb[i];
Sunny Goyal6e6f7992021-08-24 16:23:29 -07001118 }
Thales Lima78d00ad2021-09-30 11:29:06 +01001119
1120 folderBorderSpace += p.folderBorderSpace;
1121
Sunny Goyal415f1732018-11-29 10:33:47 -08001122 return this;
1123 }
1124 }
Sunny Goyalae190ff2020-04-14 00:19:01 +00001125}