private void display(@Nullable final View view) { final int sourceWidth = current == downloadDetails ? expandedWidth : contractedWidth; final int targetWidth = view == downloadDetails ? expandedWidth : contractedWidth; if (current == view || current == null) { ViewGroup.LayoutParams layoutParams = getLayoutParams(); layoutParams.width = targetWidth; setLayoutParams(layoutParams); } else { ViewUtil.fadeOut(current, TRANSITION_MS); Animator anim = getWidthAnimator(sourceWidth, targetWidth); anim.start(); } if (view == null) { ViewUtil.fadeOut(this, TRANSITION_MS); } else { ViewUtil.fadeIn(this, TRANSITION_MS); ViewUtil.fadeIn(view, TRANSITION_MS); } current = view; }
@Override public void cancel() { if (mAnimatorMap.size() > 0) { HashMap<Animator, PropertyBundle> mAnimatorMapCopy = (HashMap<Animator, PropertyBundle>)mAnimatorMap.clone(); Set<Animator> animatorSet = mAnimatorMapCopy.keySet(); for (Animator runningAnim : animatorSet) { runningAnim.cancel(); } } mPendingAnimations.clear(); View v = mView.get(); if (v != null) { v.removeCallbacks(mAnimationStarter); } }
private void animatePropertyBy(int constantName, float startValue, float byValue) { if (this.mAnimatorMap.size() > 0) { Animator animatorToCancel = null; for (Animator runningAnim : this.mAnimatorMap.keySet()) { PropertyBundle bundle = (PropertyBundle) this.mAnimatorMap.get(runningAnim); if (bundle.cancel(constantName) && bundle.mPropertyMask == 0) { animatorToCancel = runningAnim; break; } } if (animatorToCancel != null) { animatorToCancel.cancel(); } } this.mPendingAnimations.add(new NameValuesHolder(constantName, startValue, byValue)); View v = (View) this.mView.get(); if (v != null) { v.removeCallbacks(this.mAnimationStarter); v.post(this.mAnimationStarter); } }
private void acceptConfirmationIn( View v ) { if( !this.opem ) return; this.callback( this.confirmationInCallback ); YoYo.with( Techniques.ZoomOut ) .duration( 400 ) .playOn( this.ivExamConfirmationInReject ); YoYo.with( Techniques.ZoomIn ) .duration( 400 ) .withListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { super.onAnimationStart(animation); ivExamConfirmationInAccept.setImageResource( R.drawable.ic_sentiment_satisfied_green_500_18dp ); } }) .playOn( this.ivExamConfirmationInAccept ) ; //Remover o evento this.ivExamConfirmationInReject.setOnClickListener( null ); this.ivExamConfirmationInAccept.setOnClickListener( null ); }
private void acceptConfirmationOut( View v ) { if( !this.opem ) return; this.callback( this.confirmationOutCallback ); YoYo.with( Techniques.ZoomOut ) .duration( 400 ) .playOn( this.ivExamConfirmationOutReject ); YoYo.with( Techniques.ZoomIn ) .duration( 400 ) .withListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { super.onAnimationStart(animation); ivExamConfirmationOutAccept.setImageResource( R.drawable.ic_sentiment_very_dissatisfied_red_500_18dp ); } }) .playOn( this.ivExamConfirmationOutAccept ) ; //Remover o evento this.ivExamConfirmationOutReject.setOnClickListener( null ); this.ivExamConfirmationOutAccept.setOnClickListener( null ); }
/** * Filling arrays of animations to build Set of Closing / Opening animations */ private void fillOpenClosingAnimations(boolean isCloseAnimation, List<Animator> textAnimations, List<Animator> imageAnimations, int wrapperPosition) { AnimatorSet textAnimatorSet = new AnimatorSet(); Animator textAppearance = isCloseAnimation ? AnimatorUtils.alfaDisappear(mTextWrapper.getChildAt(wrapperPosition)) : AnimatorUtils.alfaAppear(mTextWrapper.getChildAt(wrapperPosition)); Animator textTranslation = isCloseAnimation ? AnimatorUtils.translationRight(mTextWrapper.getChildAt(wrapperPosition), mContext.getResources().getDimension(R.dimen.text_right_translation)) : AnimatorUtils.translationLeft(mTextWrapper.getChildAt(wrapperPosition), mContext.getResources().getDimension(R.dimen.text_right_translation)); textAnimatorSet.playTogether(textAppearance, textTranslation); textAnimations.add(textAnimatorSet); Animator imageRotation = isCloseAnimation ? wrapperPosition == 0 ? AnimatorUtils.rotationCloseToRight(mMenuWrapper.getChildAt(wrapperPosition)) : AnimatorUtils.rotationCloseVertical(mMenuWrapper.getChildAt(wrapperPosition)) : wrapperPosition == 0 ? AnimatorUtils.rotationOpenFromRight(mMenuWrapper.getChildAt(wrapperPosition)) : AnimatorUtils.rotationOpenVertical(mMenuWrapper.getChildAt(wrapperPosition)); imageAnimations.add(imageRotation); }
private Animator getWidthAnimator(final int from, final int to) { final ValueAnimator anim = ValueAnimator.ofInt(from, to); anim.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { final int val = (Integer)animation.getAnimatedValue(); final ViewGroup.LayoutParams layoutParams = getLayoutParams(); layoutParams.width = val; setLayoutParams(layoutParams); } }); anim.setInterpolator(new FastOutSlowInInterpolator()); anim.setDuration(TRANSITION_MS); return anim; }
/** * Create dismiss animation * * @param view affected view * @param swap If will change state. If is "false" returns to the original position * @param swapRight If swap is true, this parameter tells if move is to the right or left * @param position Position of list */ private void generateDismissAnimate(final View view, final boolean swap, final boolean swapRight, final int position) { int moveTo = 0; if (opened.get(position)) { if (!swap) { moveTo = openedRight.get(position) ? (int) (viewWidth - rightOffset) : (int) (-viewWidth + leftOffset); } } else { if (swap) { moveTo = swapRight ? (int) (viewWidth - rightOffset) : (int) (-viewWidth + leftOffset); } } int alpha = 1; if (swap) { ++dismissAnimationRefCount; alpha = 0; } animate(view) .translationX(moveTo) .alpha(alpha) .setDuration(animationTime) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (swap) { closeOpenedItems(); performDismiss(view, position, true); } resetCell(); } }); }
/** * Create reveal animation * * @param view affected view * @param swap If will change state. If "false" returns to the original position * @param swapRight If swap is true, this parameter tells if movement is toward right or left * @param position list position */ private void generateRevealAnimate(final View view, final boolean swap, final boolean swapRight, final int position) { int moveTo = 0; if (opened.get(position)) { if (!swap) { moveTo = openedRight.get(position) ? (int) (viewWidth - rightOffset) : (int) (-viewWidth + leftOffset); } } else { if (swap) { moveTo = swapRight ? (int) (viewWidth - rightOffset) : (int) (-viewWidth + leftOffset); } } animate(view) .translationX(moveTo) .setDuration(animationTime) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { swipeListView.resetScrolling(); if (swap) { boolean aux = !opened.get(position); opened.set(position, aux); if (aux) { swipeListView.onOpened(position, swapRight); openedRight.set(position, swapRight); } else { swipeListView.onClosed(position, openedRight.get(position)); } } resetCell(); } }); }
/** * Perform dismiss action * * @param dismissView View * @param dismissPosition Position of list */ protected void performDismiss(final View dismissView, final int dismissPosition, boolean doPendingDismiss) { final ViewGroup.LayoutParams lp = dismissView.getLayoutParams(); final int originalHeight = dismissView.getHeight(); ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(animationTime); if (doPendingDismiss) { animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { --dismissAnimationRefCount; if (dismissAnimationRefCount == 0) { removePendingDismisses(originalHeight); } } }); } animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { lp.height = (Integer) valueAnimator.getAnimatedValue(); dismissView.setLayoutParams(lp); } }); pendingDismisses.add(new PendingDismissData(dismissPosition, dismissView)); animator.start(); }
private static Animator.AnimatorListener getRevealFinishListener(RevealAnimator target) { if (SDK_INT >= 18) { return new RevealAnimator.RevealFinishedJellyBeanMr2(target); } else if (SDK_INT >= 14) { return new RevealAnimator.RevealFinishedIceCreamSandwich(target); } else { return new RevealAnimator.RevealFinishedGingerbread(target); } }
@Override public void onAnimationEnd(Animator animation) { toggleIsAnimationRun(); if (mOnItemLongClickListenerCalled != null) { mOnItemLongClickListenerCalled.onLongClick(mClickedView); } else if (mOnItemClickListenerCalled != null) { mOnItemClickListenerCalled.onClick(mClickedView); } }
@Override public void setDuration(int duration) { Animator a = mAnimator.get(); if (a != null) { a.setDuration(duration); } }
@Override public void setInterpolator(Interpolator value) { Animator a = mAnimator.get(); if (a != null) { a.setInterpolator(value); } }
@Override public void cancel() { Animator a = mAnimator.get(); if (a != null) { a.cancel(); } }
@Override public void end() { Animator a = mAnimator.get(); if (a != null) { a.end(); } }
@Override public void setupStartValues() { Animator a = mAnimator.get(); if (a != null) { a.setupStartValues(); } }
@Override public void setupEndValues() { Animator a = mAnimator.get(); if (a != null) { a.setupEndValues(); } }
@Override public void onAnimationEnd(Animator animator) { if (playAfterEndAnimation) { playAfterEndAnimation = false; mAnimator.start(); } }
@Override public void onAnimationCancel(Animator animator) { if (playAfterEndAnimation) { playAfterEndAnimation = false; mAnimator.start(); } }
/** * Utility function, called by animateProperty() and animatePropertyBy(), which handles the * details of adding a pending animation and posting the request to start the animation. * * @param constantName The specifier for the property being animated * @param startValue The starting value of the property * @param byValue The amount by which the property will change */ private void animatePropertyBy(int constantName, float startValue, float byValue) { // First, cancel any existing animations on this property if (mAnimatorMap.size() > 0) { Animator animatorToCancel = null; Set<Animator> animatorSet = mAnimatorMap.keySet(); for (Animator runningAnim : animatorSet) { PropertyBundle bundle = mAnimatorMap.get(runningAnim); if (bundle.cancel(constantName)) { // property was canceled - cancel the animation if it's now empty // Note that it's safe to break out here because every new animation // on a property will cancel a previous animation on that property, so // there can only ever be one such animation running. if (bundle.mPropertyMask == NONE) { // the animation is no longer changing anything - cancel it animatorToCancel = runningAnim; break; } } } if (animatorToCancel != null) { animatorToCancel.cancel(); } } NameValuesHolder nameValuePair = new NameValuesHolder(constantName, startValue, byValue); mPendingAnimations.add(nameValuePair); View v = mView.get(); if (v != null) { v.removeCallbacks(mAnimationStarter); v.post(mAnimationStarter); } }
@Override public void onAnimationEnd(Animator animation) { if (mListener != null) { mListener.onAnimationEnd(animation); } mAnimatorMap.remove(animation); // If the map is empty, it means all animation are done or canceled, so the listener // isn't needed anymore. Not nulling it would cause it to leak any objects used in // its implementation if (mAnimatorMap.isEmpty()) { mListener = null; } }
private BaseViewAnimator play() { animator.setTarget(target); animator.setDuration(duration) .setInterpolator(interpolator) .setStartDelay(delay); if (callbacks.size() > 0) { for (Animator.AnimatorListener callback : callbacks) { animator.addAnimatorListener(callback); } } animator.animate(); return animator; }
@Override public void onAnimationEnd(Animator animation) { //clear(view); dispatchAddFinished(mViewHolder); mAddAnimations.remove(mViewHolder); dispatchFinishedWhenDone(); }
@Override public void onAnimationEnd(Animator animation) { //ViewHelper.clear(view); dispatchRemoveFinished(mViewHolder); mRemoveAnimations.remove(mViewHolder); dispatchFinishedWhenDone(); }
public void onAnimationEnd(Animator animation) { if (ViewPropertyAnimatorHC.this.mListener != null) { ViewPropertyAnimatorHC.this.mListener.onAnimationEnd(animation); } ViewPropertyAnimatorHC.this.mAnimatorMap.remove(animation); if (ViewPropertyAnimatorHC.this.mAnimatorMap.isEmpty()) { ViewPropertyAnimatorHC.this.mListener = null; } }
public void cancel() { if (this.mAnimatorMap.size() > 0) { for (Animator runningAnim : ((HashMap) this.mAnimatorMap.clone()).keySet()) { runningAnim.cancel(); } } this.mPendingAnimations.clear(); View v = (View) this.mView.get(); if (v != null) { v.removeCallbacks(this.mAnimationStarter); } }
public void onAnimationEnd(Animator animation) { if (ViewPropertyAnimatorPreHC.this.mListener != null) { ViewPropertyAnimatorPreHC.this.mListener.onAnimationEnd(animation); } ViewPropertyAnimatorPreHC.this.mAnimatorMap.remove(animation); if (ViewPropertyAnimatorPreHC.this.mAnimatorMap.isEmpty()) { ViewPropertyAnimatorPreHC.this.mListener = null; } }
/** * Create choice animation * * @param view affected view * @param position list position */ private void generateChoiceAnimate(final View view, final int position) { animate(view) .translationX(0) .setDuration(animationTime) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { swipeListView.resetScrolling(); resetCell(); } }); }
/** * Creates Open / Close AnimatorSet */ private AnimatorSet setOpenCloseAnimation(boolean isCloseAnimation) { List<Animator> textAnimations = new ArrayList<>(); List<Animator> imageAnimations = new ArrayList<>(); if (isCloseAnimation) { for (int i = getItemCount() - 1; i >= 0; i--) { fillOpenClosingAnimations(true, textAnimations, imageAnimations, i); } } else { for (int i = 0; i < getItemCount(); i++) { fillOpenClosingAnimations(false, textAnimations, imageAnimations, i); } } AnimatorSet textCloseAnimatorSet = new AnimatorSet(); textCloseAnimatorSet.playSequentially(textAnimations); AnimatorSet imageCloseAnimatorSet = new AnimatorSet(); imageCloseAnimatorSet.playSequentially(imageAnimations); AnimatorSet animatorFullSet = new AnimatorSet(); animatorFullSet.playTogether(imageCloseAnimatorSet, textCloseAnimatorSet); animatorFullSet.setDuration(mAnimationDurationMilis); animatorFullSet.addListener(mCloseOpenAnimatorListener); animatorFullSet.setStartDelay(0); animatorFullSet.setInterpolator(new HesitateInterpolator()); return animatorFullSet; }
private void anim(final View v) { ObjectAnimator animator = ObjectAnimator.ofFloat(v, "rotationX", 0.0F, 360.0F) .setDuration(200); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (!Utils.login()) { return; } switch (v.getId()) { case R.id.fun_all: v.getContext().startActivity(new Intent(v.getContext(), CategoryActivity.class)); break; case R.id.fun_combo: v.getContext().startActivity(new Intent(v.getContext(), CloudTcActivity.class)); break; case R.id.fun_charge: v.getContext().startActivity(new Intent(v.getContext(), PhoneChargeActivity.class)); break; case R.id.fun_wolrdgo: v.getContext().startActivity(new Intent(v.getContext(), CloudWorldGoActivity.class)); break; case R.id.fun_cloud_p: v.getContext().startActivity(new Intent(v.getContext(), CloudPointActivity.class)); break; case R.id.fun_omyo: v.getContext().startActivity(new Intent(v.getContext(), OMYOActivity.class)); break; case R.id.fun_cloud_club: v.getContext().startActivity(new Intent(v.getContext(), CloudClubActivity.class)); break; case R.id.fun_aboutus: v.getContext().startActivity(new Intent(v.getContext(), AboutUsActivity.class)); break; } } }); animator.start(); }
@Override public void onAnimationRepeat(Animator animation) { }