Skip to content

Commit

Permalink
kludge wp8 until cli is fixed
Browse files Browse the repository at this point in the history
cordova cli 3.1.0-0.2.0 has a bug for wp8.
cd plaforms/wp8
remove plugins with plugman
re-add plugins with plugman
  • Loading branch information
don committed Nov 6, 2013
1 parent 711209b commit fc5893d
Show file tree
Hide file tree
Showing 9 changed files with 342 additions and 291 deletions.
35 changes: 22 additions & 13 deletions platforms/wp8/NfcReader.csproj
Expand Up @@ -199,46 +199,55 @@
</PostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Compile Include="Plugins\org.apache.cordova.device\Device.cs" />
<Content Include="www\config.xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Plugins\org.apache.cordova.vibration\Vibration.cs" />
<Content Include="www\cordova.js" />
</ItemGroup>
<ItemGroup>
<Compile Include="Plugins\com.chariotsolutions.nfc.plugin\Ndef.cs" />
<Content Include="www\css\index.css" />
</ItemGroup>
<ItemGroup>
<Compile Include="Plugins\com.chariotsolutions.nfc.plugin\NfcPlugin.cs" />
<Content Include="www\index.html" />
</ItemGroup>
<ItemGroup>
<Content Include="www/config.xml" />
<Content Include="www\js\handlebars.js" />
</ItemGroup>
<ItemGroup>
<Content Include="www/cordova.js" />
<Content Include="www\js\index.js" />
</ItemGroup>
<ItemGroup>
<Content Include="www/css" />
<Content Include="www\res\icon\blackberry10\icon-80.png" />
</ItemGroup>
<ItemGroup>
<Content Include="www/index.html" />
<Content Include="www\res\screen\blackberry10\splash-1280x768.png" />
</ItemGroup>
<ItemGroup>
<Content Include="www/js" />
<Content Include="www\res\screen\blackberry10\splash-720x720.png" />
</ItemGroup>
<ItemGroup>
<Content Include="www/res" />
<Content Include="www\res\screen\blackberry10\splash-768x1280.png" />
</ItemGroup>
<ItemGroup>
<Content Include="www\plugins\org.apache.cordova.vibration\www\vibration.js" />
<Compile Include="Plugins\com.chariotsolutions.nfc.plugin\Ndef.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="www\plugins\org.apache.cordova.device\www\device.js" />
<Compile Include="Plugins\com.chariotsolutions.nfc.plugin\NfcPlugin.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="Plugins\org.apache.cordova.device\Device.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="Plugins\org.apache.cordova.vibration\Vibration.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="www\plugins\com.chariotsolutions.nfc.plugin\www\phonegap-nfc.js" />
</ItemGroup>
<ItemGroup>
<Content Include="www\plugins\com.blackberry.invoke\www\client.js" />
<Content Include="www\plugins\org.apache.cordova.device\www\device.js" />
</ItemGroup>
<ItemGroup>
<Content Include="www\plugins\org.apache.cordova.vibration\www\vibration.js" />
</ItemGroup>
<ItemGroup>
<Content Include="www\cordova_plugins.js" />
Expand Down
12 changes: 9 additions & 3 deletions platforms/wp8/config.xml
@@ -1,9 +1,6 @@
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.megster.nfc.reader" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<access origin="*" />
<feature name="NfcPlugin">
<param name="wp-package" value="NfcPlugin" />
</feature>
<name>NfcReader</name>
<description>
PhoneGap NFC Reader Demo
Expand All @@ -14,4 +11,13 @@
<preference name="fullscreen" value="true" />
<preference name="webviewbounce" value="true" />
<content src="index.html" />
<feature name="NfcPlugin">
<param name="wp-package" value="NfcPlugin" />
</feature>
<feature name="Device">
<param name="wp-package" value="Device" />
</feature>
<feature name="Vibration">
<param name="wp-package" value="Vibration" />
</feature>
</widget>
@@ -1 +1 @@
{"source":{"type":"local","path":"C:\\Users\\don\\AppData\\Local\\Temp\\com.chariotsolutions.nfc.plugin\\package"}}
{"source":{"type":"git","url":"https://github.com/chariotsolutions/phonegap-nfc","subdir":"."}}

This file was deleted.

Expand Up @@ -60,4 +60,25 @@
<source-file src="src/windows-phone-8/NfcPlugin.cs" />

</platform>

<platform name="blackberry10">
<!-- why does this need to be repeated? -->
<js-module src="www/phonegap-nfc.js" name="NFC">
<runs />
</js-module>
<!-- override defaults for BB10 -->
<js-module src="www/phonegap-nfc-blackberry.js" name="NFCBB10">
<runs />
</js-module>

<!-- "native" implementation -->
<source-file src="src/blackberry10/index.js" />

<config-file target="www/config.xml" parent="/widget">
<!-- Note: mapping is broken in Cordova 3.1.0-0.2.0 -->
<feature name="NfcPlugin" value="com.chariotsolutions.nfc.plugin" />
</config-file>
</platform>


</plugin>
@@ -0,0 +1,148 @@
/*jshint quotmark:double, strict:false, bitwise: false */
/*global PluginResult */

// based on code from Gord Tanner https://github.com/chariotsolutions/phonegap-nfc/pull/32

var alphabet = "ABCDEFGHIJKLM" +
"NOPQRSTUVWXYZ" +
"abcdefghijklm" +
"nopqrstuvwxyz" +
"0123456789+/=";

