diff options
| author | 2016-12-12 12:02:16 -0500 | |
|---|---|---|
| committer | 2016-12-12 12:02:16 -0500 | |
| commit | d2274f848c586d86404ae14dfb8d11a02ee4867a (patch) | |
| tree | 8c1a558f1fbacb80a824608f21f2d6121d0eb10f | |
| parent | 1e40ddc47af4334cd8927243a9fab9ce7059b52d (diff) | |
Fix animations for app QS tiles.
Use correct context for third party tile drawable creation, also
fix comparison so that AVDs don't animate multiple times.
Change-Id: Ifcf7b818304d6677eacf080ed8c22893c91fdf73
Fixes: 32779384
Test: Install app with animated app QS tile.
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/qs/QSTile.java | 13 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java | 18 |
2 files changed, 26 insertions, 5 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSTile.java b/packages/SystemUI/src/com/android/systemui/qs/QSTile.java index 2fda6eac6e0b..f743a4bf1a82 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSTile.java @@ -486,10 +486,19 @@ public abstract class QSTile<TState extends State> { public Drawable getDrawable(Context context) { return mDrawable; } + } + + public static class DrawableIconWithRes extends DrawableIcon { + private final int mId; + + public DrawableIconWithRes(Drawable drawable, int id) { + super(drawable); + mId = id; + } @Override - public Drawable getInvisibleDrawable(Context context) { - return mDrawable; + public boolean equals(Object o) { + return o instanceof DrawableIconWithRes && ((DrawableIconWithRes) o).mId == mId; } } diff --git a/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java b/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java index b36221d83cd6..8a04b593600f 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java @@ -17,11 +17,14 @@ package com.android.systemui.qs.external; import android.app.ActivityManager; import android.content.ComponentName; +import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.graphics.drawable.Drawable; +import android.graphics.drawable.Icon; import android.net.Uri; import android.os.Binder; import android.os.IBinder; @@ -60,6 +63,7 @@ public class CustomTile extends QSTile<QSTile.State> implements TileChangeListen private final IQSTileService mService; private final TileServiceManager mServiceManager; private final int mUser; + private Context mAppContext; private android.graphics.drawable.Icon mDefaultIcon; private boolean mListening; @@ -77,6 +81,10 @@ public class CustomTile extends QSTile<QSTile.State> implements TileChangeListen mService = mServiceManager.getTileService(); mServiceManager.setTileChangeListener(this); mUser = ActivityManager.getCurrentUser(); + try { + mAppContext = mContext.createPackageContext(mComponent.getPackageName(), 0); + } catch (NameNotFoundException e) { + } } private void setTileIcon() { @@ -278,16 +286,20 @@ public class CustomTile extends QSTile<QSTile.State> implements TileChangeListen tileState = Tile.STATE_UNAVAILABLE; } Drawable drawable; + boolean mHasRes = false; + android.graphics.drawable.Icon icon = mTile.getIcon(); try { - drawable = mTile.getIcon().loadDrawable(mContext); + drawable = icon.loadDrawable(mAppContext); + mHasRes = icon.getType() == android.graphics.drawable.Icon.TYPE_RESOURCE; } catch (Exception e) { Log.w(TAG, "Invalid icon, forcing into unavailable state"); tileState = Tile.STATE_UNAVAILABLE; - drawable = mDefaultIcon.loadDrawable(mContext); + drawable = mDefaultIcon.loadDrawable(mAppContext); } int color = mContext.getColor(getColor(tileState)); drawable.setTint(color); - state.icon = new DrawableIcon(drawable); + state.icon = mHasRes ? new DrawableIconWithRes(drawable, icon.getResId()) + : new DrawableIcon(drawable); state.label = mTile.getLabel(); if (tileState == Tile.STATE_UNAVAILABLE) { state.label = new SpannableStringBuilder().append(state.label, |