Example usage for android.graphics Typeface BOLD_ITALIC

List of usage examples for android.graphics Typeface BOLD_ITALIC

Introduction

In this page you can find the example usage for android.graphics Typeface BOLD_ITALIC.

Prototype

int BOLD_ITALIC

To view the source code for android.graphics Typeface BOLD_ITALIC.

Click Source Link

Usage

From source file:com.codename1.impl.android.AndroidImplementation.java

private Typeface fontToRoboto(String fontName) {
    if ("native:MainThin".equals(fontName)) {
        return Typeface.create("sans-serif-thin", Typeface.NORMAL);
    }/*from  w  ww. j a va2  s . co m*/
    if ("native:MainLight".equals(fontName)) {
        return Typeface.create("sans-serif-light", Typeface.NORMAL);
    }
    if ("native:MainRegular".equals(fontName)) {
        return Typeface.create("sans-serif", Typeface.NORMAL);
    }

    if ("native:MainBold".equals(fontName)) {
        return Typeface.create("sans-serif-condensed", Typeface.BOLD);
    }

    if ("native:MainBlack".equals(fontName)) {
        return Typeface.create("sans-serif-black", Typeface.BOLD);
    }

    if ("native:ItalicThin".equals(fontName)) {
        return Typeface.create("sans-serif-thin", Typeface.ITALIC);
    }

    if ("native:ItalicLight".equals(fontName)) {
        return Typeface.create("sans-serif-thin", Typeface.ITALIC);
    }

    if ("native:ItalicRegular".equals(fontName)) {
        return Typeface.create("sans-serif", Typeface.ITALIC);
    }

    if ("native:ItalicBold".equals(fontName)) {
        return Typeface.create("sans-serif-condensed", Typeface.BOLD_ITALIC);
    }

    if ("native:ItalicBlack".equals(fontName)) {
        return Typeface.create("sans-serif-black", Typeface.BOLD_ITALIC);
    }

    throw new IllegalArgumentException("Unsupported native font type: " + fontName);
}

From source file:com.codename1.impl.android.AndroidImplementation.java

/**
 * Loads a native font based on a lookup for a font name and attributes.
 * Font lookup values can be separated by commas and thus allow fallback if
 * the primary font isn't supported by the platform.
 *
 * @param lookup string describing the font
 * @return the native font object/*from   w ww .  j  ava  2  s .c  om*/
 */
public Object loadNativeFont(String lookup) {
    try {
        lookup = lookup.split(";")[0];
        int typeface = Typeface.NORMAL;
        String familyName = lookup.substring(0, lookup.indexOf("-"));
        String style = lookup.substring(lookup.indexOf("-") + 1, lookup.lastIndexOf("-"));
        String size = lookup.substring(lookup.lastIndexOf("-") + 1, lookup.length());

        if (style.equals("bolditalic")) {
            typeface = Typeface.BOLD_ITALIC;
        } else if (style.equals("italic")) {
            typeface = Typeface.ITALIC;
        } else if (style.equals("bold")) {
            typeface = Typeface.BOLD;
        }
        Paint font = new CodenameOneTextPaint(Typeface.create(familyName, typeface));
        font.setAntiAlias(true);
        font.setTextSize(Integer.parseInt(size));
        return new NativeFont(0, 0, 0, font);
    } catch (Exception err) {
        return null;
    }
}