private void AddAngleAnimation(AngleAnimation animation)
 {
     AngleTimeline.KeyFrames.Add(
         new LinearDoubleKeyFrame(
             -animation.StartAngle,
             KeyTime.FromTimeSpan(TimeSpan.FromSeconds(animation.StartTime)))
         );
     AngleTimeline.KeyFrames.Add(
         new LinearDoubleKeyFrame(
             -animation.EndAngle,
             KeyTime.FromTimeSpan(TimeSpan.FromSeconds(animation.EndTime)))
         );
 }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it

            Button button1 = FindViewById <Button>(Resource.Id.MyButton1);
            Button button2 = FindViewById <Button>(Resource.Id.MyButton2);

            Button button3 = FindViewById <Button>(Resource.Id.MyButton3);
            Button button4 = FindViewById <Button>(Resource.Id.MyButton4);

            button1.Click += delegate { button1.Text = string.Format("{0} clicks!", count++); };
            button2.Click += delegate { button2.Text = string.Format("{0} clicks!", count++); };
            button3.Click += delegate { button3.Text = string.Format("{0} clicks!", count++); };
            button4.Click += delegate { button4.Text = string.Format("{0} clicks!", count++); };

            button1.SetBackgroundColor(Android.Graphics.Color.Blue);
            button2.SetBackgroundColor(Android.Graphics.Color.Red);
            button3.SetBackgroundColor(Android.Graphics.Color.Green);
            button4.SetBackgroundColor(Android.Graphics.Color.SlateGray);

            JazzHandsHorizontalScrollView scrollView = FindViewById <JazzHandsHorizontalScrollView> (Resource.Id.ScrollView);

            scrollView.Pages = _totalPages;
            scrollView.Views.Add(button1);
            scrollView.Views.Add(button2);
            scrollView.Views.Add(button3);
            scrollView.Views.Add(button4);

            scrollView.PageScroll(FocusSearchDirection.Left);
            scrollView.FillViewport = true;

            Console.WriteLine("Setup Alpha Anim");
            AlphaAnimation button1AlphaAnim = new AlphaAnimation(button1);

            scrollView.Animator.AddAnimation(button1AlphaAnim);

            button1AlphaAnim.AddKeyFrame(new AnimationFrame()
            {
                Time  = TimeForPage(1),
                Alpha = 0.0f
            });
            button1AlphaAnim.AddKeyFrame(new AnimationFrame()
            {
                Time  = TimeForPage(2),
                Alpha = 1.0f
            });

            AlphaAnimation button2AlphaAnim = new AlphaAnimation(button2);

            scrollView.Animator.AddAnimation(button2AlphaAnim);

            button2AlphaAnim.AddKeyFrame(new AnimationFrame()
            {
                Time  = TimeForPage(1),
                Alpha = 0.0f
            });
            button2AlphaAnim.AddKeyFrame(new AnimationFrame()
            {
                Time  = TimeForPage(2),
                Alpha = 1.0f
            });


            Console.WriteLine("Setup Alpha Anim End");

            Console.WriteLine("Setup Frame Anim");

            var button1FrameAnimation = new FrameAnimation(button1);

            scrollView.Animator.AddAnimation(button1FrameAnimation);

            var newAnimaitons = new List <AnimationFrameBase> ();

            var temp1 = new RectangleF(button1.GetX(), button1.GetY(), button1.Width, button1.Height);

            temp1.Offset(new PointF(0, 0));

            newAnimaitons.Add(new AnimationFrame()
            {
                Time  = TimeForPage(1),
                Frame = temp1
            });

            var temp2 = new RectangleF(button1.GetX(), button1.GetY(), button1.Width, button1.Height);

            temp2.Offset(new PointF(Resources.DisplayMetrics.WidthPixels, dy));

            newAnimaitons.Add(new AnimationFrame()
            {
                Time  = TimeForPage(2),
                Frame = temp2
            });

            var temp3 = new RectangleF(button1.GetX(), button1.GetY(), button1.Width, button1.Height);

            temp3.Offset(new PointF(Resources.DisplayMetrics.WidthPixels / 2, 0));

            newAnimaitons.Add(new AnimationFrame()
            {
                Time  = TimeForPage(3),
                Frame = temp3
            });

            button1FrameAnimation.AddKeyFrames(newAnimaitons);

            // button3

            var button3FrameAnimation = new FrameAnimation(button3);

            scrollView.Animator.AddAnimation(button3FrameAnimation);

            var newAnimaitonsbutton3 = new List <AnimationFrameBase> ();
            //
            //			var temp4 = new RectangleF (button3.GetX(), button3.GetY(), button3.Width, button3.Height);
            //			temp4.Offset (new PointF (button3.GetX(), button3.GetY()));
            //
            //			newAnimaitonsbutton3.Add (new AnimationKeyFrame () {
            //				Time = TimeForPage (1),
            //				Frame = temp4
            //			});
            //
            //			var temp5 = new RectangleF (button3.GetX(), button3.GetY(), button3.Width, button3.Height);
            //			temp5.Offset (new PointF (button3.GetX(),button3.GetY()));
            //
            //			newAnimaitonsbutton3.Add (new AnimationKeyFrame () {
            //				Time = TimeForPage (2),
            //				Frame = temp5
            //			});
            //
            //			var temp6 = new RectangleF (button3.GetX(), button3.GetY(), button3.Width, button3.Height);
            //			temp6.Offset (new PointF (button3.GetX(), button3.GetY()));
            //
            //			newAnimaitonsbutton3.Add (new AnimationKeyFrame () {
            //				Time = TimeForPage (3),
            //				Frame = temp6
            //			});

            var temp7 = new RectangleF(button3.GetX(), button3.GetY(), button3.Width, button3.Height);

            temp7.Offset(new PointF(button3.GetX(), button3.GetY() - 200));

            newAnimaitonsbutton3.Add(new AnimationFrame()
            {
                Time  = TimeForPage(4),
                Frame = temp7
            });


            button3FrameAnimation.AddKeyFrames(newAnimaitonsbutton3);

            Console.WriteLine("Setup Frame Anim End");

            //ToDo: Hide Animation

            HideAnimation button3HideAnimation = new HideAnimation(button3);

            scrollView.Animator.AddAnimation(button3HideAnimation);

            button3HideAnimation.AddKeyFrame(new AnimationFrame()
            {
                Time       = TimeForPage(2),
                Visibility = ViewStates.Invisible
            });

            //ToDo: Angle Animation

            AngleAnimation button2AngleAnimation = new AngleAnimation(button3);

            scrollView.Animator.AddAnimation(button2AngleAnimation);

            button2AngleAnimation.AddKeyFrames(
                new List <AnimationFrameBase>()
            {
                new AnimationFrame()
                {
                    Time  = TimeForPage(2),
                    Angle = 0.0f
                },
                new AnimationFrame()
                {
                    Time  = TimeForPage(3),
                    Angle = Convert.ToSingle(2 * Math.PI)
                },
                new AnimationFrame()
                {
                    Time  = TimeForPage(4),
                    Angle = 60.0f
                }
            });

            //ToDo : Color Animation

            ColorAnimation button3ColorAnimation = new ColorAnimation(button3);

            scrollView.Animator.AddAnimation(button3ColorAnimation);

            button3ColorAnimation.AddKeyFrames(
                new List <AnimationFrameBase>()
            {
                new AnimationFrame()
                {
                    Time  = TimeForPage(2),
                    Color = Android.Graphics.Color.Green
                },
                new AnimationFrame()
                {
                    Time  = TimeForPage(3),
                    Color = Android.Graphics.Color.Blue
                }
            });
        }
