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
17package com.android.systemui.statusbar;
18
19import com.android.systemui.statusbar.phone.SystemUIDialog;
20import com.android.systemui.statusbar.policy.UserSwitcherController;
21import android.content.Context;
22import android.content.DialogInterface;
23
24import com.android.systemui.R;
25
26public 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}
63