예제 #1
0
        private void Switch (Drawable src, ColorStateList tint, bool withAnimation = false)
        {

            if (!withAnimation) {
                SetImageDrawable (src);
                BackgroundTintList = tint;
                return;
            }

            const int ScaleDuration = 200;
            const int InitialDelay = 100;

            if (switchAnimation != null) {
                switchAnimation.Cancel ();
                switchAnimation = null;
            }

            var currentSrc = Drawable;

            // Scaling down animation
            var circleAnimOutX = ObjectAnimator.OfFloat (this, "scaleX", 1, 0.1f);
            var circleAnimOutY = ObjectAnimator.OfFloat (this, "scaleY", 1, 0.1f);
            circleAnimOutX.SetDuration (ScaleDuration);
            circleAnimOutY.SetDuration (ScaleDuration);

            // Alpha out of the icon
            //var iconAnimOut = ObjectAnimator.OfInt (currentSrc, "alpha", 255, 0);
            //iconAnimOut.SetDuration (AlphaDuration);

            var outSet = new AnimatorSet ();
            outSet.PlayTogether (circleAnimOutX, circleAnimOutY);
            outSet.SetInterpolator (AnimationUtils.LoadInterpolator (Context,
                                    Android.Resource.Animation.AccelerateInterpolator));
            outSet.StartDelay = InitialDelay;
            outSet.AnimationEnd += (sender, e) => {
                BackgroundTintList = tint;
                SetImageDrawable (src);
                JumpDrawablesToCurrentState ();
                ((Animator)sender).RemoveAllListeners ();
            };

            // Scaling up animation
            var circleAnimInX = ObjectAnimator.OfFloat (this, "scaleX", 0.1f, 1);
            var circleAnimInY = ObjectAnimator.OfFloat (this, "scaleY", 0.1f, 1);
            circleAnimInX.SetDuration (ScaleDuration);
            circleAnimInY.SetDuration (ScaleDuration);

            var inSet = new AnimatorSet ();
            inSet.PlayTogether (circleAnimInX, circleAnimInY);
            inSet.SetInterpolator (AnimationUtils.LoadInterpolator (Context,
                                   Android.Resource.Animation.DecelerateInterpolator));

            switchAnimation = new AnimatorSet ();
            switchAnimation.PlaySequentially (outSet, inSet);
            switchAnimation.Start ();
        }
예제 #2
0
        private async void OnRequestOnboardingPage(OnboardingViewModel oVm)
        {
            _viewModel = oVm;
            AnimationInitUI();
            BindEvents();
            
            var mainAnimatorSet = new AnimatorSet();

            var appNameLayoutFinalTopSpace = TypedValue.ApplyDimension(ComplexUnitType.Dip, 55.0f, Application.Context.Resources.DisplayMetrics);

            var decelerateInterpolator = new DecelerateInterpolator(1.0f);

            var appNameLayoutAnimator = new ValueAnimator();
            appNameLayoutAnimator.SetDuration(750);
            appNameLayoutAnimator.SetInterpolator(decelerateInterpolator);
            appNameLayoutAnimator.SetFloatValues(_appNameLayout.GetY(), appNameLayoutFinalTopSpace);
            appNameLayoutAnimator.Update += (o, args) => { _appNameLayout.SetY((float)args.Animation.AnimatedValue); };

            var whatAccountsAnimator = new ValueAnimator();
            whatAccountsAnimator.SetDuration(750);
            whatAccountsAnimator.SetInterpolator(decelerateInterpolator);
            whatAccountsAnimator.SetFloatValues(0.0f, 1.0f);
            whatAccountsAnimator.Update += (o, args) => { _whatAccounts.Alpha = (float)args.Animation.AnimatedValue; };

            var appNameAnimationSet = new AnimatorSet();
            appNameAnimationSet.PlayTogether(appNameLayoutAnimator, whatAccountsAnimator);


            var socialButtonsAnimatorSet = new AnimatorSet();

            var overshootInterpolator = new OvershootInterpolator(3f);

            var facebookButtonAnimator = new ValueAnimator();
            facebookButtonAnimator.SetDuration(500);
            facebookButtonAnimator.SetInterpolator(overshootInterpolator);
            facebookButtonAnimator.SetFloatValues(_facebookButton.GetY() + _facebookButton.Height, _facebookButton.GetY());
            facebookButtonAnimator.Update += (o, args) =>
                {
                    _facebookButton.SetY((float)args.Animation.AnimatedValue);
                    _facebookButton.Alpha = args.Animation.AnimatedFraction;
                };

            var twitterButtonAnimator = new ValueAnimator();
            twitterButtonAnimator.SetDuration(500);
            twitterButtonAnimator.SetInterpolator(overshootInterpolator);
            twitterButtonAnimator.SetFloatValues(_facebookButton.GetY() + _facebookButton.Height, _facebookButton.GetY());
            twitterButtonAnimator.Update += (o, args) =>
                {
                    _twitterButton.SetY((float)args.Animation.AnimatedValue);
                    _twitterButton.Alpha = args.Animation.AnimatedFraction;
                };
            socialButtonsAnimatorSet.PlaySequentially(facebookButtonAnimator, twitterButtonAnimator);
            socialButtonsAnimatorSet.StartDelay = 500;

            var letsGoButtonAnimator = new ValueAnimator();
            letsGoButtonAnimator.SetDuration(500);
            letsGoButtonAnimator.SetInterpolator(decelerateInterpolator);
            letsGoButtonAnimator.SetFloatValues(0.0f, 1.0f);
            letsGoButtonAnimator.Update += (sender, args) =>
                {
                    _goButton.Alpha = (float)args.Animation.AnimatedValue;
                };

            mainAnimatorSet.PlaySequentially(appNameAnimationSet, socialButtonsAnimatorSet, letsGoButtonAnimator);

            await _viewModel.DidLoad();

            await Task.Delay(2000);

            mainAnimatorSet.Start();
            await _viewModel.DidAppear();
        }
예제 #3
0
        public void SetCount(int count, bool animate)
        {
            if (!animate) {
                Count = count;
                return;
            }

            ValueAnimator outAnimator = null;

            if (this.count != 0) {
                outAnimator = ValueAnimator.OfInt (255, 0);
                outAnimator.SetDuration (250);
                outAnimator.Update += (sender, e) => { currentBubbleTransparency = (int)e.Animation.AnimatedValue; Invalidate (); };
                outAnimator.AnimationEnd += (sender, e) => { this.count = count; outAnimator.RemoveAllListeners (); };
            } else {
                this.count = count;
            }

            var inAnimator = ValueAnimator.OfInt (0, 255);
            inAnimator.SetDuration (700);
            inAnimator.Update += (sender, e) => { currentBubbleTransparency = (int)e.Animation.AnimatedValue; Invalidate (); };
            inAnimator.AnimationEnd += (sender, e) => inAnimator.RemoveAllListeners ();

            if (outAnimator != null) {
                var set = new AnimatorSet ();
                set.PlaySequentially (outAnimator, inAnimator);
                set.Start ();
            } else {
                inAnimator.Start ();
            }
        }
        /// <summary>
        /// Playes a series of animations.
        /// </summary>
        /// <param name="animations">The series of animations to be played.</param>
        protected void PlayAnimations(ObjectAnimator[] animations)
        {
            AnimatorSet animatorSet = new AnimatorSet();
            animatorSet.PlaySequentially(animations);
            animatorSet.Start();

            //animatorSet.AnimationEnd
            //animatorSet.Pause
        }