Java Code Examples for android.graphics.Paint.setTypeface()

The following are Jave code examples for showing how to use setTypeface() of the android.graphics.Paint class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: FlexibleRichTextView   File: JavaFontRenderingBox.java   View Source Code Vote up 6 votes
public void draw(Canvas g2, float x, float y) {
		drawDebug(g2, x, y);
//		Paint st=AjLatexMath.getPaint();
//		st.setTextSize(AjLatexMath.getTextSize());
		Paint st =new Paint();
		float w = st.getStrokeWidth();
		Style s = st.getStyle();
		Typeface f = st.getTypeface();
		st.setStrokeWidth(0);//
		st.setStyle(Style.FILL_AND_STROKE);
		st.setTypeface(font);
		g2.save();
		g2.translate(x, y);
		g2.scale(0.5f * size, 0.5f * size);
//		g2.drawText(str, x, y, st);
		g2.drawText(str, 0, 0, st);
		g2.restore();
		st.setStyle(s);
		st.setStrokeWidth(w);
		st.setTypeface(f);
	}
 
Example 2
Project: com.ruuvi.station   File: Utils.java   View Source Code Vote up 6 votes
public static Bitmap createBall(int radius, int ballColor, int letterColor, String letter) {
    letter = letter.toUpperCase();
    Bitmap bitmap = Bitmap.createBitmap(radius*2, radius*2, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint paint2 = new Paint();
    paint2.setColor(ballColor);
    canvas.drawCircle(radius, radius, (float) radius, paint2);
    Paint paint = new Paint();
    paint.setColor(letterColor);
    paint.setTextSize(120);
    paint.setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL));

    Rect textBounds = new Rect();
    paint.getTextBounds(letter, 0, letter.length(), textBounds);
    canvas.drawText(letter, radius - textBounds.exactCenterX(), radius - textBounds.exactCenterY(), paint);
    return bitmap;
}
 
Example 3
Project: EsperantoRadio   File: EgenTypefaceSpan.java   View Source Code Vote up 6 votes
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 4
Project: DeviceInfo   File: CustomTypefaceSpan.java   View Source Code Vote up 6 votes
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 5
Project: CommentView   File: TextCell.java   View Source Code Vote up 6 votes
protected float c(Paint paint) {
    float f = 0.0f;
    if (!TextUtils.isEmpty(this.text)) {
        Typeface d = d(paint);
        if ((this.useDefaultFont || !this.useHanyiColorFont) && (paint instanceof ETPaint)) {
            paint = ((ETPaint) paint).a();
        }
        int length = this.text.length();
        int i = 0;
        while (i < length) {
            int charCount = Character.charCount(this.text.codePointAt(i));
            float measureText = paint.measureText(this.text, i, i + charCount) + f;
            i += charCount;
            f = measureText;
        }
        if (d != null) {
            paint.setTypeface(d);
        }
    }
    return f;
}
 
Example 6
Project: starcor.xul   File: XulRenderContext.java   View Source Code Vote up 6 votes
static public Paint getShadowTextPaintByName(String name) {
	if (name == null) {
		return getDefShadowTextPaint();
	}
	TypefaceInfo typefaceInfo = _font_map.get(name);
	if (typefaceInfo == null) {
		return getDefShadowTextPaint();
	}
	Paint paint = typefaceInfo.paint;
	if (paint == null) {
		typefaceInfo.paint = paint = new Paint();
		paint.setTypeface(typefaceInfo.typeface);
		paint.setAntiAlias(true);
		paint.setSubpixelText(true);
		paint.setShadowLayer(3, 0, 0, Color.BLACK);
	}
	return paint;
}
 
Example 7
Project: NeoTerm   File: TabSwitcherDrawable.java   View Source Code Vote up 6 votes
/**
 * Creates a new drawable, which allows to display the number of tabs, which are currently
 * contained by a {@link TabSwitcher}.
 *
 * @param context
 *         The context, which should be used by the drawable, as an instance of the class {@link
 *         Context}. The context may not be null
 */
