Java Code Examples for android.graphics.Canvas.restore()

The following are Jave code examples for showing how to use restore() of the android.graphics.Canvas class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: WeatherStream   File: CustomViewBehind.java   View Source Code Vote up 7 votes
public void drawSelector(View content, Canvas canvas, float openPercent) {
	if (!mSelectorEnabled) return;
	if (mSelectorDrawable != null && mSelectedView != null) {
		String tag = (String) mSelectedView.getTag(R.id.selected_view);
		if (tag.equals(TAG+"SelectedView")) {
			canvas.save();
			int left, right, offset;
			offset = (int) (mSelectorDrawable.getWidth() * openPercent);
			if (mMode == SlidingMenu.LEFT) {
				right = content.getLeft();
				left = right - offset;
				canvas.clipRect(left, 0, right, getHeight());
				canvas.drawBitmap(mSelectorDrawable, left, getSelectorTop(), null);		
			} else if (mMode == SlidingMenu.RIGHT) {
				left = content.getRight();
				right = left + offset;
				canvas.clipRect(left, 0, right, getHeight());
				canvas.drawBitmap(mSelectorDrawable, right - mSelectorDrawable.getWidth(), getSelectorTop(), null);
			}
			canvas.restore();
		}
	}
}
 
Example 2
Project: FriendBook   File: SimulationPageAnim.java   View Source Code Vote up 6 votes
private void drawCurrentPageArea(Canvas canvas, Bitmap bitmap, Path path) {
    mPath0.reset();
    mPath0.moveTo(mBezierStart1.x, mBezierStart1.y);
    mPath0.quadTo(mBezierControl1.x, mBezierControl1.y, mBezierEnd1.x,
            mBezierEnd1.y);
    mPath0.lineTo(mTouchX, mTouchY);
    mPath0.lineTo(mBezierEnd2.x, mBezierEnd2.y);
    mPath0.quadTo(mBezierControl2.x, mBezierControl2.y, mBezierStart2.x,
            mBezierStart2.y);
    mPath0.lineTo(mCornerX, mCornerY);
    mPath0.close();

    canvas.save();
    canvas.clipPath(path, Region.Op.XOR);
    canvas.drawBitmap(bitmap, 0, 0, null);
    try {
        canvas.restore();
    } catch (Exception e) {

    }

}
 
Example 3
Project: PeSanKita-android   File: StickyHeaderDecoration.java   View Source Code Vote up 6 votes
/**
 * {@inheritDoc}
 */
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
  final int count = parent.getChildCount();

  for (int layoutPos = 0; layoutPos < count; layoutPos++) {
    final View child = parent.getChildAt(translatedChildPosition(parent, layoutPos));

    final int adapterPos = parent.getChildAdapterPosition(child);

    if (adapterPos != RecyclerView.NO_POSITION && ((layoutPos == 0 && sticky) || hasHeader(parent, adapter, adapterPos))) {
      View header = getHeader(parent, adapter, adapterPos).itemView;
      c.save();
      final int left = child.getLeft();
      final int top = getHeaderTop(parent, child, header, adapterPos, layoutPos);
      c.translate(left, top);
      header.draw(c);
      c.restore();
    }
  }
}
 
Example 4
Project: TextReader   File: OverlappedWidget.java   View Source Code Vote up 6 votes
@Override
protected void drawNextPageAreaAndShadow(Canvas canvas) {
    canvas.save();
    if (actiondownX > mScreenWidth >> 1) {
        canvas.clipPath(mPath0);
        canvas.drawBitmap(mNextPageBitmap, 0, 0, null);
    } else {
        canvas.clipPath(mPath0, Region.Op.XOR);
        canvas.drawBitmap(mNextPageBitmap, 0, 0, null);
    }
    try {
        canvas.restore();
    } catch (Exception e) {

    }
}
 
