Example usage for android.view View TRANSLATION_X

List of usage examples for android.view View TRANSLATION_X

Introduction

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

Prototype

Property TRANSLATION_X

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

Click Source Link

Document

A Property wrapper around the translationX functionality handled by the View#setTranslationX(float) and View#getTranslationX() methods.

Usage

From source file:com.pitchedapps.primenumbercalculator.Calculator.java

License:asdf

private void onResult(final String result) {
    // Calculate the values needed to perform the scale and translation animations,
    // accounting for how the scale will affect the final position of the text.
    final float resultScale = mInputEditText.getVariableTextSize(result) / mResultEditText.getTextSize();
    final float resultTranslationX = (1.0f - resultScale)
            * (mResultEditText.getWidth() / 2.0f - mResultEditText.getPaddingEnd());
    final float resultTranslationY = (1.0f - resultScale) * //TODO delete unnecessary lines for animation
            (mResultEditText.getHeight() / 2.0f - mResultEditText.getPaddingBottom())
            + (mInputEditText.getBottom() - mResultEditText.getBottom())
            + (mResultEditText.getPaddingBottom() - mInputEditText.getPaddingBottom());
    final float inputTranslationY = -mInputEditText.getBottom();

    // Use a value animator to fade to the final text color over the course of the animation.
    final int resultTextColor = mResultEditText.getCurrentTextColor();
    final int inputEditText = mInputEditText.getCurrentTextColor();
    final ValueAnimator textColorAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), resultTextColor,
            inputEditText);/*from   ww  w .ja  va 2  s . c  om*/
    textColorAnimator.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mResultEditText.setTextColor((int) valueAnimator.getAnimatedValue());
        }
    });

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(textColorAnimator,
            ObjectAnimator.ofFloat(mResultEditText, View.SCALE_X, resultScale),
            ObjectAnimator.ofFloat(mResultEditText, View.SCALE_Y, resultScale),
            ObjectAnimator.ofFloat(mResultEditText, View.TRANSLATION_X, resultTranslationX),
            ObjectAnimator.ofFloat(mResultEditText, View.TRANSLATION_Y, resultTranslationY),
            ObjectAnimator.ofFloat(mInputEditText, View.TRANSLATION_Y, inputTranslationY));
    animatorSet.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            mResultEditText.setText(result);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            // Reset all of the values modified during the animation.
            mResultEditText.setTextColor(resultTextColor);
            mResultEditText.setScaleX(1.0f);
            mResultEditText.setScaleY(1.0f);
            mResultEditText.setTranslationX(0.0f);
            mResultEditText.setTranslationY(0.0f);
            mInputEditText.setTranslationY(0.0f);

            // Finally update the input to use the current result.
            mInputEditText.setText(result); //TODO figure out how to reset after equal sign without changing input text
            mResultEditText.getEditableText().clear();
            setState(CalculatorState.RESULT);

            mCurrentAnimator = null;
        }

    });

    mCurrentAnimator = animatorSet;
    animatorSet.start();
}

From source file:org.mariotaku.twidere.fragment.support.AccountsDashboardFragment.java

