Merge "SyncPointerCapture (4/n): Receive capture events in InputEventReceiver"

This commit is contained in:
TreeHugger Robot
2020-11-20 04:35:02 +00:00
committed by Android (Google) Code Review
2 changed files with 31 additions and 0 deletions

View File

@@ -143,6 +143,20 @@ public abstract class InputEventReceiver {
public void onFocusEvent(boolean hasFocus, boolean inTouchMode) {
}
/**
* Called when a Pointer Capture event is received.
*
* @param pointerCaptureEnabled if true, the window associated with this input channel has just
* received Pointer Capture
* if false, the window associated with this input channel has just
* lost Pointer Capture
* @see View#requestPointerCapture()
* @see View#releasePointerCapture()
*/
// Called from native code.
public void onPointerCaptureEvent(boolean pointerCaptureEnabled) {
}
/**
* Called when a batched input event is pending.
*

View File

@@ -50,6 +50,7 @@ static struct {
jmethodID dispatchInputEvent;
jmethodID onFocusEvent;
jmethodID onPointerCaptureEvent;
jmethodID onBatchedInputEventPending;
} gInputEventReceiverClassInfo;
@@ -345,6 +346,19 @@ status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env,
finishInputEvent(seq, true /* handled */);
continue;
}
case AINPUT_EVENT_TYPE_CAPTURE: {
const CaptureEvent* captureEvent = static_cast<CaptureEvent*>(inputEvent);
if (kDebugDispatchCycle) {
ALOGD("channel '%s' ~ Received capture event: pointerCaptureEnabled=%s",
getInputChannelName().c_str(),
toString(captureEvent->getPointerCaptureEnabled()));
}
env->CallVoidMethod(receiverObj.get(),
gInputEventReceiverClassInfo.onPointerCaptureEvent,
jboolean(captureEvent->getPointerCaptureEnabled()));
finishInputEvent(seq, true /* handled */);
continue;
}
default:
assert(false); // InputConsumer should prevent this from ever happening
@@ -489,6 +503,9 @@ int register_android_view_InputEventReceiver(JNIEnv* env) {
"dispatchInputEvent", "(ILandroid/view/InputEvent;)V");
gInputEventReceiverClassInfo.onFocusEvent =
GetMethodIDOrDie(env, gInputEventReceiverClassInfo.clazz, "onFocusEvent", "(ZZ)V");
gInputEventReceiverClassInfo.onPointerCaptureEvent =
GetMethodIDOrDie(env, gInputEventReceiverClassInfo.clazz, "onPointerCaptureEvent",
"(Z)V");
gInputEventReceiverClassInfo.onBatchedInputEventPending =
GetMethodIDOrDie(env, gInputEventReceiverClassInfo.clazz, "onBatchedInputEventPending",
"(I)V");