Experimented with the WP8 ShellToast

This commit is contained in:
EddyVerbruggen 2014-04-12 10:02:41 +02:00
parent e21ecc5020
commit 30fc389fb4
2 changed files with 45 additions and 0 deletions

View File

@ -50,4 +50,15 @@
<source-file src="src/android/nl/xservices/plugins/Toast.java" target-dir="src/nl/xservices/plugins"/>
</platform>
<!-- wp8.. enable when we have a proper iOS-style Toast impl, not the native ShellToast impl which is more like a local push message
<platform name="wp8">
<config-file target="config.xml" parent="/*">
<feature name="Toast">
<param name="wp-package" value="Toast"/>
</feature>
</config-file>
<source-file src="src/wp8/Toast.cs" />
</platform-->
</plugin>

34
src/wp8/Toast.cs Normal file
View File

@ -0,0 +1,34 @@
using WPCordovaClassLib.Cordova;
using WPCordovaClassLib.Cordova.Commands;
using WPCordovaClassLib.Cordova.JSON;
// TODO create a custom overlay similar to the iOS implementation because the ShellToast on WP is
// very different from the native Android Toast the iOS impl is inspired on.
// Differences:
// - Only WP8 update 3 will show a Toast when in the foreground
// - A ShellToast can't be positioned
// - A ShellToast has a fixed duration
// DOCS: http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj662938(v=vs.105).aspx
// --> Conclusion: ShellToast is more like a localnotification/pushmessage, so it's a nice WP8 impl of the LocalNotification plugin,
// So we'll only add WP8 Toast plugin support if we can create an similar impl as the iOS version of this Toast plugin.
// Hence, leaving out the WP8 config in plugin.xml for now.
namespace Cordova.Extension.Commands {
public class Toast : BaseCommand {
public void show(string jsonArgs) {
var options = JsonHelper.Deserialize<string[]>(jsonArgs);
var message = options[0];
// var duration = options[1];
// var position = options[2];
ShellToast toast = new ShellToast();
toast.Title = "Test";
toast.Content = message;
toast.Show();
DispatchCommandResult(new PluginResult(PluginResult.Status.OK));
}
}
}