This repository has been archived by the owner on Sep 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
/
index.html
143 lines (125 loc) · 3.71 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!--
* Copyright 2012 Research In Motion Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-->
<html>
<script src="local:///chrome/webworks.js">
</script>
<script src="js/blackberrynfc.ndef.js">
</script>
<style>
TD,INPUT,BODY {
font-size: 25pt;
}
</style>
<script type="text/javascript">
// Create some aliases to save some typing.
var WELL_KNOWN = blackberrynfc.ndef.tnf.WELL_KNOWN;
var decodeRecords = blackberrynfc.ndef.message.decodeRecords;
// Aliases for record creation functions.
var createTextRecord = blackberrynfc.ndef.message.createTextRecord;
var createURIRecord = blackberrynfc.ndef.message.createURIRecord;
var createSpRecord = blackberrynfc.ndef.message.createSpRecord;
// When a tag is read by the OS - this handler will be triggered.
function onInvoked(onInvokedInfo) {
try {
if ("com.robwilliams.d20121122.ww.a" == onInvokedInfo.target
&& onInvokedInfo.data) {
// Convert the bytes to records.
var records = decodeRecords(onInvokedInfo.data);
if (records.length > 0) {
var record = records[0];
if (record.isType(WELL_KNOWN, "Sp")) {
alert("Read a smart poster\n" + record.getText() + "\n"
+ record.getURI());
} else {
alert("Read a non smart poster...");
}
} else {
alert("Message contained no (decodable) records...");
}
// Purely diagnostic code...
var output = document.getElementById("output");
output.innerHTML = records[0].getEncodedAsHTML();
} else {
alert("Didn't understand this invokation...");
}
} catch (e) {
alert(e);
}
}
function shareTag() {
try {
var text = document.getElementById("tagText").value;
var uri = document.getElementById("tagUri").value;
if (text=="" || uri=="") {
alert("Please enter text for both fields...");
return;
}
var textRecord = createTextRecord("en",text);
var uriRecord = createURIRecord(uri);
var records = Array(textRecord,uriRecord);
var spRecord = createSpRecord(records);
var data = spRecord.getEncoded("invoke");
var query = {
"action": "bb.action.SHARE",
"type": "application/vnd.rim.nfc.ndef",
"data": data
};
blackberry.invoke.invoke(query,shareGood,shareBad);
} catch (e) {
alert(e);
}
}
function shareGood() {
// The share was invoked...
}
function shareBad(error) {
alert("Could not share: " + error);
}
// Register the invokation handler.
function ready() {
try {
blackberry.event.addEventListener("invoked", onInvoked);
} catch (e) {
alert(e);
}
}
window.addEventListener("load", function(e) {
document.addEventListener("webworksready", ready)
}, false);
</script>
<body>
<h1>Scan a tag!</h1>
Please!
<div id='output'>Tag contents will go here.</div>
<hr />
<h1>Create a basic Smart Poster</h1>
<table>
<tbody>
<tr>
<td>Text:</td>
<td><input type='text' id='tagText' /></td>
</tr>
<tr>
<td>Uri:</td>
<td><input type='text' id='tagUri' /></td>
<tr>
<td></td>
<td><input type='button' value='Share Tag' onClick='shareTag()' /></td>
</tr>
</tbody>
</table>
</body>
</html>