Ejemplo n.º 1
0
        public void SwipeRight()
        {
            var spots = ExtractRemainingTouristSpots();

            if (spots.Count == 0)
            {
                return;
            }

            View target = _cardStackView.TopView;

            ValueAnimator rotation = ObjectAnimator.OfPropertyValuesHolder(target, PropertyValuesHolder.OfFloat("rotation", 10f));

            rotation.SetDuration(200);
            ValueAnimator translateX = ObjectAnimator.OfPropertyValuesHolder(target, PropertyValuesHolder.OfFloat("translationX", 0f, 2000f));
            ValueAnimator translateY = ObjectAnimator.OfPropertyValuesHolder(target, PropertyValuesHolder.OfFloat("translationY", 0f, 500f));

            translateX.StartDelay = 100;
            translateY.StartDelay = 100;
            translateX.SetDuration(500);
            translateY.SetDuration(500);
            var set = new AnimatorSet();

            set.PlayTogether(rotation, translateX, translateY);

            _cardStackView.Swipe(SwipeDirection.Right, set);
        }
Ejemplo n.º 2
0
        /**
         * This method animates the image fragment into the background by both
         * scaling and rotating the fragment's view, as well as adding a
         * translucent dark hover view to inform the user that it is inactive.
         */
        public void SlideBack()
        {
            View movingFragmentView = mImageFragment.View;

            PropertyValuesHolder rotateX = PropertyValuesHolder.OfFloat("rotationX", 40f);
            PropertyValuesHolder scaleX  = PropertyValuesHolder.OfFloat("scaleX", 0.8f);
            PropertyValuesHolder scaleY  = PropertyValuesHolder.OfFloat("scaleY", 0.8f);
            ObjectAnimator       movingFragmentAnimator = ObjectAnimator.
                                                          OfPropertyValuesHolder(movingFragmentView, rotateX, scaleX, scaleY);

            ObjectAnimator darkHoverViewAnimator = ObjectAnimator.
                                                   OfFloat(mDarkHoverView, "alpha", 0.0f, 0.5f);

            ObjectAnimator movingFragmentRotator = ObjectAnimator.
                                                   OfFloat(movingFragmentView, "rotationX", 0);

            movingFragmentRotator.StartDelay = Resources.GetInteger(Resource.Integer.half_slide_up_down_duration);

            AnimatorSet s = new AnimatorSet();

            s.PlayTogether(movingFragmentAnimator, darkHoverViewAnimator, movingFragmentRotator);
            s.AnimationEnd += delegate
            {
                FragmentTransaction transaction = FragmentManager.BeginTransaction();
                transaction.SetCustomAnimations(Resource.Animator.slide_fragment_in, 0, 0, Resource.Animator.slide_fragment_out);
                transaction.Add(Resource.Id.move_to_back_container, mTextFragment);
                transaction.AddToBackStack(null);
                transaction.Commit();
            };
            s.Start();
        }
        public static ValueAnimator JiggleBilly(this View view, float scaleAmount = 1.3f, float jiggleDegrees = 15f, int jiggleCount = 3, long duration = DefaultAnimationDuration)
        {
            var jiggleRotation = new List <float>();

            jiggleRotation.Add(0f);
            for (int i = 0; i < jiggleCount; i++)
            {
                jiggleRotation.Add(jiggleDegrees);
                jiggleRotation.Add(-jiggleDegrees);
            }
            jiggleRotation.Add(0f);


            var scale = ObjectAnimator.OfPropertyValuesHolder(
                view,
                PropertyValuesHolder.OfFloat("scaleX", 1, scaleAmount, 1),
                PropertyValuesHolder.OfFloat("scaleY", 1, scaleAmount, 1),
                PropertyValuesHolder.OfFloat("rotation", jiggleRotation.ToArray())
                );

            scale.RepeatMode = ValueAnimatorRepeatMode.Reverse;
            scale.SetInterpolator(new AccelerateDecelerateInterpolator());
            scale.SetDuration(duration);
            scale.RepeatCount = 0;
            scale.Start();
            return(scale);
        }
