summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/android/src
diff options
context:
space:
mode:
Diffstat (limited to 'StoneIsland/platforms/android/src')
-rw-r--r--StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/AbstractMobileAccessibilityHelper.java41
-rw-r--r--StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/DonutMobileAccessibilityHelper.java187
-rw-r--r--StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/IceCreamSandwichMobileAccessibilityHelper.java104
-rw-r--r--StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/JellyBeanMobileAccessibilityHelper.java52
-rw-r--r--StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/KitKatMobileAccessibilityHelper.java99
-rw-r--r--StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/MobileAccessibility.java330
6 files changed, 813 insertions, 0 deletions
diff --git a/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/AbstractMobileAccessibilityHelper.java b/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/AbstractMobileAccessibilityHelper.java
new file mode 100644
index 00000000..d76a951f
--- /dev/null
+++ b/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/AbstractMobileAccessibilityHelper.java
@@ -0,0 +1,41 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *
+*/
+
+package com.phonegap.plugin.mobileaccessibility;
+
+import android.view.ViewParent;
+
+abstract class AbstractMobileAccessibilityHelper {
+ MobileAccessibility mMobileAccessibility;
+ ViewParent mParent;
+ public abstract void initialize(MobileAccessibility mobileAccessibility);
+ public abstract boolean isClosedCaptioningEnabled();
+ public abstract boolean isScreenReaderRunning();
+ public abstract boolean isTouchExplorationEnabled();
+ public abstract void onAccessibilityStateChanged(boolean enabled);
+ public abstract void onCaptioningEnabledChanged(boolean enabled);
+ public abstract void onTouchExplorationStateChanged(boolean enabled);
+ public abstract void addStateChangeListeners();
+ public abstract void removeStateChangeListeners();
+ public abstract void announceForAccessibility(CharSequence text);
+ public abstract double getTextZoom();
+ public abstract void setTextZoom(double textZoom);
+}
diff --git a/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/DonutMobileAccessibilityHelper.java b/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/DonutMobileAccessibilityHelper.java
new file mode 100644
index 00000000..e6972719
--- /dev/null
+++ b/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/DonutMobileAccessibilityHelper.java
@@ -0,0 +1,187 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *
+*/
+
+package com.phonegap.plugin.mobileaccessibility;
+
+import android.annotation.TargetApi;
+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 {
+ AccessibilityManager mAccessibilityManager;
+ View mView;
+
+ @Override
+ public void initialize(MobileAccessibility mobileAccessibility) {
+ mMobileAccessibility = mobileAccessibility;
+ 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);
+ }
+
+ @Override
+ public boolean isClosedCaptioningEnabled() {
+ return false;
+ }
+
+ @Override
+ public boolean isScreenReaderRunning() {
+ return mAccessibilityManager.isEnabled();
+ }
+
+ @Override
+ public boolean isTouchExplorationEnabled() {
+ return false;
+ }
+
+ @Override
+ public void onAccessibilityStateChanged(boolean enabled) {
+ mMobileAccessibility.onAccessibilityStateChanged(enabled);
+ }
+
+ @Override
+ public void onCaptioningEnabledChanged(boolean enabled) {
+ mMobileAccessibility.onCaptioningEnabledChanged(enabled);
+ }
+
+ @Override
+ public void onTouchExplorationStateChanged(boolean enabled) {
+ mMobileAccessibility.onTouchExplorationStateChanged(enabled);
+ }
+
+ @Override
+ public void addStateChangeListeners() {
+ }
+
+ @Override
+ public void removeStateChangeListeners() {
+ }
+
+ @Override
+ public void announceForAccessibility(CharSequence text) {
+ if (!mAccessibilityManager.isEnabled()) {
+ return;
+ }
+
+ final int eventType = AccessibilityEvent.TYPE_VIEW_FOCUSED;
+ final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
+ event.getText().add(text);
+ event.setEnabled(mView.isEnabled());
+ event.setClassName(mView.getClass().getName());
+ event.setPackageName(mView.getContext().getPackageName());
+ event.setContentDescription(null);
+
+ mAccessibilityManager.sendAccessibilityEvent(event);
+ }
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public double getTextZoom() {
+ double zoom = 100;
+ 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;
+ break;
+ case LARGER:
+ zoom = 150;
+ break;
+ case SMALLER:
+ zoom = 75;
+ break;
+ case SMALLEST:
+ zoom = 50;
+ break;
+ }
+
+ return zoom;
+ }
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public void setTextZoom(double textZoom) {
+ WebSettings.TextSize wTextSize = WebSettings.TextSize.SMALLEST;
+ if (textZoom > 115) {
+ wTextSize = WebSettings.TextSize.LARGEST;
+ } else if (textZoom > 100) {
+ wTextSize = WebSettings.TextSize.LARGER;
+ } else if (textZoom == 100) {
+ wTextSize = WebSettings.TextSize.NORMAL;
+ } else if (textZoom > 50) {
+ wTextSize = WebSettings.TextSize.SMALLER;
+ }
+ //Log.i("MobileAccessibility", "fontScale = " + zoom + ", WebSettings.TextSize = " + wTextSize.toString());
+ 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();
+ }
+ }
+}
diff --git a/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/IceCreamSandwichMobileAccessibilityHelper.java b/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/IceCreamSandwichMobileAccessibilityHelper.java
new file mode 100644
index 00000000..f0cd252e
--- /dev/null
+++ b/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/IceCreamSandwichMobileAccessibilityHelper.java
@@ -0,0 +1,104 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *
+*/
+
+package com.phonegap.plugin.mobileaccessibility;
+
+import android.accessibilityservice.AccessibilityServiceInfo;
+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 {
+ private AccessibilityStateChangeListener mAccessibilityStateChangeListener;
+
+ @Override
+ public boolean isScreenReaderRunning() {
+ return mAccessibilityManager.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_SPOKEN).size() > 0;
+ }
+
+ @Override
+ public void addStateChangeListeners() {
+ if (mAccessibilityStateChangeListener == null) {
+ mAccessibilityStateChangeListener = new InternalAccessibilityStateChangeListener();
+ }
+ mAccessibilityManager.addAccessibilityStateChangeListener(mAccessibilityStateChangeListener);
+ }
+
+ @Override
+ public void removeStateChangeListeners() {
+ mAccessibilityManager.removeAccessibilityStateChangeListener(mAccessibilityStateChangeListener);
+ mAccessibilityStateChangeListener = null;
+ }
+
+ @Override
+ public double 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) {
+ //Log.i("MobileAccessibility", "setTextZoom(" + 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();
+ }
+ }
+
+ private class InternalAccessibilityStateChangeListener
+ implements AccessibilityStateChangeListener {
+
+ @Override
+ public void onAccessibilityStateChanged(boolean enabled) {
+ mMobileAccessibility.onAccessibilityStateChanged(enabled);
+ }
+ }
+}
diff --git a/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/JellyBeanMobileAccessibilityHelper.java b/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/JellyBeanMobileAccessibilityHelper.java
new file mode 100644
index 00000000..7c97d247
--- /dev/null
+++ b/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/JellyBeanMobileAccessibilityHelper.java
@@ -0,0 +1,52 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *
+*/
+
+package com.phonegap.plugin.mobileaccessibility;
+
+import com.phonegap.plugin.mobileaccessibility.MobileAccessibility;
+
+import android.annotation.TargetApi;
+import android.os.Build;
+import android.view.accessibility.AccessibilityEvent;
+
+@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
+public class JellyBeanMobileAccessibilityHelper extends
+ IceCreamSandwichMobileAccessibilityHelper {
+
+ @Override
+ public void initialize(MobileAccessibility mobileAccessibility) {
+ super.initialize(mobileAccessibility);
+ mParent = mView.getParentForAccessibility();
+ }
+
+ @Override
+ public void announceForAccessibility(CharSequence text) {
+ if (mAccessibilityManager.isEnabled() && mParent != null) {
+ mAccessibilityManager.interrupt();
+ AccessibilityEvent event = AccessibilityEvent.obtain(
+ AccessibilityEvent.TYPE_ANNOUNCEMENT);
+ mView.onInitializeAccessibilityEvent(event);
+ event.getText().add(text);
+ event.setContentDescription(null);
+ mParent.requestSendAccessibilityEvent(mView, event);
+ }
+ }
+}
diff --git a/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/KitKatMobileAccessibilityHelper.java b/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/KitKatMobileAccessibilityHelper.java
new file mode 100644
index 00000000..11d342cb
--- /dev/null
+++ b/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/KitKatMobileAccessibilityHelper.java
@@ -0,0 +1,99 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *
+*/
+
+package com.phonegap.plugin.mobileaccessibility;
+
+import android.accessibilityservice.AccessibilityServiceInfo;
+import android.annotation.TargetApi;
+import android.content.Context;
+import android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener;
+import android.view.accessibility.CaptioningManager;
+import android.view.accessibility.CaptioningManager.CaptioningChangeListener;
+
+@TargetApi(19)
+public class KitKatMobileAccessibilityHelper extends
+ JellyBeanMobileAccessibilityHelper {
+ private CaptioningManager mCaptioningManager;
+ private CaptioningChangeListener mCaptioningChangeListener;
+ private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
+
+ @Override
+ public void initialize(MobileAccessibility mobileAccessibility) {
+ super.initialize(mobileAccessibility);
+ mCaptioningManager = (CaptioningManager) mobileAccessibility.cordova.getActivity().getSystemService(Context.CAPTIONING_SERVICE);
+ }
+
+ @Override
+ public boolean isScreenReaderRunning() {
+ return mAccessibilityManager.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_BRAILLE | AccessibilityServiceInfo.FEEDBACK_SPOKEN).size() > 0;
+ }
+
+ @Override
+ public boolean isClosedCaptioningEnabled() {
+ return mCaptioningManager.isEnabled();
+ }
+
+ @Override
+ public boolean isTouchExplorationEnabled() {
+ return mAccessibilityManager.isTouchExplorationEnabled();
+ }
+
+ @Override
+ public void addStateChangeListeners() {
+ super.addStateChangeListeners();
+ if (mCaptioningChangeListener == null) {
+ mCaptioningChangeListener = new CaptioningChangeListener() {
+ @Override
+ public void onEnabledChanged(boolean enabled) {
+ onCaptioningEnabledChanged(enabled);
+ }
+ };
+ }
+ mCaptioningManager.addCaptioningChangeListener(mCaptioningChangeListener);
+
+ if (mTouchExplorationStateChangeListener == null) {
+ mTouchExplorationStateChangeListener = new InternalTouchExplorationStateChangeListener();
+ }
+ mAccessibilityManager.addTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
+ }
+
+ @Override
+ public void removeStateChangeListeners() {
+ super.removeStateChangeListeners();
+ if (mCaptioningChangeListener != null) {
+ mCaptioningManager.removeCaptioningChangeListener(mCaptioningChangeListener);
+ mCaptioningChangeListener = null;
+ }
+ if (mTouchExplorationStateChangeListener != null) {
+ mAccessibilityManager.removeTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
+ mTouchExplorationStateChangeListener = null;
+ }
+ }
+
+ private class InternalTouchExplorationStateChangeListener
+ implements TouchExplorationStateChangeListener {
+
+ @Override
+ public void onTouchExplorationStateChanged(boolean enabled) {
+ mMobileAccessibility.onTouchExplorationStateChanged(enabled);
+ }
+ }
+}
diff --git a/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/MobileAccessibility.java b/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/MobileAccessibility.java
new file mode 100644
index 00000000..a979420e
--- /dev/null
+++ b/StoneIsland/platforms/android/src/com/phonegap/plugin/mobileaccessibility/MobileAccessibility.java
@@ -0,0 +1,330 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *
+*/
+
+package com.phonegap.plugin.mobileaccessibility;
+
+import org.apache.cordova.CallbackContext;
+import org.apache.cordova.CordovaInterface;
+import org.apache.cordova.CordovaPlugin;
+import org.apache.cordova.CordovaWebView;
+import org.apache.cordova.PluginResult;
+import org.json.JSONArray;
+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 {
+ 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) {
+ super.initialize(cordova, webView);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ mMobileAccessibilityHelper = new KitKatMobileAccessibilityHelper();
+ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ mMobileAccessibilityHelper = new JellyBeanMobileAccessibilityHelper();
+ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
+ mMobileAccessibilityHelper = new IceCreamSandwichMobileAccessibilityHelper();
+ } else {
+ mMobileAccessibilityHelper = new DonutMobileAccessibilityHelper();
+ }
+ mMobileAccessibilityHelper.initialize(this);
+ }
+
+ @Override
+ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
+ try {
+ if (action.equals("isScreenReaderRunning")) {
+ isScreenReaderRunning(callbackContext);
+ return true;
+ } else if (action.equals("isClosedCaptioningEnabled")) {
+ isClosedCaptioningEnabled(callbackContext);
+ return true;
+ } else if (action.equals("isTouchExplorationEnabled")) {
+ isTouchExplorationEnabled(callbackContext);
+ return true;
+ } else if (action.equals("postNotification")) {
+ if (args.length() > 1) {
+ String string = args.getString(1);
+ if (!string.isEmpty()) {
+ announceForAccessibility(string, callbackContext);
+ }
+ }
+ return true;
+ } else if(action.equals("getTextZoom")) {
+ getTextZoom(callbackContext);
+ return true;
+ } else if(action.equals("setTextZoom")) {
+ if (args.length() > 0) {
+ double textZoom = args.getDouble(0);
+ if (textZoom > 0) {
+ setTextZoom(textZoom, callbackContext);
+ }
+ }
+ return true;
+ } else if(action.equals("updateTextZoom")) {
+ updateTextZoom(callbackContext);
+ return true;
+ } else if (action.equals("start")) {
+ start(callbackContext);
+ return true;
+ } else if (action.equals("stop")) {
+ stop();
+ return true;
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
+ }
+ return false;
+ }
+
+ /**
+ * Called when the system is about to pause the current activity
+ *
+ * @param multitasking Flag indicating if multitasking is turned on for app
+ */
+ @Override
+ public void onPause(boolean multitasking) {
+ //Log.i("MobileAccessibility", "onPause");
+ mCachedIsScreenReaderRunning = mIsScreenReaderRunning;
+ }
+
+ /**
+ * Called when the activity will start interacting with the user.
+ *
+ * @param multitasking Flag indicating if multitasking is turned on for app
+ */
+ @Override
+ public void onResume(boolean multitasking) {
+ //Log.i("MobileAccessibility", "onResume");
+ if (mIsScreenReaderRunning && !mCachedIsScreenReaderRunning) {
+ //Log.i("MobileAccessibility", "Reloading page on reload because the Accessibility State has changed.");
+ mCachedIsScreenReaderRunning = mIsScreenReaderRunning;
+ stop();
+ cordova.getActivity().runOnUiThread(new Runnable() {
+ public void run() {
+ 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();
+ }
+ }
+ }
+ });
+ }
+ }
+
+ /**
+ * The final call you receive before your activity is destroyed.
+ */
+ public void onDestroy() {
+ stop();
+ }
+
+ private void isScreenReaderRunning(final CallbackContext callbackContext) {
+ mIsScreenReaderRunning = mMobileAccessibilityHelper.isScreenReaderRunning();
+ cordova.getThreadPool().execute(new Runnable() {
+ public void run() {
+ callbackContext.success(mIsScreenReaderRunning ? 1 : 0);
+ }
+ });
+ }
+
+ protected boolean isScreenReaderRunning() {
+ mIsScreenReaderRunning = mMobileAccessibilityHelper.isScreenReaderRunning();
+ return mIsScreenReaderRunning;
+ }
+
+ private void isClosedCaptioningEnabled(final CallbackContext callbackContext) {
+ mClosedCaptioningEnabled = mMobileAccessibilityHelper.isClosedCaptioningEnabled();
+ cordova.getThreadPool().execute(new Runnable() {
+ public void run() {
+ callbackContext.success(mClosedCaptioningEnabled ? 1 : 0);
+ }
+ });
+ }
+
+ protected boolean isClosedCaptioningEnabled() {
+ mClosedCaptioningEnabled = mMobileAccessibilityHelper.isClosedCaptioningEnabled();
+ return mClosedCaptioningEnabled;
+ }
+
+ private void isTouchExplorationEnabled(final CallbackContext callbackContext) {
+ mTouchExplorationEnabled= mMobileAccessibilityHelper.isTouchExplorationEnabled();
+ cordova.getThreadPool().execute(new Runnable() {
+ public void run() {
+ callbackContext.success(mTouchExplorationEnabled ? 1 : 0);
+ }
+ });
+ }
+
+ protected boolean isTouchExplorationEnabled() {
+ mTouchExplorationEnabled = mMobileAccessibilityHelper.isTouchExplorationEnabled();
+ return mTouchExplorationEnabled;
+ }
+
+ private void announceForAccessibility(CharSequence text, final CallbackContext callbackContext) {
+ mMobileAccessibilityHelper.announceForAccessibility(text);
+ if (callbackContext != null) {
+ JSONObject info = new JSONObject();
+ try {
+ info.put("stringValue", text);
+ info.put("wasSuccessful", mIsScreenReaderRunning);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ callbackContext.success(info);
+ }
+ }
+
+ public void onAccessibilityStateChanged(boolean enabled) {
+ mIsScreenReaderRunning = enabled;
+ cordova.getActivity().runOnUiThread(new Runnable() {
+ public void run() {
+ sendMobileAccessibilityStatusChangedCallback();
+ }
+ });
+ }
+
+ public void onCaptioningEnabledChanged(boolean enabled) {
+ mClosedCaptioningEnabled = enabled;
+ cordova.getActivity().runOnUiThread(new Runnable() {
+ public void run() {
+ sendMobileAccessibilityStatusChangedCallback();
+ }
+ });
+ }
+
+ public void onTouchExplorationStateChanged(boolean enabled) {
+ mTouchExplorationEnabled = enabled;
+ cordova.getActivity().runOnUiThread(new Runnable() {
+ public void run() {
+ sendMobileAccessibilityStatusChangedCallback();
+ }
+ });
+ }
+
+ private void getTextZoom(final CallbackContext callbackContext) {
+ cordova.getActivity().runOnUiThread(new Runnable() {
+ public void run() {
+ final double textZoom = mMobileAccessibilityHelper.getTextZoom();
+ if (callbackContext != null) {
+ callbackContext.success((int) textZoom);
+ }
+ }
+ });
+ }
+
+ 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());
+ }
+ }
+ });
+ }
+
+ public void setTextZoom(final double textZoom) {
+ cordova.getActivity().runOnUiThread(new Runnable() {
+ public void run() {
+ mMobileAccessibilityHelper.setTextZoom(textZoom);
+ }
+ });
+ }
+
+ private void updateTextZoom(final CallbackContext callbackContext) {
+ float fontScale = cordova.getActivity().getResources().getConfiguration().fontScale;
+ if (fontScale != mFontScale) {
+ mFontScale = fontScale;
+ }
+ final double textZoom = Math.round(mFontScale * 100);
+ setTextZoom(textZoom, callbackContext);
+ }
+
+ private void sendMobileAccessibilityStatusChangedCallback() {
+ if (this.mCallbackContext != null) {
+ PluginResult result = new PluginResult(PluginResult.Status.OK, getMobileAccessibilityStatus());
+ result.setKeepCallback(true);
+ this.mCallbackContext.sendPluginResult(result);
+ }
+ }
+
+ /* Get the current mobile accessibility status. */
+ private JSONObject getMobileAccessibilityStatus() {
+ JSONObject status = new JSONObject();
+ try {
+ status.put("isScreenReaderRunning", mIsScreenReaderRunning);
+ status.put("isClosedCaptioningEnabled", mClosedCaptioningEnabled);
+ status.put("isTouchExplorationEnabled", mTouchExplorationEnabled);
+ //Log.i("MobileAccessibility", "MobileAccessibility.isScreenReaderRunning == " + status.getString("isScreenReaderRunning") +
+ // "\nMobileAccessibility.isClosedCaptioningEnabled == " + status.getString("isClosedCaptioningEnabled") +
+ // "\nMobileAccessibility.isTouchExplorationEnabled == " + status.getString("isTouchExplorationEnabled") );
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return status;
+ }
+
+ private void start(CallbackContext callbackContext) {
+ //Log.i("MobileAccessibility", "MobileAccessibility.start");
+ mCallbackContext = callbackContext;
+ mMobileAccessibilityHelper.addStateChangeListeners();
+ sendMobileAccessibilityStatusChangedCallback();
+ }
+
+ private void stop() {
+ //Log.i("MobileAccessibility", "MobileAccessibility.stop");
+ if (mCallbackContext != null) {
+ sendMobileAccessibilityStatusChangedCallback();
+ mMobileAccessibilityHelper.removeStateChangeListeners();
+ mCallbackContext = null;
+ }
+ }
+}