private void onAccountSelected(AccountProfileImageViewHolder holder, final ParcelableAccount account) {
    if (mSwitchAccountAnimationPlaying)
        return;//from w  ww  .j av  a  2  s  .  c  o m
    final ImageView snapshotView = mFloatingProfileImageSnapshotView;
    final ShapedImageView profileImageView = mAccountProfileImageView;
    final ShapedImageView clickedImageView = holder.getIconView();

    // Reset snapshot view position
    snapshotView.setPivotX(0);
    snapshotView.setPivotY(0);
    snapshotView.setTranslationX(0);
    snapshotView.setTranslationY(0);

    final Matrix matrix = new Matrix();
    final RectF sourceBounds = new RectF(), destBounds = new RectF(), snapshotBounds = new RectF();
    getLocationOnScreen(clickedImageView, sourceBounds);
    getLocationOnScreen(profileImageView, destBounds);
    getLocationOnScreen(snapshotView, snapshotBounds);
    final float finalScale = destBounds.width() / sourceBounds.width();
    final Bitmap snapshotBitmap = TransitionUtils.createViewBitmap(clickedImageView, matrix,
            new RectF(0, 0, sourceBounds.width(), sourceBounds.height()));
    final ViewGroup.LayoutParams lp = snapshotView.getLayoutParams();
    lp.width = clickedImageView.getWidth();
    lp.height = clickedImageView.getHeight();
    snapshotView.setLayoutParams(lp);
    // Copied from MaterialNavigationDrawer: https://github.com/madcyph3r/AdvancedMaterialDrawer/
    AnimatorSet set = new AnimatorSet();
    set.play(ObjectAnimator.ofFloat(snapshotView, View.TRANSLATION_X, sourceBounds.left - snapshotBounds.left,
            destBounds.left - snapshotBounds.left))
            .with(ObjectAnimator.ofFloat(snapshotView, View.TRANSLATION_Y,
                    sourceBounds.top - snapshotBounds.top, destBounds.top - snapshotBounds.top))
            .with(ObjectAnimator.ofFloat(snapshotView, View.SCALE_X, 1, finalScale))
            .with(ObjectAnimator.ofFloat(snapshotView, View.SCALE_Y, 1, finalScale))
            .with(ObjectAnimator.ofFloat(profileImageView, View.ALPHA, 1, 0))
            .with(ObjectAnimator.ofFloat(clickedImageView, View.SCALE_X, 0, 1))
            .with(ObjectAnimator.ofFloat(clickedImageView, View.SCALE_Y, 0, 1));
    final long animationTransition = 400;
    set.setDuration(animationTransition);
    set.setInterpolator(new DecelerateInterpolator());
    set.addListener(new AnimatorListener() {

        private Drawable clickedDrawable;
        private int[] clickedColors;

        @Override
        public void onAnimationStart(Animator animation) {
            snapshotView.setVisibility(View.VISIBLE);
            snapshotView.setImageBitmap(snapshotBitmap);
            final Drawable profileDrawable = profileImageView.getDrawable();
            clickedDrawable = clickedImageView.getDrawable();
            clickedColors = clickedImageView.getBorderColors();
            final ParcelableAccount oldSelectedAccount = mAccountsAdapter.getSelectedAccount();
            mImageLoader.displayDashboardProfileImage(clickedImageView, oldSelectedAccount.profile_image_url,
                    profileDrawable);
            //                mImageLoader.displayDashboardProfileImage(profileImageView,
            //                        account.profile_image_url, clickedDrawable);
            clickedImageView.setBorderColors(profileImageView.getBorderColors());
            mSwitchAccountAnimationPlaying = true;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            finishAnimation();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            finishAnimation();
        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }

        private void finishAnimation() {
            final Editor editor = mPreferences.edit();
            editor.putLong(KEY_DEFAULT_ACCOUNT_ID, account.account_id);
            editor.apply();
            mAccountsAdapter.setSelectedAccountId(account.account_id);
            mAccountOptionsAdapter.setSelectedAccount(account);
            updateAccountOptionsSeparatorLabel(clickedDrawable);
            snapshotView.setVisibility(View.INVISIBLE);
            snapshotView.setImageDrawable(null);
            profileImageView.setImageDrawable(clickedDrawable);
            profileImageView.setBorderColors(clickedColors);
            profileImageView.setAlpha(1f);
            clickedImageView.setScaleX(1);
            clickedImageView.setScaleY(1);
            clickedImageView.setAlpha(1f);
            mSwitchAccountAnimationPlaying = false;
        }
    });
    set.start();
}

From source file:org.mariotaku.twidere.fragment.AccountsDashboardFragment.java

