Added WP8 support

This commit is contained in:
Sebastián Katzer 2013-10-10 12:19:50 +02:00
parent ca36c231f4
commit 79a1327776
3 changed files with 96 additions and 10 deletions

View File

@ -31,7 +31,7 @@ cordova plugin rm de.appplant.cordova.plugin.background-mode
## Using the plugin
Simply add the plugin to your project and the app will run while in background.
The plugin creates the object ```window.plugin.notification.backgroundMode``` with two methods:
The plugin creates the object ```window.plugin.backgroundMode``` with two methods:
### enable()
The method enables the background mode. The mode is activated once the app has entered the background and will be deactivated after the app has entered the foreground.<br>

View File

@ -2,7 +2,7 @@
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
id="de.appplant.cordova.plugin.background-mode"
version="0.2.1">
version="0.4.0dev">
<name>BackgroundMode</name>

View File

@ -7,21 +7,107 @@
* GPL v2 licensed
*/
using System;
using System.Linq;
using Microsoft.Phone.Shell;
using WPCordovaClassLib.Cordova;
using WPCordovaClassLib.Cordova.Commands;
using Windows.Devices.Geolocation;
namespace APPPlant.Cordova.Plugin
namespace Cordova.Extension.Commands
{
/// </summary>
/// Ermöglicht, dass eine Anwendung im Hintergrund läuft ohne pausiert zu werden
/// </summary>
public class BackgroundMode : BaseCommand
{
/// </summary>
/// Flag gibt an, ob die App im Hintergrund wach gehalten werden soll
/// </summary>
private static bool isEnabled = true;
/// </summary>
/// Lokalisiert das Smartphone
/// </summary>
private static Geolocator Geolocator { get; set; }
/// </summary>
/// Registriert die Listener für die (sleep/resume) Events und startet
/// bzw. stoppt die Geo-Lokalisierung
/// </summary>
public BackgroundMode ()
{
Activate();
}
/// </summary>
/// @js-interface
/// Setzt den Flag, dass die App im Hintergrund wach gehalten werden soll
/// </summary>
public void enable (string args)
{
Enable();
}
/// </summary>
/// @js-interface
/// Entfernt den Flag, sodass die App im Hintergrund pausiert wird
/// </summary>
public void disable (string args)
{
Disable();
}
/// </summary>
/// Setzt den Flag, dass die App im Hintergrund wach gehalten werden soll
/// </summary>
public static void Enable ()
{
isEnabled = true;
}
/// </summary>
/// Entfernt den Flag, sodass die App im Hintergrund pausiert wird
/// </summary>
public static void Disable ()
{
isEnabled = false;
Deactivate();
}
/// </summary>
/// @js-interface
/// Registriert die Listener für die (sleep/resume) Events
/// </summary>
public void observeLifeCycle (string args)
{
// Konstruktor wird aufgerufen, falls Instanz erstellt wurde
}
/// </summary>
/// Startet das Aktualisieren des Standpunktes
/// </summary>
public static void Activate ()
{
if (Geolocator == null && isEnabled)
{
Geolocator = new Geolocator();
Geolocator.DesiredAccuracy = PositionAccuracy.Default;
Geolocator.MovementThreshold = 100000;
Geolocator.PositionChanged += geolocator_PositionChanged;
}
}
/// </summary>
/// Beendet das Aktualisieren des Standpunktes
/// </summary>
public static void Deactivate ()
{
if (Geolocator != null)
{
Geolocator.PositionChanged -= geolocator_PositionChanged;
Geolocator = null;
}
}
private static void geolocator_PositionChanged (Geolocator sender, PositionChangedEventArgs args) {}
}
}