android.graphics.Paint#SUBPIXEL_TEXT_FLAG源码实例Demo

下面列出了android.graphics.Paint#SUBPIXEL_TEXT_FLAG 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: BigApp_Discuz_Android   文件: CalendarView.java
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));
}
 
源代码2 项目: Protein   文件: BadgedFourThreeImageView.java
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();
}
 
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();
}
 
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);
}
 
源代码5 项目: revolution-irc   文件: LabelLayout.java
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();
}
 
源代码6 项目: UIWidget   文件: CollapsingTextHelper.java
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();
}
 
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();
}
 
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();
}
 
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();
}
 
源代码10 项目: talk-android   文件: TalkDialog.java
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);
}
 
源代码11 项目: Android-BadgedImageView   文件: BadgeDrawable.java
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();
}