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

The following are Jave code examples for showing how to use preRotate() 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: airgram   File: ColorPicker.java   Source Code and License Vote up 5 votes
@Override
protected void onSizeChanged(int width, int height, int oldw, int oldh) {

    int centerX = width / 2;
    int centerY = height / 2;

    innerPadding = (int) (paramInnerPadding * width / 100);
    outerPadding = (int) (paramOuterPadding * width / 100);
    arrowPointerSize = (int) (paramArrowPointerSize * width / 100);
    valueSliderWidth = (int) (paramValueSliderWidth * width / 100);

    outerWheelRadius = width / 2 - outerPadding - arrowPointerSize;
    innerWheelRadius = outerWheelRadius - valueSliderWidth;
    colorWheelRadius = innerWheelRadius - innerPadding;

    outerWheelRect.set(centerX - outerWheelRadius, centerY - outerWheelRadius, centerX + outerWheelRadius, centerY + outerWheelRadius);
    innerWheelRect.set(centerX - innerWheelRadius, centerY - innerWheelRadius, centerX + innerWheelRadius, centerY + innerWheelRadius);

    colorWheelBitmap = createColorWheelBitmap(colorWheelRadius * 2, colorWheelRadius * 2);

    gradientRotationMatrix = new Matrix();
    gradientRotationMatrix.preRotate(270, width / 2, height / 2);

    colorViewPath.arcTo(outerWheelRect, 270, -180);
    colorViewPath.arcTo(innerWheelRect, 90, 180);

    valueSliderPath.arcTo(outerWheelRect, 270, 180);
    valueSliderPath.arcTo(innerWheelRect, 90, -180);

}
 
Example 2
Project: airgram   File: MultiColorPicker.java   Source Code and License Vote up 5 votes
@Override
protected void onSizeChanged(int width, int height, int oldw, int oldh) {

    int centerX = width / 2;
    int centerY = height / 2;

    innerPadding = (int) (paramInnerPadding * width / 100);
    outerPadding = (int) (paramOuterPadding * width / 100);
    arrowPointerSize = (int) (paramArrowPointerSize * width / 100);
    valueSliderWidth = (int) (paramValueSliderWidth * width / 100);

    outerWheelRadius = width / 2 - outerPadding - arrowPointerSize;
    innerWheelRadius = outerWheelRadius - valueSliderWidth;
    colorWheelRadius = innerWheelRadius - innerPadding;

    outerWheelRect.set(centerX - outerWheelRadius, centerY - outerWheelRadius, centerX + outerWheelRadius, centerY + outerWheelRadius);
    innerWheelRect.set(centerX - innerWheelRadius, centerY - innerWheelRadius, centerX + innerWheelRadius, centerY + innerWheelRadius);

    colorWheelBitmap = createColorWheelBitmap(colorWheelRadius * 2, colorWheelRadius * 2);

    gradientRotationMatrix = new Matrix();
    gradientRotationMatrix.preRotate(270, width / 2, height / 2);

    valueSliderPath.arcTo(outerWheelRect, 270, 180);
    valueSliderPath.arcTo(innerWheelRect, 90, -180);

}
 
Example 3
Project: polling-station-app   File: CameraFragmentUtil.java   Source Code and License Vote up 5 votes
/**
 * Rotate the bitmap a given amount of degrees. This is used to get the correct bitmap when
 * the device is in landscape mode.
 * @param bitmap
 * @param degrees
 * @return a rotated bitmap
 */
public static Bitmap rotateBitmap(Bitmap bitmap, int degrees) {
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    // Setting pre rotate
    Matrix mtx = new Matrix();
    mtx.preRotate(degrees);
    // Rotating Bitmap
    Bitmap rotated = Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true);
    return Bitmap.createScaledBitmap(rotated, bitmap.getWidth(), bitmap.getHeight(), true);
}
 
