added new developer options (fix for 219)
This commit is contained in:
parent
039167051e
commit
430824825f
2
build.py
2
build.py
@ -220,7 +220,7 @@ if buildMobile:
|
|||||||
os.makedirs("mobile/assets")
|
os.makedirs("mobile/assets")
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
shutil.copy(os.path.join(outDir,"total-conversion-build.user.js"), "mobile/assets/iitc.js")
|
shutil.copy(os.path.join(outDir,"total-conversion-build.user.js"), "mobile/assets/total-conversion-build.user.js")
|
||||||
# copy the user location script into the mobile folder.
|
# copy the user location script into the mobile folder.
|
||||||
shutil.copy(os.path.join(outDir,"user-location.user.js"), "mobile/assets/user-location.user.js")
|
shutil.copy(os.path.join(outDir,"user-location.user.js"), "mobile/assets/user-location.user.js")
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.cradle.iitc_mobile"
|
package="com.cradle.iitc_mobile"
|
||||||
android:versionCode="13"
|
android:versionCode="14"
|
||||||
android:versionName="0.3.2" >
|
android:versionName="0.3.3" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
android:minSdkVersion="14"
|
android:minSdkVersion="14"
|
||||||
|
@ -39,6 +39,9 @@
|
|||||||
<string name="pref_user_loc">Display user location</string>
|
<string name="pref_user_loc">Display user location</string>
|
||||||
<string name="pref_user_loc_sum">Show users position on map</string>
|
<string name="pref_user_loc_sum">Show users position on map</string>
|
||||||
<string name="pref_developer_options">Developer options</string>
|
<string name="pref_developer_options">Developer options</string>
|
||||||
|
<string name="pref_enable_dev_options">Enable developer options</string>
|
||||||
|
<string name="pref_enable_dev_options_sum">If enabled, all IITC sources will be loaded from external storage of the Android device.
|
||||||
|
Please copy all sources from $IITC_folder/build/mobile/ to /sdcard/IITC_Mobile/dev/.</string>
|
||||||
<string name="pref_select_iitc">IITC source</string>
|
<string name="pref_select_iitc">IITC source</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@ -38,6 +38,12 @@
|
|||||||
android:summary=""
|
android:summary=""
|
||||||
android:defaultValue="local"/>
|
android:defaultValue="local"/>
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="pref_dev_checkbox"
|
||||||
|
android:title="@string/pref_enable_dev_options"
|
||||||
|
android:summary="@string/pref_enable_dev_options_sum"
|
||||||
|
android:defaultValue="false" />
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:key="pref_build_version"
|
android:key="pref_build_version"
|
||||||
android:title="@string/build_version"
|
android:title="@string/build_version"
|
||||||
|
@ -53,9 +53,8 @@ public class IITC_Mobile extends Activity {
|
|||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
if (key.equals("pref_force_desktop"))
|
if (key.equals("pref_force_desktop"))
|
||||||
desktop = sharedPreferences.getBoolean("pref_force_desktop", false);
|
desktop = sharedPreferences.getBoolean("pref_force_desktop", false);
|
||||||
if (key.equals("pref_user_loc")) {
|
if (key.equals("pref_user_loc"))
|
||||||
user_loc = sharedPreferences.getBoolean("pref_user_loc", false);
|
user_loc = sharedPreferences.getBoolean("pref_user_loc", false);
|
||||||
}
|
|
||||||
IITC_Mobile.this.loadUrl(intel_url);
|
IITC_Mobile.this.loadUrl(intel_url);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -23,6 +23,8 @@ public class IITC_WebView extends WebView {
|
|||||||
settings.setAllowFileAccess(true);
|
settings.setAllowFileAccess(true);
|
||||||
settings.setGeolocationEnabled(true);
|
settings.setGeolocationEnabled(true);
|
||||||
settings.setDatabasePath(this.getContext().getApplicationInfo().dataDir + "/databases/");
|
settings.setDatabasePath(this.getContext().getApplicationInfo().dataDir + "/databases/");
|
||||||
|
settings.setAppCachePath(this.getContext().getApplicationInfo().dataDir + "/cache/");
|
||||||
|
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
|
||||||
this.js_interface = new IITC_JSInterface(c);
|
this.js_interface = new IITC_JSInterface(c);
|
||||||
this.addJavascriptInterface(js_interface, "android");
|
this.addJavascriptInterface(js_interface, "android");
|
||||||
|
|
||||||
|
@ -6,14 +6,17 @@ import android.content.SharedPreferences;
|
|||||||
import android.content.res.AssetManager;
|
import android.content.res.AssetManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.net.http.SslError;
|
import android.net.http.SslError;
|
||||||
|
import android.os.Environment;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.webkit.SslErrorHandler;
|
import android.webkit.SslErrorHandler;
|
||||||
import android.webkit.WebResourceResponse;
|
import android.webkit.WebResourceResponse;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.webkit.WebViewClient;
|
import android.webkit.WebViewClient;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -27,10 +30,13 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
|
|
||||||
private WebResourceResponse iitcjs;
|
private WebResourceResponse iitcjs;
|
||||||
private String js = null;
|
private String js = null;
|
||||||
|
private String dev_path = null;
|
||||||
Context context;
|
Context context;
|
||||||
|
|
||||||
public IITC_WebViewClient(Context c) {
|
public IITC_WebViewClient(Context c) {
|
||||||
this.context = c;
|
this.context = c;
|
||||||
|
this.dev_path = Environment.getExternalStorageDirectory().getPath() +
|
||||||
|
"/IITC_Mobile/dev/";
|
||||||
try {
|
try {
|
||||||
loadIITC_JS(c);
|
loadIITC_JS(c);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
@ -39,7 +45,9 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getIITCVersion() {
|
public String getIITCVersion() {
|
||||||
String header = js.substring(js.indexOf("==UserScript=="), js.indexOf("==/UserScript=="));
|
String header = "";
|
||||||
|
if (js != null)
|
||||||
|
header = js.substring(js.indexOf("==UserScript=="), js.indexOf("==/UserScript=="));
|
||||||
// remove new line comments
|
// remove new line comments
|
||||||
header = header.replace("\n//", "");
|
header = header.replace("\n//", "");
|
||||||
// get a list of key-value
|
// get a list of key-value
|
||||||
@ -58,17 +66,35 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(c);
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(c);
|
||||||
String iitc_source = sharedPref.getString("pref_iitc_source", "local");
|
String iitc_source = sharedPref.getString("pref_iitc_source", "local");
|
||||||
String js = "";
|
String js = "";
|
||||||
if (iitc_source.contains("http")) {
|
|
||||||
URL url = new URL(iitc_source);
|
// if developer options are enabled, load all iitc script from external storage
|
||||||
js = new Scanner(url.openStream(), "UTF-8").useDelimiter("\\A").next();
|
if (sharedPref.getBoolean("pref_dev_checkbox", true)) {
|
||||||
|
File js_file = new File(dev_path + "total-conversion-build.user.js");
|
||||||
|
if (!js_file.exists()) {
|
||||||
|
Toast.makeText(context, "File " + dev_path +
|
||||||
|
"total-conversion-build.user.js not found. " +
|
||||||
|
"Disable developer options or add iitc files " +
|
||||||
|
"to the dev folder.", Toast.LENGTH_LONG).show();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(context, "Developer options enabled", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
Scanner s = null;
|
||||||
|
s = new Scanner(js_file).useDelimiter("\\A");
|
||||||
|
if (s != null) js = s.hasNext() ? s.next() : "";
|
||||||
} else {
|
} else {
|
||||||
InputStream input;
|
// load iitc script from web or asset folder
|
||||||
input = c.getAssets().open("iitc.js");
|
if (iitc_source.contains("http")) {
|
||||||
int size = input.available();
|
URL url = new URL(iitc_source);
|
||||||
byte[] buffer = new byte[size];
|
js = new Scanner(url.openStream(), "UTF-8").useDelimiter("\\A").next();
|
||||||
input.read(buffer);
|
} else {
|
||||||
input.close();
|
InputStream input;
|
||||||
js = new String(buffer);
|
input = c.getAssets().open("total-conversion-build.user.js");
|
||||||
|
int size = input.available();
|
||||||
|
byte[] buffer = new byte[size];
|
||||||
|
input.read(buffer);
|
||||||
|
input.close();
|
||||||
|
js = new String(buffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.js = js;
|
this.js = js;
|
||||||
@ -101,6 +127,7 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
// get the plugin preferences
|
// get the plugin preferences
|
||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
Set<String> plugin_list = sharedPref.getStringSet("pref_plugins", null);
|
Set<String> plugin_list = sharedPref.getStringSet("pref_plugins", null);
|
||||||
|
boolean dev_enabled = sharedPref.getBoolean("pref_dev_checkbox", true);
|
||||||
|
|
||||||
// iterate through all enabled plugins and load them
|
// iterate through all enabled plugins and load them
|
||||||
if (plugin_list != null) {
|
if (plugin_list != null) {
|
||||||
@ -114,7 +141,14 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
Scanner s = null;
|
Scanner s = null;
|
||||||
String src = "";
|
String src = "";
|
||||||
try {
|
try {
|
||||||
s = new Scanner(am.open("plugins/" + plugin_array[i])).useDelimiter("\\A");
|
// load plugins from external storage if dev options are enabled
|
||||||
|
if (dev_enabled) {
|
||||||
|
File js_file = new File(dev_path + "plugins/" + plugin_array[i]);
|
||||||
|
s = new Scanner(js_file).useDelimiter("\\A");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
// load plugins from asset folder
|
||||||
|
s = new Scanner(am.open("plugins/" + plugin_array[i])).useDelimiter("\\A");
|
||||||
} catch (IOException e2) {
|
} catch (IOException e2) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e2.printStackTrace();
|
e2.printStackTrace();
|
||||||
@ -127,16 +161,23 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
|
|
||||||
// inject the user location script if enabled in settings
|
// inject the user location script if enabled in settings
|
||||||
if (sharedPref.getBoolean("pref_user_loc", false))
|
if (sharedPref.getBoolean("pref_user_loc", false))
|
||||||
enableTracking(view);
|
enableTracking(view, dev_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enableTracking(WebView view) {
|
public void enableTracking(WebView view, boolean dev_enabled) {
|
||||||
Log.d("iitcm", "enable tracking...");
|
Log.d("iitcm", "enable tracking...");
|
||||||
AssetManager am = context.getAssets();
|
AssetManager am = context.getAssets();
|
||||||
Scanner s = null;
|
Scanner s = null;
|
||||||
String src = "";
|
String src = "";
|
||||||
try {
|
try {
|
||||||
s = new Scanner(am.open("user-location.user.js")).useDelimiter("\\A");
|
// load plugin from external storage if dev options are enabled
|
||||||
|
if (dev_enabled) {
|
||||||
|
File js_file = new File(dev_path + "user-location.user.js");
|
||||||
|
s = new Scanner(js_file).useDelimiter("\\A");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
// load plugin from asset folder
|
||||||
|
s = new Scanner(am.open("user-location.user.js")).useDelimiter("\\A");
|
||||||
} catch (IOException e2) {
|
} catch (IOException e2) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e2.printStackTrace();
|
e2.printStackTrace();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user