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

@Override
public void onTextSizeChanged(final TextView textView, float oldSize) {
    if (mCurrentState != CalculatorState.INPUT) {
        // Only animate text changes that occur from user input.
        return;// ww  w  .  ja  v  a2  s  .c  om
    }

    // Calculate the values needed to perform the scale and translation animations,
    // maintaining the same apparent baseline for the displayed text.
    final float textScale = oldSize / textView.getTextSize();
    final float translationX = (1.0f - textScale) * (textView.getWidth() / 2.0f - textView.getPaddingEnd());
    final float translationY = (1.0f - textScale) * (textView.getHeight() / 2.0f - textView.getPaddingBottom());

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(textView, View.SCALE_X, textScale, 1.0f),
            ObjectAnimator.ofFloat(textView, View.SCALE_Y, textScale, 1.0f),
            ObjectAnimator.ofFloat(textView, View.TRANSLATION_X, translationX, 0.0f),
            ObjectAnimator.ofFloat(textView, View.TRANSLATION_Y, translationY, 0.0f));
    animatorSet.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime));
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.start();
}

From source file:de.jeanpierrehotz.messaging.androidclient.MainActivity.java

/**
 * Diese Methode erstellt die Funktion, mit der man deL FloatingActionButton draggen
 * kann, woraufhin die CardView fr die Nachricht folgt
 *///from   ww  w . jav a 2s  .c  o  m
private void buildFollowingFun() {
    //      Frag einfach nicht, das ist Copy-Paste aus einem anderen
    //      Projekt von mir, und funktioniert einfach
    FloatingActionButton fab = mSendBtn;
    CardView cv = (CardView) findViewById(R.id.sendCardView);

    final SpringSystem springSystem = SpringSystem.create();

    final Spring fabSpringX = springSystem.createSpring();
    final Spring fabSpringY = springSystem.createSpring();

    new Actor.Builder(springSystem, fab).addMotion(fabSpringX, MotionProperty.X)
            .addMotion(fabSpringY, MotionProperty.Y).build();

    final Spring cvFollowerSpringX = springSystem.createSpring();
    final Spring cvFollowerSpringY = springSystem.createSpring();

    cvFollowerSpringX.addListener(new Performer(cv, View.TRANSLATION_X));
    cvFollowerSpringY.addListener(new Performer(cv, View.TRANSLATION_Y));

    final SpringImitator cvImitatorX = new SpringImitator(cvFollowerSpringX);
    final SpringImitator cvImitatorY = new SpringImitator(cvFollowerSpringY);

    fabSpringX.addListener(cvImitatorX);
    fabSpringY.addListener(cvImitatorY);
}

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

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./* w  w w  .  ja v  a  2 s  .  c o m*/
    final float resultScale = mFormulaEditText.getVariableTextSize(result) / mResultEditText.getTextSize();
    final float resultTranslationX = (1.0f - resultScale)
            * (mResultEditText.getWidth() / 2.0f - mResultEditText.getPaddingEnd());
    final float resultTranslationY = (1.0f - resultScale)
            * (mResultEditText.getHeight() / 2.0f - mResultEditText.getPaddingBottom())
            + (mFormulaEditText.getBottom() - mResultEditText.getBottom())
            + (mResultEditText.getPaddingBottom() - mFormulaEditText.getPaddingBottom());
    final float formulaTranslationY = -mFormulaEditText.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 formulaTextColor = mFormulaEditText.getCurrentTextColor();
    final ValueAnimator textColorAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), resultTextColor,
            formulaTextColor);
    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(mFormulaEditText, View.TRANSLATION_Y, formulaTranslationY));
    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);
            mFormulaEditText.setTranslationY(0.0f);

            // Finally update the formula to use the current result.
            mFormulaEditText.setText(result);
            setState(CalculatorState.RESULT);

            mCurrentAnimator = null;
        }
    });

    mCurrentAnimator = animatorSet;
    animatorSet.start();
}

From source file:io.plaidapp.ui.DesignerNewsStory.java

