• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 package com.android.settings;
17 
18 import android.app.AlertDialog;
19 import android.app.Dialog;
20 import android.app.DialogFragment;
21 import android.app.FragmentManager;
22 import android.content.Context;
23 import android.content.DialogInterface;
24 import android.content.DialogInterface.OnClickListener;
25 import android.os.Bundle;
26 import android.os.UserHandle;
27 import android.os.UserManager;
28 
29 import com.android.settings.dashboard.DashboardTile;
30 
31 public class ProfileSelectDialog extends DialogFragment implements OnClickListener {
32 
33     private static final String ARG_SELECTED_TILE = "selectedTile";
34 
35     private DashboardTile mSelectedTile;
36 
show(FragmentManager manager, DashboardTile tile)37     public static void show(FragmentManager manager, DashboardTile tile) {
38         ProfileSelectDialog dialog = new ProfileSelectDialog();
39         Bundle args = new Bundle();
40         args.putParcelable(ARG_SELECTED_TILE, tile);
41         dialog.setArguments(args);
42         dialog.show(manager, "select_profile");
43     }
44 
45     @Override
onCreate(Bundle savedInstanceState)46     public void onCreate(Bundle savedInstanceState) {
47         super.onCreate(savedInstanceState);
48         mSelectedTile = getArguments().getParcelable(ARG_SELECTED_TILE);
49     }
50 
51     @Override
onCreateDialog(Bundle savedInstanceState)52     public Dialog onCreateDialog(Bundle savedInstanceState) {
53         Context context = getActivity();
54         AlertDialog.Builder builder = new AlertDialog.Builder(context);
55         UserAdapter adapter = Utils.createUserAdapter(UserManager.get(context), context,
56                 mSelectedTile.userHandle);
57         builder.setTitle(R.string.choose_profile)
58                 .setAdapter(adapter, this);
59 
60         return builder.create();
61     }
62 
63     @Override
onClick(DialogInterface dialog, int which)64     public void onClick(DialogInterface dialog, int which) {
65         UserHandle user = mSelectedTile.userHandle.get(which);
66         getActivity().startActivityAsUser(mSelectedTile.intent, user);
67     }
68 }
69