• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.car.drivingstate.CarUxRestrictions;
20 import android.os.Bundle;
21 
22 import androidx.annotation.LayoutRes;
23 import androidx.annotation.StringRes;
24 import androidx.recyclerview.widget.GridLayoutManager;
25 
26 import com.android.car.settings.R;
27 import com.android.car.settings.common.BaseFragment;
28 import com.android.car.settings.common.CarUxRestrictionsHelper;
29 
30 /**
31  * Shows a profile switcher for all profiles available on this device.
32  */
33 public class ProfileSwitcherFragment extends BaseFragment {
34 
35     private ProfileGridRecyclerView mProfileGridView;
36 
37     @Override
38     @LayoutRes
getLayoutId()39     protected int getLayoutId() {
40         return R.layout.profile_switcher;
41     }
42 
43     @Override
44     @StringRes
getTitleId()45     protected int getTitleId() {
46         return R.string.profiles_list_title;
47     }
48 
49     @Override
onActivityCreated(Bundle savedInstanceState)50     public void onActivityCreated(Bundle savedInstanceState) {
51         super.onActivityCreated(savedInstanceState);
52 
53         mProfileGridView = getView().findViewById(R.id.profile_grid);
54         GridLayoutManager layoutManager = new GridLayoutManager(getContext(),
55                 getContext().getResources().getInteger(R.integer.user_switcher_num_col));
56         mProfileGridView.setFragment(this);
57         mProfileGridView.setLayoutManager(layoutManager);
58         mProfileGridView.buildAdapter();
59     }
60 
61     @Override
onDestroy()62     public void onDestroy() {
63         super.onDestroy();
64     }
65 
66     /**
67      * Profile switcher fragment is distraction optimized, so is allowed at all times.
68      */
69     @Override
canBeShown(CarUxRestrictions carUxRestrictions)70     public boolean canBeShown(CarUxRestrictions carUxRestrictions) {
71         return true;
72     }
73 
74 
75     @Override
onUxRestrictionsChanged(CarUxRestrictions restrictionInfo)76     public void onUxRestrictionsChanged(CarUxRestrictions restrictionInfo) {
77         applyRestriction(CarUxRestrictionsHelper.isNoSetup(restrictionInfo));
78     }
79 
applyRestriction(boolean restricted)80     private void applyRestriction(boolean restricted) {
81         if (mProfileGridView != null) {
82             if (restricted) {
83                 mProfileGridView.disableAddProfile();
84             } else {
85                 mProfileGridView.enableAddProfile();
86             }
87         }
88     }
89 }
90