private void onAccountSelected(AccountProfileImageViewHolder holder, @NonNull final ParcelableAccount account) {
    if (mSwitchAccountAnimationPlaying)
        return;//from   w w w .  j a  va2s.  c  o  m
    final ImageView snapshotView = mFloatingProfileImageSnapshotView;
    final ShapedImageView profileImageView = mAccountProfileImageView;
    final ShapedImageView clickedImageView = holder.getIconView();

    // Reset snapshot view position
    snapshotView.setPivotX(0);
    snapshotView.setPivotY(0);
    snapshotView.setTranslationX(0);
    snapshotView.setTranslationY(0);

    final Matrix matrix = new Matrix();
    final RectF sourceBounds = new RectF(), destBounds = new RectF(), snapshotBounds = new RectF();
    getLocationOnScreen(clickedImageView, sourceBounds);
    getLocationOnScreen(profileImageView, destBounds);
    getLocationOnScreen(snapshotView, snapshotBounds);
    final float finalScale = destBounds.width() / sourceBounds.width();
    final Bitmap snapshotBitmap = TransitionUtils.createViewBitmap(clickedImageView, matrix,
            new RectF(0, 0, sourceBounds.width(), sourceBounds.height()));
    final ViewGroup.LayoutParams lp = snapshotView.getLayoutParams();
    lp.width = clickedImageView.getWidth();
    lp.height = clickedImageView.getHeight();
    snapshotView.setLayoutParams(lp);
    // Copied from MaterialNavigationDrawer: https://github.com/madcyph3r/AdvancedMaterialDrawer/
    AnimatorSet set = new AnimatorSet();
    set.play(ObjectAnimator.ofFloat(snapshotView, View.TRANSLATION_X, sourceBounds.left - snapshotBounds.left,
            destBounds.left - snapshotBounds.left))
            .with(ObjectAnimator.ofFloat(snapshotView, View.TRANSLATION_Y,
                    sourceBounds.top - snapshotBounds.top, destBounds.top - snapshotBounds.top))
            .with(ObjectAnimator.ofFloat(snapshotView, View.SCALE_X, 1, finalScale))
            .with(ObjectAnimator.ofFloat(snapshotView, View.SCALE_Y, 1, finalScale))
            .with(ObjectAnimator.ofFloat(profileImageView, View.ALPHA, 1, 0))
            .with(ObjectAnimator.ofFloat(clickedImageView, View.SCALE_X, 0, 1))
            .with(ObjectAnimator.ofFloat(clickedImageView, View.SCALE_Y, 0, 1));
    final long animationTransition = 400;
    set.setDuration(animationTransition);
    set.setInterpolator(new DecelerateInterpolator());
    set.addListener(new AnimatorListener() {

        private Drawable clickedDrawable;
        private int[] clickedColors;

        @Override
        public void onAnimationStart(Animator animation) {
            snapshotView.setVisibility(View.VISIBLE);
            snapshotView.setImageBitmap(snapshotBitmap);
            final Drawable profileDrawable = profileImageView.getDrawable();
            clickedDrawable = clickedImageView.getDrawable();
            clickedColors = clickedImageView.getBorderColors();
            final ParcelableAccount oldSelectedAccount = mAccountsAdapter.getSelectedAccount();
            if (oldSelectedAccount == null)
                return;
            mMediaLoader.displayDashboardProfileImage(clickedImageView, oldSelectedAccount, profileDrawable);
            clickedImageView.setBorderColors(profileImageView.getBorderColors());

            displayAccountBanner(account);

            mSwitchAccountAnimationPlaying = true;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            finishAnimation();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            finishAnimation();
        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }

        private void finishAnimation() {
            final Editor editor = mPreferences.edit();
            editor.putString(KEY_DEFAULT_ACCOUNT_KEY, account.account_key.toString());
            editor.apply();
            mAccountsAdapter.setSelectedAccount(account);
            updateAccountActions();
            displayCurrentAccount(clickedDrawable);
            snapshotView.setVisibility(View.INVISIBLE);
            snapshotView.setImageDrawable(null);
            profileImageView.setImageDrawable(clickedDrawable);
            profileImageView.setBorderColors(clickedColors);
            profileImageView.setAlpha(1f);
            clickedImageView.setScaleX(1);
            clickedImageView.setScaleY(1);
            clickedImageView.setAlpha(1f);
            mSwitchAccountAnimationPlaying = false;
        }
    });
    set.start();

}

From source file:com.waz.zclient.pages.main.conversation.SingleImageFragment.java

private AnimatorSet getSaveImageAnimation(final ImageAsset image) {
    int totalAnimationDuration = getResources().getInteger(R.integer.framework_animation_duration_long);

    ObjectAnimator fadeOutAnimator = ObjectAnimator.ofFloat(saveImageViewContainer, View.ALPHA, 1, 0);
    fadeOutAnimator.setDuration(totalAnimationDuration);

    ObjectAnimator scaleDownXAnimator = ObjectAnimator.ofFloat(saveImageViewContainer, View.SCALE_X, 0f);
    ObjectAnimator scaleDownYAnimator = ObjectAnimator.ofFloat(saveImageViewContainer, View.SCALE_Y, 0f);
    scaleDownXAnimator.setDuration(totalAnimationDuration);
    scaleDownYAnimator.setDuration(totalAnimationDuration);

    int moveY = ViewUtils.getOrientationIndependentDisplayHeight(getActivity()) / 2;
    int moveX;/*from  ww w .  j a  v  a  2 s. c o m*/
    if (ViewUtils.isInLandscape(getActivity())) {
        moveX = ViewUtils.getOrientationIndependentDisplayWidth(getActivity());
    } else {
        moveX = ViewUtils.getOrientationIndependentDisplayWidth(getActivity()) / 2;
    }
    ObjectAnimator moveXAnimator = ObjectAnimator.ofFloat(saveImageViewContainer, View.TRANSLATION_X, -moveX);
    ObjectAnimator moveYAnimator = ObjectAnimator.ofFloat(saveImageViewContainer, View.TRANSLATION_Y, moveY);
    moveXAnimator.setDuration(totalAnimationDuration);
    moveYAnimator.setDuration(totalAnimationDuration);

    // Fade out top image view for blur effect
    ObjectAnimator fadeToBlurredAnimator = ObjectAnimator.ofFloat(saveImageView, View.ALPHA, 1, 0);
    fadeToBlurredAnimator.setDuration(getResources().getInteger(R.integer.framework_animation_duration_medium));

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.setInterpolator(new Expo.EaseIn());
    animatorSet.playTogether(fadeOutAnimator, scaleDownXAnimator, scaleDownYAnimator, moveXAnimator,
            moveYAnimator, fadeToBlurredAnimator);

    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (getStoreFactory() == null || getStoreFactory().isTornDown()) {
                return;
            }

            resetSaveImageView();

            // Image saving is called here, as an image save triggers a notification which contains a bitmap;
            // currently that bitmap is quite large, android.app.Notification writes the bitmap to a parcel
            // on the main thread, dropping a large number of frames and breaking the save animation
            image.saveImageToGallery(SingleImageFragment.this);

            enableSaveImageButton(true);
        }
    });

    return animatorSet;
}

