fixed indentations and trailing whitespaces
This commit is contained in:
parent
0e298c3526
commit
61fa36ff76
@ -1,44 +1,44 @@
|
|||||||
<?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.5" >
|
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" />
|
||||||
|
|
||||||
<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>
|
@ -10,22 +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
|
<ListPreference
|
||||||
android:key="pref_iitc_version"
|
android:key="pref_iitc_version"
|
||||||
android:title="@string/iitc_version"
|
android:title="@string/iitc_version"
|
||||||
android:enabled="false"
|
android:enabled="false"
|
||||||
android:selectable="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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,140 +20,140 @@ 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 == "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();
|
||||||
|
// 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"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
iitc_view.loadUrl("javascript: window.goBack();");
|
// save instance state to avoid reloading on orientation change
|
||||||
this.back_button_pressed = true;
|
@Override
|
||||||
Toast.makeText(this, "Press twice to exit", Toast.LENGTH_SHORT).show();
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
|
iitc_view.saveState(outState);
|
||||||
|
}
|
||||||
|
|
||||||
// reset back button after 0.5 seconds
|
// we want a self defined behavior for the back button
|
||||||
new Handler().postDelayed(new Runnable() {
|
@Override
|
||||||
@Override
|
public void onBackPressed() {
|
||||||
public void run() {
|
if (this.back_button_pressed) {
|
||||||
back_button_pressed=false;
|
super.onBackPressed();
|
||||||
}
|
return;
|
||||||
}, 500);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
iitc_view.loadUrl("javascript: window.goBack();");
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
this.back_button_pressed = true;
|
||||||
// Inflate the menu; this adds items to the action bar if it is present.
|
Toast.makeText(this, "Press twice to exit", Toast.LENGTH_SHORT).show();
|
||||||
getMenuInflater().inflate(R.menu.main, menu);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
// reset back button after 0.5 seconds
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
new Handler().postDelayed(new Runnable() {
|
||||||
// Handle item selection
|
@Override
|
||||||
switch (item.getItemId()) {
|
public void run() {
|
||||||
case R.id.reload_button:
|
back_button_pressed=false;
|
||||||
iitc_view.loadUrl(addUrlParam("https://www.ingress.com/intel"));
|
}
|
||||||
injectJS();
|
}, 500);
|
||||||
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() {
|
@Override
|
||||||
try {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
iitc_view.getWebViewClient().loadIITC_JS(this);
|
// Inflate the menu; this adds items to the action bar if it is present.
|
||||||
} catch (IOException e1) {
|
getMenuInflater().inflate(R.menu.main, menu);
|
||||||
e1.printStackTrace();
|
return true;
|
||||||
} catch (NullPointerException e2) {
|
}
|
||||||
e2.printStackTrace();
|
|
||||||
}
|
@Override
|
||||||
}
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
// Handle item selection
|
||||||
private String addUrlParam(String url) {
|
switch (item.getItemId()) {
|
||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
case R.id.reload_button:
|
||||||
this.desktop = sharedPref.getBoolean("pref_force_desktop", false);
|
iitc_view.loadUrl(addUrlParam("https://www.ingress.com/intel"));
|
||||||
|
injectJS();
|
||||||
if (desktop)
|
return true;
|
||||||
return (url + "?vp=f");
|
// clear cache
|
||||||
else
|
case R.id.cache_clear:
|
||||||
return (url + "?vp=m");
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,97 +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;
|
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 String getIITCVersion() {
|
public String getIITCVersion() {
|
||||||
String header = js.substring(js.indexOf("==UserScript=="), js.indexOf("==/UserScript=="));
|
String header = js.substring(js.indexOf("==UserScript=="), js.indexOf("==/UserScript=="));
|
||||||
// remove new line comments
|
// remove new line comments
|
||||||
header = header.replace("\n//", "");
|
header = header.replace("\n//", "");
|
||||||
// get a list of key-value
|
// get a list of key-value
|
||||||
String[] attributes = header.split(" +");
|
String[] attributes = header.split(" +");
|
||||||
String iitc_version = "not found";
|
String iitc_version = "not found";
|
||||||
for (int i = 0; i < attributes.length; i++) {
|
for (int i = 0; i < attributes.length; i++) {
|
||||||
// search vor version and use the value
|
// search vor version and use the value
|
||||||
if (attributes[i].contains("@version")) iitc_version = attributes[i+1];
|
if (attributes[i].contains("@version")) iitc_version = attributes[i+1];
|
||||||
}
|
}
|
||||||
return iitc_version;
|
return iitc_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadIITC_JS(Context c) throws java.io.IOException {
|
public void loadIITC_JS(Context c) throws java.io.IOException {
|
||||||
// in developer options, you are able to load the script from external source
|
// 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
|
// if a http address is given, use script from this address. else use the local script
|
||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(c);
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(c);
|
||||||
String iitc_source = sharedPref.getString("pref_iitc_source", "local");
|
String iitc_source = sharedPref.getString("pref_iitc_source", "local");
|
||||||
String js = "";
|
String js = "";
|
||||||
if (iitc_source.contains("http")) {
|
if (iitc_source.contains("http")) {
|
||||||
URL url = new URL(iitc_source);
|
URL url = new URL(iitc_source);
|
||||||
js = new Scanner(url.openStream(), "UTF-8").useDelimiter("\\A").next();
|
js = new Scanner(url.openStream(), "UTF-8").useDelimiter("\\A").next();
|
||||||
} else {
|
} else {
|
||||||
InputStream input;
|
InputStream input;
|
||||||
input = c.getAssets().open("iitc.js");
|
input = c.getAssets().open("iitc.js");
|
||||||
int size = input.available();
|
int size = input.available();
|
||||||
byte[] buffer = new byte[size];
|
byte[] buffer = new byte[size];
|
||||||
input.read(buffer);
|
input.read(buffer);
|
||||||
input.close();
|
input.close();
|
||||||
js = new String(buffer);
|
js = new String(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.js = js;
|
this.js = js;
|
||||||
|
|
||||||
// need to wrap the mobile iitc.js version in a document ready. IITC
|
// need to wrap the mobile iitc.js version in a document ready. IITC
|
||||||
// expects to be injected after the DOM has been loaded completely.
|
// expects to be injected after the DOM has been loaded completely.
|
||||||
// Since the mobile client injects IITC by replacing the gen_dashboard
|
// Since the mobile client injects IITC by replacing the gen_dashboard
|
||||||
// file, IITC runs to early. The document.ready delays IITC long enough
|
// file, IITC runs to early. The document.ready delays IITC long enough
|
||||||
// so it boots correctly.
|
// so it boots correctly.
|
||||||
js = "$(document).ready(function(){" + js + "});";
|
js = "$(document).ready(function(){" + js + "});";
|
||||||
|
|
||||||
iitcjs = new WebResourceResponse(
|
iitcjs = new WebResourceResponse(
|
||||||
"text/javascript",
|
"text/javascript",
|
||||||
"UTF-8",
|
"UTF-8",
|
||||||
new ByteArrayInputStream(js.getBytes())
|
new ByteArrayInputStream(js.getBytes())
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// enable https
|
// enable https
|
||||||
@Override
|
@Override
|
||||||
public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
|
public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
|
||||||
handler.proceed() ;
|
handler.proceed() ;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check every external resource if it’s okay to load it and maybe replace it
|
// 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
|
// with our own content. This is used to block loading Niantic resources
|
||||||
// which aren’t required and to inject IITC early into the site.
|
// which aren’t required and to inject IITC early into the site.
|
||||||
// via http://stackoverflow.com/a/8274881/1684530
|
// via http://stackoverflow.com/a/8274881/1684530
|
||||||
@Override
|
@Override
|
||||||
public WebResourceResponse shouldInterceptRequest (final WebView view, String url) {
|
public WebResourceResponse shouldInterceptRequest (final WebView view, String url) {
|
||||||
if(url.contains("/css/common.css")) {
|
if(url.contains("/css/common.css")) {
|
||||||
return new WebResourceResponse("text/css", "UTF-8", style);
|
return new WebResourceResponse("text/css", "UTF-8", style);
|
||||||
} else if(url.contains("gen_dashboard.js")) {
|
} else if(url.contains("gen_dashboard.js")) {
|
||||||
return this.iitcjs;
|
return this.iitcjs;
|
||||||
} else if(url.contains("/css/ap_icons.css")
|
} else if(url.contains("/css/ap_icons.css")
|
||||||
|| url.contains("/css/map_icons.css")
|
|| url.contains("/css/map_icons.css")
|
||||||
|| url.contains("/css/misc_icons.css")
|
|| url.contains("/css/misc_icons.css")
|
||||||
|| url.contains("/css/style_full.css")
|
|| url.contains("/css/style_full.css")
|
||||||
|| url.contains("/css/style_mobile.css")
|
|| url.contains("/css/style_mobile.css")
|
||||||
|| url.contains("/css/portalrender.css")
|
|| url.contains("/css/portalrender.css")
|
||||||
|| url.contains("js/analytics.js")
|
|| url.contains("js/analytics.js")
|
||||||
|| url.contains("google-analytics.com/ga.js")) {
|
|| url.contains("google-analytics.com/ga.js")) {
|
||||||
return new WebResourceResponse("text/plain", "UTF-8", empty);
|
return new WebResourceResponse("text/plain", "UTF-8", empty);
|
||||||
} else {
|
} else {
|
||||||
return super.shouldInterceptRequest(view, url);
|
return super.shouldInterceptRequest(view, url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user