• 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.settingslib.drawer;
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.content.Intent;
26 import android.os.Bundle;
27 import android.os.UserHandle;
28 import android.os.UserManager;
29 
30 public class ProfileSelectDialog extends DialogFragment implements OnClickListener {
31 
32     private static final String ARG_SELECTED_TILE = "selectedTile";
33 
34     private Tile mSelectedTile;
35 
show(FragmentManager manager, Tile tile)36     public static void show(FragmentManager manager, Tile tile) {
37         ProfileSelectDialog dialog = new ProfileSelectDialog();
38         Bundle args = new Bundle();
39         args.putParcelable(ARG_SELECTED_TILE, tile);
40         dialog.setArguments(args);
41         dialog.show(manager, "select_profile");
42     }
43 
44     @Override
onCreate(Bundle savedInstanceState)45     public void onCreate(Bundle savedInstanceState) {
46         super.onCreate(savedInstanceState);
47         mSelectedTile = getArguments().getParcelable(ARG_SELECTED_TILE);
48     }
49 
50     @Override
onCreateDialog(Bundle savedInstanceState)51     public Dialog onCreateDialog(Bundle savedInstanceState) {
52         Context context = getActivity();
53         AlertDialog.Builder builder = new AlertDialog.Builder(context);
54         UserAdapter adapter = UserAdapter.createUserAdapter(UserManager.get(context), context,
55                 mSelectedTile.userHandle);
56         builder.setTitle(com.android.settingslib.R.string.choose_profile)
57                 .setAdapter(adapter, this);
58 
59         return builder.create();
60     }
61 
62     @Override
onClick(DialogInterface dialog, int which)63     public void onClick(DialogInterface dialog, int which) {
64         UserHandle user = mSelectedTile.userHandle.get(which);
65         // Show menu on top level items.
66         mSelectedTile.intent.putExtra(SettingsDrawerActivity.EXTRA_SHOW_MENU, true);
67         mSelectedTile.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
68         getActivity().startActivityAsUser(mSelectedTile.intent, user);
69         ((SettingsDrawerActivity) getActivity()).onProfileTileOpen();
70     }
71 }
72