Ejemplo n.º 4
0
        /**
         * This method animates the image fragment into the foreground by both
         * scaling and rotating the fragment's view, while also removing the
         * previously added translucent dark hover view. Upon the completion of
         * this animation, the image fragment regains focus since this method is
         * called from the onBackStackChanged method.
         */
        public void SlideForward()
        {
            View movingFragmentView = mImageFragment.View;

            PropertyValuesHolder rotateX = PropertyValuesHolder.OfFloat("rotationX", 40f);
            PropertyValuesHolder scaleX  = PropertyValuesHolder.OfFloat("scaleX", 1.0f);
            PropertyValuesHolder scaleY  = PropertyValuesHolder.OfFloat("scaleY", 1.0f);
            ObjectAnimator       movingFragmentAnimator = ObjectAnimator.
                                                          OfPropertyValuesHolder(movingFragmentView, rotateX, scaleX, scaleY);

            ObjectAnimator darkHoverViewAnimator = ObjectAnimator.
                                                   OfFloat(mDarkHoverView, "alpha", 0.5f, 0.0f);

            ObjectAnimator movingFragmentRotator = ObjectAnimator.
                                                   OfFloat(movingFragmentView, "rotationX", 0);

            movingFragmentRotator.StartDelay = Resources.GetInteger(Resource.Integer.half_slide_up_down_duration);

            AnimatorSet s = new AnimatorSet();

            s.PlayTogether(movingFragmentAnimator, movingFragmentRotator, darkHoverViewAnimator);
            s.StartDelay    = Resources.GetInteger(Resource.Integer.slide_up_down_duration);
            s.AnimationEnd += delegate
            {
                mIsAnimating = false;
            };
            s.Start();
        }
        public override ObjectAnimator GetSwipeOutAnimator(View view, float deltaX, float deltaY)
        {
            float endX, endRotationY;

            float deltaXAbs = Math.Abs(deltaX);

            float fractionCovered = 1f - (deltaXAbs / view.Width);
            long  duration        = Math.Abs((int)((1 - fractionCovered) * 200 * mSpeedFactor));

            endX = deltaX < 0 ? -view.Width : view.Width;
            if (deltaX > 0)
            {
                endRotationY = -15f;
            }
            else
            {
                endRotationY = 15f;
            }

            // Animate position and alpha of swiped item
            return((ObjectAnimator)ObjectAnimator.OfPropertyValuesHolder(view,
                                                                         PropertyValuesHolder.OfFloat("alpha", 0f),
                                                                         PropertyValuesHolder.OfFloat("translationX", endX),
                                                                         PropertyValuesHolder.OfFloat("rotationY", endRotationY)).SetDuration(duration));
        }
Ejemplo n.º 6
0
        void SnapView(bool dismiss = true)
        {
            if (targetView == null)
            {
                return;
            }
            var targetAlpha       = dismiss ? 0 : 1;
            var targetTranslation = dismiss ? targetView.Width : 0;
            var a = ObjectAnimator.OfPropertyValuesHolder(
                targetView,
                PropertyValuesHolder.OfFloat("alpha", targetView.Alpha, targetAlpha),
                PropertyValuesHolder.OfFloat("translationX", targetView.TranslationX, targetTranslation)
                );

            if (dismiss)
            {
                a.AnimationEnd += (sender, e) => {
                    ((ValueAnimator)sender).RemoveAllListeners();
                    if (ItemSwipped != null)
                    {
                        ItemSwipped(this, EventArgs.Empty);
                    }
                };
            }
            a.Start();
        }
