Exemplo n.º 1
0
        public 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
            {
                long   size3     = fileaudioPath.Length() / 1024;
                string audiosize = size3.ToString();
                Comp_AttachmentModel attachmentModel = new Comp_AttachmentModel();
                attachmentModel.localPath   = AudioSavePathInDevice;
                attachmentModel.file_type   = "Audio";
                attachmentModel.FileName    = audioname;
                attachmentModel.taskId      = task_id_to_send;
                attachmentModel.GeoLocation = geolocation;
                attachmentModel.FileSize    = audiosize;
                attachmentModel.file_format = ".mp3";
                // attachmentModel.max_numbers = audio_max.ToString();
                db.InsertAttachmentData(attachmentModel, "no");
                //comp_AttachmentModels.Add(attachmentModel);
                //imagelist.AddRange(comp_AttachmentModels.Where(p => p.Attachment_Type == "Image" ));
                audio_comp_lst.AddRange(db.GetAttachmentData(audioname));

                // postattachmentcomplianceAsync(attachmentModel);
                adapter3          = new GridViewAdapter_Audio(Activity, audio_comp_lst, FragmentManager);
                Gridview3.Adapter = adapter3;


                if (ic.connectivity())
                {
                    postattachmentcomplianceAsync(attachmentModel);
                    // db.updateComplianceattachmentstatus("yes");
                }

                builder.Dismiss();
            };
            recordbtn.Click += delegate
            {
                MediaRecorderReady();

                try
                {
                    timer          = new Timer();
                    timer.Interval = 1000; // 1 second
                    timer.Elapsed += Timer_Elapsed;
                    timer.Start();
                    mediaRecorder.Stop();
                    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();
            };


            builder.Show();
        }
Exemplo n.º 2
0
        public async override void OnActivityResult(int requestCode, int resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            if (requestCode == Camera && resultCode == (int)Android.App.Result.Ok)
            {
                Bitmap bitmap;

                //Converstion Image Size
                int height = Resources.DisplayMetrics.HeightPixels;
                int width  = Resources.DisplayMetrics.WidthPixels;
                using (bitmap = fileImagePath.Path.LoadAndResizeBitmap(width / 4, height / 4))
                {
                }
                long   size1   = fileImagePath.Length() / 1024;
                string imgsize = size1.ToString();

                Comp_AttachmentModel attachmentModel = new Comp_AttachmentModel();
                attachmentModel.localPath   = imageURL;
                attachmentModel.file_type   = "Image";
                attachmentModel.FileName    = imageName;
                attachmentModel.taskId      = task_id_to_send;
                attachmentModel.GeoLocation = geolocation;
                attachmentModel.FileSize    = imgsize;
                attachmentModel.file_format = ".jpg";
                //attachmentModel.max_numbers = image_max.ToString();



                Android.App.AlertDialog.Builder alertDiag = new Android.App.AlertDialog.Builder(Activity);
                alertDiag.SetTitle("Upload Compliance");
                alertDiag.SetMessage("press upload to continue");
                alertDiag.SetPositiveButton("Upload", (senderAlert, args) =>
                {
                    db.InsertAttachmentData(attachmentModel, "no");
                    image_comp_lst.AddRange(db.GetAttachmentData(imageName));

                    adapter1          = new GridViewAdapter_Image(Activity, image_comp_lst, FragmentManager);
                    Gridview1.Adapter = adapter1;

                    if (ic.connectivity())
                    {
                        postattachmentcomplianceAsync(attachmentModel);
                        //db.updateComplianceattachmentstatus("yes");
                        //uploadcountimage++;
                        //uploadimage.Text = uploaded;
                    }
                });
                alertDiag.SetNegativeButton("Cancel", (senderAlert, args) =>
                {
                    alertDiag.Dispose();
                });
                Dialog diag = alertDiag.Create();
                diag.Show();
            }
            if (requestCode == Video && resultCode == (int)Android.App.Result.Ok)
            {
                long   size2     = fileVideoPath.Length() / 1024;
                string videosize = size2.ToString();

                Comp_AttachmentModel attachmentModel = new Comp_AttachmentModel();
                attachmentModel.localPath   = videoURL;
                attachmentModel.file_type   = "Video";
                attachmentModel.FileName    = videoName;
                attachmentModel.taskId      = task_id_to_send;
                attachmentModel.GeoLocation = geolocation;
                attachmentModel.FileSize    = videosize;
                attachmentModel.file_format = ".mp4";
                //attachmentModel.max_numbers = video_max.ToString();

                db.InsertAttachmentData(attachmentModel, "no");

                //comp_AttachmentModels.Add(attachmentModel);


                //imagelist.AddRange(comp_AttachmentModels.Where(p => p.Attachment_Type == "Image" ));
                video_comp_lst.AddRange(db.GetAttachmentData(videoName));
                // postattachmentcomplianceAsync(attachmentModel);
                adapter2          = new GridViewAdapter_Video(Activity, video_comp_lst, FragmentManager);
                Gridview2.Adapter = adapter2;

                if (ic.connectivity())
                {
                    postattachmentcomplianceAsync(attachmentModel);
                    //db.updateComplianceattachmentstatus("yes");
                    //uploadcountvideo++;
                    //uploadvideo.Text = uploaded;
                }
            }

            if (requestCode == VOICE && resultCode == (int)Android.App.Result.Ok)
            {
                var matches = data.GetStringArrayListExtra(RecognizerIntent.ExtraResults);
                if (matches.Count != 0)
                {
                    string textInput = Description.Text + matches[0];

                    // limit the output to 500 characters
                    if (textInput.Length > 500)
                    {
                        textInput = textInput.Substring(0, 500);
                    }
                    Description.Text = textInput;
                }
                else
                {
                    Description.Text = "No speech was recognised";
                }
            }

            uploadimage.Text = image_comp_lst.Count.ToString();
            uploadaudio.Text = audio_comp_lst.Count.ToString();
            uploadvideo.Text = video_comp_lst.Count.ToString();
        }
Exemplo n.º 3
0
        public void recording()
        {
            View view = LayoutInflater.Inflate(Resource.Layout.audio_recorder, null);

            Android.App.AlertDialog builder = new Android.App.AlertDialog.Builder(this).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
            {
                Comp_AttachmentModel attachmentModel = new Comp_AttachmentModel();
                attachmentModel.Attachment_Path = AudioSavePathInDevice;
                attachmentModel.Attachment_Type = "Audio";
                attachmentModel.Attachment_Name = audioname;
                attachmentModel.Task_id         = task_id_to_send;

                db.InsertAttachmentData(attachmentModel);

                //comp_AttachmentModels.Add(attachmentModel);


                //imagelist.AddRange(comp_AttachmentModels.Where(p => p.Attachment_Type == "Image" ));
                audiolist = db.GetAttachmentData("Audio");

                adapter3          = new GridViewAdapter_Audio(this, audiolist);
                Gridview3.Adapter = adapter3;
                Gridview3.setExpanded(true);
                Gridview3.ChoiceMode = (ChoiceMode)AbsListViewChoiceMode.MultipleModal;
                Gridview3.SetMultiChoiceModeListener(new MultiChoiceModeListener3(this));
                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(this, "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(this, "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();
        }
Exemplo n.º 4
0
        public async Task postattachmentcomplianceAsync(Comp_AttachmentModel compmodel)
        {
            progress.Show();
            List <Comp_AttachmentModel> models = new List <Comp_AttachmentModel>();

            //for(int i=0; i < models.Count; i++)
            //{
            models.Add(compmodel);
            //  }

            if (compmodel.file_type == "Image")
            {
                byte[] img  = GetStreamFromFile(compmodel.localPath);
                var    url1 = await blob.UploadPhotoAsync(img, compmodel.localPath.Substring(compmodel.localPath.LastIndexOf("/") + 1));

                if (url1 != null)
                {
                    compmodel.Path = url1;
                }
            }
            if (compmodel.file_type == "Video")
            {
                byte[] img  = GetStreamFromFile(compmodel.localPath);
                var    url1 = await blob.UploadPhotoAsync(img, compmodel.localPath.Substring(compmodel.localPath.LastIndexOf("/") + 1));

                if (url1 != null)
                {
                    compmodel.Path = url1;
                }
            }
            if (compmodel.file_type == "Audio")
            {
                byte[] img  = GetStreamFromFile(compmodel.localPath);
                var    url1 = await blob.UploadPhotoAsync(img, compmodel.localPath.Substring(compmodel.localPath.LastIndexOf("/") + 1));

                if (url1 != null)
                {
                    compmodel.Path = url1;
                }
            }

            string json = JsonConvert.SerializeObject(models);

            try
            {
                string item = await restService.CompliancePostServiceMethod(Activity, "UpoadTaskCompliance", json, Description.Text);

                if (item.Contains("Compliance Upload Sucessfully"))
                {
                    db.updateComplianceStatus(compmodel.taskId);
                    Toast.MakeText(Activity, "attachment post  Successfully..", ToastLength.Long).Show();
                    //progress.Dismiss();
                }
                else
                {
                    Toast.MakeText(Activity, "Oops! Something Went Wrong.", ToastLength.Long).Show();
                    //progress.Dismiss();
                }
            }
            catch (Exception ex)
            {
                //progress.Dismiss();
            }
            progress.Dismiss();
        }
Exemplo n.º 5
0
        protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            if (requestCode == Camera)
            {
                Bitmap bitmap = BitmapFactory.DecodeFile(imageURL);

                Comp_AttachmentModel attachmentModel = new Comp_AttachmentModel();
                attachmentModel.Attachment_Path = AudioSavePathInDevice;
                attachmentModel.Attachment_Type = "Image";
                attachmentModel.Attachment_Name = audioname;
                attachmentModel.Task_id         = task_id_to_send;

                db.InsertAttachmentData(attachmentModel);

                //comp_AttachmentModels.Add(attachmentModel);


                //imagelist.AddRange(comp_AttachmentModels.Where(p => p.Attachment_Type == "Image" ));
                imagelist         = db.GetAttachmentData("Image");
                adapter1          = new GridViewAdapter_Image(this, imagelist);
                Gridview1.Adapter = adapter1;
                Gridview1.setExpanded(true);
                Gridview1.ChoiceMode = (ChoiceMode)AbsListViewChoiceMode.MultipleModal;
                Gridview1.SetMultiChoiceModeListener(new MultiChoiceModeListener1(this));
                imageCount++;
            }
            if (requestCode == Video)
            {
                Comp_AttachmentModel attachmentModel = new Comp_AttachmentModel();
                attachmentModel.Attachment_Path = AudioSavePathInDevice;
                attachmentModel.Attachment_Type = "Video";
                attachmentModel.Attachment_Name = audioname;
                attachmentModel.Task_id         = task_id_to_send;

                db.InsertAttachmentData(attachmentModel);

                //comp_AttachmentModels.Add(attachmentModel);


                //imagelist.AddRange(comp_AttachmentModels.Where(p => p.Attachment_Type == "Image" ));
                videolist = db.GetAttachmentData("Video");

                adapter2          = new GridViewAdapter_Video(this, videolist);
                Gridview2.Adapter = adapter2;
                Gridview2.setExpanded(true);
                Gridview2.ChoiceMode = (ChoiceMode)AbsListViewChoiceMode.MultipleModal;
                Gridview2.SetMultiChoiceModeListener(new MultiChoiceModeListener2(this));

                videoCount++;
            }

            if (requestCode == VOICE)
            {
                var matches = data.GetStringArrayListExtra(RecognizerIntent.ExtraResults);
                if (matches.Count != 0)
                {
                    string textInput = Description.Text + matches[0];

                    // limit the output to 500 characters
                    if (textInput.Length > 500)
                    {
                        textInput = textInput.Substring(0, 500);
                    }
                    Description.Text = textInput;
                }
                else
                {
                    Description.Text = "No speech was recognised";
                }
            }
        }