Created
October 13, 2014 13:55
-
-
Save lynfogeek/d5f5cb5101dd5831e737 to your computer and use it in GitHub Desktop.
A QuoteSpan-like Span with a customisable margin between the border and the text.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Arnaud CAMUS on 13/10/2014. | |
* | |
* Creates a QuoteSpan-like Span with a customisable margin between | |
* the border and the text. | |
*/ | |
public class QuoteWithMarginSpan implements LeadingMarginSpan, ParcelableSpan { | |
private static final int STRIPE_WIDTH = 2; | |
private int mMarginLeft; | |
private final int mColor; | |
public QuoteWithMarginSpan() { | |
super(); | |
mColor = 0xff0000ff; | |
mMarginLeft = 0; | |
} | |
public QuoteWithMarginSpan(int color) { | |
super(); | |
mColor = color; | |
mMarginLeft = 0; | |
} | |
public QuoteWithMarginSpan(int color, int margin) { | |
super(); | |
mColor = color; | |
mMarginLeft = margin; | |
} | |
public QuoteWithMarginSpan(Parcel src) { | |
mColor = src.readInt(); | |
mMarginLeft = 0; | |
} | |
private void setMarginLeft(int width) { | |
mMarginLeft = width; | |
} | |
public int getSpanTypeId() { | |
return 0; | |
} | |
public int describeContents() { | |
return 0; | |
} | |
public void writeToParcel(Parcel dest, int flags) { | |
dest.writeInt(mColor); | |
} | |
public int getColor() { | |
return mColor; | |
} | |
public int getLeadingMargin(boolean first) { | |
return STRIPE_WIDTH + mMarginLeft; | |
} | |
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(); | |
p.setStyle(Paint.Style.FILL); | |
p.setColor(mColor); | |
c.drawRect(x, top, x + dir + STRIPE_WIDTH, bottom, p); | |
p.setStyle(style); | |
p.setColor(color); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment