Apply TtsSpan to known phone numbers in contact interactions
The primary content description in ContactInteraction must be
made a Spannable so that the TtsSpan can be progated from the
Loader (where the ContactInteraction is constructed) up to the
ExpandingEntryCardView.
Bug 17322140
Change-Id: If668f27cab20822f3c80aab606089e6b6f2a96c0
diff --git a/src/com/android/contacts/interactions/CalendarInteraction.java b/src/com/android/contacts/interactions/CalendarInteraction.java
index efd724a..e249e4f 100644
--- a/src/com/android/contacts/interactions/CalendarInteraction.java
+++ b/src/com/android/contacts/interactions/CalendarInteraction.java
@@ -11,6 +11,7 @@
import android.net.Uri;
import android.provider.CalendarContract.Attendees;
import android.provider.CalendarContract.Events;
+import android.text.Spannable;
import android.text.TextUtils;
import android.text.format.Time;
import android.util.Log;
@@ -278,7 +279,7 @@
}
@Override
- public String getContentDescription(Context context) {
+ public Spannable getContentDescription(Context context) {
// The default TalkBack is good
return null;
}
diff --git a/src/com/android/contacts/interactions/CallLogInteraction.java b/src/com/android/contacts/interactions/CallLogInteraction.java
index a03f6a4..3464c0f 100644
--- a/src/com/android/contacts/interactions/CallLogInteraction.java
+++ b/src/com/android/contacts/interactions/CallLogInteraction.java
@@ -17,6 +17,7 @@
import com.android.contacts.R;
import com.android.contacts.common.util.BitmapUtil;
+import com.android.contacts.common.util.ContactDisplayUtils;
import android.content.ContentValues;
import android.content.Context;
@@ -28,6 +29,7 @@
import android.provider.CallLog.Calls;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.text.BidiFormatter;
+import android.text.Spannable;
import android.text.TextDirectionHeuristics;
/**
@@ -179,9 +181,12 @@
}
@Override
- public String getContentDescription(Context context) {
- return context.getResources().getString(R.string.content_description_recent_call,
- getCallTypeString(context), getViewHeader(context), getViewFooter(context));
+ public Spannable getContentDescription(Context context) {
+ final String phoneNumber = getViewHeader(context);
+ final String contentDescription = context.getResources().getString(
+ R.string.content_description_recent_call,
+ getCallTypeString(context), phoneNumber, getViewFooter(context));
+ return ContactDisplayUtils.getTelephoneTtsSpannable(contentDescription, phoneNumber);
}
private String getCallTypeString(Context context) {
diff --git a/src/com/android/contacts/interactions/ContactInteraction.java b/src/com/android/contacts/interactions/ContactInteraction.java
index 11bbb49..bf00132 100644
--- a/src/com/android/contacts/interactions/ContactInteraction.java
+++ b/src/com/android/contacts/interactions/ContactInteraction.java
@@ -19,6 +19,7 @@
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
+import android.text.Spannable;
/**
* Represents a default interaction between the phone's owner and a contact
@@ -32,7 +33,7 @@
Drawable getIcon(Context context);
Drawable getBodyIcon(Context context);
Drawable getFooterIcon(Context context);
- String getContentDescription(Context context);
+ Spannable getContentDescription(Context context);
/** The resource id for the icon, if available. May be 0 if one is not available. */
int getIconResourceId();
}
diff --git a/src/com/android/contacts/interactions/SmsInteraction.java b/src/com/android/contacts/interactions/SmsInteraction.java
index 3bba0bc..7d26401 100644
--- a/src/com/android/contacts/interactions/SmsInteraction.java
+++ b/src/com/android/contacts/interactions/SmsInteraction.java
@@ -16,6 +16,7 @@
package com.android.contacts.interactions;
import com.android.contacts.R;
+import com.android.contacts.common.util.ContactDisplayUtils;
import android.content.ContentValues;
import android.content.Context;
@@ -24,6 +25,7 @@
import android.net.Uri;
import android.provider.Telephony.Sms;
import android.text.BidiFormatter;
+import android.text.Spannable;
import android.text.TextDirectionHeuristics;
/**
@@ -159,9 +161,12 @@
}
@Override
- public String getContentDescription(Context context) {
- return context.getResources().getString(R.string.content_description_recent_sms,
- getViewHeader(context), getViewBody(context), getViewFooter(context));
+ public Spannable getContentDescription(Context context) {
+ final String phoneNumber = getViewBody(context);
+ final String contentDescription = context.getResources().getString(
+ R.string.content_description_recent_sms,
+ getViewHeader(context), phoneNumber, getViewFooter(context));
+ return ContactDisplayUtils.getTelephoneTtsSpannable(contentDescription, phoneNumber);
}
@Override
diff --git a/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java b/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java
index 68698d6..dc8970b 100644
--- a/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java
+++ b/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java
@@ -23,6 +23,7 @@
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.CardView;
+import android.text.Spannable;
import android.text.TextUtils;
import android.transition.ChangeBounds;
import android.transition.ChangeScroll;
@@ -73,7 +74,7 @@
private final Drawable mSubHeaderIcon;
private final String mText;
private final Drawable mTextIcon;
- private final String mPrimaryContentDescription;
+ private Spannable mPrimaryContentDescription;
private final Intent mIntent;
private final Drawable mAlternateIcon;
private final Intent mAlternateIntent;
@@ -88,7 +89,7 @@
public Entry(int id, Drawable mainIcon, String header, String subHeader,
Drawable subHeaderIcon, String text, Drawable textIcon,
- String primaryContentDescription, Intent intent,
+ Spannable primaryContentDescription, Intent intent,
Drawable alternateIcon, Intent alternateIntent, String alternateContentDescription,
boolean shouldApplyColor, boolean isEditable,
EntryContextMenuInfo entryContextMenuInfo, Drawable thirdIcon, Intent thirdIntent,
@@ -138,7 +139,7 @@
return mTextIcon;
}
- String getPrimaryContentDescription() {
+ Spannable getPrimaryContentDescription() {
return mPrimaryContentDescription;
}
diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java
index 4d543a4..dbd4494 100644
--- a/src/com/android/contacts/quickcontact/QuickContactActivity.java
+++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java
@@ -73,6 +73,7 @@
import android.telecom.PhoneAccount;
import android.telecom.TelecomManager;
import android.text.BidiFormatter;
+import android.text.SpannableString;
import android.text.TextDirectionHeuristics;
import android.text.TextUtils;
import android.util.Log;
@@ -1606,7 +1607,8 @@
-1 : (int) dataItem.getId();
return new Entry(dataId, icon, header, subHeader, subHeaderIcon, text, textIcon,
- primaryContentDescription.toString(), intent, alternateIcon, alternateIntent,
+ new SpannableString(primaryContentDescription.toString()),
+ intent, alternateIcon, alternateIntent,
alternateContentDescription.toString(), shouldApplyColor, isEditable,
entryContextMenuInfo, thirdIcon, thirdIntent, thirdContentDescription,
iconResourceId);