• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.systemui.car.userswitcher;
18 
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import android.view.KeyEvent;
22 import android.widget.LinearLayout;
23 
24 import androidx.annotation.NonNull;
25 import androidx.annotation.Nullable;
26 
27 /** Container for the user switcher which intercepts the key events. */
28 public class UserSwitcherContainer extends LinearLayout {
29 
30     private KeyEventHandler mKeyEventHandler;
31 
UserSwitcherContainer(@onNull Context context)32     public UserSwitcherContainer(@NonNull Context context) {
33         super(context);
34     }
35 
UserSwitcherContainer(@onNull Context context, @Nullable AttributeSet attrs)36     public UserSwitcherContainer(@NonNull Context context, @Nullable AttributeSet attrs) {
37         super(context, attrs);
38     }
39 
UserSwitcherContainer(@onNull Context context, @Nullable AttributeSet attrs, int defStyleAttr)40     public UserSwitcherContainer(@NonNull Context context, @Nullable AttributeSet attrs,
41             int defStyleAttr) {
42         super(context, attrs, defStyleAttr);
43     }
44 
UserSwitcherContainer(@onNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes)45     public UserSwitcherContainer(@NonNull Context context, @Nullable AttributeSet attrs,
46             int defStyleAttr, int defStyleRes) {
47         super(context, attrs, defStyleAttr, defStyleRes);
48     }
49 
50     @Override
dispatchKeyEvent(KeyEvent event)51     public boolean dispatchKeyEvent(KeyEvent event) {
52         if (super.dispatchKeyEvent(event)) {
53             return true;
54         }
55 
56         if (mKeyEventHandler != null) {
57             return mKeyEventHandler.dispatchKeyEvent(event);
58         }
59 
60         return false;
61     }
62 
63     /** Sets a {@link KeyEventHandler} to help interact with the notification panel. */
setKeyEventHandler(KeyEventHandler keyEventHandler)64     public void setKeyEventHandler(KeyEventHandler keyEventHandler) {
65         mKeyEventHandler = keyEventHandler;
66     }
67 
68     /** An interface to help interact with the notification panel. */
69     public interface KeyEventHandler {
70         /** Allows handling of a {@link KeyEvent} if it wasn't already handled by the superclass. */
dispatchKeyEvent(KeyEvent event)71         boolean dispatchKeyEvent(KeyEvent event);
72     }
73 }
74