List of usage examples for android.animation Animator addListener
public void addListener(AnimatorListener listener)
From source file:com.example.mego.adas.directions.ui.DirectionsFragment.java
/** * method to hide edit text with animation */// w ww .j a v a2 s . co m private void hideEditText(final LinearLayout view) { int cx = view.getRight() - 30; int cy = view.getBottom() - 60; int initialRadius = view.getWidth(); Animator anim = null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, initialRadius, 0); } if (anim != null) { anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); view.setVisibility(View.INVISIBLE); } }); } isEditTextVisible = false; if (anim != null) { anim.start(); } }
From source file:com.android.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// www.j ava 2 s . c om */ 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. mLeftButton.setEnabled(toTimers); mRightButton.setEnabled(toTimers); mCancelCreateButton.setEnabled(!toTimers); final Animator rotateFrom = ObjectAnimator.ofFloat(mCurrentView, SCALE_X, 1, 0); rotateFrom.setDuration(mShortAnimationDuration); 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(); } else { showCreateTimerView(); } } }); final Animator rotateTo = ObjectAnimator.ofFloat(toView, SCALE_X, 0, 1); rotateTo.setDuration(mShortAnimationDuration); rotateTo.setInterpolator(new AccelerateInterpolator()); final float preScale = toTimers ? 0 : 1; final float postScale = toTimers ? 1 : 0; final Animator fabAnimator = getScaleAnimator(mFab, preScale, postScale); final Animator leftButtonAnimator = getScaleAnimator(mLeftButton, preScale, postScale); final Animator rightButtonAnimator = getScaleAnimator(mRightButton, preScale, postScale); final AnimatorSet buttons = new AnimatorSet(); buttons.setDuration(toTimers ? mMediumAnimationDuration : mShortAnimationDuration); buttons.play(leftButtonAnimator).with(rightButtonAnimator).with(fabAnimator); buttons.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mLeftButton.setVisibility(toTimers ? VISIBLE : INVISIBLE); mRightButton.setVisibility(toTimers ? VISIBLE : INVISIBLE); mFab.setScaleX(1); mFab.setScaleY(1); mLeftButton.setScaleX(1); mLeftButton.setScaleY(1); mRightButton.setScaleX(1); mRightButton.setScaleY(1); } }); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(rotateFrom).before(rotateTo).with(buttons); animatorSet.start(); }
From source file:com.gdgdevfest.android.apps.devfestbcn.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 w w w .j ava 2 s.c o 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(); outAnimator.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:com.itsronald.widget.IndicatorDotPathView.java
@NonNull private Animator retreatCenterSegmentAnimator(final float toX, final float toY, final long animationDuration) { final float originalScale = 1, scaleX = 0, scaleY = 1; final Animator animator = scaleAnimator(centerSegment, originalScale, scaleX, scaleY); // Choose the corner of the view farthest from the destination location. final float originalPivotX = getPivotX(); final float originalPivotY = getPivotY(); final float pivotX = Math.max(0, Math.min(toX, centerSegment.getWidth())); final float pivotY = Math.max(0, Math.min(toY, centerSegment.getHeight())); animator.addListener(new AnimatorListenerAdapter() { @Override/*from w w w .j a v a2 s . c o m*/ public void onAnimationStart(Animator animation) { super.onAnimationStart(animation); centerSegment.setPivotX(pivotX); centerSegment.setPivotY(pivotY); } @Override public void onAnimationEnd(Animator animation) { // Reset values. centerSegment.setVisibility(INVISIBLE); centerSegment.setScaleX(originalScale); centerSegment.setScaleY(originalScale); centerSegment.setPivotX(originalPivotX); centerSegment.setPivotY(originalPivotY); } }); animator.setDuration(animationDuration); return animator; }
From source file:com.androidinspain.deskclock.timer.TimerFragment.java
/** * @param timerToRemove the timer to be removed during the animation *///w ww. j ava 2 s . 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) { DataModel.getDataModel().removeTimer(timerToRemove); Events.sendTimerEvent(com.androidinspain.deskclock.R.string.action_delete, com.androidinspain.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:com.taobao.weex.dom.action.AnimationAction.java
private void startAnimation(@NonNull WXSDKInstance instance, @Nullable WXComponent component) { if (component != null) { if (component.getHostView() == null) { WXAnimationModule.AnimationHolder holder = new WXAnimationModule.AnimationHolder(mAnimationBean, callback);//from w ww. ja v a 2 s. c om component.postAnimation(holder); } else { try { Animator animator = createAnimator(component.getHostView(), instance.getInstanceViewPortWidth()); if (animator != null) { Animator.AnimatorListener animatorCallback = createAnimatorListener(instance, callback); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2 && component.isLayerTypeEnabled()) { component.getHostView().setLayerType(View.LAYER_TYPE_HARDWARE, null); } Interpolator interpolator = createTimeInterpolator(); if (animatorCallback != null) { animator.addListener(animatorCallback); } if (interpolator != null) { animator.setInterpolator(interpolator); } animator.setDuration(mAnimationBean.duration); animator.start(); } } catch (RuntimeException e) { WXLogUtils.e(TAG, WXLogUtils.getStackTrace(e)); } } } }
From source file:com.github.huajianjiang.expandablerecyclerview.sample.anim.CircularRevealItemAnimator.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) private void animateRemoveImpl(final RecyclerView.ViewHolder holder) { final View view = holder.itemView; // final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view); mRemoveAnimations.add(holder);// www . j a va2 s. co m // get the center for the clipping circle int cx = (view.getLeft() + view.getRight()) / 2; int cy = view.getHeight() / 2; // get the initial radius for the clipping circle int initialRadius = view.getWidth(); // create the animation (the final radius is zero) final Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, initialRadius, 0); anim.setDuration(getRemoveDuration()); // make the view invisible when the animation is done anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { dispatchAddStarting(holder); } @Override public void onAnimationEnd(Animator animation) { anim.removeListener(this); view.setVisibility(View.VISIBLE); dispatchRemoveFinished(holder); mRemoveAnimations.remove(holder); dispatchFinishedWhenDone(); } }); // start the animation anim.start(); // animation.setDuration(getRemoveDuration()) // .alpha(0).setListener(new CircularRevealItemAnimator.VpaListenerAdapter() { // @Override // public void onAnimationStart(View view) { // dispatchRemoveStarting(holder); // } // // @Override // public void onAnimationEnd(View view) { // animation.setListener(null); // ViewCompat.setAlpha(view, 1); // dispatchRemoveFinished(holder); // mRemoveAnimations.remove(holder); // dispatchFinishedWhenDone(); // } // }).start(); }
From source file:com.taobao.weex.ui.action.GraphicActionAnimation.java
private void startAnimation(@NonNull WXSDKInstance instance, @Nullable WXComponent component) { if (component != null) { if (mAnimationBean != null) { component.setNeedLayoutOnAnimation(mAnimationBean.needLayout); }/*from w ww .ja va 2 s . com*/ if (component.getHostView() == null) { WXAnimationModule.AnimationHolder holder = new WXAnimationModule.AnimationHolder(mAnimationBean, callback); component.postAnimation(holder); } else { try { Animator animator = createAnimator(component.getHostView(), instance.getInstanceViewPortWidth()); if (animator != null) { Animator.AnimatorListener animatorCallback = createAnimatorListener(instance, callback); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2 && component.isLayerTypeEnabled()) { component.getHostView().setLayerType(View.LAYER_TYPE_HARDWARE, null); } Interpolator interpolator = createTimeInterpolator(); if (animatorCallback != null) { animator.addListener(animatorCallback); } if (interpolator != null) { animator.setInterpolator(interpolator); } component.getHostView().setCameraDistance(mAnimationBean.styles.getCameraDistance()); animator.setDuration(mAnimationBean.duration); animator.start(); } } catch (RuntimeException e) { WXLogUtils.e(TAG, WXLogUtils.getStackTrace(e)); } } } }
From source file:com.androidinspain.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 . jav a2s .c o m * @param animateDown {@code true} if the views should animate upwards, otherwise downwards */ private void animateToView(final View toView, final Timer timerToRemove, final boolean animateDown) { if (mCurrentView == toView) { return; } final boolean toTimers = toView == mTimersView; if (toTimers) { mTimersView.setVisibility(VISIBLE); } else { mCreateTimerView.setVisibility(VISIBLE); } // Avoid double-taps by enabling/disabling the set of buttons active on the new view. updateFab(BUTTONS_DISABLE); final long animationDuration = UiDataModel.getUiDataModel().getLongAnimationDuration(); final ViewTreeObserver viewTreeObserver = toView.getViewTreeObserver(); viewTreeObserver.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { if (viewTreeObserver.isAlive()) { viewTreeObserver.removeOnPreDrawListener(this); } final View view = mTimersView.findViewById(com.androidinspain.deskclock.R.id.timer_time); final float distanceY = view != null ? view.getHeight() + view.getY() : 0; final float translationDistance = animateDown ? distanceY : -distanceY; toView.setTranslationY(-translationDistance); mCurrentView.setTranslationY(0f); toView.setAlpha(0f); mCurrentView.setAlpha(1f); final Animator translateCurrent = ObjectAnimator.ofFloat(mCurrentView, TRANSLATION_Y, translationDistance); final Animator translateNew = ObjectAnimator.ofFloat(toView, TRANSLATION_Y, 0f); final AnimatorSet translationAnimatorSet = new AnimatorSet(); translationAnimatorSet.playTogether(translateCurrent, translateNew); translationAnimatorSet.setDuration(animationDuration); translationAnimatorSet.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN); final Animator fadeOutAnimator = ObjectAnimator.ofFloat(mCurrentView, ALPHA, 0f); fadeOutAnimator.setDuration(animationDuration / 2); fadeOutAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { super.onAnimationStart(animation); // The fade-out animation and fab-shrinking animation should run together. updateFab(FAB_AND_BUTTONS_SHRINK); } @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); if (toTimers) { showTimersView(FAB_AND_BUTTONS_EXPAND); // Reset the state of the create view. mCreateTimerView.reset(); } else { showCreateTimerView(FAB_AND_BUTTONS_EXPAND); } if (timerToRemove != null) { DataModel.getDataModel().removeTimer(timerToRemove); Events.sendTimerEvent(com.androidinspain.deskclock.R.string.action_delete, com.androidinspain.deskclock.R.string.label_deskclock); } // Update the fab and button states now that the correct view is visible and // before the animation to expand the fab and buttons starts. updateFab(FAB_AND_BUTTONS_IMMEDIATE); } }); final Animator fadeInAnimator = ObjectAnimator.ofFloat(toView, ALPHA, 1f); fadeInAnimator.setDuration(animationDuration / 2); fadeInAnimator.setStartDelay(animationDuration / 2); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(fadeOutAnimator, fadeInAnimator, translationAnimatorSet); animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); mTimersView.setTranslationY(0f); mCreateTimerView.setTranslationY(0f); mTimersView.setAlpha(1f); mCreateTimerView.setAlpha(1f); } }); animatorSet.start(); return true; } }); }
From source file:com.pitchedapps.primenumbercalculator.Calculator.java
License:asdf
void exitReveal(View view) { // previously visible view final View myView = view; // get the initial radius for the clipping circle int initialRadius = Math.max(myView.getWidth(), myView.getHeight()); // create the animation (the final radius is zero) Animator anim = ViewAnimationUtils.createCircularReveal(myView, x, y, initialRadius, 0).setDuration(600); // make the view invisible when the animation is done anim.addListener(new AnimatorListenerAdapter() { @Override//from w ww.j a v a2 s . co m public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); myView.setVisibility(View.INVISIBLE); } }); // start the animation anim.start(); }