Adding a WebViewClient with verbose checking

This commit is contained in:
Joe Bowser 2010-04-23 16:18:11 -07:00
parent ceabaf1e37
commit 2f6a9e18d0

View File

@ -30,6 +30,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
@ -41,6 +42,7 @@ import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebStorage;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.widget.LinearLayout;
import android.os.Build.*;
@ -94,6 +96,8 @@ public class DroidGap extends Activity {
appView.setWebChromeClient(new GapClient(this));
}
appView.setWebViewClient(new GapViewClient(this));
appView.setInitialScale(100);
appView.setVerticalScrollBarEnabled(false);
@ -164,6 +168,49 @@ public class DroidGap extends Activity {
appView.loadUrl(url);
}
public class GapViewClient extends WebViewClient {
Context mCtx;
public GapViewClient(Context ctx)
{
mCtx = ctx;
}
/*
* (non-Javadoc)
* @see android.webkit.WebViewClient#shouldOverrideUrlLoading(android.webkit.WebView, java.lang.String)
*
* Note: Since we override it to make sure that we are using PhoneGap and not some other bullshit
* viewer that may or may not exist, we need to make sure that http:// and tel:// still work. We
* plan to add sms:// and gap:// to make this more compatible with the iPhone, but for right now
* we're fixing what we're breaking.
*
*/
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("http://"))
{
Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browse);
return true;
}
else if(url.startsWith("tel://"))
{
Intent dial = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
startActivity(dial);
return true;
}
else
{
view.loadUrl(url);
return false;
}
}
}
/**
* Provides a hook for calling "alert" from javascript. Useful for
* debugging your javascript.
@ -176,12 +223,6 @@ public class DroidGap extends Activity {
mCtx = ctx;
}
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
Log.d(LOG_TAG, message);