#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

View File

@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
id="nl.x-services.plugins.toast" id="nl.x-services.plugins.toast"
version="2.0.5"> version="2.0.6-dev">
<name>Toast</name> <name>Toast</name>

View File

@ -20,6 +20,7 @@ import org.json.JSONObject;
public class Toast extends CordovaPlugin { public class Toast extends CordovaPlugin {
private static final String ACTION_SHOW_EVENT = "show"; private static final String ACTION_SHOW_EVENT = "show";
private static final String ACTION_HIDE_EVENT = "hide";
private android.widget.Toast mostRecentToast; private android.widget.Toast mostRecentToast;
@ -28,7 +29,16 @@ public class Toast extends CordovaPlugin {
@Override @Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { 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) { if (this.isPaused) {
return true; return true;

View File

@ -74,6 +74,10 @@ Toast.prototype.showLongBottom = function (message, successCallback, errorCallba
this.show(message, "long", "bottom", successCallback, errorCallback); this.show(message, "long", "bottom", successCallback, errorCallback);
}; };
Toast.prototype.hide = function (successCallback, errorCallback) {
cordova.exec(successCallback, errorCallback, "Toast", "hide", []);
};
Toast.install = function () { Toast.install = function () {
if (!window.plugins) { if (!window.plugins) {
window.plugins = {}; window.plugins = {};