Example 5
Project: HeadlineNews   File: SpanUtils.java   View Source Code Vote up 6 votes
@Override
public void draw(@NonNull final Canvas canvas, final CharSequence text,
                 final int start, final int end, final float x,
                 final int top, final int y, final int bottom, @NonNull final Paint paint) {
    Drawable d = getCachedDrawable();
    Rect rect = d.getBounds();
    canvas.save();
    final float fontHeight = paint.getFontMetrics().descent - paint.getFontMetrics().ascent;
    int transY = bottom - rect.bottom;
    if (rect.height() < fontHeight) { // this is the fucking code which I waste 3 days
        if (mVerticalAlignment == ALIGN_BASELINE) {
            transY -= paint.getFontMetricsInt().descent;
        } else if (mVerticalAlignment == ALIGN_CENTER) {
            transY -= (fontHeight - rect.height()) / 2;
        } else if (mVerticalAlignment == ALIGN_TOP) {
            transY -= fontHeight - rect.height();
        }
    }
    canvas.translate(x, transY);
    d.draw(canvas);
    canvas.restore();
}
 
Example 6
Project: Simpler   File: VerticalImageSpan.java   View Source Code Vote up 5 votes
@Override
public void draw(Canvas canvas, CharSequence text, int start, int end,
                 float x, int top, int y, int bottom, Paint paint) {
    Drawable drawable = getDrawable();
    canvas.save();
    int transY = 0;
    transY = ((bottom - top) - drawable.getBounds().bottom) / 2 + top;
    canvas.translate(x, transY);
    drawable.draw(canvas);
    canvas.restore();
}
 
Example 7
Project: RLibrary   File: CropImageView.java   View Source Code Vote up 5 votes
/**
 * 绘制焦点框
 */
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (Style.RECTANGLE == mStyle) {
        mFocusPath.addRect(mFocusRect, Path.Direction.CCW);
        canvas.save();
        canvas.clipRect(0, 0, getWidth(), getHeight());
        canvas.clipPath(mFocusPath, Region.Op.DIFFERENCE);
        canvas.drawColor(mMaskColor);
        canvas.restore();
    } else if (Style.CIRCLE == mStyle) {
        float radius = Math.min((mFocusRect.right - mFocusRect.left) / 2, (mFocusRect.bottom - mFocusRect.top) / 2);
        mFocusPath.addCircle(mFocusMidPoint.x, mFocusMidPoint.y, radius, Path.Direction.CCW);
        canvas.save();
        canvas.clipRect(0, 0, getWidth(), getHeight());
        canvas.clipPath(mFocusPath, Region.Op.DIFFERENCE);
        canvas.drawColor(mMaskColor);
        canvas.restore();
    }
    mBorderPaint.setColor(mBorderColor);
    mBorderPaint.setStyle(Paint.Style.STROKE);
    mBorderPaint.setStrokeWidth(mBorderWidth);
    mBorderPaint.setAntiAlias(true);
    canvas.drawPath(mFocusPath, mBorderPaint);
    mFocusPath.reset();
}
 
Example 8
Project: Discover   File: LineScalePartyIndicator.java   View Source Code Vote up 5 votes
@Override
public void draw(Canvas canvas, Paint paint) {
    float translateX=getWidth()/9;
    float translateY=getHeight()/2;
    for (int i = 0; i < 4; i++) {
        canvas.save();
        canvas.translate((2 + i * 2) * translateX - translateX / 2, translateY);
        canvas.scale(scaleFloats[i], scaleFloats[i]);
        RectF rectF=new RectF(-translateX/2,-getHeight()/2.5f,translateX/2,getHeight()/2.5f);
        canvas.drawRoundRect(rectF,5,5,paint);
        canvas.restore();
    }
}
 
