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

This commit is contained in:
riknoll
2015-12-04 11:34:28 -08:00
committed by Richard Knoll
parent e8fa1695c4
commit e2193631d5
3 changed files with 67 additions and 3 deletions
+55 -1
View File
@@ -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;
}
}