Android Typeface - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Typeface class.

This code example shows how to use the following methods:create, getStyle
 
        Typeface old = paint.getTypeface();
        if (old == null) {
            oldStyle = 0;
        } else { 
            oldStyle = old.getStyle();
        } 
 
        int want = oldStyle | style;
 
        Typeface tf;
        if (old == null) {
            tf = Typeface.defaultFromStyle(want);
        } else { 
            tf = Typeface.create(old, want);
        } 
 
        int fake = want & ~tf.getStyle();
 
        if ((fake & Typeface.BOLD) != 0) {
6
CodeRank
This code example shows how to use the following methods:create
 
    // create array of all std faces 
    private final Typeface[] mFaces = new Typeface[] {
        Typeface.create(Typeface.SANS_SERIF, 0),
        Typeface.create(Typeface.SANS_SERIF, 1),
        Typeface.create(Typeface.SERIF, 0),
        Typeface.create(Typeface.SERIF, 1),
        Typeface.create(Typeface.SERIF, 2),
        Typeface.create(Typeface.SERIF, 3),
        Typeface.create(Typeface.MONOSPACE, 0)
    }; 
     
    @SmallTest 
    public void testBasic() throws Exception { 
        assertTrue("basic", Typeface.DEFAULT != null);
        assertTrue("basic", Typeface.DEFAULT_BOLD != null);
        assertTrue("basic", Typeface.SANS_SERIF != null);
        assertTrue("basic", Typeface.SERIF != null);
        assertTrue("basic", Typeface.MONOSPACE != null);
    } 
6
CodeRank
This code example shows how to use the following methods:create, getStyle
        if (mTypeface != null || mStyle != 0) {
            Typeface tf = ds.getTypeface();
            int style = 0;
 
            if (tf != null) {
                style = tf.getStyle();
            } 
 
            style |= mStyle;
 
            if (mTypeface != null) {
                tf = Typeface.create(mTypeface, style);
            } else if (tf == null) {
                tf = Typeface.defaultFromStyle(style);
            } else { 
                tf = Typeface.create(tf, style);
            } 
 
            int fake = style & ~tf.getStyle();
 
            if ((fake & Typeface.BOLD) != 0) {
6
CodeRank
This code example shows how to use the following methods:getStyle
            oldStyle = 0;
        } else { 
            oldStyle = old.getStyle();
        } 
 
        int fake = oldStyle & ~aType.getStyle();
        if ( ( fake & Typeface.BOLD ) != 0 ) 
        { 
        	aPaint.setFakeBoldText( true );
        } 
 
        if ( ( fake & Typeface.ITALIC ) != 0 ) 
        { 
        	aPaint.setTextSkewX(-0.25f);
        } 
 
        aPaint.setTypeface( aType );
    } 
     
    private final Typeface mNewType;
5
CodeRank
This code example shows how to use the following methods:create
    @Override 
    protected void setupView(boolean isCenterView, int textSize) {
        setGravity(Gravity.CENTER);
        setTextColor(0xFF883333); 
        setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize);
        setTypeface(Typeface.SERIF);
 
        if (isCenterView) {
            setTypeface(Typeface.create(Typeface.SERIF, Typeface.BOLD));
            setBackgroundColor(0x55FFFFFF); 
            setShadowLayer(2.5f, 3, 3, 0xFF999999); 
        } 
    } 
} 
5
CodeRank
This code example shows how to use the following methods:getStyle
 
        Typeface old = paint.getTypeface();
        if (old == null) {
            oldStyle = 0;
        } else { 
            oldStyle = old.getStyle();
        } 
 
        Typeface tf = Typeface.create(family, oldStyle);
        int fake = oldStyle & ~tf.getStyle();
 
        if ((fake & Typeface.BOLD) != 0) {
            paint.setFakeBoldText(true);
        } 
 
        if ((fake & Typeface.ITALIC) != 0) {
            paint.setTextSkewX(-0.25f);
        } 
 
        paint.setTypeface(tf);
5
CodeRank
This code example shows how to use the following methods:setTypeface
 
	public static Typeface getTypeface(Context context, String typeface) {
		Typeface font = typefaceMap.get(typeface);
		if (font == null) {
			font = Typeface.createFromAsset(context.getAssets(), typeface);
			typefaceMap.put(typeface, font);
		} 
        return font; 
	} 
	 
	/** 
	 * Changes the size dimension to fit within the width/height ratio 
	 */ 
	public static void contain(Dimension size, int width, int height) {
		 
		if (width == 0 || height == 0) {
			size.setWidth(0);
			size.setHeight(0);
			return; 
		} 

5
CodeRank
This code example shows how to use the following methods:getStyle
                tf = Typeface.create(tf, style);
            } 
 
            setSwitchTypeface(tf);
            // now compute what (if any) algorithmic styling is needed 
            final int typefaceStyle = tf != null ? tf.getStyle() : 0;
            final int need = style & ~typefaceStyle;
            mTextPaint.setFakeBoldText((need & Typeface.BOLD) != 0);
            mTextPaint.setTextSkewX((need & Typeface.ITALIC) != 0 ? -0.25f : 0);
        } else { 
            mTextPaint.setFakeBoldText(false);
            mTextPaint.setTextSkewX(0);
            setSwitchTypeface(tf);
        } 
    } 
 
    /** 
     * Sets the typeface in which the text should be displayed on the switch. 
     * Note that not all Typeface families actually have bold and italic 
     * variants, so you may need to use {@link #setSwitchTypeface(Typeface, int)} to get the appearance 
5
CodeRank
This code example shows how to use the following methods:getStyle
        String title = " PS=" + mFontSize + " X="
                    + (1 + mTextScaleXDelta/SCALE_X_RANGE)
                    + " G=" + (mGamma/GAMMA_RANGE)
                    + " S=" + ((mColumn1.getPaintFlags() & Paint.SUBPIXEL_TEXT_FLAG) != 0 ? 1 : 0)
                    + " " + sTypefaceName[mFontIndex]
                    + " " + sStyleName[tf.getStyle()]
                    ; 
        setTitle(title);
    } 
     
    /** Called when it is time to initialize the activity state. */ 
    protected void onRestoreInstanceState(Bundle state) {
        super.onRestoreInstanceState(state);
    } 
 
    protected void onResume() { 
        super.onResume(); 
    } 
     
    private static final String sStyleName[] = {
5
CodeRank
This code example shows how to use the following methods:getStyle
				tf = Typeface.create(tf, style);
			} 
 
			setSwitchTypeface(tf);
			// now compute what (if any) algorithmic styling is needed 
			int typefaceStyle = tf != null ? tf.getStyle() : 0;
			int need = style & ~typefaceStyle;
			mTextPaint.setFakeBoldText((need & Typeface.BOLD) != 0);
			mTextPaint.setTextSkewX((need & Typeface.ITALIC) != 0 ? -0.25f : 0);
		} 
		else 
		{ 
			mTextPaint.setFakeBoldText(false);
			mTextPaint.setTextSkewX(0);
			setSwitchTypeface(tf);
		} 
	} 
 
	/** 
	 * Sets the typeface in which the text should be displayed on the switch. Note that not all Typeface families actually have bold and italic variants, so you may need to use 
5
CodeRank

Related Android Typeface Questions & Answers:

Other Android Typeface Examples

18:	        // Loading Font Face
19:	        Typeface tf = Typeface.createFromAsset(getAssets(), fontPath);
20:	
21:	        // Applying font
22:	        txtGhost.setTypeface(tf);

Read More

See Code Examples for Android Typeface Methods: