Search in sources :

Example 16 with Camera

use of android.graphics.Camera in project Anki-Android by Ramblurr.

the class Animation3D method initialize.

@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
    super.initialize(width, height, parentWidth, parentHeight);
    mCamera = new Camera();
}
Also used : Camera(android.graphics.Camera)

Example 17 with Camera

use of android.graphics.Camera in project folding-cell-android by Ramotion.

the class FoldAnimation method initialize.

@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
    super.initialize(width, height, parentWidth, parentHeight);
    this.mCamera = new Camera();
    mCamera.setLocation(0, 0, -mCameraHeight);
    this.mCenterX = width / 2;
    switch(mFoldMode) {
        case FOLD_UP:
            this.mCenterY = 0;
            this.mFromDegrees = 0;
            this.mToDegrees = 90;
            break;
        case FOLD_DOWN:
            this.mCenterY = height;
            this.mFromDegrees = 0;
            this.mToDegrees = -90;
            break;
        case UNFOLD_UP:
            this.mCenterY = height;
            this.mFromDegrees = -90;
            this.mToDegrees = 0;
            break;
        case UNFOLD_DOWN:
            this.mCenterY = 0;
            this.mFromDegrees = 90;
            this.mToDegrees = 0;
            break;
        default:
            throw new IllegalStateException("Unknown animation mode.");
    }
}
Also used : Camera(android.graphics.Camera)

Example 18 with Camera

use of android.graphics.Camera in project folding-cell-android by Ramotion.

the class FoldAnimation method applyTransformation.

@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    final Camera camera = mCamera;
    final Matrix matrix = t.getMatrix();
    final float fromDegrees = mFromDegrees;
    final float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);
    camera.save();
    camera.rotateX(degrees);
    camera.getMatrix(matrix);
    camera.restore();
    matrix.preTranslate(-mCenterX, -mCenterY);
    matrix.postTranslate(mCenterX, mCenterY);
}
Also used : Matrix(android.graphics.Matrix) Camera(android.graphics.Camera)

Example 19 with Camera

use of android.graphics.Camera in project mobile-android by photo.

the class AdjustImageView method flipTo.

/**
	 * Flip to.
	 * 
	 * @param horizontal
	 *           the horizontal
	 * @param durationMs
	 *           the duration ms
	 */
protected void flipTo(final boolean horizontal, final int durationMs) {
    if (mRunning) {
        return;
    }
    mRunning = true;
    final long startTime = System.currentTimeMillis();
    final int vwidth = getWidth() - getPaddingLeft() - getPaddingRight();
    final int vheight = getHeight() - getPaddingTop() - getPaddingBottom();
    final float centerx = vwidth / 2;
    final float centery = vheight / 2;
    final Camera camera = new Camera();
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            long now = System.currentTimeMillis();
            double currentMs = Math.min(durationMs, now - startTime);
            if (mCameraEnabled) {
                float degrees = (float) (0 + ((-180 - 0) * (currentMs / durationMs)));
                camera.save();
                if (horizontal) {
                    camera.rotateY(degrees);
                } else {
                    camera.rotateX(degrees);
                }
                camera.getMatrix(mFlipMatrix);
                camera.restore();
                mFlipMatrix.preTranslate(-centerx, -centery);
                mFlipMatrix.postTranslate(centerx, centery);
            } else {
                double new_scale = mEasing.easeInOut(currentMs, 1, -2, durationMs);
                if (horizontal)
                    mFlipMatrix.setScale((float) new_scale, 1, centerx, centery);
                else
                    mFlipMatrix.setScale(1, (float) new_scale, centerx, centery);
            }
            invalidate();
            if (currentMs < durationMs) {
                mHandler.post(this);
            } else {
                if (horizontal) {
                    mFlipType ^= FlipType.FLIP_HORIZONTAL.nativeInt;
                    mDrawMatrix.postScale(-1, 1, centerx, centery);
                } else {
                    mFlipType ^= FlipType.FLIP_VERTICAL.nativeInt;
                    mDrawMatrix.postScale(1, -1, centerx, centery);
                }
                // Problem is HERE!
                mRotateMatrix.postRotate((float) (-mRotation * 2), centerx, centery);
                mRotation = Point2D.angle360(getRotationFromMatrix(mRotateMatrix));
                mFlipMatrix.reset();
                invalidate();
                printDetails();
                mRunning = false;
                if (isReset) {
                    onReset();
                }
            }
        }
    });
    if (straightenStarted && !isReset) {
        initStraighten = true;
        resetStraighten();
        invalidate();
    }
}
Also used : Camera(android.graphics.Camera) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Example 20 with Camera

use of android.graphics.Camera in project mobile-android by photo.

the class AdjustImageViewFreeRotation method flipTo.

/**
	 * Flip to.
	 * 
	 * @param horizontal
	 *           the horizontal
	 * @param durationMs
	 *           the duration ms
	 */
protected void flipTo(final boolean horizontal, final int durationMs) {
    if (mRunning) {
        return;
    }
    mRunning = true;
    final long startTime = System.currentTimeMillis();
    final int vwidth = getWidth() - getPaddingLeft() - getPaddingRight();
    final int vheight = getHeight() - getPaddingTop() - getPaddingBottom();
    final float centerx = vwidth / 2;
    final float centery = vheight / 2;
    final Camera camera = new Camera();
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            long now = System.currentTimeMillis();
            double currentMs = Math.min(durationMs, now - startTime);
            if (mCameraEnabled) {
                float degrees = (float) (0 + ((-180 - 0) * (currentMs / durationMs)));
                camera.save();
                if (horizontal) {
                    camera.rotateY(degrees);
                } else {
                    camera.rotateX(degrees);
                }
                camera.getMatrix(mFlipMatrix);
                camera.restore();
                mFlipMatrix.preTranslate(-centerx, -centery);
                mFlipMatrix.postTranslate(centerx, centery);
            } else {
                double new_scale = mEasing.easeInOut(currentMs, 1, -2, durationMs);
                if (horizontal)
                    mFlipMatrix.setScale((float) new_scale, 1, centerx, centery);
                else
                    mFlipMatrix.setScale(1, (float) new_scale, centerx, centery);
            }
            invalidate();
            if (currentMs < durationMs) {
                mHandler.post(this);
            } else {
                if (horizontal) {
                    mFlipType ^= FlipType.FLIP_HORIZONTAL.nativeInt;
                    mDrawMatrix.postScale(-1, 1, centerx, centery);
                } else {
                    mFlipType ^= FlipType.FLIP_VERTICAL.nativeInt;
                    mDrawMatrix.postScale(1, -1, centerx, centery);
                }
                mRotateMatrix.postRotate((float) (-mRotation * 2), centerx, centery);
                mRotation = Point2D.angle360(getRotationFromMatrix(mRotateMatrix));
                mFlipMatrix.reset();
                invalidate();
                printDetails();
                mRunning = false;
                if (isReset) {
                    onReset();
                }
            }
        }
    });
}
Also used : Camera(android.graphics.Camera) Paint(android.graphics.Paint)

Aggregations

Camera (android.graphics.Camera)30 Matrix (android.graphics.Matrix)11 Paint (android.graphics.Paint)3 SuppressLint (android.annotation.SuppressLint)1 Point (android.graphics.Point)1 Transformation (android.view.animation.Transformation)1 Scroller (android.widget.Scroller)1