brianleroux-phonegap 0.1.0

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.
@@ -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">&nbsp;</span></h4>
268
+ </td>
269
+ <td>
270
+ <h4>Version: <span id="version">&nbsp;</span></h4>
271
+ </td>
272
+ </tr>
273
+ <tr>
274
+ <td colspan="2">
275
+ <h4>Device Name: <span id="devicename">&nbsp;</span></h4>
276
+ </td>
277
+ </tr>
278
+ <tr>
279
+ <td colspan="2">
280
+ <h4>UUID: <span id="uuid">&nbsp;</span></h4>
281
+ </td>
282
+ </tr>
283
+ </table>
284
+ </div>
285
+ <dl id="accel-data">
286
+ <dt>X:</dt><dd id="x">&nbsp;</dd>
287
+ <dt>Y:</dt><dd id="y">&nbsp;</dd>
288
+ <dt>Z:</dt><dd id="z">&nbsp;</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>
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+ %w(optparse optparse/time ostruct pp FileUtils phonegap).each { |x| require x }
3
+ #
4
+ # Wraps the command line and passes switches and options back to the PhoneGap class.
5
+ #
6
+ class PhoneGapConsole
7
+ def self.parse(args)
8
+ p = PhoneGap.new
9
+
10
+ opts = OptionParser.new do |opts|
11
+ b = <<-E
12
+
13
+ PhoneGap #{ p.version }
14
+ --------------
15
+ Usage: phonegap [options]
16
+
17
+ E
18
+ opts.banner = b.gsub(" ","")
19
+
20
+ opts.on("-g", "--generate PATH", "Generates a new PhoneGap application skeleton.") do |path|
21
+ puts p.generate(path)
22
+ exit
23
+ end
24
+
25
+ opts.on("-b", "--build PATH", "Compiles your PhoneGapp application for supported platforms.") do |path|
26
+ puts p.build(path)
27
+ exit
28
+ end
29
+
30
+ opts.on("-r", "--report", "Generates a report for supported SDK's.") do
31
+ puts p.report
32
+ exit
33
+ end
34
+
35
+ opts.on_tail("-h", "--help", "Display this message.") do
36
+ puts "#{ opts }\n"
37
+ exit
38
+ end
39
+
40
+ opts.on_tail("-v", "--version", "Display the version.") do
41
+ puts p.version
42
+ exit
43
+ end
44
+ end
45
+ opts.parse!(args)
46
+ #options
47
+ end
48
+ end
49
+
50
+ pp PhoneGapConsole.parse(ARGV)
data/lib/phonegap.rb ADDED
@@ -0,0 +1,79 @@
1
+ %w(ftools FileUtils 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
+ `cp -rf generate #{path}`
25
+ e=<<-E
26
+
27
+ Generated a fresh PhoneGap application!
28
+
29
+ #{ path }/
30
+ |
31
+ |- config/
32
+ | |- bootstrap.js
33
+ | |- iphone-dev-cert.txt
34
+ | |- android-dev-cert.txt
35
+ | '- blackberry-dev-cert.txt
36
+ |
37
+ '- www/
38
+ |- assets/
39
+ | |- css/
40
+ | |- js/
41
+ | '- images/
42
+ |
43
+ '- index.html
44
+
45
+ For more information, tutorials, documentation and quickstarts go to http://phonegap.com
46
+
47
+ E
48
+ trim(e)
49
+ end
50
+
51
+ # builds a phonegap web application to all supported platforms
52
+ def build(path)
53
+ build_iphone(path)
54
+ build_android(path)
55
+ build_blackberry(path)
56
+ end
57
+
58
+ # outputs a tidy report of which PhoneGap supported SDK's are installed
59
+ def report
60
+ report =<<-E
61
+
62
+ PhoneGap 0.7.0
63
+ -------------------
64
+
65
+ Supported Platforms
66
+ -------------------
67
+ iPhone ............ #{ iphone_supported? ? 'yes' : 'no!' } .... #{ iphone_supported? ? '3.0' : 'Download and install from http://developer.apple.com' }
68
+ Android .......... #{ android_supported? ? 'yes' : 'no!' } .... #{ android_supported? ? '???' : 'Download and install from http://code.google.com/p/android' }
69
+ BlackBerry ........ #{ blackberry_supported? ? 'yes' : 'no!' } .... #{ blackberry_supported? ? '???' : 'Download and install from http://developer.rim.com' }
70
+
71
+ E
72
+ trim(report)
73
+ end
74
+
75
+ # helper for removing code indentation whitespace
76
+ def trim(str)
77
+ str.gsub(' ','')
78
+ end
79
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class PhonegapDevTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'phonegap-dev'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brianleroux-phonegap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian LeRoux
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-14 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: brian@westcoastlogic.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.md
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.md
30
+ - Rakefile
31
+ - VERSION
32
+ - lib/devices/android.rb
33
+ - lib/devices/blackberry.rb
34
+ - lib/devices/iphone.rb
35
+ - lib/generate/config/android-dev-cert.txt
36
+ - lib/generate/config/blackberry-dev-cert.txt
37
+ - lib/generate/config/bootstrap.js
38
+ - lib/generate/config/iphone-dev-cert.txt
39
+ - lib/generate/www/assets/css/master.css
40
+ - lib/generate/www/assets/js/phongap.js
41
+ - lib/generate/www/index.html
42
+ - lib/phonegap-console.rb
43
+ - lib/phonegap.rb
44
+ - test/phonegap-dev_test.rb
45
+ - test/test_helper.rb
46
+ has_rdoc: true
47
+ homepage: http://github.com/brianleroux/phonegap-dev
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --charset=UTF-8
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements: []
66
+
67
+ rubyforge_project: phonegap
68
+ rubygems_version: 1.2.0
69
+ signing_key:
70
+ specification_version: 2
71
+ summary: TODO
72
+ test_files:
73
+ - test/phonegap-dev_test.rb
74
+ - test/test_helper.rb