private void doFabExpand() {
    // translate the chrome placeholder ui so that it is centered on the FAB
    int fabCenterX = (fab.getLeft() + fab.getRight()) / 2;
    int fabCenterY = ((fab.getTop() + fab.getBottom()) / 2) - fabExpand.getTop();
    int translateX = fabCenterX - (fabExpand.getWidth() / 2);
    int translateY = fabCenterY - (fabExpand.getHeight() / 2);
    fabExpand.setTranslationX(translateX);
    fabExpand.setTranslationY(translateY);

    // then reveal the placeholder ui, starting from the center & same dimens as fab
    fabExpand.setVisibility(View.VISIBLE);
    Animator reveal = ViewAnimationUtils
            .createCircularReveal(fabExpand, fabExpand.getWidth() / 2, fabExpand.getHeight() / 2,
                    fab.getWidth() / 2, (int) Math.hypot(fabExpand.getWidth() / 2, fabExpand.getHeight() / 2))
            .setDuration(fabExpandDuration);

    // translate the placeholder ui back into position along an arc
    ArcMotion arcMotion = new ArcMotion();
    arcMotion.setMinimumVerticalAngle(70f);
    Path motionPath = arcMotion.getPath(translateX, translateY, 0, 0);
    Animator position = ObjectAnimator.ofFloat(fabExpand, View.TRANSLATION_X, View.TRANSLATION_Y, motionPath)
            .setDuration(fabExpandDuration);

    // animate from the FAB colour to the placeholder background color
    Animator background = ObjectAnimator
            .ofArgb(fabExpand, ViewUtils.BACKGROUND_COLOR, ContextCompat.getColor(this, R.color.designer_news),
                    ContextCompat.getColor(this, R.color.background_light))
            .setDuration(fabExpandDuration);

    // fade out the fab (rapidly)
    Animator fadeOutFab = ObjectAnimator.ofFloat(fab, View.ALPHA, 0f).setDuration(60);

    // play 'em all together with the material interpolator
    AnimatorSet show = new AnimatorSet();
    show.setInterpolator(/*w ww . j a  v  a 2  s .  c o  m*/
            AnimationUtils.loadInterpolator(DesignerNewsStory.this, android.R.interpolator.fast_out_slow_in));
    show.playTogether(reveal, background, position, fadeOutFab);
    show.start();
}

From source file:io.plaidapp.ui.DesignerNewsStory.java

private void doFabExpand() {
    // translate the chrome placeholder ui so that it is centered on the FAB
    int fabCenterX = (fab.getLeft() + fab.getRight()) / 2;
    int fabCenterY = ((fab.getTop() + fab.getBottom()) / 2) - fabExpand.getTop();
    int translateX = fabCenterX - (fabExpand.getWidth() / 2);
    int translateY = fabCenterY - (fabExpand.getHeight() / 2);
    fabExpand.setTranslationX(translateX);
    fabExpand.setTranslationY(translateY);

    // then reveal the placeholder ui, starting from the center & same dimens as fab
    fabExpand.setVisibility(View.VISIBLE);
    Animator reveal = ViewAnimationUtils
            .createCircularReveal(fabExpand, fabExpand.getWidth() / 2, fabExpand.getHeight() / 2,
                    fab.getWidth() / 2, (int) Math.hypot(fabExpand.getWidth() / 2, fabExpand.getHeight() / 2))
            .setDuration(fabExpandDuration);

    // translate the placeholder ui back into position along an arc
    GravityArcMotion arcMotion = new GravityArcMotion();
    arcMotion.setMinimumVerticalAngle(70f);
    Path motionPath = arcMotion.getPath(translateX, translateY, 0, 0);
    Animator position = ObjectAnimator.ofFloat(fabExpand, View.TRANSLATION_X, View.TRANSLATION_Y, motionPath)
            .setDuration(fabExpandDuration);

    // animate from the FAB colour to the placeholder background color
    Animator background = ObjectAnimator
            .ofArgb(fabExpand, ViewUtils.BACKGROUND_COLOR, ContextCompat.getColor(this, R.color.designer_news),
                    ContextCompat.getColor(this, R.color.background_light))
            .setDuration(fabExpandDuration);

    // fade out the fab (rapidly)
    Animator fadeOutFab = ObjectAnimator.ofFloat(fab, View.ALPHA, 0f).setDuration(60);

    // play 'em all together with the material interpolator
    AnimatorSet show = new AnimatorSet();
    show.setInterpolator(getFastOutSlowInInterpolator(DesignerNewsStory.this));
    show.playTogether(reveal, background, position, fadeOutFab);
    show.start();/*from www  .j av  a2  s. com*/
}

