added new iitc mobile project
This commit is contained in:
92
mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java
Normal file
92
mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java
Normal file
@ -0,0 +1,92 @@
|
||||
package com.cradle.iitc_mobile;
|
||||
|
||||
import com.cradle.iitc_mobile.R;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.app.Activity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnTouchListener;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class IITC_Mobile extends Activity {
|
||||
|
||||
private IITC_WebView iitc_view;
|
||||
private boolean back_button_pressed = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
// 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_WebView)findViewById(R.id.webview)).restoreState(savedInstanceState);
|
||||
}
|
||||
else {
|
||||
// load new iitc web view with ingress intel page
|
||||
iitc_view= (IITC_WebView) findViewById(R.id.webview);
|
||||
iitc_view.setWebChromeClient(new WebChromeClient());
|
||||
iitc_view.loadUrl("https://www.ingress.com/intel");
|
||||
|
||||
// listen to touches (think we need this)
|
||||
iitc_view.setOnTouchListener(new OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
back_button_pressed = false;
|
||||
// return false to indicate, that we don't consumed this event. this leads
|
||||
// to the execution of our touch event
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 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 on resume
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
this.back_button_pressed = false;
|
||||
}
|
||||
|
||||
// we want a self defined behavior for the back button
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (this.back_button_pressed) {
|
||||
super.onBackPressed();
|
||||
return;
|
||||
}
|
||||
this.back_button_pressed = true;
|
||||
Toast.makeText(this, "Press twice to exit", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@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.reload();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
}
|
46
mobile/src/com/cradle/iitc_mobile/IITC_WebView.java
Normal file
46
mobile/src/com/cradle/iitc_mobile/IITC_WebView.java
Normal file
@ -0,0 +1,46 @@
|
||||
package com.cradle.iitc_mobile;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
public class IITC_WebView extends WebView {
|
||||
|
||||
private WebSettings settings;
|
||||
private IITC_WebViewClient webclient;
|
||||
|
||||
// init web view
|
||||
private void iitc_init() {
|
||||
settings = this.getSettings();
|
||||
settings.setJavaScriptEnabled(true);
|
||||
settings.setDomStorageEnabled(true);
|
||||
settings.setAllowFileAccess(true);
|
||||
|
||||
webclient = new IITC_WebViewClient();
|
||||
this.setWebViewClient(webclient);
|
||||
}
|
||||
|
||||
// constructors -------------------------------------------------
|
||||
public IITC_WebView(Context context) {
|
||||
super(context);
|
||||
|
||||
iitc_init();
|
||||
}
|
||||
|
||||
public IITC_WebView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
iitc_init();
|
||||
}
|
||||
|
||||
public IITC_WebView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
|
||||
iitc_init();
|
||||
}
|
||||
//----------------------------------------------------------------
|
||||
|
||||
}
|
37
mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java
Normal file
37
mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java
Normal file
@ -0,0 +1,37 @@
|
||||
package com.cradle.iitc_mobile;
|
||||
|
||||
import android.net.http.SslError;
|
||||
import android.util.Log;
|
||||
import android.webkit.CookieManager;
|
||||
import android.webkit.SslErrorHandler;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
|
||||
public class IITC_WebViewClient extends WebViewClient {
|
||||
|
||||
// enable https
|
||||
@Override
|
||||
public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
|
||||
handler.proceed() ;
|
||||
};
|
||||
|
||||
// injecting IITC when page is loaded
|
||||
@Override
|
||||
public void onPageFinished(WebView web, String Url) {
|
||||
Log.d("loading finish", web.getUrl());
|
||||
if (web.getUrl().contains("ingress.com/intel") && !web.getUrl().contains("accounts")) {
|
||||
// first check for cookies, than inject javascript
|
||||
// this enables the user to login if necessary
|
||||
CookieManager cm = CookieManager.getInstance();
|
||||
final String cookie = cm.getCookie("https://www.ingress.com/intel");
|
||||
if(cookie != null) {
|
||||
web.loadUrl("javascript: (function() { "
|
||||
+ "var script=document.createElement('script');"
|
||||
+ "script.type='text/javascript';"
|
||||
+ "script.src='https://iitcserv.appspot.com/iitc-nightly/iitc-nightly-latest.user.js';"
|
||||
+ "document.getElementsByTagName('head').item(0).appendChild(script);"
|
||||
+ "})()");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user