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.profiles; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.content.pm.UserInfo; 22 import android.os.Bundle; 23 24 import androidx.annotation.NonNull; 25 26 import com.android.car.settings.common.SettingsFragment; 27 import com.android.car.ui.toolbar.ToolbarController; 28 29 /** Common logic shared for controlling the action bar which contains a button to delete a 30 * profile. 31 */ 32 public abstract class ProfileDetailsBaseFragment extends SettingsFragment { 33 private UserInfo mUserInfo; 34 35 /** Adds user id to fragment arguments. */ addUserIdToFragmentArguments( ProfileDetailsBaseFragment fragment, int userId)36 protected static ProfileDetailsBaseFragment addUserIdToFragmentArguments( 37 ProfileDetailsBaseFragment fragment, int userId) { 38 Bundle bundle = new Bundle(); 39 bundle.putInt(Intent.EXTRA_USER_ID, userId); 40 fragment.setArguments(bundle); 41 return fragment; 42 } 43 44 @Override onAttach(Context context)45 public void onAttach(Context context) { 46 super.onAttach(context); 47 int userId = getArguments().getInt(Intent.EXTRA_USER_ID); 48 mUserInfo = ProfileUtils.getUserInfo(getContext(), userId); 49 } 50 51 @Override setupToolbar(@onNull ToolbarController toolbar)52 protected void setupToolbar(@NonNull ToolbarController toolbar) { 53 super.setupToolbar(toolbar); 54 55 toolbar.setTitle(getTitleText()); 56 } 57 58 /** Make UserInfo available to subclasses. */ getUserInfo()59 protected UserInfo getUserInfo() { 60 return mUserInfo; 61 } 62 63 /** Refresh UserInfo in case it becomes invalid. */ refreshUserInfo()64 protected void refreshUserInfo() { 65 mUserInfo = ProfileUtils.getUserInfo(getContext(), mUserInfo.id); 66 } 67 68 /** Defines the text that should be shown in the action bar. */ getTitleText()69 protected abstract String getTitleText(); 70 } 71