Add TtsSpan for formatted time.

Talk back will read "Used for 3m" as "Used for 3 meters", but
it will read "Used for 3h 3m" correctly.

This cl add specific Ttsspan if the time only contains "minute"

Bug: 36379530
Test: Run SettingsRoboTests

Change-Id: I033575938cce24221980dddd9d66be4e18804541
This commit is contained in:
jackqdyulei
2017-03-31 12:57:10 -07:00
parent 9e89d528f6
commit f4c1cef322
13 changed files with 142 additions and 63 deletions

View File

@@ -81,6 +81,8 @@ import android.support.v7.preference.PreferenceScreen;
import android.telephony.TelephonyManager;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.text.style.TtsSpan;
@@ -770,8 +772,9 @@ public final class Utils extends com.android.settingslib.Utils {
* @param withSeconds include seconds?
* @return the formatted elapsed time
*/
public static String formatElapsedTime(Context context, double millis, boolean withSeconds) {
StringBuilder sb = new StringBuilder();
public static CharSequence formatElapsedTime(Context context, double millis,
boolean withSeconds) {
SpannableStringBuilder sb = new SpannableStringBuilder();
int seconds = (int) Math.floor(millis / 1000);
if (!withSeconds) {
// Round up.
@@ -812,9 +815,15 @@ public final class Utils extends com.android.settingslib.Utils {
hours, minutes));
} else {
sb.append(context.getString(R.string.battery_history_minutes_no_seconds, minutes));
// Add ttsSpan if it only have minute value, because it will be read as "meters"
TtsSpan ttsSpan = new TtsSpan.MeasureBuilder().setNumber(minutes)
.setUnit("minute").build();
sb.setSpan(ttsSpan, 0, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return sb.toString();
return sb;
}
/**
@@ -1256,4 +1265,5 @@ public final class Utils extends com.android.settingslib.Utils {
return (volume != null) && (volume.getType() == VolumeInfo.TYPE_PRIVATE)
&& volume.isMountedReadable();
}
}