From bac4da9d520846ab4e4f8cbcbb80927076deec27 Mon Sep 17 00:00:00 2001 From: linyuh Date: Thu, 7 Jun 2018 17:34:13 -0700 Subject: Wrap phone numbers in custom content descriptions in the new call log with TTS span. Bug: 70989658 Test: Manual (TTS span is not testable) PiperOrigin-RevId: 199724621 Change-Id: I6dc809660eecdd987ee966f30b68dbbf7bcf2094 --- .../calllogutils/CallLogEntryDescriptions.java | 53 +++++++++++----------- .../dialer/calllogutils/CallLogEntryText.java | 3 +- .../dialer/calllogutils/res/values/strings.xml | 24 +++++----- 3 files changed, 41 insertions(+), 39 deletions(-) (limited to 'java/com/android/dialer/calllogutils') diff --git a/java/com/android/dialer/calllogutils/CallLogEntryDescriptions.java b/java/com/android/dialer/calllogutils/CallLogEntryDescriptions.java index 244087989..52f0cfdb7 100644 --- a/java/com/android/dialer/calllogutils/CallLogEntryDescriptions.java +++ b/java/com/android/dialer/calllogutils/CallLogEntryDescriptions.java @@ -20,6 +20,7 @@ import android.content.Context; import android.provider.CallLog.Calls; import android.support.annotation.PluralsRes; import android.telecom.PhoneAccountHandle; +import android.telephony.PhoneNumberUtils; import android.text.TextUtils; import com.android.dialer.calllog.model.CoalescedRow; import com.android.dialer.telecom.TelecomUtil; @@ -65,13 +66,14 @@ public final class CallLogEntryDescriptions { // (2) For entries containing multiple calls: // "2 calls, the latest is a missed call from Jame Smith". CharSequence primaryDescription = - context - .getResources() - .getQuantityString( - getPrimaryDescriptionResIdForCallType(row), - row.getCoalescedIds().getCoalescedIdCount(), - row.getCoalescedIds().getCoalescedIdCount(), - CallLogEntryText.buildPrimaryText(context, row)); + TextUtils.expandTemplate( + context + .getResources() + .getQuantityString( + getPrimaryDescriptionResIdForCallType(row), + row.getCoalescedIds().getCoalescedIdCount()), + String.valueOf(row.getCoalescedIds().getCoalescedIdCount()), + CallLogEntryText.buildPrimaryText(context, row)); // Build the secondary description. // An example: "mobile, 11 minutes ago". @@ -85,19 +87,20 @@ public final class CallLogEntryDescriptions { CharSequence phoneAccountDescription = buildPhoneAccountDescription(context, row); return TextUtils.isEmpty(phoneAccountDescription) - ? context - .getResources() - .getString( - R.string.a11y_new_call_log_entry_full_description_without_phone_account_info, - primaryDescription, - secondaryDescription) - : context - .getResources() - .getString( - R.string.a11y_new_call_log_entry_full_description_with_phone_account_info, - primaryDescription, - secondaryDescription, - phoneAccountDescription); + ? TextUtils.expandTemplate( + context + .getResources() + .getText( + R.string.a11y_new_call_log_entry_full_description_without_phone_account_info), + primaryDescription, + secondaryDescription) + : TextUtils.expandTemplate( + context + .getResources() + .getText(R.string.a11y_new_call_log_entry_full_description_with_phone_account_info), + primaryDescription, + secondaryDescription, + phoneAccountDescription); } private static @PluralsRes int getPrimaryDescriptionResIdForCallType(CoalescedRow row) { @@ -139,12 +142,10 @@ public final class CallLogEntryDescriptions { return ""; } - return context - .getResources() - .getString( - R.string.a11y_new_call_log_entry_phone_account, - phoneAccountLabel, - row.getNumber().getNormalizedNumber()); + return TextUtils.expandTemplate( + context.getResources().getText(R.string.a11y_new_call_log_entry_phone_account), + phoneAccountLabel, + PhoneNumberUtils.createTtsSpannable(row.getNumber().getNormalizedNumber())); } private static CharSequence joinSecondaryTextComponents(List components) { diff --git a/java/com/android/dialer/calllogutils/CallLogEntryText.java b/java/com/android/dialer/calllogutils/CallLogEntryText.java index 895497f0f..1ec172f6f 100644 --- a/java/com/android/dialer/calllogutils/CallLogEntryText.java +++ b/java/com/android/dialer/calllogutils/CallLogEntryText.java @@ -18,6 +18,7 @@ package com.android.dialer.calllogutils; import android.content.Context; import android.provider.CallLog.Calls; +import android.telephony.PhoneNumberUtils; import android.text.TextUtils; import com.android.dialer.calllog.model.CoalescedRow; import com.android.dialer.duo.DuoComponent; @@ -69,7 +70,7 @@ public final class CallLogEntryText { // 4th preference: the formatted number. if (!TextUtils.isEmpty(row.getFormattedNumber())) { - return row.getFormattedNumber(); + return PhoneNumberUtils.createTtsSpannable(row.getFormattedNumber()); } // Last resort: show "Unknown". diff --git a/java/com/android/dialer/calllogutils/res/values/strings.xml b/java/com/android/dialer/calllogutils/res/values/strings.xml index 52b6d3408..3fbfb4447 100644 --- a/java/com/android/dialer/calllogutils/res/values/strings.xml +++ b/java/com/android/dialer/calllogutils/res/values/strings.xml @@ -151,8 +151,8 @@ [CHAR LIMIT=NONE] --> - %1$d missed call from %2$s - %1$d calls, the latest is a missed call from %2$s + ^1 missed call from ^2 + ^1 calls, the latest is a missed call from ^2 - %1$d answered call from %2$s - %1$d calls, the latest is an answered call from %2$s + ^1 answered call from ^2 + ^1 calls, the latest is an answered call from ^2 - %1$d outgoing call to %2$s - %1$d calls, the latest is an outgoing call to %2$s + ^1 outgoing call to ^2 + ^1 calls, the latest is an outgoing call to ^2 - %1$d blocked call from %2$s - %1$d calls, the latest is a blocked call from %2$s + ^1 blocked call from ^2 + ^1 calls, the latest is a blocked call from ^2 @@ -189,8 +189,8 @@ [CHAR LIMIT=NONE] --> - on %1$s, - via %2$s + on ^1, + via ^2 - %1$s, %2$s. + ^1, ^2. - %1$s, %2$s, %3$s. + ^1, ^2, ^3. -- cgit v1.2.3