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; |
Sunny Goyal | 8b0cb41 | 2019-04-22 09:01:26 -0700 | [diff] [blame] | 20 | import static com.android.launcher3.config.FeatureFlags.APPLY_CONFIG_AT_RUNTIME; |
| 21 | import static com.android.launcher3.util.PackageManagerHelper.getPackageFilter; |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 22 | |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 23 | import android.annotation.TargetApi; |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 24 | import android.appwidget.AppWidgetHostView; |
Hyunyoung Song | e11eb47 | 2019-03-19 15:05:21 -0700 | [diff] [blame] | 25 | import android.content.BroadcastReceiver; |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 26 | import android.content.ComponentName; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 27 | import android.content.Context; |
Hyunyoung Song | e11eb47 | 2019-03-19 15:05:21 -0700 | [diff] [blame] | 28 | import android.content.Intent; |
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; |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 34 | import android.graphics.Rect; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 35 | import android.text.TextUtils; |
| 36 | import android.util.AttributeSet; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 37 | import android.util.DisplayMetrics; |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 38 | import android.util.Log; |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 39 | import android.util.SparseArray; |
| 40 | import android.util.TypedValue; |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 41 | import android.util.Xml; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 42 | import android.view.Display; |
| 43 | import android.view.WindowManager; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 44 | |
Sunny Goyal | 90e3fbc | 2019-01-23 16:42:43 -0800 | [diff] [blame] | 45 | import com.android.launcher3.folder.FolderShape; |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 46 | import com.android.launcher3.util.ConfigMonitor; |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 47 | import com.android.launcher3.util.IntArray; |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 48 | import com.android.launcher3.util.MainThreadInitializedObject; |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 49 | import com.android.launcher3.util.Themes; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 50 | |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 51 | import org.xmlpull.v1.XmlPullParser; |
| 52 | import org.xmlpull.v1.XmlPullParserException; |
| 53 | |
| 54 | import java.io.IOException; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 55 | import java.util.ArrayList; |
Sunny Goyal | 6d55f66 | 2019-01-02 12:13:43 -0800 | [diff] [blame] | 56 | import java.util.Collections; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 57 | |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 58 | import androidx.annotation.Nullable; |
Sunny Goyal | d230307 | 2018-08-14 15:21:45 -0700 | [diff] [blame] | 59 | import androidx.annotation.VisibleForTesting; |
| 60 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 61 | public class InvariantDeviceProfile { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 62 | |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 63 | public static final String TAG = "IDP"; |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 64 | // We do not need any synchronization for this variable as its only written on UI thread. |
| 65 | public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE = |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 66 | new MainThreadInitializedObject<>(InvariantDeviceProfile::new); |
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 | private static final String KEY_IDP_GRID_NAME = "idp_grid_name"; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 69 | |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 70 | private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48; |
| 71 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 72 | public static final int CHANGE_FLAG_GRID = 1 << 0; |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 73 | public static final int CHANGE_FLAG_ICON_PARAMS = 1 << 1; |
| 74 | |
| 75 | public static final String KEY_ICON_PATH_REF = "pref_icon_shape_path"; |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 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 | |
| 85 | private static final int CONFIG_ICON_MASK_RES_ID = Resources.getSystem().getIdentifier( |
| 86 | "config_icon_mask", "string", "android"); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 87 | |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 88 | /** |
| 89 | * Number of icons per row and column in the workspace. |
| 90 | */ |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 91 | public int numRows; |
| 92 | public int numColumns; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * Number of icons per row and column in the folder. |
| 96 | */ |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 97 | public int numFolderRows; |
| 98 | public int numFolderColumns; |
Sunny Goyal | fc21830 | 2015-09-17 14:59:10 -0700 | [diff] [blame] | 99 | public float iconSize; |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 100 | public String iconShapePath; |
Jon Miranda | b28c4fc | 2017-06-20 10:58:36 -0700 | [diff] [blame] | 101 | public float landscapeIconSize; |
Sunny Goyal | fc21830 | 2015-09-17 14:59:10 -0700 | [diff] [blame] | 102 | public int iconBitmapSize; |
| 103 | public int fillResIconDpi; |
| 104 | public float iconTextSize; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 105 | |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 106 | private SparseArray<TypedValue> mExtraAttrs; |
| 107 | |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 108 | /** |
| 109 | * Number of icons inside the hotseat area. |
| 110 | */ |
Sunny Goyal | f862a26 | 2015-12-14 14:27:38 -0800 | [diff] [blame] | 111 | public int numHotseatIcons; |
Adam Cohen | 2782449 | 2017-09-22 17:10:55 -0700 | [diff] [blame] | 112 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 113 | public int defaultLayoutId; |
Adam Cohen | 2782449 | 2017-09-22 17:10:55 -0700 | [diff] [blame] | 114 | int demoModeLayoutId; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 115 | |
cuijiaxing | abda8d7 | 2017-03-20 09:51:36 -0700 | [diff] [blame] | 116 | public DeviceProfile landscapeProfile; |
| 117 | public DeviceProfile portraitProfile; |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 118 | |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 119 | public Point defaultWallpaperSize; |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 120 | public Rect defaultWidgetPadding; |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 121 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 122 | private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>(); |
| 123 | private ConfigMonitor mConfigMonitor; |
Hyunyoung Song | e11eb47 | 2019-03-19 15:05:21 -0700 | [diff] [blame] | 124 | private OverlayMonitor mOverlayMonitor; |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 125 | |
Sunny Goyal | f633ef5 | 2018-03-13 09:57:05 -0700 | [diff] [blame] | 126 | @VisibleForTesting |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 127 | public InvariantDeviceProfile() {} |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 128 | |
Sunny Goyal | f633ef5 | 2018-03-13 09:57:05 -0700 | [diff] [blame] | 129 | private InvariantDeviceProfile(InvariantDeviceProfile p) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 130 | numRows = p.numRows; |
| 131 | numColumns = p.numColumns; |
| 132 | numFolderRows = p.numFolderRows; |
| 133 | numFolderColumns = p.numFolderColumns; |
| 134 | iconSize = p.iconSize; |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 135 | iconShapePath = p.iconShapePath; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 136 | landscapeIconSize = p.landscapeIconSize; |
| 137 | iconTextSize = p.iconTextSize; |
| 138 | numHotseatIcons = p.numHotseatIcons; |
| 139 | defaultLayoutId = p.defaultLayoutId; |
| 140 | demoModeLayoutId = p.demoModeLayoutId; |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 141 | mExtraAttrs = p.mExtraAttrs; |
Hyunyoung Song | e11eb47 | 2019-03-19 15:05:21 -0700 | [diff] [blame] | 142 | mOverlayMonitor = p.mOverlayMonitor; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Sunny Goyal | bbf0184 | 2015-10-08 07:41:15 -0700 | [diff] [blame] | 145 | @TargetApi(23) |
Sunny Goyal | d0e360a | 2018-06-29 14:40:18 -0700 | [diff] [blame] | 146 | private InvariantDeviceProfile(Context context) { |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 147 | initGrid(context, Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null)); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 148 | mConfigMonitor = new ConfigMonitor(context, |
| 149 | APPLY_CONFIG_AT_RUNTIME.get() ? this::onConfigChanged : this::killProcess); |
Hyunyoung Song | e11eb47 | 2019-03-19 15:05:21 -0700 | [diff] [blame] | 150 | mOverlayMonitor = new OverlayMonitor(context); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Hyunyoung Song | e11eb47 | 2019-03-19 15:05:21 -0700 | [diff] [blame] | 153 | /** |
| 154 | * This constructor should NOT have any monitors by design. |
| 155 | */ |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 156 | public InvariantDeviceProfile(Context context, String gridName) { |
| 157 | String newName = initGrid(context, gridName); |
| 158 | if (newName == null || !newName.equals(gridName)) { |
| 159 | throw new IllegalArgumentException("Unknown grid name"); |
| 160 | } |
| 161 | } |
| 162 | |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 163 | /** |
| 164 | * Retrieve system defined or RRO overriden icon shape. |
| 165 | */ |
| 166 | private static String getIconShapePath(Context context) { |
| 167 | if (CONFIG_ICON_MASK_RES_ID == 0) { |
| 168 | Log.e(TAG, "Icon mask res identifier failed to retrieve."); |
| 169 | return ""; |
| 170 | } |
| 171 | return context.getResources().getString(CONFIG_ICON_MASK_RES_ID); |
| 172 | } |
| 173 | |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 174 | private String initGrid(Context context, String gridName) { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 175 | WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); |
| 176 | Display display = wm.getDefaultDisplay(); |
| 177 | DisplayMetrics dm = new DisplayMetrics(); |
| 178 | display.getMetrics(dm); |
| 179 | |
| 180 | Point smallestSize = new Point(); |
| 181 | Point largestSize = new Point(); |
| 182 | display.getCurrentSizeRange(smallestSize, largestSize); |
| 183 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 184 | ArrayList<DisplayOption> allOptions = getPredefinedDeviceProfiles(context, gridName); |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 185 | // This guarantees that width < height |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 186 | float minWidthDps = Utilities.dpiFromPx(Math.min(smallestSize.x, smallestSize.y), dm); |
| 187 | float minHeightDps = Utilities.dpiFromPx(Math.min(largestSize.x, largestSize.y), dm); |
| 188 | // Sort the profiles based on the closeness to the device size |
Sunny Goyal | 6d55f66 | 2019-01-02 12:13:43 -0800 | [diff] [blame] | 189 | Collections.sort(allOptions, (a, b) -> |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 190 | Float.compare(dist(minWidthDps, minHeightDps, a.minWidthDps, a.minHeightDps), |
| 191 | dist(minWidthDps, minHeightDps, b.minWidthDps, b.minHeightDps))); |
| 192 | DisplayOption interpolatedDisplayOption = |
| 193 | invDistWeightedInterpolate(minWidthDps, minHeightDps, allOptions); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 194 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 195 | GridOption closestProfile = allOptions.get(0).grid; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 196 | numRows = closestProfile.numRows; |
| 197 | numColumns = closestProfile.numColumns; |
| 198 | numHotseatIcons = closestProfile.numHotseatIcons; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 199 | defaultLayoutId = closestProfile.defaultLayoutId; |
Adam Cohen | 2782449 | 2017-09-22 17:10:55 -0700 | [diff] [blame] | 200 | demoModeLayoutId = closestProfile.demoModeLayoutId; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 201 | numFolderRows = closestProfile.numFolderRows; |
| 202 | numFolderColumns = closestProfile.numFolderColumns; |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 203 | mExtraAttrs = closestProfile.extraAttrs; |
| 204 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 205 | if (!closestProfile.name.equals(gridName)) { |
| 206 | Utilities.getPrefs(context).edit() |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 207 | .putString(KEY_IDP_GRID_NAME, closestProfile.name).apply(); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 208 | } |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 209 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 210 | iconSize = interpolatedDisplayOption.iconSize; |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 211 | iconShapePath = getIconShapePath(context); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 212 | landscapeIconSize = interpolatedDisplayOption.landscapeIconSize; |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 213 | iconBitmapSize = Utilities.pxFromDp(iconSize, dm); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 214 | iconTextSize = interpolatedDisplayOption.iconTextSize; |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 215 | fillResIconDpi = getLauncherIconDensity(iconBitmapSize); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 216 | |
| 217 | // If the partner customization apk contains any grid overrides, apply them |
| 218 | // Supported overrides: numRows, numColumns, iconSize |
| 219 | applyPartnerDeviceProfileOverrides(context, dm); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 220 | |
| 221 | Point realSize = new Point(); |
| 222 | display.getRealSize(realSize); |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 223 | // The real size never changes. smallSide and largeSide will remain the |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 224 | // same in any orientation. |
| 225 | int smallSide = Math.min(realSize.x, realSize.y); |
| 226 | int largeSide = Math.max(realSize.x, realSize.y); |
| 227 | |
| 228 | landscapeProfile = new DeviceProfile(context, this, smallestSize, largestSize, |
Sunny Goyal | d70e75a | 2018-02-22 10:07:32 -0800 | [diff] [blame] | 229 | largeSide, smallSide, true /* isLandscape */, false /* isMultiWindowMode */); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 230 | portraitProfile = new DeviceProfile(context, this, smallestSize, largestSize, |
Sunny Goyal | d70e75a | 2018-02-22 10:07:32 -0800 | [diff] [blame] | 231 | smallSide, largeSide, false /* isLandscape */, false /* isMultiWindowMode */); |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 232 | |
| 233 | // We need to ensure that there is enough extra space in the wallpaper |
| 234 | // for the intended parallax effects |
| 235 | if (context.getResources().getConfiguration().smallestScreenWidthDp >= 720) { |
| 236 | defaultWallpaperSize = new Point( |
| 237 | (int) (largeSide * wallpaperTravelToScreenWidthRatio(largeSide, smallSide)), |
| 238 | largeSide); |
| 239 | } else { |
| 240 | defaultWallpaperSize = new Point(Math.max(smallSide * 2, largeSide), largeSide); |
| 241 | } |
Sunny Goyal | 58fa4b6 | 2019-03-22 16:23:25 -0700 | [diff] [blame] | 242 | |
| 243 | ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName()); |
| 244 | defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null); |
| 245 | |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 246 | return closestProfile.name; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 249 | @Nullable |
| 250 | public TypedValue getAttrValue(int attr) { |
| 251 | return mExtraAttrs == null ? null : mExtraAttrs.get(attr); |
| 252 | } |
| 253 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 254 | public void addOnChangeListener(OnIDPChangeListener listener) { |
| 255 | mChangeListeners.add(listener); |
| 256 | } |
| 257 | |
Hyunyoung Song | b4d1ca4 | 2019-01-08 17:15:16 -0800 | [diff] [blame] | 258 | public void removeOnChangeListener(OnIDPChangeListener listener) { |
| 259 | mChangeListeners.remove(listener); |
| 260 | } |
| 261 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 262 | private void killProcess(Context context) { |
| 263 | Log.e("ConfigMonitor", "restarting launcher"); |
| 264 | android.os.Process.killProcess(android.os.Process.myPid()); |
| 265 | } |
| 266 | |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 267 | public void verifyConfigChangedInBackground(final Context context) { |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 268 | String savedIconMaskPath = getDevicePrefs(context).getString(KEY_ICON_PATH_REF, ""); |
| 269 | // Good place to check if grid size changed in themepicker when launcher was dead. |
| 270 | if (savedIconMaskPath.isEmpty()) { |
| 271 | getDevicePrefs(context).edit().putString(KEY_ICON_PATH_REF, getIconShapePath(context)) |
| 272 | .apply(); |
| 273 | } else if (!savedIconMaskPath.equals(getIconShapePath(context))) { |
| 274 | getDevicePrefs(context).edit().putString(KEY_ICON_PATH_REF, getIconShapePath(context)) |
| 275 | .apply(); |
| 276 | apply(context, CHANGE_FLAG_ICON_PARAMS); |
| 277 | } |
| 278 | } |
| 279 | |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 280 | public void setCurrentGrid(Context context, String gridName) { |
| 281 | Context appContext = context.getApplicationContext(); |
| 282 | Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply(); |
| 283 | new MainThreadExecutor().execute(() -> onConfigChanged(appContext)); |
| 284 | } |
| 285 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 286 | private void onConfigChanged(Context context) { |
| 287 | // Config changes, what shall we do? |
| 288 | InvariantDeviceProfile oldProfile = new InvariantDeviceProfile(this); |
| 289 | |
| 290 | // Re-init grid |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 291 | initGrid(context, Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null)); |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 292 | |
| 293 | int changeFlags = 0; |
| 294 | if (numRows != oldProfile.numRows || |
| 295 | numColumns != oldProfile.numColumns || |
| 296 | numFolderColumns != oldProfile.numFolderColumns || |
| 297 | numFolderRows != oldProfile.numFolderRows || |
| 298 | numHotseatIcons != oldProfile.numHotseatIcons) { |
| 299 | changeFlags |= CHANGE_FLAG_GRID; |
| 300 | } |
| 301 | |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 302 | if (iconSize != oldProfile.iconSize || iconBitmapSize != oldProfile.iconBitmapSize || |
| 303 | !iconShapePath.equals(oldProfile.iconShapePath)) { |
| 304 | changeFlags |= CHANGE_FLAG_ICON_PARAMS; |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 305 | } |
Sunny Goyal | 90e3fbc | 2019-01-23 16:42:43 -0800 | [diff] [blame] | 306 | if (!iconShapePath.equals(oldProfile.iconShapePath)) { |
| 307 | FolderShape.init(context); |
| 308 | } |
| 309 | |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 310 | apply(context, changeFlags); |
| 311 | } |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 312 | |
Hyunyoung Song | c55a350 | 2018-12-04 15:43:16 -0800 | [diff] [blame] | 313 | private void apply(Context context, int changeFlags) { |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 314 | // Create a new config monitor |
| 315 | mConfigMonitor.unregister(); |
| 316 | mConfigMonitor = new ConfigMonitor(context, this::onConfigChanged); |
| 317 | |
| 318 | for (OnIDPChangeListener listener : mChangeListeners) { |
| 319 | listener.onIdpChanged(changeFlags, this); |
| 320 | } |
| 321 | } |
| 322 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 323 | static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context, String gridName) { |
| 324 | ArrayList<DisplayOption> profiles = new ArrayList<>(); |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 325 | try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) { |
| 326 | final int depth = parser.getDepth(); |
| 327 | int type; |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 328 | while (((type = parser.next()) != XmlPullParser.END_TAG || |
| 329 | parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 330 | if ((type == XmlPullParser.START_TAG) |
| 331 | && GridOption.TAG_NAME.equals(parser.getName())) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 332 | |
| 333 | GridOption gridOption = new GridOption(context, Xml.asAttributeSet(parser)); |
| 334 | final int displayDepth = parser.getDepth(); |
| 335 | while (((type = parser.next()) != XmlPullParser.END_TAG || |
| 336 | parser.getDepth() > displayDepth) |
| 337 | && type != XmlPullParser.END_DOCUMENT) { |
| 338 | if ((type == XmlPullParser.START_TAG) && "display-option".equals( |
| 339 | parser.getName())) { |
| 340 | profiles.add(new DisplayOption( |
| 341 | gridOption, context, Xml.asAttributeSet(parser))); |
| 342 | } |
| 343 | } |
Sunny Goyal | 819e193 | 2016-07-07 16:43:58 -0700 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | } catch (IOException|XmlPullParserException e) { |
| 347 | throw new RuntimeException(e); |
| 348 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 349 | |
| 350 | ArrayList<DisplayOption> filteredProfiles = new ArrayList<>(); |
| 351 | if (!TextUtils.isEmpty(gridName)) { |
| 352 | for (DisplayOption option : profiles) { |
| 353 | if (gridName.equals(option.grid.name)) { |
| 354 | filteredProfiles.add(option); |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | if (filteredProfiles.isEmpty()) { |
| 359 | // No grid found, use the default options |
| 360 | for (DisplayOption option : profiles) { |
| 361 | if (option.canBeDefault) { |
| 362 | filteredProfiles.add(option); |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 | if (filteredProfiles.isEmpty()) { |
| 367 | throw new RuntimeException("No display option with canBeDefault=true"); |
| 368 | } |
| 369 | return filteredProfiles; |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Sunny Goyal | 53d7ee4 | 2015-05-22 12:25:45 -0700 | [diff] [blame] | 372 | private int getLauncherIconDensity(int requiredSize) { |
| 373 | // Densities typically defined by an app. |
| 374 | int[] densityBuckets = new int[] { |
| 375 | DisplayMetrics.DENSITY_LOW, |
| 376 | DisplayMetrics.DENSITY_MEDIUM, |
| 377 | DisplayMetrics.DENSITY_TV, |
| 378 | DisplayMetrics.DENSITY_HIGH, |
| 379 | DisplayMetrics.DENSITY_XHIGH, |
| 380 | DisplayMetrics.DENSITY_XXHIGH, |
| 381 | DisplayMetrics.DENSITY_XXXHIGH |
| 382 | }; |
| 383 | |
| 384 | int density = DisplayMetrics.DENSITY_XXXHIGH; |
| 385 | for (int i = densityBuckets.length - 1; i >= 0; i--) { |
| 386 | float expectedSize = ICON_SIZE_DEFINED_IN_APP_DP * densityBuckets[i] |
| 387 | / DisplayMetrics.DENSITY_DEFAULT; |
| 388 | if (expectedSize >= requiredSize) { |
| 389 | density = densityBuckets[i]; |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | return density; |
| 394 | } |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 395 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 396 | /** |
| 397 | * Apply any Partner customization grid overrides. |
| 398 | * |
| 399 | * Currently we support: all apps row / column count. |
| 400 | */ |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 401 | private void applyPartnerDeviceProfileOverrides(Context context, DisplayMetrics dm) { |
| 402 | Partner p = Partner.get(context.getPackageManager()); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 403 | if (p != null) { |
| 404 | p.applyInvariantDeviceProfileOverrides(this, dm); |
| 405 | } |
| 406 | } |
| 407 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 408 | private static float dist(float x0, float y0, float x1, float y1) { |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 409 | return (float) Math.hypot(x1 - x0, y1 - y0); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 412 | @VisibleForTesting |
| 413 | static DisplayOption invDistWeightedInterpolate(float width, float height, |
| 414 | ArrayList<DisplayOption> points) { |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 415 | float weights = 0; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 416 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 417 | DisplayOption p = points.get(0); |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 418 | if (dist(width, height, p.minWidthDps, p.minHeightDps) == 0) { |
| 419 | return p; |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 422 | DisplayOption out = new DisplayOption(); |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 423 | for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 424 | p = points.get(i); |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 425 | float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER); |
| 426 | weights += w; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 427 | out.add(new DisplayOption().add(p).multiply(w)); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 428 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 429 | return out.multiply(1.0f / weights); |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Sunny Goyal | 2783595 | 2017-01-13 12:15:53 -0800 | [diff] [blame] | 432 | public DeviceProfile getDeviceProfile(Context context) { |
| 433 | return context.getResources().getConfiguration().orientation |
| 434 | == Configuration.ORIENTATION_LANDSCAPE ? landscapeProfile : portraitProfile; |
| 435 | } |
| 436 | |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 437 | 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] | 438 | float d = dist(x0, y0, x1, y1); |
| 439 | if (Float.compare(d, 0f) == 0) { |
| 440 | return Float.POSITIVE_INFINITY; |
| 441 | } |
| 442 | return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow)); |
| 443 | } |
Sunny Goyal | 6f86609 | 2016-03-17 17:04:15 -0700 | [diff] [blame] | 444 | |
| 445 | /** |
| 446 | * As a ratio of screen height, the total distance we want the parallax effect to span |
| 447 | * horizontally |
| 448 | */ |
| 449 | private static float wallpaperTravelToScreenWidthRatio(int width, int height) { |
| 450 | float aspectRatio = width / (float) height; |
| 451 | |
| 452 | // At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width |
| 453 | // At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width |
| 454 | // We will use these two data points to extrapolate how much the wallpaper parallax effect |
| 455 | // to span (ie travel) at any aspect ratio: |
| 456 | |
| 457 | final float ASPECT_RATIO_LANDSCAPE = 16/10f; |
| 458 | final float ASPECT_RATIO_PORTRAIT = 10/16f; |
| 459 | final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f; |
| 460 | final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f; |
| 461 | |
| 462 | // To find out the desired width at different aspect ratios, we use the following two |
| 463 | // formulas, where the coefficient on x is the aspect ratio (width/height): |
| 464 | // (16/10)x + y = 1.5 |
| 465 | // (10/16)x + y = 1.2 |
| 466 | // We solve for x and y and end up with a final formula: |
| 467 | final float x = |
| 468 | (WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) / |
| 469 | (ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT); |
| 470 | final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT; |
| 471 | return x * aspectRatio + y; |
| 472 | } |
| 473 | |
Sunny Goyal | 87dc48b | 2018-10-12 11:42:33 -0700 | [diff] [blame] | 474 | public interface OnIDPChangeListener { |
| 475 | |
| 476 | void onIdpChanged(int changeFlags, InvariantDeviceProfile profile); |
| 477 | } |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 478 | |
| 479 | |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 480 | public static final class GridOption { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 481 | |
Sunny Goyal | 7d892ff | 2019-01-11 15:08:44 -0800 | [diff] [blame] | 482 | public static final String TAG_NAME = "grid-option"; |
| 483 | |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 484 | public final String name; |
| 485 | public final int numRows; |
| 486 | public final int numColumns; |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 487 | |
| 488 | private final int numFolderRows; |
| 489 | private final int numFolderColumns; |
| 490 | |
| 491 | private final int numHotseatIcons; |
| 492 | |
| 493 | private final int defaultLayoutId; |
| 494 | private final int demoModeLayoutId; |
| 495 | |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 496 | private final SparseArray<TypedValue> extraAttrs; |
| 497 | |
Sunny Goyal | eff44f3 | 2019-01-09 17:29:49 -0800 | [diff] [blame] | 498 | public GridOption(Context context, AttributeSet attrs) { |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 499 | TypedArray a = context.obtainStyledAttributes( |
| 500 | attrs, R.styleable.GridDisplayOption); |
| 501 | name = a.getString(R.styleable.GridDisplayOption_name); |
| 502 | numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0); |
| 503 | numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0); |
| 504 | |
| 505 | defaultLayoutId = a.getResourceId( |
| 506 | R.styleable.GridDisplayOption_defaultLayoutId, 0); |
| 507 | demoModeLayoutId = a.getResourceId( |
| 508 | R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId); |
| 509 | numHotseatIcons = a.getInt( |
| 510 | R.styleable.GridDisplayOption_numHotseatIcons, numColumns); |
| 511 | numFolderRows = a.getInt( |
| 512 | R.styleable.GridDisplayOption_numFolderRows, numRows); |
| 513 | numFolderColumns = a.getInt( |
| 514 | R.styleable.GridDisplayOption_numFolderColumns, numColumns); |
| 515 | a.recycle(); |
Sunny Goyal | 5bc1846 | 2019-01-07 15:13:39 -0800 | [diff] [blame] | 516 | |
| 517 | extraAttrs = Themes.createValueMap(context, attrs, |
| 518 | IntArray.wrap(R.styleable.GridDisplayOption)); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 519 | } |
| 520 | } |
| 521 | |
| 522 | private static final class DisplayOption { |
| 523 | private final GridOption grid; |
| 524 | |
| 525 | private final String name; |
| 526 | private final float minWidthDps; |
| 527 | private final float minHeightDps; |
| 528 | private final boolean canBeDefault; |
| 529 | |
| 530 | private float iconSize; |
| 531 | private float landscapeIconSize; |
| 532 | private float iconTextSize; |
| 533 | |
| 534 | DisplayOption(GridOption grid, Context context, AttributeSet attrs) { |
| 535 | this.grid = grid; |
| 536 | |
| 537 | TypedArray a = context.obtainStyledAttributes( |
| 538 | attrs, R.styleable.ProfileDisplayOption); |
| 539 | |
| 540 | name = a.getString(R.styleable.ProfileDisplayOption_name); |
| 541 | minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0); |
| 542 | minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0); |
| 543 | canBeDefault = a.getBoolean( |
| 544 | R.styleable.ProfileDisplayOption_canBeDefault, false); |
| 545 | |
Ryan Mitchell | 01b8b68 | 2019-03-28 17:01:07 -0700 | [diff] [blame^] | 546 | iconSize = a.getFloat(R.styleable.ProfileDisplayOption_iconImageSize, 0); |
Sunny Goyal | 415f173 | 2018-11-29 10:33:47 -0800 | [diff] [blame] | 547 | landscapeIconSize = a.getFloat(R.styleable.ProfileDisplayOption_landscapeIconSize, |
| 548 | iconSize); |
| 549 | iconTextSize = a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0); |
| 550 | a.recycle(); |
| 551 | } |
| 552 | |
| 553 | DisplayOption() { |
| 554 | grid = null; |
| 555 | name = null; |
| 556 | minWidthDps = 0; |
| 557 | minHeightDps = 0; |
| 558 | canBeDefault = false; |
| 559 | } |
| 560 | |
| 561 | private DisplayOption multiply(float w) { |
| 562 | iconSize *= w; |
| 563 | landscapeIconSize *= w; |
| 564 | iconTextSize *= w; |
| 565 | return this; |
| 566 | } |
| 567 | |
| 568 | private DisplayOption add(DisplayOption p) { |
| 569 | iconSize += p.iconSize; |
| 570 | landscapeIconSize += p.landscapeIconSize; |
| 571 | iconTextSize += p.iconTextSize; |
| 572 | return this; |
| 573 | } |
| 574 | } |
Hyunyoung Song | e11eb47 | 2019-03-19 15:05:21 -0700 | [diff] [blame] | 575 | |
| 576 | private class OverlayMonitor extends BroadcastReceiver { |
| 577 | |
| 578 | private final String ACTION_OVERLAY_CHANGED = "android.intent.action.OVERLAY_CHANGED"; |
| 579 | |
| 580 | OverlayMonitor(Context context) { |
Sunny Goyal | 8b0cb41 | 2019-04-22 09:01:26 -0700 | [diff] [blame] | 581 | context.registerReceiver(this, getPackageFilter("android", ACTION_OVERLAY_CHANGED)); |
Hyunyoung Song | e11eb47 | 2019-03-19 15:05:21 -0700 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | @Override |
| 585 | public void onReceive(Context context, Intent intent) { |
| 586 | onConfigChanged(context); |
| 587 | } |
| 588 | } |
Hyunyoung Song | 35c3c7f | 2015-05-28 15:33:40 -0700 | [diff] [blame] | 589 | } |