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

The following are Jave code examples for showing how to use preTranslate() 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: Flashcards-Demo   File: FlipAnimation.java   Source Code and License Vote up 6 votes
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    final double radians = Math.PI * interpolatedTime;
    float degrees = (float) (180.0 * radians / Math.PI);

    if (interpolatedTime >= 0.5f) { // Alternate the visibility of views at the exact half of animation duration.
        degrees -= 180.f;
        fromView.setVisibility(View.GONE);
        toView.setVisibility(View.VISIBLE);
    }

    if (forward)
        degrees = -degrees;

    final Matrix matrix = t.getMatrix();
    camera.save();
    camera.rotateY(degrees);
    camera.getMatrix(matrix);
    camera.restore();
    matrix.preTranslate(-centerX, -centerY);
    matrix.postTranslate(centerX, centerY);
}
 
Example 2
Project: DailyReader   File: ReadView.java   Source Code and License Vote up 6 votes
/**
 * 关于两个control连线的对称矩阵
 * @return
 */
private Matrix getSymmetricalMatrix() {
    // 根据网上资料,有一点错误,就是先-b,再b
    float k = (mBzControl1.y - mBzControl2.y) / (mBzControl1.x - mBzControl2.x);
    float[] values = new float[9];
    values[0] = -1 * (k * k - 1) / (k * k + 1);
    values[1] = 2 * k / (k * k + 1);
    values[3] = values[1];
    values[4] = -values[0];
    values[8] = 1;

    float b = mBzControl1.y - mBzControl1.x * k;
    Matrix matrix = new Matrix();
    matrix.setValues(values);
    matrix.preTranslate(0, -b);
    matrix.postTranslate(0, b);

    return matrix;
}
 
Example 3
Project: HutHelper   File: CourseInfoGallery.java   Source Code and License Vote up 6 votes
private void transformImageBitmap(View child, Transformation t,
                                  int rotationAngle) {
    mCamera.save();
    final Matrix imageMatrix = t.getMatrix();
    final int imageHeight = child.getLayoutParams().height;
    final int imageWidth = child.getLayoutParams().width;
    final int rotation = Math.abs(rotationAngle);

    mCamera.translate(0.0f, 0.0f, 100.0f);

    // As the angle of the view gets less, zoom in
    if (rotation < mMaxRotationAngle) {
        float zoomAmount = (float) (mMaxZoom + (rotation * 1.5));
        mCamera.translate(0.0f, 0.0f, zoomAmount);
    }

    mCamera.rotateY(rotationAngle);
    mCamera.getMatrix(imageMatrix);
    imageMatrix.preTranslate(-(imageWidth / 2), -(imageHeight / 2));
    imageMatrix.postTranslate((imageWidth / 2), (imageHeight / 2));
    mCamera.restore();
}
 
Example 4
Project: BookLoadingView   File: Rotate3dAnimation.java   Source Code and License Vote up 6 votes
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    final float fromDegrees = mFromDegrees;
    float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);

    final float centerX = mCenterX;
    final float centerY = mCenterY;
    final Camera camera = mCamera;

    final Matrix matrix = t.getMatrix();

    camera.save();
    if (mReverse) {
        camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);
    } else {
        camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));
    }
    camera.rotateY(degrees);
    camera.getMatrix(matrix);
    camera.restore();

    matrix.preTranslate(-centerX, -centerY);
    matrix.postTranslate(centerX, centerY);
}
 
