Example usage for android.view View setRotation

List of usage examples for android.view View setRotation

Introduction

In this page you can find the example usage for android.view View setRotation.

Prototype

public void setRotation(float rotation) 

Source Link

Document

Sets the degrees that the view is rotated around the pivot point.

Usage

From source file:Main.java

public static void rotateView(@NonNull View rotatedView) {
    int w = rotatedView.getWidth(), h = rotatedView.getHeight();
    int diff = w / 2 - h / 2;
    rotatedView.setRotation(270);
    rotatedView.setTranslationX(-diff);//from ww  w .ja  v a2 s.com
}

From source file:Main.java

public static void rotate(final View view, float fromDegrees, float toDegrees, long duration) {
    if (Build.VERSION.SDK_INT >= 12) {
        if (duration == 0)
            view.setRotation(toDegrees);
        else/*from   w  ww.j  a v  a2 s  . co  m*/
            view.animate().rotation(toDegrees).setDuration(duration).start();
    } else {
        RotateAnimation rotate = new RotateAnimation(fromDegrees, toDegrees, Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f);
        rotate.setDuration(duration);
        rotate.setFillEnabled(true);
        rotate.setFillBefore(true);
        rotate.setFillAfter(true);
        addAnimation(view, rotate);
    }
}

From source file:com.facebook.react.uimanager.BaseViewManager.java

private static void resetTransformProperty(View view) {
    view.setTranslationX(PixelUtil.toPixelFromDIP(0));
    view.setTranslationY(PixelUtil.toPixelFromDIP(0));
    view.setRotation(0);
    view.setRotationX(0);//from   ww  w  .j  ava2  s .  co  m
    view.setRotationY(0);
    view.setScaleX(1);
    view.setScaleY(1);
    view.setCameraDistance(0);
}

From source file:com.facebook.react.uimanager.BaseViewManager.java

private static void setTransformProperty(View view, ReadableArray transforms) {
    TransformHelper.processTransform(transforms, sTransformDecompositionArray);
    MatrixMathHelper.decomposeMatrix(sTransformDecompositionArray, sMatrixDecompositionContext);
    view.setTranslationX(PixelUtil.toPixelFromDIP((float) sMatrixDecompositionContext.translation[0]));
    view.setTranslationY(PixelUtil.toPixelFromDIP((float) sMatrixDecompositionContext.translation[1]));
    view.setRotation((float) sMatrixDecompositionContext.rotationDegrees[2]);
    view.setRotationX((float) sMatrixDecompositionContext.rotationDegrees[0]);
    view.setRotationY((float) sMatrixDecompositionContext.rotationDegrees[1]);
    view.setScaleX((float) sMatrixDecompositionContext.scale[0]);
    view.setScaleY((float) sMatrixDecompositionContext.scale[1]);

    double[] perspectiveArray = sMatrixDecompositionContext.perspective;

    if (perspectiveArray.length > PERSPECTIVE_ARRAY_INVERTED_CAMERA_DISTANCE_INDEX) {
        float invertedCameraDistance = (float) perspectiveArray[PERSPECTIVE_ARRAY_INVERTED_CAMERA_DISTANCE_INDEX];
        if (invertedCameraDistance == 0) {
            // Default camera distance, before scale multiplier (1280)
            invertedCameraDistance = 0.00078125f;
        }// ww  w .j  ava 2 s.  c  o m
        float cameraDistance = -1 / invertedCameraDistance;
        float scale = DisplayMetricsHolder.getScreenDisplayMetrics().density;

        // The following converts the matrix's perspective to a camera distance
        // such that the camera perspective looks the same on Android and iOS.
        // The native Android implementation removed the screen density from the
        // calculation, so squaring and a normalization value of
        // sqrt(5) produces an exact replica with iOS.
        // For more information, see https://github.com/facebook/react-native/pull/18302
        float normalizedCameraDistance = scale * scale * cameraDistance
                * CAMERA_DISTANCE_NORMALIZATION_MULTIPLIER;
        view.setCameraDistance(normalizedCameraDistance);

    }
}

From source file:android.support.transition.ChangeTransform.java

private static void setTransforms(View view, float translationX, float translationY, float translationZ,
        float scaleX, float scaleY, float rotationX, float rotationY, float rotationZ) {
    view.setTranslationX(translationX);/*from  w  ww  .j a v a 2 s  . c  o  m*/
    view.setTranslationY(translationY);
    ViewCompat.setTranslationZ(view, translationZ);
    view.setScaleX(scaleX);
    view.setScaleY(scaleY);
    view.setRotationX(rotationX);
    view.setRotationY(rotationY);
    view.setRotation(rotationZ);
}

From source file:com.aran.bang.widget.BaseTransformer.java

/**
 * Called each {@link #transformPage(View, float)} before {{@link #onTransform(View, float)} is called.
 *
 * @param view/*from  w w  w . jav  a 2  s .co  m*/
 * @param position
 */
protected void onPreTransform(View view, float position) {
    final float width = view.getWidth();

    view.setRotationX(0);
    view.setRotationY(0);
    view.setRotation(0);
    view.setScaleX(1);
    view.setScaleY(1);
    view.setPivotX(0);
    view.setPivotY(0);
    view.setTranslationY(0);
    view.setTranslationX(isPagingEnabled() ? 0f : -width * position);

    if (hideOffscreenPages()) {
        view.setAlpha(position <= -1f || position >= 1f ? 0f : 1f);
    } else {
        view.setAlpha(1f);
    }
}

