From ece37925442507a71f12a2a2f531ea213c48cad5 Mon Sep 17 00:00:00 2001 From: koem Date: Fri, 21 Jun 2013 18:57:50 -0600 Subject: Implements #750, use preference activity --- .../geocaching/settings/WpThresholdPreference.java | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 main/src/cgeo/geocaching/settings/WpThresholdPreference.java (limited to 'main/src/cgeo/geocaching/settings/WpThresholdPreference.java') diff --git a/main/src/cgeo/geocaching/settings/WpThresholdPreference.java b/main/src/cgeo/geocaching/settings/WpThresholdPreference.java new file mode 100644 index 0000000..867714f --- /dev/null +++ b/main/src/cgeo/geocaching/settings/WpThresholdPreference.java @@ -0,0 +1,73 @@ +package cgeo.geocaching.settings; + +import cgeo.geocaching.R; +import cgeo.geocaching.settings.Settings; + +import android.content.Context; +import android.preference.Preference; +import android.util.AttributeSet; +import android.view.View; +import android.view.ViewGroup; +import android.widget.SeekBar; +import android.widget.SeekBar.OnSeekBarChangeListener; +import android.widget.TextView; + +public class WpThresholdPreference extends Preference { + + TextView valueView; + + public WpThresholdPreference(Context context) { + super(context); + init(); + } + + public WpThresholdPreference(Context context, AttributeSet attrs) { + super(context, attrs); + init(); + } + + public WpThresholdPreference(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + init(); + } + + private void init() { + setPersistent(false); + } + + @Override + protected View onCreateView(ViewGroup parent) { + View v = super.onCreateView(parent); + + // get views + SeekBar seekBar = (SeekBar) v.findViewById(R.id.wp_threshold_seekbar); + valueView = (TextView) v.findViewById(R.id.wp_threshold_value_view); + + // init seekbar + seekBar.setMax(Settings.SHOW_WP_THRESHOLD_MAX); + + // set initial value + int threshold = Settings.getWayPointsThreshold(); + valueView.setText(String.valueOf(threshold)); + seekBar.setProgress(threshold); + + seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + if (fromUser) { + valueView.setText(String.valueOf(progress)); + } + } + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + } + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + Settings.setShowWaypointsThreshold(seekBar.getProgress()); + } + }); + + return v; + } + +} -- cgit v1.1