WallpaperManagerCompat should target correct platform
Also replace Utilities.isAtLeastO() to static final constant. Bug: 65544683 Change-Id: I39fbea66939d72c31702748716c4e65b4f9bee6a
This commit is contained in:
parent
9c1607886b
commit
e24cb63b81
|
@ -123,7 +123,7 @@ public class IconCache {
|
|||
}
|
||||
|
||||
private Drawable getFullResDefaultActivityIcon() {
|
||||
return getFullResIcon(Resources.getSystem(), Utilities.isAtLeastO() ?
|
||||
return getFullResIcon(Resources.getSystem(), Utilities.ATLEAST_OREO ?
|
||||
android.R.drawable.sym_def_app_icon : android.R.mipmap.sym_def_app_icon);
|
||||
}
|
||||
|
||||
|
|
|
@ -1132,7 +1132,7 @@ public class Launcher extends BaseActivity
|
|||
// On O and above we there is always some setting present settings (add icon to
|
||||
// home screen or icon badging). On earlier APIs we will have the allow rotation
|
||||
// setting, on devices with a locked orientation,
|
||||
return Utilities.isAtLeastO() || !getResources().getBoolean(R.bool.allow_rotation);
|
||||
return Utilities.ATLEAST_OREO || !getResources().getBoolean(R.bool.allow_rotation);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1414,7 +1414,7 @@ public class Launcher extends BaseActivity
|
|||
CellLayout layout = getCellLayout(container, screenId);
|
||||
|
||||
ShortcutInfo info = null;
|
||||
if (Utilities.isAtLeastO()) {
|
||||
if (Utilities.ATLEAST_OREO) {
|
||||
info = LauncherAppsCompatVO.createShortcutInfoFromPinItemRequest(
|
||||
this, LauncherAppsCompatVO.getPinItemRequest(data), 0);
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ public class LauncherAppWidgetHostView extends AppWidgetHostView
|
|||
setAccessibilityDelegate(Launcher.getLauncher(context).getAccessibilityDelegate());
|
||||
setBackgroundResource(R.drawable.widget_internal_focus_bg);
|
||||
|
||||
if (Utilities.isAtLeastO()) {
|
||||
if (Utilities.ATLEAST_OREO) {
|
||||
setExecutor(Utilities.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ public class SessionCommitReceiver extends BroadcastReceiver {
|
|||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (!isEnabled(context) || !Utilities.isAtLeastO()) {
|
||||
if (!isEnabled(context) || !Utilities.ATLEAST_OREO) {
|
||||
// User has decided to not add icons on homescreen.
|
||||
return;
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ public class SessionCommitReceiver extends BroadcastReceiver {
|
|||
}
|
||||
|
||||
public static void applyDefaultUserPrefs(final Context context) {
|
||||
if (!Utilities.isAtLeastO()) {
|
||||
if (!Utilities.ATLEAST_OREO) {
|
||||
return;
|
||||
}
|
||||
SharedPreferences prefs = Utilities.getPrefs(context);
|
||||
|
|
|
@ -94,7 +94,7 @@ public class SettingsActivity extends Activity {
|
|||
|
||||
ButtonPreference iconBadgingPref =
|
||||
(ButtonPreference) findPreference(ICON_BADGING_PREFERENCE_KEY);
|
||||
if (!Utilities.isAtLeastO()) {
|
||||
if (!Utilities.ATLEAST_OREO) {
|
||||
getPreferenceScreen().removePreference(
|
||||
findPreference(SessionCommitReceiver.ADD_ICON_PREFERENCE_KEY));
|
||||
getPreferenceScreen().removePreference(iconBadgingPref);
|
||||
|
|
|
@ -83,15 +83,17 @@ public final class Utilities {
|
|||
private static final Matrix sMatrix = new Matrix();
|
||||
private static final Matrix sInverseMatrix = new Matrix();
|
||||
|
||||
public static boolean isAtLeastO() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
|
||||
}
|
||||
public static final boolean ATLEAST_OREO_MR1 =
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1;
|
||||
|
||||
public static final boolean ATLEAST_OREO =
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
|
||||
|
||||
public static final boolean ATLEAST_NOUGAT_MR1 =
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1;
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1;
|
||||
|
||||
public static final boolean ATLEAST_NOUGAT =
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.N;
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.N;
|
||||
|
||||
public static final boolean ATLEAST_MARSHMALLOW =
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
|
||||
|
|
|
@ -40,7 +40,7 @@ public abstract class AppWidgetManagerCompat {
|
|||
public static AppWidgetManagerCompat getInstance(Context context) {
|
||||
synchronized (sInstanceLock) {
|
||||
if (sInstance == null) {
|
||||
if (Utilities.isAtLeastO()) {
|
||||
if (Utilities.ATLEAST_OREO) {
|
||||
sInstance = new AppWidgetManagerCompatVO(context.getApplicationContext());
|
||||
} else {
|
||||
sInstance = new AppWidgetManagerCompatVL(context.getApplicationContext());
|
||||
|
|
|
@ -53,7 +53,7 @@ public abstract class LauncherAppsCompat {
|
|||
public static LauncherAppsCompat getInstance(Context context) {
|
||||
synchronized (sInstanceLock) {
|
||||
if (sInstance == null) {
|
||||
if (Utilities.isAtLeastO()) {
|
||||
if (Utilities.ATLEAST_OREO) {
|
||||
sInstance = new LauncherAppsCompatVO(context.getApplicationContext());
|
||||
} else {
|
||||
sInstance = new LauncherAppsCompatVL(context.getApplicationContext());
|
||||
|
|
|
@ -31,10 +31,10 @@ public abstract class WallpaperManagerCompat {
|
|||
if (sInstance == null) {
|
||||
context = context.getApplicationContext();
|
||||
|
||||
if (Utilities.isAtLeastO()) {
|
||||
if (Utilities.ATLEAST_OREO) {
|
||||
try {
|
||||
sInstance = new WallpaperManagerCompatVOMR1(context);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
// The wallpaper APIs do not yet exist
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,8 +35,9 @@ public class WallpaperManagerCompatVOMR1 extends WallpaperManagerCompat {
|
|||
private final WallpaperManager mWm;
|
||||
private Method mWCColorHintsMethod;
|
||||
|
||||
WallpaperManagerCompatVOMR1(Context context) throws Exception {
|
||||
WallpaperManagerCompatVOMR1(Context context) throws Throwable {
|
||||
mWm = context.getSystemService(WallpaperManager.class);
|
||||
String className = WallpaperColors.class.getName();
|
||||
try {
|
||||
mWCColorHintsMethod = WallpaperColors.class.getDeclaredMethod("getColorHints");
|
||||
} catch (Exception exc) {
|
||||
|
|
|
@ -193,7 +193,7 @@ public class DragView extends View {
|
|||
*/
|
||||
@TargetApi(Build.VERSION_CODES.O)
|
||||
public void setItemInfo(final ItemInfo info) {
|
||||
if (!(FeatureFlags.LAUNCHER3_SPRING_ICONS && Utilities.isAtLeastO())) {
|
||||
if (!(FeatureFlags.LAUNCHER3_SPRING_ICONS && Utilities.ATLEAST_OREO)) {
|
||||
return;
|
||||
}
|
||||
if (info.itemType != LauncherSettings.Favorites.ITEM_TYPE_APPLICATION &&
|
||||
|
|
|
@ -128,7 +128,7 @@ public class PinItemDragListener extends BaseItemDragListener implements Parcela
|
|||
}
|
||||
|
||||
public static boolean handleDragRequest(Launcher launcher, Intent intent) {
|
||||
if (!Utilities.isAtLeastO()) {
|
||||
if (!Utilities.ATLEAST_OREO) {
|
||||
return false;
|
||||
}
|
||||
if (intent == null || !Intent.ACTION_MAIN.equals(intent.getAction())) {
|
||||
|
|
|
@ -80,7 +80,7 @@ public class DrawableFactory {
|
|||
|
||||
|
||||
protected Path getPreloadProgressPath(Context context) {
|
||||
if (Utilities.isAtLeastO()) {
|
||||
if (Utilities.ATLEAST_OREO) {
|
||||
try {
|
||||
// Try to load the path from Mask Icon
|
||||
Drawable icon = context.getDrawable(R.drawable.adaptive_icon_drawable_wrapper);
|
||||
|
|
|
@ -231,7 +231,7 @@ public class IconNormalizer {
|
|||
*/
|
||||
public synchronized float getScale(@NonNull Drawable d, @Nullable RectF outBounds,
|
||||
@Nullable Path path, @Nullable boolean[] outMaskShape) {
|
||||
if (Utilities.isAtLeastO() && d instanceof AdaptiveIconDrawable &&
|
||||
if (Utilities.ATLEAST_OREO && d instanceof AdaptiveIconDrawable &&
|
||||
mAdaptiveIconScale != SCALE_NOT_INITIALIZED) {
|
||||
if (outBounds != null) {
|
||||
outBounds.set(mAdaptiveIconBounds);
|
||||
|
@ -347,7 +347,7 @@ public class IconNormalizer {
|
|||
float areaScale = area / (width * height);
|
||||
// Use sqrt of the final ratio as the images is scaled across both width and height.
|
||||
float scale = areaScale > scaleRequired ? (float) Math.sqrt(scaleRequired / areaScale) : 1;
|
||||
if (Utilities.isAtLeastO() && d instanceof AdaptiveIconDrawable &&
|
||||
if (Utilities.ATLEAST_OREO && d instanceof AdaptiveIconDrawable &&
|
||||
mAdaptiveIconScale == SCALE_NOT_INITIALIZED) {
|
||||
mAdaptiveIconScale = scale;
|
||||
mAdaptiveIconBounds.set(mBounds);
|
||||
|
|
|
@ -59,7 +59,7 @@ public class IconShapeOverride {
|
|||
private static final int RESTART_REQUEST_CODE = 42; // the answer to everything
|
||||
|
||||
public static boolean isSupported(Context context) {
|
||||
if (!Utilities.isAtLeastO()) {
|
||||
if (!Utilities.ATLEAST_OREO) {
|
||||
return false;
|
||||
}
|
||||
// Only supported when developer settings is enabled
|
||||
|
@ -82,7 +82,7 @@ public class IconShapeOverride {
|
|||
}
|
||||
|
||||
public static void apply(Context context) {
|
||||
if (!Utilities.isAtLeastO()) {
|
||||
if (!Utilities.ATLEAST_OREO) {
|
||||
return;
|
||||
}
|
||||
String path = getAppliedValue(context);
|
||||
|
|
|
@ -104,7 +104,7 @@ public class LauncherIcons {
|
|||
float scale = 1f;
|
||||
if (!FeatureFlags.LAUNCHER3_DISABLE_ICON_NORMALIZATION) {
|
||||
normalizer = IconNormalizer.getInstance(context);
|
||||
if (Utilities.isAtLeastO() && iconAppTargetSdk >= Build.VERSION_CODES.O) {
|
||||
if (Utilities.ATLEAST_OREO && iconAppTargetSdk >= Build.VERSION_CODES.O) {
|
||||
boolean[] outShape = new boolean[1];
|
||||
AdaptiveIconDrawable dr = (AdaptiveIconDrawable)
|
||||
context.getDrawable(R.drawable.adaptive_icon_drawable_wrapper).mutate();
|
||||
|
@ -123,7 +123,7 @@ public class LauncherIcons {
|
|||
}
|
||||
}
|
||||
Bitmap bitmap = createIconBitmap(icon, context, scale);
|
||||
if (FeatureFlags.ADAPTIVE_ICON_SHADOW && Utilities.isAtLeastO() &&
|
||||
if (FeatureFlags.ADAPTIVE_ICON_SHADOW && Utilities.ATLEAST_OREO &&
|
||||
icon instanceof AdaptiveIconDrawable) {
|
||||
bitmap = ShadowGenerator.getInstance(context).recreateIcon(bitmap);
|
||||
}
|
||||
|
@ -158,13 +158,13 @@ public class LauncherIcons {
|
|||
float scale = 1f;
|
||||
if (!FeatureFlags.LAUNCHER3_DISABLE_ICON_NORMALIZATION) {
|
||||
normalizer = IconNormalizer.getInstance(context);
|
||||
if (Utilities.isAtLeastO() && iconAppTargetSdk >= Build.VERSION_CODES.O) {
|
||||
if (Utilities.ATLEAST_OREO && iconAppTargetSdk >= Build.VERSION_CODES.O) {
|
||||
boolean[] outShape = new boolean[1];
|
||||
AdaptiveIconDrawable dr = (AdaptiveIconDrawable)
|
||||
context.getDrawable(R.drawable.adaptive_icon_drawable_wrapper).mutate();
|
||||
dr.setBounds(0, 0, 1, 1);
|
||||
scale = normalizer.getScale(icon, iconBounds, dr.getIconMask(), outShape);
|
||||
if (Utilities.isAtLeastO() && FeatureFlags.LEGACY_ICON_TREATMENT &&
|
||||
if (Utilities.ATLEAST_OREO && FeatureFlags.LEGACY_ICON_TREATMENT &&
|
||||
!outShape[0]) {
|
||||
Drawable wrappedIcon = wrapToAdaptiveIconDrawable(context, icon, scale);
|
||||
if (wrappedIcon != icon) {
|
||||
|
@ -213,12 +213,12 @@ public class LauncherIcons {
|
|||
*/
|
||||
public static Bitmap createIconBitmap(Drawable icon, Context context) {
|
||||
float scale = 1f;
|
||||
if (FeatureFlags.ADAPTIVE_ICON_SHADOW && Utilities.isAtLeastO() &&
|
||||
if (FeatureFlags.ADAPTIVE_ICON_SHADOW && Utilities.ATLEAST_OREO &&
|
||||
icon instanceof AdaptiveIconDrawable) {
|
||||
scale = ShadowGenerator.getScaleForBounds(new RectF(0, 0, 0, 0));
|
||||
}
|
||||
Bitmap bitmap = createIconBitmap(icon, context, scale);
|
||||
if (FeatureFlags.ADAPTIVE_ICON_SHADOW && Utilities.isAtLeastO() &&
|
||||
if (FeatureFlags.ADAPTIVE_ICON_SHADOW && Utilities.ATLEAST_OREO &&
|
||||
icon instanceof AdaptiveIconDrawable) {
|
||||
bitmap = ShadowGenerator.getInstance(context).recreateIcon(bitmap);
|
||||
}
|
||||
|
@ -271,7 +271,7 @@ public class LauncherIcons {
|
|||
final int top = (textureHeight-height) / 2;
|
||||
|
||||
sOldBounds.set(icon.getBounds());
|
||||
if (Utilities.isAtLeastO() && icon instanceof AdaptiveIconDrawable) {
|
||||
if (Utilities.ATLEAST_OREO && icon instanceof AdaptiveIconDrawable) {
|
||||
int offset = Math.max((int)(ShadowGenerator.BLUR_FACTOR * iconBitmapSize),
|
||||
Math.min(left, top));
|
||||
int size = Math.max(width, height);
|
||||
|
@ -296,7 +296,7 @@ public class LauncherIcons {
|
|||
* create AdaptiveIconDrawable.
|
||||
*/
|
||||
static Drawable wrapToAdaptiveIconDrawable(Context context, Drawable drawable, float scale) {
|
||||
if (!(FeatureFlags.LEGACY_ICON_TREATMENT && Utilities.isAtLeastO())) {
|
||||
if (!(FeatureFlags.LEGACY_ICON_TREATMENT && Utilities.ATLEAST_OREO)) {
|
||||
return drawable;
|
||||
}
|
||||
|
||||
|
|
|
@ -146,7 +146,7 @@ public class ShadowDrawable extends Drawable {
|
|||
d.draw(canvas);
|
||||
}
|
||||
|
||||
if (Utilities.isAtLeastO()) {
|
||||
if (Utilities.ATLEAST_OREO) {
|
||||
bitmap = bitmap.copy(Bitmap.Config.HARDWARE, false);
|
||||
}
|
||||
mState.mLastDrawnBitmap = bitmap;
|
||||
|
|
|
@ -101,7 +101,7 @@ public class PackageUpdatedTask extends BaseModelUpdateTask {
|
|||
appsList.addPackage(context, packages[i], mUser);
|
||||
|
||||
// Automatically add homescreen icon for work profile apps for below O device.
|
||||
if (!Utilities.isAtLeastO() && !Process.myUserHandle().equals(mUser)) {
|
||||
if (!Utilities.ATLEAST_OREO && !Process.myUserHandle().equals(mUser)) {
|
||||
SessionCommitReceiver.queueAppIconAddition(context, packages[i], mUser);
|
||||
}
|
||||
}
|
||||
|
@ -342,7 +342,7 @@ public class PackageUpdatedTask extends BaseModelUpdateTask {
|
|||
callbacks.notifyWidgetProvidersChanged();
|
||||
}
|
||||
});
|
||||
} else if (Utilities.isAtLeastO() && mOp == OP_ADD) {
|
||||
} else if (Utilities.ATLEAST_OREO && mOp == OP_ADD) {
|
||||
// Load widgets for the new package.
|
||||
for (int i = 0; i < N; i++) {
|
||||
dataModel.widgetsModel.update(app, new PackageUserKey(packages[i], mUser));
|
||||
|
|
|
@ -67,7 +67,7 @@ public class ManagedProfileHeuristic {
|
|||
return;
|
||||
}
|
||||
|
||||
if (Utilities.isAtLeastO() && !SessionCommitReceiver.isEnabled(context)) {
|
||||
if (Utilities.ATLEAST_OREO && !SessionCommitReceiver.isEnabled(context)) {
|
||||
// Just mark the folder id preference to avoid new folder creation later.
|
||||
ufi.prefs.edit().putLong(ufi.folderIdKey, ItemInfo.NO_ID).apply();
|
||||
return;
|
||||
|
|
|
@ -59,7 +59,7 @@ public class SystemUiController {
|
|||
// Apply the state flags in priority order
|
||||
int newFlags = oldFlags;
|
||||
for (int stateFlag : mStates) {
|
||||
if (Utilities.isAtLeastO()) {
|
||||
if (Utilities.ATLEAST_OREO) {
|
||||
if ((stateFlag & FLAG_LIGHT_NAV) != 0) {
|
||||
newFlags |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
|
||||
} else if ((stateFlag & FLAG_DARK_NAV) != 0) {
|
||||
|
|
|
@ -141,7 +141,7 @@ public class RequestPinItemTest extends AbstractLauncherUiTest {
|
|||
|
||||
private void runTest(String activityMethod, boolean isWidget, ItemOperator itemMatcher,
|
||||
Intent... commandIntents) throws Throwable {
|
||||
if (!Utilities.isAtLeastO()) {
|
||||
if (!Utilities.ATLEAST_OREO) {
|
||||
return;
|
||||
}
|
||||
lockRotation(true);
|
||||
|
|
Loading…
Reference in New Issue