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.alimuzaffar.lib.pin.PinEntryEditText.java

private void animatePopIn() {
    ValueAnimator va = ValueAnimator.ofFloat(1, getPaint().getTextSize());
    va.setDuration(200);//ww w.j  a  v a2 s  .c o  m
    va.setInterpolator(new OvershootInterpolator());
    va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mLastCharPaint.setTextSize((Float) animation.getAnimatedValue());
            PinEntryEditText.this.invalidate();
        }
    });
    if (getText().length() == mMaxLength && mOnPinEnteredListener != null) {
        va.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                mOnPinEnteredListener.onPinEntered(getText());
            }

            @Override
            public void onAnimationCancel(Animator animation) {
            }

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

From source file:com.example.waitou.rxjava.LoadingView.java

private void buildAnimator() {
    final ValueAnimator valueAnimator = ValueAnimator.ofFloat(0f, 1f).setDuration(ANIMATOR_DURATION);
    valueAnimator.setRepeatCount(-1);//ww  w.j  a  v  a  2  s.co m
    valueAnimator.setInterpolator(new LinearInterpolator());
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mRotation = (float) valueAnimator.getAnimatedValue();
            invalidate();
        }
    });
    animator = valueAnimator;
    animatorSet = buildFlexibleAnimation();
    animatorSet.addListener(animatorListener);
}

From source file:com.shalzz.attendance.fragment.AttendanceListFragment.java

@Override
public void onItemExpanded(final View view) {
    final int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    final ExpandableListAdapter.GenericViewHolder viewHolder = (ExpandableListAdapter.GenericViewHolder) view
            .getTag();/* www . j a va  2  s  .co m*/
    final RelativeLayout childView = viewHolder.childView;
    childView.measure(spec, spec);
    final int startingHeight = view.getHeight();
    final ViewTreeObserver observer = mRecyclerView.getViewTreeObserver();
    observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            // We don'mTracker want to continue getting called for every draw.
            if (observer.isAlive()) {
                observer.removeOnPreDrawListener(this);
            }
            // Calculate some values to help with the animation.
            final int endingHeight = view.getHeight();
            final int distance = Math.abs(endingHeight - startingHeight);
            final int baseHeight = Math.min(endingHeight, startingHeight);
            final boolean isExpanded = endingHeight > startingHeight;

            // Set the views back to the start state of the animation
            view.getLayoutParams().height = startingHeight;
            if (!isExpanded) {
                viewHolder.childView.setVisibility(View.VISIBLE);
            }

            // Set up the fade effect for the action buttons.
            if (isExpanded) {
                // Start the fade in after the expansion has partly completed, otherwise it
                // will be mostly over before the expansion completes.
                viewHolder.childView.setAlpha(0f);
                viewHolder.childView.animate().alpha(1f).setStartDelay(mFadeInStartDelay)
                        .setDuration(mFadeInDuration).start();
            } else {
                viewHolder.childView.setAlpha(1f);
                viewHolder.childView.animate().alpha(0f).setDuration(mFadeOutDuration).start();
            }
            view.requestLayout();

            // Set up the animator to animate the expansion and shadow depth.
            ValueAnimator animator = isExpanded ? ValueAnimator.ofFloat(0f, 1f) : ValueAnimator.ofFloat(1f, 0f);

            // scroll to make the view fully visible.
            mRecyclerView.smoothScrollToPosition(viewHolder.position);

            animator.addUpdateListener(animator1 -> {
                Float value = (Float) animator1.getAnimatedValue();

                // For each value from 0 to 1, animate the various parts of the layout.
                view.getLayoutParams().height = (int) (value * distance + baseHeight);
                float z = mExpandedItemTranslationZ * value;
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    view.setTranslationZ(z);
                }
                view.requestLayout();
            });

            // Set everything to their final values when the animation's done.
            animator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    view.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;

                    if (!isExpanded) {
                        viewHolder.childView.setVisibility(View.GONE);
                    } else {
                        // This seems like it should be unnecessary, but without this, after
                        // navigating out of the activity and then back, the action view alpha
                        // is defaulting to the value (0) at the start of the expand animation.
                        viewHolder.childView.setAlpha(1);
                    }
                }
            });

            animator.setDuration(mExpandCollapseDuration);
            animator.start();

            // Return false so this draw does not occur to prevent the final frame from
            // being drawn for the single frame before the animations start.
            return false;
        }
    });
}

From source file:com.awt.supark.LayoutHandler.java

