diff --git a/core/java/android/service/autofill/IInlineSuggestionUiCallback.aidl b/core/java/android/service/autofill/IInlineSuggestionUiCallback.aidl index 1011651762932..1bcc76bfca445 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 ee15283715ffd..b6cc62dc213e1 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 6500613969927..dd1738a5ff296 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. + *
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