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