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; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 22 | import static com.android.launcher3.util.DisplayController.CHANGE_SUPPORTED_BOUNDS; |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 23 | import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 24 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 25 | import android.annotation.TargetApi; |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 26 | import android.appwidget.AppWidgetHostView; |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 27 | import android.content.ComponentName; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 28 | import android.content.Context; |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 29 | import android.content.res.Configuration; |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 30 | import android.content.res.Resources; |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 31 | import android.content.res.TypedArray; |
| 32 | import android.content.res.XmlResourceParser; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 33 | import android.graphics.Point; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 34 | import android.graphics.PointF; |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 35 | import android.graphics.Rect; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 36 | import android.text.TextUtils; |
| 37 | import android.util.AttributeSet; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 38 | import android.util.DisplayMetrics; |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 39 | import android.util.Log; |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 40 | import android.util.SparseArray; |
| 41 | import android.util.TypedValue; |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 42 | import android.util.Xml; |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 43 | import android.view.Display; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 44 | |
Sunny Goyal | 6fe3eec | 2019-08-15 14:53:41 -0700 | [diff] [blame] | 45 | import androidx.annotation.Nullable; |
| 46 | import androidx.annotation.VisibleForTesting; |
| 47 | |
Sunny Goyal | 68031ca | 2021-08-02 12:23:44 -0700 | [diff] [blame] | 48 | import com.android.launcher3.model.DeviceGridState; |
Alex Chau | 238aaee | 2021-10-06 16:15:24 +0100 | [diff] [blame] | 49 | import com.android.launcher3.provider.RestoreDbTask; |
Sunny Goyal | fd58da6 | 2020-08-11 12:06:49 -0700 | [diff] [blame] | 50 | import com.android.launcher3.util.DisplayController; |
| 51 | import com.android.launcher3.util.DisplayController.Info; |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 52 | import com.android.launcher3.util.IntArray; |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 53 | import com.android.launcher3.util.MainThreadInitializedObject; |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 54 | import com.android.launcher3.util.Themes; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 55 | import com.android.launcher3.util.WindowBounds; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 56 | |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 57 | import org.xmlpull.v1.XmlPullParser; |
| 58 | import org.xmlpull.v1.XmlPullParserException; |
| 59 | |
| 60 | import java.io.IOException; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 61 | import java.util.ArrayList; |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 62 | import java.util.Arrays; |
Sunny Goyal | 6d55f66 | 2019-01-02 12:13:43 -0800 | [diff] [blame] | 63 | import java.util.Collections; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 64 | import java.util.List; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 65 | |
| 66 | public class InvariantDeviceProfile { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 67 | |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 68 | public static final String TAG = "IDP"; |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 69 | // We do not need any synchronization for this variable as its only written on UI thread. |
| 70 | public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE = |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 71 | new MainThreadInitializedObject<>(InvariantDeviceProfile::new); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 72 | |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 73 | private static final String KEY_IDP_GRID_NAME = "idp_grid_name"; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 74 | |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 75 | private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48; |
| 76 | |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 77 | // Constants that affects the interpolation curve between statically defined device profile |
| 78 | // buckets. |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 79 | private static final float KNEARESTNEIGHBOR = 3; |
| 80 | private static final float WEIGHT_POWER = 5; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 81 | |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 82 | // 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] | 83 | private static final float WEIGHT_EFFICIENT = 100000f; |
| 84 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 85 | // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different |
| 86 | // constraints |
| 87 | static final int COUNT_SIZES = 5; |
| 88 | static final int INDEX_DEFAULT = 0; |
| 89 | static final int INDEX_LANDSCAPE = 1; |
| 90 | static final int INDEX_TWO_PANEL_PORTRAIT = 2; |
| 91 | static final int INDEX_TWO_PANEL_LANDSCAPE = 3; |
| 92 | static final int INDEX_ALL_APPS = 4; |
| 93 | |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 94 | /** |
| 95 | * Number of icons per row and column in the workspace. |
| 96 | */ |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 97 | public int numRows; |
| 98 | public int numColumns; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 99 | |
| 100 | /** |
| 101 | * Number of icons per row and column in the folder. |
| 102 | */ |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 103 | public int numFolderRows; |
| 104 | public int numFolderColumns; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 105 | public float[] iconSize; |
| 106 | public float[] iconTextSize; |
Sunny Goyal | fc21830 | 2015-09-17 14:59:10 -0700 | [diff] [blame] | 107 | public int iconBitmapSize; |
| 108 | public int fillResIconDpi; |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 109 | public boolean isSplitDisplay; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 110 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 111 | public PointF[] minCellSize; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 112 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 113 | public PointF[] borderSpaces; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 114 | public float folderBorderSpace; |
| 115 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 116 | public float[] horizontalMargin; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 117 | |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 118 | private SparseArray<TypedValue> mExtraAttrs; |
| 119 | |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 120 | /** |
| 121 | * Number of icons inside the hotseat area. |
| 122 | */ |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame] | 123 | protected int numShownHotseatIcons; |
| 124 | |
| 125 | /** |
| 126 | * Number of icons inside the hotseat area that is stored in the database. This is greater than |
| 127 | * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat |
| 128 | * sizes that share the same DB. |
| 129 | */ |
| 130 | public int numDatabaseHotseatIcons; |
Adam Cohen | 2782449 | 2017-09-22 17:10:55 -0700 | [diff] [blame] | 131 | |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 132 | /** |
| 133 | * Number of columns in the all apps list. |
| 134 | */ |
| 135 | public int numAllAppsColumns; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 136 | public int numDatabaseAllAppsColumns; |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 137 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 138 | /** |
| 139 | * Do not query directly. see {@link DeviceProfile#isScalableGrid}. |
| 140 | */ |
| 141 | protected boolean isScalable; |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 142 | public int devicePaddingId; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 143 | |
Tracy Zhou | 7df93d2 | 2020-01-27 13:44:06 -0800 | [diff] [blame] | 144 | public String dbFile; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 145 | public int defaultLayoutId; |
Adam Cohen | 2782449 | 2017-09-22 17:10:55 -0700 | [diff] [blame] | 146 | int demoModeLayoutId; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 147 | |
Pinyao Ting | 9cd63c9 | 2021-06-16 17:51:39 +0000 | [diff] [blame] | 148 | /** |
| 149 | * An immutable list of supported profiles. |
| 150 | */ |
| 151 | public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 152 | |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 153 | @Nullable |
| 154 | public DevicePaddings devicePaddings; |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 155 | |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 156 | public Point defaultWallpaperSize; |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 157 | public Rect defaultWidgetPadding; |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 158 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 159 | private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>(); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 160 | |
Sunny Goyal | f633ef5 | 2018-03-13 09:57:05 -0700 | [diff] [blame] | 161 | @VisibleForTesting |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 162 | public InvariantDeviceProfile() { |
| 163 | } |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 164 | |
Sunny Goyal | bbf0184 | 2015-10-08 07:41:15 -0700 | [diff] [blame] | 165 | @TargetApi(23) |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 166 | private InvariantDeviceProfile(Context context) { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 167 | String gridName = getCurrentGridName(context); |
| 168 | String newGridName = initGrid(context, gridName); |
| 169 | if (!newGridName.equals(gridName)) { |
| 170 | Utilities.getPrefs(context).edit().putString(KEY_IDP_GRID_NAME, newGridName).apply(); |
| 171 | } |
Sunny Goyal | 68031ca | 2021-08-02 12:23:44 -0700 | [diff] [blame] | 172 | new DeviceGridState(this).writeToPrefs(context); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 173 | |
Tracy Zhou | c8beebf | 2021-09-23 10:18:11 -0700 | [diff] [blame] | 174 | DisplayController.INSTANCE.get(context).setPriorityListener( |
Alex Chau | fd6d942 | 2021-04-22 19:10:21 +0100 | [diff] [blame] | 175 | (displayContext, info, flags) -> { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 176 | if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS)) != 0) { |
Alex Chau | fd6d942 | 2021-04-22 19:10:21 +0100 | [diff] [blame] | 177 | onConfigChanged(displayContext); |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 178 | } |
| 179 | }); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Hyunyoung Song | e11eb47 | 2019-03-19 15:05:21 -0700 | [diff] [blame] | 182 | /** |
| 183 | * This constructor should NOT have any monitors by design. |
| 184 | */ |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 185 | public InvariantDeviceProfile(Context context, String gridName) { |
| 186 | String newName = initGrid(context, gridName); |
| 187 | if (newName == null || !newName.equals(gridName)) { |
| 188 | throw new IllegalArgumentException("Unknown grid name"); |
| 189 | } |
| 190 | } |
| 191 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 192 | /** |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 193 | * This constructor should NOT have any monitors by design. |
| 194 | */ |
| 195 | public InvariantDeviceProfile(Context context, Display display) { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 196 | // Ensure that the main device profile is initialized |
Alex Chau | fd6d942 | 2021-04-22 19:10:21 +0100 | [diff] [blame] | 197 | INSTANCE.get(context); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 198 | String gridName = getCurrentGridName(context); |
| 199 | |
| 200 | // Get the display info based on default display and interpolate it to existing display |
| 201 | DisplayOption defaultDisplayOption = invDistWeightedInterpolate( |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 202 | DisplayController.INSTANCE.get(context).getInfo(), |
Alex Chau | 238aaee | 2021-10-06 16:15:24 +0100 | [diff] [blame] | 203 | getPredefinedDeviceProfiles(context, gridName, false, false), false); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 204 | |
Alex Chau | 417bd72 | 2021-01-26 15:22:18 +0000 | [diff] [blame] | 205 | Info myInfo = new Info(context, display); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 206 | DisplayOption myDisplayOption = invDistWeightedInterpolate( |
Alex Chau | 238aaee | 2021-10-06 16:15:24 +0100 | [diff] [blame] | 207 | myInfo, getPredefinedDeviceProfiles(context, gridName, false, false), false); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 208 | |
| 209 | DisplayOption result = new DisplayOption(defaultDisplayOption.grid) |
| 210 | .add(myDisplayOption); |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 211 | result.iconSizes[INDEX_DEFAULT] = |
| 212 | defaultDisplayOption.iconSizes[INDEX_DEFAULT]; |
| 213 | for (int i = 1; i < COUNT_SIZES; i++) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 214 | result.iconSizes[i] = Math.min( |
| 215 | defaultDisplayOption.iconSizes[i], myDisplayOption.iconSizes[i]); |
Alex Chau | 7c43972 | 2021-03-24 11:32:44 +0000 | [diff] [blame] | 216 | } |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 217 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 218 | System.arraycopy(defaultDisplayOption.minCellSize, 0, result.minCellSize, 0, |
| 219 | COUNT_SIZES); |
| 220 | System.arraycopy(defaultDisplayOption.borderSpaces, 0, result.borderSpaces, 0, |
| 221 | COUNT_SIZES); |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 222 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 223 | initGrid(context, myInfo, result, false); |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 224 | } |
| 225 | |
Alex Chau | 238aaee | 2021-10-06 16:15:24 +0100 | [diff] [blame] | 226 | /** |
| 227 | * Reinitialize the current grid after a restore, where some grids might now be disabled. |
| 228 | */ |
| 229 | public void reinitializeAfterRestore(Context context) { |
| 230 | String currentDbFile = dbFile; |
| 231 | String gridName = getCurrentGridName(context); |
| 232 | String newGridName = initGrid(context, gridName); |
| 233 | if (!newGridName.equals(gridName)) { |
| 234 | Log.d(TAG, "Restored grid is disabled : " + gridName |
| 235 | + ", migrating to: " + newGridName |
| 236 | + ", removing all other grid db files"); |
| 237 | for (String gridDbFile : LauncherFiles.GRID_DB_FILES) { |
| 238 | if (gridDbFile.equals(currentDbFile)) { |
| 239 | continue; |
| 240 | } |
| 241 | if (context.getDatabasePath(gridDbFile).delete()) { |
| 242 | Log.d(TAG, "Removed old grid db file: " + gridDbFile); |
| 243 | } |
| 244 | } |
| 245 | setCurrentGrid(context, gridName); |
| 246 | } |
| 247 | } |
| 248 | |
Tracy Zhou | 42255d2 | 2020-03-13 00:38:11 -0700 | [diff] [blame] | 249 | public static String getCurrentGridName(Context context) { |
Tracy Zhou | c6060e6 | 2020-04-27 13:05:34 -0700 | [diff] [blame] | 250 | return Utilities.isGridOptionsEnabled(context) |
| 251 | ? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null; |
Tracy Zhou | 42255d2 | 2020-03-13 00:38:11 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 254 | private String initGrid(Context context, String gridName) { |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 255 | Info displayInfo = DisplayController.INSTANCE.get(context).getInfo(); |
Pat Manning | 67094bf | 2021-05-26 12:38:13 +0000 | [diff] [blame] | 256 | // Each screen has two profiles (portrait/landscape), so devices with four or more |
| 257 | // supported profiles implies two or more internal displays. |
| 258 | boolean isSplitDisplay = |
| 259 | displayInfo.supportedBounds.size() >= 4 && ENABLE_TWO_PANEL_HOME.get(); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 260 | |
| 261 | ArrayList<DisplayOption> allOptions = |
Alex Chau | 238aaee | 2021-10-06 16:15:24 +0100 | [diff] [blame] | 262 | getPredefinedDeviceProfiles(context, gridName, isSplitDisplay, |
| 263 | RestoreDbTask.isPending(context)); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 264 | DisplayOption displayOption = |
| 265 | invDistWeightedInterpolate(displayInfo, allOptions, isSplitDisplay); |
| 266 | initGrid(context, displayInfo, displayOption, isSplitDisplay); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 267 | return displayOption.grid.name; |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 268 | } |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 269 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 270 | private void initGrid( |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 271 | Context context, Info displayInfo, DisplayOption displayOption, |
| 272 | boolean isSplitDisplay) { |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 273 | DisplayMetrics metrics = context.getResources().getDisplayMetrics(); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 274 | GridOption closestProfile = displayOption.grid; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 275 | numRows = closestProfile.numRows; |
| 276 | numColumns = closestProfile.numColumns; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 277 | dbFile = closestProfile.dbFile; |
| 278 | defaultLayoutId = closestProfile.defaultLayoutId; |
| 279 | demoModeLayoutId = closestProfile.demoModeLayoutId; |
| 280 | numFolderRows = closestProfile.numFolderRows; |
| 281 | numFolderColumns = closestProfile.numFolderColumns; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 282 | isScalable = closestProfile.isScalable; |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 283 | devicePaddingId = closestProfile.devicePaddingId; |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 284 | this.isSplitDisplay = isSplitDisplay; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 285 | |
| 286 | mExtraAttrs = closestProfile.extraAttrs; |
| 287 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 288 | iconSize = displayOption.iconSizes; |
Thales Lima | 6e0005a | 2021-10-27 15:53:41 +0100 | [diff] [blame^] | 289 | float maxIconSize = iconSize[0]; |
| 290 | for (int i = 1; i < iconSize.length; i++) { |
| 291 | maxIconSize = Math.max(maxIconSize, iconSize[i]); |
| 292 | } |
| 293 | iconBitmapSize = ResourceUtils.pxFromDp(maxIconSize, metrics); |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 294 | fillResIconDpi = getLauncherIconDensity(iconBitmapSize); |
| 295 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 296 | iconTextSize = displayOption.textSizes; |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 297 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 298 | minCellSize = displayOption.minCellSize; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 299 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 300 | borderSpaces = displayOption.borderSpaces; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 301 | folderBorderSpace = displayOption.folderBorderSpace; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 302 | |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 303 | horizontalMargin = displayOption.horizontalMargin; |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 304 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 305 | numShownHotseatIcons = closestProfile.numHotseatIcons; |
| 306 | numDatabaseHotseatIcons = isSplitDisplay |
| 307 | ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons; |
| 308 | |
| 309 | numAllAppsColumns = closestProfile.numAllAppsColumns; |
| 310 | numDatabaseAllAppsColumns = isSplitDisplay |
| 311 | ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 312 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 313 | if (!Utilities.isGridOptionsEnabled(context)) { |
| 314 | iconSize[INDEX_ALL_APPS] = iconSize[INDEX_DEFAULT]; |
| 315 | iconTextSize[INDEX_ALL_APPS] = iconTextSize[INDEX_DEFAULT]; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 316 | } |
| 317 | |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 318 | if (devicePaddingId != 0) { |
| 319 | devicePaddings = new DevicePaddings(context, devicePaddingId); |
| 320 | } |
| 321 | |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 322 | // If the partner customization apk contains any grid overrides, apply them |
| 323 | // Supported overrides: numRows, numColumns, iconSize |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 324 | applyPartnerDeviceProfileOverrides(context, metrics); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 325 | |
Pinyao Ting | 9cd63c9 | 2021-06-16 17:51:39 +0000 | [diff] [blame] | 326 | final List<DeviceProfile> localSupportedProfiles = new ArrayList<>(); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 327 | defaultWallpaperSize = new Point(displayInfo.currentSize); |
| 328 | for (WindowBounds bounds : displayInfo.supportedBounds) { |
Pinyao Ting | 9cd63c9 | 2021-06-16 17:51:39 +0000 | [diff] [blame] | 329 | localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo) |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 330 | .setUseTwoPanels(isSplitDisplay) |
| 331 | .setWindowBounds(bounds).build()); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 332 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 333 | // Wallpaper size should be the maximum of the all possible sizes Launcher expects |
| 334 | int displayWidth = bounds.bounds.width(); |
| 335 | int displayHeight = bounds.bounds.height(); |
| 336 | defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 337 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 338 | // We need to ensure that there is enough extra space in the wallpaper |
| 339 | // for the intended parallax effects |
| 340 | float parallaxFactor = |
| 341 | dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.densityDpi) < 720 |
| 342 | ? 2 |
| 343 | : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight); |
| 344 | defaultWallpaperSize.x = |
| 345 | Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth)); |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 346 | } |
Pinyao Ting | 9cd63c9 | 2021-06-16 17:51:39 +0000 | [diff] [blame] | 347 | supportedProfiles = Collections.unmodifiableList(localSupportedProfiles); |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 348 | |
| 349 | ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName()); |
| 350 | defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 353 | @Nullable |
| 354 | public TypedValue getAttrValue(int attr) { |
| 355 | return mExtraAttrs == null ? null : mExtraAttrs.get(attr); |
| 356 | } |
| 357 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 358 | public void addOnChangeListener(OnIDPChangeListener listener) { |
| 359 | mChangeListeners.add(listener); |
| 360 | } |
| 361 | |
Hyunyoung Song | b4d1ca4 | 2019-01-08 17:15:16 -0800 | [diff] [blame] | 362 | public void removeOnChangeListener(OnIDPChangeListener listener) { |
| 363 | mChangeListeners.remove(listener); |
| 364 | } |
| 365 | |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 366 | |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 367 | public void setCurrentGrid(Context context, String gridName) { |
| 368 | Context appContext = context.getApplicationContext(); |
| 369 | Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply(); |
Sunny Goyal | 6fe3eec | 2019-08-15 14:53:41 -0700 | [diff] [blame] | 370 | MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext)); |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 371 | } |
| 372 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 373 | private Object[] toModelState() { |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 374 | return new Object[]{ |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 375 | numColumns, numRows, numDatabaseHotseatIcons, iconBitmapSize, fillResIconDpi, |
| 376 | numDatabaseAllAppsColumns, dbFile}; |
| 377 | } |
| 378 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 379 | private void onConfigChanged(Context context) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 380 | Object[] oldState = toModelState(); |
| 381 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 382 | // Re-init grid |
Tracy Zhou | c6060e6 | 2020-04-27 13:05:34 -0700 | [diff] [blame] | 383 | String gridName = getCurrentGridName(context); |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 384 | initGrid(context, gridName); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 385 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 386 | boolean modelPropsChanged = !Arrays.equals(oldState, toModelState()); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 387 | for (OnIDPChangeListener listener : mChangeListeners) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 388 | listener.onIdpChanged(modelPropsChanged); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 389 | } |
| 390 | } |
| 391 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 392 | private static ArrayList<DisplayOption> getPredefinedDeviceProfiles( |
Alex Chau | 238aaee | 2021-10-06 16:15:24 +0100 | [diff] [blame] | 393 | Context context, String gridName, boolean isSplitDisplay, boolean allowDisabledGrid) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 394 | ArrayList<DisplayOption> profiles = new ArrayList<>(); |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame] | 395 | int xmlResource = isSplitDisplay ? R.xml.device_profiles_split : R.xml.device_profiles; |
| 396 | |
| 397 | try (XmlResourceParser parser = context.getResources().getXml(xmlResource)) { |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 398 | final int depth = parser.getDepth(); |
| 399 | int type; |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 400 | while (((type = parser.next()) != XmlPullParser.END_TAG || |
| 401 | parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 402 | if ((type == XmlPullParser.START_TAG) |
| 403 | && GridOption.TAG_NAME.equals(parser.getName())) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 404 | |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 405 | GridOption gridOption = |
| 406 | new GridOption(context, Xml.asAttributeSet(parser), isSplitDisplay); |
Alex Chau | 238aaee | 2021-10-06 16:15:24 +0100 | [diff] [blame] | 407 | if (gridOption.isEnabled || allowDisabledGrid) { |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 408 | final int displayDepth = parser.getDepth(); |
| 409 | while (((type = parser.next()) != XmlPullParser.END_TAG |
| 410 | || parser.getDepth() > displayDepth) |
| 411 | && type != XmlPullParser.END_DOCUMENT) { |
| 412 | if ((type == XmlPullParser.START_TAG) && "display-option".equals( |
| 413 | parser.getName())) { |
| 414 | profiles.add(new DisplayOption(gridOption, context, |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame] | 415 | Xml.asAttributeSet(parser))); |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 416 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 417 | } |
| 418 | } |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 419 | } |
| 420 | } |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 421 | } catch (IOException | XmlPullParserException e) { |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 422 | throw new RuntimeException(e); |
| 423 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 424 | |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 425 | ArrayList<DisplayOption> filteredProfiles = new ArrayList<>(); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 426 | if (!TextUtils.isEmpty(gridName)) { |
| 427 | for (DisplayOption option : profiles) { |
Alex Chau | 238aaee | 2021-10-06 16:15:24 +0100 | [diff] [blame] | 428 | if (gridName.equals(option.grid.name) |
| 429 | && (option.grid.isEnabled || allowDisabledGrid)) { |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 430 | filteredProfiles.add(option); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 431 | } |
| 432 | } |
| 433 | } |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 434 | if (filteredProfiles.isEmpty()) { |
| 435 | // No grid found, use the default options |
| 436 | for (DisplayOption option : profiles) { |
| 437 | if (option.canBeDefault) { |
| 438 | filteredProfiles.add(option); |
| 439 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 440 | } |
| 441 | } |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 442 | if (filteredProfiles.isEmpty()) { |
| 443 | throw new RuntimeException("No display option with canBeDefault=true"); |
| 444 | } |
| 445 | return filteredProfiles; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 448 | /** |
| 449 | * @return all the grid options that can be shown on the device |
| 450 | */ |
| 451 | public List<GridOption> parseAllGridOptions(Context context) { |
| 452 | List<GridOption> result = new ArrayList<>(); |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame] | 453 | int xmlResource = isSplitDisplay ? R.xml.device_profiles_split : R.xml.device_profiles; |
| 454 | |
| 455 | try (XmlResourceParser parser = context.getResources().getXml(xmlResource)) { |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 456 | final int depth = parser.getDepth(); |
| 457 | int type; |
| 458 | while (((type = parser.next()) != XmlPullParser.END_TAG |
| 459 | || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { |
| 460 | if ((type == XmlPullParser.START_TAG) |
| 461 | && GridOption.TAG_NAME.equals(parser.getName())) { |
| 462 | GridOption option = |
| 463 | new GridOption(context, Xml.asAttributeSet(parser), isSplitDisplay); |
| 464 | if (option.isEnabled) { |
| 465 | result.add(option); |
| 466 | } |
| 467 | } |
| 468 | } |
| 469 | } catch (IOException | XmlPullParserException e) { |
| 470 | Log.e(TAG, "Error parsing device profile", e); |
| 471 | return Collections.emptyList(); |
| 472 | } |
| 473 | return result; |
| 474 | } |
| 475 | |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 476 | private int getLauncherIconDensity(int requiredSize) { |
| 477 | // Densities typically defined by an app. |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 478 | int[] densityBuckets = new int[]{ |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 479 | DisplayMetrics.DENSITY_LOW, |
| 480 | DisplayMetrics.DENSITY_MEDIUM, |
| 481 | DisplayMetrics.DENSITY_TV, |
| 482 | DisplayMetrics.DENSITY_HIGH, |
| 483 | DisplayMetrics.DENSITY_XHIGH, |
| 484 | DisplayMetrics.DENSITY_XXHIGH, |
| 485 | DisplayMetrics.DENSITY_XXXHIGH |
| 486 | }; |
| 487 | |
| 488 | int density = DisplayMetrics.DENSITY_XXXHIGH; |
| 489 | for (int i = densityBuckets.length - 1; i >= 0; i--) { |
| 490 | float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i] |
| 491 | / DisplayMetrics.DENSITY_DEFAULT; |
| 492 | if (expectedSize >= requiredSize) { |
| 493 | density = densityBuckets[i]; |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | return density; |
| 498 | } |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 499 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 500 | /** |
| 501 | * Apply any Partner customization grid overrides. |
| 502 | * |
| 503 | * Currently we support: all apps row / column count. |
| 504 | */ |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 505 | private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) { |
| 506 | Partner p = Partner.get(context.getPackageManager()); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 507 | if (p != null) { |
| 508 | p.applyInvariantDeviceProfileOverrides(this, dm); |
| 509 | } |
| 510 | } |
| 511 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 512 | private static float dist(float x0, float y0, float x1, float y1) { |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 513 | return (float) Math.hypot(x1 - x0, y1 - y0); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 516 | private static DisplayOption invDistWeightedInterpolate( |
| 517 | Info displayInfo, ArrayList<DisplayOption> points, boolean isSplitDisplay) { |
| 518 | int minWidthPx = Integer.MAX_VALUE; |
| 519 | int minHeightPx = Integer.MAX_VALUE; |
| 520 | for (WindowBounds bounds : displayInfo.supportedBounds) { |
| 521 | boolean isTablet = displayInfo.isTablet(bounds); |
| 522 | if (isTablet && isSplitDisplay) { |
| 523 | // For split displays, take half width per page |
| 524 | minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2); |
| 525 | minHeightPx = Math.min(minHeightPx, bounds.availableSize.y); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 526 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 527 | } else if (!isTablet && bounds.isLandscape()) { |
| 528 | // We will use transposed layout in this case |
| 529 | minWidthPx = Math.min(minWidthPx, bounds.availableSize.y); |
| 530 | minHeightPx = Math.min(minHeightPx, bounds.availableSize.x); |
| 531 | } else { |
| 532 | minWidthPx = Math.min(minWidthPx, bounds.availableSize.x); |
| 533 | minHeightPx = Math.min(minHeightPx, bounds.availableSize.y); |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | float width = dpiFromPx(minWidthPx, displayInfo.densityDpi); |
| 538 | float height = dpiFromPx(minHeightPx, displayInfo.densityDpi); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 539 | |
| 540 | // Sort the profiles based on the closeness to the device size |
| 541 | Collections.sort(points, (a, b) -> |
| 542 | Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps), |
| 543 | dist(width, height, b.minWidthDps, b.minHeightDps))); |
| 544 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 545 | DisplayOption closestPoint = points.get(0); |
| 546 | GridOption closestOption = closestPoint.grid; |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 547 | float weights = 0; |
| 548 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 549 | if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) { |
| 550 | return closestPoint; |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | DisplayOption out = new DisplayOption(closestOption); |
| 554 | for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 555 | DisplayOption p = points.get(i); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 556 | float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER); |
| 557 | weights += w; |
| 558 | out.add(new DisplayOption().add(p).multiply(w)); |
| 559 | } |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 560 | out.multiply(1.0f / weights); |
| 561 | |
Thales Lima | 6e0005a | 2021-10-27 15:53:41 +0100 | [diff] [blame^] | 562 | // 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] | 563 | // predefined size to avoid cache invalidation |
Thales Lima | 6e0005a | 2021-10-27 15:53:41 +0100 | [diff] [blame^] | 564 | for (int i = INDEX_DEFAULT; i < COUNT_SIZES; i++) { |
| 565 | out.iconSizes[i] = Math.min(out.iconSizes[i], closestPoint.iconSizes[i]); |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | return out; |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 569 | } |
| 570 | |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 571 | public DeviceProfile getDeviceProfile(Context context) { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 572 | Resources res = context.getResources(); |
| 573 | Configuration config = context.getResources().getConfiguration(); |
| 574 | |
Sunny Goyal | 3e9a29c | 2021-09-07 15:53:09 -0400 | [diff] [blame] | 575 | float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density; |
| 576 | float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density; |
| 577 | return getBestMatch(screenWidth, screenHeight); |
| 578 | } |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 579 | |
Sunny Goyal | 3e9a29c | 2021-09-07 15:53:09 -0400 | [diff] [blame] | 580 | public DeviceProfile getBestMatch(float screenWidth, float screenHeight) { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 581 | DeviceProfile bestMatch = supportedProfiles.get(0); |
| 582 | float minDiff = Float.MAX_VALUE; |
| 583 | |
| 584 | for (DeviceProfile profile : supportedProfiles) { |
Sunny Goyal | 3e9a29c | 2021-09-07 15:53:09 -0400 | [diff] [blame] | 585 | float diff = Math.abs(profile.widthPx - screenWidth) |
| 586 | + Math.abs(profile.heightPx - screenHeight); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 587 | if (diff < minDiff) { |
| 588 | minDiff = diff; |
| 589 | bestMatch = profile; |
| 590 | } |
| 591 | } |
| 592 | return bestMatch; |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 593 | } |
| 594 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 595 | 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] | 596 | float d = dist(x0, y0, x1, y1); |
| 597 | if (Float.compare(d, 0f) == 0) { |
| 598 | return Float.POSITIVE_INFINITY; |
| 599 | } |
| 600 | return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow)); |
| 601 | } |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 602 | |
| 603 | /** |
| 604 | * As a ratio of screen height, the total distance we want the parallax effect to span |
| 605 | * horizontally |
| 606 | */ |
| 607 | private static float wallpaperTravelToScreenWidthRatio(int width, int height) { |
| 608 | float aspectRatio = width / (float) height; |
| 609 | |
| 610 | // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width |
| 611 | // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width |
| 612 | // We will use these two data points to extrapolate how much the wallpaper parallax effect |
| 613 | // to span (ie travel) at any aspect ratio: |
| 614 | |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 615 | final float ASPECT_RATIO_LANDSCAPE = 16 / 10f; |
| 616 | final float ASPECT_RATIO_PORTRAIT = 10 / 16f; |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 617 | final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f; |
| 618 | final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f; |
| 619 | |
| 620 | // To find out the desired width at different aspect ratios, we use the following two |
| 621 | // formulas, where the coefficient on x is the aspect ratio (width/height): |
| 622 | // (16/10)x + y = 1.5 |
| 623 | // (10/16)x + y = 1.2 |
| 624 | // We solve for x and y and end up with a final formula: |
| 625 | final float x = |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 626 | (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE |
| 627 | - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) / |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 628 | (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT); |
| 629 | final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT; |
| 630 | return x * aspectRatio + y; |
| 631 | } |
| 632 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 633 | public interface OnIDPChangeListener { |
| 634 | |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 635 | /** |
| 636 | * Called when the device provide changes |
| 637 | */ |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 638 | void onIdpChanged(boolean modelPropertiesChanged); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 639 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 640 | |
| 641 | |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 642 | public static final class GridOption { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 643 | |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 644 | public static final String TAG_NAME = "grid-option"; |
| 645 | |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 646 | public final String name; |
| 647 | public final int numRows; |
| 648 | public final int numColumns; |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 649 | public final boolean isEnabled; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 650 | |
| 651 | private final int numFolderRows; |
| 652 | private final int numFolderColumns; |
| 653 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 654 | private final int numAllAppsColumns; |
| 655 | private final int numDatabaseAllAppsColumns; |
| 656 | private final int numHotseatIcons; |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame] | 657 | private final int numDatabaseHotseatIcons; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 658 | |
Tracy Zhou | 7df93d2 | 2020-01-27 13:44:06 -0800 | [diff] [blame] | 659 | private final String dbFile; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 660 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 661 | private final int defaultLayoutId; |
| 662 | private final int demoModeLayoutId; |
| 663 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 664 | private final boolean isScalable; |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 665 | private final int devicePaddingId; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 666 | |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 667 | private final SparseArray<TypedValue> extraAttrs; |
| 668 | |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 669 | public GridOption(Context context, AttributeSet attrs, boolean isSplitDisplay) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 670 | TypedArray a = context.obtainStyledAttributes( |
| 671 | attrs, R.styleable.GridDisplayOption); |
| 672 | name = a.getString(R.styleable.GridDisplayOption_name); |
| 673 | numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0); |
| 674 | numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0); |
| 675 | |
Tracy Zhou | 7df93d2 | 2020-01-27 13:44:06 -0800 | [diff] [blame] | 676 | dbFile = a.getString(R.styleable.GridDisplayOption_dbFile); |
Alex Chau | 1e44846 | 2021-08-13 21:48:35 +0100 | [diff] [blame] | 677 | defaultLayoutId = a.getResourceId(isSplitDisplay && a.hasValue( |
| 678 | R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId) |
| 679 | ? R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId |
| 680 | : R.styleable.GridDisplayOption_defaultLayoutId, 0); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 681 | demoModeLayoutId = a.getResourceId( |
| 682 | R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 683 | |
| 684 | numAllAppsColumns = a.getInt( |
| 685 | R.styleable.GridDisplayOption_numAllAppsColumns, numColumns); |
| 686 | numDatabaseAllAppsColumns = a.getInt( |
| 687 | R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns); |
| 688 | |
| 689 | numHotseatIcons = a.getInt( |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 690 | R.styleable.GridDisplayOption_numHotseatIcons, numColumns); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 691 | numDatabaseHotseatIcons = a.getInt( |
| 692 | R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons); |
| 693 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 694 | numFolderRows = a.getInt( |
| 695 | R.styleable.GridDisplayOption_numFolderRows, numRows); |
| 696 | numFolderColumns = a.getInt( |
| 697 | R.styleable.GridDisplayOption_numFolderColumns, numColumns); |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 698 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 699 | isScalable = a.getBoolean( |
| 700 | R.styleable.GridDisplayOption_isScalable, false); |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 701 | devicePaddingId = a.getResourceId( |
| 702 | R.styleable.GridDisplayOption_devicePaddingId, 0); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 703 | |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame] | 704 | isEnabled = a.getBoolean(R.styleable.GridDisplayOption_gridEnabled, true); |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 705 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 706 | a.recycle(); |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 707 | extraAttrs = Themes.createValueMap(context, attrs, |
| 708 | IntArray.wrap(R.styleable.GridDisplayOption)); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 709 | } |
| 710 | } |
| 711 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 712 | @VisibleForTesting |
| 713 | static final class DisplayOption { |
| 714 | |
| 715 | public final GridOption grid; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 716 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 717 | private final float minWidthDps; |
| 718 | private final float minHeightDps; |
| 719 | private final boolean canBeDefault; |
| 720 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 721 | private final PointF[] minCellSize = new PointF[COUNT_SIZES]; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 722 | |
| 723 | private float folderBorderSpace; |
| 724 | private final PointF[] borderSpaces = new PointF[COUNT_SIZES]; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 725 | private final float[] horizontalMargin = new float[COUNT_SIZES]; |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 726 | |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 727 | private final float[] iconSizes = new float[COUNT_SIZES]; |
| 728 | private final float[] textSizes = new float[COUNT_SIZES]; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 729 | |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame] | 730 | DisplayOption(GridOption grid, Context context, AttributeSet attrs) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 731 | this.grid = grid; |
| 732 | |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame] | 733 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 734 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 735 | minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0); |
| 736 | minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 737 | |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame] | 738 | canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 739 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 740 | float x; |
| 741 | float y; |
| 742 | |
| 743 | x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthDps, 0); |
| 744 | y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightDps, 0); |
| 745 | minCellSize[INDEX_DEFAULT] = new PointF(x, y); |
| 746 | minCellSize[INDEX_LANDSCAPE] = new PointF(x, y); |
| 747 | minCellSize[INDEX_ALL_APPS] = new PointF(x, y); |
| 748 | |
| 749 | x = a.getFloat(R.styleable.ProfileDisplayOption_twoPanelPortraitMinCellWidthDps, |
| 750 | minCellSize[INDEX_DEFAULT].x); |
| 751 | y = a.getFloat(R.styleable.ProfileDisplayOption_twoPanelPortraitMinCellHeightDps, |
| 752 | minCellSize[INDEX_DEFAULT].y); |
| 753 | minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y); |
| 754 | |
| 755 | x = a.getFloat(R.styleable.ProfileDisplayOption_twoPanelLandscapeMinCellWidthDps, |
| 756 | minCellSize[INDEX_DEFAULT].x); |
| 757 | y = a.getFloat(R.styleable.ProfileDisplayOption_twoPanelLandscapeMinCellHeightDps, |
| 758 | minCellSize[INDEX_DEFAULT].y); |
| 759 | minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 760 | |
| 761 | float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceDps, 0); |
| 762 | float twoPanelPortraitBorderSpaceDps = a.getFloat( |
| 763 | R.styleable.ProfileDisplayOption_twoPanelPortraitBorderSpaceDps, borderSpace); |
| 764 | float twoPanelLandscapeBorderSpaceDps = a.getFloat( |
| 765 | R.styleable.ProfileDisplayOption_twoPanelLandscapeBorderSpaceDps, borderSpace); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 766 | |
| 767 | x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontalDps, borderSpace); |
| 768 | y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVerticalDps, borderSpace); |
| 769 | borderSpaces[INDEX_DEFAULT] = new PointF(x, y); |
| 770 | borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y); |
| 771 | |
| 772 | x = a.getFloat( |
| 773 | R.styleable.ProfileDisplayOption_twoPanelPortraitBorderSpaceHorizontalDps, |
| 774 | twoPanelPortraitBorderSpaceDps); |
| 775 | y = a.getFloat( |
| 776 | R.styleable.ProfileDisplayOption_twoPanelPortraitBorderSpaceVerticalDps, |
| 777 | twoPanelPortraitBorderSpaceDps); |
| 778 | borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y); |
| 779 | |
| 780 | x = a.getFloat( |
| 781 | R.styleable.ProfileDisplayOption_twoPanelLandscapeBorderSpaceHorizontalDps, |
| 782 | twoPanelLandscapeBorderSpaceDps); |
| 783 | y = a.getFloat( |
| 784 | R.styleable.ProfileDisplayOption_twoPanelLandscapeBorderSpaceVerticalDps, |
| 785 | twoPanelLandscapeBorderSpaceDps); |
| 786 | borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y); |
| 787 | |
| 788 | x = y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellSpacingDps, |
| 789 | borderSpace); |
| 790 | borderSpaces[INDEX_ALL_APPS] = new PointF(x, y); |
| 791 | folderBorderSpace = borderSpace; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 792 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 793 | iconSizes[INDEX_DEFAULT] = |
| 794 | a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0); |
| 795 | iconSizes[INDEX_LANDSCAPE] = |
| 796 | a.getFloat(R.styleable.ProfileDisplayOption_landscapeIconSize, |
| 797 | iconSizes[INDEX_DEFAULT]); |
| 798 | iconSizes[INDEX_ALL_APPS] = |
| 799 | a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconSize, |
| 800 | iconSizes[INDEX_DEFAULT]); |
| 801 | iconSizes[INDEX_TWO_PANEL_PORTRAIT] = |
| 802 | a.getFloat(R.styleable.ProfileDisplayOption_twoPanelPortraitIconSize, |
| 803 | iconSizes[INDEX_DEFAULT]); |
| 804 | iconSizes[INDEX_TWO_PANEL_LANDSCAPE] = |
| 805 | a.getFloat(R.styleable.ProfileDisplayOption_twoPanelLandscapeIconSize, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 806 | iconSizes[INDEX_DEFAULT]); |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 807 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 808 | textSizes[INDEX_DEFAULT] = |
| 809 | a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0); |
| 810 | textSizes[INDEX_LANDSCAPE] = |
| 811 | a.getFloat(R.styleable.ProfileDisplayOption_landscapeIconTextSize, |
| 812 | textSizes[INDEX_DEFAULT]); |
| 813 | textSizes[INDEX_ALL_APPS] = |
| 814 | a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconTextSize, |
| 815 | textSizes[INDEX_DEFAULT]); |
| 816 | textSizes[INDEX_TWO_PANEL_PORTRAIT] = |
| 817 | a.getFloat(R.styleable.ProfileDisplayOption_twoPanelPortraitIconTextSize, |
| 818 | textSizes[INDEX_DEFAULT]); |
| 819 | textSizes[INDEX_TWO_PANEL_LANDSCAPE] = |
| 820 | a.getFloat(R.styleable.ProfileDisplayOption_twoPanelLandscapeIconTextSize, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 821 | textSizes[INDEX_DEFAULT]); |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 822 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 823 | horizontalMargin[INDEX_DEFAULT] = a.getFloat( |
| 824 | R.styleable.ProfileDisplayOption_horizontalMargin, 0); |
| 825 | horizontalMargin[INDEX_LANDSCAPE] = horizontalMargin[INDEX_DEFAULT]; |
| 826 | horizontalMargin[INDEX_ALL_APPS] = horizontalMargin[INDEX_DEFAULT]; |
| 827 | horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat( |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 828 | R.styleable.ProfileDisplayOption_twoPanelLandscapeHorizontalMargin, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 829 | horizontalMargin[INDEX_DEFAULT]); |
| 830 | horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat( |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 831 | R.styleable.ProfileDisplayOption_twoPanelPortraitHorizontalMargin, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 832 | horizontalMargin[INDEX_DEFAULT]); |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 833 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 834 | a.recycle(); |
| 835 | } |
| 836 | |
| 837 | DisplayOption() { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 838 | this(null); |
| 839 | } |
| 840 | |
| 841 | DisplayOption(GridOption grid) { |
| 842 | this.grid = grid; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 843 | minWidthDps = 0; |
| 844 | minHeightDps = 0; |
| 845 | canBeDefault = false; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 846 | for (int i = 0; i < COUNT_SIZES; i++) { |
| 847 | iconSizes[i] = 0; |
| 848 | textSizes[i] = 0; |
| 849 | borderSpaces[i] = new PointF(); |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 850 | minCellSize[i] = new PointF(); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 851 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | private DisplayOption multiply(float w) { |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 855 | for (int i = 0; i < COUNT_SIZES; i++) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 856 | iconSizes[i] *= w; |
| 857 | textSizes[i] *= w; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 858 | borderSpaces[i].x *= w; |
| 859 | borderSpaces[i].y *= w; |
| 860 | minCellSize[i].x *= w; |
| 861 | minCellSize[i].y *= w; |
| 862 | horizontalMargin[i] *= w; |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 863 | } |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 864 | |
| 865 | folderBorderSpace *= w; |
| 866 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 867 | return this; |
| 868 | } |
| 869 | |
| 870 | private DisplayOption add(DisplayOption p) { |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 871 | for (int i = 0; i < COUNT_SIZES; i++) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 872 | iconSizes[i] += p.iconSizes[i]; |
| 873 | textSizes[i] += p.textSizes[i]; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 874 | borderSpaces[i].x += p.borderSpaces[i].x; |
| 875 | borderSpaces[i].y += p.borderSpaces[i].y; |
| 876 | minCellSize[i].x += p.minCellSize[i].x; |
| 877 | minCellSize[i].y += p.minCellSize[i].y; |
| 878 | horizontalMargin[i] += p.horizontalMargin[i]; |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 879 | } |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 880 | |
| 881 | folderBorderSpace += p.folderBorderSpace; |
| 882 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 883 | return this; |
| 884 | } |
| 885 | } |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 886 | } |