Java Code Examples for android.graphics.Matrix.setTranslate()

The following are Jave code examples for showing how to use setTranslate() of the android.graphics.Matrix class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: AndroidDigIn   File: RadialGradientRippleView.java   Source Code and License Vote up 6 votes
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    mScaledBitmap = Bitmap.createScaledBitmap(mOriBitmap, w, h, true);
    mRippleScaledBitmap = Bitmap.createScaledBitmap(mOriBitmap,
            (int) (w * RIPPLE_SCALE_FACTOR), (int) (h * RIPPLE_SCALE_FACTOR), true);
    int width1 = mScaledBitmap.getWidth();
    int height1 = mScaledBitmap.getHeight();
    int width2 = mRippleScaledBitmap.getWidth();
    int height2 = mRippleScaledBitmap.getHeight();
    mDisW = Math.abs(width1 - width2) / 2;
    mDisH = Math.abs(height1 - height2) / 2;//算出两图中点相聚的距离,就是放大后需要矫正的位移距离
    mOriBitmap.recycle();
    mOriBitmap = null;
    //这里的模式无所谓,因为在屏幕外看不到
    mBitmapShader = new BitmapShader(mRippleScaledBitmap,
            Shader.TileMode.MIRROR,//这里的模式无所谓,因为在屏幕外看不到
            Shader.TileMode.MIRROR);
    Matrix matrix = new Matrix();
    matrix.setTranslate(-mDisW, -mDisH);
    mBitmapShader.setLocalMatrix(matrix);
}
 
Example 2
Project: aos-MediaLib   File: Utils.java   Source Code and License Vote up 6 votes
public static void setBackground(View v, Bitmap bm) {

        if (bm == null) {
            v.setBackgroundResource(0);
            return;
        }

        int vwidth = v.getWidth()/4;
        int vheight = v.getHeight()/4;
        int bwidth = bm.getWidth();
        int bheight = bm.getHeight();
        float scalex = (float) vwidth / bwidth;
        float scaley = (float) vheight / bheight;
        float scale = Math.max(scalex, scaley) * 1.3f;

        Bitmap.Config config = Bitmap.Config.ARGB_8888;
        Bitmap bg = Bitmap.createBitmap(vwidth, vheight, config);
        Canvas c = new Canvas(bg);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setFilterBitmap(true);
        ColorMatrix greymatrix = new ColorMatrix();
        greymatrix.setSaturation(0);
        ColorMatrix darkmatrix = new ColorMatrix();
        darkmatrix.setScale(1f, 1f, 1f, .1f);
        greymatrix.postConcat(darkmatrix);
        ColorFilter filter = new ColorMatrixColorFilter(greymatrix);
        paint.setColorFilter(filter);
        Matrix matrix = new Matrix();
        matrix.setTranslate(-bwidth/2, -bheight/2); // move bitmap center to origin
        matrix.postRotate(10);
        matrix.postScale(scale, scale);
        matrix.postTranslate(vwidth/2, vheight/2);  // Move bitmap center to view center
        c.drawBitmap(bm, matrix, paint);
        v.setBackgroundDrawable(new BitmapDrawable(bg));
    }
 
Example 3
Project: GitHub   File: ImageUtils.java   Source Code and License Vote up 5 votes
/**
 * 转为圆形图片
 *
 * @param src         源图片
 * @param recycle     是否回收
 * @param borderSize  边框尺寸
 * @param borderColor 边框颜色
 * @return 圆形图片
 */
