Java Code Examples for com.nineoldandroids.animation.ValueAnimator#addUpdateListener()

The following examples show how to use com.nineoldandroids.animation.ValueAnimator#addUpdateListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CardFaceView.java    From CardView with Apache License 2.0 6 votes vote down vote up
private void onFlagChanged(final CardFlag oldFlag, final CardFlag newFlag) {
	int flagColor = CARD_BACKGROUND_COLOR_NOFLAG;
	if (newFlag != null) {
		flagColor = newFlag.getColor();
	}
	
	ValueAnimator fade = ObjectAnimator.ofInt(mCardPaint,
			"color", mCardPaint.getColor(), flagColor);
	fade.setDuration(500);
	fade.setEvaluator(new ArgbEvaluator());
	fade.addUpdateListener(new AnimatorUpdateListener() {
		@Override
		public void onAnimationUpdate(ValueAnimator value) {
			onFlagChangedUpdate(oldFlag, newFlag, value);
			invalidate();
		}
	});
	
	fade.start();
}
 
Example 2
Source File: ExpandableListItemAdapter.java    From ListViewAnimations with Apache License 2.0 6 votes vote down vote up
public static ValueAnimator createHeightAnimator(final View view, final int start, final int end) {
    ValueAnimator animator = ValueAnimator.ofInt(start, end);
    animator.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {

                @Override
                public void onAnimationUpdate(final ValueAnimator animation) {
                    int value = (Integer) animation.getAnimatedValue();

                    LayoutParams layoutParams = view.getLayoutParams();
                    layoutParams.height = value;
                    view.setLayoutParams(layoutParams);
                }
            }
    );
    return animator;
}
 
Example 3
Source File: ContextualUndoAdapter.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
private void performRemovalIfNecessary() {
    if (mCurrentRemovedId == -1) {
        return;
    }

    ContextualUndoView currentRemovedView = getCurrentRemovedView(mCurrentRemovedView, mCurrentRemovedId);
    if (currentRemovedView != null) {
        ValueAnimator animator = ValueAnimator.ofInt(currentRemovedView.getHeight(), 1).setDuration(ANIMATION_DURATION);

        RemoveViewAnimatorListenerAdapter listener = new RemoveViewAnimatorListenerAdapter(currentRemovedView, mCurrentRemovedId);
        RemoveViewAnimatorUpdateListener updateListener = new RemoveViewAnimatorUpdateListener(listener);

        animator.addListener(listener);
        animator.addUpdateListener(updateListener);
        animator.start();
    } else {
        // The hard way.
        deleteItemGivenId(mCurrentRemovedId);
    }
    clearCurrentRemovedView();
}
 
Example 4
Source File: SwipeDismissListViewTouchListener.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
protected void performDismiss(final PendingDismissData data) {
    // Animate the dismissed list item to zero-height and fire the
    // dismiss callback when all dismissed list item animations have
    // completed.

    final ViewGroup.LayoutParams lp = data.view.getLayoutParams();
    final int originalHeight = data.view.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(final ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            data.view.setLayoutParams(lp);
        }
    });

    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(final Animator animation) {
            finalizeDismiss();
        }
    });
    animator.start();
}
 
Example 5
Source File: ViewPagerTabFragmentParentFragment.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
private void animateToolbar(final float toY) {
    float layoutTranslationY = ViewHelper.getTranslationY(mInterceptionLayout);
    if (layoutTranslationY != toY) {
        ValueAnimator animator = ValueAnimator.ofFloat(ViewHelper.getTranslationY(mInterceptionLayout), toY).setDuration(200);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float translationY = (float) animation.getAnimatedValue();
                View toolbarView = getActivity().findViewById(R.id.toolbar);
                ViewHelper.setTranslationY(mInterceptionLayout, translationY);
                ViewHelper.setTranslationY(toolbarView, translationY);
                if (translationY < 0) {
                    FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mInterceptionLayout.getLayoutParams();
                    lp.height = (int) (-translationY + getScreenHeight());
                    mInterceptionLayout.requestLayout();
                }
            }
        });
        animator.start();
    }
}
 
