Skip to content

Commit

Permalink
Merge branch 'master' of [email protected]:phonegap/phonegap
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Bowser committed Dec 3, 2009
2 parents 4e264c0 + 73b0b76 commit e918f0b
Show file tree
Hide file tree
Showing 22 changed files with 1,573 additions and 227 deletions.
48 changes: 48 additions & 0 deletions blackberry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
PhoneGap BlackBerry
=============================================================
Allows developers to create BlackBerry applications using HTML,
CSS and JavaScript, and bridge into device functionality like
geolocation, SMS, device information, accelerometer, etc. via
a JavaScript API.

Pre-requisites
-------------------------------------------------------------
Your best bet is to check the PhoneGap wiki for detailed
installation and setup instructions:
http://phonegap.pbworks.com/Getting+Started+with+PhoneGap+(BlackBerry)

Create a PhoneGap project with Eclipse
-------------------------------------------------------------
1. Launch Eclipse, go to File->Import->Existing BlackBerry project.
2. Navigate over to where you cloned the git repo, and point it to the phonegap.jdp file located in blackberry/framework/.
3. Modify the contents of the "www" directory to add your own HTML, CSS and Javascript.
4. Before running, right-click on project root and make sure 'Activate for BlackBerry' is checked.
5. Run or debug from Eclipse as desired.
6. When you are satisfied with the application, make sure you sign it! (BlackBerry menu -> Request Signatures)
This step needs to be done every time you change your source code. If you are running in simulator, you do not need
to sign your binaries - it is only necessary for deployment to actual devices.
7. A few ways to deploy to device:
a) Right-click on the project root in Eclipse and click on 'Generate ALX file.' You can then use this
file in RIM's Desktop Manager software to load the binaries directly onto the device.
b) Use the javaloader.exe program that comes with the JDE component packs to load directly onto device. Usage:
javaloader -u load path/to/codfile.cod
The -u parameter specifies loading via USB.
c) Over-the-air installation. Set up your application .jad, .jar and .cod files onto a web server. See RIM's documentation
for more details or this succinct PDF for info: http://assets.handango.com/marketing/developerTeam/BlackBerryOTADeployment.pdf

Building PhoneGap BlackBerry Projects with Apache Ant
-------------------------------------------------------------
You'll need all the prerequisites listed by BB Ant Tools (http://bb-ant-tools.sourceforge.net/). If you want access to building using Ant from Eclipse,
check out http://www.slashdev.ca/2007/05/30/blackberry-development-with-ant-eclipse/ for instructions on how to do it.

1. Once you have cloned the PhoneGap repository, put your HTML, CSS and JavaScript application files in the phonegap/blackberry/framework/src/www folder.
2. Edit the build.xml file in phonegap/blackberry/framework and set the paths at the top of the file, in the <property> elements, to match
your environment setup. Also be sure to set your signature key password in the password <property>.
3. Open up a command-line and, assuming you have Ant on your system PATH, cd over to phonegap/blackberry/framework directory.
4. Run 'ant' from the command-line. It'll default to the 'build' task, which will build your binaries into the 'build' directory. You can also
explicitly specify other tasks to run:
a) 'ant sign': Runs the 'build' task first, and then runs the signature tool on the compiled binary. Make sure to specify the 'password'
property at the top of the build.xml file, otherwise the signature tool will fail!
b) 'ant load-simulator': Runs the 'sign' task first, then copies the signed binaries over to the simulator directory you specified at the top of the
build.xml and finally runs the simulator. You should see your application under the BB Menu -> Downloads.
c) 'ant load-device': Runs the 'sign' task first, then executes the javaloader tool to load the signed binaries onto an attached (via USB) device.
Empty file removed blackberry/framework/README
Empty file.
3 changes: 0 additions & 3 deletions blackberry/framework/README.md

This file was deleted.

71 changes: 71 additions & 0 deletions blackberry/framework/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<project name="PhoneGap BlackBerry Ant Build" default="build">
<taskdef resource="bb-ant-defs.xml" />
<!-- PROPERTY DEFINITION - FILL THESE OUT! -->
<!-- rapc and sigtool require the jde.home property to be set -->
<property name="jde.home" location="C:\eclipse\plugins\net.rim.eide.componentpack4.6.1_4.6.1.27\components\" />
<!-- directory of simulator to copy files to -->
<property name="simulator.home" location="C:\eclipse\plugins\net.rim.eide.componentpack4.6.1_4.6.1.27\components\simulator\" />
<!-- directory of BlackBerry application source code. Should include two directories: a 'com' and a 'www'. -->
<property name="src.dir" location="src" />
<!-- directory where you want the final binaries to be copied to. -->
<property name="build.dir" location="build" />
<!-- name of the binaries to generate (i.e. <blah>.cod, <blah>.jar, etc.) -->
<property name="cod.name" value="AntPGTest" />
<!-- password for the Signature Tool -->
<property name="password" value="myPassword" />
<!-- name of the application, as it appears in the BlackBerry menu -->
<property name="application.name" value="PhoneGap BlackBerry Test" />

