Merge branch 'master' into highlighter
This commit is contained in:
1
mobile/.gitignore
vendored
1
mobile/.gitignore
vendored
@ -7,3 +7,4 @@ libs/
|
||||
proguard-project.txt
|
||||
local.properties
|
||||
assets/iitc.js
|
||||
assets/plugins/
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.cradle.iitc_mobile"
|
||||
android:versionCode="9"
|
||||
android:versionName="0.2.8" >
|
||||
android:versionCode="11"
|
||||
android:versionName="0.3" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="14"
|
||||
|
@ -32,6 +32,8 @@
|
||||
</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_sum">Nice for tablets, looks awful on smartphones</string>
|
||||
<string name="pref_developer_options">Developer options</string>
|
||||
|
@ -17,6 +17,10 @@
|
||||
android:title="@string/pref_force_desktop"
|
||||
android:summary="@string/pref_force_desktop_sum"
|
||||
android:defaultValue="false" />
|
||||
<MultiSelectListPreference
|
||||
android:key="pref_plugins"
|
||||
android:title="@string/pref_plugins"
|
||||
android:dialogTitle="@string/pref_plugins_title"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
|
@ -56,7 +56,7 @@ public class IITC_Mobile extends Activity {
|
||||
if (Intent.ACTION_VIEW.equals(action)) {
|
||||
Uri uri = intent.getData();
|
||||
String url = uri.toString();
|
||||
if (intent.getScheme().equals("http://"))
|
||||
if (intent.getScheme().equals("http"))
|
||||
url = url.replace("http://", "https://");
|
||||
Log.d("iitcm", "intent received url: " + url);
|
||||
if (url.contains("ingress.com")) {
|
||||
|
@ -1,6 +1,11 @@
|
||||
package com.cradle.iitc_mobile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.res.AssetManager;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class IITC_Settings extends Activity {
|
||||
@ -10,7 +15,52 @@ public class IITC_Settings extends Activity {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
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>();
|
||||
ArrayList<String> asset_values = new ArrayList<String>();
|
||||
|
||||
for (int i = 0; i < asset_array.length ; i++) {
|
||||
if (asset_array[i].endsWith("user.js")) {
|
||||
// find user plugin name for user readable entries
|
||||
Scanner s = null;
|
||||
String src = "";
|
||||
try {
|
||||
s = new Scanner(am.open("plugins/" + asset_array[i])).useDelimiter("\\A");
|
||||
} catch (IOException e2) {
|
||||
// TODO Auto-generated catch block
|
||||
e2.printStackTrace();
|
||||
}
|
||||
if (s != null) src = s.hasNext() ? s.next() : "";
|
||||
String header = src.substring(src.indexOf("==UserScript=="), src.indexOf("==/UserScript=="));
|
||||
// remove new line comments and replace with space
|
||||
// this way we get double spaces instead of newline + double slash
|
||||
header = header.replace("\n//", " ");
|
||||
// get a list of key-value...split on multiple spaces
|
||||
String[] attributes = header.split(" +");
|
||||
String plugin_name = "not found";
|
||||
for (int j = 0; j < attributes.length; j++) {
|
||||
// search for name and use the value
|
||||
if (attributes[j].equals("@name")) plugin_name = attributes[j+1];
|
||||
}
|
||||
asset_list.add(plugin_name);
|
||||
// real value
|
||||
asset_values.add(asset_array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
getFragmentManager().beginTransaction()
|
||||
|
@ -6,6 +6,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.os.Bundle;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.MultiSelectListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.preference.PreferenceFragment;
|
||||
@ -21,7 +22,12 @@ public class IITC_SettingsFragment extends PreferenceFragment {
|
||||
iitc_version = getArguments().getString("iitc_version");
|
||||
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
|
||||
|
||||
//plugins
|
||||
MultiSelectListPreference pref_plugins = (MultiSelectListPreference) findPreference("pref_plugins");
|
||||
pref_plugins.setEntries(getArguments().getStringArray("ASSETS"));
|
||||
pref_plugins.setEntryValues(getArguments().getStringArray("ASSETS_VAL"));
|
||||
|
||||
// set build version
|
||||
ListPreference pref_build_version = (ListPreference) findPreference("pref_build_version");
|
||||
PackageManager pm = getActivity().getPackageManager();
|
||||
|
@ -3,6 +3,7 @@ package com.cradle.iitc_mobile;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.AssetManager;
|
||||
import android.net.Uri;
|
||||
import android.net.http.SslError;
|
||||
import android.preference.PreferenceManager;
|
||||
@ -17,6 +18,7 @@ import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Scanner;
|
||||
import java.util.Set;
|
||||
|
||||
public class IITC_WebViewClient extends WebViewClient {
|
||||
private static final ByteArrayInputStream style = new ByteArrayInputStream(
|
||||
@ -44,7 +46,7 @@ public class IITC_WebViewClient extends WebViewClient {
|
||||
String[] attributes = header.split(" +");
|
||||
String iitc_version = "not found";
|
||||
for (int i = 0; i < attributes.length; i++) {
|
||||
// search vor version and use the value
|
||||
// search for version and use the value
|
||||
if (attributes[i].equals("@version")) iitc_version = attributes[i+1];
|
||||
}
|
||||
return iitc_version;
|
||||
@ -91,6 +93,39 @@ public class IITC_WebViewClient extends WebViewClient {
|
||||
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
|
||||
// with our own content. This is used to block loading Niantic resources
|
||||
// which aren’t required and to inject IITC early into the site.
|
||||
@ -119,6 +154,11 @@ public class IITC_WebViewClient extends WebViewClient {
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
if (url.contains("ingress.com")) {
|
||||
// reload iitc if a poslink is clicked inside the app
|
||||
if (url.contains("intel?ll=") || (url.contains("latE6") && url.contains("lngE6"))) {
|
||||
Log.d("iitcm", "should be an internal clicked position link...reload script for: " + url);
|
||||
((IITC_Mobile) context).loadUrl(url);
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
Log.d("iitcm", "no ingress intel link, start external app to load url: " + url);
|
||||
|
Reference in New Issue
Block a user