Search in sources :

Example 31 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project android_frameworks_base by AOSPA.

the class GlobalScreenshot method createScreenshotDropOutAnimation.

private ValueAnimator createScreenshotDropOutAnimation(int w, int h, boolean statusBarVisible, boolean navBarVisible) {
    ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
    anim.setStartDelay(SCREENSHOT_DROP_OUT_DELAY);
    anim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mBackgroundView.setVisibility(View.GONE);
            mScreenshotView.setVisibility(View.GONE);
            mScreenshotView.setLayerType(View.LAYER_TYPE_NONE, null);
        }
    });
    if (!statusBarVisible || !navBarVisible) {
        // There is no status bar/nav bar, so just fade the screenshot away in place
        anim.setDuration(SCREENSHOT_FAST_DROP_OUT_DURATION);
        anim.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float t = (Float) animation.getAnimatedValue();
                float scaleT = (SCREENSHOT_DROP_IN_MIN_SCALE + mBgPaddingScale) - t * (SCREENSHOT_DROP_IN_MIN_SCALE - SCREENSHOT_FAST_DROP_OUT_MIN_SCALE);
                mBackgroundView.setAlpha((1f - t) * BACKGROUND_ALPHA);
                mScreenshotView.setAlpha(1f - t);
                mScreenshotView.setScaleX(scaleT);
                mScreenshotView.setScaleY(scaleT);
            }
        });
    } else {
        // In the case where there is a status bar, animate to the origin of the bar (top-left)
        final float scaleDurationPct = (float) SCREENSHOT_DROP_OUT_SCALE_DURATION / SCREENSHOT_DROP_OUT_DURATION;
        final Interpolator scaleInterpolator = new Interpolator() {

            @Override
            public float getInterpolation(float x) {
                if (x < scaleDurationPct) {
                    // Decelerate, and scale the input accordingly
                    return (float) (1f - Math.pow(1f - (x / scaleDurationPct), 2f));
                }
                return 1f;
            }
        };
        // Determine the bounds of how to scale
        float halfScreenWidth = (w - 2f * mBgPadding) / 2f;
        float halfScreenHeight = (h - 2f * mBgPadding) / 2f;
        final float offsetPct = SCREENSHOT_DROP_OUT_MIN_SCALE_OFFSET;
        final PointF finalPos = new PointF(-halfScreenWidth + (SCREENSHOT_DROP_OUT_MIN_SCALE + offsetPct) * halfScreenWidth, -halfScreenHeight + (SCREENSHOT_DROP_OUT_MIN_SCALE + offsetPct) * halfScreenHeight);
        // Animate the screenshot to the status bar
        anim.setDuration(SCREENSHOT_DROP_OUT_DURATION);
        anim.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float t = (Float) animation.getAnimatedValue();
                float scaleT = (SCREENSHOT_DROP_IN_MIN_SCALE + mBgPaddingScale) - scaleInterpolator.getInterpolation(t) * (SCREENSHOT_DROP_IN_MIN_SCALE - SCREENSHOT_DROP_OUT_MIN_SCALE);
                mBackgroundView.setAlpha((1f - t) * BACKGROUND_ALPHA);
                mScreenshotView.setAlpha(1f - scaleInterpolator.getInterpolation(t));
                mScreenshotView.setScaleX(scaleT);
                mScreenshotView.setScaleY(scaleT);
                mScreenshotView.setTranslationX(t * finalPos.x);
                mScreenshotView.setTranslationY(t * finalPos.y);
            }
        });
    }
    return anim;
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PointF(android.graphics.PointF) Interpolator(android.view.animation.Interpolator) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator)

Example 32 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project android_frameworks_base by AOSPA.

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 33 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project android_frameworks_base by AOSPA.

the class VolumeDialogMotion method startShowAnimation.

