package com.mobimvp.cliques.ui.widgets;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;
import com.mobimvp.cliques.R;
import com.mobimvp.cliques.util.TypefaceManager;
public class FontTextView extends TextView {
public static final int FONT_ROBOTO_CONDENSED = 1;
public static final int FONT_ROBOTO_CONDENSED_LIGHT = 2;
public static final int FONT_ROBOTO_CONDENSED_BOLD = 3;
public static final int FONT_ROBOTO_CONDENSED_ITALIC = 4;
public static final int FONT_ROBOTO_CONDENSED_LIGHT_ITALIC = 5;
public static final int FONT_ROBOTO_CONDENSED_BOLD_ITALIC = 6;
TypefaceManager mTypefaceManager;
public FontTextView(Context context) {
this(context, null);
}
public FontTextView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public FontTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
if (!isInEditMode()) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FontTextView);
setFont(a.getInt(R.styleable.FontTextView_font, 0));
a.recycle();
}
}
public static Typeface getFont(TypefaceManager typefaceManager, final int customFont) {
Typeface typeface = null;
switch (customFont) {
case FONT_ROBOTO_CONDENSED:
typeface = typefaceManager.getRobotoCondensed();
break;
case FONT_ROBOTO_CONDENSED_LIGHT:
typeface = typefaceManager.getRobotoCondensedLight();
break;
case FONT_ROBOTO_CONDENSED_BOLD:
typeface = typefaceManager.getRobotoCondensedBold();
break;
case FONT_ROBOTO_CONDENSED_ITALIC:
typeface = typefaceManager.getRobotoCondensedItaltic();
break;
case FONT_ROBOTO_CONDENSED_LIGHT_ITALIC:
typeface = typefaceManager.getRobotoCondensedLightItaltic();
break;
case FONT_ROBOTO_CONDENSED_BOLD_ITALIC:
typeface = typefaceManager.getRobotoCondensedBoldItaltic();
break;
}
return typeface;
}
public void setFont(final int customFont) {
Typeface typeface = getFont(mTypefaceManager, customFont);
if (typeface != null) {
setPaintFlags(getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
setTypeface(typeface);
}
}
}