Example usage for android.view View TRANSLATION_Y

List of usage examples for android.view View TRANSLATION_Y

Introduction

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

Prototype

Property TRANSLATION_Y

To view the source code for android.view View TRANSLATION_Y.

Click Source Link

Document

A Property wrapper around the translationY functionality handled by the View#setTranslationY(float) and View#getTranslationY() methods.

Usage

From source file:com.klinker.android.sliding.MultiShrinkScroller.java

public void runExpansionAnimation() {

    final Interpolator interpolator;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        interpolator = AnimationUtils.loadInterpolator(getContext(), android.R.interpolator.linear_out_slow_in);
    } else {/* ww  w .  j  a  va 2s.co  m*/
        interpolator = new DecelerateInterpolator();
    }

    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int screenHeight = size.y;
    int screenWidth = size.x;

    final ValueAnimator heightExpansion = ValueAnimator.ofInt(expansionViewHeight, getHeight());
    heightExpansion.setInterpolator(interpolator);
    heightExpansion.setDuration(ANIMATION_DURATION);
    heightExpansion.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int val = (int) animation.getAnimatedValue();

            ViewGroup.LayoutParams params = getLayoutParams();
            params.height = val;
            setLayoutParams(params);
        }
    });
    heightExpansion.start();

    final ValueAnimator widthExpansion = ValueAnimator.ofInt(expansionViewWidth, getWidth());
    widthExpansion.setInterpolator(interpolator);
    widthExpansion.setDuration(ANIMATION_DURATION);
    widthExpansion.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int val = (int) animation.getAnimatedValue();

            ViewGroup.LayoutParams params = getLayoutParams();
            params.width = val;
            setLayoutParams(params);
        }
    });
    widthExpansion.start();

    ObjectAnimator translationX = ObjectAnimator.ofFloat(this, View.TRANSLATION_X, expansionLeftOffset, 0f);
    translationX.setInterpolator(interpolator);
    translationX.setDuration(ANIMATION_DURATION);
    translationX.start();

    ObjectAnimator translationY = ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, expansionTopOffset, 0f);
    translationY.setInterpolator(interpolator);
    translationY.setDuration(ANIMATION_DURATION);
    translationY.start();
}

From source file:com.android.calculator2.Calculator.java

private void onResult(boolean animate) {
    // Calculate the textSize that would be used to display the result in the formula.
    // For scrollable results just use the minimum textSize to maximize the number of digits
    // that are visible on screen.
    float textSize = mFormulaText.getMinimumTextSize();
    if (!mResultText.isScrollable()) {
        textSize = mFormulaText.getVariableTextSize(mResultText.getText().toString());
    }// w  w  w .  jav  a2s  . c o  m

    // Scale the result to match the calculated textSize, minimizing the jump-cut transition
    // when a result is reused in a subsequent expression.
    final float resultScale = textSize / mResultText.getTextSize();

    // Set the result's pivot to match its gravity.
    mResultText.setPivotX(mResultText.getWidth() - mResultText.getPaddingRight());
    mResultText.setPivotY(mResultText.getHeight() - mResultText.getPaddingBottom());

    // Calculate the necessary translations so the result takes the place of the formula and
    // the formula moves off the top of the screen.
    final float resultTranslationY = (mFormulaText.getBottom() - mResultText.getBottom())
            - (mFormulaText.getPaddingBottom() - mResultText.getPaddingBottom());
    final float formulaTranslationY = -mFormulaText.getBottom();

    // Change the result's textColor to match the formula.
    final int formulaTextColor = mFormulaText.getCurrentTextColor();

    if (animate) {
        mResultText.announceForAccessibility(getResources().getString(R.string.desc_eq));
        mResultText.announceForAccessibility(mResultText.getText());
        setState(CalculatorState.ANIMATE);
        final AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(
                ObjectAnimator.ofPropertyValuesHolder(mResultText,
                        PropertyValuesHolder.ofFloat(View.SCALE_X, resultScale),
                        PropertyValuesHolder.ofFloat(View.SCALE_Y, resultScale),
                        PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, resultTranslationY)),
                ObjectAnimator.ofArgb(mResultText, TEXT_COLOR, formulaTextColor),
                ObjectAnimator.ofFloat(mFormulaText, View.TRANSLATION_Y, formulaTranslationY));
        animatorSet.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));
        animatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                setState(CalculatorState.RESULT);
                mCurrentAnimator = null;
            }
        });

        mCurrentAnimator = animatorSet;
        animatorSet.start();
    } else /* No animation desired; get there fast, e.g. when restarting */ {
        mResultText.setScaleX(resultScale);
        mResultText.setScaleY(resultScale);
        mResultText.setTranslationY(resultTranslationY);
        mResultText.setTextColor(formulaTextColor);
        mFormulaText.setTranslationY(formulaTranslationY);
        setState(CalculatorState.RESULT);
    }
}

