added plugin functionality for iitc mobile
This commit is contained in:
parent
c3f37f949f
commit
99a18444bf
15
build.py
15
build.py
@ -156,6 +156,14 @@ for fn in glob.glob("plugins/*.user.js"):
|
|||||||
metafn = fn.replace('.user.js', '.meta.js')
|
metafn = fn.replace('.user.js', '.meta.js')
|
||||||
saveScriptAndMeta(script, os.path.join(outDir,fn), os.path.join(outDir,metafn))
|
saveScriptAndMeta(script, os.path.join(outDir,fn), os.path.join(outDir,metafn))
|
||||||
|
|
||||||
|
def copytree(src, dst, symlinks=False, ignore=None):
|
||||||
|
for item in os.listdir(src):
|
||||||
|
s = os.path.join(src, item)
|
||||||
|
d = os.path.join(dst, item)
|
||||||
|
if os.path.isdir(s):
|
||||||
|
shutil.copytree(s, d, symlinks, ignore)
|
||||||
|
else:
|
||||||
|
shutil.copy2(s, d)
|
||||||
|
|
||||||
# if we're building mobile too
|
# if we're building mobile too
|
||||||
if buildMobile:
|
if buildMobile:
|
||||||
@ -169,7 +177,12 @@ if buildMobile:
|
|||||||
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/iitc.js")
|
||||||
|
|
||||||
# TODO? also copy plugins - once the mobile app supports plugins, that is
|
# also copy plugins
|
||||||
|
try:
|
||||||
|
os.makedirs("mobile/assets/plugins")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
copytree(os.path.join(outDir,"plugins"), "mobile/assets/plugins")
|
||||||
|
|
||||||
|
|
||||||
# now launch 'ant' to build the mobile project
|
# now launch 'ant' to build the mobile project
|
||||||
|
@ -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="10"
|
android:versionCode="11"
|
||||||
android:versionName="0.2.8.1" >
|
android:versionName="0.3" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
android:minSdkVersion="14"
|
android:minSdkVersion="14"
|
||||||
|
@ -32,6 +32,8 @@
|
|||||||
</string>
|
</string>
|
||||||
|
|
||||||
<string name="pref_ui_cat">UI</string>
|
<string name="pref_ui_cat">UI</string>
|
||||||
|
<string name="pref_plugins">Plugins</string>
|
||||||
|
<string name="pref_plugins_title">Available plugins</string>
|
||||||
<string name="pref_force_desktop">Force desktop mode</string>
|
<string name="pref_force_desktop">Force desktop mode</string>
|
||||||
<string name="pref_force_desktop_sum">Nice for tablets, looks awful on smartphones</string>
|
<string name="pref_force_desktop_sum">Nice for tablets, looks awful on smartphones</string>
|
||||||
<string name="pref_developer_options">Developer options</string>
|
<string name="pref_developer_options">Developer options</string>
|
||||||
|
@ -17,6 +17,10 @@
|
|||||||
android:title="@string/pref_force_desktop"
|
android:title="@string/pref_force_desktop"
|
||||||
android:summary="@string/pref_force_desktop_sum"
|
android:summary="@string/pref_force_desktop_sum"
|
||||||
android:defaultValue="false" />
|
android:defaultValue="false" />
|
||||||
|
<MultiSelectListPreference
|
||||||
|
android:key="pref_plugins"
|
||||||
|
android:title="@string/pref_plugins"
|
||||||
|
android:dialogTitle="@string/pref_plugins_title"/>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
package com.cradle.iitc_mobile;
|
package com.cradle.iitc_mobile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.res.AssetManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
public class IITC_Settings extends Activity {
|
public class IITC_Settings extends Activity {
|
||||||
@ -10,7 +15,39 @@ public class IITC_Settings extends Activity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
IITC_SettingsFragment settings = new IITC_SettingsFragment();
|
IITC_SettingsFragment settings = new IITC_SettingsFragment();
|
||||||
settings.setArguments(getIntent().getExtras());
|
|
||||||
|
AssetManager am = this.getAssets();
|
||||||
|
String[] asset_array = null;
|
||||||
|
try {
|
||||||
|
asset_array = am.list("plugins");
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<String> asset_list = new ArrayList<String>(Arrays.asList(asset_array));
|
||||||
|
ArrayList<String> asset_values = new ArrayList<String>();
|
||||||
|
|
||||||
|
for (int i = 0; i < asset_list.size();) {
|
||||||
|
try {
|
||||||
|
if (asset_list.get(i).endsWith("user.js")) {
|
||||||
|
asset_values.add(am.open("plugins/" + asset_list.get(i)).toString());
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
asset_list.remove(i);
|
||||||
|
asset_values.add(am.open("plugins/" + asset_list.get(i)).toString());
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Bundle bundle = getIntent().getExtras();
|
||||||
|
bundle.putStringArray("ASSETS", (String[]) asset_list.toArray(new String[0]));
|
||||||
|
bundle.putStringArray("ASSETS_VAL", (String[]) asset_values.toArray(new String[0]));
|
||||||
|
settings.setArguments(bundle);
|
||||||
|
|
||||||
// Display the fragment as the main content.
|
// Display the fragment as the main content.
|
||||||
getFragmentManager().beginTransaction()
|
getFragmentManager().beginTransaction()
|
||||||
|
@ -6,6 +6,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.EditTextPreference;
|
import android.preference.EditTextPreference;
|
||||||
import android.preference.ListPreference;
|
import android.preference.ListPreference;
|
||||||
|
import android.preference.MultiSelectListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.Preference.OnPreferenceChangeListener;
|
import android.preference.Preference.OnPreferenceChangeListener;
|
||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
@ -21,7 +22,12 @@ public class IITC_SettingsFragment extends PreferenceFragment {
|
|||||||
iitc_version = getArguments().getString("iitc_version");
|
iitc_version = getArguments().getString("iitc_version");
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.preferences);
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
|
|
||||||
|
//plugins
|
||||||
|
MultiSelectListPreference pref_plugins = (MultiSelectListPreference) findPreference("pref_plugins");
|
||||||
|
pref_plugins.setEntries(getArguments().getStringArray("ASSETS"));
|
||||||
|
pref_plugins.setEntryValues(getArguments().getStringArray("ASSETS"));
|
||||||
|
|
||||||
// set build version
|
// set build version
|
||||||
ListPreference pref_build_version = (ListPreference) findPreference("pref_build_version");
|
ListPreference pref_build_version = (ListPreference) findPreference("pref_build_version");
|
||||||
PackageManager pm = getActivity().getPackageManager();
|
PackageManager pm = getActivity().getPackageManager();
|
||||||
|
@ -3,6 +3,7 @@ package com.cradle.iitc_mobile;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
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.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
@ -17,6 +18,7 @@ import java.io.InputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class IITC_WebViewClient extends WebViewClient {
|
public class IITC_WebViewClient extends WebViewClient {
|
||||||
private static final ByteArrayInputStream style = new ByteArrayInputStream(
|
private static final ByteArrayInputStream style = new ByteArrayInputStream(
|
||||||
@ -91,6 +93,39 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
handler.proceed() ;
|
handler.proceed() ;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// plugins should be loaded after the main script is injected
|
||||||
|
@Override
|
||||||
|
public void onPageFinished(WebView view, String url) {
|
||||||
|
super.onPageFinished(view, url);
|
||||||
|
|
||||||
|
// get the plugin preferences
|
||||||
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
Set<String> plugin_list = sharedPref.getStringSet("pref_plugins", null);
|
||||||
|
|
||||||
|
// iterate through all enabled plugins and load them
|
||||||
|
if (plugin_list != null) {
|
||||||
|
AssetManager am = context.getAssets();
|
||||||
|
String[] plugin_array = plugin_list.toArray(new String[0]);
|
||||||
|
|
||||||
|
for(int i = 0; i < plugin_list.size(); i++) {
|
||||||
|
if (plugin_array[i].endsWith("user.js"));
|
||||||
|
{
|
||||||
|
Log.d("iitcm", "adding plugin " + plugin_array[i]);
|
||||||
|
Scanner s = null;
|
||||||
|
String src = "";
|
||||||
|
try {
|
||||||
|
s = new Scanner(am.open("plugins/" + plugin_array[i])).useDelimiter("\\A");
|
||||||
|
} catch (IOException e2) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e2.printStackTrace();
|
||||||
|
}
|
||||||
|
if (s != null) src = s.hasNext() ? s.next() : "";
|
||||||
|
view.loadUrl("javascript:" + src);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check every external resource if it’s okay to load it and maybe replace it
|
// Check every external resource if it’s okay to load it and maybe replace it
|
||||||
// with our own content. This is used to block loading Niantic resources
|
// with our own content. This is used to block loading Niantic resources
|
||||||
// which aren’t required and to inject IITC early into the site.
|
// which aren’t required and to inject IITC early into the site.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user