Adding new gtasks login activity for logging in

pull/14/head
Tim Su 14 years ago
parent d7f3108049
commit 7f5028c40d

@ -253,6 +253,8 @@
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name="com.todoroo.astrid.gtasks.auth.GtasksLoginActivity"
android:theme="@style/White"/>
<receiver android:name="com.todoroo.astrid.gtasks.GtasksFilterExposer"> <receiver android:name="com.todoroo.astrid.gtasks.GtasksFilterExposer">
<intent-filter> <intent-filter>
<action android:name="com.todoroo.astrid.REQUEST_FILTERS" /> <action android:name="com.todoroo.astrid.REQUEST_FILTERS" />

Binary file not shown.

@ -0,0 +1,159 @@
/*
* 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.gtasks.auth;
import java.io.IOException;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
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.utility.DialogUtilities;
import com.todoroo.astrid.gtasks.GtasksBackgroundService;
import com.todoroo.astrid.gtasks.GtasksPreferenceService;
import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.sync.SyncBackgroundService;
import com.todoroo.gtasks.GoogleConnectionManager;
import com.todoroo.gtasks.GoogleLoginException;
/**
* This activity allows users to sign in or log in to Producteev
*
* @author arne.jans
*
*/
public class GtasksLoginActivity extends Activity {
@Autowired private GtasksPreferenceService gtasksPreferenceService;
// --- ui initialization
public GtasksLoginActivity() {
super();
DependencyInjectionService.getInstance().inject(this);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ContextManager.setContext(this);
setContentView(R.layout.gtasks_login_activity);
setTitle(R.string.gtasks_GLA_title);
final TextView errors = (TextView) findViewById(R.id.error);
final EditText emailEditText = (EditText) findViewById(R.id.email);
final EditText passwordEditText = (EditText) findViewById(R.id.password);
final CheckBox isDomain = (CheckBox) findViewById(R.id.isDomain);
Button signIn = (Button) findViewById(R.id.signIn);
signIn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
errors.setVisibility(View.GONE);
Editable email = emailEditText.getText();
Editable password = passwordEditText.getText();
if(email.length() == 0 || password.length() == 0) {
errors.setVisibility(View.VISIBLE);
errors.setText(R.string.producteev_PLA_errorEmpty);
return;
}
performLogin(email.toString(), password.toString(), isDomain.isChecked());
}
});
}
private void performLogin(final String email, final String password, final boolean isDomain) {
final ProgressDialog dialog = DialogUtilities.progressDialog(this,
getString(R.string.DLG_wait));
final TextView errors = (TextView) findViewById(R.id.error);
dialog.show();
new Thread() {
@SuppressWarnings("nls")
@Override
public void run() {
final StringBuilder errorMessage = new StringBuilder();
GoogleConnectionManager gcm = new GoogleConnectionManager(email.toString(),
password.toString(), !isDomain);
try {
gcm.authenticate(false);
String token = gcm.getToken();
gtasksPreferenceService.setToken(token);
StatisticsService.reportEvent("gtasks-login");
synchronize();
} catch (GoogleLoginException e) {
errorMessage.append(getString(R.string.gtasks_GLA_errorAuth));
Log.e("gtasks", "login", e);
return;
} catch (IOException e) {
errorMessage.append(getString(R.string.SyP_ioerror));
Log.e("gtasks", "login", e);
} finally {
runOnUiThread(new Runnable() {
public void run() {
dialog.dismiss();
if(errorMessage.length() > 0) {
errors.setVisibility(View.VISIBLE);
errors.setText(errorMessage);
}
}
});
}
}
}.start();
}
/**
* Perform synchronization
*/
protected void synchronize() {
startService(new Intent(SyncBackgroundService.SYNC_ACTION, null,
this, GtasksBackgroundService.class));
finish();
}
@Override
protected void onStart() {
super.onStart();
StatisticsService.sessionStart(this);
}
@Override
protected void onStop() {
super.onStop();
StatisticsService.sessionStop(this);
}
}

