Skip to content

Commit

Permalink
allow custom typeface
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean Wild committed Sep 29, 2016
1 parent b9d0f26 commit 33a91c9
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.Typeface;
import android.support.v4.content.ContextCompat;
import android.text.TextPaint;
import android.util.AttributeSet;
Expand Down Expand Up @@ -55,6 +56,8 @@ public class MarqueeTextView extends View {
int topOffset;
int xOffset;

Typeface customTypeface;

public static void setGlobalDefaultPauseDuration(int pauseDuration) {
DEFAULT_PAUSE_DURATION = pauseDuration;
}
Expand Down Expand Up @@ -133,7 +136,7 @@ protected void onDraw(Canvas canvas) {

float leftMargin = 0;

if(centerText){
if (centerText) {
leftMargin = (viewWidth - textWidth) / 2;
}

Expand Down Expand Up @@ -244,6 +247,10 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
paint.density = getResources().getDisplayMetrics().density;
paint.setTextSize(textSize);

if (customTypeface != null) {
paint.setTypeface(customTypeface);
}

height = (int) (Math.abs(paint.ascent()) + Math.abs(paint.descent()));
}

Expand All @@ -258,6 +265,10 @@ void renewPaint() {
textPaint.setTextSize(textSize);
textPaint.setColor(textColor);

if (customTypeface != null) {
textPaint.setTypeface(customTypeface);
}

int absEdgeEffectWidth = (getMeasuredWidth() / 100) * edgeEffectWidth;

Shader leftShader = new LinearGradient(
Expand Down Expand Up @@ -312,7 +323,7 @@ public void setText(CharSequence text) {
public CharSequence getText() {
return text;
}

public void setTextColor(int color) {
textColor = color;
renewPaint();
Expand Down Expand Up @@ -351,4 +362,8 @@ public void setEdgeEffectEnabled(boolean edgeEffectEnabled) {
invalidate();
}

public void setCustomTypeface(Typeface customTypeface) {
this.customTypeface = customTypeface;
}

}

0 comments on commit 33a91c9

Please sign in to comment.