Compare commits

..
7 changed files with 75 additions and 20 deletions
+9 -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
@@ -160,6 +162,8 @@ The Android code was entirely created by me.
For iOS most credits go to this excellent [Toast for iOS project by Charles Scalesse] (https://github.com/scalessec/Toast).
## 6. CHANGELOG
2.0.1: iOS messages are hidden when another one is shown. [Thanks Richie Min!](https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin/pull/13)
2.0: WP8 support
1.0: initial version supporting Android and iOS
+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">
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();
}
}
}
+6
View File
@@ -46,6 +46,8 @@ static const BOOL CSToastHidesOnTap = YES; // excludes activity
static const NSString * CSToastTimerKey = @"CSToastTimerKey";
static const NSString * CSToastActivityViewKey = @"CSToastActivityViewKey";
static UIView *prevToast = NULL;
@interface UIView (ToastPrivate)
- (void)hideToast:(UIView *)toast;
@@ -91,6 +93,10 @@ static const NSString * CSToastActivityViewKey = @"CSToastActivityViewKey";
}
- (void)showToast:(UIView *)toast duration:(NSTimeInterval)duration position:(id)point {
if(prevToast){
[self hideToast:prevToast];
}
prevToast = toast;
toast.center = [self centerPointForPosition:point withToast:toast];
toast.alpha = 0.0;
+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
+18 -4
View File
@@ -82,16 +82,30 @@ namespace WPCordovaClassLib.Cordova.Commands
popup.VerticalAlignment = VerticalAlignment.Bottom;
popup.VerticalOffset = -100; // TODO can do better
}
else // center
else if ("center".Equals(position))
{
popup.VerticalAlignment = VerticalAlignment.Center;
popup.VerticalOffset = -50; // TODO can do way better
}
else
{
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "invalid position. valid options are 'top', 'center' and 'bottom'"));
return;
}
int hideDelay = 2800;
if ("long".Equals(duration))
{
hideDelay = 5500;
}
else if (!"short".Equals(duration))
{
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "invalid duration. valid options are 'short' and 'long'"));
return;
}
grid.Children.Add(popup);
popup.IsOpen = true;
int hideDelay = "long".Equals(duration) ? 5500 : 2800;
this.hidePopup(hideDelay);
}
}
@@ -108,4 +122,4 @@ namespace WPCordovaClassLib.Cordova.Commands
popup.IsOpen = false;
}
}
}
}
+3 -5
View File
@@ -1,11 +1,11 @@
cordova.define("nl.x-services.plugins.toast.tests", function(require, exports, module) { exports.defineAutoTests = function() {
exports.defineAutoTests = function() {
var fail = function (done) {
expect(false).toBe(true);
expect(true).toBe(false);
done();
},
succeed = function (done) {
expect(false).toBe(false);
expect(true).toBe(true);
done();
};
@@ -55,5 +55,3 @@ cordova.define("nl.x-services.plugins.toast.tests", function(require, exports, m
});
});
};
});