Example 5
Project: androidthings-imageclassifier   File: Helper.java   Source Code and License Vote up 6 votes
public static void cropAndRescaleBitmap(final Bitmap src, final Bitmap dst, int sensorOrientation) {
    Assert.assertEquals(dst.getWidth(), dst.getHeight());
    final float minDim = Math.min(src.getWidth(), src.getHeight());

    final Matrix matrix = new Matrix();

    // We only want the center square out of the original rectangle.
    final float translateX = -Math.max(0, (src.getWidth() - minDim) / 2);
    final float translateY = -Math.max(0, (src.getHeight() - minDim) / 2);
    matrix.preTranslate(translateX, translateY);

    final float scaleFactor = dst.getHeight() / minDim;
    matrix.postScale(scaleFactor, scaleFactor);

    // Rotate around the center if necessary.
    if (sensorOrientation != 0) {
        matrix.postTranslate(-dst.getWidth() / 2.0f, -dst.getHeight() / 2.0f);
        matrix.postRotate(sensorOrientation);
        matrix.postTranslate(dst.getWidth() / 2.0f, dst.getHeight() / 2.0f);
    }

    final Canvas canvas = new Canvas(dst);
    canvas.drawBitmap(src, matrix, null);
}
 
Example 6
Project: androidthings-imageclassifier   File: Helper.java   Source Code and License Vote up 6 votes
public static void cropAndRescaleBitmap(final Bitmap src, final Bitmap dst, int sensorOrientation) {
    Assert.assertEquals(dst.getWidth(), dst.getHeight());
    final float minDim = Math.min(src.getWidth(), src.getHeight());

    final Matrix matrix = new Matrix();

    // We only want the center square out of the original rectangle.
    final float translateX = -Math.max(0, (src.getWidth() - minDim) / 2);
    final float translateY = -Math.max(0, (src.getHeight() - minDim) / 2);
    matrix.preTranslate(translateX, translateY);

    final float scaleFactor = dst.getHeight() / minDim;
    matrix.postScale(scaleFactor, scaleFactor);

    // Rotate around the center if necessary.
    if (sensorOrientation != 0) {
        matrix.postTranslate(-dst.getWidth() / 2.0f, -dst.getHeight() / 2.0f);
        matrix.postRotate(sensorOrientation);
        matrix.postTranslate(dst.getWidth() / 2.0f, dst.getHeight() / 2.0f);
    }

    final Canvas canvas = new Canvas(dst);
    canvas.drawBitmap(src, matrix, null);
}
 
Example 7
Project: FragmentRigger   File: Rotate3d.java   Source Code and License Vote up 6 votes
@Override
  protected void applyTransformation(float interpolatedTime, Transformation t) {
    Camera camera = new Camera();
    camera.save();

    // 设置camera动作为绕Y轴旋转
    // 总共旋转180度,因此计算在每个补间时间点interpolatedTime的角度即为两着相乘
//    camera.rotateX(deg * interpolatedTime);
    camera.rotateY(180 * interpolatedTime);
//    camera.rotateZ(180 * interpolatedTime);
//
    // 根据camera动作产生一个matrix,赋给Transformation的matrix,以用来设置动画效果
    Matrix matrix = t.getMatrix();
    camera.getMatrix(matrix);

    camera.restore();
    //经过以下平移,才能以view的中心点进行翻转
    matrix.preTranslate(-view.getWidth() / 2, -view.getHeight() / 2);
    matrix.postTranslate(view.getWidth() / 2, view.getHeight() / 2);
  }
 
Example 8
Project: sample-tensorflow-imageclassifier   File: Helper.java   Source Code and License Vote up 6 votes
public static void cropAndRescaleBitmap(final Bitmap src, final Bitmap dst, int sensorOrientation) {
    Assert.assertEquals(dst.getWidth(), dst.getHeight());
    final float minDim = Math.min(src.getWidth(), src.getHeight());

    final Matrix matrix = new Matrix();

    // We only want the center square out of the original rectangle.
    final float translateX = -Math.max(0, (src.getWidth() - minDim) / 2);
    final float translateY = -Math.max(0, (src.getHeight() - minDim) / 2);
    matrix.preTranslate(translateX, translateY);

    final float scaleFactor = dst.getHeight() / minDim;
    matrix.postScale(scaleFactor, scaleFactor);

    // Rotate around the center if necessary.
    if (sensorOrientation != 0) {
        matrix.postTranslate(-dst.getWidth() / 2.0f, -dst.getHeight() / 2.0f);
        matrix.postRotate(sensorOrientation);
        matrix.postTranslate(dst.getWidth() / 2.0f, dst.getHeight() / 2.0f);
    }

    final Canvas canvas = new Canvas(dst);
    canvas.drawBitmap(src, matrix, null);
}
 