public void pullDown(final MainActivity act) {
    act.animInProgress = true;/*from  w  w w.  java2  s. c  om*/
    act.CarHandler.updateLicense(act);

    // ****** BUTTON AND LAYOUT PULL DOWN ANIMATION
    // Declaring animator
    ValueAnimator animation = ValueAnimator.ofFloat(0f, 1f);

    // Sets the animation properties
    animation.setDuration(act.layoutPullUpDuration);
    animation.setInterpolator(new AccelerateDecelerateInterpolator());
    animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float value = (float) animation.getAnimatedValue();
            act.tableRowTopHalf.setLayoutParams(new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT, value));
            act.btnMap.setAlpha(value);
            act.btnCars.setAlpha(value);
            act.btnStatistics.setAlpha(value);
            act.btnEtc.setAlpha(value);
        }
    });

    animation.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
            // Starts layout pull down and fade out animation
            act.otherContent.startAnimation(act.anim_slide_down_fade_out);
            act.anim_slide_down_fade_out.setFillAfter(true);

            // Makes layout invisible
            act.otherContent.setVisibility(View.GONE);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            act.contentLinear.setVisibility(View.VISIBLE);

            // ****** UI ELEMENTS FADE IN ANIMATION ******
            // Declaring animator
            ValueAnimator nextAnimation = ValueAnimator.ofFloat(0.17f, 1f);

            // Sets the animation properties
            nextAnimation.setDuration(act.layoutFadeInDuration);
            nextAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    float value = (float) animation.getAnimatedValue();
                    act.contentLinear.setAlpha(value);
                }
            });
            nextAnimation.start();

            act.pullUp = false;
            act.openedLayout = 0;
            act.animInProgress = false;
            FragmentTransaction transaction = act.fragmentManager.beginTransaction();
            transaction.remove(act.fragmentManager.findFragmentById(R.id.otherContent));
            transaction.commit();
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });
    animation.start();
}

From source file:com.example.waitou.rxjava.LoadingView.java

/**
 * build FlexibleAnimation to control the progress
 *
 * @return Animatorset for control the progress
 *//*from   w ww .  j  a  va 2s . c o  m*/
private AnimatorSet buildFlexibleAnimation() {
    final Ring ring = mRing;
    AnimatorSet set = new AnimatorSet();
    ValueAnimator increment = ValueAnimator.ofFloat(0, MAX_PROGRESS_ARC - MIN_PROGRESS_ARC)
            .setDuration(ANIMATOR_DURATION / 2);
    increment.setInterpolator(new LinearInterpolator());
    increment.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float sweeping = ring.sweeping;
            final float value = (float) animation.getAnimatedValue();
            ring.sweep = sweeping + value;
            invalidate();
        }
    });
    increment.addListener(animatorListener);
    ValueAnimator reduce = ValueAnimator.ofFloat(0, MAX_PROGRESS_ARC - MIN_PROGRESS_ARC)
            .setDuration(ANIMATOR_DURATION / 2);
    reduce.setInterpolator(interpolator);
    reduce.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float sweeping = ring.sweeping;
            float starting = ring.starting;
            float value = (float) animation.getAnimatedValue();
            ring.sweep = sweeping - value;
            ring.start = starting + value;
        }
    });
    set.play(reduce).after(increment);
    return set;
}

From source file:bottombar.BottomBarTab.java

private void setTopPaddingAnimated(int start, int end) {
    if (type == Type.TABLET) {
        return;/* ww w .  ja  v  a  2 s .  c  o m*/
    }

    ValueAnimator paddingAnimator = ValueAnimator.ofInt(start, end);
    paddingAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            iconView.setPadding(iconView.getPaddingLeft(), (Integer) animation.getAnimatedValue(),
                    iconView.getPaddingRight(), iconView.getPaddingBottom());
        }
    });

    paddingAnimator.setDuration(ANIMATION_DURATION);
    paddingAnimator.start();
}

From source file:nuclei.ui.view.ButtonBarView.java

private void setSelected(final Item item, boolean selected) {
    if (mItems.length < 5)
        return;//w  w  w .  ja  v a  2s  .  c om
    if (selected) {
        item.imageView.setColorFilter(mSelectedTint, PorterDuff.Mode.SRC_ATOP);
        if (item.textView != null) {
            item.textView.setTextColor(mSelectedTint);
            item.textView.setVisibility(View.VISIBLE);
            item.textView.setTextSize(0);
            ValueAnimator animator = mLabelAnimators.get(item);
            if (animator != null)
                animator.cancel();
            animator = new ValueAnimator();
            mLabelAnimators.put(item, animator);
            animator.setDuration(200);
            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    int animatedValue = (Integer) valueAnimator.getAnimatedValue();
                    item.textView.setTextSize(animatedValue);
                }
            });
            animator.setIntValues(0, 14);
            animator.start();
        }
    } else {
        item.imageView.setColorFilter(mUnselectedTint, PorterDuff.Mode.SRC_ATOP);
        if (item.textView != null) {
            item.textView.setTextColor(mUnselectedTint);
            ValueAnimator animator = mLabelAnimators.get(item);
            if (animator != null)
                animator.cancel();
            animator = new ValueAnimator();
            mLabelAnimators.put(item, animator);
            animator.setDuration(200);
            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    int animatedValue = (Integer) valueAnimator.getAnimatedValue();
                    item.textView.setTextSize(animatedValue);
                    if (animatedValue == 0)
                        item.textView.setVisibility(View.GONE);
                }
            });
            animator.setIntValues(14, 0);
            animator.start();
        }
    }
}

