• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.systemui.car.userswitcher;
18 
19 import com.android.systemui.car.keyguard.CarKeyguardViewController;
20 import com.android.systemui.car.window.OverlayViewMediator;
21 import com.android.systemui.dagger.SysUISingleton;
22 import com.android.systemui.plugins.statusbar.StatusBarStateController;
23 
24 import javax.inject.Inject;
25 
26 /**
27  * Manages the fullscreen user switcher and it's interactions with the keyguard.
28  */
29 @SysUISingleton
30 public class FullscreenUserSwitcherViewMediator implements OverlayViewMediator {
31     private static final String TAG = FullscreenUserSwitcherViewMediator.class.getSimpleName();
32 
33     private final StatusBarStateController mStatusBarStateController;
34     private final FullScreenUserSwitcherViewController mFullScreenUserSwitcherViewController;
35     private final CarKeyguardViewController mCarKeyguardViewController;
36     private final UserSwitchTransitionViewController mUserSwitchTransitionViewController;
37 
38     @Inject
FullscreenUserSwitcherViewMediator( StatusBarStateController statusBarStateController, CarKeyguardViewController carKeyguardViewController, UserSwitchTransitionViewController userSwitchTransitionViewController, FullScreenUserSwitcherViewController fullScreenUserSwitcherViewController)39     public FullscreenUserSwitcherViewMediator(
40             StatusBarStateController statusBarStateController,
41             CarKeyguardViewController carKeyguardViewController,
42             UserSwitchTransitionViewController userSwitchTransitionViewController,
43             FullScreenUserSwitcherViewController fullScreenUserSwitcherViewController) {
44 
45         mStatusBarStateController = statusBarStateController;
46         mCarKeyguardViewController = carKeyguardViewController;
47         mUserSwitchTransitionViewController = userSwitchTransitionViewController;
48         mFullScreenUserSwitcherViewController = fullScreenUserSwitcherViewController;
49     }
50 
51     @Override
registerListeners()52     public void registerListeners() {
53         registerUserSwitcherHideListeners();
54     }
55 
registerUserSwitcherHideListeners()56     private void registerUserSwitcherHideListeners() {
57         mStatusBarStateController.addCallback(new StatusBarStateController.StateListener() {
58             @Override
59             public void onStateChanged(int newState) {
60                 hide();
61             }
62         });
63     }
64 
65     @Override
setUpOverlayContentViewControllers()66     public void setUpOverlayContentViewControllers() {
67         mFullScreenUserSwitcherViewController.setUserGridSelectionListener(this::onUserSelected);
68     }
69 
70     /**
71      * Every time user clicks on an item in the switcher, we hide the switcher.
72      */
onUserSelected(UserGridRecyclerView.UserRecord record)73     private void onUserSelected(UserGridRecyclerView.UserRecord record) {
74         if (record.mType != UserGridRecyclerView.UserRecord.FOREGROUND_USER) {
75             mCarKeyguardViewController.hideKeyguardToPrepareBouncer();
76             // If guest user, we cannot use record.mInfo.id and should listen to the User lifecycle
77             // event instead.
78             if (record.mType != UserGridRecyclerView.UserRecord.START_GUEST) {
79                 mUserSwitchTransitionViewController.handleShow(record.mInfo.id);
80             }
81         }
82 
83         hide();
84     }
85 
hide()86     private void hide() {
87         mFullScreenUserSwitcherViewController.stop();
88     }
89 
show()90     private void show() {
91         mFullScreenUserSwitcherViewController.start();
92     }
93 }
94