@Override public void updateDrawState(TextPaint tp) { tp.setTypeface(mTypeface); // Note: This flag is required for proper typeface rendering tp.setFlags(tp.getFlags() | Paint.SUBPIXEL_TEXT_FLAG); }
private void init(AttributeSet attrs, int defStyle) { // Load attributes final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.MyView, defStyle, 0); mExampleString = a.getString(R.styleable.MyView_exampleString); mExampleColor = a.getColor(R.styleable.MyView_exampleColor, mExampleColor); // Use getDimensionPixelSize or getDimensionPixelOffset when dealing with // values that should fall on pixel boundaries. mExampleDimension = a.getDimension(R.styleable.MyView_exampleDimension, mExampleDimension); if (a.hasValue(R.styleable.MyView_exampleDrawable)) { mExampleDrawable = a.getDrawable(R.styleable.MyView_exampleDrawable); mExampleDrawable.setCallback(this); } a.recycle(); // Set up a default TextPaint object mTextPaint = new TextPaint(); mTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG); mTextPaint.setTextAlign(Paint.Align.LEFT); // Update TextPaint and text measurements from attributes invalidateTextPaintAndMeasurements(); }
public static TextView applyNoteViewAttrs(Context context, EditText noteView, CharSequence text) { TextPaint paint = noteView.getPaint(); paint.setFlags(TextPaint.ANTI_ALIAS_FLAG); noteView.setTypeface(Typeface.createFromAsset(context.getAssets(), "comic.ttf")); noteView.setText(text); Selection.removeSelection(noteView.getText()); return noteView; }
private void setup() { if (!mReady) { mSetupPending = true; return; } if (mBitmap == null) { return; } mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); mBitmapPaint.setAntiAlias(true); mBitmapPaint.setShader(mBitmapShader); mBorderPaint.setStyle(Paint.Style.STROKE); mBorderPaint.setAntiAlias(true); mBorderPaint.setColor(mBorderColor); mBorderPaint.setStrokeWidth(mBorderWidth); mBitmapHeight = mBitmap.getHeight(); mBitmapWidth = mBitmap.getWidth(); mBorderRect.set(0, 0, getWidth(), getHeight()); mBorderRadius = Math.min( (mBorderRect.height() - mBorderWidth) / 2, (mBorderRect.width() - mBorderWidth) / 2); mDrawableRect.set( mBorderWidth, mBorderWidth, mBorderRect.width() - mBorderWidth, mBorderRect.height() - mBorderWidth); mDrawableRadius = Math.min(mDrawableRect.height() / 2, mDrawableRect.width() / 2); mFlagBackgroundPaint.setColor(Color.BLACK & 0x66FFFFFF); mFlagBackgroundPaint.setFlags(TextPaint.ANTI_ALIAS_FLAG); mFlagTextPaint.setFlags(TextPaint.ANTI_ALIAS_FLAG); mFlagTextPaint.setTextAlign(Align.CENTER); mFlagTextPaint.setColor(Color.WHITE); mFlagTextPaint.setTextSize(getResources().getDisplayMetrics().density * 18); mSweepGradient = new SweepGradient( getWidth() / 2, getHeight() / 2, new int[] {Color.rgb(255, 255, 255), Color.rgb(1, 209, 255)}, null); mBorderPaint.setShader(mSweepGradient); updateShaderMatrix(); invalidate(); }
/** * 初始化定义的属性 * * @param attrs * @param defStyle */ private void init(AttributeSet attrs, int defStyle) { TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ProgressView, defStyle, 0); mText = a.getString(R.styleable.ProgressView_text); mTextColor = a.getColor(R.styleable.ProgressView_textColor, mTextColor); mTextSize = a.getDimension(R.styleable.ProgressView_textSize, (int) mTextSize); mInnerColor = a.getColor(R.styleable.ProgressView_innerColor, mInnerColor); mOuterColor = a.getColor(R.styleable.ProgressView_outerColor, mOuterColor); mProgressColor = a.getColor(R.styleable.ProgressView_progressColor, mProgressColor); mRadius = a.getDimension(R.styleable.ProgressView_radius, (int) mRadius); mStrokeWidth = a.getDimension(R.styleable.ProgressView_strokeWidth, (int) mStrokeWidth); mCurrentProgress = a.getInteger(R.styleable.ProgressView_currentProgress, mCurrentProgress); mMaxProgress = a.getInteger(R.styleable.ProgressView_maxProgress, mMaxProgress); a.recycle(); mTextPaint = new TextPaint(); mTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG); mTextPaint.setTextAlign(Paint.Align.CENTER); mTextPaint.setTypeface(Typeface.MONOSPACE); mTextPaint.setTextSize(mTextSize); mTextPaint.setColor(mTextColor); mInnerPaint = new Paint(); mInnerPaint.setAntiAlias(true); mInnerPaint.setDither(true); mInnerPaint.setStyle(Paint.Style.FILL); // mInnerPaint.setStrokeWidth(mStrokeWidth); mInnerPaint.setColor(mInnerColor); mOuterPaint = new Paint(); mOuterPaint.setAntiAlias(true); mOuterPaint.setStyle(Paint.Style.STROKE); mOuterPaint.setStrokeWidth(mStrokeWidth); mOuterPaint.setColor(mOuterColor); mProgressPaint = new Paint(); mProgressPaint.setAntiAlias(true); mProgressPaint.setStyle(Paint.Style.STROKE); mProgressPaint.setStrokeWidth(mStrokeWidth); mProgressPaint.setColor(mProgressColor); }
@Override public void updateDrawState(TextPaint tp) { tp.setTypeface(typeface); tp.setFlags(tp.getFlags() | Paint.SUBPIXEL_TEXT_FLAG); }
@Override public void updateMeasureState(TextPaint p) { p.setTypeface(typeface); p.setFlags(p.getFlags() | Paint.SUBPIXEL_TEXT_FLAG); }
private void initTitleText(boolean isShow) { if (isShow != mAttributes.isShowTitle()) { mAttributes.setShowTitle(isShow); // Padding final int paddingTop = getPaddingTop(); final int paddingRight = getPaddingRight(); final int paddingLeft = getPaddingLeft(); final int paddingBottom = getPaddingBottom(); if (isShow) { mCurTitleProperty = new TitleProperty(); // Set up a default TextPaint object if (mTitlePaint == null) { mTitlePaint = new TextPaint(); mTitlePaint.setFlags(Paint.ANTI_ALIAS_FLAG); mTitlePaint.setTextAlign(Paint.Align.LEFT); } setPadding( paddingLeft, paddingTop + mAttributes.getTitleTextSize(), paddingRight, paddingBottom); // Add Watcher if (mTextWatcher == null) { mTextWatcher = new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) {} @Override public void afterTextChanged(Editable s) { if (mAttributes.isShowTitle() && mTitlePaint != null) { boolean have = s != null && s.length() > 0; if (have != isHaveText) { isHaveText = have; animateShowTitle(isHaveText); } } } }; addTextChangedListener(mTextWatcher); } // Show Editable editable = getText(); animateShowTitle(editable != null && editable.length() > 0); } else { if (mTextWatcher != null) { removeTextChangedListener(mTextWatcher); mTextWatcher = null; } mTitlePaint = null; mCurTitleProperty = null; mAnimator = null; setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); } } }