Example usage for android.view View setCameraDistance

List of usage examples for android.view View setCameraDistance

Introduction

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

Prototype

public void setCameraDistance(float distance) 

Source Link

Document

Sets the distance along the Z axis (orthogonal to the X/Y plane on which views are drawn) from the camera to this view.

Usage

From source file:Main.java

public static void spinForever(View view, int cameraDistance, int duration) {
    view.setCameraDistance(cameraDistance);

    ObjectAnimator animator = ObjectAnimator.ofFloat(view, "rotationY", 0.0f, 360.0f);
    animator.setRepeatMode(ObjectAnimator.REVERSE);
    animator.setRepeatCount(ObjectAnimator.INFINITE);
    animator.setDuration(duration);/*from  w w  w  .j  a v a2 s . c o m*/
    animator.start();
}

From source file:Main.java

public static void spinOnceX(View view, int cameraDistance, int duration, boolean forward) {
    view.setCameraDistance(cameraDistance);

    ObjectAnimator animator = ObjectAnimator.ofFloat(view, "rotationX", 0.0f, forward ? 360.0f : -360.0f);
    animator.setRepeatMode(ObjectAnimator.REVERSE);
    animator.setDuration(duration);/* w  w w  .ja  v  a  2  s  . c om*/
    animator.start();
}

From source file:Main.java

private static void changeCameraDistance(final Context context, final View view) {
    float scale = context.getResources().getDisplayMetrics().density * CAMERA_DISTANCE;
    view.setCameraDistance(scale);
}

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);//from  w  w  w. ja v  a  2 s. com
    view.setRotationX(0);
    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;
        }/*from  ww  w.j  a v  a  2 s.com*/
        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:com.phonemetra.turbo.launcher.AsyncTaskCallback.java

@Override
protected void screenScrolled(int screenCenter) {
    final boolean isRtl = isLayoutRtl();

    mUseTransitionEffect = !isInOverviewMode() && !mIsSwitchingState;

    updatePageAlphaValues(screenCenter);

    super.screenScrolled(screenCenter);

    enableHwLayersOnVisiblePages();/*from  w w  w  .j a  va2 s.  c  o m*/

    boolean isInOverscroll = mOverScrollX < 0 || mOverScrollX > mMaxScrollX;

    if (isInOverscroll) {
        int index = 0;
        float pivotX = 0f;
        final float leftBiasedPivot = 0.35f;
        final float rightBiasedPivot = 0.65f;
        final int lowerIndex = 0;
        final int upperIndex = getChildCount() - 1;

        final boolean isLeftPage = mOverScrollX < 0;
        index = (!isRtl && isLeftPage) || (isRtl && !isLeftPage) ? lowerIndex : upperIndex;
        pivotX = isLeftPage ? rightBiasedPivot : leftBiasedPivot;

        View v = getPageAt(index);

        if (!mOverscrollTransformsSet || Float.compare(mLastOverscrollPivotX, pivotX) != 0) {
            mOverscrollTransformsSet = true;
            mLastOverscrollPivotX = pivotX;
            v.setCameraDistance(mDensity * mCameraDistance);
            v.setPivotX(v.getMeasuredWidth() * pivotX);
        }

        float scrollProgress = getScrollProgress(screenCenter, v, index);
        float rotation = -TRANSITION_MAX_ROTATION * scrollProgress;
        v.setRotationY(rotation);
    } else {
        if (mOverscrollTransformsSet) {
            mOverscrollTransformsSet = false;
            View v0 = getPageAt(mCurrentPage);
            v0.setRotationY(0);
            v0.setCameraDistance(mDensity * mCameraDistance);
            v0.setPivotX(v0.getMeasuredWidth() / 2);
            v0.setPivotY(v0.getMeasuredHeight() / 2);
        }
    }
}

From source file:com.android.launcher2.AsyncTaskCallback.java

