Пример #1
0
        private void CreateCustomAnimation()
        {
            FloatingActionMenu menu3 = FindViewById <FloatingActionMenu>(Resource.Id.menu3);

            AnimatorSet set = new AnimatorSet();

            ObjectAnimator scaleOutX = ObjectAnimator.OfFloat(menu3.MenuIconView, "scaleX", 1.0f, 0.2f);
            ObjectAnimator scaleOutY = ObjectAnimator.OfFloat(menu3.MenuIconView, "scaleY", 1.0f, 0.2f);

            ObjectAnimator scaleInX = ObjectAnimator.OfFloat(menu3.MenuIconView, "scaleX", 0.2f, 1.0f);
            ObjectAnimator scaleInY = ObjectAnimator.OfFloat(menu3.MenuIconView, "scaleY", 0.2f, 1.0f);

            scaleOutX.SetDuration(50);
            scaleOutY.SetDuration(50);

            scaleInX.SetDuration(150);
            scaleInY.SetDuration(150);

            scaleInX.AnimationStart += (object sender, EventArgs e) =>
            {
                menu3.MenuIconView.SetImageResource(menu3.IsOpened ? Resource.Drawable.ic_close : Resource.Drawable.ic_star);
            };

            set.Play(scaleOutX).With(scaleOutY);
            set.Play(scaleInX).With(scaleInY).After(scaleOutX);
            set.SetInterpolator(new OvershootInterpolator(2));

            menu3.IconToggleAnimatorSet = set;
        }
Пример #2
0
        private static AnimatorSet AnimateWaves(ImageView wave1, ImageView wave2, bool reverse = false)
        {
            var wave1X           = 0;
            var wave1TranslateTo = wave1.Width;

            var wave2X           = -wave2.Width;
            var wave2TranslateTo = 0;

            if (reverse)
            {
                wave1X           = wave2.Width;
                wave1TranslateTo = 0;

                wave2X           = 0;
                wave2TranslateTo = -wave2.Width;
            }

            wave1.TranslationX = wave1X;
            wave2.TranslationX = wave2X;

            var wave1TranslateX = AnimateRepeat(wave1, "translationX", wave1TranslateTo);
            var wave2TranslateX = AnimateRepeat(wave2, "translationX", wave2TranslateTo);

            var waveSet = new AnimatorSet();

            waveSet.SetDuration(1000);
            waveSet.SetInterpolator(new Android.Views.Animations.LinearInterpolator());
            waveSet.Play(wave1TranslateX).With(wave2TranslateX);

            return(waveSet);
        }
Пример #3
0
        /**
         * build FlexibleAnimation to control the progress
         *
         * @return Animatorset for control the progress
         */
        private AnimatorSet BuildFlexibleAnimation()
        {
            var ring      = _ring;
            var set       = new AnimatorSet();
            var increment = ValueAnimator.OfFloat(0, MaxProgressArc - MinProgressArc);

            increment.SetDuration(AnimatorDuration / 2);
            increment.SetInterpolator(new LinearInterpolator());
            increment.Update += (sender, e) =>
            {
                var sweeping = ring.sweeping;
                var value    = (float)e.Animation.AnimatedValue;
                ring.sweep = sweeping + value;
                Invalidate();
            };
            increment.AddListener(_animatorListener);
            var reduce = ValueAnimator.OfFloat(0, MaxProgressArc - MinProgressArc);

            reduce.SetDuration(AnimatorDuration / 2);
            reduce.SetInterpolator(_interpolator);
            reduce.Update += (sender, e) =>
            {
                var sweeping = ring.sweeping;
                var starting = ring.starting;
                var value    = (float)e.Animation.AnimatedValue;
                ring.sweep = sweeping - value;
                ring.start = starting + value;
            };
            set.Play(reduce).After(increment);
            return(set);
        }
Пример #4
0
        private AnimatorSet BuildExpandingAnimatorSet(ImageView expandedView, Rect startBounds, Rect finalBounds, float startScale)
        {
            // Each expanding animator is unique to the start location - we'll cache the AnimatorSet
            // instance based on the starting location.
            int key = startBounds.GetHashCode();

            if (_expandingAnimators.ContainsKey(key))
            {
                return(_expandingAnimators[key]);
            }

            AnimatorSet expandSet = new AnimatorSet();

            expandSet.Play(ObjectAnimator.OfFloat(expandedView, View.X, startBounds.Left, finalBounds.Left))
            .With(ObjectAnimator.OfFloat(expandedView, View.Y, startBounds.Top, finalBounds.Top))
            .With(ObjectAnimator.OfFloat(expandedView, "ScaleX", startScale, 1f))
            .With(ObjectAnimator.OfFloat(expandedView, "ScaleY", startScale, 1f));
            expandSet.SetDuration(_shortAnimationDuration);
            expandSet.SetInterpolator(new DecelerateInterpolator());
            expandSet.AnimationEnd    += NullOutCurrentAnimator;
            expandSet.AnimationCancel += NullOutCurrentAnimator;

            _expandingAnimators.Add(key, expandSet);
            return(expandSet);
        }
Пример #5
0
        /**
         * build FlexibleAnimation to control the progress
         *
         * @return Animatorset for control the progress
         */
        private AnimatorSet buildFlexibleAnimation()
        {
            Ring          ring      = mRing;
            AnimatorSet   set       = new AnimatorSet();
            ValueAnimator increment = ValueAnimator.OfFloat(0, MAX_PROGRESS_ARC - MIN_PROGRESS_ARC);

            increment.SetDuration(ANIMATOR_DURATION / 2);
            increment.SetInterpolator(new LinearInterpolator());
            increment.Update += (sender, e) =>
            {
                float sweeping = ring.sweeping;
                float value    = (float)e.Animation.AnimatedValue;
                ring.sweep = sweeping + value;
                Invalidate();
            };
            increment.AddListener(animatorListener);
            ValueAnimator reduce = ValueAnimator.OfFloat(0, MAX_PROGRESS_ARC - MIN_PROGRESS_ARC);

            reduce.SetDuration(ANIMATOR_DURATION / 2);
            reduce.SetInterpolator(interpolator);
            reduce.Update += (sender, e) =>
            {
                float sweeping = ring.sweeping;
                float starting = ring.starting;
                float value    = (float)e.Animation.AnimatedValue;
                ring.sweep = sweeping - value;
                ring.start = starting + value;
            };
            set.Play(reduce).After(increment);
            return(set);
        }
Пример #6
0
        private void AnimatoOnAppearance(TextView logo, Action onEnd = null)
        {
            logo.ScaleX = 0;
            logo.ScaleY = 0;

            var            duration   = 500;
            ObjectAnimator scaleDownX = ObjectAnimator.OfFloat(logo, "ScaleX", 1f);
            ObjectAnimator scaleDownY = ObjectAnimator.OfFloat(logo, "ScaleY", 1f);

            scaleDownX.SetDuration(duration);
            scaleDownY.SetDuration(duration);

            AnimatorSet scaleDown = new AnimatorSet();

            // scaleDown.SetDuration(duration);
            scaleDown.Play(scaleDownX).With(scaleDownY);
            // scaleDown.AnimationEnd += (s, e) => onEnd?.Invoke();

            scaleDown.Start();


            /*
             * new Android.OS.Handler().PostDelayed(() =>
             * {
             *  var bar = FindViewById(Resource.Id.progressBar) as ProgressBar;
             *  bar.Visibility = ViewStates.Visible;
             * }, 600);//*/
        }