Example 9
Project: Multi-SwipeToRefreshLayout   File: LineScaleIndicator.java   View Source Code Vote up 5 votes
@Override
public void draw(Canvas canvas, Paint paint) {
    float translateX=getWidth()/11;
    float translateY=getHeight()/2;
    for (int i = 0; i < 5; i++) {
        canvas.save();
        canvas.translate((2 + i * 2) * translateX - translateX / 2, translateY);
        canvas.scale(SCALE, scaleYFloats[i]);
        RectF rectF=new RectF(-translateX/2,-getHeight()/2.5f,translateX/2,getHeight()/2.5f);
        canvas.drawRoundRect(rectF, 5, 5, paint);
        canvas.restore();
    }
}
 
Example 10
Project: Multi-SwipeToRefreshLayout   File: BallTrianglePathIndicator.java   View Source Code Vote up 5 votes
@Override
public void draw(Canvas canvas, Paint paint) {
    paint.setStrokeWidth(3);
    paint.setStyle(Paint.Style.STROKE);
    for (int i = 0; i < 3; i++) {
        canvas.save();
        canvas.translate(translateX[i], translateY[i]);
        canvas.drawCircle(0, 0, getWidth() / 10, paint);
        canvas.restore();
    }
}
 
Example 11
Project: GitHub   File: BallTrianglePathIndicator.java   View Source Code Vote up 5 votes
@Override
public void draw(Canvas canvas, Paint paint) {
    paint.setStrokeWidth(3);
    paint.setStyle(Paint.Style.STROKE);
    for (int i = 0; i < 3; i++) {
        canvas.save();
        canvas.translate(translateX[i], translateY[i]);
        canvas.drawCircle(0, 0, getWidth() / 10, paint);
        canvas.restore();
    }
}
 
Example 12
Project: AndroidTvDemo   File: OpenEffectBridge.java   View Source Code Vote up 5 votes
/**
 * 重寫了繪製的函數.
 */
@Override
public boolean onDrawMainUpView(Canvas canvas)
{
    canvas.save();
    if (!isDrawUpRect)
    {
        // 绘制阴影.
        onDrawShadow(canvas);
        // 绘制最上层的边框.
        onDrawUpRect(canvas);
    }
    // 绘制焦点子控件.
    if (mFocusView != null && (!isDrawUpRect && isInDraw))
    {
        onDrawFocusView(canvas);
    }
    //
    if (isDrawUpRect)
    {
        // 绘制阴影.
        onDrawShadow(canvas);
        // 绘制最上层的边框.
        onDrawUpRect(canvas);
    }
    canvas.restore();
    return true;
}
 
Example 13
Project: SRecyclerView   File: LineSpinFadeLoaderIndicator.java   View Source Code Vote up 5 votes
@Override
public void draw(Canvas canvas, Paint paint) {
    float radius=getWidth()/10;
    for (int i = 0; i < 8; i++) {
        canvas.save();
        Point point=circleAt(getWidth(),getHeight(),getWidth()/2.5f-radius,i*(Math.PI/4));
        canvas.translate(point.x, point.y);
        canvas.scale(scaleFloats[i], scaleFloats[i]);
        canvas.rotate(i*45);
        paint.setAlpha(alphas[i]);
        RectF rectF=new RectF(-radius,-radius/1.5f,1.5f*radius,radius/1.5f);
        canvas.drawRoundRect(rectF,5,5,paint);
        canvas.restore();
    }
}
 