@ -15,17 +15,9 @@ import android.app.Notification;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.Service; import android.app.Service;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.method.PasswordTransformationMethod;
import android.util.Log; import android.util.Log;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.data.AbstractModel; import com.todoroo.andlib.data.AbstractModel;
@ -50,7 +42,7 @@ import com.todoroo.astrid.gtasks.GtasksMetadataService;
import com.todoroo.astrid.gtasks.GtasksPreferenceService; import com.todoroo.astrid.gtasks.GtasksPreferenceService;
import com.todoroo.astrid.gtasks.GtasksPreferences; import com.todoroo.astrid.gtasks.GtasksPreferences;
import com.todoroo.astrid.gtasks.GtasksTaskListUpdater; import com.todoroo.astrid.gtasks.GtasksTaskListUpdater;
import com.todoroo.astrid.gtasks.GtasksPreferences.OnGetCredentials; import com.todoroo.astrid.gtasks.auth.GtasksLoginActivity;
import com.todoroo.astrid.service.AstridDependencyInjector; import com.todoroo.astrid.service.AstridDependencyInjector;
import com.todoroo.astrid.service.StatisticsService; import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.sync.SyncBackgroundService; import com.todoroo.astrid.sync.SyncBackgroundService;
@ -188,40 +180,8 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
// check if we have a token & it works // check if we have a token & it works
if(authToken == null) { if(authToken == null) {
final GtasksPreferences preferenceActivity = (GtasksPreferences)activity; Intent intent = new Intent(activity, GtasksLoginActivity.class);
preferenceActivity.getCredentials(new OnGetCredentials() { activity.startActivityForResult(intent, 0);
@Override
public void getCredentials(String[] accounts) {
ScrollView layoutScroller = new ScrollView(activity);
LinearLayout layout = new LinearLayout(activity);
layoutScroller.addView(layout);
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), layoutScroller,
new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
trySynchronizing(activity, email.getText(), password.getText());
}
}, null);
}
});
} else { } else {
activity.startService(new Intent(SyncBackgroundService.SYNC_ACTION, null, activity.startService(new Intent(SyncBackgroundService.SYNC_ACTION, null,
activity, GtasksBackgroundService.class)); activity, GtasksBackgroundService.class));
@ -229,25 +189,6 @@ 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();
Log.e("gtasks", "login", e);
return;
} catch (IOException e) {
Toast.makeText(activity, R.string.SyP_ioerror, Toast.LENGTH_LONG).show();
Log.e("gtasks", "login", e);
}
String token = gcm.getToken();
gtasksPreferenceService.setToken(token);
activity.startService(new Intent(SyncBackgroundService.SYNC_ACTION, null,
activity, GtasksBackgroundService.class));
activity.finish();
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// ----------------------------------------------------- synchronization! // ----------------------------------------------------- synchronization!
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="5dip"
android:paddingBottom="5dip"
android:scaleType="fitCenter"
android:src="@drawable/gtasks_logo" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="10dip"
android:textSize="16sp"
android:text="@string/gtasks_GLA_body" />
<TextView
android:id="@+id/error"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingBottom="20dip"
android:textColor="#ff0000"
android:textSize="16sp"
android:textStyle="bold"
android:visibility="gone" />
<EditText
android:id="@+id/email"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:hint="@string/gtasks_GLA_email"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/password"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:hint="@string/gtasks_GLA_password"
android:inputType="textPassword" />
<CheckBox
android:id="@+id/isDomain"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="@string/gtasks_GLA_domain" />
<Button
android:id="@+id/signIn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/gtasks_GLA_signIn" />
</LinearLayout>
</ScrollView>

@ -2,7 +2,7 @@
<!-- See the file "LICENSE" for the full license governing this code. --> <!-- See the file "LICENSE" for the full license governing this code. -->
<resources xmlns:android="http://schemas.android.com/apk/res/android"> <resources xmlns:android="http://schemas.android.com/apk/res/android">
<!-- =========================================================== UI == --> <!-- ============================================================= UI == -->
<!-- filters header: GTasks --> <!-- filters header: GTasks -->
<string name="gtasks_FEx_header">Google Tasks</string> <string name="gtasks_FEx_header">Google Tasks</string>
@ -13,36 +13,42 @@
<!-- filter title for GTasks lists (%s => list name) --> <!-- filter title for GTasks lists (%s => list name) -->
<string name="gtasks_FEx_title">Google Tasks: %s</string> <string name="gtasks_FEx_title">Google Tasks: %s</string>
<!-- ============================================== GtasksPreferences == --> <!-- ============================================ GtasksLoginActivity == -->
<!-- GTasks Preferences Title --> <!-- Activity Title: Gtasks Login -->
<string name="gtasks_GPr_header">Google Tasks (Beta!)</string> <string name="gtasks_GLA_title">Log In to Google Tasks</string>
<!-- ================================================ Synchronization == --> <!-- Instructions: Gtasks login -->
<string name="gtasks_GLA_body">Please log in to Google Tasks. Astrid will
not store your password anywhere.</string>
<!-- title for notification tray when synchronizing --> <!-- Sign In Button -->
<string name="gtasks_notification_title">Astrid: Google Tasks</string> <string name="gtasks_GLA_signIn">Sign In</string>
<!-- title for picking a google account --> <!-- E-mail Address Label -->
<string name="choose_account_title">Choose Account</string> <string name="gtasks_GLA_email">E-mail</string>
<!-- title for no google accounts found --> <!-- Password Label -->
<string name="no_account_found_title">No Accounts Found</string> <string name="gtasks_GLA_password">Password</string>
<!-- message body for no google accounts found --> <!-- Google Apps for Domain checkbox -->
<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> <string name="gtasks_GLA_domain">Google Apps for Domain account</string>
<!-- E-mail Address Label --> <!-- Error Message when fields aren't filled out -->
<string name="gtasks_email">E-mail</string> <string name="gtasks_GLA_errorEmpty">Error: fill out all fields!</string>
<!-- Password Label --> <!-- Error Message when we receive a HTTP 401 Unauthorized -->
<string name="gtasks_password">Password</string> <string name="gtasks_GLA_errorAuth">Error: e-mail or password incorrect!</string>
<!-- ============================================== GtasksPreferences == -->
<!-- Login Message --> <!-- GTasks Preferences Title -->
<string name="gtasks_login">Google Account:</string> <string name="gtasks_GPr_header">Google Tasks (Beta!)</string>
<!-- Login Message when Error --> <!-- ================================================ Synchronization == -->
<string name="gtasks_login_error">Please try your e-mail and password again.</string>
<!-- title for notification tray when synchronizing -->
<string name="gtasks_notification_title">Astrid: Google Tasks</string>
</resources> </resources>

@ -16,6 +16,10 @@
<item name="android:windowBackground">@null</item> <item name="android:windowBackground">@null</item>
</style> </style>
<style name="White" parent="android:Theme.Light">
<item name="android:windowBackground">@null</item>
</style>
<!--=============================================== TaskListActivity == --> <!--=============================================== TaskListActivity == -->
<style name="TextAppearance.TLA_NoItems"> <style name="TextAppearance.TLA_NoItems">

Loading…
Cancel
Save