Browse Source

SeekBarPreference: show the formatted current value in the preference dialog.

master
Reece H. Dunn 12 years ago
parent
commit
20010daac3

+ 10
- 2
android/res/layout/seekbar_preference.xml View File

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:padding="16dp"
android:orientation="vertical" > 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 <SeekBar
android:id="@+id/seekBar" android:id="@+id/seekBar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1"
android:padding="20dp" />
android:layout_weight="1" />


</LinearLayout> </LinearLayout>

+ 22
- 1
android/src/com/reecedunn/espeak/SeekBarPreference.java View File

import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.widget.SeekBar; 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 SeekBar mSeekBar;
private TextView mValueText;


private int mProgress = 0; private int mProgress = 0;
private int mMin = 0; private int mMin = 0;
protected View onCreateDialogView() { protected View onCreateDialogView() {
View root = super.onCreateDialogView(); View root = super.onCreateDialogView();
mSeekBar = (SeekBar)root.findViewById(R.id.seekBar); mSeekBar = (SeekBar)root.findViewById(R.id.seekBar);
mValueText = (TextView)root.findViewById(R.id.valueText);
return root; return root;
} }


@Override @Override
protected void onBindDialogView(View view) { protected void onBindDialogView(View view) {
mSeekBar.setOnSeekBarChangeListener(this);
mSeekBar.setMax(mMax - mMin); mSeekBar.setMax(mMax - mMin);
mSeekBar.setProgress(mProgress + mMin); mSeekBar.setProgress(mProgress + mMin);
} }
} }
super.onClick(dialog, which); 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)
{
}
} }

Loading…
Cancel
Save