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

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

Merge "Adaptive scribe bounds: InputMethodService apis 2/n" into main

parents 3cbafac4 0bd9841b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -21214,6 +21214,7 @@ package android.inputmethodservice {
    method public void setExtractView(android.view.View);
    method public void setExtractViewShown(boolean);
    method public void setInputView(android.view.View);
    method @FlaggedApi("android.view.inputmethod.adaptive_handwriting_bounds") public final void setStylusHandwritingRegion(@NonNull android.graphics.Region);
    method public final void setStylusHandwritingSessionTimeout(@NonNull java.time.Duration);
    method public final boolean shouldOfferSwitchingToNextInputMethod();
    method public void showStatusIcon(@DrawableRes int);
+42 −0
Original line number Diff line number Diff line
@@ -406,6 +406,12 @@ public class InputMethodService extends AbstractInputMethodService {
     **/
    private boolean mUsingCtrlShiftShortcut = false;

    /**
     * Last handwriting bounds used for stylus handwriting
     * {@link #setStylusHandwritingRegion(Region)}.
     */
    private Region mLastHandwritingRegion;

    /**
     * Returns whether {@link InputMethodService} is responsible for rendering the back button and
     * the IME switcher button or not when the gestural navigation is enabled.
@@ -1532,6 +1538,7 @@ public class InputMethodService extends AbstractInputMethodService {
                    return;
                }
                editorInfo.makeCompatible(getApplicationInfo().targetSdkVersion);
                mLastHandwritingRegion = null;
                getInputMethodInternal().restartInput(new RemoteInputConnection(ric, sessionId),
                        editorInfo);
            }
@@ -2840,6 +2847,7 @@ public class InputMethodService extends AbstractInputMethodService {
            mHandler.removeCallbacks(mFinishHwRunnable);
        }
        mFinishHwRunnable = null;
        mLastHandwritingRegion = null;

        final int requestId = mHandwritingRequestId.getAsInt();
        mHandwritingRequestId = OptionalInt.empty();
@@ -3166,6 +3174,40 @@ public class InputMethodService extends AbstractInputMethodService {
        registerDefaultOnBackInvokedCallback();
    }

    /**
     * Sets a new stylus handwriting region as user continues to write on an editor on screen.
     * Stylus strokes that are started within the {@code touchableRegion} are treated as
     * continuation of handwriting and all the events outside are passed-through to the IME target
     * app, causing stylus handwriting to finish {@link #finishStylusHandwriting()}.
     * By default, {@link WindowManager#getMaximumWindowMetrics()} is handwritable and
     * {@code touchableRegion} resets after each handwriting session.
     * <p>
     * For example, the IME can use this API to dynamically expand the stylus handwriting region on
     * every stylus stroke as user continues to write on an editor. The region should grow around
     * the last stroke so that a UI element below the IME window is still interactable when it is
     * spaced sufficiently away (~2 character dimensions) from last stroke.
     * </p>
     * <p>
     * Note: Setting handwriting touchable region is supported on IMEs that support stylus
     * handwriting {@link InputMethodInfo#supportsStylusHandwriting()}.
     * </p>
     *
     * @param handwritingRegion new stylus handwritable {@link Region} that can accept stylus touch.
     */
    @FlaggedApi(Flags.FLAG_ADAPTIVE_HANDWRITING_BOUNDS)
    public final void setStylusHandwritingRegion(@NonNull Region handwritingRegion) {
        if (handwritingRegion.equals(mLastHandwritingRegion)) {
            Log.v(TAG, "Failed to set setStylusHandwritingRegion():"
                    + " same region set twice.");
            return;
        }

        if (DEBUG) {
            Log.d(TAG, "Setting new handwriting region for stylus handwriting "
                    + handwritingRegion + " from last " + mLastHandwritingRegion);
        }
        mLastHandwritingRegion = handwritingRegion;
    }

    /**
     * Registers an {@link OnBackInvokedCallback} to handle back invocation when ahead-of-time