|
|
|
@ -23,6 +23,7 @@ import android.graphics.Canvas;
|
|
|
|
|
import android.graphics.Paint;
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
import android.text.Layout;
|
|
|
|
|
import android.text.Spanned;
|
|
|
|
|
import android.text.style.BulletSpan;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
@ -77,6 +78,53 @@ public class BulletSpanEx extends BulletSpan {
|
|
|
|
|
public void drawLeadingMargin(@NonNull Canvas canvas, @NonNull Paint paint, int x, int dir, int top, int baseline, int bottom, @NonNull CharSequence text, int start, int end, boolean first, @Nullable Layout layout) {
|
|
|
|
|
if ("none".equals(ltype))
|
|
|
|
|
return;
|
|
|
|
|
super.drawLeadingMargin(canvas, paint, x + indentWidth * (level + 1) * dir, dir, top, baseline, bottom, text, start, end, first, layout);
|
|
|
|
|
|
|
|
|
|
boolean mWantColor = false;
|
|
|
|
|
int mColor = 0; // STANDARD_COLOR
|
|
|
|
|
int mBulletRadius = 4; // STANDARD_BULLET_RADIUS
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
|
|
|
mWantColor = true;
|
|
|
|
|
mColor = getColor();
|
|
|
|
|
mBulletRadius = getBulletRadius();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (((Spanned) text).getSpanStart(this) == start) {
|
|
|
|
|
Paint.Style style = paint.getStyle();
|
|
|
|
|
int oldcolor = 0;
|
|
|
|
|
|
|
|
|
|
if (mWantColor) {
|
|
|
|
|
oldcolor = paint.getColor();
|
|
|
|
|
paint.setColor(mColor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
paint.setStyle(Paint.Style.FILL);
|
|
|
|
|
|
|
|
|
|
if (layout != null) {
|
|
|
|
|
// "bottom" position might include extra space as a result of line spacing
|
|
|
|
|
// configuration. Subtract extra space in order to show bullet in the vertical
|
|
|
|
|
// center of characters.
|
|
|
|
|
final int line = layout.getLineForOffset(start);
|
|
|
|
|
//bottom = bottom - layout.getLineExtra(line);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final float yPosition = (top + bottom) / 2f;
|
|
|
|
|
final float xPosition = x + dir * mBulletRadius;
|
|
|
|
|
|
|
|
|
|
if ("square".equals(ltype))
|
|
|
|
|
canvas.drawRect(
|
|
|
|
|
xPosition - mBulletRadius,
|
|
|
|
|
yPosition - mBulletRadius,
|
|
|
|
|
xPosition + mBulletRadius,
|
|
|
|
|
yPosition + mBulletRadius,
|
|
|
|
|
paint);
|
|
|
|
|
else
|
|
|
|
|
canvas.drawCircle(xPosition, yPosition, mBulletRadius, paint);
|
|
|
|
|
|
|
|
|
|
if (mWantColor) {
|
|
|
|
|
paint.setColor(oldcolor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
paint.setStyle(style);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|