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
private static final String TAG = "AccountSigninActivity";
private static final String INTENT_SIGNIN_ACCESS_POINT =
"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 =
"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,
SigninAccessPoint.RECENT_TABS, SigninAccessPoint.SIGNIN_PROMO,
SigninAccessPoint.NTP_CONTENT_SUGGESTIONS, SigninAccessPoint.AUTOFILL_DROPDOWN})
@Retention(RetentionPolicy.SOURCE)
public @interface AccessPoint {}
private AccountSigninView mView;
@AccessPoint private int mAccessPoint;
/**
......@@ -56,6 +65,7 @@ public class AccountSigninActivity extends AppCompatActivity
public static void startAccountSigninActivity(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_DEFAULT);
context.startActivity(intent);
}
......@@ -88,11 +98,23 @@ public class AccountSigninActivity extends AppCompatActivity
String selectAccount, boolean isDefaultAccount) {
Intent intent = new Intent(context, AccountSigninActivity.class);
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);
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
@SuppressFBWarnings("DM_EXIT")
protected void onCreate(Bundle savedInstanceState) {
......@@ -125,14 +147,28 @@ public class AccountSigninActivity extends AppCompatActivity
int imageSize = getResources().getDimensionPixelSize(R.dimen.signin_account_image_size);
ProfileDataCache profileDataCache =
new ProfileDataCache(this, Profile.getLastUsedProfile(), imageSize);
String selectAccount = getIntent().getStringExtra(INTENT_SELECT_ACCOUNT);
if (selectAccount == null) {
mView.initFromSelectionPage(profileDataCache, false, this, this);
} else {
boolean isDefaultAccount =
getIntent().getBooleanExtra(INTENT_IS_DEFAULT_ACCOUNT, false);
mView.initFromConfirmationPage(profileDataCache, false, selectAccount, isDefaultAccount,
AccountSigninView.UNDO_ABORT, this, this);
int flowType = getIntent().getIntExtra(INTENT_SIGNIN_FLOW_TYPE, -1);
switch (flowType) {
case SIGNIN_FLOW_DEFAULT:
mView.initFromSelectionPage(profileDataCache, false, this, this);
break;
case SIGNIN_FLOW_CONFIRMATION_ONLY: {
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
......
......@@ -168,10 +168,10 @@ public class AccountSigninView extends FrameLayout {
* 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 profileData ProfileDataCache that will be used to retrieve user account info.
* @param isChildAccount Whether this view is for a child account.
* @param delegate The UI object creation delegate.
* @param listener The account selection event listener.
* @param delegate The UI object creation delegate.
* @param listener The account selection event listener.
*/
public void initFromSelectionPage(ProfileDataCache profileData, boolean isChildAccount,
Delegate delegate, Listener listener) {
......@@ -183,17 +183,38 @@ public class AccountSigninView extends FrameLayout {
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
* the caller.
*
* @param profileData ProfileDataCache that will be used to retrieve user account info.
* @param isChildAccount Whether this view is for a child account.
* @param accountName An account that should be used for confirmation page and signin.
* @param profileData ProfileDataCache that will be used to retrieve user account info.
* @param isChildAccount Whether this view is for a child account.
* @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 undoBehavior "Undo" button behavior (see {@link UndoBehavior}).
* @param delegate The UI object creation delegate.
* @param listener The account selection event listener.
* @param undoBehavior "Undo" button behavior (see {@link UndoBehavior}).
* @param delegate The UI object creation delegate.
* @param listener The account selection event listener.
*/
public void initFromConfirmationPage(ProfileDataCache profileData, boolean isChildAccount,
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