phonegap 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +21 -0
- data/README.md +25 -0
- data/Rakefile +58 -0
- data/VERSION +1 -0
- data/bin/phonegap +49 -0
- data/lib/devices/android.rb +11 -0
- data/lib/devices/blackberry.rb +32 -0
- data/lib/devices/iphone.rb +22 -0
- data/lib/generate/config/android-dev-cert.txt +0 -0
- data/lib/generate/config/blackberry-dev-cert.txt +0 -0
- data/lib/generate/config/bootstrap.js +8 -0
- data/lib/generate/config/iphone-dev-cert.txt +0 -0
- data/lib/generate/www/assets/css/master.css +97 -0
- data/lib/generate/www/assets/js/phongap.js +1122 -0
- data/lib/generate/www/index.html +303 -0
- data/lib/phonegap.rb +81 -0
- data/phonegap.gemspec +60 -0
- data/test/phonegap-dev_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +77 -0
@@ -0,0 +1,303 @@
|
|
1
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
2
|
+
"http://www.w3.org/TR/html4/strict.dtd">
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta name="viewport" content="width=320; user-scalable=no" />
|
6
|
+
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
7
|
+
<title>PhoneGap</title>
|
8
|
+
<link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title" charset="utf-8">
|
9
|
+
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
|
10
|
+
<script type="text/javascript" charset="utf-8">
|
11
|
+
|
12
|
+
function deviceInfo(){
|
13
|
+
debug.log("deviceInfo");
|
14
|
+
document.getElementById("platform").innerHTML = device.platform;
|
15
|
+
document.getElementById("version").innerHTML = device.version;
|
16
|
+
document.getElementById("devicename").innerHTML = device.name;
|
17
|
+
document.getElementById("uuid").innerHTML = device.uuid;
|
18
|
+
}
|
19
|
+
|
20
|
+
function getLocation() {
|
21
|
+
debug.log("getLocation");
|
22
|
+
navigator.notification.activityStart();
|
23
|
+
var suc = function(p){
|
24
|
+
debug.log(p.coords.latitude + " " + p.coords.longitude);
|
25
|
+
navigator.notification.alert(p.coords.latitude + " " + p.coords.longitude, "Your GeoLocation", "Thanks");
|
26
|
+
navigator.notification.activityStop();
|
27
|
+
};
|
28
|
+
var fail = function(error){
|
29
|
+
};
|
30
|
+
navigator.geolocation.getCurrentPosition(suc,fail);
|
31
|
+
}
|
32
|
+
|
33
|
+
function customAlert(){
|
34
|
+
navigator.notification.alert("Custom alert", "Custom title", "Yup!");
|
35
|
+
}
|
36
|
+
|
37
|
+
function beep(){
|
38
|
+
debug.log("beep");
|
39
|
+
navigator.notification.beep(2);
|
40
|
+
}
|
41
|
+
|
42
|
+
function vibrate(){
|
43
|
+
debug.log("vibrate");
|
44
|
+
navigator.notification.vibrate(0);
|
45
|
+
}
|
46
|
+
|
47
|
+
function getContactsPrompt(){
|
48
|
+
debug.log("getContactsPrompt");
|
49
|
+
|
50
|
+
var pageSize = prompt("Page size", 10);
|
51
|
+
if (pageSize) {
|
52
|
+
var pageNumber = prompt("Page number", 1);
|
53
|
+
if (pageNumber) {
|
54
|
+
var nameFilter = prompt("Name filter", null);
|
55
|
+
getContacts(parseInt(pageSize), parseInt(pageNumber), nameFilter);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
function showLoadingScreen(durationInSeconds){
|
61
|
+
if (!durationInSeconds) {
|
62
|
+
durationInSeconds = prompt("Enter the load duration in seconds", 3);
|
63
|
+
}
|
64
|
+
|
65
|
+
if (durationInSeconds) {
|
66
|
+
options = { 'duration': durationInSeconds };
|
67
|
+
navigator.notification.loadingStart(options);
|
68
|
+
} else {
|
69
|
+
return;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
function getContacts(pageSize, pageNumber, nameFilter){
|
74
|
+
debug.log("getContacts");
|
75
|
+
var fail = function(){};
|
76
|
+
|
77
|
+
var options = {};
|
78
|
+
if (pageSize)
|
79
|
+
options.pageSize = pageSize;
|
80
|
+
if (pageNumber)
|
81
|
+
options.pageNumber = pageNumber;
|
82
|
+
if (nameFilter)
|
83
|
+
options.nameFilter = nameFilter;
|
84
|
+
|
85
|
+
var durationOptions = { minDuration : 2 };
|
86
|
+
navigator.notification.loadingStart(durationOptions);
|
87
|
+
navigator.ContactManager.getAllContacts(getContacts_Return, fail, options);
|
88
|
+
}
|
89
|
+
|
90
|
+
function getContacts_Return(contactsArray)
|
91
|
+
{
|
92
|
+
var names = "";
|
93
|
+
|
94
|
+
for (var i = 0; i < contactsArray.length; i++) {
|
95
|
+
var con = new Contact();
|
96
|
+
con.firstName = contactsArray[i].firstName;
|
97
|
+
con.lastName = contactsArray[i].lastName;
|
98
|
+
con.phoneNumber = contactsArray[i].phoneNumber;
|
99
|
+
con.address = contactsArray[i].address;
|
100
|
+
names += con.displayName();
|
101
|
+
|
102
|
+
if (i+1 != contactsArray.length)
|
103
|
+
names += ",";
|
104
|
+
}
|
105
|
+
|
106
|
+
navigator.notification.loadingStop();
|
107
|
+
navigator.notification.alert(names, "Contacts Returned", "Dismiss");
|
108
|
+
}
|
109
|
+
|
110
|
+
var __editDisplayFirstContact = false;
|
111
|
+
function displayFirstContact(allowsEditing)
|
112
|
+
{
|
113
|
+
var options = { pageSize : 1, pageNumber: 1 };
|
114
|
+
__editDisplayFirstContact = allowsEditing;
|
115
|
+
navigator.ContactManager.getAllContacts(displayFirstContact_Return, null, options);
|
116
|
+
}
|
117
|
+
|
118
|
+
function displayFirstContact_Return(contactsArray)
|
119
|
+
{
|
120
|
+
var options = { allowsEditing: __editDisplayFirstContact };
|
121
|
+
|
122
|
+
for (var i = 0; i < contactsArray.length; i++) {
|
123
|
+
navigator.ContactManager.displayContact(contactsArray[i].recordID, null, options);
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
function contactsCount(){
|
128
|
+
debug.log("contactCount");
|
129
|
+
navigator.ContactManager.contactsCount(showContactsCount);
|
130
|
+
}
|
131
|
+
|
132
|
+
function showContactsCount(count){
|
133
|
+
alert("Number of contacts: " + count);
|
134
|
+
}
|
135
|
+
|
136
|
+
function addContact(gui){
|
137
|
+
var sample_contact = { 'firstName': 'John', 'lastName' : 'Smith', 'phoneNumber': '555-5555' };
|
138
|
+
|
139
|
+
if (gui) {
|
140
|
+
navigator.ContactManager.newContact(sample_contact, null, { 'gui': true });
|
141
|
+
} else {
|
142
|
+
var firstName = prompt("Enter a first name", sample_contact.firstName);
|
143
|
+
if (firstName) {
|
144
|
+
var lastName = prompt("Enter a last name", sample_contact.lastName);
|
145
|
+
if (lastName) {
|
146
|
+
var phoneNumber = prompt("Enter a phone number", sample_contact.phoneNumber);
|
147
|
+
if (phoneNumber) {
|
148
|
+
sample_contact = { 'firstName': firstName, 'lastName' : lastName, 'phoneNumber' : phoneNumber };
|
149
|
+
navigator.ContactManager.newContact(sample_contact, chooseContact_Return);
|
150
|
+
}
|
151
|
+
}
|
152
|
+
}
|
153
|
+
}
|
154
|
+
}
|
155
|
+
|
156
|
+
function chooseContact(allowsEditing)
|
157
|
+
{
|
158
|
+
var options = { allowsEditing: allowsEditing };
|
159
|
+
navigator.ContactManager.chooseContact(chooseContact_Return, options);
|
160
|
+
}
|
161
|
+
|
162
|
+
function chooseContact_Return(contact)
|
163
|
+
{
|
164
|
+
if (contact) {
|
165
|
+
navigator.notification.alert(contact.firstName + " " + contact.lastName, "Contact Returned", "Dismiss");
|
166
|
+
}
|
167
|
+
}
|
168
|
+
|
169
|
+
function removeContact()
|
170
|
+
{
|
171
|
+
navigator.ContactManager.chooseContact(removeContact_Return, null);
|
172
|
+
}
|
173
|
+
|
174
|
+
function removeContact_Return(contact)
|
175
|
+
{
|
176
|
+
if (contact) {
|
177
|
+
navigator.ContactManager.removeContact(contact.recordID, removeContact_Success, null);
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
181
|
+
function removeContact_Success(contact)
|
182
|
+
{
|
183
|
+
if (contact) {
|
184
|
+
navigator.notification.alert(contact.firstName + " " + contact.lastName, "Contact Removed", "Dismiss");
|
185
|
+
}
|
186
|
+
}
|
187
|
+
|
188
|
+
|
189
|
+
function watchAccel() {
|
190
|
+
debug.log("watchAccel");
|
191
|
+
var suc = function(a){
|
192
|
+
document.getElementById('x').innerHTML = roundNumber(a.x);
|
193
|
+
document.getElementById('y').innerHTML = roundNumber(a.y);
|
194
|
+
document.getElementById('z').innerHTML = roundNumber(a.z);
|
195
|
+
};
|
196
|
+
var fail = function(){};
|
197
|
+
var opt = {};
|
198
|
+
opt.frequency = 100;
|
199
|
+
timer = navigator.accelerometer.watchAcceleration(suc,fail,opt);
|
200
|
+
}
|
201
|
+
|
202
|
+
function roundNumber(num) {
|
203
|
+
var dec = 3;
|
204
|
+
var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
|
205
|
+
return result;
|
206
|
+
}
|
207
|
+
|
208
|
+
|
209
|
+
function getPhoto() {
|
210
|
+
|
211
|
+
DebugConsole.prototype.log("Test");
|
212
|
+
PhoneGap.exec('Image.test');
|
213
|
+
|
214
|
+
}
|
215
|
+
|
216
|
+
function preventBehavior(e) {
|
217
|
+
e.preventDefault();
|
218
|
+
};
|
219
|
+
|
220
|
+
PhoneGap.addConstructor(function(){
|
221
|
+
document.addEventListener("touchmove", preventBehavior, false);
|
222
|
+
deviceInfo();
|
223
|
+
document.addEventListener('orientationChanged', function(e) { debug.log("Orientation changed to " + e.orientation); }, false);
|
224
|
+
});
|
225
|
+
|
226
|
+
</script>
|
227
|
+
</head>
|
228
|
+
<body id="stage" class="theme">
|
229
|
+
<!--
|
230
|
+
<a href="javascript:addContact(true)">New Contact (GUI)</a>
|
231
|
+
<br />
|
232
|
+
<a href="javascript:addContact(false)">New Contact (API)</a>
|
233
|
+
<br />
|
234
|
+
<a href="javascript:getContacts(1,1)">Get 1st Contact (query)</a>
|
235
|
+
<br />
|
236
|
+
<a href="javascript:displayFirstContact(false)">DISPLAY 1st Contact (by recordID)</a>
|
237
|
+
<br />
|
238
|
+
<a href="javascript:displayFirstContact(true)">DISPLAY AND EDIT 1st Contact (by recordID)</a>
|
239
|
+
<br />
|
240
|
+
<a href="javascript:getContacts(5,1)">Get 1st Page of Contacts, with Page size of 5</a>
|
241
|
+
<br />
|
242
|
+
<a href="javascript:getContacts(5,2)">Get 2nd Page of Contacts, with Page size of 5</a>
|
243
|
+
<br />
|
244
|
+
<a href="javascript:getContacts(20,1)">Get All Contacts (MAXING TO 20)</a>
|
245
|
+
<br />
|
246
|
+
<a href="javascript:getContactsPrompt()">Get All Contacts (PROMPT)</a>
|
247
|
+
<br />
|
248
|
+
<a href="javascript:getContacts()">Get ALL Contacts (WARNING: may be huge)</a>
|
249
|
+
<br />
|
250
|
+
<a href="javascript:contactsCount()">Contacts Count</a>
|
251
|
+
<br />
|
252
|
+
<a href="javascript:chooseContact(true)">Choose Contact to Edit</a>
|
253
|
+
<br />
|
254
|
+
<a href="javascript:chooseContact()">Choose Contact</a>
|
255
|
+
<br />
|
256
|
+
<a href="javascript:removeContact()">Choose Contact to Remove</a>
|
257
|
+
<br />
|
258
|
+
<a href="javascript:showLoadingScreen()">Load start</a>
|
259
|
+
<br />
|
260
|
+
-->
|
261
|
+
<div id="Page1">
|
262
|
+
<h2>this file is located at iphone/www/index.html</h2>
|
263
|
+
<div id="info" class="Panel">
|
264
|
+
<table>
|
265
|
+
<tr>
|
266
|
+
<td>
|
267
|
+
<h4>Platform: <span id="platform"> </span></h4>
|
268
|
+
</td>
|
269
|
+
<td>
|
270
|
+
<h4>Version: <span id="version"> </span></h4>
|
271
|
+
</td>
|
272
|
+
</tr>
|
273
|
+
<tr>
|
274
|
+
<td colspan="2">
|
275
|
+
<h4>Device Name: <span id="devicename"> </span></h4>
|
276
|
+
</td>
|
277
|
+
</tr>
|
278
|
+
<tr>
|
279
|
+
<td colspan="2">
|
280
|
+
<h4>UUID: <span id="uuid"> </span></h4>
|
281
|
+
</td>
|
282
|
+
</tr>
|
283
|
+
</table>
|
284
|
+
</div>
|
285
|
+
<dl id="accel-data">
|
286
|
+
<dt>X:</dt><dd id="x"> </dd>
|
287
|
+
<dt>Y:</dt><dd id="y"> </dd>
|
288
|
+
<dt>Z:</dt><dd id="z"> </dd>
|
289
|
+
</dl>
|
290
|
+
|
291
|
+
<a href="#" class="btn large" onclick="watchAccel();">Watch Accelerometer</a>
|
292
|
+
<a href="#" class="btn large" onclick="getLocation();">Get Location</a>
|
293
|
+
<a href="tel:411" class="btn">Call 411</a>
|
294
|
+
<a href="#" class="btn" onclick="customAlert();">Custom Alert</a>
|
295
|
+
<a href="#" class="btn" onclick="beep();">Beep</a>
|
296
|
+
<a href="#" class="btn" onclick="vibrate();">Vibrate</a>
|
297
|
+
<a href="#" class="btn" onclick="getPhoto()">Picture</a>
|
298
|
+
</div>
|
299
|
+
<div id="Page2" style="display: none">
|
300
|
+
<a href="#" class="btn large" onclick="getContact();">Get Fourth Contact</a>
|
301
|
+
</div>
|
302
|
+
</body>
|
303
|
+
</html>
|
data/lib/phonegap.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
%w(devices/android devices/iphone devices/blackberry).each { |x| require x }
|
2
|
+
#
|
3
|
+
# Provides utilities for generating a PhoneGap application and unifies the build process for each of the supported mobile platforms.
|
4
|
+
#
|
5
|
+
class PhoneGap
|
6
|
+
|
7
|
+
include Iphone
|
8
|
+
include Android
|
9
|
+
include Blackberry
|
10
|
+
|
11
|
+
# outputs the current version of PhoneGap
|
12
|
+
# FIXME needs to pull from sauce repo found at install path
|
13
|
+
def version
|
14
|
+
'0.7.0'
|
15
|
+
end
|
16
|
+
|
17
|
+
# helper for getting the install path of phonegap
|
18
|
+
def install_path
|
19
|
+
File.expand_path('~/.phonegap')
|
20
|
+
end
|
21
|
+
|
22
|
+
# creates an app skeleton
|
23
|
+
def generate(path)
|
24
|
+
generate_path = File.join(Dir.pwd,path)
|
25
|
+
template_path = File.join(File.dirname(__FILE__),'generate')
|
26
|
+
`cp -rf #{ template_path} #{ generate_path }`
|
27
|
+
e=<<-E
|
28
|
+
|
29
|
+
Generated a fresh PhoneGap application!
|
30
|
+
|
31
|
+
#{ path }/
|
32
|
+
|
|
33
|
+
|- config/
|
34
|
+
| |- bootstrap.js
|
35
|
+
| |- iphone-dev-cert.txt
|
36
|
+
| |- android-dev-cert.txt
|
37
|
+
| '- blackberry-dev-cert.txt
|
38
|
+
|
|
39
|
+
'- www/
|
40
|
+
|- assets/
|
41
|
+
| |- css/
|
42
|
+
| |- js/
|
43
|
+
| '- images/
|
44
|
+
|
|
45
|
+
'- index.html
|
46
|
+
|
47
|
+
For more information, tutorials, documentation and quickstarts go to http://phonegap.com
|
48
|
+
|
49
|
+
E
|
50
|
+
trim(e)
|
51
|
+
end
|
52
|
+
|
53
|
+
# builds a phonegap web application to all supported platforms
|
54
|
+
def build(path)
|
55
|
+
build_iphone(path)
|
56
|
+
build_android(path)
|
57
|
+
build_blackberry(path)
|
58
|
+
end
|
59
|
+
|
60
|
+
# outputs a tidy report of which PhoneGap supported SDK's are installed
|
61
|
+
def report
|
62
|
+
report =<<-E
|
63
|
+
|
64
|
+
PhoneGap 0.7.0
|
65
|
+
-------------------
|
66
|
+
|
67
|
+
Supported Platforms
|
68
|
+
-------------------
|
69
|
+
iPhone ............ #{ iphone_supported? ? 'yes' : 'no!' } .... #{ iphone_supported? ? '3.0' : 'Download and install from http://developer.apple.com' }
|
70
|
+
Android .......... #{ android_supported? ? 'yes' : 'no!' } .... #{ android_supported? ? '???' : 'Download and install from http://code.google.com/p/android' }
|
71
|
+
BlackBerry ........ #{ blackberry_supported? ? 'yes' : 'no!' } .... #{ blackberry_supported? ? '???' : 'Download and install from http://developer.rim.com' }
|
72
|
+
|
73
|
+
E
|
74
|
+
trim(report)
|
75
|
+
end
|
76
|
+
|
77
|
+
# helper for removing code indentation whitespace
|
78
|
+
def trim(str)
|
79
|
+
str.gsub(' ','')
|
80
|
+
end
|
81
|
+
end
|
data/phonegap.gemspec
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{phonegap}
|
5
|
+
s.version = "0.2.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Brian LeRoux"]
|
9
|
+
s.date = %q{2009-07-24}
|
10
|
+
s.default_executable = %q{phonegap}
|
11
|
+
s.email = %q{brian@westcoastlogic.com}
|
12
|
+
s.executables = ["phonegap"]
|
13
|
+
s.extra_rdoc_files = [
|
14
|
+
"LICENSE",
|
15
|
+
"README.md"
|
16
|
+
]
|
17
|
+
s.files = [
|
18
|
+
".document",
|
19
|
+
".gitignore",
|
20
|
+
"LICENSE",
|
21
|
+
"README.md",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"bin/phonegap",
|
25
|
+
"lib/devices/android.rb",
|
26
|
+
"lib/devices/blackberry.rb",
|
27
|
+
"lib/devices/iphone.rb",
|
28
|
+
"lib/generate/config/android-dev-cert.txt",
|
29
|
+
"lib/generate/config/blackberry-dev-cert.txt",
|
30
|
+
"lib/generate/config/bootstrap.js",
|
31
|
+
"lib/generate/config/iphone-dev-cert.txt",
|
32
|
+
"lib/generate/www/assets/css/master.css",
|
33
|
+
"lib/generate/www/assets/js/phongap.js",
|
34
|
+
"lib/generate/www/index.html",
|
35
|
+
"lib/phonegap.rb",
|
36
|
+
"phonegap.gemspec",
|
37
|
+
"test/phonegap-dev_test.rb",
|
38
|
+
"test/test_helper.rb"
|
39
|
+
]
|
40
|
+
s.homepage = %q{http://github.com/brianleroux/phonegap-dev}
|
41
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
42
|
+
s.require_paths = ["lib"]
|
43
|
+
s.rubyforge_project = %q{phonegap}
|
44
|
+
s.rubygems_version = %q{1.3.5}
|
45
|
+
s.summary = %q{Command line utilities for PhoneGap.}
|
46
|
+
s.test_files = [
|
47
|
+
"test/phonegap-dev_test.rb",
|
48
|
+
"test/test_helper.rb"
|
49
|
+
]
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
53
|
+
s.specification_version = 3
|
54
|
+
|
55
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
56
|
+
else
|
57
|
+
end
|
58
|
+
else
|
59
|
+
end
|
60
|
+
end
|