Skip to content

Commit

Permalink
Adding a WebViewClient with verbose checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Bowser committed Apr 23, 2010
1 parent ceabaf1 commit 2f6a9e1
Showing 1 changed file with 47 additions and 6 deletions.
53 changes: 47 additions & 6 deletions framework/src/com/phonegap/DroidGap.java
Expand Up @@ -30,6 +30,7 @@
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;
Expand All @@ -41,6 +42,7 @@
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.*;
Expand Down Expand Up @@ -94,6 +96,8 @@ public void onCreate(Bundle savedInstanceState) {
appView.setWebChromeClient(new GapClient(this));
}

appView.setWebViewClient(new GapViewClient(this));

appView.setInitialScale(100);
appView.setVerticalScrollBarEnabled(false);

Expand Down Expand Up @@ -164,6 +168,49 @@ public void loadUrl(String url)
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.
Expand All @@ -176,12 +223,6 @@ public GapClient(Context ctx)
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);
Expand Down

0 comments on commit 2f6a9e1

Please sign in to comment.