|
|
|
|
|
|
|
|
private SeekBar mSeekBar; |
|
|
private SeekBar mSeekBar; |
|
|
private TextView mValueText; |
|
|
private TextView mValueText; |
|
|
|
|
|
|
|
|
|
|
|
private int mOldProgress = 0; |
|
|
private int mProgress = 0; |
|
|
private int mProgress = 0; |
|
|
private int mDefaultValue = 0; |
|
|
private int mDefaultValue = 0; |
|
|
private int mMin = 0; |
|
|
private int mMin = 0; |
|
|
|
|
|
|
|
|
mProgress = progress; |
|
|
mProgress = progress; |
|
|
String text = Integer.toString(mProgress); |
|
|
String text = Integer.toString(mProgress); |
|
|
callChangeListener(text); |
|
|
callChangeListener(text); |
|
|
|
|
|
|
|
|
|
|
|
// Update the last saved value to the so it can be restored later if |
|
|
|
|
|
// the user cancels the dialog. This needs to be done here as well |
|
|
|
|
|
// as the onProgressChanged handler as the SeekBar will not be |
|
|
|
|
|
// initialized at this point. |
|
|
|
|
|
|
|
|
|
|
|
mOldProgress = mProgress; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public int getProgress() { |
|
|
public int getProgress() { |
|
|
|
|
|
|
|
|
this(context, null); |
|
|
this(context, null); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void persistSettings(int progress) { |
|
|
|
|
|
mProgress = progress; |
|
|
|
|
|
String text = Integer.toString(mProgress); |
|
|
|
|
|
callChangeListener(text); |
|
|
|
|
|
if (shouldCommit()) { |
|
|
|
|
|
SharedPreferences.Editor editor = getEditor(); |
|
|
|
|
|
editor.putString(getKey(), text); |
|
|
|
|
|
editor.commit(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
protected View onCreateDialogView() { |
|
|
protected View onCreateDialogView() { |
|
|
View root = super.onCreateDialogView(); |
|
|
View root = super.onCreateDialogView(); |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void onClick(View v) |
|
|
public void onClick(View v) |
|
|
{ |
|
|
{ |
|
|
mSeekBar.setProgress(getDefaultValue() - mMin); |
|
|
|
|
|
|
|
|
int defaultValue = getDefaultValue(); |
|
|
|
|
|
mSeekBar.setProgress(defaultValue - mMin); |
|
|
|
|
|
|
|
|
|
|
|
// Persist the value here to ensure that eSpeak is using the |
|
|
|
|
|
// new value the next time e.g. TalkBack reads part of the UI. |
|
|
|
|
|
|
|
|
|
|
|
persistSettings(defaultValue); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
return root; |
|
|
return root; |
|
|
|
|
|
|
|
|
mSeekBar.setOnSeekBarChangeListener(this); |
|
|
mSeekBar.setOnSeekBarChangeListener(this); |
|
|
mSeekBar.setMax(mMax - mMin); |
|
|
mSeekBar.setMax(mMax - mMin); |
|
|
mSeekBar.setProgress(mProgress - mMin); |
|
|
mSeekBar.setProgress(mProgress - mMin); |
|
|
|
|
|
|
|
|
|
|
|
// Update the last saved value to the so it can be restored later if |
|
|
|
|
|
// the user cancels the dialog. |
|
|
|
|
|
|
|
|
|
|
|
mOldProgress = mProgress; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
switch (which) { |
|
|
switch (which) { |
|
|
case DialogInterface.BUTTON_POSITIVE: |
|
|
case DialogInterface.BUTTON_POSITIVE: |
|
|
mProgress = mSeekBar.getProgress() + mMin; |
|
|
|
|
|
String text = Integer.toString(mProgress); |
|
|
|
|
|
callChangeListener(text); |
|
|
|
|
|
if (shouldCommit()) { |
|
|
|
|
|
SharedPreferences.Editor editor = getEditor(); |
|
|
|
|
|
editor.putString(getKey(), text); |
|
|
|
|
|
editor.commit(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Update the last saved value so this will be persisted when |
|
|
|
|
|
// the dialog is dismissed. |
|
|
|
|
|
|
|
|
|
|
|
mOldProgress = mSeekBar.getProgress() + mMin; |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
super.onClick(dialog, which); |
|
|
super.onClick(dialog, which); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onDismiss(DialogInterface dialog) { |
|
|
|
|
|
// There are 3 ways to dismiss a dialog: |
|
|
|
|
|
// 1. Pressing the OK (positive) button. |
|
|
|
|
|
// 2. Pressing the Cancel (negative) button. |
|
|
|
|
|
// 3. Pressing the Back button. |
|
|
|
|
|
// |
|
|
|
|
|
// For [1], the new value needs to be persisted. For [2] and [3], the |
|
|
|
|
|
// old value needs to be persisted (so the last saved value is |
|
|
|
|
|
// restored). As there is no easy way to override the Dialog's back |
|
|
|
|
|
// button pressed handler, the following approach is used: |
|
|
|
|
|
// |
|
|
|
|
|
// 1. If the user presses the OK button, the last saved value is |
|
|
|
|
|
// updated to be the new value (see the onClick handler). |
|
|
|
|
|
// |
|
|
|
|
|
// 2. In all cases, the last saved value is persisted when the dialog |
|
|
|
|
|
// is closed (in this onDismiss handler). |
|
|
|
|
|
|
|
|
|
|
|
persistSettings(mOldProgress); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) |
|
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) |
|
|
{ |
|
|
{ |
|
|
|
|
|
// This callback gets called frequently when the user is moving the |
|
|
|
|
|
// slider, so constantly persisting the seeker value will be annoying. |
|
|
|
|
|
// |
|
|
|
|
|
// If the value is being set programatically, persisting the seeker |
|
|
|
|
|
// value here will cause the speech rate to be set to 80 WPM (via the |
|
|
|
|
|
// onBindDialogView handler). |
|
|
|
|
|
|
|
|
String text = String.format(getFormatter(), Integer.toString(progress + mMin)); |
|
|
String text = String.format(getFormatter(), Integer.toString(progress + mMin)); |
|
|
mValueText.setText(text); |
|
|
mValueText.setText(text); |
|
|
mSeekBar.setContentDescription(text); |
|
|
mSeekBar.setContentDescription(text); |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void onStopTrackingTouch(SeekBar seekBar) |
|
|
public void onStopTrackingTouch(SeekBar seekBar) |
|
|
{ |
|
|
{ |
|
|
|
|
|
// After the user has let go of the slider, the new value is |
|
|
|
|
|
// persisted to ensure that eSpeak is using the new value the |
|
|
|
|
|
// next time e.g. TalkBack reads part of the UI. |
|
|
|
|
|
|
|
|
|
|
|
persistSettings(mSeekBar.getProgress() + mMin); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |