10ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani/* 20ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani * Copyright (C) 2013 The Android Open Source Project 30ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani * 40ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani * Licensed under the Apache License, Version 2.0 (the "License"); 50ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani * you may not use this file except in compliance with the License. 60ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani * You may obtain a copy of the License at 70ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani * 80ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani * http://www.apache.org/licenses/LICENSE-2.0 90ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani * 100ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani * Unless required by applicable law or agreed to in writing, software 110ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani * distributed under the License is distributed on an "AS IS" BASIS, 120ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani * See the License for the specific language governing permissions and 140ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani * limitations under the License. 150ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani */ 160ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani 170ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasanipackage com.android.settings.users; 180ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani 190ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasaniimport android.app.Dialog; 20247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasaniimport android.content.DialogInterface; 210ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasaniimport android.content.Intent; 220ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasaniimport android.content.pm.UserInfo; 230ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasaniimport android.graphics.drawable.Drawable; 240ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasaniimport android.os.Bundle; 2538e761051242b2129a30e482404e6f87ea9ad75aAmith Yamasaniimport android.os.UserHandle; 260ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasaniimport android.view.LayoutInflater; 270ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasaniimport android.view.View; 280ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasaniimport android.widget.ImageView; 290ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasaniimport android.widget.TextView; 300ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani 310ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasaniimport com.android.settings.R; 32247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasaniimport com.android.settings.Utils; 330ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani 340ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasaniimport java.util.List; 350ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani 36ee3987475e1d29e8355bdb9e068149eb01e3fd43Amith Yamasanipublic class RestrictedProfileSettings extends AppRestrictionsFragment 37ee3987475e1d29e8355bdb9e068149eb01e3fd43Amith Yamasani implements EditUserInfoController.OnContentChangedCallback { 380ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani 392ad96254628675a86de330263487abe39dc024bbAmith Yamasani public static final String FILE_PROVIDER_AUTHORITY = "com.android.settings.files"; 40247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani static final int DIALOG_ID_EDIT_USER_INFO = 1; 41247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani private static final int DIALOG_CONFIRM_REMOVE = 2; 420ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani 430ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani private View mHeaderView; 440ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani private ImageView mUserIconView; 450ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani private TextView mUserNameView; 46247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani private ImageView mDeleteButton; 470ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani 48ee3987475e1d29e8355bdb9e068149eb01e3fd43Amith Yamasani private EditUserInfoController mEditUserInfoController = 49ee3987475e1d29e8355bdb9e068149eb01e3fd43Amith Yamasani new EditUserInfoController(); 500ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani 510ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani @Override 520ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani public void onCreate(Bundle icicle) { 530ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani super.onCreate(icicle); 540ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani 550ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani if (icicle != null) { 56ee3987475e1d29e8355bdb9e068149eb01e3fd43Amith Yamasani mEditUserInfoController.onRestoreInstanceState(icicle); 570ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani } 580ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani 590ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani init(icicle); 600ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani } 610ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani 620ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani @Override 630ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani public void onActivityCreated(Bundle savedInstanceState) { 640ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani if (mHeaderView == null) { 650ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani mHeaderView = LayoutInflater.from(getActivity()).inflate( 660ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani R.layout.user_info_header, null); 6786159283c98fd862723ce317f1621bcb16d451ceFabrice Di Meglio setPinnedHeaderView(mHeaderView); 680ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani mHeaderView.setOnClickListener(this); 690ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani mUserIconView = (ImageView) mHeaderView.findViewById(android.R.id.icon); 700ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani mUserNameView = (TextView) mHeaderView.findViewById(android.R.id.title); 71247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani mDeleteButton = (ImageView) mHeaderView.findViewById(R.id.delete); 72247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani mDeleteButton.setOnClickListener(this); 7351c6dac50ea8874181036f54c3a7e7aa8eb800bdAmith Yamasani getListView().setFastScrollEnabled(true); 740ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani } 750ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani // This is going to bind the preferences. 760ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani super.onActivityCreated(savedInstanceState); 770ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani } 780ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani 790ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani @Override 800ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani public void onSaveInstanceState(Bundle outState) { 810ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani super.onSaveInstanceState(outState); 82ee3987475e1d29e8355bdb9e068149eb01e3fd43Amith Yamasani mEditUserInfoController.onSaveInstanceState(outState); 830ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani } 840ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani 850ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani @Override 860ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani public void onResume() { 870ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani super.onResume(); 880ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani 8938e761051242b2129a30e482404e6f87ea9ad75aAmith Yamasani // Check if user still exists 9045f86236e4d771f9d6c464f1e54be7fb813f4cebAmith Yamasani UserInfo info = Utils.getExistingUser(mUserManager, mUser); 9138e761051242b2129a30e482404e6f87ea9ad75aAmith Yamasani if (info == null) { 9238e761051242b2129a30e482404e6f87ea9ad75aAmith Yamasani finishFragment(); 9338e761051242b2129a30e482404e6f87ea9ad75aAmith Yamasani } else { 9438e761051242b2129a30e482404e6f87ea9ad75aAmith Yamasani ((TextView) mHeaderView.findViewById(android.R.id.title)).setText(info.name); 9538e761051242b2129a30e482404e6f87ea9ad75aAmith Yamasani ((ImageView) mHeaderView.findViewById(android.R.id.icon)).setImageDrawable( 9638e761051242b2129a30e482404e6f87ea9ad75aAmith Yamasani getCircularUserIcon()); 9738e761051242b2129a30e482404e6f87ea9ad75aAmith Yamasani } 9838e761051242b2129a30e482404e6f87ea9ad75aAmith Yamasani } 9938e761051242b2129a30e482404e6f87ea9ad75aAmith Yamasani 1000ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani @Override 1017f5f0bb2aead332d4c9c8e66c818480be9fa680bAmith Yamasani public void startActivityForResult(Intent intent, int requestCode) { 102ee3987475e1d29e8355bdb9e068149eb01e3fd43Amith Yamasani mEditUserInfoController.startingActivityForResult(); 1037f5f0bb2aead332d4c9c8e66c818480be9fa680bAmith Yamasani super.startActivityForResult(intent, requestCode); 1047f5f0bb2aead332d4c9c8e66c818480be9fa680bAmith Yamasani } 1057f5f0bb2aead332d4c9c8e66c818480be9fa680bAmith Yamasani 1067f5f0bb2aead332d4c9c8e66c818480be9fa680bAmith Yamasani @Override 1070ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani public void onActivityResult(int requestCode, int resultCode, Intent data) { 1080ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani super.onActivityResult(requestCode, resultCode, data); 1090ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani 110ee3987475e1d29e8355bdb9e068149eb01e3fd43Amith Yamasani mEditUserInfoController.onActivityResult(requestCode, resultCode, data); 1110ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani } 1120ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani 1130ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani @Override 1140ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani public void onClick(View view) { 1150ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani if (view == mHeaderView) { 1160ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani showDialog(DIALOG_ID_EDIT_USER_INFO); 117247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani } else if (view == mDeleteButton) { 118247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani showDialog(DIALOG_CONFIRM_REMOVE); 1190ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani } else { 1200ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani super.onClick(view); // in AppRestrictionsFragment 1210ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani } 1220ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani } 1230ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani 1240ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani @Override 1250ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani public Dialog onCreateDialog(int dialogId) { 1260ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani if (dialogId == DIALOG_ID_EDIT_USER_INFO) { 127ee3987475e1d29e8355bdb9e068149eb01e3fd43Amith Yamasani return mEditUserInfoController.createDialog(this, mUserIconView.getDrawable(), 128ee3987475e1d29e8355bdb9e068149eb01e3fd43Amith Yamasani mUserNameView.getText(), R.string.profile_info_settings_title, 129ee3987475e1d29e8355bdb9e068149eb01e3fd43Amith Yamasani this, mUser); 130247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani } else if (dialogId == DIALOG_CONFIRM_REMOVE) { 131247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani Dialog dlg = 132247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani Utils.createRemoveConfirmationDialog(getActivity(), mUser.getIdentifier(), 133247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani new DialogInterface.OnClickListener() { 134247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani public void onClick(DialogInterface dialog, int which) { 135247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani removeUser(); 136247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani } 137247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani } 138247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani ); 139247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani return dlg; 1400ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani } 1410ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani 1420ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani return null; 1430ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani } 1440ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani 145247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani private void removeUser() { 146247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani getView().post(new Runnable() { 147247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani public void run() { 148247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani mUserManager.removeUser(mUser.getIdentifier()); 149247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani finishFragment(); 150247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani } 151247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani }); 152247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani } 153247520c369370885a1c085e53ee679dce0fd55ceAmith Yamasani 154ee3987475e1d29e8355bdb9e068149eb01e3fd43Amith Yamasani @Override 155ee3987475e1d29e8355bdb9e068149eb01e3fd43Amith Yamasani public void onPhotoChanged(Drawable photo) { 156ee3987475e1d29e8355bdb9e068149eb01e3fd43Amith Yamasani mUserIconView.setImageDrawable(photo); 1570ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani } 1580ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani 159ee3987475e1d29e8355bdb9e068149eb01e3fd43Amith Yamasani @Override 160ee3987475e1d29e8355bdb9e068149eb01e3fd43Amith Yamasani public void onLabelChanged(CharSequence label) { 161ee3987475e1d29e8355bdb9e068149eb01e3fd43Amith Yamasani mUserNameView.setText(label); 1620ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani } 1630ca80fe4cdbfa2a9298ab332770eef9890798c60Amith Yamasani} 164