#35 Close toast when app is suspended or closed: added hide() function, for Android only for now

This commit is contained in:
EddyVerbruggen
2015-05-21 21:04:37 +02:00
parent 69f1fbaa80
commit 4593549f41
3 changed files with 16 additions and 2 deletions
+11 -1
View File
@@ -20,6 +20,7 @@ import org.json.JSONObject;
public class Toast extends CordovaPlugin {
private static final String ACTION_SHOW_EVENT = "show";
private static final String ACTION_HIDE_EVENT = "hide";
private android.widget.Toast mostRecentToast;
@@ -28,7 +29,16 @@ public class Toast extends CordovaPlugin {
@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
if (ACTION_SHOW_EVENT.equals(action)) {
if (ACTION_HIDE_EVENT.equals(action)) {
if (mostRecentToast != null) {
mostRecentToast.cancel();
callbackContext.success();
} else {
callbackContext.error("No Toast has been shows yet");
}
return true;
} else if (ACTION_SHOW_EVENT.equals(action)) {
if (this.isPaused) {
return true;