mirror of https://github.com/tasks/tasks
Adding new gtasks login activity for logging in
parent
d7f3108049
commit
7f5028c40d
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
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>
|
Loading…
Reference in New Issue