added possibility to load additional plugins from /sdcard/IITC_Mobile/plugins/

This commit is contained in:
Philipp Schaefer 2013-05-04 00:08:48 +02:00
parent f6e6b76249
commit 710f4bf04e
2 changed files with 27 additions and 12 deletions

View File

@ -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="15" android:versionCode="16"
android:versionName="0.3.3" > android:versionName="0.3.4" >
<uses-sdk <uses-sdk
android:minSdkVersion="14" android:minSdkVersion="14"

View File

@ -17,6 +17,7 @@ import android.widget.Toast;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream; import java.io.InputStream;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
@ -30,13 +31,12 @@ 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; private String iitc_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() + this.iitc_path = Environment.getExternalStorageDirectory().getPath() + "/IITC_Mobile/";
"/IITC_Mobile/dev/";
try { try {
loadIITC_JS(c); loadIITC_JS(c);
} catch(IOException e) { } catch(IOException e) {
@ -69,10 +69,10 @@ public class IITC_WebViewClient extends WebViewClient {
// if developer mode are enabled, load all iitc script from external storage // if developer mode are enabled, load all iitc script from external storage
if (sharedPref.getBoolean("pref_dev_checkbox", true)) { if (sharedPref.getBoolean("pref_dev_checkbox", true)) {
File js_file = new File(dev_path + "total-conversion-build.user.js"); File js_file = new File(iitc_path + "/dev/total-conversion-build.user.js");
if (!js_file.exists()) { if (!js_file.exists()) {
Toast.makeText(context, "File " + dev_path + Toast.makeText(context, "File " + iitc_path +
"total-conversion-build.user.js not found. " + "/dev/total-conversion-build.user.js not found. " +
"Disable developer mode or add iitc files " + "Disable developer mode or add iitc files " +
"to the dev folder.", Toast.LENGTH_LONG).show(); "to the dev folder.", Toast.LENGTH_LONG).show();
} else { } else {
@ -141,14 +141,13 @@ public class IITC_WebViewClient extends WebViewClient {
try { try {
// load plugins from external storage if dev mode are enabled // load plugins from external storage if dev mode are enabled
if (dev_enabled) { if (dev_enabled) {
File js_file = new File(dev_path + "plugins/" + plugin_array[i]); File js_file = new File(iitc_path + "/dev/plugins/" + plugin_array[i]);
s = new Scanner(js_file).useDelimiter("\\A"); s = new Scanner(js_file).useDelimiter("\\A");
} }
else else
// load plugins from asset folder // load plugins from asset folder
s = new Scanner(am.open("plugins/" + plugin_array[i])).useDelimiter("\\A"); s = new Scanner(am.open("plugins/" + plugin_array[i])).useDelimiter("\\A");
} catch (IOException e2) { } catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace(); e2.printStackTrace();
} }
if (s != null) src = s.hasNext() ? s.next() : ""; if (s != null) src = s.hasNext() ? s.next() : "";
@ -159,6 +158,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, dev_enabled); enableTracking(view, dev_enabled);
// load additional plugins from <storage-path>/IITC-Mobile/plugins/
File directory = new File(iitc_path + "plugins/");
File[] files = directory.listFiles();
if (files != null) {
for (int i = 0; i < files.length; ++i) {
try {
String src = "";
Scanner s = new Scanner(files[i]).useDelimiter("\\A");
if (s != null) src = s.hasNext() ? s.next() : "";
Log.d("iitcm", "Loading additional plugin " + iitc_path + files[i]);
view.loadUrl("javascript:" + src);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
} }
public void enableTracking(WebView view, boolean dev_enabled) { public void enableTracking(WebView view, boolean dev_enabled) {
@ -169,14 +185,13 @@ public class IITC_WebViewClient extends WebViewClient {
try { try {
// load plugin from external storage if dev mode are enabled // load plugin from external storage if dev mode are enabled
if (dev_enabled) { if (dev_enabled) {
File js_file = new File(dev_path + "user-location.user.js"); File js_file = new File(iitc_path + "/dev/user-location.user.js");
s = new Scanner(js_file).useDelimiter("\\A"); s = new Scanner(js_file).useDelimiter("\\A");
} }
else else
// load plugin from asset folder // load plugin from asset folder
s = new Scanner(am.open("user-location.user.js")).useDelimiter("\\A"); s = new Scanner(am.open("user-location.user.js")).useDelimiter("\\A");
} catch (IOException e2) { } catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace(); e2.printStackTrace();
} }
if (s != null) src = s.hasNext() ? s.next() : ""; if (s != null) src = s.hasNext() ? s.next() : "";