diff -r 2a190d8613ca AndroidManifest.xml
--- a/AndroidManifest.xml Fri Aug 05 21:13:30 2011 -0700
+++ b/AndroidManifest.xml Wed Aug 24 18:53:04 2011 -0400
@@ -46,6 +46,12 @@
android:mimeType="vnd.android.cursor.item/vnd.odk.instance" />
+
+
@@ -151,6 +157,13 @@
+
+
+
-
+
+
+
+
+
+
diff -r 2a190d8613ca res/values/arrays.xml
--- a/res/values/arrays.xml Fri Aug 05 21:13:30 2011 -0700
+++ b/res/values/arrays.xml Wed Aug 24 18:53:04 2011 -0400
@@ -35,11 +35,13 @@
- odk_default
+ - google
- ODK Default
+ - Google
- Custom
Select Answer
Form will be saved as:
Saved name must not be blank!
+Select Google Account
diff -r 2a190d8613ca src/org/odk/collect/android/activities/FormDownloadList.java
--- a/src/org/odk/collect/android/activities/FormDownloadList.java Fri Aug 05 21:13:30 2011 -0700
+++ b/src/org/odk/collect/android/activities/FormDownloadList.java Wed Aug 24 18:53:04 2011 -0400
@@ -25,6 +25,7 @@
import org.odk.collect.android.preferences.PreferencesActivity;
import org.odk.collect.android.tasks.DownloadFormListTask;
import org.odk.collect.android.tasks.DownloadFormsTask;
+import org.odk.collect.android.utilities.UrlUtils;
import org.odk.collect.android.utilities.WebUtils;
import android.app.AlertDialog;
@@ -367,8 +368,13 @@
getString(R.string.default_server_url));
final String url =
- server + settings.getString(PreferencesActivity.KEY_FORMLIST_URL, "/formList");
+ UrlUtils.fixHttps(server +
+ settings.getString(PreferencesActivity.KEY_FORMLIST_URL, "/formList"),
+ settings);
+ String auth = settings.getString(PreferencesActivity.KEY_AUTH, "");
+
Log.i(t, "Trying to get formList from: " + url);
+
EditText username = (EditText) dialogView.findViewById(R.id.username_edit);
String storedUsername = settings.getString(PreferencesActivity.KEY_USERNAME, null);
@@ -434,6 +440,10 @@
showDialog(PROGRESS_DIALOG);
mDownloadFormsTask = new DownloadFormsTask();
+ SharedPreferences settings =
+ PreferenceManager.getDefaultSharedPreferences(getBaseContext());
+ String auth = settings.getString(PreferencesActivity.KEY_AUTH, "");
+ mDownloadFormsTask.setAuth(auth);
mDownloadFormsTask.setDownloaderListener(this);
mDownloadFormsTask.execute(filesToDownload);
} else {
diff -r 2a190d8613ca src/org/odk/collect/android/activities/InstanceUploaderActivity.java
--- a/src/org/odk/collect/android/activities/InstanceUploaderActivity.java Fri Aug 05 21:13:30 2011 -0700
+++ b/src/org/odk/collect/android/activities/InstanceUploaderActivity.java Wed Aug 24 18:53:04 2011 -0400
@@ -19,6 +19,7 @@
import org.odk.collect.android.preferences.PreferencesActivity;
import org.odk.collect.android.provider.InstanceProviderAPI.InstanceColumns;
import org.odk.collect.android.tasks.InstanceUploaderTask;
+import org.odk.collect.android.utilities.UrlUtils;
import org.odk.collect.android.utilities.WebUtils;
import android.app.Activity;
@@ -118,10 +119,17 @@
if (mInstanceUploaderTask == null) {
// setup dialog and upload task
showDialog(PROGRESS_DIALOG);
+
+ SharedPreferences settings =
+ PreferenceManager.getDefaultSharedPreferences(getBaseContext());
+
mInstanceUploaderTask = new InstanceUploaderTask();
Long[] toSendArray = new Long[mInstancesToSend.size()];
mInstancesToSend.toArray(toSendArray);
+
+ String auth = settings.getString(PreferencesActivity.KEY_AUTH, "");
+ mInstanceUploaderTask.setAuth(auth);
mInstanceUploaderTask.execute(toSendArray);
}
}
@@ -347,7 +355,11 @@
// Bundle b = new Bundle();
// b.putString(AUTH_URI, url.toString());
// showDialog(AUTH_DIALOG, b);
- mUrl = url.toString();
+ SharedPreferences settings =
+ PreferenceManager.getDefaultSharedPreferences(getBaseContext());
+ mUrl = url.toString();
+ mUrl = UrlUtils.fixHttps(mUrl, settings);
+
showDialog(AUTH_DIALOG);
}
diff -r 2a190d8613ca src/org/odk/collect/android/activities/MainMenuActivity.java
--- a/src/org/odk/collect/android/activities/MainMenuActivity.java Fri Aug 05 21:13:30 2011 -0700
+++ b/src/org/odk/collect/android/activities/MainMenuActivity.java Wed Aug 24 18:53:04 2011 -0400
@@ -22,7 +22,9 @@
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -48,7 +50,8 @@
private Button mManageFilesButton;
private Button mSendDataButton;
private Button mReviewDataButton;
-
+ private Button mGoogleButton;
+
private AlertDialog mAlertDialog;
private static boolean EXIT = true;
@@ -104,7 +107,7 @@
startActivity(i);
}
});
-
+
// manage forms button. no result expected.
mManageFilesButton = (Button) findViewById(R.id.manage_forms);
mManageFilesButton.setText(getString(R.string.manage_files));
@@ -115,8 +118,36 @@
startActivity(i);
}
});
+
+ SharedPreferences settings =
+ PreferenceManager.getDefaultSharedPreferences(getBaseContext());
+ String protocol = settings.getString(PreferencesActivity.KEY_PROTOCOL, "odk_default");
+ mGoogleButton = (Button) findViewById(R.id.google_button);
+ mGoogleButton.setVisibility(Button.INVISIBLE);
+ mGoogleButton.setText(getString(R.string.google_account));
+ mGoogleButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent i = new Intent(getApplicationContext(), AccountList.class);
+ startActivity(i);
+ }
+ });
}
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ SharedPreferences settings =
+ PreferenceManager.getDefaultSharedPreferences(getBaseContext());
+ String protocol = settings.getString(PreferencesActivity.KEY_PROTOCOL, "odk_default");
+ Button mGoogleButton = (Button) findViewById(R.id.google_button);
+ if (protocol.equals("google")) {
+ mGoogleButton.setVisibility(Button.VISIBLE);
+ } else {
+ mGoogleButton.setVisibility(Button.INVISIBLE);
+ }
+ }
@Override
protected void onPause() {
diff -r 2a190d8613ca src/org/odk/collect/android/preferences/PreferencesActivity.java
--- a/src/org/odk/collect/android/preferences/PreferencesActivity.java Fri Aug 05 21:13:30 2011 -0700
+++ b/src/org/odk/collect/android/preferences/PreferencesActivity.java Wed Aug 24 18:53:04 2011 -0400
@@ -58,6 +58,10 @@
public static String KEY_PROTOCOL = "protocol";
public static String KEY_FORMLIST_URL = "formlist_url";
public static String KEY_SUBMISSION_URL = "submission_url";
+
+ public static String KEY_AUTH = "auth";
+ public static String KEY_ACCOUNT = "account";
+
private PreferenceScreen mSplashPathPreference;
private EditTextPreference mSubmissionUrlPreference;
@@ -327,6 +331,23 @@
mSubmissionUrlPreference.setEnabled(false);
}
+ } else if (protocol.equals("google")) {
+ if (mServerUrlPreference != null) {
+ mServerUrlPreference.setEnabled(true);
+ }
+ if (mUsernamePreference != null) {
+ mUsernamePreference.setEnabled(false);
+ }
+ if (mPasswordPreference != null) {
+ mPasswordPreference.setEnabled(false);
+ }
+ if (mFormListUrlPreference != null) {
+ mFormListUrlPreference.setEnabled(false);
+ }
+ if (mSubmissionUrlPreference != null) {
+ mSubmissionUrlPreference.setEnabled(false);
+ }
+
} else {
if (mServerUrlPreference != null) {
mServerUrlPreference.setEnabled(true);
diff -r 2a190d8613ca src/org/odk/collect/android/tasks/DownloadFormListTask.java
--- a/src/org/odk/collect/android/tasks/DownloadFormListTask.java Fri Aug 05 21:13:30 2011 -0700
+++ b/src/org/odk/collect/android/tasks/DownloadFormListTask.java Wed Aug 24 18:53:04 2011 -0400
@@ -24,6 +24,7 @@
import org.odk.collect.android.logic.FormDetails;
import org.odk.collect.android.preferences.PreferencesActivity;
import org.odk.collect.android.utilities.DocumentFetchResult;
+import org.odk.collect.android.utilities.UrlUtils;
import org.odk.collect.android.utilities.WebUtils;
import android.content.SharedPreferences;
@@ -69,6 +70,8 @@
String downloadPath =
settings.getString(PreferencesActivity.KEY_FORMLIST_URL, "/formlist");
downloadListUrl += downloadPath;
+ downloadListUrl = UrlUtils.fixHttps(downloadListUrl, settings);
+ String auth = settings.getString(PreferencesActivity.KEY_AUTH, "");
// We populate this with available forms from the specified server.
//
@@ -79,7 +82,7 @@
HttpClient httpclient = WebUtils.createHttpClient(WebUtils.CONNECTION_TIMEOUT);
DocumentFetchResult result =
- WebUtils.getXmlDocument(downloadListUrl, localContext, httpclient);
+ WebUtils.getXmlDocument(downloadListUrl, localContext, httpclient, auth);
// If we can't get the document, return the error, cancel the task
if (result.errorMessage != null) {
diff -r 2a190d8613ca src/org/odk/collect/android/tasks/DownloadFormsTask.java
--- a/src/org/odk/collect/android/tasks/DownloadFormsTask.java Fri Aug 05 21:13:30 2011 -0700
+++ b/src/org/odk/collect/android/tasks/DownloadFormsTask.java Wed Aug 24 18:53:04 2011 -0400
@@ -67,12 +67,16 @@
private static final String NAMESPACE_OPENROSA_ORG_XFORMS_XFORMS_MANIFEST =
"http://openrosa.org/xforms/xformsManifest";
+
+ private String mAuth = "";
+ public void setAuth(String auth) {
+ this.mAuth = auth;
+ }
private boolean isXformsManifestNamespacedElement(Element e) {
return e.getNamespace().equalsIgnoreCase(NAMESPACE_OPENROSA_ORG_XFORMS_XFORMS_MANIFEST);
- }
-
+ }
@Override
protected HashMap doInBackground(ArrayList... values) {
@@ -255,7 +259,7 @@
HttpClient httpclient = WebUtils.createHttpClient(WebUtils.CONNECTION_TIMEOUT);
// set up request...
- HttpGet req = WebUtils.createOpenRosaHttpGet(uri);
+ HttpGet req = WebUtils.createOpenRosaHttpGet(uri, mAuth);
HttpResponse response = null;
try {
@@ -333,7 +337,7 @@
HttpClient httpclient = WebUtils.createHttpClient(WebUtils.CONNECTION_TIMEOUT);
DocumentFetchResult result =
- WebUtils.getXmlDocument(fd.manifestUrl, localContext, httpclient);
+ WebUtils.getXmlDocument(fd.manifestUrl, localContext, httpclient, mAuth);
if (result.errorMessage != null) {
return result.errorMessage;
diff -r 2a190d8613ca src/org/odk/collect/android/tasks/InstanceUploaderTask.java
--- a/src/org/odk/collect/android/tasks/InstanceUploaderTask.java Fri Aug 05 21:13:30 2011 -0700
+++ b/src/org/odk/collect/android/tasks/InstanceUploaderTask.java Wed Aug 24 18:53:04 2011 -0400
@@ -65,10 +65,14 @@
private InstanceUploaderListener mStateListener;
private static final int CONNECTION_TIMEOUT = 30000;
private static final String fail = "FAILED: ";
-
+
+ private String mAuth = "";
private URI mAuthRequestingServer;
HashMap mResults;
-
+
+ public void setAuth(String auth) {
+ this.mAuth = auth;
+ }
// TODO: This method is like 350 lines long, down from 400.
// still. ridiculous. make it smaller.
@@ -294,7 +298,7 @@
while (j < files.size() || first) {
first = false;
- HttpPost httppost = WebUtils.createOpenRosaHttpPost(u);
+ HttpPost httppost = WebUtils.createOpenRosaHttpPost(u, mAuth);
MimeTypeMap m = MimeTypeMap.getSingleton();
diff -r 2a190d8613ca src/org/odk/collect/android/utilities/UrlUtils.java
--- a/src/org/odk/collect/android/utilities/UrlUtils.java Fri Aug 05 21:13:30 2011 -0700
+++ b/src/org/odk/collect/android/utilities/UrlUtils.java Wed Aug 24 18:53:04 2011 -0400
@@ -14,11 +14,37 @@
package org.odk.collect.android.utilities;
+import android.content.SharedPreferences;
+
+import org.odk.collect.android.preferences.PreferencesActivity;
+
import java.net.MalformedURLException;
import java.net.URL;
public class UrlUtils {
+ public static String fixHttps(String baseUrl, SharedPreferences settings) {
+ // Check if we are making an authenticated connection.
+ // If so, ensure that we are going over SSL.
+ String auth = settings.getString(PreferencesActivity.KEY_AUTH, "");
+ if (auth.length() == 0) {
+ return baseUrl;
+ }
+
+ String url = baseUrl;
+
+ return url;
+
+ /*if (!url.startsWith("https")) {
+ if (url.startsWith("http://")) {
+ url = url.replaceFirst("http://", "https://");
+ } else {
+ url = "https://" + url;
+ }
+ }
+ return url;*/
+ }
+
public static boolean isValidUrl(String url) {
try {
diff -r 2a190d8613ca src/org/odk/collect/android/utilities/WebUtils.java
--- a/src/org/odk/collect/android/utilities/WebUtils.java Fri Aug 05 21:13:30 2011 -0700
+++ b/src/org/odk/collect/android/utilities/WebUtils.java Wed Aug 24 18:53:04 2011 -0400
@@ -148,20 +148,35 @@
public static final HttpGet createOpenRosaHttpGet(URI uri) {
- HttpGet req = new HttpGet();
+ return createOpenRosaHttpGet(uri, "");
+ }
+
+ public static final HttpGet createOpenRosaHttpGet(URI uri, String auth) {
+ HttpGet req = new HttpGet();
+ setOpenRosaHeaders(req);
+ setGoogleHeaders(req, auth);
+ req.setURI(uri);
+ return req;
+ }
+
+ public static final void setGoogleHeaders(HttpRequest req, String auth) {
+ if ((auth != null) && (auth.length() > 0)) {
+ req.setHeader("Authorization", "GoogleLogin auth=" + auth);
+ }
+ }
+
+ public static final HttpPost createOpenRosaHttpPost(URI uri) {
+ return createOpenRosaHttpPost(uri, "");
+ }
+
+ public static final HttpPost createOpenRosaHttpPost(URI uri, String auth) {
+ HttpPost req = new HttpPost(uri);
setOpenRosaHeaders(req);
- req.setURI(uri);
+ setGoogleHeaders(req, auth);
return req;
}
-
- public static final HttpPost createOpenRosaHttpPost(URI uri) {
- HttpPost req = new HttpPost(uri);
- setOpenRosaHeaders(req);
- return req;
- }
-
-
+
public static final HttpClient createHttpClient(int timeout) {
// configure connection
HttpParams params = new BasicHttpParams();
@@ -181,12 +196,11 @@
// setup client
HttpClient httpclient = new DefaultHttpClient(params);
httpclient.getParams().setParameter(ClientPNames.MAX_REDIRECTS, 1);
- httpclient.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
+ httpclient.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
return httpclient;
}
-
/**
* Common method for returning a parsed xml document given a url and the http context and client
* objects involved in the web connection.
@@ -197,7 +211,7 @@
* @return
*/
public static DocumentFetchResult getXmlDocument(String urlString, HttpContext localContext,
- HttpClient httpclient) {
+ HttpClient httpclient, String auth) {
URI u = null;
try {
URL url = new URL(urlString);
@@ -210,7 +224,7 @@
}
// set up request...
- HttpGet req = WebUtils.createOpenRosaHttpGet(u);
+ HttpGet req = WebUtils.createOpenRosaHttpGet(u, auth);
HttpResponse response = null;
try {