Example 6
Source File: DemoActivity_1.java    From android-art-res with Apache License 2.0 6 votes vote down vote up
private void performAnimate(final View target, final int start, final int end) {
    ValueAnimator valueAnimator = ValueAnimator.ofInt(1, 100);
    valueAnimator.addUpdateListener(new AnimatorUpdateListener() {

        // 持有一个IntEvaluator对象,方便下面估值的时候使用
        private IntEvaluator mEvaluator = new IntEvaluator();

        @Override
        public void onAnimationUpdate(ValueAnimator animator) {
            // 获得当前动画的进度值,整型,1-100之间
            int currentValue = (Integer) animator.getAnimatedValue();
            Log.d(TAG, "current value: " + currentValue);

            // 获得当前进度占整个动画过程的比例,浮点型,0-1之间
            float fraction = animator.getAnimatedFraction();
            // 直接调用整型估值器通过比例计算出宽度,然后再设给Button
            target.getLayoutParams().width = mEvaluator.evaluate(fraction, start, end);
            target.requestLayout();
        }
    });

    valueAnimator.setDuration(5000).start();
}
 
Example 7
Source File: SwipeDismissTouchListener.java    From Pimp_my_Z1 with GNU General Public License v2.0 5 votes vote down vote up
private void performDismiss() {
	// Animate the dismissed view to zero-height and then fire the dismiss
	// callback.
	// This triggers layout on each animation frame; in the future we may
	// want to do something
	// smarter and more performant.

	final ViewGroup.LayoutParams lp = mView.getLayoutParams();
	final int originalHeight = mView.getHeight();

	ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1)
			.setDuration(mAnimationTime);

	animator.addListener(new AnimatorListenerAdapter() {
		@Override
		public void onAnimationEnd(Animator animation) {
			mCallback.onDismiss(mView, mToken);
			// Reset view presentation
			setAlpha(mView, 1f);
			ViewHelper.setTranslationX(mView, 0);
			// mView.setAlpha(1f);
			// mView.setTranslationX(0);
			lp.height = originalHeight;
			mView.setLayoutParams(lp);
		}
	});

	animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
		@Override
		public void onAnimationUpdate(ValueAnimator valueAnimator) {
			lp.height = (Integer) valueAnimator.getAnimatedValue();
			mView.setLayoutParams(lp);
		}
	});

	animator.start();
}
 
Example 8
Source File: ExpandableListItemAdapter.java    From ALLGO with Apache License 2.0 5 votes vote down vote up
public static ValueAnimator createHeightAnimator(final View view, int start, int end) {
	ValueAnimator animator = ValueAnimator.ofInt(start, end);
	animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

		@Override
		public void onAnimationUpdate(ValueAnimator valueAnimator) {
			int value = (Integer) valueAnimator.getAnimatedValue();

			ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
			layoutParams.height = value;
			view.setLayoutParams(layoutParams);
		}
	});
	return animator;
}
 
Example 9
Source File: AnimateAdditionAdapter.java    From ListViewAnimations with Apache License 2.0 5 votes vote down vote up
@Override
@NonNull
public View getView(final int position, @Nullable final View convertView, @NonNull final ViewGroup parent) {
    final View view = super.getView(position, convertView, parent);

    if (mInsertQueue.getActiveIndexes().contains(position)) {
        int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams.MATCH_PARENT, View.MeasureSpec.AT_MOST);
        int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams.WRAP_CONTENT, View.MeasureSpec.UNSPECIFIED);
        view.measure(widthMeasureSpec, heightMeasureSpec);

        int originalHeight = view.getMeasuredHeight();

        ValueAnimator heightAnimator = ValueAnimator.ofInt(1, originalHeight);
        heightAnimator.addUpdateListener(new HeightUpdater(view));

        Animator[] customAnimators = getAdditionalAnimators(view, parent);
        Animator[] animators = new Animator[customAnimators.length + 1];
        animators[0] = heightAnimator;
        System.arraycopy(customAnimators, 0, animators, 1, customAnimators.length);

        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(animators);

        ViewHelper.setAlpha(view, 0);
        ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(view, ALPHA, 0, 1);

        AnimatorSet allAnimatorsSet = new AnimatorSet();
        allAnimatorsSet.playSequentially(animatorSet, alphaAnimator);

        allAnimatorsSet.setDuration(mInsertionAnimationDurationMs);
        allAnimatorsSet.addListener(new ExpandAnimationListener(position));
        allAnimatorsSet.start();
    }

    return view;
}
 
