Example usage for android.animation ValueAnimator addListener

List of usage examples for android.animation ValueAnimator addListener

Introduction

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

Prototype

public void addListener(AnimatorListener listener) 

Source Link

Document

Adds a listener to the set of listeners that are sent events through the life of an animation, such as start, repeat, and end.

Usage

From source file:com.android.deskclock.timer.TimerFullScreenFragment.java

private Animator getRevealAnimator(View source, int revealColor) {
    final ViewGroup containerView = (ViewGroup) source.getRootView().findViewById(android.R.id.content);

    final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth());
    containerView.offsetDescendantRectToMyCoords(source, sourceBounds);

    final int centerX = sourceBounds.centerX();
    final int centerY = sourceBounds.centerY();

    final int xMax = Math.max(centerX, containerView.getWidth() - centerX);
    final int yMax = Math.max(centerY, containerView.getHeight() - centerY);

    final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f;
    final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax);

    final CircleView revealView = new CircleView(source.getContext()).setCenterX(centerX).setCenterY(centerY)
            .setFillColor(revealColor);/*from   w w  w.  j a v  a2s .c o  m*/
    containerView.addView(revealView);

    final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius,
            endRadius);
    revealAnimator.setInterpolator(PathInterpolatorCompat.create(0.0f, 0.0f, 0.2f, 1.0f));

    final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    fadeAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            containerView.removeView(revealView);
        }
    });

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.setDuration(TimerFragment.ANIMATION_TIME_MILLIS);
    animatorSet.playSequentially(revealAnimator, fadeAnimator);

    return revealAnimator;
}

From source file:com.mark.quick.ui.view.snackbar.BaseTransientBottomBar.java

void animateViewIn() {
    if (Build.VERSION.SDK_INT >= 12) {
        //TODO CHANGE ?
        final int viewHeight = -mView.getHeight();
        if (USE_OFFSET_API) {
            ViewCompat.offsetTopAndBottom(mView, viewHeight);
        } else {/*from www  .  j a  v  a  2s . c  om*/
            mView.setTranslationY(viewHeight);
        }

        final ValueAnimator animator = new ValueAnimator();
        animator.setIntValues(viewHeight, 0);
        animator.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
        animator.setDuration(ANIMATION_DURATION);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animator) {
                mContentViewCallback.animateContentIn(ANIMATION_DURATION - ANIMATION_FADE_DURATION,
                        ANIMATION_FADE_DURATION);
            }

            @Override
            public void onAnimationEnd(Animator animator) {
                onViewShown();
            }
        });
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            private int mPreviousAnimatedIntValue = viewHeight;

            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                int currentAnimatedIntValue = (int) animator.getAnimatedValue();
                if (USE_OFFSET_API) {
                    ViewCompat.offsetTopAndBottom(mView, currentAnimatedIntValue - mPreviousAnimatedIntValue);
                } else {
                    mView.setTranslationY(currentAnimatedIntValue);
                }
                mPreviousAnimatedIntValue = currentAnimatedIntValue;
            }
        });
        animator.start();
    } else {
        final Animation anim = android.view.animation.AnimationUtils.loadAnimation(mView.getContext(),
                R.anim.design_snackbar_in);
        anim.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
        anim.setDuration(ANIMATION_DURATION);
        anim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationEnd(Animation animation) {
                onViewShown();
            }

            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        mView.startAnimation(anim);
    }
}

From source file:org.lib.ExpandableLinearLayout.java

private void animateHeight(final View view, final int targetHeight) {
    if (animatorSet == null) {
        animatorSet = new AnimatorSet();
        animatorSet.setInterpolator(interpolator);
        animatorSet.setDuration(duration);
    }//from w w w. ja  va 2 s .  c o m

    final LayoutParams lp = (LayoutParams) view.getLayoutParams();
    lp.weight = 0;
    int height = view.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(height, targetHeight);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            view.getLayoutParams().height = (Integer) valueAnimator.getAnimatedValue();
            view.requestLayout();

            if (listener != null) {
                float fraction = targetHeight == 0 ? 1 - valueAnimator.getAnimatedFraction()
                        : valueAnimator.getAnimatedFraction();
                listener.onExpansionUpdate(fraction);
            }
        }
    });
    animator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animator) {
            view.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            if (targetHeight == 0) {
                view.setVisibility(GONE);
            } else {
                lp.height = lp.originalHeight;
                lp.weight = lp.originalWeight;
            }
        }

        @Override
        public void onAnimationCancel(Animator animator) {
        }

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

    animatorSet.playTogether(animator);
}

