Example usage for android.animation ValueAnimator addUpdateListener

List of usage examples for android.animation ValueAnimator addUpdateListener

Introduction

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

Prototype

public void addUpdateListener(AnimatorUpdateListener listener) 

Source Link

Document

Adds a listener to the set of listeners that are sent update events through the life of an animation.

Usage

From source file:com.insalyon.les24heures.view.DrawerArrowDrawable.java

public void animateToSandwich() {
    final DrawerArrowDrawable self = this;
    ValueAnimator animation = ValueAnimator.ofFloat(1f, 0f);
    animation.setDuration(500);//from w  w w. j  a v a  2 s.com
    animation.start();
    animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            self.setParameter((Float) animation.getAnimatedValue());
        }
    });
    this.setParameter(0);
}

From source file:com.insalyon.les24heures.view.DrawerArrowDrawable.java

public void animateToArrow() {
    final DrawerArrowDrawable self = this;
    ValueAnimator animation = ValueAnimator.ofFloat(0f, 1f);
    animation.setDuration(500);//from ww w .j a v  a  2 s .  com
    animation.start();
    animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            self.setParameter((Float) animation.getAnimatedValue());
        }
    });

    this.setFlip(true);
}

From source file:com.liujs.library.view.refresh.BGAStickinessRefreshView.java

public void smoothToIdle() {
    ValueAnimator animator = ValueAnimator.ofInt(mCurrentBottomHeight, 0);
    animator.setDuration(mStickinessRefreshViewHolder.getTopAnimDuration());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override// ww  w . j  ava  2 s .  com
        public void onAnimationUpdate(ValueAnimator animation) {
            mCurrentBottomHeight = (int) animation.getAnimatedValue();
            postInvalidate();
        }
    });
    animator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mIsRotating = false;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }
    });
    animator.start();
}

From source file:com.liujs.library.view.refresh.BGAStickinessRefreshView.java

public void startRefreshing() {
    ValueAnimator animator = ValueAnimator.ofInt(mCurrentBottomHeight, 0);
    animator.setDuration(mStickinessRefreshViewHolder.getTopAnimDuration());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override//from ww  w. j a  va 2s . c  o m
        public void onAnimationUpdate(ValueAnimator animation) {
            mCurrentBottomHeight = (int) animation.getAnimatedValue();
            postInvalidate();
        }
    });
    animator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
            mIsRefreshing = true;
            if (mCurrentBottomHeight != 0) {
                mStickinessRefreshViewHolder.startChangeWholeHeaderViewPaddingTop(mCurrentBottomHeight);
            } else {
                mStickinessRefreshViewHolder.startChangeWholeHeaderViewPaddingTop(
                        -(mTopSize + getPaddingTop() + getPaddingBottom()));
            }
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mIsRotating = true;
            startRotating();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }
    });
    animator.start();
}

From source file:com.rong.library.widget.mapsearchbar.MapSearchBar.java

private void animateSuggestionList(int from, int to) {
    suggestionsVisible = (to > 0);/*from w  w w.ja  va  2  s.  c  o m*/

    final ViewGroup.LayoutParams lp = containerSuggestion.getLayoutParams();
    if (to == 0 && lp.height == 0)
        return; // already collapsed

    if (to == 0)
        from = lp.height;

    ValueAnimator animator = ValueAnimator.ofInt(from, to);
    animator.setDuration(200);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            lp.height = (int) animation.getAnimatedValue();
            containerSuggestion.setLayoutParams(lp);
        }
    });

    animator.start();
}

From source file:com.jungle.toolbaractivity.layout.HorizontalSwipeBackLayout.java

private void continueAnimation(float horzOffset, int width) {
    ValueAnimator animator = ValueAnimator.ofFloat(horzOffset, width);
    animator.setInterpolator(new AccelerateInterpolator());
    animator.setDuration((long) (150 * Math.abs(width - horzOffset) / width));
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override//from w  ww .  j a  v a  2  s  .  c  o m
        public void onAnimationUpdate(ValueAnimator animation) {
            float value = (float) animation.getAnimatedValue();
            updateSlideOffset(value);
        }
    });

    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            if (mSlideListener != null) {
                mSlideListener.onSlideFinished();
            }
        }
    });

    animator.start();
}

From source file:com.velli.passwordmanager.ActivityMain.java

