22
33import android .content .Context ;
44import android .speech .tts .TextToSpeech ;
5+ import android .speech .tts .Voice ;
56import android .util .AttributeSet ;
67import android .view .View ;
78import android .view .accessibility .AccessibilityEvent ;
1314import androidx .core .widget .NestedScrollView ;
1415
1516import java .util .Locale ;
17+ import java .util .Set ;
1618
1719import ee .ria .DigiDoc .R ;
1820import ee .ria .DigiDoc .common .TextUtil ;
@@ -38,8 +40,16 @@ public final class HomeMenuView extends NestedScrollView {
3840 new TextToSpeech .OnInitListener () {
3941 @ Override
4042 public void onInit (int status ) {
41- Locale accessibilityLocale = textToSpeech .getVoice ().getLocale ();
42- if (accessibilityLocale .getLanguage ().equals ("et" )) {
43+ Voice textToSpeechVoice = textToSpeech .getVoice ();
44+ String language = Locale .getDefault ().getLanguage ();
45+ boolean isESTLanguageAvailable = isTextToSpeechLanguageAvailable (textToSpeech .getAvailableLanguages (),
46+ Set .of (new Locale ("est" , "EST" ), new Locale ("et" , "ET" )));
47+ if ((textToSpeechVoice == null && isESTLanguageAvailable ) ||
48+ (textToSpeechVoice != null &&
49+ textToSpeechVoice .getLocale ().getLanguage ().equals ("et" ))) {
50+ language = "et" ;
51+ }
52+ if (language .equals ("et" )) {
4353 helpView .setContentDescription (
4454 getResources ().getString (R .string .main_home_menu_help ) +
4555 " link " +
@@ -114,4 +124,10 @@ public void locale(@Nullable Integer locale) {
114124 public Observable <Integer > localeChecks () {
115125 return checkedChanges (localeView ).skipInitialValue ();
116126 }
127+
128+ private boolean isTextToSpeechLanguageAvailable (Set <Locale > availableLocales , Set <Locale > locales ) {
129+ return locales .stream ().anyMatch (lo ->
130+ availableLocales .stream ().anyMatch (al -> al .getLanguage ().equals (lo .getLanguage ()))
131+ );
132+ }
117133}
0 commit comments