Example usage for android.animation AnimatorSet AnimatorSet

List of usage examples for android.animation AnimatorSet AnimatorSet

Introduction

In this page you can find the example usage for android.animation AnimatorSet AnimatorSet.

Prototype

public AnimatorSet() 

Source Link

Usage

From source file:com.waz.zclient.views.menus.ConfirmationMenu.java

public void animateToShow(boolean show) {
    if (show) {//from w  ww  .  j  a va2 s  .  c  o  m
        confirmed = false;
        cancelled = false;

        // Init views and post animations to get measured height of message container
        backgroundView.setAlpha(0);
        messageContainerView.setVisibility(INVISIBLE);
        setVisibility(VISIBLE);

        messageContainerView.post(new Runnable() {
            @Override
            public void run() {

                ObjectAnimator showBackgroundAnimator = ObjectAnimator.ofFloat(backgroundView, View.ALPHA, 0,
                        1);
                showBackgroundAnimator.setInterpolator(new Quart.EaseOut());
                showBackgroundAnimator
                        .setDuration(getResources().getInteger(R.integer.framework_animation_duration_short));

                ObjectAnimator showMessageAnimator = ObjectAnimator.ofFloat(messageContainerView,
                        View.TRANSLATION_Y, messageContainerView.getMeasuredHeight(), 0);
                showMessageAnimator.setInterpolator(new Expo.EaseOut());
                showMessageAnimator
                        .setDuration(getResources().getInteger(R.integer.framework_animation_duration_medium));
                showMessageAnimator.setStartDelay(getResources()
                        .getInteger(R.integer.framework_animation__confirmation_menu__show_message_delay));
                showMessageAnimator.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationStart(Animator animation) {
                        messageContainerView.setVisibility(VISIBLE);
                    }
                });

                AnimatorSet showSet = new AnimatorSet();
                showSet.playTogether(showBackgroundAnimator, showMessageAnimator);
                showSet.setDuration(getResources()
                        .getInteger(R.integer.background_accent_color_transition_animation_duration));
                showSet.start();
            }
        });
    } else {
        ObjectAnimator hideBackgroundAnimator = ObjectAnimator.ofFloat(backgroundView, View.ALPHA, 1, 0);
        hideBackgroundAnimator.setInterpolator(new Quart.EaseOut());
        hideBackgroundAnimator
                .setDuration(getResources().getInteger(R.integer.framework_animation_duration_short));
        hideBackgroundAnimator.setStartDelay(getResources()
                .getInteger(R.integer.framework_animation__confirmation_menu__hide_background_delay));
        hideBackgroundAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                setVisibility(GONE);
                boolean checkboxIsSelected = checkBoxView.getVisibility() == VISIBLE
                        && checkBoxView.isSelected();
                if (callback != null) {
                    callback.onHideAnimationEnd(confirmed, cancelled, checkboxIsSelected);
                }
            }
        });

        ObjectAnimator hideMessageAnimator = ObjectAnimator.ofFloat(messageContainerView, View.TRANSLATION_Y, 0,
                messageContainerView.getMeasuredHeight());
        hideMessageAnimator.setInterpolator(new Expo.EaseIn());
        hideMessageAnimator
                .setDuration(getResources().getInteger(R.integer.framework_animation_duration_medium));

        AnimatorSet hideSet = new AnimatorSet();
        hideSet.playTogether(hideMessageAnimator, hideBackgroundAnimator);
        hideSet.start();
    }
}

From source file:com.myhexaville.iconanimations.gooey_fab.GooeyFabCompatImpl.java

