summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario Bertschler <bmario@google.com>2017-09-05 21:51:22 (GMT)
committerMario Bertschler <bmario@google.com>2017-09-05 21:58:30 (GMT)
commitaeed7f24f22555893c34a901fac7e7262b436347 (patch)
treeab8a95cd2f3b97a43fb1098bec9bd061b34b3273
parent94b02ad8882f971e89cca12f8abfb1931b2e77dc (diff)
downloadandroid_packages_apps_Trebuchet-aeed7f24f22555893c34a901fac7e7262b436347.zip
android_packages_apps_Trebuchet-aeed7f24f22555893c34a901fac7e7262b436347.tar.gz
android_packages_apps_Trebuchet-aeed7f24f22555893c34a901fac7e7262b436347.tar.bz2
Remove reflection from wallpaper manager for wallpaper colors.
Bug: 65016704 Change-Id: I36bac7a3cd9cd4911657e693a424c9960cb9d042
-rw-r--r--src/com/android/launcher3/compat/WallpaperManagerCompatVOMR1.java81
1 files changed, 25 insertions, 56 deletions
diff --git a/src/com/android/launcher3/compat/WallpaperManagerCompatVOMR1.java b/src/com/android/launcher3/compat/WallpaperManagerCompatVOMR1.java
index fe5ff2a..4787514 100644
--- a/src/com/android/launcher3/compat/WallpaperManagerCompatVOMR1.java
+++ b/src/com/android/launcher3/compat/WallpaperManagerCompatVOMR1.java
@@ -16,96 +16,65 @@
package com.android.launcher3.compat;
import android.annotation.TargetApi;
+import android.app.WallpaperColors;
import android.app.WallpaperManager;
+import android.app.WallpaperManager.OnColorsChangedListener;
import android.content.Context;
import android.graphics.Color;
-import android.os.Build;
-import android.os.Handler;
import android.support.annotation.Nullable;
import android.util.Log;
-import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-@TargetApi(Build.VERSION_CODES.O)
+
+@TargetApi(27)
public class WallpaperManagerCompatVOMR1 extends WallpaperManagerCompat {
private static final String TAG = "WMCompatVOMR1";
private final WallpaperManager mWm;
-
- private final Class mOCLClass;
- private final Method mAddOCLMethod;
-
- private final Method mWCGetMethod;
- private final Method mWCGetPrimaryColorMethod;
- private final Method mWCGetSecondaryColorMethod;
- private final Method mWCGetTertiaryColorMethod;
private final Method mWCColorHintsMethod;
WallpaperManagerCompatVOMR1(Context context) throws Exception {
mWm = context.getSystemService(WallpaperManager.class);
-
- mOCLClass = Class.forName("android.app.WallpaperManager$OnColorsChangedListener");
- mAddOCLMethod = WallpaperManager.class.getDeclaredMethod(
- "addOnColorsChangedListener", mOCLClass, Handler.class);
- mWCGetMethod = WallpaperManager.class.getDeclaredMethod("getWallpaperColors", int.class);
- Class wallpaperColorsClass = mWCGetMethod.getReturnType();
- mWCGetPrimaryColorMethod = wallpaperColorsClass.getDeclaredMethod("getPrimaryColor");
- mWCGetSecondaryColorMethod = wallpaperColorsClass.getDeclaredMethod("getSecondaryColor");
- mWCGetTertiaryColorMethod = wallpaperColorsClass.getDeclaredMethod("getTertiaryColor");
- mWCColorHintsMethod = wallpaperColorsClass.getDeclaredMethod("getColorHints");
+ mWCColorHintsMethod = WallpaperColors.class.getDeclaredMethod("getColorHints");
}
@Nullable
@Override
public WallpaperColorsCompat getWallpaperColors(int which) {
- try {
- return convertColorsObject(mWCGetMethod.invoke(mWm, which));
- } catch (Exception e) {
- Log.e(TAG, "Error calling wallpaper API", e);
- return null;
- }
+ return convertColorsObject(mWm.getWallpaperColors(which));
}
@Override
public void addOnColorsChangedListener(final OnColorsChangedListenerCompat listener) {
- Object onChangeListener = Proxy.newProxyInstance(
- WallpaperManager.class.getClassLoader(),
- new Class[]{mOCLClass},
- new InvocationHandler() {
- @Override
- public Object invoke(Object o, Method method, Object[] objects)
- throws Throwable {
- String methodName = method.getName();
- if ("onColorsChanged".equals(methodName)) {
- listener.onColorsChanged(
- convertColorsObject(objects[0]), (Integer) objects[1]);
- } else if ("toString".equals(methodName)) {
- return listener.toString();
- }
- return null;
- }
- });
- try {
- mAddOCLMethod.invoke(mWm, onChangeListener, null);
- } catch (Exception e) {
- Log.e(TAG, "Error calling wallpaper API", e);
- }
+ OnColorsChangedListener onChangeListener = new OnColorsChangedListener() {
+ public void onColorsChanged(WallpaperColors colors, int which) {
+ listener.onColorsChanged(convertColorsObject(colors), which);
+ }
+ public void onColorsChanged(WallpaperColors colors, int which, int userId) {
+ onColorsChanged(colors, which);
+ }
+ };
+ mWm.addOnColorsChangedListener(onChangeListener, null);
}
- private WallpaperColorsCompat convertColorsObject(Object colors) throws Exception {
+ private WallpaperColorsCompat convertColorsObject(WallpaperColors colors) {
if (colors == null) {
return null;
}
- Color primary = (Color) mWCGetPrimaryColorMethod.invoke(colors);
- Color secondary = (Color) mWCGetSecondaryColorMethod.invoke(colors);
- Color tertiary = (Color) mWCGetTertiaryColorMethod.invoke(colors);
+ Color primary = colors.getPrimaryColor();
+ Color secondary = colors.getSecondaryColor();
+ Color tertiary = colors.getTertiaryColor();
int primaryVal = primary != null ? primary.toArgb() : 0;
int secondaryVal = secondary != null ? secondary.toArgb() : 0;
int tertiaryVal = tertiary != null ? tertiary.toArgb() : 0;
- int colorHints = (Integer) mWCColorHintsMethod.invoke(colors);
+ int colorHints = 0;
+ try {
+ colorHints = (Integer) mWCColorHintsMethod.invoke(colors);
+ } catch (Exception exc) {
+ Log.e(TAG, "error calling color hints", exc);
+ }
return new WallpaperColorsCompat(primaryVal, secondaryVal, tertiaryVal, colorHints);
}
}