am 61a41437: am 1e5325f4: Add Text-to-Speech annotations for phone number displays (3/3)

* commit '61a4143777480b61523b992339c68f184613ce57':
  Add Text-to-Speech annotations for phone number displays (3/3)
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 1dee644..5d06852 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -578,49 +578,49 @@
     <!-- String describing an incoming missed call entry in the call log.
          Note: AccessibilityServices uses this attribute to announce what the view represents.
          [CHAR LIMIT=NONE] -->
-    <string name="description_incoming_missed_call">Missed call from <xliff:g id="nameOrNumber" example="John Smith">%1$s</xliff:g>, <xliff:g id="typeOrLocation" example="Mobile">%2$s</xliff:g>, <xliff:g id="timeOfCall" example="2 min ago">%3$s</xliff:g>, <xliff:g id="phoneAccount" example="on SIM 1">%4$s</xliff:g>.</string>
+    <string name="description_incoming_missed_call">Missed call from <xliff:g id="nameOrNumber" example="John Smith">^1</xliff:g>, <xliff:g id="typeOrLocation" example="Mobile">^2</xliff:g>, <xliff:g id="timeOfCall" example="2 min ago">^3</xliff:g>, <xliff:g id="phoneAccount" example="on SIM 1">^4</xliff:g>.</string>
 
     <!-- String describing an incoming answered call entry in the call log.
          Note: AccessibilityServices uses this attribute to announce what the view represents.
          [CHAR LIMIT=NONE] -->
-    <string name="description_incoming_answered_call">Answered call from <xliff:g id="nameOrNumber" example="John Smith">%1$s</xliff:g>, <xliff:g id="typeOrLocation" example="Mobile">%2$s</xliff:g>, <xliff:g id="timeOfCall" example="2 min ago">%3$s</xliff:g>, <xliff:g id="phoneAccount" example="on SIM 1">%4$s</xliff:g>.</string>
+    <string name="description_incoming_answered_call">Answered call from <xliff:g id="nameOrNumber" example="John Smith">^1</xliff:g>, <xliff:g id="typeOrLocation" example="Mobile">^2</xliff:g>, <xliff:g id="timeOfCall" example="2 min ago">^3</xliff:g>, <xliff:g id="phoneAccount" example="on SIM 1">^4</xliff:g>.</string>
 
     <!-- String describing an outgoing call entry in the call log.
          Note: AccessibilityServices uses this attribute to announce what the view represents.
          [CHAR LIMIT=NONE] -->
-    <string name="description_outgoing_call">Call to <xliff:g id="nameOrNumber" example="John Smith">%1$s</xliff:g>, <xliff:g id="typeOrLocation" example="Mobile">%2$s</xliff:g>, <xliff:g id="timeOfCall" example="2 min ago">%3$s</xliff:g>, <xliff:g id="phoneAccount" example="on SIM 1">%4$s</xliff:g>.</string>
+    <string name="description_outgoing_call">Call to <xliff:g id="nameOrNumber" example="John Smith">^1</xliff:g>, <xliff:g id="typeOrLocation" example="Mobile">^2</xliff:g>, <xliff:g id="timeOfCall" example="2 min ago">^3</xliff:g>, <xliff:g id="phoneAccount" example="on SIM 1">^4</xliff:g>.</string>
 
     <!-- String describing the phone account the call was made on or to. This string will be used
          in description_incoming_missed_call, description_incoming_answered_call, and
          description_outgoing_call.
          Note: AccessibilityServices uses this attribute to announce what the view represents.
          [CHAR LIMIT=NONE] -->
-    <string name="description_phone_account">on <xliff:g id="phoneAccount" example="SIM 1">%1$s</xliff:g></string>
+    <string name="description_phone_account">on <xliff:g id="phoneAccount" example="SIM 1">^1</xliff:g></string>
 
     <!-- String describing the "call back" action for an entry in the call log.  The call back
          action triggers a return call to the named user.
          Note: AccessibilityServices uses this attribute to announce the purpose of the button.
          [CHAR LIMIT=NONE] -->