public static Bitmap toRound(final Bitmap src,
                             @IntRange(from = 0) int borderSize,
                             @ColorInt int borderColor,
                             final boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    int width = src.getWidth();
    int height = src.getHeight();
    int size = Math.min(width, height);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    Bitmap ret = Bitmap.createBitmap(width, height, src.getConfig());
    float center = size / 2f;
    RectF rectF = new RectF(0, 0, width, height);
    rectF.inset((width - size) / 2f, (height - size) / 2f);
    Matrix matrix = new Matrix();
    matrix.setTranslate(rectF.left, rectF.top);
    matrix.preScale((float) size / width, (float) size / height);
    BitmapShader shader = new BitmapShader(src, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    shader.setLocalMatrix(matrix);
    paint.setShader(shader);
    Canvas canvas = new Canvas(ret);
    canvas.drawRoundRect(rectF, center, center, paint);
    if (borderSize > 0) {
        paint.setShader(null);
        paint.setColor(borderColor);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(borderSize);
        float radius = center - borderSize / 2f;
        canvas.drawCircle(width / 2f, height / 2f, radius, paint);
    }
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
Example 4
Project: GitHub   File: ScalingUtils.java   Source Code and License Vote up 5 votes
@Override
public void getTransformImpl(
    Matrix outTransform,
    Rect parentRect,
    int childWidth,
    int childHeight,
    float focusX,
    float focusY,
    float scaleX,
    float scaleY) {
  float dx = parentRect.left + (parentRect.width() - childWidth) * 0.5f;
  float dy = parentRect.top + (parentRect.height() - childHeight) * 0.5f;
  outTransform.setTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
}
 
Example 5
Project: airgram   File: PhotoCropView.java   Source Code and License Vote up 5 votes
private Bitmap createBitmap(int x, int y, int w, int h) {
    Bitmap newBimap = delegate.getBitmap();
    if (newBimap != null) {
        bitmapToEdit = newBimap;
    }

    Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG);

    Matrix matrix = new Matrix();
    matrix.setTranslate(-bitmapToEdit.getWidth() / 2, -bitmapToEdit.getHeight() / 2);
    matrix.postRotate(orientation);
    if (orientation % 360 == 90 || orientation % 360 == 270) {
        matrix.postTranslate(bitmapToEdit.getHeight() / 2 - x, bitmapToEdit.getWidth() / 2 - y);
    } else {
        matrix.postTranslate(bitmapToEdit.getWidth() / 2 - x, bitmapToEdit.getHeight() / 2 - y);
    }
    canvas.drawBitmap(bitmapToEdit, matrix, paint);
    try {
        canvas.setBitmap(null);
    } catch (Exception e) {
        //don't promt, this will crash on 2.x
    }

    return bitmap;
}
 
Example 6
Project: CSipSimple   File: MaxScaleImageView.java   Source Code and License Vote up 5 votes
private void updateScale() {
    Drawable d = getDrawable();
    if(d instanceof BitmapDrawable) {
        BitmapDrawable bd = (BitmapDrawable) d;

        // Don't upscale if more than 2x larger
        if (getWidth() > mMaxScale * bd.getIntrinsicWidth()
                && getHeight() > mMaxScale * bd.getIntrinsicHeight()) {
            setScaleType(ScaleType.MATRIX);
            Matrix trans = new Matrix();
            Matrix scale = new Matrix();
            trans.setTranslate((getWidth() - mMaxScale * bd.getIntrinsicWidth())/2, (getHeight() - mMaxScale * bd.getIntrinsicHeight())/2);
            scale.setScale(mMaxScale, mMaxScale);
            Matrix m = new Matrix();
            
            if(isInEditMode()) {
                // WTF? Edit mode consider inversed matrix??
                m.setConcat(scale, trans);
            }else {
                m.setConcat(trans, scale);
            }
            setImageMatrix(m);
        }else {
            setScaleType(ScaleType.CENTER_CROP);
        }
    }
}
 
Example 7
Project: bubble-rank   File: BubbleRank.java   Source Code and License Vote up 5 votes
private void drawCirclesAndText(int index, Canvas canvas) {
    boolean current = (index == mCurrentRank);

    int centerX = index * 2 * smallRadius + smallRadius - index * offset * 2;

    if (current) {
        centerX += bigRadius - smallRadius;
    } else if (index > mCurrentRank) {
        centerX += 2 * (bigRadius - smallRadius);
    }

    if (index <= mCurrentRank) {
        currentShader = current ? bigPicShaders.get(index) : smallPicShaders.get(index);

        if (currentShader != null) {
            Matrix matrix = new Matrix();
            matrix.setTranslate(centerX - (current ? getBigRadius() : getSmallRadius()), current ? 0 : getBigRadius() - getSmallRadius());
            currentShader.setLocalMatrix(matrix);
            mCirclePaint.setShader(currentShader);
        }
    } else {
        mCirclePaint.setShader(null);
    }

    int radius = current ? bigRadius : smallRadius;

    canvas.drawCircle(centerX, centerY, radius, mCirclePaint);
    canvas.drawCircle(centerX, centerY, radius, mCircleBorderPaint);

    if (!current) {
        mTextPaint.setTextSize(getResources().getDimension(R.dimen.rank_default_text_size));
        mTextPaint.getTextBounds("4", 0, 1, mBounds);
        canvas.drawText(String.valueOf(index + 1), centerX, centerY + mBounds.height() / 2, mTextPaint);
    }
}
 
Example 8
Project: BBSSDK-for-Android   File: ImageUtils.java   Source Code and License Vote up 5 votes
/**
 * 转为圆形图片
 *
 * @param src         源图片
 * @param recycle     是否回收
 * @param borderSize  边框尺寸
 * @param borderColor 边框颜色
 * @return 圆形图片
 */
public static Bitmap toRound(final Bitmap src, int borderSize, int borderColor, final boolean recycle) {
	if (isEmptyBitmap(src)) {
		return null;
	}
	int width = src.getWidth();
	int height = src.getHeight();
	int size = Math.min(width, height);
	Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
	Bitmap ret = Bitmap.createBitmap(width, height, src.getConfig());
	float center = size / 2f;
	RectF rectF = new RectF(0, 0, width, height);
	rectF.inset((width - size) / 2f, (height - size) / 2f);
	Matrix matrix = new Matrix();
	matrix.setTranslate(rectF.left, rectF.top);
	matrix.preScale((float) size / width, (float) size / height);
	BitmapShader shader = new BitmapShader(src, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
	shader.setLocalMatrix(matrix);
	paint.setShader(shader);
	Canvas canvas = new Canvas(ret);
	canvas.drawRoundRect(rectF, center, center, paint);
	if (borderSize > 0) {
		paint.setShader(null);
		paint.setColor(borderColor);
		paint.setStyle(Paint.Style.STROKE);
		paint.setStrokeWidth(borderSize);
		float radius = center - borderSize / 2f;
		canvas.drawCircle(width / 2f, height / 2f, radius, paint);
	}
	if (recycle && !src.isRecycled()) {
		src.recycle();
	}
	return ret;
}
 
Example 9
Project: Glide-transformations   File: CropCircleTransformation.java   Source Code and License Vote up 5 votes
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();
  int size = Math.min(source.getWidth(), source.getHeight());

  int width = (source.getWidth() - size) / 2;
  int height = (source.getHeight() - size) / 2;

  Bitmap bitmap = mBitmapPool.get(size, size, Bitmap.Config.ARGB_8888);
  if (bitmap == null) {
    bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
  }

  Canvas canvas = new Canvas(bitmap);
  Paint paint = new Paint();
  BitmapShader shader =
      new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
  if (width != 0 || height != 0) {
    // source isn't square, move viewport to center
    Matrix matrix = new Matrix();
    matrix.setTranslate(-width, -height);
    shader.setLocalMatrix(matrix);
  }
  paint.setShader(shader);
  paint.setAntiAlias(true);

  float r = size / 2f;
  canvas.drawCircle(r, r, r, paint);

  return BitmapResource.obtain(bitmap, mBitmapPool);
}
 
Example 10
Project: KrGallery   File: PhotoCropView.java   Source Code and License Vote up 5 votes
private Bitmap createBitmap(int x, int y, int w, int h) {
    Bitmap newBimap = delegate.getBitmap();
    if (newBimap != null) {
        bitmapToEdit = newBimap;
    }

    Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG);

    Matrix matrix = new Matrix();
    matrix.setTranslate(-bitmapToEdit.getWidth() / 2, -bitmapToEdit.getHeight() / 2);
    matrix.postRotate(orientation);
    if (orientation % 360 == 90 || orientation % 360 == 270) {
        matrix.postTranslate(bitmapToEdit.getHeight() / 2 - x, bitmapToEdit.getWidth() / 2 - y);
    } else {
        matrix.postTranslate(bitmapToEdit.getWidth() / 2 - x, bitmapToEdit.getHeight() / 2 - y);
    }
    canvas.drawBitmap(bitmapToEdit, matrix, paint);
    try {
        canvas.setBitmap(null);
    } catch (Exception e) {
        //don't promt, this will crash on 2.x
    }

    return bitmap;
}
 
