Java Code Examples for android.graphics.Paint#setDither()

The following examples show how to use android.graphics.Paint#setDither() . 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: MediaView.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
private void init() {

        paint = new Paint();
        //抗锯齿
        paint.setAntiAlias(true);
        //抗抖动
        paint.setDither(true);
        paint.setColor(Color.BLUE);
        //给path描边
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(20);
        //设置paint画虚线
        DashPathEffect effect = new DashPathEffect(new float[]{16,2,16,2},0);
        paint.setPathEffect(effect);

        path = new Path();

        random = new Random();

    }
 
Example 2
Source File: PageIndicator.java    From tilt-game-android with MIT License 6 votes vote down vote up
private void setup() {
    _paintActive = new Paint();
    _paintActive.setStyle(Paint.Style.FILL);
    _paintActive.setDither(true);
    _paintActive.setAntiAlias(true);
    _paintActive.setColor(getResources().getColor(R.color.white));

    _paintInactive = new Paint();
    _paintInactive.setStyle(Paint.Style.FILL);
    _paintActive.setAntiAlias(true);
    _paintInactive.setColor(getResources().getColor(R.color.white_30));

    if (isInEditMode()) {
        _activePage = 0;
        _numPages = 3;
    }
}
 
Example 3
Source File: SmoothProgressDrawable.java    From KlyphMessenger with MIT License 6 votes vote down vote up
private SmoothProgressDrawable(Interpolator interpolator, int sectionsCount, int separatorLength, int[] colors, int width, float speed, boolean reversed, boolean mirrorMode) {
    mRunning = false;
    mInterpolator = interpolator;
    mSectionsCount = sectionsCount;
    mSeparatorLength = separatorLength;
    mSpeed = speed;
    mReversed = reversed;
    mColors = colors;
    mColorsIndex = 0;
    mMirrorMode = mirrorMode;

    mPaint = new Paint();
    mPaint.setStrokeWidth(width);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setDither(false);
    mPaint.setAntiAlias(false);
}
 
Example 4
Source File: TMSRenderer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
public TMSRenderer(ILayer layer)
{
    super(layer);
    mRasterPaint = new Paint();

    mAntiAlias = true;
    mFilterBitmap = true;
    mDither = true;
    mContrast = 1;
    mBrightness = 0;
    mForceToGrayScale = false;
    mAlpha = 255;

    mRasterPaint.setAntiAlias(mAntiAlias);
    mRasterPaint.setFilterBitmap(mFilterBitmap);
    mRasterPaint.setDither(mDither);
    mRasterPaint.setAlpha(mAlpha);
}
 
Example 5
Source File: DragPointViewWindow.java    From DragPointView with Apache License 2.0 6 votes vote down vote up
private void init() {
    mPath = new Path();
    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setTextSize(18f);
    mPaint.setColor(colorStretching);
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mDragTangentPoint = new PointF[2];
    mCenterTangentPoint = new PointF[2];
    mControlPoint = new PointF();
    mCenterCircle = new PointF();
    mCenterCircleCopy = new PointF();
    mDragCircle = new PointF();
    mDragCircleCopy = new PointF();
}
 
Example 6
Source File: ActivityPaint.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
void setPaintColor() {
    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setDither(true);
    paint.setColor(paintColor);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeJoin(Paint.Join.ROUND);
    paint.setStrokeCap(Paint.Cap.ROUND);
    paint.setStrokeWidth(brushSize);
}
 
Example 7
Source File: TextShowView.java    From easyweather with MIT License 5 votes vote down vote up
private void init() {

        //画笔初始化:
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setFilterBitmap(true);
        mPaint.setDither(true);
        mPaint.setColor(ContextCompat.getColor(MyApplication.getAppContext(),R.color.maincolor));
        String familyName ="宋体";
        Typeface font = Typeface.create(familyName,Typeface.BOLD);
        mPaint.setTypeface(font);
        mPaint.setTextSize(DisplayUtil.sp2px(MyApplication.getAppContext(),50));
        mPaint.setTextAlign(Paint.Align.CENTER);

        //背部图片的初始化
        backBitmap = getDescBitmap();
        int mBitH = backBitmap.getHeight();
        int mBitW = backBitmap.getWidth();
        bPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        bPaint.setFilterBitmap(true);
        bPaint.setDither(true);
        bPaint.setColor(ContextCompat.getColor(MyApplication.getAppContext(),R.color.white));

        //设置当前的高度
        mCurTop = mBitH / 2 ;
        mCurBelow = mCurTop;

        int topRectH = mCurTop;
        int belowRectH = mCurBelow;
        topRect = new Rect(0,
                           topRectH,
                           mBitW,
                           topRectH);  //初始化原图

        belowRect = new Rect(0,
                             belowRectH ,
                             mBitW,
                             belowRectH);
    }
 