public TabSwitcherDrawable(@NonNull final Context context) {
    ensureNotNull(context, "The context may not be null");
    Resources resources = context.getResources();
    size = resources.getDimensionPixelSize(R.dimen.tab_switcher_drawable_size);
    textSizeNormal =
            resources.getDimensionPixelSize(R.dimen.tab_switcher_drawable_font_size_normal);
    textSizeSmall =
            resources.getDimensionPixelSize(R.dimen.tab_switcher_drawable_font_size_small);
    background =
            ContextCompat.getDrawable(context, R.drawable.tab_switcher_drawable_background)
                    .mutate();
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.WHITE);
    paint.setTextAlign(Align.CENTER);
    paint.setTextSize(textSizeNormal);
    paint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
    label = Integer.toString(0);
    int tint = ThemeUtil.getColor(context, android.R.attr.textColorPrimary);
    setColorFilter(tint, PorterDuff.Mode.MULTIPLY);
}
 
Example 8
Project: CXJPadProject   File: WheelView.java   View Source Code Vote up 6 votes
private void initPaints() {
    paintOuterText = new Paint();
    paintOuterText.setAntiAlias(true);
    paintOuterText.setColor(textColorOuter);
    paintOuterText.setTypeface(typeface);
    paintOuterText.setTextSize(textSize);
    paintCenterText = new Paint();
    paintCenterText.setAntiAlias(true);
    paintCenterText.setColor(textColorCenter);
    paintCenterText.setTextScaleX(1.1F);
    paintCenterText.setTypeface(typeface);
    paintCenterText.setTextSize(textSize);
    paintIndicator = new Paint();
    paintIndicator.setAntiAlias(true);
    paintIndicator.setColor(dividerConfig.color);
    paintIndicator.setStrokeWidth(dividerConfig.thick);
    paintIndicator.setAlpha(dividerConfig.alpha);
    paintShadow = new Paint();
    paintShadow.setAntiAlias(true);
    paintShadow.setColor(dividerConfig.shadowColor);
    paintShadow.setAlpha(dividerConfig.shadowAlpha);
    setLayerType(LAYER_TYPE_SOFTWARE, null);
}
 
Example 9
Project: XERUNG   File: BadgeDrawable.java   View Source Code Vote up 5 votes
public BadgeDrawable(Context context) {
    mTextSize = 15F;
    myColor = context.getResources().getColor(R.color.theme_primary_dark_badge);
    mBadgePaint = new Paint();
    mBadgePaint.setColor(myColor);
    mBadgePaint.setAntiAlias(true);
    mBadgePaint.setStyle(Paint.Style.FILL);

    mTextPaint = new Paint();
    mTextPaint.setColor(Color.YELLOW);
    mTextPaint.setTypeface(Typeface.DEFAULT_BOLD);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setAntiAlias(true);
    mTextPaint.setTextAlign(Paint.Align.CENTER);
}
 
Example 10
Project: GoUbiquitous   File: DigitalWatchFaceService.java   View Source Code Vote up 5 votes
private Paint createTextPaint(int textColor) {
    Paint paint = new Paint();
    paint.setColor(textColor);
    paint.setTypeface(NORMAL_TYPEFACE);
    paint.setAntiAlias(true);
    return paint;
}
 
Example 11
Project: design-system-android   File: Icons.java   View Source Code Vote up 5 votes
private static void drawIconGlyph(Context context, String iconChar, int size, Canvas canvas, int color) {
    Paint textPaint = new Paint();
    textPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    textPaint.setTextAlign(Paint.Align.CENTER);
    textPaint.setColor(color);
    textPaint.setTextSize(size);
    textPaint.setTypeface(Typeface.createFromAsset(context.getResources().getAssets(), "SalesforceDesignSystemIcons.ttf"));
    float y = (size / 2.0f) - ((textPaint.descent() + textPaint.ascent()) / 2.0f);
    canvas.drawText(iconChar, (size / 2.0f), y, textPaint);
}
 
Example 12
Project: DateTimePicker   File: RadialTimePickerView.java   View Source Code Vote up 5 votes
/**
 * Draw the 12 text values at the positions specified by the textGrid parameters.
 */