Example 14
Project: PlusGram   File: Slate.java   View Source Code Vote up 5 votes
@Override
protected void onDraw(Canvas canvas) {
    if (mTiledCanvas != null) {
        canvas.save(Canvas.MATRIX_SAVE_FLAG);

        if (mPanX != 0 || mPanY != 0 || !mZoomMatrix.isIdentity()) {
            canvas.translate(mPanX, mPanY);
            canvas.concat(mZoomMatrix);

            canvas.drawRect(-20000, -20000, 20000, 0, mWorkspacePaint);
            canvas.drawRect(-20000, 0, 0, mTiledCanvas.getHeight(), mWorkspacePaint);
            canvas.drawRect(mTiledCanvas.getWidth(), 0, 20000, mTiledCanvas.getHeight(), mWorkspacePaint);
            canvas.drawRect(-20000, mTiledCanvas.getHeight(), 20000, 20000, mWorkspacePaint);
        }
        
        if (!mDirtyRegion.isEmpty()) {
            canvas.clipRegion(mDirtyRegion);
            mDirtyRegion.setEmpty();
        }
        // TODO: tune this threshold based on the device density
        mBlitPaint.setFilterBitmap(getScale(mZoomMatrix) < 3f);
        mTiledCanvas.drawTo(canvas, 0, 0, mBlitPaint, false); // @@ set to true for dirty tile updates
        if (0 != (mDebugFlags & FLAG_DEBUG_STROKES)) {
            drawStrokeDebugInfo(canvas);
        }

        canvas.restore();
        
        if (0 != (mDebugFlags & FLAG_DEBUG_PRESSURE)) {
            mPressureCooker.drawDebug(canvas);
        }
    }
}
 
Example 15
Project: snippety   File: LineDrawable.java   View Source Code Vote up 5 votes
@Override

    public void draw(Canvas canvas) {
        Rect bounds = getBounds();

        canvas.save();
        canvas.drawLine(bounds.left, bounds.centerY(), bounds.right - bounds.left, bounds.centerY(), paint);
        canvas.restore();
    }
 
Example 16
Project: android-open-source-project-analysis   File: PageView.java   View Source Code Vote up 5 votes
private void drawNextPageAreaAndShadow(Canvas canvas, Bitmap bitmap) {
    mPath1.reset();
    mPath1.moveTo(mBezierStart1.x, mBezierStart1.y);
    mPath1.lineTo(mBeziervertex1.x, mBeziervertex1.y);
    mPath1.lineTo(mBeziervertex2.x, mBeziervertex2.y);
    mPath1.lineTo(mBezierStart2.x, mBezierStart2.y);
    mPath1.lineTo(mCornerX, mCornerY);
    mPath1.close();

    mDegrees = (float) Math.toDegrees(Math.atan2(mBezierControl1.x
            - mCornerX, mBezierControl2.y - mCornerY));
    int leftx;
    int rightx;
    GradientDrawable mBackShadowDrawable;
    if (mIsRTandLB) {  //左下及右上
        leftx = (int) (mBezierStart1.x);
        rightx = (int) (mBezierStart1.x + mTouchToCornerDis / 4);
        mBackShadowDrawable = mBackShadowDrawableLR;
    } else {
        leftx = (int) (mBezierStart1.x - mTouchToCornerDis / 4);
        rightx = (int) mBezierStart1.x;
        mBackShadowDrawable = mBackShadowDrawableRL;
    }
    canvas.save();
    try {
        canvas.clipPath(mPath0);
        canvas.clipPath(mPath1, Region.Op.INTERSECT);
    } catch (Exception e) {
    }


    canvas.drawBitmap(bitmap, 0, 0, null);
    canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y);
    mBackShadowDrawable.setBounds(leftx, (int) mBezierStart1.y, rightx,
            (int) (mMaxLength + mBezierStart1.y));//左上及右下角的xy坐标值,构成一个矩形
    mBackShadowDrawable.draw(canvas);
    canvas.restore();
}
 
Example 17
Project: RvAdapter   File: HeaderRenderer.java   View Source Code Vote up 5 votes
/**
 * Draws a header to a canvas, offsetting by some x and y amount
 *
 * @param recyclerView the parent recycler view for drawing the header into
 * @param canvas       the canvas on which to draw the header
 * @param header       the view to draw as the header
 * @param offset       a Rect used to define the x/y offset of the header. Specify x/y offset by setting
 *                     the {@link Rect#left} and {@link Rect#top} properties, respectively.
 */