Example 8
Source File: RoundImageView.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 边缘画圆
 */
private void drawCircleBorder(Canvas canvas, int radius, int w, int h,
        int color) {
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    paint.setColor(color);
    /* 设置paint的 style 为STROKE:空心 */
    paint.setStyle(Paint.Style.STROKE);
    /* 设置paint的外框宽度 */
    paint.setStrokeWidth(mBorderThickness);
    canvas.drawCircle(w / 2, h / 2, radius, paint);
}
 
Example 9
Source File: VMEmojiRainView.java    From VMLibrary with Apache License 2.0 5 votes vote down vote up
private void init() {
    setVisibility(GONE);
    setWillNotDraw(false);

    mXStartPadding = VMDimen.dp2px(15);
    mEmoticonWidth = VMDimen.dp2px(32);
    mEmoticonHeight = VMDimen.dp2px(32);

    // 初始化画笔
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setFilterBitmap(true);
    mPaint.setDither(true);
    mMatrix = new Matrix();
}
 
Example 10
Source File: QiscusImageUtil.java    From qiscus-sdk-android with Apache License 2.0 5 votes vote down vote up
public static Bitmap getCircularBitmap(Bitmap bm) {
    int size = 192;

    Bitmap bitmap = ThumbnailUtils.extractThumbnail(bm, size, size);

    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(output);

    final int color = 0xffff0000;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);

    paint.setAntiAlias(true);
    paint.setDither(true);
    paint.setFilterBitmap(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawOval(rectF, paint);

    paint.setColor(Color.BLUE);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth((float) 4);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
}
 
Example 11
Source File: GestureOverlayView.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void init() {
    setWillNotDraw(false);

    final Paint gesturePaint = mGesturePaint;
    gesturePaint.setAntiAlias(GESTURE_RENDERING_ANTIALIAS);
    gesturePaint.setColor(mCertainGestureColor);
    gesturePaint.setStyle(Paint.Style.STROKE);
    gesturePaint.setStrokeJoin(Paint.Join.ROUND);
    gesturePaint.setStrokeCap(Paint.Cap.ROUND);
    gesturePaint.setStrokeWidth(mGestureStrokeWidth);
    gesturePaint.setDither(DITHER_FLAG);

    mCurrentColor = mCertainGestureColor;
    setPaintAlpha(255);
}
 
Example 12
Source File: BGAMoocStyleRefreshView.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
private void initPaint() {
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setColor(mUltimateColor);
}
 
Example 13
Source File: ColorPicker.java    From Mi-Band with GNU General Public License v2.0 5 votes vote down vote up
private void init() {

        colorPointerPaint = new Paint();
        colorPointerPaint.setStyle(Style.STROKE);
        colorPointerPaint.setStrokeWidth(2f);
        colorPointerPaint.setARGB(128, 0, 0, 0);

        valuePointerPaint = new Paint();
        valuePointerPaint.setStyle(Style.STROKE);
        valuePointerPaint.setStrokeWidth(2f);

        valuePointerArrowPaint = new Paint();

        colorWheelPaint = new Paint();
        colorWheelPaint.setAntiAlias(true);
        colorWheelPaint.setDither(true);

        valueSliderPaint = new Paint();
        valueSliderPaint.setAntiAlias(true);
        valueSliderPaint.setDither(true);

        colorViewPaint = new Paint();
        colorViewPaint.setAntiAlias(true);

        colorViewPath = new Path();
        valueSliderPath = new Path();
        arrowPointerPath = new Path();

        outerWheelRect = new RectF();
        innerWheelRect = new RectF();

        colorPointerCoords = new RectF();

    }
 