private void startShowAnimation() {
    if (D.BUG)
        Log.d(TAG, "startShowAnimation");
    mDialogView.animate().translationY(0).setDuration(scaledDuration(300)).setInterpolator(new LogDecelerateInterpolator()).setListener(null).setUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            if (mChevronPositionAnimator == null)
                return;
            // reposition chevron
            final float v = (Float) mChevronPositionAnimator.getAnimatedValue();
            final int posY = chevronPosY();
            mChevron.setTranslationY(posY + v + -mDialogView.getTranslationY());
        }
    }).start();
    mContentsPositionAnimator = ValueAnimator.ofFloat(-chevronDistance(), 0).setDuration(scaledDuration(400));
    mContentsPositionAnimator.addListener(new AnimatorListenerAdapter() {

        private boolean mCancelled;

        @Override
        public void onAnimationEnd(Animator animation) {
            if (mCancelled)
                return;
            if (D.BUG)
                Log.d(TAG, "show.onAnimationEnd");
            setShowing(false);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            if (D.BUG)
                Log.d(TAG, "show.onAnimationCancel");
            mCancelled = true;
        }
    });
    mContentsPositionAnimator.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float v = (Float) animation.getAnimatedValue();
            mContents.setTranslationY(v + -mDialogView.getTranslationY());
        }
    });
    mContentsPositionAnimator.setInterpolator(new LogDecelerateInterpolator());
    mContentsPositionAnimator.start();
    mContents.setAlpha(0);
    mContents.animate().alpha(1).setDuration(scaledDuration(150)).setInterpolator(new PathInterpolator(0f, 0f, .2f, 1f)).start();
    mChevronPositionAnimator = ValueAnimator.ofFloat(-chevronDistance(), 0).setDuration(scaledDuration(250));
    mChevronPositionAnimator.setInterpolator(new PathInterpolator(.4f, 0f, .2f, 1f));
    mChevronPositionAnimator.start();
    mChevron.setAlpha(0);
    mChevron.animate().alpha(1).setStartDelay(scaledDuration(50)).setDuration(scaledDuration(150)).setInterpolator(new PathInterpolator(.4f, 0f, 1f, 1f)).start();
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) PathInterpolator(android.view.animation.PathInterpolator)

Example 34 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project android_frameworks_base by ResurrectionRemix.

the class VolumeDialogMotion method startShowAnimation.

private void startShowAnimation() {
    if (D.BUG)
        Log.d(TAG, "startShowAnimation");
    mDialogView.animate().translationY(0).setDuration(scaledDuration(300)).setInterpolator(new LogDecelerateInterpolator()).setListener(null).setUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            if (mChevronPositionAnimator == null)
                return;
            // reposition chevron
            final float v = (Float) mChevronPositionAnimator.getAnimatedValue();
            final int posY = chevronPosY();
            mChevron.setTranslationY(posY + v + -mDialogView.getTranslationY());
        }
    }).start();
    mContentsPositionAnimator = ValueAnimator.ofFloat(-chevronDistance(), 0).setDuration(scaledDuration(400));
    mContentsPositionAnimator.addListener(new AnimatorListenerAdapter() {

        private boolean mCancelled;

        @Override
        public void onAnimationEnd(Animator animation) {
            if (mCancelled)
                return;
            if (D.BUG)
                Log.d(TAG, "show.onAnimationEnd");
            setShowing(false);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            if (D.BUG)
                Log.d(TAG, "show.onAnimationCancel");
            mCancelled = true;
        }
    });
    mContentsPositionAnimator.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float v = (Float) animation.getAnimatedValue();
            mContents.setTranslationY(v + -mDialogView.getTranslationY());
        }
    });
    mContentsPositionAnimator.setInterpolator(new LogDecelerateInterpolator());
    mContentsPositionAnimator.start();
    mContents.setAlpha(0);
    mContents.animate().alpha(1).setDuration(scaledDuration(150)).setInterpolator(new PathInterpolator(0f, 0f, .2f, 1f)).start();
    mChevronPositionAnimator = ValueAnimator.ofFloat(-chevronDistance(), 0).setDuration(scaledDuration(250));
    mChevronPositionAnimator.setInterpolator(new PathInterpolator(.4f, 0f, .2f, 1f));
    mChevronPositionAnimator.start();
    mChevron.setAlpha(0);
    mChevron.animate().alpha(1).setStartDelay(scaledDuration(50)).setDuration(scaledDuration(150)).setInterpolator(new PathInterpolator(.4f, 0f, 1f, 1f)).start();
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) PathInterpolator(android.view.animation.PathInterpolator)

Example 35 with AnimatorUpdateListener

use of android.animation.ValueAnimator.AnimatorUpdateListener in project android_frameworks_base by ResurrectionRemix.

the class GlobalScreenshot method createScreenshotDropOutAnimation.

