Skip to content

Multiple dot span to one date #1145

Open

Description

@mimakopanja

I have database with lists of tasks, i need to add multiple dot spans to one date with different color (color depends on the list category - study, work...)

Spans are adding but they are overlapping each other.
Can anyone please help?

Activity

  1. kaiyrzhanDE commented on Oct 12, 2023

    @kaiyrzhanDE

    Hi. How you solve it?

  2. LeBogoo commented on Feb 3, 2024

    @LeBogoo

    I've had almost the same problem, so I've written this class for single color dots.

    I hope this is helps anyone in the future:

    import android.graphics.Canvas;
    import android.graphics.Paint;
    import android.text.style.LineBackgroundSpan;
    
    public class MultiDotSpan implements LineBackgroundSpan {
        private static final float DEFAULT_RADIUS = 3;
        private static final float DEFAULT_PADDING = 15;
    
        private final float radius;
        private final int color;
        private final int amount;
    
        public MultiDotSpan() {
            this.radius = DEFAULT_RADIUS;
            this.color = 0;
            this.amount = 1;
        }
    
        public MultiDotSpan(float radius) {
            this(radius, 0);
        }
    
        public MultiDotSpan(float radius, int color) {
            this(radius, color, 1);
        }
    
        public MultiDotSpan(float radius, int color, int amount) {
            this.radius = radius;
            this.color = color;
            this.amount = amount;
        }
    
        @Override
        public void drawBackground(Canvas canvas, Paint paint, int left, int right, int top, int baseline, int bottom, CharSequence charSequence, int start, int end, int lineNum) {
            int oldColor = paint.getColor();
            if (color != 0) {
                paint.setColor(color);
            }
            float center = (left + right) / 2f;
            for (int i = 0; i < amount; i++) {
                float x = center + (i - (amount - 1) / 2f) * DEFAULT_PADDING;
                canvas.drawCircle(x, bottom + radius, radius, paint);
            }
            paint.setColor(oldColor);
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions