Наследование: MonoBehaviour
        void ReleaseDesignerOutlets()
        {
            if (InterviewTimer != null)
            {
                InterviewTimer.Dispose();
                InterviewTimer = null;
            }

            if (RecordButton != null)
            {
                RecordButton.Dispose();
                RecordButton = null;
            }

            if (TopicsCollectionView != null)
            {
                TopicsCollectionView.Dispose();
                TopicsCollectionView = null;
            }

            if (TopicsInstructions != null)
            {
                TopicsInstructions.Dispose();
                TopicsInstructions = null;
            }

            if (ThemeTitleLabel != null)
            {
                ThemeTitleLabel.Dispose();
                ThemeTitleLabel = null;
            }
        }
        async Task RecordAudio()
        {
            try
            {
                if (!recorder.IsRecording)
                {
                    recorder.StopRecordingOnSilence = TimeoutSwitch.On;

                    RecordButton.Enabled = false;

                    await recorder.StartRecording();

                    RecordButton.SetTitle("Stop", UIControlState.Normal);
                    RecordButton.Enabled = true;
                }
                else
                {
                    RecordButton.Enabled = false;

                    await recorder.StopRecording();

                    RecordButton.SetTitle("Record", UIControlState.Normal);
                    RecordButton.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                //blow up the app!
                throw ex;
            }
        }
Пример #3
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            NavigationController.NavigationBar.Translucent = false;

            _closeButton = new UIBarButtonItem(Translation.general_close, UIBarButtonItemStyle.Plain, null);
            NavigationItem.LeftBarButtonItem = _closeButton;

            RecordButton.SetImage(UIImage.FromBundle("ic_record"), UIControlState.Normal);
            RecordButton.TintColor = UIColor.Red;

            BGView.Layer.BorderColor = UIColor.White.CGColor;
            BGView.Layer.BorderWidth = _borderWidth;

            DurationLabel.Alpha = 0;

            var set = this.CreateBindingSet <RecordDisplayView, RecordDisplayViewModel>();

            set.Bind(this).For(v => v.IsRecording).To(vm => vm.Recording);
            set.Bind(_closeButton).To(vm => vm.CloseCommand);
            set.Bind(RecordButton).To(vm => vm.RecordCommand);
            set.Bind(HelpLabel).To(vm => vm.HelpMessage);
            set.Bind(DurationLabel).To(vm => vm.Time);
            set.Apply();
        }
Пример #4
0
 public void DidStartRecording(AVCaptureFileOutput captureOutput, NSUrl outputFileUrl, NSObject[] connections)
 {
     // Enable the Record button to let the user stop the recording.
     DispatchQueue.MainQueue.DispatchAsync(() => {
         RecordButton.Enabled = true;
         RecordButton.SetTitle("Stop", UIControlState.Normal);
     });
 }
 // Use this for initialization
 void Start()
 {
     if (btnRecord)
     {
         RecordButton recordButton = btnRecord.GetComponent <RecordButton>();
         recordButton.onButtonDown = microphone.RecordStart;
         recordButton.onButtonUp   = microphone.RecordEnd;
     }
 }
        private void Recorder_AudioInputReceived(object sender, string audioFile)
        {
            InvokeOnMainThread(() =>
            {
                RecordButton.SetTitle("Record", UIControlState.Normal);

                PlayButton.Enabled = !string.IsNullOrEmpty(audioFile);
            });
        }
Пример #7
0
 void ReleaseDesignerOutlets()
 {
     if (RecordButton != null)
     {
         RecordButton.Dispose();
         RecordButton = null;
     }
     if (StopButton != null)
     {
         StopButton.Dispose();
         StopButton = null;
     }
 }
        void ReleaseDesignerOutlets()
        {
            if (PlayButton != null)
            {
                PlayButton.Dispose();
                PlayButton = null;
            }

            if (RecordButton != null)
            {
                RecordButton.Dispose();
                RecordButton = null;
            }

            if (TimeoutSwitch != null)
            {
                TimeoutSwitch.Dispose();
                TimeoutSwitch = null;
            }
        }
