/// <summary>
        /// Initializes a new instance of the <see cref="ChooserHandler{TTaskEventArgs}" /> class.
        /// </summary>
        /// <param name="chooser">The <see cref="ChooserBase{TTaskEventArgs}"/> to show.</param>
        /// <param name="resultAction">The <see cref="Action{TTaskEventArgs}"/> to be called once the operation is finished.</param>
        public ChooserHandler(ChooserBase <TTaskEventArgs> chooser, Action <TTaskEventArgs> resultAction)
        {
            _chooser      = chooser;
            _resultAction = resultAction;

            _chooser.Completed += Chooser_Completed;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ChooserHandler{TTaskEventArgs}" /> class.
        /// </summary>
        /// <param name="chooser">The <see cref="ChooserBase{TTaskEventArgs}"/> to show.</param>
        public ChooserHandler(ChooserBase <TTaskEventArgs> chooser)
        {
            _chooser            = chooser;
            _chooser.Completed += Chooser_Completed;

            _taskCompletionSource = new TaskCompletionSource <TTaskEventArgs>();
        }
Пример #3
0
 public void ChoosePictureCommon(ChooserBase<PhotoResult> chooser, int maxPixelDimension, int percentQuality, Action<Stream> pictureAvailable, Action assumeCancelled)
 {
     chooser.Completed += (sender, args) =>
                              {
                                  if (args.ChosenPhoto != null)
                                  {
                                      ResizeThenCallOnMainThread(maxPixelDimension,
                                          percentQuality,
                                          args.ChosenPhoto,
                                          pictureAvailable);
                                  }
                                  else
                                      assumeCancelled();
                              };
     DoWithInvalidOperationProtection(chooser.Show);
 }
 public void ChoosePictureCommon(ChooserBase <PhotoResult> chooser, int maxPixelDimension, int percentQuality, Action <Stream> pictureAvailable, Action assumeCancelled)
 {
     chooser.Completed += (sender, args) =>
     {
         if (args.ChosenPhoto != null)
         {
             ResizeThenCallOnMainThread(maxPixelDimension,
                                        percentQuality,
                                        args.ChosenPhoto,
                                        pictureAvailable);
         }
         else
         {
             assumeCancelled();
         }
     };
     DoWithInvalidOperationProtection(chooser.Show);
 }
Пример #5
0
        public static Task <TTaskEventArgs> ShowAsync <TTaskEventArgs>(this ChooserBase <TTaskEventArgs> chooser)
            where TTaskEventArgs : TaskEventArgs
        {
            var taskCompletionSource = new TaskCompletionSource <TTaskEventArgs>();

            EventHandler <TTaskEventArgs> completed = null;

            completed = (s, e) =>
            {
                chooser.Completed -= completed;

                taskCompletionSource.SetResult(e);
            };

            chooser.Completed += completed;
            chooser.Show();

            return(taskCompletionSource.Task);
        }
Пример #6
0
        public void takePicture(string options)
        {
            try
            {
                string[] args = JSON.JsonHelper.Deserialize <string[]>(options);
                // ["quality", "destinationType", "sourceType", "targetWidth", "targetHeight", "encodingType",
                //     "mediaType", "allowEdit", "correctOrientation", "saveToPhotoAlbum" ]
                cameraOptions                    = new CameraOptions();
                cameraOptions.Quality            = int.Parse(args[0]);
                cameraOptions.DestinationType    = int.Parse(args[1]);
                cameraOptions.PictureSourceType  = int.Parse(args[2]);
                cameraOptions.TargetWidth        = int.Parse(args[3]);
                cameraOptions.TargetHeight       = int.Parse(args[4]);
                cameraOptions.EncodingType       = int.Parse(args[5]);
                cameraOptions.MediaType          = int.Parse(args[6]);
                cameraOptions.AllowEdit          = bool.Parse(args[7]);
                cameraOptions.CorrectOrientation = bool.Parse(args[8]);
                cameraOptions.SaveToPhotoAlbum   = bool.Parse(args[9]);

                // a very large number will force the other value to be the bound
                if (cameraOptions.TargetWidth > -1 && cameraOptions.TargetHeight == -1)
                {
                    cameraOptions.TargetHeight = 100000;
                }
                else if (cameraOptions.TargetHeight > -1 && cameraOptions.TargetWidth == -1)
                {
                    cameraOptions.TargetWidth = 100000;
                }
            }
            catch (Exception ex)
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, ex.Message));
                return;
            }

            // Api supports FILE_URI, DATA_URL, NATIVE_URI destination types.
            // Treat all other destination types as an error.
            switch (cameraOptions.DestinationType)
            {
            case Camera.FILE_URI:
            case Camera.DATA_URL:
            case Camera.NATIVE_URI:
                break;

            default:
                DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Incorrect option: destinationType"));
                return;
            }

            ChooserBase <PhotoResult> chooserTask = null;

            if (cameraOptions.PictureSourceType == CAMERA)
            {
                chooserTask = new CameraCaptureTask();
            }
            else if ((cameraOptions.PictureSourceType == PHOTOLIBRARY) || (cameraOptions.PictureSourceType == SAVEDPHOTOALBUM))
            {
                chooserTask = new PhotoChooserTask();
            }
            // if chooserTask is still null, then PictureSourceType was invalid
            if (chooserTask != null)
            {
                chooserTask.Completed += onTaskCompleted;
                chooserTask.Show();
            }
            else
            {
                Debug.WriteLine("Unrecognized PictureSourceType :: " + cameraOptions.PictureSourceType.ToString());
                DispatchCommandResult(new PluginResult(PluginResult.Status.NO_RESULT));
            }
        }
Пример #7
0
 private void DoPhotoTask(ChooserBase<PhotoResult> task)
 {
     try
     {
         task.Completed += (t, args) =>
         {
             if (args.ChosenPhoto != null)
             {
                 ShowDisplay(DisplayState.Processing);
                 var bitmapImage = new BitmapImage();
                 bitmapImage.SetSource(args.ChosenPhoto);
                 var writeableBitmap = new WriteableBitmap(bitmapImage);
                 ProcessImage(writeableBitmap);
             }
             else
             {
                 // hope the user doesn't mind being told nothing
             }
         };
         task.Show();
     }
     catch (Exception exception)
     {
         // hope the user doesn't mind being told nothing
     }
 }