Example 14
Source File: SlideActionView.java    From SlideActionView with Apache License 2.0 5 votes vote down vote up
private void init() {
    handleRadius = DimenUtils.dpToPx(12);
    expandedHandleRadius = DimenUtils.dpToPx(32);
    selectionRadius = DimenUtils.dpToPx(42);
    rippleRadius = DimenUtils.dpToPx(140);

    selected = new AnimatedFloat(0);
    ripples = new HashMap<>();

    normalPaint = new Paint();
    normalPaint.setStyle(Paint.Style.FILL);
    normalPaint.setColor(Color.GRAY);
    normalPaint.setAntiAlias(true);
    normalPaint.setDither(true);

    outlinePaint = new Paint();
    outlinePaint.setStyle(Paint.Style.STROKE);
    outlinePaint.setColor(Color.GRAY);
    outlinePaint.setAntiAlias(true);
    outlinePaint.setDither(true);

    bitmapPaint = new Paint();
    bitmapPaint.setStyle(Paint.Style.FILL);
    bitmapPaint.setColor(Color.GRAY);
    bitmapPaint.setAntiAlias(true);
    bitmapPaint.setDither(true);
    bitmapPaint.setFilterBitmap(true);

    setOnTouchListener(this);
    setFocusable(true);
    setClickable(true);
}
 
Example 15
Source File: AppIconView.java    From Alarmio with Apache License 2.0 5 votes vote down vote up
public AppIconView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(Color.parseColor("#212121"));
    paint.setDither(true);

    animator = ValueAnimator.ofFloat(bgScale, 0.8f);
    animator.setInterpolator(new OvershootInterpolator());
    animator.setDuration(750);
    animator.setStartDelay(250);
    animator.addUpdateListener(animator -> {
        bgScale = (float) animator.getAnimatedValue();
        invalidate();
    });
    animator.start();

    animator = ValueAnimator.ofFloat(rotation, 0);
    animator.setInterpolator(new DecelerateInterpolator());
    animator.setDuration(1000);
    animator.setStartDelay(250);
    animator.addUpdateListener(animator -> {
        fgScale = animator.getAnimatedFraction() * 0.8f;
        rotation = (float) animator.getAnimatedValue();
        invalidate();
    });
    animator.start();

    animator = ValueAnimator.ofFloat(bgRotation, 0);
    animator.setInterpolator(new DecelerateInterpolator());
    animator.setDuration(1250);
    animator.setStartDelay(250);
    animator.addUpdateListener(animator -> {
        bgRotation = (float) animator.getAnimatedValue();
        invalidate();
    });
    animator.start();
}
 
Example 16
Source File: TreeView.java    From BackgroundView with Apache License 2.0 5 votes vote down vote up
private void init() {
    mPaint = new Paint();
    // 绘制贝塞尔曲线
    mPaint.setColor(mColor);
    mPaint.setStrokeWidth(8);
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setTextSize(60);
    mPaint.setPathEffect(new CornerPathEffect(4));

}
 
Example 17
Source File: CircleColorView.java    From ColorPickerDialog with Apache License 2.0 5 votes vote down vote up
@Override
protected void init() {
    super.init();

    outlinePaint = new Paint();
    outlinePaint.setAntiAlias(true);
    outlinePaint.setDither(true);
    outlinePaint.setStyle(Paint.Style.STROKE);
    outlinePaint.setStrokeWidth(outlineSize);
    outlinePaint.setColor(Color.BLACK);
}
 
Example 18
Source File: RoundRectDrawableWithShadow.java    From RecyclerViewLib with Apache License 2.0 5 votes vote down vote up
RoundRectDrawableWithShadow(Resources resources, int backgroundColor, float radius) {
    mShadowStartColor = resources.getColor(R.color.cardview_shadow_start_color);
    mShadowEndColor = resources.getColor(R.color.cardview_shadow_end_color);
    mShadowSize = resources.getDimension(R.dimen.cardview_shadow_size) * SHADOW_MULTIPLIER;


    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    mPaint.setColor(backgroundColor);
    mCornerShadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    mCornerShadowPaint.setStyle(Paint.Style.FILL);
    mCornerShadowPaint.setDither(true);
    mCornerRadius = radius;
    mPreShadowBounds = new RectF();
    mEdgeShadowPaint = new Paint(mCornerShadowPaint);
}
 
