Beispiel #1
0
            public MediaPickedEventArgs(int id, bool isCanceled, MediaFileFix media = null)
            {
                RequestId  = id;
                IsCanceled = isCanceled;
                if (!IsCanceled && media == null)
                {
                    throw new ArgumentNullException("media");
                }

                Media = media;
            }
Beispiel #2
0
        internal static Task <MediaPickedEventArgs> GetMediaFileAsync(Context context, int requestCode, string action, bool isPhoto, ref Android.Net.Uri path, Android.Net.Uri data)
        {
            Task <Tuple <string, bool> > pathFuture;

            string originalPath = null;

            if (action != Intent.ActionPick)
            {
                originalPath = path.Path;

                // Not all camera apps respect EXTRA_OUTPUT, some will instead
                // return a content or file uri from data.
                if (data != null && data.Path != originalPath && !File.Exists(originalPath))
                {
                    originalPath = data.ToString();
                    string currentPath = path.Path;
                    pathFuture = TryMoveFileAsync(context, data, path, isPhoto).ContinueWith(t =>
                                                                                             new Tuple <string, bool>(t.Result ? currentPath : null, false));
                }
                else
                {
                    pathFuture = TaskFromResult(new Tuple <string, bool>(path.Path, false));
                }
            }
            else if (data != null)
            {
                originalPath = data.ToString();
                path         = data;
                pathFuture   = GetFileForUriAsync(context, path, isPhoto);
            }
            else
            {
                pathFuture = TaskFromResult <Tuple <string, bool> >(null);
            }

            return(pathFuture.ContinueWith(t => {
                string resultPath = t.Result.Item1;
                if (!string.IsNullOrEmpty(resultPath) && File.Exists(resultPath))
                {
                    var mf = new MediaFileFix(resultPath, deletePathOnDispose: t.Result.Item2);
                    return new MediaPickedEventArgs(requestCode, false, mf);
                }
                else
                {
                    return new MediaPickedEventArgs(requestCode, new Xamarin.Media.MediaFileNotFoundException(originalPath));
                }
            }));
        }