Пример #7
0
        private void StartAnimation()
        {
            var sunYStart = _sunView.Top;
            var sunYEnd   = _skyView.Height;

            var heightAnimator = ObjectAnimator
                                 .OfFloat(_sunView, "y", sunYStart, sunYEnd)
                                 .SetDuration(3000);

            heightAnimator.SetInterpolator(new AccelerateInterpolator());

            var sunsetSkyAnimator = ObjectAnimator
                                    .OfInt(_skyView, "backgroundColor", _blueSkyColor, _sunsetSkyColor)
                                    .SetDuration(3000) as ObjectAnimator;

            sunsetSkyAnimator.SetEvaluator(new ArgbEvaluator());

            var nightSkyAnimator = ObjectAnimator
                                   .OfInt(_skyView, "backgroundColor", _sunsetSkyColor, _nightSkyColor)
                                   .SetDuration(1500) as ObjectAnimator;

            nightSkyAnimator.SetEvaluator(new ArgbEvaluator());

            var animatorSet = new AnimatorSet();

            animatorSet
            .Play(heightAnimator)
            .With(sunsetSkyAnimator)
            .Before(nightSkyAnimator);
            animatorSet.Start();
        }
Пример #8
0
        private AnimatorSet BuildShrinkingAnimatorSet(View bigView, View thumbView, Rect startBounds, float scale)
        {
            if (_shrinkingAnimators.ContainsKey(thumbView.Id))
            {
                return(_shrinkingAnimators[thumbView.Id]);
            }

            AnimatorSet shrinkSet = new AnimatorSet();

            shrinkSet.Play(ObjectAnimator.OfFloat(bigView, View.X, startBounds.Left))
            .With(ObjectAnimator.OfFloat(bigView, View.Y, startBounds.Top))
            .With(ObjectAnimator.OfFloat(bigView, "ScaleX", scale))
            .With(ObjectAnimator.OfFloat(bigView, "ScaleY", scale));
            shrinkSet.SetDuration(_shortAnimationDuration);
            shrinkSet.SetInterpolator(new DecelerateInterpolator());
            shrinkSet.AnimationEnd += (sender1, args1) => {
                thumbView.Alpha    = 1.0f;
                bigView.Visibility = ViewStates.Gone;
                NullOutCurrentAnimator(sender1, args1);
            };

            shrinkSet.AnimationCancel += (sender1, args1) => {
                thumbView.Alpha    = 1.0f;
                bigView.Visibility = ViewStates.Gone;
                NullOutCurrentAnimator(sender1, args1);
            };

            _shrinkingAnimators.Add(thumbView.Id, shrinkSet);
            return(shrinkSet);
        }
Пример #9
0
        public static AnimatorSet CreateMovementAnimation(View view, float canvasX, float canvasY, float offsetStartX, float offsetStartY, float offsetEndX, float offsetEndY, EventHandler animationEndHandler)
        {
            view.Alpha = INVISIBLE;

            var alphaIn = ObjectAnimator.OfFloat(view, ALPHA, INVISIBLE, VISIBLE).SetDuration(500);

            var setUpX = ObjectAnimator.OfFloat(view, COORD_X, canvasX + offsetStartX).SetDuration(INSTANT);
            var setUpY = ObjectAnimator.OfFloat(view, COORD_Y, canvasY + offsetStartY).SetDuration(INSTANT);

            var moveX = ObjectAnimator.OfFloat(view, COORD_X, canvasX + offsetEndX).SetDuration(1000);
            var moveY = ObjectAnimator.OfFloat(view, COORD_Y, canvasY + offsetEndY).SetDuration(1000);

            moveX.StartDelay = 1000;
            moveY.StartDelay = 1000;

            var alphaOut = ObjectAnimator.OfFloat(view, ALPHA, INVISIBLE).SetDuration(500);

            alphaOut.StartDelay = 2500;

            var aset = new AnimatorSet();

            aset.Play(setUpX).With(setUpY).Before(alphaIn).Before(moveX).With(moveY).Before(alphaOut);

            var handler = new Handler();

            handler.PostDelayed(() =>
            {
                animationEndHandler(view, EventArgs.Empty);
            }, 3000);

            return(aset);
        }
Пример #10
0
        public ExpandHelper(Context context, Callback callback, int small, int large)
        {
            this.smallSize      = small;
            this.maximumStretch = Math.Max(smallSize, 1) * StretchInterval;
            this.largeSize      = large;
            this.context        = context;
            this.callback       = callback;
            this.scaler         = new ViewScaler();
            this.gravity        = GravityFlags.Top;

            //this.scaleAnimation = ObjectAnimator.OfFloat (scaler, "Height", 0f);
            this.scaleAnimation         = ValueAnimator.OfFloat(0f);
            this.scaleAnimation.Update += (sender, e) => scaler.Height = (float)e.Animation.AnimatedValue;
            this.scaleAnimation.SetDuration(ExpandDuration);

            AnimatorListenerAdapter glowVisibilityController = new AnimatorListener();

            glowTopAnimation = ObjectAnimator.OfFloat(null, "alpha", 0f);
            glowTopAnimation.AddListener(glowVisibilityController);
            glowBottomAnimation = ObjectAnimator.OfFloat(null, "alpha", 0f);
            glowBottomAnimation.AddListener(glowVisibilityController);
            glowAnimationSet = new AnimatorSet();
            glowAnimationSet.Play(glowTopAnimation).With(glowBottomAnimation);
            glowAnimationSet.SetDuration(GlowDuration);

            detector = new DoubleSwipeDetector(context, new GestureDetector(this));
        }
Пример #11
0
        void DoAnimation2(bool really, Action changePic)
        {
            if (!really)
            {
                changePic();
            }
            else
            {
                var fdIn  = ObjectAnimator.OfFloat(this, "alpha", new float[] { 0, 1 });
                var fdOut = ObjectAnimator.OfFloat(this, "alpha", new float[] { 1, 0 });
                fdOut.AnimationEnd += (sender, e) => changePic();

                var animator = new AnimatorSet();
                animator.SetInterpolator(new LinearInterpolator());
                //animator.PlaySequentially (fdOut, fdIn);
                animator.Play(fdOut);
                animator.Play(fdIn).After(fdOut).After(2000);
                animator.Start();
            }
        }
Пример #12
0
        private void PlayAnimation()
        {
            var animator    = ObjectAnimator.OfFloat(this, "animationSeek", 0.0f, 1.0f);
            var animatorSet = new AnimatorSet();

            animatorSet.SetDuration(AnimationDuration);
            animatorSet.SetInterpolator(new DecelerateInterpolator());
            animatorSet.SetTarget(this);
            animatorSet.Play(animator);
            animatorSet.Start();
        }