From source file:android.support.v17.leanback.app.OnboardingSupportFragment.java

private Animator createAnimator(View view, boolean fadeIn, int slideDirection, long startDelay) {
    boolean isLtr = getView().getLayoutDirection() == View.LAYOUT_DIRECTION_LTR;
    boolean slideRight = (isLtr && slideDirection == Gravity.END) || (!isLtr && slideDirection == Gravity.START)
            || slideDirection == Gravity.RIGHT;
    Animator fadeAnimator;/*from   ww  w  .  j ava  2s. c  om*/
    Animator slideAnimator;
    if (fadeIn) {
        fadeAnimator = ObjectAnimator.ofFloat(view, View.ALPHA, 0.0f, 1.0f);
        slideAnimator = ObjectAnimator.ofFloat(view, View.TRANSLATION_X,
                slideRight ? sSlideDistance : -sSlideDistance, 0);
        fadeAnimator.setInterpolator(HEADER_APPEAR_INTERPOLATOR);
        slideAnimator.setInterpolator(HEADER_APPEAR_INTERPOLATOR);
    } else {
        fadeAnimator = ObjectAnimator.ofFloat(view, View.ALPHA, 1.0f, 0.0f);
        slideAnimator = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, 0,
                slideRight ? sSlideDistance : -sSlideDistance);
        fadeAnimator.setInterpolator(HEADER_DISAPPEAR_INTERPOLATOR);
        slideAnimator.setInterpolator(HEADER_DISAPPEAR_INTERPOLATOR);
    }
    fadeAnimator.setDuration(HEADER_ANIMATION_DURATION_MS);
    fadeAnimator.setTarget(view);
    slideAnimator.setDuration(HEADER_ANIMATION_DURATION_MS);
    slideAnimator.setTarget(view);
    AnimatorSet animator = new AnimatorSet();
    animator.playTogether(fadeAnimator, slideAnimator);
    if (startDelay > 0) {
        animator.setStartDelay(startDelay);
    }
    return animator;
}

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 {//from  w w w .  j  ava 2  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(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.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 {/*from ww w  . j  a va  2  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.waz.zclient.pages.main.participants.dialog.ParticipantsDialogFragment.java

/**
 * @return true if the animation was performed,
 *         false otherwise//w w  w .  j  a  v  a 2s  .  c  o  m
 */
private boolean animateBetweenMainAndDetail(boolean showGroup) {
    float startDetail;
    float endDetail;
    float startMain;
    float endMain;
    Interpolator interpolator;
    if (showGroup) {
        startDetail = 0;
        endDetail = dialogFrameLayout.getMeasuredWidth();
        startMain = -dialogFrameLayout.getMeasuredHeight();
        endMain = 0;
        interpolator = new Quart.EaseOut();
    } else {
        startDetail = dialogFrameLayout.getMeasuredWidth();
        endDetail = 0;
        startMain = 0;
        endMain = -dialogFrameLayout.getMeasuredHeight();
        interpolator = new Quart.EaseOut();
    }

    if (MathUtils.floatEqual(mainParticipantsContainer.getTranslationX(), endMain)
            && MathUtils.floatEqual(detailParticipantContainer.getTranslationX(), endDetail)) {
        return false;
    }

    ObjectAnimator slideInDetailParticipantAnimation = ObjectAnimator.ofFloat(detailParticipantContainer,
            View.TRANSLATION_X, startDetail, endDetail);
    slideInDetailParticipantAnimation
            .setDuration(getResources().getInteger(R.integer.framework_animation_duration_long));
    slideInDetailParticipantAnimation.setInterpolator(interpolator);

    ObjectAnimator slideOutMainAnimation = ObjectAnimator.ofFloat(mainParticipantsContainer, View.TRANSLATION_X,
            startMain, endMain);
    slideOutMainAnimation.setDuration(getResources().getInteger(R.integer.framework_animation_duration_long));
    slideOutMainAnimation.setInterpolator(interpolator);

    AnimatorSet participantTransition = new AnimatorSet();
    participantTransition.playTogether(slideOutMainAnimation, slideInDetailParticipantAnimation);
    participantTransition.start();
    return true;
}