private void drawTextElements(Canvas canvas, float textSize, Typeface typeface,
        ColorStateList textColor, String[] texts, float[] textX, float[] textY, Paint paint,
        int alpha, boolean showActivated, int activatedDegrees, boolean activatedOnly) {
    paint.setTextSize(textSize);
    paint.setTypeface(typeface);

    // The activated index can touch a range of elements.
    final float activatedIndex = activatedDegrees / (360.0f / NUM_POSITIONS);
    final int activatedFloor = (int) activatedIndex;
    final int activatedCeil = ((int) Math.ceil(activatedIndex)) % NUM_POSITIONS;

    for (int i = 0; i < 12; i++) {
        final boolean activated = (activatedFloor == i || activatedCeil == i);
        if (activatedOnly && !activated) {
            continue;
        }

        final int stateMask = StateSet.VIEW_STATE_ENABLED
                | (showActivated && activated ? StateSet.VIEW_STATE_ACTIVATED : 0);
        final int color = textColor.getColorForState(StateSet.get(stateMask), 0);
        paint.setColor(color);
        paint.setAlpha(getMultipliedAlpha(color, alpha));

        canvas.drawText(texts[i], textX[i], textY[i], paint);
    }
}
 
Example 13
Project: RNLearn_Project1   File: CustomStyleSpan.java   View Source Code Vote up 5 votes
private static void apply(
    Paint paint,
    int style,
    int weight,
    @Nullable String family,
    AssetManager assetManager) {
  int oldStyle;
  Typeface typeface = paint.getTypeface();
  if (typeface == null) {
    oldStyle = 0;
  } else {
    oldStyle = typeface.getStyle();
  }

  int want = 0;
  if ((weight == Typeface.BOLD) ||
      ((oldStyle & Typeface.BOLD) != 0 && weight == ReactTextShadowNode.UNSET)) {
    want |= Typeface.BOLD;
  }

  if ((style == Typeface.ITALIC) ||
      ((oldStyle & Typeface.ITALIC) != 0 && style == ReactTextShadowNode.UNSET)) {
    want |= Typeface.ITALIC;
  }

  if (family != null) {
    typeface = ReactFontManager.getInstance().getTypeface(family, want, assetManager);
  } else if (typeface != null) {
    // TODO(t9055065): Fix custom fonts getting applied to text children with different style
    typeface = Typeface.create(typeface, want);
  }

  if (typeface != null) {
    paint.setTypeface(typeface);
  } else {
    paint.setTypeface(Typeface.defaultFromStyle(want));
  }
}
 
Example 14
Project: ucar-weex-core   File: TypefaceUtil.java   View Source Code Vote up 5 votes
public static void applyFontStyle(Paint paint, int style, int weight, String family) {
  int oldStyle;
  Typeface typeface = paint.getTypeface();
  if (typeface == null) {
    oldStyle = 0;
  } else {
    oldStyle = typeface.getStyle();
  }

  int want = 0;
  if ((weight == Typeface.BOLD)
    || ((oldStyle & Typeface.BOLD) != 0 && weight == WXStyle.UNSET)) {
    want |= Typeface.BOLD;
  }

  if ((style == Typeface.ITALIC)
    || ((oldStyle & Typeface.ITALIC) != 0 && style == WXStyle.UNSET)) {
    want |= Typeface.ITALIC;
  }

  if (family != null) {
    typeface = getOrCreateTypeface(family, want);
  }

  if (typeface != null) {
    paint.setTypeface(Typeface.create(typeface, want));
  } else {
    paint.setTypeface(Typeface.defaultFromStyle(want));
  }
}
 