Example 19
Source File: ClipImageView.java    From Tok-Android with GNU General Public License v3.0 4 votes vote down vote up
public ClipImageView(Context context, AttributeSet attrs) {
    super(context, attrs);

    setScaleType(ScaleType.MATRIX);
    mGestureDetector = new GestureDetector(context, new SimpleOnGestureListener() {
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (isAutoScale) return true;

            float x = e.getX();
            float y = e.getY();
            if (getScale() < mScaleMin) {
                ClipImageView.this.postDelayed(new AutoScaleRunnable(mScaleMin, x, y), 16);
            } else {
                ClipImageView.this.postDelayed(new AutoScaleRunnable(mInitScale, x, y), 16);
            }
            isAutoScale = true;

            return true;
        }
    });
    mScaleGestureDetector = new ScaleGestureDetector(context, this);
    this.setOnTouchListener(this);

    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setColor(Color.WHITE);

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ClipImageView);
    mAspectX = ta.getInteger(R.styleable.ClipImageView_civWidth, 1);
    mAspectY = ta.getInteger(R.styleable.ClipImageView_civHeight, 1);
    mClipPadding = ta.getDimensionPixelSize(R.styleable.ClipImageView_civClipPadding, 0);
    mTipText = ta.getString(R.styleable.ClipImageView_civTipText);
    mMaskColor = ta.getColor(R.styleable.ClipImageView_civMaskColor, 0xB2000000);
    mDrawCircleFlag = ta.getBoolean(R.styleable.ClipImageView_civClipCircle, false);
    mRoundCorner = ta.getDimension(R.styleable.ClipImageView_civClipRoundCorner, 0);
    final int textSize = ta.getDimensionPixelSize(R.styleable.ClipImageView_civTipTextSize, 24);
    mPaint.setTextSize(textSize);
    ta.recycle();

    mPaint.setDither(true);
}
 
Example 20
Source File: ChangeColorItem.java    From SlidingTabWithColorIcons with Apache License 2.0 4 votes vote down vote up
/**
 */
public ChangeColorItem(Context context, AttributeSet attrs,
                       int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray typedArray = context.obtainStyledAttributes(attrs,
            R.styleable.ChangeColorItem);
    int mTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12, getResources().getDisplayMetrics());
    for (int i = 0; i < typedArray.getIndexCount(); i++) {
        int attr = typedArray.getIndex(i);
        if (attr == R.styleable.ChangeColorItem_item_icon) {
            BitmapDrawable drawable = (BitmapDrawable) typedArray.getDrawable(attr);
            if (drawable != null)
                mIconBitmap = drawable.getBitmap();

        } else if (attr == R.styleable.ChangeColorItem_item_icon_color) {
            mIconColor = typedArray.getColor(attr, 0xFF45C01A);

        } else if (attr == R.styleable.ChangeColorItem_item_text_color) {
            mTextColor = typedArray.getColor(attr, 0xFF45C01A);

        } else if (attr == R.styleable.ChangeColorItem_item_tab_color) {
            mTabLineColor = typedArray.getColor(attr, 0xFF45C01A);

        } else if (attr == R.styleable.ChangeColorItem_item_text) {
            mText = typedArray.getString(attr);

        } else if (attr == R.styleable.ChangeColorItem_item_tab_position) {
            tabPosition = typedArray.getString(attr);

        } else if (attr == R.styleable.ChangeColorItem_item_text_size) {
            mTextSize = (int) typedArray.getDimension(attr, TypedValue
                    .applyDimension(TypedValue.COMPLEX_UNIT_SP, 12,
                            getResources().getDisplayMetrics()));

        }

    }
    typedArray.recycle();

    mTextBound = new Rect();
    mTextPaint = new Paint();
    mTextPaint.setAntiAlias(true);
    mTextPaint.setDither(true);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setColor(0Xff555555);
    mTextPaint.getTextBounds(mText, 0, mText.length(), mTextBound);

    // Hacking the view to add Stepper line to bottom of the view
    mLineBound = new Rect();
    mLinePaint = new Paint();
    mLinePaint.setAntiAlias(true);
    mLinePaint.setDither(true);
    mLinePaint.setTextSize(mLineTextSize);
    mLinePaint.setColor(0Xff555555);
    mLinePaint.getTextBounds(mLineText, 0, mLineText.length(), mLineBound);

    mIconRect = new Rect();

}