From 43af6366f2aad8c0c0a8ae1367215961ccd75c29 Mon Sep 17 00:00:00 2001 From: Mihai Nita Date: Tue, 19 Apr 2016 09:09:07 -0700 Subject: [PATCH] Framework: change the TTS text to use the current locale MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Google TTS currently does not support language auto-switching. Also, not all languages are available in TTS at all times. This means that TTS cannot properly handle text in other languages / scripts than the current language. Languages with different scripts would not be read at all, and the others would be read with "bad pronunciation", to the point of being unrecognizable. This change is not a full fix, but makes things slightly better by using the default locale for the contentDescription in the language / region lists. This might be a bit unsettling, as the label will not match the sound. The label will show "Deutsch" or "Русский" and text-to-speech will say "German" or "Russian" (for English UI), or "Allemand" or "Russe" (if the UI is French). Might also say nothing, if the current UI language has no text-to-speech engine. But this is the best we can do, and better that what we get if we do nothing. Bug: 28087937 Change-Id: I7390a063708647e022be29161c2f2bedc19896ae --- .../java/com/android/internal/app/LocaleStore.java | 14 ++++++++++++++ .../internal/app/SuggestedLocaleAdapter.java | 1 + 2 files changed, 15 insertions(+) diff --git a/core/java/com/android/internal/app/LocaleStore.java b/core/java/com/android/internal/app/LocaleStore.java index 7803e52c45e1a..e3fce5197dca7 100644 --- a/core/java/com/android/internal/app/LocaleStore.java +++ b/core/java/com/android/internal/app/LocaleStore.java @@ -126,12 +126,18 @@ public class LocaleStore { return mFullCountryNameNative; } + String getFullCountryNameInUiLanguage() { + // We don't cache the UI name because the default locale keeps changing + return LocaleHelper.getDisplayCountry(mLocale); + } + /** Returns the name of the locale in the language of the UI. * It is used for search, but never shown. * For instance German will show as "Deutsch" in the list, but we will also search for * "allemand" if the system UI is in French. */ public String getFullNameInUiLanguage() { + // We don't cache the UI name because the default locale keeps changing return LocaleHelper.getDisplayName(mLocale, true /* sentence case */); } @@ -154,6 +160,14 @@ public class LocaleStore { } } + String getContentDescription(boolean countryMode) { + if (countryMode) { + return getFullCountryNameInUiLanguage(); + } else { + return getFullNameInUiLanguage(); + } + } + public boolean getChecked() { return mIsChecked; } diff --git a/core/java/com/android/internal/app/SuggestedLocaleAdapter.java b/core/java/com/android/internal/app/SuggestedLocaleAdapter.java index e2d29e313be4a..a4b5a8e6595c8 100644 --- a/core/java/com/android/internal/app/SuggestedLocaleAdapter.java +++ b/core/java/com/android/internal/app/SuggestedLocaleAdapter.java @@ -159,6 +159,7 @@ public class SuggestedLocaleAdapter extends BaseAdapter implements Filterable { LocaleStore.LocaleInfo item = (LocaleStore.LocaleInfo) getItem(position); text.setText(item.getLabel(mCountryMode)); text.setTextLocale(item.getLocale()); + text.setContentDescription(item.getContentDescription(mCountryMode)); if (mCountryMode) { int layoutDir = TextUtils.getLayoutDirectionFromLocale(item.getParent()); //noinspection ResourceType