Example usage for android.graphics Canvas clipRect

List of usage examples for android.graphics Canvas clipRect

Introduction

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

Prototype

public boolean clipRect(@NonNull Rect rect) 

Source Link

Document

Intersect the current clip with the specified rectangle, which is expressed in local coordinates.

Usage

From source file:com.blestep.sportsbracelet.view.TimelineChartViewSleep.java

/**
 * {@inheritDoc}/*from w w  w  . j  av  a2  s  .  co m*/
 */
@Override
protected void onDraw(Canvas c) {
    // 
    c.clipRect(mViewArea);
    mViewAreaBgShader = new LinearGradient(0, 0, 0, mViewArea.height(),
            ContextCompat.getColor(getContext(), R.color.tlcSleepGraphBgColorStart),
            ContextCompat.getColor(getContext(), R.color.tlcSleepGraphBgColorEnd), Shader.TileMode.CLAMP);
    mViewAreaBgPaint.setShader(mViewAreaBgShader);
    // 
    c.drawRect(mViewArea, mViewAreaBgPaint);
    c.drawRect(mGraphArea, mGraphAreaBgPaint);
    c.drawRect(mFooterArea, mFooterAreaBgPaint);
    // 
    c.drawLine(0, mGraphArea.height(), mGraphArea.width(), mGraphArea.height(), mGraphBottomLinePaint);

    final SparseArray<Object[]> data;
    final double maxValue;
    synchronized (mLock) {
        data = mData;
        maxValue = mMaxValue;
    }
    boolean hasData = data.size() > 0;
    if (hasData) {

        // ???
        computeItemsOnScreen(data.size());
        // 
        drawBarItems(c, data, maxValue);
        // 
        drawTickLabels(c, data);

    }
}

From source file:com.blestep.sportsbracelet.view.TimelineChartView.java

/**
 * {@inheritDoc}/*w  w  w  .j ava 2s  . co m*/
 */
@Override
protected void onDraw(Canvas c) {
    // 
    c.clipRect(mViewArea);
    mViewAreaBgShader = new LinearGradient(0, 0, 0, mViewArea.height(),
            ContextCompat.getColor(getContext(), R.color.tlcStepsGraphBgColorStart),
            ContextCompat.getColor(getContext(), R.color.tlcStepsGraphBgColorEnd), Shader.TileMode.CLAMP);
    mViewAreaBgPaint.setShader(mViewAreaBgShader);
    // 
    c.drawRect(mViewArea, mViewAreaBgPaint);
    c.drawRect(mGraphArea, mGraphAreaBgPaint);
    c.drawRect(mFooterArea, mFooterAreaBgPaint);
    // 
    c.drawLine(0, mGraphArea.height(), mGraphArea.width(), mGraphArea.height(), mGraphBottomLinePaint);

    final SparseArray<Object[]> data;
    final double maxValue;
    synchronized (mLock) {
        data = mData;
        if (mIsShowTargetDashedLine && mTargetValue > mMaxValue) {
            maxValue = mTargetValue;
        } else {
            maxValue = mMaxValue;
        }
    }
    boolean hasData = data.size() > 0;
    if (hasData) {

        // ???
        computeItemsOnScreen(data.size());
        // 
        drawTargetLine(c);
        // 
        drawBarItems(c, data, maxValue);
        // 
        drawTickLabels(c, data);

    }
}

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

private void changeClipRect(Canvas canvas) {
    canvas.getClipBounds(mClipRect);//from   www  . j  a v a2s . co  m
    mClipRect.left += getPaddingLeft();
    mClipRect.top += getPaddingTop();
    mClipRect.right -= getPaddingRight();
    mClipRect.bottom -= getPaddingBottom();
    canvas.clipRect(mClipRect);
}

From source file:com.appunite.scroll.ScaleImageView.java

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

    // Clips the next few drawing operations to the content area
    int clipRestoreCount = canvas.save();
    canvas.clipRect(mContentRect);

    if (mSrc != null) {
        getRealTranslation(mTranslation, mRealTranslation);
        canvas.translate(mRealTranslation.x, mRealTranslation.y);
        canvas.scale(mScale, mScale);/*  w w  w. ja  va  2s  .c  o  m*/
        Log.v(TAG, "scale=" + mScale + " translation=" + mTranslation.toString() + " realTranslation="
                + mRealTranslation.toString());
        mSrc.draw(canvas);
    }

    // Removes clipping rectangle
    canvas.restoreToCount(clipRestoreCount);

    drawEdgeEffectsUnclipped(canvas);

}

From source file:com.facebook.react.views.scroll.ReactScrollView.java

@Override
public void draw(Canvas canvas) {
    if (mEndFillColor != Color.TRANSPARENT) {
        final View content = getChildAt(0);
        if (mEndBackground != null && content != null && content.getBottom() < getHeight()) {
            mEndBackground.setBounds(0, content.getBottom(), getWidth(), getHeight());
            mEndBackground.draw(canvas);
        }//from  www.j a v a  2  s .  com
    }
    getDrawingRect(mRect);

    switch (mOverflow) {
    case ViewProps.VISIBLE:
        break;
    default:
        canvas.clipRect(mRect);
        break;
    }

    super.draw(canvas);
}

