Skip to content

Commit

Permalink
work in progress for command bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
purplecabbage committed Aug 29, 2011
1 parent 9570b8c commit 2d2727e
Show file tree
Hide file tree
Showing 8 changed files with 583 additions and 458 deletions.
7 changes: 6 additions & 1 deletion example/GapExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
</Page>
</ItemGroup>
<ItemGroup>
<Content Include="www\debugconsole.js" />
<Content Include="www\phonegap-base.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="Properties\AppManifest.xml">
<SubType>Designer</SubType>
</None>
Expand All @@ -84,6 +88,7 @@
</None>
<Content Include="GapSourceDictionary.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType>
</Content>
</ItemGroup>
<ItemGroup>
Expand All @@ -98,7 +103,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="www\index.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<SubType>Designer</SubType>
</Content>
<Content Include="www\master.css">
Expand Down
4 changes: 4 additions & 0 deletions example/GapSourceDictionary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

<FilePath Value="www/index.html"/>

<FilePath Value="www/phonegap-base.js"/>

<FilePath Value="www/debugconsole.js"/>

<FilePath Value="www/master.css"/>

<FilePath Value="www/pg_logo.png"/>
Expand Down
4 changes: 2 additions & 2 deletions example/Properties/AppManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Deployment.Parts>
</Deployment.Parts>
<Deployment.Parts>
</Deployment.Parts>
</Deployment>
10 changes: 9 additions & 1 deletion example/Properties/WMAppManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@
<App xmlns="" ProductID="{16782d49-b494-4f58-bec6-7d2e7846e16b}" Title="GapExample" RuntimeType="Silverlight" Version="1.0.0.0" Genre="apps.normal" Author="GapExample author" Description="Sample description" Publisher="GapExample">
<IconPath IsRelative="true" IsResource="false">ApplicationIcon.png</IconPath>
<Capabilities>
<Capability Name="ID_CAP_GAMERSERVICES" />
<!--<Capability Name="ID_CAP_APPOINTMENTS"/>-->
<Capability Name="ID_CAP_CAMERA"/>
<Capability Name="ID_CAP_CONTACTS"/>
<!--<Capability Name="ID_CAP_FILEVIEWER"/>-->
<!--<Capability Name="ID_CAP_GAMERSERVICES" />-->
<Capability Name="ID_CAP_IDENTITY_DEVICE" />
<Capability Name="ID_CAP_IDENTITY_USER" />
<!--<Capability Name="ID_CAP_INTEROPSERVICES"/>-->
<!--<Capability Name="ID_CAP_ISV_CAMERA"/>-->
<Capability Name="ID_CAP_LOCATION" />
<Capability Name="ID_CAP_MEDIALIB" />
<Capability Name="ID_CAP_MICROPHONE" />
<Capability Name="ID_CAP_NETWORKING" />

<Capability Name="ID_CAP_PHONEDIALER" />
<Capability Name="ID_CAP_PUSH_NOTIFICATION" />
<Capability Name="ID_CAP_RINGTONE_ADD"/>
<Capability Name="ID_CAP_SENSORS" />
<Capability Name="ID_CAP_WEBBROWSERCOMPONENT" />
</Capabilities>
Expand Down
95 changes: 95 additions & 0 deletions example/www/debugconsole.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@

/****************************** DEBUGCONSOLE ******************************/

/**
* This class provides access to the debugging console.
* @constructor
*/
function DebugConsole() {
}

/**
* Utility function for rendering and indenting strings, or serializing
* objects to a string capable of being printed to the console.
* @param {Object|String} message The string or object to convert to an indented string
* @private
*/
DebugConsole.prototype.processMessage = function(message) {
if (typeof(message) != 'object') {
return message;
} else {
/**
* @function
* @ignore
*/
function indent(str) {
return str.replace(/^/mg, " ");
}
/**
* @function
* @ignore
*/
function makeStructured(obj) {
var str = "";
for (var i in obj) {
try {
if (typeof(obj[i]) == 'object') {
str += i + ":\n" + indent(makeStructured(obj[i])) + "\n";
} else {
str += i + " = " + indent(String(obj[i])).replace(/^ /, "") + "\n";
}
} catch(e) {
str += i + " = EXCEPTION: " + e.message + "\n";
}
}
return str;
}
return "Object:\n" + makeStructured(message);
}
};

