aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/accessibility
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/accessibility')
-rw-r--r--java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java2
-rw-r--r--java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java25
-rw-r--r--java/src/com/android/inputmethod/accessibility/KeyboardAccessibilityDelegate.java105
-rw-r--r--java/src/com/android/inputmethod/accessibility/KeyboardAccessibilityNodeProvider.java17
-rw-r--r--java/src/com/android/inputmethod/accessibility/MainKeyboardAccessibilityDelegate.java8
5 files changed, 79 insertions, 78 deletions
diff --git a/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java b/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java
index d50dd3ee6..27896fd11 100644
--- a/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java
+++ b/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java
@@ -114,7 +114,7 @@ public final class AccessibilityUtils {
* @param event The event to check.
* @return {@true} is the event is a touch exploration event
*/
- public boolean isTouchExplorationEvent(final MotionEvent event) {
+ public static boolean isTouchExplorationEvent(final MotionEvent event) {
final int action = event.getAction();
return action == MotionEvent.ACTION_HOVER_ENTER
|| action == MotionEvent.ACTION_HOVER_EXIT
diff --git a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
index 2c87fc1e9..58672ace7 100644
--- a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
+++ b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
@@ -285,15 +285,14 @@ public final class KeyCodeDescriptionMapper {
if (index >= 0) {
return context.getString(mKeyCodeMap.valueAt(index));
}
- final String accentedLetter = getSpokenAccentedLetterDescriptionId(context, code);
+ final String accentedLetter = getSpokenAccentedLetterDescription(context, code);
if (accentedLetter != null) {
return accentedLetter;
}
- // Here, <code>code</code> may be a base letter.
- final int spokenEmojiId = getSpokenDescriptionId(
- context, code, SPOKEN_EMOJI_RESOURCE_NAME_FORMAT);
- if (spokenEmojiId != 0) {
- return context.getString(spokenEmojiId);
+ // Here, <code>code</code> may be a base (non-accented) letter.
+ final String emojiDescription = getSpokenEmojiDescription(context, code);
+ if (emojiDescription != null) {
+ return emojiDescription;
}
if (isDefinedNonCtrl) {
return Character.toString((char) code);
@@ -304,7 +303,7 @@ public final class KeyCodeDescriptionMapper {
return context.getString(R.string.spoken_description_unknown, code);
}
- private String getSpokenAccentedLetterDescriptionId(final Context context, final int code) {
+ private String getSpokenAccentedLetterDescription(final Context context, final int code) {
final boolean isUpperCase = Character.isUpperCase(code);
final int baseCode = isUpperCase ? Character.toLowerCase(code) : code;
final int baseIndex = mKeyCodeMap.indexOfKey(baseCode);
@@ -314,7 +313,17 @@ public final class KeyCodeDescriptionMapper {
return null;
}
final String spokenText = context.getString(resId);
- return isUpperCase ? context.getString(R.string.spoke_description_upper_case, spokenText)
+ return isUpperCase ? context.getString(R.string.spoken_description_upper_case, spokenText)
+ : spokenText;
+ }
+
+ private String getSpokenEmojiDescription(final Context context, final int code) {
+ final int resId = getSpokenDescriptionId(context, code, SPOKEN_EMOJI_RESOURCE_NAME_FORMAT);
+ if (resId == 0) {
+ return null;
+ }
+ final String spokenText = context.getString(resId);
+ return TextUtils.isEmpty(spokenText) ? context.getString(R.string.spoken_emoji_unknown)
: spokenText;
}
diff --git a/java/src/com/android/inputmethod/accessibility/KeyboardAccessibilityDelegate.java b/java/src/com/android/inputmethod/accessibility/KeyboardAccessibilityDelegate.java
index eed40f4a9..0ebad9774 100644
--- a/java/src/com/android/inputmethod/accessibility/KeyboardAccessibilityDelegate.java
+++ b/java/src/com/android/inputmethod/accessibility/KeyboardAccessibilityDelegate.java
@@ -16,6 +16,7 @@
package com.android.inputmethod.accessibility;
+import android.content.Context;
import android.os.SystemClock;
import android.support.v4.view.AccessibilityDelegateCompat;
import android.support.v4.view.ViewCompat;
@@ -37,7 +38,7 @@ public class KeyboardAccessibilityDelegate<KV extends KeyboardView>
protected final KeyDetector mKeyDetector;
private Keyboard mKeyboard;
private KeyboardAccessibilityNodeProvider mAccessibilityNodeProvider;
- private Key mLastHoverKey;
+ private Key mCurrentHoverKey;
public KeyboardAccessibilityDelegate(final KV keyboardView, final KeyDetector keyDetector) {
super();
@@ -70,6 +71,19 @@ public class KeyboardAccessibilityDelegate<KV extends KeyboardView>
}
/**
+ * Sends a window state change event with the specified string resource id.
+ *
+ * @param resId The string resource id of the text to send with the event.
+ */
+ protected void sendWindowStateChanged(final int resId) {
+ if (resId == 0) {
+ return;
+ }
+ final Context context = mKeyboardView.getContext();
+ sendWindowStateChanged(context.getString(resId));
+ }
+
+ /**
* Sends a window state change event with the specified text.
*
* @param text The text to send with the event.
@@ -117,14 +131,14 @@ public class KeyboardAccessibilityDelegate<KV extends KeyboardView>
* Receives hover events when touch exploration is turned on in SDK versions ICS and higher.
*
* @param event The hover event.
- * @return {@code true} if the event is handled
+ * @return {@code true} if the event is handled.
*/
- public boolean dispatchHoverEvent(final MotionEvent event) {
+ public boolean onHoverEvent(final MotionEvent event) {
final int x = (int) event.getX();
final int y = (int) event.getY();
- final Key previousKey = mLastHoverKey;
+ final Key previousKey = mCurrentHoverKey;
final Key key = mKeyDetector.detectHitKey(x, y);
- mLastHoverKey = key;
+ mCurrentHoverKey = key;
switch (event.getAction()) {
case MotionEvent.ACTION_HOVER_EXIT:
@@ -133,17 +147,30 @@ public class KeyboardAccessibilityDelegate<KV extends KeyboardView>
if (key != null) {
final long downTime = simulateKeyPress(key);
simulateKeyRelease(key, downTime);
+ onHoverExitKey(key);
}
- //$FALL-THROUGH$
+ mCurrentHoverKey = null;
+ break;
case MotionEvent.ACTION_HOVER_ENTER:
- return onHoverKey(key, event);
+ if (key != null) {
+ onHoverEnterKey(key);
+ }
+ break;
case MotionEvent.ACTION_HOVER_MOVE:
if (key != previousKey) {
- return onTransitionKey(key, previousKey, event);
+ if (previousKey != null) {
+ onHoverExitKey(previousKey);
+ }
+ if (key != null) {
+ onHoverEnterKey(key);
+ }
+ }
+ if (key != null) {
+ onHoverMoveKey(key);
}
- return onHoverKey(key, event);
+ break;
}
- return false;
+ return true;
}
/**
@@ -151,6 +178,7 @@ public class KeyboardAccessibilityDelegate<KV extends KeyboardView>
* This avoids the complexity of trackers and listeners within the keyboard.
*
* @param key The key to press.
+ * @return the event time of the simulated key press.
*/
private long simulateKeyPress(final Key key) {
final int x = key.getHitBox().centerX();
@@ -168,6 +196,7 @@ public class KeyboardAccessibilityDelegate<KV extends KeyboardView>
* This avoids the complexity of trackers and listeners within the keyboard.
*
* @param key The key to release.
+ * @param downTime the event time of the key press.
*/
private void simulateKeyRelease(final Key key, final long downTime) {
final int x = key.getHitBox().centerX();
@@ -179,54 +208,30 @@ public class KeyboardAccessibilityDelegate<KV extends KeyboardView>
}
/**
- * Simulates a transition between two {@link Key}s by sending a HOVER_EXIT on the previous key,
- * a HOVER_ENTER on the current key, and a HOVER_MOVE on the current key.
+ * Handles a hover enter event on a key.
*
- * @param currentKey The currently hovered key.
- * @param previousKey The previously hovered key.
- * @param event The event that triggered the transition.
- * @return {@code true} if the event was handled.
+ * @param key The currently hovered key.
*/
- private boolean onTransitionKey(final Key currentKey, final Key previousKey,
- final MotionEvent event) {
- final int savedAction = event.getAction();
- event.setAction(MotionEvent.ACTION_HOVER_EXIT);
- onHoverKey(previousKey, event);
- event.setAction(MotionEvent.ACTION_HOVER_ENTER);
- onHoverKey(currentKey, event);
- event.setAction(MotionEvent.ACTION_HOVER_MOVE);
- final boolean handled = onHoverKey(currentKey, event);
- event.setAction(savedAction);
- return handled;
+ protected void onHoverEnterKey(final Key key) {
+ final KeyboardAccessibilityNodeProvider provider = getAccessibilityNodeProvider();
+ provider.sendAccessibilityEventForKey(key, AccessibilityEventCompat.TYPE_VIEW_HOVER_ENTER);
+ provider.performActionForKey(key, AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
}
/**
- * Handles a hover event on a key. If {@link Key} extended View, this would be analogous to
- * calling View.onHoverEvent(MotionEvent).
+ * Handles a hover move event on a key.
*
* @param key The currently hovered key.
- * @param event The hover event.
- * @return {@code true} if the event was handled.
*/
- private boolean onHoverKey(final Key key, final MotionEvent event) {
- // Null keys can't receive events.
- if (key == null) {
- return false;
- }
- final KeyboardAccessibilityNodeProvider provider = getAccessibilityNodeProvider();
+ protected void onHoverMoveKey(final Key key) { }
- switch (event.getAction()) {
- case MotionEvent.ACTION_HOVER_ENTER:
- provider.sendAccessibilityEventForKey(
- key, AccessibilityEventCompat.TYPE_VIEW_HOVER_ENTER);
- provider.performActionForKey(
- key, AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS, null);
- break;
- case MotionEvent.ACTION_HOVER_EXIT:
- provider.sendAccessibilityEventForKey(
- key, AccessibilityEventCompat.TYPE_VIEW_HOVER_EXIT);
- break;
- }
- return true;
+ /**
+ * Handles a hover exit event on a key.
+ *
+ * @param key The currently hovered key.
+ */
+ protected void onHoverExitKey(final Key key) {
+ final KeyboardAccessibilityNodeProvider provider = getAccessibilityNodeProvider();
+ provider.sendAccessibilityEventForKey(key, AccessibilityEventCompat.TYPE_VIEW_HOVER_EXIT);
}
}
diff --git a/java/src/com/android/inputmethod/accessibility/KeyboardAccessibilityNodeProvider.java b/java/src/com/android/inputmethod/accessibility/KeyboardAccessibilityNodeProvider.java
index cddd1c7ed..a6997e2f9 100644
--- a/java/src/com/android/inputmethod/accessibility/KeyboardAccessibilityNodeProvider.java
+++ b/java/src/com/android/inputmethod/accessibility/KeyboardAccessibilityNodeProvider.java
@@ -134,7 +134,7 @@ public final class KeyboardAccessibilityNodeProvider extends AccessibilityNodePr
event.setClassName(key.getClass().getName());
event.setContentDescription(keyDescription);
event.setEnabled(true);
- final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);
+ final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
record.setSource(mKeyboardView, virtualViewId);
return event;
}
@@ -229,7 +229,7 @@ public final class KeyboardAccessibilityNodeProvider extends AccessibilityNodePr
if (key == null) {
return false;
}
- return performActionForKey(key, action, arguments);
+ return performActionForKey(key, action);
}
/**
@@ -237,25 +237,16 @@ public final class KeyboardAccessibilityNodeProvider extends AccessibilityNodePr
*
* @param key The on which to perform the action.
* @param action The action to perform.
- * @param arguments The action's arguments.
* @return The result of performing the action, or false if the action is not supported.
*/
- boolean performActionForKey(final Key key, final int action, final Bundle arguments) {
- final int virtualViewId = getVirtualViewIdOf(key);
-
+ boolean performActionForKey(final Key key, final int action) {
switch (action) {
case AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS:
- if (mAccessibilityFocusedView == virtualViewId) {
- return false;
- }
- mAccessibilityFocusedView = virtualViewId;
+ mAccessibilityFocusedView = getVirtualViewIdOf(key);
sendAccessibilityEventForKey(
key, AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
return true;
case AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS:
- if (mAccessibilityFocusedView != virtualViewId) {
- return false;
- }
mAccessibilityFocusedView = UNDEFINED;
sendAccessibilityEventForKey(
key, AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED);
diff --git a/java/src/com/android/inputmethod/accessibility/MainKeyboardAccessibilityDelegate.java b/java/src/com/android/inputmethod/accessibility/MainKeyboardAccessibilityDelegate.java
index 443f793a1..ec6bb0156 100644
--- a/java/src/com/android/inputmethod/accessibility/MainKeyboardAccessibilityDelegate.java
+++ b/java/src/com/android/inputmethod/accessibility/MainKeyboardAccessibilityDelegate.java
@@ -163,17 +163,13 @@ public final class MainKeyboardAccessibilityDelegate
default:
return;
}
- final String text = mKeyboardView.getContext().getString(resId);
- sendWindowStateChanged(text);
+ sendWindowStateChanged(resId);
}
/**
* Announces that the keyboard has been hidden.
*/
private void announceKeyboardHidden() {
- final Context context = mKeyboardView.getContext();
- final String text = context.getString(R.string.announce_keyboard_hidden);
-
- sendWindowStateChanged(text);
+ sendWindowStateChanged(R.string.announce_keyboard_hidden);
}
}