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;