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

Commit f135f895 authored by Taran Singh's avatar Taran Singh
Browse files

Add supported gesture type to EditorInfo

Editors should declare which Scribe Gestures do they support
as a means of providing this info to IME.

Bug: 239783077
Test: atest CtsInputMethodTestCases

Change-Id: Ic52a48c0a04d405e65ad49e9d447d603fefb4eb0
parent a39cb4ae
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -53027,10 +53027,12 @@ package android.view.inputmethod {
    method @Nullable public CharSequence getInitialTextAfterCursor(@IntRange(from=0) int, int);
    method @Nullable public CharSequence getInitialTextBeforeCursor(@IntRange(from=0) int, int);
    method public int getInitialToolType();
    method @NonNull public java.util.List<java.lang.Class<? extends android.view.inputmethod.HandwritingGesture>> getSupportedHandwritingGestures();
    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 public void setSupportedHandwritingGestures(@NonNull java.util.List<java.lang.Class<? extends android.view.inputmethod.HandwritingGesture>>);
    method public void writeToParcel(android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.view.inputmethod.EditorInfo> CREATOR;
    field public static final int IME_ACTION_DONE = 6; // 0x6
@@ -53099,6 +53101,10 @@ package android.view.inputmethod {
  public abstract class HandwritingGesture {
    method @Nullable public String getFallbackText();
    field public static final int GESTURE_TYPE_DELETE = 4; // 0x4
    field public static final int GESTURE_TYPE_INSERT = 2; // 0x2
    field public static final int GESTURE_TYPE_NONE = 0; // 0x0
    field public static final int GESTURE_TYPE_SELECT = 1; // 0x1
    field public static final int GRANULARITY_CHARACTER = 2; // 0x2
    field public static final int GRANULARITY_WORD = 1; // 0x1
  }
+4 −0
Original line number Diff line number Diff line
@@ -3099,6 +3099,10 @@ package android.view.displayhash {

package android.view.inputmethod {

  public abstract class HandwritingGesture {
    method public int getGestureType();
  }

  public final class InlineSuggestion implements android.os.Parcelable {
    method @NonNull public static android.view.inputmethod.InlineSuggestion newInlineSuggestion(@NonNull android.view.inputmethod.InlineSuggestionInfo);
  }
+2 −0
Original line number Diff line number Diff line
@@ -37,12 +37,14 @@ public final class DeleteGesture extends HandwritingGesture implements Parcelabl
    private RectF mArea;

    private DeleteGesture(@Granularity int granularity, RectF area, String fallbackText) {
        mType = GESTURE_TYPE_DELETE;
        mArea = area;
        mGranularity = granularity;
        mFallbackText = fallbackText;
    }

    private DeleteGesture(@NonNull final Parcel source) {
        mType = GESTURE_TYPE_DELETE;
        mFallbackText = source.readString8();
        mGranularity = source.readInt();
        mArea = source.readTypedObject(RectF.CREATOR);
+76 −0
Original line number Diff line number Diff line
@@ -46,12 +46,15 @@ import android.view.View;
import android.view.autofill.AutofillId;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.inputmethod.InputMethodDebug;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.Preconditions;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
@@ -528,6 +531,72 @@ public class EditorInfo implements InputType, Parcelable {
    @Nullable
    public String[] contentMimeTypes = null;

    private @HandwritingGesture.GestureTypeFlags int mSupportedHandwritingGestureTypes;

    /**
     * Set the Handwriting gestures supported by the current {@code Editor}.
     * For an editor that supports Stylus Handwriting
     * {@link InputMethodManager#startStylusHandwriting}, it is also recommended that it declares
     * supported gestures.
     * <p> If editor doesn't support one of the declared types, IME will not send those Gestures
     *  to the editor. Instead they will fallback to using normal text input. </p>
     * @param gestures List of supported gesture classes including any of {@link SelectGesture},
     * {@link InsertGesture}, {@link DeleteGesture}.
     */
    public void setSupportedHandwritingGestures(
            @NonNull List<Class<? extends HandwritingGesture>> gestures) {
        Objects.requireNonNull(gestures);
        if (gestures.isEmpty()) {
            mSupportedHandwritingGestureTypes = 0;
            return;
        }

        int supportedTypes = 0;
        for (Class<? extends HandwritingGesture> gesture : gestures) {
            Objects.requireNonNull(gesture);
            if (gesture.equals(SelectGesture.class)) {
                supportedTypes |= HandwritingGesture.GESTURE_TYPE_SELECT;
            } else if (gesture.equals(InsertGesture.class)) {
                supportedTypes |= HandwritingGesture.GESTURE_TYPE_INSERT;
            } else if (gesture.equals(DeleteGesture.class)) {
                supportedTypes |= HandwritingGesture.GESTURE_TYPE_DELETE;
            } else {
                throw new IllegalArgumentException("Unknown gesture type: " + gesture);
            }
        }

        mSupportedHandwritingGestureTypes = supportedTypes;
    }

    /**
     * Returns the combination of Stylus handwriting gesture types
     * supported by the current {@code Editor}.
     * For an editor that supports Stylus Handwriting.
     * {@link InputMethodManager#startStylusHandwriting}, it also declares supported gestures.
     * @return List of supported gesture classes including any of {@link SelectGesture},
     * {@link InsertGesture}, {@link DeleteGesture}.
     */
    @NonNull
    public List<Class<? extends HandwritingGesture>> getSupportedHandwritingGestures() {
        List<Class<? extends HandwritingGesture>> list  = new ArrayList<>();
        if (mSupportedHandwritingGestureTypes == 0) {
            return list;
        }
        if ((mSupportedHandwritingGestureTypes & HandwritingGesture.GESTURE_TYPE_SELECT)
                == HandwritingGesture.GESTURE_TYPE_SELECT) {
            list.add(SelectGesture.class);
        }
        if ((mSupportedHandwritingGestureTypes & HandwritingGesture.GESTURE_TYPE_INSERT)
                == HandwritingGesture.GESTURE_TYPE_INSERT) {
            list.add(InsertGesture.class);
        }
        if ((mSupportedHandwritingGestureTypes & HandwritingGesture.GESTURE_TYPE_DELETE)
                == HandwritingGesture.GESTURE_TYPE_DELETE) {
            list.add(DeleteGesture.class);
        }
        return list;
    }

    /**
     * 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.
@@ -1018,6 +1087,9 @@ public class EditorInfo implements InputType, Parcelable {
            pw.println(prefix + "extras=" + extras);
        }
        pw.println(prefix + "hintLocales=" + hintLocales);
        pw.println(prefix + "supportedHandwritingGestureTypes="
                + InputMethodDebug.handwritingGestureTypeFlagsToString(
                        mSupportedHandwritingGestureTypes));
        pw.println(prefix + "contentMimeTypes=" + Arrays.toString(contentMimeTypes));
        if (targetInputMethodUser != null) {
            pw.println(prefix + "targetInputMethodUserId=" + targetInputMethodUser.getIdentifier());
@@ -1052,6 +1124,7 @@ public class EditorInfo implements InputType, Parcelable {
        newEditorInfo.hintLocales = hintLocales;
        newEditorInfo.contentMimeTypes = ArrayUtils.cloneOrNull(contentMimeTypes);
        newEditorInfo.targetInputMethodUser = targetInputMethodUser;
        newEditorInfo.mSupportedHandwritingGestureTypes = mSupportedHandwritingGestureTypes;
        return newEditorInfo;
    }

@@ -1079,6 +1152,7 @@ public class EditorInfo implements InputType, Parcelable {
        dest.writeInt(fieldId);
        dest.writeString(fieldName);
        dest.writeBundle(extras);
        dest.writeInt(mSupportedHandwritingGestureTypes);
        dest.writeBoolean(mInitialSurroundingText != null);
        if (mInitialSurroundingText != null) {
            mInitialSurroundingText.writeToParcel(dest, flags);
@@ -1116,6 +1190,7 @@ public class EditorInfo implements InputType, Parcelable {
                    res.fieldId = source.readInt();
                    res.fieldName = source.readString();
                    res.extras = source.readBundle();
                    res.mSupportedHandwritingGestureTypes = source.readInt();
                    boolean hasInitialSurroundingText = source.readBoolean();
                    if (hasInitialSurroundingText) {
                        res.mInitialSurroundingText =
@@ -1158,6 +1233,7 @@ public class EditorInfo implements InputType, Parcelable {
                && initialSelEnd == that.initialSelEnd
                && initialCapsMode == that.initialCapsMode
                && fieldId == that.fieldId
                && mSupportedHandwritingGestureTypes == that.mSupportedHandwritingGestureTypes
                && Objects.equals(autofillId, that.autofillId)
                && Objects.equals(privateImeOptions, that.privateImeOptions)
                && Objects.equals(packageName, that.packageName)
+60 −0
Original line number Diff line number Diff line
@@ -18,10 +18,13 @@ package android.view.inputmethod;

import android.annotation.IntDef;
import android.annotation.Nullable;
import android.annotation.TestApi;
import android.graphics.RectF;
import android.inputmethodservice.InputMethodService;
import android.view.MotionEvent;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.concurrent.Executor;
import java.util.function.IntConsumer;

@@ -78,6 +81,63 @@ public abstract class HandwritingGesture {
    @IntDef({GRANULARITY_CHARACTER, GRANULARITY_WORD})
    @interface Granularity {}

    /** Undefined gesture type. */
    public static final int GESTURE_TYPE_NONE = 0x0000;

    /**
     * Gesture of type {@link SelectGesture} to select an area of text.
     */
    public static final int GESTURE_TYPE_SELECT = 0x0001;

    /**
     * Gesture of type {@link InsertGesture} to insert text at a designated point.
     */
    public static final int GESTURE_TYPE_INSERT = 1 << 1;

    /**
     * Gesture of type {@link DeleteGesture} to delete an area of text.
     */
    public static final int GESTURE_TYPE_DELETE = 1 << 2;

    /**
     * Type of gesture like {@link #GESTURE_TYPE_SELECT}, {@link #GESTURE_TYPE_INSERT},
     * or {@link #GESTURE_TYPE_DELETE}.
     */
    @IntDef(prefix = {"GESTURE_TYPE_"}, value = {
                GESTURE_TYPE_NONE,
                GESTURE_TYPE_SELECT,
                GESTURE_TYPE_INSERT,
                GESTURE_TYPE_DELETE})
    @Retention(RetentionPolicy.SOURCE)
    @interface GestureType{}

    /**
     * Flags which can be any combination of {@link #GESTURE_TYPE_SELECT},
     * {@link #GESTURE_TYPE_INSERT}, or {@link #GESTURE_TYPE_DELETE}.
     * {@link GestureTypeFlags} can be used by editors to declare what gestures are supported
     *  and report them in {@link EditorInfo#setSupportedHandwritingGestureTypes(int)}.
     * @hide
     */
    @IntDef(flag = true, prefix = {"GESTURE_TYPE_"}, value = {
            GESTURE_TYPE_SELECT,
            GESTURE_TYPE_INSERT,
            GESTURE_TYPE_DELETE})
    @Retention(RetentionPolicy.SOURCE)
    public @interface GestureTypeFlags{}

    @GestureType int mType = GESTURE_TYPE_NONE;

    /**
     * Returns the gesture type {@link GestureType}.
     * {@link GestureType} can be used by editors to declare what gestures are supported and report
     * them in {@link EditorInfo#setSupportedHandwritingGestureTypes(int)}.
     * @hide
     */
    @TestApi
    public @GestureType int getGestureType() {
        return mType;
    }

    @Nullable
    String mFallbackText;

Loading