@TargetApi(21)
void onElevationsChanged(final float elevation, final float pressedTranslationZ) {
    final StateListAnimator stateListAnimator = new StateListAnimator();

    // Animate elevation and translationZ to our values when pressed
    AnimatorSet set = new AnimatorSet();
    set.play(ObjectAnimator.ofFloat(this, "elevation", elevation).setDuration(0)).with(ObjectAnimator
            .ofFloat(this, View.TRANSLATION_Z, pressedTranslationZ).setDuration(PRESSED_ANIM_DURATION));
    set.setInterpolator(ANIM_INTERPOLATOR);
    stateListAnimator.addState(PRESSED_ENABLED_STATE_SET, set);

    // Same deal for when we're focused
    set = new AnimatorSet();
    set.play(ObjectAnimator.ofFloat(this, "elevation", elevation).setDuration(0)).with(ObjectAnimator
            .ofFloat(this, View.TRANSLATION_Z, pressedTranslationZ).setDuration(PRESSED_ANIM_DURATION));
    set.setInterpolator(ANIM_INTERPOLATOR);
    stateListAnimator.addState(FOCUSED_ENABLED_STATE_SET, set);

    // Animate translationZ to 0 if not pressed
    set = new AnimatorSet();
    // Use an AnimatorSet to set a start delay since there is a bug with ValueAnimator that
    // prevents it from being cancelled properly when used with a StateListAnimator.
    AnimatorSet anim = new AnimatorSet();
    anim.play(ObjectAnimator.ofFloat(this, View.TRANSLATION_Z, 0f).setDuration(PRESSED_ANIM_DURATION))
            .after(PRESSED_ANIM_DURATION);
    set.play(ObjectAnimator.ofFloat(this, "elevation", elevation).setDuration(0)).with(anim);
    set.setInterpolator(ANIM_INTERPOLATOR);
    stateListAnimator.addState(ENABLED_STATE_SET, set);

    // Animate everything to 0 when disabled
    set = new AnimatorSet();
    set.play(ObjectAnimator.ofFloat(this, "elevation", 0f).setDuration(0))
            .with(ObjectAnimator.ofFloat(this, View.TRANSLATION_Z, 0f).setDuration(0));
    set.setInterpolator(ANIM_INTERPOLATOR);
    stateListAnimator.addState(EMPTY_STATE_SET, set);

    setStateListAnimator(stateListAnimator);
}

From source file:me.lizheng.deckview.views.DeckChildViewHeader.java

/**
 * Notifies the associated TaskView has been focused.
 *//*from ww w.ja v a 2 s. c o m*/
void onTaskViewFocusChanged(boolean focused, boolean animateFocusedState) {
    // If we are not animating the visible state, just return
    if (!animateFocusedState)
        return;

    boolean isRunning = false;
    if (mFocusAnimator != null) {
        isRunning = mFocusAnimator.isRunning();
        DVUtils.cancelAnimationWithoutCallbacks(mFocusAnimator);
    }

    if (focused) {
        // Pulse the background color
        int currentColor = mBackgroundColor;
        int lightPrimaryColor = getSecondaryColor(mCurrentPrimaryColor, mCurrentPrimaryColorIsDark);
        ValueAnimator backgroundColor = ValueAnimator.ofObject(new ArgbEvaluator(), currentColor,
                lightPrimaryColor);

        backgroundColor.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                int color = (int) animation.getAnimatedValue();
                mBackgroundColorDrawable.setColor(color);
                mBackgroundColor = color;
            }
        });

        backgroundColor.setRepeatCount(ValueAnimator.INFINITE);
        backgroundColor.setRepeatMode(ValueAnimator.REVERSE);

        // Pulse the translation
        ObjectAnimator translation = ObjectAnimator.ofFloat(this, "translationZ", 15f);
        translation.setRepeatCount(ValueAnimator.INFINITE);
        translation.setRepeatMode(ValueAnimator.REVERSE);

        mFocusAnimator = new AnimatorSet();
        mFocusAnimator.playTogether(backgroundColor, translation);
        mFocusAnimator.setStartDelay(750);
        mFocusAnimator.setDuration(750);
        mFocusAnimator.start();
    } else if (isRunning) {
        // Restore the background color
        int currentColor = mBackgroundColor;
        ValueAnimator backgroundColor = ValueAnimator.ofObject(new ArgbEvaluator(), currentColor,
                mCurrentPrimaryColor);
        backgroundColor.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                int color = (int) animation.getAnimatedValue();
                mBackgroundColorDrawable.setColor(color);
                mBackgroundColor = color;
            }
        });

        // Restore the translation
        ObjectAnimator translation = ObjectAnimator.ofFloat(this, "translationZ", 0f);

        mFocusAnimator = new AnimatorSet();
        mFocusAnimator.playTogether(backgroundColor, translation);
        mFocusAnimator.setDuration(150);
        mFocusAnimator.start();
    }
}

