aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2014-09-29 20:40:18 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-09-29 20:40:18 +0000
commit16dfe4d31263357e33f8277a2c22122cc7d4c299 (patch)
tree62f3bfbe9423db8a34f9e91d81ea9e4699595d06 /java/src
parentd5d0057a7cbc5e26114bc874406393a4287e8ed4 (diff)
parent4936d259d7eaa00017b73fdb3a1ae0fadb0531e2 (diff)
downloadlatinime-16dfe4d31263357e33f8277a2c22122cc7d4c299.tar.gz
latinime-16dfe4d31263357e33f8277a2c22122cc7d4c299.tar.xz
latinime-16dfe4d31263357e33f8277a2c22122cc7d4c299.zip
am 4936d259: Merge "Fix verbalizing missing emoticons"
* commit '4936d259d7eaa00017b73fdb3a1ae0fadb0531e2': Fix verbalizing missing emoticons
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java23
1 files changed, 22 insertions, 1 deletions
diff --git a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
index 7a3510ee1..edcdd4c4c 100644
--- a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
+++ b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
@@ -37,6 +37,8 @@ final class KeyCodeDescriptionMapper {
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";
+ private static final String SPOKEN_EMOTICON_RESOURCE_NAME_PREFIX = "spoken_emoticon";
+ private static final String SPOKEN_EMOTICON_CODE_POINT_FORMAT = "_%02X";
// The resource ID of the string spoken for obscured keys
private static final int OBSCURED_KEY_RES_ID = R.string.spoken_description_dot;
@@ -109,7 +111,9 @@ final class KeyCodeDescriptionMapper {
}
if (code == Constants.CODE_OUTPUT_TEXT) {
- return key.getOutputText();
+ final String outputText = key.getOutputText();
+ final String description = getSpokenEmoticonDescription(context, outputText);
+ return TextUtils.isEmpty(description) ? outputText : description;
}
// Just attempt to speak the description.
@@ -340,4 +344,21 @@ final class KeyCodeDescriptionMapper {
}
return resId;
}
+
+ // TODO: Remove this method once TTS supports emoticon verbalization.
+ private String getSpokenEmoticonDescription(final Context context, final String outputText) {
+ final StringBuilder sb = new StringBuilder(SPOKEN_EMOTICON_RESOURCE_NAME_PREFIX);
+ final int textLength = outputText.length();
+ for (int index = 0; index < textLength; index = outputText.offsetByCodePoints(index, 1)) {
+ final int codePoint = outputText.codePointAt(index);
+ sb.append(String.format(Locale.ROOT, SPOKEN_EMOTICON_CODE_POINT_FORMAT, codePoint));
+ }
+ final String resourceName = sb.toString();
+ final Resources resources = context.getResources();
+ // Note that the resource package name may differ from the context package name.
+ final String resourcePackageName = resources.getResourcePackageName(
+ R.string.spoken_description_unknown);
+ final int resId = resources.getIdentifier(resourceName, "string", resourcePackageName);
+ return (resId == 0) ? null : resources.getString(resId);
+ }
}