Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5a98d436 authored by Craig Mautner's avatar Craig Mautner
Browse files

Take TextToSpeechSettings out of endless loop

Launching an Activity using startActivityForResult() every time
you are in onResume() is a recipe for endless looping. I.e. every
time the launched Activity finishes it will be relaunched because
the launching Activity reenters onResume().

This change keeps the GetSampleText activity from being launched
from onResume if we already have the sample text and the Locale
hasn't changed since the last onResume.

Fixes bug 15951054.

Change-Id: I65d9070df93396d8d3a45a6673ae56826f418122
parent ebdd13fa
Loading
Loading
Loading
Loading
+7 −2
Original line number Original line Diff line number Diff line
@@ -47,6 +47,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.List;
import java.util.Locale;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.MissingResourceException;
import java.util.Objects;
import java.util.Set;
import java.util.Set;


public class TextToSpeechSettings extends SettingsPreferenceFragment implements
public class TextToSpeechSettings extends SettingsPreferenceFragment implements
@@ -104,7 +105,7 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
    private TextToSpeech mTts = null;
    private TextToSpeech mTts = null;
    private TtsEngines mEnginesHelper = null;
    private TtsEngines mEnginesHelper = null;


    private String mSampleText = "";
    private String mSampleText = null;


    /**
    /**
     * Default locale used by selected TTS engine, null if not connected to any engine.
     * Default locale used by selected TTS engine, null if not connected to any engine.
@@ -270,10 +271,14 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements


        // ISO-3166 alpha 3 country codes are out of spec. If we won't normalize,
        // ISO-3166 alpha 3 country codes are out of spec. If we won't normalize,
        // we may end up with English (USA)and German (DEU).
        // we may end up with English (USA)and German (DEU).
        final Locale oldDefaultLocale = mCurrentDefaultLocale;
        mCurrentDefaultLocale = mEnginesHelper.parseLocaleString(defaultLocale.toString());
        mCurrentDefaultLocale = mEnginesHelper.parseLocaleString(defaultLocale.toString());
        if (!Objects.equals(oldDefaultLocale, mCurrentDefaultLocale)) {
            mSampleText = null;
        }


        int defaultAvailable = mTts.setLanguage(defaultLocale);
        int defaultAvailable = mTts.setLanguage(defaultLocale);
        if (evaluateDefaultLocale()) {
        if (evaluateDefaultLocale() && mSampleText == null) {
            getSampleText();
            getSampleText();
        }
        }
    }
    }