public void drawHeader(RecyclerView recyclerView, Canvas canvas, View header, Rect offset) {
    canvas.save();

    if (recyclerView.getLayoutManager().getClipToPadding()) {
        // Clip drawing of headers to the padding of the RecyclerView. Avoids drawing in the padding
        initClipRectForHeader(mTempRect, recyclerView, header);
        canvas.clipRect(mTempRect);
    }

    canvas.translate(offset.left, offset.top);

    header.draw(canvas);
    canvas.restore();
}
 
Example 18
Project: boohee_v5.6   File: WheelView.java   View Source Code Vote up 4 votes
private void drawItems(Canvas canvas) {
    canvas.save();
    canvas.translate(10.0f, (float) ((-(((this.currentItem - this.firstItem) * getItemHeight()) + ((getItemHeight() - getHeight()) / 2))) + this.scrollingOffset));
    this.itemsLayout.draw(canvas);
    canvas.restore();
}
 
Example 19
Project: Roll3DImageView   File: Roll3DView.java   View Source Code Vote up 4 votes
/**
 * 整体翻滚
 * degree 0->90 往下翻滚或者往右翻滚
 *
 * @param canvas
 * @param draw2D  是否画2D效果:true  画2D效果; false  画3D效果
 */
private void drawRollWhole3D(Canvas canvas, boolean draw2D) {

    Bitmap currWholeBitmap = bitmapList.get(currIndex);
    Bitmap nextWholeBitmap = bitmapList.get(nextIndex);
    canvas.save();

    if (direction == 1) {
        camera.save();
        if (draw2D)
            camera.rotateX(0);
        else
            camera.rotateX(-rotateDegree);
        camera.getMatrix(matrix);
        camera.restore();

        matrix.preTranslate(-viewWidth / 2, 0);
        matrix.postTranslate(viewWidth / 2, axisY);
        canvas.drawBitmap(currWholeBitmap, matrix, paint);

        camera.save();
        if (draw2D)
            camera.rotateX(0);
        else
            camera.rotateX((90 - rotateDegree));
        camera.getMatrix(matrix);
        camera.restore();

        matrix.preTranslate(-viewWidth / 2, -viewHeight);
        matrix.postTranslate(viewWidth / 2, axisY);
        canvas.drawBitmap(nextWholeBitmap, matrix, paint);

    } else {
        camera.save();
        if (draw2D)
            camera.rotateY(0);
        else
            camera.rotateY(rotateDegree);
        camera.getMatrix(matrix);
        camera.restore();

        matrix.preTranslate(0, -viewHeight / 2);
        matrix.postTranslate(axisX, viewHeight / 2);

        canvas.drawBitmap(currWholeBitmap, matrix, paint);

        camera.save();
        if (draw2D)
            camera.rotateY(0);
        else
            camera.rotateY(rotateDegree - 90);
        camera.getMatrix(matrix);
        camera.restore();

        matrix.preTranslate(-viewWidth, -viewHeight / 2);
        matrix.postTranslate(axisX, viewHeight / 2);
        canvas.drawBitmap(nextWholeBitmap, matrix, paint);
    }
    canvas.restore();
}
 
