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

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

Merge "API for stylusHandwritingEnabled" into main

parents 7060dee4 2420b22f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -55029,10 +55029,12 @@ package android.view.inputmethod {
    method public int getInitialToolType();
    method @NonNull public java.util.Set<java.lang.Class<? extends android.view.inputmethod.PreviewableHandwritingGesture>> getSupportedHandwritingGesturePreviews();
    method @NonNull public java.util.List<java.lang.Class<? extends android.view.inputmethod.HandwritingGesture>> getSupportedHandwritingGestures();
    method @FlaggedApi("android.view.inputmethod.editorinfo_handwriting_enabled") public boolean isStylusHandwritingEnabled();
    method public final void makeCompatible(int);
    method public void setInitialSurroundingSubText(@NonNull CharSequence, int);
    method public void setInitialSurroundingText(@NonNull CharSequence);
    method public void setInitialToolType(int);
    method @FlaggedApi("android.view.inputmethod.editorinfo_handwriting_enabled") public void setStylusHandwritingEnabled(boolean);
    method public void setSupportedHandwritingGesturePreviews(@NonNull java.util.Set<java.lang.Class<? extends android.view.inputmethod.PreviewableHandwritingGesture>>);
    method public void setSupportedHandwritingGestures(@NonNull java.util.List<java.lang.Class<? extends android.view.inputmethod.HandwritingGesture>>);
    method public void writeToParcel(android.os.Parcel, int);
+1 −0
Original line number Diff line number Diff line
@@ -32635,6 +32635,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * @see android.view.inputmethod.InputMethodManager#startStylusHandwriting(View)
     * @param enabled whether auto handwriting initiation is enabled for this view.
     * @attr ref android.R.styleable#View_autoHandwritingEnabled
     * @see EditorInfo#setStylusHandwritingEnabled(boolean)
     */
    public void setAutoHandwritingEnabled(boolean enabled) {
        if (enabled) {
+37 −0
Original line number Diff line number Diff line
@@ -23,7 +23,9 @@ import static android.view.inputmethod.EditorInfoProto.INPUT_TYPE;
import static android.view.inputmethod.EditorInfoProto.PACKAGE_NAME;
import static android.view.inputmethod.EditorInfoProto.PRIVATE_IME_OPTIONS;
import static android.view.inputmethod.EditorInfoProto.TARGET_INPUT_METHOD_USER_ID;
import static android.view.inputmethod.Flags.FLAG_EDITORINFO_HANDWRITING_ENABLED;

import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
@@ -45,6 +47,7 @@ import android.view.MotionEvent;
import android.view.MotionEvent.ToolType;
import android.view.View;
import android.view.autofill.AutofillId;
import android.widget.Editor;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.inputmethod.InputMethodDebug;
@@ -716,6 +719,33 @@ public class EditorInfo implements InputType, Parcelable {
        return set;
    }

    private boolean mIsStylusHandwritingEnabled;

    /**
     * Set {@code true} if the {@link Editor} has
     * {@link InputMethodManager#startStylusHandwriting stylus handwriting} enabled.
     * {@code false} by default, {@link Editor} must set it {@code true} to indicate that
     * it supports stylus handwriting.
     *
     * @param enabled {@code true} if stylus handwriting is enabled.
     * @see View#setAutoHandwritingEnabled(boolean)
     */
    @FlaggedApi(FLAG_EDITORINFO_HANDWRITING_ENABLED)
    public void setStylusHandwritingEnabled(boolean enabled) {
        mIsStylusHandwritingEnabled = enabled;
    }

    /**
     * Returns {@code true} when an {@link Editor} has stylus handwriting enabled.
     * {@code false} by default.
     * @see #setStylusHandwritingEnabled(boolean)
     * @see InputMethodManager#isStylusHandwritingAvailable()
     */
    @FlaggedApi(FLAG_EDITORINFO_HANDWRITING_ENABLED)
    public boolean isStylusHandwritingEnabled() {
        return mIsStylusHandwritingEnabled;
    }

    /**
     * If not {@code null}, this editor needs to talk to IMEs that run for the specified user, no
     * matter what user ID the calling process has.
@@ -1211,6 +1241,7 @@ public class EditorInfo implements InputType, Parcelable {
        pw.println(prefix + "supportedHandwritingGesturePreviewTypes="
                + InputMethodDebug.handwritingGestureTypeFlagsToString(
                        mSupportedHandwritingGesturePreviewTypes));
        pw.println(prefix + "isStylusHandwritingEnabled=" + mIsStylusHandwritingEnabled);
        pw.println(prefix + "contentMimeTypes=" + Arrays.toString(contentMimeTypes));
        if (targetInputMethodUser != null) {
            pw.println(prefix + "targetInputMethodUserId=" + targetInputMethodUser.getIdentifier());
@@ -1277,6 +1308,9 @@ public class EditorInfo implements InputType, Parcelable {
        dest.writeBundle(extras);
        dest.writeInt(mSupportedHandwritingGestureTypes);
        dest.writeInt(mSupportedHandwritingGesturePreviewTypes);
        if (Flags.editorinfoHandwritingEnabled()) {
            dest.writeBoolean(mIsStylusHandwritingEnabled);
        }
        dest.writeBoolean(mInitialSurroundingText != null);
        if (mInitialSurroundingText != null) {
            mInitialSurroundingText.writeToParcel(dest, flags);
@@ -1316,6 +1350,9 @@ public class EditorInfo implements InputType, Parcelable {
                    res.extras = source.readBundle();
                    res.mSupportedHandwritingGestureTypes = source.readInt();
                    res.mSupportedHandwritingGesturePreviewTypes = source.readInt();
                    if (Flags.editorinfoHandwritingEnabled()) {
                        res.mIsStylusHandwritingEnabled = source.readBoolean();
                    }
                    boolean hasInitialSurroundingText = source.readBoolean();
                    if (hasInitialSurroundingText) {
                        res.mInitialSurroundingText =
+8 −0
Original line number Diff line number Diff line
@@ -7,3 +7,11 @@ flag {
    bug: "298172246"
    is_fixed_read_only: true
}

flag {
    name: "editorinfo_handwriting_enabled"
    namespace: "input_method"
    description: "Feature flag for adding EditorInfo#mStylusHandwritingEnabled"
    bug: "293898187"
    is_fixed_read_only: true
}
 No newline at end of file
+7 −0
Original line number Diff line number Diff line
@@ -503,6 +503,7 @@ public class EditorInfoTest {
                + "prefix: hintLocales=null\n"
                + "prefix: supportedHandwritingGestureTypes=(none)\n"
                + "prefix: supportedHandwritingGesturePreviewTypes=(none)\n"
                + "prefix: isStylusHandwritingEnabled=false\n"
                + "prefix: contentMimeTypes=null\n");
    }

@@ -521,6 +522,9 @@ public class EditorInfoTest {
        info.setSupportedHandwritingGestures(Arrays.asList(SelectGesture.class));
        info.setSupportedHandwritingGesturePreviews(
                Stream.of(SelectGesture.class).collect(Collectors.toSet()));
        if (Flags.editorinfoHandwritingEnabled()) {
            info.setStylusHandwritingEnabled(true);
        }
        info.packageName = "android.view.inputmethod";
        info.autofillId = new AutofillId(123);
        info.fieldId = 456;
@@ -544,6 +548,8 @@ public class EditorInfoTest {
                        + "prefix2: hintLocales=[en,es,zh]\n"
                        + "prefix2: supportedHandwritingGestureTypes=SELECT\n"
                        + "prefix2: supportedHandwritingGesturePreviewTypes=SELECT\n"
                        + "prefix2: isStylusHandwritingEnabled="
                                + Flags.editorinfoHandwritingEnabled() + "\n"
                        + "prefix2: contentMimeTypes=[image/png]\n"
                        + "prefix2: targetInputMethodUserId=10\n");
    }
@@ -565,6 +571,7 @@ public class EditorInfoTest {
                        + "prefix: hintLocales=null\n"
                        + "prefix: supportedHandwritingGestureTypes=(none)\n"
                        + "prefix: supportedHandwritingGesturePreviewTypes=(none)\n"
                        + "prefix: isStylusHandwritingEnabled=false\n"
                        + "prefix: contentMimeTypes=null\n");
    }