Java Code Examples for android.graphics.Paint#DITHER_FLAG

The following examples show how to use android.graphics.Paint#DITHER_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: RefreshView.java    From WidgetCase with Apache License 2.0 6 votes vote down vote up
private void init(Context context) {
        mContext = context;

        DisplayMetrics dm = getResources().getDisplayMetrics();
        mScreenW = dm.widthPixels;
        mHeadBmp = BitmapFactory.decodeResource(getResources(), R.drawable.load_more_1);

//		mScrDistance = mScreenH / 3 - 46;
        mHeadW = mHeadBmp.getWidth();
        mHeadH = mHeadBmp.getHeight();
        mInitLeftPX = mScreenW / 2 - mHeadW;
        mInitRightPX = mScreenW / 2 + mHeadW;
        mBmpL = mScreenW / 2 - mHeadBmp.getWidth() / 2;
        mBmpT = 0;

        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
        mPaint.setColor(Color.RED);
        mPaint.setStyle(Style.FILL);//设置非填充
        mScroller = new Scroller(mContext, new DecelerateInterpolator());
        mScroller1 = new Scroller(mContext, new DecelerateInterpolator());

        mAniDraw = (AnimationDrawable) mAnimList.getDrawable();
    }
 
Example 2
Source File: CustomShadow.java    From Android-Plugin-Framework with MIT License 6 votes vote down vote up
public CustomShadow(Resources resources, int backgroundColor, float radius, float shadowSize,
    float maxShadowSize) {
  mShadowStartColor = resources.getColor(R.color.cardview_shadow_start_color);
  mShadowEndColor = resources.getColor(R.color.cardview_shadow_end_color);
  mInsetShadow = resources.getDimensionPixelSize(R.dimen.cardview_compat_inset_shadow);
  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);
  mCornerRadius = (int) (radius + .5f);
  mCardBounds = new RectF();
  mEdgeShadowPaint = new Paint(mCornerShadowPaint);
  mEdgeShadowPaint.setAntiAlias(false);
  setShadowSize(shadowSize, maxShadowSize);

  CustomShadow.sRoundRectHelper = new RoundRectHelper() {
    @Override
    public void drawRoundRect(Canvas canvas, RectF bounds, float cornerRadius, Paint paint) {
      canvas.drawRoundRect(bounds, cornerRadius, cornerRadius, paint);
    }
  };
}
 
Example 3
Source File: DataRenderer.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
public DataRenderer(ChartAnimator animator, ViewPortHandler viewPortHandler) {
    super(viewPortHandler);
    this.mAnimator = animator;

    mRenderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mRenderPaint.setStyle(Style.FILL);

    mDrawPaint = new Paint(Paint.DITHER_FLAG);

    mValuePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mValuePaint.setColor(Color.rgb(63, 63, 63));
    mValuePaint.setTextAlign(Align.CENTER);
    mValuePaint.setTextSize(Utils.convertDpToPixel(9f));

    mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mHighlightPaint.setStyle(Paint.Style.STROKE);
    mHighlightPaint.setStrokeWidth(2f);
    mHighlightPaint.setColor(Color.rgb(255, 187, 115));
}
 
Example 4
Source File: CircleTransform.java    From android-proguards with Apache License 2.0 6 votes vote down vote up
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
    if (source == null) return null;

    int size = Math.min(source.getWidth(), source.getHeight());
    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;

    // TODO this could be acquired from the pool too
    Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);

    Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
    if (result == null) {
        result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(result);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG | Paint
            .ANTI_ALIAS_FLAG);
    paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader
            .TileMode.CLAMP));
    float r = size / 2f;
    canvas.drawCircle(r, r, r, paint);
    return result;
}
 
Example 5
Source File: DrawingView.java    From Coloring-book with Apache License 2.0 6 votes vote down vote up
private void setupDrawing() {

        brushSize = getResources().getInteger(R.integer.medium_size);
        lastBrushSize = brushSize;
        drawPath = new Path();
        drawPaint = new Paint();
        drawPaint.setColor(paintColor);
        drawPaint.setAntiAlias(true);
        drawPaint.setStrokeWidth(brushSize);
        drawPaint.setStyle(Paint.Style.STROKE);
        drawPaint.setStrokeJoin(Paint.Join.ROUND);
        drawPaint.setStrokeCap(Paint.Cap.ROUND);
        drawPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));

        canvasPaint = new Paint(Paint.DITHER_FLAG);
    }
 
Example 6
Source File: CircleTransform.java    From ZhihuDaily with Apache License 2.0 6 votes vote down vote up
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
    if (source == null) return null;

    int size = Math.min(source.getWidth(), source.getHeight());
    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;

    // TODO this could be acquired from the pool too
    Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);

    Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
    if (result == null) {
        result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(result);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG | Paint
            .ANTI_ALIAS_FLAG);
    paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader
            .TileMode.CLAMP));
    float r = size / 2f;
    canvas.drawCircle(r, r, r, paint);
    return result;
}
 
