diff options
Diffstat (limited to 'src/main/java/de/pixart/messenger/ui/text')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/text/DividerSpan.java | 29 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/text/QuoteSpan.java | 52 |
2 files changed, 81 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/text/DividerSpan.java b/src/main/java/de/pixart/messenger/ui/text/DividerSpan.java new file mode 100644 index 000000000..672a267be --- /dev/null +++ b/src/main/java/de/pixart/messenger/ui/text/DividerSpan.java @@ -0,0 +1,29 @@ +package de.pixart.messenger.ui.text; + +import android.text.TextPaint; +import android.text.style.MetricAffectingSpan; + +public class DividerSpan extends MetricAffectingSpan { + + private static final float PROPORTION = 0.3f; + + private final boolean large; + + public DividerSpan(boolean large) { + this.large = large; + } + + public boolean isLarge() { + return large; + } + + @Override + public void updateDrawState(TextPaint tp) { + tp.setTextSize(tp.getTextSize() * PROPORTION); + } + + @Override + public void updateMeasureState(TextPaint p) { + p.setTextSize(p.getTextSize() * PROPORTION); + } +}
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/ui/text/QuoteSpan.java b/src/main/java/de/pixart/messenger/ui/text/QuoteSpan.java new file mode 100644 index 000000000..a24575509 --- /dev/null +++ b/src/main/java/de/pixart/messenger/ui/text/QuoteSpan.java @@ -0,0 +1,52 @@ +package de.pixart.messenger.ui.text; + +import android.graphics.Canvas; +import android.graphics.Paint; +import android.text.Layout; +import android.text.TextPaint; +import android.text.style.CharacterStyle; +import android.text.style.LeadingMarginSpan; +import android.util.DisplayMetrics; +import android.util.TypedValue; + +public class QuoteSpan extends CharacterStyle implements LeadingMarginSpan { + + private final int color; + + private final int width; + private final int paddingLeft; + private final int paddingRight; + + private static final float WIDTH_SP = 2f; + private static final float PADDING_LEFT_SP = 1.5f; + private static final float PADDING_RIGHT_SP = 8f; + + public QuoteSpan(int color, DisplayMetrics metrics) { + this.color = color; + this.width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, WIDTH_SP, metrics); + this.paddingLeft = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, PADDING_LEFT_SP, metrics); + this.paddingRight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, PADDING_RIGHT_SP, metrics); + } + + @Override + public void updateDrawState(TextPaint tp) { + tp.setColor(this.color); + } + + @Override + public int getLeadingMargin(boolean first) { + return paddingLeft + width + paddingRight; + } + + @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(); + p.setStyle(Paint.Style.FILL); + p.setColor(this.color); + c.drawRect(x + dir * paddingLeft, top, x + dir * (paddingLeft + width), bottom, p); + p.setStyle(style); + p.setColor(color); + } +}
\ No newline at end of file |