Esempio n. 1
0
        private void recording()
        {
            View view = LayoutInflater.Inflate(Resource.Layout.audio_recorder, null);

            Android.App.AlertDialog builder = new Android.App.AlertDialog.Builder(Activity).Create();
            builder.SetView(view);
            builder.Window.SetLayout(600, 600);
            builder.SetCanceledOnTouchOutside(false);
            recordbtn = view.FindViewById <Button>(Resource.Id.recordbtn);
            stopbtn   = view.FindViewById <ImageView>(Resource.Id.stopbtn);
            playbtn   = view.FindViewById <ImageView>(Resource.Id.playbtn);
            Timer     = view.FindViewById <TextView>(Resource.Id.timerbtn);
            seekBar   = view.FindViewById <SeekBar>(Resource.Id.seek_bar);
            Done_Btn  = view.FindViewById <Button>(Resource.Id.donebtn);


            Done_Btn.Click += delegate
            {
                TaskFileMapping_Model attachmentModel = new TaskFileMapping_Model();
                long   size3     = fileaudioPath.Length() / 1024 * 1024;
                string audiosize = size3.ToString();
                attachmentModel.Path        = AudioSavePathInDevice;
                attachmentModel.FileType    = "Audio";
                attachmentModel.FileName    = audioname;
                attachmentModel.localtaskId = task_id_to_send;
                // attachmentModel.file_format = Utility.audiotype;
                attachmentModel.FileSize = audiosize;
                //  attachmentModel.GeoLocation = geolocation;
                //  attachmentModel.max_numbers = audio_max.ToString();
                // db.InsertCreateAttachData(attachmentModel);

                //   comp_AttachmentModels.Add(attachmentModel);

                listmapping.Add(attachmentModel);
                //imagelist.AddRange(comp_AttachmentModels.Where(p => p.Attachment_Type == "Image" ));
                //  audio_list = db.GetCreateAttachmentData("Audio", licenceidmodel[0].taskid.ToString());
                for (int i = 0; i < listmapping.Count; i++)
                {
                    if (listmapping[i].FileType.Equals("Audio"))
                    {
                        audio_list.Add(listmapping[i]);
                    }
                }
                adapter_3          = new GridAudioCreateTask(Activity, audio_list);
                Gridview_3.Adapter = adapter_3;
                Gridview_3.setExpanded(true);
                Gridview_3.ChoiceMode = (ChoiceMode)AbsListViewChoiceMode.MultipleModal;
                Gridview_3.SetMultiChoiceModeListener(new MultiChoiceModeListener3(Activity));
                audioCount++;
                builder.Dismiss();
            };
            recordbtn.Click += delegate
            {
                MediaRecorderReady();

                try
                {
                    timer          = new Timer();
                    timer.Interval = 1000; // 1 second
                    timer.Elapsed += Timer_Elapsed;
                    timer.Start();
                    mediaRecorder.Prepare();
                    mediaRecorder.Start();
                }
                catch (Exception e)
                {
                    // TODO Auto-generated catch block
                    //e.printStackTrace();
                }

                Toast.MakeText(Activity, "Recording started", ToastLength.Long).Show();
            };
            stopbtn.Click += delegate
            {
                try
                {
                    mediaRecorder.Stop();
                    Timer.Text = "00:00:00";
                    timer.Stop();

                    timer = null;
                }
                catch (Exception ex)
                {
                }

                //stoprecorder();

                //btn2.Enabled=false;
                //buttonPlayLastRecordAudio.setEnabled(true);
                //buttonStart.setEnabled(true);
                //buttonStopPlayingRecording.setEnabled(false);

                Toast.MakeText(Activity, "Recording completed", ToastLength.Long).Show();
            };
            //pausebtn.Click += delegate
            //{
            //    //OnPause();
            //    mediaRecorder.Pause();
            //    timer.Dispose();

            //};
            playbtn.Click += delegate
            {
                mediaPlayer = new MediaPlayer();
                mediaPlayer.SetDataSource(AudioSavePathInDevice);
                mediaPlayer.Prepare();
                mediaPlayer.Start();
                //mediaPlayer = MediaPlayer.Create(this, Resource.Raw.AudioSavePathInDevice);
                seekBar.Max = mediaPlayer.Duration;
                run();
            };

            //resumebtn.Click += delegate
            // {
            //     mediaRecorder.Resume();
            //     timer.Start();

            // };

            //savebtn.Click += delegate
            // {
            //     Java.IO.File path = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures);
            //     audiofile = new Java.IO.File(path, "TaskApp");
            //     if (!audiofile.Exists())
            //     {
            //         audiofile.Mkdirs();
            //     }
            //     audioname = Utility.fileName1();
            //     fileImagePath = new Java.IO.File(audiofile, string.Format(audioname, Guid.NewGuid()));
            //     AudioSavePathInDevice = fileImagePath.AbsolutePath;

            //     mediaRecorder.SetOutputFile(AudioSavePathInDevice);

            //     builder.Dismiss();
            // };
            builder.Show();
        }
