Merge "Fix animations for app QS tiles." into nyc-mr2-dev
This commit is contained in:
@@ -486,10 +486,19 @@ public abstract class QSTile<TState extends State> {
|
|||||||
public Drawable getDrawable(Context context) {
|
public Drawable getDrawable(Context context) {
|
||||||
return mDrawable;
|
return mDrawable;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DrawableIconWithRes extends DrawableIcon {
|
||||||
|
private final int mId;
|
||||||
|
|
||||||
|
public DrawableIconWithRes(Drawable drawable, int id) {
|
||||||
|
super(drawable);
|
||||||
|
mId = id;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Drawable getInvisibleDrawable(Context context) {
|
public boolean equals(Object o) {
|
||||||
return mDrawable;
|
return o instanceof DrawableIconWithRes && ((DrawableIconWithRes) o).mId == mId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,11 +17,14 @@ package com.android.systemui.qs.external;
|
|||||||
|
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.content.pm.ServiceInfo;
|
import android.content.pm.ServiceInfo;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.graphics.drawable.Icon;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
@@ -60,6 +63,7 @@ public class CustomTile extends QSTile<QSTile.State> implements TileChangeListen
|
|||||||
private final IQSTileService mService;
|
private final IQSTileService mService;
|
||||||
private final TileServiceManager mServiceManager;
|
private final TileServiceManager mServiceManager;
|
||||||
private final int mUser;
|
private final int mUser;
|
||||||
|
private Context mAppContext;
|
||||||
private android.graphics.drawable.Icon mDefaultIcon;
|
private android.graphics.drawable.Icon mDefaultIcon;
|
||||||
|
|
||||||
private boolean mListening;
|
private boolean mListening;
|
||||||
@@ -77,6 +81,10 @@ public class CustomTile extends QSTile<QSTile.State> implements TileChangeListen
|
|||||||
mService = mServiceManager.getTileService();
|
mService = mServiceManager.getTileService();
|
||||||
mServiceManager.setTileChangeListener(this);
|
mServiceManager.setTileChangeListener(this);
|
||||||
mUser = ActivityManager.getCurrentUser();
|
mUser = ActivityManager.getCurrentUser();
|
||||||
|
try {
|
||||||
|
mAppContext = mContext.createPackageContext(mComponent.getPackageName(), 0);
|
||||||
|
} catch (NameNotFoundException e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTileIcon() {
|
private void setTileIcon() {
|
||||||
@@ -278,16 +286,20 @@ public class CustomTile extends QSTile<QSTile.State> implements TileChangeListen
|
|||||||
tileState = Tile.STATE_UNAVAILABLE;
|
tileState = Tile.STATE_UNAVAILABLE;
|
||||||
}
|
}
|
||||||
Drawable drawable;
|
Drawable drawable;
|
||||||
|
boolean mHasRes = false;
|
||||||
|
android.graphics.drawable.Icon icon = mTile.getIcon();
|
||||||
try {
|
try {
|
||||||
drawable = mTile.getIcon().loadDrawable(mContext);
|
drawable = icon.loadDrawable(mAppContext);
|
||||||
|
mHasRes = icon.getType() == android.graphics.drawable.Icon.TYPE_RESOURCE;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.w(TAG, "Invalid icon, forcing into unavailable state");
|
Log.w(TAG, "Invalid icon, forcing into unavailable state");
|
||||||
tileState = Tile.STATE_UNAVAILABLE;
|
tileState = Tile.STATE_UNAVAILABLE;
|
||||||
drawable = mDefaultIcon.loadDrawable(mContext);
|
drawable = mDefaultIcon.loadDrawable(mAppContext);
|
||||||
}
|
}
|
||||||
int color = mContext.getColor(getColor(tileState));
|
int color = mContext.getColor(getColor(tileState));
|
||||||
drawable.setTint(color);
|
drawable.setTint(color);
|
||||||
state.icon = new DrawableIcon(drawable);
|
state.icon = mHasRes ? new DrawableIconWithRes(drawable, icon.getResId())
|
||||||
|
: new DrawableIcon(drawable);
|
||||||
state.label = mTile.getLabel();
|
state.label = mTile.getLabel();
|
||||||
if (tileState == Tile.STATE_UNAVAILABLE) {
|
if (tileState == Tile.STATE_UNAVAILABLE) {
|
||||||
state.label = new SpannableStringBuilder().append(state.label,
|
state.label = new SpannableStringBuilder().append(state.label,
|
||||||
|
|||||||
Reference in New Issue
Block a user