Example 11
Project: GlidePlus   File: BitmapCircleTransformation.java   Source Code and License Vote up 5 votes
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
    Bitmap source = resource.get();
    int size = Math.min(source.getWidth(), source.getHeight());

    int width = (source.getWidth() - size) / 2;
    int height = (source.getHeight() - size) / 2;

    Bitmap bitmap = mBitmapPool.get(size, size, Bitmap.Config.ARGB_8888);
    if (bitmap == null) {
        bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    BitmapShader shader =
            new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
    if (width != 0 || height != 0) {
        Matrix matrix = new Matrix();
        matrix.setTranslate(-width, -height);
        shader.setLocalMatrix(matrix);
    }
    paint.setShader(shader);
    paint.setAntiAlias(true);

    float r = size / 2f;
    canvas.drawCircle(r, r, r, paint);

    return BitmapResource.obtain(bitmap, mBitmapPool);
}
 
Example 12
Project: PlusGram   File: AndroidUtilities.java   Source Code and License Vote up 5 votes
public static void setRectToRect(Matrix matrix, RectF src, RectF dst, int rotation, Matrix.ScaleToFit align) {
    float tx, sx;
    float ty, sy;
    if (rotation == 90 || rotation == 270) {
        sx = dst.height() / src.width();
        sy = dst.width() / src.height();
    } else {
        sx = dst.width() / src.width();
        sy = dst.height() / src.height();
    }
    if (align != Matrix.ScaleToFit.FILL) {
        if (sx > sy) {
            sx = sy;
        } else {
            sy = sx;
        }
    }
    tx = -src.left * sx;
    ty = -src.top * sy;

    matrix.setTranslate(dst.left, dst.top);
    if (rotation == 90) {
        matrix.preRotate(90);
        matrix.preTranslate(0, -dst.width());
    } else if (rotation == 180) {
        matrix.preRotate(180);
        matrix.preTranslate(-dst.width(), -dst.height());
    } else if (rotation == 270) {
        matrix.preRotate(270);
        matrix.preTranslate(-dst.height(), 0);
    }

    matrix.preScale(sx, sy);
    matrix.preTranslate(tx, ty);
}
 
