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; 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_OVERSCROLL = 1 << 9; 37 int TYPE_SYSUI_OVERLAY = 1 << 10; 38 39 String[] NAMES = new String[] { 40 "TYPE_NO_OP", // 0 41 "TYPE_OVERVIEW", // 1 42 "TYPE_OTHER_ACTIVITY", // 2 43 "TYPE_ASSISTANT", // 3 44 "TYPE_DEVICE_LOCKED", // 4 45 "TYPE_ACCESSIBILITY", // 5 46 "TYPE_SCREEN_PINNED", // 6 47 "TYPE_OVERVIEW_WITHOUT_FOCUS", // 7 48 "TYPE_RESET_GESTURE", // 8 49 "TYPE_OVERSCROLL", // 9 50 "TYPE_SYSUI_OVERLAY" // 10 51 }; 52 53 InputConsumer NO_OP = () -> TYPE_NO_OP; 54 getType()55 int getType(); 56 57 /** 58 * Returns true if the user has crossed the threshold for it to be an explicit action. 59 */ allowInterceptByParent()60 default boolean allowInterceptByParent() { 61 return true; 62 } 63 64 /** 65 * Returns true if the lifecycle of this input consumer is detached from the normal gesture 66 * down/up flow. If so, it is the responsibility of the input consumer to call back to 67 * {@link TouchInteractionService#onConsumerInactive(InputConsumer)} after the consumer is 68 * finished. 69 */ isConsumerDetachedFromGesture()70 default boolean isConsumerDetachedFromGesture() { 71 return false; 72 } 73 74 /** 75 * Handle and specific setup necessary based on the orientation of the device 76 */ notifyOrientationSetup()77 default void notifyOrientationSetup() {} 78 79 /** 80 * Returns the active input consumer is in the hierarchy of this input consumer. 81 */ getActiveConsumerInHierarchy()82 default InputConsumer getActiveConsumerInHierarchy() { 83 return this; 84 } 85 86 /** 87 * Called by the event queue when the consumer is about to be switched to a new consumer. 88 * Consumers should update the state accordingly here before the state is passed to the new 89 * consumer. 90 */ onConsumerAboutToBeSwitched()91 default void onConsumerAboutToBeSwitched() { } 92 onMotionEvent(MotionEvent ev)93 default void onMotionEvent(MotionEvent ev) { } 94 onKeyEvent(KeyEvent ev)95 default void onKeyEvent(KeyEvent ev) { } 96 onInputEvent(InputEvent ev)97 default void onInputEvent(InputEvent ev) { 98 if (ev instanceof MotionEvent) { 99 onMotionEvent((MotionEvent) ev); 100 } else { 101 onKeyEvent((KeyEvent) ev); 102 } 103 } 104 getName()105 default String getName() { 106 StringBuilder name = new StringBuilder(); 107 for (int i = 0; i < NAMES.length; i++) { 108 if ((getType() & (1 << i)) != 0) { 109 if (name.length() > 0) { 110 name.append(":"); 111 } 112 name.append(NAMES[i]); 113 } 114 } 115 return name.toString(); 116 } 117 } 118