Ejemplo n.º 7
0
        public DroidAnimator ScaleTo(float[] scales, float[] scaleDurations, double?durationSeconds, double?delaySeconds, AnimationInterpolation?interpolation)
        {
            return(base.ExecuteFunction <DroidAnimator>("ScaleTo", delegate()
            {
                PropertyValuesHolder propX = PropertyValuesHolder.OfFloat("scaleX", scales);
                PropertyValuesHolder propY = PropertyValuesHolder.OfFloat("scaleY", scales);
                if (scaleDurations != null && (scaleDurations.Length > 0))
                {
                    int keyFrameCount = scaleDurations.Length;
                    if (scales.Length < keyFrameCount)
                    {
                        keyFrameCount -= keyFrameCount - scales.Length;
                    }
                    Keyframe[] keyFrames = new Keyframe[keyFrameCount];
                    for (int i = 0; i < keyFrameCount; i++)
                    {
                        keyFrames[i] = Keyframe.OfFloat(scaleDurations[i], scales[i]);
                    }
                    propX.SetKeyframes(keyFrames);
                    propY.SetKeyframes(keyFrames);
                }

                ObjectAnimator fadeAnimator = ObjectAnimator.OfPropertyValuesHolder(this.TargetView, propX, propY);
                SetDefaultsFor(fadeAnimator, durationSeconds, delaySeconds, interpolation);
                _animators.Add(fadeAnimator);

                return this;
            }));
        }
Ejemplo n.º 8
0
        public Animator CreateAnimation(View view, float startScale, float endScale)
        {
            view.ScaleX = startScale;
            view.ScaleY = startScale;
            PropertyValuesHolder holderX = PropertyValuesHolder.OfFloat("scaleX", startScale, endScale);
            PropertyValuesHolder holderY = PropertyValuesHolder.OfFloat("scaleY", startScale, endScale);

            return(ObjectAnimator.OfPropertyValuesHolder(view, holderX, holderY));
        }
        public override ObjectAnimator GetInitialAnimator(Android.Content.Context context)
        {
            ObjectAnimator animator = ObjectAnimator.OfPropertyValuesHolder(
                PropertyValuesHolder.OfFloat("alpha", 0.5f, 1f),
                PropertyValuesHolder.OfFloat("rotation", 60f, 0f));

            animator.SetDuration((long)(200 * mSpeedFactor));
            return(animator);
        }
Ejemplo n.º 10
0
        public void ToggleVisibleTitles()
        {
            // Use these for custom animations.
            FragmentManager fm         = FragmentManager;
            TitlesFragment  f          = (TitlesFragment)fm.FindFragmentById(Resource.Id.frag_title);
            View            titlesView = f.View;

            mLabelIndex = 1 - mLabelIndex;

            // Determine if we're in portrait, and whether we're showing or hiding the titles
            // with this toggle.
            bool isPortrait = Resources.Configuration.Orientation ==
                              Android.Content.Res.Orientation.Portrait;

            bool shouldShow = f.IsHidden || mCurrentTitlesAnimator != null;

            // Cancel the current titles animation if there is one.
            if (mCurrentTitlesAnimator != null)
            {
                mCurrentTitlesAnimator.Cancel();
            }

            // Begin setting up the object animator. We'll animate the bottom or right edge of the
            // titles view, as well as its alpha for a fade effect.
            ObjectAnimator objectAnimator = ObjectAnimator.OfPropertyValuesHolder(
                titlesView,
                PropertyValuesHolder.OfInt(
                    isPortrait ? "bottom" : "right",
                    shouldShow ? Resources.GetDimensionPixelSize(Resource.Dimension.titles_size)
                                 : 0),
                PropertyValuesHolder.OfFloat("alpha", shouldShow ? 1 : 0)
                );

            // At each step of the animation, we'll perform layout by calling setLayoutParams.
            ViewGroup.LayoutParams lp = titlesView.LayoutParameters;
            objectAnimator.AddUpdateListener(new AnimatorUpdateListener(isPortrait, titlesView, lp));

            if (shouldShow)
            {
                fm.BeginTransaction().Show(f).Commit();
                objectAnimator.AddListener(new ObjectAnimatorListenerAdapter(this));
            }
            else
            {
                objectAnimator.AddListener(new ObjectAnimatorListenerAdapter2(this, fm, f));
            }

            // Start the animation.
            objectAnimator.Start();
            mCurrentTitlesAnimator = objectAnimator;

            InvalidateOptionsMenu();

            // Manually trigger onNewIntent to check for ACTION_DIALOG.
            OnNewIntent(Intent);
        }
        public override ObjectAnimator GetDisappearingAnimator(Android.Content.Context context)
        {
            ObjectAnimator animator = ObjectAnimator.OfPropertyValuesHolder(
                PropertyValuesHolder.OfFloat("alpha", 1f, 0f),
                PropertyValuesHolder.OfFloat("scaleX", 1f, 0f),
                PropertyValuesHolder.OfFloat("scaleY", 1f, 0f),
                PropertyValuesHolder.OfFloat("rotation", 0f, 270f));

            animator.SetDuration((long)(200 * mSpeedFactor));
            return(animator);
        }
