diff options
| author | Jim Miller <jaggies@google.com> | 2012-06-01 20:34:43 -0700 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-06-01 20:34:43 -0700 |
| commit | 94a8ae09bea03ec2ca5563601e28a196d41bb6b6 (patch) | |
| tree | 5fbc519bb6f3f6cd44d5244a0eaa52cc41af4997 /core | |
| parent | 2aeaf2345ea0b72322ee301cb4412fa737b594bc (diff) | |
| parent | 3294b6b09b2f52cb44005720051c32c9c851fc9f (diff) | |
| download | frameworks_base-94a8ae09bea03ec2ca5563601e28a196d41bb6b6.zip frameworks_base-94a8ae09bea03ec2ca5563601e28a196d41bb6b6.tar.gz frameworks_base-94a8ae09bea03ec2ca5563601e28a196d41bb6b6.tar.bz2 | |
Merge "Fix 6592932: add means to replace assist icon from given package" into jb-dev
Diffstat (limited to 'core')
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> |