From source file:io.plaidapp.designernews.ui.story.StoryActivity.java

private void doFabExpand() {
    // translate the chrome placeholder ui so that it is centered on the FAB
    int fabCenterX = (fab.getLeft() + fab.getRight()) / 2;
    int fabCenterY = ((fab.getTop() + fab.getBottom()) / 2) - fabExpand.getTop();
    int translateX = fabCenterX - (fabExpand.getWidth() / 2);
    int translateY = fabCenterY - (fabExpand.getHeight() / 2);
    fabExpand.setTranslationX(translateX);
    fabExpand.setTranslationY(translateY);

    // then reveal the placeholder ui, starting from the center & same dimens as fab
    fabExpand.setVisibility(View.VISIBLE);
    Animator reveal = ViewAnimationUtils
            .createCircularReveal(fabExpand, fabExpand.getWidth() / 2, fabExpand.getHeight() / 2,
                    fab.getWidth() / 2, (int) Math.hypot(fabExpand.getWidth() / 2, fabExpand.getHeight() / 2))
            .setDuration(fabExpandDuration);

    // translate the placeholder ui back into position along an arc
    GravityArcMotion arcMotion = new GravityArcMotion();
    arcMotion.setMinimumVerticalAngle(70f);
    Path motionPath = arcMotion.getPath(translateX, translateY, 0, 0);
    Animator position = ObjectAnimator.ofFloat(fabExpand, View.TRANSLATION_X, View.TRANSLATION_Y, motionPath)
            .setDuration(fabExpandDuration);

    // animate from the FAB colour to the placeholder background color
    Animator background = ObjectAnimator
            .ofArgb(fabExpand, ViewUtils.BACKGROUND_COLOR,
                    ContextCompat.getColor(this, io.plaidapp.R.color.designer_news),
                    ContextCompat.getColor(this, io.plaidapp.R.color.background_light))
            .setDuration(fabExpandDuration);

    // fade out the fab (rapidly)
    Animator fadeOutFab = ObjectAnimator.ofFloat(fab, View.ALPHA, 0f).setDuration(60);

    // play 'em all together with the material interpolator
    AnimatorSet show = new AnimatorSet();
    show.setInterpolator(getFastOutSlowInInterpolator(StoryActivity.this));
    show.playTogether(reveal, background, position, fadeOutFab);
    show.start();/*from   w w  w  .j ava2s. c  om*/
}

From source file:org.chromium.chrome.browser.ntp.cards.NewTabPageRecyclerView.java

/**
 * Animates the card being swiped to the right as if the user had dismissed it. Any changes to
 * the animation here should be reflected also in
 * {@link #updateViewStateForDismiss(float, ViewHolder)} and reset in
 * {@link CardViewHolder#onBindViewHolder()}.
 * @param suggestion The item to be dismissed.
 *//*from w  w  w.  ja  va 2 s .c o  m*/
