Example usage for android.graphics Canvas getClipBounds

List of usage examples for android.graphics Canvas getClipBounds

Introduction

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

Prototype

public boolean getClipBounds(@Nullable Rect bounds) 

Source Link

Document

Return the bounds of the current clip (in local coordinates) in the bounds parameter, and return true if it is non-empty.

Usage

From source file:org.stockchart.core.LegendItem.java

protected void innerDraw(Canvas c, CustomObjects customObjects) {
    c.getClipBounds(this.TempRect());

    float halfHeight = this.TempRect().height() / 2f;

    drawMarker(c, halfHeight, halfHeight, fMarkerSize / 2);

    fAppearance.applyText(this.Paint());

    SizeF sz = fAppearance.measureTextSize(fText, this.Paint(), false);

    c.drawText(fText, fMarkerSize + getOutlineIssues(), halfHeight + sz.height / 2f, this.Paint());
}

From source file:com.ez.gallery.ucrop.view.widget.AspectRatioTextView.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (isSelected()) {
        canvas.getClipBounds(mCanvasClipBounds);
        canvas.drawCircle((mCanvasClipBounds.right - mCanvasClipBounds.left) / 2.0f,
                mCanvasClipBounds.bottom - mDotSize, mDotSize / 2, mDotPaint);
    }/*from   w  w  w. j  av a 2  s .  c  o m*/
}

From source file:com.ez.gallery.ucrop.view.widget.HorizontalProgressWheelView.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.getClipBounds(mCanvasClipBounds);

    int linesCount = mCanvasClipBounds.width() / (mProgressLineWidth + mProgressLineMargin);
    float deltaX = (mTotalScrollDistance) % (float) (mProgressLineMargin + mProgressLineWidth);

    mProgressLinePaint.setColor(getResources().getColor(R.color.ucrop_color_progress_wheel_line));
    for (int i = 0; i < linesCount; i++) {
        if (i < (linesCount / 4)) {
            mProgressLinePaint.setAlpha((int) (255 * (i / (float) (linesCount / 4))));
        } else if (i > (linesCount * 3 / 4)) {
            mProgressLinePaint.setAlpha((int) (255 * ((linesCount - i) / (float) (linesCount / 4))));
        } else {/*from w w  w .  j  ava 2 s . co m*/
            mProgressLinePaint.setAlpha(255);
        }
        canvas.drawLine(-deltaX + mCanvasClipBounds.left + i * (mProgressLineWidth + mProgressLineMargin),
                mCanvasClipBounds.centerY() - mProgressLineHeight / 4.0f,
                -deltaX + mCanvasClipBounds.left + i * (mProgressLineWidth + mProgressLineMargin),
                mCanvasClipBounds.centerY() + mProgressLineHeight / 4.0f, mProgressLinePaint);
    }

    mProgressLinePaint.setColor(mMiddleLineColor);
    canvas.drawLine(mCanvasClipBounds.centerX(), mCanvasClipBounds.centerY() - mProgressLineHeight / 2.0f,
            mCanvasClipBounds.centerX(), mCanvasClipBounds.centerY() + mProgressLineHeight / 2.0f,
            mProgressLinePaint);

}

From source file:org.stockchart.core.Legend.java

protected void innerDraw(Canvas c, CustomObjects customObjects) {
    if (!isVisible())
        return;//from w w w .  j a va  2 s  .com

    c.getClipBounds(fTempRect);

    PaintUtils.drawFullRect(c, fPaint, fLegendAppearance, fTempRect);

    for (LegendItem i : fItems)
        i.draw(c, customObjects);

}

From source file:org.mozilla.focus.widget.AnimatedProgressBar.java

@Override
public void onDraw(Canvas canvas) {
    if (mClipRegion == 0) {
        super.onDraw(canvas);
    } else {/*from www  .  j  a  v a  2s . co m*/
        canvas.getClipBounds(tempRect);
        final float clipWidth = tempRect.width() * mClipRegion;
        final int saveCount = canvas.save();

        if (mIsRtl) {
            canvas.clipRect(tempRect.left, tempRect.top, tempRect.right - clipWidth, tempRect.bottom);
        } else {
            canvas.clipRect(tempRect.left + clipWidth, tempRect.top, tempRect.right, tempRect.bottom);
        }
        super.onDraw(canvas);
        canvas.restoreToCount(saveCount);
    }
}

From source file:org.stockchart.core.Axis.java

