Search in sources :

Example 46 with Interpolator

use of android.view.animation.Interpolator in project muzei by romannurik.

the class MuzeiActivity method updateUiMode.

private void updateUiMode() {
    // TODO: this should really just use fragment transactions and transitions
    int newUiMode = UI_MODE_INTRO;
    if (mWallpaperActive) {
        newUiMode = UI_MODE_TUTORIAL;
        if (mSeenTutorial) {
            newUiMode = UI_MODE_ART_DETAIL;
        }
    }
    if (mUiMode == newUiMode) {
        return;
    }
    // Crossfade between main containers
    final View oldContainerView = getMainContainerForUiMode(mUiMode);
    final View newContainerView = getMainContainerForUiMode(newUiMode);
    if (oldContainerView != null) {
        oldContainerView.animate().alpha(0).setDuration(1000).withEndAction(new Runnable() {

            @Override
            public void run() {
                oldContainerView.setVisibility(View.GONE);
            }
        });
    }
    if (newContainerView != null) {
        if (newContainerView.getAlpha() == 1) {
            newContainerView.setAlpha(0);
        }
        newContainerView.setVisibility(View.VISIBLE);
        newContainerView.animate().alpha(1).setDuration(1000).withEndAction(null);
    }
    // Special work
    if (newUiMode == UI_MODE_INTRO) {
        FirebaseAnalytics.getInstance(this).logEvent(FirebaseAnalytics.Event.TUTORIAL_BEGIN, null);
        final View activateButton = findViewById(R.id.activate_muzei_button);
        activateButton.setAlpha(0);
        final AnimatedMuzeiLogoFragment logoFragment = (AnimatedMuzeiLogoFragment) getFragmentManager().findFragmentById(R.id.animated_logo_fragment);
        logoFragment.reset();
        logoFragment.setOnFillStartedCallback(new Runnable() {

            @Override
            public void run() {
                activateButton.animate().alpha(1f).setDuration(500);
            }
        });
        mHandler.postDelayed(new Runnable() {

            @Override
            public void run() {
                logoFragment.start();
            }
        }, 1000);
    }
    if (mUiMode == UI_MODE_INTRO || newUiMode == UI_MODE_INTRO) {
        FragmentManager fm = getSupportFragmentManager();
        Fragment demoFragment = fm.findFragmentById(R.id.demo_view_container);
        if (newUiMode == UI_MODE_INTRO && demoFragment == null) {
            fm.beginTransaction().add(R.id.demo_view_container, MuzeiRendererFragment.createInstance(true, true)).commit();
        } else if (newUiMode != UI_MODE_INTRO && demoFragment != null) {
            fm.beginTransaction().remove(demoFragment).commit();
        }
    }
    if (newUiMode == UI_MODE_TUTORIAL) {
        float animateDistance = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, getResources().getDisplayMetrics());
        View mainTextView = findViewById(R.id.tutorial_main_text);
        mainTextView.setAlpha(0);
        mainTextView.setTranslationY(-animateDistance / 5);
        View subTextView = findViewById(R.id.tutorial_sub_text);
        subTextView.setAlpha(0);
        subTextView.setTranslationY(-animateDistance / 5);
        final View affordanceView = findViewById(R.id.tutorial_icon_affordance);
        affordanceView.setAlpha(0);
        affordanceView.setTranslationY(animateDistance);
        View iconTextView = findViewById(R.id.tutorial_icon_text);
        iconTextView.setAlpha(0);
        iconTextView.setTranslationY(animateDistance);
        AnimatorSet set = new AnimatorSet();
        set.setStartDelay(500);
        set.setDuration(250);
        set.playTogether(ObjectAnimator.ofFloat(mainTextView, View.ALPHA, 1f), ObjectAnimator.ofFloat(subTextView, View.ALPHA, 1f));
        set.start();
        set = new AnimatorSet();
        set.setStartDelay(2000);
        // Bug in older versions where set.setInterpolator didn't work
        Interpolator interpolator = new OvershootInterpolator();
        ObjectAnimator a1 = ObjectAnimator.ofFloat(affordanceView, View.TRANSLATION_Y, 0);
        ObjectAnimator a2 = ObjectAnimator.ofFloat(iconTextView, View.TRANSLATION_Y, 0);
        ObjectAnimator a3 = ObjectAnimator.ofFloat(mainTextView, View.TRANSLATION_Y, 0);
        ObjectAnimator a4 = ObjectAnimator.ofFloat(subTextView, View.TRANSLATION_Y, 0);
        a1.setInterpolator(interpolator);
        a2.setInterpolator(interpolator);
        a3.setInterpolator(interpolator);
        a4.setInterpolator(interpolator);
        set.setDuration(500).playTogether(ObjectAnimator.ofFloat(affordanceView, View.ALPHA, 1f), ObjectAnimator.ofFloat(iconTextView, View.ALPHA, 1f), a1, a2, a3, a4);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            set.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    ImageView emanateView = (ImageView) findViewById(R.id.tutorial_icon_emanate);
                    AnimatedVectorDrawable avd = (AnimatedVectorDrawable) getResources().getDrawable(R.drawable.avd_tutorial_icon_emanate, getTheme());
                    emanateView.setImageDrawable(avd);
                    avd.start();
                }
            });
        }
        set.start();
    }
    if (newUiMode == UI_MODE_ART_DETAIL) {
        FirebaseAnalytics.getInstance(this).logEvent(FirebaseAnalytics.Event.TUTORIAL_COMPLETE, null);
    }
    mPanScaleProxyView.setVisibility(newUiMode == UI_MODE_ART_DETAIL ? View.VISIBLE : View.GONE);
    mUiMode = newUiMode;
    maybeUpdateArtDetailOpenedClosed();
}
Also used : OvershootInterpolator(android.view.animation.OvershootInterpolator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorSet(android.animation.AnimatorSet) ImageView(android.widget.ImageView) View(android.view.View) AnimatedMuzeiLoadingSpinnerView(com.google.android.apps.muzei.util.AnimatedMuzeiLoadingSpinnerView) TextView(android.widget.TextView) PanScaleProxyView(com.google.android.apps.muzei.util.PanScaleProxyView) AnimatedMuzeiLogoFragment(com.google.android.apps.muzei.util.AnimatedMuzeiLogoFragment) Fragment(android.support.v4.app.Fragment) AnimatedMuzeiLogoFragment(com.google.android.apps.muzei.util.AnimatedMuzeiLogoFragment) MuzeiRendererFragment(com.google.android.apps.muzei.render.MuzeiRendererFragment) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable) FragmentManager(android.support.v4.app.FragmentManager) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) Interpolator(android.view.animation.Interpolator) OvershootInterpolator(android.view.animation.OvershootInterpolator) ImageView(android.widget.ImageView)

