本文整理匯總了Java中android.graphics.Canvas.getSaveCount方法的典型用法代碼示例。如果您正苦於以下問題:Java Canvas.getSaveCount方法的具體用法?Java Canvas.getSaveCount怎麽用?Java Canvas.getSaveCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.getSaveCount方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: drawSky
import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawSky(Canvas canvas, int width, int height) {
Matrix matrix = mMatrix;
matrix.reset();
int bWidth = mDrawableSky.width();//mSky.getWidth();
int bHeight = mDrawableSky.height();//mSky.getHeight();
float townScale = 1f * width / bWidth;
float offsetx = 0;
float offsety = height / 2 - bHeight / 2;
// matrix.postScale(townScale, townScale);
// matrix.postTranslate(offsetx, offsety);
//
// canvas.drawBitmap(mSky, matrix, null);
final int saveCount = canvas.getSaveCount();
canvas.save();
canvas.translate(offsetx, offsety);
matrix.postScale(townScale, townScale);
mDrawableSky.draw(canvas);
canvas.restoreToCount(saveCount);
}
示例2: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if(gifDecoder == null)
return;
if(currentImage == null){
currentImage = gifDecoder.getImage();
}
if(currentImage == null){
return;
}
int saveCount = canvas.getSaveCount();
canvas.save();
canvas.translate(getPaddingLeft(), getPaddingTop());
if(showWidth == -1){
canvas.drawBitmap(currentImage, 0, 0,null);
}else{
canvas.drawBitmap(currentImage, null, rect, null);
}
canvas.restoreToCount(saveCount);
}
示例3: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
Drawable mDrawable = getDrawable();
if (mDrawable == null) return;
final int mDrawableWidth = mDrawable.getIntrinsicWidth();
final int mDrawableHeight = mDrawable.getIntrinsicHeight();
if (mDrawableWidth == 0 || mDrawableHeight == 0) {
return; // nothing to draw (empty bounds)
}
int saveCount = canvas.getSaveCount();
canvas.save();
canvas.translate(translateLeft, translateTop);
canvas.scale(scale, scale);
// 如果先scale,再translate,那麽,真實translate的值是要與scale值相乘的
mDrawable.draw(canvas);
canvas.restoreToCount(saveCount);
}
示例4: drawSun
import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawSun(Canvas canvas, int width, int height) {
Matrix matrix = mMatrix;
matrix.reset();
float mSunLeftOffset = 0.3f * (float) width;
float mSunTopOffset = (mHeaderHeight * 0.1f);
float sunRadius = (float) mSunSize / 2.0f;
float offsetX = mSunLeftOffset + sunRadius;
float offsetY = mSunTopOffset + (mHeaderHeight / 2) * (1.0f - Math.min(mPercent, 1)); // Move the sun up
int bWidth = mDrawableSun.width();
float sunScale = 1f * mSunSize / bWidth;
if (mPercent > 1) {
sunScale = sunScale * (1.0f - 0.5f * (mPercent - 1));
sunRadius = sunRadius * (1.0f - 0.5f * (mPercent - 1));
}
matrix.preScale(sunScale, sunScale);
matrix.postRotate((isRefreshing ? -360 : 360) * mRotate * (isRefreshing ? 1 : SUN_INITIAL_ROTATE_GROWTH),
sunRadius,
sunRadius);
// canvas.save();
// canvas.translate(offsetX, offsetY);
// canvas.drawBitmap(mSun, matrix, null);
// canvas.restore();
final int saveCount = canvas.getSaveCount();
canvas.save();
canvas.translate(offsetX, offsetY);
canvas.concat(matrix);
mDrawableSun.draw(canvas);
canvas.restoreToCount(saveCount);
}
示例5: drawTown
import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawTown(Canvas canvas, int width, int height) {
Matrix matrix = mMatrix;
matrix.reset();
int bWidth = mDrawableTown.width();//mTown.getWidth();
int bHeight = mDrawableTown.height();//mTown.getHeight();
float townScale = 1f * width / bWidth;
float amplification = (0.3f * Math.max(mPercent - 1, 0) + 1);
float offsetx = width / 2 - (int) (width * amplification) / 2;
float offsety = mHeaderHeight * 0.1f * mPercent;
townScale = amplification * townScale;
if (offsety + bHeight * townScale < height) {
offsety = height - bHeight * townScale;
}
// matrix.postScale(townScale, townScale, mDrawableTown.width() / 2, mDrawableTown.height() / 2);
// matrix.postTranslate(offsetx, offsety);
// canvas.drawBitmap(mTown, matrix, null);
final int saveCount = canvas.getSaveCount();
canvas.save();
canvas.translate(offsetx, offsety);
canvas.scale(townScale, townScale);
mDrawableTown.draw(canvas);
canvas.restoreToCount(saveCount);
}
示例6: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
final int width = getWidth();
final int height = getHeight();
final int saveCount = canvas.getSaveCount();
canvas.save();
int shake = (int) (mHeaderHeight / 13 * Math.sin(mAppreciation));
if (mState == RefreshState.Refreshing
|| mState == RefreshState.RefreshFinish) {
mCloudDrawable.getBounds().offsetTo(mCloudX1, mHeaderHeight / 3);
mCloudDrawable.draw(canvas);
mCloudDrawable.getBounds().offsetTo(mCloudX2, mHeaderHeight / 2);
mCloudDrawable.draw(canvas);
mCloudDrawable.getBounds().offsetTo(mCloudX3, mHeaderHeight * 2 / 3);
mCloudDrawable.draw(canvas);
canvas.rotate(5 * (float) Math.sin(mAppreciation / 2), width / 2 , mHeaderHeight / 2 - mUmbrellaDrawable.height());
calculateFrame(width);
}
final int centerY = height - mHeaderHeight / 2 + shake;
final int centerYBox = centerY + (mHeaderHeight / 2 - mBoxDrawable.height())
- Math.min(mHeaderHeight / 2 - mBoxDrawable.height(), DensityUtil.dp2px(mAppreciation * 100));
mBoxDrawable.getBounds().offsetTo(width / 2 - mBoxDrawable.width() / 2, centerYBox - mBoxDrawable.height() / 4);
mBoxDrawable.draw(canvas);
if (mState == RefreshState.Refreshing
|| mState == RefreshState.RefreshFinish) {
Rect bounds = mUmbrellaDrawable.getBounds();
final int centerYUmbrella = centerY - mHeaderHeight + Math.min(mHeaderHeight, DensityUtil.dp2px(mAppreciation * 100));
mUmbrellaDrawable.getBounds().offsetTo(width / 2 - bounds.width() / 2, centerYUmbrella - bounds.height());
mUmbrellaDrawable.draw(canvas);
}
canvas.restoreToCount(saveCount);
}
示例7: drawEdgeEffect
import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawEdgeEffect(
Canvas canvas,
EdgeEffectCompat edgeEffect,
int degrees) {
if (canvas == null || edgeEffect == null ||
edgeEffect.isFinished()) {
return;
}
int restoreCount = canvas.getSaveCount();
int width = getWidth();
int height = getHeight() - getPaddingTop() - getPaddingBottom();
canvas.rotate(degrees);
if (degrees == 270) {
canvas.translate(
(float) -height + getPaddingTop(),
0);
} else {
canvas.translate(
-getPaddingTop(),
-width);
}
edgeEffect.setSize(height, width);
if (edgeEffect.draw(canvas)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
postInvalidateOnAnimation();
} else {
postInvalidate();
}
}
canvas.restoreToCount(restoreCount);
}
示例8: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int saveCount = canvas.getSaveCount();
canvas.save();
if (this.mCanvasArea != null) {
this.mCanvasArea.draw(canvas);
}
canvas.restoreToCount(saveCount);
}
示例9: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
public final void draw(Canvas canvas) {
if (this.mVisibility == 0) {
int saveCount = canvas.getSaveCount();
canvas.save();
canvas.clipRect(0, 0, this.width, this.height);
if (this.mBackground != null) {
this.mBackground.setBounds(0, 0, this.width, this.height);
this.mBackground.draw(canvas);
}
onDraw(canvas);
canvas.restoreToCount(saveCount);
}
}
示例10: drawAirplane
import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawAirplane(Canvas canvas, int width, int height) {
Matrix matrix = mMatrix;
matrix.reset();
float dragPercent = mPercent;
float rotateAngle = 0;
if (isInEditMode()) {
dragPercent = 1;
mHeaderHeight = height;
}
// Check overdrag
if (dragPercent > 1.0f /*&& !mEndOfRefreshing*/) {
rotateAngle = (dragPercent % 1) * 20;
dragPercent = 1.0f;
}
float offsetX = ((width * dragPercent) / 2) - mAirplane.width() / 2;
float offsetY = mHeaderHeight * (1 - dragPercent/2) - mAirplane.height() / 2;
if (mEndOfRefreshing) {
offsetX = width/2 + width * (1-dragPercent) / 2 - mAirplane.width() / 2;
offsetY = (dragPercent) * (mHeaderHeight / 2 + mAirplane.height() * 3 / 2) - 2 * mAirplane.height();
}
if (isRefreshing) {
if (checkCurrentAnimationPart(AnimationPart.FIRST)) {
offsetY -= getAnimationPartValue(AnimationPart.FIRST);
} else if (checkCurrentAnimationPart(AnimationPart.SECOND)) {
offsetY -= getAnimationPartValue(AnimationPart.SECOND);
} else if (checkCurrentAnimationPart(AnimationPart.THIRD)) {
offsetY += getAnimationPartValue(AnimationPart.THIRD);
} else if (checkCurrentAnimationPart(AnimationPart.FOURTH)) {
offsetY += getAnimationPartValue(AnimationPart.FOURTH);
}
}
if (rotateAngle > 0) {
matrix.postRotate(rotateAngle,
mAirplane.width() / 2,
mAirplane.height() / 2);
}
final int saveCount = canvas.getSaveCount();
canvas.save();
canvas.translate(offsetX, offsetY);
canvas.concat(matrix);
mAirplane.draw(canvas);
canvas.restoreToCount(saveCount);
}
示例11: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
if (bubbleDrawable == null) {
return; // couldn't resolve the URI
}
if (bubbleDrawable.getIntrinsicHeight() == 0 || bubbleDrawable.getIntrinsicWidth() == 0) {
return; // nothing to draw (empty bounds)
}
final Matrix mDrawMatrix = getImageMatrix();
final int mPaddingLeft = getPaddingLeft();
final int mPaddingTop = getPaddingTop();
if (mDrawMatrix == null && getPaddingTop() == 0 && getPaddingLeft() == 0) {
bubbleDrawable.draw(canvas);
} else {
final int saveCount = canvas.getSaveCount();
canvas.save();
//crop to padding api above 16
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
if (getCropToPadding()) {
final int scrollX = getScrollX();
final int scrollY = getScrollY();
canvas.clipRect(scrollX + mPaddingLeft, scrollY + mPaddingTop,
scrollX + getRight() - getLeft() - getRight(),
scrollY + getBottom() - getTop() - getBottom());
}
}
canvas.translate(mPaddingLeft, mPaddingTop);
if (mDrawMatrix != null) {
canvas.concat(mDrawMatrix);
mDrawMatrix.getValues(matrixValues);
final float scaleX = matrixValues[Matrix.MSCALE_X];
final float scaleY = matrixValues[Matrix.MSCALE_Y];
final float translateX = matrixValues[Matrix.MTRANS_X];
final float translateY = matrixValues[Matrix.MTRANS_Y];
final ScaleType scaleType = getScaleType();
if (scaleType == ScaleType.CENTER) {
bubbleDrawable.setOffsetLeft(-translateX);
bubbleDrawable.setOffsetTop(-translateY);
bubbleDrawable.setOffsetBottom(-translateY);
bubbleDrawable.setOffsetRight(-translateX);
} else if (scaleType == ScaleType.CENTER_CROP) {
float scale = scaleX > scaleY ? 1 / scaleY : 1 / scaleX;
bubbleDrawable.setOffsetLeft(-translateX * scale);
bubbleDrawable.setOffsetTop(-translateY * scale);
bubbleDrawable.setOffsetBottom(-translateY * scale);
bubbleDrawable.setOffsetRight(-translateX * scale);
bubbleDrawable.setScale(scale);
} else {
bubbleDrawable.setScale(scaleX > scaleY ? 1 / scaleY : 1 / scaleX);
}
}
bubbleDrawable.draw(canvas);
canvas.restoreToCount(saveCount);
}
}
示例12: drawCenterClouds
import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawCenterClouds(Canvas canvas, int width, int height) {
Matrix matrix = mMatrix;
matrix.reset();
float dragPercent = Math.min(1f, Math.abs(mPercent));
if (isInEditMode()) {
dragPercent = 1;
mHeaderHeight = height;
}
float scale;
float overdragPercent = 0;
boolean overdrag = false;
if (mPercent > 1.0f) {
overdrag = true;
// Here we want know about how mach percent of over drag we done
overdragPercent = Math.abs(1.0f - mPercent);
}
float scalePercentDelta = dragPercent - SCALE_START_PERCENT;
if (scalePercentDelta > 0) {
float scalePercent = scalePercentDelta / (1.0f - SCALE_START_PERCENT);
scale = CENTER_CLOUDS_INITIAL_SCALE + (CENTER_CLOUDS_FINAL_SCALE - CENTER_CLOUDS_INITIAL_SCALE) * scalePercent;
} else {
scale = CENTER_CLOUDS_INITIAL_SCALE;
}
float parallaxPercent = 0;
boolean parallax = false;
// Current y position of clouds
float dragYOffset = mHeaderHeight * dragPercent;
// Position when should start parallax scrolling
int startParallaxHeight = mHeaderHeight - mCloudCenter.height()/2;
if (dragYOffset > startParallaxHeight) {
parallax = true;
parallaxPercent = dragYOffset - startParallaxHeight;
}
float offsetX = (width / 2) - mCloudCenter.width() / 2;
float offsetY = dragYOffset
- (parallax ? mCloudCenter.height()/2 + parallaxPercent : mCloudCenter.height()/2);
float sx = overdrag ? scale + overdragPercent / 4 : scale;
float sy = overdrag ? scale + overdragPercent / 2 : scale;
if (isRefreshing && !overdrag) {
if (checkCurrentAnimationPart(AnimationPart.FIRST)) {
sx = scale - (getAnimationPartValue(AnimationPart.FIRST) / LOADING_ANIMATION_COEFFICIENT) / 8;
} else if (checkCurrentAnimationPart(AnimationPart.SECOND)) {
sx = scale - (getAnimationPartValue(AnimationPart.SECOND) / LOADING_ANIMATION_COEFFICIENT) / 8;
} else if (checkCurrentAnimationPart(AnimationPart.THIRD)) {
sx = scale + (getAnimationPartValue(AnimationPart.THIRD) / LOADING_ANIMATION_COEFFICIENT) / 6;
} else if (checkCurrentAnimationPart(AnimationPart.FOURTH)) {
sx = scale + (getAnimationPartValue(AnimationPart.FOURTH) / LOADING_ANIMATION_COEFFICIENT) / 6;
}
sy = sx;
}
matrix.postScale(sx, sy, mCloudCenter.width() / 2, 0);
if (offsetY + sy * mCloudCenter.height() < height + 2) {
offsetY = height + 2 - sy * mCloudCenter.height();
}
final int saveCount = canvas.getSaveCount();
canvas.save();
canvas.translate(offsetX, offsetY);
canvas.concat(matrix);
mCloudCenter.draw(canvas);
canvas.restoreToCount(saveCount);
}