Java Code Examples for android.text.TextPaint.getTypeface()

The following are Jave code examples for showing how to use getTypeface() of the android.text.TextPaint class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: AOSP-Kayboard-7.1.2   File: SuggestionStripLayoutHelper.java   Source Code and License Vote up 8 votes
private static int getTextWidth(@Nullable final CharSequence text, final TextPaint paint) {
    if (TextUtils.isEmpty(text)) {
        return 0;
    }
    final int length = text.length();
    final float[] widths = new float[length];
    final int count;
    final Typeface savedTypeface = paint.getTypeface();
    try {
        paint.setTypeface(getTextTypeface(text));
        count = paint.getTextWidths(text, 0, length, widths);
    } finally {
        paint.setTypeface(savedTypeface);
    }
    int width = 0;
    for (int i = 0; i < count; i++) {
        width += Math.round(widths[i] + 0.5f);
    }
    return width;
}
 
Example 2
Project: mongol-library   File: MongolTypefaceSpan.java   Source Code and License Vote up 6 votes
private void apply(TextPaint paint) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }
    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 3
Project: RNLearn_Project1   File: FontStylingSpan.java   Source Code and License Vote up 6 votes
private void updateTypeface(TextPaint ds) {
  Typeface typeface = ds.getTypeface();

  int oldStyle = (typeface == null) ? 0 : typeface.getStyle();
  int newStyle = getNewStyle(oldStyle);

  if (oldStyle == newStyle && mFontFamily == null) {
    // nothing to do
    return;
  }

  if (mFontFamily != null) {
    typeface = TypefaceCache.getTypeface(mFontFamily, newStyle);
  } else {
    typeface = TypefaceCache.getTypeface(typeface, newStyle);
  }

  ds.setTypeface(typeface);
}
 
Example 4
Project: RNLearn_Project1   File: FontStylingSpan.java   Source Code and License Vote up 6 votes
private void updateTypeface(TextPaint ds) {
  Typeface typeface = ds.getTypeface();

  int oldStyle = (typeface == null) ? 0 : typeface.getStyle();
  int newStyle = getNewStyle(oldStyle);

  if (oldStyle == newStyle && mFontFamily == null) {
    // nothing to do
    return;
  }

  if (mFontFamily != null) {
    typeface = TypefaceCache.getTypeface(mFontFamily, newStyle);
  } else {
    typeface = TypefaceCache.getTypeface(typeface, newStyle);
  }

  ds.setTypeface(typeface);
}
 
Example 5
Project: QuranKeyboard   File: CandidateView.java   Source Code and License Vote up 4 votes
/**
 * Construct a CandidateView for showing suggested words for completion.
 * @param context context
 */
public CandidateView(Context context) {
    super(context);
    mService = (QuranKeyboardIME) context;

    mSelectionHighlight = ContextCompat.getDrawable(context,
            android.R.drawable.list_selector_background);
    mSelectionHighlight.setState(new int[] {
            android.R.attr.state_enabled,
            android.R.attr.state_focused,
            android.R.attr.state_window_focused,
            android.R.attr.state_pressed
    });

    Resources r = context.getResources();
    
    setBackgroundColor(ContextCompat.getColor(context, R.color.candidate_background));
    
    mColorNormal = ContextCompat.getColor(context, R.color.candidate_normal);
    mColorRecommended = ContextCompat.getColor(context, R.color.candidate_recommended);
    mColorOther = ContextCompat.getColor(context, R.color.candidate_other);
    mVerticalPadding = r.getDimensionPixelSize(R.dimen.candidate_vertical_padding);

    mPaint = new TextPaint();
    mPaint.setColor(mColorNormal);
    mPaint.setAntiAlias(true);
    mPaint.setTextSize(r.getDimensionPixelSize(R.dimen.candidate_font_height));
    mPaint.setStrokeWidth(0);
    mDefaultTf = mPaint.getTypeface();
    mUthamniTf = mService.getUthmaniTypeFace();

    mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2,
                float distanceX, float distanceY) {
            mScrolled = true;
            int sx = getScrollX();
            sx += distanceX;
            if (sx < 0) {
                sx = 0;
            }
            if (sx + getWidth() > mTotalWidth) {                    
                sx -= distanceX;
            }
            mTargetScrollX = sx;
            scrollTo(sx, getScrollY());
            invalidate();
            return true;
        }
    });
    setHorizontalFadingEdgeEnabled(true);
    setWillNotDraw(false);
    setHorizontalScrollBarEnabled(false);
    setVerticalScrollBarEnabled(false);
}