Ejemplo n.º 12
0
        private void PulseView(View view)
        {
            view.ClearAnimation();

            var a = ObjectAnimator.OfPropertyValuesHolder(view, PropertyValuesHolder.OfFloat("scaleX", 0.8f), PropertyValuesHolder.OfFloat("scaleY", 0.8f));

            a.SetDuration(500);
            a.RepeatCount = ObjectAnimator.Infinite;
            a.RepeatMode  = ValueAnimatorRepeatMode.Reverse;

            a.Start();
        }
        private Animator InitInnerContainerAnimations()
        {
            var scaleUpAnimator = ObjectAnimator.OfPropertyValuesHolder(
                innerContainer,
                PropertyValuesHolder.OfFloat("scaleX", 0.60f, 1f),
                PropertyValuesHolder.OfFloat("scaleY", 0.60f, 1f),
                PropertyValuesHolder.OfFloat("alpha", 0f, 1f)
                );

            scaleUpAnimator.SetInterpolator(new OvershootInterpolator());
            scaleUpAnimator.SetDuration(500);
            return((Animator)scaleUpAnimator);
        }
        public static ValueAnimator Scale(this View view, float scaleAmount, long duration = DefaultAnimationDuration)
        {
            var scale = ObjectAnimator.OfPropertyValuesHolder(
                view,
                PropertyValuesHolder.OfFloat("scaleX", 1, scaleAmount),
                PropertyValuesHolder.OfFloat("scaleY", 1, scaleAmount)
                );

            scale.SetDuration(duration);
            scale.RepeatCount = 0;
            scale.Start();
            return(scale);
        }
Ejemplo n.º 15
0
        public virtual DroidAnimator MoveTo(PointF fromPoint, PointF toPoint, double?durationSeconds, double?delaySeconds, AnimationInterpolation?interpolation)
        {
            return(base.ExecuteFunction <DroidAnimator>("MoveTo", delegate()
            {
                PropertyValuesHolder propX = PropertyValuesHolder.OfFloat("X", fromPoint.X, toPoint.X);
                PropertyValuesHolder propY = PropertyValuesHolder.OfFloat("Y", fromPoint.Y, toPoint.Y);

                ObjectAnimator positionAnimator = ObjectAnimator.OfPropertyValuesHolder(this.TargetView, propX, propY);
                this.SetDefaultsFor(positionAnimator, durationSeconds, delaySeconds, interpolation);
                _animators.Add(positionAnimator);

                return this;
            }));
        }
Ejemplo n.º 16
0
        public DroidAnimator SizeTo(SizeF size, double?durationSeconds, double?delaySeconds, AnimationInterpolation?interpolation)
        {
            return(base.ExecuteFunction <DroidAnimator>("SizeTo", delegate()
            {
                PropertyValuesHolder propX = PropertyValuesHolder.OfFloat("scaleX", size.Width / this.TargetView.Width);
                PropertyValuesHolder propY = PropertyValuesHolder.OfFloat("scaleY", size.Height / this.TargetView.Height);

                ObjectAnimator fadeAnimator = ObjectAnimator.OfPropertyValuesHolder(this.TargetView, propX, propY);
                SetDefaultsFor(fadeAnimator, durationSeconds, delaySeconds, interpolation);
                _animators.Add(fadeAnimator);

                return this;
            }));
        }
        public static ValueAnimator Pulsate(this View view, float pulsateSize = .9f, long duration = DefaultAnimationDuration)
        {
            var scale = ObjectAnimator.OfPropertyValuesHolder(
                view,
                PropertyValuesHolder.OfFloat("scaleX", 1, pulsateSize),
                PropertyValuesHolder.OfFloat("scaleY", 1, pulsateSize)
                );

            scale.RepeatMode = ValueAnimatorRepeatMode.Reverse;
            scale.SetDuration(duration / 2);
            scale.RepeatCount = ValueAnimator.Infinite;
            scale.Start();
            return(scale);
        }