@Override
protected void screenScrolled(int screenCenter) {
    super.screenScrolled(screenCenter);

    for (int i = 0; i < getChildCount(); i++) {
        View v = getPageAt(i);
        if (v != null) {
            float scrollProgress = getScrollProgress(screenCenter, v, i);

            float interpolatedProgress = mZInterpolator.getInterpolation(Math.abs(Math.min(scrollProgress, 0)));
            float scale = (1 - interpolatedProgress) + interpolatedProgress * TRANSITION_SCALE_FACTOR;
            float translationX = Math.min(0, scrollProgress) * v.getMeasuredWidth();

            float alpha;

            if (scrollProgress < 0) {
                alpha = scrollProgress < 0 ? mAlphaInterpolator.getInterpolation(1 - Math.abs(scrollProgress))
                        : 1.0f;//from www . ja  v  a 2s. c o  m
            } else {
                // On large screens we need to fade the page as it nears its leftmost position
                alpha = mLeftScreenAlphaInterpolator.getInterpolation(1 - scrollProgress);
            }

            v.setCameraDistance(mDensity * CAMERA_DISTANCE);
            int pageWidth = v.getMeasuredWidth();
            int pageHeight = v.getMeasuredHeight();

            if (PERFORM_OVERSCROLL_ROTATION) {
                if (i == 0 && scrollProgress < 0) {
                    // Overscroll to the left
                    v.setPivotX(TRANSITION_PIVOT * pageWidth);
                    v.setRotationY(-TRANSITION_MAX_ROTATION * scrollProgress);
                    scale = 1.0f;
                    alpha = 1.0f;
                    // On the first page, we don't want the page to have any lateral motion
                    translationX = 0;
                } else if (i == getChildCount() - 1 && scrollProgress > 0) {
                    // Overscroll to the right
                    v.setPivotX((1 - TRANSITION_PIVOT) * pageWidth);
                    v.setRotationY(-TRANSITION_MAX_ROTATION * scrollProgress);
                    scale = 1.0f;
                    alpha = 1.0f;
                    // On the last page, we don't want the page to have any lateral motion.
                    translationX = 0;
                } else {
                    v.setPivotY(pageHeight / 2.0f);
                    v.setPivotX(pageWidth / 2.0f);
                    v.setRotationY(0f);
                }
            }

            v.setTranslationX(translationX);
            v.setScaleX(scale);
            v.setScaleY(scale);
            v.setAlpha(alpha);

            // If the view has 0 alpha, we set it to be invisible so as to prevent
            // it from accepting touches
            if (alpha == 0) {
                v.setVisibility(INVISIBLE);
            } else if (v.getVisibility() != VISIBLE) {
                v.setVisibility(VISIBLE);
            }
        }
    }
}

From source file:us.shandian.launcher.Page.java

protected void screenScrolled(int screenCenter) {
    boolean isInOverscroll = mOverScrollX < 0 || mOverScrollX > mMaxScrollX;

    if (mFadeInAdjacentScreens || mTransitionEffect != null || mScrollTransformsSet) {
        for (int i = 0; i < getChildCount(); i++) {
            View v = getPageAt(i);
            if (v != null) {
                float scrollProgress = getScrollProgress(screenCenter, v, i);

                if (Math.abs(scrollProgress) >= 1f) {
                    v.setCameraDistance(0);
                }/* w w  w .  j  a v a  2  s  .  c  o m*/

                if (mTransitionEffect != null && !isInOverscroll) {
                    mTransitionEffect.screenScrolled(v, i, scrollProgress);
                } else if (mScrollTransformsSet) {
                    v.setPivotX(v.getMeasuredWidth() * 0.5f);
                    v.setPivotY(v.getMeasuredHeight() * 0.5f);
                    v.setRotation(0);
                    v.setRotationX(0);
                    v.setRotationY(0);
                    v.setScaleX(1f);
                    v.setScaleY(1f);
                    v.setTranslationX(0f);
                    v.setTranslationY(0f);
                    v.setVisibility(VISIBLE);
                    setChildAlpha(v, 1f);
                }
            }
        }
        mScrollTransformsSet = mTransitionEffect != null && !isInOverscroll;
    }
}