示例#3
0
        private void ConfigureAnimation()
        {
            Single dy = 240;
            // apply a 3D zoom animation to the first label
            Transform3DAnimation labelTransform = new Transform3DAnimation(FirstLabel, 0.3f);
            Transform3D          tt1            = new Transform3D()
            {
                M34 = 0.03f
            };
            Transform3D tt2 = new Transform3D()
            {
                M34 = 0.3f
            };

            tt2.Rotate = new Transform3DRotate {
                Angle = Convert.ToSingle(Math.PI), X = 1, Y = 0, Z = 0
            };
            tt2.Translate = new Transform3DTranslate()
            {
                Tx = 320, Ty = 150, Tz = -50
            };
            tt2.Scale = new Transform3DScale()
            {
                Sx = 1.0f, Sy = 1.0f, Sz = 1.0f
            };
            labelTransform.AddKeyFrame(new AnimationFrame()
            {
                Time  = TimeForPage(0),
                Alpha = 1.0f
            });
            labelTransform.AddKeyFrame(new AnimationFrame()
            {
                Time      = TimeForPage(1),
                Transform = tt1
            });
            labelTransform.AddKeyFrame(new AnimationFrame()
            {
                Time      = TimeForPage(1.5f),
                Transform = tt2
            });
            //	        labelTransform.AddKeyFrame(new AnimationKeyFrame()
            //	        {
            //	            Time = TimeForPage(1.5f) + 1,
            //	            Alpha = 0.0f
            //	        });
            Animator.AddAnimation(labelTransform);

            // let's animate the wordmark
            var wordmarkFrameAnimation = new FrameAnimation(Wordmark);

            Animator.AddAnimation(wordmarkFrameAnimation);

            var newAnimaitons = new List <AnimationFrameBase> ();

            var temp1 = Wordmark.Frame;

            temp1.Offset(new CGPoint(200, 0));

            newAnimaitons.Add(new AnimationFrame()
            {
                Time  = TimeForPage(1),
                Frame = temp1
            });

            newAnimaitons.Add(new AnimationFrame()
            {
                Time = TimeForPage(2), Frame = Wordmark.Frame
            });


            var temp2 = Wordmark.Frame;

            temp2.Offset(new CGPoint((float)View.Frame.Width, dy));

            newAnimaitons.Add(new AnimationFrame()
            {
                Time  = TimeForPage(3),
                Frame = temp2
            });

            var temp3 = Wordmark.Frame;

            temp3.Offset(new CGPoint(0, dy));

            newAnimaitons.Add(new AnimationFrame()
            {
                Time  = TimeForPage(4),
                Frame = temp3
            });

            wordmarkFrameAnimation.AddKeyFrames(newAnimaitons);

            //Rotate a full circle from page 2 to 3
            var wordmarkRotationAnimation = new AngleAnimation(Wordmark);

            Animator.AddAnimation(wordmarkRotationAnimation);
            wordmarkRotationAnimation.AddKeyFrames(
                new List <AnimationFrameBase>()
            {
                new AnimationFrame()
                {
                    Time  = TimeForPage(2),
                    Angle = 0.0f
                },
                new AnimationFrame()
                {
                    Time  = TimeForPage(3),
                    Angle = Convert.ToSingle(2 * Math.PI)
                }
            });

            // now, we animate the unicorn
            FrameAnimation unicornFrameAnimation = new FrameAnimation(Unicorn);

            Animator.AddAnimation(unicornFrameAnimation);

            float ds = 50f;

            // move down and to the right, and shrink between pages 2 and 3
            unicornFrameAnimation.AddKeyFrame(new AnimationFrame {
                Time  = TimeForPage(2),
                Frame = Unicorn.Frame
            });

            Unicorn.Frame = CGRect.Inflate(Unicorn.Frame, -ds, -ds);


            var uTemp1 = Unicorn.Frame;

            uTemp1.Offset(TimeForPage(2), dy);
            Unicorn.Frame = uTemp1;

            var animKeyFrame = new AnimationFrame
            {
                Time  = TimeForPage(3),
                Frame = Unicorn.Frame
            };

            unicornFrameAnimation.AddKeyFrame(animKeyFrame);

            // fade the unicorn in on page 2 and out on page 4
            AlphaAnimation unicornAlphaAnimation = new AlphaAnimation(Unicorn);

            Animator.AddAnimation(unicornAlphaAnimation);

            unicornAlphaAnimation.AddKeyFrame(new AnimationFrame()
            {
                Time  = TimeForPage(1),
                Alpha = 0.0f
            });
            unicornAlphaAnimation.AddKeyFrame(new AnimationFrame()
            {
                Time  = TimeForPage(2),
                Alpha = 1.0f
            });
            unicornAlphaAnimation.AddKeyFrame(new AnimationFrame()
            {
                Time  = TimeForPage(3),
                Alpha = 1.0f
            });
            unicornAlphaAnimation.AddKeyFrame(new AnimationFrame()
            {
                Time  = TimeForPage(4),
                Alpha = 0.0f
            });

            // Fade out the label by dragging on the last page
            AlphaAnimation labelAlphaAnimation = new AlphaAnimation(this.LastLabel);

            labelAlphaAnimation.AddKeyFrame(new AnimationFrame()
            {
                Time  = TimeForPage(4),
                Alpha = 1.0f
            });
            labelAlphaAnimation.AddKeyFrame(new AnimationFrame()
            {
                Time  = TimeForPage(4.35f),
                Alpha = 0.0f
            });
            Animator.AddAnimation(labelAlphaAnimation);
        }