Example 4
Project: buildAPKsApps   File: ColorPicker.java   Source Code and License Vote up 5 votes
@Override
protected void onSizeChanged(int width, int height, int oldw, int oldh) {

    int centerX = width / 2;
    int centerY = height / 2;

    innerPadding = (int) (paramInnerPadding * width / 100);
    outerPadding = (int) (paramOuterPadding * width / 100);
    arrowPointerSize = (int) (paramArrowPointerSize * width / 100);
    valueSliderWidth = (int) (paramValueSliderWidth * width / 100);

    outerWheelRadius = width / 2 - outerPadding - arrowPointerSize;
    innerWheelRadius = outerWheelRadius - valueSliderWidth;
    colorWheelRadius = innerWheelRadius - innerPadding;

    outerWheelRect.set(centerX - outerWheelRadius, centerY - outerWheelRadius, centerX + outerWheelRadius, centerY + outerWheelRadius);
    innerWheelRect.set(centerX - innerWheelRadius, centerY - innerWheelRadius, centerX + innerWheelRadius, centerY + innerWheelRadius);

    colorWheelBitmap = createColorWheelBitmap(colorWheelRadius * 2, colorWheelRadius * 2);

    gradientRotationMatrix = new Matrix();
    gradientRotationMatrix.preRotate(270, width / 2, height / 2);

    colorViewPath.arcTo(outerWheelRect, 270, -180);
    colorViewPath.arcTo(innerWheelRect, 90, 180);

    valueSliderPath.arcTo(outerWheelRect, 270, 180);
    valueSliderPath.arcTo(innerWheelRect, 90, -180);

}
 
Example 5
Project: buildAPKsApps   File: MultiColorPicker.java   Source Code and License Vote up 5 votes
@Override
protected void onSizeChanged(int width, int height, int oldw, int oldh) {

    int centerX = width / 2;
    int centerY = height / 2;

    innerPadding = (int) (paramInnerPadding * width / 100);
    outerPadding = (int) (paramOuterPadding * width / 100);
    arrowPointerSize = (int) (paramArrowPointerSize * width / 100);
    valueSliderWidth = (int) (paramValueSliderWidth * width / 100);

    outerWheelRadius = width / 2 - outerPadding - arrowPointerSize;
    innerWheelRadius = outerWheelRadius - valueSliderWidth;
    colorWheelRadius = innerWheelRadius - innerPadding;

    outerWheelRect.set(centerX - outerWheelRadius, centerY - outerWheelRadius, centerX + outerWheelRadius, centerY + outerWheelRadius);
    innerWheelRect.set(centerX - innerWheelRadius, centerY - innerWheelRadius, centerX + innerWheelRadius, centerY + innerWheelRadius);

    colorWheelBitmap = createColorWheelBitmap(colorWheelRadius * 2, colorWheelRadius * 2);

    gradientRotationMatrix = new Matrix();
    gradientRotationMatrix.preRotate(270, width / 2, height / 2);

    valueSliderPath.arcTo(outerWheelRect, 270, 180);
    valueSliderPath.arcTo(innerWheelRect, 90, -180);

}
 
Example 6
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 7
Project: boohee_v5.6   File: ProgressIndicator.java   Source Code and License Vote up 5 votes
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    RectF oval = new RectF(8.0f, 8.0f, (float) (this.mSize - 8), (float) (this.mSize - 8));
    Paint bgPaint = new Paint();
    bgPaint.setAntiAlias(true);
    bgPaint.setStrokeWidth(2.0f);
    bgPaint.setStyle(Style.STROKE);
    bgPaint.setColor(this.CIRCLE_INDICATOR_COLOR);
    canvas.drawArc(oval, 0.0f, 360.0f, false, bgPaint);
    Paint circlePaint = new Paint();
    circlePaint.setAntiAlias(true);
    circlePaint.setStrokeWidth(8.0f);
    circlePaint.setStyle(Style.STROKE);
    circlePaint.setStrokeCap(Cap.ROUND);
    Matrix matrix = new Matrix();
    matrix.preRotate(-90.0f, (float) (this.mSize / 2), (float) (this.mSize / 2));
    SweepGradient gradient = new SweepGradient((float) (this.mSize / 2), (float) (this
            .mSize / 2), this.CIRCLE_STROKE_COLOR, this.CIRCLE_STROKE_COLOR_END);
    gradient.setLocalMatrix(matrix);
    circlePaint.setShader(gradient);
    canvas.drawArc(oval, -90.0f, (float) this.mProgress, false, circlePaint);
    Paint fullPaint = new Paint();
    fullPaint.setAntiAlias(true);
    fullPaint.setStyle(Style.FILL);
    fullPaint.setStrokeCap(Cap.ROUND);
    if (this.mProgress == 360) {
        fullPaint.setColor(this.CIRCLE_STROKE_COLOR_END);
    } else {
        fullPaint.setColor(this.CIRCLE_STROKE_COLOR);
    }
    canvas.drawCircle((float) (this.mSize / 2), 8.0f, aj.hA, fullPaint);
}
 