Example 15
Project: AOSP-Kayboard-7.1.2   File: MainKeyboardView.java   View Source Code Vote up 5 votes
private void drawLanguageOnSpacebar(final Key key, final Canvas canvas, final Paint paint) {
    final Keyboard keyboard = getKeyboard();
    if (keyboard == null) {
        return;
    }
    final int width = key.getWidth();
    final int height = key.getHeight();
    paint.setTextAlign(Align.CENTER);
    paint.setTypeface(Typeface.DEFAULT);
    paint.setTextSize(mLanguageOnSpacebarTextSize);
    final String language = layoutLanguageOnSpacebar(paint, keyboard.mId.mSubtype, width);
    // Draw language text with shadow
    final float descent = paint.descent();
    final float textHeight = -paint.ascent() + descent;
    final float baseline = height / 2 + textHeight / 2;
    if (mLanguageOnSpacebarTextShadowRadius > 0.0f) {
        paint.setShadowLayer(mLanguageOnSpacebarTextShadowRadius, 0, 0,
                mLanguageOnSpacebarTextShadowColor);
    } else {
        paint.clearShadowLayer();
    }
    paint.setColor(mLanguageOnSpacebarTextColor);
    paint.setAlpha(mLanguageOnSpacebarAnimAlpha);
    canvas.drawText(language, width / 2, baseline - descent, paint);
    paint.clearShadowLayer();
    paint.setTextScaleX(1.0f);
}
 
Example 16
Project: DownloadableCalligraphy   File: CalligraphyTypefaceSpan.java   View Source Code Vote up 5 votes
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 17
Project: CodeWatch   File: BadgeView.java   View Source Code Vote up 5 votes
private void setUpPaint() {
    backgroundPaint = new Paint();
    backgroundPaint.setColor(backgroundColor);
    backgroundPaint.setStyle(Paint.Style.FILL);

    badgePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    badgePaint.setColor(badgeColor);

    textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    textPaint.setTypeface(Typeface.create("sans-serif-condensed", Typeface.NORMAL));
    textPaint.setColor(textColor);
    textPaint.setTextSize(textSize);
    textPaint.setFakeBoldText(true);
}
 
Example 18
Project: referendum_1o_android   File: DefaultClusterOptionsProvider.java   View Source Code Vote up 5 votes
private Paint createTextPaint(Resources resources) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(resources.getColor(R.color.ame_default_cluster_text_color));
    shadowBlurRadius = resources.getDimension(R.dimen.ame_default_cluster_text_shadow_blur_radius);
    if (shadowBlurRadius > 0.0f) {
        shadowOffsetX = resources.getDimension(R.dimen.ame_default_cluster_text_shadow_offset_x);
        shadowOffsetY = resources.getDimension(R.dimen.ame_default_cluster_text_shadow_offset_y);
        int shadowColor = resources.getColor(R.color.ame_default_cluster_text_shadow_color);
        paint.setShadowLayer(shadowBlurRadius, shadowOffsetX, shadowOffsetY, shadowColor);
    }
    paint.setTextSize(resources.getDimension(R.dimen.ame_default_cluster_text_size));
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    return paint;
}
 
