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.navigationbar;
18 
19 import static android.view.MotionEvent.ACTION_OUTSIDE;
20 
21 import android.annotation.AttrRes;
22 import android.annotation.NonNull;
23 import android.annotation.Nullable;
24 import android.content.Context;
25 import android.util.AttributeSet;
26 import android.view.MotionEvent;
27 import android.widget.FrameLayout;
28 
29 import com.android.systemui.navigationbar.buttons.DeadZone;
30 
31 public class NavigationBarFrame extends FrameLayout {
32 
33     private DeadZone mDeadZone = null;
34 
NavigationBarFrame(@onNull Context context)35     public NavigationBarFrame(@NonNull Context context) {
36         super(context);
37     }
38 
NavigationBarFrame(Context context, AttributeSet attrs)39     public NavigationBarFrame(Context context, AttributeSet attrs) {
40         super(context, attrs);
41     }
42 
NavigationBarFrame(@onNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr)43     public NavigationBarFrame(@NonNull Context context, @Nullable AttributeSet attrs,
44             @AttrRes int defStyleAttr) {
45         super(context, attrs, defStyleAttr);
46     }
47 
setDeadZone(@onNull DeadZone deadZone)48     public void setDeadZone(@NonNull DeadZone deadZone) {
49         mDeadZone = deadZone;
50     }
51 
52     @Override
dispatchTouchEvent(MotionEvent event)53     public boolean dispatchTouchEvent(MotionEvent event) {
54         if (event.getAction() == ACTION_OUTSIDE) {
55             if (mDeadZone != null) {
56                 return mDeadZone.onTouchEvent(event);
57             }
58         }
59         return super.dispatchTouchEvent(event);
60     }
61 }