Vadim Tryshev | a22dd33 | 2016-01-26 18:40:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar; |
| 18 | |
Vadim Tryshev | a22dd33 | 2016-01-26 18:40:37 -0800 | [diff] [blame] | 19 | import android.content.Context; |
| 20 | import android.content.DialogInterface; |
| 21 | |
| 22 | import com.android.systemui.R; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 23 | import com.android.systemui.statusbar.phone.SystemUIDialog; |
| 24 | import com.android.systemui.statusbar.policy.UserSwitcherController; |
Vadim Tryshev | a22dd33 | 2016-01-26 18:40:37 -0800 | [diff] [blame] | 25 | |
| 26 | public class UserUtil { |
| 27 | public static void deleteUserWithPrompt(Context context, int userId, |
| 28 | UserSwitcherController userSwitcherController) { |
| 29 | new RemoveUserDialog(context, userId, userSwitcherController).show(); |
| 30 | } |
| 31 | |
| 32 | private final static class RemoveUserDialog extends SystemUIDialog implements |
| 33 | DialogInterface.OnClickListener { |
| 34 | |
| 35 | private final int mUserId; |
| 36 | private final UserSwitcherController mUserSwitcherController; |
| 37 | |
| 38 | public RemoveUserDialog(Context context, int userId, |
| 39 | UserSwitcherController userSwitcherController) { |
| 40 | super(context); |
| 41 | setTitle(R.string.user_remove_user_title); |
| 42 | setMessage(context.getString(R.string.user_remove_user_message)); |
| 43 | setButton(DialogInterface.BUTTON_NEGATIVE, |
| 44 | context.getString(android.R.string.cancel), this); |
| 45 | setButton(DialogInterface.BUTTON_POSITIVE, |
| 46 | context.getString(R.string.user_remove_user_remove), this); |
| 47 | setCanceledOnTouchOutside(false); |
| 48 | mUserId = userId; |
| 49 | mUserSwitcherController = userSwitcherController; |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public void onClick(DialogInterface dialog, int which) { |
| 54 | if (which == BUTTON_NEGATIVE) { |
| 55 | cancel(); |
| 56 | } else { |
| 57 | dismiss(); |
| 58 | mUserSwitcherController.removeUserId(mUserId); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | } |