Update dialog to edit user info
This CL includes replacing AlertDialog used in EditUserInfoController class with dialog from CustomDialogHelper class that has an updated layout. Tests are updated to comply with new layout of the dialog. Minor changes made to code to better work with this update. Bug: 280568195 Test: atest EditUserInfoController Change-Id: Ic93887eebf85757e50b4ccdcf2ba24f338763ae8
This commit is contained in:
@@ -41,7 +41,6 @@
|
||||
android:id="@+id/dialog_with_icon_message"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dp"
|
||||
android:gravity="center"
|
||||
style="@style/TextAppearanceSmall"/>
|
||||
|
||||
|
||||
@@ -14,62 +14,48 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<ScrollView
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/user_info_editor"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/user_info_scroll"
|
||||
android:padding="16dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:baselineAligned="false"
|
||||
android:orientation="vertical">
|
||||
<FrameLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:baselineAligned="false"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:id="@+id/user_info_title"
|
||||
android:gravity="center"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/EditUserDialogTitle"
|
||||
android:text="@string/user_info_settings_title"
|
||||
android:textDirection="locale"/>
|
||||
<FrameLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center">
|
||||
<ImageView
|
||||
android:id="@+id/user_photo"
|
||||
android:layout_width="@dimen/user_photo_size_in_user_info_dialog"
|
||||
android:layout_height="@dimen/user_photo_size_in_user_info_dialog"
|
||||
android:contentDescription="@string/user_image_photo_selector"
|
||||
android:scaleType="fitCenter"/>
|
||||
<ImageView
|
||||
android:id="@+id/add_a_photo_icon"
|
||||
android:layout_width="@dimen/add_a_photo_icon_size_in_user_info_dialog"
|
||||
android:layout_height="@dimen/add_a_photo_icon_size_in_user_info_dialog"
|
||||
android:src="@drawable/add_a_photo_circled"
|
||||
android:layout_gravity="bottom|right"/>
|
||||
</FrameLayout>
|
||||
android:layout_gravity="center">
|
||||
<ImageView
|
||||
android:id="@+id/user_photo"
|
||||
android:layout_width="@dimen/user_photo_size_in_user_info_dialog"
|
||||
android:layout_height="@dimen/user_photo_size_in_user_info_dialog"
|
||||
android:contentDescription="@string/user_image_photo_selector"
|
||||
android:scaleType="fitCenter"/>
|
||||
<ImageView
|
||||
android:id="@+id/add_a_photo_icon"
|
||||
android:layout_width="@dimen/add_a_photo_icon_size_in_user_info_dialog"
|
||||
android:layout_height="@dimen/add_a_photo_icon_size_in_user_info_dialog"
|
||||
android:src="@drawable/add_a_photo_circled"
|
||||
android:layout_gravity="bottom|right"/>
|
||||
</FrameLayout>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/user_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/user_name_height_in_user_info_dialog"
|
||||
android:layout_gravity="center"
|
||||
android:minWidth="200dp"
|
||||
android:layout_marginStart="6dp"
|
||||
android:minHeight="@dimen/min_tap_target_size"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textAlignment="viewStart"
|
||||
android:inputType="text|textCapWords"
|
||||
android:selectAllOnFocus="true"
|
||||
android:hint="@string/user_nickname"
|
||||
android:maxLength="100"/>
|
||||
<EditText
|
||||
android:id="@+id/user_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/user_name_height_in_user_info_dialog"
|
||||
android:layout_gravity="center"
|
||||
android:minWidth="200dp"
|
||||
android:layout_marginStart="6dp"
|
||||
android:minHeight="@dimen/min_tap_target_size"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textAlignment="viewStart"
|
||||
android:inputType="text|textCapWords"
|
||||
android:selectAllOnFocus="true"
|
||||
android:hint="@string/user_nickname"
|
||||
android:maxLength="100"/>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ public class CreateUserDialogController {
|
||||
private static final String KEY_IS_ADMIN = "admin_status";
|
||||
private static final String KEY_ADD_USER_LONG_MESSAGE_DISPLAYED =
|
||||
"key_add_user_long_message_displayed";
|
||||
public static final int MESSAGE_PADDING = 10;
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({EXIT_DIALOG, INITIAL_DIALOG, GRANT_ADMIN_DIALOG,
|
||||
@@ -191,6 +192,7 @@ public class CreateUserDialogController {
|
||||
cancelCallback.run();
|
||||
clear();
|
||||
});
|
||||
mCustomDialogHelper.setMessagePadding(MESSAGE_PADDING);
|
||||
mUserCreationDialog.setCanceledOnTouchOutside(true);
|
||||
return mUserCreationDialog;
|
||||
}
|
||||
@@ -212,7 +214,6 @@ public class CreateUserDialogController {
|
||||
}
|
||||
updateLayout();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
private void updateLayout() {
|
||||
@@ -234,7 +235,6 @@ public class CreateUserDialogController {
|
||||
}
|
||||
Drawable icon = mActivity.getDrawable(R.drawable.ic_person_add);
|
||||
mCustomDialogHelper.setVisibility(mCustomDialogHelper.ICON, true)
|
||||
.setVisibility(mCustomDialogHelper.TITLE, true)
|
||||
.setVisibility(mCustomDialogHelper.MESSAGE, true)
|
||||
.setIcon(icon)
|
||||
.setButtonEnabled(true)
|
||||
@@ -248,7 +248,6 @@ public class CreateUserDialogController {
|
||||
mGrantAdminView.setVisibility(View.VISIBLE);
|
||||
mCustomDialogHelper
|
||||
.setVisibility(mCustomDialogHelper.ICON, true)
|
||||
.setVisibility(mCustomDialogHelper.TITLE, true)
|
||||
.setVisibility(mCustomDialogHelper.MESSAGE, true)
|
||||
.setIcon(mActivity.getDrawable(R.drawable.ic_admin_panel_settings))
|
||||
.setTitle(R.string.user_grant_admin_title)
|
||||
@@ -262,8 +261,8 @@ public class CreateUserDialogController {
|
||||
case EDIT_NAME_DIALOG:
|
||||
mCustomDialogHelper
|
||||
.setVisibility(mCustomDialogHelper.ICON, false)
|
||||
.setVisibility(mCustomDialogHelper.TITLE, false)
|
||||
.setVisibility(mCustomDialogHelper.MESSAGE, false)
|
||||
.setTitle(R.string.user_info_settings_title)
|
||||
.setNegativeButtonText(R.string.back)
|
||||
.setPositiveButtonText(R.string.done);
|
||||
mEditUserInfoView.setVisibility(View.VISIBLE);
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.android.settingslib.users;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -31,7 +30,6 @@ import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ScrollView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
@@ -41,6 +39,7 @@ import com.android.settingslib.R;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.drawable.CircleFramedDrawable;
|
||||
import com.android.settingslib.utils.CustomDialogHelper;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.function.BiConsumer;
|
||||
@@ -128,7 +127,7 @@ public class EditUserInfoController {
|
||||
* codes to take photo/choose photo/crop photo.
|
||||
*/
|
||||
public Dialog createDialog(Activity activity, ActivityStarter activityStarter,
|
||||
@Nullable Drawable oldUserIcon, String defaultUserName, String title,
|
||||
@Nullable Drawable oldUserIcon, String defaultUserName,
|
||||
BiConsumer<String, Drawable> successCallback, Runnable cancelCallback) {
|
||||
LayoutInflater inflater = LayoutInflater.from(activity);
|
||||
View content = inflater.inflate(R.layout.edit_user_info_dialog_content, null);
|
||||
@@ -160,10 +159,8 @@ public class EditUserInfoController {
|
||||
userPhotoView);
|
||||
}
|
||||
}
|
||||
ScrollView scrollView = content.findViewById(R.id.user_info_scroll);
|
||||
scrollView.setClipToOutline(true);
|
||||
mEditUserInfoDialog = buildDialog(activity, content, userNameView, oldUserIcon,
|
||||
defaultUserName, title, successCallback, cancelCallback);
|
||||
defaultUserName, successCallback, cancelCallback);
|
||||
|
||||
// Make sure the IME is up.
|
||||
mEditUserInfoDialog.getWindow()
|
||||
@@ -181,12 +178,13 @@ public class EditUserInfoController {
|
||||
}
|
||||
|
||||
private Dialog buildDialog(Activity activity, View content, EditText userNameView,
|
||||
@Nullable Drawable oldUserIcon, String defaultUserName, String title,
|
||||
@Nullable Drawable oldUserIcon, String defaultUserName,
|
||||
BiConsumer<String, Drawable> successCallback, Runnable cancelCallback) {
|
||||
return new AlertDialog.Builder(activity)
|
||||
.setView(content)
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
CustomDialogHelper dialogHelper = new CustomDialogHelper(activity);
|
||||
dialogHelper
|
||||
.setTitle(R.string.user_info_settings_title)
|
||||
.addCustomView(content)
|
||||
.setPositiveButton(android.R.string.ok, view -> {
|
||||
Drawable newUserIcon = mEditUserPhotoController != null
|
||||
? mEditUserPhotoController.getNewUserPhotoDrawable()
|
||||
: null;
|
||||
@@ -201,20 +199,23 @@ public class EditUserInfoController {
|
||||
if (successCallback != null) {
|
||||
successCallback.accept(userName, userIcon);
|
||||
}
|
||||
dialogHelper.getDialog().dismiss();
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
|
||||
.setBackButton(android.R.string.cancel, view -> {
|
||||
clear();
|
||||
if (cancelCallback != null) {
|
||||
cancelCallback.run();
|
||||
}
|
||||
})
|
||||
.setOnCancelListener(dialog -> {
|
||||
clear();
|
||||
if (cancelCallback != null) {
|
||||
cancelCallback.run();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
dialogHelper.getDialog().dismiss();
|
||||
});
|
||||
dialogHelper.getDialog().setOnCancelListener(dialog -> {
|
||||
clear();
|
||||
if (cancelCallback != null) {
|
||||
cancelCallback.run();
|
||||
}
|
||||
dialogHelper.getDialog().dismiss();
|
||||
});
|
||||
return dialogHelper.getDialog();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
||||
@@ -192,6 +192,14 @@ public class CustomDialogHelper {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets message padding of the dialog.
|
||||
*/
|
||||
public CustomDialogHelper setMessagePadding(int dp) {
|
||||
mDialogMessage.setPadding(dp, dp, dp, dp);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets icon of the dialog.
|
||||
*/
|
||||
|
||||
@@ -111,13 +111,13 @@ public class CreateUserDialogControllerTest {
|
||||
mActivityStarter, true, null,
|
||||
cancelCallback);
|
||||
dialog.show();
|
||||
assertThat(dialog.findViewById(R.id.user_info_scroll).getVisibility()).isEqualTo(View.GONE);
|
||||
assertThat(dialog.findViewById(R.id.user_info_editor).getVisibility()).isEqualTo(View.GONE);
|
||||
Button next = dialog.findViewById(R.id.button_ok);
|
||||
next.performClick();
|
||||
((RadioButton) dialog.findViewById(R.id.grant_admin_yes)).setChecked(true);
|
||||
assertThat(dialog.findViewById(R.id.user_info_scroll).getVisibility()).isEqualTo(View.GONE);
|
||||
assertThat(dialog.findViewById(R.id.user_info_editor).getVisibility()).isEqualTo(View.GONE);
|
||||
next.performClick();
|
||||
assertThat(dialog.findViewById(R.id.user_info_scroll).getVisibility())
|
||||
assertThat(dialog.findViewById(R.id.user_info_editor).getVisibility())
|
||||
.isEqualTo(View.VISIBLE);
|
||||
dialog.dismiss();
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
@@ -108,7 +107,7 @@ public class EditUserInfoControllerTest {
|
||||
@Test
|
||||
public void photoControllerOnActivityResult_whenWaiting_isCalled() {
|
||||
mController.createDialog(mActivity, mActivityStarter, mCurrentIcon, "test user",
|
||||
"title", null, null);
|
||||
null, null);
|
||||
mController.startingActivityForResult();
|
||||
Intent resultData = new Intent();
|
||||
mController.onActivityResult(0, 0, resultData);
|
||||
@@ -126,9 +125,7 @@ public class EditUserInfoControllerTest {
|
||||
() -> String.valueOf('A')).limit(200).collect(Collectors.joining());
|
||||
|
||||
final AlertDialog dialog = (AlertDialog) mController.createDialog(mActivity,
|
||||
mActivityStarter, mCurrentIcon,
|
||||
"test user", "title", null,
|
||||
null);
|
||||
mActivityStarter, mCurrentIcon, "test user", null, null);
|
||||
dialog.show();
|
||||
final EditText userNameEditText = dialog.findViewById(R.id.user_name);
|
||||
userNameEditText.setText(longName);
|
||||
@@ -143,7 +140,7 @@ public class EditUserInfoControllerTest {
|
||||
|
||||
AlertDialog dialog = (AlertDialog) mController.createDialog(
|
||||
mActivity, mActivityStarter, mCurrentIcon, "test",
|
||||
"title", successCallback, cancelCallback);
|
||||
successCallback, cancelCallback);
|
||||
dialog.show();
|
||||
dialog.cancel();
|
||||
|
||||
@@ -159,9 +156,9 @@ public class EditUserInfoControllerTest {
|
||||
|
||||
AlertDialog dialog = (AlertDialog) mController.createDialog(
|
||||
mActivity, mActivityStarter, mCurrentIcon, "test",
|
||||
"title", successCallback, cancelCallback);
|
||||
successCallback, cancelCallback);
|
||||
dialog.show();
|
||||
dialog.getButton(Dialog.BUTTON_NEGATIVE).performClick();
|
||||
dialog.findViewById(R.id.button_back).performClick();
|
||||
|
||||
verifyNoInteractions(successCallback);
|
||||
verify(cancelCallback, times(1))
|
||||
@@ -176,11 +173,11 @@ public class EditUserInfoControllerTest {
|
||||
Drawable oldUserIcon = mCurrentIcon;
|
||||
AlertDialog dialog = (AlertDialog) mController.createDialog(
|
||||
mActivity, mActivityStarter, oldUserIcon, "test",
|
||||
"title", successCallback, cancelCallback);
|
||||
successCallback, cancelCallback);
|
||||
// No change to the photo.
|
||||
when(mController.getPhotoController().getNewUserPhotoDrawable()).thenReturn(null);
|
||||
dialog.show();
|
||||
dialog.getButton(Dialog.BUTTON_POSITIVE).performClick();
|
||||
dialog.findViewById(R.id.button_ok).performClick();
|
||||
|
||||
verify(successCallback, times(1))
|
||||
.accept("test", oldUserIcon);
|
||||
@@ -194,11 +191,11 @@ public class EditUserInfoControllerTest {
|
||||
|
||||
AlertDialog dialog = (AlertDialog) mController.createDialog(
|
||||
mActivity, mActivityStarter, null, "test",
|
||||
"title", successCallback, cancelCallback);
|
||||
successCallback, cancelCallback);
|
||||
// No change to the photo.
|
||||
when(mController.getPhotoController().getNewUserPhotoDrawable()).thenReturn(null);
|
||||
dialog.show();
|
||||
dialog.getButton(Dialog.BUTTON_POSITIVE).performClick();
|
||||
dialog.findViewById(R.id.button_ok).performClick();
|
||||
|
||||
verify(successCallback, times(1))
|
||||
.accept("test", null);
|
||||
@@ -212,14 +209,14 @@ public class EditUserInfoControllerTest {
|
||||
|
||||
AlertDialog dialog = (AlertDialog) mController.createDialog(
|
||||
mActivity, mActivityStarter, mCurrentIcon, "test",
|
||||
"title", successCallback, cancelCallback);
|
||||
successCallback, cancelCallback);
|
||||
// No change to the photo.
|
||||
when(mController.getPhotoController().getNewUserPhotoDrawable()).thenReturn(null);
|
||||
dialog.show();
|
||||
String expectedNewName = "new test user";
|
||||
EditText editText = (EditText) dialog.findViewById(R.id.user_name);
|
||||
editText.setText(expectedNewName);
|
||||
dialog.getButton(Dialog.BUTTON_POSITIVE).performClick();
|
||||
dialog.findViewById(R.id.button_ok).performClick();
|
||||
|
||||
verify(successCallback, times(1))
|
||||
.accept(expectedNewName, mCurrentIcon);
|
||||
@@ -233,12 +230,12 @@ public class EditUserInfoControllerTest {
|
||||
|
||||
AlertDialog dialog = (AlertDialog) mController.createDialog(
|
||||
mActivity, mActivityStarter, mCurrentIcon, "test",
|
||||
"title", successCallback, cancelCallback);
|
||||
successCallback, cancelCallback);
|
||||
// A different drawable.
|
||||
Drawable newPhoto = mock(Drawable.class);
|
||||
when(mController.getPhotoController().getNewUserPhotoDrawable()).thenReturn(newPhoto);
|
||||
dialog.show();
|
||||
dialog.getButton(Dialog.BUTTON_POSITIVE).performClick();
|
||||
dialog.findViewById(R.id.button_ok).performClick();
|
||||
|
||||
verify(successCallback, times(1))
|
||||
.accept("test", newPhoto);
|
||||
@@ -252,12 +249,12 @@ public class EditUserInfoControllerTest {
|
||||
|
||||
AlertDialog dialog = (AlertDialog) mController.createDialog(
|
||||
mActivity, mActivityStarter, null, "test",
|
||||
"title", successCallback, cancelCallback);
|
||||
successCallback, cancelCallback);
|
||||
// A different drawable.
|
||||
Drawable newPhoto = mock(Drawable.class);
|
||||
when(mController.getPhotoController().getNewUserPhotoDrawable()).thenReturn(newPhoto);
|
||||
dialog.show();
|
||||
dialog.getButton(Dialog.BUTTON_POSITIVE).performClick();
|
||||
dialog.findViewById(R.id.button_ok).performClick();
|
||||
|
||||
verify(successCallback, times(1))
|
||||
.accept("test", newPhoto);
|
||||
@@ -269,7 +266,7 @@ public class EditUserInfoControllerTest {
|
||||
mPhotoRestrictedByBase = true;
|
||||
|
||||
mController.createDialog(mActivity, mActivityStarter, mCurrentIcon,
|
||||
"test", "title", null, null);
|
||||
"test", null, null);
|
||||
|
||||
assertThat(mController.mPhotoController).isNull();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user