Пример #9
0
        void ReleaseDesignerOutlets()
        {
            if (FlipButton != null)
            {
                FlipButton.Dispose();
                FlipButton = null;
            }

            if (RecordDurationLabel != null)
            {
                RecordDurationLabel.Dispose();
                RecordDurationLabel = null;
            }

            if (RecordVideoButton != null)
            {
                RecordVideoButton.Dispose();
                RecordVideoButton = null;
            }
        }
Пример #10
0
        void OnRecordingChanged(NSObservedChange change)
        {
            bool isRecording = ((NSNumber)change.NewValue).BoolValue;

            DispatchQueue.MainQueue.DispatchAsync(() => {
                if (isRecording)
                {
                    CameraButton.Enabled = false;
                    RecordButton.Enabled = true;
                    RecordButton.SetTitle("Stop", UIControlState.Normal);
                }
                else
                {
                    // Only enable the ability to change camera if the device has more than one camera.
                    CameraButton.Enabled = NumberOfVideoCameras() > 1;
                    RecordButton.Enabled = true;
                    RecordButton.SetTitle("Record", UIControlState.Normal);
                }
            });
        }
Пример #11
0
        private void UpdateRecordUI()
        {
            if (DurationLabel != null)
            {
                if (IsRecording)
                {
                    DurationLabel.FadeIn();
                }
                else
                {
                    DurationLabel.FadeOut(0.5);
                }
            }

            if (BGView != null)
            {
                CABasicAnimation borderCol = CABasicAnimation.FromKeyPath("borderColor");
                borderCol.SetFrom((IsRecording) ? UIColor.White.CGColor : UIColor.Red.CGColor);
                borderCol.SetTo((IsRecording) ? UIColor.Red.CGColor : UIColor.White.CGColor);
                borderCol.FillMode       = CAFillMode.Forwards;
                borderCol.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
                borderCol.Duration       = 1;
                BGView.Layer.BorderColor = (IsRecording) ? UIColor.Red.CGColor : UIColor.White.CGColor;

                BGView.Layer.AddAnimation(borderCol, "color");
            }

            if (RecordButton != null)
            {
                RecordButton.FadeOut(0.25, 0, () =>
                {
                    if (RecordButton != null)
                    {
                        string fileName = (IsRecording) ? "ic_stop" : "ic_record";
                        RecordButton.SetImage(UIImage.FromBundle(fileName), UIControlState.Normal);
                        RecordButton.TintColor = (IsRecording) ? UIColor.Black : UIColor.Red;
                        RecordButton.FadeIn(0.25);
                    }
                });
            }
        }
        async Task RecordAudio()
        {
            try
            {
                if (!recorder.IsRecording)
                {
                    recorder.StopRecordingOnSilence = TimeoutSwitch.On;

                    RecordButton.Enabled = false;
                    PlayButton.Enabled   = false;

                    //the returned Task here will complete once recording is finished
                    var recordTask = await recorder.StartRecording();

                    RecordButton.SetTitle("Stop", UIControlState.Normal);
                    RecordButton.Enabled = true;

                    var audioFile = await recordTask;

                    //audioFile will contain the path to the recorded audio file

                    RecordButton.SetTitle("Record", UIControlState.Normal);
                    PlayButton.Enabled = !string.IsNullOrEmpty(audioFile);
                }
                else
                {
                    RecordButton.Enabled = false;

                    await recorder.StopRecording();

                    RecordButton.SetTitle("Record", UIControlState.Normal);
                    RecordButton.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                //blow up the app!
                throw ex;
            }
        }
Пример #13
0
        void ReleaseDesignerOutlets()
        {
            if (AssistButton != null)
            {
                AssistButton.Dispose();
                AssistButton = null;
            }

            if (KlipTypeButton != null)
            {
                KlipTypeButton.Dispose();
                KlipTypeButton = null;
            }

            if (KlipTypePickerContainer != null)
            {
                KlipTypePickerContainer.Dispose();
                KlipTypePickerContainer = null;
            }

            if (MenuButton != null)
            {
                MenuButton.Dispose();
                MenuButton = null;
            }

            if (ProjectNameButton != null)
            {
                ProjectNameButton.Dispose();
                ProjectNameButton = null;
            }

            if (RecordButton != null)
            {
                RecordButton.Dispose();
                RecordButton = null;
            }

            if (SelectProjectContainer != null)
            {
                SelectProjectContainer.Dispose();
                SelectProjectContainer = null;
            }

            if (ShotListButton != null)
            {
                ShotListButton.Dispose();
                ShotListButton = null;
            }

            if (ShotListContainer != null)
            {
                ShotListContainer.Dispose();
                ShotListContainer = null;
            }

            if (TimerLabel != null)
            {
                TimerLabel.Dispose();
                TimerLabel = null;
            }
        }
Пример #14
0
        void ReleaseDesignerOutlets()
        {
            if (CameraButton != null)
            {
                CameraButton.Dispose();
                CameraButton = null;
            }

            if (CameraUnavailableLabel != null)
            {
                CameraUnavailableLabel.Dispose();
                CameraUnavailableLabel = null;
            }

            if (CaptureModeControl != null)
            {
                CaptureModeControl.Dispose();
                CaptureModeControl = null;
            }

            if (CapturingLivePhotoLabel != null)
            {
                CapturingLivePhotoLabel.Dispose();
                CapturingLivePhotoLabel = null;
            }

            if (DepthDataDeliveryButton != null)
            {
                DepthDataDeliveryButton.Dispose();
                DepthDataDeliveryButton = null;
            }

            if (LivePhotoModeButton != null)
            {
                LivePhotoModeButton.Dispose();
                LivePhotoModeButton = null;
            }

            if (PhotoButton != null)
            {
                PhotoButton.Dispose();
                PhotoButton = null;
            }

            if (PreviewView != null)
            {
                PreviewView.Dispose();
                PreviewView = null;
            }

            if (RecordButton != null)
            {
                RecordButton.Dispose();
                RecordButton = null;
            }

            if (ResumeButton != null)
            {
                ResumeButton.Dispose();
                ResumeButton = null;
            }
        }
Пример #15
0
        public override void Create()
        {
            base.Create();

            Music.Instance.Play(Assets.THEME, true);
            Music.Instance.Volume(1f);

            uiCamera.Visible = false;

            var w = Camera.Main.CameraWidth;
            var h = Camera.Main.CameraHeight;

            _archs = new Archs();
            _archs.SetSize(w, h);
            Add(_archs);

            Rankings.Instance.Load();

            if (Rankings.Instance.records.Count > 0)
            {
                var left = (w - Math.Min(160, w)) / 2 + Gap;
                var top  = Align((h - RowHeight * Rankings.Instance.records.Count) / 2);

                var title = CreateText(TxtTitle, 9);
                title.Hardlight(Window.TitleColor);
                title.Measure();
                title.X = Align((w - title.Width) / 2);
                title.Y = Align(top - title.Height - Gap);
                Add(title);

                var pos = 0;

                foreach (var rec in Rankings.Instance.records)
                {
                    var row = new RecordButton(pos, pos == Rankings.Instance.lastRecord, rec);
                    row.SetRect(left, top + pos * RowHeight, w - left * 2, RowHeight);
                    Add(row);

                    pos++;
                }

                if (Rankings.Instance.totalNumber >= Rankings.TABLE_SIZE)
                {
                    var total = CreateText(Utils.Format(TxtTotal, Rankings.Instance.totalNumber), 8);
                    total.Hardlight(Window.TitleColor);
                    total.Measure();
                    total.X = Align((w - total.Width) / 2);
                    total.Y = Align(top + pos * RowHeight + Gap);
                    Add(total);
                }
            }
            else
            {
                var title = CreateText(TxtNoGames, 8);
                title.Hardlight(Window.TitleColor);
                title.Measure();
                title.X = Align((w - title.Width) / 2);
                title.Y = Align((h - title.Height) / 2);
                Add(title);
            }

            var btnExit = new ExitButton();

            btnExit.SetPos(Camera.Main.CameraWidth - btnExit.Width, 0);
            Add(btnExit);

            FadeIn();
        }
Пример #16
0
        private void UpdateSeries(IDictionary <string, float> sensors)
        {
            if (!m_startTime.HasValue)
            {
                m_startTime = DateTime.Now;
            }

            var isCelcius = sensors[SensorsKeys.Celcius] > 0;

            m_seriesData[SensorsKeys.Temperature].SetLastValueFormat(isCelcius ? "{0} °C" : "{0} °F");
            m_seriesData[SensorsKeys.TemperatureSet].SetLastValueFormat(isCelcius ? "{0} °C" : "{0} °F");

            var now      = DateTime.Now;
            var xValue   = now.ToOADate();
            var xAxisMax = now.AddSeconds(1).ToOADate();

            foreach (var kvp in m_seriesData)
            {
                var sensorName = kvp.Key;
                var data       = kvp.Value;
                var readings   = sensorName == SensorsKeys.Power
                                        ? sensors[SensorsKeys.OutputCurrent] * sensors[SensorsKeys.OutputVoltage]
                                        : sensors[sensorName];

                var interpolatedValue = Interpolate(readings, data.InterpolationLimits);

                var point = new DataPoint();
                if (Math.Abs(readings) > 0.001)
                {
                    var roundedValue = (float)Math.Round(readings, 3);
                    point.XValue      = xValue;
                    point.YValues     = new double[] { interpolatedValue };
                    point.Tag         = point.Label = roundedValue.ToString(CultureInfo.InvariantCulture);
                    point.MarkerSize  = 7;
                    point.MarkerStyle = MarkerStyle.Circle;
                    data.SetLastValue(roundedValue);
                }
                else
                {
                    point.IsEmpty = true;
                    data.SetLastValue(null);
                }
                data.Seires.Points.Add(point);
            }

            if (m_isRecording)
            {
                m_lineBuilder.Clear();
                m_lineBuilder.Append((now - m_recordStartTime).TotalSeconds.ToString(CultureInfo.InvariantCulture));
                m_lineBuilder.Append(",");

                var values = m_seriesData.Values
                             .Where(x => x.CheckBox.Checked)
                             .Select(x => x.LastValue.HasValue ? x.LastValue.Value.ToString(CultureInfo.InvariantCulture) : string.Empty);

                m_lineBuilder.Append(string.Join(",", values));
                var ex = Safe.Execute(() =>
                {
                    m_fileWriter.WriteLine(m_lineBuilder.ToString());
                    m_fileWriter.Flush();
                });
                if (ex != null)
                {
                    InfoBox.Show("Recording was stopped because of error:\n" + ex.Message);
                    RecordButton.PerformClick();
                }
            }

            foreach (var series in MainChart.Series)
            {
                while (series.Points.Count > MaxItems)
                {
                    series.Points.RemoveAt(0);
                }

                if (series.Points.Count > 0)
                {
                    var lastPoint = series.Points[series.Points.Count - 1];
                    if (lastPoint.IsEmpty)
                    {
                        continue;
                    }

                    if (series.Points.Count > 1)
                    {
                        var preLastPoint = series.Points[series.Points.Count - 2];
                        preLastPoint.Label      = null;
                        preLastPoint.MarkerSize = 0;
                    }
                }
            }

            var points = MainChart.Series.SelectMany(x => x.Points).Where(x => !x.IsEmpty).ToArray();

            var minDate = DateTime.FromOADate(points.Min(x => x.XValue));
            var maxDate = DateTime.FromOADate(points.Max(x => x.XValue));

            var range       = maxDate - minDate;
            var framesCount = Math.Floor(range.TotalSeconds / m_timeFrame.TotalSeconds);

            MainChartScrollBar.Maximum = (int)(framesCount * 30);
            if (IsTracking)
            {
                MainChartScrollBar.Value = MainChartScrollBar.Maximum;
                ScrollChart(true);
            }

            MainChart.ChartAreas[0].AxisX.Minimum = m_startTime.Value.AddSeconds(-5).ToOADate();
            MainChart.ChartAreas[0].AxisX.Maximum = xAxisMax;
        }
        private void UpdateSeries(IDictionary <string, float> sensors)
        {
            if (!m_startTime.HasValue)
            {
                m_startTime = DateTime.Now;
            }

            var now      = DateTime.Now;
            var xValue   = m_prevReceiveTime.HasValue ? m_xPrevValue + (now - m_prevReceiveTime.Value).TotalSeconds : 0;
            var xAxisMax = xValue + 1;

            m_prevReceiveTime = now;
            if (ShowPuffsBoundariesCheckBox.Checked)
            {
                var isFiring = sensors[SensorsKeys.IsFiring] > 0;
                if (isFiring && !m_isFiring)
                {
                    CreateFiringAnnotation(xValue, true);
                }
                if (!isFiring && m_isFiring && m_xPrevValue > 0)
                {
                    CreateFiringAnnotation(m_xPrevValue, false);
                }
                m_isFiring = isFiring;
            }
            m_xPrevValue = xValue;

            var isCelcius = sensors[SensorsKeys.IsCelcius] > 0;

            m_seriesData[SensorsKeys.Temperature].SetLastValueFormat(isCelcius ? "{0} °C" : "{0} °F");
            m_seriesData[SensorsKeys.TemperatureSet].SetLastValueFormat(isCelcius ? "{0} °C" : "{0} °F");

            foreach (var kvp in m_seriesData)
            {
                var sensorName        = kvp.Key;
                var data              = kvp.Value;
                var readings          = sensors[sensorName];
                var interpolatedValue = Interpolate(readings, data.InterpolationLimits);

                var point = new DataPoint();
                if (Math.Abs(readings) > 0.001)
                {
                    var roundedValue = (float)Math.Round(readings, 3);
                    point.XValue      = xValue;
                    point.YValues     = new double[] { interpolatedValue };
                    point.Tag         = point.Label = roundedValue.ToString(CultureInfo.InvariantCulture);
                    point.MarkerSize  = ChartSelectedMarkerSize;
                    point.MarkerStyle = MarkerStyle.Circle;
                    data.SetLastValue(roundedValue);
                }
                else
                {
                    point.IsEmpty = true;
                    data.SetLastValue(null);
                }
                data.Seires.Points.Add(point);
            }

            if (m_isRecording)
            {
                m_lineBuilder.Clear();
                // Trace time
                m_lineBuilder.Append(xValue.ToString(CultureInfo.InvariantCulture));
                m_lineBuilder.Append(",");
                // Other values
                var values = m_seriesData.Values
                             .Where(x => x.CheckBox.Checked)
                             .Select(x => x.LastValue.HasValue ? x.LastValue.Value.ToString(CultureInfo.InvariantCulture) : string.Empty);

                m_lineBuilder.Append(string.Join(",", values));
                var ex = Safe.Execute(() =>
                {
                    m_fileWriter.WriteLine(m_lineBuilder.ToString());
                    m_fileWriter.Flush();
                });
                if (ex != null)
                {
                    InfoBox.Show("Recording was stopped because of error:\n" + ex.Message);
                    RecordButton.PerformClick();
                }
            }

            while (MainChart.Annotations.Count > 1 && MainChart.Annotations.Count - 1 > ChartMaxFiringAnnotationsCount)
            {
                MainChart.Annotations.RemoveAt(1);
            }

            foreach (var series in MainChart.Series)
            {
                while (series.Points.Count > ChartMaxDataPointsCount)
                {
                    series.Points.RemoveAt(0);
                }
                MainChart.ChartAreas[0].AxisX.Minimum = MainChart.Series[0].Points[0].XValue - 1;

                if (series.Points.Count > 0)
                {
                    var lastPoint = series.Points[series.Points.Count - 1];
                    if (lastPoint.IsEmpty)
                    {
                        continue;
                    }

                    if (series.Points.Count > 1)
                    {
                        var preLastPoint = series.Points[series.Points.Count - 2];
                        preLastPoint.Label      = null;
                        preLastPoint.MarkerSize = ChartMarkerSize;
                    }
                }
            }

            UpdateHorizontalScrollAndAxisXMax(xAxisMax);
            if (IsTracking)
            {
                if (MainChartHorizontalScrollBar.Value == MainChartHorizontalScrollBar.Maximum)
                {
                    // Force zoom.
                    ScrollChartHorizontally(true);
                }
                else if (!m_isScrollingHorizontally)
                {
                    // Zoom applies automatically when changing scrollbar value.
                    MainChartHorizontalScrollBar.Value = MainChartHorizontalScrollBar.Maximum;
                }
            }
        }
Пример #18
0
        public void FinishedRecording(AVCaptureFileOutput captureOutput, NSUrl outputFileUrl, NSObject[] connections, NSError error)
        {
            // Note that currentBackgroundRecordingID is used to end the background task associated with this recording.
            // This allows a new recording to be started, associated with a new UIBackgroundTaskIdentifier, once the movie file output's isRecording property
            // is back to false — which happens sometime after this method returns.
            // Note: Since we use a unique file path for each recording, a new recording will not overwrite a recording currently being saved.

            Action cleanup = () => {
                var path = outputFileUrl.Path;
                if (NSFileManager.DefaultManager.FileExists(path))
                {
                    NSError err;
                    if (!NSFileManager.DefaultManager.Remove(path, out err))
                    {
                        Console.WriteLine($"Could not remove file at url: {outputFileUrl}");
                    }
                }
                var currentBackgroundRecordingID = backgroundRecordingID;
                if (currentBackgroundRecordingID != -1)
                {
                    backgroundRecordingID = -1;
                    UIApplication.SharedApplication.EndBackgroundTask(currentBackgroundRecordingID);
                }
            };

            bool success = true;

            if (error != null)
            {
                Console.WriteLine($"Movie file finishing error: {error.LocalizedDescription}");
                success = ((NSNumber)error.UserInfo[AVErrorKeys.RecordingSuccessfullyFinished]).BoolValue;
            }

            if (success)
            {
                // Check authorization status.
                PHPhotoLibrary.RequestAuthorization(status => {
                    if (status == PHAuthorizationStatus.Authorized)
                    {
                        // Save the movie file to the photo library and cleanup.
                        PHPhotoLibrary.SharedPhotoLibrary.PerformChanges(() => {
                            var options = new PHAssetResourceCreationOptions
                            {
                                ShouldMoveFile = true
                            };
                            var creationRequest = PHAssetCreationRequest.CreationRequestForAsset();
                            creationRequest.AddResource(PHAssetResourceType.Video, outputFileUrl, options);
                        }, (success2, error2) => {
                            if (!success2)
                            {
                                Console.WriteLine($"Could not save movie to photo library: {error2}");
                            }
                            cleanup();
                        });
                    }
                    else
                    {
                        cleanup();
                    }
                });
            }
            else
            {
                cleanup();
            }

            // Enable the Camera and Record buttons to let the user switch camera and start another recording.
            DispatchQueue.MainQueue.DispatchAsync(() => {
                // Only enable the ability to change camera if the device has more than one camera.
                CameraButton.Enabled       = UniqueDevicePositionsCount(videoDeviceDiscoverySession) > 1;
                RecordButton.Enabled       = true;
                CaptureModeControl.Enabled = true;
                RecordButton.SetTitle("Record", UIControlState.Normal);
            });
        }