import android.content.pm.ApplicationInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
+import android.database.ContentObserver;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
+import android.graphics.Typeface;
+import android.os.Handler;
import android.os.Parcelable;
import android.os.UserHandle;
+import android.provider.Settings;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import com.android.systemui.R;
import java.text.NumberFormat;
+import java.util.ArrayList;
public class StatusBarIconView extends AnimatedImageView {
private static final String TAG = "StatusBarIconView";
private Notification mNotification;
private final boolean mBlocked;
private int mDensity;
+ private boolean mShowNotificationCount;
+ private GlobalSettingsObserver mObserver;
public StatusBarIconView(Context context, String slot, Notification notification) {
this(context, slot, notification, false);
boolean blocked) {
super(context);
mBlocked = blocked;
+ final float densityMultiplier = res.getDisplayMetrics().density;
+ final float scaledPx = 8 * densityMultiplier;
mSlot = slot;
mNumberPain = new Paint();
mNumberPain.setTextAlign(Paint.Align.CENTER);
mNumberPain.setColor(context.getColor(R.drawable.notification_number_text_color));
mNumberPain.setAntiAlias(true);
+ mNumberPain.setTypeface(Typeface.DEFAULT_BOLD);
+ mNumberPain.setTextSize(scaledPx);
setNotification(notification);
maybeUpdateIconScale();
setScaleType(ScaleType.CENTER);
mDensity = context.getResources().getDisplayMetrics().densityDpi;
+
+ mObserver = GlobalSettingsObserver.getInstance(context);
}
private void maybeUpdateIconScale() {
public void setNotification(Notification notification) {
mNotification = notification;
+ mShowNotificationCount = Settings.System.getIntForUser(mContext.getContentResolver(),
+ Settings.System.STATUS_BAR_NOTIF_COUNT, 0, UserHandle.USER_CURRENT) == 1;
setContentDescription(notification);
}
* Returns whether the set succeeded.
*/
public boolean set(StatusBarIcon icon) {
+ return set(icon, false);
+ }
+
+ private boolean set(StatusBarIcon icon, boolean force) {
final boolean iconEquals = mIcon != null && equalIcons(mIcon.icon, icon.icon);
final boolean levelEquals = iconEquals
&& mIcon.iconLevel == icon.iconLevel;
&& mIcon.number == icon.number;
mIcon = icon.clone();
setContentDescription(icon.contentDescription);
- if (!iconEquals) {
+ if (!iconEquals || force) {
if (!updateDrawable(false /* no clear */)) return false;
}
- if (!levelEquals) {
+ if (!levelEquals || force) {
setImageLevel(icon.iconLevel);
}
- if (!numberEquals) {
- if (icon.number > 0 && getContext().getResources().getBoolean(
- R.bool.config_statusBarShowNumber)) {
+ if (!numberEquals || force) {
+ if (icon.number > 1 && mShowNotificationCount) {
if (mNumberBackground == null) {
mNumberBackground = getContext().getResources().getDrawable(
R.drawable.ic_notification_overlay);
}
invalidate();
}
- if (!visibilityEquals) {
+ if (!visibilityEquals || force) {
setVisibility(icon.visible && !mBlocked ? VISIBLE : GONE);
}
return true;
}
@Override
+ public void onAttachedToWindow() {
+ super.onAttachedToWindow();
+
+ if (mObserver != null) {
+ mObserver.attach(this);
+ }
+ }
+
+ @Override
+ public void onDetachedFromWindow() {
+ super.onDetachedFromWindow();
+
+ if (mObserver != null) {
+ mObserver.detach(this);
+ }
+ }
+
+ @Override
protected void debug(int depth) {
super.debug(depth);
Log.d("View", debugIndent(depth) + "slot=" + mSlot);
return c.getString(R.string.accessibility_desc_notification_icon, appName, desc);
}
+ static class GlobalSettingsObserver extends ContentObserver {
+ private static GlobalSettingsObserver sInstance;
+ private ArrayList<StatusBarIconView> mIconViews = new ArrayList<StatusBarIconView>();
+ private Context mContext;
+
+ GlobalSettingsObserver(Handler handler, Context context) {
+ super(handler);
+ mContext = context.getApplicationContext();
+ }
+
+ static GlobalSettingsObserver getInstance(Context context) {
+ if (sInstance == null) {
+ sInstance = new GlobalSettingsObserver(new Handler(), context);
+ }
+ return sInstance;
+ }
+
+ void attach(StatusBarIconView sbiv) {
+ if (mIconViews.isEmpty()) {
+ observe();
+ }
+ mIconViews.add(sbiv);
+ }
+
+ void detach(StatusBarIconView sbiv) {
+ mIconViews.remove(sbiv);
+ if (mIconViews.isEmpty()) {
+ unobserve();
+ }
+ }
+
+ void observe() {
+ mContext.getContentResolver().registerContentObserver(
+ Settings.System.getUriFor(Settings.System.STATUS_BAR_NOTIF_COUNT),
+ false, this);
+ }
+
+ void unobserve() {
+ mContext.getContentResolver().unregisterContentObserver(this);
+ }
+
+ @Override
+ public void onChange(boolean selfChange) {
+ boolean showIconCount = Settings.System.getIntForUser(mContext.getContentResolver(),
+ Settings.System.STATUS_BAR_NOTIF_COUNT, 0, UserHandle.USER_CURRENT) == 1;
+ for (StatusBarIconView sbiv : mIconViews) {
+ sbiv.mShowNotificationCount = showIconCount;
+ sbiv.set(sbiv.mIcon, true);
+ }
+ }
+ }
}
+