I'm trying to fix a bug in our app, there is an option to quote a message, when you quote a message we need to add a quotation " with special styling (color and different font styling). The first quote is being added correctly but I need to add the second quote at the end of the text.
This is portion of the class that we are using to add manually "
public class ZMQuoteSpan extends MetricAffectingSpan {
...
@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 layout) {
Paint.Style style = p.getStyle();
int color = p.getColor();
boolean isFakeBoldText = p.isFakeBoldText();
Typeface oldTypeface = p.getTypeface();
Typeface typeface = Typeface.create(Typeface.DEFAULT, Typeface.ITALIC);
p.setTypeface(typeface);
p.setColor(QUOTE_SYSBOLM_COLOR);
p.setFakeBoldText(true);
float textSize = ZmUIUtils.px2sp(context, (int)p.getTextSize());
int spanStart = ((Spanned) text).getSpanStart(this);
int spanEnd = ((Spanned) text).getSpanEnd(this);
int y = layout.getLineBaseline(layout.getLineForOffset(spanStart));
int endY = layout.getLineBaseline(layout.getLineForOffset(spanEnd));
c.drawText("\"", x, y, p); //<---first quote this is working correctly
c.drawText("\"", textSize*text.length(), y, p); //<---second quote is not working correctly
p.setStyle(style);
p.setColor(color);
p.setFakeBoldText(isFakeBoldText);
p.setTypeface(oldTypeface);
}
I'm not sure how to find the position (x,y) where I need to add the second quotation, the textview could have also new lines (\n) as part of the text which means the y cord needs to be changed accordingly. I'm attaching an image on how the second quotation looks now with the current codesample