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