Example usage for android.graphics Canvas drawRect

List of usage examples for android.graphics Canvas drawRect

Introduction

In this page you can find the example usage for android.graphics Canvas drawRect.

Prototype

public void drawRect(float left, float top, float right, float bottom, @NonNull Paint paint) 

Source Link

Document

Draw the specified Rect using the specified paint.

Usage

From source file:com.ahamed.sample.common.decorator.ArticleItemDecorator.java

@SuppressLint("NewApi")
private void draw(Canvas canvas, RecyclerView parent, View child) {
    canvas.save();//from   w w w  .  j  av  a  2  s.  c  o m
    final int left;
    final int right;
    if (parent.getClipToPadding()) {
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
        canvas.clipRect(left, parent.getPaddingTop(), right, parent.getHeight() - parent.getPaddingBottom());
    } else {
        left = 0;
        right = parent.getWidth();
    }

    parent.getDecoratedBoundsWithMargins(child, mBounds);
    final int bottom = mBounds.bottom + Math.round(ViewCompat.getTranslationY(child));
    final int top = bottom - 16;

    canvas.drawRect(left, top, right, bottom, myPaint);
    canvas.restore();
}

From source file:com.arbo.gaogao.view.GridItemDividerDecoration.java

@Override
public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    if (parent.isAnimating())
        return;// w w  w  .  jav  a 2 s . c  om

    final int childCount = parent.getChildCount();
    final RecyclerView.LayoutManager lm = parent.getLayoutManager();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        RecyclerView.ViewHolder viewHolder = parent.getChildViewHolder(child);

        if (requiresDivider(viewHolder)) {
            final int right = lm.getDecoratedRight(child);
            final int bottom = lm.getDecoratedBottom(child);
            // draw the bottom divider
            canvas.drawRect(lm.getDecoratedLeft(child), bottom - dividerSize, right, bottom, paint);
            // draw the right edge divider
            canvas.drawRect(right - dividerSize, lm.getDecoratedTop(child), right, bottom - dividerSize, paint);
        }

    }
}

From source file:com.amitupadhyay.aboutexample.ui.recyclerview.GridItemDividerDecoration.java

@Override
public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    if (parent.isAnimating())
        return;//from  ww w .ja v a 2 s .  c  om

    final int childCount = parent.getChildCount();
    final RecyclerView.LayoutManager lm = parent.getLayoutManager();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        RecyclerView.ViewHolder viewHolder = parent.getChildViewHolder(child);

        if (requiresDivider(viewHolder)) {
            final int right = lm.getDecoratedRight(child);
            final int bottom = lm.getDecoratedBottom(child);
            // draw the bottom divider
            canvas.drawRect(lm.getDecoratedLeft(child), bottom - dividerSize, right, bottom, paint);
            // draw the right edge divider
            canvas.drawRect(right - dividerSize, lm.getDecoratedTop(child), right, bottom - dividerSize, paint);
        }
    }
}

From source file:android.example.com.visualizerpreferences.AudioVisuals.VisualizerView.java

public VisualizerView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mBytes = null;/*from w w  w.j av  a 2 s .  c  o m*/
    TrailedShape.setMinSize(MIN_SIZE_DEFAULT);

    // Create each of the shapes and define how they are drawn on screen
    // Make bass circle
    mBassCircle = new TrailedShape(BASS_MULTIPLIER) {
        @Override
        protected void drawThisShape(float shapeCenterX, float shapeCenterY, float currentSize, Canvas canvas,
                Paint paint) {
            canvas.drawCircle(shapeCenterX, shapeCenterY, currentSize, paint);
        }
    };

    // Make midrange square
    mMidSquare = new TrailedShape(MID_MULTIPLIER) {
        @Override
        protected void drawThisShape(float shapeCenterX, float shapeCenterY, float currentSize, Canvas canvas,
                Paint paint) {
            canvas.drawRect(shapeCenterX - currentSize, shapeCenterY - currentSize, shapeCenterX + currentSize,
                    shapeCenterY + currentSize, paint);
        }
    };

    // Make treble triangle
    mTrebleTriangle = new TrailedShape(TREBLE_MULTIPLIER) {
        @Override
        protected void drawThisShape(float shapeCenterX, float shapeCenterY, float currentSize, Canvas canvas,
                Paint paint) {
            Path trianglePath = new Path();
            trianglePath.moveTo(shapeCenterX, shapeCenterY - currentSize);
            trianglePath.lineTo(shapeCenterX + currentSize, shapeCenterY + currentSize / 2);
            trianglePath.lineTo(shapeCenterX - currentSize, shapeCenterY + currentSize / 2);
            trianglePath.lineTo(shapeCenterX, shapeCenterY - currentSize);
            canvas.drawPath(trianglePath, paint);
        }
    };
}

