Merge branch 'master' of https://github.com/jonatkins/ingress-intel-total-conversion
This commit is contained in:
commit
6bd79c8293
@ -1,44 +1,45 @@
|
|||||||
<?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="1"
|
android:versionCode="1"
|
||||||
android:versionName="0.2.4" >
|
android:versionName="0.2.5" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
android:minSdkVersion="14"
|
android:minSdkVersion="14"
|
||||||
android:targetSdkVersion="17" />
|
android:targetSdkVersion="17" />
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@drawable/iitc_icon"
|
android:icon="@drawable/iitc_icon"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:theme="@style/AppTheme" >
|
android:theme="@style/AppTheme" >
|
||||||
<activity
|
<activity
|
||||||
android:name="com.cradle.iitc_mobile.IITC_Mobile"
|
android:name="com.cradle.iitc_mobile.IITC_Mobile"
|
||||||
android:theme="@style/AppBaseTheme"
|
android:theme="@style/AppBaseTheme"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:configChanges="orientation|keyboard|keyboardHidden|screenSize" >
|
android:configChanges="orientation|keyboard|keyboardHidden|screenSize" >
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.MAIN" />
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
|
||||||
</intent-filter>
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.VIEW"/>
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
<category android:name="android.intent.category.BROWSABLE"/>
|
</intent-filter>
|
||||||
<data android:host="www.ingress.com" android:scheme="https" android:pathPrefix="/intel"></data>
|
<intent-filter>
|
||||||
<data android:host="www.ingress.com" android:scheme="http" android:pathPrefix="/intel"></data>
|
<action android:name="android.intent.action.VIEW"/>
|
||||||
</intent-filter>
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
</activity>
|
<category android:name="android.intent.category.BROWSABLE"/>
|
||||||
<activity
|
<data android:host="www.ingress.com" android:scheme="https" android:pathPrefix="/intel"></data>
|
||||||
android:name="com.cradle.iitc_mobile.IITC_Settings"
|
<data android:host="www.ingress.com" android:scheme="http" android:pathPrefix="/intel"></data>
|
||||||
android:theme="@style/AppBaseTheme"
|
</intent-filter>
|
||||||
android:label="@string/app_name"
|
</activity>
|
||||||
android:configChanges="orientation|keyboard|keyboardHidden|screenSize" >
|
<activity
|
||||||
</activity>
|
android:name="com.cradle.iitc_mobile.IITC_Settings"
|
||||||
</application>
|
android:theme="@style/AppBaseTheme"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:configChanges="orientation|keyboard|keyboardHidden|screenSize" >
|
||||||
|
</activity>
|
||||||
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@ -3,4 +3,4 @@
|
|||||||
<issue id="SetJavaScriptEnabled">
|
<issue id="SetJavaScriptEnabled">
|
||||||
<ignore path="src/com/cradle/ittc_mobile/iitc_webview.java" />
|
<ignore path="src/com/cradle/ittc_mobile/iitc_webview.java" />
|
||||||
</issue>
|
</issue>
|
||||||
</lint>
|
</lint>
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||||
<item android:id="@+id/reload_button"
|
<item android:id="@+id/reload_button"
|
||||||
android:icon="@drawable/ic_menu_refresh"
|
android:icon="@drawable/ic_menu_refresh"
|
||||||
android:orderInCategory="90"
|
android:orderInCategory="90"
|
||||||
android:showAsAction="ifRoom"
|
android:showAsAction="ifRoom"
|
||||||
android:title="@string/reload"></item>
|
android:title="@string/reload"></item>
|
||||||
|
|
||||||
<item android:id="@+id/settings"
|
<item android:id="@+id/settings"
|
||||||
android:orderInCategory="120"
|
android:orderInCategory="120"
|
||||||
android:showAsAction="never"
|
android:showAsAction="never"
|
||||||
android:title="@string/action_settings"></item>
|
android:title="@string/action_settings"></item>
|
||||||
|
|
||||||
<item android:id="@+id/cache_clear"
|
<item android:id="@+id/cache_clear"
|
||||||
android:orderInCategory="100"
|
android:orderInCategory="100"
|
||||||
android:showAsAction="never"
|
android:showAsAction="never"
|
||||||
android:title="@string/cache_clear"></item>
|
android:title="@string/cache_clear"></item>
|
||||||
|
|
||||||
<item android:id="@+id/locate"
|
<item android:id="@+id/locate"
|
||||||
android:icon="@android:drawable/ic_menu_mylocation"
|
android:icon="@android:drawable/ic_menu_mylocation"
|
||||||
android:orderInCategory="80"
|
android:orderInCategory="80"
|
||||||
android:showAsAction="ifRoom"
|
android:showAsAction="ifRoom"
|
||||||
android:title="@string/locate"></item>
|
android:title="@string/locate"></item>
|
||||||
|
|
||||||
</menu>
|
</menu>
|
@ -9,6 +9,7 @@
|
|||||||
<string name="locate">Get Location</string>
|
<string name="locate">Get Location</string>
|
||||||
<string name="local">local</string>
|
<string name="local">local</string>
|
||||||
<string name="build_version">Build Version</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">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>
|
||||||
|
@ -10,16 +10,22 @@
|
|||||||
android:key="pref_developer_options"
|
android:key="pref_developer_options"
|
||||||
android:title="@string/pref_developer_options">
|
android:title="@string/pref_developer_options">
|
||||||
|
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:key="pref_iitc_source"
|
android:key="pref_iitc_source"
|
||||||
android:title="@string/pref_select_iitc"
|
android:title="@string/pref_select_iitc"
|
||||||
android:summary=""
|
android:summary=""
|
||||||
android:defaultValue="local"/>
|
android:defaultValue="local"/>
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:key="pref_build_version"
|
android:key="pref_build_version"
|
||||||
android:title="@string/build_version"
|
android:title="@string/build_version"
|
||||||
android:enabled="false"
|
android:enabled="false"
|
||||||
android:selectable="false" />
|
android:selectable="false" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:key="pref_iitc_version"
|
||||||
|
android:title="@string/iitc_version"
|
||||||
|
android:enabled="false"
|
||||||
|
android:selectable="false" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
@ -11,27 +11,27 @@ import android.widget.Toast;
|
|||||||
// provide communication between IITC script and android app
|
// provide communication between IITC script and android app
|
||||||
public class IITC_JSInterface {
|
public class IITC_JSInterface {
|
||||||
|
|
||||||
// context of main activity
|
// context of main activity
|
||||||
Context context;
|
Context context;
|
||||||
|
|
||||||
IITC_JSInterface(Context c) {
|
IITC_JSInterface(Context c) {
|
||||||
context = c;
|
context = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
// send intent for gmaps link
|
// send intent for gmaps link
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public void intentPosLink(String s) {
|
public void intentPosLink(String s) {
|
||||||
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
|
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
|
||||||
Uri.parse(s));
|
Uri.parse(s));
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy link to specific portal to android clipboard
|
// copy link to specific portal to android clipboard
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public void copy(String s) {
|
public void copy(String s) {
|
||||||
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
ClipData clip = ClipData.newPlainText("Copied Text ", s);
|
ClipData clip = ClipData.newPlainText("Copied Text ", s);
|
||||||
clipboard.setPrimaryClip(clip);
|
clipboard.setPrimaryClip(clip);
|
||||||
Toast.makeText(context, "copied to clipboard", Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, "copied to clipboard", Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,16 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import com.cradle.iitc_mobile.R;
|
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.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.StrictMode;
|
import android.os.StrictMode;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||||
@ -20,138 +24,165 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
public class IITC_Mobile extends Activity {
|
public class IITC_Mobile extends Activity {
|
||||||
|
|
||||||
private IITC_WebView iitc_view;
|
private IITC_WebView iitc_view;
|
||||||
private boolean back_button_pressed = false;
|
private boolean back_button_pressed = false;
|
||||||
private boolean desktop = false;
|
private boolean desktop = false;
|
||||||
private OnSharedPreferenceChangeListener listener;
|
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);
|
@Override
|
||||||
listener = new OnSharedPreferenceChangeListener() {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@Override
|
super.onCreate(savedInstanceState);
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
// TODO build an async task for url.openStream() in IITC_WebViewClient
|
||||||
if (key == "pref_force_desktop")
|
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
|
||||||
desktop = sharedPreferences.getBoolean("pref_force_desktop", false);
|
StrictMode.setThreadPolicy(policy);
|
||||||
// reload intel map
|
setContentView(R.layout.activity_main);
|
||||||
iitc_view.loadUrl(addUrlParam("https://www.ingress.com/intel"));
|
iitc_view = (IITC_WebView) findViewById(R.id.iitc_webview);
|
||||||
injectJS();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
sharedPref.registerOnSharedPreferenceChangeListener(listener);
|
|
||||||
|
|
||||||
// we do not want to reload our page every time we switch orientations...
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
// so restore state if activity was already created
|
listener = new OnSharedPreferenceChangeListener() {
|
||||||
if(savedInstanceState != null) {
|
@Override
|
||||||
iitc_view.restoreState(savedInstanceState);
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
}
|
if (key.equals("pref_force_desktop"))
|
||||||
else {
|
desktop = sharedPreferences.getBoolean("pref_force_desktop", false);
|
||||||
// load new iitc web view with ingress intel page
|
// reload intel map
|
||||||
Intent intent = getIntent();
|
iitc_view.loadUrl(addUrlParam("https://www.ingress.com/intel"));
|
||||||
String action = intent.getAction();
|
injectJS();
|
||||||
if (Intent.ACTION_VIEW.equals(action)) {
|
}
|
||||||
Uri uri = intent.getData();
|
};
|
||||||
String url = uri.toString();
|
sharedPref.registerOnSharedPreferenceChangeListener(listener);
|
||||||
// TODO Why does "if(intent.getScheme() == "http")" not work?
|
|
||||||
if (url.contains("http://"))
|
|
||||||
url = url.replace("http://", "https://");
|
|
||||||
Log.d("Intent received", "url: " + url);
|
|
||||||
if (url.contains("ingress.com")) {
|
|
||||||
Log.d("Intent received", "loading url...");
|
|
||||||
iitc_view.loadUrl(addUrlParam(url));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Log.d("No Intent call", "loading https://www.ingress.com/intel");
|
|
||||||
iitc_view.loadUrl(addUrlParam("https://www.ingress.com/intel"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// save instance state to avoid reloading on orientation change
|
|
||||||
@Override
|
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
|
||||||
iitc_view.saveState(outState);
|
|
||||||
}
|
|
||||||
|
|
||||||
// we want a self defined behavior for the back button
|
// we do not want to reload our page every time we switch orientations...
|
||||||
@Override
|
// so restore state if activity was already created
|
||||||
public void onBackPressed() {
|
if(savedInstanceState != null) {
|
||||||
if (this.back_button_pressed) {
|
iitc_view.restoreState(savedInstanceState);
|
||||||
super.onBackPressed();
|
}
|
||||||
return;
|
else {
|
||||||
}
|
// load new iitc web view with ingress intel page
|
||||||
|
Intent intent = getIntent();
|
||||||
|
String action = intent.getAction();
|
||||||
|
if (Intent.ACTION_VIEW.equals(action)) {
|
||||||
|
Uri uri = intent.getData();
|
||||||
|
String url = uri.toString();
|
||||||
|
if (intent.getScheme().equals("http://"))
|
||||||
|
url = url.replace("http://", "https://");
|
||||||
|
Log.d("Intent received", "url: " + url);
|
||||||
|
if (url.contains("ingress.com")) {
|
||||||
|
Log.d("Intent received", "loading url...");
|
||||||
|
iitc_view.loadUrl(addUrlParam(url));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Log.d("No Intent call", "loading https://www.ingress.com/intel");
|
||||||
|
iitc_view.loadUrl(addUrlParam("https://www.ingress.com/intel"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
iitc_view.loadUrl("javascript: window.goBack();");
|
@Override
|
||||||
this.back_button_pressed = true;
|
protected void onResume() {
|
||||||
Toast.makeText(this, "Press twice to exit", Toast.LENGTH_SHORT).show();
|
// enough idle...let's do some work
|
||||||
|
iitc_view.loadUrl("javascript: window.idleTime = 0");
|
||||||
|
iitc_view.loadUrl("javascript: window.renderUpdateStatus()");
|
||||||
|
super.onResume();
|
||||||
|
}
|
||||||
|
|
||||||
// reset back button after 0.5 seconds
|
@Override
|
||||||
new Handler().postDelayed(new Runnable() {
|
protected void onStop() {
|
||||||
@Override
|
ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
public void run() {
|
|
||||||
back_button_pressed=false;
|
|
||||||
}
|
|
||||||
}, 500);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
State mobile = conMan.getNetworkInfo(0).getState();
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
State wifi = conMan.getNetworkInfo(1).getState();
|
||||||
// Inflate the menu; this adds items to the action bar if it is present.
|
|
||||||
getMenuInflater().inflate(R.menu.main, menu);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (mobile == NetworkInfo.State.CONNECTED || mobile == NetworkInfo.State.CONNECTING) {
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
// cancel all current requests
|
||||||
// Handle item selection
|
iitc_view.loadUrl("javascript: window.requests.abort()");
|
||||||
switch (item.getItemId()) {
|
// set idletime to maximum...no need for more
|
||||||
case R.id.reload_button:
|
iitc_view.loadUrl("javascript: window.idleTime = 999");
|
||||||
iitc_view.loadUrl(addUrlParam("https://www.ingress.com/intel"));
|
} else if (wifi == NetworkInfo.State.CONNECTED || wifi == NetworkInfo.State.CONNECTING) {
|
||||||
injectJS();
|
iitc_view.loadUrl("javascript: window.idleTime = 999");
|
||||||
return true;
|
}
|
||||||
// clear cache
|
super.onStop();
|
||||||
case R.id.cache_clear:
|
}
|
||||||
iitc_view.clearHistory();
|
|
||||||
iitc_view.clearFormData();
|
|
||||||
iitc_view.clearCache(true);
|
|
||||||
return true;
|
|
||||||
// get the users current location and focus it on map
|
|
||||||
case R.id.locate:
|
|
||||||
iitc_view.loadUrl("javascript: window.map.locate({setView : true, maxZoom: 13});");
|
|
||||||
return true;
|
|
||||||
case R.id.settings:
|
|
||||||
startActivity(new Intent(this, IITC_Settings.class));
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void injectJS() {
|
// save instance state to avoid reloading on orientation change
|
||||||
try {
|
@Override
|
||||||
iitc_view.getWebViewClient().loadIITC_JS(this);
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
} catch (IOException e1) {
|
iitc_view.saveState(outState);
|
||||||
e1.printStackTrace();
|
}
|
||||||
} catch (NullPointerException e2) {
|
|
||||||
e2.printStackTrace();
|
// we want a self defined behavior for the back button
|
||||||
}
|
@Override
|
||||||
}
|
public void onBackPressed() {
|
||||||
|
if (this.back_button_pressed) {
|
||||||
private String addUrlParam(String url) {
|
super.onBackPressed();
|
||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
return;
|
||||||
this.desktop = sharedPref.getBoolean("pref_force_desktop", false);
|
}
|
||||||
|
|
||||||
if (desktop)
|
iitc_view.loadUrl("javascript: window.goBack();");
|
||||||
return (url + "?vp=f");
|
this.back_button_pressed = true;
|
||||||
else
|
Toast.makeText(this, "Press twice to exit", Toast.LENGTH_SHORT).show();
|
||||||
return (url + "?vp=m");
|
|
||||||
}
|
// reset back button after 0.5 seconds
|
||||||
|
new Handler().postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
back_button_pressed=false;
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
// Inflate the menu; this adds items to the action bar if it is present.
|
||||||
|
getMenuInflater().inflate(R.menu.main, menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
// Handle item selection
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.reload_button:
|
||||||
|
iitc_view.loadUrl(addUrlParam("https://www.ingress.com/intel"));
|
||||||
|
injectJS();
|
||||||
|
return true;
|
||||||
|
// clear cache
|
||||||
|
case R.id.cache_clear:
|
||||||
|
iitc_view.clearHistory();
|
||||||
|
iitc_view.clearFormData();
|
||||||
|
iitc_view.clearCache(true);
|
||||||
|
return true;
|
||||||
|
// get the users current location and focus it on map
|
||||||
|
case R.id.locate:
|
||||||
|
iitc_view.loadUrl("javascript: window.map.locate({setView : true, maxZoom: 13});");
|
||||||
|
return true;
|
||||||
|
case R.id.settings:
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void injectJS() {
|
||||||
|
try {
|
||||||
|
iitc_view.getWebViewClient().loadIITC_JS(this);
|
||||||
|
} catch (IOException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
} catch (NullPointerException e2) {
|
||||||
|
e2.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String addUrlParam(String url) {
|
||||||
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
this.desktop = sharedPref.getBoolean("pref_force_desktop", false);
|
||||||
|
|
||||||
|
if (desktop)
|
||||||
|
return (url + "?vp=f");
|
||||||
|
else
|
||||||
|
return (url + "?vp=m");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,17 @@ import android.app.Activity;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
public class IITC_Settings extends Activity {
|
public class IITC_Settings extends Activity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
IITC_SettingsFragment settings = new IITC_SettingsFragment();
|
||||||
|
settings.setArguments(getIntent().getExtras());
|
||||||
|
|
||||||
// Display the fragment as the main content.
|
// Display the fragment as the main content.
|
||||||
getFragmentManager().beginTransaction()
|
getFragmentManager().beginTransaction()
|
||||||
.replace(android.R.id.content, new IITC_SettingsFragment())
|
.replace(android.R.id.content, settings)
|
||||||
.commit();
|
.commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,12 +11,15 @@ import android.preference.Preference.OnPreferenceChangeListener;
|
|||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
|
|
||||||
public class IITC_SettingsFragment extends PreferenceFragment {
|
public class IITC_SettingsFragment extends PreferenceFragment {
|
||||||
|
|
||||||
|
String iitc_version;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
iitc_version = getArguments().getString("iitc_version");
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.preferences);
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
|
|
||||||
// set build version
|
// set build version
|
||||||
@ -28,15 +31,21 @@ public class IITC_SettingsFragment extends PreferenceFragment {
|
|||||||
version = info.versionName;
|
version = info.versionName;
|
||||||
}
|
}
|
||||||
catch (NameNotFoundException e) {
|
catch (NameNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
pref_build_version.setSummary(version);
|
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
|
// set iitc source
|
||||||
EditTextPreference pref_iitc_source = (EditTextPreference) findPreference("pref_iitc_source");
|
EditTextPreference pref_iitc_source = (EditTextPreference) findPreference("pref_iitc_source");
|
||||||
pref_iitc_source.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
pref_iitc_source.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
preference.setSummary((CharSequence) newValue);
|
preference.setSummary((CharSequence) newValue);
|
||||||
|
// TODO: update iitc_version when iitc source has changed
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -11,59 +11,59 @@ import android.webkit.GeolocationPermissions;
|
|||||||
@SuppressLint("SetJavaScriptEnabled")
|
@SuppressLint("SetJavaScriptEnabled")
|
||||||
public class IITC_WebView extends WebView {
|
public class IITC_WebView extends WebView {
|
||||||
|
|
||||||
private WebSettings settings;
|
private WebSettings settings;
|
||||||
private IITC_WebViewClient webclient;
|
private IITC_WebViewClient webclient;
|
||||||
private IITC_JSInterface js_interface;
|
private IITC_JSInterface js_interface;
|
||||||
|
|
||||||
// init web view
|
// init web view
|
||||||
private void iitc_init(Context c) {
|
private void iitc_init(Context c) {
|
||||||
settings = this.getSettings();
|
settings = this.getSettings();
|
||||||
settings.setJavaScriptEnabled(true);
|
settings.setJavaScriptEnabled(true);
|
||||||
settings.setDomStorageEnabled(true);
|
settings.setDomStorageEnabled(true);
|
||||||
settings.setAllowFileAccess(true);
|
settings.setAllowFileAccess(true);
|
||||||
settings.setGeolocationEnabled(true);
|
settings.setGeolocationEnabled(true);
|
||||||
this.js_interface = new IITC_JSInterface(c);
|
this.js_interface = new IITC_JSInterface(c);
|
||||||
this.addJavascriptInterface(js_interface, "android");
|
this.addJavascriptInterface(js_interface, "android");
|
||||||
|
|
||||||
// our webchromeclient should share geolocation with the iitc script
|
// our webchromeclient should share geolocation with the iitc script
|
||||||
// allow access by default
|
// allow access by default
|
||||||
this.setWebChromeClient(new WebChromeClient() {
|
this.setWebChromeClient(new WebChromeClient() {
|
||||||
@Override
|
@Override
|
||||||
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
|
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
|
||||||
callback.invoke(origin, true, false);
|
callback.invoke(origin, true, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
webclient = new IITC_WebViewClient(c);
|
webclient = new IITC_WebViewClient(c);
|
||||||
this.setWebViewClient(webclient);
|
this.setWebViewClient(webclient);
|
||||||
}
|
}
|
||||||
|
|
||||||
// constructors -------------------------------------------------
|
// constructors -------------------------------------------------
|
||||||
public IITC_WebView(Context context) {
|
public IITC_WebView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
iitc_init(context);
|
iitc_init(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IITC_WebView(Context context, AttributeSet attrs) {
|
public IITC_WebView(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
|
|
||||||
iitc_init(context);
|
iitc_init(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IITC_WebView(Context context, AttributeSet attrs, int defStyle) {
|
public IITC_WebView(Context context, AttributeSet attrs, int defStyle) {
|
||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
|
|
||||||
iitc_init(context);
|
iitc_init(context);
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
|
|
||||||
public IITC_WebViewClient getWebViewClient() {
|
public IITC_WebViewClient getWebViewClient() {
|
||||||
return this.webclient;
|
return this.webclient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IITC_JSInterface getJSInterface() {
|
public IITC_JSInterface getJSInterface() {
|
||||||
return this.js_interface;
|
return this.js_interface;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,80 +16,97 @@ import java.net.URL;
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
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(
|
||||||
"body, #dashboard_container, #map_canvas { background: #000 !important; }".getBytes());
|
"body, #dashboard_container, #map_canvas { background: #000 !important; }".getBytes());
|
||||||
private static final ByteArrayInputStream empty = new ByteArrayInputStream("".getBytes());
|
private static final ByteArrayInputStream empty = new ByteArrayInputStream("".getBytes());
|
||||||
|
|
||||||
private WebResourceResponse iitcjs;
|
private WebResourceResponse iitcjs;
|
||||||
|
private String js = null;
|
||||||
|
|
||||||
public IITC_WebViewClient(Context c) {
|
public IITC_WebViewClient(Context c) {
|
||||||
try {
|
try {
|
||||||
loadIITC_JS(c);
|
loadIITC_JS(c);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadIITC_JS(Context c) throws java.io.IOException {
|
public String getIITCVersion() {
|
||||||
// in developer options, you are able to load the script from external source
|
String header = js.substring(js.indexOf("==UserScript=="), js.indexOf("==/UserScript=="));
|
||||||
// if a http address is given, use script from this address. else use the local script
|
// remove new line comments
|
||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(c);
|
header = header.replace("\n//", "");
|
||||||
String iitc_source = sharedPref.getString("pref_iitc_source", "local");
|
// get a list of key-value
|
||||||
String js = "";
|
String[] attributes = header.split(" +");
|
||||||
if (iitc_source.contains("http")) {
|
String iitc_version = "not found";
|
||||||
URL url = new URL(iitc_source);
|
for (int i = 0; i < attributes.length; i++) {
|
||||||
js = new Scanner(url.openStream(), "UTF-8").useDelimiter("\\A").next();
|
// search vor version and use the value
|
||||||
} else {
|
if (attributes[i].equals("@version")) iitc_version = attributes[i+1];
|
||||||
InputStream input;
|
}
|
||||||
input = c.getAssets().open("iitc.js");
|
return iitc_version;
|
||||||
int size = input.available();
|
}
|
||||||
byte[] buffer = new byte[size];
|
|
||||||
input.read(buffer);
|
|
||||||
input.close();
|
|
||||||
js = new String(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
// need to wrap the mobile iitc.js version in a document ready. IITC
|
public void loadIITC_JS(Context c) throws java.io.IOException {
|
||||||
// expects to be injected after the DOM has been loaded completely.
|
// in developer options, you are able to load the script from external source
|
||||||
// Since the mobile client injects IITC by replacing the gen_dashboard
|
// if a http address is given, use script from this address. else use the local script
|
||||||
// file, IITC runs to early. The document.ready delays IITC long enough
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(c);
|
||||||
// so it boots correctly.
|
String iitc_source = sharedPref.getString("pref_iitc_source", "local");
|
||||||
js = "$(document).ready(function(){" + js + "});";
|
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();
|
||||||
|
js = new String(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
iitcjs = new WebResourceResponse(
|
this.js = js;
|
||||||
"text/javascript",
|
|
||||||
"UTF-8",
|
|
||||||
new ByteArrayInputStream(js.getBytes())
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
// enable https
|
// need to wrap the mobile iitc.js version in a document ready. IITC
|
||||||
@Override
|
// expects to be injected after the DOM has been loaded completely.
|
||||||
public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
|
// Since the mobile client injects IITC by replacing the gen_dashboard
|
||||||
handler.proceed() ;
|
// file, IITC runs to early. The document.ready delays IITC long enough
|
||||||
};
|
// so it boots correctly.
|
||||||
|
js = "$(document).ready(function(){" + js + "});";
|
||||||
|
|
||||||
// Check every external resource if it’s okay to load it and maybe replace it
|
iitcjs = new WebResourceResponse(
|
||||||
// with our own content. This is used to block loading Niantic resources
|
"text/javascript",
|
||||||
// which aren’t required and to inject IITC early into the site.
|
"UTF-8",
|
||||||
// via http://stackoverflow.com/a/8274881/1684530
|
new ByteArrayInputStream(js.getBytes())
|
||||||
@Override
|
);
|
||||||
public WebResourceResponse shouldInterceptRequest (final WebView view, String url) {
|
};
|
||||||
if(url.contains("/css/common.css")) {
|
|
||||||
return new WebResourceResponse("text/css", "UTF-8", style);
|
// enable https
|
||||||
} else if(url.contains("gen_dashboard.js")) {
|
@Override
|
||||||
return this.iitcjs;
|
public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
|
||||||
} else if(url.contains("/css/ap_icons.css")
|
handler.proceed() ;
|
||||||
|| url.contains("/css/map_icons.css")
|
};
|
||||||
|| url.contains("/css/misc_icons.css")
|
|
||||||
|| url.contains("/css/style_full.css")
|
// Check every external resource if it’s okay to load it and maybe replace it
|
||||||
|| url.contains("/css/style_mobile.css")
|
// with our own content. This is used to block loading Niantic resources
|
||||||
|| url.contains("/css/portalrender.css")
|
// which aren’t required and to inject IITC early into the site.
|
||||||
|| url.contains("js/analytics.js")
|
// via http://stackoverflow.com/a/8274881/1684530
|
||||||
|| url.contains("google-analytics.com/ga.js")) {
|
@Override
|
||||||
return new WebResourceResponse("text/plain", "UTF-8", empty);
|
public WebResourceResponse shouldInterceptRequest (final WebView view, String url) {
|
||||||
} else {
|
if(url.contains("/css/common.css")) {
|
||||||
return super.shouldInterceptRequest(view, url);
|
return new WebResourceResponse("text/css", "UTF-8", style);
|
||||||
}
|
} else if(url.contains("gen_dashboard.js")) {
|
||||||
}
|
return this.iitcjs;
|
||||||
|
} else if(url.contains("/css/ap_icons.css")
|
||||||
|
|| url.contains("/css/map_icons.css")
|
||||||
|
|| url.contains("/css/misc_icons.css")
|
||||||
|
|| url.contains("/css/style_full.css")
|
||||||
|
|| url.contains("/css/style_mobile.css")
|
||||||
|
|| url.contains("/css/portalrender.css")
|
||||||
|
|| url.contains("js/analytics.js")
|
||||||
|
|| url.contains("google-analytics.com/ga.js")) {
|
||||||
|
return new WebResourceResponse("text/plain", "UTF-8", empty);
|
||||||
|
} else {
|
||||||
|
return super.shouldInterceptRequest(view, url);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user