summaryrefslogtreecommitdiffstats
path: root/core/java/android/view/accessibility
diff options
context:
space:
mode:
authorAlan Viverette <alanv@google.com>2013-10-09 15:21:22 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-10-09 15:21:22 -0700
commit359404288c441904d636d48094669fcf66d49308 (patch)
tree22d0e51011fa0ba36f7fd5210f5020e39d16d4f9 /core/java/android/view/accessibility
parent6699ae2b76fabaf179738c853f29ac21d5caf1be (diff)
parent9f57774ebb3b400b6597a9dbe854b4b6b1c8afd4 (diff)
downloadframeworks_base-359404288c441904d636d48094669fcf66d49308.zip
frameworks_base-359404288c441904d636d48094669fcf66d49308.tar.gz
frameworks_base-359404288c441904d636d48094669fcf66d49308.tar.bz2
am 9f57774e: am 972de252: am 24305da7: Merge "Add listener for changes to touch exploration state" into klp-dev
* commit '9f57774ebb3b400b6597a9dbe854b4b6b1c8afd4': Add listener for changes to touch exploration state
Diffstat (limited to 'core/java/android/view/accessibility')
-rw-r--r--core/java/android/view/accessibility/AccessibilityManager.java96
1 files changed, 76 insertions, 20 deletions
diff --git a/core/java/android/view/accessibility/AccessibilityManager.java b/core/java/android/view/accessibility/AccessibilityManager.java
index 020b92c..d8859e3 100644
--- a/core/java/android/view/accessibility/AccessibilityManager.java
+++ b/core/java/android/view/accessibility/AccessibilityManager.java
@@ -127,25 +127,45 @@ public final class AccessibilityManager {
boolean mIsTouchExplorationEnabled;
- final CopyOnWriteArrayList<AccessibilityStateChangeListener> mAccessibilityStateChangeListeners =
- new CopyOnWriteArrayList<AccessibilityStateChangeListener>();
+ private final CopyOnWriteArrayList<AccessibilityStateChangeListener>
+ mAccessibilityStateChangeListeners = new CopyOnWriteArrayList<
+ AccessibilityStateChangeListener>();
+
+ private final CopyOnWriteArrayList<TouchExplorationStateChangeListener>
+ mTouchExplorationStateChangeListeners = new CopyOnWriteArrayList<
+ TouchExplorationStateChangeListener>();
/**
- * Listener for the system accessibility state. To listen for changes to the accessibility
- * state on the device, implement this interface and register it with the system by
- * calling {@link AccessibilityManager#addAccessibilityStateChangeListener
- * addAccessibilityStateChangeListener()}.
+ * Listener for the system accessibility state. To listen for changes to the
+ * accessibility state on the device, implement this interface and register
+ * it with the system by calling {@link #addAccessibilityStateChangeListener}.
*/
public interface AccessibilityStateChangeListener {
/**
- * Called back on change in the accessibility state.
+ * Called when the accessibility enabled state changes.
*
* @param enabled Whether accessibility is enabled.
*/
public void onAccessibilityStateChanged(boolean enabled);
}
+ /**
+ * Listener for the system touch exploration state. To listen for changes to
+ * the touch exploration state on the device, implement this interface and
+ * register it with the system by calling
+ * {@link #addTouchExplorationStateChangeListener}.
+ */
+ public interface TouchExplorationStateChangeListener {
+
+ /**
+ * Called when the touch exploration enabled state changes.
+ *
+ * @param enabled Whether touch exploration is enabled.
+ */
+ public void onTouchExplorationStateChanged(boolean enabled);
+ }
+
final IAccessibilityManagerClient.Stub mClient = new IAccessibilityManagerClient.Stub() {
public void setState(int state) {
mHandler.obtainMessage(DO_SET_STATE, state, 0).sendToTarget();
@@ -399,34 +419,57 @@ public final class AccessibilityManager {
}
/**
- * Sets the current state.
+ * Registers a {@link TouchExplorationStateChangeListener} for changes in
+ * the global touch exploration state of the system.
*
- * @param stateFlags The state flags.
+ * @param listener The listener.
+ * @return True if successfully registered.
*/
- private void setState(int stateFlags) {
- final boolean accessibilityEnabled = (stateFlags & STATE_FLAG_ACCESSIBILITY_ENABLED) != 0;
- setAccessibilityState(accessibilityEnabled);
- mIsTouchExplorationEnabled = (stateFlags & STATE_FLAG_TOUCH_EXPLORATION_ENABLED) != 0;
+ public boolean addTouchExplorationStateChangeListener(
+ TouchExplorationStateChangeListener listener) {
+ return mTouchExplorationStateChangeListeners.add(listener);
}
/**
- * Sets the enabled state.
+ * Unregisters a {@link TouchExplorationStateChangeListener}.
*
- * @param isEnabled The accessibility state.
+ * @param listener The listener.
+ * @return True if successfully unregistered.
*/
- private void setAccessibilityState(boolean isEnabled) {
+ public boolean removeTouchExplorationStateChangeListener(
+ TouchExplorationStateChangeListener listener) {
+ return mTouchExplorationStateChangeListeners.remove(listener);
+ }
+
+ /**
+ * Sets the current state and notifies listeners, if necessary.
+ *
+ * @param stateFlags The state flags.
+ */
+ private void setState(int stateFlags) {
+ final boolean enabled = (stateFlags & STATE_FLAG_ACCESSIBILITY_ENABLED) != 0;
+ final boolean touchExplorationEnabled =
+ (stateFlags & STATE_FLAG_TOUCH_EXPLORATION_ENABLED) != 0;
synchronized (mHandler) {
- if (isEnabled != mIsEnabled) {
- mIsEnabled = isEnabled;
- notifyAccessibilityStateChanged();
+ mIsEnabled = enabled;
+ mIsTouchExplorationEnabled = touchExplorationEnabled;
+
+ if (enabled != mIsEnabled) {
+ notifyAccessibilityStateChangedLh();
+ }
+
+ if (touchExplorationEnabled != mIsTouchExplorationEnabled) {
+ notifyTouchExplorationStateChangedLh();
}
}
}
/**
* Notifies the registered {@link AccessibilityStateChangeListener}s.
+ * <p>
+ * The caller must be locked on {@link #mHandler}.
*/
- private void notifyAccessibilityStateChanged() {
+ private void notifyAccessibilityStateChangedLh() {
final int listenerCount = mAccessibilityStateChangeListeners.size();
for (int i = 0; i < listenerCount; i++) {
mAccessibilityStateChangeListeners.get(i).onAccessibilityStateChanged(mIsEnabled);
@@ -434,6 +477,19 @@ public final class AccessibilityManager {
}
/**
+ * Notifies the registered {@link TouchExplorationStateChangeListener}s.
+ * <p>
+ * The caller must be locked on {@link #mHandler}.
+ */
+ private void notifyTouchExplorationStateChangedLh() {
+ final int listenerCount = mTouchExplorationStateChangeListeners.size();
+ for (int i = 0; i < listenerCount; i++) {
+ mTouchExplorationStateChangeListeners.get(i)
+ .onTouchExplorationStateChanged(mIsTouchExplorationEnabled);
+ }
+ }
+
+ /**
* Adds an accessibility interaction connection interface for a given window.
* @param windowToken The window token to which a connection is added.
* @param connection The connection.