Java Code Examples for android.graphics.Typeface#BOLD

The following examples show how to use android.graphics.Typeface#BOLD . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextUtils.java    From glimmr with Apache License 2.0 6 votes vote down vote up
private void applyCustomTypeface(Paint paint, Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    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);
}
 
Example 2
Source File: CustomTypefaceSpan.java    From Expert-Android-Programming with MIT License 6 votes vote down vote up
private static void applyCustomTypeFace(Paint paint, Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    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);
}
 
Example 3
Source File: SVGAndroidRenderer.java    From starcor.xul with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Typeface  checkGenericFont(String fontName, Integer fontWeight, FontStyle fontStyle)
{
   Typeface font = null;
   int      typefaceStyle;

   boolean  italic = (fontStyle == Style.FontStyle.Italic);
   typefaceStyle = (fontWeight > 500) ? (italic ? Typeface.BOLD_ITALIC : Typeface.BOLD)
                                      : (italic ? Typeface.ITALIC : Typeface.NORMAL);

   if (fontName.equals("serif")) {
      font = Typeface.create(Typeface.SERIF, typefaceStyle);
   } else if (fontName.equals("sans-serif")) {
      font = Typeface.create(Typeface.SANS_SERIF, typefaceStyle);
   } else if (fontName.equals("monospace")) {
      font = Typeface.create(Typeface.MONOSPACE, typefaceStyle);
   } else if (fontName.equals("cursive")) {
      font = Typeface.create(Typeface.SANS_SERIF, typefaceStyle);
   } else if (fontName.equals("fantasy")) {
      font = Typeface.create(Typeface.SANS_SERIF, typefaceStyle);
   }
   return font;
}
 
Example 4
Source File: TypefaceSpan.java    From JotaTextEditor with Apache License 2.0 6 votes vote down vote up
private static void apply(Paint paint, String family) {
    int oldStyle;

    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);
}
 
Example 5
Source File: SpannableStringUtils.java    From DevUtils with Apache License 2.0 6 votes vote down vote up
private void apply(final Paint paint, final Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    int fake = oldStyle & ~tf.getStyle();
    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.getShader();
    paint.setTypeface(tf);
}
 
Example 6
Source File: IconicsTypefaceSpan.java    From clear-todolist with GNU General Public License v3.0 6 votes vote down vote up
private static void applyCustomTypeFace(Paint paint, Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    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);
}
 
Example 7
Source File: TypefaceManager.java    From Android-Font-Library with The Unlicense 5 votes vote down vote up
/**
 * Converts a style constant from {@link Typeface} to a style constant from the {@link
 * TypefaceManager}.
 *
 * @param typefaceStyle A style from the constants in Typeface
 * @return The corresponding internal style
 */
private static byte toInternalStyle(int typefaceStyle) {
	switch (typefaceStyle) {
		//@formatter:off
		case Typeface.NORMAL:      return REGULAR;
		case Typeface.BOLD:        return BOLD;
		case Typeface.ITALIC:      return ITALIC;
		case Typeface.BOLD_ITALIC: return BOLD_ITALIC;
		default:                   return INVALID;
		//@formatter:on
	}
}
 
Example 8
Source File: TextAppearanceSpan.java    From JotaTextEditor with Apache License 2.0 5 votes vote down vote up
@Override
public void updateMeasureState(TextPaint ds) {
    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) {
            ds.setFakeBoldText(true);
        }

        if ((fake & Typeface.ITALIC) != 0) {
            ds.setTextSkewX(-0.25f);
        }

        ds.setTypeface(tf);
    }

    if (mTextSize > 0) {
        ds.setTextSize(mTextSize);
    }
}
 
Example 9
Source File: SearchBookContentsListItem.java    From ZXing-Standalone-library with Apache License 2.0 5 votes vote down vote up
public void set(SearchBookContentsResult result) {
  pageNumberView.setText(result.getPageNumber());
  String snippet = result.getSnippet();
  if (snippet.isEmpty()) {
    snippetView.setText("");
  } else {
    if (result.getValidSnippet()) {
      String lowerQuery = SearchBookContentsResult.getQuery().toLowerCase(Locale.getDefault());
      String lowerSnippet = snippet.toLowerCase(Locale.getDefault());
      Spannable styledSnippet = new SpannableString(snippet);
      StyleSpan boldSpan = new StyleSpan(Typeface.BOLD);
      int queryLength = lowerQuery.length();
      int offset = 0;
      while (true) {
        int pos = lowerSnippet.indexOf(lowerQuery, offset);
        if (pos < 0) {
          break;
        }
        styledSnippet.setSpan(boldSpan, pos, pos + queryLength, 0);
        offset = pos + queryLength;
      }
      snippetView.setText(styledSnippet);
    } else {
      // This may be an error message, so don't try to bold the query terms within it
      snippetView.setText(snippet);
    }
  }
}
 