Example 47 with Interpolator

use of android.view.animation.Interpolator in project muzei by romannurik.

the class AnimatedMuzeiLogoFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.animated_logo_fragment, container, false);
    mSubtitleView = rootView.findViewById(R.id.logo_subtitle);
    mLogoView = (AnimatedMuzeiLogoView) rootView.findViewById(R.id.animated_logo);
    mLogoView.setOnStateChangeListener(new AnimatedMuzeiLogoView.OnStateChangeListener() {

        @Override
        public void onStateChange(int state) {
            if (state == AnimatedMuzeiLogoView.STATE_FILL_STARTED) {
                mSubtitleView.setAlpha(0);
                mSubtitleView.setVisibility(View.VISIBLE);
                mSubtitleView.setTranslationY(-mSubtitleView.getHeight());
                // Bug in older versions where set.setInterpolator didn't work
                AnimatorSet set = new AnimatorSet();
                Interpolator interpolator = new OvershootInterpolator();
                ObjectAnimator a1 = ObjectAnimator.ofFloat(mLogoView, View.TRANSLATION_Y, 0);
                ObjectAnimator a2 = ObjectAnimator.ofFloat(mSubtitleView, View.TRANSLATION_Y, 0);
                ObjectAnimator a3 = ObjectAnimator.ofFloat(mSubtitleView, View.ALPHA, 1);
                a1.setInterpolator(interpolator);
                a2.setInterpolator(interpolator);
                set.setDuration(500).playTogether(a1, a2, a3);
                set.start();
                if (mOnFillStartedCallback != null) {
                    mOnFillStartedCallback.run();
                }
            }
        }
    });
    reset();
    return rootView;
}
Also used : OvershootInterpolator(android.view.animation.OvershootInterpolator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorSet(android.animation.AnimatorSet) Interpolator(android.view.animation.Interpolator) OvershootInterpolator(android.view.animation.OvershootInterpolator) View(android.view.View)

Example 48 with Interpolator

use of android.view.animation.Interpolator in project platform_frameworks_base by android.

the class GlobalScreenshot method createScreenshotDropInAnimation.

private ValueAnimator createScreenshotDropInAnimation() {
    final float flashPeakDurationPct = ((float) (SCREENSHOT_FLASH_TO_PEAK_DURATION) / SCREENSHOT_DROP_IN_DURATION);
    final float flashDurationPct = 2f * flashPeakDurationPct;
    final Interpolator flashAlphaInterpolator = new Interpolator() {

        @Override
        public float getInterpolation(float x) {
            // Flash the flash view in and out quickly
            if (x <= flashDurationPct) {
                return (float) Math.sin(Math.PI * (x / flashDurationPct));
            }
            return 0;
        }
    };
    final Interpolator scaleInterpolator = new Interpolator() {

        @Override
        public float getInterpolation(float x) {
            // We start scaling when the flash is at it's peak
            if (x < flashPeakDurationPct) {
                return 0;
            }
            return (x - flashDurationPct) / (1f - flashDurationPct);
        }
    };
    ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
    anim.setDuration(SCREENSHOT_DROP_IN_DURATION);
    anim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animation) {
            mBackgroundView.setAlpha(0f);
            mBackgroundView.setVisibility(View.VISIBLE);
            mScreenshotView.setAlpha(0f);
            mScreenshotView.setTranslationX(0f);
            mScreenshotView.setTranslationY(0f);
            mScreenshotView.setScaleX(SCREENSHOT_SCALE + mBgPaddingScale);
            mScreenshotView.setScaleY(SCREENSHOT_SCALE + mBgPaddingScale);
            mScreenshotView.setVisibility(View.VISIBLE);
            mScreenshotFlash.setAlpha(0f);
            mScreenshotFlash.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationEnd(android.animation.Animator animation) {
            mScreenshotFlash.setVisibility(View.GONE);
        }
    });
    anim.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float t = (Float) animation.getAnimatedValue();
            float scaleT = (SCREENSHOT_SCALE + mBgPaddingScale) - scaleInterpolator.getInterpolation(t) * (SCREENSHOT_SCALE - SCREENSHOT_DROP_IN_MIN_SCALE);
            mBackgroundView.setAlpha(scaleInterpolator.getInterpolation(t) * BACKGROUND_ALPHA);
            mScreenshotView.setAlpha(t);
            mScreenshotView.setScaleX(scaleT);
            mScreenshotView.setScaleY(scaleT);
            mScreenshotFlash.setAlpha(flashAlphaInterpolator.getInterpolation(t));
        }
    });
    return anim;
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) Interpolator(android.view.animation.Interpolator) Animator(android.animation.Animator) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator)