-    <string name="description_call_back_action">Call back <xliff:g id="nameOrNumber" example="John Smith">%1$s</xliff:g></string>
+    <string name="description_call_back_action">Call back <xliff:g id="nameOrNumber" example="John Smith">^1</xliff:g></string>
 
     <!-- String describing the "video call" action for an entry in the call log.  The video call
          action triggers a return video call to the named person/number.
          Note: AccessibilityServices uses this attribute to announce the purpose of the button.
          [CHAR LIMIT=NONE] -->
-    <string name="description_video_call_action">Video call to <xliff:g id="nameOrNumber" example="John Smith">%1$s</xliff:g>.</string>
+    <string name="description_video_call_action">Video call to <xliff:g id="nameOrNumber" example="John Smith">^1</xliff:g>.</string>
 
     <!-- String describing the "listen" action for an entry in the call log.  The listen
          action is shown for call log entries representing a voicemail message and this button
          triggers playing back the voicemail.
          Note: AccessibilityServices uses this attribute to announce the purpose of the button.
          [CHAR LIMIT=NONE] -->
-    <string name="description_voicemail_action">Listen to voicemail from <xliff:g id="nameOrNumber" example="John Smith">%1$s</xliff:g></string>
+    <string name="description_voicemail_action">Listen to voicemail from <xliff:g id="nameOrNumber" example="John Smith">^1</xliff:g></string>
 
     <!-- String describing the "details" action for an entry in the call log.  The details action
          displays the call details screen for an entry in the call log.  This shows the calls to
          and from the specified number associated with the call log entry.
          [CHAR LIMIT=NONE] -->
-    <string name="description_details_action">Call details for <xliff:g id="nameOrNumber" example="John Smith">%1$s</xliff:g></string>
+    <string name="description_details_action">Call details for <xliff:g id="nameOrNumber" example="John Smith">^1</xliff:g></string>
 
     <!-- Toast message which appears when a call log entry is deleted.
          [CHAR LIMIT=NONE] -->
diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java
index e799b00..aba00b0 100644
--- a/src/com/android/dialer/calllog/CallLogAdapter.java
+++ b/src/com/android/dialer/calllog/CallLogAdapter.java
@@ -29,6 +29,7 @@
 import android.provider.ContactsContract;
 import android.provider.ContactsContract.PhoneLookup;
 import android.telecom.PhoneAccountHandle;
+import android.telephony.PhoneNumberUtils;
 import android.text.TextUtils;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -45,6 +46,7 @@
 import com.android.contacts.common.CallUtil;
 import com.android.contacts.common.ContactPhotoManager;
 import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest;
+import com.android.contacts.common.util.PhoneNumberHelper;
 import com.android.contacts.common.model.Contact;
 import com.android.contacts.common.model.ContactLoader;
 import com.android.contacts.common.util.UriUtils;
@@ -754,7 +756,8 @@
         final String label = info.label;
         final long photoId = info.photoId;
         final Uri photoUri = info.photoUri;
-        CharSequence formattedNumber = info.formattedNumber;
+        CharSequence formattedNumber = info.formattedNumber == null
+                ? null : PhoneNumberUtils.ttsSpanAsPhoneNumber(info.formattedNumber);
         final int[] callTypes = getCallTypes(c, count);
         final String geocode = c.getString(CallLogQuery.GEOCODED_LOCATION);
         final int sourceType = info.sourceType;
diff --git a/src/com/android/dialer/calllog/CallLogListItemHelper.java b/src/com/android/dialer/calllog/CallLogListItemHelper.java
index 4ebfb4b..793a175 100644
--- a/src/com/android/dialer/calllog/CallLogListItemHelper.java
+++ b/src/com/android/dialer/calllog/CallLogListItemHelper.java
@@ -19,6 +19,7 @@
 import android.content.Context;
 import android.content.res.Resources;
 import android.provider.CallLog.Calls;