Ejemplo n.º 18
0
            private void CreateAnimation()
            {
                if (animation == null)
                {
                    ShapeHolder ball;

                    ball = balls[0];
                    var yBouncer = ObjectAnimator.OfFloat(ball, "y", ball.Y, Height - BallSize);
                    yBouncer.SetDuration(Duration);
                    yBouncer.SetInterpolator(new CycleInterpolator(2));
                    yBouncer.Update += delegate
                    {
                        Invalidate();
                    };

                    ball = balls[1];
                    var pvhY          = PropertyValuesHolder.OfFloat("y", ball.Y, Height - BallSize);
                    var pvhAlpha      = PropertyValuesHolder.OfFloat("alpha", 1.0f, 0f);
                    var yAlphaBouncer = ObjectAnimator.OfPropertyValuesHolder(ball, pvhY, pvhAlpha);
                    yAlphaBouncer.SetDuration(Duration / 2);
                    yAlphaBouncer.SetInterpolator(new AccelerateInterpolator());
                    yAlphaBouncer.RepeatCount = 1;
                    yAlphaBouncer.RepeatMode  = ValueAnimatorRepeatMode.Reverse;

                    ball = balls[2];
                    var pvhW        = PropertyValuesHolder.OfFloat("width", ball.Width, ball.Width * 2);
                    var pvhH        = PropertyValuesHolder.OfFloat("height", ball.Height, ball.Height * 2);
                    var pvTX        = PropertyValuesHolder.OfFloat("x", ball.X, ball.X - BallSize / 2f);
                    var pvTY        = PropertyValuesHolder.OfFloat("y", ball.Y, ball.Y - BallSize / 2f);
                    var whxyBouncer = ObjectAnimator.OfPropertyValuesHolder(ball, pvhW, pvhH, pvTX, pvTY);
                    whxyBouncer.SetDuration(Duration / 2);
                    whxyBouncer.RepeatCount = 1;
                    whxyBouncer.RepeatMode  = ValueAnimatorRepeatMode.Reverse;

                    ball = balls[3];
                    pvhY = PropertyValuesHolder.OfFloat("y", ball.Y, Height - BallSize);
                    var ballX     = ball.X;
                    var kf0       = Keyframe.OfFloat(0f, ballX);
                    var kf1       = Keyframe.OfFloat(.5f, ballX + 100f);
                    var kf2       = Keyframe.OfFloat(1f, ballX + 50f);
                    var pvhX      = PropertyValuesHolder.OfKeyframe("x", kf0, kf1, kf2);
                    var yxBouncer = ObjectAnimator.OfPropertyValuesHolder(ball, pvhY, pvhX);
                    yxBouncer.SetDuration(Duration / 2);
                    yxBouncer.RepeatCount = 1;
                    yxBouncer.RepeatMode  = ValueAnimatorRepeatMode.Reverse;

                    animation = new AnimatorSet();
                    animation.PlayTogether(yBouncer, yAlphaBouncer, whxyBouncer, yxBouncer);
                }
            }
Ejemplo n.º 19
0
        private async Task FinalAnimationAsync()
        {
            if (_icon == null)
            {
                return;
            }

            _icon.SetImageResource(Resource.Drawable.fingerprint_accepted);
            var press = ObjectAnimator.OfPropertyValuesHolder(_icon, PropertyValuesHolder.OfFloat("scaleX", 0.7f), PropertyValuesHolder.OfFloat("scaleY", 0.7f));

            press.SetDuration(300);
            press.RepeatMode  = ValueAnimatorRepeatMode.Reverse;
            press.RepeatCount = 1;
            await press.StartAsync();
        }
