Compare commits

..
3 Commits
4 changed files with 46 additions and 11 deletions
+7 -5
View File
@@ -61,15 +61,17 @@ Windows Phone 8
### Automatically (CLI / Plugman)
Toast is compatible with [Cordova Plugman](https://github.com/apache/cordova-plugman), compatible with [PhoneGap 3.0 CLI](http://docs.phonegap.com/en/3.0.0/guide_cli_index.md.html#The%20Command-line%20Interface_add_features), here's how it works with the CLI (backup your project first!):
Using the Cordova CLI and the [Cordova Plugin Registry](http://plugins.cordova.io)
```
$ phonegap local plugin add https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git
```
or
```
$ cordova plugin add https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git
$ cordova plugin add nl.x-services.plugins.toast
$ cordova prepare
```
Or using the phonegap CLI
```
$ phonegap local plugin add nl.x-services.plugins.toast
```
Toast.js is brought in automatically. There is no need to change or add anything in your html.
### Manually
+9 -1
View File
@@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="nl.x-services.plugins.toast"
version="2.0.1">
version="2.0.3">
<name>Toast</name>
@@ -11,8 +11,16 @@
A Toast is a little non intrusive buttonless popup which automatically disappears.
</description>
<author>Eddy Verbruggen</author>
<license>MIT</license>
<keywords>Toast, Notification, Message, Alert</keywords>
<repo>https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git</repo>
<issue>https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin/issues</issue>
<engines>
<engine name="cordova" version=">=3.0.0"/>
</engines>
+26 -1
View File
@@ -6,14 +6,31 @@ import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
/*
// TODO nice way for the Toast plugin to offer a longer delay than the default short and long options
// TODO also look at https://github.com/JohnPersano/Supertoasts
new CountDownTimer(6000, 1000) {
public void onTick(long millisUntilFinished) {toast.show();}
public void onFinish() {toast.show();}
}.start();
Also, check https://github.com/JohnPersano/SuperToasts
*/
public class Toast extends CordovaPlugin {
private static final String ACTION_SHOW_EVENT = "show";
private android.widget.Toast mostRecentToast;
@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
if (ACTION_SHOW_EVENT.equals(action)) {
if (webView.isPaused()) {
// suppress while paused
return true;
}
final String message = args.getString(0);
final String duration = args.getString(1);
final String position = args.getString(2);
@@ -43,6 +60,7 @@ public class Toast extends CordovaPlugin {
}
toast.show();
mostRecentToast = toast;
callbackContext.success();
}
});
@@ -53,4 +71,11 @@ public class Toast extends CordovaPlugin {
return false;
}
}
}
@Override
public void onPause(boolean multitasking) {
if (mostRecentToast != null) {
mostRecentToast.cancel();
}
}
}
+4 -4
View File
@@ -12,7 +12,7 @@
if (![position isEqual: @"top"] && ![position isEqual: @"center"] && ![position isEqual: @"bottom"]) {
CDVPluginResult * pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"invalid position. valid options are 'top', 'center' and 'bottom'"];
[self writeJavascript:[pluginResult toErrorCallbackString:command.callbackId]];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
return;
}
@@ -23,14 +23,14 @@
durationInt = 5;
} else {
CDVPluginResult * pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"invalid duration. valid options are 'short' and 'long'"];
[self writeJavascript:[pluginResult toErrorCallbackString:command.callbackId]];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
return;
}
[self.webView makeToast:message duration:durationInt position:position];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self writeJavascript:[pluginResult toSuccessCallbackString:command.callbackId]];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
@end