Example 8
Project: ThunderMusic   File: ColorPicker.java   Source Code and License Vote up 5 votes
@Override
protected void onSizeChanged(int width, int height, int oldw, int oldh) {

    int centerX = width / 2;
    int centerY = height / 2;

    innerPadding = paramInnerPadding * width / 100;
    outerPadding = paramOuterPadding * width / 100;
    arrowPointerSize = paramArrowPointerSize * width / 100;
    valueSliderWidth = paramValueSliderWidth * width / 100;

    outerWheelRadius = width / 2 - outerPadding - arrowPointerSize;
    innerWheelRadius = outerWheelRadius - valueSliderWidth;
    colorWheelRadius = innerWheelRadius - innerPadding;

    outerWheelRect.set(centerX - outerWheelRadius, centerY
            - outerWheelRadius, centerX + outerWheelRadius, centerY
            + outerWheelRadius);
    innerWheelRect.set(centerX - innerWheelRadius, centerY
            - innerWheelRadius, centerX + innerWheelRadius, centerY
            + innerWheelRadius);

    colorWheelBitmap = createColorWheelBitmap(colorWheelRadius * 2,
            colorWheelRadius * 2);

    gradientRotationMatrix = new Matrix();
    gradientRotationMatrix.preRotate(270, width / 2, height / 2);

    colorViewPath.arcTo(outerWheelRect, 270, -180);
    colorViewPath.arcTo(innerWheelRect, 90, 180);

    valueSliderPath.arcTo(outerWheelRect, 270, 180);
    valueSliderPath.arcTo(innerWheelRect, 90, -180);

}
 
Example 9
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 10
Project: pc-android-controller-android   File: ScreentShotUtil.java   Source Code and License Vote up 4 votes
/**
 * Takes Reboot screenshot of the current display and shows an animation.
 */
@SuppressLint("NewApi")
public void takeScreenshot(Context context, String fileFullPath)
{
    if(fileFullPath == ""){
        format = new SimpleDateFormat("yyyyMMddHHmmss");
        String fileName = format.format(new Date(System.currentTimeMillis())) + ".png";
        fileFullPath = "/data/local/tmp/" + fileName;
    }

    if(ShellUtils.checkRootPermission()){
        if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH){
            ShellUtils.execCommand("/system/bin/screencap -p "+ fileFullPath,true);
        }
    }
    else {
        if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2 && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH){
            wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            mDisplay = wm.getDefaultDisplay();
            mDisplayMatrix = new Matrix();
            mDisplayMetrics = new DisplayMetrics();
            // We need to orient the screenshot correctly (and the Surface api seems to take screenshots
            // only in the natural orientation of the device :!)
            mDisplay.getRealMetrics(mDisplayMetrics);
            float[] dims =
                    {
                            mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels
                    };
            float degrees = getDegreesForRotation(mDisplay.getRotation());
            boolean requiresRotation = (degrees > 0);
            if (requiresRotation)
            {
                // Get the dimensions of the device in its native orientation
                mDisplayMatrix.reset();
                mDisplayMatrix.preRotate(-degrees);
                mDisplayMatrix.mapPoints(dims);
                dims[0] = Math.abs(dims[0]);
                dims[1] = Math.abs(dims[1]);
            }

            Bitmap mScreenBitmap = screenShot((int) dims[0], (int) dims[1]);
            if (requiresRotation)
            {
                // Rotate the screenshot to the current orientation
                Bitmap ss = Bitmap.createBitmap(mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels,
                        Bitmap.Config.ARGB_8888);
                Canvas c = new Canvas(ss);
                c.translate(ss.getWidth() / 2, ss.getHeight() / 2);
                c.rotate(degrees);
                c.translate(-dims[0] / 2, -dims[1] / 2);
                c.drawBitmap(mScreenBitmap, 0, 0, null);
                c.setBitmap(null);
                mScreenBitmap = ss;
                if (ss != null && !ss.isRecycled())
                {
                    ss.recycle();
                }
            }

            // If we couldn't take the screenshot, notify the user
            if (mScreenBitmap == null)
            {
                Toast.makeText(context, "screen shot fail", Toast.LENGTH_SHORT).show();
            }

            // Optimizations
            mScreenBitmap.setHasAlpha(false);
            mScreenBitmap.prepareToDraw();

            saveBitmap2file(context, mScreenBitmap, fileFullPath);
        }
    }

}
 
Example 11
Project: DashProgress   File: DashProgressCircle.java   Source Code and License Vote up 4 votes
@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);

}
 
Example 12
Project: Tesseract-OCR-Scanner   File: Tools.java   Source Code and License Vote up 4 votes
public static Bitmap preRotateBitmap(Bitmap source, float angle) {
    Matrix matrix = new Matrix();
    matrix.preRotate(angle);
    return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, false);
}
 
Example 13
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);
}