1 /* 2 * Copyright (C) 2021 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 static com.android.car.settings.common.TopLevelMenuFragment.FRAGMENT_MENU_PREFERENCE_KEY; 20 21 import android.car.drivingstate.CarUxRestrictions; 22 import android.content.Context; 23 import android.os.Bundle; 24 import android.os.UserHandle; 25 26 import androidx.fragment.app.Fragment; 27 import androidx.preference.Preference; 28 29 import com.android.car.settings.common.FragmentController; 30 import com.android.car.settings.common.Logger; 31 import com.android.car.settings.common.PreferenceController; 32 33 /** 34 * Controller for the top-level entry into Profile settings that open to the user's profile details 35 * page. 36 */ 37 public class ProfilesEntryPreferenceController extends PreferenceController<Preference> { 38 39 private static final Logger LOG = new Logger(ProfilesEntryPreferenceController.class); 40 ProfilesEntryPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)41 public ProfilesEntryPreferenceController(Context context, String preferenceKey, 42 FragmentController fragmentController, CarUxRestrictions uxRestrictions) { 43 super(context, preferenceKey, fragmentController, uxRestrictions); 44 } 45 46 @Override getPreferenceType()47 protected Class<Preference> getPreferenceType() { 48 return Preference.class; 49 } 50 51 @Override handlePreferenceClicked(Preference preference)52 public boolean handlePreferenceClicked(Preference preference) { 53 Fragment fragment = ProfileDetailsFragment.newInstance(UserHandle.myUserId()); 54 55 Bundle args = fragment.getArguments(); 56 if (args == null) { 57 args = new Bundle(); 58 fragment.setArguments(args); 59 } 60 args.putString(FRAGMENT_MENU_PREFERENCE_KEY, getPreferenceKey()); 61 getFragmentController().launchFragment(fragment); 62 return true; 63 } 64 } 65