Search in sources :

Example 41 with ValueAnimator

use of android.animation.ValueAnimator in project platform_frameworks_base by android.

the class VolumeDialogMotion method startDismiss.

public void startDismiss(final Runnable onComplete) {
    if (D.BUG)
        Log.d(TAG, "startDismiss");
    if (mDismissing)
        return;
    setDismissing(true);
    if (mShowing) {
        mDialogView.animate().cancel();
        if (mContentsPositionAnimator != null) {
            mContentsPositionAnimator.cancel();
        }
        mContents.animate().cancel();
        if (mChevronPositionAnimator != null) {
            mChevronPositionAnimator.cancel();
        }
        mChevron.animate().cancel();
        setShowing(false);
    }
    mDialogView.animate().translationY(-mDialogView.getHeight()).setDuration(scaledDuration(250)).setInterpolator(new LogAccelerateInterpolator()).setUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mContents.setTranslationY(-mDialogView.getTranslationY());
            final int posY = chevronPosY();
            mChevron.setTranslationY(posY + -mDialogView.getTranslationY());
        }
    }).setListener(new AnimatorListenerAdapter() {

        private boolean mCancelled;

        @Override
        public void onAnimationEnd(Animator animation) {
            if (mCancelled)
                return;
            if (D.BUG)
                Log.d(TAG, "dismiss.onAnimationEnd");
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (D.BUG)
                        Log.d(TAG, "mDialog.dismiss()");
                    mDialog.dismiss();
                    onComplete.run();
                    setDismissing(false);
                }
            }, PRE_DISMISS_DELAY);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            if (D.BUG)
                Log.d(TAG, "dismiss.onAnimationCancel");
            mCancelled = true;
        }
    }).start();
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator)

Example 42 with ValueAnimator

use of android.animation.ValueAnimator in project platform_frameworks_base by android.

the class ChangeText method createAnimator.

@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
    if (startValues == null || endValues == null || !(startValues.view instanceof TextView) || !(endValues.view instanceof TextView)) {
        return null;
    }
    final TextView view = (TextView) endValues.view;
    Map<String, Object> startVals = startValues.values;
    Map<String, Object> endVals = endValues.values;
    final CharSequence startText = startVals.get(PROPNAME_TEXT) != null ? (CharSequence) startVals.get(PROPNAME_TEXT) : "";
    final CharSequence endText = endVals.get(PROPNAME_TEXT) != null ? (CharSequence) endVals.get(PROPNAME_TEXT) : "";
    final int startSelectionStart, startSelectionEnd, endSelectionStart, endSelectionEnd;
    if (view instanceof EditText) {
        startSelectionStart = startVals.get(PROPNAME_TEXT_SELECTION_START) != null ? (Integer) startVals.get(PROPNAME_TEXT_SELECTION_START) : -1;
        startSelectionEnd = startVals.get(PROPNAME_TEXT_SELECTION_END) != null ? (Integer) startVals.get(PROPNAME_TEXT_SELECTION_END) : startSelectionStart;
        endSelectionStart = endVals.get(PROPNAME_TEXT_SELECTION_START) != null ? (Integer) endVals.get(PROPNAME_TEXT_SELECTION_START) : -1;
        endSelectionEnd = endVals.get(PROPNAME_TEXT_SELECTION_END) != null ? (Integer) endVals.get(PROPNAME_TEXT_SELECTION_END) : endSelectionStart;
    } else {
        startSelectionStart = startSelectionEnd = endSelectionStart = endSelectionEnd = -1;
    }
    if (!startText.equals(endText)) {
        final int startColor;
        final int endColor;
        if (mChangeBehavior != CHANGE_BEHAVIOR_IN) {
            view.setText(startText);
            if (view instanceof EditText) {
                setSelection(((EditText) view), startSelectionStart, startSelectionEnd);
            }
        }
        Animator anim;
        if (mChangeBehavior == CHANGE_BEHAVIOR_KEEP) {
            startColor = endColor = 0;
            anim = ValueAnimator.ofFloat(0, 1);
            anim.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    if (startText.equals(view.getText())) {
                        // Only set if it hasn't been changed since anim started
                        view.setText(endText);
                        if (view instanceof EditText) {
                            setSelection(((EditText) view), endSelectionStart, endSelectionEnd);
                        }
                    }
                }
            });
        } else {
            startColor = (Integer) startVals.get(PROPNAME_TEXT_COLOR);
            endColor = (Integer) endVals.get(PROPNAME_TEXT_COLOR);
            // Fade out start text
            ValueAnimator outAnim = null, inAnim = null;
            if (mChangeBehavior == CHANGE_BEHAVIOR_OUT_IN || mChangeBehavior == CHANGE_BEHAVIOR_OUT) {
                outAnim = ValueAnimator.ofInt(255, 0);
                outAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        int currAlpha = (Integer) animation.getAnimatedValue();
                        view.setTextColor(currAlpha << 24 | startColor & 0xff0000 | startColor & 0xff00 | startColor & 0xff);
                    }
                });
                outAnim.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        if (startText.equals(view.getText())) {
                            // Only set if it hasn't been changed since anim started
                            view.setText(endText);
                            if (view instanceof EditText) {
                                setSelection(((EditText) view), endSelectionStart, endSelectionEnd);
                            }
                        }
                        // restore opaque alpha and correct end color
                        view.setTextColor(endColor);
                    }
                });
            }
            if (mChangeBehavior == CHANGE_BEHAVIOR_OUT_IN || mChangeBehavior == CHANGE_BEHAVIOR_IN) {
                inAnim = ValueAnimator.ofInt(0, 255);
                inAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        int currAlpha = (Integer) animation.getAnimatedValue();
                        view.setTextColor(currAlpha << 24 | Color.red(endColor) << 16 | Color.green(endColor) << 8 | Color.red(endColor));
                    }
                });
                inAnim.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationCancel(Animator animation) {
                        // restore opaque alpha and correct end color
                        view.setTextColor(endColor);
                    }
                });
            }
            if (outAnim != null && inAnim != null) {
                anim = new AnimatorSet();
                ((AnimatorSet) anim).playSequentially(outAnim, inAnim);
            } else if (outAnim != null) {
                anim = outAnim;
            } else {
                // Must be an in-only animation
                anim = inAnim;
            }
        }
        TransitionListener transitionListener = new TransitionListenerAdapter() {

            int mPausedColor = 0;

            @Override
            public void onTransitionPause(Transition transition) {
                if (mChangeBehavior != CHANGE_BEHAVIOR_IN) {
                    view.setText(endText);
                    if (view instanceof EditText) {
                        setSelection(((EditText) view), endSelectionStart, endSelectionEnd);
                    }
                }
                if (mChangeBehavior > CHANGE_BEHAVIOR_KEEP) {
                    mPausedColor = view.getCurrentTextColor();
                    view.setTextColor(endColor);
                }
            }

            @Override
            public void onTransitionResume(Transition transition) {
                if (mChangeBehavior != CHANGE_BEHAVIOR_IN) {
                    view.setText(startText);
                    if (view instanceof EditText) {
                        setSelection(((EditText) view), startSelectionStart, startSelectionEnd);
                    }
                }
                if (mChangeBehavior > CHANGE_BEHAVIOR_KEEP) {
                    view.setTextColor(mPausedColor);
                }
            }
        };
        addListener(transitionListener);
        if (DBG) {
            Log.d(LOG_TAG, "createAnimator returning " + anim);
        }
        return anim;
    }
    return null;
}
Also used : EditText(android.widget.EditText) AnimatorSet(android.animation.AnimatorSet) ValueAnimator(android.animation.ValueAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) TextView(android.widget.TextView)