Example 13
Project: PlusGram   File: PhotoCropView.java   Source Code and License Vote up 5 votes
private Bitmap createBitmap(int x, int y, int w, int h) {
    Bitmap newBimap = delegate.getBitmap();
    if (newBimap != null) {
        bitmapToEdit = newBimap;
    }

    Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG);

    Matrix matrix = new Matrix();
    matrix.setTranslate(-bitmapToEdit.getWidth() / 2, -bitmapToEdit.getHeight() / 2);
    matrix.postRotate(orientation);
    if (orientation % 360 == 90 || orientation % 360 == 270) {
        matrix.postTranslate(bitmapToEdit.getHeight() / 2 - x, bitmapToEdit.getWidth() / 2 - y);
    } else {
        matrix.postTranslate(bitmapToEdit.getWidth() / 2 - x, bitmapToEdit.getHeight() / 2 - y);
    }
    canvas.drawBitmap(bitmapToEdit, matrix, paint);
    try {
        canvas.setBitmap(null);
    } catch (Exception e) {
        //don't promt, this will crash on 2.x
    }

    return bitmap;
}
 
Example 14
Project: QuickDrawEverywhere   File: MatrixUtils.java   Source Code and License Vote up 5 votes
public static Matrix GetCenterCropMatrix(RectF srcSize, RectF destSize){
    Matrix matrix = new Matrix();
    float scale = Math.max(destSize.width() / srcSize.width(),
            destSize.height() / srcSize.height());
    matrix.setTranslate(-(destSize.width() / 2), - (destSize.height() / 2));
    matrix.setScale(scale, scale);

    return matrix;
}
 