+import android.text.SpannableStringBuilder;
 import android.text.TextUtils;
 
 import com.android.contacts.common.CallUtil;
@@ -79,16 +80,24 @@
      */
     public void setActionContentDescriptions(CallLogListItemViews views) {
         views.callBackButtonView.setContentDescription(
-                mResources.getString(R.string.description_call_back_action, views.nameOrNumber));
+                TextUtils.expandTemplate(
+                        mResources.getString(R.string.description_call_back_action),
+                        views.nameOrNumber));
 
         views.videoCallButtonView.setContentDescription(
-                mResources.getString(R.string.description_video_call_action, views.nameOrNumber));
+                TextUtils.expandTemplate(
+                        mResources.getString(R.string.description_video_call_action),
+                        views.nameOrNumber));
 
         views.voicemailButtonView.setContentDescription(
-                mResources.getString(R.string.description_voicemail_action, views.nameOrNumber));
+                TextUtils.expandTemplate(
+                        mResources.getString(R.string.description_voicemail_action),
+                        views.nameOrNumber));
 
         views.detailsButtonView.setContentDescription(
-                mResources.getString(R.string.description_details_action, views.nameOrNumber));
+                TextUtils.expandTemplate(
+                        mResources.getString(R.string.description_details_action),
+                        views.nameOrNumber));
     }
 
     /**
@@ -149,7 +158,7 @@
         // Get the time/date of the call
         final CharSequence timeOfCall = mPhoneCallDetailsHelper.getCallDate(details);
 
-        StringBuilder callDescription = new StringBuilder();
+        SpannableStringBuilder callDescription = new SpannableStringBuilder();
 
         // Prepend the voicemail indication.
         if (isVoiceMail) {
@@ -172,13 +181,19 @@
         String accountLabel = PhoneAccountUtils.getAccountLabel(context, details.accountHandle);
 
         // Use chosen string resource to build up the message.
-        callDescription.append(mResources.getString(stringID,
-                nameOrNumber,
-                // If no type or location can be determined, sub in empty string.
-                typeOrLocation == null ? "" : typeOrLocation,
-                timeOfCall,
-                accountLabel == null ? "" :
-                    mResources.getString(R.string.description_phone_account, accountLabel)));
+        CharSequence onAccountLabel = accountLabel == null
+                ? ""
+                : TextUtils.expandTemplate(
+                        mResources.getString(R.string.description_phone_account),
+                        accountLabel);
+        callDescription.append(
+                TextUtils.expandTemplate(
+                        mResources.getString(stringID),
+                        nameOrNumber,
+                        // If no type or location can be determined, sub in empty string.
+                        typeOrLocation == null ? "" : typeOrLocation,
+                        timeOfCall,
+                        onAccountLabel));
 
         return callDescription;
     }
diff --git a/src/com/android/dialer/list/ShortcutCardsAdapter.java b/src/com/android/dialer/list/ShortcutCardsAdapter.java
index 78b774b..7864788 100644
--- a/src/com/android/dialer/list/ShortcutCardsAdapter.java
+++ b/src/com/android/dialer/list/ShortcutCardsAdapter.java
@@ -21,6 +21,7 @@
 import android.database.Cursor;
 import android.database.DataSetObserver;
 import android.graphics.Rect;
+import android.text.TextUtils;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewConfiguration;
@@ -258,8 +259,11 @@
 
             // TODO: Set content description including type/location and time information.
             TextView nameView = (TextView) actionView.findViewById(R.id.name);
-            actionView.setContentDescription(getResources().getString(
-                    R.string.description_call_back_action, nameView.getText()));
+
+            actionView.setContentDescription(
+                    TextUtils.expandTemplate(
+                            getResources().getString(R.string.description_call_back_action),
+                            nameView.getText()));
 
             mPreviousTranslationZ = getResources().getDimensionPixelSize(
                     R.dimen.recent_call_log_item_translation_z);