Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple dot span to one date #1145

Open
mimakopanja opened this issue Aug 23, 2023 · 2 comments
Open

Multiple dot span to one date #1145

mimakopanja opened this issue Aug 23, 2023 · 2 comments

Comments

@mimakopanja
Copy link

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?

@kaiyrzhanDE
Copy link

Hi. How you solve it?

@LeBogoo
Copy link

LeBogoo commented Feb 3, 2024

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants