mirror of
https://github.com/apache/cordova-android.git
synced 2026-04-23 00:00:09 +08:00
Add PluginResult status values to handle RESULT_TO_BE_SENT, NEXT_RESULT, NO_MORE_RESULTS .
This commit is contained in:
@@ -87,10 +87,22 @@ public final class PluginManager {
|
||||
try {
|
||||
// Call execute on the plugin so that it can do it's thing
|
||||
PluginResult cr = plugin.execute(action, args, callbackId);
|
||||
// Check the status for 0 (success) or otherwise
|
||||
if (cr.getStatus() == 0) {
|
||||
int status = cr.getStatus();
|
||||
|
||||
// Check the success (OK, NEXT_RESULT, NO_MORE_RESULTS)
|
||||
if ((status == PluginResult.Status.OK.ordinal()) ||
|
||||
(status == PluginResult.Status.NEXT_RESULT.ordinal()) ||
|
||||
(status == PluginResult.Status.NO_MORE_RESULTS.ordinal())
|
||||
) {
|
||||
ctx.sendJavascript(cr.toSuccessCallbackString(callbackId));
|
||||
} else {
|
||||
}
|
||||
|
||||
// If return result will be sent later, no need to sent back to JavaScript
|
||||
else if (status == PluginResult.Status.RESULT_TO_BE_SENT.ordinal()) {
|
||||
}
|
||||
|
||||
// If error
|
||||
else {
|
||||
ctx.sendJavascript(cr.toErrorCallbackString(callbackId));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -104,6 +116,11 @@ public final class PluginManager {
|
||||
} else {
|
||||
// Call execute on the plugin so that it can do it's thing
|
||||
cr = plugin.execute(action, args, callbackId);
|
||||
|
||||
// If return result will be sent later
|
||||
if (cr.getStatus() == PluginResult.Status.RESULT_TO_BE_SENT.ordinal()) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
|
||||
@@ -33,16 +33,17 @@ public class PluginResult {
|
||||
this.status = status.ordinal();
|
||||
this.message = message.toString();
|
||||
}
|
||||
|
||||
// TODO: BC: Added
|
||||
|
||||
public PluginResult(Status status, int i) {
|
||||
this.status = status.ordinal();
|
||||
this.message = ""+i;
|
||||
}
|
||||
|
||||
public PluginResult(Status status, float f) {
|
||||
this.status = status.ordinal();
|
||||
this.message = ""+f;
|
||||
}
|
||||
|
||||
public PluginResult(Status status, boolean b) {
|
||||
this.status = status.ordinal();
|
||||
this.message = ""+b;
|
||||
@@ -55,9 +56,9 @@ public class PluginResult {
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
public String getJSONString() {
|
||||
return "{ status: " + this.getStatus() + ", message: " + this.getMessage() + " }";
|
||||
return "{ status: " + this.getStatus() + ", message: '" + this.getMessage() + "' }";
|
||||
}
|
||||
|
||||
public String toSuccessCallbackString(String callbackId) {
|
||||
@@ -77,7 +78,10 @@ public class PluginResult {
|
||||
"IO error",
|
||||
"Invalid action",
|
||||
"JSON error",
|
||||
"Error"
|
||||
"Error",
|
||||
"Result to be sent later",
|
||||
"Next result",
|
||||
"No more results"
|
||||
};
|
||||
|
||||
public enum Status {
|
||||
@@ -89,6 +93,9 @@ public class PluginResult {
|
||||
IO_EXCEPTION,
|
||||
INVALID_ACTION,
|
||||
JSON_EXCEPTION,
|
||||
ERROR
|
||||
ERROR,
|
||||
RESULT_TO_BE_SENT,
|
||||
NEXT_RESULT,
|
||||
NO_MORE_RESULTS
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user