incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject [3/10] git commit: changed over CompassConstants -> CompassError, added a proper CompassError obj, tweaking CompassHeading constructor, added fail wrappers to compass, set a default quality level for camera.getPicture.
Date Sat, 03 Mar 2012 19:33:07 GMT
changed over CompassConstants -> CompassError, added a proper CompassError obj, tweaking
CompassHeading constructor, added fail wrappers to compass, set a default quality level for
camera.getPicture.


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

Branch: refs/heads/master
Commit: d156df99b4104e349ddbee0d877ebff6b45c0f0e
Parents: acef6ab
Author: Fil Maj <maj.fil@gmail.com>
Authored: Sat Mar 3 11:02:21 2012 -0800
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Sat Mar 3 11:02:21 2012 -0800

----------------------------------------------------------------------
 README.md                      |    9 +--------
 lib/platform/common.js         |    2 +-
 lib/plugin/Camera.js           |    4 +++-
 lib/plugin/CompassConstants.js |    4 ----
 lib/plugin/CompassError.js     |   17 +++++++++++++++++
 lib/plugin/CompassHeading.js   |   10 +++++-----
 lib/plugin/compass.js          |   30 ++++++++++++++++++------------
 7 files changed, 45 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/d156df99/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index c582678..45dffe9 100644
--- a/README.md
+++ b/README.md
@@ -212,26 +212,19 @@ Use the cordova.proto platform in ripple.
   However, Compass requires that JS initiates a `start`. This is dumb.
 - Media (and other plugin) implementations across platforms need to use the established
   cordova/exec callback method (instead of triggering globally-accessible functions to 
-  dispatch listeners). On iOS and Android, grep for "cast" in the native
+  dispatch listeners). On iOS, grep for "cast" in the native
   code - you'll see a bunch of invoked JavaScript from native, which
   shouldn't be there.
 - Media needs updates across all platforms. Methods need fixing with
   respect to timing: some methods use milliseconds, some use seconds.
   Some methods not documented (setVolume on Android). Consolidate /
   implement properly across platforms.
-- Storage shim on Android needs to change its win/fail callbacks to
-  `require('cordova/plugin/android/storage').failQuery / completeQuery`
-  (away from droiddb.fail / completeQuery)
 - Normalize `Entry.toURL` return values. iOS returns `"file://localhost" +
   fullPath`, Android returns `"file://" + fullPath`, BlackBerry returns just `fullPath`
 - APIs that are not cross-platform - what
   to do with these?
   - Crypto on Android
   - SMS, telephony, splashscreen on iOS