From source file:com.google.samples.apps.topeka.activity.QuizActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void revealFragmentContainerLollipop(final View clickedView, final FrameLayout fragmentContainer) {
    prepareCircularReveal(clickedView, fragmentContainer);

    ViewCompat.animate(clickedView).scaleX(0).scaleY(0).alpha(0).setInterpolator(mInterpolator)
            .setListener(new ViewPropertyAnimatorListenerAdapter() {
                @Override// w  w w. j a  va 2  s .co  m
                public void onAnimationEnd(View view) {
                    fragmentContainer.setVisibility(View.VISIBLE);
                    clickedView.setVisibility(View.GONE);
                }
            }).start();

    fragmentContainer.setVisibility(View.VISIBLE);
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(mCircularReveal).with(mColorChange);
    animatorSet.start();
}

From source file:sg.fxl.topekaport.QuizActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void revealFragmentContainerLollipop(final View clickedView, final FrameLayout fragmentContainer) {
    prepareCircularReveal(clickedView, fragmentContainer);

    ViewCompat.animate(clickedView).scaleX(0).scaleY(0).alpha(0).setInterpolator(interpolator)
            .setListener(new ViewPropertyAnimatorListenerAdapter() {
                @Override//from   w ww .j  av  a  2  s . c  o m
                public void onAnimationEnd(View view) {
                    fragmentContainer.setVisibility(View.VISIBLE);
                    clickedView.setVisibility(View.GONE);
                }
            }).start();

    fragmentContainer.setVisibility(View.VISIBLE);
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(circularReveal).with(colorChange);
    animatorSet.start();
}

From source file:com.android.clear.reminder.ItemAnimator.java

@Override
public void runPendingAnimations() {
    final AnimatorSet removeAnimatorSet = new AnimatorSet();
    removeAnimatorSet.playTogether(mRemoveAnimatorsList);
    mRemoveAnimatorsList.clear();/*from   ww w .  ja va  2  s . c  om*/

    final AnimatorSet addAnimatorSet = new AnimatorSet();
    addAnimatorSet.playTogether(mAddAnimatorsList);
    mAddAnimatorsList.clear();

    final AnimatorSet changeAnimatorSet = new AnimatorSet();
    changeAnimatorSet.playTogether(mChangeAnimatorsList);
    mChangeAnimatorsList.clear();

    final AnimatorSet moveAnimatorSet = new AnimatorSet();
    moveAnimatorSet.playTogether(mMoveAnimatorsList);
    mMoveAnimatorsList.clear();

    final AnimatorSet pendingAnimatorSet = new AnimatorSet();
    pendingAnimatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            animator.removeAllListeners();
            dispatchFinishedWhenDone();
        }
    });
    // Required order: removes, then changes & moves simultaneously, then additions. There are
    // redundant edges because changes or moves may be empty, causing the removes to incorrectly
    // play immediately.
    pendingAnimatorSet.play(removeAnimatorSet).before(changeAnimatorSet);
    pendingAnimatorSet.play(removeAnimatorSet).before(moveAnimatorSet);
    pendingAnimatorSet.play(changeAnimatorSet).with(moveAnimatorSet);
    pendingAnimatorSet.play(addAnimatorSet).after(changeAnimatorSet);
    pendingAnimatorSet.play(addAnimatorSet).after(moveAnimatorSet);
    pendingAnimatorSet.start();
}

From source file:com.pictureperfect.FaceTrackerActivity.java

