Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 506b0eb0 authored by Taran Singh's avatar Taran Singh Committed by Android (Google) Code Review
Browse files

Merge "Introduce system Handwriting session idle-timeout"

parents 87e108d0 e72f9241
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -99,7 +99,6 @@ final class InkWindow extends PhoneWindow {
        if (getDecorView() != null) {
            getDecorView().setVisibility(remove ? View.GONE : View.INVISIBLE);
        }
        //TODO(b/210039666): remove window from WM after a delay. Delay amount TBD.
    }

    void setToken(@NonNull IBinder token) {
+39 −0
Original line number Diff line number Diff line
@@ -345,6 +345,14 @@ public class InputMethodService extends AbstractInputMethodService {
     */
    private static final int MAX_EVENTS_BUFFER = 500;

    /**
     * When IME doesn't receive stylus input for these many milliseconds, Handwriting session
     * will be finished by calling {@link #finishStylusHandwriting()}.
     * @see #onStartStylusHandwriting()
     * @see #onFinishStylusHandwriting()
     */
    private static final int STYLUS_HANDWRITING_IDLE_TIMEOUT_MS = 10000;

    /**
     * A circular buffer of size MAX_EVENTS_BUFFER in case IME is taking too long to add ink view.
     **/
@@ -353,6 +361,7 @@ public class InputMethodService extends AbstractInputMethodService {
    private Boolean mBackCallbackRegistered = false;
    private final OnBackInvokedCallback mCompatBackCallback = this::compatHandleBack;
    private Runnable mImeSurfaceRemoverRunnable;
    private Runnable mFinishHwRunnable;

    /**
     * Returns whether {@link InputMethodService} is responsible for rendering the back button and
@@ -996,8 +1005,10 @@ public class InputMethodService extends AbstractInputMethodService {
                            return false;
                        }
                        onStylusHandwritingMotionEvent((MotionEvent) event);
                        scheduleHandwritingSessionTimeout();
                        return true;
                    });
            scheduleHandwritingSessionTimeout();
        }

        /**
@@ -2475,6 +2486,10 @@ public class InputMethodService extends AbstractInputMethodService {
        if (!mHandwritingRequestId.isPresent()) {
            return;
        }
        if (mHandler != null && mFinishHwRunnable != null) {
            mHandler.removeCallbacks(mFinishHwRunnable);
        }
        mFinishHwRunnable = null;

        final int requestId = mHandwritingRequestId.getAsInt();
        mHandwritingRequestId = OptionalInt.empty();
@@ -2488,6 +2503,30 @@ public class InputMethodService extends AbstractInputMethodService {
        onFinishStylusHandwriting();
    }

    private Runnable getFinishHandwritingRunnable() {
        if (mFinishHwRunnable != null) {
            return mFinishHwRunnable;
        }
        return mFinishHwRunnable = () -> {
            if (mHandler != null) {
                mHandler.removeCallbacks(mFinishHwRunnable);
            }
            Log.d(TAG, "Stylus handwriting idle timed-out. calling finishStylusHandwriting()");
            mFinishHwRunnable = null;
            finishStylusHandwriting();
        };
    }

    private void scheduleHandwritingSessionTimeout() {
        if (mHandler == null) {
            mHandler = new Handler(getMainLooper());
        }
        if (mFinishHwRunnable != null) {
            mHandler.removeCallbacks(mFinishHwRunnable);
        }
        mHandler.postDelayed(getFinishHandwritingRunnable(), STYLUS_HANDWRITING_IDLE_TIMEOUT_MS);
    }

    /**
     * The system has decided that it may be time to show your input method.
     * This is called due to a corresponding call to your