Loading packages/SettingsLib/src/com/android/settingslib/users/CreateUserDialogController.java +24 −12 Original line number Diff line number Diff line Loading @@ -80,6 +80,8 @@ public class CreateUserDialogController { private Bitmap mSavedPhoto; private String mSavedName; private Drawable mSavedDrawable; private String mUserName; private Drawable mNewUserIcon; private Boolean mIsAdmin; private Dialog mUserCreationDialog; private View mGrantAdminView; Loading @@ -89,6 +91,7 @@ public class CreateUserDialogController { private ActivityStarter mActivityStarter; private boolean mWaitingForActivityResult; private NewUserData mSuccessCallback; private Runnable mCancelCallback; private final String mFileAuthority; Loading @@ -113,6 +116,7 @@ public class CreateUserDialogController { mEditUserInfoView = null; mUserNameView = null; mSuccessCallback = null; mCancelCallback = null; mCurrentState = INITIAL_DIALOG; } Loading Loading @@ -184,14 +188,12 @@ public class CreateUserDialogController { mActivity = activity; mCustomDialogHelper = new CustomDialogHelper(activity); mSuccessCallback = successCallback; mCancelCallback = cancelCallback; mActivityStarter = activityStarter; addCustomViews(isMultipleAdminEnabled); mUserCreationDialog = mCustomDialogHelper.getDialog(); updateLayout(); mUserCreationDialog.setOnDismissListener(view -> { cancelCallback.run(); clear(); }); mUserCreationDialog.setOnDismissListener(view -> finish()); mCustomDialogHelper.setMessagePadding(MESSAGE_PADDING); mUserCreationDialog.setCanceledOnTouchOutside(true); return mUserCreationDialog; Loading Loading @@ -269,20 +271,14 @@ public class CreateUserDialogController { mGrantAdminView.setVisibility(View.GONE); break; case CREATE_USER_AND_CLOSE: Drawable newUserIcon = mEditUserPhotoController != null mNewUserIcon = mEditUserPhotoController != null ? mEditUserPhotoController.getNewUserPhotoDrawable() : null; String newName = mUserNameView.getText().toString().trim(); String defaultName = mActivity.getString(R.string.user_new_user_name); String userName = !newName.isEmpty() ? newName : defaultName; if (mSuccessCallback != null) { mSuccessCallback.onSuccess(userName, newUserIcon, Boolean.TRUE.equals(mIsAdmin)); } mUserName = !newName.isEmpty() ? newName : defaultName; mCustomDialogHelper.getDialog().dismiss(); clear(); break; case EXIT_DIALOG: mCustomDialogHelper.getDialog().dismiss(); Loading Loading @@ -384,4 +380,20 @@ public class CreateUserDialogController { public boolean isActive() { return mCustomDialogHelper != null && mCustomDialogHelper.getDialog() != null; } /** * Runs callback and clears saved values after dialog is dismissed. */ public void finish() { if (mCurrentState == CREATE_USER_AND_CLOSE) { if (mSuccessCallback != null) { mSuccessCallback.onSuccess(mUserName, mNewUserIcon, Boolean.TRUE.equals(mIsAdmin)); } } else { if (mCancelCallback != null) { mCancelCallback.run(); } } clear(); } } packages/SettingsLib/tests/robotests/src/com/android/settingslib/users/CreateUserDialogControllerTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -212,6 +212,7 @@ public class CreateUserDialogControllerTest { next.performClick(); verify(successCallback, times(1)) .onSuccess(expectedNewName, null, true); verifyNoInteractions(cancelCallback); } @Test Loading @@ -233,6 +234,7 @@ public class CreateUserDialogControllerTest { next.performClick(); verify(successCallback, times(1)) .onSuccess(expectedNewName, null, false); verifyNoInteractions(cancelCallback); } private class TestCreateUserDialogController extends CreateUserDialogController { Loading Loading
packages/SettingsLib/src/com/android/settingslib/users/CreateUserDialogController.java +24 −12 Original line number Diff line number Diff line Loading @@ -80,6 +80,8 @@ public class CreateUserDialogController { private Bitmap mSavedPhoto; private String mSavedName; private Drawable mSavedDrawable; private String mUserName; private Drawable mNewUserIcon; private Boolean mIsAdmin; private Dialog mUserCreationDialog; private View mGrantAdminView; Loading @@ -89,6 +91,7 @@ public class CreateUserDialogController { private ActivityStarter mActivityStarter; private boolean mWaitingForActivityResult; private NewUserData mSuccessCallback; private Runnable mCancelCallback; private final String mFileAuthority; Loading @@ -113,6 +116,7 @@ public class CreateUserDialogController { mEditUserInfoView = null; mUserNameView = null; mSuccessCallback = null; mCancelCallback = null; mCurrentState = INITIAL_DIALOG; } Loading Loading @@ -184,14 +188,12 @@ public class CreateUserDialogController { mActivity = activity; mCustomDialogHelper = new CustomDialogHelper(activity); mSuccessCallback = successCallback; mCancelCallback = cancelCallback; mActivityStarter = activityStarter; addCustomViews(isMultipleAdminEnabled); mUserCreationDialog = mCustomDialogHelper.getDialog(); updateLayout(); mUserCreationDialog.setOnDismissListener(view -> { cancelCallback.run(); clear(); }); mUserCreationDialog.setOnDismissListener(view -> finish()); mCustomDialogHelper.setMessagePadding(MESSAGE_PADDING); mUserCreationDialog.setCanceledOnTouchOutside(true); return mUserCreationDialog; Loading Loading @@ -269,20 +271,14 @@ public class CreateUserDialogController { mGrantAdminView.setVisibility(View.GONE); break; case CREATE_USER_AND_CLOSE: Drawable newUserIcon = mEditUserPhotoController != null mNewUserIcon = mEditUserPhotoController != null ? mEditUserPhotoController.getNewUserPhotoDrawable() : null; String newName = mUserNameView.getText().toString().trim(); String defaultName = mActivity.getString(R.string.user_new_user_name); String userName = !newName.isEmpty() ? newName : defaultName; if (mSuccessCallback != null) { mSuccessCallback.onSuccess(userName, newUserIcon, Boolean.TRUE.equals(mIsAdmin)); } mUserName = !newName.isEmpty() ? newName : defaultName; mCustomDialogHelper.getDialog().dismiss(); clear(); break; case EXIT_DIALOG: mCustomDialogHelper.getDialog().dismiss(); Loading Loading @@ -384,4 +380,20 @@ public class CreateUserDialogController { public boolean isActive() { return mCustomDialogHelper != null && mCustomDialogHelper.getDialog() != null; } /** * Runs callback and clears saved values after dialog is dismissed. */ public void finish() { if (mCurrentState == CREATE_USER_AND_CLOSE) { if (mSuccessCallback != null) { mSuccessCallback.onSuccess(mUserName, mNewUserIcon, Boolean.TRUE.equals(mIsAdmin)); } } else { if (mCancelCallback != null) { mCancelCallback.run(); } } clear(); } }
packages/SettingsLib/tests/robotests/src/com/android/settingslib/users/CreateUserDialogControllerTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -212,6 +212,7 @@ public class CreateUserDialogControllerTest { next.performClick(); verify(successCallback, times(1)) .onSuccess(expectedNewName, null, true); verifyNoInteractions(cancelCallback); } @Test Loading @@ -233,6 +234,7 @@ public class CreateUserDialogControllerTest { next.performClick(); verify(successCallback, times(1)) .onSuccess(expectedNewName, null, false); verifyNoInteractions(cancelCallback); } private class TestCreateUserDialogController extends CreateUserDialogController { Loading