diff options
| author | Jim Miller <jaggies@google.com> | 2012-05-31 17:49:13 -0700 |
|---|---|---|
| committer | Jim Miller <jaggies@google.com> | 2012-06-01 14:08:28 -0700 |
| commit | 3294b6b09b2f52cb44005720051c32c9c851fc9f (patch) | |
| tree | 109bdb85becd0cc2c0b7b24a1e7a4abbfe8d1997 /core | |
| parent | ef3a8021e412b33db817789a9c1869022b5c901b (diff) | |
| download | frameworks_base-3294b6b09b2f52cb44005720051c32c9c851fc9f.zip frameworks_base-3294b6b09b2f52cb44005720051c32c9c851fc9f.tar.gz frameworks_base-3294b6b09b2f52cb44005720051c32c9c851fc9f.tar.bz2 | |
Fix 6592932: add means to replace assist icon from given package
This provides the means to replace the assist icon shown in keyguard and the
navigation gesture for assist. It's done by adding metadata called
"com.android.systemui.action_assist_icon" to the activity that handles
android.intent.action.ASSIST. It should point to a StateListDrawable
in that package with the required states. For example:
<meta-data android:name="com.android.systemui.action_assist_icon"
android:resource="@drawable/ic_android_systemui_action_assist" />
And then something like this in drawable/ic_android_systemui_action_assist.xml :
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true"
android:state_active="false"
android:state_focused="false"
android:drawable="@drawable/ic_action_assist_normal" />
<item android:state_enabled="true"
android:state_active="true"
android:state_focused="false"
android:drawable="@drawable/ic_action_assist_activated" />
<item android:state_enabled="true"
android:state_active="false"
android:state_focused="true"
android:drawable="@drawable/ic_action_assist_focused" />
</selector>
Change-Id: Ibc29360e179fed68253ff06a07b1bb2b982d0dab
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> |