Пример #13
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();
        }
Пример #14
0
        public static AnimatorSet CreateMovementAnimation(View view, float x, float y)
        {
            var alphaIn = ObjectAnimator.OfFloat(view, ALPHA, INVISIBLE, VISIBLE).SetDuration(500);

            var setUpX = ObjectAnimator.OfFloat(view, COORD_X, x).SetDuration(INSTANT);
            var setUpY = ObjectAnimator.OfFloat(view, COORD_Y, y).SetDuration(INSTANT);

            var aset = new AnimatorSet();

            aset.Play(setUpX).With(setUpY).Before(alphaIn);
            return(aset);
        }
        private void FirstSolution()
        {
            //using an AnimatorSet and Object Animator to rotate the view

            originalSet = new AnimatorSet();
            originalSet.SetInterpolator(new OvershootInterpolator(0.8f));
            originalSet.SetDuration(3000);

            ObjectAnimator dialrotate = ObjectAnimator.OfFloat(originalSolution, "rotation", 0, 826);

            originalSet.Play(dialrotate);
        }
        public void animate()
        {
            int startDelay = 0;

            mAnimSet = new AnimatorSet();

            for (int i = 0; i < mImageViewList.Count; i++)
            {
                ImageView dot = mImageViewList[i];
                //            ValueAnimator bounce = ObjectAnimator.ofFloat(dot, "y", mAnimMagnitude);
                ValueAnimator fadeIn = ObjectAnimator.OfFloat(dot, "alpha", 1f, 0.5f);
                ValueAnimator scaleX = ObjectAnimator.OfFloat(dot, "scaleX", 1f, 0.7f);
                ValueAnimator scaleY = ObjectAnimator.OfFloat(dot, "scaleY", 1f, 0.7f);

                fadeIn.SetDuration(mAnimDuration);
                fadeIn.SetInterpolator(new AccelerateDecelerateInterpolator());
                fadeIn.RepeatMode  = ValueAnimatorRepeatMode.Reverse;
                fadeIn.RepeatCount = ValueAnimator.Infinite;

                scaleX.SetDuration(mAnimDuration);
                scaleX.SetInterpolator(new AccelerateDecelerateInterpolator());
                fadeIn.RepeatMode  = ValueAnimatorRepeatMode.Reverse;
                fadeIn.RepeatCount = ValueAnimator.Infinite;

                scaleY.SetDuration(mAnimDuration);
                scaleY.SetInterpolator(new AccelerateDecelerateInterpolator());
                fadeIn.RepeatMode  = ValueAnimatorRepeatMode.Reverse;
                fadeIn.RepeatCount = ValueAnimator.Infinite;

                mAnimSet.Play(fadeIn).After(startDelay);
                mAnimSet.Play(scaleX).With(fadeIn);
                mAnimSet.Play(scaleY).With(fadeIn);

                mAnimSet.StartDelay = 500;

                startDelay += (mAnimDuration / (mImageViewList.Count - 1));
            }

            mAnimSet.Start();
        }
Пример #17
0
        public void Dismiss()
        {
            // Slide out animation
            var objectAnimator = ObjectAnimator.OfFloat(_viewToDisplay, "y", _rootView.Height - _viewToDisplay.LayoutParameters.Height, _rootView.Height);

            objectAnimator.SetDuration(300);
            var yAnimator = new AnimatorSet();

            yAnimator.Play(objectAnimator);
            yAnimator.AnimationEnd += (sender, e) =>
            {
                _rootView.RemoveView(_viewToDisplay);
            };
            yAnimator.Start();
        }
Пример #18
0
        private void Animate(params View[] view)
        {
            AnimatorSet animatorSet = new AnimatorSet();

            AnimatorSet.Builder builder = animatorSet.Play(new AnimatorSet());
            for (int i = 0; i < view.Length; i++)
            {
                ObjectAnimator scaleX = ObjectAnimator.OfFloat(view[i], "scaleX", 0.8f, 1f);
                ObjectAnimator scaleY = ObjectAnimator.OfFloat(view[i], "scaleY", 0.8f, 1f);
                builder.With(scaleX).With(scaleY);
            }
            animatorSet.SetDuration(500);
            animatorSet.SetInterpolator(new BounceInterpolator());
            animatorSet.Start();
        }
        private void NotWorking()
        {
            // This does not create an animation. Is it not possible to animate a vector drawable in code?
            // Am I missing a step here?

            VectorDrawable avd = (VectorDrawable)this.GetDrawable(Resource.Drawable.Needle);

            idealSolution.SetImageDrawable(avd);

            var rotate = ObjectAnimator.OfFloat(avd, "rotation", 0f, 756f).SetDuration(3000);

            notWorking = new AnimatorSet();
            notWorking.SetInterpolator(new AccelerateDecelerateInterpolator());
            notWorking.Play(rotate).With(ObjectAnimator.OfFloat(avd, "pivotX", 13.22f)).With(ObjectAnimator.OfFloat(rotate, "pivotY", 13.22f));
        }
        /// <summary>
        /// Flips a view, hiding one view and revealing another as the flip finished.
        /// </summary>
        /// <param name="view">View.</param>
        /// <param name="hideId">Hide identifier.</param>
        /// <param name="revealId">Reveal identifier.</param>
        private void FlipView(View view, int hideId, int revealId)
        {
            var fo      = AnimatorInflater.LoadAnimator(this, Resource.Animation.card_flip_left_out);
            var fi      = AnimatorInflater.LoadAnimator(this, Resource.Animation.card_flip_left_in);
            var fadeOut = AnimatorInflater.LoadAnimator(this, Resource.Animation.fade_out);
            var fadeIn  = AnimatorInflater.LoadAnimator(this, Resource.Animation.fade_in);

            var hideView   = view.FindViewById(hideId);
            var revealView = view.FindViewById(revealId);

            fo.SetTarget(view);
            fi.SetTarget(view);
            fadeOut.SetTarget(hideView);
            fadeIn.SetTarget(revealView);

            var animOut = new AnimatorSet();

            animOut.Play(fo);
            animOut.SetDuration(350);
            animOut.AnimationEnd += (obj, args) => {
                hideView.Visibility   = ViewStates.Gone;
                revealView.Visibility = ViewStates.Visible;
            };

            var animIn = new AnimatorSet();

            animIn.Play(fi);
            animIn.SetDuration(350);

            var animationSet = new AnimatorSet();

            animationSet.AnimationEnd += (obj, args) => {
                hideView.Visibility   = ViewStates.Gone;
                revealView.Visibility = ViewStates.Visible;
            };
            animationSet.Play(animOut)
            .Before(animIn);
            animationSet.Start();
        }
