mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-20 23:56:20 +08:00
Merge pull request #128 from brycecurtis/pages
Update version number and fix issues with prompt().
This commit is contained in:
commit
4b647fc58d
@ -5,7 +5,7 @@
|
||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
||||
<title>PhoneGap</title>
|
||||
<link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title" charset="utf-8">
|
||||
<script type="text/javascript" charset="utf-8" src="phonegap.0.9.5.min.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="phonegap.0.9.6.min.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="main.js"></script>
|
||||
|
||||
</head>
|
||||
|
@ -37,8 +37,11 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
<uses-sdk android:minSdkVersion="2" />
|
||||
|
||||
<uses-sdk android:minSdkVersion="2" />
|
||||
</manifest>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<title></title>
|
||||
<script src="phonegap.0.9.5.min.js"></script>
|
||||
<script src="phonegap.0.9.6.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
@ -12,6 +12,7 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* This class exposes methods in DroidGap that can be called from JavaScript.
|
||||
@ -83,8 +84,11 @@ public class App extends Plugin {
|
||||
public void loadUrl(String url, JSONObject props) throws JSONException {
|
||||
System.out.println("App.loadUrl("+url+","+props+")");
|
||||
int wait = 0;
|
||||
|
||||
boolean usePhoneGap = true;
|
||||
boolean clearPrev = false;
|
||||
|
||||
// If there are properties, then set them on the Activity
|
||||
HashMap<String, Object> params = new HashMap<String, Object>();
|
||||
if (props != null) {
|
||||
JSONArray keys = props.names();
|
||||
for (int i=0; i<keys.length(); i++) {
|
||||
@ -92,31 +96,42 @@ public class App extends Plugin {
|
||||
if (key.equals("wait")) {
|
||||
wait = props.getInt(key);
|
||||
}
|
||||
else if (key.equalsIgnoreCase("usephonegap")) {
|
||||
usePhoneGap = props.getBoolean(key);
|
||||
}
|
||||
else if (key.equalsIgnoreCase("clearprev")) {
|
||||
clearPrev = props.getBoolean(key);
|
||||
}
|
||||
else {
|
||||
Object value = props.get(key);
|
||||
if (value == null) {
|
||||
|
||||
|
||||
}
|
||||
else if (value.getClass().equals(String.class)) {
|
||||
this.ctx.getIntent().putExtra(key, (String)value);
|
||||
params.put(key, (String)value);
|
||||
}
|
||||
else if (value.getClass().equals(Boolean.class)) {
|
||||
this.ctx.getIntent().putExtra(key, (Boolean)value);
|
||||
params.put(key, (Boolean)value);
|
||||
}
|
||||
else if (value.getClass().equals(Integer.class)) {
|
||||
this.ctx.getIntent().putExtra(key, (Integer)value);
|
||||
params.put(key, (Integer)value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If wait property, then delay loading
|
||||
|
||||
if (wait > 0) {
|
||||
((DroidGap)this.ctx).loadUrl(url, wait);
|
||||
}
|
||||
else {
|
||||
((DroidGap)this.ctx).loadUrl(url);
|
||||
try {
|
||||
synchronized(this) {
|
||||
this.wait(wait);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
((DroidGap)this.ctx).showWebPage(url, usePhoneGap, clearPrev, params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,7 +18,7 @@ import android.provider.Settings;
|
||||
|
||||
public class Device extends Plugin {
|
||||
|
||||
public static String phonegapVersion = "0.9.5"; // PhoneGap version
|
||||
public static String phonegapVersion = "0.9.6"; // PhoneGap version
|
||||
public static String platform = "Android"; // Device OS
|
||||
public static String uuid; // Device UUID
|
||||
|
||||
|
@ -7,6 +7,8 @@
|
||||
*/
|
||||
package com.phonegap;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
@ -136,7 +138,7 @@ public class DroidGap extends PhonegapActivity {
|
||||
private String urlFile;
|
||||
|
||||
// The base of the initial URL for our app
|
||||
private String baseUrl;
|
||||
private String baseUrl = null;
|
||||
|
||||
// Plugin to call when activity result is received
|
||||
protected Plugin activityResultCallback = null;
|
||||
@ -350,12 +352,14 @@ public class DroidGap extends PhonegapActivity {
|
||||
System.out.println("loadUrl("+url+")");
|
||||
this.urlFile = this.getUrlFile(url);
|
||||
this.url = url;
|
||||
int i = url.lastIndexOf('/');
|
||||
if (i > 0) {
|
||||
this.baseUrl = url.substring(0, i);
|
||||
}
|
||||
else {
|
||||
this.baseUrl = this.url;
|
||||
if (this.baseUrl == null) {
|
||||
int i = url.lastIndexOf('/');
|
||||
if (i > 0) {
|
||||
this.baseUrl = url.substring(0, i+1);
|
||||
}
|
||||
else {
|
||||
this.baseUrl = this.url + "/";
|
||||
}
|
||||
}
|
||||
System.out.println("url="+url+" baseUrl="+baseUrl);
|
||||
|
||||
@ -738,6 +742,59 @@ public class DroidGap extends PhonegapActivity {
|
||||
int p3 = (p1 < p2) ? p1 : p2;
|
||||
return url.substring(0, p3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a new browser with the specified URL.
|
||||
*
|
||||
* NOTE: If usePhoneGap is set, only trusted PhoneGap URLs should be loaded,
|
||||
* since any PhoneGap API can be called by the loaded HTML page.
|
||||
*
|
||||
* @param url The url to load.
|
||||
* @param usePhoneGap Load url in PhoneGap webview.
|
||||
* @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, boolean clearPrev, HashMap<String, Object> params) throws android.content.ActivityNotFoundException {
|
||||
Intent intent = null;
|
||||
if (usePhoneGap) {
|
||||
intent = new Intent().setClass(this, com.phonegap.DroidGap.class);
|
||||
intent.putExtra("url", url);
|
||||
|
||||
// Add parameters
|
||||
if (params != null) {
|
||||
java.util.Set<Entry<String,Object>> s = params.entrySet();
|
||||
java.util.Iterator<Entry<String,Object>> it = s.iterator();
|
||||
while(it.hasNext()) {
|
||||
Entry<String,Object> entry = it.next();
|
||||
String key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
if (value == null) {
|
||||
}
|
||||
else if (value.getClass().equals(String.class)) {
|
||||
intent.putExtra(key, (String)value);
|
||||
}
|
||||
else if (value.getClass().equals(Boolean.class)) {
|
||||
intent.putExtra(key, (Boolean)value);
|
||||
}
|
||||
else if (value.getClass().equals(Integer.class)) {
|
||||
intent.putExtra(key, (Integer)value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(url));
|
||||
}
|
||||
this.startActivity(intent);
|
||||
|
||||
// Finish current activity
|
||||
if (clearPrev) {
|
||||
this.finish();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a hook for calling "alert" from javascript. Useful for
|
||||
@ -825,8 +882,11 @@ public class DroidGap extends PhonegapActivity {
|
||||
*/
|
||||
@Override
|
||||
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) {
|
||||
|
||||
// Security check to make sure any requests are coming from the page initially
|
||||
// loaded in webview and not another loaded in an iframe.
|
||||
boolean reqOk = false;
|
||||
if (this.ctx.urlFile.equals(this.ctx.getUrlFile(url))) {
|
||||
if (url.indexOf(this.ctx.baseUrl) == 0) {
|
||||
reqOk = true;
|
||||
}
|
||||
|
||||
@ -1069,17 +1129,18 @@ public class DroidGap extends PhonegapActivity {
|
||||
// All else
|
||||
else {
|
||||
|
||||
int i = url.lastIndexOf('/');
|
||||
String newBaseUrl = url;
|
||||
if (i > 0) {
|
||||
newBaseUrl = url.substring(0, i);
|
||||
}
|
||||
|
||||
// If our app or file:, then load into our webview
|
||||
// NOTE: This replaces our app with new URL. When BACK is pressed,
|
||||
// our app is reloaded and restarted. All state is lost.
|
||||
if (this.ctx.loadInWebView || url.startsWith("file://") || this.ctx.baseUrl.equals(newBaseUrl)) {
|
||||
this.ctx.appView.loadUrl(url);
|
||||
if (this.ctx.loadInWebView || url.startsWith("file://") || url.indexOf(this.ctx.baseUrl) == 0) {
|
||||
try {
|
||||
HashMap<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("loadingDialog", "");
|
||||
params.put("hideLoadingDialogOnPageLoad", true);
|
||||
this.ctx.showWebPage(url, true, false, 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
|
||||
|
Loading…
Reference in New Issue
Block a user