aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java28
-rw-r--r--java/src/com/android/inputmethod/accessibility/KeyboardAccessibilityDelegate.java53
2 files changed, 56 insertions, 25 deletions
diff --git a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
index 58672ace7..27c4732ca 100644
--- a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
+++ b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
@@ -34,6 +34,7 @@ import java.util.Locale;
public final class KeyCodeDescriptionMapper {
private static final String TAG = KeyCodeDescriptionMapper.class.getSimpleName();
private static final String SPOKEN_LETTER_RESOURCE_NAME_FORMAT = "spoken_accented_letter_%04X";
+ private static final String SPOKEN_SYMBOL_RESOURCE_NAME_FORMAT = "spoken_symbol_%04X";
private static final String SPOKEN_EMOJI_RESOURCE_NAME_FORMAT = "spoken_emoji_%04X";
// The resource ID of the string spoken for obscured keys
@@ -290,6 +291,10 @@ public final class KeyCodeDescriptionMapper {
return accentedLetter;
}
// Here, <code>code</code> may be a base (non-accented) letter.
+ final String unsupportedSymbol = getSpokenSymbolDescription(context, code);
+ if (unsupportedSymbol != null) {
+ return unsupportedSymbol;
+ }
final String emojiDescription = getSpokenEmojiDescription(context, code);
if (emojiDescription != null) {
return emojiDescription;
@@ -303,6 +308,7 @@ public final class KeyCodeDescriptionMapper {
return context.getString(R.string.spoken_description_unknown, code);
}
+ // TODO: Remove this method once TTS supports those accented letters' verbalization.
private String getSpokenAccentedLetterDescription(final Context context, final int code) {
final boolean isUpperCase = Character.isUpperCase(code);
final int baseCode = isUpperCase ? Character.toLowerCase(code) : code;
@@ -317,14 +323,32 @@ public final class KeyCodeDescriptionMapper {
: spokenText;
}
+ // TODO: Remove this method once TTS supports those symbols' verbalization.
+ private String getSpokenSymbolDescription(final Context context, final int code) {
+ final int resId = getSpokenDescriptionId(context, code, SPOKEN_SYMBOL_RESOURCE_NAME_FORMAT);
+ if (resId == 0) {
+ return null;
+ }
+ final String spokenText = context.getString(resId);
+ if (!TextUtils.isEmpty(spokenText)) {
+ return spokenText;
+ }
+ // If a translated description is empty, fall back to unknown symbol description.
+ return context.getString(R.string.spoken_symbol_unknown);
+ }
+
+ // TODO: Remove this method once TTS supports emoji verbalization.
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;
+ if (!TextUtils.isEmpty(spokenText)) {
+ return spokenText;
+ }
+ // If a translated description is empty, fall back to unknown emoji description.
+ return context.getString(R.string.spoken_emoji_unknown);
}
private int getSpokenDescriptionId(final Context context, final int code,
diff --git a/java/src/com/android/inputmethod/accessibility/KeyboardAccessibilityDelegate.java b/java/src/com/android/inputmethod/accessibility/KeyboardAccessibilityDelegate.java
index 7cae9861c..398a933df 100644
--- a/java/src/com/android/inputmethod/accessibility/KeyboardAccessibilityDelegate.java
+++ b/java/src/com/android/inputmethod/accessibility/KeyboardAccessibilityDelegate.java
@@ -39,7 +39,7 @@ public class KeyboardAccessibilityDelegate<KV extends KeyboardView>
protected final KeyDetector mKeyDetector;
private Keyboard mKeyboard;
private KeyboardAccessibilityNodeProvider mAccessibilityNodeProvider;
- private Key mCurrentHoverKey;
+ private Key mLastHoverKey;
public KeyboardAccessibilityDelegate(final KV keyboardView, final KeyDetector keyDetector) {
super();
@@ -71,12 +71,12 @@ public class KeyboardAccessibilityDelegate<KV extends KeyboardView>
return mKeyboard;
}
- protected final void setCurrentHoverKey(final Key key) {
- mCurrentHoverKey = key;
+ protected final void setLastHoverKey(final Key key) {
+ mLastHoverKey = key;
}
- protected final Key getCurrentHoverKey() {
- return mCurrentHoverKey;
+ protected final Key getLastHoverKey() {
+ return mLastHoverKey;
}
/**
@@ -142,7 +142,7 @@ public class KeyboardAccessibilityDelegate<KV extends KeyboardView>
* @param event The hover event.
* @return key The key that the <code>event</code> is on.
*/
- protected final Key getHoverKey(final MotionEvent event) {
+ protected final Key getHoverKeyOf(final MotionEvent event) {
final int actionIndex = event.getActionIndex();
final int x = (int)event.getX(actionIndex);
final int y = (int)event.getY(actionIndex);
@@ -179,11 +179,11 @@ public class KeyboardAccessibilityDelegate<KV extends KeyboardView>
* @param event A hover enter event.
*/
protected void onHoverEnter(final MotionEvent event) {
- final Key key = getHoverKey(event);
+ final Key key = getHoverKeyOf(event);
if (key != null) {
- onHoverEnterKey(key);
+ onHoverEnterKey(key, event);
}
- setCurrentHoverKey(key);
+ setLastHoverKey(key);
}
/**
@@ -192,20 +192,20 @@ public class KeyboardAccessibilityDelegate<KV extends KeyboardView>
* @param event A hover move event.
*/
protected void onHoverMove(final MotionEvent event) {
- final Key previousKey = getCurrentHoverKey();
- final Key key = getHoverKey(event);
- if (key != previousKey) {
- if (previousKey != null) {
- onHoverExitKey(previousKey);
+ final Key lastKey = getLastHoverKey();
+ final Key key = getHoverKeyOf(event);
+ if (key != lastKey) {
+ if (lastKey != null) {
+ onHoverExitKey(lastKey, event);
}
if (key != null) {
- onHoverEnterKey(key);
+ onHoverEnterKey(key, event);
}
}
if (key != null) {
- onHoverMoveKey(key);
+ onHoverMoveKey(key, event);
}
- setCurrentHoverKey(key);
+ setLastHoverKey(key);
}
/**
@@ -214,15 +214,19 @@ public class KeyboardAccessibilityDelegate<KV extends KeyboardView>
* @param event A hover exit event.
*/
protected void onHoverExit(final MotionEvent event) {
- final Key key = getHoverKey(event);
+ final Key lastKey = getLastHoverKey();
+ if (lastKey != null) {
+ onHoverExitKey(lastKey, event);
+ }
+ final Key key = getHoverKeyOf(event);
// Make sure we're not getting an EXIT event because the user slid
// off the keyboard area, then force a key press.
if (key != null) {
simulateTouchEvent(MotionEvent.ACTION_DOWN, event);
simulateTouchEvent(MotionEvent.ACTION_UP, event);
- onHoverExitKey(key);
+ onHoverExitKey(key, event);
}
- setCurrentHoverKey(null);
+ setLastHoverKey(null);
}
/**
@@ -263,8 +267,9 @@ public class KeyboardAccessibilityDelegate<KV extends KeyboardView>
* Handles a hover enter event on a key.
*
* @param key The currently hovered key.
+ * @param event The hover event that triggers a call to this method.
*/
- protected void onHoverEnterKey(final Key key) {
+ protected void onHoverEnterKey(final Key key, final MotionEvent event) {
key.onPressed();
mKeyboardView.invalidateKey(key);
final KeyboardAccessibilityNodeProvider provider = getAccessibilityNodeProvider();
@@ -276,15 +281,17 @@ public class KeyboardAccessibilityDelegate<KV extends KeyboardView>
* Handles a hover move event on a key.
*
* @param key The currently hovered key.
+ * @param event The hover event that triggers a call to this method.
*/
- protected void onHoverMoveKey(final Key key) { }
+ protected void onHoverMoveKey(final Key key, final MotionEvent event) { }
/**
* Handles a hover exit event on a key.
*
* @param key The currently hovered key.
+ * @param event The hover event that triggers a call to this method.
*/
- protected void onHoverExitKey(final Key key) {
+ protected void onHoverExitKey(final Key key, final MotionEvent event) {
key.onReleased();
mKeyboardView.invalidateKey(key);
final KeyboardAccessibilityNodeProvider provider = getAccessibilityNodeProvider();