Fixing merge conflict

This commit is contained in:
macdonst 2010-09-16 13:39:59 -04:00
commit c483ebd1d7
7 changed files with 276 additions and 108 deletions

View File

@ -1,57 +1,58 @@
/** /**
* this represents the mobile device, and provides properties for inspecting the model, version, UUID of the * This represents the mobile device, and provides properties for inspecting the model, version, UUID of the
* phone, etc. * phone, etc.
* @constructor * @constructor
*/ */
function Device() { function Device() {
this.available = PhoneGap.available; this.available = PhoneGap.available;
this.platform = null; this.platform = null;
this.version = null; this.version = null;
this.name = null; this.name = null;
this.gap = null; this.uuid = null;
this.uuid = null; this.phonegap = null;
try {
if (window.DroidGap) { var me = this;
this.available = true; PhoneGap.execAsync(
this.uuid = window.DroidGap.getUuid(); function(info) {
this.version = window.DroidGap.getOSVersion(); me.available = true;
this.gapVersion = window.DroidGap.getVersion(); me.platform = info.platform;
this.platform = window.DroidGap.getPlatform(); me.version = info.version;
this.name = window.DroidGap.getProductName(); me.uuid = info.uuid;
this.line1Number = window.DroidGap.getLine1Number(); me.phonegap = info.phonegap;
this.deviceId = window.DroidGap.getDeviceId(); },
this.simSerialNumber = window.DroidGap.getSimSerialNumber(); function(e) {
this.subscriberId = window.DroidGap.getSubscriberId(); me.available = false;
} console.log("Error initializing PhoneGap: " + e);
} catch(e) { alert("Error initializing PhoneGap: "+e);
this.available = false; },
} "Device", "getDeviceInfo", []);
} }
/* /*
* This is only for Android.
*
* You must explicitly override the back button. * You must explicitly override the back button.
*/ */
Device.prototype.overrideBackButton = function() {
Device.prototype.overrideBackButton = function() BackButton.override();
{
BackButton.override();
} }
/* /*
* This is only for Android.
*
* This resets the back button to the default behaviour * This resets the back button to the default behaviour
*/ */
Device.prototype.resetBackButton = function() {
Device.prototype.resetBackButton = function() BackButton.reset();
{
BackButton.reset();
} }
/* /*
* This is only for Android.
*
* This terminates the activity! * This terminates the activity!
*/ */
Device.prototype.exitApp = function() Device.prototype.exitApp = function() {
{ BackButton.exitApp();
BackButton.exitApp();
} }
PhoneGap.addConstructor(function() { PhoneGap.addConstructor(function() {

View File

@ -2,7 +2,6 @@
* This class provides access to notifications on the device. * This class provides access to notifications on the device.
*/ */
function Notification() { function Notification() {
} }
/** /**
@ -42,16 +41,17 @@ Notification.prototype.blink = function(count, colour) {
* @param {Integer} mills The number of milliseconds to vibrate for. * @param {Integer} mills The number of milliseconds to vibrate for.
*/ */
Notification.prototype.vibrate = function(mills) { Notification.prototype.vibrate = function(mills) {
PhoneGap.execAsync(null, null, "Device", "vibrate", [mills]);
}; };
/** /**
* Causes the device to beep. * Causes the device to beep.
* On Android, the default notification ringtone is played.
*
* @param {Integer} count The number of beeps. * @param {Integer} count The number of beeps.
* @param {Integer} volume The volume of the beep.
*/ */
Notification.prototype.beep = function(count, volume) { Notification.prototype.beep = function(count) {
PhoneGap.execAsync(null, null, "Device", "beep", [count]);
}; };
// TODO: of course on Blackberry and Android there notifications in the UI as well // TODO: of course on Blackberry and Android there notifications in the UI as well
@ -60,18 +60,3 @@ PhoneGap.addConstructor(function() {
if (typeof navigator.notification == "undefined") navigator.notification = new Notification(); if (typeof navigator.notification == "undefined") navigator.notification = new Notification();
}); });
Notification.prototype.vibrate = function(mills)
{
DroidGap.vibrate(mills);
}
/*
* On the Android, we don't beep, we notify you with your
* notification! We shouldn't keep hammering on this, and should
* review what we want beep to do.
*/
Notification.prototype.beep = function(count, volume)
{
DroidGap.beep(count);
}

View File

@ -219,6 +219,36 @@ document.addEventListener = function(evt, handler, capture) {
} }
}; };
/**
* If JSON not included, use our own stringify. (Android 1.6)
* The restriction on ours is that it must be an array of simple types.
*
* @param args
* @return
*/
PhoneGap.stringify = function(args) {
if (typeof JSON == "undefined") {
var s = "[";
for (var i=0; i<args.length; i++) {
if (i > 0) {
s = s + ",";
}
var type = typeof args[i];
if ((type == "number") || (type == "boolean")) {
s = s + args[i];
}
else {
s = s + '"' + args[i] + '"';
}
}
s = s + "]";
return s;
}
else {
return JSON.stringify(args);
}
};
PhoneGap.callbackId = 0; PhoneGap.callbackId = 0;
PhoneGap.callbacks = {}; PhoneGap.callbacks = {};
@ -232,7 +262,7 @@ PhoneGap.callbacks = {};
PhoneGap.exec = function(clazz, action, args) { PhoneGap.exec = function(clazz, action, args) {
try { try {
var callbackId = 0; var callbackId = 0;
var r = PluginManager.exec(clazz, action, callbackId, JSON.stringify(args), false); var r = PluginManager.exec(clazz, action, callbackId, this.stringify(args), false);
eval("var v="+r+";"); eval("var v="+r+";");
// If status is OK, then return value back to caller // If status is OK, then return value back to caller
@ -256,10 +286,10 @@ PhoneGap.execAsync = function(success, fail, clazz, action, args) {
if (success || fail) { if (success || fail) {
PhoneGap.callbacks[callbackId] = {success:success, fail:fail}; PhoneGap.callbacks[callbackId] = {success:success, fail:fail};
} }
var r = PluginManager.exec(clazz, action, callbackId, JSON.stringify(args), true); var r = PluginManager.exec(clazz, action, callbackId, this.stringify(args), true);
// If a result was returned // If a result was returned
if (r) { if (typeof r == "string") {
eval("var v="+r+";"); eval("var v="+r+";");
// If status is OK, then return value back to caller // If status is OK, then return value back to caller

View File

@ -105,13 +105,18 @@ public class AccelListener implements SensorEventListener, Plugin{
return new PluginResult(PluginResult.Status.IO_EXCEPTION, AccelListener.ERROR_FAILED_TO_START); return new PluginResult(PluginResult.Status.IO_EXCEPTION, AccelListener.ERROR_FAILED_TO_START);
} }
// Wait until running // Wait until running
while (this.status == STARTING) { long timeout = 2000;
while ((this.status == STARTING) && (timeout > 0)) {
timeout = timeout - 100;
try { try {
Thread.sleep(100); Thread.sleep(100);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
if (timeout == 0) {
return new PluginResult(PluginResult.Status.IO_EXCEPTION, AccelListener.ERROR_FAILED_TO_START);
}
} }
JSONObject r = new JSONObject(); JSONObject r = new JSONObject();
r.put("x", this.x); r.put("x", this.x);

View File

@ -98,13 +98,18 @@ public class CompassListener implements SensorEventListener, Plugin{
return new PluginResult(PluginResult.Status.IO_EXCEPTION, ERROR_FAILED_TO_START); return new PluginResult(PluginResult.Status.IO_EXCEPTION, ERROR_FAILED_TO_START);
} }
// Wait until running // Wait until running
while (this.status == STARTING) { long timeout = 2000;
while ((this.status == STARTING) && (timeout > 0)) {
timeout = timeout - 100;
try { try {
Thread.sleep(100); Thread.sleep(100);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
if (timeout == 0) {
return new PluginResult(PluginResult.Status.IO_EXCEPTION, AccelListener.ERROR_FAILED_TO_START);
}
} }
float f = this.getHeading(); float f = this.getHeading();
return new PluginResult(status, f); return new PluginResult(status, f);

View File

@ -24,7 +24,15 @@ package com.phonegap;
import java.util.TimeZone; import java.util.TimeZone;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Vibrator; import android.os.Vibrator;
import android.provider.Settings; import android.provider.Settings;
@ -33,76 +41,210 @@ import android.webkit.WebView;
import android.media.Ringtone; import android.media.Ringtone;
import android.media.RingtoneManager; import android.media.RingtoneManager;
public class Device{ public class Device implements Plugin {
private static final String LOG_TAG = "PhoneGap"; public static String phonegapVersion = "pre-0.92 EDGE"; // PhoneGap version
/* public static String platform = "Android"; // Device OS
* UUID, version and availability public static String uuid; // Device UUID
*/ private DroidGap ctx; // DroidGap object
public boolean droid = true; @SuppressWarnings("unused")
public static String version = "0.91"; private WebView webView; // Webview object
public static String platform = "Android";
public static String uuid;
private Context mCtx;
private WebView mAppView;
AudioPlayer audio;
public Device(WebView appView, Context ctx) { /**
this.mCtx = ctx; * Constructor.
this.mAppView = appView; */
uuid = getUuid(); public Device() {
} }
public void beep(long pattern) /**
{ * Sets the context of the Command. This can then be used to do things like
* get file paths associated with the Activity.
*
* @param ctx The context of the main Activity.
*/
public void setContext(DroidGap ctx) {
this.ctx = ctx;
Device.uuid = getUuid();
}
/**
* Sets the main View of the application, this is the WebView within which
* a PhoneGap app runs.
*
* @param webView The PhoneGap WebView
*/
public void setView(WebView webView) {
this.webView = webView;
}
/**
* Executes the request and returns CommandResult.
*
* @param action The command to execute.
* @param args JSONArry of arguments for the command.
* @return A CommandResult object with a status and message.
*/
public PluginResult execute(String action, JSONArray args) {
PluginResult.Status status = PluginResult.Status.OK;
String result = "";
try {
if (action.equals("getDeviceInfo")) {
JSONObject r = new JSONObject();
r.put("uuid", Device.uuid);
r.put("version", this.getOSVersion());
r.put("platform", Device.platform);
r.put("name", this.getProductName());
r.put("phonegap", Device.phonegapVersion);
//JSONObject pg = new JSONObject();
//pg.put("version", Device.phonegapVersion);
//r.put("phonegap", pg);
return new PluginResult(status, r);
}
else if (action.equals("beep")) {
this.beep(args.getLong(0));
}
else if (action.equals("vibrate")) {
this.vibrate(args.getLong(0));
}
return new PluginResult(status, result);
} catch (JSONException e) {
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
}
}
/**
* Identifies if action to be executed returns a value and should be run synchronously.
*
* @param action The action to execute
* @return T=returns value
*/
public boolean isSynch(String action) {
if (action.equals("getDeviceInfo")) {
return true;
}
return false;
}
/**
* Called when the system is about to start resuming a previous activity.
*/
public void onPause() {
}
/**
* Called when the activity will start interacting with the user.
*/
public void onResume() {
}
/**
* Called when the activity is to be shut down.
* Stop listener.
*/
public void onDestroy() {
}
/**
* Called when an activity you launched exits, giving you the requestCode you started it with,
* the resultCode it returned, and any additional data from it.
*
* @param requestCode The request code originally supplied to startActivityForResult(),
* allowing you to identify who this result came from.
* @param resultCode The integer result code returned by the child activity through its setResult().
* @param data An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
}
//--------------------------------------------------------------------------
// LOCAL METHODS
//--------------------------------------------------------------------------
/**
* Beep plays the default notification ringtone.
*
* @param count Number of times to play notification
*/
public void beep(long count) {
Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone notification = RingtoneManager.getRingtone(mCtx, ringtone); Ringtone notification = RingtoneManager.getRingtone(this.ctx, ringtone);
if (notification != null) { // This will be the case when the phone is set to silent for example
for (long i = 0; i < pattern; ++i) // If phone is not set to silent mode
{ if (notification != null) {
for (long i = 0; i < count; ++i) {
notification.play(); notification.play();
long timeout = 5000;
while (notification.isPlaying() && (timeout > 0)) {
timeout = timeout - 100;
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
} }
} }
} }
public void vibrate(long pattern){ /**
* Vibrates the device for the specified amount of time.
*
* @param time Time to vibrate in ms.
*/
public void vibrate(long time){
// Start the vibration, 0 defaults to half a second. // Start the vibration, 0 defaults to half a second.
if (pattern == 0) if (time == 0) {
pattern = 500; time = 500;
Vibrator vibrator = (Vibrator) mCtx.getSystemService(Context.VIBRATOR_SERVICE); }
vibrator.vibrate(pattern); Vibrator vibrator = (Vibrator) this.ctx.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(time);
} }
public String getPlatform() /**
{ * Get the OS name.
return this.platform; *
* @return
*/
public String getPlatform() {
return Device.platform;
} }
public String getUuid() /**
{ * Get the device's Universally Unique Identifier (UUID).
//TelephonyManager operator = (TelephonyManager) mCtx.getSystemService(Context.TELEPHONY_SERVICE); *
//String uuid = operator.getDeviceId(); * @return
String uuid = Settings.Secure.getString(mCtx.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); */
public String getUuid() {
String uuid = Settings.Secure.getString(this.ctx.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
return uuid; return uuid;
} }
/**
* Get the PhoneGap version.
*
* @return
*/
public String getPhonegapVersion() {
return Device.phonegapVersion;
}
public String getLine1Number(){ public String getLine1Number(){
TelephonyManager operator = (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE); TelephonyManager operator = (TelephonyManager)this.ctx.getSystemService(Context.TELEPHONY_SERVICE);
return operator.getLine1Number(); return operator.getLine1Number();
} }
public String getDeviceId(){ public String getDeviceId(){
TelephonyManager operator = (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE); TelephonyManager operator = (TelephonyManager)this.ctx.getSystemService(Context.TELEPHONY_SERVICE);
return operator.getDeviceId(); return operator.getDeviceId();
} }
public String getSimSerialNumber(){ public String getSimSerialNumber(){
TelephonyManager operator = (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE); TelephonyManager operator = (TelephonyManager)this.ctx.getSystemService(Context.TELEPHONY_SERVICE);
return operator.getSimSerialNumber(); return operator.getSimSerialNumber();
} }
public String getSubscriberId(){ public String getSubscriberId(){
TelephonyManager operator = (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE); TelephonyManager operator = (TelephonyManager)this.ctx.getSystemService(Context.TELEPHONY_SERVICE);
return operator.getSubscriberId(); return operator.getSubscriberId();
} }
@ -116,21 +258,23 @@ public class Device{
String productname = android.os.Build.PRODUCT; String productname = android.os.Build.PRODUCT;
return productname; return productname;
} }
public String getOSVersion()
{ /**
* Get the OS version.
*
* @return
*/
public String getOSVersion() {
String osversion = android.os.Build.VERSION.RELEASE; String osversion = android.os.Build.VERSION.RELEASE;
return osversion; return osversion;
} }
public String getSDKVersion() public String getSDKVersion()
{ {
String sdkversion = android.os.Build.VERSION.SDK; String sdkversion = android.os.Build.VERSION.SDK;
return sdkversion; return sdkversion;
} }
public String getVersion()
{
return version;
}
public String getTimeZoneID() { public String getTimeZoneID() {
TimeZone tz = TimeZone.getDefault(); TimeZone tz = TimeZone.getDefault();

View File

@ -83,7 +83,6 @@ public class DroidGap extends Activity {
protected Boolean loadInWebView = false; protected Boolean loadInWebView = false;
private LinearLayout root; private LinearLayout root;
private Device gap;
private FileUtils fs; private FileUtils fs;
private BrowserKey mKey; private BrowserKey mKey;
public CallbackServer callbackServer; public CallbackServer callbackServer;
@ -270,13 +269,11 @@ public class DroidGap extends Activity {
private void bindBrowser(WebView appView) { private void bindBrowser(WebView appView) {
this.callbackServer = new CallbackServer(); this.callbackServer = new CallbackServer();
this.pluginManager = new PluginManager(appView, this); this.pluginManager = new PluginManager(appView, this);
this.gap = new Device(appView, this);
this.fs = new FileUtils(appView, this); this.fs = new FileUtils(appView, this);
this.mKey = new BrowserKey(appView, this); this.mKey = new BrowserKey(appView, this);
// This creates the new javascript interfaces for PhoneGap // This creates the new javascript interfaces for PhoneGap
appView.addJavascriptInterface(this.pluginManager, "PluginManager"); appView.addJavascriptInterface(this.pluginManager, "PluginManager");
appView.addJavascriptInterface(this.gap, "DroidGap");
appView.addJavascriptInterface(this.fs, "FileUtil"); appView.addJavascriptInterface(this.fs, "FileUtil");
appView.addJavascriptInterface(this.mKey, "BackButton"); appView.addJavascriptInterface(this.mKey, "BackButton");
@ -295,6 +292,7 @@ public class DroidGap extends Activity {
} }
this.addService("Device", "com.phonegap.Device");
this.addService("Accelerometer", "com.phonegap.AccelListener"); this.addService("Accelerometer", "com.phonegap.AccelListener");
this.addService("Compass", "com.phonegap.CompassListener"); this.addService("Compass", "com.phonegap.CompassListener");
this.addService("Media", "com.phonegap.AudioHandler"); this.addService("Media", "com.phonegap.AudioHandler");