Example 10
Source File: SlidingUpBaseActivity.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
private void slideWithAnimation(float toY) {
    float layoutTranslationY = ViewHelper.getTranslationY(mInterceptionLayout);
    if (layoutTranslationY != toY) {
        ValueAnimator animator = ValueAnimator.ofFloat(ViewHelper.getTranslationY(mInterceptionLayout), toY).setDuration(200);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                slideTo((float) animation.getAnimatedValue(), true);
            }
        });
        animator.start();
    }
}
 
Example 11
Source File: ExpandableListItemAdapter.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
public static void animateExpanding(final View view, final AbsListView listView) {
    view.setVisibility(View.VISIBLE);

    View parent = (View) view.getParent();
    final int widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getMeasuredWidth() - parent.getPaddingLeft() - parent.getPaddingRight(), View.MeasureSpec.AT_MOST);
    final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    view.measure(widthSpec, heightSpec);

    ValueAnimator animator = createHeightAnimator(view, 0, view.getMeasuredHeight());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        final int listViewHeight = listView.getHeight();
        final int listViewBottomPadding = listView.getPaddingBottom();
        final View v = findDirectChild(view, listView);

        @Override
        public void onAnimationUpdate(final ValueAnimator valueAnimator) {
            final int bottom = v.getBottom();
            if (bottom > listViewHeight) {
                final int top = v.getTop();
                if (top > 0) {
                    listView.smoothScrollBy(Math.min(bottom - listViewHeight + listViewBottomPadding, top), 0);
                }
            }
        }
    });
    animator.start();
}
 
Example 12
Source File: RoundProgressBar.java    From Conquer with Apache License 2.0 5 votes vote down vote up
/**
     * 设置进度,此为线程安全控件,由于考虑多线的问题,需要同步 刷新界面调用postInvalidate()能在非UI线程刷新
     *
     * @param progress
     */

    public synchronized void setProgress(int progress) {
        if (this.progress == progress) {
            return;
        }

//        hasShowing = true;
        if (progress < 0) {
//			throw new IllegalArgumentException("progress not less than 0");
            return;
        }
        if (progress > max) {
            progress = max;
        }
        ValueAnimator va = ValueAnimator.ofInt(this.progress, progress);
        va.setDuration(1000);
        va.setInterpolator(new AccelerateInterpolator());
        va.start();
        va.addUpdateListener(new AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator arg0) {
                int value = (Integer) arg0.getAnimatedValue();
                if (value <= max) {
                    RoundProgressBar.this.progress = value;
                    invalidate();
                }
            }
        });

    }
 
Example 13
Source File: TransferControlView.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 14
Source File: SwipeDismissList.java    From sms-ticket with Apache License 2.0 5 votes vote down vote up
private void performDismiss(final View dismissView, final int dismissPosition) {
    // Animate the dismissed list item to zero-height and notifyTicket the dismiss callback when
    // all dismissed list item animations have completed. This triggers layout on each animation
    // frame; in the future we may want to do something smarter and more performant.
    mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));

    if (dismissView != null) {
        final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
        final int originalHeight = dismissView.getHeight();

        ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                finishDismiss(originalHeight);
            }
        });

        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                lp.height = (Integer) valueAnimator.getAnimatedValue();
                dismissView.setLayoutParams(lp);
            }
        });
        animator.start();
    } else {
        finishDismiss(0);
    }
}
 