Example 7
Source File: DoodleView.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
private void init(Context context) {
    mBitmapPaint = new Paint(Paint.DITHER_FLAG | Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);

    mBgColor = ResourcesUtils.getAttrColor(context, R.attr.colorPure);

    mColor = ResourcesUtils.getAttrColor(context, R.attr.colorPureInverse);
    mWidth = LayoutUtils.dp2pix(context, 4);

    mPath = new Path();

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);

    mRecycler = new Recycler();
}
 
Example 8
Source File: CardViewDecoration.java    From recyclerviewItemDecorations with MIT License 6 votes vote down vote up
public CardViewDecoration(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);

    buildShadowCorners();
}
 
Example 9
Source File: SimpleRatingBar.java    From SimpleRatingBar with Apache License 2.0 5 votes vote down vote up
/**
 * Inits paint objects and default values.
 */
private void initView() {
  starPath = new Path();
  cornerPathEffect = new CornerPathEffect(starCornerRadius);

  paintStarOutline = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
  paintStarOutline.setStyle(Paint.Style.FILL_AND_STROKE);
  paintStarOutline.setAntiAlias(true);
  paintStarOutline.setDither(true);
  paintStarOutline.setStrokeJoin(Paint.Join.ROUND);
  paintStarOutline.setStrokeCap(Paint.Cap.ROUND);
  paintStarOutline.setColor(Color.BLACK);
  paintStarOutline.setPathEffect(cornerPathEffect);

  paintStarBorder = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
  paintStarBorder.setStyle(Paint.Style.STROKE);
  paintStarBorder.setStrokeJoin(Paint.Join.ROUND);
  paintStarBorder.setStrokeCap(Paint.Cap.ROUND);
  paintStarBorder.setStrokeWidth(starBorderWidth);
  paintStarBorder.setPathEffect(cornerPathEffect);

  paintStarBackground = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
  paintStarBackground.setStyle(Paint.Style.FILL_AND_STROKE);
  paintStarBackground.setAntiAlias(true);
  paintStarBackground.setDither(true);
  paintStarBackground.setStrokeJoin(Paint.Join.ROUND);
  paintStarBackground.setStrokeCap(Paint.Cap.ROUND);

  paintStarFill = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
  paintStarFill.setStyle(Paint.Style.FILL_AND_STROKE);
  paintStarFill.setAntiAlias(true);
  paintStarFill.setDither(true);
  paintStarFill.setStrokeJoin(Paint.Join.ROUND);
  paintStarFill.setStrokeCap(Paint.Cap.ROUND);

  defaultStarSize = applyDimension(COMPLEX_UNIT_DIP, 30, getResources().getDisplayMetrics());
}
 
Example 10
Source File: ClippedImageView.java    From beauty-treatment-android-animations with Apache License 2.0 5 votes vote down vote up
private void setupStrokePaint(int color, int borderWidth) {

        strokePaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
        strokePaint.setStrokeJoin(Paint.Join.ROUND);
        strokePaint.setStrokeCap(Paint.Cap.ROUND);
        strokePaint.setStyle(Paint.Style.STROKE);
        strokePaint.setColor(color);
        strokePaint.setStrokeWidth(borderWidth);
    }
 
Example 11
Source File: DividerView.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DividerView);
    int color = a.getColor(R.styleable.DividerView_dividerColor, Color.BLACK);
    mDividerWidth = a.getDimensionPixelOffset(R.styleable.DividerView_dividerWidth, 0);
    mDividerHeight = a.getDimensionPixelOffset(R.styleable.DividerView_dividerHeight, 0);
    a.recycle();

    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    mPaint.setColor(color);
    mRect = new Rect();
}
 
Example 12
Source File: RoundRectDrawable.java    From Slice with Apache License 2.0 5 votes vote down vote up
public RoundRectDrawable(int backgroundColor, float radius) {
    mRadius = radius;
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    mPaint.setColor(backgroundColor);
    mBoundsF = new RectF();
    mBoundsI = new Rect();
}
 
Example 13
Source File: ShadowRenderer.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
public ShadowRenderer(int color) {
  shadowPaint = new Paint();
  setShadowColor(color);

  transparentPaint.setColor(Color.TRANSPARENT);
  cornerShadowPaint = new Paint(Paint.DITHER_FLAG);
  cornerShadowPaint.setStyle(Paint.Style.FILL);

  edgeShadowPaint = new Paint(cornerShadowPaint);
}
 
Example 14
Source File: CardView.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
public RoundRectDrawableWithShadow(Resources resources, int backgroundColor, float size) {
	float density = ResourceUtils.obtainDensity(resources);
	insetShadow = (int) (1f * density + 0.5f);
	paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
	paint.setColor(backgroundColor);
	cornerShadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
	cornerShadowPaint.setStyle(Paint.Style.FILL);
	cornerRadius = (int) (size + .5f);
	cardBounds = new RectF();
	edgeShadowPaint = new Paint(cornerShadowPaint);
	edgeShadowPaint.setAntiAlias(false);
	setShadowSize(size, size);
}
 
