mirror of
https://gitee.com/shuto-github/phonegap-mobile-accessibility.git
synced 2026-02-19 00:07:07 +08:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3224bc2332 | ||
|
|
e3ac5fc92f | ||
|
|
9714162405 | ||
|
|
7961963ac2 | ||
|
|
995295bdcd | ||
|
|
af7394ccd3 | ||
|
|
71640de527 | ||
|
|
188d5c583c | ||
|
|
6fb09a600d | ||
|
|
415b357e9a | ||
|
|
382ba4a835 | ||
|
|
435745aa91 | ||
|
|
3256a29085 | ||
|
|
e9af64bc44 | ||
|
|
3efce21dfd | ||
|
|
37a7d11251 | ||
|
|
b35a21f724 | ||
|
|
852cec5240 | ||
|
|
2fb3aa4c2b | ||
|
|
b8f90d3841 | ||
|
|
d0db5b05b5 | ||
|
|
c924261c26 |
21
README.md
21
README.md
@@ -1,23 +1,4 @@
|
||||
<!--
|
||||
The following copyright message should appear at the top of all
|
||||
source files. This file can be removed from your repository.
|
||||
|
||||
Copyright (c) 2013-2014 Adobe Systems Incorporated. All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
# com.phonegap.plugin.mobile-accessibility
|
||||
# phonegap-plugin-mobile-accessibility
|
||||
==========================================
|
||||
|
||||
This plugin exposes information on the status of various accessibility features of mobile operating systems, including, for example, whether a screen reader is running, invert colors is enabled, and the preferred scaling for text. It also allows an application to send a string to be spoken by the screen reader, or a command to stop the screen reader from speaking.
|
||||
|
||||
37
package.json
Normal file
37
package.json
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "phonegap-plugin-mobile-accessibility",
|
||||
"description": "PhoneGap Mobile Accessibility Plugin",
|
||||
"version": "1.0.3",
|
||||
"homepage": "http://github.com/phonegap/phonegap-mobile-accessibility#readme",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/phonegap/phonegap-mobile-accessibility.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/phonegap/phonegap-mobile-accessibility/issues"
|
||||
},
|
||||
"cordova": {
|
||||
"id": "phonegap-plugin-mobile-accessibility",
|
||||
"platforms": [
|
||||
"ios",
|
||||
"android",
|
||||
"windows"
|
||||
]
|
||||
},
|
||||
"keywords": [
|
||||
"phonegap",
|
||||
"mobile accessibility",
|
||||
"ecosystem:cordova",
|
||||
"cordova-ios",
|
||||
"cordova-android",
|
||||
"cordova-windows"
|
||||
],
|
||||
"engines": [
|
||||
{
|
||||
"name": "cordova",
|
||||
"version": ">=3.0.0"
|
||||
}
|
||||
],
|
||||
"author": "Adobe PhoneGap Team",
|
||||
"license": "Apache 2.0"
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
xmlns:rim="http://www.blackberry.com/ns/widgets"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
id="com.phonegap.plugin.mobile-accessibility"
|
||||
version="0.1.2">
|
||||
id="phonegap-plugin-mobile-accessibility"
|
||||
version="1.0.3">
|
||||
<name>Mobile Accessibility</name>
|
||||
<description>PhoneGap Mobile Accessibility Plugin</description>
|
||||
<license>Apache 2.0</license>
|
||||
@@ -21,8 +20,8 @@
|
||||
<clobbers target="MobileAccessibilityNotifications" />
|
||||
</js-module>
|
||||
|
||||
<dependency id="org.apache.cordova.device" url="https://github.com/apache/cordova-plugin-device.git" />
|
||||
<dependency id="org.apache.cordova.network-information" url="https://github.com/apache/cordova-plugin-network-information.git" />
|
||||
<dependency id="cordova-plugin-device" url="https://github.com/apache/cordova-plugin-device.git" />
|
||||
<dependency id="cordova-plugin-network-information" url="https://github.com/apache/cordova-plugin-network-information.git" />
|
||||
|
||||
<!-- ios -->
|
||||
<platform name="ios">
|
||||
|
||||
@@ -23,9 +23,9 @@ package com.phonegap.plugin.mobileaccessibility;
|
||||
|
||||
import android.view.ViewParent;
|
||||
|
||||
public abstract class AbstractMobileAccessibilityHelper {
|
||||
protected MobileAccessibility mMobileAccessibility;
|
||||
protected ViewParent mParent;
|
||||
abstract class AbstractMobileAccessibilityHelper {
|
||||
MobileAccessibility mMobileAccessibility;
|
||||
ViewParent mParent;
|
||||
public abstract void initialize(MobileAccessibility mobileAccessibility);
|
||||
public abstract boolean isClosedCaptioningEnabled();
|
||||
public abstract boolean isScreenReaderRunning();
|
||||
|
||||
@@ -26,19 +26,40 @@ import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
import android.view.View;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import java.lang.IllegalAccessException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.DONUT)
|
||||
public class DonutMobileAccessibilityHelper extends
|
||||
AbstractMobileAccessibilityHelper {
|
||||
protected AccessibilityManager mAccessibilityManager;
|
||||
protected WebView mWebView;
|
||||
AccessibilityManager mAccessibilityManager;
|
||||
View mView;
|
||||
|
||||
@Override
|
||||
public void initialize(MobileAccessibility mobileAccessibility) {
|
||||
mMobileAccessibility = mobileAccessibility;
|
||||
mWebView = mobileAccessibility.webView;
|
||||
WebView view;
|
||||
try {
|
||||
view = (WebView) mobileAccessibility.webView;
|
||||
mView = view;
|
||||
} catch(ClassCastException ce) { // cordova-android 4.0+
|
||||
try {
|
||||
Method getView = mobileAccessibility.webView.getClass().getMethod("getView");
|
||||
mView = (View) getView.invoke(mobileAccessibility.webView);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
mAccessibilityManager = (AccessibilityManager) mMobileAccessibility.cordova.getActivity().getSystemService(Context.ACCESSIBILITY_SERVICE);
|
||||
}
|
||||
|
||||
@@ -89,9 +110,9 @@ public class DonutMobileAccessibilityHelper extends
|
||||
final int eventType = AccessibilityEvent.TYPE_VIEW_FOCUSED;
|
||||
final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
|
||||
event.getText().add(text);
|
||||
event.setEnabled(mWebView.isEnabled());
|
||||
event.setClassName(mWebView.getClass().getName());
|
||||
event.setPackageName(mWebView.getContext().getPackageName());
|
||||
event.setEnabled(mView.isEnabled());
|
||||
event.setClassName(mView.getClass().getName());
|
||||
event.setPackageName(mView.getContext().getPackageName());
|
||||
event.setContentDescription(null);
|
||||
|
||||
mAccessibilityManager.sendAccessibilityEvent(event);
|
||||
@@ -101,7 +122,23 @@ public class DonutMobileAccessibilityHelper extends
|
||||
@Override
|
||||
public double getTextZoom() {
|
||||
double zoom = 100;
|
||||
WebSettings.TextSize wTextSize = mWebView.getSettings().getTextSize();
|
||||
WebSettings.TextSize wTextSize = WebSettings.TextSize.NORMAL;
|
||||
|
||||
try {
|
||||
Method getSettings = mView.getClass().getMethod("getSettings");
|
||||
Object wSettings = getSettings.invoke(mView);
|
||||
Method getTextSize = wSettings.getClass().getMethod("getTextSize");
|
||||
wTextSize = (WebSettings.TextSize) getTextSize.invoke(wSettings);
|
||||
} catch(ClassCastException ce) {
|
||||
ce.printStackTrace();
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
switch (wTextSize) {
|
||||
case LARGEST:
|
||||
zoom = 200;
|
||||
@@ -109,39 +146,42 @@ public class DonutMobileAccessibilityHelper extends
|
||||
case LARGER:
|
||||
zoom = 150;
|
||||
break;
|
||||
case NORMAL:
|
||||
zoom = 100;
|
||||
break;
|
||||
case SMALLER:
|
||||
zoom = 75;
|
||||
break;
|
||||
case SMALLEST:
|
||||
zoom = 50;
|
||||
break;
|
||||
default:
|
||||
zoom = 100;
|
||||
break;
|
||||
}
|
||||
|
||||
return zoom;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void setTextZoom(double textZoom) {
|
||||
final double zoom = textZoom;
|
||||
WebSettings.TextSize wTextSize = WebSettings.TextSize.NORMAL;
|
||||
if (zoom > 115) {
|
||||
WebSettings.TextSize wTextSize = WebSettings.TextSize.SMALLEST;
|
||||
if (textZoom > 115) {
|
||||
wTextSize = WebSettings.TextSize.LARGEST;
|
||||
} else if (zoom > 100) {
|
||||
} else if (textZoom > 100) {
|
||||
wTextSize = WebSettings.TextSize.LARGER;
|
||||
} else if (zoom == 100) {
|
||||
} else if (textZoom == 100) {
|
||||
wTextSize = WebSettings.TextSize.NORMAL;
|
||||
} else if (zoom > 50) {
|
||||
} else if (textZoom > 50) {
|
||||
wTextSize = WebSettings.TextSize.SMALLER;
|
||||
} else {
|
||||
wTextSize = WebSettings.TextSize.SMALLEST;
|
||||
}
|
||||
//Log.i("MobileAccessibility", "fontScale = " + zoom + ", WebSettings.TextSize = " + wTextSize.toString());
|
||||
mWebView.getSettings().setTextSize(wTextSize);
|
||||
try {
|
||||
Method getSettings = mView.getClass().getMethod("getSettings");
|
||||
Object wSettings = getSettings.invoke(mView);
|
||||
Method setTextSize = wSettings.getClass().getMethod("setTextSize", WebSettings.TextSize.class);
|
||||
setTextSize.invoke(wSettings, wTextSize);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,14 @@ import android.annotation.TargetApi;
|
||||
import android.os.Build;
|
||||
import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener;
|
||||
|
||||
import java.lang.IllegalAccessException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
||||
public class IceCreamSandwichMobileAccessibilityHelper extends
|
||||
DonutMobileAccessibilityHelper {
|
||||
protected AccessibilityStateChangeListener mAccessibilityStateChangeListener;
|
||||
private AccessibilityStateChangeListener mAccessibilityStateChangeListener;
|
||||
|
||||
@Override
|
||||
public boolean isScreenReaderRunning() {
|
||||
@@ -52,17 +56,44 @@ public class IceCreamSandwichMobileAccessibilityHelper extends
|
||||
|
||||
@Override
|
||||
public double getTextZoom() {
|
||||
return mWebView.getSettings().getTextZoom();
|
||||
double zoom = 100;
|
||||
try {
|
||||
Method getSettings = mView.getClass().getMethod("getSettings");
|
||||
Object wSettings = getSettings.invoke(mView);
|
||||
Method getTextZoom = wSettings.getClass().getMethod("getTextZoom");
|
||||
zoom = Double.valueOf(getTextZoom.invoke(wSettings).toString());
|
||||
} catch (ClassCastException ce) {
|
||||
ce.printStackTrace();
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return zoom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTextZoom(double textZoom) {
|
||||
final double zoom = textZoom;
|
||||
//Log.i("MobileAccessibility", "setTextZoom(" + zoom + ")");
|
||||
mWebView.getSettings().setTextZoom((int) zoom);
|
||||
try {
|
||||
Method getSettings = mView.getClass().getMethod("getSettings");
|
||||
Object wSettings = getSettings.invoke(mView);
|
||||
Method setTextZoom = wSettings.getClass().getMethod("setTextZoom", Integer.TYPE);
|
||||
setTextZoom.invoke(wSettings, (int) textZoom);
|
||||
} catch (ClassCastException ce) {
|
||||
ce.printStackTrace();
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected class InternalAccessibilityStateChangeListener
|
||||
private class InternalAccessibilityStateChangeListener
|
||||
implements AccessibilityStateChangeListener {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,7 +34,7 @@ public class JellyBeanMobileAccessibilityHelper extends
|
||||
@Override
|
||||
public void initialize(MobileAccessibility mobileAccessibility) {
|
||||
super.initialize(mobileAccessibility);
|
||||
mParent = mobileAccessibility.webView.getParentForAccessibility();
|
||||
mParent = mView.getParentForAccessibility();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,10 +43,10 @@ public class JellyBeanMobileAccessibilityHelper extends
|
||||
mAccessibilityManager.interrupt();
|
||||
AccessibilityEvent event = AccessibilityEvent.obtain(
|
||||
AccessibilityEvent.TYPE_ANNOUNCEMENT);
|
||||
mWebView.onInitializeAccessibilityEvent(event);
|
||||
mView.onInitializeAccessibilityEvent(event);
|
||||
event.getText().add(text);
|
||||
event.setContentDescription(null);
|
||||
mParent.requestSendAccessibilityEvent(mWebView, event);
|
||||
mParent.requestSendAccessibilityEvent(mView, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,9 +31,9 @@ import android.view.accessibility.CaptioningManager.CaptioningChangeListener;
|
||||
@TargetApi(19)
|
||||
public class KitKatMobileAccessibilityHelper extends
|
||||
JellyBeanMobileAccessibilityHelper {
|
||||
protected CaptioningManager mCaptioningManager;
|
||||
protected CaptioningChangeListener mCaptioningChangeListener;
|
||||
protected TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
|
||||
private CaptioningManager mCaptioningManager;
|
||||
private CaptioningChangeListener mCaptioningChangeListener;
|
||||
private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
|
||||
|
||||
@Override
|
||||
public void initialize(MobileAccessibility mobileAccessibility) {
|
||||
@@ -61,7 +61,6 @@ public class KitKatMobileAccessibilityHelper extends
|
||||
super.addStateChangeListeners();
|
||||
if (mCaptioningChangeListener == null) {
|
||||
mCaptioningChangeListener = new CaptioningChangeListener() {
|
||||
/** @hide */
|
||||
@Override
|
||||
public void onEnabledChanged(boolean enabled) {
|
||||
onCaptioningEnabledChanged(enabled);
|
||||
@@ -89,7 +88,7 @@ public class KitKatMobileAccessibilityHelper extends
|
||||
}
|
||||
}
|
||||
|
||||
protected class InternalTouchExplorationStateChangeListener
|
||||
private class InternalTouchExplorationStateChangeListener
|
||||
implements TouchExplorationStateChangeListener {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,18 +31,23 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.os.Build;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import java.lang.IllegalAccessException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* This class provides information on the status of native accessibility services to JavaScript.
|
||||
*/
|
||||
public class MobileAccessibility extends CordovaPlugin {
|
||||
protected AbstractMobileAccessibilityHelper mMobileAccessibilityHelper;
|
||||
protected CallbackContext mCallbackContext = null;
|
||||
protected boolean mIsScreenReaderRunning = false;
|
||||
protected boolean mClosedCaptioningEnabled = false;
|
||||
protected boolean mTouchExplorationEnabled = false;
|
||||
protected boolean mCachedIsScreenReaderRunning = false;
|
||||
protected float mFontScale = 1;
|
||||
private AbstractMobileAccessibilityHelper mMobileAccessibilityHelper;
|
||||
private CallbackContext mCallbackContext = null;
|
||||
private boolean mIsScreenReaderRunning = false;
|
||||
private boolean mClosedCaptioningEnabled = false;
|
||||
private boolean mTouchExplorationEnabled = false;
|
||||
private boolean mCachedIsScreenReaderRunning = false;
|
||||
private float mFontScale = 1;
|
||||
|
||||
@Override
|
||||
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
||||
@@ -132,9 +137,25 @@ public class MobileAccessibility extends CordovaPlugin {
|
||||
stop();
|
||||
cordova.getActivity().runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
webView.reload();
|
||||
WebView view;
|
||||
try {
|
||||
view = (WebView) webView;
|
||||
view.reload();
|
||||
} catch(ClassCastException ce) { // cordova-android 4.0+
|
||||
try { // cordova-android 4.0+
|
||||
Method getView = webView.getClass().getMethod("getView");
|
||||
Method reload = getView.invoke(webView).getClass().getMethod("reload");
|
||||
reload.invoke(webView);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,14 +166,13 @@ public class MobileAccessibility extends CordovaPlugin {
|
||||
stop();
|
||||
}
|
||||
|
||||
protected boolean isScreenReaderRunning(final CallbackContext callbackContext) {
|
||||
private void isScreenReaderRunning(final CallbackContext callbackContext) {
|
||||
mIsScreenReaderRunning = mMobileAccessibilityHelper.isScreenReaderRunning();
|
||||
cordova.getThreadPool().execute(new Runnable() {
|
||||
public void run() {
|
||||
callbackContext.success(mIsScreenReaderRunning ? 1 : 0);
|
||||
}
|
||||
});
|
||||
return mIsScreenReaderRunning;
|
||||
}
|
||||
|
||||
protected boolean isScreenReaderRunning() {
|
||||
@@ -160,14 +180,13 @@ public class MobileAccessibility extends CordovaPlugin {
|
||||
return mIsScreenReaderRunning;
|
||||
}
|
||||
|
||||
protected boolean isClosedCaptioningEnabled(final CallbackContext callbackContext) {
|
||||
private void isClosedCaptioningEnabled(final CallbackContext callbackContext) {
|
||||
mClosedCaptioningEnabled = mMobileAccessibilityHelper.isClosedCaptioningEnabled();
|
||||
cordova.getThreadPool().execute(new Runnable() {
|
||||
public void run() {
|
||||
callbackContext.success(mClosedCaptioningEnabled ? 1 : 0);
|
||||
}
|
||||
});
|
||||
return mClosedCaptioningEnabled;
|
||||
}
|
||||
|
||||
protected boolean isClosedCaptioningEnabled() {
|
||||
@@ -175,14 +194,13 @@ public class MobileAccessibility extends CordovaPlugin {
|
||||
return mClosedCaptioningEnabled;
|
||||
}
|
||||
|
||||
protected boolean isTouchExplorationEnabled(final CallbackContext callbackContext) {
|
||||
private void isTouchExplorationEnabled(final CallbackContext callbackContext) {
|
||||
mTouchExplorationEnabled= mMobileAccessibilityHelper.isTouchExplorationEnabled();
|
||||
cordova.getThreadPool().execute(new Runnable() {
|
||||
public void run() {
|
||||
callbackContext.success(mTouchExplorationEnabled ? 1 : 0);
|
||||
}
|
||||
});
|
||||
return mTouchExplorationEnabled;
|
||||
}
|
||||
|
||||
protected boolean isTouchExplorationEnabled() {
|
||||
@@ -190,7 +208,7 @@ public class MobileAccessibility extends CordovaPlugin {
|
||||
return mTouchExplorationEnabled;
|
||||
}
|
||||
|
||||
protected void announceForAccessibility(CharSequence text, final CallbackContext callbackContext) {
|
||||
private void announceForAccessibility(CharSequence text, final CallbackContext callbackContext) {
|
||||
mMobileAccessibilityHelper.announceForAccessibility(text);
|
||||
if (callbackContext != null) {
|
||||
JSONObject info = new JSONObject();
|
||||
@@ -231,7 +249,7 @@ public class MobileAccessibility extends CordovaPlugin {
|
||||
});
|
||||
}
|
||||
|
||||
public void getTextZoom(final CallbackContext callbackContext) {
|
||||
private void getTextZoom(final CallbackContext callbackContext) {
|
||||
cordova.getActivity().runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
final double textZoom = mMobileAccessibilityHelper.getTextZoom();
|
||||
@@ -242,13 +260,13 @@ public class MobileAccessibility extends CordovaPlugin {
|
||||
});
|
||||
}
|
||||
|
||||
public void setTextZoom(final double textZoom, final CallbackContext callbackContext) {
|
||||
private void setTextZoom(final double textZoom, final CallbackContext callbackContext) {
|
||||
cordova.getActivity().runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
mMobileAccessibilityHelper.setTextZoom(textZoom);
|
||||
if (callbackContext != null) {
|
||||
callbackContext.success((int) mMobileAccessibilityHelper.getTextZoom());
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -261,7 +279,7 @@ public class MobileAccessibility extends CordovaPlugin {
|
||||
});
|
||||
}
|
||||
|
||||
public void updateTextZoom(final CallbackContext callbackContext) {
|
||||
private void updateTextZoom(final CallbackContext callbackContext) {
|
||||
float fontScale = cordova.getActivity().getResources().getConfiguration().fontScale;
|
||||
if (fontScale != mFontScale) {
|
||||
mFontScale = fontScale;
|
||||
@@ -270,7 +288,7 @@ public class MobileAccessibility extends CordovaPlugin {
|
||||
setTextZoom(textZoom, callbackContext);
|
||||
}
|
||||
|
||||
protected void sendMobileAccessibilityStatusChangedCallback() {
|
||||
private void sendMobileAccessibilityStatusChangedCallback() {
|
||||
if (this.mCallbackContext != null) {
|
||||
PluginResult result = new PluginResult(PluginResult.Status.OK, getMobileAccessibilityStatus());
|
||||
result.setKeepCallback(true);
|
||||
@@ -279,7 +297,7 @@ public class MobileAccessibility extends CordovaPlugin {
|
||||
}
|
||||
|
||||
/* Get the current mobile accessibility status. */
|
||||
protected JSONObject getMobileAccessibilityStatus() {
|
||||
private JSONObject getMobileAccessibilityStatus() {
|
||||
JSONObject status = new JSONObject();
|
||||
try {
|
||||
status.put("isScreenReaderRunning", mIsScreenReaderRunning);
|
||||
@@ -294,14 +312,14 @@ public class MobileAccessibility extends CordovaPlugin {
|
||||
return status;
|
||||
}
|
||||
|
||||
protected void start(CallbackContext callbackContext) {
|
||||
private void start(CallbackContext callbackContext) {
|
||||
//Log.i("MobileAccessibility", "MobileAccessibility.start");
|
||||
mCallbackContext = callbackContext;
|
||||
mMobileAccessibilityHelper.addStateChangeListeners();
|
||||
sendMobileAccessibilityStatusChangedCallback();
|
||||
}
|
||||
|
||||
protected void stop() {
|
||||
private void stop() {
|
||||
//Log.i("MobileAccessibility", "MobileAccessibility.stop");
|
||||
if (mCallbackContext != null) {
|
||||
sendMobileAccessibilityStatusChangedCallback();
|
||||
|
||||
@@ -180,7 +180,7 @@
|
||||
mFontScale = zoom/100;
|
||||
if (iOS7Delta) {
|
||||
NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '%f%%'", zoom];
|
||||
[[self webView] stringByEvaluatingJavaScriptFromString:jsString];
|
||||
[self.commandDelegate evalJs:jsString];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,10 +22,10 @@
|
||||
var argscheck = require('cordova/argscheck'),
|
||||
utils = require('cordova/utils'),
|
||||
exec = require('cordova/exec'),
|
||||
device = require('org.apache.cordova.device.device'),
|
||||
network = require('org.apache.cordova.network-information.network'),
|
||||
connection = require('org.apache.cordova.network-information.Connection'),
|
||||
MobileAccessibilityNotifications = require('com.phonegap.plugin.mobile-accessibility.MobileAccessibilityNotifications');
|
||||
device = require('cordova-plugin-device.device'),
|
||||
network = require('cordova-plugin-network-information.network'),
|
||||
connection = require('cordova-plugin-network-information.Connection'),
|
||||
MobileAccessibilityNotifications = require('phonegap-plugin-mobile-accessibility.MobileAccessibilityNotifications');
|
||||
|
||||
var MobileAccessibility = function() {
|
||||
this._isScreenReaderRunning = false;
|
||||
@@ -255,11 +255,19 @@ MobileAccessibility.prototype.usePreferredTextZoom = function(bool) {
|
||||
window.localStorage.setItem("MobileAccessibility.usePreferredTextZoom", bool);
|
||||
}
|
||||
|
||||
document.removeEventListener("resume", mobileAccessibility.updateTextZoom);
|
||||
var callback = function(){
|
||||
// Wrapping updateTextZoom call in a function to stop
|
||||
// the event parameter propagation. This fixes an error
|
||||
// on resume where cordova tried to call apply() on the
|
||||
// event, expecting a function.
|
||||
mobileAccessibility.updateTextZoom();
|
||||
};
|
||||
|
||||
document.removeEventListener("resume", callback);
|
||||
|
||||
if (bool) {
|
||||
// console.log("We should update the text zoom at this point: " + bool)
|
||||
document.addEventListener("resume", mobileAccessibility.updateTextZoom, false);
|
||||
document.addEventListener("resume", callback, false);
|
||||
mobileAccessibility.updateTextZoom();
|
||||
} else {
|
||||
mobileAccessibility.setTextZoom(100);
|
||||
|
||||
Reference in New Issue
Block a user