1 /* 2 * Copyright (C) 2018 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.car.settings.users; 18 19 import android.car.userlib.CarUserManagerHelper; 20 import android.content.Context; 21 import android.os.Bundle; 22 23 import androidx.annotation.VisibleForTesting; 24 import androidx.annotation.XmlRes; 25 26 import com.android.car.settings.R; 27 28 /** 29 * Shows details for a user with the ability to remove user and edit current user. 30 */ 31 public class UserDetailsFragment extends UserDetailsBaseFragment { 32 33 /** Creates instance of UserDetailsFragment. */ newInstance(int userId)34 public static UserDetailsFragment newInstance(int userId) { 35 return (UserDetailsFragment) UserDetailsBaseFragment.addUserIdToFragmentArguments( 36 new UserDetailsFragment(), userId); 37 } 38 39 @VisibleForTesting 40 final CarUserManagerHelper.OnUsersUpdateListener mOnUsersUpdateListener = () -> { 41 // Update the user info value, as it may have changed. 42 refreshUserInfo(); 43 // Update the text in the toolbar when there is a user update. 44 getToolbar().setTitle(getTitleText()); 45 }; 46 47 @Override 48 @XmlRes getPreferenceScreenResId()49 protected int getPreferenceScreenResId() { 50 return R.xml.user_details_fragment; 51 } 52 53 @Override onAttach(Context context)54 public void onAttach(Context context) { 55 super.onAttach(context); 56 use(EditUserNameEntryPreferenceController.class, 57 R.string.pk_edit_user_name_entry).setUserInfo(getUserInfo()); 58 } 59 60 @Override onCreate(Bundle savedInstanceState)61 public void onCreate(Bundle savedInstanceState) { 62 super.onCreate(savedInstanceState); 63 getCarUserManagerHelper().registerOnUsersUpdateListener(mOnUsersUpdateListener); 64 } 65 66 @Override onDestroy()67 public void onDestroy() { 68 super.onDestroy(); 69 getCarUserManagerHelper().unregisterOnUsersUpdateListener(mOnUsersUpdateListener); 70 } 71 72 @Override getTitleText()73 protected String getTitleText() { 74 return UserUtils.getUserDisplayName(getContext(), getCarUserManagerHelper(), getUserInfo()); 75 } 76 } 77