<target name="build">
<delete dir="www" />
<mkdir dir="www" />
<delete dir="${build.dir}" />
<mkdir dir="${build.dir}" />
<copy todir="www">
<fileset dir="src/www" />
</copy>
<delete dir="src/www" />
<rapc output="${cod.name}">
<src>
<fileset dir="src" />
<fileset dir="www" />
</src>
<jdp title="${application.name}" />
</rapc>
<mkdir dir="src/www" />
<copy todir="src/www">
<fileset dir="www" />
</copy>
<delete dir="www" />
<copy todir="${build.dir}">
<fileset dir="" includes="*.cod,*.cso,*.debug,*.jad,*.jar,*.csl,*.rapc" />
</copy>
<delete file="${cod.name}.cod" />
<delete file="${cod.name}.cso" />
<delete file="${cod.name}.debug" />
<delete file="${cod.name}.jad" />
<delete file="${cod.name}.jar" />
</target>

<target name="sign" depends="build">
<sigtool codfile="${build.dir}/${cod.name}.cod" password="${password}" />
</target>

<target name="clean">
<delete dir="${build.dir}" />
</target>

<target name="load-simulator" depends="sign">
<copy todir="${simulator.home}">
<fileset dir="${build.dir}" includes="*.cod,*.cso,*.debug,*.jad,*.jar,*.csl,*.rapc" />
</copy>
<exec executable="${simulator.home}/defaultSimulator.bat" dir="${simulator.home}" spawn="true"></exec>
</target>
<target name="load-device" depends="sign">
<exec executable="${jde.home}/bin/JavaLoader.exe" dir="." failonerror="true">
<arg value="-u" />
<arg value="load" />
<arg value="${build.dir}/${cod.name}.cod" />
</exec>
</target>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public CommandManager(PhoneGap phoneGap) {
commands[1] = new ContactsCommand();
commands[2] = new NotificationCommand();
commands[3] = new TelephonyCommand();
commands[4] = new GeoLocationCommand();
commands[4] = new GeoLocationCommand(phoneGap);
commands[5] = new DeviceCommand();
commands[6] = new MediaCommand();
commands[7] = new NetworkCommand(phoneGap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class ContactsCommand implements Command {
private static final int REMOVE_COMMAND = 3;
private static final int NEW_COMMAND = 4;
private static final String CODE = "PhoneGap=contacts";
private static final String CONTACT_MANAGER_JS_NAMESPACE = "navigator.ContactManager";
private static final String CONTACT_MANAGER_JS_NAMESPACE = "navigator.contacts";

private static final String ERROR_NO_CONTACTID = ";alert('[PhoneGap Error] Contact ID not specified during contact removal operation.');";

Expand Down Expand Up @@ -279,7 +279,7 @@ private static void addContactToBuffer(StringBuffer buff, BlackBerryContact cont
// TODO: Eventually extend this to return proper labels/values for differing phone/email types.
buff.append("{");
if (contact.countValues(Contact.EMAIL) > 0) {
buff.append("email:[{'label':'mobile','value':'");
buff.append("emails:[{'types':['mobile'],'address':'");
buff.append(contact.getString(Contact.EMAIL, 0));
buff.append("'}]");
}
Expand All @@ -300,38 +300,24 @@ private static void addContactToBuffer(StringBuffer buff, BlackBerryContact cont
}
if (sentinel) {
if (buff.length() > 1) buff.append(",");
buff.append("phoneNumber:[{'label':'mobile','value':'");
buff.append("phoneNumber:[{'types':['mobile'],'number':'");
buff.append(phoneMobile);
buff.append("'}]");
}
}
// See if there is a meaningful name set for the contact.
if (contact.countValues(Contact.NAME) > 0) {
if (buff.length() > 1) buff.append(",");
buff.append("firstName:'");
buff.append("name:{");
buff.append("givenName:'");
final String[] name = contact.getStringArray(Contact.NAME, 0);
final String firstName = name[Contact.NAME_GIVEN];
final String lastName = name[Contact.NAME_FAMILY];
buff.append((firstName != null ? firstName : "") + "',lastName:'");
buff.append((firstName != null ? firstName : "") + "',familyName:'");
buff.append((lastName != null ? lastName : "") + "'");
}
if (buff.length() > 1) buff.append(",");
buff.append("address:'");
// Build up a meaningful address field.
if (contact.countValues(Contact.ADDR) > 0) {
String address = "";
final String[] addr = contact.getStringArray(Contact.ADDR, 0);
final String street = addr[Contact.ADDR_STREET];
final String city = addr[Contact.ADDR_LOCALITY];
final String state = addr[Contact.ADDR_REGION];
final String country = addr[Contact.ADDR_COUNTRY];
final String postalCode = addr[Contact.ADDR_POSTALCODE];
if (street!=null) address = street.replace('\'',' ');
if (city!=null) if (address.length() > 0) address += ", " + city.replace('\'',' '); else address = city.replace('\'',' ');
if (state!=null) if (address.length() > 0) address += ", " + state.replace('\'',' '); else address = state.replace('\'',' ');
if (country!=null) if (address.length() > 0) address += ", " + country.replace('\'',' '); else address = country.replace('\'',' ');
if (postalCode!=null) if (address.length() > 0) address += ", " + postalCode.replace('\'',' '); else address = postalCode.replace('\'',' ');
buff.append(address);
String formatted = (firstName != null ? firstName : "");
formatted += (lastName != null? " " + lastName : "");
buff.append(",'formatted':'" + formatted + "'}");
}
buff.append("'}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public class DeviceCommand implements Command {

private static final String CODE = "PhoneGap=initialize";
private static final String EMULATOR = "Emulator";
private static final String DEVICE_NAME = ";Device.name = '";
private static final String DEVICE_FLASH = "';Device.flash = ";
private static final String DEVICE_PLATFORM = ";Device.platform = '";
private static final String DEVICE_VENDOR = "';Device.vendor = '";
private static final String DEVICE_BATTERY = "';Device.battery = ";
private static final String DEVICE_VERSION = ";Device.version = '";
private static final String DEVICE_SIMULATOR = "';Device.isSimulator = ";
private static final String DEVICE_CAMERA = ";Device.hasCamera = ";
private static final String DEVICE_UUID = ";Device.uuid = ";
private static final String DEVICE_NAME = ";device.name = '";
private static final String DEVICE_FLASH = "';device.flash = ";
private static final String DEVICE_PLATFORM = ";device.platform = '";
private static final String DEVICE_VENDOR = "';device.vendor = '";
private static final String DEVICE_BATTERY = "';device.battery = ";
private static final String DEVICE_VERSION = ";device.version = '";
private static final String DEVICE_SIMULATOR = "';device.isSimulator = ";
private static final String DEVICE_CAMERA = ";device.hasCamera = ";
private static final String DEVICE_UUID = ";device.uuid = ";
private static final String SEMI_COLON = ";";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import net.rim.blackberry.api.invoke.Invoke;
import net.rim.blackberry.api.invoke.MapsArguments;

import com.nitobi.phonegap.PhoneGap;
import com.nitobi.phonegap.api.Command;
import com.nitobi.phonegap.model.Position;

Expand All @@ -44,24 +45,26 @@ public class GeoLocationCommand implements Command {
private static final int MAP_COMMAND = 0;
private static final int STOP_COMMAND = 1;
private static final int START_COMMAND = 2;
private static final int CHECK_COMMAND = 3;
private static final int CAPTURE_INTERVAL = 5;
private static final String CODE = "PhoneGap=location";
private static final String GEO_NS = "navigator.geolocation.";
private static final String GEO_STOP = GEO_NS + "started = false;" + GEO_NS + "lastPosition = null;";
private static final String GEO_START = GEO_NS + "started = true;";
private static final String GEO_CHECK = GEO_NS + "setLocation(";
private static final String GEO_ERROR = GEO_NS + "setError(";
private static final String GEO_SET_LOCATION = GEO_NS + "setLocation(";
private static final String GEO_SET_ERROR = GEO_NS + "setError(";
private static final String FUNC_SUF = ");";

private static final String ERROR_UNAVAILABLE = "'GPS unavailable on this device.'";
private static final String ERROR_OUTOFSERVICE = "'GPS is out of service on this device.'";

private PhoneGap berryGap;

private Position position;
private boolean availableGPS = true;
private LocationProvider locationProvider;

public GeoLocationCommand() {
public GeoLocationCommand(PhoneGap phoneGap) {
this.berryGap = phoneGap;
try {
locationProvider = LocationProvider.getInstance(null);
// Passing null as the parameter is equal to passing a Criteria that has all fields set to the default values,
Expand Down Expand Up @@ -104,7 +107,6 @@ public String execute(String instruction) {
return GEO_STOP;
case START_COMMAND: locationProvider.setLocationListener(new LocationListenerImpl(this), CAPTURE_INTERVAL, 1, 1);
return GEO_START;
case CHECK_COMMAND: if (position != null) return GEO_CHECK + position.toJavascript() + FUNC_SUF;
}
return null;
}
Expand All @@ -118,7 +120,6 @@ private int getCommand(String instruction) {
if ("map".equals(command)) return MAP_COMMAND;
if ("stop".equals(command)) return STOP_COMMAND;
if ("start".equals(command)) return START_COMMAND;
if ("check".equals(command)) return CHECK_COMMAND;
return -1;
}

Expand All @@ -132,10 +133,11 @@ private void updateLocation(double lat, double lng, float altitude, float accura
position.setHeading(heading);
position.setVelocity(speed);
position.setTimestamp(time);
berryGap.pendingResponses.addElement(GEO_SET_LOCATION + position.toJavascript() + FUNC_SUF);
}

private String setError(String error) {
return GEO_ERROR + error + FUNC_SUF;
return GEO_SET_ERROR + error + FUNC_SUF;
}

private String getLocationDocument() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
public class TelephonyCommand implements Command {

private static final String CODE = "PhoneGap=call";
private static final String CODE = "PhoneGap=send";

public boolean accept(String instruction) {
return instruction != null && instruction.startsWith(CODE);
Expand Down
Loading

0 comments on commit e918f0b

Please sign in to comment.