disable splash screen on JS error and HTTP response error code (fixes #475)

This commit is contained in:
Philipp Schaefer 2013-08-10 17:34:18 +02:00
parent e85af06559
commit 855ad003a2
7 changed files with 76 additions and 21 deletions

View File

@ -506,8 +506,8 @@ function boot() {
window.iitcLoaded = true; window.iitcLoaded = true;
window.runHooks('iitcLoaded'); window.runHooks('iitcLoaded');
if (typeof android !== 'undefined' && android && android.iitcLoaded) { if (typeof android !== 'undefined' && android && android.removeSplashScreen) {
android.iitcLoaded(); android.removeSplashScreen();
} }
} }

View File

@ -1,8 +1,8 @@
<?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="34" android:versionCode="35"
android:versionName="0.5.3"> android:versionName="0.5.4">
<uses-sdk <uses-sdk
android:minSdkVersion="14" android:minSdkVersion="14"

View File

@ -126,8 +126,8 @@ public class IITC_JSInterface {
} }
@JavascriptInterface @JavascriptInterface
public void iitcLoaded() { public void removeSplashScreen() {
Log.d("iitcm", "iitc loaded completely"); Log.d("iitcm", "removing splash screen");
final IITC_Mobile iitc = ((IITC_Mobile) mContext); final IITC_Mobile iitc = ((IITC_Mobile) mContext);
iitc.runOnUiThread(new Runnable() { iitc.runOnUiThread(new Runnable() {

View File

@ -274,7 +274,6 @@ public class IITC_Mobile extends Activity {
// enough idle...let's do some work // enough idle...let's do some work
Log.d("iitcm", "resuming...setting reset idleTimer"); Log.d("iitcm", "resuming...setting reset idleTimer");
mIitcWebView.loadUrl("javascript: window.idleTime = 0"); mIitcWebView.loadUrl("javascript: window.idleTime = 0");
mIitcWebView.loadUrl("javascript: window.renderUpdateStatus()");
mIitcWebView.updateCaching(); mIitcWebView.updateCaching();
if (mIsLocEnabled) { if (mIsLocEnabled) {

View File

@ -11,11 +11,14 @@ import android.os.Build;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import android.webkit.ConsoleMessage;
import android.webkit.GeolocationPermissions; import android.webkit.GeolocationPermissions;
import android.webkit.WebChromeClient; import android.webkit.WebChromeClient;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
import com.cradle.iitc_mobile.async.CheckHttpResponse;
@SuppressLint("SetJavaScriptEnabled") @SuppressLint("SetJavaScriptEnabled")
public class IITC_WebView extends WebView { public class IITC_WebView extends WebView {
@ -63,6 +66,18 @@ public class IITC_WebView extends WebView {
// maximum for setProgress is 10,000 // maximum for setProgress is 10,000
((Activity) getContext()).setProgress(newProgress * 100); ((Activity) getContext()).setProgress(newProgress * 100);
} }
/**
* remove splash screen if any JS error occurs
*/
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
if (consoleMessage.messageLevel() == ConsoleMessage.MessageLevel.ERROR) {
Log.d("iitcm", consoleMessage.message());
mJsInterface.removeSplashScreen();
}
return super.onConsoleMessage(consoleMessage);
}
}); });
mIitcWebViewClient = new IITC_WebViewClient(c); mIitcWebViewClient = new IITC_WebViewClient(c);
@ -117,6 +132,9 @@ public class IITC_WebView extends WebView {
url = url.replace("http://", "https://"); url = url.replace("http://", "https://");
else else
url = url.replace("https://", "http://"); url = url.replace("https://", "http://");
// disable splash screen if a http error code is responded
new CheckHttpResponse(mJsInterface).execute(url);
Log.d("iitcm", "loading url: " + url); Log.d("iitcm", "loading url: " + url);
} }
super.loadUrl(url); super.loadUrl(url);

View File

@ -10,7 +10,6 @@ import android.net.http.SslError;
import android.os.Environment; import android.os.Environment;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.view.View;
import android.webkit.SslErrorHandler; import android.webkit.SslErrorHandler;
import android.webkit.WebResourceResponse; import android.webkit.WebResourceResponse;
import android.webkit.WebSettings; import android.webkit.WebSettings;
@ -292,18 +291,6 @@ public class IITC_WebViewClient extends WebViewClient {
return js; return js;
} }
@Override
public void onLoadResource(WebView view, String url) {
if(url.contains("css/basic.css")) {
Log.d("iitcm", "basic.css received...should be ingress intel login");
// get rid of loading screen to log in
IITC_Mobile iitc = (IITC_Mobile) mContext;
iitc.findViewById(R.id.iitc_webview).setVisibility(View.VISIBLE);
iitc.findViewById(R.id.imageLoading).setVisibility(View.GONE);
}
super.onLoadResource(view, url);
}
// Check every external resource if its okay to load it and maybe replace // Check every external resource if its okay to load it and maybe replace
// it // 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
@ -315,7 +302,10 @@ public class IITC_WebViewClient extends WebViewClient {
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 new WebResourceResponse("text/javascript", "UTF-8", EMPTY); // define initialize function to get rid of JS ReferenceError on intel page's 'onLoad'
String gen_dashboad_replacement = "window.initialize = function() {}";
return new WebResourceResponse("text/javascript", "UTF-8",
new ByteArrayInputStream(gen_dashboad_replacement.getBytes()));
} 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/common.css") || url.contains("/css/common.css")

View File

@ -0,0 +1,48 @@
package com.cradle.iitc_mobile.async;
import android.os.AsyncTask;
import android.util.Log;
import com.cradle.iitc_mobile.IITC_JSInterface;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import java.io.IOException;
/*
* this class parses the http response of a web page.
* since network operations shouldn't be done on main UI thread
* (NetworkOnMainThread exception is thrown) we use an async task for this.
*/
public class CheckHttpResponse extends AsyncTask<String, Void, Void> {
private IITC_JSInterface mJsInterface;
public CheckHttpResponse(IITC_JSInterface jsInterface) {
mJsInterface = jsInterface;
};
@Override
protected Void doInBackground(String... urls) {
// check http responses and disable splash screen on error
HttpGet httpRequest = new HttpGet(urls[0]);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = null;
try {
response = httpclient.execute(httpRequest);
int code = response.getStatusLine().getStatusCode();
if (code != HttpStatus.SC_OK) {
Log.d("iitcm", "received error code: " + code);
mJsInterface.removeSplashScreen();
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}