Пример #21
0
        public bool Show()
        {
            // Prevent multiple toasts to be displayed on home activity
            if (_rootView.ChildCount > 1 && _owner is HomeActivity)
            {
                return(false);
            }

            // Hide toast while setting its place on screen
            _viewToDisplay.Visibility = ViewStates.Invisible;

            // add the view to the rootview
            _rootView.AddView(_viewToDisplay);

            // Get size of the screen because sometimes _rootView.Height == 0
            var display = _owner.ApplicationContext.GetSystemService(Context.WindowService).JavaCast <IWindowManager>().DefaultDisplay;
            var metrics = new DisplayMetrics();

            display.GetMetrics(metrics);

            // Set the Toast a the bottom of the view
            _viewToDisplay.SetY(metrics.HeightPixels);

            // Now we can make it visible
            _viewToDisplay.Visibility = ViewStates.Visible;

            // Slide in animation
            var objectAnimator = ObjectAnimator.OfFloat(_viewToDisplay, "y", metrics.HeightPixels, metrics.HeightPixels - _viewToDisplay.LayoutParameters.Height);

            objectAnimator.SetDuration(300);
            var yAnimator = new AnimatorSet();

            yAnimator.Play(objectAnimator);
            yAnimator.Start();

            return(true);
        }
Пример #22
0
        private AnimatorSet AnimateBeat()
        {
            var scaleOutX = ObjectAnimator.OfFloat(elapsedTimeTxt, "scaleX", 1.05f);
            var scaleOutY = ObjectAnimator.OfFloat(elapsedTimeTxt, "scaleY", 1.05f);

            var beatOut = new AnimatorSet();

            beatOut.PlayTogether(scaleOutX, scaleOutY);
            beatOut.SetDuration(128);

            var restoreX = ObjectAnimator.OfFloat(elapsedTimeTxt, "scaleX", 1f);
            var restoreY = ObjectAnimator.OfFloat(elapsedTimeTxt, "scaleY", 1f);

            var restore = new AnimatorSet();

            restore.PlayTogether(restoreX, restoreY);
            restore.SetDuration(128);

            var beatAnimator = new AnimatorSet();

            beatAnimator.Play(beatOut).Before(restore);
            beatAnimator.SetInterpolator(new Android.Views.Animations.LinearInterpolator());
            return(beatAnimator);
        }
            public override bool OnTouchEvent(MotionEvent motionEvent)
            {
                if (motionEvent.Action != MotionEventActions.Down && motionEvent.Action != MotionEventActions.Move)
                {
                    return(false);
                }
                var newBall = AddBall(motionEvent.GetX(), motionEvent.GetY());

                // Bouncing animation with squash and stretch
                var startY   = newBall.Y;
                var endY     = Height - 50f;
                var h        = (float)Height;
                var eventY   = motionEvent.GetY();
                var duration = (int)(500 * ((h - eventY) / h));

                var bounceAnim = ObjectAnimator.OfFloat(newBall, "y", startY, endY);

                bounceAnim.SetDuration(duration);
                bounceAnim.SetInterpolator(new AccelerateInterpolator());
                var squashAnim1 = ObjectAnimator.OfFloat(newBall, "x", newBall.X, newBall.X - 25f);

                squashAnim1.SetDuration(duration / 4);
                squashAnim1.RepeatCount = 1;
                squashAnim1.RepeatMode  = ValueAnimatorRepeatMode.Reverse;
                squashAnim1.SetInterpolator(new DecelerateInterpolator());
                var squashAnim2 = ObjectAnimator.OfFloat(newBall, "width", newBall.Width, newBall.Width + 50);

                squashAnim2.SetDuration(duration / 4);
                squashAnim2.RepeatCount = 1;
                squashAnim2.RepeatMode  = ValueAnimatorRepeatMode.Reverse;
                squashAnim2.SetInterpolator(new DecelerateInterpolator());
                var stretchAnim1 = ObjectAnimator.OfFloat(newBall, "y", endY, endY + 25f);

                stretchAnim1.SetDuration(duration / 4);
                stretchAnim1.RepeatCount = 1;
                stretchAnim1.SetInterpolator(new DecelerateInterpolator());
                stretchAnim1.RepeatMode = ValueAnimatorRepeatMode.Reverse;
                var stretchAnim2 = ObjectAnimator.OfFloat(newBall, "height", newBall.Height, newBall.Height - 25);

                stretchAnim2.SetDuration(duration / 4);
                stretchAnim2.RepeatCount = 1;
                stretchAnim2.SetInterpolator(new DecelerateInterpolator());
                stretchAnim2.RepeatMode = ValueAnimatorRepeatMode.Reverse;
                var bounceBackAnim = ObjectAnimator.OfFloat(newBall, "y", endY, startY);

                bounceBackAnim.SetDuration(duration);
                bounceBackAnim.SetInterpolator(new DecelerateInterpolator());

                // Sequence the down/squash&stretch/up animations
                var bouncer = new AnimatorSet();

                bouncer.Play(bounceAnim).Before(squashAnim1);
                bouncer.Play(squashAnim1).With(squashAnim2);
                bouncer.Play(squashAnim1).With(stretchAnim1);
                bouncer.Play(squashAnim1).With(stretchAnim2);
                bouncer.Play(bounceBackAnim).After(stretchAnim2);

                // Fading animation - remove the ball when the animation is done
                var fadeAnim = ObjectAnimator.OfFloat(newBall, "alpha", 1f, 0f);

                fadeAnim.SetDuration(250);
                fadeAnim.AnimationEnd += (sender, e) =>
                {
                    var animator = (ObjectAnimator)e.Animation;
                    balls.Remove((ShapeHolder)animator.Target);
                };

                // Sequence the two animations to play one after the other
                var animatorSet = new AnimatorSet();

                animatorSet.Play(bouncer).Before(fadeAnim);

                // Start the animation
                animatorSet.Start();

                return(true);
            }
