OSDN Git Service

systemui: Forward-port notification counters
authorSteve Kondik <steve@cyngn.com>
Fri, 5 Dec 2014 16:31:29 +0000 (08:31 -0800)
committerSteve Kondik <steve@cyngn.com>
Sun, 4 Sep 2016 09:38:33 +0000 (02:38 -0700)
 * Port from CM11

Change-Id: Id9d0954acffd00bdb470b9eccbdb3b45fbd995c1

core/java/android/provider/Settings.java
packages/SettingsProvider/res/values/defaults.xml
packages/SystemUI/res/drawable-hdpi/ic_notification_overlay.9.png
packages/SystemUI/res/drawable-mdpi/ic_notification_overlay.9.png
packages/SystemUI/res/drawable-xhdpi/ic_notification_overlay.9.png
packages/SystemUI/res/drawable-xxhdpi/ic_notification_overlay.9.png
packages/SystemUI/res/values/colors.xml
packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java

index 062ede4..40c0b34 100644 (file)
@@ -3292,6 +3292,12 @@ public final class Settings {
         public static final String ACCELEROMETER_ROTATION_ANGLES = "accelerometer_rotation_angles";
 
         /**
+         * Show the pending notification counts as overlays on the status bar
+         * @hide
+         */
+        public static final String STATUS_BAR_NOTIF_COUNT = "status_bar_notif_count";
+
+        /**
          * Control whether the accelerometer will be used to change screen
          * orientation.  If 0, it will not be used unless explicitly requested
          * by the application; if 1, it will be used by default unless explicitly
index 20ed573..81e835f 100644 (file)
 
     <!-- Defaults for Settings.System.DEV_FORCE_SHOW_NAVBAR. -->
     <integer name="def_force_disable_navkeys">0</integer>
+
+    <!-- Default for Settings.System.STATUS_BAR_NOTIF_COUNT. -->
+    <integer name="def_notif_count">0</integer>
+
 </resources>
index a93916f..5bde6ef 100644 (file)
Binary files a/packages/SystemUI/res/drawable-hdpi/ic_notification_overlay.9.png and b/packages/SystemUI/res/drawable-hdpi/ic_notification_overlay.9.png differ
index 7ae6079..c8c8102 100644 (file)
Binary files a/packages/SystemUI/res/drawable-mdpi/ic_notification_overlay.9.png and b/packages/SystemUI/res/drawable-mdpi/ic_notification_overlay.9.png differ
index aae807b..77eeda1 100644 (file)
Binary files a/packages/SystemUI/res/drawable-xhdpi/ic_notification_overlay.9.png and b/packages/SystemUI/res/drawable-xhdpi/ic_notification_overlay.9.png differ
index fa7de0e..ea09774 100644 (file)
Binary files a/packages/SystemUI/res/drawable-xxhdpi/ic_notification_overlay.9.png and b/packages/SystemUI/res/drawable-xxhdpi/ic_notification_overlay.9.png differ
index cb51649..7ba29aa 100644 (file)
@@ -17,7 +17,7 @@
  */
 -->
 <resources>
-    <drawable name="notification_number_text_color">#ffffffff</drawable>
+    <drawable name="notification_number_text_color">#ff000000</drawable>
     <drawable name="ticker_background_color">#ff1d1d1d</drawable>
     <drawable name="system_bar_background">@color/system_bar_background_opaque</drawable>
     <color name="system_bar_background_opaque">#ff000000</color>
index cdfdad4..f658b8e 100644 (file)
@@ -21,13 +21,17 @@ import android.content.Context;
 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;
@@ -39,6 +43,7 @@ import com.android.internal.statusbar.StatusBarIcon;
 import com.android.systemui.R;
 
 import java.text.NumberFormat;
+import java.util.ArrayList;
 
 public class StatusBarIconView extends AnimatedImageView {
     private static final String TAG = "StatusBarIconView";
@@ -54,6 +59,8 @@ public class StatusBarIconView extends AnimatedImageView {
     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);
@@ -63,15 +70,21 @@ public class StatusBarIconView extends AnimatedImageView {
             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() {
@@ -104,6 +117,8 @@ public class StatusBarIconView extends AnimatedImageView {
 
     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);
     }
 
@@ -144,6 +159,10 @@ public class StatusBarIconView extends AnimatedImageView {
      * 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;
@@ -153,16 +172,15 @@ public class StatusBarIconView extends AnimatedImageView {
                 && 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);
@@ -174,7 +192,7 @@ public class StatusBarIconView extends AnimatedImageView {
             }
             invalidate();
         }
-        if (!visibilityEquals) {
+        if (!visibilityEquals || force) {
             setVisibility(icon.visible && !mBlocked ? VISIBLE : GONE);
         }
         return true;
@@ -268,6 +286,24 @@ public class StatusBarIconView extends AnimatedImageView {
     }
 
     @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);
@@ -351,4 +387,56 @@ public class StatusBarIconView extends AnimatedImageView {
         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);
+            }
+        }
+    }
 }
+