public void initializeAnimation() {
    if (flash != null) {
        ObjectAnimator fadeOut = ObjectAnimator.ofFloat(flash, "alpha", 7f, 0f);
        fadeOut.setDuration(250);//from   ww  w . j  ava 2  s  .c o  m
        ObjectAnimator fadeIn = ObjectAnimator.ofFloat(flash, "alpha", 0f, 7f);
        fadeIn.setDuration(250);

        mAnimationSet = new AnimatorSet();

        mAnimationSet.play(fadeOut).after(fadeIn);

        mAnimationSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                flash.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                Toast.makeText(getApplicationContext(), "Picture Taken", Toast.LENGTH_SHORT).show();
            }
        });
    }
}

From source file:com.example.george.sharedelementimplementation.MainActivity.java

public void runEnterAnimation() {
    final long duration = (long) (ANIM_DURATION * MainActivity.sAnimatorScale);
    // set starting values for properties we're going to animate. These
    // values scale and position the full size version down to the thumbnail
    // size/location, from which we'll animate it back up
    ObjectAnimator anim = ObjectAnimator.ofInt(mBackground, "alpha", 0, 255);
    anim.addListener(new Animator.AnimatorListener() {
        @Override/*from  w  w  w  .  ja  va2 s . c o m*/
        public void onAnimationStart(Animator animation) {

        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mIsAnimationPlaying = false;
            mImage.setVisibility(View.GONE);
            mPager.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });

    AnimatorSet set = new AnimatorSet();
    set.playTogether(ObjectAnimator.ofFloat(mImage, "translationX", mXDelta, 0),
            ObjectAnimator.ofFloat(mImage, "translationY", mYDelta, 0),
            ObjectAnimator.ofFloat(mImage, "scaleX", mImageScale, 1),
            ObjectAnimator.ofFloat(mImage, "scaleY", mImageScale, 1),
            //            ObjectAnimator.ofFloat(mImage, "alpha", 0, 1),
            ObjectAnimator.ofFloat(mImage, "imageCrop", clipRatio, 0f), anim);
    set.setInterpolator(sDecelerator);
    set.setDuration(duration).start();
    mIsAnimationPlaying = true;
}

From source file:org.goodev.material.SearchActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);
    ButterKnife.bind(this);
    setupSearchView();/*from  ww  w  . j  ava  2s.  co m*/
    if (UI.isLollipop()) {
        auto = TransitionInflater.from(this).inflateTransition(R.transition.auto);
    }

    dataManager = new SearchDataManager(this) {
        @Override
        public void onDataLoaded(List<Hit> data) {
            if (data != null && data.size() > 0) {
                if (results.getVisibility() != View.VISIBLE) {
                    if (UI.isLollipop()) {
                        TransitionManager.beginDelayedTransition(container, auto);
                    }
                    progress.setVisibility(View.GONE);
                    results.setVisibility(View.VISIBLE);
                }
                adapter.addAll(data);
                if (dataManager.getPage() == 0) {
                    results.scrollToPosition(0);
                }
            } else if (adapter.getItemCount() == 0) {
                if (UI.isLollipop()) {
                    TransitionManager.beginDelayedTransition(container, auto);
                }
                progress.setVisibility(View.GONE);
                setNoResultsVisibility(View.VISIBLE);
            } else {
                adapter.notifyDataSetChanged();
                Snackbar.make(results, R.string.no_more_posts, Snackbar.LENGTH_LONG).show();
            }
        }
    };
    adapter = new FeedAdapter(this, dataManager, columns);
    results.setAdapter(adapter);
    GridLayoutManager layoutManager = new GridLayoutManager(this, columns);
    //        layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
    //            @Override
    //            public int getSpanSize(int position) {
    //                return adapter.getItemColumnSpan(position);
    //            }
    //        });
    results.setLayoutManager(layoutManager);
    results.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) {
        @Override
        public void onLoadMore() {
            dataManager.loadMore();
        }
    });
    results.setHasFixedSize(true);
    if (UI.isLollipop()) {
        results.addOnScrollListener(gridScroll);
    }

    // extract the search icon's location passed from the launching activity, minus 4dp to
    // compensate for different paddings in the views
    searchBackDistanceX = getIntent().getIntExtra(EXTRA_MENU_LEFT, 0) - (int) TypedValue
            .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics());
    searchIconCenterX = getIntent().getIntExtra(EXTRA_MENU_CENTER_X, 0);

    int interpolator = UI.isLollipop() ? android.R.interpolator.fast_out_slow_in
            : android.R.interpolator.accelerate_decelerate;
    int backInterpolator = UI.isLollipop() ? android.R.interpolator.linear_out_slow_in
            : android.R.interpolator.accelerate_decelerate;
    // translate icon to match the launching screen then animate back into position
    searchBackContainer.setTranslationX(searchBackDistanceX);
    searchBackContainer.animate().translationX(0f).setDuration(650L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, interpolator));
    if (UI.isLollipop()) {
        // transform from search icon to back icon
        AnimatedVectorDrawable searchToBack = (AnimatedVectorDrawable) ContextCompat.getDrawable(this,
                R.drawable.avd_search_to_back);
        searchBack.setImageDrawable(searchToBack);
        searchToBack.start();
    } else {
        searchBack.setVisibility(View.INVISIBLE);
        searchBack.setImageResource(R.drawable.ic_arrow_back_padded);
    }
    // for some reason the animation doesn't always finish (leaving a part arrow!?) so after
    // the animation set a static drawable. Also animation callbacks weren't added until API23
    // so using post delayed :(
    // TODO fix properly!!
    searchBack.postDelayed(new Runnable() {
        @Override
        public void run() {
            searchBack.setImageDrawable(
                    ContextCompat.getDrawable(SearchActivity.this, R.drawable.ic_arrow_back_padded));
        }
    }, 600);

    // fade in the other search chrome
    searchBackground.animate().alpha(1f).setDuration(300L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, backInterpolator));
    searchView.animate().alpha(1f).setStartDelay(400L).setDuration(400L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, backInterpolator))
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    searchView.requestFocus();
                    ImeUtils.showIme(searchView);
                }
            });

    if (UI.isLollipop()) {
        // animate in a scrim over the content behind
        scrim.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public boolean onPreDraw() {
                scrim.getViewTreeObserver().removeOnPreDrawListener(this);
                AnimatorSet showScrim = new AnimatorSet();
                showScrim.playTogether(
                        ViewAnimationUtils.createCircularReveal(scrim, searchIconCenterX,
                                searchBackground.getBottom(), 0,
                                (float) Math.hypot(searchBackDistanceX,
                                        scrim.getHeight() - searchBackground.getBottom())),
                        ObjectAnimator.ofArgb(scrim, ViewUtils.BACKGROUND_COLOR, Color.TRANSPARENT,
                                ContextCompat.getColor(SearchActivity.this, R.color.scrim)));
                showScrim.setDuration(400L);
                showScrim.setInterpolator(
                        AnimationUtils.loadInterpolator(SearchActivity.this, backInterpolator));
                showScrim.start();
                return false;
            }
        });
    }

    onNewIntent(getIntent());
}

From source file:org.telegram.ui.ChangePhoneActivity.java

public void setPage(int page, boolean animated, Bundle params, boolean back) {
    if (page == 3) {
        doneButton.setVisibility(View.GONE);
    } else {//from  w  w  w .  ja v a2 s  . c  o  m
        if (page == 0) {
            checkPermissions = true;
        }
        doneButton.setVisibility(View.VISIBLE);
    }
    final SlideView outView = views[currentViewNum];
    final SlideView newView = views[page];
    currentViewNum = page;

    newView.setParams(params);
    actionBar.setTitle(newView.getHeaderName());
    newView.onShow();
    newView.setX(back ? -AndroidUtilities.displaySize.x : AndroidUtilities.displaySize.x);

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.setDuration(300);
    animatorSet.playTogether(
            ObjectAnimator.ofFloat(outView, "translationX",
                    back ? AndroidUtilities.displaySize.x : -AndroidUtilities.displaySize.x),
            ObjectAnimator.ofFloat(newView, "translationX", 0));
    animatorSet.addListener(new AnimatorListenerAdapterProxy() {
        @Override
        public void onAnimationStart(Animator animation) {
            newView.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            outView.setVisibility(View.GONE);
            outView.setX(0);
        }
    });
    animatorSet.start();
}