summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIhab Awad <ihab@google.com>2014-12-05 13:38:11 -0800
committerIhab Awad <ihab@google.com>2014-12-05 15:27:08 -0800
commit0855e7aea22e863f21a546b87acf38b7c3912e2e (patch)
tree05a4e26f3ff8a410402ae56f1b06fc23c688469f
parentd386d0f391c41e3e6e87abab44600df24f45ac4a (diff)
downloadframeworks_base-0855e7aea22e863f21a546b87acf38b7c3912e2e.zip
frameworks_base-0855e7aea22e863f21a546b87acf38b7c3912e2e.tar.gz
frameworks_base-0855e7aea22e863f21a546b87acf38b7c3912e2e.tar.bz2
Add Text-to-Speech annotations for phone number displays (1/3)
Bug: 17321294 Change-Id: Id7e48e683694e2f9ea2a7dd7fa7d69acc727489d
-rw-r--r--telephony/java/android/telephony/PhoneNumberFormattingTextWatcher.java1
-rw-r--r--telephony/java/android/telephony/PhoneNumberUtils.java55
2 files changed, 56 insertions, 0 deletions
diff --git a/telephony/java/android/telephony/PhoneNumberFormattingTextWatcher.java b/telephony/java/android/telephony/PhoneNumberFormattingTextWatcher.java
index 438b572..f7dee99 100644
--- a/telephony/java/android/telephony/PhoneNumberFormattingTextWatcher.java
+++ b/telephony/java/android/telephony/PhoneNumberFormattingTextWatcher.java
@@ -117,6 +117,7 @@ public class PhoneNumberFormattingTextWatcher implements TextWatcher {
}
mSelfChange = false;
}
+ PhoneNumberUtils.ttsSpanAsPhoneNumber(s, 0, s.length());
}
/**
diff --git a/telephony/java/android/telephony/PhoneNumberUtils.java b/telephony/java/android/telephony/PhoneNumberUtils.java
index 897702d..0844232 100644
--- a/telephony/java/android/telephony/PhoneNumberUtils.java
+++ b/telephony/java/android/telephony/PhoneNumberUtils.java
@@ -31,9 +31,11 @@ import android.os.SystemProperties;
import android.provider.Contacts;
import android.provider.ContactsContract;
import android.text.Editable;
+import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.telephony.Rlog;
+import android.text.style.TtsSpan;
import android.util.SparseIntArray;
import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
@@ -2307,6 +2309,59 @@ public class PhoneNumberUtils
return retStr;
}
+ /**
+ * Wrap the supplied {@code CharSequence} with a {@code TtsSpan}, annotating it as
+ * containing a phone number in its entirety.
+ *
+ * @param phoneNumber A {@code CharSequence} the entirety of which represents a phone number.
+ * @return A {@code CharSequence} with appropriate annotations.
+ *
+ * @hide
+ */
+ public static CharSequence ttsSpanAsPhoneNumber(CharSequence phoneNumber) {
+ if (phoneNumber == null) {
+ return null;
+ }
+ Spannable spannable = Spannable.Factory.getInstance().newSpannable(phoneNumber);
+ PhoneNumberUtils.ttsSpanAsPhoneNumber(spannable, 0, spannable.length());
+ return spannable;
+ }
+
+ /**
+ * Attach a {@link TtsSpan} to the supplied {@code Spannable} at the indicated location,
+ * annotating that location as containing a phone number.
+ *
+ * @param s A {@code Spannable} to annotate.
+ * @param start The starting character position of the phone number in {@code s}.
+ * @param end The ending character position of the phone number in {@code s}.
+ *
+ * @hide
+ */
+ public static void ttsSpanAsPhoneNumber(Spannable s, int start, int end) {
+ s.setSpan(
+ new TtsSpan.TelephoneBuilder()
+ .setNumberParts(splitAtNonNumerics(s.subSequence(start, end)))
+ .build(),
+ start,
+ end,
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ }
+
+ // Split a phone number like "+20(123)-456#" using spaces, ignoring anything that is not
+ // a digit, to produce a result like "20 123 456".
+ private static String splitAtNonNumerics(CharSequence number) {
+ StringBuilder sb = new StringBuilder(number.length());
+ for (int i = 0; i < number.length(); i++) {
+ sb.append(PhoneNumberUtils.isISODigit(number.charAt(i))
+ ? number.charAt(i)
+ : " ");
+ }
+ // It is very important to remove extra spaces. At time of writing, any leading or trailing
+ // spaces, or any sequence of more than one space, will confuse TalkBack and cause the TTS
+ // span to be non-functional!
+ return sb.toString().replaceAll(" +", " ").trim();
+ }
+
private static String getCurrentIdp(boolean useNanp) {
// in case, there is no IDD is found, we shouldn't convert it.
String ps = SystemProperties.get(