Esempio n. 2
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = inflater.Inflate(Resource.Layout.create_ref_layout, null);

            db             = new DbHelper();
            geo            = new Geolocation();
            geolocation    = geo.GetGeoLocation(Activity);
            HasOptionsMenu = true;
            isRecording    = false;
            prefs          = PreferenceManager.GetDefaultSharedPreferences(Activity);
            licenceId      = prefs.GetString("LicenceId", "");
            tempId         = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + licenceId;
            camera         = view.FindViewById <ImageButton>(Resource.Id.camera_btn);
            video          = view.FindViewById <ImageButton>(Resource.Id.video_btn);
            microphone     = view.FindViewById <ImageButton>(Resource.Id.micro_btn);
            Gridview_1     = view.FindViewById <ExpandableHeightGridView>(Resource.Id.grid);
            Grid_attach    = view.FindViewById <ExpandableHeightGridView>(Resource.Id.gridattachment);
            Gridview_2     = view.FindViewById <ExpandableHeightGridView>(Resource.Id.gridView2);
            Gridview_3     = view.FindViewById <ExpandableHeightGridView>(Resource.Id.gridView3);
            attachment_btn = view.FindViewById <ImageButton>(Resource.Id.attachment);
            // Gridview_1 = view.FindViewById<ExpandableHeightGridView>(Resource.Id.gridView1);
            //Grid_attach = view.FindViewById<ExpandableHeightGridView>(Resource.Id.gridattachment);
            //Gridview_2 = view.FindViewById<ExpandableHeightGridView>(Resource.Id.gridView2);
            //Gridview_3 = view.FindViewById<ExpandableHeightGridView>(Resource.Id.gridView3);
            //title = view.FindViewById<ImageView>(Resource.Id.imageView1);
            //   listmapping = new List<TaskFileMapping_Model>();
            desc = view.FindViewById <ImageView>(Resource.Id.imageView3);

            if (image_list.Count > 0)
            {
                adapter_1          = new GridImageAdapterCreatetask(Activity, image_list);
                Gridview_1.Adapter = adapter_1;
                Gridview_1.setExpanded(true);
                Gridview_1.ChoiceMode = (ChoiceMode)AbsListViewChoiceMode.MultipleModal;
                Gridview_1.SetMultiChoiceModeListener(new MultiChoiceModeListener1(Activity));
            }
            if (video_list.Count > 0)
            {
                adapter_2          = new GridVideoAdapterCreateTask(Activity, video_list);
                Gridview_2.Adapter = adapter_2;
                Gridview_2.setExpanded(true);
                Gridview_2.ChoiceMode = (ChoiceMode)AbsListViewChoiceMode.MultipleModal;
                Gridview_2.SetMultiChoiceModeListener(new MultiChoiceModeListener2(Activity));
            }
            if (audio_list.Count > 0)
            {
                adapter_3          = new GridAudioCreateTask(Activity, audio_list);
                Gridview_3.Adapter = adapter_3;
                Gridview_3.setExpanded(true);
                Gridview_3.ChoiceMode = (ChoiceMode)AbsListViewChoiceMode.MultipleModal;
                Gridview_3.SetMultiChoiceModeListener(new MultiChoiceModeListener3(Activity));
            }
            if (listmapping.Count > 0)
            {
                forCreate           = new GridAttachmentForCreate(Activity, listmapping);
                Grid_attach.Adapter = forCreate;
                Grid_attach.setExpanded(true);
            }
            attachment_btn.Click += delegate
            {
                attachmentClick();
            };
            camera.Click += delegate
            {
                BtnCamera_Click();
            };

            video.Click += delegate
            {
                VideoClick();
            };
            microphone.Click += delegate
            {
                recording();
            };
            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 Android.App.AlertDialog.Builder(title.Context);
                alert.SetTitle("You don't seem to have a microphone to record with");
                alert.SetPositiveButton("OK", (sender, e) =>
                {
                    task_name.Text    = "No microphone present";
                    title.Enabled     = false;
                    task_comment.Text = "No microphone present";
                    desc.Enabled      = false;
                    return;
                });

                alert.Show();
            }
            else
            {
                //title.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, Android.App.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);


                //        voiceIntent.PutExtra(RecognizerIntent.ExtraLanguage, Java.Util.Locale.Default);
                //        StartActivityForResult(voiceIntent, VOICE);
                //    }
                //  };
                //desc.Click += delegate
                //{
                //    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, Android.App.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.Default);
                //        StartActivityForResult(voiceIntent, DESC);
                //    }
                //};
            }
            return(view);
        }