Bug 956581 - Make FxAccountGetStartedActivity an AuthenticatorActivity. r=rnewman
--- a/mobile/android/base/fxa/activities/FxAccountCreateAccountActivity.java
+++ b/mobile/android/base/fxa/activities/FxAccountCreateAccountActivity.java
@@ -9,40 +9,42 @@ import java.util.concurrent.Executors;
import org.mozilla.gecko.R;
import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.background.fxa.FxAccountClient10.RequestDelegate;
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;
/**
* Activity which displays create account screen to the user.
*/
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;
/**
* {@inheritDoc}
*/
@Override
public void onCreate(Bundle icicle) {
Logger.debug(LOG_TAG, "onCreate(" + icicle + ")");
@@ -60,29 +62,51 @@ public class FxAccountCreateAccountActiv
button = (Button) ensureFindViewById(null, R.id.create_account_button, "create account button");
createCreateAccountButton();
createYearEdit();
addListeners();
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() {
yearEdit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final String[] years = new String[20];
for (int i = 0; i < years.length; i++) {
@@ -146,18 +170,23 @@ public class FxAccountCreateAccountActiv
return;
}
// For great debugging.
if (FxAccountConstants.LOG_PERSONAL_INFORMATION) {
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();
}
}
public void createAccount(String email, String password) {
String serverURI = FxAccountConstants.DEFAULT_IDP_ENDPOINT;
RequestDelegate<String> delegate = new CreateAccountDelegate(email, password, serverURI);
Executor executor = Executors.newSingleThreadExecutor();
FxAccountClient20 client = new FxAccountClient20(serverURI, executor);
--- a/mobile/android/base/fxa/activities/FxAccountGetStartedActivity.java
+++ b/mobile/android/base/fxa/activities/FxAccountGetStartedActivity.java
@@ -1,32 +1,83 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
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 });
+
+ 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);
+ }
+ });
+ }
- launchActivityOnClick(ensureFindViewById(null, R.id.get_started_button, "get started button"), FxAccountCreateAccountActivity.class);
+ 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);
}
}
--- a/mobile/android/base/fxa/activities/FxAccountSignInActivity.java
+++ b/mobile/android/base/fxa/activities/FxAccountSignInActivity.java
@@ -10,37 +10,39 @@ import java.util.concurrent.Executors;
import org.mozilla.gecko.R;
import org.mozilla.gecko.background.common.log.Logger;
import org.mozilla.gecko.background.fxa.FxAccountClient10.RequestDelegate;
import org.mozilla.gecko.background.fxa.FxAccountClient20;
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;
/**
* Activity which displays sign in screen to the user.
*/
public class FxAccountSignInActivity extends FxAccountAbstractSetupActivity {
protected static final String LOG_TAG = FxAccountSignInActivity.class.getSimpleName();
+ private static final int CHILD_REQUEST_CODE = 3;
+
/**
* {@inheritDoc}
*/
@Override
public void onCreate(Bundle icicle) {
Logger.debug(LOG_TAG, "onCreate(" + icicle + ")");
super.onCreate(icicle);
@@ -53,31 +55,54 @@ public class FxAccountSignInActivity ext
button = (Button) ensureFindViewById(null, R.id.sign_in_button, "sign in button");
minimumPasswordLength = 1; // Minimal restriction on passwords entered to sign in.
createSignInButton();
addListeners();
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> {
public final String email;
public final String password;
public final String serverURI;
public SignInDelegate(String email, String password, String serverURI) {
@@ -114,18 +139,23 @@ public class FxAccountSignInActivity ext
return;
}
// For great debugging.
if (FxAccountConstants.LOG_PERSONAL_INFORMATION) {
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();
}
}
public void signIn(String email, String password) {
String serverURI = FxAccountConstants.DEFAULT_IDP_ENDPOINT;
RequestDelegate<LoginResponse> delegate = new SignInDelegate(email, password, serverURI);
Executor executor = Executors.newSingleThreadExecutor();
FxAccountClient20 client = new FxAccountClient20(serverURI, executor);
--- a/mobile/android/base/fxa/activities/FxAccountStatusActivity.java
+++ b/mobile/android/base/fxa/activities/FxAccountStatusActivity.java
@@ -1,16 +1,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
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;
import android.accounts.Account;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
@@ -24,16 +25,17 @@ public class FxAccountStatusActivity ext
protected View connectionStatusSignInView;
protected View connectionStatusSyncingView;
/**
* {@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_status);
connectionStatusUnverifiedView = ensureFindViewById(null, R.id.unverified_view, "unverified view");
connectionStatusSignInView = ensureFindViewById(null, R.id.sign_in_view, "sign in view");
connectionStatusSyncingView = ensureFindViewById(null, R.id.syncing_view, "syncing view");
--- a/mobile/android/base/fxa/activities/FxAccountUpdateCredentialsActivity.java
+++ b/mobile/android/base/fxa/activities/FxAccountUpdateCredentialsActivity.java
@@ -61,17 +61,17 @@ public class FxAccountUpdateCredentialsA
createButton();
addListeners();
updateButtonState();
createShowPasswordButton();
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
public void onResume() {
super.onResume();
Account accounts[] = FxAccountAuthenticator.getFirefoxAccounts(this);
if (accounts.length < 1) {
redirectToActivity(FxAccountGetStartedActivity.class);