From source file:cn.androidy.androiddevelopmentpatterns.interactivechart.InteractiveLineGraphView.java

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

    // Draws axes and text labels
    drawAxes(canvas);//from w  ww  .  j a  va2s  .  co m

    // Clips the next few drawing operations to the content area
    int clipRestoreCount = canvas.save();
    canvas.clipRect(mContentRect);

    drawDataSeriesUnclipped(canvas);
    drawEdgeEffectsUnclipped(canvas);

    // Removes clipping rectangle
    canvas.restoreToCount(clipRestoreCount);

    // Draws chart container
    canvas.drawRect(mContentRect, mAxisPaint);
}

From source file:com.mylikes.likes.etchasketch.Slate.java

private void drawStrokeDebugInfo(Canvas c) {
    final int ROW_HEIGHT = 24;
    final int ROW_MARGIN = 6;
    final int COLUMN_WIDTH = 55;

    final float FIRM_PRESSURE_LOW = 0.85f;
    final float FIRM_PRESSURE_HIGH = 1.25f;

    if (mStrokeDebugGraph == null) {
        final int width = c.getWidth() - 128;
        final int height = ROW_HEIGHT * mStrokes.length + 2 * ROW_MARGIN;
        mStrokeDebugGraph = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        if (mStrokeDebugGraph == null) {
            throw new RuntimeException(
                    "drawStrokeDebugInfo: couldn't create debug bitmap (" + width + "x" + height + ")");
        }/*from  w  w w.  j a v  a  2 s  .co m*/
        mGraphPaint1 = new Paint(Paint.ANTI_ALIAS_FLAG);
    }

    Canvas graph = new Canvas(mStrokeDebugGraph);
    graph.save();
    graph.clipRect(new Rect(0, 0, COLUMN_WIDTH, graph.getHeight()));
    graph.drawColor(0, PorterDuff.Mode.CLEAR);
    graph.restore();

    int left = 4;
    int bottom = graph.getHeight() - ROW_MARGIN;
    final int STEP = 4;
    for (MarkersPlotter st : mStrokes) {
        float r = st.getLastPressure();

        if (r >= FIRM_PRESSURE_LOW && r <= FIRM_PRESSURE_HIGH)
            mGraphPaint1.setColor(0xFF33FF33);
        else if (r < FIRM_PRESSURE_LOW)
            mGraphPaint1.setColor(0xFF808080);
        else
            mGraphPaint1.setColor(0xFFFF8000);

        String s = (r < 0) ? "--"
                : String.format("%s %.4f", ((st.getLastTool() == MotionEvent.TOOL_TYPE_STYLUS) ? "S" : "F"), r);

        graph.drawText(s, left, bottom - 2, mGraphPaint1);

        if (mGraphX + COLUMN_WIDTH > graph.getWidth()) {
            mGraphX = 0;
            graph.save();
            graph.clipRect(new Rect(30, 0, graph.getWidth(), graph.getHeight()));
            graph.drawColor(0, PorterDuff.Mode.CLEAR);
            graph.restore();
        }

        if (r >= 0) {
            int barsize = (int) (r * ROW_HEIGHT);
            graph.drawRect(mGraphX + COLUMN_WIDTH, bottom - barsize, mGraphX + COLUMN_WIDTH + STEP, bottom,
                    mGraphPaint1);
        } else {
            graph.drawPoint(mGraphX + COLUMN_WIDTH + STEP, bottom, mGraphPaint1);
        }
        bottom -= (ROW_HEIGHT + ROW_MARGIN);
    }

    mGraphX += STEP;

    final int x = 96;
    final int y = 64;

    c.drawBitmap(mStrokeDebugGraph, x, y, null);
    invalidate(new Rect(x, y, x + c.getWidth(), y + c.getHeight()));
}

From source file:com.android.gallery3d.filtershow.imageshow.ImageShow.java

private void drawHighresImage(Canvas canvas, Bitmap fullHighres) {
    Matrix originalToScreen = MasterImage.getImage().originalImageToScreen();
    if (fullHighres != null && originalToScreen != null) {
        Matrix screenToOriginal = new Matrix();
        originalToScreen.invert(screenToOriginal);
        Rect rBounds = new Rect();
        rBounds.set(MasterImage.getImage().getPartialBounds());
        if (fullHighres != null) {
            originalToScreen.preTranslate(rBounds.left, rBounds.top);
            canvas.clipRect(mImageBounds);
            canvas.drawBitmap(fullHighres, originalToScreen, mPaint);
        }/*from  w  w  w .j a  va  2 s  . c  o  m*/
    }
}

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);/*from w  w w.  j  a  v a2 s  .co  m*/
        mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop());
        canvas.clipRect(mTmpRect);
    }

    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);/* w ww.java2s.  co  m*/
        mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop());

        if (!mIsTransparent) {
            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;
}