Example 10
Source File: CalligraphyTypefaceSpan.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private void apply(final Paint paint) {
    final Typeface oldTypeface = paint.getTypeface();
    final int oldStyle = oldTypeface != null ? oldTypeface.getStyle() : 0;
    final int fakeStyle = oldStyle & ~typeface.getStyle();

    if ((fakeStyle & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fakeStyle & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(typeface);
}
 
Example 11
Source File: TickerView.java    From ticker with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the typeface size used by this view.
 *
 * @param typeface the typeface to use on the text.
 */
public void setTypeface(Typeface typeface) {
    if (textStyle == Typeface.BOLD_ITALIC) {
        typeface = Typeface.create(typeface, Typeface.BOLD_ITALIC);
    } else if (textStyle == Typeface.BOLD) {
        typeface = Typeface.create(typeface, Typeface.BOLD);
    } else if (textStyle == Typeface.ITALIC) {
        typeface = Typeface.create(typeface, Typeface.ITALIC);
    }

    textPaint.setTypeface(typeface);
    onTextPaintMeasurementChanged();
}
 
Example 12
Source File: SearchBookContentsListItem.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
public void set(SearchBookContentsResult result) {
  pageNumberView.setText(result.getPageNumber());
  String snippet = result.getSnippet();
  if (snippet.isEmpty()) {
    snippetView.setText("");
  } else {
    if (result.getValidSnippet()) {
      String lowerQuery = SearchBookContentsResult.getQuery().toLowerCase(Locale.getDefault());
      String lowerSnippet = snippet.toLowerCase(Locale.getDefault());
      Spannable styledSnippet = new SpannableString(snippet);
      StyleSpan boldSpan = new StyleSpan(Typeface.BOLD);
      int queryLength = lowerQuery.length();
      int offset = 0;
      while (true) {
        int pos = lowerSnippet.indexOf(lowerQuery, offset);
        if (pos < 0) {
          break;
        }
        styledSnippet.setSpan(boldSpan, pos, pos + queryLength, 0);
        offset = pos + queryLength;
      }
      snippetView.setText(styledSnippet);
    } else {
      // This may be an error message, so don't try to bold the query terms within it
      snippetView.setText(snippet);
    }
  }
}
 
Example 13
Source File: Style.java    From SuperToasts with Apache License 2.0 5 votes vote down vote up
/**
 * Public constructor for a new {@link com.github.johnpersano.supertoasts.library.Style}.
 * This constructor will assign a few default values.
 */
public Style() {
    // General SuperToast items
    this.duration = DURATION_MEDIUM;
    this.color = PaletteUtils.getSolidColor(PaletteUtils.MATERIAL_GREY);
    this.gravity = Gravity.BOTTOM | Gravity.CENTER;
    this.yOffset = BackgroundUtils.convertToDIP(64);
    this.width = FrameLayout.LayoutParams.WRAP_CONTENT;
    this.height = FrameLayout.LayoutParams.WRAP_CONTENT;
    this.priorityLevel = PRIORITY_MEDIUM;

    // Message TextView items
    this.messageTypefaceStyle = Typeface.NORMAL;
    this.messageTextColor = PaletteUtils.getSolidColor(PaletteUtils.WHITE);
    this.messageTextSize = TEXTSIZE_SMALL;
    this.messageIconPosition = ICONPOSITION_LEFT;

    // SuperActivityToast Button items
    this.buttonTypefaceStyle = Typeface.BOLD;
    this.buttonTextColor = PaletteUtils.getSolidColor(PaletteUtils.WHITE);
    this.buttonTextSize = TEXTSIZE_VERY_SMALL;
    this.buttonDividerColor = PaletteUtils.getSolidColor(PaletteUtils.WHITE);

    //SuperActivityToast Progress items
    this.progressBarColor = PaletteUtils.getSolidColor(PaletteUtils.WHITE);
    this.progressIndeterminate = true;
}
 
Example 14
Source File: AndroidEmoji.java    From Emoji with Apache License 2.0 5 votes vote down vote up
private void apply(final Paint paint) {
	final Typeface oldTypeface = paint.getTypeface();
	final int oldStyle = oldTypeface != null ? oldTypeface.getStyle() : 0;
	final int fakeStyle = oldStyle & ~mTypeface.getStyle();
	
	if ((fakeStyle & Typeface.BOLD) != 0) {
		paint.setFakeBoldText(true);
	}
	
	if ((fakeStyle & Typeface.ITALIC) != 0) {
		paint.setTextSkewX(-0.25f);
	}
	
	paint.setTypeface(mTypeface);
}
 
Example 15
Source File: KnifeText.java    From Knife with Apache License 2.0 5 votes vote down vote up
protected boolean containStyle(int style, int start, int end) {
    switch (style) {
        case Typeface.NORMAL:
        case Typeface.BOLD:
        case Typeface.ITALIC:
        case Typeface.BOLD_ITALIC:
            break;
        default:
            return false;
    }

    if (start > end) {
        return false;
    }

    if (start == end) {
        if (start - 1 < 0 || start + 1 > getEditableText().length()) {
            return false;
        } else {
            StyleSpan[] before = getEditableText().getSpans(start - 1, start, StyleSpan.class);
            StyleSpan[] after = getEditableText().getSpans(start, start + 1, StyleSpan.class);
            return before.length > 0 && after.length > 0 && before[0].getStyle() == style && after[0].getStyle() == style;
        }
    } else {
        StringBuilder builder = new StringBuilder();

        // Make sure no duplicate characters be added
        for (int i = start; i < end; i++) {
            StyleSpan[] spans = getEditableText().getSpans(i, i + 1, StyleSpan.class);
            for (StyleSpan span : spans) {
                if (span.getStyle() == style) {
                    builder.append(getEditableText().subSequence(i, i + 1).toString());
                    break;
                }
            }
        }

        return getEditableText().subSequence(start, end).toString().equals(builder.toString());
    }
}
 
Example 16
Source File: BidiInfoActivity.java    From Tehreer-Android with Apache License 2.0 4 votes vote down vote up
private Object[] spansFirstHeading() {
    return new Object[] {
        new AbsoluteSizeSpan((int) (20.0f * mDensity + 0.5f)),
        new StyleSpan(Typeface.BOLD)
    };
}
 
Example 17
Source File: PredefMacros.java    From AndroidMathKeyboard with Apache License 2.0 4 votes vote down vote up
public static final Atom jlmTextitbf_macro(final TeXParser tp,
		final String[] args) throws ParseException {
	return new JavaFontRenderingAtom(args[1], Typeface.BOLD
			| Typeface.ITALIC);
}
 
Example 18
Source File: BoldStyleSpan.java    From RichEditor with MIT License 4 votes vote down vote up
public BoldStyleSpan() {
    super(Typeface.BOLD);
    type = RichTypeEnum.BOLD;
}
 
Example 19
Source File: PredefMacros.java    From FlexibleRichTextView with Apache License 2.0 4 votes vote down vote up
public static final Atom jlmTextitbf_macro(final TeXParser tp,
		final String[] args) throws ParseException {
	return new JavaFontRenderingAtom(args[1], Typeface.BOLD
			| Typeface.ITALIC);
}
 
Example 20
Source File: AMeter.java    From Stylish-Widget-for-Android with Apache License 2.0 4 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
private void setCustomAttr(Context context, AttributeSet attrs) {

    initView();


    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.meterAttr);

    setMeterColor(a.getColor(R.styleable.meterAttr_sw_meterColor, Color.WHITE));
    setShowNeedle(a.getBoolean(R.styleable.meterAttr_sw_showNeedle, true));
    setLineWidth(a.getFloat(R.styleable.meterAttr_sw_lineWidth, 1f));
    setLineStrokeSize(a.getDimension(R.styleable.meterAttr_sw_lineStrokeSize, Utils.convertDpToPixel(10)));
    a.recycle();

    a = getContext().obtainStyledAttributes(attrs, R.styleable.textAttr);

    setTextSize(a.getDimension(R.styleable.textAttr_sw_textSize,
            getResources().getDimension(R.dimen.meterTextSize)));

    int textStyle;
    try {
        textStyle = a.getInt(R.styleable.textAttr_sw_textStyle, Typeface.BOLD);
    } catch (Exception e) {
        textStyle = Typeface.BOLD;
    }

    setTextStyle(textStyle);

    a.recycle();


    a = getContext().obtainStyledAttributes(attrs, R.styleable.constraintAttr);
    setShowText(a.getBoolean(R.styleable.constraintAttr_sw_showText, true));
    setValue(a.getFloat(R.styleable.constraintAttr_sw_value, 0f));
    setStartValue(a.getFloat(R.styleable.constraintAttr_sw_startValue, 0f));
    setMaxValue(a.getFloat(R.styleable.constraintAttr_sw_maxValue, 1f));
    setNumberOfLine(a.getInt(R.styleable.constraintAttr_sw_numberOfLine, 1));
    setUnit(a.getString(R.styleable.constraintAttr_sw_unit));

    a.recycle();

}