public boolean lockDrawer(final boolean lock, boolean animate) {
    final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    boolean locked = isDrawerLocked();

    if (drawer != null && lock != locked) {
        if (lock) {
            drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        } else {//from   w w  w  .  j  av  a 2 s  .co m
            drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
            if (!animate) {
                initDrawer();
            }
        }

        if (animate) {
            final ValueAnimator anim = ValueAnimator.ofFloat(lock ? 0 : 1, lock ? 1 : 0);
            anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    float slideOffset = (Float) valueAnimator.getAnimatedValue();
                    mToolbarDrawerToggle.onDrawerSlide(drawer, slideOffset);
                }
            });
            anim.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    anim.removeAllUpdateListeners();
                    if (!lock) {
                        initDrawer();
                    }
                    animation.removeAllListeners();
                }
            });
            anim.setInterpolator(new DecelerateInterpolator());
            anim.setDuration(500);
            anim.start();
        } else {
            mToolbarDrawerToggle.onDrawerSlide(drawer, lock ? 1 : 0);

        }
        return true;
    }
    return false;
}

From source file:org.digitalcampus.oppia.activity.CourseIndexActivity.java

private void initializeCourseIndex(boolean animate) {

    final ListView listView = (ListView) findViewById(R.id.section_list);
    if (listView == null)
        return;//from ww w. jav a  2  s .  co  m
    ViewCompat.setNestedScrollingEnabled(listView, true);
    sla = new SectionListAdapter(CourseIndexActivity.this, course, sections,
            new SectionListAdapter.CourseClickListener() {
                @Override
                public void onActivityClicked(String activityDigest) {
                    startCourseActivityByDigest(activityDigest);
                }
            });

    if (animate) {
        AlphaAnimation fadeOutAnimation = new AlphaAnimation(1f, 0f);
        fadeOutAnimation.setDuration(700);
        fadeOutAnimation.setFillAfter(true);

        listView.setAlpha(0f);
        ValueAnimator animator = ValueAnimator.ofFloat(1f, 0f);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                listView.setTranslationX((Float) valueAnimator.getAnimatedValue() * 80);
                listView.setAlpha(1f - (Float) valueAnimator.getAnimatedValue());
            }
        });
        animator.setDuration(700);
        animator.start();
        loadingCourseView.startAnimation(fadeOutAnimation);

    } else {
        loadingCourseView.setVisibility(View.GONE);
        listView.setVisibility(View.VISIBLE);
    }

    listView.setAdapter(sla);
}

From source file:arun.com.chromer.browsing.article.view.ElasticDragDismissFrameLayout.java

@Override
public void onStopNestedScroll(View child) {
    if (enabled) {
        if (Math.abs(totalDrag) >= dragDismissDistance) {
            dispatchDismissCallback();//from w  w w  . ja  va  2 s .  com
        } else { // settle back to natural position
            if (fastOutSlowInInterpolator == null) {
                fastOutSlowInInterpolator = AnimationUtils.loadInterpolator(getContext(),
                        android.R.interpolator.fast_out_slow_in);
            }
            getChildAt(0).animate().translationY(0f).scaleX(1f).scaleY(1f).setDuration(200L)
                    .setInterpolator(fastOutSlowInInterpolator).setListener(null).start();

            ValueAnimator animator = null;
            if (draggingUp) {
                animator = ValueAnimator.ofFloat(draggingBackground.top, draggingBackground.bottom);
                animator.addUpdateListener(valueAnimator -> {
                    draggingBackground.top = (float) valueAnimator.getAnimatedValue();
                    invalidate();
                });
            } else if (draggingDown) {
                animator = ValueAnimator.ofFloat(draggingBackground.bottom, draggingBackground.top);
                animator.addUpdateListener(valueAnimator -> {
                    draggingBackground.bottom = (float) valueAnimator.getAnimatedValue();
                    invalidate();
                });
            }

            if (animator != null) {
                animator.setInterpolator(fastOutSlowInInterpolator);
                animator.setDuration(200L);
                animator.start();
            }

            totalDrag = 0;
            draggingDown = draggingUp = false;
            dispatchDragCallback(0f, 0f, 0f, 0f);
        }
    }
}

From source file:com.wytiger.common.widget.SlideSwitch.java

private void moveToDest(final boolean toRight) {
    ValueAnimator toDestAnim = ValueAnimator.ofInt(frontRect_left, toRight ? max_left : min_left);
    toDestAnim.setDuration(500);//from w  w w  .  ja  va  2s.co  m
    toDestAnim.setInterpolator(new AccelerateDecelerateInterpolator());
    toDestAnim.start();
    toDestAnim.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            frontRect_left = (Integer) animation.getAnimatedValue();
            alpha = (int) (255 * (float) frontRect_left / (float) max_left);
            invalidateView();
        }
    });
    toDestAnim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (toRight) {
                isOpen = true;
                if (listener != null)
                    listener.open();
                frontRect_left_begin = max_left;
            } else {
                isOpen = false;
                if (listener != null)
                    listener.close();
                frontRect_left_begin = min_left;
            }
        }
    });
}