diff --git a/astrid/AndroidManifest.xml b/astrid/AndroidManifest.xml
index 504769ea0..f1b19ff34 100644
--- a/astrid/AndroidManifest.xml
+++ b/astrid/AndroidManifest.xml
@@ -406,8 +406,8 @@
-
-
+
+
diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java
index bfbdfe657..9b0819032 100644
--- a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java
+++ b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java
@@ -21,7 +21,9 @@ package com.todoroo.astrid.actfm;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
+import java.security.NoSuchAlgorithmException;
import org.json.JSONException;
import org.json.JSONObject;
@@ -35,7 +37,6 @@ import android.graphics.PixelFormat;
import android.os.Build;
import android.os.Bundle;
import android.text.method.PasswordTransformationMethod;
-import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
@@ -57,6 +58,7 @@ import com.timsu.astrid.R;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService;
+import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.sync.ActFmInvoker;
@@ -76,6 +78,7 @@ public class ActFmLoginActivity extends Activity implements AuthListener {
public static final String APP_ID = "183862944961271"; //$NON-NLS-1$
+ @Autowired ExceptionService exceptionService;
@Autowired TaskService taskService;
@Autowired ActFmPreferenceService actFmPreferenceService;
private final ActFmInvoker actFmInvoker = new ActFmInvoker();
@@ -87,7 +90,8 @@ public class ActFmLoginActivity extends Activity implements AuthListener {
// --- ui initialization
- private static final int REQUEST_CODE_GOOGLE = 1;
+ private static final int REQUEST_CODE_GOOGLE_ACCOUNTS = 1;
+ private static final int REQUEST_CODE_OAUTH = 2;
static {
AstridDependencyInjector.initialize();
@@ -122,6 +126,7 @@ public class ActFmLoginActivity extends Activity implements AuthListener {
"publish_stream"
});
+ findViewById(R.id.gg_login).setOnClickListener(googleListener);
findViewById(R.id.pw_signup).setOnClickListener(signUpListener);
findViewById(R.id.pw_login).setOnClickListener(loginListener);
@@ -135,6 +140,23 @@ public class ActFmLoginActivity extends Activity implements AuthListener {
// --- event handler
+ private final OnClickListener googleListener = new OnClickListener() {
+ @Override
+ @SuppressWarnings("nls")
+ public void onClick(View arg0) {
+ Intent intent = new Intent(ActFmLoginActivity.this, OAuthLoginActivity.class);
+ try {
+ String url = actFmInvoker.createFetchUrl("user_oauth", "provider", "google");
+ intent.putExtra(OAuthLoginActivity.URL_TOKEN, url);
+ startActivityForResult(intent, REQUEST_CODE_OAUTH);
+ } catch (UnsupportedEncodingException e) {
+ handleError(e);
+ } catch (NoSuchAlgorithmException e) {
+ handleError(e);
+ }
+ }
+ };
+
private final OnClickListener signUpListener = new OnClickListener() {
@Override
public void onClick(View arg0) {
@@ -292,7 +314,6 @@ public class ActFmLoginActivity extends Activity implements AuthListener {
// --- utilities
- @SuppressWarnings("nls")
public void authenticate(String email, String name, String provider, String secret) {
if(progressDialog == null)
progressDialog = DialogUtilities.progressDialog(this, getString(R.string.DLG_please_wait));
@@ -300,34 +321,44 @@ public class ActFmLoginActivity extends Activity implements AuthListener {
try {
JSONObject result = actFmInvoker.authenticate(email, name, provider, secret);
String token = actFmInvoker.getToken();
- actFmPreferenceService.setToken(token);
+ postAuthenticate(result, token);
+ } catch (IOException e) {
+ handleError(e);
+ } finally {
+ DialogUtilities.dismissDialog(this, progressDialog);
+ }
+ }
- if(Preferences.getStringValue(R.string.actfm_APr_interval_key) == null)
- Preferences.setStringFromInteger(R.string.actfm_APr_interval_key, 3600);
+ @SuppressWarnings("nls")
+ private void postAuthenticate(JSONObject result, String token) {
+ actFmPreferenceService.setToken(token);
- Preferences.setLong(ActFmPreferenceService.PREF_USER_ID,
- result.optLong("id"));
- Preferences.setString(ActFmPreferenceService.PREF_NAME, result.optString("name"));
- Preferences.setString(ActFmPreferenceService.PREF_EMAIL, result.optString("email"));
- Preferences.setString(ActFmPreferenceService.PREF_PICTURE, result.optString("picture"));
+ if(Preferences.getStringValue(R.string.actfm_APr_interval_key) == null)
+ Preferences.setStringFromInteger(R.string.actfm_APr_interval_key, 3600);
- C2DMReceiver.register();
+ Preferences.setLong(ActFmPreferenceService.PREF_USER_ID,
+ result.optLong("id"));
+ Preferences.setString(ActFmPreferenceService.PREF_NAME, result.optString("name"));
+ Preferences.setString(ActFmPreferenceService.PREF_EMAIL, result.optString("email"));
+ Preferences.setString(ActFmPreferenceService.PREF_PICTURE, result.optString("picture"));
- setResult(RESULT_OK);
- finish();
+ setResult(RESULT_OK);
+ finish();
- if(!noSync)
- synchronize();
- } catch (IOException e) {
- handleError(e);
- } finally {
- DialogUtilities.dismissDialog(this, progressDialog);
+ if(!noSync)
+ synchronize();
+
+ try {
+ C2DMReceiver.register();
+ } catch (Exception e) {
+ // phone may not support c2dm
+ exceptionService.reportError("error-c2dm-register", e);
}
}
private void handleError(final Throwable e) {
DialogUtilities.dismissDialog(this, progressDialog);
- Log.e("astrid-sharing", "error-doing-sla", e); //$NON-NLS-1$ //$NON-NLS-2$
+ exceptionService.reportError("astrid-sharing-login", e); //$NON-NLS-1$
runOnUiThread(new Runnable() {
@Override
@@ -349,7 +380,11 @@ public class ActFmLoginActivity extends Activity implements AuthListener {
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
- if(requestCode == REQUEST_CODE_GOOGLE){
+
+ if(resultCode == RESULT_CANCELED)
+ return;
+
+ if(requestCode == REQUEST_CODE_GOOGLE_ACCOUNTS){
String accounts[] = data.getExtras().getStringArray(GoogleLoginServiceConstants.ACCOUNTS_KEY);
credentialsListener.getCredentials(accounts);
} else if(requestCode == LoginButton.REQUEST_CODE_FACEBOOK) {
@@ -370,6 +405,14 @@ public class ActFmLoginActivity extends Activity implements AuthListener {
onFBAuthSucceed();
}
errors.setVisibility(View.GONE);
+ } else if(requestCode == REQUEST_CODE_OAUTH) {
+ String result = data.getStringExtra(OAuthLoginActivity.DATA_RESPONSE);
+ try {
+ JSONObject json = new JSONObject(result);
+ postAuthenticate(json, json.getString("token"));
+ } catch (JSONException e) {
+ handleError(e);
+ }
}
}
public interface OnGetCredentials {
@@ -383,7 +426,7 @@ public class ActFmLoginActivity extends Activity implements AuthListener {
if(Integer.parseInt(Build.VERSION.SDK) >= 7)
credentialsListener.getCredentials(ModernAuthManager.getAccounts(this));
else
- GoogleLoginServiceHelper.getAccount(this, REQUEST_CODE_GOOGLE, false);
+ GoogleLoginServiceHelper.getAccount(this, REQUEST_CODE_GOOGLE_ACCOUNTS, false);
}
}
\ No newline at end of file
diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/OAuthLoginActivity.java b/astrid/plugin-src/com/todoroo/astrid/actfm/OAuthLoginActivity.java
new file mode 100644
index 000000000..2eb3cf2d9
--- /dev/null
+++ b/astrid/plugin-src/com/todoroo/astrid/actfm/OAuthLoginActivity.java
@@ -0,0 +1,105 @@
+/*
+ * ASTRID: Android's Simple Task Recording Dashboard
+ *
+ * Copyright (c) 2009 Tim Su
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.todoroo.astrid.actfm;
+
+import java.io.IOException;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
+
+import com.timsu.astrid.R;
+import com.todoroo.andlib.service.Autowired;
+import com.todoroo.andlib.service.DependencyInjectionService;
+import com.todoroo.andlib.service.RestClient;
+
+/**
+ * This activity displays a WebView
that allows users to log in to the
+ * synchronization provider requested. A callback method determines whether
+ * their login was successful and therefore whether to dismiss the dialog.
+ *
+ * @author timsu
+ *
+ */
+public class OAuthLoginActivity extends Activity {
+
+ /**
+ * URL to display
+ */
+ public static final String URL_TOKEN = "u"; //$NON-NLS-1$
+
+ /**
+ * Resultant URL data
+ */
+ public static final String DATA_RESPONSE = "response"; //$NON-NLS-1$
+
+ @Autowired RestClient restClient;
+
+ // --- ui initialization
+
+ @SuppressWarnings("nls")
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ DependencyInjectionService.getInstance().inject(this);
+
+ setContentView(R.layout.oauth_login_activity);
+ setTitle(R.string.actfm_ALA_login_title);
+
+ final String urlParam = getIntent().getStringExtra(URL_TOKEN);
+
+ final WebView webView = (WebView)findViewById(R.id.browser);
+
+ webView.getSettings().setJavaScriptEnabled(true);
+ webView.getSettings().setSavePassword(false);
+ webView.getSettings().setSupportZoom(true);
+ webView.setWebViewClient(new WebViewClient() {
+
+ @Override
+ public void onPageFinished(WebView view, String url) {
+ super.onPageFinished(view, url);
+ System.err.println("page finished loading: " + url);
+
+ String data;
+ try {
+ data = restClient.get(url);
+ System.err.println("DATA: " + data);
+
+ if(data.startsWith("{")) { //$NON-NLS-1$
+ Intent intent = new Intent();
+ intent.putExtra(DATA_RESPONSE, data);
+ setResult(RESULT_OK, intent);
+ finish();
+ }
+ } catch (IOException e) {
+ Log.e("astrid", "error-load-url", e);
+ }
+ }
+ });
+
+
+ webView.loadUrl(urlParam);
+ }
+
+}
\ No newline at end of file
diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmInvoker.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmInvoker.java
index b5c494eb4..ebcd60bb3 100644
--- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmInvoker.java
+++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmInvoker.java
@@ -148,7 +148,7 @@ public class ActFmInvoker {
* @throws UnsupportedEncodingException
* @throws NoSuchAlgorithmException
*/
- private String createFetchUrl(String method, Object... getParameters) throws UnsupportedEncodingException, NoSuchAlgorithmException {
+ public String createFetchUrl(String method, Object... getParameters) throws UnsupportedEncodingException, NoSuchAlgorithmException {
ArrayList> params = new ArrayList>();
for(int i = 0; i < getParameters.length; i += 2) {
if(getParameters[i+1] instanceof ArrayList) {
diff --git a/astrid/res/drawable-hdpi/google.png b/astrid/res/drawable-hdpi/google.png
new file mode 100644
index 000000000..5033304e7
Binary files /dev/null and b/astrid/res/drawable-hdpi/google.png differ
diff --git a/astrid/res/drawable/facebook_64.png b/astrid/res/drawable/facebook_64.png
deleted file mode 100644
index c7a9d8331..000000000
Binary files a/astrid/res/drawable/facebook_64.png and /dev/null differ
diff --git a/astrid/res/drawable/google.png b/astrid/res/drawable/google.png
new file mode 100644
index 000000000..183680ad7
Binary files /dev/null and b/astrid/res/drawable/google.png differ
diff --git a/astrid/res/drawable/google_64.png b/astrid/res/drawable/google_64.png
deleted file mode 100644
index e55f34f1b..000000000
Binary files a/astrid/res/drawable/google_64.png and /dev/null differ
diff --git a/astrid/res/layout/actfm_login_activity.xml b/astrid/res/layout/actfm_login_activity.xml
index 91c207bd2..8153f33a8 100644
--- a/astrid/res/layout/actfm_login_activity.xml
+++ b/astrid/res/layout/actfm_login_activity.xml
@@ -79,17 +79,31 @@
android:textSize="16sp"
android:text="@string/actfm_ALA_pw_login" />
-
+ android:layout_marginBottom="3dip">
+
+
+
+
+
+
diff --git a/astrid/res/layout/oauth_login_activity.xml b/astrid/res/layout/oauth_login_activity.xml
new file mode 100644
index 000000000..fa97dfc6c
--- /dev/null
+++ b/astrid/res/layout/oauth_login_activity.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
diff --git a/astrid/res/layout/rmilk_login_activity.xml b/astrid/res/layout/rmilk_login_activity.xml
index e91492e54..c671537a2 100644
--- a/astrid/res/layout/rmilk_login_activity.xml
+++ b/astrid/res/layout/rmilk_login_activity.xml
@@ -32,7 +32,7 @@
-
diff --git a/astrid/res/values/strings-actfm.xml b/astrid/res/values/strings-actfm.xml
index 8c1764a9d..0b964b36c 100644
--- a/astrid/res/values/strings-actfm.xml
+++ b/astrid/res/values/strings-actfm.xml
@@ -133,13 +133,16 @@
share, and delegate with others. Perfect for personal use, friends, family, and coworkers!
- Login with Facebook
+ Facebook
+
+
+ Google
Login
- Sign Up
+ Join Now
Name
@@ -159,6 +162,9 @@
Login to Astrid.com
+
+ Please connect to Google:
+
We promise not to post messages or send
e-mails without your permission.