Commit 361a25f6 authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Android] Add startFromAddAccountPage entry point to AccountSigninActivity

This CL adds AccountSigninActivity.startFromAddAccountPage. This entry point
doesn't show account selection page, starting flow to add account on device
instead.

Bug: 749075
Change-Id: I58323c117db9d899119b55e5a2667e5aaebd09b1
Reviewed-on: https://chromium-review.googlesource.com/595983
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491357}
parent dc8030c1
...@@ -35,17 +35,26 @@ public class AccountSigninActivity extends AppCompatActivity ...@@ -35,17 +35,26 @@ public class AccountSigninActivity extends AppCompatActivity
private static final String TAG = "AccountSigninActivity"; private static final String TAG = "AccountSigninActivity";
private static final String INTENT_SIGNIN_ACCESS_POINT = private static final String INTENT_SIGNIN_ACCESS_POINT =
"AccountSigninActivity.SigninAccessPoint"; "AccountSigninActivity.SigninAccessPoint";
private static final String INTENT_SELECT_ACCOUNT = "AccountSigninActivity.SelectAccount"; private static final String INTENT_SIGNIN_FLOW_TYPE = "AccountSigninActivity.SigninFlowType";
private static final String INTENT_ACCOUNT_NAME = "AccountSigninActivity.AccountName";
private static final String INTENT_IS_DEFAULT_ACCOUNT = private static final String INTENT_IS_DEFAULT_ACCOUNT =
"AccountSigninActivity.IsDefaultAccount"; "AccountSigninActivity.IsDefaultAccount";
private AccountSigninView mView; @IntDef({SIGNIN_FLOW_DEFAULT, SIGNIN_FLOW_CONFIRMATION_ONLY, SIGNIN_FLOW_ADD_NEW_ACCOUNT})
@Retention(RetentionPolicy.SOURCE)
private @interface SigninFlowType {}
private static final int SIGNIN_FLOW_DEFAULT = 0;
private static final int SIGNIN_FLOW_CONFIRMATION_ONLY = 1;
private static final int SIGNIN_FLOW_ADD_NEW_ACCOUNT = 2;
@IntDef({SigninAccessPoint.SETTINGS, SigninAccessPoint.BOOKMARK_MANAGER, @IntDef({SigninAccessPoint.SETTINGS, SigninAccessPoint.BOOKMARK_MANAGER,
SigninAccessPoint.RECENT_TABS, SigninAccessPoint.SIGNIN_PROMO, SigninAccessPoint.RECENT_TABS, SigninAccessPoint.SIGNIN_PROMO,
SigninAccessPoint.NTP_CONTENT_SUGGESTIONS, SigninAccessPoint.AUTOFILL_DROPDOWN}) SigninAccessPoint.NTP_CONTENT_SUGGESTIONS, SigninAccessPoint.AUTOFILL_DROPDOWN})
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
public @interface AccessPoint {} public @interface AccessPoint {}
private AccountSigninView mView;
@AccessPoint private int mAccessPoint; @AccessPoint private int mAccessPoint;
/** /**
...@@ -56,6 +65,7 @@ public class AccountSigninActivity extends AppCompatActivity ...@@ -56,6 +65,7 @@ public class AccountSigninActivity extends AppCompatActivity
public static void startAccountSigninActivity(Context context, @AccessPoint int accessPoint) { public static void startAccountSigninActivity(Context context, @AccessPoint int accessPoint) {
Intent intent = new Intent(context, AccountSigninActivity.class); Intent intent = new Intent(context, AccountSigninActivity.class);
intent.putExtra(INTENT_SIGNIN_ACCESS_POINT, accessPoint); intent.putExtra(INTENT_SIGNIN_ACCESS_POINT, accessPoint);
intent.putExtra(INTENT_SIGNIN_FLOW_TYPE, SIGNIN_FLOW_DEFAULT);
context.startActivity(intent); context.startActivity(intent);
} }
...@@ -88,11 +98,23 @@ public class AccountSigninActivity extends AppCompatActivity ...@@ -88,11 +98,23 @@ public class AccountSigninActivity extends AppCompatActivity
String selectAccount, boolean isDefaultAccount) { String selectAccount, boolean isDefaultAccount) {
Intent intent = new Intent(context, AccountSigninActivity.class); Intent intent = new Intent(context, AccountSigninActivity.class);
intent.putExtra(INTENT_SIGNIN_ACCESS_POINT, accessPoint); intent.putExtra(INTENT_SIGNIN_ACCESS_POINT, accessPoint);
intent.putExtra(INTENT_SELECT_ACCOUNT, selectAccount); intent.putExtra(INTENT_SIGNIN_FLOW_TYPE, SIGNIN_FLOW_CONFIRMATION_ONLY);
intent.putExtra(INTENT_ACCOUNT_NAME, selectAccount);
intent.putExtra(INTENT_IS_DEFAULT_ACCOUNT, isDefaultAccount); intent.putExtra(INTENT_IS_DEFAULT_ACCOUNT, isDefaultAccount);
context.startActivity(intent); context.startActivity(intent);
} }
/**
* Starts AccountSigninActivity from "Add account" page.
* @param accessPoint {@link AccessPoint} for starting signin flow. Used in metrics.
*/
public static void startFromAddAccountPage(Context context, @AccessPoint int accessPoint) {
Intent intent = new Intent(context, AccountSigninActivity.class);
intent.putExtra(INTENT_SIGNIN_ACCESS_POINT, accessPoint);
intent.putExtra(INTENT_SIGNIN_FLOW_TYPE, SIGNIN_FLOW_ADD_NEW_ACCOUNT);
context.startActivity(intent);
}
@Override @Override
@SuppressFBWarnings("DM_EXIT") @SuppressFBWarnings("DM_EXIT")
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -125,14 +147,28 @@ public class AccountSigninActivity extends AppCompatActivity ...@@ -125,14 +147,28 @@ public class AccountSigninActivity extends AppCompatActivity
int imageSize = getResources().getDimensionPixelSize(R.dimen.signin_account_image_size); int imageSize = getResources().getDimensionPixelSize(R.dimen.signin_account_image_size);
ProfileDataCache profileDataCache = ProfileDataCache profileDataCache =
new ProfileDataCache(this, Profile.getLastUsedProfile(), imageSize); new ProfileDataCache(this, Profile.getLastUsedProfile(), imageSize);
String selectAccount = getIntent().getStringExtra(INTENT_SELECT_ACCOUNT);
if (selectAccount == null) { int flowType = getIntent().getIntExtra(INTENT_SIGNIN_FLOW_TYPE, -1);
mView.initFromSelectionPage(profileDataCache, false, this, this); switch (flowType) {
} else { case SIGNIN_FLOW_DEFAULT:
boolean isDefaultAccount = mView.initFromSelectionPage(profileDataCache, false, this, this);
getIntent().getBooleanExtra(INTENT_IS_DEFAULT_ACCOUNT, false); break;
mView.initFromConfirmationPage(profileDataCache, false, selectAccount, isDefaultAccount, case SIGNIN_FLOW_CONFIRMATION_ONLY: {
AccountSigninView.UNDO_ABORT, this, this); String accountName = getIntent().getStringExtra(INTENT_ACCOUNT_NAME);
if (accountName == null) {
throw new IllegalArgumentException("Account name can't be null!");
}
boolean isDefaultAccount =
getIntent().getBooleanExtra(INTENT_IS_DEFAULT_ACCOUNT, false);
mView.initFromConfirmationPage(profileDataCache, false, accountName,
isDefaultAccount, AccountSigninView.UNDO_ABORT, this, this);
break;
}
case SIGNIN_FLOW_ADD_NEW_ACCOUNT:
mView.initFromAddAccountPage(profileDataCache, this, this);
break;
default:
throw new IllegalArgumentException("Unknown signin flow type: " + flowType);
} }
if (getAccessPoint() == SigninAccessPoint.BOOKMARK_MANAGER if (getAccessPoint() == SigninAccessPoint.BOOKMARK_MANAGER
......
...@@ -168,10 +168,10 @@ public class AccountSigninView extends FrameLayout { ...@@ -168,10 +168,10 @@ public class AccountSigninView extends FrameLayout {
* Initializes the view from account selection page. After selecting the account, signin * Initializes the view from account selection page. After selecting the account, signin
* confirmation page will be opened. * confirmation page will be opened.
* *
* @param profileData ProfileDataCache that will be used to retrieve user account info. * @param profileData ProfileDataCache that will be used to retrieve user account info.
* @param isChildAccount Whether this view is for a child account. * @param isChildAccount Whether this view is for a child account.
* @param delegate The UI object creation delegate. * @param delegate The UI object creation delegate.
* @param listener The account selection event listener. * @param listener The account selection event listener.
*/ */
public void initFromSelectionPage(ProfileDataCache profileData, boolean isChildAccount, public void initFromSelectionPage(ProfileDataCache profileData, boolean isChildAccount,
Delegate delegate, Listener listener) { Delegate delegate, Listener listener) {
...@@ -183,17 +183,38 @@ public class AccountSigninView extends FrameLayout { ...@@ -183,17 +183,38 @@ public class AccountSigninView extends FrameLayout {
showSigninPage(); showSigninPage();
} }
/**
* Initializes the view from account selection page. After selecting the account, signin
* confirmation page will be opened.
*
* @param profileData ProfileDataCache that will be used to retrieve user account info.
* @param delegate The UI object creation delegate.
* @param listener The account selection event listener.
*/
public void initFromAddAccountPage(
ProfileDataCache profileData, Delegate delegate, Listener listener) {
setProfileDataCache(profileData);
mIsChildAccount = false; // Children profiles can't add accounts.
mUndoBehavior = UNDO_ABORT;
mDelegate = delegate;
mListener = listener;
showSigninPage();
RecordUserAction.record("Signin_AddAccountToDevice");
mListener.onNewAccount();
}
/** /**
* Initializes the view from signin confirmation page. The account name should be provided by * Initializes the view from signin confirmation page. The account name should be provided by
* the caller. * the caller.
* *
* @param profileData ProfileDataCache that will be used to retrieve user account info. * @param profileData ProfileDataCache that will be used to retrieve user account info.
* @param isChildAccount Whether this view is for a child account. * @param isChildAccount Whether this view is for a child account.
* @param accountName An account that should be used for confirmation page and signin. * @param accountName An account that should be used for confirmation page and signin.
* @param isDefaultAccount Whether {@param accountName} is a default account, used for metrics. * @param isDefaultAccount Whether {@param accountName} is a default account, used for metrics.
* @param undoBehavior "Undo" button behavior (see {@link UndoBehavior}). * @param undoBehavior "Undo" button behavior (see {@link UndoBehavior}).
* @param delegate The UI object creation delegate. * @param delegate The UI object creation delegate.
* @param listener The account selection event listener. * @param listener The account selection event listener.
*/ */
public void initFromConfirmationPage(ProfileDataCache profileData, boolean isChildAccount, public void initFromConfirmationPage(ProfileDataCache profileData, boolean isChildAccount,
String accountName, boolean isDefaultAccount, @UndoBehavior int undoBehavior, String accountName, boolean isDefaultAccount, @UndoBehavior int undoBehavior,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment