Open mimakopanja opened 10 months ago
Hi. How you solve it?
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);
}
}
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?