Bug 956581 - Make FxAccountGetStartedActivity an AuthenticatorActivity. r=rnewman

This commit is contained in:
Nick Alexander 2014-01-20 21:26:21 -08:00
parent 02dd2cbf5a
commit bf40d9ed51
5 changed files with 137 additions and 25 deletions

View File

@ -14,22 +14,22 @@ import org.mozilla.gecko.background.fxa.FxAccountClient20;
import org.mozilla.gecko.fxa.FxAccountConstants;
import org.mozilla.gecko.fxa.activities.FxAccountSetupTask.FxAccountSignUpTask;
import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
import org.mozilla.gecko.fxa.authenticator.FxAccountAuthenticator;
import org.mozilla.gecko.sync.HTTPFailureException;
import org.mozilla.gecko.sync.net.SyncStorageResponse;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import ch.boye.httpclientandroidlib.HttpResponse;
/**
@ -38,6 +38,8 @@ import ch.boye.httpclientandroidlib.HttpResponse;
public class FxAccountCreateAccountActivity extends FxAccountAbstractSetupActivity {
protected static final String LOG_TAG = FxAccountCreateAccountActivity.class.getSimpleName();
private static final int CHILD_REQUEST_CODE = 2;
protected EditText yearEdit;
/**
@ -65,19 +67,41 @@ public class FxAccountCreateAccountActivity extends FxAccountAbstractSetupActivi
updateButtonState();
createShowPasswordButton();
launchActivityOnClick(ensureFindViewById(null, R.id.sign_in_instead_link, "sign in instead link"), FxAccountSignInActivity.class);
View signInInsteadLink = ensureFindViewById(null, R.id.sign_in_instead_link, "sign in instead link");
signInInsteadLink.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(FxAccountCreateAccountActivity.this, FxAccountSignInActivity.class);
intent.putExtra("email", emailEdit.getText().toString());
intent.putExtra("password", passwordEdit.getText().toString());
// Per http://stackoverflow.com/a/8992365, this triggers a known bug with
// the soft keyboard not being shown for the started activity. Why, Android, why?
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivityForResult(intent, CHILD_REQUEST_CODE);
}
});
// Only set email/password in onCreate; we don't want to overwrite edited values onResume.
if (getIntent() != null && getIntent().getExtras() != null) {
Bundle bundle = getIntent().getExtras();
emailEdit.setText(bundle.getString("email"));
passwordEdit.setText(bundle.getString("password"));
}
}
/**
* {@inheritDoc}
* We might have switched to the SignIn activity; if that activity
* succeeds, feed its result back to the authenticator.
*/
@Override
public void onResume() {
super.onResume();
if (FxAccountAuthenticator.getFirefoxAccounts(this).length > 0) {
redirectToActivity(FxAccountStatusActivity.class);
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Logger.debug(LOG_TAG, "onActivityResult: " + requestCode);
if (requestCode != CHILD_REQUEST_CODE || resultCode != RESULT_OK) {
super.onActivityResult(requestCode, resultCode, data);
return;
}
this.setResult(resultCode, data);
this.finish();
}
protected void createYearEdit() {
@ -151,8 +175,13 @@ public class FxAccountCreateAccountActivity extends FxAccountAbstractSetupActivi
new AndroidFxAccount(activity, account).dump();
}
Toast.makeText(getApplicationContext(), "Got success creating account.", Toast.LENGTH_LONG).show();
redirectToActivity(FxAccountStatusActivity.class);
// The GetStarted activity has called us and needs to return a result to the authenticator.
final Intent intent = new Intent();
intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, email);
intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, FxAccountConstants.ACCOUNT_TYPE);
// intent.putExtra(AccountManager.KEY_AUTHTOKEN, accountType);
setResult(RESULT_OK, intent);
finish();
}
}

View File

