You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ia...@apache.org on 2014/04/23 20:56:24 UTC
[10/16] git commit: combining callbacks, removing lots of dupe code
combining callbacks, removing lots of dupe code
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/commit/f6e85483
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/f6e85483
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/f6e85483
Branch: refs/heads/master
Commit: f6e8548381db0e7e4b7d6e095c6718313a001edf
Parents: e7a3d70
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Mon Apr 7 16:32:21 2014 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Mon Apr 7 16:32:21 2014 -0700
----------------------------------------------------------------------
src/wp/Camera.cs | 99 ++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 94 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/f6e85483/src/wp/Camera.cs
----------------------------------------------------------------------
diff --git a/src/wp/Camera.cs b/src/wp/Camera.cs
index 53ae61a..c9f6f78 100644
--- a/src/wp/Camera.cs
+++ b/src/wp/Camera.cs
@@ -200,7 +200,7 @@ namespace WPCordovaClassLib.Cordova.Commands
}
catch (Exception ex)
{
- this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, ex.Message));
+ DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, ex.Message));
return;
}
@@ -227,6 +227,95 @@ namespace WPCordovaClassLib.Cordova.Commands
}
+ public void onTaskCompleted(object sender, PhotoResult e)
+ {
+ var task = sender as ChooserBase<PhotoResult>;
+ if (task != null)
+ {
+ task.Completed -= onCameraTaskCompleted;
+ }
+
+ if (e.Error != null)
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR));
+ return;
+ }
+
+ switch (e.TaskResult)
+ {
+ case TaskResult.OK:
+ try
+ {
+ string imagePathOrContent = string.Empty;
+ if (cameraOptions.DestinationType == FILE_URI)
+ {
+ // Save image in media library
+ if (cameraOptions.SaveToPhotoAlbum)
+ {
+ MediaLibrary library = new MediaLibrary();
+ Picture pict = library.SavePicture(e.OriginalFileName, e.ChosenPhoto); // to save to photo-roll ...
+ }
+
+ /*
+ int orient = ImageExifHelper.getImageOrientationFromStream(e.ChosenPhoto);
+ int newAngle = 0;
+ switch (orient)
+ {
+ case ImageExifOrientation.LandscapeLeft:
+ newAngle = 90;
+ break;
+ case ImageExifOrientation.PortraitUpsideDown:
+ newAngle = 180;
+ break;
+ case ImageExifOrientation.LandscapeRight:
+ newAngle = 270;
+ break;
+ case ImageExifOrientation.Portrait:
+ default: break; // 0 default already set
+ }
+
+ Stream rotImageStream = ImageExifHelper.RotateStream(e.ChosenPhoto, newAngle);
+
+ // we should reset stream position after saving stream to media library
+ rotImageStream.Seek(0, SeekOrigin.Begin);
+ imagePathOrContent = SaveImageToLocalStorage(rotImageStream, Path.GetFileName(e.OriginalFileName));
+
+ */
+
+
+ imagePathOrContent = SaveImageToLocalStorage(e.ChosenPhoto, Path.GetFileName(e.OriginalFileName));
+ }
+ else if (cameraOptions.DestinationType == DATA_URL)
+ {
+ imagePathOrContent = GetImageContent(e.ChosenPhoto);
+ }
+ else
+ {
+ // TODO: shouldn't this happen before we launch the camera-picker?
+ DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Incorrect option: destinationType"));
+ return;
+ }
+ DispatchCommandResult(new PluginResult(PluginResult.Status.OK, imagePathOrContent));
+
+ }
+ catch (Exception)
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Error retrieving image."));
+ }
+ break;
+
+ case TaskResult.Cancel:
+ DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Selection cancelled."));
+ break;
+
+ default:
+ DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Selection did not complete!"));
+ break;
+ }
+
+
+ }
+
public void onCameraTaskCompleted(object sender, PhotoResult e)
{
var task = sender as ChooserBase<PhotoResult>;
@@ -278,13 +367,13 @@ namespace WPCordovaClassLib.Cordova.Commands
// we should return stream position back after saving stream to media library
rotImageStream.Seek(0, SeekOrigin.Begin);
- imagePathOrContent = this.SaveImageToLocalStorage(rotImageStream, Path.GetFileName(e.OriginalFileName));
+ imagePathOrContent = SaveImageToLocalStorage(rotImageStream, Path.GetFileName(e.OriginalFileName));
}
else if (cameraOptions.DestinationType == DATA_URL)
{
- imagePathOrContent = this.GetImageContent(e.ChosenPhoto);
+ imagePathOrContent = GetImageContent(e.ChosenPhoto);
}
else
{
@@ -336,11 +425,11 @@ namespace WPCordovaClassLib.Cordova.Commands
if (cameraOptions.DestinationType == FILE_URI)
{
- imagePathOrContent = this.SaveImageToLocalStorage(e.ChosenPhoto, Path.GetFileName(e.OriginalFileName));
+ imagePathOrContent = SaveImageToLocalStorage(e.ChosenPhoto, Path.GetFileName(e.OriginalFileName));
}
else if (cameraOptions.DestinationType == DATA_URL)
{
- imagePathOrContent = this.GetImageContent(e.ChosenPhoto);
+ imagePathOrContent = GetImageContent(e.ChosenPhoto);
}
else