Example 15
Project: Picasso-transformations   File: CropCircleTransformation.java   Source Code and License Vote up 5 votes
@Override public Bitmap transform(Bitmap source) {
  int size = Math.min(source.getWidth(), source.getHeight());

  int width = (source.getWidth() - size) / 2;
  int height = (source.getHeight() - size) / 2;

  Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);

  Canvas canvas = new Canvas(bitmap);
  Paint paint = new Paint();
  BitmapShader shader =
      new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
  if (width != 0 || height != 0) {
    // source isn't square, move viewport to center
    Matrix matrix = new Matrix();
    matrix.setTranslate(-width, -height);
    shader.setLocalMatrix(matrix);
  }
  paint.setShader(shader);
  paint.setAntiAlias(true);

  float r = size / 2f;
  canvas.drawCircle(r, r, r, paint);

  source.recycle();

  return bitmap;
}
 
Example 16
Project: LeafLoadingView   File: LeafLoadingView.java   Source Code and License Vote up 5 votes
private void drawFan(Canvas canvas){
    int centerX = (int) mTotalProgressWidth;
    int centerY = 8;
    if(mProgress == 100){
        String text = "100%";
        canvas.drawText(text,centerX,mPicHeight/2+getTextHeight(text)/2,mFanPaint);
    }else{
        Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.fengshan);
        int bitmapWidth = bitmap.getWidth();
        int bitmapHeight = bitmap.getHeight();

        Matrix matrix = new Matrix();
        matrix.setTranslate(centerX, centerY);     //设置图片的原点坐标
        if (this.mProgress >= 95 && this.mProgress < 100){
            float scale = Math.abs(this.mProgress - 100) * 0.2f;
            //缩放 参数1:X轴缩放倍数,参数2:Y轴缩放倍数 参数3,4:缩放中心点
            matrix.preScale(scale,scale,(float)bitmapWidth/2, (float)bitmapHeight/2);
        }else{
            //旋转 参数1:角度,参数2,3:旋转中心点
            matrix.preRotate(mAngle, (float)bitmapWidth/2, (float)bitmapHeight/2);
        }
        canvas.drawBitmap(bitmap, matrix, mFanPaint);
        if (this.mProgress != 100){
            mAngle += 60;
        }
    }
}
 
Example 17
Project: YiZhi   File: MovingImageView.java   Source Code and License Vote up 4 votes
/**
 * 设置最佳的运动类型
 * 计算缩放比例
 *
 * @return image scale.
 */
