Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

phonegap 1.0.0rc1-SNAPSHOT

  • Loading branch information...
commit a6b8f28ee06fb476ce6b43e1dc1a7a5780a8a49d 1 parent b9d0643
@don authored
View
2  .classpath
@@ -3,7 +3,7 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
- <classpathentry kind="lib" path="/usr/local/phonegap/Android/phonegap.0.9.6.jar"/>
+ <classpathentry kind="lib" path="lib/phonegap-1.0.0rc1-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/phonegap-nfc.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
View
2  AndroidManifest.xml
@@ -32,7 +32,7 @@
<application android:debuggable="true" android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:configChanges="orientation|keyboardHidden" android:name=".RockPaperScissors"
- android:label="@string/app_name">
+ android:label="@string/app_name" android:screenOrientation="nosensor">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
View
2  README.md
@@ -8,7 +8,7 @@ Demo web app that allows you to play Rock Paper Scissors with another user via N
Requires
* Google Nexus S phone
-* PhoneGap 0.9.6+
+* PhoneGap 1.0
* phonegap-nfc plugin
See [phonegap-nfc](https://github.com/chariotsolutions/phonegap-nfc) for more info
View
4 assets/www/index.html
@@ -4,8 +4,8 @@
<meta name="viewport" content="width=320; user-scalable=no" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Rock Paper Scissors</title>
- <link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title" charset="utf-8">
- <script type="text/javascript" charset="utf-8" src="phonegap.0.9.6.js"></script>
+ <link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title" />
+ <script type="text/javascript" charset="utf-8" src="phonegap-1.0.0rc1-SNAPSHOT.js"></script>
<script type="text/javascript" charset="utf-8" src="phonegap-nfc.js"></script>
<script type="text/javascript" charset="utf-8" src="main.js"></script>
</head>
View
49 assets/www/main.js
@@ -1,16 +1,23 @@
/*global NdefPlugin, Ndef */
-var choice = null;
+var choice = null,
+ listening = false,
+ mimeType = "game/rockpaperscissors";
-function onNfc(nfcEvent) {
- console.log(JSON.stringify(nfcEvent.tagData));
+function stop() {
+ navigator.nfc.unshareTag();
+ listening = false;
+ // TODO deselect button. blur doesn't work
+}
+function onNfc(nfcEvent) {
+ if (!listening) {
+ return;
+ }
+
var records = nfcEvent.tagData,
opponentsChoice = Ndef.bytesToString(records[0].payload),
result;
- // If choice is null, prompt the user or wait for a choice, then determine the winner
-
- // TODO clean up logic, doesn't handle edge cases
if (choice === opponentsChoice) {
result = "tie";
} else if (choice === "Rock" && opponentsChoice === "Scissors") {
@@ -24,22 +31,30 @@ function onNfc(nfcEvent) {
}
if (result === "tie") {
- alert("Tie! " + choice);
+ navigator.notification.alert(choice + " === " + opponentsChoice, stop, "Tie", "Meh");
} else if (result === "win") {
- alert("You WIN! " + choice + " beats " + opponentsChoice); // TODO grammar for Scissors
+ navigator.notification.alert(message(choice, opponentsChoice), stop, "You Win!", "OK");
} else {
- alert("You LOOSE! " + opponentsChoice + " beats " + choice);
+ navigator.notification.alert(message(opponentsChoice, choice), stop, "You Lose", "Bummer");
}
navigator.notification.vibrate(100);
}
+function message(win, lose) {
+ if (/s$/.test(win)) {
+ return win + " beat " + lose;
+ } else {
+ return win + " beats " + lose;
+ }
+}
+
function choose(text) {
choice = text;
var ndefMessage = [
- Ndef.mimeMediaRecord("game/rockpaperscissors", Ndef.stringToBytes(choice))
+ Ndef.mimeMediaRecord(mimeType, Ndef.stringToBytes(choice))
];
- window.plugins.NdefPlugin.p2p(
+ navigator.nfc.shareTag(
ndefMessage,
function () {
navigator.notification.vibrate(100);
@@ -47,11 +62,11 @@ function choose(text) {
alert("Failed to share tag.");
}
);
+ listening = true;
}
var ready = function () {
- var mimeType = "game/rockpaperscissors",
- buttons = document.getElementsByTagName('button');
+ var buttons = document.getElementsByTagName('button');
for (var i = 0; i < buttons.length; i++) {
buttons[i].addEventListener("click", function () { choose(this.innerHTML); }, false);
@@ -65,12 +80,8 @@ var ready = function () {
alert('Failed to register mime type ' + mimeType + ' with NFC');
}
- window.plugins.NdefPlugin.addMimeTypeListener(mimeType, onNfc, win, fail);
- // don't want this but need as a hack
- window.plugins.NdefPlugin.addNdefFormattableListener(function () { alert("This tag is formattable"); });
+ navigator.nfc.addMimeTypeListener(mimeType, onNfc, win, fail);
};
-// deviceready is being called before the plugins finish initializing
-// add setTimeout as a kludge until the real problem is fixed
-document.addEventListener('deviceready', function () { window.setTimeout(ready, 500); }, false);
+document.addEventListener('deviceready', ready, false);
View
141 assets/www/phonegap.0.9.6.js → assets/www/phonegap-1.0.0rc1-SNAPSHOT.js
@@ -365,10 +365,6 @@ PhoneGap.Channel.join(function() {
// Fire onDeviceReady event once all constructors have run and PhoneGap info has been
// received from native side, and any user defined initialization channels.
PhoneGap.Channel.join(function() {
-
- // Turn off app loading dialog
- navigator.notification.activityStop();
-
PhoneGap.onDeviceReady.fire();
// Fire the onresume event, since first one happens before JavaScript is loaded
@@ -928,22 +924,6 @@ PhoneGap.includeJavascript = function(jsfile, successCallback) {
id.appendChild(el);
};
-/**
- * This class is provided to bridge the gap between the way plugins were setup in 0.9.3 and 0.9.4.
- * Users should be calling navigator.add.addService() instead of PluginManager.addService().
- * @class
- * @deprecated
- */
-var PluginManager = {
- addService: function(serviceType, className) {
- try {
- navigator.app.addService(serviceType, className);
- } catch (e) {
- console.log("Error adding service "+serviceType+": "+e);
- }
- }
-};
-
}
/*
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
@@ -1132,16 +1112,6 @@ App.prototype.clearHistory = function() {
};
/**
- * Add a class that implements a service.
- *
- * @param serviceType
- * @param className
- */
-App.prototype.addService = function(serviceType, className) {
- PhoneGap.exec(null, null, "App", "addService", [serviceType, className]);
-};
-
-/**
* Override the default behavior of the Android back button.
* If overridden, when the back button is pressed, the "backKeyDown" JavaScript event will be fired.
*
@@ -1594,17 +1564,14 @@ PhoneGap.addResource("contact");
* @param {Array.<ContactAddress>} addresses array of addresses
* @param {Array.<ContactField>} ims instant messaging user ids
* @param {Array.<ContactOrganization>} organizations
-* @param {DOMString} revision date contact was last updated
* @param {DOMString} birthday contact's birthday
-* @param {DOMString} gender contact's gender
* @param {DOMString} note user notes about contact
* @param {Array.<ContactField>} photos
* @param {Array.<ContactField>} categories
* @param {Array.<ContactField>} urls contact's web sites
-* @param {DOMString} timezone the contacts time zone
*/
var Contact = function (id, displayName, name, nickname, phoneNumbers, emails, addresses,
- ims, organizations, revision, birthday, gender, note, photos, categories, urls, timezone) {
+ ims, organizations, birthday, note, photos, categories, urls) {
this.id = id || null;
this.rawId = null;
this.displayName = displayName || null;
@@ -1615,14 +1582,11 @@ var Contact = function (id, displayName, name, nickname, phoneNumbers, emails, a
this.addresses = addresses || null; // ContactAddress[]
this.ims = ims || null; // ContactField[]
this.organizations = organizations || null; // ContactOrganization[]
- this.revision = revision || null;
this.birthday = birthday || null;
- this.gender = gender || null;
this.note = note || null;
this.photos = photos || null; // ContactField[]
this.categories = categories || null; // ContactField[]
this.urls = urls || null; // ContactField[]
- this.timezone = timezone || null;
};
/**
@@ -1639,11 +1603,10 @@ var ContactError = function() {
*/
ContactError.UNKNOWN_ERROR = 0;
ContactError.INVALID_ARGUMENT_ERROR = 1;
-ContactError.NOT_FOUND_ERROR = 2;
-ContactError.TIMEOUT_ERROR = 3;
-ContactError.PENDING_OPERATION_ERROR = 4;
-ContactError.IO_ERROR = 5;
-ContactError.NOT_SUPPORTED_ERROR = 6;
+ContactError.TIMEOUT_ERROR = 2;
+ContactError.PENDING_OPERATION_ERROR = 3;
+ContactError.IO_ERROR = 4;
+ContactError.NOT_SUPPORTED_ERROR = 5;
ContactError.PERMISSION_DENIED_ERROR = 20;
/**
@@ -1654,7 +1617,7 @@ ContactError.PERMISSION_DENIED_ERROR = 20;
Contact.prototype.remove = function(successCB, errorCB) {
if (this.id === null) {
var errorObj = new ContactError();
- errorObj.code = ContactError.NOT_FOUND_ERROR;
+ errorObj.code = ContactError.UNKNOWN_ERROR;
errorCB(errorObj);
}
else {
@@ -1770,8 +1733,10 @@ var ContactField = function(type, value, pref) {
* @param postalCode
* @param country
*/
-var ContactAddress = function(formatted, streetAddress, locality, region, postalCode, country) {
+var ContactAddress = function(pref, type, formatted, streetAddress, locality, region, postalCode, country) {
this.id = null;
+ this.pref = pref || null;
+ this.type = type || null;
this.formatted = formatted || null;
this.streetAddress = streetAddress || null;
this.locality = locality || null;
@@ -1792,8 +1757,10 @@ var ContactAddress = function(formatted, streetAddress, locality, region, postal
* @param location
* @param desc
*/
-var ContactOrganization = function(name, dept, title) {
+var ContactOrganization = function(pref, type, name, dept, title) {
this.id = null;
+ this.pref = pref || null;
+ this.type = type || null;
this.name = name || null;
this.department = dept || null;
this.title = title || null;
@@ -1816,7 +1783,16 @@ var Contacts = function() {
* @return array of Contacts matching search criteria
*/
Contacts.prototype.find = function(fields, successCB, errorCB, options) {
- PhoneGap.exec(successCB, errorCB, "Contacts", "search", [fields, options]);
+ if (successCB === null) {
+ throw new TypeError("You must specify a success callback for the find command.");
+ }
+ if (fields === null || fields === "undefined" || fields.length === "undefined" || fields.length <= 0) {
+ if (typeof errorCB === "function") {
+ errorCB({"code": ContactError.INVALID_ARGUMENT_ERROR});
+ }
+ } else {
+ PhoneGap.exec(successCB, errorCB, "Contacts", "search", [fields, options]);
+ }
};
/**
@@ -1840,7 +1816,7 @@ Contacts.prototype.create = function(properties) {
/**
* This function returns and array of contacts. It is required as we need to convert raw
* JSON objects into concrete Contact objects. Currently this method is called after
-* navigator.service.contacts.find but before the find methods success call back.
+* navigator.contacts.find but before the find methods success call back.
*
* @param jsonArray an array of JSON Objects that need to be converted to Contact objects.
* @returns an array of Contact objects
@@ -1849,7 +1825,7 @@ Contacts.prototype.cast = function(pluginResult) {
var contacts = [];
var i;
for (i=0; i<pluginResult.message.length; i++) {
- contacts.push(navigator.service.contacts.create(pluginResult.message[i]));
+ contacts.push(navigator.contacts.create(pluginResult.message[i]));
}
pluginResult.message = contacts;
return pluginResult;
@@ -1860,23 +1836,18 @@ Contacts.prototype.cast = function(pluginResult) {
* @constructor
* @param filter used to match contacts against
* @param multiple boolean used to determine if more than one contact should be returned
- * @param updatedSince return only contact records that have been updated on or after the given time
*/
-var ContactFindOptions = function(filter, multiple, updatedSince) {
+var ContactFindOptions = function(filter, multiple) {
this.filter = filter || '';
- this.multiple = multiple || true;
- this.updatedSince = updatedSince || '';
+ this.multiple = multiple || false;
};
/**
* Add the contact interface into the browser.
*/
PhoneGap.addConstructor(function() {
- if(typeof navigator.service === "undefined") {
- navigator.service = {};
- }
- if(typeof navigator.service.contacts === "undefined") {
- navigator.service.contacts = new Contacts();
+ if(typeof navigator.contacts === "undefined") {
+ navigator.contacts = new Contacts();
}
});
}
@@ -2122,10 +2093,6 @@ FileMgr.prototype.getFreeDiskSpace = function(successCallback, errorCallback) {
return PhoneGap.exec(successCallback, errorCallback, "File", "getFreeDiskSpace", []);
};
-FileMgr.prototype.writeAsText = function(fileName, data, append, successCallback, errorCallback) {
- PhoneGap.exec(successCallback, errorCallback, "File", "writeAsText", [fileName, data, append]);
-};
-
FileMgr.prototype.write = function(fileName, data, position, successCallback, errorCallback) {
PhoneGap.exec(successCallback, errorCallback, "File", "write", [fileName, data, position]);
};
@@ -3597,56 +3564,6 @@ if (!PhoneGap.hasResource("network")) {
PhoneGap.addResource("network");
/**
- * This class contains information about any NetworkStatus.
- * @constructor
- */
-var NetworkStatus = function() {
- //this.code = null;
- //this.message = "";
-};
-
-NetworkStatus.NOT_REACHABLE = 0;
-NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK = 1;
-NetworkStatus.REACHABLE_VIA_WIFI_NETWORK = 2;
-
-/**
- * This class provides access to device Network data (reachability).
- * @constructor
- */
-var Network = function() {
- /**
- * The last known Network status.
- * { hostName: string, ipAddress: string,
- remoteHostStatus: int(0/1/2), internetConnectionStatus: int(0/1/2), localWiFiConnectionStatus: int (0/2) }
- */
- this.lastReachability = null;
-};
-
-/**
- * Called by the geolocation framework when the reachability status has changed.
- * @param {Reachibility} reachability The current reachability status.
- */
-// TODO: Callback from native code not implemented for Android
-Network.prototype.updateReachability = function(reachability) {
- this.lastReachability = reachability;
-};
-
-/**
- * Determine if a URI is reachable over the network.
-
- * @param {Object} uri
- * @param {Function} callback
- * @param {Object} options (isIpAddress:boolean)
- */
-Network.prototype.isReachable = function(uri, callback, options) {
- var isIpAddress = false;
- if (options && options.isIpAddress) {
- isIpAddress = options.isIpAddress;
- }
- PhoneGap.exec(callback, null, "Network Status", "isReachable", [uri, isIpAddress]);
-};
-
-/**
* This class contains information about the current network Connection.
* @constructor
*/
@@ -3710,7 +3627,7 @@ Connection.prototype.getInfo = function(successCallback, errorCallback) {
PhoneGap.addConstructor(function() {
if (typeof navigator.network === "undefined") {
- navigator.network = new Network();
+ navigator.network = new Object();
}
if (typeof navigator.network.connection === "undefined") {
navigator.network.connection = new Connection();
View
26 assets/www/phonegap-nfc.js
@@ -119,7 +119,7 @@ var Ndef = {
};
-var NdefPlugin = {
+navigator.nfc = {
addMimeTypeListener: function (mime_type, callback, win, fail) {
document.addEventListener("ndef-mime", callback, false);
@@ -140,10 +140,14 @@ var NdefPlugin = {
PhoneGap.exec(win, fail, "NdefPlugin", "writeTag", [ndefMessage]);
},
- p2p: function (ndefMessage, win, fail) {
- PhoneGap.exec(win, fail, "NdefPlugin", "p2p", [ndefMessage]);
+ shareTag: function (ndefMessage, win, fail) {
+ PhoneGap.exec(win, fail, "NdefPlugin", "shareTag", [ndefMessage]);
},
-
+
+ unshareTag: function (win, fail) {
+ PhoneGap.exec(win, fail, "NdefPlugin", "unshareTag", []);
+ },
+
// Java is responsible for calling this method
// Type is ndef-mime, ndef, or ndef-unformatted
fireEvent: function (type, tagData) {
@@ -153,17 +157,3 @@ var NdefPlugin = {
document.dispatchEvent(e);
}
};
-
-/**
- * <ul>
- * <li>Register the NFC Javascript plugin.</li>
- * <li>Also register native call which will be called when this plugin runs</li>
- * </ul>
- */
-PhoneGap.addConstructor(function() {
- // Register the javascript plugin with PhoneGap
- PhoneGap.addPlugin('NdefPlugin', NdefPlugin);
-
- // Register the native class of plugin with PhoneGap
- navigator.app.addService("NdefPlugin", "com.chariotsolutions.nfc.plugin.NdefPlugin");
-});
View
BIN  lib/phonegap-1.0.0rc1-SNAPSHOT.jar
Binary file not shown
View
BIN  lib/phonegap-nfc.jar
Binary file not shown
View
21 res/xml/plugins.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<plugins>
+ <plugin name="App" value="com.phonegap.App"/>
+ <plugin name="Geolocation" value="com.phonegap.GeoBroker"/>
+ <plugin name="Device" value="com.phonegap.Device"/>
+ <plugin name="Accelerometer" value="com.phonegap.AccelListener"/>
+ <plugin name="Compass" value="com.phonegap.CompassListener"/>
+ <plugin name="Media" value="com.phonegap.AudioHandler"/>
+ <plugin name="Camera" value="com.phonegap.CameraLauncher"/>
+ <plugin name="Contacts" value="com.phonegap.ContactManager"/>
+ <plugin name="Crypto" value="com.phonegap.CryptoHandler"/>
+ <plugin name="File" value="com.phonegap.FileUtils"/>
+ <plugin name="Location" value="com.phonegap.GeoBroker"/>
+ <plugin name="Network Status" value="com.phonegap.NetworkManager"/>
+ <plugin name="Notification" value="com.phonegap.Notification"/>
+ <plugin name="Storage" value="com.phonegap.Storage"/>
+ <plugin name="Temperature" value="com.phonegap.TempListener"/>
+ <plugin name="FileTransfer" value="com.phonegap.FileTransfer"/>
+ <plugin name="Capture" value="com.phonegap.Capture"/>
+ <plugin name="NdefPlugin" value="com.chariotsolutions.nfc.plugin.NdefPlugin"/>
+</plugins>
Please sign in to comment.
Something went wrong with that request. Please try again.