Example 15
Source File: AnimatedDrawable.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ValueAnimator createValueAnimator() {
  int loopCount = mAnimatedDrawableBackend.getLoopCount();
  ValueAnimator animator = new ValueAnimator();
  animator.setIntValues(0, mDurationMs);
  animator.setDuration(mDurationMs);
  animator.setRepeatCount(loopCount != 0 ? loopCount : ValueAnimator.INFINITE);
  animator.setRepeatMode(ValueAnimator.RESTART);
  animator.setInterpolator(new LinearInterpolator());
  animator.addUpdateListener(createAnimatorUpdateListener());
  return animator;
}
 
Example 16
Source File: BGARefreshLayout.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 设置下拉刷新控件的paddingTop到0,带动画
 */
private void changeRefreshHeaderViewToZero() {
    ValueAnimator animator = ValueAnimator.ofInt(mWholeHeaderView.getPaddingTop(), 0);
    animator.setDuration(mRefreshViewHolder.getTopAnimDuration());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int paddingTop = (int) animation.getAnimatedValue();
            mWholeHeaderView.setPadding(0, paddingTop, 0, 0);
        }
    });
    animator.start();
}
 
Example 17
Source File: BGARefreshLayout.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
public void startChangeWholeHeaderViewPaddingTop(int distance) {
    ValueAnimator animator = ValueAnimator.ofInt(mWholeHeaderView.getPaddingTop(), mWholeHeaderView.getPaddingTop() - distance);
    animator.setDuration(mRefreshViewHolder.getTopAnimDuration());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int paddingTop = (int) animation.getAnimatedValue();
            mWholeHeaderView.setPadding(0, paddingTop, 0, 0);
        }
    });
    animator.start();
}
 
Example 18
Source File: ExpandableListItemAdapter.java    From ListViewAnimations with Apache License 2.0 5 votes vote down vote up
public static void animateExpanding(@NonNull final View view, @NonNull final ListViewWrapper listViewWrapper) {
    view.setVisibility(View.VISIBLE);

    View parent = (View) view.getParent();
    final int widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getMeasuredWidth() - parent.getPaddingLeft() - parent.getPaddingRight(), View.MeasureSpec.AT_MOST);
    final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    view.measure(widthSpec, heightSpec);

    ValueAnimator animator = createHeightAnimator(view, 0, view.getMeasuredHeight());
    animator.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {
                final int listViewHeight = listViewWrapper.getListView().getHeight();
                final int listViewBottomPadding = listViewWrapper.getListView().getPaddingBottom();
                final View v = findDirectChild(view, listViewWrapper.getListView());

                @Override
                public void onAnimationUpdate(final ValueAnimator animation) {
                    final int bottom = v.getBottom();
                    if (bottom > listViewHeight) {
                        final int top = v.getTop();
                        if (top > 0) {
                            listViewWrapper.smoothScrollBy(Math.min(bottom - listViewHeight + listViewBottomPadding, top), 0);
                        }
                    }
                }
            }
    );
    animator.start();
}
 
Example 19
Source File: SwipeDismissTouchListener.java    From SimplePomodoro-android with MIT License 5 votes vote down vote up
private void performDismiss() {
    // Animate the dismissed view to zero-height and then fire the dismiss callback.
    // This triggers layout on each animation frame; in the future we may want to do something
    // smarter and more performant.

    final ViewGroup.LayoutParams lp = mView.getLayoutParams();
    final int originalHeight = mView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mCallback.onDismiss(mView, mToken);
            // Reset view presentation
            setAlpha(mView, 1f);
            setTranslationX(mView, 0);
            lp.height = originalHeight;
            mView.setLayoutParams(lp);
        }
    });

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            mView.setLayoutParams(lp);
        }
    });

    animator.start();
}
 
Example 20
Source File: LrcView.java    From DMusic with Apache License 2.0 4 votes vote down vote up
private void initAnim() {
    mAnimation = new ValueAnimator();
    mAnimation.setInterpolator(new LinearInterpolator());
    mAnimation.addUpdateListener(new UpdateListener(this));
}