From source file:com.geecko.QuickLyric.adapter.IntroScreenSlidePagerAdapter.java

public IntroScreenSlidePagerAdapter(FragmentManager fm, final Activity activity) {
    super(fm);//from w  ww .j  av  a  2s  .  c  om
    this.mActivity = activity;
    mPager = ((ViewPager) mActivity.findViewById(R.id.pager));
    mPager.setOnTouchListener(exitTouchListener);
    if (Build.VERSION.SDK_INT >= 17)
        rightToLeft = TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == 1;
    if (rightToLeft) {
        List<Integer> list = Arrays.asList(colors);
        Collections.reverse(list);
        colors = (Integer[]) list.toArray();
    }
    ImageButton pagerArrow = ((ImageButton) mActivity.findViewById(R.id.pager_arrow));
    Button okButton = ((Button) mActivity.findViewById(R.id.pager_ok));
    okButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && !Tutorial_5.nlEnabled) {
                final ViewGroup nlFrame = (ViewGroup) activity.findViewById(R.id.NL_frame);
                final ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
                        Color.parseColor("#30000000"), Color.parseColor("#80FFFFFF"));
                colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        nlFrame.setBackgroundColor((int) animation.getAnimatedValue());
                    }
                });
                colorAnimation.setInterpolator(new LinearOutSlowInInterpolator());
                colorAnimation.setRepeatCount(3);
                colorAnimation.setRepeatMode(ValueAnimator.REVERSE);
                colorAnimation.setDuration(650L);
                colorAnimation.start();
            } else if (!hasClicked) {
                exitAction();
                hasClicked = true;
            }
        }
    });
    pagerArrow.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            nextAction();
        }
    });
}

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

private void animateScanMediaMessage() {
    TranslateAnimation anim = new TranslateAnimation(0, 0, -200, 0);
    anim.setDuration(900);//from w w  w . ja v a 2 s . c  o m
    messageContainer.startAnimation(anim);

    messageContainer.measure(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    ValueAnimator animator = ValueAnimator.ofInt(initialCourseListPadding,
            messageContainer.getMeasuredHeight());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        //@Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            courseList.setPadding(0, (Integer) valueAnimator.getAnimatedValue(), 0, 0);
            courseList.setSelectionAfterHeaderView();
        }
    });
    animator.setStartDelay(200);
    animator.setDuration(700);
    animator.start();
}

From source file:com.jsibbold.zoomage.ZoomageView.java

/**
 * Animate the matrix back to its original position after the user stopped interacting with it.
 *//*from  w  ww  . j  a  va  2s .c om*/
private void animateToStartMatrix() {

    final Matrix beginMatrix = new Matrix(getImageMatrix());
    beginMatrix.getValues(mValues);

    //difference in current and original values
    final float xsdiff = startValues[Matrix.MSCALE_X] - mValues[Matrix.MSCALE_X];
    final float ysdiff = startValues[Matrix.MSCALE_Y] - mValues[Matrix.MSCALE_Y];
    final float xtdiff = startValues[Matrix.MTRANS_X] - mValues[Matrix.MTRANS_X];
    final float ytdiff = startValues[Matrix.MTRANS_Y] - mValues[Matrix.MTRANS_Y];

    ValueAnimator anim = ValueAnimator.ofFloat(0, 1f);
    anim.addUpdateListener(new AnimatorUpdateListener() {

        final Matrix activeMatrix = new Matrix(getImageMatrix());
        final float[] values = new float[9];

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float val = (Float) animation.getAnimatedValue();
            activeMatrix.set(beginMatrix);
            activeMatrix.getValues(values);
            values[Matrix.MTRANS_X] = values[Matrix.MTRANS_X] + xtdiff * val;
            values[Matrix.MTRANS_Y] = values[Matrix.MTRANS_Y] + ytdiff * val;
            values[Matrix.MSCALE_X] = values[Matrix.MSCALE_X] + xsdiff * val;
            values[Matrix.MSCALE_Y] = values[Matrix.MSCALE_Y] + ysdiff * val;
            activeMatrix.setValues(values);
            setImageMatrix(activeMatrix);
        }
    });
    anim.setDuration(RESET_DURATION);
    anim.start();
}