If you think the Android project sms-smap-gateway listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.android.smap.ui.views;
//fromwww.java2s.comimport android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.TextView;
import com.android.smap.R;
import com.android.smap.utils.MWAssetsUtils;
/**
* TextView implementation for setting the custom font in resources.<br/>
* The font has to be set in the in styles.xml using the customTextFont
* attribute. <br/>
* This class checks if the font file is inside "assets/fonts/" and if the font
* is present initializes the text with the specified font.
*
* @author Matt Witherow
*/publicclass FontableTextView extends TextView {
public FontableTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setCustomFont(context, attrs);
}
public FontableTextView(Context context, AttributeSet attrs) {
super(context, attrs);
setCustomFont(context, attrs);
}
public FontableTextView(Context context) {
super(context);
}
privatevoid setCustomFont(Context ctx, AttributeSet attrs) {
TypedArray a = ctx.obtainStyledAttributes(attrs,
R.styleable.MWCustomFontView);
String customFont = a
.getString(R.styleable.MWCustomFontView_customFont);
String editorText = a
.getString(R.styleable.MWCustomFontView_editorText);
if (isInEditMode()) {
// set editor text value
if (!TextUtils.isEmpty(editorText)) {
setText(editorText);
} else {
setText(FontableTextView.class.getSimpleName());
}
} else {
// set font only when not in editor mode
setCustomAssetFont(customFont);
}
a.recycle();
setPaintFlags(getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
/**
* @param ctx
* @param font
* @return
*/publicboolean setCustomAssetFont(String font) {
Context ctx = getContext();
Typeface tf = MWAssetsUtils.getCachedFont(ctx, font);
// check if could not find font
if (tf == null) {
return false;
}
setTypeface(tf);
return true;
}
}