Merge branch 'master' into new-map-data

This commit is contained in:
Jon Atkins 2013-08-29 19:51:17 +01:00
commit 8910a463a0
5 changed files with 71 additions and 20 deletions

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="39" android:versionCode="40"
android:versionName="0.5.5"> android:versionName="0.5.6">
<uses-sdk <uses-sdk
android:minSdkVersion="14" android:minSdkVersion="14"

View File

@ -456,12 +456,7 @@ public class IITC_Mobile extends Activity {
mIitcWebView.loadUrl("javascript: window.show('map');"); mIitcWebView.loadUrl("javascript: window.show('map');");
return true; return true;
case R.id.reload_button: case R.id.reload_button:
mActionBar.setTitle(getString(R.string.app_name)); reloadIITC();
mBackStack.clear();
setActionBarHomeEnabledWithUp(false);
// iitc starts on map after reload
mCurrentPane = android.R.id.home;
this.loadUrl(mIntelUrl);
return true; return true;
case R.id.toggle_fullscreen: case R.id.toggle_fullscreen:
toggleFullscreen(); toggleFullscreen();
@ -518,6 +513,15 @@ public class IITC_Mobile extends Activity {
} }
} }
public void reloadIITC() {
mActionBar.setTitle(getString(R.string.app_name));
mBackStack.clear();
setActionBarHomeEnabledWithUp(false);
// iitc starts on map after reload
mCurrentPane = android.R.id.home;
this.loadUrl(mIntelUrl);
}
private void loadIITC() { private void loadIITC() {
try { try {
mIitcWebView.getWebViewClient().loadIITC_JS(this); mIitcWebView.getWebViewClient().loadIITC_JS(this);

View File

@ -25,11 +25,13 @@ public class IITC_WebView extends WebView {
private WebSettings mSettings; private WebSettings mSettings;
private IITC_WebViewClient mIitcWebViewClient; private IITC_WebViewClient mIitcWebViewClient;
private IITC_JSInterface mJsInterface; private IITC_JSInterface mJsInterface;
private Context mContext;
private boolean mDisableJs = false; private boolean mDisableJs = false;
// init web view // init web view
private void iitc_init(Context c) { private void iitc_init(Context c) {
if (this.isInEditMode()) return; if (this.isInEditMode()) return;
mContext = c;
mSettings = this.getSettings(); mSettings = this.getSettings();
mSettings.setJavaScriptEnabled(true); mSettings.setJavaScriptEnabled(true);
mSettings.setDomStorageEnabled(true); mSettings.setDomStorageEnabled(true);
@ -40,7 +42,7 @@ public class IITC_WebView extends WebView {
+ "/databases/"); + "/databases/");
mSettings.setAppCachePath(this.getContext().getCacheDir() mSettings.setAppCachePath(this.getContext().getCacheDir()
.getAbsolutePath()); .getAbsolutePath());
this.mJsInterface = new IITC_JSInterface(c); this.mJsInterface = new IITC_JSInterface(mContext);
this.addJavascriptInterface(mJsInterface, "android"); this.addJavascriptInterface(mJsInterface, "android");
this.setWebChromeClient(new WebChromeClient() { this.setWebChromeClient(new WebChromeClient() {
@ -134,7 +136,7 @@ public class IITC_WebView extends WebView {
url = url.replace("https://", "http://"); url = url.replace("https://", "http://");
// disable splash screen if a http error code is responded // disable splash screen if a http error code is responded
new CheckHttpResponse(mJsInterface).execute(url); new CheckHttpResponse(mJsInterface, mContext).execute(url);
Log.d("iitcm", "loading url: " + url); Log.d("iitcm", "loading url: " + url);
} }
super.loadUrl(url); super.loadUrl(url);

View File

@ -132,12 +132,9 @@ public class IITC_WebViewClient extends WebViewClient {
// add all plugins to the script...inject plugins + main script simultaneously // add all plugins to the script...inject plugins + main script simultaneously
js += parsePlugins(); js += parsePlugins();
// need to wrap the mobile iitc.js version in a document ready. IITC // IITC expects to be injected after the DOM has been loaded completely.
// expects to be injected after the DOM has been loaded completely. // since it is injected with the onPageFinished() event, no further delay is necessary.
// Since the mobile client injects IITC by replacing the gen_dashboard this.mIitcScript = js;
// file, IITC runs to early. The document.ready delays IITC long enough
// so it boots correctly.
this.mIitcScript = "setTimeout(function(){" + js + "},1);";
} }

View File

@ -1,9 +1,14 @@
package com.cradle.iitc_mobile.async; package com.cradle.iitc_mobile.async;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.util.Log; import android.util.Log;
import com.cradle.iitc_mobile.IITC_JSInterface; import com.cradle.iitc_mobile.IITC_JSInterface;
import com.cradle.iitc_mobile.IITC_Mobile;
import com.cradle.iitc_mobile.IITC_WebView;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
@ -18,16 +23,18 @@ import java.io.IOException;
* since network operations shouldn't be done on main UI thread * since network operations shouldn't be done on main UI thread
* (NetworkOnMainThread exception is thrown) we use an async task for this. * (NetworkOnMainThread exception is thrown) we use an async task for this.
*/ */
public class CheckHttpResponse extends AsyncTask<String, Void, Void> { public class CheckHttpResponse extends AsyncTask<String, Void, Boolean> {
private IITC_JSInterface mJsInterface; private IITC_JSInterface mJsInterface;
private Context mContext;
public CheckHttpResponse(IITC_JSInterface jsInterface) { public CheckHttpResponse(IITC_JSInterface jsInterface, Context c) {
mContext = c;
mJsInterface = jsInterface; mJsInterface = jsInterface;
}; };
@Override @Override
protected Void doInBackground(String... urls) { protected Boolean doInBackground(String... urls) {
// check http responses and disable splash screen on error // check http responses and disable splash screen on error
HttpGet httpRequest = new HttpGet(urls[0]); HttpGet httpRequest = new HttpGet(urls[0]);
HttpClient httpclient = new DefaultHttpClient(); HttpClient httpclient = new DefaultHttpClient();
@ -38,11 +45,52 @@ public class CheckHttpResponse extends AsyncTask<String, Void, Void> {
if (code != HttpStatus.SC_OK) { if (code != HttpStatus.SC_OK) {
Log.d("iitcm", "received error code: " + code); Log.d("iitcm", "received error code: " + code);
mJsInterface.removeSplashScreen(); mJsInterface.removeSplashScreen();
// TODO: remove when google login issue is fixed
if (urls[0].contains("uberauth=WILL_NOT_SIGN_IN")) {
return true;
}
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return false;
} }
/*
* TEMPORARY WORKAROUND for Google login fail
*/
@Override
protected void onPostExecute(Boolean aBoolean) {
if (aBoolean) {
Log.d("iitcm", "google auth error, redirecting to work-around page");
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);
// set title
alertDialogBuilder.setTitle("LOGIN FAILED!");
// set dialog message
alertDialogBuilder
.setMessage("This is caused by Google and hopefully fixed soon. " +
"To workaround this issue:\n" +
"• Choose 'Cancel' when asked to choose an account " +
"and manually enter your email address and password into the web page\n" +
"• If you don't see the account chooser, delete apps cache/data " +
"to force a new login session and handle it as described above")
.setCancelable(true)
.setNeutralButton("Reload now", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
IITC_Mobile iitc_mobile = (IITC_Mobile) mContext;
iitc_mobile.reloadIITC();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
}
} }