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

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

Merge changes from topics "performHandwritingGesture-return", "supported-gestures"

* changes:
  Add consumer callback in performHandwritingGesture()
  Add supported gesture type to EditorInfo
parents 3d68a330 4b5d6969
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -53035,10 +53035,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
@@ -53107,6 +53109,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
  }
@@ -53222,6 +53228,12 @@ package android.view.inputmethod {
    field public static final int CURSOR_UPDATE_MONITOR = 2; // 0x2
    field public static final int GET_EXTRACTED_TEXT_MONITOR = 1; // 0x1
    field public static final int GET_TEXT_WITH_STYLES = 1; // 0x1
    field public static final int HANDWRITING_GESTURE_RESULT_CANCELLED = 4; // 0x4
    field public static final int HANDWRITING_GESTURE_RESULT_FAILED = 3; // 0x3
    field public static final int HANDWRITING_GESTURE_RESULT_FALLBACK = 5; // 0x5
    field public static final int HANDWRITING_GESTURE_RESULT_SUCCESS = 1; // 0x1
    field public static final int HANDWRITING_GESTURE_RESULT_UNKNOWN = 0; // 0x0
    field public static final int HANDWRITING_GESTURE_RESULT_UNSUPPORTED = 2; // 0x2
    field public static final int INPUT_CONTENT_GRANT_READ_URI_PERMISSION = 1; // 0x1
  }
+4 −0
Original line number Diff line number Diff line
@@ -3100,6 +3100,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);
  }
+62 −5
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.view.KeyEvent;
import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.CorrectionInfo;
@@ -29,6 +30,7 @@ import android.view.inputmethod.DeleteGesture;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.HandwritingGesture;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputContentInfo;
import android.view.inputmethod.InsertGesture;
import android.view.inputmethod.SelectGesture;
@@ -59,6 +61,38 @@ final class IRemoteInputConnectionInvoker {
        mSessionId = sessionId;
    }

    /**
     * Subclass of {@link ResultReceiver} used by
     * {@link #performHandwritingGesture(HandwritingGesture, Executor, IntConsumer)} for providing
     * callback.
     */
    private static final class IntResultReceiver extends ResultReceiver {
        @NonNull
        private IntConsumer mConsumer;
        @NonNull
        private Executor mExecutor;

        IntResultReceiver(@NonNull Executor executor, @NonNull IntConsumer consumer) {
            super(null);
            mExecutor = executor;
            mConsumer = consumer;
        }

        @Override
        protected void onReceiveResult(int resultCode, Bundle resultData) {
            if (mExecutor != null && mConsumer != null) {
                mExecutor.execute(() -> mConsumer.accept(resultCode));
                // provide callback only once.
                clear();
            }
        }

        private void clear() {
            mExecutor = null;
            mConsumer = null;
        }
    };

    /**
     * Creates a new instance of {@link IRemoteInputConnectionInvoker} for the given
     * {@link IRemoteInputConnection}.
@@ -598,24 +632,47 @@ final class IRemoteInputConnectionInvoker {
        }
    }

    /**
     * Invokes one of {@link IRemoteInputConnection#performHandwritingSelectGesture(
     * InputConnectionCommandHeader, SelectGesture, AndroidFuture)},
     * {@link IRemoteInputConnection#performHandwritingDeleteGesture(InputConnectionCommandHeader,
     * DeleteGesture, AndroidFuture)},
     * {@link IRemoteInputConnection#performHandwritingInsertGesture(InputConnectionCommandHeader,
     * InsertGesture, AndroidFuture)}
     *
     * @param {@code gesture} parameter {@link HandwritingGesture}.
     * @return {@link AndroidFuture<Integer>} that can be used to retrieve the invocation
     *         result. {@link RemoteException} will be treated as an error.
     */
    @AnyThread
    public void performHandwritingGesture(
            @NonNull HandwritingGesture gesture, @Nullable @CallbackExecutor Executor executor,
            @Nullable IntConsumer consumer) {
        // TODO(b/210039666): implement resultReceiver

        ResultReceiver resultReceiver = null;
        if (consumer != null) {
            Objects.requireNonNull(executor);
            resultReceiver = new IntResultReceiver(executor, consumer);
        }
        try {
            if (gesture instanceof SelectGesture) {
                mConnection.performHandwritingSelectGesture(
                        createHeader(), (SelectGesture) gesture, null);
                        createHeader(), (SelectGesture) gesture, resultReceiver);
            } else if (gesture instanceof InsertGesture) {
                mConnection.performHandwritingInsertGesture(
                        createHeader(), (InsertGesture) gesture, null);
                        createHeader(), (InsertGesture) gesture, resultReceiver);
            } else if (gesture instanceof DeleteGesture) {
                mConnection.performHandwritingDeleteGesture(
                        createHeader(), (DeleteGesture) gesture, null);
                        createHeader(), (DeleteGesture) gesture, resultReceiver);
            } else if (consumer != null && executor != null) {
                executor.execute(()
                        -> consumer.accept(InputConnection.HANDWRITING_GESTURE_RESULT_UNSUPPORTED));
            }
        } catch (RemoteException e) {
            // TODO(b/210039666): return result
            if (consumer != null && executor != null) {
                executor.execute(() -> consumer.accept(
                        InputConnection.HANDWRITING_GESTURE_RESULT_CANCELLED));
            }
        }
    }

+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)
Loading