From source file:com.klinker.android.sliding.MultiShrinkScroller.java

public void reverseExpansionAnimation() {

    final Interpolator interpolator;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        interpolator = AnimationUtils.loadInterpolator(getContext(), android.R.interpolator.linear_out_slow_in);
    } else {/* ww w.ja v a2 s .  c  om*/
        interpolator = new DecelerateInterpolator();
    }

    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int screenHeight = size.y;
    int screenWidth = size.x;

    final ValueAnimator heightExpansion = ValueAnimator.ofInt(screenHeight, expansionViewHeight);
    heightExpansion.setInterpolator(interpolator);
    heightExpansion.setDuration(ANIMATION_DURATION);
    heightExpansion.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int val = (int) animation.getAnimatedValue();

            ViewGroup.LayoutParams params = getLayoutParams();
            params.height = val;
            setLayoutParams(params);
        }
    });
    heightExpansion.start();

    final ValueAnimator widthExpansion = ValueAnimator.ofInt(getWidth(), expansionViewWidth);
    widthExpansion.setInterpolator(interpolator);
    widthExpansion.setDuration(ANIMATION_DURATION);
    widthExpansion.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int val = (int) animation.getAnimatedValue();

            ViewGroup.LayoutParams params = getLayoutParams();
            params.width = val;
            setLayoutParams(params);
        }
    });
    widthExpansion.start();

    ObjectAnimator translationX = ObjectAnimator.ofFloat(this, View.TRANSLATION_X, 0f, expansionLeftOffset);
    translationX.setInterpolator(interpolator);
    translationX.setDuration(ANIMATION_DURATION);
    translationX.start();

    ObjectAnimator translationY = ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, 0f, expansionTopOffset);
    translationY.setInterpolator(interpolator);
    translationY.setDuration(ANIMATION_DURATION);
    translationY.addListener(exitAnimationListner);
    translationY.start();
}

From source file:com.android.tv.menu.MenuLayoutManager.java

private ObjectAnimator createTranslationYAnimator(View view, float from, float to) {
    ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.TRANSLATION_Y, from, to);
    animator.setDuration(mRowAnimationDuration);
    animator.setInterpolator(mFastOutSlowIn);
    mPropertyValuesAfterAnimation.add(new ViewPropertyValueHolder(View.TRANSLATION_Y, view, 0));
    return animator;
}

From source file:com.waz.zclient.pages.main.participants.ParticipantFragment.java

