The original variant list UI resulted in a long, complex list that was difficult to navigate. This change splits up that list into more manageable groups.master
@@ -0,0 +1,52 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="vertical" > | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="48dp" | |||
android:layout_gravity="center"> | |||
<TextView | |||
android:layout_width="0dp" | |||
android:layout_height="wrap_content" | |||
android:textAppearance="?android:attr/textAppearanceMedium" | |||
android:text="@string/category" | |||
android:layout_weight="0.5" | |||
android:gravity="center_vertical" | |||
android:layout_gravity="center_vertical" /> | |||
<Spinner | |||
android:layout_width="0dp" | |||
android:layout_height="wrap_content" | |||
android:id="@+id/category" | |||
android:layout_weight="0.5" | |||
android:gravity="bottom" | |||
android:layout_gravity="center_vertical" /> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="48dp"> | |||
<TextView | |||
android:layout_width="0dp" | |||
android:layout_height="wrap_content" | |||
android:textAppearance="?android:attr/textAppearanceMedium" | |||
android:text="@string/variant" | |||
android:layout_weight="0.5" | |||
android:gravity="center_vertical" | |||
android:layout_gravity="center_vertical" /> | |||
<Spinner | |||
android:layout_width="0dp" | |||
android:layout_height="wrap_content" | |||
android:id="@+id/variant" | |||
android:layout_weight="0.5" | |||
android:gravity="bottom" | |||
android:layout_gravity="center_vertical" /> | |||
</LinearLayout> | |||
</LinearLayout> |
@@ -6,32 +6,7 @@ | |||
--> | |||
<string name="app_name" translatable="false">eSpeak</string> | |||
<string-array name="default_variant_values"> | |||
<item>male</item> | |||
<item>m1</item> | |||
<item>m2</item> | |||
<item>m3</item> | |||
<item>m4</item> | |||
<item>m5</item> | |||
<item>m6</item> | |||
<item>m7</item> | |||
<item>female</item> | |||
<item>f1</item> | |||
<item>f2</item> | |||
<item>f3</item> | |||
<item>f4</item> | |||
<item>f5</item> | |||
<item>klatt</item> | |||
<item>klatt2</item> | |||
<item>klatt3</item> | |||
<item>klatt4</item> | |||
<item>croak</item> | |||
<item>whisper</item> | |||
<item>whisperf</item> | |||
<item>male-young</item> | |||
<item>female-young</item> | |||
<item>male-old</item> | |||
<item>female-old</item> | |||
</string-array> | |||
<!-- Voice Variants that are people's names. --> | |||
<string name="variant_klatt">Klatt</string> | |||
</resources> |
@@ -65,41 +65,6 @@ | |||
Description: Sample text spoken aloud when the user is trying out a language. | |||
--> | |||
<string name="sample_text">This is a sample of text spoken in %s</string> | |||
<!-- | |||
Source: Variant preference labels. | |||
Description: Labels for possible voice variant/gender/age values. | |||
--> | |||
<string-array name="default_variant_entries"> | |||
<item>Male</item> | |||
<item>Male (Variant 1)</item> | |||
<item>Male (Variant 2)</item> | |||
<item>Male (Variant 3)</item> | |||
<item>Male (Variant 4)</item> | |||
<item>Male (Variant 5)</item> | |||
<item>Male (Variant 6)</item> | |||
<item>Male (Variant 7)</item> | |||
<item>Female</item> | |||
<item>Female (Variant 1)</item> | |||
<item>Female (Variant 2)</item> | |||
<item>Female (Variant 3)</item> | |||
<item>Female (Variant 4)</item> | |||
<item>Female (Variant 5)</item> | |||
<item>Klatt (Variant 1)</item> | |||
<item>Klatt (Variant 2)</item> | |||
<item>Klatt (Variant 3)</item> | |||
<item>Klatt (Variant 4)</item> | |||
<item>Croak (Male)</item> | |||
<item>Whisper (Male)</item> | |||
<item>Whisper (Female)</item> | |||
<item>Young (Male)</item> | |||
<item>Young (Female)</item> | |||
<item>Old (Male)</item> | |||
<item>Old (Female)</item> | |||
</string-array> | |||
<!-- | |||
Source: Rate preference labels. | |||
Description: Labels for possible rate multiplier values. | |||
--> | |||
<string name="status">Status</string> | |||
<string name="tts_version">eSpeak version</string> | |||
<string name="speak">Speak</string> | |||
@@ -117,4 +82,14 @@ | |||
<string name="punctuation_custom_fmt">Custom: %s</string> | |||
<string name="punctuation_none">None</string> | |||
<string name="punctuation_characters">Punctuation characters</string> | |||
<string name="category">Category</string> | |||
<string name="variant">Variant</string> | |||
<string name="variant_male">Male</string> | |||
<string name="variant_female">Female</string> | |||
<string name="variant_default">Default</string> | |||
<string name="variant_n">Variant %d</string> | |||
<string name="variant_young">Young</string> | |||
<string name="variant_old">Old</string> | |||
<string name="variant_croak">Croak</string> | |||
<string name="variant_whisper">Whisper</string> | |||
</resources> |
@@ -1,12 +1,3 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > | |||
<ListPreference | |||
android:defaultValue="1" | |||
android:entries="@array/default_variant_entries" | |||
android:entryValues="@array/default_variant_values" | |||
android:key="espeak_variant" | |||
android:summary="%s" | |||
android:title="@string/espeak_variant" /> | |||
</PreferenceScreen> |
@@ -0,0 +1,66 @@ | |||
/* | |||
* Copyright (C) 2012 Reece H. Dunn | |||
* | |||
* 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.app.Activity; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.view.ViewGroup; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.TextView; | |||
public class ResourceIdListAdapter extends ArrayAdapter<Integer> | |||
{ | |||
private final LayoutInflater mInflater; | |||
static class ViewHolder | |||
{ | |||
public TextView text; | |||
} | |||
public ResourceIdListAdapter(Activity context, Integer[] resources) | |||
{ | |||
super(context, android.R.layout.simple_list_item_1, resources); | |||
mInflater = context.getLayoutInflater(); | |||
} | |||
@Override | |||
public View getView(int position, View convertView, ViewGroup parent) | |||
{ | |||
ViewHolder holder; | |||
if (convertView == null) | |||
{ | |||
convertView = mInflater.inflate(android.R.layout.simple_list_item_1, parent, false); | |||
holder = new ViewHolder(); | |||
holder.text = (TextView)convertView.findViewById(android.R.id.text1); | |||
convertView.setTag(holder); | |||
} | |||
else | |||
{ | |||
holder = (ViewHolder)convertView.getTag(); | |||
} | |||
holder.text.setText(getItem(position)); | |||
return convertView; | |||
} | |||
@Override | |||
public View getDropDownView(int position, View convertView, ViewGroup parent) | |||
{ | |||
return getView(position, convertView, parent); | |||
} | |||
} |
@@ -97,7 +97,19 @@ public class TtsSettingsActivity extends PreferenceActivity { | |||
} | |||
} | |||
private static Preference createSpeakPunctuationPreference(Context context, SpeechSynthesis engine, int titleRes) { | |||
private static Preference createVoiceVariantPreference(Context context, VoiceSettings settings, int titleRes) { | |||
final String title = context.getString(titleRes); | |||
final VoiceVariantPreference pref = new VoiceVariantPreference(context); | |||
pref.setTitle(title); | |||
pref.setDialogTitle(title); | |||
pref.setOnPreferenceChangeListener(mOnPreferenceChanged); | |||
pref.setPersistent(true); | |||
pref.setVoiceVariant(settings.getVoiceVariant()); | |||
return pref; | |||
} | |||
private static Preference createSpeakPunctuationPreference(Context context, VoiceSettings settings, int titleRes) { | |||
final String title = context.getString(titleRes); | |||
final SpeakPunctuationPreference pref = new SpeakPunctuationPreference(context); | |||
@@ -105,7 +117,7 @@ public class TtsSettingsActivity extends PreferenceActivity { | |||
pref.setDialogTitle(title); | |||
pref.setOnPreferenceChangeListener(mOnPreferenceChanged); | |||
pref.setPersistent(true); | |||
pref.setVoiceSettings(new VoiceSettings(PreferenceManager.getDefaultSharedPreferences(context), engine)); | |||
pref.setVoiceSettings(settings); | |||
return pref; | |||
} | |||
@@ -153,31 +165,11 @@ public class TtsSettingsActivity extends PreferenceActivity { | |||
* summary with the current entry value. | |||
*/ | |||
private static void createPreferences(Context context, 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) { | |||
createPreferences(null, (PreferenceGroup) preference); | |||
} else if (preference instanceof ListPreference) { | |||
preference.setOnPreferenceChangeListener(mOnPreferenceChanged); | |||
} | |||
} | |||
if (context == null) { | |||
return; | |||
} | |||
// Bind eSpeak parameters to preference settings: | |||
SpeechSynthesis engine = new SpeechSynthesis(context, null); | |||
VoiceSettings settings = new VoiceSettings(PreferenceManager.getDefaultSharedPreferences(context), engine); | |||
group.addPreference(createSpeakPunctuationPreference(context, engine, R.string.espeak_speak_punctuation)); | |||
group.addPreference(createVoiceVariantPreference(context, settings, R.string.espeak_variant)); | |||
group.addPreference(createSpeakPunctuationPreference(context, settings, R.string.espeak_speak_punctuation)); | |||
group.addPreference(createSeekBarPreference(context, engine.Rate, "espeak_rate", R.string.setting_default_rate)); | |||
group.addPreference(createSeekBarPreference(context, engine.Pitch, "espeak_pitch", R.string.setting_default_pitch)); | |||
group.addPreference(createSeekBarPreference(context, engine.PitchRange, "espeak_pitch_range", R.string.espeak_pitch_range)); |
@@ -60,6 +60,17 @@ public class VoiceVariant { | |||
return ret; | |||
} | |||
public boolean equals(Object o) { | |||
if (o instanceof VoiceVariant) { | |||
VoiceVariant other = (VoiceVariant)o; | |||
if (variant == null || other.variant == null) { | |||
return other.variant == null && variant == null && other.gender == gender && other.age == age; | |||
} | |||
return other.variant.equals(variant) && other.gender == gender && other.age == age; | |||
} | |||
return false; | |||
} | |||
public static VoiceVariant parseVoiceVariant(String value) { | |||
String[] parts = mVariantPattern.split(value); | |||
int age = SpeechSynthesis.AGE_ANY; |
@@ -0,0 +1,265 @@ | |||
/* | |||
* Copyright (C) 2013 Reece H. Dunn | |||
* | |||
* 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.app.Activity; | |||
import android.content.Context; | |||
import android.content.DialogInterface; | |||
import android.content.SharedPreferences; | |||
import android.preference.DialogPreference; | |||
import android.text.Editable; | |||
import android.util.AttributeSet; | |||
import android.util.Log; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.view.ViewGroup; | |||
import android.widget.AdapterView; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.EditText; | |||
import android.widget.RadioButton; | |||
import android.widget.Spinner; | |||
import android.widget.TextView; | |||
import java.util.List; | |||
public class VoiceVariantPreference extends DialogPreference { | |||
private Spinner mCategory; | |||
private Spinner mVariant; | |||
private int mCategoryIndex = 0; | |||
private int mVariantIndex = 0; | |||
static class ViewHolder | |||
{ | |||
public TextView text; | |||
} | |||
private class VariantData { | |||
private final int name; | |||
private final Object arg; | |||
private final VoiceVariant variant; | |||
protected VariantData(int name, String variant) { | |||
this(name, null, variant); | |||
} | |||
protected VariantData(int name, Object arg, String variant) { | |||
this.name = name; | |||
this.arg = arg; | |||
this.variant = VoiceVariant.parseVoiceVariant(variant); | |||
} | |||
public String getDisplayName(Context context) { | |||
String text = context.getText(name).toString(); | |||
if (arg == null) { | |||
return text; | |||
} | |||
return String.format(text, arg); | |||
} | |||
public VoiceVariant getVariant() { | |||
return variant; | |||
} | |||
} | |||
public class VariantDataListAdapter extends ArrayAdapter<VariantData> | |||
{ | |||
private final LayoutInflater mInflater; | |||
public VariantDataListAdapter(Activity context, VariantData[] resources) | |||
{ | |||
super(context, android.R.layout.simple_list_item_1, resources); | |||
mInflater = context.getLayoutInflater(); | |||
} | |||
@Override | |||
public View getView(int position, View convertView, ViewGroup parent) | |||
{ | |||
ViewHolder holder; | |||
if (convertView == null) | |||
{ | |||
convertView = mInflater.inflate(android.R.layout.simple_list_item_1, parent, false); | |||
holder = new ViewHolder(); | |||
holder.text = (TextView)convertView.findViewById(android.R.id.text1); | |||
convertView.setTag(holder); | |||
} | |||
else | |||
{ | |||
holder = (ViewHolder)convertView.getTag(); | |||
} | |||
holder.text.setText(getItem(position).getDisplayName(getContext())); | |||
return convertView; | |||
} | |||
@Override | |||
public View getDropDownView(int position, View convertView, ViewGroup parent) | |||
{ | |||
return getView(position, convertView, parent); | |||
} | |||
} | |||
private Integer[] categories = { | |||
R.string.variant_male, | |||
R.string.variant_female, | |||
R.string.variant_klatt, | |||
R.string.variant_young, | |||
R.string.variant_old, | |||
R.string.variant_croak, | |||
R.string.variant_whisper, | |||
}; | |||
private VariantData[][] variants = { | |||
{ // Male | |||
new VariantData(R.string.variant_default, "male"), | |||
new VariantData(R.string.variant_n, 1, "m1"), | |||
new VariantData(R.string.variant_n, 2, "m2"), | |||
new VariantData(R.string.variant_n, 3, "m3"), | |||
new VariantData(R.string.variant_n, 4, "m4"), | |||
new VariantData(R.string.variant_n, 5, "m5"), | |||
new VariantData(R.string.variant_n, 6, "m6"), | |||
new VariantData(R.string.variant_n, 7, "m7"), | |||
},{ // Female | |||
new VariantData(R.string.variant_default, "female"), | |||
new VariantData(R.string.variant_n, 1, "f1"), | |||
new VariantData(R.string.variant_n, 2, "f2"), | |||
new VariantData(R.string.variant_n, 3, "f3"), | |||
new VariantData(R.string.variant_n, 4, "f4"), | |||
new VariantData(R.string.variant_n, 5, "f5"), | |||
},{ // Klatt | |||
new VariantData(R.string.variant_n, 1, "klatt"), | |||
new VariantData(R.string.variant_n, 2, "klatt2"), | |||
new VariantData(R.string.variant_n, 3, "klatt3"), | |||
new VariantData(R.string.variant_n, 4, "klatt4"), | |||
},{ // Young | |||
new VariantData(R.string.variant_male, "male-young"), | |||
new VariantData(R.string.variant_female, "female-young"), | |||
},{ // Old | |||
new VariantData(R.string.variant_male, "male-old"), | |||
new VariantData(R.string.variant_female, "female-old"), | |||
},{ // Croak | |||
new VariantData(R.string.variant_male, "croak"), | |||
},{ // Whisper | |||
new VariantData(R.string.variant_male, "whisper"), | |||
new VariantData(R.string.variant_female, "whisperf"), | |||
}, | |||
}; | |||
public VoiceVariantPreference(Context context, AttributeSet attrs, int defStyle) { | |||
super(context, attrs, defStyle); | |||
setDialogLayoutResource(R.layout.voice_variant_preference); | |||
setLayoutResource(R.layout.information_view); | |||
setPositiveButtonText(android.R.string.ok); | |||
setNegativeButtonText(android.R.string.cancel); | |||
} | |||
public VoiceVariantPreference(Context context, AttributeSet attrs) { | |||
this(context, attrs, 0); | |||
} | |||
public VoiceVariantPreference(Context context) { | |||
this(context, null); | |||
} | |||
public void setVoiceVariant(VoiceVariant variant) { | |||
for (int i = 0; i < variants.length; ++i) { | |||
VariantData[] items = variants[i]; | |||
for (int j = 0; j < items.length; ++j) { | |||
if (items[j].getVariant().equals(variant)) { | |||
mCategoryIndex = i; | |||
mVariantIndex = j; | |||
onDataChanged(); | |||
return; | |||
} | |||
} | |||
} | |||
onDataChanged(); | |||
} | |||
@Override | |||
protected View onCreateDialogView() { | |||
View root = super.onCreateDialogView(); | |||
mCategory = (Spinner)root.findViewById(R.id.category); | |||
mVariant = (Spinner)root.findViewById(R.id.variant); | |||
return root; | |||
} | |||
@Override | |||
protected void onBindDialogView(View view) { | |||
super.onBindDialogView(view); | |||
// Cache the indices so they don't get overwritten by the OnItemSelectedListener handlers. | |||
final int category = mCategoryIndex; | |||
final int variant = mVariantIndex; | |||
mCategory.setAdapter(new ResourceIdListAdapter((Activity)getContext(), categories)); | |||
mCategory.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | |||
private boolean mInitializing = true; | |||
@Override | |||
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) { | |||
mVariant.setAdapter(new VariantDataListAdapter((Activity) getContext(), variants[position])); | |||
if (mInitializing) { | |||
mVariant.setSelection(variant); | |||
mInitializing = false; | |||
} | |||
mCategoryIndex = position; | |||
} | |||
@Override | |||
public void onNothingSelected(AdapterView<?> adapterView) { | |||
} | |||
}); | |||
mVariant.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | |||
@Override | |||
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) { | |||
mVariantIndex = position; | |||
} | |||
@Override | |||
public void onNothingSelected(AdapterView<?> adapterView) { | |||
} | |||
}); | |||
mCategory.setSelection(category); | |||
} | |||
@Override | |||
public void onClick(DialogInterface dialog, int which) { | |||
switch (which) { | |||
case DialogInterface.BUTTON_POSITIVE: | |||
onDataChanged(); | |||
if (shouldCommit()) { | |||
SharedPreferences.Editor editor = getEditor(); | |||
if (editor != null) { | |||
VoiceVariant variant = variants[mCategoryIndex][mVariantIndex].getVariant(); | |||
editor.putString(VoiceSettings.PREF_VARIANT, variant.toString()); | |||
editor.commit(); | |||
} | |||
} | |||
break; | |||
} | |||
super.onClick(dialog, which); | |||
} | |||
private void onDataChanged() { | |||
Context context = getContext(); | |||
CharSequence category = context.getText(categories[mCategoryIndex]); | |||
CharSequence variant = variants[mCategoryIndex][mVariantIndex].getDisplayName(context); | |||
callChangeListener(String.format("%s (%s)", category, variant)); | |||
} | |||
} |