Merge "Handle non-initalized InkWindow"
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user