Example 9
Project: HiBangClient   File: RotateAnimation.java   Source Code and License Vote up 6 votes
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
	float deg = 0.0F + 360.0F * interpolatedTime;
	Matrix matrix = t.getMatrix();
	mCamera.save();
	if (mMode == Mode.X)
		mCamera.rotateX(deg);
	if (mMode == Mode.Y)
		mCamera.rotateY(deg);
	if (mMode == Mode.Z)
		mCamera.rotateZ(deg);

	mCamera.getMatrix(matrix);
	mCamera.restore();
	matrix.preTranslate(-mCenterX, -mCenterY);
	matrix.postTranslate(mCenterX, mCenterY);

}
 
Example 10
Project: SciChart.Android.Examples   File: FlipAnimation.java   Source Code and License Vote up 6 votes
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    float degrees = fromDegrees + ((toDegrees - fromDegrees) * interpolatedTime);
    final Matrix matrix = t.getMatrix();

    final Camera camera = mCamera;
    camera.save();

    camera.rotateY(degrees);
    camera.getMatrix(matrix);

    camera.restore();

    matrix.preTranslate(-centerX, -centerY);
    matrix.postTranslate(centerX, centerY);
}
 
Example 11
Project: exciting-app   File: AnimatorProxy.java   Source Code and License Vote up 5 votes
private void transformMatrix(Matrix m, View view) {
    final float w = view.getWidth();
    final float h = view.getHeight();
    final boolean hasPivot = mHasPivot;
    final float pX = hasPivot ? mPivotX : w / 2f;
    final float pY = hasPivot ? mPivotY : h / 2f;

    final float rX = mRotationX;
    final float rY = mRotationY;
    final float rZ = mRotationZ;
    if ((rX != 0) || (rY != 0) || (rZ != 0)) {
        final Camera camera = mCamera;
        camera.save();
        camera.rotateX(rX);
        camera.rotateY(rY);
        camera.rotateZ(-rZ);
        camera.getMatrix(m);
        camera.restore();
        m.preTranslate(-pX, -pY);
        m.postTranslate(pX, pY);
    }

    final float sX = mScaleX;
    final float sY = mScaleY;
    if ((sX != 1.0f) || (sY != 1.0f)) {
        m.postScale(sX, sY);
        final float sPX = -(pX / w) * ((sX * w) - w);
        final float sPY = -(pY / h) * ((sY * h) - h);
        m.postTranslate(sPX, sPY);
    }

    m.postTranslate(mTranslationX, mTranslationY);
}
 
Example 12
Project: boohee_v5.6   File: ViewGroupUtilsHoneycomb.java   Source Code and License Vote up 5 votes
static void offsetDescendantMatrix(ViewParent target, View view, Matrix m) {
    ViewParent parent = view.getParent();
    if ((parent instanceof View) && parent != target) {
        View vp = (View) parent;
        offsetDescendantMatrix(target, vp, m);
        m.preTranslate((float) (-vp.getScrollX()), (float) (-vp.getScrollY()));
    }
    m.preTranslate((float) view.getLeft(), (float) view.getTop());
    if (!view.getMatrix().isIdentity()) {
        m.preConcat(view.getMatrix());
    }
}
 
