示例#1
0
  private void update() {
    enableListeners(false);

    List<LanguageData> languages = TtsPlayer.INSTANCE.refreshLanguages();
    mLanguages.clear();
    mCurrentLanguage = null;

    if (languages.isEmpty()) {
      mPrefEnabled.setChecked(false);
      mPrefEnabled.setEnabled(false);
      mPrefEnabled.setSummary(R.string.pref_tts_unavailable);
      mPrefLanguages.setEnabled(false);
      mPrefLanguages.setSummary(null);

      enableListeners(true);
      return;
    }

    mPrefEnabled.setChecked(TtsPlayer.INSTANCE.isEnabled());
    mPrefEnabled.setSummary(null);

    final CharSequence[] entries = new CharSequence[languages.size()];
    final CharSequence[] values = new CharSequence[languages.size()];
    for (int i = 0; i < languages.size(); i++) {
      LanguageData lang = languages.get(i);
      entries[i] = lang.name;
      values[i] = lang.internalCode;

      mLanguages.put(lang.internalCode, lang);
    }

    mPrefLanguages.setEntries(entries);
    mPrefLanguages.setEntryValues(values);

    mCurrentLanguage = TtsPlayer.getSelectedLanguage(languages);
    boolean available = (mCurrentLanguage != null && mCurrentLanguage.downloaded);
    mPrefLanguages.setEnabled(available && TtsPlayer.INSTANCE.isEnabled());
    mPrefLanguages.setSummary(available ? mCurrentLanguage.name : null);
    mPrefLanguages.setValue(available ? mCurrentLanguage.internalCode : null);
    mPrefEnabled.setChecked(available && TtsPlayer.INSTANCE.isEnabled());

    enableListeners(true);
  }
示例#2
0
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
          Statistics.INSTANCE.trackEvent(
              Statistics.EventName.Settings.VOICE_ENABLED,
              Statistics.params().add(Statistics.EventParam.ENABLED, newValue.toString()));
          boolean set = (Boolean) newValue;
          if (!set) {
            TtsPlayer.setEnabled(false);
            mPrefLanguages.setEnabled(false);
            return true;
          }

          if (mCurrentLanguage != null && mCurrentLanguage.downloaded) {
            setLanguage(mCurrentLanguage);
            return true;
          }

          mPrefLanguages.setEnabled(true);
          getPreferenceScreen().onItemClick(null, null, mPrefLanguages.getOrder(), 0);
          mPrefLanguages.setEnabled(false);
          return false;
        }