Example usage for android.graphics Typeface isBold

List of usage examples for android.graphics Typeface isBold

Introduction

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

Prototype

public final boolean isBold() 

Source Link

Document

Returns true if getStyle() has the BOLD bit set.

Usage

From source file:Main.java

public static String getDefaultFontWeight(Context context) {
    String style = "normal";
    TextView tv = new TextView(context);
    if (tv != null) {
        Typeface tf = tv.getTypeface();
        if (tf != null && tf.isBold()) {
            style = "bold";
        }//  w  ww  .  ja va2 s  .  c  o m
    }

    return style;
}

From source file:Main.java

private static String getFontName(String fontType, Typeface typeface) {
    if (fontType == null)
        if (typeface == null)
            return "Roboto-Regular";
        else if (typeface.isBold() && typeface.isItalic())
            return "Roboto-BoldItalic";
        else if (typeface.isBold())
            return "Roboto-Bold";
        else if (typeface.isItalic())
            return "Roboto-Italic";
        else/*from ww  w .  ja  v  a2  s. com*/
            return "Roboto-Regular";
    else if (fontType.equals("roboto-light"))
        if (typeface == null)
            return "Roboto-Light";
        else if (typeface.isItalic())
            return "Roboto-LightItalic";
        else
            return "Roboto-Light";
    else if (fontType.equals("roboto-condensed"))
        if (typeface == null)
            return "RobotoCondensed-Regular";
        else if (typeface.isBold() && typeface.isItalic())
            return "RobotoCondensed-BoldItalic";
        else if (typeface.isBold())
            return "RobotoCondensed-Bold";
        else if (typeface.isItalic())
            return "RobotoCondensed-Italic";
        else
            return "RobotoCondensed-Regular";
    else if (fontType.equals("roboto-slab"))
        if (typeface == null)
            return "RobotoSlab-Regular";
        else if (typeface.isBold())
            return "RobotoSlab-Bold";
        else
            return "RobotoSlab-Regular";
    else if (fontType.equals("roboto-slab-light"))
        return "RobotoSlab-Light";
    else if (fontType.equals("roboto-slab-thin"))
        return "RobotoSlab-Thin";
    else if (fontType.equals("roboto-condensed-light"))
        if (typeface == null)
            return "RobotoCondensed-Light";
        else if (typeface.isItalic())
            return "RobotoCondensed-LightItalic";
        else
            return "RobotoCondensed-Light";
    else if (fontType.equals("roboto-thin"))
        if (typeface == null)
            return "Roboto-Thin";
        else if (typeface.isItalic())
            return "Roboto-ThinItalic";
        else
            return "Roboto-Thin";
    else if (fontType.equals("roboto-medium"))
        if (typeface == null)
            return "Roboto-Medium";
        else if (typeface.isItalic())
            return "Roboto-MediumItalic";
        else
            return "Roboto-Medium";
    else if (typeface == null)
        return "Roboto-Regular";
    else if (typeface.isBold() && typeface.isItalic())
        return "Roboto-BoldItalic";
    else if (typeface.isBold())
        return "Roboto-Bold";
    else if (typeface.isItalic())
        return "Roboto-Italic";
    else
        return "Roboto-Regular";
}

From source file:com.facebook.appevents.codeless.internal.ViewHierarchy.java

public static JSONObject setAppearanceOfView(View view, JSONObject json, float displayDensity) {
    try {//from www.  j  a v  a2  s . c  om
        JSONObject textStyle = new JSONObject();
        if (view instanceof TextView) {
            TextView textView = (TextView) view;
            Typeface typeface = textView.getTypeface();
            if (typeface != null) {
                textStyle.put(TEXT_SIZE, textView.getTextSize());
                textStyle.put(TEXT_IS_BOLD, typeface.isBold());
                textStyle.put(TEXT_IS_ITALIC, typeface.isItalic());
                json.put(TEXT_STYLE, textStyle);
            }
        }
        if (view instanceof ImageView) {
            Drawable drawable = ((ImageView) view).getDrawable();
            if (drawable instanceof BitmapDrawable) {
                if (view.getHeight() / displayDensity <= ICON_MAX_EDGE_LENGTH
                        && view.getWidth() / displayDensity <= ICON_MAX_EDGE_LENGTH) {
                    Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                    bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
                    byte[] byteArray = byteArrayOutputStream.toByteArray();
                    String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
                    json.put(ICON_BITMAP, encoded);
                }
            }
        }
    } catch (JSONException e) {
        Utility.logd(TAG, e);
    }

    return json;
}

From source file:org.appcelerator.titanium.util.TiUIHelper.java

public static String getDefaultFontWeight(final Context context) {
    String style = "normal";
    TextView tv = new TextView(context);
    if (tv != null) {
        Typeface tf = tv.getTypeface();
        if (tf != null && tf.isBold()) {
            style = "bold";
        }/*from  w  ww.  j av  a  2  s  .com*/
    }

    return style;
}

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

@Override
public Object loadTrueTypeFont(String fontName, String fileName) {
    if (fontName.startsWith("native:")) {
        Typeface t = fontToRoboto(fontName);
        int fontStyle = com.codename1.ui.Font.STYLE_PLAIN;
        if (t.isBold()) {
            fontStyle |= com.codename1.ui.Font.STYLE_BOLD;
        }//from www .  j  av a2 s.com
        if (t.isItalic()) {
            fontStyle |= com.codename1.ui.Font.STYLE_ITALIC;
        }
        CodenameOneTextPaint newPaint = new CodenameOneTextPaint(t);
        newPaint.setAntiAlias(true);
        newPaint.setSubpixelText(true);
        return new NativeFont(com.codename1.ui.Font.FACE_SYSTEM, fontStyle, com.codename1.ui.Font.SIZE_MEDIUM,
                newPaint, fileName, 0, 0);
    }
    Typeface t = Typeface.createFromAsset(getContext().getAssets(), fileName);
    if (t == null) {
        throw new RuntimeException("Font not found: " + fileName);
    }
    CodenameOneTextPaint newPaint = new CodenameOneTextPaint(t);
    newPaint.setAntiAlias(true);
    newPaint.setSubpixelText(true);
    return new NativeFont(com.codename1.ui.Font.FACE_SYSTEM, com.codename1.ui.Font.STYLE_PLAIN,
            com.codename1.ui.Font.SIZE_MEDIUM, newPaint, fileName, 0, 0);
}

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

@Override
public Object deriveTrueTypeFont(Object font, float size, int weight) {
    NativeFont fnt = (NativeFont) font;//from   ww  w.j  a v  a 2s  .  c  o m
    CodenameOneTextPaint paint = (CodenameOneTextPaint) fnt.font;
    paint.setAntiAlias(true);
    Typeface type = paint.getTypeface();
    int fontstyle = Typeface.NORMAL;
    if ((weight & Font.STYLE_BOLD) != 0 || type.isBold()) {
        fontstyle |= Typeface.BOLD;
    }
    if ((weight & Font.STYLE_ITALIC) != 0 || type.isItalic()) {
        fontstyle |= Typeface.ITALIC;
    }
    type = Typeface.create(type, fontstyle);
    CodenameOneTextPaint newPaint = new CodenameOneTextPaint(type);
    newPaint.setTextSize(size);
    newPaint.setAntiAlias(true);
    NativeFont n = new NativeFont(com.codename1.ui.Font.FACE_SYSTEM, weight, com.codename1.ui.Font.SIZE_MEDIUM,
            newPaint, fnt.fileName, size, weight);
    return n;
}