Example 13
Project: LuaViewPlayground   File: AnimatorProxy.java   Source Code and License Vote up 5 votes
private void transformMatrix(Matrix m, View view) {
    final float w = view.getWidth();
    final float h = view.getHeight();
    final boolean hasPivot = mHasPivot;
    final float pX = hasPivot ? mPivotX : w / 2f;
    final float pY = hasPivot ? mPivotY : h / 2f;

    final float rX = mRotationX;
    final float rY = mRotationY;
    final float rZ = mRotationZ;
    if ((rX != 0) || (rY != 0) || (rZ != 0)) {
        final Camera camera = mCamera;
        camera.save();
        camera.rotateX(rX);
        camera.rotateY(rY);
        camera.rotateZ(-rZ);
        camera.getMatrix(m);
        camera.restore();
        m.preTranslate(-pX, -pY);
        m.postTranslate(pX, pY);
    }

    final float sX = mScaleX;
    final float sY = mScaleY;
    if ((sX != 1.0f) || (sY != 1.0f)) {
        m.postScale(sX, sY);
        final float sPX = -(pX / w) * ((sX * w) - w);
        final float sPY = -(pY / h) * ((sY * h) - h);
        m.postTranslate(sPX, sPY);
    }

    m.postTranslate(mTranslationX, mTranslationY);
}
 
Example 14
Project: simple-share-android   File: ViewGroupUtilsHoneycomb.java   Source Code and License Vote up 5 votes
static void offsetDescendantMatrix(ViewParent target, View view, Matrix m) {
    final ViewParent parent = view.getParent();
    if (parent instanceof View && parent != target) {
        final View vp = (View) parent;
        offsetDescendantMatrix(target, vp, m);
        m.preTranslate(-vp.getScrollX(), -vp.getScrollY());
    }

    m.preTranslate(view.getLeft(), view.getTop());

    if (!view.getMatrix().isIdentity()) {
        m.preConcat(view.getMatrix());
    }
}
 
Example 15
Project: XERUNG   File: RotateBitmap.java   Source Code and License Vote up 5 votes
public Matrix getRotateMatrix() {
    // By default this is an identity matrix
    Matrix matrix = new Matrix();
    if (bitmap != null && rotation != 0) {
        // We want to do the rotation at origin, but since the bounding
        // rectangle will be changed after rotation, so the delta values
        // are based on old & new width/height respectively.
        int cx = bitmap.getWidth() / 2;
        int cy = bitmap.getHeight() / 2;
        matrix.preTranslate(-cx, -cy);
        matrix.postRotate(rotation);
        matrix.postTranslate(getWidth() / 2, getHeight() / 2);
    }
    return matrix;
}
 
Example 16
Project: fast_face_android   File: OnGetImageListener.java   Source Code and License Vote up 5 votes
private void drawResizedBitmap(final Bitmap src, final Bitmap dst) {

        Display getOrient = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        int orientation = Configuration.ORIENTATION_UNDEFINED;
        Point point = new Point();
        getOrient.getSize(point);
        int screen_width = point.x;
        int screen_height = point.y;
        Log.d(TAG, String.format("screen size (%d,%d)", screen_width, screen_height));
        if (screen_width < screen_height) {
            orientation = Configuration.ORIENTATION_PORTRAIT;
            mScreenRotation = -90;
        } else {
            orientation = Configuration.ORIENTATION_LANDSCAPE;
            mScreenRotation = 0;
        }

        Assert.assertEquals(dst.getWidth(), dst.getHeight());
        final float minDim = Math.min(src.getWidth(), src.getHeight());

        final Matrix matrix = new Matrix();

        // We only want the center square out of the original rectangle.
        final float translateX = -Math.max(0, (src.getWidth() - minDim) / 2);
        final float translateY = -Math.max(0, (src.getHeight() - minDim) / 2);
        matrix.preTranslate(translateX, translateY);

        final float scaleFactor = dst.getHeight() / minDim;
        matrix.postScale(scaleFactor, scaleFactor);

        // Rotate around the center if necessary.
        if (mScreenRotation != 0) {
            matrix.postTranslate(-dst.getWidth() / 2.0f, -dst.getHeight() / 2.0f);
            matrix.postRotate(mScreenRotation);
            matrix.postTranslate(dst.getWidth() / 2.0f, dst.getHeight() / 2.0f);
        }

        final Canvas canvas = new Canvas(dst);
        canvas.drawBitmap(src, matrix, null);
    }
 
