Skip to content

Commit

Permalink
Merge branch 'master' of github.com:phonegap/phonegap-android
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Johnson committed Jun 30, 2011
2 parents 8f7a5de + c98b758 commit 941b64f
Show file tree
Hide file tree
Showing 25 changed files with 631 additions and 233 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ local.properties
framework/phonegap.jar
framework/bin
framework/assets/www/.DS_Store
.DS_Store
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.5
0.9.6.1
8 changes: 4 additions & 4 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>PhoneGap</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.5.min.js"></script>
<script type="text/javascript" charset="utf-8" src="main.js"></script>
<script type="text/javascript" charset="utf-8" src="phonegap.0.9.6.1.min.js"></script>
<script type="text/javascript" charset="utf-8" src="main.js"></script>

</head>
<body onload="init();" id="stage" class="theme">
Expand All @@ -31,8 +31,8 @@ <h4>Width: <span id="width"> &nbsp;</span>, Height: <span id="height">&nbsp;
<a href="#" class="btn large" onclick="show_pic();">Get a Picture</a>
<a href="#" class="btn large" onclick="get_contacts();">Get Phone's Contacts</a>
<a href="#" class="btn large" onclick="check_network();">Check Network</a>
<div id="viewport" class="viewport" style="display: none;">
<div id="viewport" class="viewport" style="display: none;">
<img style="width:60px;height:60px" id="test_img" src="" />
</div>
</div>
</body>
</html>
10 changes: 7 additions & 3 deletions framework/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.RECORD_VIDEO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
Expand All @@ -36,8 +37,11 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name">
<intent-filter>
</intent-filter>
</activity>
</application>

<uses-sdk android:minSdkVersion="2" />