Example 20
Project: FancyView   File: LineDrawStrategy.java   View Source Code Vote up 4 votes
@Override
public void drawAppIcon(Canvas canvas, float fraction, Drawable icon, int colorOfIcon,
                        WidthAndHeightOfView widthAndHeightOfView) {
    int centerX = widthAndHeightOfView.getWidth() / 2;
    int centerY = widthAndHeightOfView.getHeight() / 2;
    Bitmap bitmap = ((BitmapDrawable) icon).getBitmap();
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(colorOfIcon);
    paint.setStrokeWidth(3);
    paint.setStrokeJoin(Paint.Join.ROUND);
    paint.setStyle(Paint.Style.STROKE);
    float bitmapLeft = centerX - 250;
    float bitmapRight = bitmapLeft + bitmap.getWidth() * 1.7f;
    float bitmapTop = centerY - 250;
    float bitmapBottom = bitmapTop + bitmap.getHeight() * 1.7f;
    canvas.save();
    if (fraction <= 0.75) {
        float newfraction = fraction / 0.75f;
        if (newfraction <= 0.25) {
            canvas.drawLine(bitmapLeft, bitmapBottom, bitmapLeft,
                    bitmapBottom - (bitmapBottom - bitmapTop) * (newfraction / 0.25f), paint);
          //  path.lineTo(bitmapLeft, bitmapBottom + (bitmapBottom - bitmapTop) * (newfraction / 0.25f));
        } else {
            canvas.drawLine(bitmapLeft, bitmapBottom, bitmapLeft, bitmapTop, paint);
          //  path.lineTo(bitmapLeft, bitmapTop);
        }
        if (newfraction > 0.25) {
            if (newfraction <= 0.50) {
                canvas.drawLine(bitmapLeft, bitmapTop,
                        bitmapLeft + (bitmapRight - bitmapLeft) * ((newfraction - 0.25f)/0.25f),
                        bitmapTop, paint);
              //  path.lineTo(bitmapLeft + (bitmapRight - bitmapLeft) * ((newfraction - 0.25f)/0.25f),
               //         bitmapTop);
            } else {
                canvas.drawLine(bitmapLeft, bitmapTop, bitmapRight, bitmapTop, paint);
               // path.lineTo(bitmapRight, bitmapTop);
            }
        }
        if (newfraction > 0.50) {
            if (newfraction <= 0.75) {
                canvas.drawLine(bitmapRight, bitmapTop, bitmapRight,
                        bitmapTop + (bitmapBottom - bitmapTop) * ((newfraction - 0.50f) / 0.25f),
                        paint);
                //path.lineTo(bitmapRight, bitmapTop + (bitmapBottom - bitmapTop) * ((fraction - 0.50f) / 0.25f));
            } else {
                canvas.drawLine(bitmapRight, bitmapTop, bitmapRight, bitmapBottom, paint);
                //path.lineTo(bitmapRight, bitmapBottom);
            }
        }
        if (newfraction > 0.75) {
            if (newfraction <= 1) {
                canvas.drawLine(bitmapRight, bitmapBottom, bitmapRight - (bitmapRight - bitmapLeft) * ((newfraction - 0.75f)/ 0.25f),
                                 bitmapBottom, paint);
               // path.lineTo(bitmapLeft + (bitmapRight - bitmapLeft) * ((fraction - 0.75f)/ 0.25f),
               //         bitmapBottom);
            } else {
                canvas.drawLine(bitmapRight, bitmapBottom, bitmapLeft, bitmapBottom, paint);
               // path.lineTo(bitmapLeft, bitmapBottom);
            }
        }
    }
    canvas.restore();
    canvas.save();
    if (fraction > 0.75) {
        canvas.clipRect(bitmapLeft + (bitmap.getWidth()/2f) * ((1 - fraction) /0.25f),
                bitmapTop + (bitmap.getHeight()/2f)* ((1 - fraction) / 0.25f),
                bitmapRight - (bitmap.getWidth()/2f) * ((1 - fraction) /0.25f),
                bitmapBottom - (bitmap.getHeight()/2f)* ((1 - fraction) / 0.25f));
        Matrix matrix = new Matrix();
        matrix.postScale(1.7f, 1.7f, (bitmapLeft + bitmapRight) * 0.5f,
                (bitmapTop + bitmapBottom) * 0.5f);
        canvas.concat(matrix);
        canvas.drawBitmap(bitmap, (bitmapLeft + bitmapRight) / 2 - bitmap.getWidth() / 2,
                (bitmapTop + bitmapBottom) / 2 - bitmap.getHeight() / 2, paint);
    }
    canvas.restore();
}