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; |
| 289 | iconBitmapSize = ResourceUtils.pxFromDp(iconSize[INDEX_DEFAULT], metrics); |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 290 | fillResIconDpi = getLauncherIconDensity(iconBitmapSize); |
| 291 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 292 | iconTextSize = displayOption.textSizes; |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 293 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 294 | minCellSize = displayOption.minCellSize; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 295 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 296 | borderSpaces = displayOption.borderSpaces; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 297 | folderBorderSpace = displayOption.folderBorderSpace; |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 298 | |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 299 | horizontalMargin = displayOption.horizontalMargin; |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 300 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 301 | numShownHotseatIcons = closestProfile.numHotseatIcons; |
| 302 | numDatabaseHotseatIcons = isSplitDisplay |
| 303 | ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons; |
| 304 | |
| 305 | numAllAppsColumns = closestProfile.numAllAppsColumns; |
| 306 | numDatabaseAllAppsColumns = isSplitDisplay |
| 307 | ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 308 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 309 | if (!Utilities.isGridOptionsEnabled(context)) { |
| 310 | iconSize[INDEX_ALL_APPS] = iconSize[INDEX_DEFAULT]; |
| 311 | iconTextSize[INDEX_ALL_APPS] = iconTextSize[INDEX_DEFAULT]; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 312 | } |
| 313 | |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 314 | if (devicePaddingId != 0) { |
| 315 | devicePaddings = new DevicePaddings(context, devicePaddingId); |
| 316 | } |
| 317 | |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 318 | // If the partner customization apk contains any grid overrides, apply them |
| 319 | // Supported overrides: numRows, numColumns, iconSize |
Sunny Goyal | 35c7b19 | 2021-04-20 16:51:10 -0700 | [diff] [blame] | 320 | applyPartnerDeviceProfileOverrides(context, metrics); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 321 | |
Pinyao Ting | 9cd63c9 | 2021-06-16 17:51:39 +0000 | [diff] [blame] | 322 | final List<DeviceProfile> localSupportedProfiles = new ArrayList<>(); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 323 | defaultWallpaperSize = new Point(displayInfo.currentSize); |
| 324 | for (WindowBounds bounds : displayInfo.supportedBounds) { |
Pinyao Ting | 9cd63c9 | 2021-06-16 17:51:39 +0000 | [diff] [blame] | 325 | localSupportedProfiles.add(new DeviceProfile.Builder(context, this, displayInfo) |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 326 | .setUseTwoPanels(isSplitDisplay) |
| 327 | .setWindowBounds(bounds).build()); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 328 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 329 | // Wallpaper size should be the maximum of the all possible sizes Launcher expects |
| 330 | int displayWidth = bounds.bounds.width(); |
| 331 | int displayHeight = bounds.bounds.height(); |
| 332 | defaultWallpaperSize.y = Math.max(defaultWallpaperSize.y, displayHeight); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 333 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 334 | // We need to ensure that there is enough extra space in the wallpaper |
| 335 | // for the intended parallax effects |
| 336 | float parallaxFactor = |
| 337 | dpiFromPx(Math.min(displayWidth, displayHeight), displayInfo.densityDpi) < 720 |
| 338 | ? 2 |
| 339 | : wallpaperTravelToScreenWidthRatio(displayWidth, displayHeight); |
| 340 | defaultWallpaperSize.x = |
| 341 | Math.max(defaultWallpaperSize.x, Math.round(parallaxFactor * displayWidth)); |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 342 | } |
Pinyao Ting | 9cd63c9 | 2021-06-16 17:51:39 +0000 | [diff] [blame] | 343 | supportedProfiles = Collections.unmodifiableList(localSupportedProfiles); |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 344 | |
| 345 | ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName()); |
| 346 | defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 349 | @Nullable |
| 350 | public TypedValue getAttrValue(int attr) { |
| 351 | return mExtraAttrs == null ? null : mExtraAttrs.get(attr); |
| 352 | } |
| 353 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 354 | public void addOnChangeListener(OnIDPChangeListener listener) { |
| 355 | mChangeListeners.add(listener); |
| 356 | } |
| 357 | |
Hyunyoung Song | b4d1ca4 | 2019-01-08 17:15:16 -0800 | [diff] [blame] | 358 | public void removeOnChangeListener(OnIDPChangeListener listener) { |
| 359 | mChangeListeners.remove(listener); |
| 360 | } |
| 361 | |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 362 | |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 363 | public void setCurrentGrid(Context context, String gridName) { |
| 364 | Context appContext = context.getApplicationContext(); |
| 365 | Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply(); |
Sunny Goyal | 6fe3eec | 2019-08-15 14:53:41 -0700 | [diff] [blame] | 366 | MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext)); |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 367 | } |
| 368 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 369 | private Object[] toModelState() { |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 370 | return new Object[]{ |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 371 | numColumns, numRows, numDatabaseHotseatIcons, iconBitmapSize, fillResIconDpi, |
| 372 | numDatabaseAllAppsColumns, dbFile}; |
| 373 | } |
| 374 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 375 | private void onConfigChanged(Context context) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 376 | Object[] oldState = toModelState(); |
| 377 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 378 | // Re-init grid |
Tracy Zhou | c6060e6 | 2020-04-27 13:05:34 -0700 | [diff] [blame] | 379 | String gridName = getCurrentGridName(context); |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 380 | initGrid(context, gridName); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 381 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 382 | boolean modelPropsChanged = !Arrays.equals(oldState, toModelState()); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 383 | for (OnIDPChangeListener listener : mChangeListeners) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 384 | listener.onIdpChanged(modelPropsChanged); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 388 | private static ArrayList<DisplayOption> getPredefinedDeviceProfiles( |
Alex Chau | 238aaee | 2021-10-06 16:15:24 +0100 | [diff] [blame] | 389 | Context context, String gridName, boolean isSplitDisplay, boolean allowDisabledGrid) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 390 | ArrayList<DisplayOption> profiles = new ArrayList<>(); |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame^] | 391 | int xmlResource = isSplitDisplay ? R.xml.device_profiles_split : R.xml.device_profiles; |
| 392 | |
| 393 | try (XmlResourceParser parser = context.getResources().getXml(xmlResource)) { |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 394 | final int depth = parser.getDepth(); |
| 395 | int type; |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 396 | while (((type = parser.next()) != XmlPullParser.END_TAG || |
| 397 | parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 398 | if ((type == XmlPullParser.START_TAG) |
| 399 | && GridOption.TAG_NAME.equals(parser.getName())) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 400 | |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 401 | GridOption gridOption = |
| 402 | new GridOption(context, Xml.asAttributeSet(parser), isSplitDisplay); |
Alex Chau | 238aaee | 2021-10-06 16:15:24 +0100 | [diff] [blame] | 403 | if (gridOption.isEnabled || allowDisabledGrid) { |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 404 | final int displayDepth = parser.getDepth(); |
| 405 | while (((type = parser.next()) != XmlPullParser.END_TAG |
| 406 | || parser.getDepth() > displayDepth) |
| 407 | && type != XmlPullParser.END_DOCUMENT) { |
| 408 | if ((type == XmlPullParser.START_TAG) && "display-option".equals( |
| 409 | parser.getName())) { |
| 410 | profiles.add(new DisplayOption(gridOption, context, |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame^] | 411 | Xml.asAttributeSet(parser))); |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 412 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 413 | } |
| 414 | } |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 415 | } |
| 416 | } |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 417 | } catch (IOException | XmlPullParserException e) { |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 418 | throw new RuntimeException(e); |
| 419 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 420 | |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 421 | ArrayList<DisplayOption> filteredProfiles = new ArrayList<>(); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 422 | if (!TextUtils.isEmpty(gridName)) { |
| 423 | for (DisplayOption option : profiles) { |
Alex Chau | 238aaee | 2021-10-06 16:15:24 +0100 | [diff] [blame] | 424 | if (gridName.equals(option.grid.name) |
| 425 | && (option.grid.isEnabled || allowDisabledGrid)) { |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 426 | filteredProfiles.add(option); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | } |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 430 | if (filteredProfiles.isEmpty()) { |
| 431 | // No grid found, use the default options |
| 432 | for (DisplayOption option : profiles) { |
| 433 | if (option.canBeDefault) { |
| 434 | filteredProfiles.add(option); |
| 435 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 436 | } |
| 437 | } |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 438 | if (filteredProfiles.isEmpty()) { |
| 439 | throw new RuntimeException("No display option with canBeDefault=true"); |
| 440 | } |
| 441 | return filteredProfiles; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 444 | /** |
| 445 | * @return all the grid options that can be shown on the device |
| 446 | */ |
| 447 | public List<GridOption> parseAllGridOptions(Context context) { |
| 448 | List<GridOption> result = new ArrayList<>(); |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame^] | 449 | int xmlResource = isSplitDisplay ? R.xml.device_profiles_split : R.xml.device_profiles; |
| 450 | |
| 451 | try (XmlResourceParser parser = context.getResources().getXml(xmlResource)) { |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 452 | final int depth = parser.getDepth(); |
| 453 | int type; |
| 454 | while (((type = parser.next()) != XmlPullParser.END_TAG |
| 455 | || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { |
| 456 | if ((type == XmlPullParser.START_TAG) |
| 457 | && GridOption.TAG_NAME.equals(parser.getName())) { |
| 458 | GridOption option = |
| 459 | new GridOption(context, Xml.asAttributeSet(parser), isSplitDisplay); |
| 460 | if (option.isEnabled) { |
| 461 | result.add(option); |
| 462 | } |
| 463 | } |
| 464 | } |
| 465 | } catch (IOException | XmlPullParserException e) { |
| 466 | Log.e(TAG, "Error parsing device profile", e); |
| 467 | return Collections.emptyList(); |
| 468 | } |
| 469 | return result; |
| 470 | } |
| 471 | |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 472 | private int getLauncherIconDensity(int requiredSize) { |
| 473 | // Densities typically defined by an app. |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 474 | int[] densityBuckets = new int[]{ |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 475 | DisplayMetrics.DENSITY_LOW, |
| 476 | DisplayMetrics.DENSITY_MEDIUM, |
| 477 | DisplayMetrics.DENSITY_TV, |
| 478 | DisplayMetrics.DENSITY_HIGH, |
| 479 | DisplayMetrics.DENSITY_XHIGH, |
| 480 | DisplayMetrics.DENSITY_XXHIGH, |
| 481 | DisplayMetrics.DENSITY_XXXHIGH |
| 482 | }; |
| 483 | |
| 484 | int density = DisplayMetrics.DENSITY_XXXHIGH; |
| 485 | for (int i = densityBuckets.length - 1; i >= 0; i--) { |
| 486 | float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i] |
| 487 | / DisplayMetrics.DENSITY_DEFAULT; |
| 488 | if (expectedSize >= requiredSize) { |
| 489 | density = densityBuckets[i]; |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | return density; |
| 494 | } |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 495 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 496 | /** |
| 497 | * Apply any Partner customization grid overrides. |
| 498 | * |
| 499 | * Currently we support: all apps row / column count. |
| 500 | */ |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 501 | private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) { |
| 502 | Partner p = Partner.get(context.getPackageManager()); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 503 | if (p != null) { |
| 504 | p.applyInvariantDeviceProfileOverrides(this, dm); |
| 505 | } |
| 506 | } |
| 507 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 508 | private static float dist(float x0, float y0, float x1, float y1) { |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 509 | return (float) Math.hypot(x1 - x0, y1 - y0); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 510 | } |
| 511 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 512 | private static DisplayOption invDistWeightedInterpolate( |
| 513 | Info displayInfo, ArrayList<DisplayOption> points, boolean isSplitDisplay) { |
| 514 | int minWidthPx = Integer.MAX_VALUE; |
| 515 | int minHeightPx = Integer.MAX_VALUE; |
| 516 | for (WindowBounds bounds : displayInfo.supportedBounds) { |
| 517 | boolean isTablet = displayInfo.isTablet(bounds); |
| 518 | if (isTablet && isSplitDisplay) { |
| 519 | // For split displays, take half width per page |
| 520 | minWidthPx = Math.min(minWidthPx, bounds.availableSize.x / 2); |
| 521 | minHeightPx = Math.min(minHeightPx, bounds.availableSize.y); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 522 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 523 | } else if (!isTablet && bounds.isLandscape()) { |
| 524 | // We will use transposed layout in this case |
| 525 | minWidthPx = Math.min(minWidthPx, bounds.availableSize.y); |
| 526 | minHeightPx = Math.min(minHeightPx, bounds.availableSize.x); |
| 527 | } else { |
| 528 | minWidthPx = Math.min(minWidthPx, bounds.availableSize.x); |
| 529 | minHeightPx = Math.min(minHeightPx, bounds.availableSize.y); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | float width = dpiFromPx(minWidthPx, displayInfo.densityDpi); |
| 534 | float height = dpiFromPx(minHeightPx, displayInfo.densityDpi); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 535 | |
| 536 | // Sort the profiles based on the closeness to the device size |
| 537 | Collections.sort(points, (a, b) -> |
| 538 | Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps), |
| 539 | dist(width, height, b.minWidthDps, b.minHeightDps))); |
| 540 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 541 | DisplayOption closestPoint = points.get(0); |
| 542 | GridOption closestOption = closestPoint.grid; |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 543 | float weights = 0; |
| 544 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 545 | if (dist(width, height, closestPoint.minWidthDps, closestPoint.minHeightDps) == 0) { |
| 546 | return closestPoint; |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | DisplayOption out = new DisplayOption(closestOption); |
| 550 | for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 551 | DisplayOption p = points.get(i); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 552 | float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER); |
| 553 | weights += w; |
| 554 | out.add(new DisplayOption().add(p).multiply(w)); |
| 555 | } |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 556 | out.multiply(1.0f / weights); |
| 557 | |
| 558 | // Since the bitmaps are persisted, ensure that the default bitmap size is same as |
| 559 | // predefined size to avoid cache invalidation |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 560 | out.iconSizes[INDEX_DEFAULT] = |
| 561 | closestPoint.iconSizes[INDEX_DEFAULT]; |
| 562 | for (int i = INDEX_DEFAULT + 1; i < COUNT_SIZES; i++) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 563 | out.iconSizes[i] = Math.min(out.iconSizes[i], |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 564 | out.iconSizes[INDEX_DEFAULT]); |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | return out; |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 568 | } |
| 569 | |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 570 | public DeviceProfile getDeviceProfile(Context context) { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 571 | Resources res = context.getResources(); |
| 572 | Configuration config = context.getResources().getConfiguration(); |
| 573 | |
Sunny Goyal | 3e9a29c | 2021-09-07 15:53:09 -0400 | [diff] [blame] | 574 | float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density; |
| 575 | float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density; |
| 576 | return getBestMatch(screenWidth, screenHeight); |
| 577 | } |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 578 | |
Sunny Goyal | 3e9a29c | 2021-09-07 15:53:09 -0400 | [diff] [blame] | 579 | public DeviceProfile getBestMatch(float screenWidth, float screenHeight) { |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 580 | DeviceProfile bestMatch = supportedProfiles.get(0); |
| 581 | float minDiff = Float.MAX_VALUE; |
| 582 | |
| 583 | for (DeviceProfile profile : supportedProfiles) { |
Sunny Goyal | 3e9a29c | 2021-09-07 15:53:09 -0400 | [diff] [blame] | 584 | float diff = Math.abs(profile.widthPx - screenWidth) |
| 585 | + Math.abs(profile.heightPx - screenHeight); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 586 | if (diff < minDiff) { |
| 587 | minDiff = diff; |
| 588 | bestMatch = profile; |
| 589 | } |
| 590 | } |
| 591 | return bestMatch; |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 592 | } |
| 593 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 594 | 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] | 595 | float d = dist(x0, y0, x1, y1); |
| 596 | if (Float.compare(d, 0f) == 0) { |
| 597 | return Float.POSITIVE_INFINITY; |
| 598 | } |
| 599 | return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow)); |
| 600 | } |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 601 | |
| 602 | /** |
| 603 | * As a ratio of screen height, the total distance we want the parallax effect to span |
| 604 | * horizontally |
| 605 | */ |
| 606 | private static float wallpaperTravelToScreenWidthRatio(int width, int height) { |
| 607 | float aspectRatio = width / (float) height; |
| 608 | |
| 609 | // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width |
| 610 | // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width |
| 611 | // We will use these two data points to extrapolate how much the wallpaper parallax effect |
| 612 | // to span (ie travel) at any aspect ratio: |
| 613 | |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 614 | final float ASPECT_RATIO_LANDSCAPE = 16 / 10f; |
| 615 | final float ASPECT_RATIO_PORTRAIT = 10 / 16f; |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 616 | final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f; |
| 617 | final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f; |
| 618 | |
| 619 | // To find out the desired width at different aspect ratios, we use the following two |
| 620 | // formulas, where the coefficient on x is the aspect ratio (width/height): |
| 621 | // (16/10)x + y = 1.5 |
| 622 | // (10/16)x + y = 1.2 |
| 623 | // We solve for x and y and end up with a final formula: |
| 624 | final float x = |
sfufa@google.com | de01329 | 2021-09-21 18:22:44 -0700 | [diff] [blame] | 625 | (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE |
| 626 | - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) / |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 627 | (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT); |
| 628 | final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT; |
| 629 | return x * aspectRatio + y; |
| 630 | } |
| 631 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 632 | public interface OnIDPChangeListener { |
| 633 | |
Sunny Goyal | b47172b | 2021-05-03 19:59:51 -0700 | [diff] [blame] | 634 | /** |
| 635 | * Called when the device provide changes |
| 636 | */ |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 637 | void onIdpChanged(boolean modelPropertiesChanged); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 638 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 639 | |
| 640 | |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 641 | public static final class GridOption { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 642 | |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 643 | public static final String TAG_NAME = "grid-option"; |
| 644 | |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 645 | public final String name; |
| 646 | public final int numRows; |
| 647 | public final int numColumns; |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 648 | public final boolean isEnabled; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 649 | |
| 650 | private final int numFolderRows; |
| 651 | private final int numFolderColumns; |
| 652 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 653 | private final int numAllAppsColumns; |
| 654 | private final int numDatabaseAllAppsColumns; |
| 655 | private final int numHotseatIcons; |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame] | 656 | private final int numDatabaseHotseatIcons; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 657 | |
Tracy Zhou | 7df93d2 | 2020-01-27 13:44:06 -0800 | [diff] [blame] | 658 | private final String dbFile; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 659 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 660 | private final int defaultLayoutId; |
| 661 | private final int demoModeLayoutId; |
| 662 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 663 | private final boolean isScalable; |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 664 | private final int devicePaddingId; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 665 | |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 666 | private final SparseArray<TypedValue> extraAttrs; |
| 667 | |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 668 | public GridOption(Context context, AttributeSet attrs, boolean isSplitDisplay) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 669 | TypedArray a = context.obtainStyledAttributes( |
| 670 | attrs, R.styleable.GridDisplayOption); |
| 671 | name = a.getString(R.styleable.GridDisplayOption_name); |
| 672 | numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0); |
| 673 | numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0); |
| 674 | |
Tracy Zhou | 7df93d2 | 2020-01-27 13:44:06 -0800 | [diff] [blame] | 675 | dbFile = a.getString(R.styleable.GridDisplayOption_dbFile); |
Alex Chau | 1e44846 | 2021-08-13 21:48:35 +0100 | [diff] [blame] | 676 | defaultLayoutId = a.getResourceId(isSplitDisplay && a.hasValue( |
| 677 | R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId) |
| 678 | ? R.styleable.GridDisplayOption_defaultSplitDisplayLayoutId |
| 679 | : R.styleable.GridDisplayOption_defaultLayoutId, 0); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 680 | demoModeLayoutId = a.getResourceId( |
| 681 | R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 682 | |
| 683 | numAllAppsColumns = a.getInt( |
| 684 | R.styleable.GridDisplayOption_numAllAppsColumns, numColumns); |
| 685 | numDatabaseAllAppsColumns = a.getInt( |
| 686 | R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns); |
| 687 | |
| 688 | numHotseatIcons = a.getInt( |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 689 | R.styleable.GridDisplayOption_numHotseatIcons, numColumns); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 690 | numDatabaseHotseatIcons = a.getInt( |
| 691 | R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons); |
| 692 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 693 | numFolderRows = a.getInt( |
| 694 | R.styleable.GridDisplayOption_numFolderRows, numRows); |
| 695 | numFolderColumns = a.getInt( |
| 696 | R.styleable.GridDisplayOption_numFolderColumns, numColumns); |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 697 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 698 | isScalable = a.getBoolean( |
| 699 | R.styleable.GridDisplayOption_isScalable, false); |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 700 | devicePaddingId = a.getResourceId( |
| 701 | R.styleable.GridDisplayOption_devicePaddingId, 0); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 702 | |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame^] | 703 | isEnabled = a.getBoolean(R.styleable.GridDisplayOption_gridEnabled, true); |
Thales Lima | 7ec8382 | 2021-08-05 13:32:10 +0100 | [diff] [blame] | 704 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 705 | a.recycle(); |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 706 | extraAttrs = Themes.createValueMap(context, attrs, |
| 707 | IntArray.wrap(R.styleable.GridDisplayOption)); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 708 | } |
| 709 | } |
| 710 | |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 711 | @VisibleForTesting |
| 712 | static final class DisplayOption { |
| 713 | |
| 714 | public final GridOption grid; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 715 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 716 | private final float minWidthDps; |
| 717 | private final float minHeightDps; |
| 718 | private final boolean canBeDefault; |
| 719 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 720 | private final PointF[] minCellSize = new PointF[COUNT_SIZES]; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 721 | |
| 722 | private float folderBorderSpace; |
| 723 | private final PointF[] borderSpaces = new PointF[COUNT_SIZES]; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 724 | private final float[] horizontalMargin = new float[COUNT_SIZES]; |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 725 | |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 726 | private final float[] iconSizes = new float[COUNT_SIZES]; |
| 727 | private final float[] textSizes = new float[COUNT_SIZES]; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 728 | |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame^] | 729 | DisplayOption(GridOption grid, Context context, AttributeSet attrs) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 730 | this.grid = grid; |
| 731 | |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame^] | 732 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 733 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 734 | minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0); |
| 735 | minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0); |
Sunny Goyal | 19ff728 | 2021-04-22 10:12:54 -0700 | [diff] [blame] | 736 | |
Thales Lima | 1de4d55 | 2021-10-13 16:13:25 +0100 | [diff] [blame^] | 737 | canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 738 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 739 | float x; |
| 740 | float y; |
| 741 | |
| 742 | x = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthDps, 0); |
| 743 | y = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightDps, 0); |
| 744 | minCellSize[INDEX_DEFAULT] = new PointF(x, y); |
| 745 | minCellSize[INDEX_LANDSCAPE] = new PointF(x, y); |
| 746 | minCellSize[INDEX_ALL_APPS] = new PointF(x, y); |
| 747 | |
| 748 | x = a.getFloat(R.styleable.ProfileDisplayOption_twoPanelPortraitMinCellWidthDps, |
| 749 | minCellSize[INDEX_DEFAULT].x); |
| 750 | y = a.getFloat(R.styleable.ProfileDisplayOption_twoPanelPortraitMinCellHeightDps, |
| 751 | minCellSize[INDEX_DEFAULT].y); |
| 752 | minCellSize[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y); |
| 753 | |
| 754 | x = a.getFloat(R.styleable.ProfileDisplayOption_twoPanelLandscapeMinCellWidthDps, |
| 755 | minCellSize[INDEX_DEFAULT].x); |
| 756 | y = a.getFloat(R.styleable.ProfileDisplayOption_twoPanelLandscapeMinCellHeightDps, |
| 757 | minCellSize[INDEX_DEFAULT].y); |
| 758 | minCellSize[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 759 | |
| 760 | float borderSpace = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceDps, 0); |
| 761 | float twoPanelPortraitBorderSpaceDps = a.getFloat( |
| 762 | R.styleable.ProfileDisplayOption_twoPanelPortraitBorderSpaceDps, borderSpace); |
| 763 | float twoPanelLandscapeBorderSpaceDps = a.getFloat( |
| 764 | R.styleable.ProfileDisplayOption_twoPanelLandscapeBorderSpaceDps, borderSpace); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 765 | |
| 766 | x = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceHorizontalDps, borderSpace); |
| 767 | y = a.getFloat(R.styleable.ProfileDisplayOption_borderSpaceVerticalDps, borderSpace); |
| 768 | borderSpaces[INDEX_DEFAULT] = new PointF(x, y); |
| 769 | borderSpaces[INDEX_LANDSCAPE] = new PointF(x, y); |
| 770 | |
| 771 | x = a.getFloat( |
| 772 | R.styleable.ProfileDisplayOption_twoPanelPortraitBorderSpaceHorizontalDps, |
| 773 | twoPanelPortraitBorderSpaceDps); |
| 774 | y = a.getFloat( |
| 775 | R.styleable.ProfileDisplayOption_twoPanelPortraitBorderSpaceVerticalDps, |
| 776 | twoPanelPortraitBorderSpaceDps); |
| 777 | borderSpaces[INDEX_TWO_PANEL_PORTRAIT] = new PointF(x, y); |
| 778 | |
| 779 | x = a.getFloat( |
| 780 | R.styleable.ProfileDisplayOption_twoPanelLandscapeBorderSpaceHorizontalDps, |
| 781 | twoPanelLandscapeBorderSpaceDps); |
| 782 | y = a.getFloat( |
| 783 | R.styleable.ProfileDisplayOption_twoPanelLandscapeBorderSpaceVerticalDps, |
| 784 | twoPanelLandscapeBorderSpaceDps); |
| 785 | borderSpaces[INDEX_TWO_PANEL_LANDSCAPE] = new PointF(x, y); |
| 786 | |
| 787 | x = y = a.getFloat(R.styleable.ProfileDisplayOption_allAppsCellSpacingDps, |
| 788 | borderSpace); |
| 789 | borderSpaces[INDEX_ALL_APPS] = new PointF(x, y); |
| 790 | folderBorderSpace = borderSpace; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 791 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 792 | iconSizes[INDEX_DEFAULT] = |
| 793 | a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0); |
| 794 | iconSizes[INDEX_LANDSCAPE] = |
| 795 | a.getFloat(R.styleable.ProfileDisplayOption_landscapeIconSize, |
| 796 | iconSizes[INDEX_DEFAULT]); |
| 797 | iconSizes[INDEX_ALL_APPS] = |
| 798 | a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconSize, |
| 799 | iconSizes[INDEX_DEFAULT]); |
| 800 | iconSizes[INDEX_TWO_PANEL_PORTRAIT] = |
| 801 | a.getFloat(R.styleable.ProfileDisplayOption_twoPanelPortraitIconSize, |
| 802 | iconSizes[INDEX_DEFAULT]); |
| 803 | iconSizes[INDEX_TWO_PANEL_LANDSCAPE] = |
| 804 | a.getFloat(R.styleable.ProfileDisplayOption_twoPanelLandscapeIconSize, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 805 | iconSizes[INDEX_DEFAULT]); |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 806 | |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 807 | textSizes[INDEX_DEFAULT] = |
| 808 | a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0); |
| 809 | textSizes[INDEX_LANDSCAPE] = |
| 810 | a.getFloat(R.styleable.ProfileDisplayOption_landscapeIconTextSize, |
| 811 | textSizes[INDEX_DEFAULT]); |
| 812 | textSizes[INDEX_ALL_APPS] = |
| 813 | a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconTextSize, |
| 814 | textSizes[INDEX_DEFAULT]); |
| 815 | textSizes[INDEX_TWO_PANEL_PORTRAIT] = |
| 816 | a.getFloat(R.styleable.ProfileDisplayOption_twoPanelPortraitIconTextSize, |
| 817 | textSizes[INDEX_DEFAULT]); |
| 818 | textSizes[INDEX_TWO_PANEL_LANDSCAPE] = |
| 819 | a.getFloat(R.styleable.ProfileDisplayOption_twoPanelLandscapeIconTextSize, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 820 | textSizes[INDEX_DEFAULT]); |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 821 | |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 822 | horizontalMargin[INDEX_DEFAULT] = a.getFloat( |
| 823 | R.styleable.ProfileDisplayOption_horizontalMargin, 0); |
| 824 | horizontalMargin[INDEX_LANDSCAPE] = horizontalMargin[INDEX_DEFAULT]; |
| 825 | horizontalMargin[INDEX_ALL_APPS] = horizontalMargin[INDEX_DEFAULT]; |
| 826 | horizontalMargin[INDEX_TWO_PANEL_LANDSCAPE] = a.getFloat( |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 827 | R.styleable.ProfileDisplayOption_twoPanelLandscapeHorizontalMargin, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 828 | horizontalMargin[INDEX_DEFAULT]); |
| 829 | horizontalMargin[INDEX_TWO_PANEL_PORTRAIT] = a.getFloat( |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 830 | R.styleable.ProfileDisplayOption_twoPanelPortraitHorizontalMargin, |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 831 | horizontalMargin[INDEX_DEFAULT]); |
Thales Lima | d90faab | 2021-09-21 17:18:47 +0100 | [diff] [blame] | 832 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 833 | a.recycle(); |
| 834 | } |
| 835 | |
| 836 | DisplayOption() { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 837 | this(null); |
| 838 | } |
| 839 | |
| 840 | DisplayOption(GridOption grid) { |
| 841 | this.grid = grid; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 842 | minWidthDps = 0; |
| 843 | minHeightDps = 0; |
| 844 | canBeDefault = false; |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 845 | for (int i = 0; i < COUNT_SIZES; i++) { |
| 846 | iconSizes[i] = 0; |
| 847 | textSizes[i] = 0; |
| 848 | borderSpaces[i] = new PointF(); |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 849 | minCellSize[i] = new PointF(); |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 850 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | private DisplayOption multiply(float w) { |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 854 | for (int i = 0; i < COUNT_SIZES; i++) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 855 | iconSizes[i] *= w; |
| 856 | textSizes[i] *= w; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 857 | borderSpaces[i].x *= w; |
| 858 | borderSpaces[i].y *= w; |
| 859 | minCellSize[i].x *= w; |
| 860 | minCellSize[i].y *= w; |
| 861 | horizontalMargin[i] *= w; |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 862 | } |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 863 | |
| 864 | folderBorderSpace *= w; |
| 865 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 866 | return this; |
| 867 | } |
| 868 | |
| 869 | private DisplayOption add(DisplayOption p) { |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 870 | for (int i = 0; i < COUNT_SIZES; i++) { |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 871 | iconSizes[i] += p.iconSizes[i]; |
| 872 | textSizes[i] += p.textSizes[i]; |
Thales Lima | 83bedbf | 2021-10-05 17:47:39 +0100 | [diff] [blame] | 873 | borderSpaces[i].x += p.borderSpaces[i].x; |
| 874 | borderSpaces[i].y += p.borderSpaces[i].y; |
| 875 | minCellSize[i].x += p.minCellSize[i].x; |
| 876 | minCellSize[i].y += p.minCellSize[i].y; |
| 877 | horizontalMargin[i] += p.horizontalMargin[i]; |
Sunny Goyal | 6e6f799 | 2021-08-24 16:23:29 -0700 | [diff] [blame] | 878 | } |
Thales Lima | 78d00ad | 2021-09-30 11:29:06 +0100 | [diff] [blame] | 879 | |
| 880 | folderBorderSpace += p.folderBorderSpace; |
| 881 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 882 | return this; |
| 883 | } |
| 884 | } |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 885 | } |