CB-11625: Managed to get Content Providers to work with a weird mix of Content Providers and non-Content Providers

This commit is contained in:
Joe Bowser 2016-08-03 14:43:11 -07:00
parent b62fdf50f7
commit 00e0a7dc46

View File

@ -33,12 +33,13 @@ import java.util.Date;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaResourceApi;
import org.apache.cordova.CoreAndroid;
import org.apache.cordova.LOG;
import org.apache.cordova.PermissionHelper;
import org.apache.cordova.PluginResult;
import org.apache.mobilespec.BuildConfig;
import org.json.JSONArray;
import org.json.JSONException;
import org.apache.cordova.Api24Camera.BuildConfig;
import android.Manifest;
import android.app.Activity;
@ -120,6 +121,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
private MediaScannerConnection conn; // Used to update gallery app with newly-written files
private Uri scanMe; // Uri of image to be added to content store
private Uri croppedUri;
private String applicationId;
/**
@ -132,6 +134,10 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
*/
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
this.callbackContext = callbackContext;
//Adding an API to CoreAndroid to get the BuildConfigValue
//This allows us to not make this a breaking change to embedding
this.applicationId = (String) CoreAndroid.getBuildConfigValue(cordova.getActivity(), "APPLICATION_ID");
if (action.equals("takePicture")) {
this.srcType = CAMERA;
@ -233,8 +239,8 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
* or to display URI in an img tag
* img.src=result;
*
* @param quality Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
* @param returnType Set the type of image to return.
* @param encodingType Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
*/
public void callTakePicture(int returnType, int encodingType) {
boolean saveAlbumPermission = PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
@ -285,7 +291,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
// Specify file so that large image is captured and returned
File photo = createCaptureFile(encodingType);
this.imageUri = FileProvider.getUriForFile(cordova.getActivity(),
BuildConfig.APPLICATION_ID + ".provider",
applicationId + ".provider",
photo);
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, this.imageUri);
//We can write to this URI, this will hopefully allow us to write files to get to the next step
@ -346,7 +352,6 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
/**
* Get image from photo library.
*
* @param quality Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
* @param srcType The album to get image from.
* @param returnType Set the type of image to return.
* @param encodingType
@ -405,37 +410,39 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
*/
private void performCrop(Uri picUri, int destType, Intent cameraIntent) {
try {
Intent cropIntent = new Intent("com.android.camera.action.CROP");
// indicate image type and Uri
cropIntent.setDataAndType(picUri, "image/*");
// set crop properties
cropIntent.putExtra("crop", "true");
Intent cropIntent = new Intent("com.android.camera.action.CROP");
// indicate image type and Uri
cropIntent.setDataAndType(picUri, "image/*");
// set crop properties
cropIntent.putExtra("crop", "true");
// indicate output X and Y
if (targetWidth > 0) {
// indicate output X and Y
if (targetWidth > 0) {
cropIntent.putExtra("outputX", targetWidth);
}
if (targetHeight > 0) {
}
if (targetHeight > 0) {
cropIntent.putExtra("outputY", targetHeight);
}
if (targetHeight > 0 && targetWidth > 0 && targetWidth == targetHeight) {
}
if (targetHeight > 0 && targetWidth > 0 && targetWidth == targetHeight) {
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
}
// create new file handle to get full resolution crop
croppedUri = FileProvider.getUriForFile(cordova.getActivity(),
BuildConfig.APPLICATION_ID + ".provider",
createCaptureFile(this.encodingType, System.currentTimeMillis() + ""));
cropIntent.putExtra("output", croppedUri);
}
// create new file handle to get full resolution crop
croppedUri = Uri.fromFile(createCaptureFile(this.encodingType, System.currentTimeMillis() + ""));
cropIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
cropIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
cropIntent.putExtra("output", croppedUri);
// start the activity - we handle returning in onActivityResult
if (this.cordova != null) {
this.cordova.startActivityForResult((CordovaPlugin) this,
cropIntent, CROP_CAMERA + destType);
}
// start the activity - we handle returning in onActivityResult
if (this.cordova != null) {
this.cordova.startActivityForResult((CordovaPlugin) this,
cropIntent, CROP_CAMERA + destType);
}
} catch (ActivityNotFoundException anfe) {
Log.e(LOG_TAG, "Crop operation not supported on this device");
Log.e(LOG_TAG, "Crop operation not supported on this device");
try {
processResultFromCamera(destType, cameraIntent);
}
@ -460,7 +467,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
ExifHelper exif = new ExifHelper();
String sourcePath = (this.allowEdit && this.croppedUri != null) ?
getFileNameFromUri(this.croppedUri) :
FileHelper.stripFileProtocol(this.croppedUri.toString()) :
getFileNameFromUri(this.imageUri);
@ -487,7 +494,6 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
if (this.allowEdit && this.croppedUri != null) {
Uri croppedUri = Uri.fromFile(new File(getFileNameFromUri(this.croppedUri)));
writeUncompressedImage(croppedUri, galleryUri);
} else {
Uri imageUri = Uri.fromFile(new File(getFileNameFromUri(this.imageUri)));
@ -791,7 +797,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
try {
if (this.allowEdit) {
Uri tmpFile = FileProvider.getUriForFile(cordova.getActivity(),
BuildConfig.APPLICATION_ID + ".provider",
applicationId + ".provider",
createCaptureFile(this.encodingType));
performCrop(tmpFile, destType, intent);
} else {
@ -881,7 +887,8 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
* In the special case where the default width, height and quality are unchanged
* we just write the file out to disk saving the expensive Bitmap.compress function.
*
* @param uri
* @param src
* @param dest
* @throws FileNotFoundException
* @throws IOException
*/