public void dismissItemWithAnimation(SnippetArticle suggestion) {
    // We need to recompute the position, as it might have changed.
    final int position = getNewTabPageAdapter().getSuggestionPosition(suggestion);
    if (position == RecyclerView.NO_POSITION) {
        // The item does not exist anymore, so ignore.
        return;
    }

    final View itemView = mLayoutManager.findViewByPosition(position);
    if (itemView == null) {
        // The view is not visible anymore, skip the animation.
        getNewTabPageAdapter().dismissItem(position);
        return;
    }

    final ViewHolder viewHolder = getChildViewHolder(itemView);
    if (!((NewTabPageViewHolder) viewHolder).isDismissable()) {
        // The item is not dismissable (anymore), so ignore.
        return;
    }

    AnimatorSet animation = new AnimatorSet();
    animation.playTogether(ObjectAnimator.ofFloat(itemView, View.ALPHA, 0f),
            ObjectAnimator.ofFloat(itemView, View.TRANSLATION_X, (float) itemView.getWidth()));

    animation.setDuration(DISMISS_ANIMATION_TIME_MS);
    animation.setInterpolator(DISMISS_INTERPOLATOR);
    animation.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            NewTabPageRecyclerView.this.onItemDismissStarted(viewHolder);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            getNewTabPageAdapter().dismissItem(position);
            NewTabPageRecyclerView.this.onItemDismissFinished(viewHolder);
        }
    });
    animation.start();
}

From source file:org.getlantern.firetweet.fragment.support.AccountsDashboardFragment.java

private void onAccountSelected(AccountProfileImageViewHolder holder, final ParcelableAccount account) {
    if (mSwitchAccountAnimationPlaying)
        return;//from  w  ww. ja va  2  s  .  co  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();
        }

        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;
        }

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

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });
    set.start();
}

From source file:com.android.deskclock.alarms.AlarmActivity.java

private ValueAnimator getAlarmBounceAnimator(float translationX, final int hintResId) {
    final ValueAnimator bounceAnimator = ObjectAnimator.ofFloat(mAlarmButton, View.TRANSLATION_X,
            mAlarmButton.getTranslationX(), translationX, 0.0f);
    bounceAnimator.setInterpolator(AnimatorUtils.DECELERATE_ACCELERATE_INTERPOLATOR);
    bounceAnimator.setDuration(ALARM_BOUNCE_DURATION_MILLIS);
    bounceAnimator.addListener(new AnimatorListenerAdapter() {
        @Override//from   ww w .j  a  v a2 s .  c o m
        public void onAnimationStart(Animator animator) {
            mHintView.setText(hintResId);
            if (mHintView.getVisibility() != View.VISIBLE) {
                mHintView.setVisibility(View.VISIBLE);
                ObjectAnimator.ofFloat(mHintView, View.ALPHA, 0.0f, 1.0f).start();
            }
        }
    });
    return bounceAnimator;
}

From source file:com.tiancaicc.springfloatingactionmenu.SpringFloatingActionMenu.java

private void applyFollowAnimation() {
    /* Animation code */

    final SpringSystem springSystem = SpringSystem.create();

    // create the springs that control movement
    final Spring springX = springSystem.createSpring();
    final Spring springY = springSystem.createSpring();

    // bind circle movement to events
    new Actor.Builder(springSystem, mFAB)
            .addMotion(springX, Imitator.TRACK_DELTA, Imitator.FOLLOW_EXACT, MotionProperty.X)
            .addMotion(springY, Imitator.TRACK_DELTA, Imitator.FOLLOW_EXACT, MotionProperty.Y).build();

    // add springs to connect between the views
    final Spring[] followsX = new Spring[mMenuItemCount];
    final Spring[] followsY = new Spring[mMenuItemCount];

    for (int i = 0; i < mFollowCircles.size(); i++) {

        // create spring to bind views
        followsX[i] = springSystem.createSpring();
        followsY[i] = springSystem.createSpring();
        followsX[i].addListener(new Performer(mFollowCircles.get(i), View.TRANSLATION_X));
        followsY[i].addListener(new Performer(mFollowCircles.get(i), View.TRANSLATION_Y));

        // imitates another character
        final SpringImitator followX = new SpringImitator(followsX[i]);
        final SpringImitator followY = new SpringImitator(followsY[i]);

        //  imitate the previous character
        if (i == 0) {
            springX.addListener(followX);
            springY.addListener(followY);
        } else {/*w ww . java  2s  .co m*/
            followsX[i - 1].addListener(followX);
            followsY[i - 1].addListener(followY);
        }
    }
}