aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/settings/WpThresholdPreference.java
blob: 37edafa075964616b420b2e5c3b885c48dfb1248 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package cgeo.geocaching.settings;

import butterknife.ButterKnife;

import cgeo.geocaching.R;

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 {

    private TextView valueView;

    public WpThresholdPreference(final Context context) {
        super(context);
        init();
    }

    public WpThresholdPreference(final Context context, final AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public WpThresholdPreference(final Context context, final AttributeSet attrs, final int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init() {
        setPersistent(false);
    }

    @Override
    protected View onCreateView(final ViewGroup parent) {
        final View v = super.onCreateView(parent);

        // get views
        final SeekBar seekBar = ButterKnife.findById(v, R.id.wp_threshold_seekbar);
        valueView = ButterKnife.findById(v, R.id.wp_threshold_value_view);

        // init seekbar
        seekBar.setMax(Settings.SHOW_WP_THRESHOLD_MAX);

        // set initial value
        final int threshold = Settings.getWayPointsThreshold();
        valueView.setText(String.valueOf(threshold));
        seekBar.setProgress(threshold);

        seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
                if (fromUser) {
                    valueView.setText(String.valueOf(progress));
                }
            }
            @Override
            public void onStartTrackingTouch(final SeekBar seekBar) {
            }
            @Override
            public void onStopTrackingTouch(final SeekBar seekBar) {
                Settings.setShowWaypointsThreshold(seekBar.getProgress());
            }
        });

        return v;
    }

}