Пример #24
0
        public void Reset(SummaryReportView data)
        {
            // Cancel old animation
            if (currentAnimation != null)
            {
                currentAnimation.Cancel();
                currentAnimation = null;
            }

            // Not zooming
            isZooming = false;

            var totalRows = 0;
            var hasTime   = false;

            if (data == null)
            {
                backgroundView.XAxisLabels = null;
                ResetRows(totalRows);
            }
            else
            {
                var showEveryYLabel = 1;
                var showValueLabels = true;

                backgroundView.XAxisLabels = data.ChartTimeLabels.ToArray();

                totalRows = Math.Min(data.Activity.Count, data.ChartRowLabels.Count);
                ResetRows(totalRows);

                if (totalRows > 25)
                {
                    showEveryYLabel = 3;
                    showValueLabels = false;
                }

                for (var i = 0; i < totalRows; i++)
                {
                    var activity = data.Activity [i];
                    var yLabel   = data.ChartRowLabels [i];

                    if (activity.TotalTime > 0)
                    {
                        hasTime = true;
                    }

                    var barWidth  = (float)activity.TotalTime / (float)(data.MaxTotal * 3600);
                    var showYAxis = i % showEveryYLabel == 0;

                    // Bind the data to row
                    var row = rows [i];
                    row.RelativeWidth            = barWidth;
                    row.BarView.BillableTime     = activity.BillableTime;
                    row.BarView.TotalTime        = activity.TotalTime;
                    row.ValueTextView.Text       = activity.FormattedTotalTime;
                    row.ValueTextView.Visibility = showValueLabels ? ViewStates.Visible : ViewStates.Gone;
                    row.YAxisTextView.Text       = yLabel;
                    row.YAxisTextView.Visibility = showYAxis ? ViewStates.Visible : ViewStates.Gone;
                }
            }

            // Detect state
            var isLoading = totalRows == 0 || (data != null && data.IsLoading);
            var isEmpty   = !isLoading && !hasTime;

            if (isLoading)
            {
                // Loading state
                loadingOverlayView.Visibility = ViewStates.Visible;
                loadingOverlayView.Alpha      = 1f;

                emptyOverlayView.Visibility = ViewStates.Gone;
            }
            else if (isEmpty)
            {
                // Error state
                loadingOverlayView.Visibility = ViewStates.Visible;
                loadingOverlayView.Alpha      = 1f;

                emptyOverlayView.Visibility = ViewStates.Visible;
                emptyOverlayView.Alpha      = 0f;

                // Animate overlay in
                var scene = new AnimatorSet();

                var fadeIn  = ObjectAnimator.OfFloat(emptyOverlayView, "alpha", 0f, 1f).SetDuration(500);
                var fadeOut = ObjectAnimator.OfFloat(loadingOverlayView, "alpha", 1f, 0f).SetDuration(500);
                fadeOut.AnimationEnd += delegate {
                    loadingOverlayView.Visibility = ViewStates.Gone;
                };

                scene.Play(fadeOut);
                scene.Play(fadeIn).After(3 * fadeOut.Duration / 4);

                currentAnimation = scene;
                scene.Start();
            }
            else
            {
                // Normal state
                var scene = new AnimatorSet();

                // Fade loading message out
                var fadeOverlayOut = ObjectAnimator.OfFloat(loadingOverlayView, "alpha", 1f, 0f).SetDuration(500);
                fadeOverlayOut.AnimationEnd += delegate {
                    loadingOverlayView.Visibility = ViewStates.Gone;
                };

                scene.Play(fadeOverlayOut);

                foreach (var row in rows)
                {
                    var axisFadeIn  = ObjectAnimator.OfFloat(row.YAxisTextView, "alpha", 0f, 1f).SetDuration(500);
                    var barScaleUp  = ObjectAnimator.OfFloat(row.BarView, "scaleX", 0f, 1f).SetDuration(750);
                    var valueFadeIn = ObjectAnimator.OfFloat(row.ValueTextView, "alpha", 0f, 1f).SetDuration(400);

                    scene.Play(axisFadeIn);
                    scene.Play(barScaleUp).After(axisFadeIn.Duration / 2);
                    scene.Play(valueFadeIn).After(barScaleUp);
                }

                currentAnimation = scene;
                scene.Start();
            }

            RequestLayout();
        }
        private void ZoomImageFromThumb(View thumbView, int imageResId)
        {
            var expandedImageView = FindViewById <ImageView>(Resource.Id.expanded_image);

            expandedImageView.SetImageResource(imageResId);

            var startBounds  = new Rect();
            var finalBounds  = new Rect();
            var globalOffset = new Point();

            thumbView.GetGlobalVisibleRect(startBounds);
            FindViewById(Resource.Id.container).GetGlobalVisibleRect(finalBounds, globalOffset);
            startBounds.Offset(-globalOffset.X, -globalOffset.Y);
            finalBounds.Offset(-globalOffset.X, -globalOffset.Y);

            float startScale;

            if (((float)finalBounds.Width() / finalBounds.Height())
                .CompareTo((float)startBounds.Width() / startBounds.Height()) < 0)
            {
                startScale = (float)startBounds.Height() / finalBounds.Height();
                var startWidth = startScale * finalBounds.Width();
                var deltaWidth = (startWidth - startBounds.Width()) / 2;
                startBounds.Left  -= (int)deltaWidth;
                startBounds.Right += (int)deltaWidth;
            }
            else
            {
                startScale = (float)startBounds.Width() / finalBounds.Width();
                var startHeight = startScale * finalBounds.Height();
                var deltaHeight = (startHeight - startBounds.Height()) / 2;
                startBounds.Top    -= (int)deltaHeight;
                startBounds.Bottom += (int)deltaHeight;
            }

            thumbView.Alpha = 0f;
            expandedImageView.Visibility = ViewStates.Visible;

            expandedImageView.PivotX = 0f;
            expandedImageView.PivotY = 0f;

            var set = new AnimatorSet();

            set.Play(ObjectAnimator.OfFloat(expandedImageView, View.X, startBounds.Left, finalBounds.Left))
            .With(ObjectAnimator.OfFloat(expandedImageView, View.Y, startBounds.Top, finalBounds.Top))
            .With(ObjectAnimator.OfFloat(expandedImageView, View.ScaleXs, startScale, 1f))
            .With(ObjectAnimator.OfFloat(expandedImageView, View.ScaleYs, startScale, 1f));
            set.SetDuration(_shortAnimationDuration);
            set.SetInterpolator(new DecelerateInterpolator());
            set.AddListener(new AnimatorListener(this));
            set.Start();
            _currentAnimator = set;

            expandedImageView.Click += (s, e) =>
            {
                if (_currentAnimator != null)
                {
                    _currentAnimator.Cancel();
                }

                var animSet = new AnimatorSet();
                animSet.Play(ObjectAnimator.OfFloat(expandedImageView, View.X, startBounds.Left))
                .With(ObjectAnimator.OfFloat(expandedImageView, View.Y, startBounds.Top))
                .With(ObjectAnimator.OfFloat(expandedImageView, View.ScaleXs, startScale))
                .With(ObjectAnimator.OfFloat(expandedImageView, View.ScaleYs, startScale));
                animSet.SetDuration(_shortAnimationDuration);
                animSet.SetInterpolator(new DecelerateInterpolator());
                animSet.AnimationEnd += (sender, args) =>
                {
                    thumbView.Alpha = 1f;
                    expandedImageView.Visibility = ViewStates.Gone;
                    _currentAnimator             = null;
                };
                animSet.AnimationCancel += (sender, args) =>
                {
                    thumbView.Alpha = 1f;
                    expandedImageView.Visibility = ViewStates.Gone;
                    _currentAnimator             = null;
                };
            };
        }
