diff options
| author | 2016-01-26 18:40:37 -0800 | |
|---|---|---|
| committer | 2016-02-01 18:53:51 +0000 | |
| commit | a22dd3341970a9f572724d81a27993c7ac58e9e8 (patch) | |
| tree | cea555437e254410eb1b3e5d8237ec0b23fdac7f | |
| parent | 84867864932d7b8ed20e2c31f4568cb16bcc020e (diff) | |
Make user deletion dialog reusable.
This change will be immediately integrated into master.
This dialog will be also used by the alternate lock screen.
Bug: 25192625
Change-Id: Idc374312fe884af104e342d58f207e0510b9754a
(cherry picked from commit b29374806c393a06c993e5c6b92c62f06d5978c7)
3 files changed, 67 insertions, 33 deletions
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 32da3c62e1f4..c6c448d0c449 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -897,10 +897,10 @@ <!-- Message for add user confirmation dialog - short version. [CHAR LIMIT=none] --> <string name="user_add_user_message_short" msgid="1511354412249044381">When you add a new user, that person needs to set up their space.\n\nAny user can update apps for all other users. </string> - <!-- Title of the confirmation dialog when exiting guest session [CHAR LIMIT=NONE] --> + <!-- Title of the confirmation dialog for deleting a user [CHAR LIMIT=NONE] --> <string name="user_remove_user_title">Remove user?</string> - <!-- Message of the confirmation dialog when exiting guest session [CHAR LIMIT=NONE] --> + <!-- Message of the confirmation dialog for deleting a user [CHAR LIMIT=NONE] --> <string name="user_remove_user_message">All apps and data of this user will be deleted.</string> <!-- Label for button in confirmation dialog when exiting guest session [CHAR LIMIT=35] --> diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/UserUtil.java b/packages/SystemUI/src/com/android/systemui/statusbar/UserUtil.java new file mode 100644 index 000000000000..f9afc7c34668 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/UserUtil.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.statusbar; + +import com.android.systemui.statusbar.phone.SystemUIDialog; +import com.android.systemui.statusbar.policy.UserSwitcherController; +import android.content.Context; +import android.content.DialogInterface; + +import com.android.systemui.R; + +public class UserUtil { + public static void deleteUserWithPrompt(Context context, int userId, + UserSwitcherController userSwitcherController) { + new RemoveUserDialog(context, userId, userSwitcherController).show(); + } + + private final static class RemoveUserDialog extends SystemUIDialog implements + DialogInterface.OnClickListener { + + private final int mUserId; + private final UserSwitcherController mUserSwitcherController; + + public RemoveUserDialog(Context context, int userId, + UserSwitcherController userSwitcherController) { + super(context); + setTitle(R.string.user_remove_user_title); + setMessage(context.getString(R.string.user_remove_user_message)); + setButton(DialogInterface.BUTTON_NEGATIVE, + context.getString(android.R.string.cancel), this); + setButton(DialogInterface.BUTTON_POSITIVE, + context.getString(R.string.user_remove_user_remove), this); + setCanceledOnTouchOutside(false); + mUserId = userId; + mUserSwitcherController = userSwitcherController; + } + + @Override + public void onClick(DialogInterface dialog, int which) { + if (which == BUTTON_NEGATIVE) { + cancel(); + } else { + dismiss(); + mUserSwitcherController.removeUserId(mUserId); + } + } + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/car/UserGridView.java b/packages/SystemUI/src/com/android/systemui/statusbar/car/UserGridView.java index 28f4e05a85ce..229493142402 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/car/UserGridView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/car/UserGridView.java @@ -17,7 +17,6 @@ package com.android.systemui.statusbar.car; import android.content.Context; -import android.content.DialogInterface; import android.os.UserHandle; import android.util.AttributeSet; import android.view.LayoutInflater; @@ -29,8 +28,8 @@ import android.widget.ImageView; import android.widget.TextView; import com.android.systemui.R; +import com.android.systemui.statusbar.UserUtil; import com.android.systemui.statusbar.phone.PhoneStatusBar; -import com.android.systemui.statusbar.phone.SystemUIDialog; import com.android.systemui.statusbar.policy.UserSwitcherController; public class UserGridView extends GridView { @@ -88,7 +87,8 @@ public class UserGridView extends GridView { return true; } - new RemoveUserDialog(getContext(), record.info.id).show(); + UserUtil.deleteUserWithPrompt(getContext(), record.info.id, + mUserSwitcherController); return true; } }); @@ -159,32 +159,4 @@ public class UserGridView extends GridView { return convertView; } } - - private final class RemoveUserDialog extends SystemUIDialog implements - DialogInterface.OnClickListener { - - private final int mUserId; - - public RemoveUserDialog(Context context, int userId) { - super(context); - setTitle(R.string.user_remove_user_title); - setMessage(context.getString(R.string.user_remove_user_message)); - setButton(DialogInterface.BUTTON_NEGATIVE, - context.getString(android.R.string.cancel), this); - setButton(DialogInterface.BUTTON_POSITIVE, - context.getString(R.string.user_remove_user_remove), this); - setCanceledOnTouchOutside(false); - mUserId = userId; - } - - @Override - public void onClick(DialogInterface dialog, int which) { - if (which == BUTTON_NEGATIVE) { - cancel(); - } else { - dismiss(); - mUserSwitcherController.removeUserId(mUserId); - } - } - } } |