I create a custom BulletSpan
by extending LeadingMarginSpan
to draw a custom bulleted items in a TextView
. The documentation of LeadingMarginSpan
says it can be nested (i.e. multilevel bullets):
There can be multiple leading margin spans on a single paragraph; they will be rendered in order, each adding its margin to the ones before it.
The LeadingMarginSpan
class has this method:
public void drawLeadingMargin(Canvas c, Paint p, int x, int dir,
int top, int baseline, int bottom,
CharSequence text, int start, int end,
boolean first, Layout l);
I don't know whether the implementation of the method should calculate the indentation itself or it has been indented. There's different behaviour across devices. For example, in API level 21 it's called with x
always 0, in API level 23 it's called with different x
for different level.
So, what is the correct way to implement this method?
Current implementation is much like the original BulletSpan
:
@Override
public void drawLeadingMargin(Canvas c, Paint p, int x, int dir,
int top, int baseline, int bottom,
CharSequence text, int start, int end,
boolean first, Layout l) {
if (((Spanned) text).getSpanStart(this) == start) {
...
if (c.isHardwareAccelerated()) {
...
c.translate(x + dir * mBulletRadius,
(top + bottom) / 2.0f);
...
} else {
c.drawCircle(x + dir * mBulletRadius,
(top + bottom) / 2.0f, mBulletRadius, p);
}
...
}
...
}
Behaviour in API level 21:
o Level 1
o Level 2
o Level 3
o Level 3
o Level 2
Behaviour in API level 23:
o Level 1
o Level 2
o Level 3
o Level 3
o Level 2
Thanks in advance