blob: bf18bdd5b174559916cb1bec7ee51df1461c5a1b [file] [log] [blame]
Aarthi Balachander71096762018-05-21 18:22:23 -07001/*
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
17package com.android.car.settings.users;
18
19import android.car.drivingstate.CarUxRestrictions;
20import android.os.Bundle;
Lujiang Xue8937ba52018-06-06 10:36:17 -070021
davidlncb0bfa22018-08-27 14:13:05 -070022import androidx.annotation.LayoutRes;
23import androidx.annotation.StringRes;
Lujiang Xue8937ba52018-06-06 10:36:17 -070024import androidx.recyclerview.widget.GridLayoutManager;
Aarthi Balachander71096762018-05-21 18:22:23 -070025
26import com.android.car.settings.R;
27import com.android.car.settings.common.BaseFragment;
Aarthi Balachanderb88fd9b2018-05-30 16:25:16 -070028import com.android.car.settings.common.CarUxRestrictionsHelper;
Aarthi Balachander71096762018-05-21 18:22:23 -070029
30/**
31 * Shows a user switcher for all Users available on this device.
32 */
33public class UserSwitcherFragment extends BaseFragment {
34
Aarthi Balachanderb88fd9b2018-05-30 16:25:16 -070035 private UserGridRecyclerView mUserGridView;
36
davidlncb0bfa22018-08-27 14:13:05 -070037 @Override
38 @LayoutRes
39 protected int getActionBarLayoutId() {
40 return R.layout.action_bar_with_button;
41 }
42
43 @Override
44 @LayoutRes
45 protected int getLayoutId() {
davidln14aa5072019-01-03 11:27:16 -080046 return R.layout.user_switcher;
davidlncb0bfa22018-08-27 14:13:05 -070047 }
48
49 @Override
50 @StringRes
51 protected int getTitleId() {
52 return R.string.users_list_title;
Aarthi Balachander71096762018-05-21 18:22:23 -070053 }
54
55 @Override
56 public void onActivityCreated(Bundle savedInstanceState) {
57 super.onActivityCreated(savedInstanceState);
58
Aarthi Balachanderb88fd9b2018-05-30 16:25:16 -070059 mUserGridView = getView().findViewById(R.id.user_grid);
Aarthi Balachander71096762018-05-21 18:22:23 -070060 GridLayoutManager layoutManager = new GridLayoutManager(getContext(),
61 getContext().getResources().getInteger(R.integer.user_switcher_num_col));
62 mUserGridView.setFragment(this);
davidlnf1494d82019-03-08 16:35:55 -080063 mUserGridView.setLayoutManager(layoutManager);
Aarthi Balachander71096762018-05-21 18:22:23 -070064 mUserGridView.buildAdapter();
65 }
66
67 @Override
68 public void onDestroy() {
69 super.onDestroy();
70 }
71
72 /**
73 * User switcher fragment is distraction optimized, so is allowed at all times.
74 */
75 @Override
76 public boolean canBeShown(CarUxRestrictions carUxRestrictions) {
77 return true;
78 }
79
Aarthi Balachanderb88fd9b2018-05-30 16:25:16 -070080
81 @Override
davidlnf9757292018-09-17 09:52:47 -070082 public void onUxRestrictionsChanged(CarUxRestrictions restrictionInfo) {
83 applyRestriction(CarUxRestrictionsHelper.isNoSetup(restrictionInfo));
Aarthi Balachanderb88fd9b2018-05-30 16:25:16 -070084 }
85
86 private void applyRestriction(boolean restricted) {
87 if (mUserGridView != null) {
88 if (restricted) {
Lujiang Xue8601fa32018-05-31 13:59:08 -070089 mUserGridView.disableAddUser();
Aarthi Balachanderb88fd9b2018-05-30 16:25:16 -070090 } else {
Lujiang Xue8601fa32018-05-31 13:59:08 -070091 mUserGridView.enableAddUser();
Aarthi Balachanderb88fd9b2018-05-30 16:25:16 -070092 }
93 }
94 }
95
Aarthi Balachander71096762018-05-21 18:22:23 -070096}