Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9a5a329d authored by Roman Birg's avatar Roman Birg
Browse files

SystemUI: small optimization for notification icon numbers



Don't create the paint object used to draw notification icon count
badges in the status bar unless the user actually wants to see those
counts.

Change-Id: Iabba316102583a798acdc124d9fb51c0d7826a0d
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 67de6b76
Loading
Loading
Loading
Loading
+13 −12
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.content.res.ThemeConfig;
import android.database.ContentObserver;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
@@ -50,7 +49,7 @@ public class StatusBarIconView extends AnimatedImageView {
    private StatusBarIcon mIcon;
    @ViewDebug.ExportedProperty private String mSlot;
    private Drawable mNumberBackground;
    private Paint mNumberPain;
    private Paint mNumberPaint;
    private int mNumberX;
    private int mNumberY;
    private String mNumberText;
@@ -61,15 +60,7 @@ public class StatusBarIconView extends AnimatedImageView {
    public StatusBarIconView(Context context, String slot, Notification notification) {
        super(context);
        final Resources res = context.getResources();
        final float densityMultiplier = res.getDisplayMetrics().density;
        final float scaledPx = 8 * densityMultiplier;
        mSlot = slot;
        mNumberPain = new Paint();
        mNumberPain.setTextAlign(Paint.Align.CENTER);
        mNumberPain.setColor(res.getColor(R.drawable.notification_number_text_color));
        mNumberPain.setAntiAlias(true);
        mNumberPain.setTypeface(Typeface.DEFAULT_BOLD);
        mNumberPain.setTextSize(scaledPx);
        setNotification(notification);

        mObserver = GlobalSettingsObserver.getInstance(context);
@@ -146,6 +137,15 @@ public class StatusBarIconView extends AnimatedImageView {
        if (!numberEquals || force) {
            if (icon.number > 1 && mShowNotificationCount) {
                if (mNumberBackground == null) {
                    final Resources res = mContext.getResources();
                    final float densityMultiplier = res.getDisplayMetrics().density;
                    final float scaledPx = 8 * densityMultiplier;
                    mNumberPaint = new Paint();
                    mNumberPaint.setTextAlign(Paint.Align.CENTER);
                    mNumberPaint.setColor(res.getColor(R.drawable.notification_number_text_color));
                    mNumberPaint.setAntiAlias(true);
                    mNumberPaint.setTypeface(Typeface.DEFAULT_BOLD);
                    mNumberPaint.setTextSize(scaledPx);
                    mNumberBackground = getContext().getResources().getDrawable(
                            R.drawable.ic_notification_overlay);
                }
@@ -153,6 +153,7 @@ public class StatusBarIconView extends AnimatedImageView {
            } else {
                mNumberBackground = null;
                mNumberText = null;
                mNumberPaint = null;
            }
            invalidate();
        }
@@ -262,7 +263,7 @@ public class StatusBarIconView extends AnimatedImageView {

        if (mNumberBackground != null) {
            mNumberBackground.draw(canvas);
            canvas.drawText(mNumberText, mNumberX, mNumberY, mNumberPain);
            canvas.drawText(mNumberText, mNumberX, mNumberY, mNumberPaint);
        }
    }

@@ -307,7 +308,7 @@ public class StatusBarIconView extends AnimatedImageView {
        final int w = getWidth();
        final int h = getHeight();
        final Rect r = new Rect();
        mNumberPain.getTextBounds(str, 0, str.length(), r);
        mNumberPaint.getTextBounds(str, 0, str.length(), r);
        final int tw = r.right - r.left;
        final int th = r.bottom - r.top;
        mNumberBackground.getPadding(r);