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"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.cradle.iitc_mobile"
|
||||
android:versionCode="1"
|
||||
android:versionName="0.2.5" >
|
||||
package="com.cradle.iitc_mobile"
|
||||
android:versionCode="1"
|
||||
android:versionName="0.2.5" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="14"
|
||||
android:targetSdkVersion="17" />
|
||||
<uses-sdk
|
||||
android:minSdkVersion="14"
|
||||
android:targetSdkVersion="17" />
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/iitc_icon"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
<activity
|
||||
android:name="com.cradle.iitc_mobile.IITC_Mobile"
|
||||
android:theme="@style/AppBaseTheme"
|
||||
android:label="@string/app_name"
|
||||
android:configChanges="orientation|keyboard|keyboardHidden|screenSize" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/iitc_icon"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
<activity
|
||||
android:name="com.cradle.iitc_mobile.IITC_Mobile"
|
||||
android:theme="@style/AppBaseTheme"
|
||||
android:label="@string/app_name"
|
||||
android:configChanges="orientation|keyboard|keyboardHidden|screenSize" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
<data android:host="www.ingress.com" android:scheme="https" android:pathPrefix="/intel"></data>
|
||||
<data android:host="www.ingress.com" android:scheme="http" android:pathPrefix="/intel"></data>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.cradle.iitc_mobile.IITC_Settings"
|
||||
android:theme="@style/AppBaseTheme"
|
||||
android:label="@string/app_name"
|
||||
android:configChanges="orientation|keyboard|keyboardHidden|screenSize" >
|
||||
</activity>
|
||||
</application>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
<data android:host="www.ingress.com" android:scheme="https" android:pathPrefix="/intel"></data>
|
||||
<data android:host="www.ingress.com" android:scheme="http" android:pathPrefix="/intel"></data>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.cradle.iitc_mobile.IITC_Settings"
|
||||
android:theme="@style/AppBaseTheme"
|
||||
android:label="@string/app_name"
|
||||
android:configChanges="orientation|keyboard|keyboardHidden|screenSize" >
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
@ -3,4 +3,4 @@
|
||||
<issue id="SetJavaScriptEnabled">
|
||||
<ignore path="src/com/cradle/ittc_mobile/iitc_webview.java" />
|
||||
</issue>
|
||||
</lint>
|
||||
</lint>
|
||||
|
@ -1,24 +1,24 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<item android:id="@+id/reload_button"
|
||||
android:icon="@drawable/ic_menu_refresh"
|
||||
android:orderInCategory="90"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/reload"></item>
|
||||
<item android:id="@+id/reload_button"
|
||||
android:icon="@drawable/ic_menu_refresh"
|
||||
android:orderInCategory="90"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/reload"></item>
|
||||
|
||||
<item android:id="@+id/settings"
|
||||
android:orderInCategory="120"
|
||||
android:showAsAction="never"
|
||||
android:title="@string/action_settings"></item>
|
||||
<item android:id="@+id/settings"
|
||||
android:orderInCategory="120"
|
||||
android:showAsAction="never"
|
||||
android:title="@string/action_settings"></item>
|
||||
|
||||
<item android:id="@+id/cache_clear"
|
||||
android:orderInCategory="100"
|
||||
android:showAsAction="never"
|
||||
android:title="@string/cache_clear"></item>
|
||||
<item android:id="@+id/cache_clear"
|
||||
android:orderInCategory="100"
|
||||
android:showAsAction="never"
|
||||
android:title="@string/cache_clear"></item>
|
||||
|
||||
<item android:id="@+id/locate"
|
||||
android:icon="@android:drawable/ic_menu_mylocation"
|
||||
android:orderInCategory="80"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/locate"></item>
|
||||
<item android:id="@+id/locate"
|
||||
android:icon="@android:drawable/ic_menu_mylocation"
|
||||
android:orderInCategory="80"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/locate"></item>
|
||||
|
||||
</menu>
|
@ -10,22 +10,22 @@
|
||||
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"/>
|
||||
<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" />
|
||||
<ListPreference
|
||||
android:key="pref_build_version"
|
||||
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" />
|
||||
<ListPreference
|
||||
android:key="pref_iitc_version"
|
||||
android:title="@string/iitc_version"
|
||||
android:enabled="false"
|
||||
android:selectable="false" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
@ -11,27 +11,27 @@ import android.widget.Toast;
|
||||
// provide communication between IITC script and android app
|
||||
public class IITC_JSInterface {
|
||||
|
||||
// context of main activity
|
||||
Context context;
|
||||
// context of main activity
|
||||
Context context;
|
||||
|
||||
IITC_JSInterface(Context c) {
|
||||
context = c;
|
||||
}
|
||||
IITC_JSInterface(Context c) {
|
||||
context = c;
|
||||
}
|
||||
|
||||
// send intent for gmaps link
|
||||
@JavascriptInterface
|
||||
public void intentPosLink(String s) {
|
||||
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
|
||||
Uri.parse(s));
|
||||
context.startActivity(intent);
|
||||
}
|
||||
// send intent for gmaps link
|
||||
@JavascriptInterface
|
||||
public void intentPosLink(String s) {
|
||||
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
|
||||
Uri.parse(s));
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
// copy link to specific portal to android clipboard
|
||||
@JavascriptInterface
|
||||
public void copy(String s) {
|
||||
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData clip = ClipData.newPlainText("Copied Text ", s);
|
||||
clipboard.setPrimaryClip(clip);
|
||||
Toast.makeText(context, "copied to clipboard", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
// copy link to specific portal to android clipboard
|
||||
@JavascriptInterface
|
||||
public void copy(String s) {
|
||||
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData clip = ClipData.newPlainText("Copied Text ", s);
|
||||
clipboard.setPrimaryClip(clip);
|
||||
Toast.makeText(context, "copied to clipboard", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
@ -20,140 +20,140 @@ import android.widget.Toast;
|
||||
|
||||
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);
|
||||
private IITC_WebView iitc_view;
|
||||
private boolean back_button_pressed = false;
|
||||
private boolean desktop = false;
|
||||
private OnSharedPreferenceChangeListener listener;
|
||||
|
||||
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);
|
||||
@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);
|
||||
|
||||
// we do not want to reload our page every time we switch orientations...
|
||||
// so restore state if activity was already created
|
||||
if(savedInstanceState != null) {
|
||||
iitc_view.restoreState(savedInstanceState);
|
||||
}
|
||||
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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// save instance state to avoid reloading on orientation change
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
iitc_view.saveState(outState);
|
||||
}
|
||||
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 want a self defined behavior for the back button
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (this.back_button_pressed) {
|
||||
super.onBackPressed();
|
||||
return;
|
||||
}
|
||||
// we do not want to reload our page every time we switch orientations...
|
||||
// so restore state if activity was already created
|
||||
if(savedInstanceState != null) {
|
||||
iitc_view.restoreState(savedInstanceState);
|
||||
}
|
||||
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();");
|
||||
this.back_button_pressed = true;
|
||||
Toast.makeText(this, "Press twice to exit", Toast.LENGTH_SHORT).show();
|
||||
// save instance state to avoid reloading on orientation change
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
iitc_view.saveState(outState);
|
||||
}
|
||||
|
||||
// reset back button after 0.5 seconds
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
back_button_pressed=false;
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
// we want a self defined behavior for the back button
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (this.back_button_pressed) {
|
||||
super.onBackPressed();
|
||||
return;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
iitc_view.loadUrl("javascript: window.goBack();");
|
||||
this.back_button_pressed = true;
|
||||
Toast.makeText(this, "Press twice to exit", Toast.LENGTH_SHORT).show();
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
// reset back button after 0.5 seconds
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
back_button_pressed=false;
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
@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");
|
||||
}
|
||||
}
|
||||
|
@ -11,59 +11,59 @@ import android.webkit.GeolocationPermissions;
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
public class IITC_WebView extends WebView {
|
||||
|
||||
private WebSettings settings;
|
||||
private IITC_WebViewClient webclient;
|
||||
private IITC_JSInterface js_interface;
|
||||
private WebSettings settings;
|
||||
private IITC_WebViewClient webclient;
|
||||
private IITC_JSInterface js_interface;
|
||||
|
||||
// init web view
|
||||
private void iitc_init(Context c) {
|
||||
settings = this.getSettings();
|
||||
settings.setJavaScriptEnabled(true);
|
||||
settings.setDomStorageEnabled(true);
|
||||
settings.setAllowFileAccess(true);
|
||||
settings.setGeolocationEnabled(true);
|
||||
this.js_interface = new IITC_JSInterface(c);
|
||||
this.addJavascriptInterface(js_interface, "android");
|
||||
// init web view
|
||||
private void iitc_init(Context c) {
|
||||
settings = this.getSettings();
|
||||
settings.setJavaScriptEnabled(true);
|
||||
settings.setDomStorageEnabled(true);
|
||||
settings.setAllowFileAccess(true);
|
||||
settings.setGeolocationEnabled(true);
|
||||
this.js_interface = new IITC_JSInterface(c);
|
||||
this.addJavascriptInterface(js_interface, "android");
|
||||
|
||||
// our webchromeclient should share geolocation with the iitc script
|
||||
// allow access by default
|
||||
this.setWebChromeClient(new WebChromeClient() {
|
||||
@Override
|
||||
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
|
||||
callback.invoke(origin, true, false);
|
||||
}
|
||||
});
|
||||
// our webchromeclient should share geolocation with the iitc script
|
||||
// allow access by default
|
||||
this.setWebChromeClient(new WebChromeClient() {
|
||||
@Override
|
||||
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
|
||||
callback.invoke(origin, true, false);
|
||||
}
|
||||
});
|
||||
|
||||
webclient = new IITC_WebViewClient(c);
|
||||
this.setWebViewClient(webclient);
|
||||
}
|
||||
webclient = new IITC_WebViewClient(c);
|
||||
this.setWebViewClient(webclient);
|
||||
}
|
||||
|
||||
// constructors -------------------------------------------------
|
||||
public IITC_WebView(Context context) {
|
||||
super(context);
|
||||
// constructors -------------------------------------------------
|
||||
public IITC_WebView(Context context) {
|
||||
super(context);
|
||||
|
||||
iitc_init(context);
|
||||
}
|
||||
iitc_init(context);
|
||||
}
|
||||
|
||||
public IITC_WebView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
public IITC_WebView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
iitc_init(context);
|
||||
}
|
||||
iitc_init(context);
|
||||
}
|
||||
|
||||
public IITC_WebView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
public IITC_WebView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
|
||||
iitc_init(context);
|
||||
}
|
||||
//----------------------------------------------------------------
|
||||
iitc_init(context);
|
||||
}
|
||||
//----------------------------------------------------------------
|
||||
|
||||
public IITC_WebViewClient getWebViewClient() {
|
||||
return this.webclient;
|
||||
}
|
||||
public IITC_WebViewClient getWebViewClient() {
|
||||
return this.webclient;
|
||||
}
|
||||
|
||||
public IITC_JSInterface getJSInterface() {
|
||||
return this.js_interface;
|
||||
}
|
||||
public IITC_JSInterface getJSInterface() {
|
||||
return this.js_interface;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,97 +16,97 @@ import java.net.URL;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class IITC_WebViewClient extends WebViewClient {
|
||||
private static final ByteArrayInputStream style = new ByteArrayInputStream(
|
||||
"body, #dashboard_container, #map_canvas { background: #000 !important; }".getBytes());
|
||||
private static final ByteArrayInputStream empty = new ByteArrayInputStream("".getBytes());
|
||||
private static final ByteArrayInputStream style = new ByteArrayInputStream(
|
||||
"body, #dashboard_container, #map_canvas { background: #000 !important; }".getBytes());
|
||||
private static final ByteArrayInputStream empty = new ByteArrayInputStream("".getBytes());
|
||||
|
||||
private WebResourceResponse iitcjs;
|
||||
private String js = null;
|
||||
private WebResourceResponse iitcjs;
|
||||
private String js = null;
|
||||
|
||||
public IITC_WebViewClient(Context c) {
|
||||
try {
|
||||
loadIITC_JS(c);
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public IITC_WebViewClient(Context c) {
|
||||
try {
|
||||
loadIITC_JS(c);
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
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].contains("@version")) iitc_version = attributes[i+1];
|
||||
}
|
||||
return iitc_version;
|
||||
}
|
||||
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].contains("@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
|
||||
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();
|
||||
js = new String(buffer);
|
||||
}
|
||||
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();
|
||||
js = new String(buffer);
|
||||
}
|
||||
|
||||
this.js = js;
|
||||
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
|
||||
// file, IITC runs to early. The document.ready delays IITC long enough
|
||||
// so it boots correctly.
|
||||
js = "$(document).ready(function(){" + 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
|
||||
// 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())
|
||||
);
|
||||
};
|
||||
iitcjs = new WebResourceResponse(
|
||||
"text/javascript",
|
||||
"UTF-8",
|
||||
new ByteArrayInputStream(js.getBytes())
|
||||
);
|
||||
};
|
||||
|
||||
// enable https
|
||||
@Override
|
||||
public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
|
||||
handler.proceed() ;
|
||||
};
|
||||
// enable https
|
||||
@Override
|
||||
public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
|
||||
handler.proceed() ;
|
||||
};
|
||||
|
||||
// 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
|
||||
// which aren’t required and to inject IITC early into the site.
|
||||
// via http://stackoverflow.com/a/8274881/1684530
|
||||
@Override
|
||||
public WebResourceResponse shouldInterceptRequest (final WebView view, String url) {
|
||||
if(url.contains("/css/common.css")) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
// 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
|
||||
// which aren’t required and to inject IITC early into the site.
|
||||
// via http://stackoverflow.com/a/8274881/1684530
|
||||
@Override
|
||||
public WebResourceResponse shouldInterceptRequest (final WebView view, String url) {
|
||||
if(url.contains("/css/common.css")) {
|
||||
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