Skip to content

Commit

Permalink
Adding unsupported action plugin result return if invalid action stri…
Browse files Browse the repository at this point in the history
…ng is specified to accel and compass listener plugins
  • Loading branch information
Fil Maj authored and infil00p committed Feb 20, 2012
1 parent 040619c commit 40cd714
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
7 changes: 5 additions & 2 deletions framework/src/org/apache/cordova/AccelListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ else if (action.equals("setTimeout")) {
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);
Expand All @@ -167,7 +170,7 @@ public boolean isSynch(String action) {
}
else if (action.equals("getAcceleration")) {
// Can only return value if RUNNING
if (this.status == RUNNING) {
if (this.status == AccelListener.RUNNING) {
return true;
}
}
Expand Down
19 changes: 11 additions & 8 deletions framework/src/org/apache/cordova/CompassListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -99,10 +100,10 @@ else if (action.equals("getStatus")) {
}
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;
Expand All @@ -115,10 +116,9 @@ else if (action.equals("getHeading")) {
}
}
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")) {
Expand All @@ -127,6 +127,9 @@ else if (action.equals("setTimeout")) {
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) {
Expand All @@ -147,7 +150,7 @@ public boolean isSynch(String action) {
}
else if (action.equals("getHeading")) {
// Can only return value if RUNNING
if (this.status == RUNNING) {
if (this.status == CompassListener.RUNNING) {
return true;
}
}
Expand Down Expand Up @@ -180,11 +183,11 @@ public int start() {
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();
Expand Down

0 comments on commit 40cd714

Please sign in to comment.