Example usage for android.graphics Canvas clipPath

List of usage examples for android.graphics Canvas clipPath

Introduction

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

Prototype

public boolean clipPath(@NonNull Path path) 

Source Link

Document

Intersect the current clip with the specified path.

Usage

From source file:pl.rmakowiecki.simplemusicplayer.ui.widget.MusicCoverView.java

@Override
protected void onDraw(Canvas canvas) {
    canvas.clipPath(mClipPath);
    super.onDraw(canvas);
    canvas.drawPath(mTrackPath, mTrackPaint);
}

From source file:com.andremion.music.MusicCoverView.java

@Override
protected void onDraw(Canvas canvas) {

    if (SHAPE_CIRCLE == mShape) {
        canvas.clipPath(mClipPath);
    } else if (SHAPE_RECTANGLE == mShape) {
        canvas.clipPath(mClipPath);/*from w  ww .  j  av  a 2 s. co m*/
    } else if (SHAPE_SQUARE == mShape) {
        if (getTransitionSquareAsCircle()) {
            canvas.clipPath(mClipPathAsCircle, Region.Op.REPLACE);
        } else {
            canvas.clipPath(mRectSquarePath, Region.Op.REPLACE);
        }
    }

    super.onDraw(canvas);
    canvas.drawPath(mTrackPath, mTrackPaint);
    canvas.drawPath(mDiscPathCenterDecor, mDiscPaintCenterDecor);
    canvas.drawPath(mDiscPathCenter, mDiscPaintCenter);

}

From source file:com.mukesh.OtpView.java

private void drawOtpView(Canvas canvas) {
    int nextItemToFill;
    if (rtlTextDirection) {
        nextItemToFill = otpViewItemCount - 1;
    } else {// w w  w . j a va 2s .  c  om
        if (getText() != null) {
            nextItemToFill = getText().length();
        } else {
            nextItemToFill = 0;
        }
    }
    for (int i = 0; i < otpViewItemCount; i++) {
        boolean itemSelected = isFocused() && nextItemToFill == i;
        boolean itemFilled = i < nextItemToFill;
        int[] itemState = null;
        if (itemFilled) {
            itemState = FILLED_STATE;
        } else if (itemSelected) {
            itemState = SELECTED_STATE;
        }
        paint.setColor(itemState != null ? getLineColorForState(itemState) : cursorLineColor);
        updateItemRectF(i);
        updateCenterPoint();
        canvas.save();
        if (viewType == VIEW_TYPE_RECTANGLE) {
            updateOtpViewBoxPath(i);
            canvas.clipPath(path);
        }
        drawItemBackground(canvas, itemState);
        canvas.restore();
        if (itemSelected) {
            drawCursor(canvas);
        }
        if (viewType == VIEW_TYPE_RECTANGLE) {
            drawOtpBox(canvas, i);
        } else if (viewType == VIEW_TYPE_LINE) {
            drawOtpLine(canvas, i);
        }
        if (DBG) {
            drawAnchorLine(canvas);
        }
        if (rtlTextDirection) {
            int reversedPosition = otpViewItemCount - i;
            if (getText().length() >= reversedPosition) {
                drawInput(canvas, i);
            } else if (!TextUtils.isEmpty(getHint()) && getHint().length() == otpViewItemCount) {
                drawHint(canvas, i);
            }
        } else {
            if (getText().length() > i) {
                drawInput(canvas, i);
            } else if (!TextUtils.isEmpty(getHint()) && getHint().length() == otpViewItemCount) {
                drawHint(canvas, i);
            }
        }
    }
    if (isFocused() && getText() != null && getText().length() != otpViewItemCount
            && viewType == VIEW_TYPE_RECTANGLE) {
        int index = getText().length();
        updateItemRectF(index);
        updateCenterPoint();
        updateOtpViewBoxPath(index);
        paint.setColor(getLineColorForState(SELECTED_STATE));
        drawOtpBox(canvas, index);
    }
}