You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2016/12/08 00:56:29 UTC

[07/25] cordova-plugin-camera git commit: Merging API 24 code with master including large refactor

Merging API 24 code with master including large refactor


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

Branch: refs/heads/2.3.x
Commit: b63a0d83e05b81deb09429776e621f0a713af43f
Parents: 9fe9447 3ed3d88
Author: Joe Bowser <bo...@apache.org>
Authored: Thu Sep 1 15:11:33 2016 -0700
Committer: Joe Bowser <bo...@apache.org>
Committed: Thu Sep 1 15:11:33 2016 -0700

----------------------------------------------------------------------
 plugin.xml                         |  18 ++-
 src/android/CameraLauncher.java    | 199 +++++++++++++++++++-------------
 src/android/xml/provider_paths.xml |   4 +
 3 files changed, 141 insertions(+), 80 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/b63a0d83/plugin.xml
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/b63a0d83/src/android/CameraLauncher.java
----------------------------------------------------------------------
diff --cc src/android/CameraLauncher.java
index 69cb5db,8abdc39..c68462d
--- a/src/android/CameraLauncher.java
+++ b/src/android/CameraLauncher.java
@@@ -56,11 -56,14 +58,13 @@@ 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.util.Log;
  import android.content.pm.PackageManager;
  import android.content.pm.PackageManager.NameNotFoundException;
 -import android.content.pm.PermissionInfo;
  
  /**
   * This class launches the camera view, allows the user to take a picture, closes the camera view,
@@@ -117,7 -120,7 +121,8 @@@ public class CameraLauncher extends Cor
      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 ExifHelper exifData;            // Exif data from source
+     private String applicationId;
  
  
      /**
@@@ -399,35 -409,39 +412,39 @@@
     */
    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");
- 
-       // indicate output X and Y
-       if (targetWidth > 0) {
+         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) {
            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 = Uri.fromFile(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);
        }
@@@ -475,10 -491,12 +494,11 @@@
          if (this.saveToPhotoAlbum) {
              galleryUri = Uri.fromFile(new File(getPicturesPath()));
  
-             if(this.allowEdit && this.croppedUri != null) {
-                 writeUncompressedImage(this.croppedUri, galleryUri);
 -
+             if (this.allowEdit && this.croppedUri != null) {
+                 writeUncompressedImage(croppedUri, galleryUri);
              } else {
-                 writeUncompressedImage(this.imageUri, galleryUri);
+                 Uri imageUri = Uri.fromFile(new File(getFileNameFromUri(this.imageUri)));
+                 writeUncompressedImage(imageUri, galleryUri);
              }
  
              refreshGallery(galleryUri);
@@@ -587,23 -611,16 +607,30 @@@
          this.cordova.getActivity().sendBroadcast(mediaScanIntent);
      }
  
 +    /**
 +     * Converts output image format int value to string value of mime type.
 +     * @param outputFormat int Output format of camera API.
 +     *                     Must be value of either JPEG or PNG constant
 +     * @return String String value of mime type or empty string if mime type is not supported
 +     */
 +    private String getMimetypeForFormat(int outputFormat) {
 +        if (outputFormat == PNG) return "image/png";
 +        if (outputFormat == JPEG) return "image/jpeg";
 +        return "";
 +    }
  
 -    private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
 +
 +    private String outputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
+         // Some content: URIs do not map to file paths (e.g. picasa).
+         String realPath = FileHelper.getRealPath(uri, this.cordova);
+ 
+         // Get filename from uri
+         String fileName = realPath != null ?
+                 realPath.substring(realPath.lastIndexOf('/') + 1) :
+                 "modified." + (this.encodingType == JPEG ? "jpg" : "png");
  
 +        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
-         String fileName = "IMG_" + timeStamp + (this.encodingType == JPEG ? ".jpg" : ".png");
++        //String fileName = "IMG_" + timeStamp + (this.encodingType == JPEG ? ".jpg" : ".png");
          String modifiedPath = getTempDirectoryPath() + "/" + fileName;
  
          OutputStream os = new FileOutputStream(modifiedPath);
@@@ -1347,4 -1297,26 +1368,26 @@@
  
          this.callbackContext = callbackContext;
      }
- }
+ 
 -/*
 - * This is dirty, but it does the job.
++ /*
++  * 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