Add more control over how url is loaded.

This commit is contained in:
Bryce Curtis 2011-06-29 18:25:49 -05:00
parent 1e3422ae70
commit 9643314553

View File

@ -751,46 +751,49 @@ public class DroidGap extends PhonegapActivity {
* *
* @param url The url to load. * @param url The url to load.
* @param usePhoneGap Load url in PhoneGap webview. * @param usePhoneGap Load url in PhoneGap webview.
* @return "" if ok, or error message. * @param clearPrev Clear the activity stack, so new app becomes top of stack
* @param params DroidGap parameters for new app
* @throws android.content.ActivityNotFoundException
*/ */
public void showWebPage(String url, boolean usePhoneGap, HashMap<String, Object> params) { public void showWebPage(String url, boolean usePhoneGap, boolean clearPrev, HashMap<String, Object> params) throws android.content.ActivityNotFoundException {
try { Intent intent = null;
Intent intent = null; if (usePhoneGap) {
if (usePhoneGap) { intent = new Intent().setClass(this, com.phonegap.DroidGap.class);
intent = new Intent().setClass(this, com.phonegap.DroidGap.class); intent.putExtra("url", url);
intent.putExtra("url", url);
// Add parameters // Add parameters
if (params != null) { if (params != null) {
java.util.Set<Entry<String,Object>> s = params.entrySet(); java.util.Set<Entry<String,Object>> s = params.entrySet();
java.util.Iterator<Entry<String,Object>> it = s.iterator(); java.util.Iterator<Entry<String,Object>> it = s.iterator();
while(it.hasNext()) { while(it.hasNext()) {
Entry<String,Object> entry = it.next(); Entry<String,Object> entry = it.next();
String key = entry.getKey(); String key = entry.getKey();
Object value = entry.getValue(); Object value = entry.getValue();
if (value == null) { if (value == null) {
} }
else if (value.getClass().equals(String.class)) { else if (value.getClass().equals(String.class)) {
intent.putExtra(key, (String)value); intent.putExtra(key, (String)value);
} }
else if (value.getClass().equals(Boolean.class)) { else if (value.getClass().equals(Boolean.class)) {
intent.putExtra(key, (Boolean)value); intent.putExtra(key, (Boolean)value);
} }
else if (value.getClass().equals(Integer.class)) { else if (value.getClass().equals(Integer.class)) {
intent.putExtra(key, (Integer)value); intent.putExtra(key, (Integer)value);
} }
} }
} }
} }
else { else {
intent = new Intent(Intent.ACTION_VIEW); intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url)); intent.setData(Uri.parse(url));
} }
this.startActivity(intent); this.startActivity(intent);
} catch (android.content.ActivityNotFoundException e) {
System.out.println("DroidGap.showWebPage: Error loading url "+url+":"+ e.toString()); // Finish current activity
} if (clearPrev) {
this.finish();
}
} }
/** /**
@ -1127,10 +1130,14 @@ public class DroidGap extends PhonegapActivity {
// NOTE: This replaces our app with new URL. When BACK is pressed, // NOTE: This replaces our app with new URL. When BACK is pressed,
// our app is reloaded and restarted. All state is lost. // 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) {
HashMap<String, Object> params = new HashMap<String, Object>(); try {
params.put("loadingDialog", ""); HashMap<String, Object> params = new HashMap<String, Object>();
params.put("hideLoadingDialogOnPageLoad", true); params.put("loadingDialog", "");
this.ctx.showWebPage(url, true, params); params.put("hideLoadingDialogOnPageLoad", true);
this.ctx.showWebPage(url, true, true, params);
} catch (android.content.ActivityNotFoundException e) {
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