Example 43 with ValueAnimator

use of android.animation.ValueAnimator in project platform_frameworks_base by android.

the class GlTextureViewActivity method onSurfaceTextureAvailable.

@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
    mRenderThread = new ImageFlipRenderThread(getResources(), surface);
    mRenderThread.start();
    mTextureView.setCameraDistance(5000);
    ObjectAnimator animator = ObjectAnimator.ofFloat(mTextureView, "rotationY", 0.0f, 360.0f);
    animator.setRepeatMode(ObjectAnimator.REVERSE);
    animator.setRepeatCount(ObjectAnimator.INFINITE);
    animator.setDuration(4000);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mTextureView.invalidate();
        }
    });
    animator.start();
}
Also used : ImageFlipRenderThread(com.android.test.uibench.opengl.ImageFlipRenderThread) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator)

Example 44 with ValueAnimator

use of android.animation.ValueAnimator in project Android-MaterialRefreshLayout by android-cjj.

the class MaterialWaveView method onRefreshing.

@Override
public void onRefreshing(MaterialRefreshLayout br) {
    setHeadHeight((int) (Util.dip2px(getContext(), DefaulHeadHeight)));
    ValueAnimator animator = ValueAnimator.ofInt(getWaveHeight(), 0);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            Log.i("anim", "value--->" + (int) animation.getAnimatedValue());
            setWaveHeight((int) animation.getAnimatedValue());
            invalidate();
        }
    });
    animator.setInterpolator(new BounceInterpolator());
    animator.setDuration(200);
    animator.start();
}
Also used : BounceInterpolator(android.view.animation.BounceInterpolator) ValueAnimator(android.animation.ValueAnimator)

Example 45 with ValueAnimator

use of android.animation.ValueAnimator in project JJSearchViewAnim by android-cjj.

the class JJBaseController method startSearchViewAnim.

public ValueAnimator startSearchViewAnim(float startF, float endF, long time, final PathMeasure pathMeasure) {
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(startF, endF);
    valueAnimator.setDuration(time);
    valueAnimator.setInterpolator(new LinearInterpolator());
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mPro = (float) valueAnimator.getAnimatedValue();
            if (null != pathMeasure)
                pathMeasure.getPosTan(mPro, mPos, null);
            getSearchView().invalidate();
        }
    });
    valueAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
        }
    });
    if (!valueAnimator.isRunning()) {
        valueAnimator.start();
    }
    mPro = 0;
    return valueAnimator;
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) LinearInterpolator(android.view.animation.LinearInterpolator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ValueAnimator(android.animation.ValueAnimator)

Aggregations

ValueAnimator (android.animation.ValueAnimator)745 Animator (android.animation.Animator)377 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)307 ObjectAnimator (android.animation.ObjectAnimator)142 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)88 ArrayList (java.util.ArrayList)77 Paint (android.graphics.Paint)68 AnimatorSet (android.animation.AnimatorSet)57 LinearInterpolator (android.view.animation.LinearInterpolator)56 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)51 View (android.view.View)47 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)40 StackStateAnimator (com.android.systemui.statusbar.stack.StackStateAnimator)40 PropertyValuesHolder (android.animation.PropertyValuesHolder)31 ArgbEvaluator (android.animation.ArgbEvaluator)30 ViewGroup (android.view.ViewGroup)30 Interpolator (android.view.animation.Interpolator)26 TextView (android.widget.TextView)25 RenderNodeAnimator (android.view.RenderNodeAnimator)20 Rect (android.graphics.Rect)19