summaryrefslogtreecommitdiff
path: root/core/java/android/inputmethodservice/InputMethodService.java
diff options
context:
space:
mode:
authorTaran Singh <tarandeep@google.com>2021-11-24 01:59:29 +0000
committerTaran Singh <tarandeep@google.com>2022-01-26 15:41:24 +0000
commit52f330491b861720250710d74aada3d0c23bf9a2 (patch)
treed617ea941f36081727c58b9885fbfbce58d4435d /core/java/android/inputmethodservice/InputMethodService.java
parent490be11e8b111e4d74ac54749b179a654020828e (diff)
Scribe in IMF: Stylus Spy windows Impl 5/N
Implement Handwriting surface spy in IMF that listens and manages Stylus events. Test: atest StylusHandwritingTest Bug: 210039666 Bug: 203086136 Change-Id: I8681a33bb32f20b48cf741ba3ad2116de5db7ffa
Diffstat (limited to 'core/java/android/inputmethodservice/InputMethodService.java')
-rw-r--r--core/java/android/inputmethodservice/InputMethodService.java47
1 files changed, 38 insertions, 9 deletions
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java
index 5d2d8eafb3a8..80da3617d4a4 100644
--- a/core/java/android/inputmethodservice/InputMethodService.java
+++ b/core/java/android/inputmethodservice/InputMethodService.java
@@ -82,6 +82,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
+import android.os.Looper;
import android.os.ResultReceiver;
import android.os.SystemClock;
import android.os.SystemProperties;
@@ -95,8 +96,11 @@ import android.util.Log;
import android.util.PrintWriterPrinter;
import android.util.Printer;
import android.util.proto.ProtoOutputStream;
+import android.view.BatchedInputEventReceiver.SimpleBatchedInputEventReceiver;
+import android.view.Choreographer;
import android.view.Gravity;
import android.view.InputChannel;
+import android.view.InputEventReceiver;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@@ -148,6 +152,7 @@ import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
+import java.util.OptionalInt;
/**
* InputMethodService provides a standard implementation of an InputMethod,
@@ -567,7 +572,8 @@ public class InputMethodService extends AbstractInputMethodService {
private boolean mAutomotiveHideNavBarForKeyboard;
private boolean mIsAutomotive;
- private boolean mHandwritingStarted;
+ private @NonNull OptionalInt mHandwritingRequestId = OptionalInt.empty();
+ private InputEventReceiver mHandwritingEventReceiver;
private Handler mHandler;
private boolean mImeSurfaceScheduledForRemoval;
private ImsConfigurationTracker mConfigTracker = new ImsConfigurationTracker();
@@ -888,7 +894,7 @@ public class InputMethodService extends AbstractInputMethodService {
@Override
public void canStartStylusHandwriting(int requestId) {
if (DEBUG) Log.v(TAG, "canStartStylusHandwriting()");
- if (mHandwritingStarted) {
+ if (mHandwritingRequestId.isPresent()) {
Log.d(TAG, "There is an ongoing Handwriting session. ignoring.");
return;
}
@@ -900,6 +906,7 @@ public class InputMethodService extends AbstractInputMethodService {
mPrivOps.onStylusHandwritingReady(requestId);
} else {
Log.i(TAG, "IME is not ready. Can't start Stylus Handwriting");
+ // TODO(b/210039666): see if it's valuable to propagate this back to IMM.
}
}
@@ -910,20 +917,36 @@ public class InputMethodService extends AbstractInputMethodService {
@MainThread
@Override
public void startStylusHandwriting(
- @NonNull InputChannel channel, @Nullable List<MotionEvent> stylusEvents) {
+ int requestId, @NonNull InputChannel channel,
+ @NonNull List<MotionEvent> stylusEvents) {
if (DEBUG) Log.v(TAG, "startStylusHandwriting()");
- if (mHandwritingStarted) {
+ Objects.requireNonNull(channel);
+ Objects.requireNonNull(stylusEvents);
+
+ if (mHandwritingRequestId.isPresent()) {
return;
}
- mHandwritingStarted = true;
+ mHandwritingRequestId = OptionalInt.of(requestId);
mShowInputRequested = false;
mInkWindow.show();
- // TODO: deliver previous @param stylusEvents
- // TODO: create spy receiver for @param channel
+
+ // deliver previous @param stylusEvents
+ stylusEvents.forEach(mInkWindow.getDecorView()::dispatchTouchEvent);
+ // create receiver for channel
+ mHandwritingEventReceiver = new SimpleBatchedInputEventReceiver(
+ channel,
+ Looper.getMainLooper(), Choreographer.getInstance(),
+ event -> {
+ if (!(event instanceof MotionEvent)) {
+ return false;
+ }
+ return mInkWindow.getDecorView().dispatchTouchEvent((MotionEvent) event);
+ });
}
+
/**
* {@inheritDoc}
*/
@@ -2358,12 +2381,18 @@ public class InputMethodService extends AbstractInputMethodService {
if (mInkWindow == null) {
return;
}
- if (!mHandwritingStarted) {
+ if (!mHandwritingRequestId.isPresent()) {
return;
}
- mHandwritingStarted = false;
+ final int requestId = mHandwritingRequestId.getAsInt();
+ mHandwritingRequestId = OptionalInt.empty();
+
+ mHandwritingEventReceiver.dispose();
+ mHandwritingEventReceiver = null;
mInkWindow.hide(false /* remove */);
+
+ mPrivOps.finishStylusHandwriting(requestId);
onFinishStylusHandwriting();
}