diff options
| author | 2020-04-29 00:35:10 -0700 | |
|---|---|---|
| committer | 2020-05-01 12:36:51 -0700 | |
| commit | c23bfc7819894214c93cf13ea1a2e35722a23a6e (patch) | |
| tree | d184b28fa993a0183bf10a0a711f037cb552fe82 | |
| parent | 7291aad962f1d74bbfad1013a87a1f183836051a (diff) | |
Support receiving touch event in the inline suggestion view
* Before this change, the suggestionRoot would intercept all touch
events so that it can optionally forward them to the IME process
to support scrolling, no touch event will be sent to the child
view through the regular event dispatching process.
* With this change, we move the touch event transferring (to IME)
logic from SuggestionRoot's onTouchEvent to dispatchTouchEvent.
Now the touch events before a scroll is detected will be sent to
the child chip view, and only the touch events after a scroll is
detected will be sent to the IME.
* This patch also move the OnClickListener and OnLongClickListener
from the root view to the chip view, since the touch events now
either goes to the chip view or to the IME process.
* Note that in order to achieve this, given that we can't change
the API, and there is existing OnLongClickListener registered
to the chip view, we have to add a @hide API to the View to
get the existing OnLongClickListener and attach a new one to the
chip view, such that we can do the additional work of sending
the long click event to IME, when the view is long clicked.
* This patch should also fix the a11y talkback mode bug where
double-tapping on the view doesn't autofill the value.
Double-tap and hold also works that it triggers the attribution
dialog.
Test: atest CtsAutoFillServiceTestCases (sanity test)
Bug: 155245913
Bug: 154149807
Change-Id: I6f7be1ea5c0955969abb4ccae0cb421423095c4d
| -rw-r--r-- | core/java/android/service/autofill/InlineSuggestionRenderService.java | 20 | ||||
| -rw-r--r-- | core/java/android/service/autofill/InlineSuggestionRoot.java | 9 | ||||
| -rw-r--r-- | core/java/android/view/View.java | 10 |
3 files changed, 23 insertions, 16 deletions
diff --git a/core/java/android/service/autofill/InlineSuggestionRenderService.java b/core/java/android/service/autofill/InlineSuggestionRenderService.java index 19961e5efc6a..6c22b1936d74 100644 --- a/core/java/android/service/autofill/InlineSuggestionRenderService.java +++ b/core/java/android/service/autofill/InlineSuggestionRenderService.java @@ -144,22 +144,24 @@ public abstract class InlineSuggestionRenderService extends Service { final SurfaceControlViewHost host = new SurfaceControlViewHost(this, getDisplay(), hostInputToken); host.setView(suggestionRoot, lp); - suggestionRoot.setOnClickListener((v) -> { + + // Set the suggestion view to be non-focusable so that if its background is set to a + // ripple drawable, the ripple won't be shown initially. + suggestionView.setFocusable(false); + suggestionView.setOnClickListener((v) -> { try { - if (suggestionView.hasOnClickListeners()) { - suggestionView.callOnClick(); - } callback.onClick(); } catch (RemoteException e) { Log.w(TAG, "RemoteException calling onClick()"); } }); - - suggestionRoot.setOnLongClickListener((v) -> { + final View.OnLongClickListener onLongClickListener = + suggestionView.getOnLongClickListener(); + suggestionView.setOnLongClickListener((v) -> { + if (onLongClickListener != null) { + onLongClickListener.onLongClick(v); + } try { - if (suggestionView.hasOnLongClickListeners()) { - suggestionView.performLongClick(); - } callback.onLongClick(); } catch (RemoteException e) { Log.w(TAG, "RemoteException calling onLongClick()"); diff --git a/core/java/android/service/autofill/InlineSuggestionRoot.java b/core/java/android/service/autofill/InlineSuggestionRoot.java index 653e513f13d8..c879653859d8 100644 --- a/core/java/android/service/autofill/InlineSuggestionRoot.java +++ b/core/java/android/service/autofill/InlineSuggestionRoot.java @@ -52,13 +52,8 @@ public class InlineSuggestionRoot extends FrameLayout { } @Override - public boolean onInterceptTouchEvent(MotionEvent ev) { - return true; - } - - @Override @SuppressLint("ClickableViewAccessibility") - public boolean onTouchEvent(@NonNull MotionEvent event) { + public boolean dispatchTouchEvent(@NonNull MotionEvent event) { switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: { mDownX = event.getX(); @@ -80,6 +75,6 @@ public class InlineSuggestionRoot extends FrameLayout { } } break; } - return super.onTouchEvent(event); + return super.dispatchTouchEvent(event); } } diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index f98c1f660cfa..da0671f3597b 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -7263,6 +7263,16 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } /** + * @return the registered {@link OnLongClickListener} if there is one, {@code null} otherwise. + * @hide + */ + @Nullable + public OnLongClickListener getOnLongClickListener() { + ListenerInfo li = mListenerInfo; + return (li != null) ? li.mOnLongClickListener : null; + } + + /** * Register a callback to be invoked when this view is context clicked. If the view is not * context clickable, it becomes context clickable. * |