1 /* 2 * Copyright (C) 2013 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.users; 18 19 import android.app.Dialog; 20 import android.content.DialogInterface; 21 import android.content.Intent; 22 import android.content.pm.UserInfo; 23 import android.graphics.drawable.Drawable; 24 import android.os.Bundle; 25 import android.view.View; 26 import android.view.ViewGroup; 27 import android.widget.ImageView; 28 import android.widget.TextView; 29 30 import com.android.settings.R; 31 import com.android.settings.Utils; 32 33 public class RestrictedProfileSettings extends AppRestrictionsFragment 34 implements EditUserInfoController.OnContentChangedCallback { 35 36 public static final String FILE_PROVIDER_AUTHORITY = "com.android.settings.files"; 37 static final int DIALOG_ID_EDIT_USER_INFO = 1; 38 private static final int DIALOG_CONFIRM_REMOVE = 2; 39 40 private View mHeaderView; 41 private ImageView mUserIconView; 42 private TextView mUserNameView; 43 private ImageView mDeleteButton; 44 45 private EditUserInfoController mEditUserInfoController = 46 new EditUserInfoController(); 47 48 @Override onCreate(Bundle icicle)49 public void onCreate(Bundle icicle) { 50 super.onCreate(icicle); 51 52 if (icicle != null) { 53 mEditUserInfoController.onRestoreInstanceState(icicle); 54 } 55 56 init(icicle); 57 } 58 59 @Override onActivityCreated(Bundle savedInstanceState)60 public void onActivityCreated(Bundle savedInstanceState) { 61 mHeaderView = setPinnedHeaderView(R.layout.user_info_header); 62 mHeaderView.setOnClickListener(this); 63 mUserIconView = (ImageView) mHeaderView.findViewById(android.R.id.icon); 64 mUserNameView = (TextView) mHeaderView.findViewById(android.R.id.title); 65 mDeleteButton = (ImageView) mHeaderView.findViewById(R.id.delete); 66 mDeleteButton.setOnClickListener(this); 67 getListView().setFastScrollEnabled(true); 68 // This is going to bind the preferences. 69 super.onActivityCreated(savedInstanceState); 70 } 71 72 @Override onSaveInstanceState(Bundle outState)73 public void onSaveInstanceState(Bundle outState) { 74 super.onSaveInstanceState(outState); 75 mEditUserInfoController.onSaveInstanceState(outState); 76 } 77 78 @Override onResume()79 public void onResume() { 80 super.onResume(); 81 82 // Check if user still exists 83 UserInfo info = Utils.getExistingUser(mUserManager, mUser); 84 if (info == null) { 85 finishFragment(); 86 } else { 87 ((TextView) mHeaderView.findViewById(android.R.id.title)).setText(info.name); 88 ((ImageView) mHeaderView.findViewById(android.R.id.icon)).setImageDrawable( 89 Utils.getUserIcon(getActivity(), mUserManager, info)); 90 } 91 } 92 93 @Override startActivityForResult(Intent intent, int requestCode)94 public void startActivityForResult(Intent intent, int requestCode) { 95 mEditUserInfoController.startingActivityForResult(); 96 super.startActivityForResult(intent, requestCode); 97 } 98 99 @Override onActivityResult(int requestCode, int resultCode, Intent data)100 public void onActivityResult(int requestCode, int resultCode, Intent data) { 101 super.onActivityResult(requestCode, resultCode, data); 102 103 mEditUserInfoController.onActivityResult(requestCode, resultCode, data); 104 } 105 106 @Override onClick(View view)107 public void onClick(View view) { 108 if (view == mHeaderView) { 109 showDialog(DIALOG_ID_EDIT_USER_INFO); 110 } else if (view == mDeleteButton) { 111 showDialog(DIALOG_CONFIRM_REMOVE); 112 } else { 113 super.onClick(view); // in AppRestrictionsFragment 114 } 115 } 116 117 @Override onCreateDialog(int dialogId)118 public Dialog onCreateDialog(int dialogId) { 119 if (dialogId == DIALOG_ID_EDIT_USER_INFO) { 120 return mEditUserInfoController.createDialog(this, mUserIconView.getDrawable(), 121 mUserNameView.getText(), R.string.profile_info_settings_title, 122 this, mUser); 123 } else if (dialogId == DIALOG_CONFIRM_REMOVE) { 124 Dialog dlg = 125 UserDialogs.createRemoveDialog(getActivity(), mUser.getIdentifier(), 126 new DialogInterface.OnClickListener() { 127 public void onClick(DialogInterface dialog, int which) { 128 removeUser(); 129 } 130 } 131 ); 132 return dlg; 133 } 134 135 return null; 136 } 137 removeUser()138 private void removeUser() { 139 getView().post(new Runnable() { 140 public void run() { 141 mUserManager.removeUser(mUser.getIdentifier()); 142 finishFragment(); 143 } 144 }); 145 } 146 147 @Override onPhotoChanged(Drawable photo)148 public void onPhotoChanged(Drawable photo) { 149 mUserIconView.setImageDrawable(photo); 150 } 151 152 @Override onLabelChanged(CharSequence label)153 public void onLabelChanged(CharSequence label) { 154 mUserNameView.setText(label); 155 } 156 } 157