Repository: cordova-plugin-camera
Updated Branches:
  refs/heads/master e8fa1695c -> e2193631d


CB-9189 android: Implementing save/restore API to handle Activity destruction


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/e2193631
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/e2193631
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/e2193631

Branch: refs/heads/master
Commit: e2193631d552bc8ad97cb0ce69413bc85dc6c821
Parents: e8fa169
Author: riknoll <richard.b.kn...@gmail.com>
Authored: Fri Dec 4 11:34:28 2015 -0800
Committer: Richard Knoll <richard.b.kn...@gmail.com>
Committed: Tue Jan 5 14:18:43 2016 -0800

----------------------------------------------------------------------
 README.md                       |  7 ++++-
 jsdoc2md/TEMPLATE.md            |  7 ++++-
 src/android/CameraLauncher.java | 56 +++++++++++++++++++++++++++++++++++-
 3 files changed, 67 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/e2193631/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 8060af9..700722b 100644
--- a/README.md
+++ b/README.md
@@ -400,7 +400,12 @@ scenario, the image may not appear when the cordova 
activity is restored.
 
 Android uses intents to launch the camera activity on the device to capture
 images, and on phones with low memory, the Cordova activity may be killed.  In 
this
-scenario, the image may not appear when the Cordova activity is restored.
+scenario, the result from the plugin call will be delivered via the resume 
event.
+See [the Android Lifecycle 
guide](http://cordova.apache.org/docs/en/dev/guide/platforms/android/lifecycle.html)
+for more information. The `pendingResult.result` value will contain the value 
that
+would be passed to the callbacks (either the URI/URL or an error message). 
Check
+the `pendingResult.pluginStatus` to determine whether or not the call was
+successful.
 
 #### Browser Quirks
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/e2193631/jsdoc2md/TEMPLATE.md
----------------------------------------------------------------------
diff --git a/jsdoc2md/TEMPLATE.md b/jsdoc2md/TEMPLATE.md
index d068748..39f06ba 100644
--- a/jsdoc2md/TEMPLATE.md
+++ b/jsdoc2md/TEMPLATE.md
@@ -77,7 +77,12 @@ scenario, the image may not appear when the cordova activity 
is restored.
 
 Android uses intents to launch the camera activity on the device to capture
 images, and on phones with low memory, the Cordova activity may be killed.  In 
this
-scenario, the image may not appear when the Cordova activity is restored.
+scenario, the result from the plugin call will be delivered via the resume 
event.
+See [the Android Lifecycle 
guide](http://cordova.apache.org/docs/en/dev/guide/platforms/android/lifecycle.html)
+for more information. The `pendingResult.result` value will contain the value 
that
+would be passed to the callbacks (either the URI/URL or an error message). 
Check
+the `pendingResult.pluginStatus` to determine whether or not the call was
+successful.
 
 #### Browser Quirks
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/e2193631/src/android/CameraLauncher.java
----------------------------------------------------------------------
diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java
index d45d43b..ff8599b 100644
--- a/src/android/CameraLauncher.java
+++ b/src/android/CameraLauncher.java
@@ -503,7 +503,7 @@ public class CameraLauncher extends CordovaPlugin 
implements MediaScannerConnect
                     } else {
                         writeUncompressedImage(this.imageUri, uri);
                     }
-                    
+
                     this.callbackContext.success(uri.toString());
                 }
             } else {
@@ -1214,4 +1214,58 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri 
uri) throws IOException {
         return (this.targetWidth > 0 && this.targetHeight > 0) ||
                     this.correctOrientation || this.allowEdit;
     }
+
+    /**
+     * Taking or choosing a picture launches another Activity, so we need to 
implement the
+     * save/restore APIs to handle the case where the CordovaActivity is 
killed by the OS
+     * before we get the launched Activity's result.
+     */
+    public Bundle onSaveInstanceState() {
+        Bundle state = new Bundle();
+        state.putInt("destType", this.destType);
+        state.putInt("srcType", this.srcType);
+        state.putInt("mQuality", this.mQuality);
+        state.putInt("targetWidth", this.targetWidth);
+        state.putInt("targetHeight", this.targetHeight);
+        state.putInt("encodingType", this.encodingType);
+        state.putInt("mediaType", this.mediaType);
+        state.putInt("numPics", this.numPics);
+        state.putBoolean("allowEdit", this.allowEdit);
+        state.putBoolean("correctOrientation", this.correctOrientation);
+        state.putBoolean("saveToPhotoAlbum", this.saveToPhotoAlbum);
+
+        if(this.croppedUri != null) {
+            state.putString("croppedUri", this.croppedUri.toString());
+        }
+
+        if(this.imageUri != null) {
+            state.putString("imageUri", this.imageUri.toString());
+        }
+
+        return state;
+    }
+
+    public void onRestoreStateForActivityResult(Bundle state, CallbackContext 
callbackContext) {
+        this.destType = state.getInt("destType");
+        this.srcType = state.getInt("srcType");
+        this.mQuality = state.getInt("mQuality");
+        this.targetWidth = state.getInt("targetWidth");
+        this.targetHeight = state.getInt("targetHeight");
+        this.encodingType = state.getInt("encodingType");
+        this.mediaType = state.getInt("mediaType");
+        this.numPics = state.getInt("numPics");
+        this.allowEdit = state.getBoolean("allowEdit");
+        this.correctOrientation = state.getBoolean("correctOrientation");
+        this.saveToPhotoAlbum = state.getBoolean("saveToPhotoAlbum");
+
+        if(state.containsKey("croppedUri")) {
+            this.croppedUri = Uri.parse(state.getString("croppedUri"));
+        }
+
+        if(state.containsKey("imageUri")) {
+            this.imageUri = Uri.parse(state.getString("imageUri"));
+        }
+
+        this.callbackContext = callbackContext;
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org
For additional commands, e-mail: commits-h...@cordova.apache.org

Reply via email to