From source file:com.loopeer.codereader.ui.decoration.DividerItemDecorationMainList.java

public void drawVertical(Canvas c, RecyclerView parent) {
    final int left = parent.getPaddingLeft();
    final int right = parent.getWidth() - parent.getPaddingRight();

    final int childCount = parent.getChildCount();

    for (int i = 0; i < childCount - 1; i++) {
        if (i == 0) {
            continue;
        }//from  w ww.  jav a2  s  .  c  om
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int top = child.getBottom() + params.bottomMargin + Math.round(ViewCompat.getTranslationY(child));
        final int bottom = top + dividerHeight;

        c.drawRect(left, top, left + startpadding, bottom, mPaddingPaint);
        c.drawRect(right - endpadding, top, right, bottom, mPaddingPaint);
        c.drawRect(left + startpadding, top, right - endpadding, bottom, mDividerPaint);
    }
}

From source file:com.example.aqing.materialdesign.deleteitem.DividerItemDecoration.java

public void drawHorizontal(Canvas c, RecyclerView parent) {
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount - 1; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int left = child.getRight() + params.rightMargin + Math.round(ViewCompat.getTranslationX(child));
        final int right = left + dividerHeight;
        c.drawRect(left, top, right, top + startpadding, mPaddingPaint);
        c.drawRect(left, bottom - endpadding, right, bottom, mPaddingPaint);
        c.drawRect(left, top + startpadding, right, bottom - endpadding, mDividerPaint);
    }//from  w  w w .j  a  v a 2s  . c  o m
}

From source file:com.example.aqing.materialdesign.deleteitem.DividerItemDecoration.java

public void drawVertical(Canvas c, RecyclerView parent) {
    final int left = parent.getPaddingLeft();
    final int right = parent.getWidth() - parent.getPaddingRight();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount - 1; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int top = child.getBottom() + params.bottomMargin + Math.round(ViewCompat.getTranslationY(child));
        final int bottom = top + dividerHeight;

        c.drawRect(left, top, left + startpadding, bottom, mPaddingPaint);
        c.drawRect(right - endpadding, top, right, bottom, mPaddingPaint);
        c.drawRect(left + startpadding, top, right - endpadding, bottom, mDividerPaint);
    }/* w w  w.  j  a  va 2  s. c o m*/
}

From source file:com.jungle.toolbaractivity.layout.HorizontalSwipeBackLayout.java

@Override
protected void dispatchDraw(Canvas canvas) {
    if (!mSwipeBackEnable) {
        super.dispatchDraw(canvas);
        return;//from  ww  w.ja va 2s  . c o m
    }

    final int width = getMeasuredWidth();
    final int height = getMeasuredHeight();

    if (mBkgDrawable != null) {
        mBkgDrawable.setBounds((int) (mTranslationX + 0.5f), 0, width, height);
        mBkgDrawable.draw(canvas);
    } else {
        Paint paint = new Paint();
        paint.setColor(Color.WHITE);
        canvas.drawRect(mTranslationX, 0, width, height, paint);
    }

    if (mTranslationX > 0) {
        canvas.save();
        canvas.translate(mTranslationX - mShadowWidth, 0);
        mEdgeShadowDrawable.setBounds(0, 0, mShadowWidth, height);
        mEdgeShadowDrawable.draw(canvas);
        canvas.restore();
    }

    super.dispatchDraw(canvas);
}

From source file:com.kmagic.solitaire.DrawMaster.java

/**
 * Draw game background, green board/*from w  w  w .ja  v a 2s.  c  o m*/
 * @param canvas canvas to draw on
 */
public void drawBackground(final Canvas canvas) {
    canvas.drawRect(0, 0, mScreenWidth, mScreenHeight, mBGPaint);
}

From source file:com.kmagic.solitaire.DrawMaster.java

/**
 * Draw shade background/*w  ww . j a v  a 2s  .co m*/
 * @param canvas canvas to draw on
 */
public void drawShade(final Canvas canvas) {
    canvas.drawRect(0, 0, mScreenWidth, mScreenHeight, mShadePaint);
}