Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 1 | /* |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame] | 2 | * Copyright (C) 2021 The Android Open Source Project |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.launcher3; |
| 18 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 19 | import static com.android.launcher3.Utilities.dpiFromPx; |
Andras Kloczl | 8e57cce | 2021-02-11 23:51:19 +0100 | [diff] [blame] | 20 | import static com.android.launcher3.config.FeatureFlags.ENABLE_TWO_PANEL_HOME; |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 21 | import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY; |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 22 | import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 23 | import static com.android.launcher3.util.DisplayController.CHANGE_SUPPORTED_BOUNDS; |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 24 | import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 25 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 26 | import android.annotation.TargetApi; |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 27 | import android.appwidget.AppWidgetHostView; |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 28 | import android.content.ComponentName; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 29 | import android.content.Context; |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 30 | import android.content.res.Configuration; |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 31 | import android.content.res.Resources; |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 32 | import android.content.res.TypedArray; |
| 33 | import android.content.res.XmlResourceParser; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 34 | import android.graphics.Point; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 35 | import android.graphics.PointF; |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 36 | import android.graphics.Rect; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 37 | import android.text.TextUtils; |
| 38 | import android.util.AttributeSet; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 39 | import android.util.DisplayMetrics; |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 40 | import android.util.Log; |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 41 | import android.util.SparseArray; |
| 42 | import android.util.TypedValue; |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 43 | import android.util.Xml; |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 44 | import android.view.Display; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 45 | |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 46 | import androidx.annotation.IntDef; |
Sunny Goyal | 6fe3eec | 2019-08-15 14:53:41 -0700 | [diff] [blame] | 47 | import androidx.annotation.Nullable; |
| 48 | import androidx.annotation.VisibleForTesting; |
| 49 | |
Sunny Goyal | 68031ca | 2021-08-02 12:23:44 -0700 | [diff] [blame] | 50 | import com.android.launcher3.model.DeviceGridState; |
Alex Chau | 238aaee | 2021-10-06 16:15:24 +0100 | [diff] [blame] | 51 | import com.android.launcher3.provider.RestoreDbTask; |
Sunny Goyal | fd58da6 | 2020-08-11 12:06:49 -0700 | [diff] [blame] | 52 | import com.android.launcher3.util.DisplayController; |
| 53 | import com.android.launcher3.util.DisplayController.Info; |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 54 | import com.android.launcher3.util.IntArray; |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 55 | import com.android.launcher3.util.MainThreadInitializedObject; |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 56 | import com.android.launcher3.util.Themes; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 57 | import com.android.launcher3.util.WindowBounds; |
Sunny Goyal | 187b16c | 2022-03-01 16:53:23 -0800 | [diff] [blame] | 58 | import com.android.launcher3.util.window.WindowManagerProxy; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 59 | |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 60 | import org.xmlpull.v1.XmlPullParser; |
| 61 | import org.xmlpull.v1.XmlPullParserException; |
| 62 | |
| 63 | import java.io.IOException; |
Alex Chau | d3e8cc4 | 2022-05-03 17:45:34 +0100 | [diff] [blame] | 64 | import java.io.PrintWriter; |
| 65 | import java.io.StringWriter; |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 66 | import java.lang.annotation.Retention; |
| 67 | import java.lang.annotation.RetentionPolicy; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 68 | import java.util.ArrayList; |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 69 | import java.util.Arrays; |
Sunny Goyal | 6d55f66 | 2019-01-02 12:13:43 -0800 | [diff] [blame] | 70 | import java.util.Collections; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 71 | import java.util.List; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 72 | |
| 73 | public class InvariantDeviceProfile { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 74 | |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 75 | public static final String TAG = "IDP"; |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 76 | // We do not need any synchronization for this variable as its only written on UI thread. |
| 77 | public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE = |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 78 | new MainThreadInitializedObject<>(InvariantDeviceProfile::new); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 79 | |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 80 | @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 Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 87 | private static final String KEY_IDP_GRID_NAME = "idp_grid_name"; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 88 | |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 89 | private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48; |
| 90 | |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 91 | // Constants that affects the interpolation curve between statically defined device profile |
| 92 | // buckets. |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 93 | private static final float KNEARESTNEIGHBOR = 3; |
| 94 | private static final float WEIGHT_POWER = 5; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 95 | |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 96 | // used to offset float not being able to express extremely small weights in extreme cases. |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 97 | private static final float WEIGHT_EFFICIENT = 100000f; |
| 98 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 99 | // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different |
| 100 | // constraints |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 101 | static final int COUNT_SIZES = 4; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 102 | 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 Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 106 | |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 107 | /** |
| 108 | * Number of icons per row and column in the workspace. |
| 109 | */ |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 110 | public int numRows; |
| 111 | public int numColumns; |
Alex Chau | 9fee3fd | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 112 | public int numSearchContainerColumns; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 113 | |
| 114 | /** |
| 115 | * Number of icons per row and column in the folder. |
| 116 | */ |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 117 | public int numFolderRows; |
| 118 | public int numFolderColumns; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 119 | public float[] iconSize; |
| 120 | public float[] iconTextSize; |
Sunny Goyal | fc21830 | 2015-09-17 14:59:10 -0700 | [diff] [blame] | 121 | public int iconBitmapSize; |
| 122 | public int fillResIconDpi; |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 123 | public @DeviceType int deviceType; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 124 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 125 | public PointF[] minCellSize; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 126 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 127 | public PointF[] borderSpaces; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 128 | public float folderBorderSpace; |
Thales Lima | 6e7f36c | 2022-01-04 12:14:11 +0000 | [diff] [blame] | 129 | public float[] hotseatBorderSpaces; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 130 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 131 | public float[] horizontalMargin; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 132 | |
Thales Lima | b7ef569 | 2022-03-10 10:32:36 +0000 | [diff] [blame] | 133 | public PointF[] allAppsCellSize; |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 134 | public float[] allAppsIconSize; |
| 135 | public float[] allAppsIconTextSize; |
| 136 | public PointF[] allAppsBorderSpaces; |
| 137 | |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 138 | private SparseArray<TypedValue> mExtraAttrs; |
| 139 | |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 140 | /** |
| 141 | * Number of icons inside the hotseat area. |
| 142 | */ |
Jon Miranda | fd48b0c | 2022-01-31 16:25:22 -0800 | [diff] [blame] | 143 | public int numShownHotseatIcons; |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame] | 144 | |
| 145 | /** |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 146 | * Number of icons inside the hotseat area when using 3 buttons navigation. |
| 147 | */ |
| 148 | public int numShrunkenHotseatIcons; |
| 149 | |
| 150 | /** |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame] | 151 | * Number of icons inside the hotseat area that is stored in the database. This is greater than |
| 152 | * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat |
| 153 | * sizes that share the same DB. |
| 154 | */ |
| 155 | public int numDatabaseHotseatIcons; |
Adam Cohen | 2782449 | 2017-09-22 17:10:55 -0700 | [diff] [blame] | 156 | |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 157 | /** |
| 158 | * Number of columns in the all apps list. |
| 159 | */ |
| 160 | public int numAllAppsColumns; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 161 | public int numDatabaseAllAppsColumns; |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 162 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 163 | /** |
| 164 | * Do not query directly. see {@link DeviceProfile#isScalableGrid}. |
| 165 | */ |
| 166 | protected boolean isScalable; |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 167 | public int devicePaddingId; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 168 | |
Tracy Zhou | 7df93d2 | 2020-01-27 13:44:06 -0800 | [diff] [blame] | 169 | public String dbFile; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 170 | public int defaultLayoutId; |
Adam Cohen | 2782449 | 2017-09-22 17:10:55 -0700 | [diff] [blame] | 171 | int demoModeLayoutId; |
Thales Lima | 12d0eff | 2022-03-25 17:06:11 +0000 | [diff] [blame] | 172 | boolean[] inlineQsb = new boolean[COUNT_SIZES]; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 173 | |
Pinyao Ting | 9cd63c9 | 2021-06-16 17:51:39 +0000 | [diff] [blame] | 174 | /** |
| 175 | * An immutable list of supported profiles. |
| 176 | */ |
| 177 | public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 178 | |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 179 | @Nullable |
| 180 | public DevicePaddings devicePaddings; |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 181 | |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 182 | public Point defaultWallpaperSize; |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 183 | public Rect defaultWidgetPadding; |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 184 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 185 | private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>(); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 186 | |
Sunny Goyal | f633ef5 | 2018-03-13 09:57:05 -0700 | [diff] [blame] | 187 | @VisibleForTesting |
Sunny Goyal | 187b16c | 2022-03-01 16:53:23 -0800 | [diff] [blame] | 188 | public InvariantDeviceProfile() { } |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 189 | |
Sunny Goyal | bbf0184 | 2015-10-08 07:41:15 -0700 | [diff] [blame] | 190 | @TargetApi(23) |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 191 | private InvariantDeviceProfile(Context context) { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 192 | 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 Goyal | 68031ca | 2021-08-02 12:23:44 -0700 | [diff] [blame] | 197 | new DeviceGridState(this).writeToPrefs(context); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 198 | |
Tracy Zhou | c8beebf | 2021-09-23 10:18:11 -0700 | [diff] [blame] | 199 | DisplayController.INSTANCE.get(context).setPriorityListener( |
Alex Chau | fd6d942 | 2021-04-22 19:10:21 +0100 | [diff] [blame] | 200 | (displayContext, info, flags) -> { |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 201 | if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS |
| 202 | | CHANGE_NAVIGATION_MODE)) != 0) { |
Alex Chau | fd6d942 | 2021-04-22 19:10:21 +0100 | [diff] [blame] | 203 | onConfigChanged(displayContext); |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 204 | } |
| 205 | }); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Hyunyoung Song | e11eb47 | 2019-03-19 15:05:21 -0700 | [diff] [blame] | 208 | /** |
| 209 | * This constructor should NOT have any monitors by design. |
| 210 | */ |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 211 | 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 Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 218 | /** |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 219 | * This constructor should NOT have any monitors by design. |
| 220 | */ |
| 221 | public InvariantDeviceProfile(Context context, Display display) { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 222 | // Ensure that the main device profile is initialized |
Alex Chau | fd6d942 | 2021-04-22 19:10:21 +0100 | [diff] [blame] | 223 | INSTANCE.get(context); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 224 | String gridName = getCurrentGridName(context); |
| 225 | |
| 226 | // Get the display info based on default display and interpolate it to existing display |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 227 | Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo(); |
| 228 | @DeviceType int defaultDeviceType = getDeviceType(defaultInfo); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 229 | DisplayOption defaultDisplayOption = invDistWeightedInterpolate( |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 230 | defaultInfo, |
| 231 | getPredefinedDeviceProfiles(context, gridName, defaultDeviceType, |
| 232 | /*allowDisabledGrid=*/false), |
| 233 | defaultDeviceType); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 234 | |
Alex Chau | 417bd72 | 2021-01-26 15:22:18 +0000 | [diff] [blame] | 235 | Info myInfo = new Info(context, display); |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 236 | @DeviceType int deviceType = getDeviceType(myInfo); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 237 | DisplayOption myDisplayOption = invDistWeightedInterpolate( |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 238 | myInfo, |
| 239 | getPredefinedDeviceProfiles(context, gridName, deviceType, |
| 240 | /*allowDisabledGrid=*/false), |
| 241 | deviceType); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 242 | |
| 243 | DisplayOption result = new DisplayOption(defaultDisplayOption.grid) |
| 244 | .add(myDisplayOption); |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 245 | result.iconSizes[INDEX_DEFAULT] = |
| 246 | defaultDisplayOption.iconSizes[INDEX_DEFAULT]; |
| 247 | for (int i = 1; i < COUNT_SIZES; i++) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 248 | result.iconSizes[i] = Math.min( |
| 249 | defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]); |
Alex Chau | 7c43972 | 2021-03-24 11:32:44 +0000 | [diff] [blame] | 250 | } |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 251 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 252 | System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0, |
| 253 | COUNT_SIZES); |
| 254 | System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0, |
| 255 | COUNT_SIZES); |
Thales Lima | 12d0eff | 2022-03-25 17:06:11 +0000 | [diff] [blame] | 256 | System.arraycopy(defaultDisplayOption.inlineQsb, 0, result.inlineQsb, 0, |
| 257 | COUNT_SIZES); |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 258 | |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 259 | initGrid(context, myInfo, result, deviceType); |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 260 | } |
| 261 | |
Alex Chau | 238aaee | 2021-10-06 16:15:24 +0100 | [diff] [blame] | 262 | /** |
| 263 | * Reinitialize the current grid after a restore, where some grids might now be disabled. |
| 264 | */ |
| 265 | public void reinitializeAfterRestore(Context context) { |
Alex Chau | 29a96ad | 2022-02-10 13:12:20 +0000 | [diff] [blame] | 266 | String currentGridName = getCurrentGridName(context); |
Alex Chau | 238aaee | 2021-10-06 16:15:24 +0100 | [diff] [blame] | 267 | String currentDbFile = dbFile; |
Alex Chau | 29a96ad | 2022-02-10 13:12:20 +0000 | [diff] [blame] | 268 | String newGridName = initGrid(context, currentGridName); |
| 269 | String newDbFile = dbFile; |
| 270 | if (!newDbFile.equals(currentDbFile)) { |
| 271 | Log.d(TAG, "Restored grid is disabled : " + currentGridName |
Alex Chau | 238aaee | 2021-10-06 16:15:24 +0100 | [diff] [blame] | 272 | + ", migrating to: " + newGridName |
| 273 | + ", removing all other grid db files"); |
| 274 | for (String gridDbFile : LauncherFiles.GRID_DB_FILES) { |
| 275 | if (gridDbFile.equals(currentDbFile)) { |
| 276 | continue; |
| 277 | } |
| 278 | if (context.getDatabasePath(gridDbFile).delete()) { |
| 279 | Log.d(TAG, "Removed old grid db file: " + gridDbFile); |
| 280 | } |
| 281 | } |
Alex Chau | 29a96ad | 2022-02-10 13:12:20 +0000 | [diff] [blame] | 282 | setCurrentGrid(context, newGridName); |
Alex Chau | 238aaee | 2021-10-06 16:15:24 +0100 | [diff] [blame] | 283 | } |
| 284 | } |
| 285 | |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 286 | private static @DeviceType int getDeviceType(Info displayInfo) { |
Sunny Goyal | 187b16c | 2022-03-01 16:53:23 -0800 | [diff] [blame] | 287 | int flagPhone = 1 << 0; |
| 288 | int flagTablet = 1 << 1; |
| 289 | |
| 290 | int type = displayInfo.supportedBounds.stream() |
| 291 | .mapToInt(bounds -> displayInfo.isTablet(bounds) ? flagTablet : flagPhone) |
| 292 | .reduce(0, (a, b) -> a | b); |
| 293 | if ((type == (flagPhone | flagTablet)) && ENABLE_TWO_PANEL_HOME.get()) { |
| 294 | // device has profiles supporting both phone and table modes |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 295 | return TYPE_MULTI_DISPLAY; |
Sunny Goyal | 187b16c | 2022-03-01 16:53:23 -0800 | [diff] [blame] | 296 | } else if (type == flagTablet) { |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 297 | return TYPE_TABLET; |
| 298 | } else { |
| 299 | return TYPE_PHONE; |
| 300 | } |
| 301 | } |
| 302 | |
Tracy Zhou | 42255d2 | 2020-03-13 00:38:11 -0700 | [diff] [blame] | 303 | public static String getCurrentGridName(Context context) { |
Tracy Zhou | c6060e6 | 2020-04-27 13:05:34 -0700 | [diff] [blame] | 304 | return Utilities.isGridOptionsEnabled(context) |
| 305 | ? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null; |
Tracy Zhou | 42255d2 | 2020-03-13 00:38:11 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 308 | private String initGrid(Context context, String gridName) { |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 309 | Info displayInfo = DisplayController.INSTANCE.get(context).getInfo(); |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 310 | @DeviceType int deviceType = getDeviceType(displayInfo); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 311 | |
| 312 | ArrayList<DisplayOption> allOptions = |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 313 | getPredefinedDeviceProfiles(context, gridName, deviceType, |
Alex Chau | 238aaee | 2021-10-06 16:15:24 +0100 | [diff] [blame] | 314 | RestoreDbTask.isPending(context)); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 315 | DisplayOption displayOption = |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 316 | invDistWeightedInterpolate(displayInfo, allOptions, deviceType); |
| 317 | initGrid(context, displayInfo, displayOption, deviceType); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 318 | return displayOption.grid.name; |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 319 | } |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 320 | |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 321 | private void initGrid(Context context, Info displayInfo, DisplayOption displayOption, |
| 322 | @DeviceType int deviceType) { |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 323 | DisplayMetrics metrics = context.getResources().getDisplayMetrics(); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 324 | GridOption closestProfile = displayOption.grid; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 325 | numRows = closestProfile.numRows; |
| 326 | numColumns = closestProfile.numColumns; |
Alex Chau | 9fee3fd | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 327 | numSearchContainerColumns = closestProfile.numSearchContainerColumns; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 328 | dbFile = closestProfile.dbFile; |
| 329 | defaultLayoutId = closestProfile.defaultLayoutId; |
| 330 | demoModeLayoutId = closestProfile.demoModeLayoutId; |
| 331 | numFolderRows = closestProfile.numFolderRows; |
| 332 | numFolderColumns = closestProfile.numFolderColumns; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 333 | isScalable = closestProfile.isScalable; |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 334 | devicePaddingId = closestProfile.devicePaddingId; |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 335 | this.deviceType = deviceType; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 336 | |
| 337 | mExtraAttrs = closestProfile.extraAttrs; |
| 338 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 339 | iconSize = displayOption.iconSizes; |
Thales Lima | 6e0005a | 2021-10-27 15:53:41 +0100 | [diff] [blame] | 340 | float maxIconSize = iconSize[0]; |
| 341 | for (int i = 1; i < iconSize.length; i++) { |
| 342 | maxIconSize = Math.max(maxIconSize, iconSize[i]); |
| 343 | } |
| 344 | iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics); |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 345 | fillResIconDpi = getLauncherIconDensity(iconBitmapSize); |
| 346 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 347 | iconTextSize = displayOption.textSizes; |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 348 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 349 | minCellSize = displayOption.minCellSize; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 350 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 351 | borderSpaces = displayOption.borderSpaces; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 352 | folderBorderSpace = displayOption.folderBorderSpace; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 353 | |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 354 | horizontalMargin = displayOption.horizontalMargin; |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 355 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 356 | numShownHotseatIcons = closestProfile.numHotseatIcons; |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 357 | numShrunkenHotseatIcons = closestProfile.numShrunkenHotseatIcons; |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 358 | numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 359 | ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons; |
Thales Lima | 6e7f36c | 2022-01-04 12:14:11 +0000 | [diff] [blame] | 360 | hotseatBorderSpaces = displayOption.hotseatBorderSpaces; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 361 | |
| 362 | numAllAppsColumns = closestProfile.numAllAppsColumns; |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 363 | numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 364 | ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 365 | |
Thales Lima | b7ef569 | 2022-03-10 10:32:36 +0000 | [diff] [blame] | 366 | allAppsCellSize = displayOption.allAppsCellSize; |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 367 | allAppsBorderSpaces = displayOption.allAppsBorderSpaces; |
| 368 | allAppsIconSize = displayOption.allAppsIconSizes; |
| 369 | allAppsIconTextSize = displayOption.allAppsIconTextSizes; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 370 | if (!Utilities.isGridOptionsEnabled(context)) { |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 371 | allAppsIconSize = iconSize; |
| 372 | allAppsIconTextSize = iconTextSize; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 373 | } |
| 374 | |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 375 | if (devicePaddingId != 0) { |
| 376 | devicePaddings = new DevicePaddings(context, devicePaddingId); |
| 377 | } |
| 378 | |
Thales Lima | 12d0eff | 2022-03-25 17:06:11 +0000 | [diff] [blame] | 379 | inlineQsb = displayOption.inlineQsb; |
| 380 | |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 381 | // If the partner customization apk contains any grid overrides, apply them |
| 382 | // Supported overrides: numRows, numColumns, iconSize |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 383 | applyPartnerDeviceProfileOverrides(context, metrics); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 384 | |
Pinyao Ting | 9cd63c9 | 2021-06-16 17:51:39 +0000 | [diff] [blame] | 385 | final List<DeviceProfile> localSupportedProfiles = new ArrayList<>(); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 386 | defaultWallpaperSize = new Point(displayInfo.currentSize); |
| 387 | for (WindowBounds bounds : displayInfo.supportedBounds) { |
Pinyao Ting | 9cd63c9 | 2021-06-16 17:51:39 +0000 | [diff] [blame] | 388 | localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo) |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 389 | .setUseTwoPanels(deviceType == TYPE_MULTI_DISPLAY) |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 390 | .setWindowBounds(bounds) |
| 391 | .build()); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 392 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 393 | // Wallpaper size should be the maximum of the all possible sizes Launcher expects |
| 394 | int displayWidth = bounds.bounds.width(); |
| 395 | int displayHeight = bounds.bounds.height(); |
| 396 | defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 397 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 398 | // We need to ensure that there is enough extra space in the wallpaper |
| 399 | // for the intended parallax effects |
| 400 | float parallaxFactor = |
Sunny Goyal | 89a89d6 | 2022-05-09 19:25:15 +0000 | [diff] [blame] | 401 | dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.densityDpi) < 720 |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 402 | ? 2 |
| 403 | : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight); |
| 404 | defaultWallpaperSize.x = |
| 405 | Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth)); |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 406 | } |
Pinyao Ting | 9cd63c9 | 2021-06-16 17:51:39 +0000 | [diff] [blame] | 407 | supportedProfiles = Collections.unmodifiableList(localSupportedProfiles); |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 408 | |
| 409 | ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName()); |
| 410 | defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 413 | public void addOnChangeListener(OnIDPChangeListener listener) { |
| 414 | mChangeListeners.add(listener); |
| 415 | } |
| 416 | |
Hyunyoung Song | b4d1ca4 | 2019-01-08 17:15:16 -0800 | [diff] [blame] | 417 | public void removeOnChangeListener(OnIDPChangeListener listener) { |
| 418 | mChangeListeners.remove(listener); |
| 419 | } |
| 420 | |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 421 | |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 422 | public void setCurrentGrid(Context context, String gridName) { |
| 423 | Context appContext = context.getApplicationContext(); |
| 424 | Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply(); |
Sunny Goyal | 6fe3eec | 2019-08-15 14:53:41 -0700 | [diff] [blame] | 425 | MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext)); |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 426 | } |
| 427 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 428 | private Object[] toModelState() { |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 429 | return new Object[]{ |
Alex Chau | 9fee3fd | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 430 | numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons, |
| 431 | iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile}; |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 434 | private void onConfigChanged(Context context) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 435 | Object[] oldState = toModelState(); |
| 436 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 437 | // Re-init grid |
Tracy Zhou | c6060e6 | 2020-04-27 13:05:34 -0700 | [diff] [blame] | 438 | String gridName = getCurrentGridName(context); |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 439 | initGrid(context, gridName); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 440 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 441 | boolean modelPropsChanged = !Arrays.equals(oldState, toModelState()); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 442 | for (OnIDPChangeListener listener : mChangeListeners) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 443 | listener.onIdpChanged(modelPropsChanged); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 447 | private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context, |
| 448 | String gridName, @DeviceType int deviceType, boolean allowDisabledGrid) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 449 | ArrayList<DisplayOption> profiles = new ArrayList<>(); |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame] | 450 | |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 451 | try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) { |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 452 | final int depth = parser.getDepth(); |
| 453 | int type; |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 454 | while (((type = parser.next()) != XmlPullParser.END_TAG || |
| 455 | parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 456 | if ((type == XmlPullParser.START_TAG) |
| 457 | && GridOption.TAG_NAME.equals(parser.getName())) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 458 | |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 459 | GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser), |
| 460 | deviceType); |
Alex Chau | 238aaee | 2021-10-06 16:15:24 +0100 | [diff] [blame] | 461 | if (gridOption.isEnabled || allowDisabledGrid) { |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 462 | final int displayDepth = parser.getDepth(); |
| 463 | while (((type = parser.next()) != XmlPullParser.END_TAG |
| 464 | || parser.getDepth() > displayDepth) |
| 465 | && type != XmlPullParser.END_DOCUMENT) { |
| 466 | if ((type == XmlPullParser.START_TAG) && "display-option".equals( |
| 467 | parser.getName())) { |
| 468 | profiles.add(new DisplayOption(gridOption, context, |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame] | 469 | Xml.asAttributeSet(parser))); |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 470 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 471 | } |
| 472 | } |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 473 | } |
| 474 | } |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 475 | } catch (IOException | XmlPullParserException e) { |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 476 | throw new RuntimeException(e); |
| 477 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 478 | |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 479 | ArrayList<DisplayOption> filteredProfiles = new ArrayList<>(); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 480 | if (!TextUtils.isEmpty(gridName)) { |
| 481 | for (DisplayOption option : profiles) { |
Alex Chau | 238aaee | 2021-10-06 16:15:24 +0100 | [diff] [blame] | 482 | if (gridName.equals(option.grid.name) |
| 483 | && (option.grid.isEnabled || allowDisabledGrid)) { |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 484 | filteredProfiles.add(option); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 485 | } |
| 486 | } |
| 487 | } |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 488 | if (filteredProfiles.isEmpty()) { |
| 489 | // No grid found, use the default options |
| 490 | for (DisplayOption option : profiles) { |
| 491 | if (option.canBeDefault) { |
| 492 | filteredProfiles.add(option); |
| 493 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 494 | } |
| 495 | } |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 496 | if (filteredProfiles.isEmpty()) { |
| 497 | throw new RuntimeException("No display option with canBeDefault=true"); |
| 498 | } |
| 499 | return filteredProfiles; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 502 | /** |
| 503 | * @return all the grid options that can be shown on the device |
| 504 | */ |
| 505 | public List<GridOption> parseAllGridOptions(Context context) { |
| 506 | List<GridOption> result = new ArrayList<>(); |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame] | 507 | |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 508 | try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) { |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 509 | final int depth = parser.getDepth(); |
| 510 | int type; |
| 511 | while (((type = parser.next()) != XmlPullParser.END_TAG |
| 512 | || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { |
| 513 | if ((type == XmlPullParser.START_TAG) |
| 514 | && GridOption.TAG_NAME.equals(parser.getName())) { |
| 515 | GridOption option = |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 516 | new GridOption(context, Xml.asAttributeSet(parser), deviceType); |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 517 | if (option.isEnabled) { |
| 518 | result.add(option); |
| 519 | } |
| 520 | } |
| 521 | } |
| 522 | } catch (IOException | XmlPullParserException e) { |
| 523 | Log.e(TAG, "Error parsing device profile", e); |
| 524 | return Collections.emptyList(); |
| 525 | } |
| 526 | return result; |
| 527 | } |
| 528 | |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 529 | private int getLauncherIconDensity(int requiredSize) { |
| 530 | // Densities typically defined by an app. |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 531 | int[] densityBuckets = new int[]{ |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 532 | DisplayMetrics.DENSITY_LOW, |
| 533 | DisplayMetrics.DENSITY_MEDIUM, |
| 534 | DisplayMetrics.DENSITY_TV, |
| 535 | DisplayMetrics.DENSITY_HIGH, |
| 536 | DisplayMetrics.DENSITY_XHIGH, |
| 537 | DisplayMetrics.DENSITY_XXHIGH, |
| 538 | DisplayMetrics.DENSITY_XXXHIGH |
| 539 | }; |
| 540 | |
| 541 | int density = DisplayMetrics.DENSITY_XXXHIGH; |
| 542 | for (int i = densityBuckets.length - 1; i >= 0; i--) { |
| 543 | float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i] |
| 544 | / DisplayMetrics.DENSITY_DEFAULT; |
| 545 | if (expectedSize >= requiredSize) { |
| 546 | density = densityBuckets[i]; |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | return density; |
| 551 | } |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 552 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 553 | /** |
| 554 | * Apply any Partner customization grid overrides. |
| 555 | * |
| 556 | * Currently we support: all apps row / column count. |
| 557 | */ |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 558 | private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) { |
| 559 | Partner p = Partner.get(context.getPackageManager()); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 560 | if (p != null) { |
| 561 | p.applyInvariantDeviceProfileOverrides(this, dm); |
| 562 | } |
| 563 | } |
| 564 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 565 | private static float dist(float x0, float y0, float x1, float y1) { |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 566 | return (float) Math.hypot(x1 - x0, y1 - y0); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 569 | private static DisplayOption invDistWeightedInterpolate( |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 570 | Info displayInfo, ArrayList<DisplayOption> points, @DeviceType int deviceType) { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 571 | int minWidthPx = Integer.MAX_VALUE; |
| 572 | int minHeightPx = Integer.MAX_VALUE; |
| 573 | for (WindowBounds bounds : displayInfo.supportedBounds) { |
| 574 | boolean isTablet = displayInfo.isTablet(bounds); |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 575 | if (isTablet && deviceType == TYPE_MULTI_DISPLAY) { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 576 | // For split displays, take half width per page |
| 577 | minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2); |
| 578 | minHeightPx = Math.min(minHeightPx, bounds.availableSize.y); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 579 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 580 | } else if (!isTablet && bounds.isLandscape()) { |
| 581 | // We will use transposed layout in this case |
| 582 | minWidthPx = Math.min(minWidthPx, bounds.availableSize.y); |
| 583 | minHeightPx = Math.min(minHeightPx, bounds.availableSize.x); |
| 584 | } else { |
| 585 | minWidthPx = Math.min(minWidthPx, bounds.availableSize.x); |
| 586 | minHeightPx = Math.min(minHeightPx, bounds.availableSize.y); |
| 587 | } |
| 588 | } |
| 589 | |
Sunny Goyal | 89a89d6 | 2022-05-09 19:25:15 +0000 | [diff] [blame] | 590 | float width = dpiFromPx(minWidthPx, displayInfo.densityDpi); |
| 591 | float height = dpiFromPx(minHeightPx, displayInfo.densityDpi); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 592 | |
| 593 | // Sort the profiles based on the closeness to the device size |
| 594 | Collections.sort(points, (a, b) -> |
| 595 | Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps), |
| 596 | dist(width, height, b.minWidthDps, b.minHeightDps))); |
| 597 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 598 | DisplayOption closestPoint = points.get(0); |
| 599 | GridOption closestOption = closestPoint.grid; |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 600 | float weights = 0; |
| 601 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 602 | if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) { |
| 603 | return closestPoint; |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | DisplayOption out = new DisplayOption(closestOption); |
| 607 | for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 608 | DisplayOption p = points.get(i); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 609 | float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER); |
| 610 | weights += w; |
| 611 | out.add(new DisplayOption().add(p).multiply(w)); |
| 612 | } |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 613 | out.multiply(1.0f / weights); |
| 614 | |
Thales Lima | 6e0005a | 2021-10-27 15:53:41 +0100 | [diff] [blame] | 615 | // Since the bitmaps are persisted, ensure that all bitmap sizes are not larger than |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 616 | // predefined size to avoid cache invalidation |
Thales Lima | 6e0005a | 2021-10-27 15:53:41 +0100 | [diff] [blame] | 617 | for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) { |
| 618 | out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]); |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | return out; |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 622 | } |
| 623 | |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 624 | public DeviceProfile getDeviceProfile(Context context) { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 625 | Resources res = context.getResources(); |
| 626 | Configuration config = context.getResources().getConfiguration(); |
| 627 | |
Sunny Goyal | 3e9a29c | 2021-09-07 15:53:09 -0400 | [diff] [blame] | 628 | float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density; |
| 629 | float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density; |
Alex Chau | d3e8cc4 | 2022-05-03 17:45:34 +0100 | [diff] [blame] | 630 | int rotation = WindowManagerProxy.INSTANCE.get(context).getRotation(context); |
| 631 | |
| 632 | if (Utilities.IS_DEBUG_DEVICE) { |
| 633 | StringWriter stringWriter = new StringWriter(); |
| 634 | PrintWriter printWriter = new PrintWriter(stringWriter); |
| 635 | DisplayController.INSTANCE.get(context).dump(printWriter); |
| 636 | printWriter.flush(); |
| 637 | Log.d("b/231312158", "getDeviceProfile -" |
| 638 | + "\nconfig: " + config |
| 639 | + "\ndisplayMetrics: " + res.getDisplayMetrics() |
| 640 | + "\nrotation: " + rotation |
| 641 | + "\n" + stringWriter.toString(), |
| 642 | new Exception()); |
| 643 | } |
| 644 | return getBestMatch(screenWidth, screenHeight, rotation); |
Sunny Goyal | 3e9a29c | 2021-09-07 15:53:09 -0400 | [diff] [blame] | 645 | } |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 646 | |
Sunny Goyal | 187b16c | 2022-03-01 16:53:23 -0800 | [diff] [blame] | 647 | /** |
| 648 | * Returns the device profile matching the provided screen configuration |
| 649 | */ |
| 650 | public DeviceProfile getBestMatch(float screenWidth, float screenHeight, int rotation) { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 651 | DeviceProfile bestMatch = supportedProfiles.get(0); |
| 652 | float minDiff = Float.MAX_VALUE; |
| 653 | |
| 654 | for (DeviceProfile profile : supportedProfiles) { |
Sunny Goyal | 3e9a29c | 2021-09-07 15:53:09 -0400 | [diff] [blame] | 655 | float diff = Math.abs(profile.widthPx - screenWidth) |
| 656 | + Math.abs(profile.heightPx - screenHeight); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 657 | if (diff < minDiff) { |
| 658 | minDiff = diff; |
| 659 | bestMatch = profile; |
Sunny Goyal | 187b16c | 2022-03-01 16:53:23 -0800 | [diff] [blame] | 660 | } else if (diff == minDiff && profile.rotationHint == rotation) { |
| 661 | bestMatch = profile; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 662 | } |
| 663 | } |
| 664 | return bestMatch; |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 665 | } |
| 666 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 667 | private static float weight(float x0, float y0, float x1, float y1, float pow) { |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 668 | float d = dist(x0, y0, x1, y1); |
| 669 | if (Float.compare(d, 0f) == 0) { |
| 670 | return Float.POSITIVE_INFINITY; |
| 671 | } |
| 672 | return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow)); |
| 673 | } |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 674 | |
| 675 | /** |
| 676 | * As a ratio of screen height, the total distance we want the parallax effect to span |
| 677 | * horizontally |
| 678 | */ |
| 679 | private static float wallpaperTravelToScreenWidthRatio(int width, int height) { |
| 680 | float aspectRatio = width / (float) height; |
| 681 | |
| 682 | // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width |
| 683 | // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width |
| 684 | // We will use these two data points to extrapolate how much the wallpaper parallax effect |
| 685 | // to span (ie travel) at any aspect ratio: |
| 686 | |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 687 | final float ASPECT_RATIO_LANDSCAPE = 16 / 10f; |
| 688 | final float ASPECT_RATIO_PORTRAIT = 10 / 16f; |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 689 | final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f; |
| 690 | final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f; |
| 691 | |
| 692 | // To find out the desired width at different aspect ratios, we use the following two |
| 693 | // formulas, where the coefficient on x is the aspect ratio (width/height): |
| 694 | // (16/10)x + y = 1.5 |
| 695 | // (10/16)x + y = 1.2 |
| 696 | // We solve for x and y and end up with a final formula: |
| 697 | final float x = |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 698 | (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE |
| 699 | - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) / |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 700 | (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT); |
| 701 | final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT; |
| 702 | return x * aspectRatio + y; |
| 703 | } |
| 704 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 705 | public interface OnIDPChangeListener { |
| 706 | |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 707 | /** |
| 708 | * Called when the device provide changes |
| 709 | */ |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 710 | void onIdpChanged(boolean modelPropertiesChanged); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 711 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 712 | |
| 713 | |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 714 | public static final class GridOption { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 715 | |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 716 | public static final String TAG_NAME = "grid-option"; |
| 717 | |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 718 | private static final int DEVICE_CATEGORY_PHONE = 1 << 0; |
| 719 | private static final int DEVICE_CATEGORY_TABLET = 1 << 1; |
| 720 | private static final int DEVICE_CATEGORY_MULTI_DISPLAY = 1 << 2; |
| 721 | private static final int DEVICE_CATEGORY_ALL = |
| 722 | DEVICE_CATEGORY_PHONE | DEVICE_CATEGORY_TABLET | DEVICE_CATEGORY_MULTI_DISPLAY; |
| 723 | |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 724 | public final String name; |
| 725 | public final int numRows; |
| 726 | public final int numColumns; |
Alex Chau | 9fee3fd | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 727 | public final int numSearchContainerColumns; |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 728 | public final boolean isEnabled; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 729 | |
| 730 | private final int numFolderRows; |
| 731 | private final int numFolderColumns; |
| 732 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 733 | private final int numAllAppsColumns; |
| 734 | private final int numDatabaseAllAppsColumns; |
| 735 | private final int numHotseatIcons; |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 736 | private final int numShrunkenHotseatIcons; |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame] | 737 | private final int numDatabaseHotseatIcons; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 738 | |
Tracy Zhou | 7df93d2 | 2020-01-27 13:44:06 -0800 | [diff] [blame] | 739 | private final String dbFile; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 740 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 741 | private final int defaultLayoutId; |
| 742 | private final int demoModeLayoutId; |
| 743 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 744 | private final boolean isScalable; |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 745 | private final int devicePaddingId; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 746 | |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 747 | private final SparseArray<TypedValue> extraAttrs; |
| 748 | |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 749 | public GridOption(Context context, AttributeSet attrs, @DeviceType int deviceType) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 750 | TypedArray a = context.obtainStyledAttributes( |
| 751 | attrs, R.styleable.GridDisplayOption); |
| 752 | name = a.getString(R.styleable.GridDisplayOption_name); |
| 753 | numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0); |
| 754 | numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0); |
Alex Chau | 9fee3fd | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 755 | numSearchContainerColumns = a.getInt( |
| 756 | R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 757 | |
Tracy Zhou | 7df93d2 | 2020-01-27 13:44:06 -0800 | [diff] [blame] | 758 | dbFile = a.getString(R.styleable.GridDisplayOption_dbFile); |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 759 | defaultLayoutId = a.getResourceId(deviceType == TYPE_MULTI_DISPLAY && a.hasValue( |
Alex Chau | 1e44846 | 2021-08-13 21:48:35 +0100 | [diff] [blame] | 760 | R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId) |
| 761 | ? R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId |
| 762 | : R.styleable.GridDisplayOption_defaultLayoutId, 0); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 763 | demoModeLayoutId = a.getResourceId( |
| 764 | R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 765 | |
| 766 | numAllAppsColumns = a.getInt( |
| 767 | R.styleable.GridDisplayOption_numAllAppsColumns, numColumns); |
| 768 | numDatabaseAllAppsColumns = a.getInt( |
| 769 | R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns); |
| 770 | |
| 771 | numHotseatIcons = a.getInt( |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 772 | R.styleable.GridDisplayOption_numHotseatIcons, numColumns); |
Alex Chau | 6ed408f | 2022-03-04 12:58:05 +0000 | [diff] [blame] | 773 | numShrunkenHotseatIcons = a.getInt( |
| 774 | R.styleable.GridDisplayOption_numShrunkenHotseatIcons, numHotseatIcons / 2); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 775 | numDatabaseHotseatIcons = a.getInt( |
| 776 | R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons); |
| 777 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 778 | numFolderRows = a.getInt( |
| 779 | R.styleable.GridDisplayOption_numFolderRows, numRows); |
| 780 | numFolderColumns = a.getInt( |
| 781 | R.styleable.GridDisplayOption_numFolderColumns, numColumns); |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 782 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 783 | isScalable = a.getBoolean( |
| 784 | R.styleable.GridDisplayOption_isScalable, false); |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 785 | devicePaddingId = a.getResourceId( |
| 786 | R.styleable.GridDisplayOption_devicePaddingId, 0); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 787 | |
Alex Chau | 1c883d8 | 2021-12-01 18:43:10 +0000 | [diff] [blame] | 788 | int deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory, |
| 789 | DEVICE_CATEGORY_ALL); |
| 790 | isEnabled = (deviceType == TYPE_PHONE |
| 791 | && ((deviceCategory & DEVICE_CATEGORY_PHONE) == DEVICE_CATEGORY_PHONE)) |
| 792 | || (deviceType == TYPE_TABLET |
| 793 | && ((deviceCategory & DEVICE_CATEGORY_TABLET) == DEVICE_CATEGORY_TABLET)) |
| 794 | || (deviceType == TYPE_MULTI_DISPLAY |
| 795 | && ((deviceCategory & DEVICE_CATEGORY_MULTI_DISPLAY) |
| 796 | == DEVICE_CATEGORY_MULTI_DISPLAY)); |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 797 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 798 | a.recycle(); |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 799 | extraAttrs = Themes.createValueMap(context, attrs, |
| 800 | IntArray.wrap(R.styleable.GridDisplayOption)); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 801 | } |
| 802 | } |
| 803 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 804 | @VisibleForTesting |
| 805 | static final class DisplayOption { |
Thales Lima | 12d0eff | 2022-03-25 17:06:11 +0000 | [diff] [blame] | 806 | private static final int INLINE_QSB_FOR_PORTRAIT = 1 << 0; |
| 807 | private static final int INLINE_QSB_FOR_LANDSCAPE = 1 << 1; |
| 808 | private static final int INLINE_QSB_FOR_TWO_PANEL_PORTRAIT = 1 << 2; |
| 809 | private static final int INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE = 1 << 3; |
| 810 | private static final int DONT_INLINE_QSB = 0; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 811 | |
| 812 | public final GridOption grid; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 813 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 814 | private final float minWidthDps; |
| 815 | private final float minHeightDps; |
| 816 | private final boolean canBeDefault; |
Thales Lima | 12d0eff | 2022-03-25 17:06:11 +0000 | [diff] [blame] | 817 | private final boolean[] inlineQsb = new boolean[COUNT_SIZES]; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 818 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 819 | private final PointF[] minCellSize = new PointF[COUNT_SIZES]; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 820 | |
| 821 | private float folderBorderSpace; |
| 822 | private final PointF[] borderSpaces = new PointF[COUNT_SIZES]; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 823 | private final float[] horizontalMargin = new float[COUNT_SIZES]; |
Thales Lima | 6e7f36c | 2022-01-04 12:14:11 +0000 | [diff] [blame] | 824 | private final float[] hotseatBorderSpaces = new float[COUNT_SIZES]; |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 825 | |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 826 | private final float[] iconSizes = new float[COUNT_SIZES]; |
| 827 | private final float[] textSizes = new float[COUNT_SIZES]; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 828 | |
Thales Lima | b7ef569 | 2022-03-10 10:32:36 +0000 | [diff] [blame] | 829 | private final PointF[] allAppsCellSize = new PointF[COUNT_SIZES]; |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 830 | private final float[] allAppsIconSizes = new float[COUNT_SIZES]; |
| 831 | private final float[] allAppsIconTextSizes = new float[COUNT_SIZES]; |
| 832 | private final PointF[] allAppsBorderSpaces = new PointF[COUNT_SIZES]; |
| 833 | |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame] | 834 | DisplayOption(GridOption grid, Context context, AttributeSet attrs) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 835 | this.grid = grid; |
| 836 | |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame] | 837 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 838 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 839 | minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0); |
| 840 | minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 841 | |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame] | 842 | canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 843 | |
Thales Lima | 12d0eff | 2022-03-25 17:06:11 +0000 | [diff] [blame] | 844 | int inlineForRotation = a.getInt(R.styleable.ProfileDisplayOption_inlineQsb, |
| 845 | DONT_INLINE_QSB); |
| 846 | inlineQsb[INDEX_DEFAULT] = |
| 847 | (inlineForRotation & INLINE_QSB_FOR_PORTRAIT) == INLINE_QSB_FOR_PORTRAIT; |
| 848 | inlineQsb[INDEX_LANDSCAPE] = |
| 849 | (inlineForRotation & INLINE_QSB_FOR_LANDSCAPE) == INLINE_QSB_FOR_LANDSCAPE; |
| 850 | inlineQsb[INDEX_TWO_PANEL_PORTRAIT] = |
| 851 | (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_PORTRAIT) |
| 852 | == INLINE_QSB_FOR_TWO_PANEL_PORTRAIT; |
| 853 | inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] = |
| 854 | (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE) |
| 855 | == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE; |
| 856 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 857 | float x; |
| 858 | float y; |
| 859 | |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 860 | x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidth, 0); |
| 861 | y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeight, 0); |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 862 | minCellSize[INDEX_DEFAULT] = new PointF(x, y); |
Thales Lima | dd02734 | 2022-01-07 12:54:37 +0000 | [diff] [blame] | 863 | |
| 864 | x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthLandscape, |
| 865 | minCellSize[INDEX_DEFAULT].x); |
| 866 | y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightLandscape, |
| 867 | minCellSize[INDEX_DEFAULT].y); |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 868 | minCellSize[INDEX_LANDSCAPE] = new PointF(x, y); |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 869 | |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 870 | x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelPortrait, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 871 | minCellSize[INDEX_DEFAULT].x); |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 872 | y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelPortrait, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 873 | minCellSize[INDEX_DEFAULT].y); |
| 874 | minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y); |
| 875 | |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 876 | x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthTwoPanelLandscape, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 877 | minCellSize[INDEX_DEFAULT].x); |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 878 | y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightTwoPanelLandscape, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 879 | minCellSize[INDEX_DEFAULT].y); |
| 880 | minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 881 | |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 882 | float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpace, 0); |
Thales Lima | 44cc3a2 | 2022-03-18 14:28:24 +0000 | [diff] [blame] | 883 | float borderSpaceLandscape = a.getFloat( |
| 884 | R.styleable.ProfileDisplayOption_borderSpaceLandscape, borderSpace); |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 885 | float borderSpaceTwoPanelPortrait = a.getFloat( |
| 886 | R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortrait, borderSpace); |
| 887 | float borderSpaceTwoPanelLandscape = a.getFloat( |
| 888 | R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscape, borderSpace); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 889 | |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 890 | x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontal, borderSpace); |
| 891 | y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVertical, borderSpace); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 892 | borderSpaces[INDEX_DEFAULT] = new PointF(x, y); |
Thales Lima | 44cc3a2 | 2022-03-18 14:28:24 +0000 | [diff] [blame] | 893 | |
| 894 | x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeHorizontal, |
| 895 | borderSpaceLandscape); |
| 896 | y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceLandscapeVertical, |
| 897 | borderSpaceLandscape); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 898 | borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y); |
| 899 | |
| 900 | x = a.getFloat( |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 901 | R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitHorizontal, |
| 902 | borderSpaceTwoPanelPortrait); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 903 | y = a.getFloat( |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 904 | R.styleable.ProfileDisplayOption_borderSpaceTwoPanelPortraitVertical, |
| 905 | borderSpaceTwoPanelPortrait); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 906 | borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y); |
| 907 | |
| 908 | x = a.getFloat( |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 909 | R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeHorizontal, |
| 910 | borderSpaceTwoPanelLandscape); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 911 | y = a.getFloat( |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 912 | R.styleable.ProfileDisplayOption_borderSpaceTwoPanelLandscapeVertical, |
| 913 | borderSpaceTwoPanelLandscape); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 914 | borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y); |
| 915 | |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 916 | folderBorderSpace = borderSpace; |
| 917 | |
Thales Lima | b7ef569 | 2022-03-10 10:32:36 +0000 | [diff] [blame] | 918 | x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidth, |
| 919 | minCellSize[INDEX_DEFAULT].x); |
| 920 | y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeight, |
| 921 | minCellSize[INDEX_DEFAULT].y); |
| 922 | allAppsCellSize[INDEX_DEFAULT] = new PointF(x, y); |
| 923 | |
| 924 | x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthLandscape, |
| 925 | allAppsCellSize[INDEX_DEFAULT].x); |
| 926 | y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightLandscape, |
| 927 | allAppsCellSize[INDEX_DEFAULT].y); |
| 928 | allAppsCellSize[INDEX_LANDSCAPE] = new PointF(x, y); |
| 929 | |
| 930 | x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelPortrait, |
| 931 | allAppsCellSize[INDEX_DEFAULT].x); |
| 932 | y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelPortrait, |
| 933 | allAppsCellSize[INDEX_DEFAULT].y); |
| 934 | allAppsCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y); |
| 935 | |
| 936 | x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellWidthTwoPanelLandscape, |
| 937 | allAppsCellSize[INDEX_DEFAULT].x); |
| 938 | y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellHeightTwoPanelLandscape, |
| 939 | allAppsCellSize[INDEX_DEFAULT].y); |
| 940 | allAppsCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y); |
| 941 | |
Thales Lima | 080d890 | 2022-03-28 15:30:29 +0100 | [diff] [blame] | 942 | float allAppsBorderSpace = a.getFloat( |
| 943 | R.styleable.ProfileDisplayOption_allAppsBorderSpace, borderSpace); |
| 944 | float allAppsBorderSpaceLandscape = a.getFloat( |
| 945 | R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscape, |
| 946 | allAppsBorderSpace); |
| 947 | float allAppsBorderSpaceTwoPanelPortrait = a.getFloat( |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 948 | R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortrait, |
Thales Lima | 080d890 | 2022-03-28 15:30:29 +0100 | [diff] [blame] | 949 | allAppsBorderSpace); |
| 950 | float allAppsBorderSpaceTwoPanelLandscape = a.getFloat( |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 951 | R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscape, |
Thales Lima | 080d890 | 2022-03-28 15:30:29 +0100 | [diff] [blame] | 952 | allAppsBorderSpace); |
| 953 | |
| 954 | x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceHorizontal, |
| 955 | allAppsBorderSpace); |
| 956 | y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceVertical, |
| 957 | allAppsBorderSpace); |
| 958 | allAppsBorderSpaces[INDEX_DEFAULT] = new PointF(x, y); |
| 959 | |
| 960 | x = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeHorizontal, |
| 961 | allAppsBorderSpaceLandscape); |
| 962 | y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsBorderSpaceLandscapeVertical, |
| 963 | allAppsBorderSpaceLandscape); |
| 964 | allAppsBorderSpaces[INDEX_LANDSCAPE] = new PointF(x, y); |
| 965 | |
| 966 | x = a.getFloat( |
| 967 | R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitHorizontal, |
| 968 | allAppsBorderSpaceTwoPanelPortrait); |
| 969 | y = a.getFloat( |
| 970 | R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelPortraitVertical, |
| 971 | allAppsBorderSpaceTwoPanelPortrait); |
| 972 | allAppsBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y); |
| 973 | |
| 974 | x = a.getFloat( |
| 975 | R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeHorizontal, |
| 976 | allAppsBorderSpaceTwoPanelLandscape); |
| 977 | y = a.getFloat( |
| 978 | R.styleable.ProfileDisplayOption_allAppsBorderSpaceTwoPanelLandscapeVertical, |
| 979 | allAppsBorderSpaceTwoPanelLandscape); |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 980 | allAppsBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 981 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 982 | iconSizes[INDEX_DEFAULT] = |
| 983 | a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0); |
| 984 | iconSizes[INDEX_LANDSCAPE] = |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 985 | a.getFloat(R.styleable.ProfileDisplayOption_iconSizeLandscape, |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 986 | iconSizes[INDEX_DEFAULT]); |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 987 | iconSizes[INDEX_TWO_PANEL_PORTRAIT] = |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 988 | a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelPortrait, |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 989 | iconSizes[INDEX_DEFAULT]); |
| 990 | iconSizes[INDEX_TWO_PANEL_LANDSCAPE] = |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 991 | a.getFloat(R.styleable.ProfileDisplayOption_iconSizeTwoPanelLandscape, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 992 | iconSizes[INDEX_DEFAULT]); |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 993 | |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 994 | allAppsIconSizes[INDEX_DEFAULT] = a.getFloat( |
| 995 | R.styleable.ProfileDisplayOption_allAppsIconSize, iconSizes[INDEX_DEFAULT]); |
| 996 | allAppsIconSizes[INDEX_LANDSCAPE] = allAppsIconSizes[INDEX_DEFAULT]; |
| 997 | allAppsIconSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat( |
| 998 | R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelPortrait, |
| 999 | allAppsIconSizes[INDEX_DEFAULT]); |
| 1000 | allAppsIconSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat( |
| 1001 | R.styleable.ProfileDisplayOption_allAppsIconSizeTwoPanelLandscape, |
| 1002 | allAppsIconSizes[INDEX_DEFAULT]); |
| 1003 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 1004 | textSizes[INDEX_DEFAULT] = |
| 1005 | a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0); |
| 1006 | textSizes[INDEX_LANDSCAPE] = |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1007 | a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeLandscape, |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 1008 | textSizes[INDEX_DEFAULT]); |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 1009 | textSizes[INDEX_TWO_PANEL_PORTRAIT] = |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1010 | a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelPortrait, |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 1011 | textSizes[INDEX_DEFAULT]); |
| 1012 | textSizes[INDEX_TWO_PANEL_LANDSCAPE] = |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1013 | a.getFloat(R.styleable.ProfileDisplayOption_iconTextSizeTwoPanelLandscape, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1014 | textSizes[INDEX_DEFAULT]); |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 1015 | |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 1016 | allAppsIconTextSizes[INDEX_DEFAULT] = a.getFloat( |
| 1017 | R.styleable.ProfileDisplayOption_allAppsIconTextSize, textSizes[INDEX_DEFAULT]); |
| 1018 | allAppsIconTextSizes[INDEX_LANDSCAPE] = allAppsIconTextSizes[INDEX_DEFAULT]; |
| 1019 | allAppsIconTextSizes[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat( |
| 1020 | R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelPortrait, |
| 1021 | allAppsIconTextSizes[INDEX_DEFAULT]); |
| 1022 | allAppsIconTextSizes[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat( |
| 1023 | R.styleable.ProfileDisplayOption_allAppsIconTextSizeTwoPanelLandscape, |
| 1024 | allAppsIconTextSizes[INDEX_DEFAULT]); |
| 1025 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1026 | horizontalMargin[INDEX_DEFAULT] = a.getFloat( |
| 1027 | R.styleable.ProfileDisplayOption_horizontalMargin, 0); |
Thales Lima | dd02734 | 2022-01-07 12:54:37 +0000 | [diff] [blame] | 1028 | horizontalMargin[INDEX_LANDSCAPE] = a.getFloat( |
| 1029 | R.styleable.ProfileDisplayOption_horizontalMarginLandscape, |
| 1030 | horizontalMargin[INDEX_DEFAULT]); |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1031 | horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat( |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1032 | R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelLandscape, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1033 | horizontalMargin[INDEX_DEFAULT]); |
| 1034 | horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat( |
Thales Lima | 85c942f | 2021-12-31 13:04:20 +0000 | [diff] [blame] | 1035 | R.styleable.ProfileDisplayOption_horizontalMarginTwoPanelPortrait, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1036 | horizontalMargin[INDEX_DEFAULT]); |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 1037 | |
Thales Lima | 6e7f36c | 2022-01-04 12:14:11 +0000 | [diff] [blame] | 1038 | hotseatBorderSpaces[INDEX_DEFAULT] = a.getFloat( |
| 1039 | R.styleable.ProfileDisplayOption_hotseatBorderSpace, borderSpace); |
Thales Lima | dd02734 | 2022-01-07 12:54:37 +0000 | [diff] [blame] | 1040 | hotseatBorderSpaces[INDEX_LANDSCAPE] = a.getFloat( |
| 1041 | R.styleable.ProfileDisplayOption_hotseatBorderSpaceLandscape, |
| 1042 | hotseatBorderSpaces[INDEX_DEFAULT]); |
Thales Lima | 6e7f36c | 2022-01-04 12:14:11 +0000 | [diff] [blame] | 1043 | hotseatBorderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat( |
| 1044 | R.styleable.ProfileDisplayOption_hotseatBorderSpaceTwoPanelLandscape, |
| 1045 | hotseatBorderSpaces[INDEX_DEFAULT]); |
| 1046 | hotseatBorderSpaces[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat( |
| 1047 | R.styleable.ProfileDisplayOption_hotseatBorderSpaceTwoPanelPortrait, |
| 1048 | hotseatBorderSpaces[INDEX_DEFAULT]); |
| 1049 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1050 | a.recycle(); |
| 1051 | } |
| 1052 | |
| 1053 | DisplayOption() { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 1054 | this(null); |
| 1055 | } |
| 1056 | |
| 1057 | DisplayOption(GridOption grid) { |
| 1058 | this.grid = grid; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1059 | minWidthDps = 0; |
| 1060 | minHeightDps = 0; |
| 1061 | canBeDefault = false; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1062 | for (int i = 0; i < COUNT_SIZES; i++) { |
| 1063 | iconSizes[i] = 0; |
| 1064 | textSizes[i] = 0; |
| 1065 | borderSpaces[i] = new PointF(); |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1066 | minCellSize[i] = new PointF(); |
Thales Lima | b7ef569 | 2022-03-10 10:32:36 +0000 | [diff] [blame] | 1067 | allAppsCellSize[i] = new PointF(); |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 1068 | allAppsIconSizes[i] = 0; |
| 1069 | allAppsIconTextSizes[i] = 0; |
| 1070 | allAppsBorderSpaces[i] = new PointF(); |
Thales Lima | 12d0eff | 2022-03-25 17:06:11 +0000 | [diff] [blame] | 1071 | inlineQsb[i] = false; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1072 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | private DisplayOption multiply(float w) { |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1076 | for (int i = 0; i < COUNT_SIZES; i++) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 1077 | iconSizes[i] *= w; |
| 1078 | textSizes[i] *= w; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1079 | borderSpaces[i].x *= w; |
| 1080 | borderSpaces[i].y *= w; |
| 1081 | minCellSize[i].x *= w; |
| 1082 | minCellSize[i].y *= w; |
| 1083 | horizontalMargin[i] *= w; |
Thales Lima | 6e7f36c | 2022-01-04 12:14:11 +0000 | [diff] [blame] | 1084 | hotseatBorderSpaces[i] *= w; |
Thales Lima | b7ef569 | 2022-03-10 10:32:36 +0000 | [diff] [blame] | 1085 | allAppsCellSize[i].x *= w; |
| 1086 | allAppsCellSize[i].y *= w; |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 1087 | allAppsIconSizes[i] *= w; |
| 1088 | allAppsIconTextSizes[i] *= w; |
| 1089 | allAppsBorderSpaces[i].x *= w; |
| 1090 | allAppsBorderSpaces[i].y *= w; |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 1091 | } |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1092 | |
| 1093 | folderBorderSpace *= w; |
| 1094 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1095 | return this; |
| 1096 | } |
| 1097 | |
| 1098 | private DisplayOption add(DisplayOption p) { |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1099 | for (int i = 0; i < COUNT_SIZES; i++) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 1100 | iconSizes[i] += p.iconSizes[i]; |
| 1101 | textSizes[i] += p.textSizes[i]; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 1102 | borderSpaces[i].x += p.borderSpaces[i].x; |
| 1103 | borderSpaces[i].y += p.borderSpaces[i].y; |
| 1104 | minCellSize[i].x += p.minCellSize[i].x; |
| 1105 | minCellSize[i].y += p.minCellSize[i].y; |
| 1106 | horizontalMargin[i] += p.horizontalMargin[i]; |
Thales Lima | 6e7f36c | 2022-01-04 12:14:11 +0000 | [diff] [blame] | 1107 | hotseatBorderSpaces[i] += p.hotseatBorderSpaces[i]; |
Thales Lima | b7ef569 | 2022-03-10 10:32:36 +0000 | [diff] [blame] | 1108 | allAppsCellSize[i].x += p.allAppsCellSize[i].x; |
| 1109 | allAppsCellSize[i].y += p.allAppsCellSize[i].y; |
Thales Lima | bb7d388 | 2021-12-22 12:56:29 +0000 | [diff] [blame] | 1110 | allAppsIconSizes[i] += p.allAppsIconSizes[i]; |
| 1111 | allAppsIconTextSizes[i] += p.allAppsIconTextSizes[i]; |
| 1112 | allAppsBorderSpaces[i].x += p.allAppsBorderSpaces[i].x; |
| 1113 | allAppsBorderSpaces[i].y += p.allAppsBorderSpaces[i].y; |
Thales Lima | 12d0eff | 2022-03-25 17:06:11 +0000 | [diff] [blame] | 1114 | inlineQsb[i] |= p.inlineQsb[i]; |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 1115 | } |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 1116 | |
| 1117 | folderBorderSpace += p.folderBorderSpace; |
| 1118 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 1119 | return this; |
| 1120 | } |
| 1121 | } |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 1122 | } |