From 88127f0b20591fe79b6cf2603674406801fc0eed Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Wed, 15 Oct 2008 14:29:08 -0700 Subject: [PATCH 1/5] Adding comments --- src/com/android/droidgap/PhoneGap.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/android/droidgap/PhoneGap.java b/src/com/android/droidgap/PhoneGap.java index 5cca01a0..1f61ec3a 100644 --- a/src/com/android/droidgap/PhoneGap.java +++ b/src/com/android/droidgap/PhoneGap.java @@ -24,11 +24,11 @@ public class PhoneGap { } public void takePhoto(){ - + // TO-DO: Figure out what this should do } public void playSound(){ - + // TO-DO: Figure out what this should do } public void vibrate(long pattern){ From 4ce3c333812410a4dd8b26b735a340038db53304 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Wed, 15 Oct 2008 14:31:09 -0700 Subject: [PATCH 2/5] More comments --- src/com/android/droidgap/PhoneGap.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/com/android/droidgap/PhoneGap.java b/src/com/android/droidgap/PhoneGap.java index 1f61ec3a..947f7c8d 100644 --- a/src/com/android/droidgap/PhoneGap.java +++ b/src/com/android/droidgap/PhoneGap.java @@ -37,6 +37,10 @@ public class PhoneGap { vibrator.vibrate(pattern); } + /* + * Android requires a provider, since it can fall back on triangulation and other means as well as GPS + */ + public void getLocation(String provider){ LocationManager locMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE); Location myLoc = (Location) locMan.getLastKnownLocation(provider); From c42a0ae5e2b7549326ec1972921295e4da2161c0 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Thu, 16 Oct 2008 13:23:10 -0700 Subject: [PATCH 3/5] Forgot to move the manifest to the branch --- AndroidManifest.xml | 8 ++++++++ src/com/android/droidgap/DroidGap.java | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 326dab12..9b92f368 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -3,6 +3,13 @@ package="com.android.droidgap" android:versionCode="1" android:versionName="1.0.0"> + + + + + + + @@ -12,4 +19,5 @@ + \ No newline at end of file diff --git a/src/com/android/droidgap/DroidGap.java b/src/com/android/droidgap/DroidGap.java index 9ce4d3e9..908a3b54 100644 --- a/src/com/android/droidgap/DroidGap.java +++ b/src/com/android/droidgap/DroidGap.java @@ -29,7 +29,7 @@ public class DroidGap extends Activity { * we can use HTML with both local and remote applications, but it means that we have to open the local file */ - appView.loadUrl("http://infil00p.org/gap/"); + appView.loadUrl("http://www.infil00p.org/gap/"); } From 2337509c1593c4ef99f09f4bb92ec69e45dfa147 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Fri, 17 Oct 2008 11:04:18 -0700 Subject: [PATCH 4/5] Added helpers to make life easier --- src/com/android/droidgap/PhoneGap.java | 64 +++++++++++++++++++++----- 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/src/com/android/droidgap/PhoneGap.java b/src/com/android/droidgap/PhoneGap.java index 947f7c8d..c0c53e7c 100644 --- a/src/com/android/droidgap/PhoneGap.java +++ b/src/com/android/droidgap/PhoneGap.java @@ -4,23 +4,39 @@ import android.content.Context; import android.hardware.SensorManager; import android.location.Location; import android.location.LocationManager; +import android.os.Handler; import android.os.Vibrator; +import android.telephony.TelephonyManager; +import android.webkit.WebView; public class PhoneGap { - public GeoTuple location; - public AccelTuple accel; + /* + * UUID, version and availability + */ + public boolean droid = true; + private String version = "0.1"; private Context mCtx; + private Handler mHandler; + private WebView mAppView; - public PhoneGap(Context ctx) { + public PhoneGap(Context ctx, Handler handler, WebView appView) { this.mCtx = ctx; + this.mHandler = handler; + this.mAppView = appView; } public void updateAccel(AccelTuple accel){ - accel.accelX = SensorManager.DATA_X; - accel.accelY = SensorManager.DATA_Y; - accel.accelZ = SensorManager.DATA_Z; + mHandler.post(new Runnable() { + public void run() { + int accelX = SensorManager.DATA_X; + int accelY = SensorManager.DATA_Y; + int accelZ = SensorManager.DATA_Z; + mAppView.loadUrl("javascript:gotAcceleration(" + accelX + ", " + accelY + "," + accelZ + ")"); + } + }); + } public void takePhoto(){ @@ -41,16 +57,40 @@ public class PhoneGap { * Android requires a provider, since it can fall back on triangulation and other means as well as GPS */ - public void getLocation(String provider){ - LocationManager locMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE); - Location myLoc = (Location) locMan.getLastKnownLocation(provider); - location.lat = myLoc.getLatitude(); - location.lng = myLoc.getLongitude(); - location.ele = myLoc.getAltitude(); + public void getLocation(final String provider){ + mHandler.post(new Runnable() { + public void run() { + LocationManager locMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE); + Location myLoc = (Location) locMan.getLastKnownLocation(provider); + GeoTuple geoloc = new GeoTuple(); + geoloc.lat = myLoc.getLatitude(); + geoloc.lng = myLoc.getLongitude(); + geoloc.ele = myLoc.getAltitude(); + mAppView.loadUrl("javascript:gotLocation(" + geoloc.lat + ", " + geoloc.lng + ")"); + } + }); } public String outputText(){ String test = "

Test

"; return test; } + + public String getUuid() + { + TelephonyManager operator = (TelephonyManager) mCtx.getSystemService(Context.TELEPHONY_SERVICE); + String uuid = operator.getDeviceId(); + return uuid; + } + + public String getVersion() + { + return version; + } + + public boolean exists() + { + return true; + } + } From 782310849f2d58201d082e8f6d5d9301e900788b Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Wed, 22 Oct 2008 13:07:33 -0700 Subject: [PATCH 5/5] Latest PhoneGap Source --- src/com/android/droidgap/DroidGap.java | 30 +++++++++++++++++++++++--- src/com/android/droidgap/PhoneGap.java | 2 +- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/com/android/droidgap/DroidGap.java b/src/com/android/droidgap/DroidGap.java index 908a3b54..c8c325ae 100644 --- a/src/com/android/droidgap/DroidGap.java +++ b/src/com/android/droidgap/DroidGap.java @@ -5,19 +5,30 @@ import java.io.InputStream; import android.app.Activity; import android.os.Bundle; +import android.os.Handler; +import android.util.Log; +import android.webkit.JsResult; +import android.webkit.WebChromeClient; import android.webkit.WebView; public class DroidGap extends Activity { + private static final String LOG_TAG = "DroidGap"; private WebView appView; + private Handler mHandler = new Handler(); + /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); - appView = (WebView) findViewById(R.id.appView); + appView = (WebView) findViewById(R.id.appView); + + /* This changes the setWebChromeClient to log alerts to LogCat! Important for Javascript Debugging */ + + appView.setWebChromeClient(new MyWebChromeClient()); appView.getSettings().setJavaScriptEnabled(true); appView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); @@ -29,7 +40,7 @@ public class DroidGap extends Activity { * we can use HTML with both local and remote applications, but it means that we have to open the local file */ - appView.loadUrl("http://www.infil00p.org/gap/"); + appView.loadUrl("http://www.infil00p.org/gap/demo/"); } @@ -58,8 +69,21 @@ public class DroidGap extends Activity { private void bindBrowser(WebView appView) { - PhoneGap gap = new PhoneGap(this); + PhoneGap gap = new PhoneGap(this, mHandler, appView); appView.addJavascriptInterface(gap, "DroidGap"); } + /** + * Provides a hook for calling "alert" from javascript. Useful for + * debugging your javascript. + */ + final class MyWebChromeClient extends WebChromeClient { + @Override + public boolean onJsAlert(WebView view, String url, String message, JsResult result) { + Log.d(LOG_TAG, message); + result.confirm(); + return true; + } + } + } \ No newline at end of file diff --git a/src/com/android/droidgap/PhoneGap.java b/src/com/android/droidgap/PhoneGap.java index c0c53e7c..7862258a 100644 --- a/src/com/android/droidgap/PhoneGap.java +++ b/src/com/android/droidgap/PhoneGap.java @@ -27,7 +27,7 @@ public class PhoneGap { this.mAppView = appView; } - public void updateAccel(AccelTuple accel){ + public void updateAccel(){ mHandler.post(new Runnable() { public void run() { int accelX = SensorManager.DATA_X;