mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-11-05 06:45:39 +00:00
106 lines
3.9 KiB
Java
106 lines
3.9 KiB
Java
/*
|
|
* Copyright (C) 2013 Reece H. Dunn
|
|
* Copyright (C) 2011 The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
package com.reecedunn.espeak;
|
|
|
|
import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.preference.ListPreference;
|
|
import android.preference.Preference;
|
|
import android.preference.Preference.OnPreferenceChangeListener;
|
|
import android.preference.PreferenceActivity;
|
|
import android.preference.PreferenceFragment;
|
|
import android.preference.PreferenceGroup;
|
|
|
|
public class TtsSettingsActivity extends PreferenceActivity {
|
|
@Override
|
|
@SuppressWarnings("deprecation")
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
|
|
{
|
|
getFragmentManager().beginTransaction().replace(
|
|
android.R.id.content,
|
|
new PrefsEspeakFragment()).commit();
|
|
}
|
|
else
|
|
{
|
|
addPreferencesFromResource(R.xml.preferences);
|
|
fixListSummaries(getPreferenceScreen());
|
|
}
|
|
}
|
|
|
|
public static class PrefsEspeakFragment extends PreferenceFragment {
|
|
@Override
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
|
|
addPreferencesFromResource(R.xml.preferences);
|
|
fixListSummaries(getPreferenceScreen());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Since the "%s" summary is currently broken, this sets the preference
|
|
* change listener for all {@link ListPreference} views to fill in the
|
|
* summary with the current entry value.
|
|
*/
|
|
private static void fixListSummaries(PreferenceGroup group) {
|
|
if (group == null) {
|
|
return;
|
|
}
|
|
|
|
final int count = group.getPreferenceCount();
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
final Preference preference = group.getPreference(i);
|
|
|
|
if (preference instanceof PreferenceGroup) {
|
|
fixListSummaries((PreferenceGroup) preference);
|
|
} else if (preference instanceof ListPreference) {
|
|
preference.setOnPreferenceChangeListener(mPreferenceChangeListener);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Listens for preference changes and updates the summary to reflect the
|
|
* current setting. This shouldn't be necessary, since preferences are
|
|
* supposed to automatically do this when the summary is set to "%s".
|
|
*/
|
|
private static final OnPreferenceChangeListener mPreferenceChangeListener =
|
|
new OnPreferenceChangeListener() {
|
|
@Override
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
if (preference instanceof ListPreference && newValue instanceof String) {
|
|
final ListPreference listPreference = (ListPreference) preference;
|
|
final int index = listPreference.findIndexOfValue((String) newValue);
|
|
final CharSequence[] entries = listPreference.getEntries();
|
|
|
|
if (index >= 0 && index < entries.length) {
|
|
preference.setSummary(entries[index].toString().replaceAll("%", "%%"));
|
|
} else {
|
|
preference.setSummary("");
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
};
|
|
}
|