Search in sources :

Example 1 with AnimatedMuzeiLogoFragment

use of com.google.android.apps.muzei.util.AnimatedMuzeiLogoFragment 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 2 with AnimatedMuzeiLogoFragment

use of com.google.android.apps.muzei.util.AnimatedMuzeiLogoFragment in project muzei by romannurik.

the class AboutActivity method onPostCreate.

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    View demoContainerView = findViewById(R.id.demo_view_container);
    demoContainerView.setAlpha(0);
    mAnimator = demoContainerView.animate().alpha(1).setStartDelay(250).setDuration(1000).withEndAction(new Runnable() {

        @Override
        public void run() {
            AnimatedMuzeiLogoFragment logoFragment = (AnimatedMuzeiLogoFragment) getFragmentManager().findFragmentById(R.id.animated_logo_fragment);
            if (logoFragment != null) {
                logoFragment.start();
            }
        }
    });
}
Also used : TextView(android.widget.TextView) View(android.view.View) AnimatedMuzeiLogoFragment(com.google.android.apps.muzei.util.AnimatedMuzeiLogoFragment)

Aggregations

View (android.view.View)2 TextView (android.widget.TextView)2 AnimatedMuzeiLogoFragment (com.google.android.apps.muzei.util.AnimatedMuzeiLogoFragment)2 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 AnimatorSet (android.animation.AnimatorSet)1 ObjectAnimator (android.animation.ObjectAnimator)1 AnimatedVectorDrawable (android.graphics.drawable.AnimatedVectorDrawable)1 Fragment (android.support.v4.app.Fragment)1 FragmentManager (android.support.v4.app.FragmentManager)1 Interpolator (android.view.animation.Interpolator)1 OvershootInterpolator (android.view.animation.OvershootInterpolator)1 ImageView (android.widget.ImageView)1 MuzeiRendererFragment (com.google.android.apps.muzei.render.MuzeiRendererFragment)1 AnimatedMuzeiLoadingSpinnerView (com.google.android.apps.muzei.util.AnimatedMuzeiLoadingSpinnerView)1 PanScaleProxyView (com.google.android.apps.muzei.util.PanScaleProxyView)1