|
|
|
|
@ -6,6 +6,14 @@
|
|
|
|
|
|
|
|
|
|
package com.todoroo.astrid.welcome.tutorial;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
import android.accounts.Account;
|
|
|
|
|
import android.accounts.AccountManager;
|
|
|
|
|
import android.accounts.AccountManagerCallback;
|
|
|
|
|
import android.accounts.AccountManagerFuture;
|
|
|
|
|
import android.app.ProgressDialog;
|
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
|
import android.graphics.Color;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
@ -13,16 +21,22 @@ import android.support.v4.view.ViewPager;
|
|
|
|
|
import android.text.SpannableString;
|
|
|
|
|
import android.text.Spanned;
|
|
|
|
|
import android.text.TextPaint;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.text.style.ClickableSpan;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
|
import android.view.Window;
|
|
|
|
|
import android.widget.Button;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
import com.google.api.client.googleapis.extensions.android2.auth.GoogleAccountManager;
|
|
|
|
|
import com.timsu.astrid.R;
|
|
|
|
|
import com.todoroo.andlib.utility.DialogUtilities;
|
|
|
|
|
import com.todoroo.astrid.actfm.ActFmGoogleAuthActivity;
|
|
|
|
|
import com.todoroo.astrid.actfm.ActFmLoginActivity;
|
|
|
|
|
import com.todoroo.astrid.gtasks.auth.ModernAuthManager;
|
|
|
|
|
import com.viewpagerindicator.CirclePageIndicator;
|
|
|
|
|
import com.viewpagerindicator.PageIndicator;
|
|
|
|
|
|
|
|
|
|
@ -68,6 +82,90 @@ public class WelcomeWalkthrough extends ActFmLoginActivity {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void initializeUI() {
|
|
|
|
|
String[] accounts = ModernAuthManager.getAccounts(this);
|
|
|
|
|
String email = null;
|
|
|
|
|
if (accounts != null && accounts.length > 0) {
|
|
|
|
|
email = accounts[0];
|
|
|
|
|
}
|
|
|
|
|
Button simpleLogin = (Button) findViewById(R.id.quick_login_google);
|
|
|
|
|
if (simpleLogin != null && !TextUtils.isEmpty(email)) {
|
|
|
|
|
initializeSimpleUI(email);
|
|
|
|
|
} else {
|
|
|
|
|
if (mAdapter != null && mAdapter.layouts[mAdapter.layouts.length - 1] != R.layout.welcome_walkthrough_login_page)
|
|
|
|
|
mAdapter.changeLoginPage(R.layout.welcome_walkthrough_login_page);
|
|
|
|
|
super.initializeUI();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initializeSimpleUI(final String email) {
|
|
|
|
|
Button simpleLogin = (Button) findViewById(R.id.quick_login_google);
|
|
|
|
|
simpleLogin.setText(getString(R.string.actfm_quick_login, email));
|
|
|
|
|
simpleLogin.setOnClickListener(new OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
final ProgressDialog pd = DialogUtilities.progressDialog(WelcomeWalkthrough.this, getString(R.string.gtasks_GLA_authenticating));
|
|
|
|
|
pd.show();
|
|
|
|
|
GoogleAccountManager accountManager = new GoogleAccountManager(WelcomeWalkthrough.this);
|
|
|
|
|
Account a = accountManager.getAccountByName(email);
|
|
|
|
|
AccountManagerCallback<Bundle> callback = new AccountManagerCallback<Bundle>() {
|
|
|
|
|
public void run(final AccountManagerFuture<Bundle> future) {
|
|
|
|
|
new Thread() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
try {
|
|
|
|
|
Bundle bundle = future.getResult(30, TimeUnit.SECONDS);
|
|
|
|
|
if (bundle.containsKey(AccountManager.KEY_AUTHTOKEN)) {
|
|
|
|
|
String authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN);
|
|
|
|
|
onAuthTokenSuccess(email, authToken);
|
|
|
|
|
}
|
|
|
|
|
} catch (final Exception e) {
|
|
|
|
|
Log.e("actfm-google-auth", "Login Error", e); //$NON-NLS-1$ //$NON-NLS-2$
|
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
int error = e instanceof IOException ? R.string.gtasks_GLA_errorIOAuth :
|
|
|
|
|
R.string.gtasks_GLA_errorAuth;
|
|
|
|
|
Toast.makeText(WelcomeWalkthrough.this,
|
|
|
|
|
error,
|
|
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} finally {
|
|
|
|
|
DialogUtilities.dismissDialog(WelcomeWalkthrough.this, pd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}.start();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
accountManager.manager.getAuthToken(a, ActFmGoogleAuthActivity.AUTH_TOKEN_TYPE, null, WelcomeWalkthrough.this, callback, null);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
TextView rejectQuickLogin = (TextView) findViewById(R.id.quick_login_reject);
|
|
|
|
|
rejectQuickLogin.setText(getString(R.string.actfm_quick_login_reject, email));
|
|
|
|
|
rejectQuickLogin.setOnClickListener(new OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
mAdapter.changeLoginPage(R.layout.welcome_walkthrough_login_page);
|
|
|
|
|
mPager.setAdapter(mAdapter);
|
|
|
|
|
mPager.setCurrentItem(mAdapter.layouts.length - 1, false);
|
|
|
|
|
initializeUI();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onAuthTokenSuccess(final String email, final String authToken) {
|
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
authenticate(email, email, "", "google", authToken); //$NON-NLS-1$ //$NON-NLS-2$
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onPageChanged(View view, int position) {
|
|
|
|
|
currentPage = position;
|
|
|
|
|
currentView = view;
|
|
|
|
|
|