From 1e5325f43c98a92f8bfec1dbd9db3d32a91835e9 Mon Sep 17 00:00:00 2001 From: Ihab Awad Date: Mon, 1 Dec 2014 14:47:38 -0800 Subject: Add Text-to-Speech annotations for phone number displays (3/3) Bug: 17321294 Change-Id: Icc712da80e25e5a5294986ece055fcffaa558f1e --- res/values/strings.xml | 16 ++++----- src/com/android/dialer/calllog/CallLogAdapter.java | 5 ++- .../dialer/calllog/CallLogListItemHelper.java | 39 +++++++++++++++------- .../android/dialer/list/ShortcutCardsAdapter.java | 8 +++-- 4 files changed, 45 insertions(+), 23 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 1dee6442e..5d0685227 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -578,49 +578,49 @@ - Missed call from %1$s, %2$s, %3$s, %4$s. + Missed call from ^1, ^2, ^3, ^4. - Answered call from %1$s, %2$s, %3$s, %4$s. + Answered call from ^1, ^2, ^3, ^4. - Call to %1$s, %2$s, %3$s, %4$s. + Call to ^1, ^2, ^3, ^4. - on %1$s + on ^1 - Call back %1$s + Call back ^1 - Video call to %1$s. + Video call to ^1. - Listen to voicemail from %1$s + Listen to voicemail from ^1 - Call details for %1$s + Call details for ^1 diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java index e799b00cc..aba00b036 100644 --- a/src/com/android/dialer/calllog/CallLogAdapter.java +++ b/src/com/android/dialer/calllog/CallLogAdapter.java @@ -29,6 +29,7 @@ import android.provider.CallLog.Calls; 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.common.widget.GroupingListAdapter; 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 @@ public class CallLogAdapter extends GroupingListAdapter 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 4ebfb4b88..793a1755c 100644 --- a/src/com/android/dialer/calllog/CallLogListItemHelper.java +++ b/src/com/android/dialer/calllog/CallLogListItemHelper.java @@ -19,6 +19,7 @@ package com.android.dialer.calllog; 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 @@ import com.android.dialer.R; */ 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 @@ import com.android.dialer.R; // 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 @@ import com.android.dialer.R; 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 78b774b02..78647882c 100644 --- a/src/com/android/dialer/list/ShortcutCardsAdapter.java +++ b/src/com/android/dialer/list/ShortcutCardsAdapter.java @@ -21,6 +21,7 @@ import android.content.res.Resources; 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 @@ public class ShortcutCardsAdapter extends BaseAdapter { // 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); -- cgit v1.2.3