From source file:net.margaritov.preference.colorpicker.ColorPickerDialog.java

private ValueAnimator createAlphaAnimator(int start, int end) {
    ValueAnimator animator = ValueAnimator.ofInt(start, end);

    animator.setDuration(500);/*from   w  w w .j av a  2s.com*/
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int value = (Integer) valueAnimator.getAnimatedValue();
            float currentAlpha = value / 100f;
            mActionBarMain.setAlpha(1f - currentAlpha);
            mActionBarEditHex.setAlpha(currentAlpha);
            mDivider.setAlpha(currentAlpha);
        }
    });
    if (mHideEditHexBar) {
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                mActionBarMain.setVisibility(View.VISIBLE);
                ViewCompat.jumpDrawablesToCurrentState(mActionBarMain);
            }
        });
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mActionBarEditHex.setVisibility(View.GONE);
                mDivider.setVisibility(View.GONE);
            }
        });
    } else {
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                mActionBarEditHex.setVisibility(View.VISIBLE);
                ViewCompat.jumpDrawablesToCurrentState(mActionBarEditHex);
                mDivider.setVisibility(View.VISIBLE);
            }
        });
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mActionBarMain.setVisibility(View.GONE);
            }
        });
    }
    return animator;
}

From source file:com.example.volunteerhandbook.MainActivity.java

void loop_what_I_thought() {
    thoughts = getResources().getStringArray(R.array.what_I_thought);
    int lines = thoughts.length / 4;
    container = (FrameLayout) findViewById(R.id.main_content_frame);
    LinearLayout[] textBox = new LinearLayout[3];
    endY = container.getHeight() - 100f;
    h = (float) container.getHeight();
    hBox = 0;//from  w  ww .  j av a 2  s .  co m
    /*
    for (int k=0; k<3; k++){
       textBox[k]=new LinearLayout(this);
       textBox[k].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    textBox[k].setOrientation(1);
    }
    */
    //LinearLayout tmp=(LinearLayout) getLayoutInflater().inflate(R.layout.one_line, null);
    //TextView  tmpTxt=(TextView)tmp.findViewById(R.id.oneLine);
    //tmp.removeView(tmpTxt);
    int[] color = new int[4];
    color[3] = Color.parseColor("#66FF66");
    color[1] = Color.parseColor("#FF9900");
    color[2] = Color.parseColor("#0099FF");
    color[0] = Color.parseColor("#00FF00");
    toMove = new TextView[thoughts.length];
    int textSize = 24;
    for (int i = 0; i < thoughts.length; i++) {
        toMove[i] = new TextView(this);
        toMove[i].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        toMove[i].setText(thoughts[i]);
        toMove[i].setTextSize(textSize);
        toMove[i].getPaint().setFakeBoldText(true);
        toMove[i].setTextColor(color[1] - 0x20202 * i);
        //textBox.addView(toMove);
    }
    int boxHeight = (lines + 1) * (int) (textSize * 1.5);
    for (int k = 0; k < 3; k++) {
        textBox[k].removeAllViews();
        for (int i = 0; i < thoughts.length / 4; i++) {
            TextView v = toMove[iTh++ % thoughts.length];
            v.setTextColor(color[k]);
            textBox[k].addView(v);
        }
        //toMove.setTranslationY(600);
        //container.addView(textBox);
        container.addView(textBox[k]);
        textBox[k].setX(20);
        textBox[k].setY(2 * boxHeight + hBox);
        hBox += boxHeight; //textBox[k].getHeight();
        float startY = textBox[k].getY();
        endY = (-1) * boxHeight;
        int duration = (int) (((startY - endY) / (3 * boxHeight)) * 20000);
        ValueAnimator bounceAnim = ObjectAnimator.ofFloat(textBox[k], "y", startY, endY);
        bounceAnim.setDuration(duration);
        bounceAnim.setInterpolator(new LinearInterpolator());
        final LinearLayout iBox = textBox[k];
        bounceAnim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                loopNewBox(iBox);
            }
        });
        bounceAnim.start();
    }

}

