Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 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 | |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 19 | import static com.android.launcher3.Utilities.getDevicePrefs; |
Tracy Zhou | ed5f308 | 2020-04-20 01:13:26 -0700 | [diff] [blame] | 20 | import static com.android.launcher3.Utilities.getPointString; |
Jon Miranda | 73dcc98 | 2020-12-11 14:14:46 -0800 | [diff] [blame] | 21 | import static com.android.launcher3.config.FeatureFlags.ENABLE_FOUR_COLUMNS; |
Andras Kloczl | 8e57cce | 2021-02-11 23:51:19 +0100 | [diff] [blame] | 22 | import static com.android.launcher3.config.FeatureFlags.ENABLE_TWO_PANEL_HOME; |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 23 | import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; |
Sunny Goyal | 8b0cb41 | 2019-04-22 09:01:26 -0700 | [diff] [blame] | 24 | import static com.android.launcher3.util.PackageManagerHelper.getPackageFilter; |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 25 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 26 | import android.annotation.TargetApi; |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 27 | import android.appwidget.AppWidgetHostView; |
Hyunyoung Song | e11eb47 | 2019-03-19 15:05:21 -0700 | [diff] [blame] | 28 | import android.content.BroadcastReceiver; |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 29 | import android.content.ComponentName; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 30 | import android.content.Context; |
Hyunyoung Song | e11eb47 | 2019-03-19 15:05:21 -0700 | [diff] [blame] | 31 | import android.content.Intent; |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 32 | import android.content.res.Configuration; |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 33 | import android.content.res.Resources; |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 34 | import android.content.res.TypedArray; |
| 35 | import android.content.res.XmlResourceParser; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 36 | import android.graphics.Point; |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 37 | import android.graphics.Rect; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 38 | import android.text.TextUtils; |
| 39 | import android.util.AttributeSet; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 40 | import android.util.DisplayMetrics; |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 41 | import android.util.Log; |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 42 | import android.util.SparseArray; |
| 43 | import android.util.TypedValue; |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 44 | import android.util.Xml; |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 45 | import android.view.Display; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 46 | |
Sunny Goyal | 6fe3eec | 2019-08-15 14:53:41 -0700 | [diff] [blame] | 47 | import androidx.annotation.Nullable; |
| 48 | import androidx.annotation.VisibleForTesting; |
| 49 | |
Sunny Goyal | 905262c | 2019-05-03 16:50:43 -0700 | [diff] [blame] | 50 | import com.android.launcher3.graphics.IconShape; |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 51 | import com.android.launcher3.util.ConfigMonitor; |
Sunny Goyal | fd58da6 | 2020-08-11 12:06:49 -0700 | [diff] [blame] | 52 | import com.android.launcher3.util.DisplayController; |
| 53 | import com.android.launcher3.util.DisplayController.Info; |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 54 | import com.android.launcher3.util.IntArray; |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 55 | import com.android.launcher3.util.MainThreadInitializedObject; |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 56 | import com.android.launcher3.util.Themes; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 57 | |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 58 | import org.xmlpull.v1.XmlPullParser; |
| 59 | import org.xmlpull.v1.XmlPullParserException; |
| 60 | |
| 61 | import java.io.IOException; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 62 | import java.util.ArrayList; |
Sunny Goyal | 6d55f66 | 2019-01-02 12:13:43 -0800 | [diff] [blame] | 63 | import java.util.Collections; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 64 | |
| 65 | public class InvariantDeviceProfile { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 66 | |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 67 | public static final String TAG = "IDP"; |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 68 | // We do not need any synchronization for this variable as its only written on UI thread. |
| 69 | public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE = |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 70 | new MainThreadInitializedObject<>(InvariantDeviceProfile::new); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 71 | |
Tracy Zhou | ed5f308 | 2020-04-20 01:13:26 -0700 | [diff] [blame] | 72 | public static final String KEY_MIGRATION_SRC_WORKSPACE_SIZE = "migration_src_workspace_size"; |
| 73 | public static final String KEY_MIGRATION_SRC_HOTSEAT_COUNT = "migration_src_hotseat_count"; |
| 74 | |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 75 | private static final String KEY_IDP_GRID_NAME = "idp_grid_name"; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 76 | |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 77 | private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48; |
| 78 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 79 | public static final int CHANGE_FLAG_GRID = 1 << 0; |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 80 | public static final int CHANGE_FLAG_ICON_PARAMS = 1 << 1; |
| 81 | |
| 82 | public static final String KEY_ICON_PATH_REF = "pref_icon_shape_path"; |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 83 | |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 84 | // Constants that affects the interpolation curve between statically defined device profile |
| 85 | // buckets. |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 86 | private static final float KNEARESTNEIGHBOR = 3; |
| 87 | private static final float WEIGHT_POWER = 5; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 88 | |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 89 | // 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] | 90 | private static final float WEIGHT_EFFICIENT = 100000f; |
| 91 | |
| 92 | private static final int CONFIG_ICON_MASK_RES_ID = Resources.getSystem().getIdentifier( |
| 93 | "config_icon_mask", "string", "android"); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 94 | |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 95 | /** |
| 96 | * Number of icons per row and column in the workspace. |
| 97 | */ |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 98 | public int numRows; |
| 99 | public int numColumns; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 100 | |
| 101 | /** |
| 102 | * Number of icons per row and column in the folder. |
| 103 | */ |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 104 | public int numFolderRows; |
| 105 | public int numFolderColumns; |
Sunny Goyal | fc21830 | 2015-09-17 14:59:10 -0700 | [diff] [blame] | 106 | public float iconSize; |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 107 | public String iconShapePath; |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 108 | public float landscapeIconSize; |
Andras Kloczl | 6057cb9 | 2021-04-07 13:45:17 +0200 | [diff] [blame] | 109 | public float landscapeIconTextSize; |
Sunny Goyal | fc21830 | 2015-09-17 14:59:10 -0700 | [diff] [blame] | 110 | public int iconBitmapSize; |
| 111 | public int fillResIconDpi; |
| 112 | public float iconTextSize; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 113 | public float allAppsIconSize; |
| 114 | public float allAppsIconTextSize; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 115 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 116 | public float minCellHeight; |
| 117 | public float minCellWidth; |
| 118 | public float borderSpacing; |
| 119 | |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 120 | private SparseArray<TypedValue> mExtraAttrs; |
| 121 | |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 122 | /** |
| 123 | * Number of icons inside the hotseat area. |
| 124 | */ |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame^] | 125 | protected int numShownHotseatIcons; |
| 126 | |
| 127 | /** |
| 128 | * Number of icons inside the hotseat area that is stored in the database. This is greater than |
| 129 | * or equal to numnShownHotseatIcons, allowing for a seamless transition between two hotseat |
| 130 | * sizes that share the same DB. |
| 131 | */ |
| 132 | public int numDatabaseHotseatIcons; |
Adam Cohen | 2782449 | 2017-09-22 17:10:55 -0700 | [diff] [blame] | 133 | |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 134 | /** |
| 135 | * Number of columns in the all apps list. |
| 136 | */ |
| 137 | public int numAllAppsColumns; |
| 138 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 139 | /** |
| 140 | * Do not query directly. see {@link DeviceProfile#isScalableGrid}. |
| 141 | */ |
| 142 | protected boolean isScalable; |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 143 | public int devicePaddingId; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 144 | |
Tracy Zhou | 7df93d2 | 2020-01-27 13:44:06 -0800 | [diff] [blame] | 145 | public String dbFile; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 146 | public int defaultLayoutId; |
Adam Cohen | 2782449 | 2017-09-22 17:10:55 -0700 | [diff] [blame] | 147 | int demoModeLayoutId; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 148 | |
cuijiaxing | abda8d7 | 2017-03-20 09:51:36 -0700 | [diff] [blame] | 149 | public DeviceProfile landscapeProfile; |
| 150 | public DeviceProfile portraitProfile; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 151 | |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 152 | @Nullable public DevicePaddings devicePaddings; |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 153 | |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 154 | public Point defaultWallpaperSize; |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 155 | public Rect defaultWidgetPadding; |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 156 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 157 | private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>(); |
| 158 | private ConfigMonitor mConfigMonitor; |
Hyunyoung Song | e11eb47 | 2019-03-19 15:05:21 -0700 | [diff] [blame] | 159 | private OverlayMonitor mOverlayMonitor; |
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 |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 162 | public InvariantDeviceProfile() {} |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 163 | |
Sunny Goyal | f633ef5 | 2018-03-13 09:57:05 -0700 | [diff] [blame] | 164 | private InvariantDeviceProfile(InvariantDeviceProfile p) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 165 | numRows = p.numRows; |
| 166 | numColumns = p.numColumns; |
| 167 | numFolderRows = p.numFolderRows; |
| 168 | numFolderColumns = p.numFolderColumns; |
| 169 | iconSize = p.iconSize; |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 170 | iconShapePath = p.iconShapePath; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 171 | landscapeIconSize = p.landscapeIconSize; |
Tony Wickham | 9459f31 | 2020-06-15 13:30:20 -0500 | [diff] [blame] | 172 | iconBitmapSize = p.iconBitmapSize; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 173 | iconTextSize = p.iconTextSize; |
Andras Kloczl | 6057cb9 | 2021-04-07 13:45:17 +0200 | [diff] [blame] | 174 | landscapeIconTextSize = p.landscapeIconTextSize; |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame^] | 175 | numShownHotseatIcons = p.numShownHotseatIcons; |
| 176 | numDatabaseHotseatIcons = p.numDatabaseHotseatIcons; |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 177 | numAllAppsColumns = p.numAllAppsColumns; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 178 | isScalable = p.isScalable; |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 179 | devicePaddingId = p.devicePaddingId; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 180 | minCellHeight = p.minCellHeight; |
| 181 | minCellWidth = p.minCellWidth; |
| 182 | borderSpacing = p.borderSpacing; |
Tracy Zhou | 7df93d2 | 2020-01-27 13:44:06 -0800 | [diff] [blame] | 183 | dbFile = p.dbFile; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 184 | allAppsIconSize = p.allAppsIconSize; |
| 185 | allAppsIconTextSize = p.allAppsIconTextSize; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 186 | defaultLayoutId = p.defaultLayoutId; |
| 187 | demoModeLayoutId = p.demoModeLayoutId; |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 188 | mExtraAttrs = p.mExtraAttrs; |
Hyunyoung Song | e11eb47 | 2019-03-19 15:05:21 -0700 | [diff] [blame] | 189 | mOverlayMonitor = p.mOverlayMonitor; |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 190 | devicePaddings = p.devicePaddings; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Sunny Goyal | bbf0184 | 2015-10-08 07:41:15 -0700 | [diff] [blame] | 193 | @TargetApi(23) |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 194 | private InvariantDeviceProfile(Context context) { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 195 | String gridName = getCurrentGridName(context); |
| 196 | String newGridName = initGrid(context, gridName); |
| 197 | if (!newGridName.equals(gridName)) { |
| 198 | Utilities.getPrefs(context).edit().putString(KEY_IDP_GRID_NAME, newGridName).apply(); |
| 199 | } |
Tracy Zhou | ed5f308 | 2020-04-20 01:13:26 -0700 | [diff] [blame] | 200 | Utilities.getPrefs(context).edit() |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame^] | 201 | .putInt(KEY_MIGRATION_SRC_HOTSEAT_COUNT, numDatabaseHotseatIcons) |
Tracy Zhou | ed5f308 | 2020-04-20 01:13:26 -0700 | [diff] [blame] | 202 | .putString(KEY_MIGRATION_SRC_WORKSPACE_SIZE, getPointString(numColumns, numRows)) |
| 203 | .apply(); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 204 | |
Sunny Goyal | ead22a5 | 2021-02-02 23:21:55 -0800 | [diff] [blame] | 205 | mConfigMonitor = new ConfigMonitor(context, this::onConfigChanged); |
Hyunyoung Song | e11eb47 | 2019-03-19 15:05:21 -0700 | [diff] [blame] | 206 | mOverlayMonitor = new OverlayMonitor(context); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Hyunyoung Song | e11eb47 | 2019-03-19 15:05:21 -0700 | [diff] [blame] | 209 | /** |
| 210 | * This constructor should NOT have any monitors by design. |
| 211 | */ |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 212 | public InvariantDeviceProfile(Context context, String gridName) { |
| 213 | String newName = initGrid(context, gridName); |
| 214 | if (newName == null || !newName.equals(gridName)) { |
| 215 | throw new IllegalArgumentException("Unknown grid name"); |
| 216 | } |
| 217 | } |
| 218 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 219 | /** |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 220 | * This constructor should NOT have any monitors by design. |
| 221 | */ |
| 222 | public InvariantDeviceProfile(Context context, Display display) { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 223 | // Ensure that the main device profile is initialized |
| 224 | InvariantDeviceProfile originalProfile = INSTANCE.get(context); |
| 225 | String gridName = getCurrentGridName(context); |
| 226 | |
| 227 | // Get the display info based on default display and interpolate it to existing display |
| 228 | DisplayOption defaultDisplayOption = invDistWeightedInterpolate( |
Sunny Goyal | fd58da6 | 2020-08-11 12:06:49 -0700 | [diff] [blame] | 229 | DisplayController.getDefaultDisplay(context).getInfo(), |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 230 | getPredefinedDeviceProfiles(context, gridName)); |
| 231 | |
Alex Chau | 417bd72 | 2021-01-26 15:22:18 +0000 | [diff] [blame] | 232 | Info myInfo = new Info(context, display); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 233 | DisplayOption myDisplayOption = invDistWeightedInterpolate( |
| 234 | myInfo, getPredefinedDeviceProfiles(context, gridName)); |
| 235 | |
| 236 | DisplayOption result = new DisplayOption(defaultDisplayOption.grid) |
| 237 | .add(myDisplayOption); |
| 238 | result.iconSize = defaultDisplayOption.iconSize; |
| 239 | result.landscapeIconSize = defaultDisplayOption.landscapeIconSize; |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame^] | 240 | result.numShownHotseatIcons = myDisplayOption.numShownHotseatIcons; |
Alex Chau | 7c43972 | 2021-03-24 11:32:44 +0000 | [diff] [blame] | 241 | if (defaultDisplayOption.allAppsIconSize < myDisplayOption.allAppsIconSize) { |
| 242 | result.allAppsIconSize = defaultDisplayOption.allAppsIconSize; |
| 243 | result.numAllAppsColumns = defaultDisplayOption.numAllAppsColumns; |
| 244 | } else { |
| 245 | result.allAppsIconSize = myDisplayOption.allAppsIconSize; |
| 246 | result.numAllAppsColumns = myDisplayOption.numAllAppsColumns; |
| 247 | } |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 248 | result.minCellHeight = defaultDisplayOption.minCellHeight; |
| 249 | result.minCellWidth = defaultDisplayOption.minCellWidth; |
| 250 | result.borderSpacing = defaultDisplayOption.borderSpacing; |
Jon Miranda | 228877d | 2021-02-09 11:05:00 -0500 | [diff] [blame] | 251 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 252 | initGrid(context, myInfo, result); |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 253 | } |
| 254 | |
Tracy Zhou | 42255d2 | 2020-03-13 00:38:11 -0700 | [diff] [blame] | 255 | public static String getCurrentGridName(Context context) { |
Andras Kloczl | 8e57cce | 2021-02-11 23:51:19 +0100 | [diff] [blame] | 256 | if (ENABLE_TWO_PANEL_HOME.get()) { |
| 257 | return ENABLE_TWO_PANEL_HOME.key; |
| 258 | } |
Jon Miranda | 73dcc98 | 2020-12-11 14:14:46 -0800 | [diff] [blame] | 259 | if (ENABLE_FOUR_COLUMNS.get()) { |
| 260 | return ENABLE_FOUR_COLUMNS.key; |
| 261 | } |
Tracy Zhou | c6060e6 | 2020-04-27 13:05:34 -0700 | [diff] [blame] | 262 | return Utilities.isGridOptionsEnabled(context) |
| 263 | ? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null) : null; |
Tracy Zhou | 42255d2 | 2020-03-13 00:38:11 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 266 | /** |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 267 | * Retrieve system defined or RRO overriden icon shape. |
| 268 | */ |
| 269 | private static String getIconShapePath(Context context) { |
| 270 | if (CONFIG_ICON_MASK_RES_ID == 0) { |
| 271 | Log.e(TAG, "Icon mask res identifier failed to retrieve."); |
| 272 | return ""; |
| 273 | } |
| 274 | return context.getResources().getString(CONFIG_ICON_MASK_RES_ID); |
| 275 | } |
| 276 | |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 277 | private String initGrid(Context context, String gridName) { |
Sunny Goyal | fd58da6 | 2020-08-11 12:06:49 -0700 | [diff] [blame] | 278 | Info displayInfo = DisplayController.getDefaultDisplay(context).getInfo(); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 279 | ArrayList<DisplayOption> allOptions = getPredefinedDeviceProfiles(context, gridName); |
| 280 | |
| 281 | DisplayOption displayOption = invDistWeightedInterpolate(displayInfo, allOptions); |
| 282 | initGrid(context, displayInfo, displayOption); |
| 283 | return displayOption.grid.name; |
Sunny Goyal | 9c2b960 | 2020-01-07 13:07:55 -0800 | [diff] [blame] | 284 | } |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 285 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 286 | private void initGrid( |
Sunny Goyal | fd58da6 | 2020-08-11 12:06:49 -0700 | [diff] [blame] | 287 | Context context, Info displayInfo, DisplayOption displayOption) { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 288 | GridOption closestProfile = displayOption.grid; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 289 | numRows = closestProfile.numRows; |
| 290 | numColumns = closestProfile.numColumns; |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame^] | 291 | numDatabaseHotseatIcons = closestProfile.numDatabaseHotseatIcons; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 292 | dbFile = closestProfile.dbFile; |
| 293 | defaultLayoutId = closestProfile.defaultLayoutId; |
| 294 | demoModeLayoutId = closestProfile.demoModeLayoutId; |
| 295 | numFolderRows = closestProfile.numFolderRows; |
| 296 | numFolderColumns = closestProfile.numFolderColumns; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 297 | isScalable = closestProfile.isScalable; |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 298 | devicePaddingId = closestProfile.devicePaddingId; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 299 | |
| 300 | mExtraAttrs = closestProfile.extraAttrs; |
| 301 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 302 | iconSize = displayOption.iconSize; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 303 | iconShapePath = getIconShapePath(context); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 304 | landscapeIconSize = displayOption.landscapeIconSize; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 305 | iconBitmapSize = ResourceUtils.pxFromDp(iconSize, displayInfo.metrics); |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 306 | iconTextSize = displayOption.iconTextSize; |
Andras Kloczl | 6057cb9 | 2021-04-07 13:45:17 +0200 | [diff] [blame] | 307 | landscapeIconTextSize = displayOption.landscapeIconTextSize; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 308 | fillResIconDpi = getLauncherIconDensity(iconBitmapSize); |
| 309 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 310 | minCellHeight = displayOption.minCellHeight; |
| 311 | minCellWidth = displayOption.minCellWidth; |
| 312 | borderSpacing = displayOption.borderSpacing; |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame^] | 313 | numShownHotseatIcons = Math.round(displayOption.numShownHotseatIcons); |
Alex Chau | 7c43972 | 2021-03-24 11:32:44 +0000 | [diff] [blame] | 314 | numAllAppsColumns = Math.round(displayOption.numAllAppsColumns); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 315 | |
Tracy Zhou | c6060e6 | 2020-04-27 13:05:34 -0700 | [diff] [blame] | 316 | if (Utilities.isGridOptionsEnabled(context)) { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 317 | allAppsIconSize = displayOption.allAppsIconSize; |
| 318 | allAppsIconTextSize = displayOption.allAppsIconTextSize; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 319 | } else { |
| 320 | allAppsIconSize = iconSize; |
| 321 | allAppsIconTextSize = iconTextSize; |
| 322 | } |
| 323 | |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 324 | if (devicePaddingId != 0) { |
| 325 | devicePaddings = new DevicePaddings(context, devicePaddingId); |
| 326 | } |
| 327 | |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 328 | // If the partner customization apk contains any grid overrides, apply them |
| 329 | // Supported overrides: numRows, numColumns, iconSize |
| 330 | applyPartnerDeviceProfileOverrides(context, displayInfo.metrics); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 331 | |
Winson Chung | 13c1c2c | 2019-09-06 11:46:19 -0700 | [diff] [blame] | 332 | Point realSize = new Point(displayInfo.realSize); |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 333 | // The real size never changes. smallSide and largeSide will remain the |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 334 | // same in any orientation. |
| 335 | int smallSide = Math.min(realSize.x, realSize.y); |
| 336 | int largeSide = Math.max(realSize.x, realSize.y); |
| 337 | |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 338 | DeviceProfile.Builder builder = new DeviceProfile.Builder(context, this, displayInfo) |
| 339 | .setSizeRange(new Point(displayInfo.smallestSize), |
| 340 | new Point(displayInfo.largestSize)); |
| 341 | |
| 342 | landscapeProfile = builder.setSize(largeSide, smallSide).build(); |
| 343 | portraitProfile = builder.setSize(smallSide, largeSide).build(); |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 344 | |
| 345 | // We need to ensure that there is enough extra space in the wallpaper |
| 346 | // for the intended parallax effects |
| 347 | if (context.getResources().getConfiguration().smallestScreenWidthDp >= 720) { |
| 348 | defaultWallpaperSize = new Point( |
| 349 | (int) (largeSide * wallpaperTravelToScreenWidthRatio(largeSide, smallSide)), |
| 350 | largeSide); |
| 351 | } else { |
| 352 | defaultWallpaperSize = new Point(Math.max(smallSide * 2, largeSide), largeSide); |
| 353 | } |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 354 | |
| 355 | ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName()); |
| 356 | defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 359 | @Nullable |
| 360 | public TypedValue getAttrValue(int attr) { |
| 361 | return mExtraAttrs == null ? null : mExtraAttrs.get(attr); |
| 362 | } |
| 363 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 364 | public void addOnChangeListener(OnIDPChangeListener listener) { |
| 365 | mChangeListeners.add(listener); |
| 366 | } |
| 367 | |
Hyunyoung Song | b4d1ca4 | 2019-01-08 17:15:16 -0800 | [diff] [blame] | 368 | public void removeOnChangeListener(OnIDPChangeListener listener) { |
| 369 | mChangeListeners.remove(listener); |
| 370 | } |
| 371 | |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 372 | public void verifyConfigChangedInBackground(final Context context) { |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 373 | String savedIconMaskPath = getDevicePrefs(context).getString(KEY_ICON_PATH_REF, ""); |
| 374 | // Good place to check if grid size changed in themepicker when launcher was dead. |
| 375 | if (savedIconMaskPath.isEmpty()) { |
| 376 | getDevicePrefs(context).edit().putString(KEY_ICON_PATH_REF, getIconShapePath(context)) |
| 377 | .apply(); |
| 378 | } else if (!savedIconMaskPath.equals(getIconShapePath(context))) { |
| 379 | getDevicePrefs(context).edit().putString(KEY_ICON_PATH_REF, getIconShapePath(context)) |
| 380 | .apply(); |
| 381 | apply(context, CHANGE_FLAG_ICON_PARAMS); |
| 382 | } |
| 383 | } |
| 384 | |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 385 | public void setCurrentGrid(Context context, String gridName) { |
| 386 | Context appContext = context.getApplicationContext(); |
| 387 | Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply(); |
Sunny Goyal | 6fe3eec | 2019-08-15 14:53:41 -0700 | [diff] [blame] | 388 | MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext)); |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 389 | } |
| 390 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 391 | private void onConfigChanged(Context context) { |
| 392 | // Config changes, what shall we do? |
| 393 | InvariantDeviceProfile oldProfile = new InvariantDeviceProfile(this); |
| 394 | |
| 395 | // Re-init grid |
Tracy Zhou | c6060e6 | 2020-04-27 13:05:34 -0700 | [diff] [blame] | 396 | String gridName = getCurrentGridName(context); |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 397 | initGrid(context, gridName); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 398 | |
| 399 | int changeFlags = 0; |
| 400 | if (numRows != oldProfile.numRows || |
| 401 | numColumns != oldProfile.numColumns || |
| 402 | numFolderColumns != oldProfile.numFolderColumns || |
| 403 | numFolderRows != oldProfile.numFolderRows || |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame^] | 404 | numDatabaseHotseatIcons != oldProfile.numDatabaseHotseatIcons) { |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 405 | changeFlags |= CHANGE_FLAG_GRID; |
| 406 | } |
| 407 | |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 408 | if (iconSize != oldProfile.iconSize || iconBitmapSize != oldProfile.iconBitmapSize || |
| 409 | !iconShapePath.equals(oldProfile.iconShapePath)) { |
| 410 | changeFlags |= CHANGE_FLAG_ICON_PARAMS; |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 411 | } |
Sunny Goyal | 90e3fbc | 2019-01-23 16:42:43 -0800 | [diff] [blame] | 412 | if (!iconShapePath.equals(oldProfile.iconShapePath)) { |
Sunny Goyal | 905262c | 2019-05-03 16:50:43 -0700 | [diff] [blame] | 413 | IconShape.init(context); |
Sunny Goyal | 90e3fbc | 2019-01-23 16:42:43 -0800 | [diff] [blame] | 414 | } |
| 415 | |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 416 | apply(context, changeFlags); |
| 417 | } |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 418 | |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 419 | private void apply(Context context, int changeFlags) { |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 420 | // Create a new config monitor |
| 421 | mConfigMonitor.unregister(); |
| 422 | mConfigMonitor = new ConfigMonitor(context, this::onConfigChanged); |
| 423 | |
| 424 | for (OnIDPChangeListener listener : mChangeListeners) { |
| 425 | listener.onIdpChanged(changeFlags, this); |
| 426 | } |
| 427 | } |
| 428 | |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 429 | static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context, String gridName) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 430 | ArrayList<DisplayOption> profiles = new ArrayList<>(); |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 431 | try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) { |
| 432 | final int depth = parser.getDepth(); |
| 433 | int type; |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 434 | while (((type = parser.next()) != XmlPullParser.END_TAG || |
| 435 | parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 436 | if ((type == XmlPullParser.START_TAG) |
| 437 | && GridOption.TAG_NAME.equals(parser.getName())) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 438 | |
| 439 | GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser)); |
| 440 | final int displayDepth = parser.getDepth(); |
| 441 | while (((type = parser.next()) != XmlPullParser.END_TAG || |
| 442 | parser.getDepth() > displayDepth) |
| 443 | && type != XmlPullParser.END_DOCUMENT) { |
| 444 | if ((type == XmlPullParser.START_TAG) && "display-option".equals( |
| 445 | parser.getName())) { |
| 446 | profiles.add(new DisplayOption( |
| 447 | gridOption, context, Xml.asAttributeSet(parser))); |
| 448 | } |
| 449 | } |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 450 | } |
| 451 | } |
| 452 | } catch (IOException|XmlPullParserException e) { |
| 453 | throw new RuntimeException(e); |
| 454 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 455 | |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 456 | ArrayList<DisplayOption> filteredProfiles = new ArrayList<>(); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 457 | if (!TextUtils.isEmpty(gridName)) { |
| 458 | for (DisplayOption option : profiles) { |
| 459 | if (gridName.equals(option.grid.name)) { |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 460 | filteredProfiles.add(option); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 461 | } |
| 462 | } |
| 463 | } |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 464 | if (filteredProfiles.isEmpty()) { |
| 465 | // No grid found, use the default options |
| 466 | for (DisplayOption option : profiles) { |
| 467 | if (option.canBeDefault) { |
| 468 | filteredProfiles.add(option); |
| 469 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 470 | } |
| 471 | } |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 472 | if (filteredProfiles.isEmpty()) { |
| 473 | throw new RuntimeException("No display option with canBeDefault=true"); |
| 474 | } |
| 475 | return filteredProfiles; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 478 | private int getLauncherIconDensity(int requiredSize) { |
| 479 | // Densities typically defined by an app. |
| 480 | int[] densityBuckets = new int[] { |
| 481 | DisplayMetrics.DENSITY_LOW, |
| 482 | DisplayMetrics.DENSITY_MEDIUM, |
| 483 | DisplayMetrics.DENSITY_TV, |
| 484 | DisplayMetrics.DENSITY_HIGH, |
| 485 | DisplayMetrics.DENSITY_XHIGH, |
| 486 | DisplayMetrics.DENSITY_XXHIGH, |
| 487 | DisplayMetrics.DENSITY_XXXHIGH |
| 488 | }; |
| 489 | |
| 490 | int density = DisplayMetrics.DENSITY_XXXHIGH; |
| 491 | for (int i = densityBuckets.length - 1; i >= 0; i--) { |
| 492 | float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i] |
| 493 | / DisplayMetrics.DENSITY_DEFAULT; |
| 494 | if (expectedSize >= requiredSize) { |
| 495 | density = densityBuckets[i]; |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | return density; |
| 500 | } |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 501 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 502 | /** |
| 503 | * Apply any Partner customization grid overrides. |
| 504 | * |
| 505 | * Currently we support: all apps row / column count. |
| 506 | */ |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 507 | private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) { |
| 508 | Partner p = Partner.get(context.getPackageManager()); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 509 | if (p != null) { |
| 510 | p.applyInvariantDeviceProfileOverrides(this, dm); |
| 511 | } |
| 512 | } |
| 513 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 514 | private static float dist(float x0, float y0, float x1, float y1) { |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 515 | return (float) Math.hypot(x1 - x0, y1 - y0); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 518 | @VisibleForTesting |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 519 | static DisplayOption invDistWeightedInterpolate( |
Sunny Goyal | fd58da6 | 2020-08-11 12:06:49 -0700 | [diff] [blame] | 520 | Info displayInfo, ArrayList<DisplayOption> points) { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 521 | Point smallestSize = new Point(displayInfo.smallestSize); |
| 522 | Point largestSize = new Point(displayInfo.largestSize); |
| 523 | |
| 524 | // This guarantees that width < height |
| 525 | float width = Utilities.dpiFromPx(Math.min(smallestSize.x, smallestSize.y), |
| 526 | displayInfo.metrics); |
| 527 | float height = Utilities.dpiFromPx(Math.min(largestSize.x, largestSize.y), |
| 528 | displayInfo.metrics); |
| 529 | |
| 530 | // Sort the profiles based on the closeness to the device size |
| 531 | Collections.sort(points, (a, b) -> |
| 532 | Float.compare(dist(width, height, a.minWidthDps, a.minHeightDps), |
| 533 | dist(width, height, b.minWidthDps, b.minHeightDps))); |
| 534 | |
| 535 | GridOption closestOption = points.get(0).grid; |
| 536 | float weights = 0; |
| 537 | |
| 538 | DisplayOption p = points.get(0); |
| 539 | if (dist(width, height, p.minWidthDps, p.minHeightDps) == 0) { |
| 540 | return p; |
| 541 | } |
| 542 | |
| 543 | DisplayOption out = new DisplayOption(closestOption); |
| 544 | for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) { |
| 545 | p = points.get(i); |
| 546 | float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER); |
| 547 | weights += w; |
| 548 | out.add(new DisplayOption().add(p).multiply(w)); |
| 549 | } |
| 550 | return out.multiply(1.0f / weights); |
| 551 | } |
| 552 | |
| 553 | @VisibleForTesting |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 554 | static DisplayOption invDistWeightedInterpolate(float width, float height, |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 555 | ArrayList<DisplayOption> points) { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 556 | float weights = 0; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 557 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 558 | DisplayOption p = points.get(0); |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 559 | if (dist(width, height, p.minWidthDps, p.minHeightDps) == 0) { |
| 560 | return p; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 561 | } |
| 562 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 563 | DisplayOption out = new DisplayOption(); |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 564 | for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 565 | p = points.get(i); |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 566 | float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER); |
| 567 | weights += w; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 568 | out.add(new DisplayOption().add(p).multiply(w)); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 569 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 570 | return out.multiply(1.0f / weights); |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 573 | public DeviceProfile getDeviceProfile(Context context) { |
| 574 | return context.getResources().getConfiguration().orientation |
| 575 | == Configuration.ORIENTATION_LANDSCAPE ? landscapeProfile : portraitProfile; |
| 576 | } |
| 577 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 578 | 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] | 579 | float d = dist(x0, y0, x1, y1); |
| 580 | if (Float.compare(d, 0f) == 0) { |
| 581 | return Float.POSITIVE_INFINITY; |
| 582 | } |
| 583 | return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow)); |
| 584 | } |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 585 | |
| 586 | /** |
| 587 | * As a ratio of screen height, the total distance we want the parallax effect to span |
| 588 | * horizontally |
| 589 | */ |
| 590 | private static float wallpaperTravelToScreenWidthRatio(int width, int height) { |
| 591 | float aspectRatio = width / (float) height; |
| 592 | |
| 593 | // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width |
| 594 | // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width |
| 595 | // We will use these two data points to extrapolate how much the wallpaper parallax effect |
| 596 | // to span (ie travel) at any aspect ratio: |
| 597 | |
| 598 | final float ASPECT_RATIO_LANDSCAPE = 16/10f; |
| 599 | final float ASPECT_RATIO_PORTRAIT = 10/16f; |
| 600 | final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f; |
| 601 | final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f; |
| 602 | |
| 603 | // To find out the desired width at different aspect ratios, we use the following two |
| 604 | // formulas, where the coefficient on x is the aspect ratio (width/height): |
| 605 | // (16/10)x + y = 1.5 |
| 606 | // (10/16)x + y = 1.2 |
| 607 | // We solve for x and y and end up with a final formula: |
| 608 | final float x = |
| 609 | (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) / |
| 610 | (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT); |
| 611 | final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT; |
| 612 | return x * aspectRatio + y; |
| 613 | } |
| 614 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 615 | public interface OnIDPChangeListener { |
| 616 | |
| 617 | void onIdpChanged(int changeFlags, InvariantDeviceProfile profile); |
| 618 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 619 | |
| 620 | |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 621 | public static final class GridOption { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 622 | |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 623 | public static final String TAG_NAME = "grid-option"; |
| 624 | |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 625 | public final String name; |
| 626 | public final int numRows; |
| 627 | public final int numColumns; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 628 | |
| 629 | private final int numFolderRows; |
| 630 | private final int numFolderColumns; |
| 631 | |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame^] | 632 | private final int numDatabaseHotseatIcons; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 633 | |
Tracy Zhou | 7df93d2 | 2020-01-27 13:44:06 -0800 | [diff] [blame] | 634 | private final String dbFile; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 635 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 636 | private final int defaultLayoutId; |
| 637 | private final int demoModeLayoutId; |
| 638 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 639 | private final boolean isScalable; |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 640 | private final int devicePaddingId; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 641 | |
Jon Miranda | ec1277e | 2021-03-25 10:41:54 -0400 | [diff] [blame] | 642 | public final boolean visible; |
| 643 | |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 644 | private final SparseArray<TypedValue> extraAttrs; |
| 645 | |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 646 | public GridOption(Context context, AttributeSet attrs) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 647 | TypedArray a = context.obtainStyledAttributes( |
| 648 | attrs, R.styleable.GridDisplayOption); |
| 649 | name = a.getString(R.styleable.GridDisplayOption_name); |
| 650 | numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0); |
| 651 | numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0); |
| 652 | |
Tracy Zhou | 7df93d2 | 2020-01-27 13:44:06 -0800 | [diff] [blame] | 653 | dbFile = a.getString(R.styleable.GridDisplayOption_dbFile); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 654 | defaultLayoutId = a.getResourceId( |
| 655 | R.styleable.GridDisplayOption_defaultLayoutId, 0); |
| 656 | demoModeLayoutId = a.getResourceId( |
| 657 | R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId); |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame^] | 658 | numDatabaseHotseatIcons = a.getInt( |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 659 | R.styleable.GridDisplayOption_numHotseatIcons, numColumns); |
| 660 | numFolderRows = a.getInt( |
| 661 | R.styleable.GridDisplayOption_numFolderRows, numRows); |
| 662 | numFolderColumns = a.getInt( |
| 663 | R.styleable.GridDisplayOption_numFolderColumns, numColumns); |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 664 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 665 | isScalable = a.getBoolean( |
| 666 | R.styleable.GridDisplayOption_isScalable, false); |
Jon Miranda | c9e69fa | 2021-03-22 17:13:34 -0400 | [diff] [blame] | 667 | devicePaddingId = a.getResourceId( |
| 668 | R.styleable.GridDisplayOption_devicePaddingId, 0); |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 669 | |
Jon Miranda | ec1277e | 2021-03-25 10:41:54 -0400 | [diff] [blame] | 670 | visible = a.getBoolean(R.styleable.GridDisplayOption_visible, true); |
| 671 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 672 | a.recycle(); |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 673 | |
| 674 | extraAttrs = Themes.createValueMap(context, attrs, |
| 675 | IntArray.wrap(R.styleable.GridDisplayOption)); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 676 | } |
| 677 | } |
| 678 | |
| 679 | private static final class DisplayOption { |
| 680 | private final GridOption grid; |
| 681 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 682 | private final float minWidthDps; |
| 683 | private final float minHeightDps; |
| 684 | private final boolean canBeDefault; |
| 685 | |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame^] | 686 | private float numShownHotseatIcons; |
Alex Chau | 7c43972 | 2021-03-24 11:32:44 +0000 | [diff] [blame] | 687 | private float numAllAppsColumns; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 688 | private float minCellHeight; |
| 689 | private float minCellWidth; |
| 690 | private float borderSpacing; |
| 691 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 692 | private float iconSize; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 693 | private float iconTextSize; |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 694 | private float landscapeIconSize; |
Andras Kloczl | 6057cb9 | 2021-04-07 13:45:17 +0200 | [diff] [blame] | 695 | private float landscapeIconTextSize; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 696 | private float allAppsIconSize; |
| 697 | private float allAppsIconTextSize; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 698 | |
| 699 | DisplayOption(GridOption grid, Context context, AttributeSet attrs) { |
| 700 | this.grid = grid; |
| 701 | |
| 702 | TypedArray a = context.obtainStyledAttributes( |
| 703 | attrs, R.styleable.ProfileDisplayOption); |
| 704 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 705 | minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0); |
| 706 | minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0); |
| 707 | canBeDefault = a.getBoolean( |
| 708 | R.styleable.ProfileDisplayOption_canBeDefault, false); |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame^] | 709 | numShownHotseatIcons = a.getInt(R.styleable.ProfileDisplayOption_numShownHotseatIcons, |
| 710 | grid.numDatabaseHotseatIcons); |
Alex Chau | 7c43972 | 2021-03-24 11:32:44 +0000 | [diff] [blame] | 711 | numAllAppsColumns = a.getInt(R.styleable.ProfileDisplayOption_numAllAppsColumns, |
| 712 | grid.numColumns); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 713 | |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 714 | minCellHeight = a.getFloat(R.styleable.ProfileDisplayOption_minCellHeightDps, 0); |
| 715 | minCellWidth = a.getFloat(R.styleable.ProfileDisplayOption_minCellWidthDps, 0); |
| 716 | borderSpacing = a.getFloat(R.styleable.ProfileDisplayOption_borderSpacingDps, 0); |
| 717 | |
Ryan Mitchell | 01b8b68 | 2019-03-28 17:01:07 -0700 | [diff] [blame] | 718 | iconSize = a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 719 | landscapeIconSize = a.getFloat(R.styleable.ProfileDisplayOption_landscapeIconSize, |
| 720 | iconSize); |
| 721 | iconTextSize = a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0); |
Andras Kloczl | 6057cb9 | 2021-04-07 13:45:17 +0200 | [diff] [blame] | 722 | landscapeIconTextSize = a.getFloat( |
| 723 | R.styleable.ProfileDisplayOption_landscapeIconTextSize, iconTextSize); |
Jon Miranda | 6f7e970 | 2019-09-16 14:44:14 -0700 | [diff] [blame] | 724 | |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 725 | allAppsIconSize = a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconSize, |
| 726 | iconSize); |
| 727 | allAppsIconTextSize = a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconTextSize, |
| 728 | iconTextSize); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 729 | a.recycle(); |
| 730 | } |
| 731 | |
| 732 | DisplayOption() { |
Sunny Goyal | 0e7a338 | 2020-04-13 17:15:05 -0700 | [diff] [blame] | 733 | this(null); |
| 734 | } |
| 735 | |
| 736 | DisplayOption(GridOption grid) { |
| 737 | this.grid = grid; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 738 | minWidthDps = 0; |
| 739 | minHeightDps = 0; |
| 740 | canBeDefault = false; |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame^] | 741 | numShownHotseatIcons = 0; |
Alex Chau | 7c43972 | 2021-03-24 11:32:44 +0000 | [diff] [blame] | 742 | numAllAppsColumns = 0; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 743 | minCellHeight = 0; |
| 744 | minCellWidth = 0; |
| 745 | borderSpacing = 0; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | private DisplayOption multiply(float w) { |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame^] | 749 | numShownHotseatIcons *= w; |
Alex Chau | 7c43972 | 2021-03-24 11:32:44 +0000 | [diff] [blame] | 750 | numAllAppsColumns *= w; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 751 | iconSize *= w; |
| 752 | landscapeIconSize *= w; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 753 | allAppsIconSize *= w; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 754 | iconTextSize *= w; |
Andras Kloczl | 6057cb9 | 2021-04-07 13:45:17 +0200 | [diff] [blame] | 755 | landscapeIconTextSize *= w; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 756 | allAppsIconTextSize *= w; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 757 | minCellHeight *= w; |
| 758 | minCellWidth *= w; |
| 759 | borderSpacing *= w; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 760 | return this; |
| 761 | } |
| 762 | |
| 763 | private DisplayOption add(DisplayOption p) { |
Tony Wickham | b87f3cd | 2021-04-07 15:02:37 -0700 | [diff] [blame^] | 764 | numShownHotseatIcons += p.numShownHotseatIcons; |
Alex Chau | 7c43972 | 2021-03-24 11:32:44 +0000 | [diff] [blame] | 765 | numAllAppsColumns += p.numAllAppsColumns; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 766 | iconSize += p.iconSize; |
| 767 | landscapeIconSize += p.landscapeIconSize; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 768 | allAppsIconSize += p.allAppsIconSize; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 769 | iconTextSize += p.iconTextSize; |
Andras Kloczl | 6057cb9 | 2021-04-07 13:45:17 +0200 | [diff] [blame] | 770 | landscapeIconTextSize += p.landscapeIconTextSize; |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 771 | allAppsIconTextSize += p.allAppsIconTextSize; |
Jon Miranda | e126d72 | 2021-02-25 10:45:20 -0500 | [diff] [blame] | 772 | minCellHeight += p.minCellHeight; |
| 773 | minCellWidth += p.minCellWidth; |
| 774 | borderSpacing += p.borderSpacing; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 775 | return this; |
| 776 | } |
| 777 | } |
Hyunyoung Song | e11eb47 | 2019-03-19 15:05:21 -0700 | [diff] [blame] | 778 | |
| 779 | private class OverlayMonitor extends BroadcastReceiver { |
| 780 | |
| 781 | private final String ACTION_OVERLAY_CHANGED = "android.intent.action.OVERLAY_CHANGED"; |
| 782 | |
| 783 | OverlayMonitor(Context context) { |
Sunny Goyal | 8b0cb41 | 2019-04-22 09:01:26 -0700 | [diff] [blame] | 784 | context.registerReceiver(this, getPackageFilter("android", ACTION_OVERLAY_CHANGED)); |
Hyunyoung Song | e11eb47 | 2019-03-19 15:05:21 -0700 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | @Override |
| 788 | public void onReceive(Context context, Intent intent) { |
| 789 | onConfigChanged(context); |
| 790 | } |
| 791 | } |
Sunny Goyal | ae190ff | 2020-04-14 00:19:01 +0000 | [diff] [blame] | 792 | } |