@Override
public void onHidePickUser(IPickUserController.Destination destination, boolean closeWithoutSelectingPeople) {
    if (LayoutSpec.isPhone(getActivity())) {
        return;/* w w w  . j a  v a  2  s .  c o  m*/
    }
    if (!destination.equals(getCurrentPickerDestination())) {
        return;
    }
    // Workaround for animation bug with nested child fragments
    // Animating fragment container views and then popping stack at end of animation

    int showParticipantsDelay = getResources().getInteger(R.integer.framework_animation_delay_long);
    int hidePickUserAnimDuration = getResources().getInteger(R.integer.framework_animation_duration_medium);
    TimeInterpolator hidePickUserInterpolator = new Expo.EaseIn();
    ObjectAnimator hidePickUserAnimator;
    // Fade animation in participants dialog on tablet
    if (LayoutSpec.isTablet(getActivity())) {
        hidePickUserAnimator = ObjectAnimator.ofFloat(pickUserContainerView, View.ALPHA, 1f, 0f);
        hidePickUserAnimator.setInterpolator(new Linear.EaseIn());

    } else {
        hidePickUserAnimator = ObjectAnimator.ofFloat(pickUserContainerView, View.TRANSLATION_Y, 0f,
                pickUserContainerView.getMeasuredHeight());
        hidePickUserAnimator.setInterpolator(hidePickUserInterpolator);
        hidePickUserAnimator.setDuration(hidePickUserAnimDuration);
    }
    hidePickUserAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (!isResumed()) {
                return;
            }
            getChildFragmentManager().popBackStackImmediate(PickUserFragment.TAG,
                    FragmentManager.POP_BACK_STACK_INCLUSIVE);

            if (LayoutSpec.isTablet(getActivity())) {
                // Reset for fade animation in participants dialog on tablet
                pickUserContainerView.setAlpha(1f);
            } else {
                pickUserContainerView.setTranslationY(0f);
            }
        }
    });

    participantsContainerView.setAlpha(0);
    participantsContainerView.setVisibility(View.VISIBLE);
    ObjectAnimator showParticipantsAnimator = ObjectAnimator.ofFloat(participantsContainerView, View.ALPHA, 0f,
            1f);
    showParticipantsAnimator.setInterpolator(new Quart.EaseOut());
    showParticipantsAnimator
            .setDuration(getResources().getInteger(R.integer.framework_animation_duration_medium));
    showParticipantsAnimator.setStartDelay(showParticipantsDelay);

    AnimatorSet hideSet = new AnimatorSet();
    hideSet.playTogether(hidePickUserAnimator, showParticipantsAnimator);
    hideSet.start();

    if (LayoutSpec.isPhone(getActivity()) && getControllerFactory().getNavigationController()
            .getPagerPosition() == NavigationController.SECOND_PAGE) {
        // TODO: https://wearezeta.atlassian.net/browse/AN-3081
        if (getControllerFactory().getConversationScreenController().isShowingParticipant()) {
            getControllerFactory().getNavigationController().setRightPage(Page.PARTICIPANT, TAG);
        } else {
            getControllerFactory().getNavigationController().setRightPage(Page.MESSAGE_STREAM, TAG);
        }
    }
}

From source file:com.stanleyidesis.quotograph.ui.activity.LWQSettingsActivity.java

Animator generateAnimator(View target, boolean dismiss, long startDelay) {
    float[] fadeIn = new float[] { 0f, 1f };
    float[] fadeOut = new float[] { 1f, 0f };
    final ObjectAnimator propAnimator = ObjectAnimator.ofPropertyValuesHolder(target,
            PropertyValuesHolder.ofFloat(View.ALPHA, dismiss ? fadeOut : fadeIn),
            PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, dismiss ? (target.getHeight() * 2f) : 0f));
    propAnimator.setStartDelay(startDelay);
    propAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
    propAnimator.setDuration(240);//  w  w w .j a  va  2s  .  com
    return propAnimator;
}

From source file:org.chromium.chrome.browser.toolbar.ToolbarPhone.java

private ObjectAnimator createPostExitTabSwitcherAnimation() {
    ObjectAnimator exitAnimation = ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, -getHeight(), 0.f);
    exitAnimation.setDuration(TAB_SWITCHER_MODE_POST_EXIT_ANIMATION_DURATION_MS);
    exitAnimation.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
    exitAnimation.addListener(new AnimatorListenerAdapter() {
        @Override//w w w.java  2 s  .co m
        public void onAnimationStart(Animator animation) {
            updateViewsForTabSwitcherMode();
            // On older builds, force an update to ensure the new visuals are used
            // when bringing in the toolbar.  crbug.com/404571
            if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN) {
                requestLayout();
            }
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mDelayedTabSwitcherModeAnimation = null;
            updateShadowVisibility();
            updateViewsForTabSwitcherMode();
        }
    });

    return exitAnimation;
}