private float calculateTypeAndScale() {
    movementType = MovingViewAnimator.AUTO_MOVE;
    float scale = 1f;
    float scaleByImage = Math.max(imageWidth / canvasWidth, imageHeight / canvasHeight);
    Matrix matrix = new Matrix();

    if (offsetWidth == 0 && offsetHeight == 0) {//图片太小,无法动画,需要放大
        //画布宽度/图片宽度
        float sW = canvasWidth / imageWidth;
        //画布高度/图片高度
        float sH = canvasHeight / imageHeight;

        if (sW > sH) {
            scale = Math.min(sW, maxRelativeSize);//限定最大缩放值
            matrix.setTranslate((canvasWidth - imageWidth * scale) / 2f, 0);
            movementType = MovingViewAnimator.VERTICAL_MOVE;//垂直移动

        } else if (sW < sH) {
            scale = Math.min(sH, maxRelativeSize);//限定最大缩放值
            matrix.setTranslate(0, (canvasHeight - imageHeight * scale) / 2f);
            movementType = MovingViewAnimator.HORIZONTAL_MOVE;//水平移动

        } else {
            scale = Math.max(sW, maxRelativeSize);//限定最大缩放值
            movementType = (scale == sW) ? MovingViewAnimator.NONE_MOVE :
                    MovingViewAnimator.DIAGONAL_MOVE;//对角线移动
        }
    } else if (offsetWidth == 0) {//宽度太小,无法执行水平动画,放大宽度
        scale = canvasWidth / imageWidth;
        movementType = MovingViewAnimator.VERTICAL_MOVE;

    } else if (offsetHeight == 0) {//高度太小,无法执行垂直动画,放大高度
        scale = canvasHeight / imageHeight;//求出画布高度和图片高度的比值用于确定画布起始坐标
        movementType = MovingViewAnimator.HORIZONTAL_MOVE;

    } else if (scaleByImage > maxRelativeSize) {//图片太大,根据最大比值设定图片缩放值
        scale = maxRelativeSize / scaleByImage;
        if (imageWidth * scale < canvasWidth || imageHeight * scale < canvasHeight) {
            scale = Math.max(canvasWidth / imageWidth, canvasHeight / imageHeight);
        }
    }

    matrix.preScale(scale, scale);
    setImageMatrix(matrix);
    return scale;
}
 
Example 18
Project: HtmlNative   File: Background.java   Source Code and License Vote up 4 votes
public static Matrix createBitmapMatrix(Background background) {
    Matrix matrix = new Matrix();
    matrix.setTranslate(background.getX(), background.getY());
    return matrix;
}
 
Example 19
Project: utilsLibrary   File: GlideWatermarkTransform.java   Source Code and License Vote up 4 votes
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {

    if (toTransform == null) return null;

    Bitmap newBm=Bitmap.createBitmap(toTransform.getWidth(), toTransform.getHeight(), toTransform.getConfig());
    Canvas canvas =new Canvas(newBm);

    //先比对toTransform画一张图
    canvas.drawBitmap(toTransform, new Matrix(), new Paint());

    Matrix matrix= new Matrix();
    //移动第二张空白画布到合适的位置
    matrix.setTranslate((toTransform.getWidth()-watermarkBitmap.getWidth())/2, (toTransform.getWidth()-watermarkBitmap.getWidth())/2);

    canvas.drawBitmap(watermarkBitmap, matrix, new Paint());

    return newBm;

}
 
Example 20
Project: QSRefreshLayout   File: PlainRefreshDraw.java   Source Code and License Vote up 4 votes
private void drawJet(Canvas canvas) {
    Matrix matrix = mMatrix;
    matrix.reset();

    float dragPercent = mPercent;
    float rotateAngle = 0;

    // Check overdrag
    if (dragPercent > 1.0f && !mEndOfRefreshing) {
        if (dragPercent > 2)
            dragPercent = 2;
        rotateAngle = (dragPercent - 1) * 10;
        dragPercent = 1.0f;
    }
    if (mEndOfRefreshing) {
        dragPercent = 2 - dragPercent;
    }

    float offsetX = ((mScreenWidth * dragPercent) / 2) - mJetWidthCenter;

    float offsetY = mJetTopOffset
            + (getTotalDragDistance / 2)
            * (1.0f - dragPercent)
            - mJetHeightCenter;

    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);
        }
    }

    matrix.setTranslate(offsetX, offsetY);

    if (dragPercent == 1.0f) {
        matrix.preRotate(rotateAngle, mJetWidthCenter, mJetHeightCenter);
    }

    canvas.drawBitmap(mJet, matrix, null);
}