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

Commit 50a911f5 authored by Yash Garg's avatar Yash Garg 💬 Committed by Mohammed Althaf T
Browse files

feat: convert badge to round rect when count > 99

parent a015a67d
Loading
Loading
Loading
Loading
+30 −6
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ public class DotRenderer {
    private static final float SIZE_PERCENTAGE_WITH_COUNT = 0.28f;

    // The max number to draw on dots
    private static final int MAX_COUNT = 99;
    private static final int MAX_COUNT = 999;

    private final float mCircleRadius;
    private final Paint mCirclePaint = new Paint(ANTI_ALIAS_FLAG | FILTER_BITMAP_FLAG);
@@ -143,18 +143,34 @@ public class DotRenderer {
        float offsetY = Math.max(0, canvasBounds.top - (dotCenterY + mBitmapOffset));

        // We draw the dot relative to its center.
        canvas.translate(dotCenterX + offsetX, dotCenterY + offsetY);
        float dx = dotCenterX + offsetX;
        float dy = dotCenterY + offsetY - 15f;

        if (numNotifications > 9 && numNotifications < 100) {
            canvas.translate(dx - 3f, dy);
        } else if (numNotifications > 99 && numNotifications < 1000) {
            canvas.translate(dx + 6f, dy);
        } else {
            canvas.translate(dx - 12f, dy);
        }

        canvas.scale(params.scale, params.scale);

        mCirclePaint.setColor(Color.BLACK);
        canvas.drawBitmap(mBackgroundWithShadow, mBitmapOffset, mBitmapOffset, mCirclePaint);
        mCirclePaint.setColor(params.dotColor);
        if (numNotifications > 9 && numNotifications < 100) {
            canvas.drawRoundRect(new RectF(-mCircleRadius - 10, -mCircleRadius, mCircleRadius + 10, mCircleRadius), 50, 50, mCirclePaint);
        } else if (numNotifications > 99 && numNotifications < 1000) {
            canvas.drawRoundRect(new RectF(-mCircleRadius - 20, -mCircleRadius, mCircleRadius + 20, mCircleRadius), 50, 50, mCirclePaint);
        } else {
            canvas.drawCircle(0, 0, mCircleRadius, mCirclePaint);
        }

        if (mDisplayCount && numNotifications > 0) {
            // Draw the numNotifications text
            mTextPaint.setColor(getCounterTextColor(Color.WHITE));
            String text = String.valueOf(Math.min(numNotifications, MAX_COUNT));
            mTextPaint.setTextSize(42f);
            mTextPaint.setTypeface(Typeface.DEFAULT_BOLD);
            String text = numToNotation(numNotifications);
            mTextPaint.getTextBounds(text, 0, text.length(), mTextRect);
            float x = (-mTextRect.width() / 2f - mTextRect.left) * getAdjustment(numNotifications);
            float y = mTextRect.height() / 2f - mTextRect.bottom;
@@ -164,6 +180,14 @@ public class DotRenderer {
        canvas.restore();
    }

    private String numToNotation(int num) {
        if (num < 1000) {
            return String.valueOf(num);
        } else {
            return num / 1000 + "k";
        }
    }

    /**
     * Returns the color to use for the counter text based on the dot's background color.
     *