• 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 package com.android.quickstep.inputconsumers;
17 
18 import android.annotation.TargetApi;
19 import android.os.Build;
20 import android.view.InputEvent;
21 import android.view.KeyEvent;
22 import android.view.MotionEvent;
23 
24 @TargetApi(Build.VERSION_CODES.O)
25 public interface InputConsumer {
26 
27     int TYPE_NO_OP = 1 << 0;
28     int TYPE_OVERVIEW = 1 << 1;
29     int TYPE_OTHER_ACTIVITY = 1 << 2;
30     int TYPE_ASSISTANT = 1 << 3;
31     int TYPE_DEVICE_LOCKED = 1 << 4;
32     int TYPE_ACCESSIBILITY = 1 << 5;
33     int TYPE_SCREEN_PINNED = 1 << 6;
34     int TYPE_OVERVIEW_WITHOUT_FOCUS = 1 << 7;
35     int TYPE_RESET_GESTURE = 1 << 8;
36     int TYPE_FALLBACK_NO_BUTTON = 1 << 9;
37 
38     String[] NAMES = new String[] {
39            "TYPE_NO_OP",                    // 0
40             "TYPE_OVERVIEW",                // 1
41             "TYPE_OTHER_ACTIVITY",          // 2
42             "TYPE_ASSISTANT",               // 3
43             "TYPE_DEVICE_LOCKED",           // 4
44             "TYPE_ACCESSIBILITY",           // 5
45             "TYPE_SCREEN_PINNED",           // 6
46             "TYPE_OVERVIEW_WITHOUT_FOCUS",  // 7
47             "TYPE_RESET_GESTURE",           // 8
48             "TYPE_FALLBACK_NO_BUTTON",      // 9
49     };
50 
51     InputConsumer NO_OP = () -> TYPE_NO_OP;
52 
getType()53     int getType();
54 
useSharedSwipeState()55     default boolean useSharedSwipeState() {
56         return false;
57     }
58 
59     /**
60      * Returns true if the user has crossed the threshold for it to be an explicit action.
61      */
allowInterceptByParent()62     default boolean allowInterceptByParent() {
63         return true;
64     }
65 
66     /**
67      * Called by the event queue when the consumer is about to be switched to a new consumer.
68      */
onConsumerAboutToBeSwitched()69     default void onConsumerAboutToBeSwitched() { }
70 
onMotionEvent(MotionEvent ev)71     default void onMotionEvent(MotionEvent ev) { }
72 
onKeyEvent(KeyEvent ev)73     default void onKeyEvent(KeyEvent ev) { }
74 
onInputEvent(InputEvent ev)75     default void onInputEvent(InputEvent ev) {
76         if (ev instanceof MotionEvent) {
77             onMotionEvent((MotionEvent) ev);
78         } else {
79             onKeyEvent((KeyEvent) ev);
80         }
81     }
82 
getName()83     default String getName() {
84         String name = "";
85         for (int i = 0; i < NAMES.length; i++) {
86             if ((getType() & (1 << i)) != 0) {
87                 if (name.length() > 0) {
88                     name += ":";
89                 }
90                 name += NAMES[i];
91             }
92         }
93         return name;
94     }
95 }
96