diff options
author | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2013-10-24 17:37:27 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-05 19:08:08 +0100 |
commit | 2c11a492fb067cf00ae298a6e2c8af4f10d21e18 (patch) | |
tree | ca7c35099614492bc58a962f79733f940cae6ffa /src/android | |
parent | 54ed14d5c61b2f65bdcb6a0a5c6fa00a9617555d (diff) |
Add better version checks for accessibility
We would spam the debug output on devices with api < 16 with some
warnings that the super class a11y delegate could not be found and
others.
Instead check the runtime version before trying to load the JNI code and
only load the delegate if api is new enough.
Change-Id: I52286cb99924b034b9b58c53566f15030939b0c9
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Diffstat (limited to 'src/android')
-rw-r--r-- | src/android/jar/src/org/qtproject/qt5/android/QtSurface.java | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtSurface.java b/src/android/jar/src/org/qtproject/qt5/android/QtSurface.java index cd0bddf2c8..c499dc3898 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtSurface.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtSurface.java @@ -117,21 +117,23 @@ public class QtSurface extends SurfaceView implements SurfaceHolder.Callback // Initialize Accessibility // The accessibility code depends on android API level 16, so dynamically resolve it - try { - final String a11yDelegateClassName = "org.qtproject.qt5.android.accessibility.QtAccessibilityDelegate"; - Class<?> qtDelegateClass = Class.forName(a11yDelegateClassName); - Constructor constructor = qtDelegateClass.getConstructor(Class.forName("android.view.View")); - m_accessibilityDelegate = constructor.newInstance(this); - - Class a11yDelegateClass = Class.forName("android.view.View$AccessibilityDelegate"); - Method setDelegateMethod = this.getClass().getMethod("setAccessibilityDelegate", a11yDelegateClass); - setDelegateMethod.invoke(this, m_accessibilityDelegate); - } catch (ClassNotFoundException e) { - // Class not found is fine since we are compatible with Android API < 16, but the function will - // only be available with that API level. - } catch (Exception e) { - // Unknown exception means something went wrong. - Log.w("Qt A11y", "Unknown exception: " + e.toString()); + if (android.os.Build.VERSION.SDK_INT >= 16) { + try { + final String a11yDelegateClassName = "org.qtproject.qt5.android.accessibility.QtAccessibilityDelegate"; + Class<?> qtDelegateClass = Class.forName(a11yDelegateClassName); + Constructor constructor = qtDelegateClass.getConstructor(Class.forName("android.view.View")); + m_accessibilityDelegate = constructor.newInstance(this); + + Class a11yDelegateClass = Class.forName("android.view.View$AccessibilityDelegate"); + Method setDelegateMethod = this.getClass().getMethod("setAccessibilityDelegate", a11yDelegateClass); + setDelegateMethod.invoke(this, m_accessibilityDelegate); + } catch (ClassNotFoundException e) { + // Class not found is fine since we are compatible with Android API < 16, but the function will + // only be available with that API level. + } catch (Exception e) { + // Unknown exception means something went wrong. + Log.w("Qt A11y", "Unknown exception: " + e.toString()); + } } } |