@Override
protected void innerDraw(Canvas c, CustomObjects customObjects) {
    if (!isVisible())
        return;//from  w ww.j ava2  s.  c om

    fPaintInfo.loadFrom(this);

    c.getClipBounds(fTempRect);

    fAppearance.applyFill(fPaint, fTempRect);
    c.drawRect(fTempRect, fPaint);

    GridLabelPosition pos = GridLabelPosition.NEAR;

    switch (this.getSide()) {
    case LEFT: {
        pos = GridLabelPosition.FAR;
    }
        break;
    case TOP: {
        pos = GridLabelPosition.FAR;
    }
        break;
    case RIGHT: {
        pos = GridLabelPosition.NEAR;
    }
        break;

    case BOTTOM: {
        pos = GridLabelPosition.NEAR;
    }
        break;
    }

    Double[] values = this.getScaleValues(fPaintInfo);
    if (null != values)
        GridPainter.drawGrid(values, fTempRect, c, fAppearance, fPaint, fPaintInfo, getGridType(), pos, this,
                3.0f);

    if (this.fDrawMaxMin) {
        GridPainter.drawGridLineAt(fPaintInfo.Max, fTempRect, c, fAppearance, fPaint, fPaintInfo, getGridType(),
                pos, this, 3.0f);
        GridPainter.drawGridLineAt(fPaintInfo.Min, fTempRect, c, fAppearance, fPaint, fPaintInfo, getGridType(),
                pos, this, 3.0f);
    }

    if (this.fDrawLastValue) {
        Iterator<SeriesBase> i = fParent.getSeries().iterator();
        while (i.hasNext()) {
            AbstractSeries<?> ss = (AbstractSeries<?>) i.next();

            double lastValue = ss.getLastValue();

            if (!Double.isNaN(lastValue) && ss.getYAxisSide() == getSide()) {
                GridPainter.drawGridLineAt(lastValue, fTempRect, c, ss.getAppearance(), fPaint, fPaintInfo,
                        getGridType(), pos, this, 3.0f);
            }
        }
    }

}

From source file:com.acbelter.scheduleview.ScheduleView.java

private void changeClipRect(Canvas canvas) {
    canvas.getClipBounds(mClipRect);
    mClipRect.left += getPaddingLeft();//from   w  w  w .  ja v  a2s.  c  o  m
    mClipRect.top += getPaddingTop();
    mClipRect.right -= getPaddingRight();
    mClipRect.bottom -= getPaddingBottom();
    canvas.clipRect(mClipRect);
}

From source file:com.android.widget.SlidingPaneLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    boolean result;
    final int save = canvas.save(Canvas.CLIP_SAVE_FLAG);

    if (mCanSlide && !lp.slideable && mSlideableView != null) {
        // Clip against the slider; no sense drawing what will immediately be covered.
        canvas.getClipBounds(mTmpRect);
        mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop());
        canvas.clipRect(mTmpRect);/*from   ww  w.ja v  a2  s  .  c  om*/
    }

    result = super.drawChild(canvas, child, drawingTime);

    canvas.restoreToCount(save);

    return result;
}

From source file:uk.ac.kent.jb509.shopper.utils.SlidingUpPanelLayout.java

@Override
protected boolean drawChild(final Canvas canvas, final View child, final long drawingTime) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    boolean result;
    final int save = canvas.save(Canvas.CLIP_SAVE_FLAG);

    boolean drawScrim = false;

    if (mCanSlide && !lp.slideable && mSlideableView != null) {
        // Clip against the slider; no sense drawing what will immediately
        // be covered.
        canvas.getClipBounds(mTmpRect);
        mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop());

        if (!mIsTransparent) {
            canvas.clipRect(mTmpRect);//  ww  w  .ja v  a2  s.c o m
        }

        if (mSlideOffset < 1) {
            drawScrim = true;
        }
    }

    result = super.drawChild(canvas, child, drawingTime);
    canvas.restoreToCount(save);

    if (drawScrim) {
        final int baseAlpha = (mCoveredFadeColor & 0xff000000) >>> 24;
        final int imag = (int) (baseAlpha * (1 - mSlideOffset));
        final int color = imag << 24 | mCoveredFadeColor & 0xffffff;
        mCoveredFadePaint.setColor(color);
        canvas.drawRect(mTmpRect, mCoveredFadePaint);
    }

    return result;
}

From source file:ca.mymenuapp.ui.widgets.SlidingUpPanelLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    boolean result;
    final int save = canvas.save(Canvas.CLIP_SAVE_FLAG);

    boolean drawScrim = false;

    if (mCanSlide && !lp.slideable && mSlideableView != null) {
        // Clip against the slider; no sense drawing what will immediately be covered.
        canvas.getClipBounds(mTmpRect);
        if (mIsSlidingUp) {
            mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop());
        } else {/*from w ww. j a v a2s  .  co m*/
            mTmpRect.top = Math.max(mTmpRect.top, mSlideableView.getBottom());
        }
        canvas.clipRect(mTmpRect);
        if (mSlideOffset < 1) {
            drawScrim = true;
        }
    }

    result = super.drawChild(canvas, child, drawingTime);
    canvas.restoreToCount(save);

    if (drawScrim) {
        final int baseAlpha = (mCoveredFadeColor & 0xff000000) >>> 24;
        final int imag = (int) (baseAlpha * (1 - mSlideOffset));
        final int color = imag << 24 | (mCoveredFadeColor & 0xffffff);
        mCoveredFadePaint.setColor(color);
        canvas.drawRect(mTmpRect, mCoveredFadePaint);
    }

    return result;
}