You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ma...@apache.org on 2019/03/01 19:00:45 UTC
[cordova-plugin-camera] branch master updated: AAR-232: (android)
Enhancement: Camera plugin code cleanup (#425)
This is an automated email from the ASF dual-hosted git repository.
macdonst pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-plugin-camera.git
The following commit(s) were added to refs/heads/master by this push:
new a13665d AAR-232: (android) Enhancement: Camera plugin code cleanup (#425)
a13665d is described below
commit a13665d530f24a667a17d2a3bc61296fc316d3d2
Author: Hazem Saleh <ha...@apache.org>
AuthorDate: Fri Mar 1 14:00:39 2019 -0500
AAR-232: (android) Enhancement: Camera plugin code cleanup (#425)
---
src/android/CameraLauncher.java | 104 +++++++++++++++++++---------------------
1 file changed, 49 insertions(+), 55 deletions(-)
diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java
index 6cdf0c5..b133340 100644
--- a/src/android/CameraLauncher.java
+++ b/src/android/CameraLauncher.java
@@ -18,34 +18,13 @@
*/
package org.apache.cordova.camera;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import org.apache.cordova.BuildHelper;
-import org.apache.cordova.CallbackContext;
-import org.apache.cordova.CordovaPlugin;
-import org.apache.cordova.CordovaResourceApi;
-import org.apache.cordova.LOG;
-import org.apache.cordova.PermissionHelper;
-import org.apache.cordova.PluginResult;
-import org.json.JSONArray;
-import org.json.JSONException;
-
import android.Manifest;
-import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ContentValues;
-import android.content.Context;
import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
@@ -55,16 +34,31 @@ import android.media.ExifInterface;
import android.media.MediaScannerConnection;
import android.media.MediaScannerConnection.MediaScannerConnectionClient;
import android.net.Uri;
-import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
-import android.provider.DocumentsContract;
import android.provider.MediaStore;
-import android.provider.OpenableColumns;
import android.support.v4.content.FileProvider;
import android.util.Base64;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
+
+import org.apache.cordova.BuildHelper;
+import org.apache.cordova.CallbackContext;
+import org.apache.cordova.CordovaPlugin;
+import org.apache.cordova.LOG;
+import org.apache.cordova.PermissionHelper;
+import org.apache.cordova.PluginResult;
+import org.json.JSONArray;
+import org.json.JSONException;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.text.SimpleDateFormat;
+import java.util.Date;
/**
* This class launches the camera view, allows the user to take a picture, closes the camera view,
@@ -87,13 +81,19 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
private static final int JPEG = 0; // Take a picture of type JPEG
private static final int PNG = 1; // Take a picture of type PNG
- private static final String JPEG_EXTENSION = ".jpg";
- private static final String PNG_EXTENSION = ".png";
+ private static final String JPEG_TYPE = "jpg";
+ private static final String PNG_TYPE = "png";
+ private static final String JPEG_EXTENSION = "." + JPEG_TYPE;
+ private static final String PNG_EXTENSION = "." + PNG_TYPE;
private static final String PNG_MIME_TYPE = "image/png";
private static final String JPEG_MIME_TYPE = "image/jpeg";
private static final String GET_PICTURE = "Get Picture";
private static final String GET_VIDEO = "Get Video";
private static final String GET_All = "Get All";
+ private static final String CROPPED_URI_KEY = "croppedUri";
+ private static final String IMAGE_URI_KEY = "imageUri";
+
+ private static final String TAKE_PICTURE_ACTION = "takePicture";
public static final int PERMISSION_DENIED_ERROR = 20;
public static final int TAKE_PIC_SEC = 0;
@@ -147,7 +147,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
this.applicationId = preferences.getString("applicationId", this.applicationId);
- if (action.equals("takePicture")) {
+ if (action.equals(TAKE_PICTURE_ACTION)) {
this.srcType = CAMERA;
this.destType = FILE_URI;
this.saveToPhotoAlbum = false;
@@ -312,7 +312,6 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
PackageManager mPm = this.cordova.getActivity().getPackageManager();
if(intent.resolveActivity(mPm) != null)
{
-
this.cordova.startActivityForResult((CordovaPlugin) this, intent, (CAMERA + 1) * 16 + returnType + 1);
}
else
@@ -358,7 +357,6 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
}
-
/**
* Get image from photo library.
*
@@ -640,7 +638,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
// Get filename from uri
String fileName = realPath != null ?
realPath.substring(realPath.lastIndexOf('/') + 1) :
- "modified." + (this.encodingType == JPEG ? "jpg" : "png");
+ "modified." + (this.encodingType == JPEG ? JPEG_TYPE : PNG_TYPE);
String timeStamp = new SimpleDateFormat(TIME_FORMAT).format(new Date());
//String fileName = "IMG_" + timeStamp + (this.encodingType == JPEG ? ".jpg" : ".png");
@@ -1348,11 +1346,11 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
state.putBoolean("saveToPhotoAlbum", this.saveToPhotoAlbum);
if (this.croppedUri != null) {
- state.putString("croppedUri", this.croppedUri.toString());
+ state.putString(CROPPED_URI_KEY, this.croppedUri.toString());
}
if (this.imageUri != null) {
- state.putString("imageUri", this.imageUri.getFileUri().toString());
+ state.putString(IMAGE_URI_KEY, this.imageUri.getFileUri().toString());
}
return state;
@@ -1371,38 +1369,34 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
this.correctOrientation = state.getBoolean("correctOrientation");
this.saveToPhotoAlbum = state.getBoolean("saveToPhotoAlbum");
- if (state.containsKey("croppedUri")) {
- this.croppedUri = Uri.parse(state.getString("croppedUri"));
+ if (state.containsKey(CROPPED_URI_KEY)) {
+ this.croppedUri = Uri.parse(state.getString(CROPPED_URI_KEY));
}
- if (state.containsKey("imageUri")) {
+ if (state.containsKey(IMAGE_URI_KEY)) {
//I have no idea what type of URI is being passed in
- this.imageUri = new CordovaUri(Uri.parse(state.getString("imageUri")));
+ this.imageUri = new CordovaUri(Uri.parse(state.getString(IMAGE_URI_KEY)));
}
this.callbackContext = callbackContext;
}
- /*
- * This is dirty, but it does the job.
- *
- * Since the FilesProvider doesn't really provide you a way of getting a URL from the file,
- * and since we actually need the Camera to create the file for us most of the time, we don't
- * actually write the file, just generate the location based on a timestamp, we need to get it
- * back from the Intent.
- *
- * However, the FilesProvider preserves the path, so we can at least write to it from here, since
- * we own the context in this case.
- */
-
+ /*
+ * This is dirty, but it does the job.
+ *
+ * Since the FilesProvider doesn't really provide you a way of getting a URL from the file,
+ * and since we actually need the Camera to create the file for us most of the time, we don't
+ * actually write the file, just generate the location based on a timestamp, we need to get it
+ * back from the Intent.
+ *
+ * However, the FilesProvider preserves the path, so we can at least write to it from here, since
+ * we own the context in this case.
+ */
private String getFileNameFromUri(Uri uri) {
String fullUri = uri.toString();
String partial_path = fullUri.split("external_files")[1];
File external_storage = Environment.getExternalStorageDirectory();
String path = external_storage.getAbsolutePath() + partial_path;
return path;
-
}
-
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org