diff options
| author | Feng Cao <fengcao@google.com> | 2020-03-10 18:14:13 -0700 |
|---|---|---|
| committer | Feng Cao <fengcao@google.com> | 2020-03-12 15:51:22 -0700 |
| commit | deec8f01752508a65fbbee6ff692d29b6aff4855 (patch) | |
| tree | 772b96dc683edea9afc000c8abea0b45d7e33eab /core/java | |
| parent | c47c4c0e13d73e6de3cfd122b6c0f19747eb9a34 (diff) | |
Sends click and long click events from the inline suggestion to host app
Test: manual, atest InlineSuggestionTest
Bug: 151185482
Change-Id: Iafeb4584feca8a1cb1374f81105fa22136eba183
Diffstat (limited to 'core/java')
4 files changed, 63 insertions, 13 deletions
diff --git a/core/java/android/service/autofill/IInlineSuggestionUiCallback.aidl b/core/java/android/service/autofill/IInlineSuggestionUiCallback.aidl index 101165176293..1bcc76bfca44 100644 --- a/core/java/android/service/autofill/IInlineSuggestionUiCallback.aidl +++ b/core/java/android/service/autofill/IInlineSuggestionUiCallback.aidl @@ -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); diff --git a/core/java/android/service/autofill/InlineSuggestionRenderService.java b/core/java/android/service/autofill/InlineSuggestionRenderService.java index ee15283715ff..b6cc62dc213e 100644 --- a/core/java/android/service/autofill/InlineSuggestionRenderService.java +++ b/core/java/android/service/autofill/InlineSuggestionRenderService.java @@ -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); diff --git a/core/java/android/view/inputmethod/InlineSuggestion.java b/core/java/android/view/inputmethod/InlineSuggestion.java index 650061396992..dd1738a5ff29 100644 --- a/core/java/android/view/inputmethod/InlineSuggestion.java +++ b/core/java/android/view/inputmethod/InlineSuggestion.java @@ -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()}. * - * @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. + * <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 diff --git a/core/java/com/android/internal/view/inline/IInlineContentCallback.aidl b/core/java/com/android/internal/view/inline/IInlineContentCallback.aidl index 29bdf5661eaf..feb3f026b806 100644 --- a/core/java/com/android/internal/view/inline/IInlineContentCallback.aidl +++ b/core/java/com/android/internal/view/inline/IInlineContentCallback.aidl @@ -24,4 +24,6 @@ import android.view.SurfaceControlViewHost; */ oneway interface IInlineContentCallback { void onContent(in SurfaceControlViewHost.SurfacePackage content); + void onClick(); + void onLongClick(); } |
