Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
560 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry exported="true" kind="src" path="/.test.jdw"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/NET_RIM_BLACKBERRY"/> | ||
<classpathentry kind="src" path=".tmp"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#Fri May 15 15:56:25 CEST 2009 | ||
RIM.BLACKBERRY.TYPE=COPY | ||
eclipse.preferences.version=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#Sun Oct 19 18:43:38 PDT 2008 | ||
#Fri May 15 15:56:25 CEST 2009 | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 | ||
org.eclipse.jdt.core.compiler.compliance=1.3 | ||
org.eclipse.jdt.core.compiler.compliance=1.4 | ||
org.eclipse.jdt.core.compiler.source=1.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
33000000=RIMAPPSA2 | ||
52424200=RIM Blackberry Apps API | ||
52434300=RIM Crypto API - Certicom | ||
52434900=RIM Crypto API - Internal | ||
52435200=RIM Crypto API - RIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
## RIM Java Development Environment | ||
# RIM Project file | ||
# | ||
# This file is generated and managed by BlackBerry developer tools. | ||
# It SHOULD NOT BE modified manually. | ||
# | ||
AddOn=0 | ||
AlwaysBuild=0 | ||
[AlxImports | ||
] | ||
AutoRestart=0 | ||
[ClassProtection | ||
] | ||
[CustomBuildFiles | ||
] | ||
[CustomBuildRules | ||
] | ||
[DefFiles | ||
] | ||
[DependsOn | ||
] | ||
ExcludeFromBuildAll=0 | ||
[Files | ||
src\com\nitobi\phonegap\api\Command.java | ||
src\com\nitobi\phonegap\api\impl\GeoLocationCommand.java | ||
src\com\nitobi\phonegap\api\impl\InitializationCommand.java | ||
src\com\nitobi\phonegap\api\impl\TelephonyCommand.java | ||
src\com\nitobi\phonegap\api\impl\VibrationCommand.java | ||
src\com\nitobi\phonegap\model\Position.java | ||
src\com\nitobi\phonegap\PhoneGap.java | ||
src\com\nitobi\phonegap\SecondaryResourceFetchThread.java | ||
src\com\nitobi\phonegap\Utilities.java | ||
] | ||
HaveAlxImports=0 | ||
HaveDefs=0 | ||
HaveImports=0 | ||
[Icons | ||
] | ||
[ImplicitRules | ||
] | ||
[Imports | ||
] | ||
Listing=0 | ||
Options=-quiet | ||
OutputFileName=phonegap | ||
[PackageProtection | ||
] | ||
RibbonPosition=0 | ||
[RolloverIcons | ||
] | ||
RunOnStartup=0 | ||
StartupTier=7 | ||
SystemModule=0 | ||
Title=PhoneGap | ||
Type=0 | ||
UserData=|src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* The MIT License | ||
* ------------------------------------------------------------- | ||
* Copyright (c) 2008, Rob Ellis, Brock Whitten, Brian Leroux, Joe Bowser, Dave Johnson, Nitobi | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package com.nitobi.phonegap.api; | ||
|
||
/** | ||
* Each part of the PhoneGap API. | ||
* | ||
* @author Jose Noheda [jose.noheda@gmail.com] | ||
* | ||
*/ | ||
public interface Command { | ||
|
||
/** | ||
* Executes the request and returns JS code to chang client state. | ||
* | ||
* @param instruction the command to execute | ||
* @return a string with Javascript code or null | ||
*/ | ||
String execute(String instruction); | ||
|
||
/** | ||
* Determines if this command can process a request. | ||
* | ||
* @param instruction the command to execute | ||
* | ||
* @return true if this command understands the petition | ||
*/ | ||
boolean accept(String instruction); | ||
|
||
} |
150 changes: 150 additions & 0 deletions
150
blackberry/src/com/nitobi/phonegap/api/impl/GeoLocationCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/** | ||
* The MIT License | ||
* ------------------------------------------------------------- | ||
* Copyright (c) 2008, Rob Ellis, Brock Whitten, Brian Leroux, Joe Bowser, Dave Johnson, Nitobi | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package com.nitobi.phonegap.api.impl; | ||
|
||
import javax.microedition.location.Location; | ||
import javax.microedition.location.LocationException; | ||
import javax.microedition.location.LocationListener; | ||
import javax.microedition.location.LocationProvider; | ||
|
||
import net.rim.blackberry.api.invoke.Invoke; | ||
import net.rim.blackberry.api.invoke.MapsArguments; | ||
|
||
import com.nitobi.phonegap.api.Command; | ||
import com.nitobi.phonegap.model.Position; | ||
|
||
/** | ||
* Wraps all GPS functions. | ||
* | ||
* @author Jose Noheda | ||
* | ||
*/ | ||
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 = "gap://location"; | ||
|
||
private Position position; | ||
private boolean availableGPS = true; | ||
private LocationProvider locationProvider; | ||
|
||
public GeoLocationCommand() { | ||
try { | ||
locationProvider = LocationProvider.getInstance(null); | ||
} catch (LocationException e) { | ||
availableGPS = false; | ||
} | ||
} | ||
|
||
/** | ||
* Able to run the <i>location</i> command (all options). | ||
* Ex: gap://location/start | ||
*/ | ||
public boolean accept(String instruction) { | ||
return instruction != null && instruction.startsWith(CODE); | ||
} | ||
|
||
/** | ||
* Deletes the last valid obtained position. | ||
*/ | ||
public void clearPosition() { | ||
position = null; | ||
} | ||
|
||
/** | ||
* Executes the following sub-commands: | ||
* START: Initiliazes the internal GPS module | ||
* STOP: Stops GPS module (saving battery life) | ||
* CHECK: Reads latest position available | ||
* MAP: Invokes the internal MAP application | ||
*/ | ||
public String execute(String instruction) { | ||
if (!availableGPS) return ";alert('GPS not available');"; | ||
switch (getCommand(instruction)) { | ||
case MAP_COMMAND: if (position != null) Invoke.invokeApplication(Invoke.APP_TYPE_MAPS, new MapsArguments(MapsArguments.ARG_LOCATION_DOCUMENT, getLocationDocument())); | ||
break; | ||
case STOP_COMMAND: clearPosition(); | ||
locationProvider.setLocationListener(null, 0, 0, 0); | ||
return ";navigator.geolocation.started = false;"; | ||
case START_COMMAND: locationProvider.setLocationListener(new LocationListenerImpl(this), CAPTURE_INTERVAL, 1, 1); | ||
return ";navigator.geolocation.started = true;"; | ||
case CHECK_COMMAND: if (position != null) return ";navigator.geolocation.lastPosition = " + position.toJavascript() + ";"; | ||
} | ||
return null; | ||
} | ||
|
||
private int getCommand(String instruction) { | ||
String command = instruction.substring(instruction.lastIndexOf('/') + 1); | ||
if ("map".equals(command)) return MAP_COMMAND; | ||
if ("start".equals(command)) return START_COMMAND; | ||
if ("check".equals(command)) return CHECK_COMMAND; | ||
return -1; | ||
} | ||
|
||
private void updateLocation(double lat, double lng, float speed, float heading, float altitude) { | ||
position = new Position(); | ||
position.setLatitude(lat); | ||
position.setLongitude(lng); | ||
position.setVelocity(speed); | ||
position.setHeading(heading); | ||
position.setAltitude(altitude); | ||
} | ||
|
||
private String getLocationDocument() { | ||
StringBuffer location = new StringBuffer("<location-document><location x=\""); | ||
location.append(position.getLatitude()).append("\" y=\""); | ||
location.append(position.getLongitude()).append("\" label=\"Here\" description=\"Unavailable\""); | ||
location.append("/></location-document>"); | ||
return location.toString(); | ||
} | ||
|
||
/** | ||
* Implementation of the LocationListener interface | ||
*/ | ||
private class LocationListenerImpl implements LocationListener { | ||
|
||
private GeoLocationCommand command; | ||
|
||
public LocationListenerImpl(GeoLocationCommand command) { | ||
this.command = command; | ||
} | ||
|
||
public void locationUpdated(LocationProvider provider, Location location) { | ||
if (location.isValid()) { | ||
float heading = location.getCourse(); | ||
double longitude = location.getQualifiedCoordinates().getLongitude(); | ||
double latitude = location.getQualifiedCoordinates().getLatitude(); | ||
float altitude = location.getQualifiedCoordinates().getAltitude(); | ||
float speed = location.getSpeed(); | ||
command.updateLocation(latitude, longitude, speed, heading, altitude); | ||
} else command.clearPosition(); | ||
} | ||
|
||
public void providerStateChanged(LocationProvider provider, int newState) {} | ||
} | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
blackberry/src/com/nitobi/phonegap/api/impl/InitializationCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* The MIT License | ||
* ------------------------------------------------------------- | ||
* Copyright (c) 2008, Rob Ellis, Brock Whitten, Brian Leroux, Joe Bowser, Dave Johnson, Nitobi | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package com.nitobi.phonegap.api.impl; | ||
|
||
import com.nitobi.phonegap.api.Command; | ||
import net.rim.device.api.system.DeviceInfo; | ||
|
||
/** | ||
* Configures the Device API. | ||
* | ||
* @author Jose Noheda [jose.noheda@gmail.com] | ||
* | ||
*/ | ||
public class InitializationCommand implements Command { | ||
|
||
private static final String CODE = "gap://initialize"; | ||
|
||
/** | ||
* Able to run the <i>initialize</i> command (usually onLoad). | ||
*/ | ||
public boolean accept(String instruction) { | ||
return instruction != null && instruction.startsWith(CODE); | ||
} | ||
|
||
/** | ||
* Fills the JS variable Device with: | ||
* Model | ||
* Flash memory available | ||
* Platform | ||
* Vendor | ||
* Battery | ||
* Software version | ||
* Camera support | ||
* ID | ||
* Simulator | ||
* | ||
*/ | ||
public String execute(String instruction) { | ||
StringBuffer deviceInfo = new StringBuffer(";Device.model = '"); | ||
deviceInfo.append(DeviceInfo.getDeviceName()).append("';Device.flash = "); | ||
deviceInfo.append(DeviceInfo.getTotalFlashSize()).append(";Device.platform = '"); | ||
deviceInfo.append(DeviceInfo.getPlatformVersion()).append("';Device.vendor = '"); | ||
deviceInfo.append(DeviceInfo.getManufacturerName()).append("';Device.battery = "); | ||
deviceInfo.append(DeviceInfo.getBatteryLevel()).append(";Device.version = '"); | ||
deviceInfo.append(DeviceInfo.getSoftwareVersion()).append("';Device.isSimulator = "); | ||
deviceInfo.append(DeviceInfo.isSimulator()).append(";Device.hasCamera = "); | ||
deviceInfo.append(DeviceInfo.hasCamera()).append(";Device.uuid = "); | ||
deviceInfo.append(DeviceInfo.getDeviceId()).append(";"); | ||
return deviceInfo.toString(); | ||
} | ||
|
||
} |
Oops, something went wrong.