From 355ffe46ac0e6b426553dea1825ace734dfac7fe Mon Sep 17 00:00:00 2001 From: Harry Bond Date: Mon, 4 Mar 2024 10:58:06 +0000 Subject: [PATCH] [android] add button to open system TTS settings Signed-off-by: Harry Bond --- .../VoiceInstructionsSettingsFragment.java | 22 ++++- .../main/res/xml/prefs_voice_instructions.xml | 3 + data/strings/strings.txt | 94 +++++++++++++++++++ 3 files changed, 118 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/java/app/organicmaps/settings/VoiceInstructionsSettingsFragment.java b/android/app/src/main/java/app/organicmaps/settings/VoiceInstructionsSettingsFragment.java index cb3efbc44e..5274f5def2 100644 --- a/android/app/src/main/java/app/organicmaps/settings/VoiceInstructionsSettingsFragment.java +++ b/android/app/src/main/java/app/organicmaps/settings/VoiceInstructionsSettingsFragment.java @@ -1,5 +1,6 @@ package app.organicmaps.settings; +import android.content.ActivityNotFoundException; import android.content.Intent; import android.content.res.Configuration; import android.os.Bundle; @@ -8,6 +9,7 @@ import android.text.Spannable; import android.text.SpannableString; import android.text.style.ForegroundColorSpan; import android.view.View; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -50,7 +52,6 @@ public class VoiceInstructionsSettingsFragment extends BaseXmlSettingsFragment @NonNull @SuppressWarnings("NotNullFieldNotInitialized") private Preference mTtsVoiceTest; - private List mTtsTestStringArray; private int mTestStringIndex; @@ -116,6 +117,25 @@ public class VoiceInstructionsSettingsFragment extends BaseXmlSettingsFragment mTtsPrefEnabled = getPreference(getString(R.string.pref_tts_enabled)); mTtsPrefLanguages = getPreference(getString(R.string.pref_tts_language)); mTtsLangInfo = getPreference(getString(R.string.pref_tts_info)); + + Preference mTtsOpenSystemSettings = getPreference(getString(R.string.pref_tts_open_system_settings)); + mTtsOpenSystemSettings.setOnPreferenceClickListener(pref -> { + try + { + final Intent intent = new Intent() + .setAction("com.android.settings.TTS_SETTINGS") + .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + return true; + } + catch(ActivityNotFoundException e) + { + CharSequence noTtsSettingString = getString(R.string.pref_tts_no_system_tts); + Toast.makeText(super.getSettingsActivity(), noTtsSettingString, Toast.LENGTH_LONG).show(); + return false; + } + }); + mTtsVoiceTest = getPreference(getString(R.string.pref_tts_test_voice)); mTtsVoiceTest.setOnPreferenceClickListener(pref -> { if (mTtsTestStringArray == null) diff --git a/android/app/src/main/res/xml/prefs_voice_instructions.xml b/android/app/src/main/res/xml/prefs_voice_instructions.xml index cf1ef421b7..6e4d25642a 100644 --- a/android/app/src/main/res/xml/prefs_voice_instructions.xml +++ b/android/app/src/main/res/xml/prefs_voice_instructions.xml @@ -15,6 +15,9 @@ +