From source file:com.mark.quick.ui.view.snackbar.BaseTransientBottomBar.java

private void animateViewOut(final int event) {
    if (Build.VERSION.SDK_INT >= 12) {
        //TODO CHANGE 0
        mView.setTranslationY(0);//from   w w w . j a v a  2s .co m
        final ValueAnimator animator = new ValueAnimator();
        //TODO CHANGE ?
        animator.setIntValues(0, -mView.getHeight());
        animator.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
        animator.setDuration(ANIMATION_DURATION);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animator) {
                mContentViewCallback.animateContentOut(0, ANIMATION_FADE_DURATION);
            }

            @Override
            public void onAnimationEnd(Animator animator) {
                onViewHidden(event);
            }
        });
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            private int mPreviousAnimatedIntValue = 0;

            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                int currentAnimatedIntValue = (int) animator.getAnimatedValue();
                if (USE_OFFSET_API) {
                    ViewCompat.offsetTopAndBottom(mView, currentAnimatedIntValue - mPreviousAnimatedIntValue);
                } else {
                    mView.setTranslationY(currentAnimatedIntValue);
                }
                mPreviousAnimatedIntValue = currentAnimatedIntValue;
            }
        });
        animator.start();
    } else {
        final Animation anim = android.view.animation.AnimationUtils.loadAnimation(mView.getContext(),
                R.anim.design_snackbar_out);
        anim.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
        anim.setDuration(ANIMATION_DURATION);
        anim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationEnd(Animation animation) {
                onViewHidden(event);
            }

            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        mView.startAnimation(anim);
    }
}

From source file:cn.com.hgh.view.SlideSwitch.java

public void moveToDest(final boolean toRight) {
    ValueAnimator toDestAnim = ValueAnimator.ofInt(frontRect_left, toRight ? max_left : min_left);
    toDestAnim.setDuration(500);//from  w w w. j  av a  2s  . c  o  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;
            }

        }
    });
}

From source file:com.alimuzaffar.lib.pin.PinEntryEditText.java

private void animatePopIn() {
    ValueAnimator va = ValueAnimator.ofFloat(1, getPaint().getTextSize());
    va.setDuration(200);//from   www  .  j  ava  2  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

/**
 * build FlexibleAnimation to control the progress
 *
 * @return Animatorset for control the progress
 *///from   ww  w.  j a  v a 2 s  .  c om
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:com.folioreader.view.ConfigView.java

private void toggleBlackTheme() {

    int day = getResources().getColor(R.color.white);
    int night = getResources().getColor(R.color.night);
    int darkNight = getResources().getColor(R.color.dark_night);
    final int diffNightDark = night - darkNight;

    ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), mIsNightMode ? night : day,
            mIsNightMode ? day : night);
    colorAnimation.setDuration(FADE_DAY_NIGHT_MODE);
    colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override//from w  w w.j  av a 2 s .c  om
        public void onAnimationUpdate(ValueAnimator animator) {
            int value = (int) animator.getAnimatedValue();
            mContainer.setBackgroundColor(value);
            if (mConfigViewCallback != null) {
                mConfigViewCallback.onBackgroundUpdate(value - diffNightDark);
            }
        }
    });

    colorAnimation.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animator) {
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            mIsNightMode = !mIsNightMode;
            Config.getConfig().setNightMode(mIsNightMode);
            mConfigViewCallback.onConfigChange();
        }

        @Override
        public void onAnimationCancel(Animator animator) {
        }

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

    colorAnimation.setDuration(FADE_DAY_NIGHT_MODE);
    colorAnimation.start();
}