Java Code Examples for android.graphics.Paint#SUBPIXEL_TEXT_FLAG

The following examples show how to use android.graphics.Paint#SUBPIXEL_TEXT_FLAG . 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: CalendarView.java    From BigApp_Discuz_Android with Apache License 2.0 6 votes vote down vote up
private void initCalendarView() {
	mRightNow = Calendar.getInstance();
	mHelper = new MonthDisplayHelper(mRightNow.get(Calendar.YEAR),
			mRightNow.get(Calendar.MONTH), mRightNow.getFirstDayOfWeek());

	mBackgroundColor = new Paint();
	mBackgroundColorToday = new Paint();
	mBackgroundColorTouched = new Paint();
	mWeekTitle = new Paint(Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
	mLinePaint = new Paint();
	mLinePaint2 = new Paint();

	mBackgroundColor.setColor(Color.WHITE);
	mBackgroundColorToday.setColor(Color.RED);
	mBackgroundColorToday.setAlpha(100);
	mBackgroundColorTouched.setColor(Color.BLUE);
	mBackgroundColorTouched.setAlpha(100);
	mWeekTitle.setColor(Color.rgb(135, 135, 135));
	mLinePaint.setColor(Color.BLACK);
	mLinePaint2.setColor(Color.rgb(90, 90, 90));
}
 
Example 2
Source File: BadgedFourThreeImageView.java    From Protein with Apache License 2.0 5 votes vote down vote up
GifBadge(Context context) {
    if (bitmap == null) {
        final DisplayMetrics dm = context.getResources().getDisplayMetrics();
        final float density = dm.density;
        final float scaledDensity = dm.scaledDensity;
        final TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint
                .SUBPIXEL_TEXT_FLAG);
        textPaint.setTypeface(Typeface.create(TYPEFACE, TYPEFACE_STYLE));
        textPaint.setTextSize(TEXT_SIZE * scaledDensity);

        final float padding = PADDING * density;
        final float cornerRadius = CORNER_RADIUS * density;
        final Rect textBounds = new Rect();
        textPaint.getTextBounds(GIF, 0, GIF.length(), textBounds);
        height = (int) (padding + textBounds.height() + padding);
        width = (int) (padding + textBounds.width() + padding);
        bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        bitmap.setHasAlpha(true);
        final Canvas canvas = new Canvas(bitmap);
        final Paint backgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        backgroundPaint.setColor(BACKGROUND_COLOR);
        canvas.drawRoundRect(0, 0, width, height, cornerRadius, cornerRadius,
                backgroundPaint);
        // punch out the word 'GIF', leaving transparency
        textPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
        canvas.drawText(GIF, padding, height - padding, textPaint);
    }
    paint = new Paint();
}
 
Example 3
Source File: SubtitleCollapsingTextHelper.java    From collapsingtoolbarlayout-subtitle with Apache License 2.0 5 votes vote down vote up
public SubtitleCollapsingTextHelper(View view) {
    this.view = view;

    titleTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    titleTmpPaint = new TextPaint(titleTextPaint);
    subtitleTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    subtitleTmpPaint = new TextPaint(subtitleTextPaint);

    collapsedBounds = new Rect();
    expandedBounds = new Rect();
    currentBounds = new RectF();
}
 
Example 4
Source File: StaticLabelTextInputLayout.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
public StaticLabelTextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    mTextPaint.setTypeface(getTypeface());
    mTextPaint.setTextSize(getResources().getDimensionPixelSize(R.dimen.abc_text_size_caption_material));
    StyledAttributesHelper ta = StyledAttributesHelper.obtainStyledAttributes(context,
            new int[] { R.attr.colorAccent, android.R.attr.textColorHint });
    mTextColorUnfocused = ta.getColor(android.R.attr.textColorHint, 0);
    mTextColorFocused = ta.getColor(R.attr.colorAccent, 0);
    ta.recycle();
    mTextPaint.setColor(mTextColorUnfocused);
}
 
Example 5
Source File: LabelLayout.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
public LabelLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    setWillNotDraw(false);
    setAddStatesFromChildren(true);

    mInputFrame = new FrameLayout(context);
    mInputFrame.setAddStatesFromChildren(true);
    super.addView(mInputFrame, -1, generateDefaultLayoutParams());

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    mTextPaint.setTypeface(Typeface.DEFAULT);// getTypeface());
    mTextSizeCollapsed = getResources().getDimensionPixelSize(R.dimen.abc_text_size_caption_material);
    mTextSizeExpanded = getResources().getDimensionPixelSize(R.dimen.abc_text_size_medium_material);
    mTextPaint.setTextSize(mTextSizeCollapsed);

    StyledAttributesHelper ta = StyledAttributesHelper.obtainStyledAttributes(context, attrs,
            new int[] { R.attr.colorAccent, R.attr.doNotExpand, android.R.attr.hint, android.R.attr.textColorHint });
    try {
        mDoNotExpand = ta.getBoolean(R.attr.doNotExpand, false);
        mHint = ta.getString(android.R.attr.hint);
        mTextColorUnfocused = ta.getColorStateList(android.R.attr.textColorHint);
        mTextColorFocused = ta.getColor(R.attr.colorAccent, 0);
    } finally {
        ta.recycle();
    }
    mTextPaint.setColor(mTextColorUnfocused.getColorForState(getDrawableState(), mTextColorUnfocused.getDefaultColor()));

    mAnimator = ValueAnimator.ofFloat(0.f, 1.f);
    mAnimator.setInterpolator(new LinearInterpolator());
    mAnimator.setDuration(200);
    mAnimator.addUpdateListener((ValueAnimator animation) -> {
        mAnimState = (float) animation.getAnimatedValue();
        invalidate();
    });

    updateTopMargin();
    updateTextPositions();
}
 
