mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-11-25 12:46:13 +00:00
SeekBarPreference: show the formatted current value in the preference dialog.
This commit is contained in:
@@ -2,13 +2,21 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="16dp"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/valueText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_horizontal"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/seekBar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:padding="20dp" />
|
||||
android:layout_weight="1" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -23,10 +23,12 @@ import android.preference.DialogPreference;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class SeekBarPreference extends DialogPreference
|
||||
public class SeekBarPreference extends DialogPreference implements SeekBar.OnSeekBarChangeListener
|
||||
{
|
||||
private SeekBar mSeekBar;
|
||||
private TextView mValueText;
|
||||
|
||||
private int mProgress = 0;
|
||||
private int mMin = 0;
|
||||
@@ -93,11 +95,13 @@ public class SeekBarPreference extends DialogPreference
|
||||
protected View onCreateDialogView() {
|
||||
View root = super.onCreateDialogView();
|
||||
mSeekBar = (SeekBar)root.findViewById(R.id.seekBar);
|
||||
mValueText = (TextView)root.findViewById(R.id.valueText);
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindDialogView(View view) {
|
||||
mSeekBar.setOnSeekBarChangeListener(this);
|
||||
mSeekBar.setMax(mMax - mMin);
|
||||
mSeekBar.setProgress(mProgress + mMin);
|
||||
}
|
||||
@@ -118,4 +122,21 @@ public class SeekBarPreference extends DialogPreference
|
||||
}
|
||||
super.onClick(dialog, which);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
|
||||
{
|
||||
String text = String.format(getFormatter(), Integer.toString(progress + mMin));
|
||||
mValueText.setText(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user