Merge "Handle non-initalized InkWindow"

This commit is contained in:
Taran Singh
2022-09-29 23:58:30 +00:00
committed by Android (Google) Code Review
2 changed files with 21 additions and 13 deletions

View File

@@ -163,6 +163,9 @@ final class InkWindow extends PhoneWindow {
mGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (mInkView == null) {
return;
}
if (mInkView.isVisibleToUser()) {
if (mInkViewVisibilityListener != null) {
mInkViewVisibilityListener.onInkViewVisible();

View File

@@ -977,7 +977,7 @@ public class InputMethodService extends AbstractInputMethodService {
Log.d(TAG, "Input should have started before starting Stylus handwriting.");
return;
}
maybeCreateInkWindow();
maybeCreateAndInitInkWindow();
if (!mOnPreparedStylusHwCalled) {
// prepare hasn't been called by Stylus HOVER.
onPrepareStylusHandwriting();
@@ -1037,21 +1037,21 @@ public class InputMethodService extends AbstractInputMethodService {
*/
@Override
public void initInkWindow() {
maybeCreateInkWindow();
mInkWindow.initOnly();
maybeCreateAndInitInkWindow();
onPrepareStylusHandwriting();
mOnPreparedStylusHwCalled = true;
}
/**
* Create and attach token to Ink window if it wasn't already created.
* Create, attach token and layout Ink window if it wasn't already created.
*/
private void maybeCreateInkWindow() {
private void maybeCreateAndInitInkWindow() {
if (mInkWindow == null) {
mInkWindow = new InkWindow(mWindow.getContext());
mInkWindow.setToken(mToken);
}
// TODO(b/243571274): set an idle-timeout after which InkWindow is removed.
mInkWindow.initOnly();
}
/**
@@ -2487,21 +2487,26 @@ public class InputMethodService extends AbstractInputMethodService {
* @param motionEvent {@link MotionEvent} from stylus.
*/
public void onStylusHandwritingMotionEvent(@NonNull MotionEvent motionEvent) {
if (mInkWindow.isInkViewVisible()) {
if (mInkWindow != null && mInkWindow.isInkViewVisible()) {
mInkWindow.getDecorView().dispatchTouchEvent(motionEvent);
} else {
if (mPendingEvents == null) {
mPendingEvents = new RingBuffer(MotionEvent.class, MAX_EVENTS_BUFFER);
}
mPendingEvents.append(motionEvent);
mInkWindow.setInkViewVisibilityListener(() -> {
if (mPendingEvents != null && !mPendingEvents.isEmpty()) {
for (MotionEvent event : mPendingEvents.toArray()) {
mInkWindow.getDecorView().dispatchTouchEvent(event);
if (mInkWindow != null) {
mInkWindow.setInkViewVisibilityListener(() -> {
if (mPendingEvents != null && !mPendingEvents.isEmpty()) {
for (MotionEvent event : mPendingEvents.toArray()) {
if (mInkWindow == null) {
break;
}
mInkWindow.getDecorView().dispatchTouchEvent(event);
}
mPendingEvents.clear();
}
mPendingEvents.clear();
}
});
});
}
}
}