@ -6,27 +6,78 @@ package org.mozilla.gecko.fxa.activities;
import org.mozilla.gecko.R;
import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.fxa.FxAccountConstants;
import org.mozilla.gecko.fxa.authenticator.FxAccountAuthenticator;
import android.accounts.AccountAuthenticatorActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
/**
* Activity which displays sign up/sign in screen to the user.
*/
public class FxAccountGetStartedActivity extends FxAccountAbstractActivity {
public class FxAccountGetStartedActivity extends AccountAuthenticatorActivity {
protected static final String LOG_TAG = FxAccountGetStartedActivity.class.getSimpleName();
private static final int CHILD_REQUEST_CODE = 1;
/**
* {@inheritDoc}
*/
@Override
public void onCreate(Bundle icicle) {
Logger.setThreadLogTag(FxAccountConstants.GLOBAL_LOG_TAG);
Logger.debug(LOG_TAG, "onCreate(" + icicle + ")");
super.onCreate(icicle);
setContentView(R.layout.fxaccount_get_started);
linkifyTextViews(null, new int[] { R.id.old_firefox });
// linkifyTextViews(null, new int[] { R.id.old_firefox });
launchActivityOnClick(ensureFindViewById(null, R.id.get_started_button, "get started button"), FxAccountCreateAccountActivity.class);
View button = findViewById(R.id.get_started_button);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(FxAccountGetStartedActivity.this, FxAccountCreateAccountActivity.class);
// Per http://stackoverflow.com/a/8992365, this triggers a known bug with
// the soft keyboard not being shown for the started activity. Why, Android, why?
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivityForResult(intent, CHILD_REQUEST_CODE);
}
});
}
public void onResume() {
super.onResume();
if (FxAccountAuthenticator.getFirefoxAccounts(this).length > 0) {
this.setAccountAuthenticatorResult(null);
setResult(RESULT_CANCELED);
Intent intent = new Intent(this, FxAccountStatusActivity.class);
// Per http://stackoverflow.com/a/8992365, this triggers a known bug with
// the soft keyboard not being shown for the started activity. Why, Android, why?
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
finish();
return;
}
}
/**
* We started the CreateAccount activity for a result; this returns it to the
* authenticator.
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Logger.debug(LOG_TAG, "onActivityResult: " + requestCode);
if (requestCode != CHILD_REQUEST_CODE) {
super.onActivityResult(requestCode, resultCode, data);
return;
}
if (data != null) {
this.setAccountAuthenticatorResult(data.getExtras());
}
this.setResult(requestCode, data);
}
}

View File

@ -15,19 +15,19 @@ import org.mozilla.gecko.background.fxa.FxAccountClient20.LoginResponse;
import org.mozilla.gecko.fxa.FxAccountConstants;
import org.mozilla.gecko.fxa.activities.FxAccountSetupTask.FxAccountSignInTask;
import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
import org.mozilla.gecko.fxa.authenticator.FxAccountAuthenticator;
import org.mozilla.gecko.sync.HTTPFailureException;
import org.mozilla.gecko.sync.net.SyncStorageResponse;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import ch.boye.httpclientandroidlib.HttpResponse;
/**
@ -36,6 +36,8 @@ import ch.boye.httpclientandroidlib.HttpResponse;
public class FxAccountSignInActivity extends FxAccountAbstractSetupActivity {
protected static final String LOG_TAG = FxAccountSignInActivity.class.getSimpleName();
private static final int CHILD_REQUEST_CODE = 3;
/**
* {@inheritDoc}
*/
@ -58,21 +60,44 @@ public class FxAccountSignInActivity extends FxAccountAbstractSetupActivity {
updateButtonState();
createShowPasswordButton();
this.launchActivityOnClick(ensureFindViewById(null, R.id.create_account_link, "create account instead link"), FxAccountCreateAccountActivity.class);
View signInInsteadLink = ensureFindViewById(null, R.id.create_account_link, "create account instead link");
signInInsteadLink.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(FxAccountSignInActivity.this, FxAccountCreateAccountActivity.class);
intent.putExtra("email", emailEdit.getText().toString());
intent.putExtra("password", passwordEdit.getText().toString());
// Per http://stackoverflow.com/a/8992365, this triggers a known bug with
// the soft keyboard not being shown for the started activity. Why, Android, why?
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivityForResult(intent, CHILD_REQUEST_CODE);
}
});
// Only set email/password in onCreate; we don't want to overwrite edited values onResume.
if (getIntent() != null && getIntent().getExtras() != null) {
Bundle bundle = getIntent().getExtras();
emailEdit.setText(bundle.getString("email"));
passwordEdit.setText(bundle.getString("password"));
}
// Not yet implemented.
this.launchActivityOnClick(ensureFindViewById(null, R.id.forgot_password_link, "forgot password link"), null);
// this.launchActivityOnClick(ensureFindViewById(null, R.id.forgot_password_link, "forgot password link"), null);
}
/**
* {@inheritDoc}
* We might have switched to the CreateAccount activity; if that activity
* succeeds, feed its result back to the authenticator.
*/
@Override
public void onResume() {
super.onResume();
if (FxAccountAuthenticator.getFirefoxAccounts(this).length > 0) {
redirectToActivity(FxAccountStatusActivity.class);
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Logger.debug(LOG_TAG, "onActivityResult: " + requestCode);
if (requestCode != CHILD_REQUEST_CODE || resultCode != RESULT_OK) {
super.onActivityResult(requestCode, resultCode, data);
return;
}
this.setResult(resultCode, data);
this.finish();
}
protected class SignInDelegate implements RequestDelegate<LoginResponse> {
@ -119,8 +144,13 @@ public class FxAccountSignInActivity extends FxAccountAbstractSetupActivity {
new AndroidFxAccount(activity, account).dump();
}
Toast.makeText(getApplicationContext(), "Got success creating account.", Toast.LENGTH_LONG).show();
redirectToActivity(FxAccountStatusActivity.class);
// The GetStarted activity has called us and needs to return a result to the authenticator.
final Intent intent = new Intent();
intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, email);
intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, FxAccountConstants.ACCOUNT_TYPE);
// intent.putExtra(AccountManager.KEY_AUTHTOKEN, accountType);
setResult(RESULT_OK, intent);
finish();
}
}

View File

@ -6,6 +6,7 @@ package org.mozilla.gecko.fxa.activities;
import org.mozilla.gecko.R;
import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.fxa.FxAccountConstants;
import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
import org.mozilla.gecko.fxa.authenticator.FxAccountAuthenticator;
@ -29,6 +30,7 @@ public class FxAccountStatusActivity extends FxAccountAbstractActivity {
*/
@Override
public void onCreate(Bundle icicle) {
Logger.setThreadLogTag(FxAccountConstants.GLOBAL_LOG_TAG);
Logger.debug(LOG_TAG, "onCreate(" + icicle + ")");
super.onCreate(icicle);

View File

@ -66,7 +66,7 @@ public class FxAccountUpdateCredentialsActivity extends FxAccountAbstractSetupAc
emailEdit.setEnabled(false);
// Not yet implemented.
this.launchActivityOnClick(ensureFindViewById(null, R.id.forgot_password_link, "forgot password link"), null);
// this.launchActivityOnClick(ensureFindViewById(null, R.id.forgot_password_link, "forgot password link"), null);
}
@Override