Example 6
Source File: CollapsingTextHelper.java    From UIWidget with Apache License 2.0 5 votes vote down vote up
public CollapsingTextHelper(View view) {
    mView = view;

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    mCollapsedBounds = new Rect();
    mExpandedBounds = new Rect();
    mCurrentBounds = new RectF();
}
 
Example 7
Source File: CollapsingTextHelper.java    From GpCollapsingToolbar with Apache License 2.0 5 votes vote down vote up
public CollapsingTextHelper(View view) {
    mView = view;

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    mCollapsedBounds = new Rect();
    mExpandedBounds = new Rect();
    mCurrentBounds = new RectF();
}
 
Example 8
Source File: CollapsingTextHelper.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
public CollapsingTextHelper(View view) {
  this.view = view;

  textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
  tmpPaint = new TextPaint(textPaint);

  collapsedBounds = new Rect();
  expandedBounds = new Rect();
  currentBounds = new RectF();
}
 
Example 9
Source File: BadgedFourThreeImageView.java    From android-proguards with Apache License 2.0 5 votes vote down vote up
GifBadge(Context context) {
    if (bitmap == null) {
        final DisplayMetrics dm = context.getResources().getDisplayMetrics();
        final float density = dm.density;
        final float scaledDensity = dm.scaledDensity;
        final TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint
                .SUBPIXEL_TEXT_FLAG);
        textPaint.setTypeface(Typeface.create(TYPEFACE, TYPEFACE_STYLE));
        textPaint.setTextSize(TEXT_SIZE * scaledDensity);

        final float padding = PADDING * density;
        final float cornerRadius = CORNER_RADIUS * density;
        final Rect textBounds = new Rect();
        textPaint.getTextBounds(GIF, 0, GIF.length(), textBounds);
        height = (int) (padding + textBounds.height() + padding);
        width = (int) (padding + textBounds.width() + padding);
        bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        bitmap.setHasAlpha(true);
        final Canvas canvas = new Canvas(bitmap);
        final Paint backgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        backgroundPaint.setColor(BACKGROUND_COLOR);
        canvas.drawRoundRect(0, 0, width, height, cornerRadius, cornerRadius,
                backgroundPaint);
        // punch out the word 'GIF', leaving transparency
        textPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
        canvas.drawText(GIF, padding, height - padding, textPaint);
    }
    paint = new Paint();
}
 
Example 10
Source File: TalkDialog.java    From talk-android with MIT License 4 votes vote down vote up
public final void setTypeface(TextView target, Typeface t) {
    if (t == null) return;
    int flags = target.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG;
    target.setPaintFlags(flags);
    target.setTypeface(t);
}
 
Example 11
Source File: BadgeDrawable.java    From Android-BadgedImageView with MIT License 4 votes vote down vote up
public BadgeDrawable(Context context, String text) {
    this.text = text;

    final DisplayMetrics dm = context.getResources().getDisplayMetrics();

    final float density = dm.density;
    final float scaledDensity = dm.scaledDensity;
    final float padding = PADDING * density;
    final float cornerRadius = CORNER_RADIUS * density;

    final Rect textBounds = new Rect();
    final TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint
            .SUBPIXEL_TEXT_FLAG);
    textPaint.setTypeface(Typeface.create(TYPEFACE, TYPEFACE_STYLE));
    textPaint.setTextSize(TEXT_SIZE * scaledDensity);
    textPaint.getTextBounds(text, 0, text.length(), textBounds);

    height = (int) (padding + textBounds.height() + padding);
    width = (int) (padding + textBounds.width() + padding);

    if (bitmaps.get(text) == null) {

        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        bitmap.setHasAlpha(true);

        final Canvas canvas = new Canvas(bitmap);
        final Paint backgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        backgroundPaint.setColor(BACKGROUND_COLOR);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            canvas.drawRoundRect(0, 0, width, height, cornerRadius, cornerRadius,
                    backgroundPaint);
        } else {
            canvas.drawRect(0, 0, width, height, backgroundPaint);
        }

        // punch out the text leaving transparency
        textPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
        canvas.drawText(text, padding, height - padding, textPaint);

        bitmaps.put(text, bitmap);
    }

    paint = new Paint();
}