private ValueAnimator createScreenshotDropOutAnimation(int w, int h, boolean statusBarVisible, boolean navBarVisible) {
    ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
    anim.setStartDelay(SCREENSHOT_DROP_OUT_DELAY);
    anim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mBackgroundView.setVisibility(View.GONE);
            mScreenshotView.setVisibility(View.GONE);
            mScreenshotView.setLayerType(View.LAYER_TYPE_NONE, null);
        }
    });
    if (!statusBarVisible || !navBarVisible) {
        // There is no status bar/nav bar, so just fade the screenshot away in place
        anim.setDuration(SCREENSHOT_FAST_DROP_OUT_DURATION);
        anim.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float t = (Float) animation.getAnimatedValue();
                float scaleT = (SCREENSHOT_DROP_IN_MIN_SCALE + mBgPaddingScale) - t * (SCREENSHOT_DROP_IN_MIN_SCALE - SCREENSHOT_FAST_DROP_OUT_MIN_SCALE);
                mBackgroundView.setAlpha((1f - t) * BACKGROUND_ALPHA);
                mScreenshotView.setAlpha(1f - t);
                mScreenshotView.setScaleX(scaleT);
                mScreenshotView.setScaleY(scaleT);
            }
        });
    } else {
        // In the case where there is a status bar, animate to the origin of the bar (top-left)
        final float scaleDurationPct = (float) SCREENSHOT_DROP_OUT_SCALE_DURATION / SCREENSHOT_DROP_OUT_DURATION;
        final Interpolator scaleInterpolator = new Interpolator() {

            @Override
            public float getInterpolation(float x) {
                if (x < scaleDurationPct) {
                    // Decelerate, and scale the input accordingly
                    return (float) (1f - Math.pow(1f - (x / scaleDurationPct), 2f));
                }
                return 1f;
            }
        };
        // Determine the bounds of how to scale
        float halfScreenWidth = (w - 2f * mBgPadding) / 2f;
        float halfScreenHeight = (h - 2f * mBgPadding) / 2f;
        final float offsetPct = SCREENSHOT_DROP_OUT_MIN_SCALE_OFFSET;
        final PointF finalPos = new PointF(-halfScreenWidth + (SCREENSHOT_DROP_OUT_MIN_SCALE + offsetPct) * halfScreenWidth, -halfScreenHeight + (SCREENSHOT_DROP_OUT_MIN_SCALE + offsetPct) * halfScreenHeight);
        // Animate the screenshot to the status bar
        anim.setDuration(SCREENSHOT_DROP_OUT_DURATION);
        anim.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float t = (Float) animation.getAnimatedValue();
                float scaleT = (SCREENSHOT_DROP_IN_MIN_SCALE + mBgPaddingScale) - scaleInterpolator.getInterpolation(t) * (SCREENSHOT_DROP_IN_MIN_SCALE - SCREENSHOT_DROP_OUT_MIN_SCALE);
                mBackgroundView.setAlpha((1f - t) * BACKGROUND_ALPHA);
                mScreenshotView.setAlpha(1f - scaleInterpolator.getInterpolation(t));
                mScreenshotView.setScaleX(scaleT);
                mScreenshotView.setScaleY(scaleT);
                mScreenshotView.setTranslationX(t * finalPos.x);
                mScreenshotView.setTranslationY(t * finalPos.y);
            }
        });
    }
    return anim;
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PointF(android.graphics.PointF) Interpolator(android.view.animation.Interpolator) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator)

Aggregations

AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)94 ValueAnimator (android.animation.ValueAnimator)88 Animator (android.animation.Animator)65 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)62 ObjectAnimator (android.animation.ObjectAnimator)31 TimeInterpolator (android.animation.TimeInterpolator)14 View (android.view.View)13 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)12 Interpolator (android.view.animation.Interpolator)12 Resources (android.content.res.Resources)9 SuppressLint (android.annotation.SuppressLint)8 AnimatorSet (android.animation.AnimatorSet)7 Rect (android.graphics.Rect)7 ImageView (android.widget.ImageView)7 PropertyValuesHolder (android.animation.PropertyValuesHolder)6 AppWidgetHostView (android.appwidget.AppWidgetHostView)6 Point (android.graphics.Point)6 PointF (android.graphics.PointF)6 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)6 TextView (android.widget.TextView)6