summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java62
-rw-r--r--core/java/com/android/internal/widget/multiwaveview/TargetDrawable.java8
-rw-r--r--core/res/res/drawable/ic_lockscreen_search.xml2
3 files changed, 70 insertions, 2 deletions
diff --git a/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java b/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java
index b2c3091..89dbd1b 100644
--- a/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java
+++ b/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java
@@ -23,12 +23,16 @@ import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
+import android.content.ComponentName;
import android.content.Context;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
+import android.os.Bundle;
import android.os.Vibrator;
import android.text.TextUtils;
import android.util.AttributeSet;
@@ -1233,4 +1237,62 @@ public class MultiWaveView extends View {
}
return -1;
}
+
+ private boolean replaceTargetDrawables(Resources res, int existingResourceId,
+ int newResourceId) {
+ if (existingResourceId == 0 || newResourceId == 0) {
+ return false;
+ }
+
+ boolean result = false;
+ final ArrayList<TargetDrawable> drawables = mTargetDrawables;
+ final int size = drawables.size();
+ for (int i = 0; i < size; i++) {
+ final TargetDrawable target = drawables.get(i);
+ if (target != null && target.getResourceId() == existingResourceId) {
+ target.setDrawable(res, newResourceId);
+ result = true;
+ }
+ }
+
+ if (result) {
+ requestLayout(); // in case any given drawable's size changes
+ }
+
+ return result;
+ }
+
+ /**
+ * Searches the given package for a resource to use to replace the Drawable on the
+ * target with the given resource id
+ * @param component of the .apk that contains the resource
+ * @param name of the metadata in the .apk
+ * @param existingResId the resource id of the target to search for
+ * @return true if found in the given package and replaced at least one target Drawables
+ */
+ public boolean replaceTargetDrawablesIfPresent(ComponentName component, String name,
+ int existingResId) {
+ if (existingResId == 0) return false;
+
+ try {
+ PackageManager packageManager = mContext.getPackageManager();
+ // Look for the search icon specified in the activity meta-data
+ Bundle metaData = packageManager.getActivityInfo(
+ component, PackageManager.GET_META_DATA).metaData;
+ if (metaData != null) {
+ int iconResId = metaData.getInt(name);
+ if (iconResId != 0) {
+ Resources res = packageManager.getResourcesForActivity(component);
+ return replaceTargetDrawables(res, existingResId, iconResId);
+ }
+ }
+ } catch (NameNotFoundException e) {
+ Log.w(TAG, "Failed to swap drawable; "
+ + component.flattenToShortString() + " not found", e);
+ } catch (Resources.NotFoundException nfe) {
+ Log.w(TAG, "Failed to swap drawable from "
+ + component.flattenToShortString(), nfe);
+ }
+ return false;
+ }
}
diff --git a/core/java/com/android/internal/widget/multiwaveview/TargetDrawable.java b/core/java/com/android/internal/widget/multiwaveview/TargetDrawable.java
index 6392093..30f5f2f 100644
--- a/core/java/com/android/internal/widget/multiwaveview/TargetDrawable.java
+++ b/core/java/com/android/internal/widget/multiwaveview/TargetDrawable.java
@@ -44,7 +44,7 @@ public class TargetDrawable {
private float mAlpha = 1.0f;
private Drawable mDrawable;
private boolean mEnabled = true;
- private int mResourceId;
+ private final int mResourceId;
/* package */ static class DrawableWithAlpha extends Drawable {
private float mAlpha = 1.0f;
@@ -78,6 +78,12 @@ public class TargetDrawable {
public TargetDrawable(Resources res, int resId) {
mResourceId = resId;
+ setDrawable(res, resId);
+ }
+
+ public void setDrawable(Resources res, int resId) {
+ // Note we explicitly don't set mResourceId to resId since we allow the drawable to be
+ // swapped at runtime and want to re-use the existing resource id for identification.
Drawable drawable = resId == 0 ? null : res.getDrawable(resId);
// Mutate the drawable so we can animate shared drawable properties.
mDrawable = drawable != null ? drawable.mutate() : null;
diff --git a/core/res/res/drawable/ic_lockscreen_search.xml b/core/res/res/drawable/ic_lockscreen_search.xml
index 4040153..d7a5b00 100644
--- a/core/res/res/drawable/ic_lockscreen_search.xml
+++ b/core/res/res/drawable/ic_lockscreen_search.xml
@@ -31,6 +31,6 @@
android:state_enabled="true"
android:state_active="false"
android:state_focused="true"
- android:drawable="@drawable/ic_lockscreen_google_activated" />
+ android:drawable="@drawable/ic_lockscreen_google_focused" />
</selector>