Add ability to override url handling in plugins. This takes part of code from "Issue 216: Droidgap now allows plugins to override url loading" by davejohnson.

This commit is contained in:
Bryce Curtis 2011-09-08 15:36:20 -05:00
parent aa577416de
commit 0b6a39bc6f

View File

@ -1074,8 +1074,13 @@ public class DroidGap extends PhonegapActivity {
*/ */
@Override @Override
public boolean shouldOverrideUrlLoading(WebView view, String url) { public boolean shouldOverrideUrlLoading(WebView view, String url) {
// First give any plugins the chance to handle the url themselves
if (this.ctx.pluginManager.onOverrideUrlLoading(url)) {
}
// If dialing phone (tel:5551212) // If dialing phone (tel:5551212)
if (url.startsWith(WebView.SCHEME_TEL)) { else if (url.startsWith(WebView.SCHEME_TEL)) {
try { try {
Intent intent = new Intent(Intent.ACTION_DIAL); Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse(url)); intent.setData(Uri.parse(url));
@ -1083,9 +1088,8 @@ public class DroidGap extends PhonegapActivity {
} catch (android.content.ActivityNotFoundException e) { } catch (android.content.ActivityNotFoundException e) {
System.out.println("Error dialing "+url+": "+ e.toString()); System.out.println("Error dialing "+url+": "+ e.toString());
} }
return true;
} }
// If displaying map (geo:0,0?q=address) // If displaying map (geo:0,0?q=address)
else if (url.startsWith("geo:")) { else if (url.startsWith("geo:")) {
try { try {
@ -1095,9 +1099,8 @@ public class DroidGap extends PhonegapActivity {
} catch (android.content.ActivityNotFoundException e) { } catch (android.content.ActivityNotFoundException e) {
System.out.println("Error showing map "+url+": "+ e.toString()); System.out.println("Error showing map "+url+": "+ e.toString());
} }
return true;
} }
// If sending email (mailto:abc@corp.com) // If sending email (mailto:abc@corp.com)
else if (url.startsWith(WebView.SCHEME_MAILTO)) { else if (url.startsWith(WebView.SCHEME_MAILTO)) {
try { try {
@ -1107,9 +1110,8 @@ public class DroidGap extends PhonegapActivity {
} catch (android.content.ActivityNotFoundException e) { } catch (android.content.ActivityNotFoundException e) {
System.out.println("Error sending email "+url+": "+ e.toString()); System.out.println("Error sending email "+url+": "+ e.toString());
} }
return true;
} }
// If sms:5551212?body=This is the message // If sms:5551212?body=This is the message
else if (url.startsWith("sms:")) { else if (url.startsWith("sms:")) {
try { try {
@ -1140,15 +1142,13 @@ public class DroidGap extends PhonegapActivity {
} catch (android.content.ActivityNotFoundException e) { } catch (android.content.ActivityNotFoundException e) {
System.out.println("Error sending sms "+url+":"+ e.toString()); System.out.println("Error sending sms "+url+":"+ e.toString());
} }
return true;
} }
// All else // All else
else { else {
// If our app or file:, then load into our webview // If our app or file:, then load into a new phonegap webview container by starting a new instance of our activity.
// NOTE: This replaces our app with new URL. When BACK is pressed, // Our app continues to run. When BACK is pressed, our app is redisplayed.
// our app is reloaded and restarted. All state is lost.
if (this.ctx.loadInWebView || url.startsWith("file://") || url.indexOf(this.ctx.baseUrl) == 0) { if (this.ctx.loadInWebView || url.startsWith("file://") || url.indexOf(this.ctx.baseUrl) == 0) {
try { try {
// Init parameters to new DroidGap activity and propagate existing parameters // Init parameters to new DroidGap activity and propagate existing parameters
@ -1174,7 +1174,7 @@ public class DroidGap extends PhonegapActivity {
System.out.println("Error loading url into DroidGap - "+url+":"+ e.toString()); System.out.println("Error loading url into DroidGap - "+url+":"+ e.toString());
} }
} }
// If not our application, let default viewer handle // If not our application, let default viewer handle
else { else {
try { try {
@ -1185,8 +1185,8 @@ public class DroidGap extends PhonegapActivity {
System.out.println("Error loading url "+url+":"+ e.toString()); System.out.println("Error loading url "+url+":"+ e.toString());
} }
} }
return true;
} }
return true;
} }
/** /**