Added explicit disabling of native Geolocation object in the web client, added a fallback measure to JavaScript geolocation PhoneGap constructor so that it builds/proxies the the instantiated Geo objects properly if it still does exist.

This commit is contained in:
filmaj
2010-03-23 16:37:30 -07:00
parent 655c6ac130
commit 887ab4a28b
3 changed files with 41 additions and 15 deletions
+3 -1
View File
@@ -101,7 +101,6 @@ public class DroidGap extends Activity {
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
Package pack = this.getClass().getPackage();
String appPackage = pack.getName();
@@ -111,6 +110,9 @@ public class DroidGap extends Activity {
// Turn on DOM storage!
WebViewReflect.setDomStorage(settings);
// Turn off native geolocation object in browser - we use our own :)
WebViewReflect.setGeolocationEnabled(settings, false);
/* Bind the appView object to the gap class methods */
bindBrowser(appView);
if(cupcakeStorage != null)
+25 -3
View File
@@ -10,6 +10,7 @@ public class WebViewReflect {
private static Method mWebSettings_setDatabaseEnabled;
private static Method mWebSettings_setDatabasePath;
private static Method mWebSettings_setDomStorageEnabled;
private static Method mWebSettings_setGeolocationEnabled;
static
{
@@ -48,6 +49,8 @@ public class WebViewReflect {
"setDatabasePath", new Class[] { String.class });
mWebSettings_setDomStorageEnabled = WebSettings.class.getMethod(
"setDomStorageEnabled", new Class[] { boolean.class });
mWebSettings_setGeolocationEnabled = WebSettings.class.getMethod(
"setGeolocationEnabled", new Class[] { boolean.class });
/* success, this is a newer device */
} catch (NoSuchMethodException nsme) {
/* failure, must be older device */
@@ -58,9 +61,9 @@ public class WebViewReflect {
if (mWebSettings_setDatabaseEnabled != null) {
/* feature is supported */
try {
mWebSettings_setDatabaseEnabled.invoke(setting, true);
mWebSettings_setDatabaseEnabled.invoke(setting, enable);
mWebSettings_setDatabasePath.invoke(setting, path);
} catch (IllegalArgumentException e) {
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
@@ -75,7 +78,26 @@ public class WebViewReflect {
System.out.println("Database not supported");
}
}
public static void setGeolocationEnabled(WebSettings setting, boolean enable) {
if (mWebSettings_setGeolocationEnabled != null) {
/* feature is supported */
try {
mWebSettings_setGeolocationEnabled.invoke(setting, enable);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
/* feature not supported, do something else */
System.out.println("Native Geolocation not supported - we're ok");
}
}
public static void setDomStorage(WebSettings setting)
{
if(mWebSettings_setDomStorageEnabled != null)