From source file:pl.hypeapp.wykopolka.extra.pagetransformer.BaseTransformer.java

/**
 * Called each {@link #transformPage(android.view.View, float)} before {{@link #onTransform(android.view.View, float)} is called.
 *
 * @param view/*w ww .j av a2s .co  m*/
 * @param position
 */
protected void onPreTransform(View view, float position) {
    final float width = view.getWidth();

    view.setRotationX(0);
    view.setRotationY(0);
    view.setRotation(0);
    view.setScaleX(1);
    view.setScaleY(1);
    view.setPivotX(0);
    view.setPivotY(0);
    view.setTranslationY(0);
    if (isPagingEnabled())
        view.setTranslationX(0f);
    else
        view.setTranslationX(-width * position);

    if (hideOffscreenPages()) {
        view.setAlpha(position <= -1f || position >= 1f ? 0f : 1f);
    } else {
        view.setAlpha(1f);
    }
}

From source file:com.cesards.samples.cropimageview.ABaseTransformer.java

/**
 * Called each {@link #transformPage(android.view.View, float)} before {{@link #onTransform(android.view.View,
 * float)}.//ww w  .j  a  v a 2  s  .c o  m
 * <p>
 * The default implementation attempts to reset all view properties. This is useful when toggling transforms that do
 * not modify the same page properties. For instance changing from a transformation that applies rotation to a
 * transformation that fades can inadvertently leave a fragment stuck with a rotation or with some degree of applied
 * alpha.
 *
 * @param page Apply the transformation to this page
 * @param position Position of page relative to the current front-and-center position of the pager. 0 is front and
 * center. 1 is one full page position to the right, and -1 is one page position to the left.
 */
protected void onPreTransform(View page, float position) {
    final float width = page.getWidth();

    page.setRotationX(0);
    page.setRotationY(0);
    page.setRotation(0);
    page.setScaleX(1);
    page.setScaleY(1);
    page.setPivotX(0);
    page.setPivotY(0);
    page.setTranslationY(0);
    page.setTranslationX(isPagingEnabled() ? 0f : -width * position);

    if (hideOffscreenPages()) {
        page.setAlpha(position <= -1f || position >= 1f ? 0f : 1f);
    } else {
        page.setAlpha(1f);
    }
}

From source file:com.wuzhanglao.niubi.utils.transformer.BaseTransformer.java

/**
 * Called each {@link #transformPage(android.view.View, float)} before {{@link #onTransform(android.view.View, float)}.
 * <p>/* ww  w . j  a va2  s .c om*/
 * The default implementation attempts to reset all view properties. This is useful when toggling transforms that do
 * not modify the same page properties. For instance changing from a transformation that applies rotation to a
 * transformation that fades can inadvertently leave a fragment stuck with a rotation or with some degree of applied
 * alpha.
 *
 * @param page     Apply the transformation to this page
 * @param position Position of page relative to the current front-and-center position of the pager. 0 is front and
 *                 center. 1 is one full page position to the right, and -1 is one page position to the left.
 */
protected void onPreTransform(View page, float position) {
    final float width = page.getWidth();

    page.setRotationX(0);
    page.setRotationY(0);
    page.setRotation(0);
    page.setScaleX(1);
    page.setScaleY(1);
    page.setPivotX(0);
    page.setPivotY(0);
    page.setTranslationY(0);
    if (isPagingEnabled())
        page.setTranslationX(0f);
    else
        page.setTranslationX(-width * position);

    if (hideOffscreenPages()) {
        page.setAlpha(position <= -1f || position >= 1f ? 0f : 1f);
        page.setEnabled(false);
    } else {
        page.setEnabled(true);
        page.setAlpha(1f);
    }
}

From source file:banner.transformer.ABaseTransformer.java

/**
 * Called each {@link #transformPage(View, float)} before {{@link #onTransform(View, float)}.
 * <p>//w  w  w .j a  va 2s.com
 * The default implementation attempts to reset all view properties. This is useful when toggling transforms that do
 * not modify the same page properties. For instance changing from a transformation that applies rotation to a
 * transformation that fades can inadvertently leave a fragment stuck with a rotation or with some degree of applied
 * alpha.
 *
 * @param page
 *            Apply the transformation to this page
 * @param position
 *            Position of page relative to the current front-and-center position of the pager. 0 is front and
 *            center. 1 is one full page position to the right, and -1 is one page position to the left.
 */
protected void onPreTransform(View page, float position) {
    final float width = page.getWidth();

    page.setRotationX(0);
    page.setRotationY(0);
    page.setRotation(0);
    page.setScaleX(1);
    page.setScaleY(1);
    page.setPivotX(0);
    page.setPivotY(0);
    page.setTranslationY(0);
    page.setTranslationX(isPagingEnabled() ? 0f : -width * position);

    if (hideOffscreenPages()) {
        page.setAlpha(position <= -1f || position >= 1f ? 0f : 1f);
        //         page.setEnabled(false);
    } else {
        //         page.setEnabled(true);
        page.setAlpha(1f);
    }
}