diff --git a/framework/src/com/phonegap/AccelListener.java b/framework/src/com/phonegap/AccelListener.java index f0000849..21d7c502 100755 --- a/framework/src/com/phonegap/AccelListener.java +++ b/framework/src/com/phonegap/AccelListener.java @@ -133,6 +133,17 @@ public class AccelListener implements SensorEventListener, Plugin{ } } + /** + * Identifies if action to be executed returns a value. + * + * @param action The action to execute + * @return T=returns value + */ + public boolean hasReturnValue(String action) { + // TODO + return false; + } + /** * Called when the system is about to start resuming a previous activity. */ diff --git a/framework/src/com/phonegap/AudioHandler.java b/framework/src/com/phonegap/AudioHandler.java index 79e2349e..8b66ea1b 100755 --- a/framework/src/com/phonegap/AudioHandler.java +++ b/framework/src/com/phonegap/AudioHandler.java @@ -101,6 +101,22 @@ public class AudioHandler implements Plugin { return new PluginResult(PluginResult.Status.JSON_EXCEPTION); } } + + /** + * Identifies if action to be executed returns a value. + * + * @param action The action to execute + * @return T=returns value + */ + public boolean hasReturnValue(String action) { + if (action.equals("getCurrentPositionAudio")) { + return true; + } + else if (action.equals("getDurationAudio")) { + return true; + } + return false; + } /** * Called when the system is about to start resuming a previous activity. diff --git a/framework/src/com/phonegap/CameraLauncher.java b/framework/src/com/phonegap/CameraLauncher.java index aa838763..8e31b010 100755 --- a/framework/src/com/phonegap/CameraLauncher.java +++ b/framework/src/com/phonegap/CameraLauncher.java @@ -88,6 +88,16 @@ public class CameraLauncher implements Plugin { } } + /** + * Identifies if action to be executed returns a value. + * + * @param action The action to execute + * @return T=returns value + */ + public boolean hasReturnValue(String action) { + return false; + } + /** * Called when the system is about to start resuming a previous activity. */ diff --git a/framework/src/com/phonegap/CompassListener.java b/framework/src/com/phonegap/CompassListener.java index 35f8ad09..6820b322 100755 --- a/framework/src/com/phonegap/CompassListener.java +++ b/framework/src/com/phonegap/CompassListener.java @@ -44,7 +44,7 @@ public class CompassListener implements SensorEventListener, Plugin{ */ public CompassListener() { this.timeStamp = 0; - this.status = CompassListener.STOPPED; + this.setStatus(CompassListener.STOPPED); } /** @@ -91,6 +91,21 @@ public class CompassListener implements SensorEventListener, Plugin{ return new PluginResult(status, i); } else if (action.equals("getHeading")) { + // If not running, then this is an async call, so don't worry about waiting + if (this.status != RUNNING) { + int r = this.start(); + if (r == ERROR_FAILED_TO_START) { + return new PluginResult(PluginResult.Status.IO_EXCEPTION, ERROR_FAILED_TO_START); + } + // Wait until running + while (this.status == STARTING) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } float f = this.getHeading(); return new PluginResult(status, f); } @@ -108,6 +123,28 @@ public class CompassListener implements SensorEventListener, Plugin{ } } + /** + * Identifies if action to be executed returns a value. + * + * @param action The action to execute + * @return T=returns value + */ + public boolean hasReturnValue(String action) { + if (action.equals("getStatus")) { + return true; + } + else if (action.equals("getHeading")) { + // Can only return value if RUNNING + if (this.status == RUNNING) { + return true; + } + } + else if (action.equals("getTimeout")) { + return true; + } + return false; + } + /** * Called when the system is about to start resuming a previous activity. */ @@ -162,13 +199,13 @@ public class CompassListener implements SensorEventListener, Plugin{ if (list.size() > 0) { this.mSensor = list.get(0); this.sensorManager.registerListener(this, this.mSensor, SensorManager.SENSOR_DELAY_NORMAL); - this.status = CompassListener.STARTING; this.lastAccessTime = System.currentTimeMillis(); + this.setStatus(CompassListener.STARTING); } // If error, then set status to error else { - this.status = CompassListener.ERROR_FAILED_TO_START; + this.setStatus(CompassListener.ERROR_FAILED_TO_START); } return this.status; @@ -181,7 +218,7 @@ public class CompassListener implements SensorEventListener, Plugin{ if (this.status != CompassListener.STOPPED) { this.sensorManager.unregisterListener(this); } - this.status = CompassListener.STOPPED; + this.setStatus(CompassListener.STOPPED); } @@ -202,7 +239,7 @@ public class CompassListener implements SensorEventListener, Plugin{ // Save heading this.timeStamp = System.currentTimeMillis(); this.heading = heading; - this.status = CompassListener.RUNNING; + this.setStatus(CompassListener.RUNNING); // If heading hasn't been read for TIMEOUT time, then turn off compass sensor to save power if ((this.timeStamp - this.lastAccessTime) > this.TIMEOUT) { @@ -246,4 +283,13 @@ public class CompassListener implements SensorEventListener, Plugin{ public long getTimeout() { return this.TIMEOUT; } + + /** + * Set the status and send it to JavaScript. + * @param status + */ + private void setStatus(int status) { + this.status = status; + } + } diff --git a/framework/src/com/phonegap/ContactManager.java b/framework/src/com/phonegap/ContactManager.java index 01c6ef18..44899539 100755 --- a/framework/src/com/phonegap/ContactManager.java +++ b/framework/src/com/phonegap/ContactManager.java @@ -83,6 +83,16 @@ public class ContactManager implements Plugin { } } + /** + * Identifies if action to be executed returns a value. + * + * @param action The action to execute + * @return T=returns value + */ + public boolean hasReturnValue(String action) { + return false; + } + /** * Called when the system is about to start resuming a previous activity. */ diff --git a/framework/src/com/phonegap/CryptoHandler.java b/framework/src/com/phonegap/CryptoHandler.java index 9c68a3c1..31dbca3d 100755 --- a/framework/src/com/phonegap/CryptoHandler.java +++ b/framework/src/com/phonegap/CryptoHandler.java @@ -64,6 +64,16 @@ public class CryptoHandler implements Plugin { } } + /** + * Identifies if action to be executed returns a value. + * + * @param action The action to execute + * @return T=returns value + */ + public boolean hasReturnValue(String action) { + return false; + } + /** * Called when the system is about to start resuming a previous activity. */ diff --git a/framework/src/com/phonegap/GeoBroker.java b/framework/src/com/phonegap/GeoBroker.java index b3e7ca9b..0877495b 100644 --- a/framework/src/com/phonegap/GeoBroker.java +++ b/framework/src/com/phonegap/GeoBroker.java @@ -80,6 +80,16 @@ public class GeoBroker implements Plugin { } } + /** + * Identifies if action to be executed returns a value. + * + * @param action The action to execute + * @return T=returns value + */ + public boolean hasReturnValue(String action) { + return false; + } + /** * Called when the system is about to start resuming a previous activity. */ diff --git a/framework/src/com/phonegap/NetworkManager.java b/framework/src/com/phonegap/NetworkManager.java index bf847f8d..90cb3275 100644 --- a/framework/src/com/phonegap/NetworkManager.java +++ b/framework/src/com/phonegap/NetworkManager.java @@ -76,6 +76,10 @@ public class NetworkManager implements Plugin { } } + public boolean hasReturnValue(String action) { + return false; + } + /** * Called when the system is about to start resuming a previous activity. */ diff --git a/framework/src/com/phonegap/Storage.java b/framework/src/com/phonegap/Storage.java index 9bd3e3b8..f6cbb0a6 100644 --- a/framework/src/com/phonegap/Storage.java +++ b/framework/src/com/phonegap/Storage.java @@ -82,6 +82,16 @@ public class Storage implements Plugin { } } + /** + * Identifies if action to be executed returns a value. + * + * @param action The action to execute + * @return T=returns value + */ + public boolean hasReturnValue(String action) { + return false; + } + /** * Called when the system is about to start resuming a previous activity. */ diff --git a/framework/src/com/phonegap/TempListener.java b/framework/src/com/phonegap/TempListener.java index b7a13288..d7e7d69a 100644 --- a/framework/src/com/phonegap/TempListener.java +++ b/framework/src/com/phonegap/TempListener.java @@ -70,6 +70,16 @@ public class TempListener implements SensorEventListener, Plugin { return new PluginResult(status, result); } + /** + * Identifies if action to be executed returns a value. + * + * @param action The action to execute + * @return T=returns value + */ + public boolean hasReturnValue(String action) { + return false; + } + /** * Called when the system is about to start resuming a previous activity. */