Back to project page whoisit-android.
The source code is released under:
MIT License
If you think the Android project whoisit-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.mitchbarry.android.whoisit.ui.view; //from www . j a v a 2 s. co m import android.content.Context; import android.graphics.Typeface; import android.os.Build; import android.util.AttributeSet; import android.widget.Button; import com.mitchbarry.android.whoisit.util.Strings; import java.util.Locale; /** * A button who's text is always uppercase which uses the roboto font. * Inspired by {@link com.actionbarsherlock.internal.widget.CapitalizingTextView} */ public class CapitalizedTextView extends Button { private static final boolean SANS_ICE_CREAM = Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH; private static final boolean IS_GINGERBREAD = Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD; public CapitalizedTextView(Context context) { super( context ); if (!isInEditMode()) setTF( context ); } public CapitalizedTextView(Context context, AttributeSet attrs) { super( context, attrs ); if (!isInEditMode()) setTF(context); } public CapitalizedTextView(Context context, AttributeSet attrs, int defStyle) { super( context, attrs, defStyle ); if (!isInEditMode()) setTF(context); } @Override public void setText(CharSequence text, BufferType type) { if (IS_GINGERBREAD) { try { super.setText(text.toString().toUpperCase(Locale.ROOT), type); } catch (NoSuchFieldError e) { //Some manufacturer broke Locale.ROOT. See #572. super.setText(text.toString().toUpperCase(), type); } } else { super.setText(text.toString().toUpperCase(), type); } } private void setTF(Context context) { setTypeface( Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Regular.ttf") ); } }