Пример #26
0
        private void SetActiveSlice(int value, bool animate = false, bool updateStats = true)
        {
            if (slices.Count == 1 || value >= slices.Count)
            {
                value = -1;
            }

            if (value == activeSlice)
            {
                return;
            }

            activeSlice = value;
            Clickable   = activeSlice >= 0;

            if (updateStats)
            {
                UpdateStats();
            }

            if (animate)
            {
                // Finish currently running animations
                if (currentSelectAnimation != null)
                {
                    currentSelectAnimation.Cancel();
                }

                // Animate changes
                var scene = new AnimatorSet();
                for (var i = 0; i < slices.Count; i++)
                {
                    var slice = slices [i];

                    if (i == activeSlice)
                    {
                        // Slice activating animations
                        if (slice.Alpha < 1)
                        {
                            var fadeIn = ObjectAnimator.OfFloat(slice, "alpha", slice.Alpha, 1).SetDuration(500);
                            scene.Play(fadeIn);
                        }
                        if (slice.ScaleX != ActiveSliceScale)
                        {
                            var scaleXUp = ObjectAnimator.OfFloat(slice, "scaleX", slice.ScaleX, ActiveSliceScale).SetDuration(500);
                            scene.Play(scaleXUp);
                        }
                        if (slice.ScaleY != ActiveSliceScale)
                        {
                            var scaleYUp = ObjectAnimator.OfFloat(slice, "scaleY", slice.ScaleY, ActiveSliceScale).SetDuration(500);
                            scene.Play(scaleYUp);
                        }
                    }
                    else if (activeSlice >= 0)
                    {
                        // Slice deactivating animations
                        if (slice.Alpha > 0.5f)
                        {
                            var fadeOut = ObjectAnimator.OfFloat(slice, "alpha", slice.Alpha, 0.5f).SetDuration(300);
                            scene.Play(fadeOut);
                        }
                        if (slice.ScaleX != NonActiveSliceScale)
                        {
                            var scaleXDown = ObjectAnimator.OfFloat(slice, "scaleX", slice.ScaleX, NonActiveSliceScale).SetDuration(300);
                            scene.Play(scaleXDown);
                        }
                        if (slice.ScaleY != NonActiveSliceScale)
                        {
                            var scaleYDown = ObjectAnimator.OfFloat(slice, "scaleY", slice.ScaleY, NonActiveSliceScale).SetDuration(300);
                            scene.Play(scaleYDown);
                        }
                    }
                    else
                    {
                        // No slice selected animations
                        if (slice.Alpha < 1)
                        {
                            var fadeIn = ObjectAnimator.OfFloat(slice, "alpha", slice.Alpha, 1).SetDuration(300);
                            scene.Play(fadeIn);
                        }
                        if (slice.ScaleX != 1)
                        {
                            var scaleXDown = ObjectAnimator.OfFloat(slice, "scaleX", slice.ScaleX, 1f).SetDuration(300);
                            scene.Play(scaleXDown);
                        }
                        if (slice.ScaleY != 1)
                        {
                            var scaleYDown = ObjectAnimator.OfFloat(slice, "scaleY", slice.ScaleY, 1f).SetDuration(300);
                            scene.Play(scaleYDown);
                        }
                    }
                }

                currentSelectAnimation = scene;
                scene.Start();
            }

            // Notify listeners
            if (ActiveSliceChanged != null)
            {
                ActiveSliceChanged(this, EventArgs.Empty);
            }
        }
Пример #27
0
        private void Item_Click(object sender, EventArgs e)
        {
            if (sender is ActionMenuItemView item)
            {
                var  duration = 125;
                bool clicked  = false;

                /*
                 * var navpgItms = (Element as NavigationPage).ToolbarItems.ToArray();
                 * var s1 = (Element as NavigationPage).RootPage.ToolbarItems.ToArray();
                 * var r = (Element as NavigationPage).CurrentPage.ToolbarItems.ToArray();
                 * bool b = s1.FirstOrDefault() == r.FirstOrDefault();
                 * //*/


                var navPage = Element as NavigationPage;
                var btn     = navPage.CurrentPage.ToolbarItems.Last() as SearchToolbarButton;      // RootPage

                if (item == subMenuItems.FirstOrDefault())
                {
                    btn = navPage.CurrentPage.ToolbarItems.First() as SearchToolbarButton;
                    btn.ItemClicked();
                    clicked = true;
                    // return;
                }    //*/
                else // if (item == subMenuItems.LastOrDefault())
                {
                    if (btn.State == (SearchPanelState.Hidden | SearchPanelState.InSearch) || navPage.CurrentPage != navPage.RootPage)
                    {
                        btn.ItemClicked();                                                              // occurs click event on X.Forms project
                        clicked = true;
                    }
                }

                objectAnimator = ObjectAnimator.OfFloat(item, "Alpha", 0.3f);
                ObjectAnimator scaleDownX = ObjectAnimator.OfFloat(item, "ScaleX", 0.7f);
                ObjectAnimator scaleDownY = ObjectAnimator.OfFloat(item, "ScaleY", 0.7f);
                scaleDownX.SetDuration(duration);
                scaleDownY.SetDuration(duration);
                AnimatorSet scaleDown = new AnimatorSet();
                scaleDown.Play(scaleDownX).With(scaleDownY).With(objectAnimator);
                scaleDown.Start();

                scaleDown.AnimationEnd += (object s, EventArgs ev) =>
                {
                    // btn.Icon = new FileImageSource { File = SearchToolbarButton.Icons[btn.State] };


                    if (clicked == false)
                    {
                        btn.ItemClicked();
                    }

                    if (navPage.CurrentPage.GetType() != typeof(MessagesPage) || item == subMenuItems.LastOrDefault())
                    {
                        var image = SearchToolbarButton.Icons[btn.State].Split('.')[0];
                        var d     = item.Context.GetDrawable(image);
                        item.SetIcon(d);
                    }

                    var            a           = ObjectAnimator.OfFloat(item, "Alpha", 1); // item.Alpha == 0 ? 1 : 0
                    ObjectAnimator scaleDownX1 = ObjectAnimator.OfFloat(item, "ScaleX", 1);
                    ObjectAnimator scaleDownY1 = ObjectAnimator.OfFloat(item, "ScaleY", 1);
                    scaleDownX1.SetDuration(duration * 2);
                    scaleDownY1.SetDuration(duration * 2);
                    AnimatorSet scaleDown1 = new AnimatorSet();
                    scaleDown1.Play(scaleDownX1).With(scaleDownY1).With(a);
                    scaleDown1.Start();
                    scaleDown1.AnimationEnd += delegate { };
                };
            }
        }
