incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bows...@apache.org
Subject [17/21] android commit: Adding unsupported action plugin result return if invalid action string is specified to accel and compass listener plugins
Date Mon, 20 Feb 2012 21:01:01 GMT
Adding unsupported action plugin result return if invalid action string is specified to accel
and compass listener plugins


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/40cd7148
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/40cd7148
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/40cd7148

Branch: refs/heads/master
Commit: 40cd71484c05563eb76ca0b2c087adf713fdc338
Parents: 040619c
Author: Fil Maj <filip.maj@nitobi.com>
Authored: Wed Jan 25 14:10:22 2012 -0800
Committer: Joe Bowser <bowserj@apache.org>
Committed: Mon Feb 20 11:04:35 2012 -0800

----------------------------------------------------------------------
 .../src/org/apache/cordova/AccelListener.java      |    7 ++++-
 .../src/org/apache/cordova/CompassListener.java    |   19 ++++++++------
 2 files changed, 16 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/40cd7148/framework/src/org/apache/cordova/AccelListener.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/AccelListener.java b/framework/src/org/apache/cordova/AccelListener.java
index 6eb917f..f751e4e 100755
--- a/framework/src/org/apache/cordova/AccelListener.java
+++ b/framework/src/org/apache/cordova/AccelListener.java
@@ -148,7 +148,10 @@ public class AccelListener extends Plugin implements SensorEventListener
{
 			else if (action.equals("getTimeout")) {
 				float f = this.getTimeout();
 				return new PluginResult(status, f);
-			}
+			} else {
+        // Unsupported action
+        return new PluginResult(PluginResult.Status.INVALID_ACTION);
+      }
 			return new PluginResult(status, result);
 		} catch (JSONException e) {
 			return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
@@ -167,7 +170,7 @@ public class AccelListener extends Plugin implements SensorEventListener
{
 		}
 		else if (action.equals("getAcceleration")) {
 			// Can only return value if RUNNING
-			if (this.status == RUNNING) {
+			if (this.status == AccelListener.RUNNING) {
 				return true;
 			}
 		}

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/40cd7148/framework/src/org/apache/cordova/CompassListener.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CompassListener.java b/framework/src/org/apache/cordova/CompassListener.java
index 49f0bb8..97a8b6f 100755
--- a/framework/src/org/apache/cordova/CompassListener.java
+++ b/framework/src/org/apache/cordova/CompassListener.java
@@ -59,6 +59,7 @@ public class CompassListener extends Plugin implements SensorEventListener
{
      * Constructor.
      */
     public CompassListener() {
+        this.heading = 0.0;
         this.timeStamp = 0;
         this.setStatus(CompassListener.STOPPED);
     }
@@ -99,10 +100,10 @@ public class CompassListener extends Plugin implements SensorEventListener
{
             }
             else if (action.equals("getHeading")) {
                 // If not running, then this is an async call, so don't worry about waiting
-                if (this.status != RUNNING) {
+                if (this.status != CompassListener.RUNNING) {
                     int r = this.start();
-                    if (r == ERROR_FAILED_TO_START) {
-                        return new PluginResult(PluginResult.Status.IO_EXCEPTION, ERROR_FAILED_TO_START);
+                    if (r == CompassListener.ERROR_FAILED_TO_START) {
+                        return new PluginResult(PluginResult.Status.IO_EXCEPTION, CompassListener.ERROR_FAILED_TO_START);
                     }
                     // Wait until running
                     long timeout = 2000;
@@ -115,10 +116,9 @@ public class CompassListener extends Plugin implements SensorEventListener
{
                         }
                     }
                     if (timeout == 0) {
-                        return new PluginResult(PluginResult.Status.IO_EXCEPTION, AccelListener.ERROR_FAILED_TO_START);
                    
+                        return new PluginResult(PluginResult.Status.IO_EXCEPTION, CompassListener.ERROR_FAILED_TO_START);
                    
                     }
                 }
-                //float f = this.getHeading();
                 return new PluginResult(status, getCompassHeading());
             }
             else if (action.equals("setTimeout")) {
@@ -127,6 +127,9 @@ public class CompassListener extends Plugin implements SensorEventListener
{
             else if (action.equals("getTimeout")) {
                 long l = this.getTimeout();
                 return new PluginResult(status, l);
+            } else {
+                // Unsupported action
+                return new PluginResult(PluginResult.Status.INVALID_ACTION);
             }
             return new PluginResult(status, result);
         } catch (JSONException e) {
@@ -147,7 +150,7 @@ public class CompassListener extends Plugin implements SensorEventListener
{
         }
         else if (action.equals("getHeading")) {
             // Can only return value if RUNNING
-            if (this.status == RUNNING) {
+            if (this.status == CompassListener.RUNNING) {
                 return true;
             }
         }
@@ -180,11 +183,11 @@ public class CompassListener extends Plugin implements SensorEventListener
{
             return this.status;
         }
 
-        // Get accelerometer from sensor manager
+        // Get compass sensor from sensor manager
         List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_ORIENTATION);
 
         // If found, then register as listener
-        if (list.size() > 0) {
+        if (list != null && list.size() > 0) {
             this.mSensor = list.get(0);
             this.sensorManager.registerListener(this, this.mSensor, SensorManager.SENSOR_DELAY_NORMAL);
             this.lastAccessTime = System.currentTimeMillis();


Mime
View raw message