Example 15
Source File: RoundRectDrawable.java    From AppCompat-Extension-Library with Apache License 2.0 5 votes vote down vote up
public RoundRectDrawable(int backgroundColor, float radius) {
    mRadius = radius;
    // increment it to account for half pixels.
    if (mHasJellybeanMr1 && mRadius >= 1f)
        mRadius += .5f;
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    mPaint.setColor(backgroundColor);
    mCornerRect = new RectF();
    mBoundsF = new RectF();
    mBoundsI = new Rect();
}
 
Example 16
Source File: BubbleLayout.java    From HappyBubble with Apache License 2.0 5 votes vote down vote up
public BubbleLayout(Context context, AttributeSet attrs, int defStyleAttr)
{
    super(context, attrs, defStyleAttr);
    setLayerType(LAYER_TYPE_SOFTWARE, null);
    setWillNotDraw(false);
    initAttr(context.obtainStyledAttributes(attrs, R.styleable.BubbleLayout, defStyleAttr, 0));
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    mPaint.setStyle(Paint.Style.FILL);
    mPath = new Path();
    initPadding();
}
 
Example 17
Source File: TriangleDrawable.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
public TriangleDrawable(int color) {
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    mPaint.setColor(color);
    mPath = new Path();
}
 
Example 18
Source File: WheelPicker.java    From ScrollChoice with MIT License 4 votes vote down vote up
public WheelPicker(Context context, AttributeSet attrs) {
    super(context, attrs);
    adapter = new Adapter();

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.WheelPicker);

    mItemTextSize = a.getDimensionPixelSize(R.styleable.WheelPicker_scroll_item_text_size,
            getResources().getDimensionPixelSize(R.dimen.WheelItemTextSize));
    mVisibleItemCount = a.getInt(R.styleable.WheelPicker_scroll_visible_item_count, 7);
    selectedItemPosition = a.getInt(R.styleable.WheelPicker_scroll_selected_item_position, 0);
    textMaxWidthPosition = a.getInt(R.styleable.WheelPicker_scroll_maximum_width_text_position, -1);
    maxWidthText = a.getString(R.styleable.WheelPicker_scroll_maximum_width_text);
    mSelectedItemTextColor = a.getColor(R.styleable.WheelPicker_scroll_selected_item_text_color, -1);
    mItemTextColor = a.getColor(R.styleable.WheelPicker_scroll_item_text_color, 0xFF424242);
    backgroundColor = a.getColor(R.styleable.WheelPicker_scroll_background_color, 0xFFF5F5F5);
    backgroundOfSelectedItem = a.getColor(R.styleable.WheelPicker_scroll_selected_item_background, 0xFFFFFFFF);
    mItemSpace = a.getDimensionPixelSize(R.styleable.WheelPicker_scroll_item_space,
            getResources().getDimensionPixelSize(R.dimen.WheelItemSpace));
    hasIndicator = a.getBoolean(R.styleable.WheelPicker_scroll_indicator, false);
    mIndicatorColor = a.getColor(R.styleable.WheelPicker_scroll_indicator_color, 0xFFDDDDDD);
    mIndicatorSize = a.getDimensionPixelSize(R.styleable.WheelPicker_scroll_indicator_size,
            getResources().getDimensionPixelSize(R.dimen.WheelIndicatorSize));
    hasAtmospheric = a.getBoolean(R.styleable.WheelPicker_scroll_atmospheric, false);
    mItemAlign = a.getInt(R.styleable.WheelPicker_scroll_item_align, ALIGN_CENTER);
    a.recycle();

    updateVisibleItemCount();

    paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG | Paint.LINEAR_TEXT_FLAG);
    paintBackground = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG );
    paint.setTextSize(mItemTextSize);

    updateItemTextAlign();

    computeTextSize();

    scroller = new Scroller(getContext());


    ViewConfiguration conf = ViewConfiguration.get(getContext());
    minimumVelocity = conf.getScaledMinimumFlingVelocity();
    maximumVelocity = conf.getScaledMaximumFlingVelocity();
    touchSlop = conf.getScaledTouchSlop();
    rectDrawn = new Rect();

    rectIndicatorHead = new Rect();
    rectIndicatorFoot = new Rect();

    rectCurrentItem = new Rect();
}
 
Example 19
Source File: DebugCanvasLogger.java    From DrawableView with Apache License 2.0 4 votes vote down vote up
public DebugCanvasLogger() {
  paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG | Paint.FILTER_BITMAP_FLAG);
  paint.setTextSize(25.0f);
}
 
Example 20
Source File: PolygonDrawable.java    From AndroidUtilCode with Apache License 2.0 4 votes vote down vote up
public PolygonDrawable(int num, int color) {
    mNum = num;
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setColor(color);
}