Пример #28
0
        private void ZoomImageFromThumb(object sender, EventArgs eventArgs)
        {
            View thumbView = (View)sender;

            // If there's an animation in progress, cancel it immediately and proceed with this one.
            if (_currentAnimator != null)
            {
                _currentAnimator.Cancel();
            }

            // Load the high-resolution "zoomed-in" image.
            // ImageView expandedImageView = (ImageView)FindViewById(Resource.Id.expanded_image);
            // expandedImageView.SetImageResource(imageResId);

            expandedImageView = this.FindViewById <ImageView>(Resource.Id.expanded_image);

            Glide.With(this).Load(Uri.Parse((thumbView.Tag).ToString()))
            .Into(expandedImageView);

            // Calculate the starting and ending bounds for the zoomed-in image.
            Rect  startBounds  = new Rect();
            Rect  finalBounds  = new Rect();
            Point globalOffset = new Point();

            // The start bounds are the global visible rectangle of the thumbnail, and the
            // final bounds are the global visible rectangle of the container view. Also
            // set the container view's offset as the origin for the bounds, since that's
            // the origin for the positioning animation properties (X, Y).
            thumbView.GetGlobalVisibleRect(startBounds);
            FindViewById(Resource.Id.container).GetGlobalVisibleRect(finalBounds, globalOffset);
            startBounds.Offset(-globalOffset.X, -globalOffset.Y);
            finalBounds.Offset(-globalOffset.X, -globalOffset.Y);

            // Adjust the start bounds to be the same aspect ratio as the final bounds using the
            // "center crop" technique. This prevents undesirable stretching during the animation.
            // Also calculate the start scaling factor (the end scaling factor is always 1.0).
            float startScale;

            if ((float)finalBounds.Width() / finalBounds.Height()
                > (float)startBounds.Width() / startBounds.Height())
            {
                // Extend start bounds horizontally
                startScale = (float)startBounds.Height() / finalBounds.Height();
                float startWidth = startScale * finalBounds.Width();
                float deltaWidth = (startWidth - startBounds.Width()) / 2;
                startBounds.Left  -= (int)deltaWidth;
                startBounds.Right += (int)deltaWidth;
            }
            else
            {
                // Extend start bounds vertically
                startScale = (float)startBounds.Width() / finalBounds.Width();
                float startHeight = startScale * finalBounds.Height();
                float deltaHeight = (startHeight - startBounds.Height()) / 2;
                startBounds.Top    -= (int)deltaHeight;
                startBounds.Bottom += (int)deltaHeight;
            }

            // Hide the thumbnail and show the zoomed-in view. When the animation begins,
            // it will position the zoomed-in view in the place of the thumbnail.
            thumbView.Alpha = 0f;
            expandedImageView.Visibility = ViewStates.Visible;

            // Set the pivot point for SCALE_X and SCALE_Y transformations to the top-left corner of
            // the zoomed-in view (the default is the center of the view).
            expandedImageView.PivotX = 0f;
            expandedImageView.PivotY = 0f;

            AnimatorSet expandSet = new AnimatorSet();

            expandSet.Play(ObjectAnimator.OfFloat(expandedImageView, View.X, startBounds.Left, finalBounds.Left))
            .With(ObjectAnimator.OfFloat(expandedImageView, View.Y, startBounds.Top, finalBounds.Top))
            .With(ObjectAnimator.OfFloat(expandedImageView, View.ScaleXs, startScale, 1f))
            .With(ObjectAnimator.OfFloat(expandedImageView, View.ScaleYs, startScale, 1f));
            expandSet.SetDuration(_shortAnimationDuration);
            expandSet.SetInterpolator(new DecelerateInterpolator());
            // expandSet.AnimationEnd += NullOutCurrentAnimator;
            // expandSet.AnimationCancel += NullOutCurrentAnimator;

            expandSet.AnimationEnd += (sender1, args1) =>
            {
                _currentAnimator = null;
            };
            expandSet.AnimationCancel += (sender1, args1) =>
            {
                _currentAnimator = null;
            };

            expandSet.Start();
            _currentAnimator = expandSet;

            // Upon clicking the zoomed-in image, it should zoom back down to the original bounds
            // and show the thumbnail instead of the expanded image.
            float startScaleFinal = startScale;

            // Create a custom clickListener so that click listeners won't be set multiple times
            var local = new LocalOnclickListener();

            expandedImageView.SetOnClickListener(local);

            local.HandleOnClick = () =>
            {
                if (_currentAnimator != null)
                {
                    _currentAnimator.Cancel();
                }

                AnimatorSet shrinkSet = new AnimatorSet();
                shrinkSet.Play(ObjectAnimator.OfFloat(expandedImageView, View.X, startBounds.Left))
                .With(ObjectAnimator.OfFloat(expandedImageView, View.Y, startBounds.Top))
                .With(ObjectAnimator.OfFloat(expandedImageView, View.ScaleXs, startScaleFinal))
                .With(ObjectAnimator.OfFloat(expandedImageView, View.ScaleYs, startScaleFinal));
                shrinkSet.SetDuration(_shortAnimationDuration);
                shrinkSet.SetInterpolator(new DecelerateInterpolator());

                shrinkSet.AnimationEnd += (sender1, args1) =>
                {
                    thumbView.Alpha = 1.0f;
                    expandedImageView.Visibility = ViewStates.Gone;
                    _currentAnimator             = null;
                };
                shrinkSet.AnimationCancel += (sender1, args1) =>
                {
                    thumbView.Alpha = 1.0f;
                    expandedImageView.Visibility = ViewStates.Gone;
                    _currentAnimator             = null;
                };
                shrinkSet.Start();
                _currentAnimator = shrinkSet;
            };
        }
Пример #29
0
        public void Reset(SummaryReportView data)
        {
            this.data = data;

            // Cancel old animation
            if (currentRevealAnimation != null)
            {
                currentRevealAnimation.Cancel();
                currentRevealAnimation = null;
            }
            if (currentSelectAnimation != null)
            {
                currentSelectAnimation.Cancel();
                currentSelectAnimation = null;
            }

            var totalSlices = data == null || data.CollapsedProjects == null ? 0 : data.CollapsedProjects.Count;

            SetActiveSlice(-1, updateStats: false);
            backgroundView.Visibility = ViewStates.Visible;
            backgroundView.Radius     = defaultRadius;

            ResetSlices(totalSlices);
            if (totalSlices > 0)
            {
                var totalTime  = data.CollapsedProjects.Sum(x => x.TotalTime);
                var startAngle = 0f;

                for (var i = 0; i < totalSlices; i++)
                {
                    var slice        = slices [i];
                    var project      = data.CollapsedProjects [i];
                    var percentOfAll = (float)project.TotalTime / totalTime;

                    slice.Visibility = ViewStates.Gone;
                    slice.Radius     = defaultRadius;
                    if (project.Color == ProjectModel.GroupedProjectColorIndex)
                    {
                        slice.Color = Color.ParseColor(ProjectModel.GroupedProjectColor);
                    }
                    else
                    {
                        slice.Color = Color.ParseColor(ProjectModel.HexColors [project.Color % ProjectModel.HexColors.Length]);
                    }
                    slice.StartAngle = startAngle;
                    startAngle      += percentOfAll * 360;
                }
            }

            // Detect state
            var isLoading = data == null || data.IsLoading;
            var isEmpty   = !isLoading && totalSlices == 0;

            if (isLoading)
            {
                // Loading state
                loadingOverlayView.Visibility = ViewStates.Visible;
                loadingOverlayView.Alpha      = 1f;

                emptyOverlayView.Visibility = ViewStates.Gone;
                statsOverlayView.Visibility = ViewStates.Gone;
            }
            else if (isEmpty)
            {
                // Error state
                loadingOverlayView.Visibility = ViewStates.Visible;
                loadingOverlayView.Alpha      = 1f;

                emptyOverlayView.Visibility = ViewStates.Visible;
                emptyOverlayView.Alpha      = 0f;

                statsOverlayView.Visibility = ViewStates.Gone;

                // Animate overlay in
                var scene = new AnimatorSet();

                var fadeIn  = ObjectAnimator.OfFloat(emptyOverlayView, "alpha", 0f, 1f).SetDuration(500);
                var fadeOut = ObjectAnimator.OfFloat(loadingOverlayView, "alpha", 1f, 0f).SetDuration(500);
                fadeOut.AnimationEnd += delegate {
                    loadingOverlayView.Visibility = ViewStates.Gone;
                };

                scene.Play(fadeOut);
                scene.Play(fadeIn).After(3 * fadeOut.Duration / 4);

                currentRevealAnimation = scene;
                scene.Start();
            }
            else
            {
                // Normal state
                var scene = new AnimatorSet();

                // Fade loading message out
                statsOverlayView.Visibility = ViewStates.Visible;
                statsOverlayView.Alpha      = 0f;

                var fadeOverlayOut = ObjectAnimator.OfFloat(loadingOverlayView, "alpha", 1f, 0f).SetDuration(500);
                fadeOverlayOut.AnimationEnd += delegate {
                    loadingOverlayView.Visibility = ViewStates.Gone;
                };
                scene.Play(fadeOverlayOut);

                var fadeOverlayIn = ObjectAnimator.OfFloat(statsOverlayView, "alpha", 0f, 1f).SetDuration(500);
                scene.Play(fadeOverlayIn).After(3 * fadeOverlayOut.Duration / 4);

                var donutReveal = ValueAnimator.OfFloat(0, 360);
                donutReveal.SetDuration(750);
                donutReveal.Update += (sender, e) => ShowSlices((float)e.Animation.AnimatedValue);
                scene.Play(donutReveal).After(fadeOverlayOut.Duration / 2);

                currentRevealAnimation = scene;
                scene.Start();
            }

            UpdateStats();
            RequestLayout();
        }
