public CancelPage(RecordingPageModel vm)
 {
     // Hide navigation bar
     NavigationPage.SetHasNavigationBar(this, false);
     // Subscribe notification of locale changes to update text based on locale
     MessagingCenter.Subscribe <App>(this, MessageKeys.UpdateByLanguageChange, (obj) =>
     {
         // Update text that has been translated into the current language.
         CancelLabel.Text = AppResources.CancelRecording;
     });
     InitializeComponent();
     Init(vm);
 }
Esempio n. 2
0
        public RecordingPage(RecordingPageModel viewModel)
        {
            BindingContext = ViewModel = viewModel;
            InitializeComponent();
            UpdateColor();

            RegisterForEvents();

            RecordingEffectAnimation = false;
            TimeFlickeringAnimation  = false;

            SetBinding(RecordingEffectAnimationProperty, new Binding("RecordingEffectOn", mode: BindingMode.Default));
            SetBinding(TimeFlickeringAnimationProperty, new Binding("TimeFlickeringOn", mode: BindingMode.Default));

            Init();
        }
Esempio n. 3
0
        // Draw animation effects depending on volume level
        private async Task CheckVolumeAndResizeAnimationAsync()
        {
            RecordingPageModel recordingViewModel = (RecordingPageModel)BindingContext;

            if (recordingViewModel.AudioRecordingService.State == AudioRecordState.Recording)
            {
                double       fScaleValue = 0, fShodowScaleValue = 0;
                double       volume           = recordingViewModel.AudioRecordingService.GetRecordingLevel(); //-300 ~ 0
                int          uwLevel          = 0;
                int          uwShadowLevel    = 0;
                int          effectLevel      = 0;
                double       db               = volume;
                const int    VOLUME_LEVEL_MIN = -55;
                const int    VOLUME_LEVEL_MAX = -10;
                const double LINEAR_VI_SCALE  = 1.0 / 20.0;

                if (db < VOLUME_LEVEL_MIN)
                {
                    effectLevel = 0;
                }
                else if (db > VOLUME_LEVEL_MAX)
                {
                    effectLevel = VOLUME_LEVEL_MAX - VOLUME_LEVEL_MIN;
                }
                else
                {
                    effectLevel = (int)(db - VOLUME_LEVEL_MIN);
                }

                uwLevel = effectLevel;

                if (uwLevel > 1)
                {
                    uwShadowLevel = uwLevel / 4 + (new Random().Next() % (uwLevel / 2));
                }

                if (uwLevel > prevAudioLevel)
                {
                    fScaleValue       = (30 + 70 * (uwLevel) / (VOLUME_LEVEL_MAX - VOLUME_LEVEL_MIN)) / 100.0;
                    fShodowScaleValue = (30 + 70 * (uwShadowLevel) / (VOLUME_LEVEL_MAX - VOLUME_LEVEL_MIN)) / 100.0;

                    if (fScaleValue < prevScale)
                    {
                        fScaleValue = prevScale - LINEAR_VI_SCALE;
                    }

                    if (fShodowScaleValue < prevShadowScale)
                    {
                        fShodowScaleValue = prevShadowScale - LINEAR_VI_SCALE;
                    }
                }
                else
                {
                    fScaleValue       = prevScale - LINEAR_VI_SCALE;
                    fShodowScaleValue = prevShadowScale - LINEAR_VI_SCALE;
                }

                if (fScaleValue < 0.3)
                {
                    fScaleValue = 0.3;
                }
                else if (fScaleValue > 1.0)
                {
                    fScaleValue = 1.0;
                }

                if (fShodowScaleValue < 0.3)
                {
                    fShodowScaleValue = 0.3;
                }
                else if (fShodowScaleValue > 1.0)
                {
                    fShodowScaleValue = 1.0;
                }

                int actualSize       = (int)(fScaleValue * 360);
                int acutalShadowSize = (int)(fShodowScaleValue * 360);

                await DrawVolumeEffectAnimationAsync(actualSize, acutalShadowSize);

                prevAudioLevel  = uwLevel;
                prevScale       = fScaleValue;
                prevShadowScale = fShodowScaleValue;
            }
        }
 void Init(RecordingPageModel vm)
 {
     BindingContext = ViewModel = vm;
 }
        // Draw animation effects depending on volume level
        private bool CheckVolumeAndResizeAnimationAsync()
        {
            RecordingPageModel recordingViewModel = (RecordingPageModel)BindingContext;

            // @20180217-vincent: async chain can be stopped by using Task.Factory.StartNew(...)
            //                    Device.InovkeOnMainThread was removed because it is guaranteed main thread
            Task.Factory.StartNew(async() =>
            {
                if (recordingViewModel.AudioRecordingService.State == AudioRecordState.Recording)
                {
                    double fScaleValue           = 0, fShodowScaleValue = 0;
                    double volume                = recordingViewModel.AudioRecordingService.GetRecordingLevel(); //-300 ~ 0
                    int uwLevel                  = 0;
                    int uwShadowLevel            = 0;
                    int effectLevel              = 0;
                    double db                    = volume;
                    const int VOLUME_LEVEL_MIN   = -55;
                    const int VOLUME_LEVEL_MAX   = -10;
                    const double LINEAR_VI_SCALE = 1.0 / 20.0;

                    if (db < VOLUME_LEVEL_MIN)
                    {
                        effectLevel = 0;
                    }
                    else if (db > VOLUME_LEVEL_MAX)
                    {
                        effectLevel = VOLUME_LEVEL_MAX - VOLUME_LEVEL_MIN;
                    }
                    else
                    {
                        effectLevel = (int)(db - VOLUME_LEVEL_MIN);
                    }

                    uwLevel = effectLevel;

                    if (uwLevel > 1)
                    {
                        uwShadowLevel = uwLevel / 4 + (new Random().Next() % (uwLevel / 2));
                    }

                    if (uwLevel > prevAudioLevel)
                    {
                        fScaleValue       = (30 + 70 * (uwLevel) / (VOLUME_LEVEL_MAX - VOLUME_LEVEL_MIN)) / 100.0;
                        fShodowScaleValue = (30 + 70 * (uwShadowLevel) / (VOLUME_LEVEL_MAX - VOLUME_LEVEL_MIN)) / 100.0;

                        if (fScaleValue < prevScale)
                        {
                            fScaleValue = prevScale - LINEAR_VI_SCALE;
                        }

                        if (fShodowScaleValue < prevShadowScale)
                        {
                            fShodowScaleValue = prevShadowScale - LINEAR_VI_SCALE;
                        }
                    }
                    else
                    {
                        fScaleValue       = prevScale - LINEAR_VI_SCALE;
                        fShodowScaleValue = prevShadowScale - LINEAR_VI_SCALE;
                    }

                    if (fScaleValue < 0.3)
                    {
                        fScaleValue = 0.3;
                    }
                    else if (fScaleValue > 1.0)
                    {
                        fScaleValue = 1.0;
                    }

                    if (fShodowScaleValue < 0.3)
                    {
                        fShodowScaleValue = 0.3;
                    }
                    else if (fShodowScaleValue > 1.0)
                    {
                        fShodowScaleValue = 1.0;
                    }

                    int actualSize       = (int)(fScaleValue * 360);
                    int acutalShadowSize = (int)(fShodowScaleValue * 360);

                    await DrawVolumeEffectAnimationAsync(actualSize, acutalShadowSize);

                    prevAudioLevel  = uwLevel;
                    prevScale       = fScaleValue;
                    prevShadowScale = fShodowScaleValue;
                }
            });
            return(((RecordingPageModel)BindingContext).RecordingEffectOn);
        }