developer options: added possibility to use external script in app
This commit is contained in:
parent
551f0608fd
commit
af4ee26575
@ -7,9 +7,12 @@
|
||||
<string name="version">Print Version</string>
|
||||
<string name="cache_clear">Clear Cache</string>
|
||||
<string name="locate">Get Location</string>
|
||||
<string name="local">local</string>
|
||||
<string name="build_version">Build Version</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>
|
||||
<string name="pref_select_iitc">IITC source</string>
|
||||
|
||||
</resources>
|
@ -5,9 +5,21 @@
|
||||
android:title="@string/pref_force_desktop"
|
||||
android:summary="@string/pref_force_desktop_sum"
|
||||
android:defaultValue="false" />
|
||||
<ListPreference
|
||||
android:key="pref_build_version"
|
||||
android:title="@string/build_version"
|
||||
android:enabled="false"
|
||||
android:selectable="false" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="pref_developer_options"
|
||||
android:title="@string/pref_developer_options">
|
||||
|
||||
<EditTextPreference
|
||||
android:key="pref_iitc_source"
|
||||
android:title="@string/pref_select_iitc"
|
||||
android:summary=""
|
||||
android:defaultValue="local"/>
|
||||
|
||||
<ListPreference
|
||||
android:key="pref_build_version"
|
||||
android:title="@string/build_version"
|
||||
android:enabled="false"
|
||||
android:selectable="false" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user