/**
* Print a normal log message to the console
* @param {Object|String} message Message or object to print to the console
*/
DebugConsole.prototype.log = function(message) {
if (PhoneGap.available) {
PhoneGap.exec('DebugConsole;INFO;' + this.processMessage(message));
}
};

DebugConsole.prototype.log = function(message)
{
if (PhoneGap.available && this.logLevel <= DebugConsole.INFO_LEVEL)
{
PhoneGap.exec(null, null, 'com.phonegap.debugconsole', 'log', message);
}
else
{
this.winConsole.log(message);
}
};

/**
* Print a warning message to the console
* @param {Object|String} message Message or object to print to the console
*/
DebugConsole.prototype.warn = function(message) {
if (PhoneGap.available) {
PhoneGap.exec('DebugConsole;WARN;' + this.processMessage(message));
}
};

/**
* Print an error message to the console
* @param {Object|String} message Message or object to print to the console
*/
DebugConsole.prototype.error = function(message) {
if (PhoneGap.available) {
PhoneGap.exec('DebugConsole;ERROR;' + this.processMessage(message));
}
};

if (typeof window.debug == "undefined") {
window.debug = new DebugConsole();
}
92 changes: 79 additions & 13 deletions example/www/index.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,93 @@
<!DOCTYPE html>
<html>
<head>
<meta name="mobileoptimized" content="800" />
<meta name="viewport" content="user-scalable=no" />

<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<meta name="Viewport" content="width=480" />
<meta http-equiv="Expires" content="0" />

<title>PhoneGap - WP7 : Proof of concept</title>
<link rel="stylesheet" type="text/css" href="master.css"/>

<script type="text/javascript" charset="utf-8" src="phonegap-base.js"></script>
<script type="text/javascript" charset="utf-8">

if(typeof window.console == "undefined")
{
window.console = {log:function(str){window.external.Notify(str);}};
}

<script>

function onLoad()
{
console.log("loaded");
}
</script>
window.onerror=function(e){console.log("Error ::" + e);};

console.log("Installed console ! ");

</head>
<body onload="onLoad">
//forceError();


//document.writeln(getScript("Accelerometer"));

function JavaScriptFunctionWithoutParameters()
{
outputID.innerHTML = "JavaScript function called!";
return "hey";
}

function makeError()
{
forceError(); // forceError does not exist
}

//console.log("JSON = " + JSON);

function doLoad()
{


//console.log("OnLoad");


console.log("document.addEventListener = " + document.addEventListener);

<div>Hmmm</div>
}

var NextcallbackId = 0;
var callbacks = {};
var exec = function(success, fail, service, action, args)
{

var callbackId = service + NextcallbackId++;
if (typeof success == "Function" || typeof fail == "Function")
{
callbacks[callbackId] = {success:success, fail:fail};
}

var command = service + "/" + action + "/" + callbackId + "/" + JSON.stringify(args);

window.external.Notify(command);
}


exec(null,null,"DebugConsole","log",{message:"This is message 1"});
exec(null,null,"DebugConsole","log",{message:"This is message 2"});
exec(null,null,"DebugConsole","log",{message:"This is message 3"});

exec(null,null,"Notification","alert","here is a freakin message");
exec(null,null,"Notification","confirm","here is a freakin message");

</script>

</head>
<body onload="doLoad()">
<div id="dude">Hmmm</div>

<!-- This image has been included to prove it can be done -->
<img alt="PhoneGap" src="pg_logo.png" />
<img alt="PhoneGap" src="pg_logo.png" id="gapImage" />

<div id="outputID" style="color:Orange; font-size:16">
Hello from HTML document pre script!
</div>


</body>
</html>
Loading

0 comments on commit 2d2727e

Please sign in to comment.