function b64toArray(input) {
var result = [],
workValue = [],
bytes = [],
offset = 0;

while (offset < input.length) {
for (var i = 0; i < 4; ++i) {
if (offset >= input.length) {
workValue[i] = 64;
} else {
var index = alphabet.indexOf(input.substring(offset++, offset));
if (index === -1) {
--i;
continue;
}
workValue[i] = index;
}
}
bytes[0] = (workValue[0] << 2 | workValue[1] >> 4) & 255;
bytes[1] = (workValue[1] << 4 | workValue[2] >> 2) & 255;
bytes[2] = (workValue[2] << 6 | workValue[3]) & 255;

if (workValue[3] === 64 && workValue[2] === 64) {
result.push(bytes[0]);
} else if (workValue[3] === 64) {
result.push(bytes[0]);
result.push(bytes[1]);
} else {
result.push(bytes[0]);
result.push(bytes[1]);
result.push(bytes[2]);
}
}

return result;
}

function decodeNdefRecord(encoded) {

var ndefRecord = {
tnf: encoded[0] & 7
},
flags = encoded[0],
isShortRecord = (flags & 16) !== 0, // short record
hasIdLength = (flags & 8) !== 0, // identification length
offset = 1,
typeLength = encoded[offset++],
idLength = 0,
payloadLength = 0;

if (isShortRecord) {
payloadLength = encoded[offset++];
} else {
for ( var i = 0; i < 4; ++i) {
payloadLength *= 256;
payloadLength |= encoded[offset++];
}
}

if (hasIdLength) {
idLength = encoded[offset++];
}

ndefRecord.type = encoded.slice(offset, offset + typeLength);

offset += typeLength;
ndefRecord.id = encoded.slice(offset, offset + idLength);

offset += idLength;
ndefRecord.payload = encoded.slice(offset, offset + payloadLength);

return ndefRecord;
}

function decode(encoding) {
var decoded = [];
var offset = 0;

while (offset < encoding.length) {
var start = offset;
var remaining = encoding.length - offset;
var flags = encoding[offset++];
var minLength = 1 + 1;
var sr = (flags & 16) !== 0;
var il = (flags & 8) !== 0;

minLength += sr ? 1 : 4;
minLength += il ? 1 : 0;
if (minLength <= remaining) {
var typeLength = encoding[offset++];
var payloadLength = 0;
if (sr) {
payloadLength = encoding[offset++];
} else {
for ( var i = 0; i < 4; ++i) {
payloadLength <<= 8;
payloadLength |= encoding[offset++];
}
}
var idLength = il ? encoding[offset++] : 0;
var totalLength = minLength + typeLength + payloadLength + idLength;
if (totalLength <= remaining) {
var encoded = encoding.slice(start, start + totalLength);

decoded.push(decodeNdefRecord(encoded));

offset = start + totalLength;
}
}
}
return decoded;
}

// called by invoke, when NFC tag is scanned
var tagListener = function(pluginResult, payloadString) {
var payload = JSON.parse(payloadString),
ndefObjectAsString = JSON.stringify(decode(b64toArray(payload.data)));
pluginResult.callbackOk(ndefObjectAsString, true);
};

module.exports = {
init: function(success, failure, args, env) {
// no-op, just here for Android compatibility
var result = new PluginResult(args, env);
result.ok();
},
registerNdef: function(success, failure, args, env) {

var result = new PluginResult(args, env),
application = window.qnx.webplatform.getApplication(),
ndefListener = tagListener.bind(null, result);

application.invocation.addEventListener("invoked", ndefListener);
result.noResult(true);
}
};
@@ -0,0 +1,63 @@
/*jslint browser: true, unused: vars, quotmark: double */
/*global cordova, nfc, ndef, blackberry */

// blackberry requires the com.blackberry.invoke plugin installed

// you need to edit config.xml for your app and add an invoke-target
// <rim:invoke-target id="com.chariotsolutions.nfc.demo.reader.target">
// <type>APPLICATION</type>
// <filter>
// <action>bb.action.OPEN</action>
// <mime-type>application/vnd.rim.nfc.ndef</mime-type>
// <property value="ndef://0,ndef://1,ndef://2,ndef://3,ndef://4" var="uris" />
// </filter>
// </rim:invoke-target>

// clobber existing share function
nfc.share = function(ndefMessage, success, failure) {
"use strict";
var byteArray = ndef.encodeMessage(ndefMessage),
data = "",
query;

for (var i=0; i< byteArray.length; ++i) {
data += String.fromCharCode(byteArray[i]);
}

query = {
"action": "bb.action.SHARE",
"type": "application/vnd.rim.nfc.ndef",
"data": data
};

blackberry.invoke.invoke(query, success, failure);
};

// clobber existing unshare function
nfc.unshare = function(success, failure) {
"use strict";
blackberry.invoke.closeChildCard();
if (success) { // no idea if it worked. assume success.
success();
}
};

// takes an ndefMessage from the success callback and fires a javascript event
var proxy = function(ndefMessageAsString) {
"use strict";
var ndefMessage = JSON.parse(ndefMessageAsString);
cordova.fireDocumentEvent("ndef", {
type: "ndef",
tag: {
ndefMessage: ndefMessage
}
});
};

// clobber existing addNdefListener function
nfc.addNdefListener = function (callback, success, failure) {
"use strict";
document.addEventListener("ndef", callback, false);
cordova.exec(proxy, failure, "com.chariotsolutions.nfc.plugin", "registerNdef", []);
success(); // assume success
};

0 comments on commit fc5893d

Please sign in to comment.