<uses-sdk android:minSdkVersion="2" />
</manifest>
2 changes: 1 addition & 1 deletion framework/assets/js/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ LocalFileSystem.prototype._castDate = function(pluginResult) {
file.type = pluginResult.message.type;
file.name = pluginResult.message.name;
file.fullPath = pluginResult.message.fullPath;
file.lastModifedDate = new Date(pluginResult.message.lastModifiedDate);
file.lastModifiedDate = new Date(pluginResult.message.lastModifiedDate);
pluginResult.message = file;
}
return pluginResult;
Expand Down
48 changes: 34 additions & 14 deletions framework/assets/js/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,49 @@ Network.prototype.isReachable = function(uri, callback, options) {
*/
var Connection = function() {
this.type = null;
this.homeNW = null;
this.currentNW = null;
this._firstRun = true;
this._timer = null;
this.timeout = 500;

var me = this;
this.getInfo(
function(info) {
me.type = info.type;
me.homeNW = info.homeNW;
me.currentNW = info.currentNW;
PhoneGap.onPhoneGapConnectionReady.fire();
function(type) {
// Need to send events if we are on or offline
if (type == "none") {
// set a timer if still offline at the end of timer send the offline event
me._timer = setTimeout(function(){
me.type = type;
PhoneGap.fireEvent('offline');
me._timer = null;
}, me.timeout);
} else {
// If there is a current offline event pending clear it
if (me._timer != null) {
clearTimeout(me._timer);
me._timer = null;
}
me.type = type;
PhoneGap.fireEvent('online');
}

// should only fire this once
if (me._firstRun) {
me._firstRun = false;
PhoneGap.onPhoneGapConnectionReady.fire();
}
},
function(e) {
console.log("Error initializing Network Connection: " + e);
});
};

Connection.UNKNOWN = 0;
Connection.ETHERNET = 1;
Connection.WIFI = 2;
Connection.CELL_2G = 3;
Connection.CELL_3G = 4;
Connection.CELL_4G = 5;
Connection.NONE = 20;
Connection.UNKNOWN = "unknown";
Connection.ETHERNET = "ethernet";
Connection.WIFI = "wifi";
Connection.CELL_2G = "2g";
Connection.CELL_3G = "3g";
Connection.CELL_4G = "4g";
Connection.NONE = "none";

/**
* Get connection info
Expand Down
31 changes: 18 additions & 13 deletions framework/assets/js/phonegap.js.base
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ PhoneGap.Channel.prototype.subscribe = function(f, c, g) {
if (f === null) { return; }

var func = f;
if (typeof c === "object" && f instanceof Function) { func = PhoneGap.close(c, f); }
if (typeof c === "object" && typeof f === "function") { func = PhoneGap.close(c, f); }

g = g || func.observer_guid || f.observer_guid || this.guid++;
func.observer_guid = g;
Expand All @@ -120,7 +120,7 @@ PhoneGap.Channel.prototype.subscribeOnce = function(f, c) {
_this.unsubscribe(g);
};
if (this.fired) {
if (typeof c === "object" && f instanceof Function) { f = PhoneGap.close(c, f); }
if (typeof c === "object" && typeof f === "function") { f = PhoneGap.close(c, f); }
f.apply(this, this.fireArgs);
} else {
g = this.subscribe(m);
Expand All @@ -132,7 +132,7 @@ PhoneGap.Channel.prototype.subscribeOnce = function(f, c) {
* Unsubscribes the function with the given guid from the channel.
*/
PhoneGap.Channel.prototype.unsubscribe = function(g) {
if (g instanceof Function) { g = g.observer_guid; }
if (typeof g === "function") { g = g.observer_guid; }
this.handlers[g] = null;
delete this.handlers[g];
};
Expand All @@ -147,7 +147,7 @@ PhoneGap.Channel.prototype.fire = function(e) {
for (item in this.handlers) {
if (this.handlers.hasOwnProperty(item)) {
handler = this.handlers[item];
if (handler instanceof Function) {
if (typeof handler === "function") {
rv = (handler.apply(this, arguments) === false);
fail = fail || rv;
}
Expand Down Expand Up @@ -344,10 +344,13 @@ PhoneGap.Channel.join(function() {
}
else {
var polling = prompt("usePolling", "gap_callbackServer:");
PhoneGap.UsePolling = polling;
if (polling == "true") {
PhoneGap.UsePolling = true;
PhoneGap.JSCallbackPolling();
}
else {
PhoneGap.UsePolling = false;
PhoneGap.JSCallback();
}
}
Expand Down Expand Up @@ -507,7 +510,7 @@ PhoneGap.clone = function(obj) {
return retVal;
}

if (obj instanceof Function) {
if (typeof obj === "function") {
return obj;
}

Expand Down Expand Up @@ -767,8 +770,8 @@ PhoneGap.JSCallback = function() {
// If callback has JavaScript statement to execute
if (xmlhttp.status === 200) {

// Need to url decode the response and replace %20 with a space
var msg = decodeURIComponent(xmlhttp.responseText.replace(/\+/g, '%20'));
// Need to url decode the response
var msg = decodeURIComponent(xmlhttp.responseText);
setTimeout(function() {
try {
var t = eval(msg);
Expand Down Expand Up @@ -802,13 +805,11 @@ PhoneGap.JSCallback = function() {
console.log("JSCallback Error: Bad request. Stopping callbacks.");
}

// If error, restart callback server
// If error, revert to polling
else {
console.log("JSCallback Error: Request failed.");
prompt("restartServer", "gap_callbackServer:");
PhoneGap.JSCallbackPort = null;
PhoneGap.JSCallbackToken = null;
setTimeout(PhoneGap.JSCallback, 100);
PhoneGap.UsePolling = true;
PhoneGap.JSCallbackPolling();
}
}
};
Expand Down Expand Up @@ -935,7 +936,11 @@ PhoneGap.includeJavascript = function(jsfile, successCallback) {
*/
var PluginManager = {
addService: function(serviceType, className) {
navigator.app.addService(serviceType, className);
try {
navigator.app.addService(serviceType, className);
} catch (e) {
console.log("Error adding service "+serviceType+": "+e);
}
}
};

Expand Down
2 changes: 1 addition & 1 deletion framework/assets/www/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html>
<head>
<title></title>
<script src="phonegap.0.9.5.min.js"></script>
<script src="phonegap.0.9.6.1.min.js"></script>
</head>
<body>

Expand Down
2 changes: 1 addition & 1 deletion framework/default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=android-8
target=android-12
apk-configurations=
35 changes: 25 additions & 10 deletions framework/src/com/phonegap/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.json.JSONObject;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import java.util.HashMap;

/**
* This class exposes methods in DroidGap that can be called from JavaScript.
Expand Down Expand Up @@ -83,40 +84,54 @@ public void clearCache() {
public void loadUrl(String url, JSONObject props) throws JSONException {
System.out.println("App.loadUrl("+url+","+props+")");
int wait = 0;

boolean usePhoneGap = true;
boolean clearPrev = false;

// If there are properties, then set them on the Activity
HashMap<String, Object> params = new HashMap<String, Object>();
if (props != null) {
JSONArray keys = props.names();
for (int i=0; i<keys.length(); i++) {
String key = keys.getString(i);
if (key.equals("wait")) {
wait = props.getInt(key);
}
else if (key.equalsIgnoreCase("usephonegap")) {
usePhoneGap = props.getBoolean(key);
}
else if (key.equalsIgnoreCase("clearprev")) {
clearPrev = props.getBoolean(key);
}
else {
Object value = props.get(key);
if (value == null) {

}
else if (value.getClass().equals(String.class)) {
this.ctx.getIntent().putExtra(key, (String)value);
params.put(key, (String)value);
}
else if (value.getClass().equals(Boolean.class)) {
this.ctx.getIntent().putExtra(key, (Boolean)value);
params.put(key, (Boolean)value);
}
else if (value.getClass().equals(Integer.class)) {
this.ctx.getIntent().putExtra(key, (Integer)value);
params.put(key, (Integer)value);
}
}
}
}

// If wait property, then delay loading

if (wait > 0) {
((DroidGap)this.ctx).loadUrl(url, wait);
}
else {
((DroidGap)this.ctx).loadUrl(url);
try {
synchronized(this) {
this.wait(wait);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
((DroidGap)this.ctx).showWebPage(url, usePhoneGap, clearPrev, params);
}

/**
Expand Down
14 changes: 7 additions & 7 deletions framework/src/com/phonegap/AudioHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ else if (action.equals("stopPlayingAudio")) {
this.stopPlayingAudio(args.getString(0));
}
else if (action.equals("getCurrentPositionAudio")) {
long l = this.getCurrentPositionAudio(args.getString(0));
return new PluginResult(status, l);
float f = this.getCurrentPositionAudio(args.getString(0));
return new PluginResult(status, f);
}
else if (action.equals("getDurationAudio")) {
long l = this.getDurationAudio(args.getString(0), args.getString(1));
return new PluginResult(status, l);
float f = this.getDurationAudio(args.getString(0), args.getString(1));
return new PluginResult(status, f);
}
else if (action.equals("release")) {
boolean b = this.release(args.getString(0));
Expand Down Expand Up @@ -230,10 +230,10 @@ public void stopPlayingAudio(String id) {
* @param id The id of the audio player
* @return position in msec
*/
public long getCurrentPositionAudio(String id) {
public float getCurrentPositionAudio(String id) {
AudioPlayer audio = this.players.get(id);
if (audio != null) {
return(audio.getCurrentPosition());
return(audio.getCurrentPosition()/1000.0f);
}
return -1;
}
Expand All @@ -245,7 +245,7 @@ public long getCurrentPositionAudio(String id) {
* @param file The name of the audio file.
* @return The duration in msec.
*/
public long getDurationAudio(String id, String file) {
public float getDurationAudio(String id, String file) {

// Get audio file
AudioPlayer audio = this.players.get(id);
Expand Down
Loading

0 comments on commit 941b64f

Please sign in to comment.