Example 19
Project: CustomAnimatingCalendar   File: CustomCalendar.java   View Source Code Vote up 4 votes
private void drawDates(Canvas canvas, Paint textPaint, Paint circlePaint){
    Calendar calendar = Calendar.getInstance(Locale.getDefault());
    int currentDate = calendar.get(Calendar.DATE);
    boolean isDrawingCurrentMonth = false;

    //calculate the "day" of 1st day of the month
    if(drawingMonth >= 0  && drawingYear > 0){
        //check whether current month
        if(calendar.get(Calendar.YEAR) == drawingYear && calendar.get(Calendar.MONTH) == drawingMonth){
            isDrawingCurrentMonth = true;
        } else {
            calendar.set(Calendar.YEAR, drawingYear);
            calendar.set(Calendar.MONTH, drawingMonth);
        }
    }else {
        isDrawingCurrentMonth = true;
    }
    calendar.set(Calendar.DATE, 1);
    int start_day_of_week = calendar.get(Calendar.DAY_OF_WEEK); // sunday is 1 and saturday is 7

    int dayToPrint = 1;

    //calculate the last date of the month
    int last_day_of_the_month = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);

    for (int week_no = 1; week_no <= NO_OF_WEEKS && dayToPrint <= last_day_of_the_month; week_no++) {
        for(int day_of_week=0; day_of_week < NO_OF_DAYS; day_of_week++){

            float left = FIXED_MARGIN + day_of_week*cell_width;
            float right = FIXED_MARGIN + (day_of_week + 1)*cell_width;
            float top = week_no * cell_height;

            //draw cells
            /*canvas.drawRect(left, top, right,(top + cell_height), cellPaint);*/

            //check whether text needs to drawn...
            if(week_no == 1 && day_of_week < start_day_of_week-1){ // before the 1st day of the month
                continue;
            }else if(dayToPrint > last_day_of_the_month){ // after the last day of the month
                continue;
            }else if(hideClickedDate && dayToPrint == clickedDate){ // before animation hide the date
                dayToPrint ++;
                continue;
            }

            //draw background circle if touched
            if (touchedRow == week_no && touchedColumn == day_of_week) {
                int radius = 0;
                if(cell_height<cell_width){
                    radius = (int)cell_height/2;
                } else{
                    radius = (int)cell_width/2;
                }
                canvas.drawCircle(left + cell_width/2, top + cell_height/2, radius, circlePaint);
            }

            //draw text
            String drawingDate = String.valueOf(dayToPrint);
            if(isDrawingCurrentMonth && dayToPrint == currentDate){
                textPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
            }else {
                textPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
            }
            Rect bounds = new Rect();
            textPaint.getTextBounds(drawingDate, 0, drawingDate.length(), bounds);

            canvas.drawText(drawingDate, left + cell_width/2 - (bounds.right - bounds.left)/2,
                    top + cell_height/2 + (bounds.bottom - bounds.top)/2,
                    textPaint);
            datePostionMap.put(String.valueOf(week_no)+","+ String.valueOf(day_of_week), String.valueOf(dayToPrint));
            dayToPrint ++;
        }
    }
}
 
Example 20
Project: CalendarCheck   File: SimpleMonthView.java   View Source Code Vote up 4 votes
protected void initView() {
    mMonthTitlePaint = new Paint();
    mMonthTitlePaint.setFakeBoldText(true);
    mMonthTitlePaint.setAntiAlias(true);
    mMonthTitlePaint.setTextSize(MONTH_TITLE_SIZE);
    mMonthTitlePaint.setTypeface(Typeface.create(mMonthTitleTypeface, Typeface.NORMAL));
    mMonthTitlePaint.setColor(mMonthTextColor);
    mMonthTitlePaint.setTextAlign(Align.CENTER);
    mMonthTitlePaint.setStyle(Style.FILL);

    mSelectedPointPaint = new Paint();
    mSelectedPointPaint.setFakeBoldText(true);
    mSelectedPointPaint.setAntiAlias(true);
    mSelectedPointPaint.setColor(0xffff6827);
    mSelectedPointPaint.setTextAlign(Align.CENTER);
    mSelectedPointPaint.setStyle(Style.FILL);

    mSelectedCirclePaint = new Paint();
    mSelectedCirclePaint.setFakeBoldText(true);
    mSelectedCirclePaint.setAntiAlias(true);
    mSelectedCirclePaint.setColor(mLinkedDayBgColor);
    mSelectedCirclePaint.setTextAlign(Align.CENTER);
    mSelectedCirclePaint.setStyle(Style.FILL);
    //mSelectedCirclePaint.setAlpha(SELECTED_CIRCLE_ALPHA);

    mWeekPaint = new Paint();
    mWeekPaint.setAntiAlias(true);
    mWeekPaint.setTextSize(WEEK_NAME_BAR_SIZE);
    mWeekPaint.setColor(mWeekTextColor);
    mWeekPaint.setTypeface(Typeface.create(mDayOfWeekTypeface, Typeface.NORMAL));
    mWeekPaint.setStyle(Style.FILL);
    mWeekPaint.setTextAlign(Align.CENTER);
    mWeekPaint.setFakeBoldText(true);

    mDayDigitPaint = new Paint();
    mDayDigitPaint.setAntiAlias(true);
    mDayDigitPaint.setTextSize(DAY_DIGIT_SIZE);
    mDayDigitPaint.setColor(mDayDigitTextColor);
    mDayDigitPaint.setStyle(Style.FILL);
    mDayDigitPaint.setTextAlign(Align.CENTER);
    mDayDigitPaint.setFakeBoldText(false);
}