Example 49 with Interpolator

use of android.view.animation.Interpolator in project platform_frameworks_base by android.

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 50 with Interpolator

use of android.view.animation.Interpolator in project platform_frameworks_base by android.

the class ActivatableNotificationView method startActivateAnimation.

private void startActivateAnimation(final boolean reverse) {
    if (!isAttachedToWindow()) {
        return;
    }
    int widthHalf = mBackgroundNormal.getWidth() / 2;
    int heightHalf = mBackgroundNormal.getActualHeight() / 2;
    float radius = (float) Math.sqrt(widthHalf * widthHalf + heightHalf * heightHalf);
    Animator animator;
    if (reverse) {
        animator = ViewAnimationUtils.createCircularReveal(mBackgroundNormal, widthHalf, heightHalf, radius, 0);
    } else {
        animator = ViewAnimationUtils.createCircularReveal(mBackgroundNormal, widthHalf, heightHalf, 0, radius);
    }
    mBackgroundNormal.setVisibility(View.VISIBLE);
    Interpolator interpolator;
    Interpolator alphaInterpolator;
    if (!reverse) {
        interpolator = Interpolators.LINEAR_OUT_SLOW_IN;
        alphaInterpolator = Interpolators.LINEAR_OUT_SLOW_IN;
    } else {
        interpolator = ACTIVATE_INVERSE_INTERPOLATOR;
        alphaInterpolator = ACTIVATE_INVERSE_ALPHA_INTERPOLATOR;
    }
    animator.setInterpolator(interpolator);
    animator.setDuration(ACTIVATE_ANIMATION_LENGTH);
    if (reverse) {
        mBackgroundNormal.setAlpha(1f);
        animator.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                updateBackground();
            }
        });
        animator.start();
    } else {
        mBackgroundNormal.setAlpha(0.4f);
        animator.start();
    }
    mBackgroundNormal.animate().alpha(reverse ? 0f : 1f).setInterpolator(alphaInterpolator).setUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float animatedFraction = animation.getAnimatedFraction();
            if (reverse) {
                animatedFraction = 1.0f - animatedFraction;
            }
            setNormalBackgroundVisibilityAmount(animatedFraction);
        }
    }).setDuration(ACTIVATE_ANIMATION_LENGTH);
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) StackStateAnimator(com.android.systemui.statusbar.stack.StackStateAnimator) TimeAnimator(android.animation.TimeAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PathInterpolator(android.view.animation.PathInterpolator) Interpolator(android.view.animation.Interpolator) ValueAnimator(android.animation.ValueAnimator)

Aggregations

Interpolator (android.view.animation.Interpolator)229 Animator (android.animation.Animator)60 ValueAnimator (android.animation.ValueAnimator)49 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)46 ObjectAnimator (android.animation.ObjectAnimator)39 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)25 PathInterpolator (android.view.animation.PathInterpolator)25 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)23 LinearInterpolator (android.view.animation.LinearInterpolator)18 Paint (android.graphics.Paint)17 View (android.view.View)17 PropertyValuesHolder (android.animation.PropertyValuesHolder)16 FloatKeyframe (com.actionbarsherlock.internal.nineoldandroids.animation.Keyframe.FloatKeyframe)16 IntKeyframe (com.actionbarsherlock.internal.nineoldandroids.animation.Keyframe.IntKeyframe)16 TimeAnimator (android.animation.TimeAnimator)15 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)14 TypedArray (android.content.res.TypedArray)14 Animation (android.view.animation.Animation)13 AnimatorSet (android.animation.AnimatorSet)12 TimeInterpolator (android.animation.TimeInterpolator)11