You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2012/02/23 18:53:19 UTC

[26/35] git commit: Need to override File object on Android. Also casting proper File stuff from native

Need to override File object on Android. Also casting proper File stuff from native


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/9cf624a4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/9cf624a4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/9cf624a4

Branch: refs/heads/ios
Commit: 9cf624a4b8b8868008adb9d17ec67ea1ab85f955
Parents: fc8c389
Author: Fil Maj <fi...@nitobi.com>
Authored: Thu Feb 16 17:20:39 2012 -0800
Committer: Fil Maj <fi...@nitobi.com>
Committed: Thu Feb 16 17:20:39 2012 -0800

----------------------------------------------------------------------
 lib/platform/android.js      |    3 +++
 lib/plugin/DirectoryEntry.js |   14 ++++++++++++--
 lib/plugin/FileEntry.js      |    8 +++++++-
 3 files changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/9cf624a4/lib/platform/android.js
----------------------------------------------------------------------
diff --git a/lib/platform/android.js b/lib/platform/android.js
index 498c219..3556306 100644
--- a/lib/platform/android.js
+++ b/lib/platform/android.js
@@ -116,6 +116,9 @@ module.exports = {
     },
     device:{
       path: "cordova/plugin/android/device"
+    },
+    File: { // exists natively on Android WebView, override
+      path: "cordova/plugin/File"
     }
   }
 };

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/9cf624a4/lib/plugin/DirectoryEntry.js
----------------------------------------------------------------------
diff --git a/lib/plugin/DirectoryEntry.js b/lib/plugin/DirectoryEntry.js
index be011eb..dc208f6 100644
--- a/lib/plugin/DirectoryEntry.js
+++ b/lib/plugin/DirectoryEntry.js
@@ -34,7 +34,14 @@ DirectoryEntry.prototype.createReader = function() {
  * @param {Function} errorCallback is called with a FileError
  */
 DirectoryEntry.prototype.getDirectory = function(path, options, successCallback, errorCallback) {
-    exec(successCallback, errorCallback, "File", "getDirectory", [this.fullPath, path, options]);
+    var win = function(result) {
+        var entry = new DirectoryEntry(result.name, result.fullPath);
+        successCallback(entry);
+    };
+    var fail = function(code) {
+        errorCallback(new FileError(code));
+    };
+    exec(win, fail, "File", "getDirectory", [this.fullPath, path, options]);
 };
 
 /**
@@ -61,7 +68,10 @@ DirectoryEntry.prototype.getFile = function(path, options, successCallback, erro
         var entry = new FileEntry(result.name, result.fullPath);
         successCallback(entry);
     };
-    exec(win, errorCallback, "File", "getFile", [this.fullPath, path, options]);
+    var fail = function(code) {
+        errorCallback(new FileError(code));
+    };
+    exec(win, fail, "File", "getFile", [this.fullPath, path, options]);
 };
 
 module.exports = DirectoryEntry;

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/9cf624a4/lib/plugin/FileEntry.js
----------------------------------------------------------------------
diff --git a/lib/plugin/FileEntry.js b/lib/plugin/FileEntry.js
index 8079473..4bce002 100644
--- a/lib/plugin/FileEntry.js
+++ b/lib/plugin/FileEntry.js
@@ -1,6 +1,8 @@
 var utils = require('cordova/utils'),
+    exec = require('cordova/exec'),
     Entry = require('cordova/plugin/Entry'),
     FileWriter = require('cordova/plugin/FileWriter'),
+    File = require('cordova/plugin/File'),
     FileError = require('cordova/plugin/FileError');
 
 /**
@@ -47,7 +49,11 @@ FileEntry.prototype.createWriter = function(successCallback, errorCallback) {
  * @param {Function} errorCallback is called with a FileError
  */
 FileEntry.prototype.file = function(successCallback, errorCallback) {
-    exec(successCallback, errorCallback, "File", "getFileMetadata", [this.fullPath]);
+    var win = function(f) {
+        var file = new File(f.name, f.fullPath, f.type, f.lastModifiedDate, f.size);
+        successCallback(file);
+    };
+    exec(win, errorCallback, "File", "getFileMetadata", [this.fullPath]);
 };