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.settings.accounts;
18 
19 import android.app.Dialog;
20 import android.app.settings.SettingsEnums;
21 import android.content.Context;
22 import android.content.DialogInterface;
23 import android.os.Bundle;
24 import android.os.UserManager;
25 
26 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
27 import com.android.settings.users.UserDialogs;
28 
29 public class RemoveUserFragment extends InstrumentedDialogFragment {
30     private static final String ARG_USER_ID = "userId";
31 
newInstance(int userId)32     static RemoveUserFragment newInstance(int userId) {
33         Bundle args = new Bundle();
34         args.putInt(ARG_USER_ID, userId);
35         RemoveUserFragment fragment = new RemoveUserFragment();
36         fragment.setArguments(args);
37         return fragment;
38     }
39 
40     @Override
onCreateDialog(Bundle savedInstanceState)41     public Dialog onCreateDialog(Bundle savedInstanceState) {
42         final int userId = getArguments().getInt(ARG_USER_ID);
43         return UserDialogs.createRemoveDialog(getActivity(), userId,
44             new DialogInterface.OnClickListener() {
45                 @Override
46                 public void onClick(DialogInterface dialog, int which) {
47                     UserManager um = (UserManager)
48                         getActivity().getSystemService(Context.USER_SERVICE);
49                     um.removeUser(userId);
50                 }
51             });
52     }
53 
54     @Override
55     public int getMetricsCategory() {
56         return SettingsEnums.DIALOG_REMOVE_USER;
57     }
58 }
59