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

Commit deec8f01 authored by Feng Cao's avatar Feng Cao
Browse files

Sends click and long click events from the inline suggestion to host app

Test: manual, atest InlineSuggestionTest
Bug: 151185482

Change-Id: Iafeb4584feca8a1cb1374f81105fa22136eba183
parent c47c4c0e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -25,7 +25,8 @@ import android.view.SurfaceControlViewHost;
 * @hide
 */
oneway interface IInlineSuggestionUiCallback {
    void onAutofill();
    void onClick();
    void onLongClick();
    void onContent(in SurfaceControlViewHost.SurfacePackage surface);
    void onError();
    void onTransferTouchFocusToImeWindow(in IBinder sourceInputToken, int displayId);
+11 −2
Original line number Diff line number Diff line
@@ -97,12 +97,21 @@ public abstract class InlineSuggestionRenderService extends Service {
            host.addView(suggestionRoot, lp);
            suggestionRoot.setOnClickListener((v) -> {
                try {
                    callback.onAutofill();
                    callback.onClick();
                } catch (RemoteException e) {
                    Log.w(TAG, "RemoteException calling onAutofill()");
                    Log.w(TAG, "RemoteException calling onClick()");
                }
            });

            suggestionRoot.setOnLongClickListener((v) -> {
                try {
                    callback.onLongClick();
                } catch (RemoteException e) {
                    Log.w(TAG, "RemoteException calling onLongClick()");
                }
                return true;
            });

            sendResult(callback, host.getSurfacePackage());
        } finally {
            updateDisplay(Display.DEFAULT_DISPLAY);
+48 −10
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.view.inputmethod;

import android.annotation.BinderThread;
import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -94,19 +95,21 @@ public final class InlineSuggestion implements Parcelable {
    }



    /**
     * Inflates a view with the content of this suggestion at a specific size.
     * The size must be between the {@link InlinePresentationSpec#getMinSize() min size}
     * and the {@link InlinePresentationSpec#getMaxSize() max size} of the presentation
     * spec returned by {@link InlineSuggestionInfo#getPresentationSpec()}.
     *
     * <p> The caller can attach an {@link View.OnClickListener} and/or an
     * {@link View.OnLongClickListener} to the view in the {@code callback} to receive click and
     * long click events on the view.
     *
     * @param context  Context in which to inflate the view.
     * @param size     The size at which to inflate the suggestion.
     * @param callback Callback for receiving the inflated view.
     *
     * @throws IllegalArgumentException If an invalid argument is passed.
     * @throws IllegalStateException if this method is already called.
     * @throws IllegalStateException    If this method is already called.
     */
    public void inflate(@NonNull Context context, @NonNull Size size,
            @NonNull @CallbackExecutor Executor callbackExecutor,
@@ -151,12 +154,31 @@ public final class InlineSuggestion implements Parcelable {
        }

        @Override
        @BinderThread
        public void onContent(SurfaceControlViewHost.SurfacePackage content) {
            final InlineContentCallbackImpl callbackImpl = mCallbackImpl.get();
            if (callbackImpl != null) {
                callbackImpl.onContent(content);
            }
        }

        @Override
        @BinderThread
        public void onClick() {
            final InlineContentCallbackImpl callbackImpl = mCallbackImpl.get();
            if (callbackImpl != null) {
                callbackImpl.onClick();
            }
        }

        @Override
        @BinderThread
        public void onLongClick() {
            final InlineContentCallbackImpl callbackImpl = mCallbackImpl.get();
            if (callbackImpl != null) {
                callbackImpl.onLongClick();
            }
        }
    }

    private static final class InlineContentCallbackImpl {
@@ -164,6 +186,7 @@ public final class InlineSuggestion implements Parcelable {
        private final @NonNull Context mContext;
        private final @NonNull Executor mCallbackExecutor;
        private final @NonNull Consumer<View> mCallback;
        private @Nullable View mView;

        InlineContentCallbackImpl(@NonNull Context context,
                @NonNull @CallbackExecutor Executor callbackExecutor,
@@ -173,12 +196,27 @@ public final class InlineSuggestion implements Parcelable {
            mCallback = callback;
        }

        @BinderThread
        public void onContent(SurfaceControlViewHost.SurfacePackage content) {
            if (content == null) {
                mCallbackExecutor.execute(() -> mCallback.accept(/* view */null));
            } else {
                mCallbackExecutor.execute(
                        () -> mCallback.accept(new InlineContentView(mContext, content)));
                mView = new InlineContentView(mContext, content);
                mCallbackExecutor.execute(() -> mCallback.accept(mView));
            }
        }

        @BinderThread
        public void onClick() {
            if (mView != null && mView.hasOnClickListeners()) {
                mView.callOnClick();
            }
        }

        @BinderThread
        public void onLongClick() {
            if (mView != null && mView.hasOnLongClickListeners()) {
                mView.performLongClick();
            }
        }
    }
@@ -201,7 +239,7 @@ public final class InlineSuggestion implements Parcelable {



    // Code below generated by codegen v1.0.14.
    // Code below generated by codegen v1.0.15.
    //
    // DO NOT MODIFY!
    // CHECKSTYLE:OFF Generated code
@@ -360,8 +398,8 @@ public final class InlineSuggestion implements Parcelable {
    };

    @DataClass.Generated(
            time = 1581929285156L,
            codegenVersion = "1.0.14",
            time = 1583889058241L,
            codegenVersion = "1.0.15",
            sourceFile = "frameworks/base/core/java/android/view/inputmethod/InlineSuggestion.java",
            inputSignatures = "private static final  java.lang.String TAG\nprivate final @android.annotation.NonNull android.view.inputmethod.InlineSuggestionInfo mInfo\nprivate final @android.annotation.Nullable com.android.internal.view.inline.IInlineContentProvider mContentProvider\nprivate @com.android.internal.util.DataClass.ParcelWith(android.view.inputmethod.InlineSuggestion.InlineContentCallbackImplParceling.class) @android.annotation.Nullable android.view.inputmethod.InlineSuggestion.InlineContentCallbackImpl mInlineContentCallback\npublic static @android.annotation.TestApi @android.annotation.NonNull android.view.inputmethod.InlineSuggestion newInlineSuggestion(android.view.inputmethod.InlineSuggestionInfo)\npublic  void inflate(android.content.Context,android.util.Size,java.util.concurrent.Executor,java.util.function.Consumer<android.view.View>)\nprivate synchronized  android.view.inputmethod.InlineSuggestion.InlineContentCallbackImpl getInlineContentCallback(android.content.Context,java.util.concurrent.Executor,java.util.function.Consumer<android.view.View>)\nclass InlineSuggestion extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genToString=true, genHiddenConstDefs=true, genHiddenConstructor=true)")
    @Deprecated
+2 −0
Original line number Diff line number Diff line
@@ -24,4 +24,6 @@ import android.view.SurfaceControlViewHost;
 */
oneway interface IInlineContentCallback {
    void onContent(in SurfaceControlViewHost.SurfacePackage content);
    void onClick();
    void onLongClick();
}
+7 −1
Original line number Diff line number Diff line
@@ -329,8 +329,14 @@ public final class InlineSuggestionFactory {
            @NonNull Runnable onErrorCallback) {
        return new IInlineSuggestionUiCallback.Stub() {
            @Override
            public void onAutofill() throws RemoteException {
            public void onClick() throws RemoteException {
                onAutofillCallback.run();
                callback.onClick();
            }

            @Override
            public void onLongClick() throws RemoteException {
                callback.onLongClick();
            }

            @Override