List of usage examples for android.animation Animator addListener
public void addListener(AnimatorListener listener)
From source file:com.betterAlarm.deskclock.timer.TimerFragment.java
private Animator createRotateAnimator(AnimatorListenerAdapter adapter, boolean toSetup) { final AnimatorSet animatorSet = new AnimatorSet(); final Animator rotateFrom = getRotateFromAnimator(toSetup ? mTimerView : mSetupView); rotateFrom.addListener(adapter); final Animator rotateTo = getRotateToAnimator(toSetup ? mSetupView : mTimerView); final Animator expandFooterButton = getScaleFooterButtonsAnimator(!toSetup); animatorSet.play(rotateFrom).before(rotateTo).with(expandFooterButton); return animatorSet; }
From source file:orbin.deskclock.timer.TimerFragment.java
/** * @param timerToRemove the timer to be removed during the animation *//*from www . ja v a2 s . c o m*/ private void animateTimerRemove(final Timer timerToRemove) { final long duration = UiDataModel.getUiDataModel().getShortAnimationDuration(); final Animator fadeOut = ObjectAnimator.ofFloat(mViewPager, ALPHA, 1, 0); fadeOut.setDuration(duration); fadeOut.setInterpolator(new DecelerateInterpolator()); fadeOut.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { DataModel.getDataModel().removeTimer(timerToRemove); Events.sendTimerEvent(R.string.action_delete, R.string.label_deskclock); } }); final Animator fadeIn = ObjectAnimator.ofFloat(mViewPager, ALPHA, 0, 1); fadeIn.setDuration(duration); fadeIn.setInterpolator(new AccelerateInterpolator()); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(fadeOut).before(fadeIn); animatorSet.start(); }
From source file:com.wizardsofm.deskclock.timer.TimerFragment.java
/** * @param timerToRemove the timer to be removed during the animation *///from ww w. j a v a 2 s . c om private void animateTimerRemove(final Timer timerToRemove) { final long duration = UiDataModel.getUiDataModel().getShortAnimationDuration(); final Animator fadeOut = ObjectAnimator.ofFloat(mViewPager, ALPHA, 1, 0); fadeOut.setDuration(duration); fadeOut.setInterpolator(new DecelerateInterpolator()); fadeOut.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { DataModel.getDataModel().removeTimer(timerToRemove); Events.sendTimerEvent(com.wizardsofm.deskclock.R.string.action_delete, com.wizardsofm.deskclock.R.string.label_deskclock); } }); final Animator fadeIn = ObjectAnimator.ofFloat(mViewPager, ALPHA, 0, 1); fadeIn.setDuration(duration); fadeIn.setInterpolator(new AccelerateInterpolator()); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(fadeOut).before(fadeIn); animatorSet.start(); }
From source file:orbin.deskclock.timer.TimerFragment.java
/** * @param toView one of {@link #mTimersView} or {@link #mCreateTimerView} * @param timerToRemove the timer to be removed during the animation; {@code null} if no timer * should be removed// ww w . ja v a2 s . c o m */ private void animateToView(View toView, final Timer timerToRemove) { if (mCurrentView == toView) { throw new IllegalStateException("toView is already the current view"); } final boolean toTimers = toView == mTimersView; // Avoid double-taps by enabling/disabling the set of buttons active on the new view. updateFab(DISABLE_BUTTONS); final long duration = UiDataModel.getUiDataModel().getShortAnimationDuration(); final Animator rotateFrom = ObjectAnimator.ofFloat(mCurrentView, SCALE_X, 1, 0); rotateFrom.setDuration(duration); rotateFrom.setInterpolator(new DecelerateInterpolator()); rotateFrom.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (timerToRemove != null) { DataModel.getDataModel().removeTimer(timerToRemove); Events.sendTimerEvent(R.string.action_delete, R.string.label_deskclock); } mCurrentView.setScaleX(1); if (toTimers) { showTimersView(FAB_AND_BUTTONS_SHRINK_AND_EXPAND); } else { showCreateTimerView(FAB_AND_BUTTONS_SHRINK_AND_EXPAND); } } }); final Animator rotateTo = ObjectAnimator.ofFloat(toView, SCALE_X, 0, 1); rotateTo.setDuration(duration); rotateTo.setInterpolator(new AccelerateInterpolator()); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(rotateFrom).before(rotateTo); animatorSet.start(); }
From source file:com.conferenceengineer.android.iosched.ui.SessionDetailFragment.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void setOrAnimateIconTo(final ImageView imageView, final int imageResId, boolean animate) { if (UIUtils.hasICS() && imageView.getTag() != null) { if (imageView.getTag() instanceof Animator) { Animator anim = (Animator) imageView.getTag(); anim.end();//from ww w . j a va 2s . co m imageView.setAlpha(1f); } } animate = animate && UIUtils.hasICS(); if (animate) { int duration = getResources().getInteger(android.R.integer.config_shortAnimTime); Animator outAnimator = ObjectAnimator.ofFloat(imageView, View.ALPHA, 0f); outAnimator.setDuration(duration / 2); outAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { imageView.setImageResource(imageResId); } }); AnimatorSet inAnimator = new AnimatorSet(); inAnimator.setDuration(duration); inAnimator.playTogether(ObjectAnimator.ofFloat(imageView, View.ALPHA, 1f), ObjectAnimator.ofFloat(imageView, View.SCALE_X, 0f, 1f), ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 0f, 1f)); AnimatorSet set = new AnimatorSet(); set.playSequentially(outAnimator, inAnimator); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { imageView.setTag(null); } }); imageView.setTag(set); set.start(); } else { mHandler.post(new Runnable() { @Override public void run() { imageView.setImageResource(imageResId); } }); } }
From source file:despotoski.nikola.github.com.bottomnavigationlayout.BottomTabLayout.java
/** * @param position Position of the bottom tab to be removed (0 based) * @param removeAnimation Animation to be perfomed before tab being removed from its container */// w ww.j av a2 s.co m @TargetApi(Build.VERSION_CODES.HONEYCOMB) public void removeTabAt(final int position, @NonNull Animator removeAnimation) { ensureListenersList(); final View removedTab = mBottomTabViews.remove(position); if (removedTab != null) { removeAnimation.setTarget(removedTab); removeAnimation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { removeTabInternal(removedTab, position); } }); removeAnimation.start(); } }
From source file:com.stasbar.knowyourself.timer.TimerFragment.java
/** * @param timerToRemove the timer to be removed during the animation *//*from w w w .ja v a 2s. co m*/ private void animateTimerRemove(final Timer timerToRemove) { final long duration = UiDataModel.getUiDataModel().getShortAnimationDuration(); final Animator fadeOut = ObjectAnimator.ofFloat(mViewPager, ALPHA, 1, 0); fadeOut.setDuration(duration); fadeOut.setInterpolator(new DecelerateInterpolator()); fadeOut.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { LogUtils.d("animateTimerRemove"); DataModel.getDataModel().removeTimer(timerToRemove); } }); final Animator fadeIn = ObjectAnimator.ofFloat(mViewPager, ALPHA, 0, 1); fadeIn.setDuration(duration); fadeIn.setInterpolator(new AccelerateInterpolator()); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(fadeOut).before(fadeIn); animatorSet.start(); }
From source file:com.wizardsofm.deskclock.timer.TimerFragment.java
/** * @param toView one of {@link #mTimersView} or {@link #mCreateTimerView} * @param timerToRemove the timer to be removed during the animation; {@code null} if no timer * should be removed/*from ww w . j ava 2 s. c o m*/ */ private void animateToView(View toView, final Timer timerToRemove) { if (mCurrentView == toView) { throw new IllegalStateException("toView is already the current view"); } final boolean toTimers = toView == mTimersView; // Avoid double-taps by enabling/disabling the set of buttons active on the new view. updateFab(UpdateType.DISABLE_BUTTONS); final long duration = UiDataModel.getUiDataModel().getShortAnimationDuration(); final Animator rotateFrom = ObjectAnimator.ofFloat(mCurrentView, SCALE_X, 1, 0); rotateFrom.setDuration(duration); rotateFrom.setInterpolator(new DecelerateInterpolator()); rotateFrom.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (timerToRemove != null) { DataModel.getDataModel().removeTimer(timerToRemove); Events.sendTimerEvent(com.wizardsofm.deskclock.R.string.action_delete, com.wizardsofm.deskclock.R.string.label_deskclock); } mCurrentView.setScaleX(1); if (toTimers) { showTimersView(UpdateType.FAB_AND_BUTTONS_SHRINK_AND_EXPAND); } else { showCreateTimerView(UpdateType.FAB_AND_BUTTONS_SHRINK_AND_EXPAND); } } }); final Animator rotateTo = ObjectAnimator.ofFloat(toView, SCALE_X, 0, 1); rotateTo.setDuration(duration); rotateTo.setInterpolator(new AccelerateInterpolator()); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(rotateFrom).before(rotateTo); animatorSet.start(); }
From source file:org.goodev.material.SearchActivity.java
@OnClick({ R.id.scrim, R.id.searchback }) protected void dismiss() { int interpolator = UI.isLollipop() ? android.R.interpolator.fast_out_slow_in : android.R.interpolator.accelerate_decelerate; int backInterpolator = UI.isLollipop() ? android.R.interpolator.fast_out_linear_in : android.R.interpolator.accelerate_decelerate; // translate the icon to match position in the launching activity searchBackContainer.animate().translationX(searchBackDistanceX).setDuration(600L) .setInterpolator(AnimationUtils.loadInterpolator(this, interpolator)) .setListener(new AnimatorListenerAdapter() { @Override/*from w w w.j a v a 2s . co m*/ public void onAnimationEnd(Animator animation) { supportFinishAfterTransition(); } }).start(); if (UI.isLollipop()) { // transform from back icon to search icon AnimatedVectorDrawable backToSearch = (AnimatedVectorDrawable) ContextCompat.getDrawable(this, R.drawable.avd_back_to_search); searchBack.setImageDrawable(backToSearch); // clear the background else the touch ripple moves with the translation which looks bad searchBack.setBackground(null); backToSearch.start(); } // fade out the other search chrome searchView.animate().alpha(0f).setStartDelay(0L).setDuration(120L) .setInterpolator(AnimationUtils.loadInterpolator(this, backInterpolator)).setListener(null).start(); searchBackground.animate().alpha(0f).setStartDelay(300L).setDuration(160L) .setInterpolator(AnimationUtils.loadInterpolator(this, backInterpolator)).setListener(null).start(); if (UI.isLollipop()) { if (searchToolbar.getZ() != 0f) { searchToolbar.animate().z(0f).setDuration(600L) .setInterpolator(AnimationUtils.loadInterpolator(this, backInterpolator)).start(); } } // if we're showing search results, circular hide them if (UI.isLollipop() && resultsContainer.getHeight() > 0) { Animator closeResults = ViewAnimationUtils.createCircularReveal(resultsContainer, searchIconCenterX, 0, (float) Math.hypot(searchIconCenterX, resultsContainer.getHeight()), 0f); closeResults.setDuration(500L); closeResults.setInterpolator( AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.fast_out_slow_in)); closeResults.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { resultsContainer.setVisibility(View.INVISIBLE); } }); closeResults.start(); } // fade out the scrim scrim.animate().alpha(0f).setDuration(400L) .setInterpolator(AnimationUtils.loadInterpolator(this, backInterpolator)).setListener(null).start(); }
From source file:android.support.transition.Visibility.java
/** * The default implementation of this method does nothing. Subclasses * should override if they need to create an Animator when targets disappear. * The method should only be called by the Visibility class; it is * not intended to be called from external classes. * * @param sceneRoot The root of the transition hierarchy * @param startValues The target values in the start scene * @param startVisibility The target visibility in the start scene * @param endValues The target values in the end scene * @param endVisibility The target visibility in the end scene * @return An Animator to be started at the appropriate time in the * overall transition for this scene change. A null value means no animation * should be run./*from w ww .j a v a 2 s . c o m*/ */ @SuppressWarnings("UnusedParameters") public Animator onDisappear(ViewGroup sceneRoot, TransitionValues startValues, int startVisibility, TransitionValues endValues, int endVisibility) { if ((mMode & MODE_OUT) != MODE_OUT) { return null; } View startView = (startValues != null) ? startValues.view : null; View endView = (endValues != null) ? endValues.view : null; View overlayView = null; View viewToKeep = null; if (endView == null || endView.getParent() == null) { if (endView != null) { // endView was removed from its parent - add it to the overlay overlayView = endView; } else if (startView != null) { // endView does not exist. Use startView only under certain // conditions, because placing a view in an overlay necessitates // it being removed from its current parent if (startView.getParent() == null) { // no parent - safe to use overlayView = startView; } else if (startView.getParent() instanceof View) { View startParent = (View) startView.getParent(); TransitionValues startParentValues = getTransitionValues(startParent, true); TransitionValues endParentValues = getMatchedTransitionValues(startParent, true); VisibilityInfo parentVisibilityInfo = getVisibilityChangeInfo(startParentValues, endParentValues); if (!parentVisibilityInfo.mVisibilityChange) { overlayView = TransitionUtils.copyViewImage(sceneRoot, startView, startParent); } else if (startParent.getParent() == null) { int id = startParent.getId(); if (id != View.NO_ID && sceneRoot.findViewById(id) != null && mCanRemoveViews) { // no parent, but its parent is unparented but the parent // hierarchy has been replaced by a new hierarchy with the same id // and it is safe to un-parent startView overlayView = startView; } } } } } else { // visibility change if (endVisibility == View.INVISIBLE) { viewToKeep = endView; } else { // Becoming GONE if (startView == endView) { viewToKeep = endView; } else { overlayView = startView; } } } final int finalVisibility = endVisibility; if (overlayView != null && startValues != null) { // TODO: Need to do this for general case of adding to overlay int[] screenLoc = (int[]) startValues.values.get(PROPNAME_SCREEN_LOCATION); int screenX = screenLoc[0]; int screenY = screenLoc[1]; int[] loc = new int[2]; sceneRoot.getLocationOnScreen(loc); overlayView.offsetLeftAndRight((screenX - loc[0]) - overlayView.getLeft()); overlayView.offsetTopAndBottom((screenY - loc[1]) - overlayView.getTop()); final ViewGroupOverlayImpl overlay = ViewGroupUtils.getOverlay(sceneRoot); overlay.add(overlayView); Animator animator = onDisappear(sceneRoot, overlayView, startValues, endValues); if (animator == null) { overlay.remove(overlayView); } else { final View finalOverlayView = overlayView; animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { overlay.remove(finalOverlayView); } }); } return animator; } if (viewToKeep != null) { int originalVisibility = viewToKeep.getVisibility(); ViewUtils.setTransitionVisibility(viewToKeep, View.VISIBLE); Animator animator = onDisappear(sceneRoot, viewToKeep, startValues, endValues); if (animator != null) { DisappearListener disappearListener = new DisappearListener(viewToKeep, finalVisibility, true); animator.addListener(disappearListener); AnimatorUtils.addPauseListener(animator, disappearListener); addListener(disappearListener); } else { ViewUtils.setTransitionVisibility(viewToKeep, originalVisibility); } return animator; } return null; }