-- Need to normalize native return values as much as possible across
-  platforms. For example, error objects. Should we return JSON objects
-  from native or minimal primitives (i.e. error codes as numbers)? Both
-  are in use today, we need to decide on a standard.
 - Once-over all of the cordova-docs with the APIs defined in here to
   make sure all is consistent. There were function signature tweaks,
   undocumented procedures, etc.

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/d156df99/lib/platform/common.js
----------------------------------------------------------------------
diff --git a/lib/platform/common.js b/lib/platform/common.js
index 3942b6c..e07bf03 100644
--- a/lib/platform/common.js
+++ b/lib/platform/common.js
@@ -69,7 +69,7 @@ module.exports = {
             path: 'cordova/plugin/CompassHeading'
         },
         CompassError:{
-            path: 'cordova/plugin/CompassConstants'
+            path: 'cordova/plugin/CompassError'
         },
         ConfigurationData: {
             path: 'cordova/plugin/ConfigurationData'

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/d156df99/lib/plugin/Camera.js
----------------------------------------------------------------------
diff --git a/lib/plugin/Camera.js b/lib/plugin/Camera.js
index 5aa8025..05eaac2 100644
--- a/lib/plugin/Camera.js
+++ b/lib/plugin/Camera.js
@@ -31,7 +31,7 @@ cameraExport.getPicture = function(successCallback, errorCallback, options)
{
         return;
     }
 
-
+    var quality = 50;
     if (options && typeof options.quality == "number") {
         quality = options.quality;
     } else if (options && typeof options.quality == "string") {
@@ -75,6 +75,8 @@ cameraExport.getPicture = function(successCallback, errorCallback, options)
{
     if (typeof options.encodingType == "number") {
         encodingType = options.encodingType;
     }
+    // TODO: parse MediaType
+    // TODO: enable allow edit?
 
     exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType,
sourceType, targetWidth, targetHeight, encodingType]);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/d156df99/lib/plugin/CompassConstants.js
----------------------------------------------------------------------
diff --git a/lib/plugin/CompassConstants.js b/lib/plugin/CompassConstants.js
deleted file mode 100644
index bf23156..0000000
--- a/lib/plugin/CompassConstants.js
+++ /dev/null
@@ -1,4 +0,0 @@
-module.exports = {
-  COMPASS_INTERNAL_ERR:0,
-  COMPASS_NOT_SUPPORTED:20
-};

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/d156df99/lib/plugin/CompassError.js
----------------------------------------------------------------------
diff --git a/lib/plugin/CompassError.js b/lib/plugin/CompassError.js
new file mode 100644
index 0000000..60067d2
--- /dev/null
+++ b/lib/plugin/CompassError.js
@@ -0,0 +1,17 @@
+/**
+ *  CompassError.
+ *  An error code assigned by an implementation when an error has occured
+ * @constructor
+ */
+var CompassError = function(err) {
+    this.code = (typeof err != 'undefined' ? err : null);
+};
+
+/**
+ * Error codes
+ */
+CompassError.COMPASS_INTERNAL_ERR = 0;
+CompassError.COMPASS_NOT_SUPPORTED = 20;
+
+module.exports = CompassError;
+

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/d156df99/lib/plugin/CompassHeading.js
----------------------------------------------------------------------
diff --git a/lib/plugin/CompassHeading.js b/lib/plugin/CompassHeading.js
index 839b370..f9fe5e7 100644
--- a/lib/plugin/CompassHeading.js
+++ b/lib/plugin/CompassHeading.js
@@ -1,8 +1,8 @@
-var CompassHeading = function() {
-  this.magneticHeading = null;
-  this.trueHeading = null;
-  this.headingAccuracy = null;
-  this.timestamp = new Date();
+var CompassHeading = function(magneticHeading, trueHeading, headingAccuracy, timestamp) {
+  this.magneticHeading = magneticHeading || null;
+  this.trueHeading = trueHeading || null;
+  this.headingAccuracy = headingAccuracy || null;
+  this.timestamp = (timestamp ? new Date(timestamp) : new Date());
 };
 
 module.exports = CompassHeading;

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/d156df99/lib/plugin/compass.js
----------------------------------------------------------------------
diff --git a/lib/plugin/compass.js b/lib/plugin/compass.js
index bd93582..3e6049c 100644
--- a/lib/plugin/compass.js
+++ b/lib/plugin/compass.js
@@ -1,5 +1,7 @@
 var exec = require('cordova/exec'),
     utils = require('cordova/utils'),
+    CompassHeading = require('cordova/plugin/CompassHeading'),
+    CompassError = require('cordova/plugin/CompassError'),
     timers = {},
     compass = {
         /**
@@ -24,15 +26,16 @@ var exec = require('cordova/exec'),
             }
 
             var win = function(result) {
-                if (result.timestamp) {
-                    var timestamp = new Date(result.timestamp);
-                    result.timestamp = timestamp;
-                }
-                successCallback(result);   
+                var ch = new CompassHeading(result.magneticHeading, result.trueHeading, result.headingAccuracy,
result.timestamp);
+                successCallback(ch);
             };
+            var fail = function(code) {
+                var ce = new CompassError(code);
+                errorCallback(ce);
+            }
             
             // Get heading
-            exec(win, errorCallback, "Compass", "getHeading", []);
+            exec(win, fail, "Compass", "getHeading", []);
         },
 
         /**
@@ -63,14 +66,16 @@ var exec = require('cordova/exec'),
             // Start watch timer to get headings
             var id = utils.createUUID();
             var win = function(result) {
-                if (result.timestamp) {
-                    var timestamp = new Date(result.timestamp);
-                    result.timestamp = timestamp;
-                }
-                successCallback(result);   
+                var ch = new CompassHeading(result.magneticHeading, result.trueHeading, result.headingAccuracy,
result.timestamp);
+                successCallback(ch);
+            };
+            var fail = function(code) {
+                var ce = new CompassError(code);
+                errorCallback(ce);
             };
+
             timers[id] = window.setInterval(function() {
-                 exec(win, errorCallback, "Compass", "getHeading", []);
+                 exec(win, fail, "Compass", "getHeading", []);
             }, frequency);
 
             return id;
@@ -87,6 +92,7 @@ var exec = require('cordova/exec'),
               delete timers[id];
             }
         }
+        // TODO: add the filter-based iOS-only methods
     };
 
 module.exports = compass;


Mime
View raw message