Ejemplo n.º 20
0
        private async Task FinalAnimationAsync(Color color)
        {
            if (_icon == null)
            {
                return;
            }

            _icon.SetColorFilter(color);
            var press = ObjectAnimator.OfPropertyValuesHolder(_icon, PropertyValuesHolder.OfFloat("scaleX", 0.7f), PropertyValuesHolder.OfFloat("scaleY", 0.7f));

            press.SetDuration(300);
            press.RepeatMode  = ValueAnimatorRepeatMode.Reverse;
            press.RepeatCount = 1;
            await press.StartAsync();
        }
        public override ObjectAnimator GetAppearingAnimator(Android.Content.Context context)
        {
            Point          outPoint = new Point();
            IWindowManager wm       = context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();

            wm.DefaultDisplay.GetSize(outPoint);

            ObjectAnimator animator = ObjectAnimator.OfPropertyValuesHolder(
                PropertyValuesHolder.OfFloat("alpha", 0f, 1f),
                PropertyValuesHolder.OfFloat("translationY", outPoint.Y / 2f, 0f),
                PropertyValuesHolder.OfFloat("rotation", -45f, 0f));

            animator.SetDuration((long)(200 * mSpeedFactor));
            return(animator);
        }
Ejemplo n.º 22
0
        private async void AnimateImage()
        {
            ToneGenerator toneG = new ToneGenerator(Stream.Music, 50);

            while (shouldAnimate)
            {
                if (!googleApiClient.IsConnected)
                {
                    continue;
                }

                float opacity = 0.1f;

                if (distanceMetres <= 10)
                {
                    opacity = 1;
                }
                else if (distanceMetres < 100)
                {
                    float finalOpacity = 1 - (float)distanceMetres / 100;
                    if (finalOpacity > opacity)
                    {
                        opacity = finalOpacity;
                    }
                }

                image.Alpha = opacity;

                long animationDuration = Math.Max((long)Math.Min(1000, distanceMetres), 10);

                ObjectAnimator scaleDown = ObjectAnimator.OfPropertyValuesHolder(image,
                                                                                 PropertyValuesHolder.OfFloat("scaleX", 1.2f),
                                                                                 PropertyValuesHolder.OfFloat("scaleY", 1.2f));
                scaleDown.SetDuration(Math.Max(animationDuration, 50));

                scaleDown.RepeatCount = 1;
                scaleDown.RepeatMode  = ValueAnimatorRepeatMode.Reverse;

                RunOnUiThread(() =>
                {
                    scaleDown.Start();
                });

                toneG.StartTone(Tone.CdmaAlertCallGuard, 50);
                await System.Threading.Tasks.Task.Delay((int)animationDuration * 5);
            }
            toneG.Release();
        }
