From 50cf698b76bd140a4ada4058f9abbee837289a75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Str=C3=B8mme?= Date: Mon, 16 Jun 2014 13:35:21 +0200 Subject: Android: Fix hover-event handling. The accessibility delegate needs to intercept the hover events before the view gets them, but since the dispatchHoverEvent() method was added in API level 14 and we build with API level < 14, we can't call the super class implementation (e.g., when the event isn't handled by the accessibility delegate). In the previous implementation we where trying to solve this by using the reflection API, but that does not provide a solution to call the super class implementation (Note: It's possible with JDK 7 or newer), so the code would call itself recursively and we would eventually get a stack overflow exception. This change uses the OnHoverListener class to intercept the hover events, this way we avoid "overriding" the dispatchHoverEvent() method in QtSurface and therefore avoid the problem it causes. Task-number: QTBUG-38905 Change-Id: I8b3cbad718d8524042397bb877e39e3005bfb4ce Reviewed-by: Frederik Gladhorn --- .../qt5/android/accessibility/QtAccessibilityDelegate.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/android/accessibility/jar/src') diff --git a/src/android/accessibility/jar/src/org/qtproject/qt5/android/accessibility/QtAccessibilityDelegate.java b/src/android/accessibility/jar/src/org/qtproject/qt5/android/accessibility/QtAccessibilityDelegate.java index 70b02d8d04..3275b90e33 100644 --- a/src/android/accessibility/jar/src/org/qtproject/qt5/android/accessibility/QtAccessibilityDelegate.java +++ b/src/android/accessibility/jar/src/org/qtproject/qt5/android/accessibility/QtAccessibilityDelegate.java @@ -53,6 +53,7 @@ import android.text.TextUtils; import android.view.accessibility.*; import android.view.MotionEvent; +import android.view.View.OnHoverListener; import android.content.Context; @@ -85,9 +86,19 @@ public class QtAccessibilityDelegate extends View.AccessibilityDelegate // the offset of the view on screen into account (eg status bar on top) private final int[] m_globalOffset = new int[2]; + private class HoverEventListener implements View.OnHoverListener + { + @Override + public boolean onHover(View v, MotionEvent event) + { + return dispatchHoverEvent(event); + } + } + public QtAccessibilityDelegate(View host) { m_view = host; + m_view.setOnHoverListener(new HoverEventListener()); m_manager = (AccessibilityManager) host.getContext() .getSystemService(Context.ACCESSIBILITY_SERVICE); @@ -103,7 +114,7 @@ public class QtAccessibilityDelegate extends View.AccessibilityDelegate // For "explore by touch" we need all movement events here first // (user moves finger over screen to discover items on screen). - public boolean dispatchHoverEvent(MotionEvent event) + private boolean dispatchHoverEvent(MotionEvent event) { if (!m_manager.isTouchExplorationEnabled()) { return false; -- cgit v1.2.3