Merge branch 'master' of https://github.com/jonatkins/ingress-intel-total-conversion
This commit is contained in:
commit
6bd79c8293
@ -2,7 +2,7 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.cradle.iitc_mobile"
|
||||
android:versionCode="1"
|
||||
android:versionName="0.2.4" >
|
||||
android:versionName="0.2.5" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="14"
|
||||
@ -10,6 +10,7 @@
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
@ -9,6 +9,7 @@
|
||||
<string name="locate">Get Location</string>
|
||||
<string name="local">local</string>
|
||||
<string name="build_version">Build Version</string>
|
||||
<string name="iitc_version">IITC 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>
|
||||
|
@ -21,5 +21,11 @@
|
||||
android:title="@string/build_version"
|
||||
android:enabled="false"
|
||||
android:selectable="false" />
|
||||
|
||||
<ListPreference
|
||||
android:key="pref_iitc_version"
|
||||
android:title="@string/iitc_version"
|
||||
android:enabled="false"
|
||||
android:selectable="false" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
@ -4,12 +4,16 @@ import java.io.IOException;
|
||||
|
||||
import com.cradle.iitc_mobile.R;
|
||||
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.NetworkInfo.State;
|
||||
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.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
@ -38,7 +42,7 @@ public class IITC_Mobile extends Activity {
|
||||
listener = new OnSharedPreferenceChangeListener() {
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (key == "pref_force_desktop")
|
||||
if (key.equals("pref_force_desktop"))
|
||||
desktop = sharedPreferences.getBoolean("pref_force_desktop", false);
|
||||
// reload intel map
|
||||
iitc_view.loadUrl(addUrlParam("https://www.ingress.com/intel"));
|
||||
@ -59,8 +63,7 @@ public class IITC_Mobile extends Activity {
|
||||
if (Intent.ACTION_VIEW.equals(action)) {
|
||||
Uri uri = intent.getData();
|
||||
String url = uri.toString();
|
||||
// TODO Why does "if(intent.getScheme() == "http")" not work?
|
||||
if (url.contains("http://"))
|
||||
if (intent.getScheme().equals("http://"))
|
||||
url = url.replace("http://", "https://");
|
||||
Log.d("Intent received", "url: " + url);
|
||||
if (url.contains("ingress.com")) {
|
||||
@ -75,6 +78,32 @@ public class IITC_Mobile extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
// enough idle...let's do some work
|
||||
iitc_view.loadUrl("javascript: window.idleTime = 0");
|
||||
iitc_view.loadUrl("javascript: window.renderUpdateStatus()");
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
||||
State mobile = conMan.getNetworkInfo(0).getState();
|
||||
State wifi = conMan.getNetworkInfo(1).getState();
|
||||
|
||||
if (mobile == NetworkInfo.State.CONNECTED || mobile == NetworkInfo.State.CONNECTING) {
|
||||
// cancel all current requests
|
||||
iitc_view.loadUrl("javascript: window.requests.abort()");
|
||||
// set idletime to maximum...no need for more
|
||||
iitc_view.loadUrl("javascript: window.idleTime = 999");
|
||||
} else if (wifi == NetworkInfo.State.CONNECTED || wifi == NetworkInfo.State.CONNECTING) {
|
||||
iitc_view.loadUrl("javascript: window.idleTime = 999");
|
||||
}
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
// save instance state to avoid reloading on orientation change
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
@ -128,7 +157,9 @@ public class IITC_Mobile extends Activity {
|
||||
iitc_view.loadUrl("javascript: window.map.locate({setView : true, maxZoom: 13});");
|
||||
return true;
|
||||
case R.id.settings:
|
||||
startActivity(new Intent(this, IITC_Settings.class));
|
||||
Intent intent = new Intent(this, IITC_Settings.class);
|
||||
intent.putExtra("iitc_version", iitc_view.getWebViewClient().getIITCVersion());
|
||||
startActivity(intent);
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
@ -4,13 +4,17 @@ import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class IITC_Settings extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
IITC_SettingsFragment settings = new IITC_SettingsFragment();
|
||||
settings.setArguments(getIntent().getExtras());
|
||||
|
||||
// Display the fragment as the main content.
|
||||
getFragmentManager().beginTransaction()
|
||||
.replace(android.R.id.content, new IITC_SettingsFragment())
|
||||
.replace(android.R.id.content, settings)
|
||||
.commit();
|
||||
}
|
||||
}
|
@ -12,11 +12,14 @@ import android.preference.PreferenceFragment;
|
||||
|
||||
public class IITC_SettingsFragment extends PreferenceFragment {
|
||||
|
||||
String iitc_version;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
iitc_version = getArguments().getString("iitc_version");
|
||||
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
|
||||
// set build version
|
||||
@ -28,15 +31,21 @@ public class IITC_SettingsFragment extends PreferenceFragment {
|
||||
version = info.versionName;
|
||||
}
|
||||
catch (NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
pref_build_version.setSummary(version);
|
||||
|
||||
// set iitc version
|
||||
ListPreference pref_iitc_version = (ListPreference) findPreference("pref_iitc_version");
|
||||
pref_iitc_version.setSummary(iitc_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);
|
||||
// TODO: update iitc_version when iitc source has changed
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
@ -21,6 +21,7 @@ public class IITC_WebViewClient extends WebViewClient {
|
||||
private static final ByteArrayInputStream empty = new ByteArrayInputStream("".getBytes());
|
||||
|
||||
private WebResourceResponse iitcjs;
|
||||
private String js = null;
|
||||
|
||||
public IITC_WebViewClient(Context c) {
|
||||
try {
|
||||
@ -30,6 +31,20 @@ public class IITC_WebViewClient extends WebViewClient {
|
||||
}
|
||||
}
|
||||
|
||||
public String getIITCVersion() {
|
||||
String header = js.substring(js.indexOf("==UserScript=="), js.indexOf("==/UserScript=="));
|
||||
// remove new line comments
|
||||
header = header.replace("\n//", "");
|
||||
// get a list of key-value
|
||||
String[] attributes = header.split(" +");
|
||||
String iitc_version = "not found";
|
||||
for (int i = 0; i < attributes.length; i++) {
|
||||
// search vor version and use the value
|
||||
if (attributes[i].equals("@version")) iitc_version = attributes[i+1];
|
||||
}
|
||||
return iitc_version;
|
||||
}
|
||||
|
||||
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
|
||||
@ -49,6 +64,8 @@ public class IITC_WebViewClient extends WebViewClient {
|
||||
js = new String(buffer);
|
||||
}
|
||||
|
||||
this.js = js;
|
||||
|
||||
// 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user