Ejemplo n.º 23
0
        public void StartAnimation(bool slowMode)
        {
            textBubble.Visibility = ViewStates.Visible;
            textBubble.PivotX     = textBubble.Width / 2;
            textBubble.PivotY     = 0;

            var fallTime = 270;
            var time     = 600;

            if (slowMode)
            {
                fallTime *= 4;
                time     *= 5;
            }

            var interpolator = curve.ToAndroidInterpolator();

            var deltaY   = TypedValue.ApplyDimension(ComplexUnitType.Dip, 200, Resources.DisplayMetrics);
            var animator = ObjectAnimator.OfPropertyValuesHolder(textBubble,
                                                                 PropertyValuesHolder.OfFloat("translationY", deltaY, 0),
                                                                 PropertyValuesHolder.OfFloat("alpha", 0, 1));

            animator.SetAutoCancel(true);
            animator.SetDuration(fallTime);
            animator.SetInterpolator(new Android.Views.Animations.AccelerateInterpolator());

            var squashStretch = ObjectAnimator.OfPropertyValuesHolder(textBubble,
                                                                      PropertyValuesHolder.OfFloat("scaleY", 1f, 0.4f),
                                                                      PropertyValuesHolder.OfFloat("scaleX", 1f, 1.1f));

            squashStretch.SetAutoCancel(true);
            squashStretch.SetDuration(time);
            squashStretch.SetInterpolator(interpolator);

            if (AnimationCurrentCompletion != null)
            {
                squashStretch.AnimationEnd += (sender, e) => {
                    AnimationCurrentCompletion(-1);
                    ((Animator)sender).RemoveAllListeners();
                };
                squashStretch.Update += (sender, e) => AnimationCurrentCompletion(e.Animation.CurrentPlayTime / (float)time);
            }

            var animSet = new AnimatorSet();

            animSet.PlaySequentially(animator, squashStretch);
            animSet.Start();
        }
        private static IEnumerable <PropertyValuesHolder> CreatePropertyValues(TransitionValues startValues, TransitionValues endValues)
        {
            foreach (var propertyName in AnimateProperties())
            {
                var   fullName = $"{Prefix}:{propertyName}";
                float start    = (float)startValues.Values[fullName],
                      end      = (float)endValues.Values[fullName];

                // ReSharper disable once CompareOfFloatsByEqualityOperator
                if (start == end)
                {
                    continue;
                }

                yield return(PropertyValuesHolder.OfFloat(propertyName, start, end));
            }
        }
        public override ObjectAnimator GetSwipeInAnimator(View view, float deltaX, float deltaY)
        {
            float deltaXAbs       = Math.Abs(deltaX);
            float fractionCovered = 1f - (deltaXAbs / view.Width);
            long  duration        = Math.Abs((int)((1 - fractionCovered) * 200 * mSpeedFactor));

            // Animate position and alpha of swiped item

            ObjectAnimator animator = ObjectAnimator.OfPropertyValuesHolder(view,
                                                                            PropertyValuesHolder.OfFloat("alpha", 1f),
                                                                            PropertyValuesHolder.OfFloat("translationX", 0f),
                                                                            PropertyValuesHolder.OfFloat("rotationY", 0f));

            animator.SetDuration(duration).SetInterpolator(new BounceInterpolator());

            return(animator);
        }
        public static ValueAnimator ResetAnimation(this View view, long duration = DefaultAnimationDuration, ITimeInterpolator interpolator = null)
        {
            System.Diagnostics.Debug.WriteLine("Reset Values");

            var reset = ObjectAnimator.OfPropertyValuesHolder(
                view,
                PropertyValuesHolder.OfFloat("translationY", view.TranslationY, 0f),
                PropertyValuesHolder.OfFloat("translationX", view.TranslationX, 0f),
                PropertyValuesHolder.OfFloat("scaleX", view.ScaleX, 1.0f),
                PropertyValuesHolder.OfFloat("scaleY", view.ScaleY, 1.0f),
                PropertyValuesHolder.OfFloat("rotation", view.Rotation, 0.0f),
                PropertyValuesHolder.OfFloat("rotationX", view.RotationX, 0.0f),
                PropertyValuesHolder.OfFloat("rotationY", view.RotationY, 0.0f),
                PropertyValuesHolder.OfFloat("alpha", view.Alpha, 1.0f));

            reset.SetInterpolator(interpolator ?? new AccelerateDecelerateInterpolator());
            reset.SetDuration(duration);
            reset.RepeatCount = 0;
            reset.Start();
            return(reset);
        }
Ejemplo n.º 27
0
        private async Task FallbackAnimationAsync()
        {
            if (_icon == null)
            {
                return;
            }

            var rotate = ObjectAnimator.OfFloat(_icon, "rotationY", 0f, 180f);
            var fade   = ObjectAnimator.OfFloat(_icon, "alpha", 1f, 0f);
            var scale  = ObjectAnimator.OfPropertyValuesHolder(_icon, PropertyValuesHolder.OfFloat("scaleX", 0.4f), PropertyValuesHolder.OfFloat("scaleY", 0.4f));

            rotate.SetDuration(200);
            fade.SetDuration(600);
            scale.SetDuration(600);

            var animation = new AnimatorSet();

            animation.Play(rotate).Before(scale);
            animation.Play(fade).With(scale);
            await animation.StartAsync();
        }
