You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ia...@apache.org on 2014/04/23 20:57:45 UTC
[12/14] git commit: CB-6152: Make mediafile compatible with file
plugin
CB-6152: Make mediafile compatible with file plugin
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/commit/bb9fb051
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/tree/bb9fb051
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/diff/bb9fb051
Branch: refs/heads/master
Commit: bb9fb051223aa8cb52c5f6eed5b07d8722d162fb
Parents: 3419111
Author: Ian Clelland <ic...@chromium.org>
Authored: Tue Apr 15 15:25:20 2014 -0400
Committer: Ian Clelland <ic...@chromium.org>
Committed: Tue Apr 15 15:25:20 2014 -0400
----------------------------------------------------------------------
src/android/Capture.java | 18 ++++++++++--------
src/ios/CDVCapture.m | 13 +++++++++++++
www/MediaFile.js | 4 ++--
www/capture.js | 3 +++
4 files changed, 28 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/blob/bb9fb051/src/android/Capture.java
----------------------------------------------------------------------
diff --git a/src/android/Capture.java b/src/android/Capture.java
index a24511e..65df61f 100644
--- a/src/android/Capture.java
+++ b/src/android/Capture.java
@@ -25,6 +25,9 @@ import java.io.OutputStream;
import android.os.Build;
+import org.apache.cordova.file.FileUtils;
+import org.apache.cordova.file.LocalFilesystemURL;
+
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.LOG;
@@ -201,15 +204,8 @@ public class Capture extends CordovaPlugin {
private String getTempDirectoryPath() {
File cache = null;
- // SD Card Mounted
- if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
- cache = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +
- "/Android/data/" + cordova.getActivity().getPackageName() + "/cache/");
- }
// Use internal storage
- else {
- cache = cordova.getActivity().getCacheDir();
- }
+ cache = cordova.getActivity().getCacheDir();
// Create the cache directory if it doesn't exist
cache.mkdirs();
@@ -416,10 +412,16 @@ public class Capture extends CordovaPlugin {
File fp = webView.getResourceApi().mapUriToFile(data);
JSONObject obj = new JSONObject();
+ FileUtils filePlugin = (FileUtils)webView.pluginManager.getPlugin("File");
+ LocalFilesystemURL url = filePlugin.filesystemURLforLocalPath(fp.getAbsolutePath());
+
try {
// File properties
obj.put("name", fp.getName());
obj.put("fullPath", fp.toURI().toString());
+ if (url != null) {
+ obj.put("localURL", url.toString());
+ }
// Because of an issue with MimeTypeMap.getMimeTypeFromExtension() all .3gpp files
// are reported as video/3gpp. I'm doing this hacky check of the URI to see if it
// is stored in the audio or video content store.
http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/blob/bb9fb051/src/ios/CDVCapture.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVCapture.m b/src/ios/CDVCapture.m
index aaa5d54..6bcf0ad 100644
--- a/src/ios/CDVCapture.m
+++ b/src/ios/CDVCapture.m
@@ -18,6 +18,7 @@
*/
#import "CDVCapture.h"
+#import "CDVFile.h"
#import <Cordova/CDVJSON.h>
#import <Cordova/CDVAvailability.h>
@@ -452,8 +453,20 @@
NSFileManager* fileMgr = [[NSFileManager alloc] init];
NSMutableDictionary* fileDict = [NSMutableDictionary dictionaryWithCapacity:5];
+ CDVFile *fs = [self.commandDelegate getCommandInstance:@"File"];
+
+ // Get canonical version of localPath
+ NSURL *fileURL = [NSURL URLWithString:[NSString stringWithFormat:@"file://%@", fullPath]];
+ NSURL *resolvedFileURL = [fileURL URLByResolvingSymlinksInPath];
+ NSString *path = [resolvedFileURL path];
+
+ CDVFilesystemURL *url = [fs fileSystemURLforLocalPath:path];
+
[fileDict setObject:[fullPath lastPathComponent] forKey:@"name"];
[fileDict setObject:fullPath forKey:@"fullPath"];
+ if (url) {
+ [fileDict setObject:[url absoluteURL] forKey:@"localURL"];
+ }
// determine type
if (!type) {
id command = [self.commandDelegate getCommandInstance:@"File"];
http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/blob/bb9fb051/www/MediaFile.js
----------------------------------------------------------------------
diff --git a/www/MediaFile.js b/www/MediaFile.js
index 75a255b..17f12ef 100644
--- a/www/MediaFile.js
+++ b/www/MediaFile.js
@@ -32,7 +32,7 @@ var utils = require('cordova/utils'),
* lastModifiedDate {Date} last modified date
* size {Number} size of the file in bytes
*/
-var MediaFile = function(name, fullPath, type, lastModifiedDate, size){
+var MediaFile = function(name, localURL, type, lastModifiedDate, size){
MediaFile.__super__.constructor.apply(this, arguments);
};
@@ -48,7 +48,7 @@ MediaFile.prototype.getFormatData = function(successCallback, errorCallback) {
if (typeof this.fullPath === "undefined" || this.fullPath === null) {
errorCallback(new CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
} else {
- exec(successCallback, errorCallback, "Capture", "getFormatData", [this.fullPath, this.type]);
+ exec(successCallback, errorCallback, "Capture", "getFormatData", [this.localURL, this.type]);
}
};
http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/blob/bb9fb051/www/capture.js
----------------------------------------------------------------------
diff --git a/www/capture.js b/www/capture.js
index 6b67ca8..fd17474 100644
--- a/www/capture.js
+++ b/www/capture.js
@@ -37,6 +37,9 @@ function _capture(type, successCallback, errorCallback, options) {
for (i = 0; i < pluginResult.length; i++) {
var mediaFile = new MediaFile();
mediaFile.name = pluginResult[i].name;
+
+ // Backwards compatibility
+ mediaFile.localURL = pluginResult[i].localURL || pluginResult[i].fullPath;
mediaFile.fullPath = pluginResult[i].fullPath;
mediaFile.type = pluginResult[i].type;
mediaFile.lastModifiedDate = pluginResult[i].lastModifiedDate;