Browse files

update for 2.x

  • Loading branch information...
1 parent 0d460d3 commit ec0073dbe4ed044726b08d62ae30f1136dda3064 @purplecabbage committed Jul 24, 2012
View
19 WindowsPhone/LiveTiles/LiveTiles.cs
@@ -7,17 +7,17 @@
*/
using System.Runtime.Serialization;
-using WP7GapClassLib.PhoneGap;
-using WP7GapClassLib.PhoneGap.Commands;
-using WP7GapClassLib.PhoneGap.JSON;
+using WP7CordovaClassLib.Cordova;
+using WP7CordovaClassLib.Cordova.Commands;
+using WP7CordovaClassLib.Cordova.JSON;
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Phone.Controls;
using System.Windows;
-namespace PhoneGap.Extension.Commands
+namespace Cordova.Extension.Commands
{
/// <summary>
/// Implementes access to application live tiles
@@ -87,7 +87,7 @@ public void updateAppTile(string options)
LiveTilesOptions liveTileOptions;
try
{
- liveTileOptions = WP7GapClassLib.PhoneGap.JSON.JsonHelper.Deserialize<LiveTilesOptions>(options);
+ liveTileOptions = JsonHelper.Deserialize<LiveTilesOptions[]>(options)[0];
}
catch (Exception e)
{
@@ -124,7 +124,7 @@ public void createSecondaryTile(string options)
LiveTilesOptions liveTileOptions;
try
{
- liveTileOptions = WP7GapClassLib.PhoneGap.JSON.JsonHelper.Deserialize<LiveTilesOptions>(options);
+ liveTileOptions = JsonHelper.Deserialize<LiveTilesOptions[]>(options)[0];
}
catch (Exception e)
{
@@ -171,7 +171,7 @@ public void updateSecondaryTile(string options)
LiveTilesOptions liveTileOptions;
try
{
- liveTileOptions = WP7GapClassLib.PhoneGap.JSON.JsonHelper.Deserialize<LiveTilesOptions>(options);
+ liveTileOptions = JsonHelper.Deserialize<LiveTilesOptions[]>(options)[0];
}
catch (Exception e)
{
@@ -214,7 +214,7 @@ public void deleteSecondaryTile(string options)
LiveTilesOptions liveTileOptions;
try
{
- liveTileOptions = WP7GapClassLib.PhoneGap.JSON.JsonHelper.Deserialize<LiveTilesOptions>(options);
+ liveTileOptions = JsonHelper.Deserialize<LiveTilesOptions[]>(options)[0];
}
catch (Exception e)
{
@@ -238,8 +238,7 @@ public void deleteSecondaryTile(string options)
else
{
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Can't get secondary live tile"));
- }
-
+ }
}
catch (Exception e)
{
View
88 WindowsPhone/LiveTiles/liveTiles.js
@@ -1,55 +1,45 @@
-PhoneGap.addConstructor(function () {
-
- navigator.plugins.liveTiles =
- {
- updateAppTile: function (successCallback, errorCallback, options) {
- if (successCallback && (typeof successCallback !== "function")) {
- console.log("LiveTiles Error: successCallback is not a function");
- return;
- }
+
- if (errorCallback && (typeof errorCallback !== "function")) {
- console.log("LiveTiles Error: errorCallback is not a function");
- return;
- }
- PhoneGap.exec(successCallback, errorCallback, "LiveTiles", "updateAppTile", options);
- },
+(function () {
- createSecondaryTile: function (successCallback, errorCallback, options) {
- if (successCallback && (typeof successCallback !== "function")) {
- console.log("LiveTiles Error: successCallback is not a function");
- return;
- }
+ function checkArgs(win,fail) {
+ if(win && typeof win === "function" && fail && typeof fail === "function") {
+ return true;
+ }
+ else {
+ console.log("LiveTiles Error: successCallback || errorCallback is not a function");
+ return false;
+ }
+ }
- if (errorCallback && (typeof errorCallback !== "function")) {
- console.log("LiveTiles Error: errorCallback is not a function");
- return;
- }
- PhoneGap.exec(successCallback, errorCallback, "LiveTiles", "createSecondaryTile", options);
- },
- updateSecondaryTile: function (successCallback, errorCallback, options) {
- if (successCallback && (typeof successCallback !== "function")) {
- console.log("LiveTiles Error: successCallback is not a function");
- return;
- }
+ var cdv = window.cordova || window.Cordova;
+ // if(cdv && cdv.exec) {
+ navigator.plugins.liveTiles = {
+ updateAppTile: function (successCallback, errorCallback, options) {
+ if(checkArgs(successCallback, errorCallback)) {
+ cdv.exec(successCallback, errorCallback, "LiveTiles", "updateAppTile", [options]);
+ }
+ },
- if (errorCallback && (typeof errorCallback !== "function")) {
- console.log("LiveTiles Error: errorCallback is not a function");
- return;
- }
- PhoneGap.exec(successCallback, errorCallback, "LiveTiles", "updateSecondaryTile", options);
- },
- deleteSecondaryTile: function (successCallback, errorCallback, options) {
- if (successCallback && (typeof successCallback !== "function")) {
- console.log("LiveTile Error: successCallback is not a function");
- return;
- }
+ createSecondaryTile: function (successCallback, errorCallback, options) {
+ if(checkArgs(successCallback, errorCallback)) {
+ cdv.exec(successCallback, errorCallback, "LiveTiles", "createSecondaryTile", [options]);
+ }
+ },
- if (errorCallback && (typeof errorCallback !== "function")) {
- console.log("LiveTiles Error: errorCallback is not a function");
- return;
+ updateSecondaryTile: function (successCallback, errorCallback, options) {
+ if(checkArgs(successCallback, errorCallback)) {
+ cdv.exec(successCallback, errorCallback, "LiveTiles", "updateSecondaryTile", [options]);
+ }
+ },
+
+ deleteSecondaryTile: function (successCallback, errorCallback, options) {
+ if(checkArgs(successCallback, errorCallback)) {
+ cdv.exec(successCallback, errorCallback, "LiveTiles", "deleteSecondaryTile", [options]);
+ }
}
- PhoneGap.exec(successCallback, errorCallback, "LiveTiles", "deleteSecondaryTile", options);
- }
- }
-});
+
+ };
+ // }
+
+})();
View
32 WindowsPhone/LiveTiles/liveTilesExample.html
@@ -1,48 +1,26 @@
-<!DOCTYPE HTML>
+<!DOCTYPE html>
<html>
<head>
<!-- meta name="viewport" content="width=device-width, height=device-height, user-scalable=yes, initial-scale=2.0, maximum-scale=4.0, minimum-scale=1.0" / -->
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
- <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 -->
- <title>PhoneGap</title>
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8"/> <!-- ISO-8859-1 -->
+ <title>Live Tiles</title>
<link rel="stylesheet" href="master.css" type="text/css" media="screen"/>
- <script type="text/javascript">
- // provide our own console if it does not exist, huge dev aid!
- if (typeof window.console == "undefined") {
- window.console = { log: function (str) { window.external.Notify(str); } };
- }
-
- // output any errors to console log, created above.
- window.onerror = function (e) {
- console.log("window.onerror ::" + JSON.stringify(e));
- };
-
- console.log("Installed console ! ");
- </script>
- <script type="text/javascript" charset="utf-8" src="phonegap-1.2.0.js"></script>
+ <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
<script type="text/javascript" charset="utf-8" src="liveTiles.js"></script>
<script type="text/javascript" charset="utf-8">
- var deviceReady = false;
var secondaryTile = 'www/liveTiles.html';
/**
* Function called when page has finished loading.
*/
function init() {
- document.addEventListener("deviceready", function () {
- deviceReady = true;
- console.log("Device=" + device.platform + " " + device.version);
- }, false);
- window.setTimeout(function () {
- if (!deviceReady) {
- alert("Error: PhoneGap did not initialize. Demo will not run correctly.");
- }
- }, 1000);
+
}
function updateAppTile() {

0 comments on commit ec0073d

Please sign in to comment.