@@ -19,4 +19,19 @@ | |||
android:layout_height="0dp" | |||
android:layout_weight="1" /> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" > | |||
<Button | |||
android:id="@+id/resetToDefault" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_gravity="bottom" | |||
android:layout_weight="1" | |||
android:text="@string/resetToDefault" /> | |||
</LinearLayout> | |||
</LinearLayout> |
@@ -135,5 +135,6 @@ | |||
<string name="espeak_volume">Volume</string> | |||
<string name="formatter_wpm">%s WPM</string> | |||
<string name="formatter_percentage">%s%%</string> | |||
<string name="resetToDefault">Set to default</string> | |||
</resources> |
@@ -22,6 +22,7 @@ import android.content.SharedPreferences; | |||
import android.preference.DialogPreference; | |||
import android.util.AttributeSet; | |||
import android.view.View; | |||
import android.widget.Button; | |||
import android.widget.SeekBar; | |||
import android.widget.TextView; | |||
@@ -31,6 +32,7 @@ public class SeekBarPreference extends DialogPreference implements SeekBar.OnSee | |||
private TextView mValueText; | |||
private int mProgress = 0; | |||
private int mDefaultValue = 0; | |||
private int mMin = 0; | |||
private int mMax = 100; | |||
private String mFormatter = "%s"; | |||
@@ -53,6 +55,14 @@ public class SeekBarPreference extends DialogPreference implements SeekBar.OnSee | |||
callChangeListener(text); | |||
} | |||
public void setDefaultValue(int defaultValue) { | |||
mDefaultValue = defaultValue; | |||
} | |||
public int getDefaultValue() { | |||
return mDefaultValue; | |||
} | |||
public int getMin() { | |||
return mMin; | |||
} | |||
@@ -96,6 +106,15 @@ public class SeekBarPreference extends DialogPreference implements SeekBar.OnSee | |||
View root = super.onCreateDialogView(); | |||
mSeekBar = (SeekBar)root.findViewById(R.id.seekBar); | |||
mValueText = (TextView)root.findViewById(R.id.valueText); | |||
Button reset = (Button)root.findViewById(R.id.resetToDefault); | |||
reset.setOnClickListener(new View.OnClickListener(){ | |||
@Override | |||
public void onClick(View v) | |||
{ | |||
mSeekBar.setProgress(getDefaultValue()); | |||
} | |||
}); | |||
return root; | |||
} | |||
@@ -60,6 +60,7 @@ public class TtsSettingsActivity extends PreferenceActivity { | |||
private static Preference createPreference(Context context, SpeechSynthesis.Parameter parameter, String key, int titleRes) { | |||
final String title = context.getString(titleRes); | |||
final int defaultValue = parameter.getDefaultValue(); | |||
final SeekBarPreference pref = new SeekBarPreference(context); | |||
pref.setTitle(title); | |||
@@ -82,11 +83,12 @@ public class TtsSettingsActivity extends PreferenceActivity { | |||
pref.setMin(parameter.getMinValue()); | |||
pref.setMax(parameter.getMaxValue()); | |||
pref.setDefaultValue(defaultValue); | |||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); | |||
final String prefString = prefs.getString(key, null); | |||
if (prefString == null) { | |||
pref.setProgress(parameter.getDefaultValue()); | |||
pref.setProgress(defaultValue); | |||
} else { | |||
pref.setProgress(Integer.parseInt(prefString)); | |||
} |