本文整理匯總了Java中android.graphics.Canvas.restoreToCount方法的典型用法代碼示例。如果您正苦於以下問題:Java Canvas.restoreToCount方法的具體用法?Java Canvas.restoreToCount怎麽用?Java Canvas.restoreToCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.restoreToCount方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void draw(Canvas canvas, Rect bounds) {
int saveCount = canvas.save();
RectF arcBounds = mCurrentBounds;
arcBounds.set(bounds);
mPaint.setColor(mBottomColor);
canvas.drawPath(mCurrentBottomWaitPath, mPaint);
mPaint.setColor(mMiddleColor);
canvas.drawPath(mCurrentMiddleWaitPath, mPaint);
mPaint.setColor(mTopColor);
canvas.drawPath(mCurrentTopWaitPath, mPaint);
canvas.restoreToCount(saveCount);
}
示例2: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
mHasDrawn = true;
boolean crossFade = mCrossFadeProgress > 0 && mCrossFadeBitmap != null;
if (crossFade) {
int alpha = crossFade ? (int) (255 * (1 - mCrossFadeProgress)) : 255;
mPaint.setAlpha(alpha);
}
canvas.drawBitmap(mBitmap, 0.0f, 0.0f, mPaint);
if (crossFade) {
mPaint.setAlpha((int) (255 * mCrossFadeProgress));
final int saveCount = canvas.save(Canvas.MATRIX_SAVE_FLAG);
float sX = (mBitmap.getWidth() * 1.0f) / mCrossFadeBitmap.getWidth();
float sY = (mBitmap.getHeight() * 1.0f) / mCrossFadeBitmap.getHeight();
canvas.scale(sX, sY);
canvas.drawBitmap(mCrossFadeBitmap, 0.0f, 0.0f, mPaint);
canvas.restoreToCount(saveCount);
}
}
示例3: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
int saveCount = canvas.save();
canvas.concat(mZoomableController.getTransform());
try {
super.onDraw(canvas);
} catch (Exception e) {
DraweeController controller = getController();
if (controller != null && controller instanceof AbstractDraweeController) {
Object callerContext = ((AbstractDraweeController) controller).getCallerContext();
if (callerContext != null) {
throw new RuntimeException(
String.format("Exception in onDraw, callerContext=%s", callerContext.toString()),
e);
}
}
throw e;
}
canvas.restoreToCount(saveCount);
}
示例4: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
public void draw(Canvas canvas) {
super.draw(canvas);
boolean needsInvalidate = false;
int overScrollMode = ViewCompat.getOverScrollMode(this);
if (overScrollMode == 0 || (overScrollMode == 1 && this.mAdapter != null && this.mAdapter.getCount() > 1)) {
int restoreCount;
int height;
int width;
if (!this.mLeftEdge.isFinished()) {
restoreCount = canvas.save();
height = (getHeight() - getPaddingTop()) - getPaddingBottom();
width = getWidth();
canvas.rotate(270.0f);
canvas.translate((float) ((-height) + getPaddingTop()), this.mFirstOffset * ((float) width));
this.mLeftEdge.setSize(height, width);
needsInvalidate = false | this.mLeftEdge.draw(canvas);
canvas.restoreToCount(restoreCount);
}
if (!this.mRightEdge.isFinished()) {
restoreCount = canvas.save();
width = getWidth();
height = (getHeight() - getPaddingTop()) - getPaddingBottom();
canvas.rotate(90.0f);
canvas.translate((float) (-getPaddingTop()), (-(this.mLastOffset + 1.0f)) * ((float) width));
this.mRightEdge.setSize(height, width);
needsInvalidate |= this.mRightEdge.draw(canvas);
canvas.restoreToCount(restoreCount);
}
} else {
this.mLeftEdge.finish();
this.mRightEdge.finish();
}
if (needsInvalidate) {
ViewCompat.postInvalidateOnAnimation(this);
}
}
示例5: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
int width = getWidth();
int height = getHeight();
if (mInsets != null && mInsetForeground != null) {
int sc = canvas.save();
canvas.translate(getScrollX(), getScrollY());
// Top
mTempRect.set(0, 0, width, mInsets.top);
mInsetForeground.setBounds(mTempRect);
mInsetForeground.draw(canvas);
// Bottom
mTempRect.set(0, height - mInsets.bottom, width, height);
mInsetForeground.setBounds(mTempRect);
mInsetForeground.draw(canvas);
// Left
mTempRect.set(0, mInsets.top, mInsets.left, height - mInsets.bottom);
mInsetForeground.setBounds(mTempRect);
mInsetForeground.draw(canvas);
// Right
mTempRect.set(width - mInsets.right, mInsets.top, width, height - mInsets.bottom);
mInsetForeground.setBounds(mTempRect);
mInsetForeground.draw(canvas);
canvas.restoreToCount(sc);
}
}
示例6: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
int restorePoint = canvas.save();
if (mForceShowHint && mForceHint != null)
canvas.drawText(mForceHint, 0, mForceHint.length(), mTextX, mTextY - mTextPaint.ascent(), this.mTextPaint);
canvas.restoreToCount(restorePoint);
}
示例7: getRoundedCornerBitmap
import android.graphics.Canvas; //導入方法依賴的package包/類
public static Bitmap getRoundedCornerBitmap(Context context, @DrawableRes int drawable, int width, int height,
@DrawableRes int backgroundDrawable, float roundPx) {
Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
//繪製背景
Drawable bgDrawable = context.getResources().getDrawable(backgroundDrawable);
bgDrawable.setBounds(0, 0, width, height);
bgDrawable.draw(canvas);
//在背景的上麵繪製圓角圖片
int offset = (int) (context.getResources().getDisplayMetrics().density * 10);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(offset, offset, width - offset, width - offset);
final RectF rectF = new RectF(rect);
paint.setAntiAlias(true);
int layer = canvas.saveLayer(0, 0, width, height, null, Canvas.ALL_SAVE_FLAG);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
// 第二個參數為null,表示繪製整個目標圖片
canvas.drawBitmap(getBitmap(context.getResources().getDrawable(drawable)), null, rect, paint);
canvas.restoreToCount(layer);
return output;
}
示例8: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas) {
int width = Util.getScreenWidth(mContext);
int height = Util.getScreenHeight(mContext);
mLeft = (width - mCropWidth) / 2;
mTop = (height - mCropHeight) / 2;
mRight = (width + mCropWidth) / 2;
mBottom = (height + mCropHeight) / 2;
Rect rect = new Rect(mLeft, mTop, mRight, mBottom);
canvas.drawRect(rect, mLinePaint);
//左上
canvas.drawLine(mLeft, mTop, mLeft, mTop + 50, mCornerPaint);
canvas.drawLine(mLeft - 4, mTop, mLeft + 50, mTop, mCornerPaint);
//右上
canvas.drawLine(mRight, mTop, mRight, mTop + 50, mCornerPaint);
canvas.drawLine(mRight - 50, mTop, mRight + 4, mTop, mCornerPaint);
//左下
canvas.drawLine(mLeft, mBottom, mLeft + 50, mBottom, mCornerPaint);
canvas.drawLine(mLeft, mBottom - 50, mLeft, mBottom + 4, mCornerPaint);
//右下
canvas.drawLine(mRight, mBottom, mRight, mBottom - 50, mCornerPaint);
canvas.drawLine(mRight - 50, mBottom, mRight + 4, mBottom, mCornerPaint);
int index = canvas.save();
canvas.clipRect(rect);
//畫九宮格
int vAvg = mCropWidth / 3;
int hAvg = mCropHeight / 3;
canvas.drawLine(mLeft + vAvg, mTop, mLeft + vAvg, mBottom, mNineLinePaint);
canvas.drawLine(mLeft + vAvg * 2, mTop, mLeft + vAvg * 2, mBottom, mNineLinePaint);
canvas.drawLine(mLeft, mTop + hAvg, mRight, mTop + hAvg, mNineLinePaint);
canvas.drawLine(mLeft, mTop + hAvg * 2, mRight, mTop + hAvg * 2, mNineLinePaint);
canvas.restoreToCount(index);
}
示例9: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void draw(Canvas canvas, Rect bounds) {
int saveCount = canvas.save();
RectF arcBounds = mTempBounds;
arcBounds.set(bounds);
mPaint.setColor(mColor);
//calculate fish clip bounds
//clip the width of the fish need to increase mPathDottedLineSize * 1.2f
RectF fishRectF = new RectF(mFishHeadPos[0] - mFishWidth / 2.0f - mPathDottedLineSize * 1.2f, mFishHeadPos[1] - mFishHeight / 2.0f,
mFishHeadPos[0] + mFishWidth / 2.0f + mPathDottedLineSize * 1.2f, mFishHeadPos[1] + mFishHeight / 2.0f);
Matrix matrix = new Matrix();
matrix.postRotate(mFishRotateDegrees, fishRectF.centerX(), fishRectF.centerY());
matrix.mapRect(fishRectF);
//draw river
int riverSaveCount = canvas.save();
mPaint.setStyle(Paint.Style.STROKE);
canvas.clipRect(fishRectF, Region.Op.DIFFERENCE);
canvas.drawPath(createRiverPath(arcBounds), mPaint);
canvas.restoreToCount(riverSaveCount);
//draw fish
int fishSaveCount = canvas.save();
mPaint.setStyle(Paint.Style.FILL);
canvas.rotate(mFishRotateDegrees, mFishHeadPos[0], mFishHeadPos[1]);
canvas.clipPath(createFishEyePath(mFishHeadPos[0], mFishHeadPos[1] - mFishHeight * 0.06f), Region.Op.DIFFERENCE);
canvas.drawPath(createFishPath(mFishHeadPos[0], mFishHeadPos[1]), mPaint);
canvas.restoreToCount(fishSaveCount);
canvas.restoreToCount(saveCount);
}
示例10: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
public void draw(Canvas canvas) {
int saveCount = canvas.save();
if (this.mTextToDraw != null && this.mDrawTitle) {
boolean drawTexture;
float ascent;
float x = this.mCurrentDrawX;
float y = this.mCurrentDrawY;
if (!this.mUseTexture || this.mExpandedTitleTexture == null) {
drawTexture = false;
} else {
drawTexture = true;
}
float descent;
if (drawTexture) {
ascent = this.mTextureAscent * this.mScale;
descent = this.mTextureDescent * this.mScale;
} else {
ascent = this.mTextPaint.ascent() * this.mScale;
descent = this.mTextPaint.descent() * this.mScale;
}
if (drawTexture) {
y += ascent;
}
if (this.mScale != 1.0f) {
canvas.scale(this.mScale, this.mScale, x, y);
}
if (drawTexture) {
canvas.drawBitmap(this.mExpandedTitleTexture, x, y, this.mTexturePaint);
} else {
canvas.drawText(this.mTextToDraw, 0, this.mTextToDraw.length(), x, y, this.mTextPaint);
}
}
canvas.restoreToCount(saveCount);
}
示例11: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas) {
int num = (int) (System.currentTimeMillis() / 50 % 11);
final int saveCount = canvas.save();
canvas.translate(0, mOffset);
Bitmap bitmap = bitmaps.get(num);
canvas.drawBitmap(bitmap, null, rectF, null);
canvas.restoreToCount(saveCount);
}
示例12: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
if (!mIsAnimatorCancel) {
final Rect bounds = getBounds();
final int saveCount = canvas.save();
canvas.rotate(mRotation * 360, bounds.exactCenterX(), bounds.exactCenterY());
drawRing(canvas, bounds);
canvas.restoreToCount(saveCount);
} else {
canvas.restore();
}
}
示例13: drawShadow
import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawShadow(Canvas canvas) {
final float edgeShadowTop = -mCornerRadius - mShadowSize;
final float inset = mCornerRadius + mInsetShadow + mRawShadowSize / 2;
final boolean drawHorizontalEdges = mCardBounds.width() - 2 * inset > 0;
final boolean drawVerticalEdges = mCardBounds.height() - 2 * inset > 0;
// LT
int saved = canvas.save();
canvas.translate(mCardBounds.left + inset, mCardBounds.top + inset);
canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
if (drawHorizontalEdges) {
canvas.drawRect(0, edgeShadowTop,
mCardBounds.width() - 2 * inset, -mCornerRadius,
mEdgeShadowPaint);
}
canvas.restoreToCount(saved);
// RB
saved = canvas.save();
canvas.translate(mCardBounds.right - inset, mCardBounds.bottom - inset);
canvas.rotate(180f);
canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
if (drawHorizontalEdges) {
canvas.drawRect(0, edgeShadowTop,
mCardBounds.width() - 2 * inset, -mCornerRadius + mShadowSize,
mEdgeShadowPaint);
}
canvas.restoreToCount(saved);
// LB
saved = canvas.save();
canvas.translate(mCardBounds.left + inset, mCardBounds.bottom - inset);
canvas.rotate(270f);
canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
if (drawVerticalEdges) {
canvas.drawRect(0, edgeShadowTop,
mCardBounds.height() - 2 * inset, -mCornerRadius, mEdgeShadowPaint);
}
canvas.restoreToCount(saved);
// RT
saved = canvas.save();
canvas.translate(mCardBounds.right - inset, mCardBounds.top + inset);
canvas.rotate(90f);
canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
if (drawVerticalEdges) {
canvas.drawRect(0, edgeShadowTop,
mCardBounds.height() - 2 * inset, -mCornerRadius, mEdgeShadowPaint);
}
canvas.restoreToCount(saved);
}
示例14: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
final int store = canvas.save();
//參數修正
int w = getMeasuredWidth();
int h = getMeasuredHeight();
//圓心
int x = w/2;
int y = h/2;
//半徑
int radius = (Math.min(w,h)-2*padding)/2-internalStrokeWidth/2;//半徑
//線冒的範圍,默認在roate 為0的位置,之後通過旋轉擺正
recthead = new RectF(x+radius-internalStrokeWidth/2,y-internalStrokeWidth/2,
x+radius+internalStrokeWidth/2,y+internalStrokeWidth/2);
calculatePercentEndColor(pre);
sweepGradient = new SweepGradient(x,y,colors,dur);
//旋轉sweepGradient的角度
Matrix gradientMatrix = new Matrix();
gradientMatrix.preRotate(roate, x, y);
sweepGradient.setLocalMatrix(gradientMatrix);
outpaint.setShader(sweepGradient);
//繪製背景
canvas.drawCircle(x,y,radius+internalStrokeWidth/2+padding,bgpaint);
//繪製外部單元格
canvas.drawCircle(x,y,radius,outpaint);
//如果是非dash樣式,線冒會被染色為終點顏色.例如紅色,這裏需要一個半圓蓋著
if(!dash){
//為保證旋轉不畫布其他元素生效
if(pre>0&&pre<1) {
canvas.save();
// 繪製開頭的半圓,線冒
canvas.rotate(roate, x, y);
canvas.drawArc(recthead, 180, 180, true, startPaint);
canvas.restore();
}
// 繪製結束的半圓,線冒
if (pre>0&&pre <= 1) {
//為保證旋轉不畫布其他元素生效
canvas.save();
endPaint.setColor(percentEndColor);
//-1個角度,因為計算後有一定的精度損失
canvas.rotate(roate+360*pre-1, x, y);
canvas.drawArc(recthead, 0f, 180f, true, endPaint);
canvas.restore();
}
}
canvas.restoreToCount(store);
}
示例15: drawShadow
import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawShadow(Canvas canvas) {
boolean drawHorizontalEdges;
boolean drawVerticalEdges;
float edgeShadowTop = (-this.mCornerRadius) - this.mShadowSize;
float inset = (this.mCornerRadius + ((float) this.mInsetShadow)) + (this.mRawShadowSize / 2.0f);
if (this.mCardBounds.width() - (2.0f * inset) > 0.0f) {
drawHorizontalEdges = true;
} else {
drawHorizontalEdges = false;
}
if (this.mCardBounds.height() - (2.0f * inset) > 0.0f) {
drawVerticalEdges = true;
} else {
drawVerticalEdges = false;
}
int saved = canvas.save();
canvas.translate(this.mCardBounds.left + inset, this.mCardBounds.top + inset);
canvas.drawPath(this.mCornerShadowPath, this.mCornerShadowPaint);
if (drawHorizontalEdges) {
canvas.drawRect(0.0f, edgeShadowTop, this.mCardBounds.width() - (2.0f * inset), -this.mCornerRadius, this.mEdgeShadowPaint);
}
canvas.restoreToCount(saved);
saved = canvas.save();
canvas.translate(this.mCardBounds.right - inset, this.mCardBounds.bottom - inset);
canvas.rotate(180.0f);
canvas.drawPath(this.mCornerShadowPath, this.mCornerShadowPaint);
if (drawHorizontalEdges) {
Canvas canvas2 = canvas;
canvas2.drawRect(0.0f, edgeShadowTop, this.mCardBounds.width() - (2.0f * inset), this.mShadowSize + (-this.mCornerRadius), this.mEdgeShadowPaint);
}
canvas.restoreToCount(saved);
saved = canvas.save();
canvas.translate(this.mCardBounds.left + inset, this.mCardBounds.bottom - inset);
canvas.rotate(270.0f);
canvas.drawPath(this.mCornerShadowPath, this.mCornerShadowPaint);
if (drawVerticalEdges) {
canvas.drawRect(0.0f, edgeShadowTop, this.mCardBounds.height() - (2.0f * inset), -this.mCornerRadius, this.mEdgeShadowPaint);
}
canvas.restoreToCount(saved);
saved = canvas.save();
canvas.translate(this.mCardBounds.right - inset, this.mCardBounds.top + inset);
canvas.rotate(90.0f);
canvas.drawPath(this.mCornerShadowPath, this.mCornerShadowPaint);
if (drawVerticalEdges) {
canvas.drawRect(0.0f, edgeShadowTop, this.mCardBounds.height() - (2.0f * inset), -this.mCornerRadius, this.mEdgeShadowPaint);
}
canvas.restoreToCount(saved);
}