Example 17
Project: cwac-crossport   File: ViewGroupUtils.java   Source Code and License Vote up 5 votes
private static void offsetDescendantMatrix(ViewParent target, View view, Matrix m) {
    final ViewParent parent = view.getParent();
    if (parent instanceof View && parent != target) {
        final View vp = (View) parent;
        offsetDescendantMatrix(target, vp, m);
        m.preTranslate(-vp.getScrollX(), -vp.getScrollY());
    }

    m.preTranslate(view.getLeft(), view.getTop());

    if (!view.getMatrix().isIdentity()) {
        m.preConcat(view.getMatrix());
    }
}
 
Example 18
Project: FireFiles   File: ViewGroupUtilsHoneycomb.java   Source Code and License Vote up 5 votes
static void offsetDescendantMatrix(ViewParent target, View view, Matrix m) {
    final ViewParent parent = view.getParent();
    if (parent instanceof View && parent != target) {
        final View vp = (View) parent;
        offsetDescendantMatrix(target, vp, m);
        m.preTranslate(-vp.getScrollX(), -vp.getScrollY());
    }

    m.preTranslate(view.getLeft(), view.getTop());

    if (!view.getMatrix().isIdentity()) {
        m.preConcat(view.getMatrix());
    }
}
 
Example 19
Project: GeekZone   File: AnimUtil.java   Source Code and License Vote up 5 votes
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    final float fromDegrees = mFromDegrees;
    float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);

    final float centerX = mCenterX;
    final float centerY = mCenterY;
    final Camera camera = mCamera;

    final Matrix matrix = t.getMatrix();

    camera.save();
    if (mReverse) {
        camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);
    } else {
        camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));
    }
    if (mRotateX)
        camera.rotateX(degrees);
    else
        camera.rotateY(degrees);
    camera.getMatrix(matrix);
    camera.restore();

    matrix.preTranslate(-centerX, -centerY);
    matrix.postTranslate(centerX, centerY);
}
 
Example 20
Project: RLibrary   File: RotateAnimation.java   Source Code and License Vote up 4 votes
@Override
protected void applyTransformation(float interpolatedTime, Transformation transformation) {
    // interpolatedTime:动画进度值,范围为[0.0f,10.f]
    //L.e("call: applyTransformation-> interpolatedTime:" + interpolatedTime + "\n" + transformation);
    if (listener != null) {
        listener.interpolatedTime(interpolatedTime);
    }
    float from = 0.0f, to = 0.0f;
    if (type == ROTATE_DECREASE) {
        from = 0.0f;
        to = 180.0f;
    } else if (type == ROTATE_INCREASE) {
        from = 360.0f;
        to = 180.0f;
    }
    float degree = from + (to - from) * interpolatedTime;
    boolean overHalf = (interpolatedTime > 0.5f);
    if (overHalf) {
        // 翻转过半的情况下,为保证数字仍为可读的文字而非镜面效果的文字,需翻转180度。
        degree = degree - 180;
    }
    // float depth = 0.0f;
    float depth = (0.5f - Math.abs(interpolatedTime - 0.5f)) * DEPTH_Z;
    //L.e("call: applyTransformation depth:-> " + depth);
    final Matrix matrix = transformation.getMatrix();
    camera.save();
    camera.translate(0.0f, 0.0f, depth);
    //L.e("call: applyTransformation([interpolatedTime, transformation])-> x:" + camera.getLocationX() + " y:" + camera.getLocationY() + " z:" + camera.getLocationZ());\
    if (TextUtils.equals(Build.MANUFACTURER, "HUAWEI") &&
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP /*华为手机处理圆角, 偶尔会失败.*/) {
        camera.setLocation(0, 0, -160);
    }
    camera.rotateY(degree);
    camera.getMatrix(matrix);
    camera.restore();
    if (DEBUG) {
        if (overHalf) {
            matrix.preTranslate(-centerX * 2, -centerY);
            matrix.postTranslate(centerX * 2, centerY);
        }
    } else {
        //确保图片的翻转过程一直处于组件的中心点位置
        matrix.preTranslate(-centerX, -centerY);
        matrix.postTranslate(centerX, centerY);
    }
}