* moved advanced settings to own preference screen
* added setting to fake user agent (see https://plus.google.com/u/0/104992284359985480029/posts/9mPFLPKjgvL) * bumped version number
This commit is contained in:
@ -27,25 +27,32 @@ public class IITC_WebView extends WebView {
|
||||
private IITC_JSInterface mJsInterface;
|
||||
private Context mContext;
|
||||
private boolean mDisableJs = false;
|
||||
private String mDefaultUserAgent;
|
||||
private final String mDesktopUserAgent = "Mozilla/5.0 (X11; Linux x86_64; rv:17.0)" +
|
||||
" Gecko/20130810 Firefox/17.0 Iceweasel/17.0.8";
|
||||
|
||||
|
||||
|
||||
// init web view
|
||||
private void iitc_init(Context c) {
|
||||
if (this.isInEditMode()) return;
|
||||
if (isInEditMode()) return;
|
||||
mContext = c;
|
||||
mSettings = this.getSettings();
|
||||
mSettings = getSettings();
|
||||
mSettings.setJavaScriptEnabled(true);
|
||||
mSettings.setDomStorageEnabled(true);
|
||||
mSettings.setAllowFileAccess(true);
|
||||
mSettings.setGeolocationEnabled(true);
|
||||
mSettings.setAppCacheEnabled(true);
|
||||
mSettings.setDatabasePath(this.getContext().getApplicationInfo().dataDir
|
||||
mSettings.setDatabasePath(getContext().getApplicationInfo().dataDir
|
||||
+ "/databases/");
|
||||
mSettings.setAppCachePath(this.getContext().getCacheDir()
|
||||
mSettings.setAppCachePath(getContext().getCacheDir()
|
||||
.getAbsolutePath());
|
||||
this.mJsInterface = new IITC_JSInterface((IITC_Mobile) mContext);
|
||||
this.addJavascriptInterface(mJsInterface, "android");
|
||||
mJsInterface = new IITC_JSInterface((IITC_Mobile) mContext);
|
||||
addJavascriptInterface(mJsInterface, "android");
|
||||
mDefaultUserAgent = mSettings.getUserAgentString();
|
||||
setUserAgent();
|
||||
|
||||
this.setWebChromeClient(new WebChromeClient() {
|
||||
setWebChromeClient(new WebChromeClient() {
|
||||
/**
|
||||
* our webchromeclient should share geolocation with the iitc script
|
||||
*
|
||||
@ -83,7 +90,7 @@ public class IITC_WebView extends WebView {
|
||||
});
|
||||
|
||||
mIitcWebViewClient = new IITC_WebViewClient(c);
|
||||
this.setWebViewClient(mIitcWebViewClient);
|
||||
setWebViewClient(mIitcWebViewClient);
|
||||
}
|
||||
|
||||
// constructors -------------------------------------------------
|
||||
@ -110,7 +117,7 @@ public class IITC_WebView extends WebView {
|
||||
@Override
|
||||
public void loadUrl(String url) {
|
||||
// if in edit text mode, don't load javascript otherwise the keyboard closes.
|
||||
HitTestResult testResult = this.getHitTestResult();
|
||||
HitTestResult testResult = getHitTestResult();
|
||||
if (url.startsWith("javascript:") && testResult != null &&
|
||||
testResult.getType() == HitTestResult.EDIT_TEXT_TYPE) {
|
||||
// let window.show(...) interupt input
|
||||
@ -122,7 +129,7 @@ public class IITC_WebView extends WebView {
|
||||
}
|
||||
}
|
||||
// do nothing if script is enabled;
|
||||
if (this.mDisableJs) {
|
||||
if (mDisableJs) {
|
||||
Log.d("iitcm", "javascript injection disabled...return");
|
||||
return;
|
||||
}
|
||||
@ -143,11 +150,11 @@ public class IITC_WebView extends WebView {
|
||||
}
|
||||
|
||||
public IITC_WebViewClient getWebViewClient() {
|
||||
return this.mIitcWebViewClient;
|
||||
return mIitcWebViewClient;
|
||||
}
|
||||
|
||||
public IITC_JSInterface getJSInterface() {
|
||||
return this.mJsInterface;
|
||||
return mJsInterface;
|
||||
}
|
||||
|
||||
public void updateCaching() {
|
||||
@ -156,7 +163,7 @@ public class IITC_WebView extends WebView {
|
||||
login = getUrl().contains("accounts.google.com");
|
||||
}
|
||||
// use cache if on mobile network...saves traffic
|
||||
if (!this.isConnectedToWifi() && !login) {
|
||||
if (!isConnectedToWifi() && !login) {
|
||||
Log.d("iitcm", "not connected to wifi...load tiles from cache");
|
||||
mSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
|
||||
} else {
|
||||
@ -184,7 +191,14 @@ public class IITC_WebView extends WebView {
|
||||
}
|
||||
|
||||
public void disableJS(boolean val) {
|
||||
this.mDisableJs = val;
|
||||
mDisableJs = val;
|
||||
}
|
||||
|
||||
public void setUserAgent() {
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||
String ua = sharedPrefs.getBoolean("pref_fake_user_agent", false) ? mDesktopUserAgent : mDefaultUserAgent;
|
||||
Log.d("iitcm", "setting user agent to: " + ua);
|
||||
mSettings.setUserAgentString(ua);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user