mirror of
https://gitee.com/shuto-github/phonegap-mobile-accessibility.git
synced 2026-05-08 00:00:02 +08:00
Inject AndroidVox locally when there is no network connection.
The WebView typically injects AndroidVox from a Google server when it launches a page with TalkBack enabled, however, in the unlikely event that the app launches without a network connection and AndroidVox has not been cached from an previous connected session, AndroidVox will not start and the app will be inaccessible. We try to mitigate this by injecting AndroidVox from a local path.
This commit is contained in:
+9
-9
@@ -18,6 +18,7 @@
|
||||
</js-module>
|
||||
|
||||
<dependency id="org.apache.cordova.device" url="https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git" />
|
||||
<dependency id="org.apache.cordova.network-information" url="https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git" />
|
||||
|
||||
<!-- ios -->
|
||||
<platform name="ios">
|
||||
@@ -26,25 +27,24 @@
|
||||
<param name="ios-package" value="CDVMobileAccessibility" onload="true" />
|
||||
</feature>
|
||||
</config-file>
|
||||
|
||||
<header-file src="src/ios/CDVMobileAccessibility.h" />
|
||||
<source-file src="src/ios/CDVMobileAccessibility.m" />
|
||||
</platform>
|
||||
|
||||
<!-- android -->
|
||||
<platform name="android">
|
||||
<config-file target="res/xml/config.xml" parent="/*">
|
||||
<config-file target="config.xml" parent="/*">
|
||||
<access origin="https://ssl.gstatic.com/accessibility/javascript/android/*" />
|
||||
<feature name="MobileAccessibility" >
|
||||
<param name="android-package" value="com.phonegap.plugin.mobileaccessibility.MobileAccessibility"/>
|
||||
</feature>
|
||||
<access origin="https://ssl.gstatic.com/accessibility/javascript/android/*" />
|
||||
</config-file>
|
||||
<config-file target="assets/www/config.xml" parent="/*">
|
||||
<feature name="MobileAccessibility" >
|
||||
<param name="android-package" value="com.phonegap.plugin.mobileaccessibility.MobileAccessibility"/>
|
||||
</feature>
|
||||
<access origin="https://ssl.gstatic.com/accessibility/javascript/android/*" />
|
||||
</config-file>
|
||||
<source-file src="src/android/com/phonegap/plugin/mobileaccessibility/MobileAccessibility.java" target-dir="src/com/phonegap/plugin/mobileaccessibility" />
|
||||
<source-file src="src/android/com/phonegap/plugin/mobileaccessibility/AbstractMobileAccessibilityHelper.java" target-dir="src/com/phonegap/plugin/mobileaccessibility" />
|
||||
<source-file src="src/android/com/phonegap/plugin/mobileaccessibility/DonutMobileAccessibilityHelper.java" target-dir="src/com/phonegap/plugin/mobileaccessibility" />
|
||||
<source-file src="src/android/com/phonegap/plugin/mobileaccessibility/IceCreamSandwichMobileAccessibilityHelper.java" target-dir="src/com/phonegap/plugin/mobileaccessibility" />
|
||||
<source-file src="src/android/com/phonegap/plugin/mobileaccessibility/JellyBeanMobileAccessibilityHelper.java" target-dir="src/com/phonegap/plugin/mobileaccessibility" />
|
||||
<source-file src="src/android/com/phonegap/plugin/mobileaccessibility/KitKatMobileAccessibilityHelper.java" target-dir="src/com/phonegap/plugin/mobileaccessibility" />
|
||||
<asset src="www/android" target="plugins/com.phonegap.plugin.mobile-accessibility/android" />
|
||||
</platform>
|
||||
</plugin>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -22,7 +22,9 @@
|
||||
var argscheck = require('cordova/argscheck'),
|
||||
utils = require('cordova/utils'),
|
||||
exec = require('cordova/exec'),
|
||||
device = require('org.apache.cordova.device.device');
|
||||
device = require('org.apache.cordova.device.device'),
|
||||
network = require('org.apache.cordova.network-information.network'),
|
||||
connection = require('org.apache.cordova.network-information.Connection');
|
||||
|
||||
var MobileAccessibility = function() {
|
||||
this._isScreenReaderRunning = false;
|
||||
@@ -95,6 +97,9 @@ MobileAccessibility.prototype.activateOrDeactivateChromeVox = function(bool) {
|
||||
if (typeof cvox === "undefined") {
|
||||
if (bool) {
|
||||
console.warn('A screen reader is running but ChromeVox has failed to initialize.');
|
||||
if (navigator.connection.type === Connection.UNKNOWN || navigator.connection.type === Connection.NONE) {
|
||||
mobileAccessibility.injectLocalAndroidVoxScript();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// activate or deactivate ChromeVox based on whether or not or not the screen reader is running.
|
||||
@@ -106,6 +111,31 @@ MobileAccessibility.prototype.activateOrDeactivateChromeVox = function(bool) {
|
||||
}
|
||||
};
|
||||
|
||||
MobileAccessibility.prototype.scriptInjected = false;
|
||||
MobileAccessibility.prototype.injectLocalAndroidVoxScript = function() {
|
||||
var versionsplit = device.version.split('.');
|
||||
if (device.platform !== "Android" ||
|
||||
!(versionsplit[0] > 4 || (versionsplit[0] == 4 && versionsplit[1] >= 1)) ||
|
||||
typeof cvox !== "undefined" || mobileAccessibility.scriptInjected) return;
|
||||
var script = document.createElement('script');
|
||||
script.type = 'text/javascript';
|
||||
script.async = true;
|
||||
script.onload = function(){
|
||||
// console.log(this.src + ' has loaded');
|
||||
if (mobileAccessibility.isChromeVoxActive()) {
|
||||
cordova.fireWindowEvent("screenreaderstatuschanged", {
|
||||
isScreenReaderRunning: true
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
script.src = (versionsplit[0] > 4 || versionsplit[1] > 3)
|
||||
? "plugins/com.phonegap.plugin.mobile-accessibility/android/chromeandroidvox.js"
|
||||
: "plugins/com.phonegap.plugin.mobile-accessibility/android/AndroidVox_v1.js";
|
||||
document.getElementsByTagName('head')[0].appendChild(script);
|
||||
mobileAccessibility.scriptInjected = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Asynchronous call to native MobileAccessibility to determine if closed captioning is enabled.
|
||||
* @param {function} callback A callback method to receive the asynchronous result from the native MobileAccessibility.
|
||||
|
||||
Reference in New Issue
Block a user