diff --git a/mobile/res/values/strings.xml b/mobile/res/values/strings.xml
index dba49d08..9b792d1a 100644
--- a/mobile/res/values/strings.xml
+++ b/mobile/res/values/strings.xml
@@ -7,9 +7,12 @@
Print Version
Clear Cache
Get Location
+ local
Build Version
Force desktop mode
Nice for tablets, looks awful on smartphones
+ Developer options
+ IITC source
\ No newline at end of file
diff --git a/mobile/res/xml/preferences.xml b/mobile/res/xml/preferences.xml
index 176338c5..f0fa675c 100644
--- a/mobile/res/xml/preferences.xml
+++ b/mobile/res/xml/preferences.xml
@@ -5,9 +5,21 @@
android:title="@string/pref_force_desktop"
android:summary="@string/pref_force_desktop_sum"
android:defaultValue="false" />
-
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java
index 31a0a612..1bf37ed9 100644
--- a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java
+++ b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java
@@ -7,10 +7,12 @@ import com.cradle.iitc_mobile.R;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
+import android.os.StrictMode;
import android.preference.PreferenceManager;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -21,13 +23,30 @@ public class IITC_Mobile extends Activity {
private IITC_WebView iitc_view;
private boolean back_button_pressed = false;
private boolean desktop = false;
+ private OnSharedPreferenceChangeListener listener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ // TODO build an async task for url.openStream() in IITC_WebViewClient
+ StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
+ StrictMode.setThreadPolicy(policy);
setContentView(R.layout.activity_main);
iitc_view = (IITC_WebView) findViewById(R.id.iitc_webview);
+ SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
+ listener = new OnSharedPreferenceChangeListener() {
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ if (key == "pref_force_desktop")
+ desktop = sharedPreferences.getBoolean("pref_force_desktop", false);
+ // reload intel map
+ iitc_view.loadUrl(addUrlParam("https://www.ingress.com/intel"));
+ injectJS();
+ }
+ };
+ sharedPref.registerOnSharedPreferenceChangeListener(listener);
+
// we do not want to reload our page every time we switch orientations...
// so restore state if activity was already created
if(savedInstanceState != null) {
@@ -56,20 +75,6 @@ public class IITC_Mobile extends Activity {
}
}
- @Override
- protected void onResume() {
- super.onResume();
-
- // reload page if, the desktop/mobile pref has changed
- SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
- if (desktop != sharedPref.getBoolean("pref_force_desktop", false)) {
- Log.d("pref changed", "force Desktop/Mobile changed...reloading");
- desktop = sharedPref.getBoolean("pref_force_desktop", false);
- iitc_view.loadUrl(addUrlParam("https://www.ingress.com/intel"));
- injectJS();
- }
- }
-
// save instance state to avoid reloading on orientation change
@Override
protected void onSaveInstanceState(Bundle outState) {
diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java b/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java
index 07a0f371..7580f634 100644
--- a/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java
+++ b/mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java
@@ -4,7 +4,10 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
+import android.preference.EditTextPreference;
import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceFragment;
public class IITC_SettingsFragment extends PreferenceFragment {
@@ -27,5 +30,18 @@ public class IITC_SettingsFragment extends PreferenceFragment {
catch (NameNotFoundException e) {
}
pref_build_version.setSummary(version);
+
+ // set iitc source
+ EditTextPreference pref_iitc_source = (EditTextPreference) findPreference("pref_iitc_source");
+ pref_iitc_source.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ preference.setSummary((CharSequence) newValue);
+ return true;
+ }
+ });
+ // first init of summary
+ String pref_iitc_source_sum = (String) pref_iitc_source.getSummary() + pref_iitc_source.getText();
+ pref_iitc_source.setSummary(pref_iitc_source_sum);
}
}
diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java
index 0ef26879..2b142058 100644
--- a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java
+++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java
@@ -1,7 +1,9 @@
package com.cradle.iitc_mobile;
import android.content.Context;
+import android.content.SharedPreferences;
import android.net.http.SslError;
+import android.preference.PreferenceManager;
import android.webkit.SslErrorHandler;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
@@ -10,6 +12,8 @@ import android.webkit.WebViewClient;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.IOException;
+import java.net.URL;
+import java.util.Scanner;
public class IITC_WebViewClient extends WebViewClient {
private static final ByteArrayInputStream style = new ByteArrayInputStream(
@@ -27,26 +31,36 @@ public class IITC_WebViewClient extends WebViewClient {
}
public void loadIITC_JS(Context c) throws java.io.IOException {
+ // in developer options, you are able to load the script from external source
+ // if a http address is given, use script from this address. else use the local script
+ SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(c);
+ String iitc_source = sharedPref.getString("pref_iitc_source", "local");
+ String js = "";
+ if (iitc_source.contains("http")) {
+ URL url = new URL(iitc_source);
+ js = new Scanner(url.openStream(), "UTF-8").useDelimiter("\\A").next();
+ } else {
InputStream input;
input = c.getAssets().open("iitc.js");
-
int size = input.available();
byte[] buffer = new byte[size];
input.read(buffer);
input.close();
- String js = new String(buffer);
- // need to wrap the mobile iitc.js version in a document ready. IITC
- // expects to be injected after the DOM has been loaded completely.
- // Since the mobile client injects IITC by replacing the gen_dashboard
- // file, IITC runs to early. The document.ready delays IITC long enough
- // so it boots correctly.
- js = "$(document).ready(function(){" + js + "});";
+ js = new String(buffer);
+ }
- iitcjs = new WebResourceResponse(
- "text/javascript",
- "UTF-8",
- new ByteArrayInputStream(js.getBytes())
- );
+ // need to wrap the mobile iitc.js version in a document ready. IITC
+ // expects to be injected after the DOM has been loaded completely.
+ // Since the mobile client injects IITC by replacing the gen_dashboard
+ // file, IITC runs to early. The document.ready delays IITC long enough
+ // so it boots correctly.
+ js = "$(document).ready(function(){" + js + "});";
+
+ iitcjs = new WebResourceResponse(
+ "text/javascript",
+ "UTF-8",
+ new ByteArrayInputStream(js.getBytes())
+ );
};
// enable https