public void OnActionDown(RecordButton recordBtn, MotionEvent motionEvent)
        {
            try
            {
                RecordListener?.OnStartRecord();

                AnimationHelper.SetStartRecorded(true);
                AnimationHelper.ResetBasketAnimation();
                AnimationHelper.ResetSmallMic();

                recordBtn.StartScale();
                SlideToCancelLayout.StartShimmerAnimation();

                InitialX = recordBtn.GetX();

                BasketInitialY = BasketImg.GetY() + 90;

                PlaySound(RecordStart);

                ShowViews();

                AnimationHelper.AnimateSmallMicAlpha();
                CounterTime.Base = SystemClock.ElapsedRealtime();
                StartTime        = Methods.Time.CurrentTimeMillis();
                CounterTime.Start();
                IsSwiped = false;
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
            }
        }
        public void OnActionUp(RecordButton recordBtn)
        {
            try
            {
                ElapsedTime = Methods.Time.CurrentTimeMillis() - StartTime;

                if (!IsLessThanSecondAllowed && isLessThanOneSecond(ElapsedTime) && !IsSwiped)
                {
                    RecordListener?.OnLessThanSecond();

                    AnimationHelper.SetStartRecorded(false);
                    PlaySound(RecordError);
                }
                else
                {
                    if (!IsSwiped)
                    {
                        RecordListener?.OnFinishRecord(ElapsedTime);
                    }

                    AnimationHelper.SetStartRecorded(false);

                    if (!IsSwiped)
                    {
                        PlaySound(RecordFinished);
                    }
                }

                //if user has swiped then do not hide SmallMic since it will be hidden after swipe Animation
                HideViews(!IsSwiped);

                if (!IsSwiped)
                {
                    AnimationHelper.ClearAlphaAnimation(true);
                }

                AnimationHelper?.MoveRecordButtonAndSlideToCancelBack(recordBtn, SlideToCancelLayout, InitialX, DifX);
                CounterTime.Stop();
                SlideToCancelLayout.StopShimmerAnimation();
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
            }
        }
Esempio n. 3
0
        public void MoveRecordButtonAndSlideToCancelBack(RecordButton recordBtn, FrameLayout slideToCancelLayout, float initialX, float difX)
        {
            try
            {
                ValueAnimator positionAnimator = ValueAnimator.OfFloat(recordBtn.GetX(), initialX);
                if (positionAnimator != null)
                {
                    positionAnimator.SetInterpolator(new AccelerateDecelerateInterpolator());
                    positionAnimator.Update += (sender, args) =>
                    {
                        try
                        {
                            float x = (float)args.Animation?.AnimatedValue;
                            recordBtn.SetX(x);
                        }
                        catch (Exception e)
                        {
                            Methods.DisplayReportResultTrack(e);
                        }
                    };

                    recordBtn.StopScale();
                    positionAnimator.SetDuration(0);
                    positionAnimator.Start();
                }

                // if the move event was not called ,then the difX will still 0 and there is no need to move it back
                if (difX != 0)
                {
                    float x = initialX - difX;
                    slideToCancelLayout.Animate()
                    ?.X(x)
                    ?.SetDuration(0)
                    ?.Start();
                }
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
            }
        }
        public void OnActionMove(RecordButton recordBtn, MotionEvent motionEvent)
        {
            try
            {
                long time = Methods.Time.CurrentTimeMillis() - StartTime;

                if (!IsSwiped)
                {
                    //Swipe To Cancel
                    if (SlideToCancelLayout.GetX() != 0 && SlideToCancelLayout.GetX() <= CounterTime.Right + CancelBounds)
                    {
                        //if the time was less than one second then do not start basket animation
                        if (isLessThanOneSecond(time))
                        {
                            HideViews(true);
                            AnimationHelper.ClearAlphaAnimation(false);
                            AnimationHelper.OnAnimationEnd();
                        }
                        else
                        {
                            HideViews(false);
                            AnimationHelper.AnimateBasket(BasketInitialY);
                        }

                        AnimationHelper.MoveRecordButtonAndSlideToCancelBack(recordBtn, SlideToCancelLayout, InitialX, DifX);

                        CounterTime.Stop();
                        SlideToCancelLayout.StopShimmerAnimation();
                        IsSwiped = true;

                        AnimationHelper.SetStartRecorded(false);

                        RecordListener?.OnCancelRecord();
                    }
                    else
                    {
                        //if statement is to Prevent Swiping out of bounds
                        if (motionEvent.RawX < InitialX)
                        {
                            recordBtn.Animate()
                            ?.X(motionEvent.RawX)
                            ?.SetDuration(0)
                            ?.Start();

                            if (DifX == 0)
                            {
                                DifX = InitialX - SlideToCancelLayout.GetX();
                            }

                            SlideToCancelLayout.Animate()
                            ?.X(motionEvent.RawX - DifX)
                            ?.SetDuration(0)
                            ?.Start();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
            }
        }