Compare commits

..
Author SHA1 Message Date
Eddy Verbruggen 95fe5ce19b creating different failures 2014-07-16 17:20:26 +02:00
Eddy Verbruggen 9def9e77f5 Creating a failing test 2014-07-16 17:11:18 +02:00
7 changed files with 20 additions and 75 deletions
+5 -9
View File
@@ -61,17 +61,15 @@ 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)
```
$ cordova plugin add nl.x-services.plugins.toast
$ 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 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
@@ -162,8 +160,6 @@ 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
+1 -9
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.3">
version="2.0">
<name>Toast</name>
@@ -11,16 +11,8 @@
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>
+1 -26
View File
@@ -6,31 +6,14 @@ 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);
@@ -60,7 +43,6 @@ public class Toast extends CordovaPlugin {
}
toast.show();
mostRecentToast = toast;
callbackContext.success();
}
});
@@ -71,11 +53,4 @@ public class Toast extends CordovaPlugin {
return false;
}
}
@Override
public void onPause(boolean multitasking) {
if (mostRecentToast != null) {
mostRecentToast.cancel();
}
}
}
}
-6
View File
@@ -46,8 +46,6 @@ 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;
@@ -93,10 +91,6 @@ static UIView *prevToast = NULL;
}
- (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.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self writeJavascript:[pluginResult toErrorCallbackString: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.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self writeJavascript:[pluginResult toErrorCallbackString:command.callbackId]];
return;
}
[self.webView makeToast:message duration:durationInt position:position];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self writeJavascript:[pluginResult toSuccessCallbackString:command.callbackId]];
}
@end
+4 -18
View File
@@ -82,30 +82,16 @@ namespace WPCordovaClassLib.Cordova.Commands
popup.VerticalAlignment = VerticalAlignment.Bottom;
popup.VerticalOffset = -100; // TODO can do better
}
else if ("center".Equals(position))
else // center
{
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);
}
}
@@ -122,4 +108,4 @@ namespace WPCordovaClassLib.Cordova.Commands
popup.IsOpen = false;
}
}
}
}
+5 -3
View File
@@ -1,11 +1,11 @@
exports.defineAutoTests = function() {
cordova.define("nl.x-services.plugins.toast.tests", function(require, exports, module) { exports.defineAutoTests = function() {
var fail = function (done) {
expect(true).toBe(false);
expect(false).toBe(true);
done();
},
succeed = function (done) {
expect(true).toBe(true);
expect(false).toBe(false);
done();
};
@@ -55,3 +55,5 @@ exports.defineAutoTests = function() {
});
});
};
});