Google tasks login thing

pull/14/head
Tim Su 14 years ago
parent 09d96e9865
commit 9a977e0129

@ -24,11 +24,7 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- for google tasks -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH" />
<uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH.goanna_mobile" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- ============================================== Exported Permissions = -->

Binary file not shown.

@ -7,17 +7,7 @@ import com.commonsware.cwac.tlv.TouchListView.DropListener;
import com.commonsware.cwac.tlv.TouchListView.SwipeListener;
import com.todoroo.andlib.data.Property.IntegerProperty;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Functions;
import com.todoroo.andlib.sql.Join;
import com.todoroo.andlib.sql.Order;
import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.astrid.activity.DraggableTaskListActivity;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task;
public class GtasksListActivity extends DraggableTaskListActivity {
@ -25,18 +15,7 @@ public class GtasksListActivity extends DraggableTaskListActivity {
public static final String TOKEN_LIST_ID = "listId"; //$NON-NLS-1$
// --- gtasks temp stuff
private final String listId = "17816916813445155620:0:0"; //$NON-NLS-1$
Filter builtInFilter = new Filter("Tim's Tasks", "Tim's Tasks", new QueryTemplate().join( //$NON-NLS-1$ //$NON-NLS-2$
Join.left(Metadata.TABLE, Task.ID.eq(Metadata.TASK))).where(Criterion.and(
MetadataCriteria.withKey("gtasks"), //$NON-NLS-1$
TaskCriteria.isVisible(),
TaskCriteria.notDeleted(),
Metadata.VALUE2.eq(listId))).orderBy(
Order.asc(Functions.cast(Metadata.VALUE5, "INTEGER"))), //$NON-NLS-1$
null);
// --- end
private String listId;
@Override
protected IntegerProperty getIndentProperty() {
@ -45,10 +24,10 @@ public class GtasksListActivity extends DraggableTaskListActivity {
@Override
public void onCreate(Bundle icicle) {
if(!getIntent().hasExtra(TOKEN_FILTER))
getIntent().putExtra(TOKEN_FILTER, builtInFilter);
super.onCreate(icicle);
listId = getIntent().getStringExtra(TOKEN_LIST_ID);
getTouchListView().setDropListener(dropListener);
getTouchListView().setSwipeListener(swipeListener);
}

@ -3,11 +3,11 @@ package com.todoroo.astrid.gtasks;
import android.content.Intent;
import android.os.Bundle;
import com.google.android.googlelogin.GoogleLoginServiceConstants;
import com.google.android.googlelogin.GoogleLoginServiceHelper;
import com.timsu.astrid.R;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.astrid.gtasks.auth.AuthManager;
import com.todoroo.astrid.gtasks.auth.AuthManagerFactory;
import com.todoroo.astrid.gtasks.sync.GtasksSyncProvider;
import com.todoroo.astrid.sync.SyncProviderPreferences;
import com.todoroo.astrid.sync.SyncProviderUtilities;
@ -25,9 +25,6 @@ public class GtasksPreferences extends SyncProviderPreferences {
private static final int REQUEST_CODE_GOOGLE = 1;
private final AuthManager authManager = AuthManagerFactory.getAuthManager(
this, REQUEST_CODE_GOOGLE, new Bundle(), false, "goanna_mobile"); //$NON-NLS-1$
public GtasksPreferences() {
super();
DependencyInjectionService.getInstance().inject(this);
@ -42,14 +39,11 @@ public class GtasksPreferences extends SyncProviderPreferences {
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == REQUEST_CODE_GOOGLE){
authManager.authResult(resultCode, data);
String accounts[] = data.getExtras().getStringArray(GoogleLoginServiceConstants.ACCOUNTS_KEY);
credentialsListener.getCredentials(accounts);
}
}
public AuthManager getAuthManager() {
return authManager;
}
@Override
public int getPreferenceResource() {
return R.xml.preferences_gtasks;
@ -70,4 +64,15 @@ public class GtasksPreferences extends SyncProviderPreferences {
return gtasksPreferenceService;
}
public interface OnGetCredentials {
public void getCredentials(String[] accounts);
}
private OnGetCredentials credentialsListener;
public void getCredentials(OnGetCredentials onGetCredentials) {
credentialsListener = onGetCredentials;
GoogleLoginServiceHelper.getAccount(this, REQUEST_CODE_GOOGLE, false);
}
}

@ -15,8 +15,15 @@ import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.text.method.PasswordTransformationMethod;
import android.util.Log;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.flurry.android.FlurryAgent;
import com.timsu.astrid.R;
@ -41,6 +48,7 @@ import com.todoroo.astrid.gtasks.GtasksMetadata;
import com.todoroo.astrid.gtasks.GtasksMetadataService;
import com.todoroo.astrid.gtasks.GtasksPreferenceService;
import com.todoroo.astrid.gtasks.GtasksPreferences;
import com.todoroo.astrid.gtasks.GtasksPreferences.OnGetCredentials;
import com.todoroo.astrid.gtasks.GtasksTaskListUpdater;
import com.todoroo.astrid.service.AstridDependencyInjector;
import com.todoroo.astrid.sync.SyncBackgroundService;
@ -177,24 +185,38 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
// check if we have a token & it works
if(authToken == null) {
try {
final GtasksPreferences preferenceActivity = (GtasksPreferences)activity;
preferenceActivity.getAuthManager().invalidateAndRefresh(new Runnable() {
@Override
public void run() {
String token = preferenceActivity.getAuthManager().getAuthToken();
if(token != null) {
token = "auth=" + token;
gtasksPreferenceService.setToken(token);
activity.startService(new Intent(SyncBackgroundService.SYNC_ACTION, null,
activity, GtasksBackgroundService.class));
activity.finish();
}
}
});
} catch (Exception e) {
handleException("auth", e, true);
}
final GtasksPreferences preferenceActivity = (GtasksPreferences)activity;
preferenceActivity.getCredentials(new OnGetCredentials() {
@Override
public void getCredentials(String[] accounts) {
LinearLayout layout = new LinearLayout(activity);
layout.setPadding(5, -5, 5, 0);
layout.setOrientation(LinearLayout.VERTICAL);
TextView textView = new TextView(activity);
textView.setText(R.string.producteev_PLA_email);
layout.addView(textView);
final EditText email = new EditText(activity);
if(accounts != null && accounts.length > 0)
email.setText(accounts[0]);
layout.addView(email);
textView = new TextView(activity);
textView.setText(R.string.producteev_PLA_password);
layout.addView(textView);
final EditText password = new EditText(activity);
password.setTransformationMethod(new PasswordTransformationMethod());
layout.addView(password);
DialogUtilities.viewDialog(activity,
activity.getString(R.string.gtasks_login), layout,
new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
trySynchronizing(activity, email.getText(), password.getText());
}
}, null);
}
});
} else {
activity.startService(new Intent(SyncBackgroundService.SYNC_ACTION, null,
activity, GtasksBackgroundService.class));
@ -202,6 +224,23 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
}
}
private void trySynchronizing(Activity activity, CharSequence email, CharSequence password) {
GoogleConnectionManager gcm = new GoogleConnectionManager(email.toString(), password.toString());
try {
gcm.authenticate(false);
} catch (GoogleLoginException e) {
Toast.makeText(activity, R.string.gtasks_login_error, Toast.LENGTH_LONG).show();
return;
} catch (IOException e) {
Toast.makeText(activity, R.string.SyP_ioerror, Toast.LENGTH_LONG).show();
}
String token = gcm.getToken();
System.err.println("got token " + token);
gtasksPreferenceService.setToken(token);
activity.startService(new Intent(SyncBackgroundService.SYNC_ACTION, null,
activity, GtasksBackgroundService.class));
activity.finish();
}
// ----------------------------------------------------------------------
// ----------------------------------------------------- synchronization!
@ -213,8 +252,11 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
try {
GoogleTaskView taskView = taskService.getTaskView();
Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST,
if(taskView.getActiveTaskList() != null)
Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST,
taskView.getActiveTaskList().getInfo().getId());
else
Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST, null);
gtasksListService.updateLists(taskView.getAllLists());

@ -32,5 +32,18 @@
<!-- message body for no google accounts found -->
<string name="no_account_found">We were unable to find a Google account on this phone. You will not be able to synchronize to Google Tasks without one!</string>
<!-- E-mail Address Label -->
<string name="gtasks_email">E-mail</string>
<!-- Password Label -->
<string name="gtasks_password">Password</string>
<!-- Login Message -->
<string name="gtasks_login">Google Account:</string>
<!-- Login Message when Error -->
<string name="gtasks_login_error">Please try your e-mail and password again.</string>
</resources>

Loading…
Cancel
Save