From 04b92740d25676680a0abf0b320573a253d8c71a Mon Sep 17 00:00:00 2001 From: Rivu Chakraborty Date: Tue, 13 Nov 2018 16:29:50 +0530 Subject: [PATCH] Add custom typeface support Call `initPaints()` from onDraw to add support to runtime configuration changes --- .../bigbangbutton/editcodeview/EditCodeView.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/editcodeview/src/main/java/com/bigbangbutton/editcodeview/EditCodeView.java b/editcodeview/src/main/java/com/bigbangbutton/editcodeview/EditCodeView.java index bd30008..67cfef2 100644 --- a/editcodeview/src/main/java/com/bigbangbutton/editcodeview/EditCodeView.java +++ b/editcodeview/src/main/java/com/bigbangbutton/editcodeview/EditCodeView.java @@ -62,6 +62,7 @@ public class EditCodeView extends View private boolean codeHiddenMode; private boolean isSelected; private String codeHiddenMask; + private Typeface typeface; private Rect textBounds = new Rect(); private Runnable cursorAnimation = new Runnable() { @@ -180,7 +181,11 @@ private void initPaints() { textPaint = new Paint(); textPaint.setColor(textColor); textPaint.setTextSize(textSize); - textPaint.setTypeface(Typeface.create(Typeface.DEFAULT, fontStyle)); + if(typeface == null) { + textPaint.setTypeface(Typeface.create(Typeface.DEFAULT, fontStyle)); + } else { + textPaint.setTypeface(typeface); + } textPaint.setAntiAlias(true); underlinePaint = new Paint(); @@ -222,6 +227,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { @Override protected void onDraw(Canvas canvas) { + initPaints(); drawUnderline(canvas); drawText(canvas); } @@ -367,6 +373,11 @@ public void setTextColor(@ColorInt int colorId) { invalidate(); } + public void setTypeface(@NonNull Typeface typeface) { + this.typeface = typeface; + invalidate(); + } + public void setUnderlineStrokeWidth(float underlineStrokeWidth) { this.underlineStrokeWidth = underlineStrokeWidth; invalidate();