当前位置: 首页>>代码示例>>Java>>正文


Java Canvas.getSaveCount方法代码示例

本文整理汇总了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);
    }
 
开发者ID:Brave-wan,项目名称:SmartRefresh,代码行数:23,代码来源:PhoenixHeader.java

示例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);
}
 
开发者ID:fengdongfei,项目名称:CXJPadProject,代码行数:21,代码来源:GifView.java

示例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);
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:23,代码来源:ImagePreviewView.java

示例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);
    }
 
开发者ID:scwang90,项目名称:SmartRefreshLayout,代码行数:38,代码来源:PhoenixHeader.java

示例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);
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:28,代码来源:PhoenixHeader.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:39,代码来源:DeliveryHeader.java

示例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);
}
 
开发者ID:markusfisch,项目名称:SwipeImageView,代码行数:38,代码来源:SwipeImageView.java

示例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);
}
 
开发者ID:xieyangxuejun,项目名称:CommentView,代码行数:10,代码来源:CanvasAreaView.java

示例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);
    }
}
 
开发者ID:xieyangxuejun,项目名称:CommentView,代码行数:14,代码来源:CanvasArea.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:52,代码来源:TaurusHeader.java

示例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);
    }
}
 
开发者ID:leochuan,项目名称:BubbleView,代码行数:66,代码来源:BubbleImageView.java

示例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);
}
 
开发者ID:scwang90,项目名称:SmartRefreshLayout,代码行数:75,代码来源:TaurusHeader.java


注:本文中的android.graphics.Canvas.getSaveCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。