Пример #30
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = inflater.Inflate(Resource.Layout.scripteditor, container, false);

            // set the isRecording flag to false (not recording)
            isRecording = false;

            // get the resources from the layout
            textBox = view.FindViewById <EditText>(Resource.Id.textYourText);

            //disable textBox editing
            textBox.Enabled = false;
            textBox.SetMaxLines(10);
            textBox.SetHorizontallyScrolling(false);

            saveScript    = view.FindViewById <Button>(Resource.Id.save_script);
            editIPaddress = view.FindViewById <EditText>(Resource.Id.edIPaddress);
            recButton     = view.FindViewById <Button>(Resource.Id.btnRecord);
            connectButton = view.FindViewById <Button>(Resource.Id.connect);
            editButton    = view.FindViewById <Button>(Resource.Id.btnEdit);
            glowCircle    = view.FindViewById <LinearLayout>(Resource.Id.glow_circle);
            recButtonGlow = new AnimatorSet();

            ObjectAnimator fadeout = ObjectAnimator.OfFloat(glowCircle, "alpha", 0.7f, 0.1f);

            fadeout.SetDuration(1000);

            ObjectAnimator fadein = ObjectAnimator.OfFloat(glowCircle, "alpha", 0.1f, 0.7f);

            fadein.SetDuration(1000);

            recButtonGlow.Play(fadein).After(fadeout);
            recButtonGlow.AnimationEnd += delegate { recButtonGlow.Start(); };
            recButtonGlow.Start();


            //connect to computer
            connectButton.Click += delegate
            {
                MainActivity.Ip = editIPaddress.Text;
                GetScriptConnection.StartConnectionAsync(editIPaddress.Text);
                while (true)
                {
                    if (ConnectMessage != null)
                    {
                        if (ConnectMessage == "Connected")
                        {
                            Thread.Sleep(3000);
                            connectButton.Text = null;
                            connectButton.SetBackgroundResource(Resource.Drawable.check_mark_connect);
                            break;
                        }
                        Thread.Sleep(3000);
                        connectButton.Text = null;
                        connectButton.SetBackgroundResource(Resource.Drawable.not_connect);
                        break;
                    }
                }
            };

            textBox.EditorAction += delegate(object sender, TextView.EditorActionEventArgs args)
            {
                if (args.ActionId == ImeAction.Done)
                {
                    textBox.Enabled = false;
                }
            };

            //enable editing
            editButton.Click += delegate
            {
                LayoutInflater      layoutInflater = LayoutInflater.From(Context);
                View                editView       = layoutInflater.Inflate(Resource.Layout.edit_dialog, null);
                AlertDialog.Builder builder        = new AlertDialog.Builder(Context, Resource.Style.AlertDialogTheme);
                EditText            input          = editView.FindViewById <EditText>(Resource.Id.edit_field);
                input.SetBackgroundColor(Color.Transparent);
                input.Text = textBox.Text;
                builder.SetView(editView);

                builder.SetCancelable(false)
                .SetPositiveButton("EDIT", delegate { textBox.Text = input.Text; });
                var dialog = builder.Create();
                dialog.Show();
                dialog.GetButton((int)DialogButtonType.Positive).SetTextColor(new Color(ContextCompat.GetColor(Context, Resource.Color.mainColor)));

                dialog.Window.SetBackgroundDrawableResource(Resource.Drawable.ip_background);
                InputMethodManager imm =
                    Activity.GetSystemService(Context.InputMethodService) as InputMethodManager;
                imm?.ShowSoftInput(textBox, ShowFlags.Forced);
            };


            // check to see if we can actually record - if we can, assign the event to the button
            string rec = Android.Content.PM.PackageManager.FeatureMicrophone;

            if (rec != "android.hardware.microphone")
            {
                // no microphone, no recording. Disable the button and output an alert
                var alert = new AlertDialog.Builder(recButton.Context);
                alert.SetTitle("You don't seem to have a microphone to record with");
                alert.SetPositiveButton("OK", (sender, e) =>
                {
                    textBox.Text      = "No microphone present";
                    recButton.Enabled = false;
                });

                alert.Show();
            }
            else
            {
                recButton.Click += delegate
                {
                    // change the text on the button
                    isRecording = !isRecording;
                    if (isRecording)
                    {
                        // create the intent and start the activity
                        var voiceIntent = new Intent(RecognizerIntent.ActionRecognizeSpeech);
                        voiceIntent.PutExtra(RecognizerIntent.ExtraLanguageModel,
                                             RecognizerIntent.LanguageModelFreeForm);

                        // put a message on the modal dialog
                        voiceIntent.PutExtra(RecognizerIntent.ExtraPrompt,
                                             Application.Context.GetString(Resource.String.messageSpeakNow));

                        // if there is more then 1.5s of silence, consider the speech over
                        voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputCompleteSilenceLengthMillis, 1500);
                        voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputPossiblyCompleteSilenceLengthMillis,
                                             1500);
                        voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputMinimumLengthMillis, 15000);
                        voiceIntent.PutExtra(RecognizerIntent.ExtraMaxResults, 1);

                        // you can specify other languages recognised here, for example
                        // voiceIntent.PutExtra(RecognizerIntent.ExtraLanguage, Java.Util.Locale.German);
                        // if you wish it to recognise the default Locale language and German
                        // if you do use another locale, regional dialects may not be recognised very well

                        voiceIntent.PutExtra(RecognizerIntent.ExtraLanguage, Java.Util.Locale.SimplifiedChinese);
                        StartActivityForResult(voiceIntent, VOICE);
                    }
                    isRecording = !isRecording;
                }
            };
            return(view);
        }