Android: Delay initialization of Accessibility.
The accessibility class was created and activated in onCreate(), which meant we where trying to activate accessibility before the platform plugin was properly initialized. With this change we will also activate, or deactivate, accessibility in Qt whenever the state is changed by Android, compared to doing it at start-up only. Task-number: QTBUG-46355 Change-Id: I5cbae125df43f7694d4464d5054e6cfec4626e26 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>bb10
parent
42f5f03d0a
commit
5ef662f1af
|
|
@ -107,10 +107,6 @@ public class QtAccessibilityDelegate extends View.AccessibilityDelegate
|
|||
if (m_manager.isEnabled())
|
||||
accServiceListener.onAccessibilityStateChanged(true);
|
||||
}
|
||||
|
||||
|
||||
// Enable Qt Accessibility so that notifications are enabled
|
||||
QtNativeAccessibility.setActive(true);
|
||||
}
|
||||
|
||||
private class AccessibilityManagerListener implements AccessibilityManager.AccessibilityStateChangeListener
|
||||
|
|
@ -119,8 +115,6 @@ public class QtAccessibilityDelegate extends View.AccessibilityDelegate
|
|||
public void onAccessibilityStateChanged(boolean enabled)
|
||||
{
|
||||
if (enabled) {
|
||||
// The accessibility code depends on android API level 16, so dynamically resolve it
|
||||
if (android.os.Build.VERSION.SDK_INT >= 16) {
|
||||
try {
|
||||
View view = m_view;
|
||||
if (view == null) {
|
||||
|
|
@ -147,13 +141,14 @@ public class QtAccessibilityDelegate extends View.AccessibilityDelegate
|
|||
// Unknown exception means something went wrong.
|
||||
Log.w("Qt A11y", "Unknown exception: " + e.toString());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (m_view != null) {
|
||||
m_layout.removeView(m_view);
|
||||
m_view = null;
|
||||
}
|
||||
}
|
||||
|
||||
QtNativeAccessibility.setActive(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -794,23 +794,6 @@ public class QtActivityDelegate
|
|||
m_surfaces = new HashMap<Integer, QtSurface>();
|
||||
m_nativeViews = new HashMap<Integer, View>();
|
||||
m_activity.registerForContextMenu(m_layout);
|
||||
|
||||
// Initialize accessibility
|
||||
try {
|
||||
final String a11yDelegateClassName = "org.qtproject.qt5.android.accessibility.QtAccessibilityDelegate";
|
||||
Class<?> qtDelegateClass = Class.forName(a11yDelegateClassName);
|
||||
Constructor constructor = qtDelegateClass.getConstructor(android.app.Activity.class,
|
||||
android.view.ViewGroup.class,
|
||||
this.getClass());
|
||||
Object accessibilityDelegate = constructor.newInstance(m_activity, m_layout, this);
|
||||
} 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());
|
||||
}
|
||||
|
||||
m_activity.setContentView(m_layout,
|
||||
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
|
|
@ -828,6 +811,25 @@ public class QtActivityDelegate
|
|||
m_currentRotation = rotation;
|
||||
}
|
||||
|
||||
public void initializeAccessibility()
|
||||
{
|
||||
// Initialize accessibility
|
||||
try {
|
||||
final String a11yDelegateClassName = "org.qtproject.qt5.android.accessibility.QtAccessibilityDelegate";
|
||||
Class<?> qtDelegateClass = Class.forName(a11yDelegateClassName);
|
||||
Constructor constructor = qtDelegateClass.getConstructor(android.app.Activity.class,
|
||||
android.view.ViewGroup.class,
|
||||
this.getClass());
|
||||
Object accessibilityDelegate = constructor.newInstance(m_activity, m_layout, this);
|
||||
} 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());
|
||||
}
|
||||
}
|
||||
|
||||
public void onConfigurationChanged(Configuration configuration)
|
||||
{
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -571,6 +571,16 @@ public class QtNative
|
|||
});
|
||||
}
|
||||
|
||||
private static void initializeAccessibility()
|
||||
{
|
||||
runAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
m_activityDelegate.initializeAccessibility();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// screen methods
|
||||
public static native void setDisplayMetrics(int screenWidthPixels,
|
||||
int screenHeightPixels,
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@
|
|||
#include "QtGui/qaccessible.h"
|
||||
#include <QtCore/qmath.h>
|
||||
#include <QtCore/private/qjnihelpers_p.h>
|
||||
#include <QtCore/private/qjni_p.h>
|
||||
|
||||
#include "qdebug.h"
|
||||
|
||||
|
|
@ -65,6 +66,15 @@ namespace QtAndroidAccessibility
|
|||
static jmethodID m_setTextSelectionMethodID = 0;
|
||||
static jmethodID m_setVisibleToUserMethodID = 0;
|
||||
|
||||
void initialize()
|
||||
{
|
||||
// API level > 16 is required.
|
||||
if (QtAndroidPrivate::androidSdkVersion() < 16)
|
||||
return;
|
||||
|
||||
QJNIObjectPrivate::callStaticMethod<void>(QtAndroid::applicationClass(),
|
||||
"initializeAccessibility");
|
||||
}
|
||||
|
||||
static void setActive(JNIEnv */*env*/, jobject /*thiz*/, jboolean active)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ QT_BEGIN_NAMESPACE
|
|||
|
||||
namespace QtAndroidAccessibility
|
||||
{
|
||||
void initialize();
|
||||
bool registerNatives(JNIEnv *env);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,11 +33,14 @@
|
|||
|
||||
|
||||
#include "qandroidplatformaccessibility.h"
|
||||
#include "androidjniaccessibility.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QAndroidPlatformAccessibility::QAndroidPlatformAccessibility()
|
||||
{}
|
||||
{
|
||||
QtAndroidAccessibility::initialize();
|
||||
}
|
||||
|
||||
QAndroidPlatformAccessibility::~QAndroidPlatformAccessibility()
|
||||
{}
|
||||
|
|
|
|||
|
|
@ -148,6 +148,10 @@ QAndroidPlatformIntegration::QAndroidPlatformIntegration(const QStringList ¶
|
|||
|
||||
m_androidSystemLocale = new QAndroidSystemLocale;
|
||||
|
||||
#ifndef QT_NO_ACCESSIBILITY
|
||||
m_accessibility = new QAndroidPlatformAccessibility();
|
||||
#endif // QT_NO_ACCESSIBILITY
|
||||
|
||||
QJNIObjectPrivate javaActivity(QtAndroid::activity());
|
||||
if (javaActivity.isValid()) {
|
||||
QJNIObjectPrivate resources = javaActivity.callObjectMethod("getResources", "()Landroid/content/res/Resources;");
|
||||
|
|
@ -348,8 +352,6 @@ void QAndroidPlatformIntegration::setScreenOrientation(Qt::ScreenOrientation cur
|
|||
#ifndef QT_NO_ACCESSIBILITY
|
||||
QPlatformAccessibility *QAndroidPlatformIntegration::accessibility() const
|
||||
{
|
||||
if (!m_accessibility)
|
||||
m_accessibility = new QAndroidPlatformAccessibility();
|
||||
return m_accessibility;
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue