From 0c6763a19f32f73f8a940aaee7abecb2a04d1889 Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Mon, 8 Sep 2014 19:11:00 +0200 Subject: [PATCH] Show confirmation dialog when adding user from QS Bug: 17392352 Change-Id: I522b0427dbb594d5e8ce33e928dfdc896dc961c7 --- packages/SystemUI/res/values/strings.xml | 6 +++ .../policy/UserSwitcherController.java | 39 ++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 23d9748ddd09e..147efaf10d47b 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -798,6 +798,12 @@ Yes, continue + + Add new user? + + + When you add a new user, that person needs to set up their space.\n\nAny user can update apps for all other users. + diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java index 52fa621dc5cc6..d02826ffdaa8a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java @@ -73,6 +73,7 @@ public class UserSwitcherController { private ArrayList mUsers = new ArrayList<>(); private Dialog mExitGuestDialog; + private Dialog mAddUserDialog; private int mLastNonGuestUser = UserHandle.USER_OWNER; private boolean mSimpleUserSwitcher; private boolean mAddUsersWhenLocked; @@ -228,8 +229,8 @@ public class UserSwitcherController { // No guest user. Create one. id = mUserManager.createGuest(mContext, mContext.getString(R.string.guest_nickname)).id; } else if (record.isAddUser) { - id = mUserManager.createUser( - mContext.getString(R.string.user_new_user_name), 0 /* flags */).id; + showAddUserDialog(); + return; } else { id = record.info.id; } @@ -260,6 +261,14 @@ public class UserSwitcherController { mExitGuestDialog.show(); } + private void showAddUserDialog() { + if (mAddUserDialog != null && mAddUserDialog.isShowing()) { + mAddUserDialog.cancel(); + } + mAddUserDialog = new AddUserDialog(mContext); + mAddUserDialog.show(); + } + private void exitGuest(int id) { int newId = UserHandle.USER_OWNER; if (mLastNonGuestUser != UserHandle.USER_OWNER) { @@ -534,4 +543,30 @@ public class UserSwitcherController { } } } + + private final class AddUserDialog extends SystemUIDialog implements + DialogInterface.OnClickListener { + + public AddUserDialog(Context context) { + super(context); + setTitle(R.string.user_add_user_title); + setMessage(context.getString(R.string.user_add_user_message_short)); + setButton(DialogInterface.BUTTON_NEGATIVE, + context.getString(android.R.string.cancel), this); + setButton(DialogInterface.BUTTON_POSITIVE, + context.getString(android.R.string.ok), this); + } + + @Override + public void onClick(DialogInterface dialog, int which) { + if (which == BUTTON_NEGATIVE) { + cancel(); + } else { + dismiss(); + int id = mUserManager.createUser( + mContext.getString(R.string.user_new_user_name), 0 /* flags */).id; + switchToUserId(id); + } + } + } }