Ejemplo n.º 28
0
        void Initialize()
        {
            ScaleX = ScaleY = 1;
            var baseDuration = 1000;

            animation = new AnimatorSet();
            var rotation = ObjectAnimator.OfFloat(this, "rotation", 0, 60);

            rotation.SetDuration(baseDuration);
            rotation.RepeatCount = ValueAnimator.Infinite;
            var scale = ObjectAnimator.OfPropertyValuesHolder(
                this,
                PropertyValuesHolder.OfFloat("scaleX", 1, .9f),
                PropertyValuesHolder.OfFloat("scaleY", 1, .9f)
                );

            scale.RepeatMode = ValueAnimatorRepeatMode.Reverse;
            scale.SetDuration(baseDuration / 2);
            scale.RepeatCount = ValueAnimator.Infinite;
            animation.PlayTogether(rotation, scale);
            animation.Start();
        }
Ejemplo n.º 29
0
        public void SwipeRight()
        {
            var spots = ExtractRemainingTouristSpots();

            if (spots.Count == 0)
            {
                return;
            }

            View target        = cardStackView.TopView;
            View targetOverlay = cardStackView.TopView.GetOverlayContainer();

            ValueAnimator rotation = ObjectAnimator.OfPropertyValuesHolder(
                target, PropertyValuesHolder.OfFloat("rotation", 10f));

            rotation.SetDuration(200);
            ValueAnimator translateX = ObjectAnimator.OfPropertyValuesHolder(
                target, PropertyValuesHolder.OfFloat("translationX", 0f, 2000f));
            ValueAnimator translateY = ObjectAnimator.OfPropertyValuesHolder(
                target, PropertyValuesHolder.OfFloat("translationY", 0f, 500f));

            translateX.StartDelay = 100;
            translateY.StartDelay = 100;
            translateX.SetDuration(500);
            translateY.SetDuration(500);
            AnimatorSet cardAnimationSet = new AnimatorSet();

            cardAnimationSet.PlayTogether(rotation, translateX, translateY);

            ObjectAnimator overlayAnimator = ObjectAnimator.OfFloat(targetOverlay, "alpha", 0f, 1f);

            overlayAnimator.SetDuration(200);
            AnimatorSet overlayAnimationSet = new AnimatorSet();

            overlayAnimationSet.PlayTogether(overlayAnimator);

            cardStackView.Swipe(SwipeDirection.Right, cardAnimationSet, overlayAnimationSet);
        }
Ejemplo n.º 30
0
        public DroidAnimator TransitionBackgroundColor(int[] colors, float[] colorTransformDurations, double?durationSeconds, double?delaySeconds, AnimationInterpolation?interpolation)
        {
            return(base.ExecuteFunction <DroidAnimator>("BackgroundColorValue", delegate()
            {
                PropertyValuesHolder colorValues = PropertyValuesHolder.OfInt("backgroundColor", colors);
                if (colorTransformDurations == null || colorTransformDurations.Length == 0)
                {
                    colorTransformDurations = new float[colors.Length];
                    for (int i = 0; i < colors.Length; i++)
                    {
                        colorTransformDurations[i] = i / colors.Length;
                    }
                }
                if (colorTransformDurations != null && colorTransformDurations.Length > 0)
                {
                    int keyFrameCount = colorTransformDurations.Length;
                    if (colors.Length < keyFrameCount)
                    {
                        keyFrameCount -= (keyFrameCount - colors.Length);
                    }
                    Keyframe[] keyFrames = new Keyframe[keyFrameCount];
                    for (int i = 0; i < keyFrameCount; i++)
                    {
                        keyFrames[i] = Keyframe.OfFloat(colorTransformDurations[i], colors[i]);
                    }
                    colorValues.SetKeyframes(keyFrames);
                }

                ValueAnimator valueAnimator = ValueAnimator.OfPropertyValuesHolder(colorValues);
                valueAnimator.SetEvaluator(new ArgbEvaluator());
                SetDefaultsFor(valueAnimator, durationSeconds, delaySeconds, interpolation);
                valueAnimator.Update += colorValueAnimator_Update;
                _animators.Add(valueAnimator);

                return this;
            }));
        }