1716ba89e7f459f49ea85070d4710c1d79d715298George Mount/*
2716ba89e7f459f49ea85070d4710c1d79d715298George Mount * Copyright (C) 2015 The Android Open Source Project
3716ba89e7f459f49ea85070d4710c1d79d715298George Mount *
4716ba89e7f459f49ea85070d4710c1d79d715298George Mount * Licensed under the Apache License, Version 2.0 (the "License");
5716ba89e7f459f49ea85070d4710c1d79d715298George Mount * you may not use this file except in compliance with the License.
6716ba89e7f459f49ea85070d4710c1d79d715298George Mount * You may obtain a copy of the License at
7716ba89e7f459f49ea85070d4710c1d79d715298George Mount *
8716ba89e7f459f49ea85070d4710c1d79d715298George Mount *      http://www.apache.org/licenses/LICENSE-2.0
9716ba89e7f459f49ea85070d4710c1d79d715298George Mount *
10716ba89e7f459f49ea85070d4710c1d79d715298George Mount * Unless required by applicable law or agreed to in writing, software
11716ba89e7f459f49ea85070d4710c1d79d715298George Mount * distributed under the License is distributed on an "AS IS" BASIS,
12716ba89e7f459f49ea85070d4710c1d79d715298George Mount * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13716ba89e7f459f49ea85070d4710c1d79d715298George Mount * See the License for the specific language governing permissions and
14716ba89e7f459f49ea85070d4710c1d79d715298George Mount * limitations under the License.
15716ba89e7f459f49ea85070d4710c1d79d715298George Mount */
16716ba89e7f459f49ea85070d4710c1d79d715298George Mountpackage android.databinding.adapters;
17716ba89e7f459f49ea85070d4710c1d79d715298George Mount
18716ba89e7f459f49ea85070d4710c1d79d715298George Mountimport android.databinding.BindingAdapter;
19716ba89e7f459f49ea85070d4710c1d79d715298George Mountimport android.widget.SeekBar;
20716ba89e7f459f49ea85070d4710c1d79d715298George Mountimport android.widget.SeekBar.OnSeekBarChangeListener;
21716ba89e7f459f49ea85070d4710c1d79d715298George Mount
22716ba89e7f459f49ea85070d4710c1d79d715298George Mountpublic class SeekBarBindingAdapter {
23716ba89e7f459f49ea85070d4710c1d79d715298George Mount    @BindingAdapter("android:onProgressChanged")
24716ba89e7f459f49ea85070d4710c1d79d715298George Mount    public static void setListener(SeekBar view, OnProgressChanged listener) {
25716ba89e7f459f49ea85070d4710c1d79d715298George Mount        setListener(view, null, null, listener);
26716ba89e7f459f49ea85070d4710c1d79d715298George Mount    }
27716ba89e7f459f49ea85070d4710c1d79d715298George Mount
28716ba89e7f459f49ea85070d4710c1d79d715298George Mount    @BindingAdapter("android:onStartTrackingTouch")
29716ba89e7f459f49ea85070d4710c1d79d715298George Mount    public static void setListener(SeekBar view, OnStartTrackingTouch listener) {
30716ba89e7f459f49ea85070d4710c1d79d715298George Mount        setListener(view, listener, null, null);
31716ba89e7f459f49ea85070d4710c1d79d715298George Mount    }
32716ba89e7f459f49ea85070d4710c1d79d715298George Mount
33716ba89e7f459f49ea85070d4710c1d79d715298George Mount    @BindingAdapter("android:onStopTrackingTouch")
34716ba89e7f459f49ea85070d4710c1d79d715298George Mount    public static void setListener(SeekBar view, OnStopTrackingTouch listener) {
35716ba89e7f459f49ea85070d4710c1d79d715298George Mount        setListener(view, null, listener, null);
36716ba89e7f459f49ea85070d4710c1d79d715298George Mount    }
37716ba89e7f459f49ea85070d4710c1d79d715298George Mount
38716ba89e7f459f49ea85070d4710c1d79d715298George Mount    @BindingAdapter({"android:onStartTrackingTouch", "android:onStopTrackingTouch"})
39716ba89e7f459f49ea85070d4710c1d79d715298George Mount    public static void setListener(SeekBar view, final OnStartTrackingTouch start,
40716ba89e7f459f49ea85070d4710c1d79d715298George Mount            final OnStopTrackingTouch stop) {
41716ba89e7f459f49ea85070d4710c1d79d715298George Mount        setListener(view, start, stop, null);
42716ba89e7f459f49ea85070d4710c1d79d715298George Mount    }
43716ba89e7f459f49ea85070d4710c1d79d715298George Mount
44716ba89e7f459f49ea85070d4710c1d79d715298George Mount    @BindingAdapter({"android:onStartTrackingTouch", "android:onProgressChanged"})
45716ba89e7f459f49ea85070d4710c1d79d715298George Mount    public static void setListener(SeekBar view, final OnStartTrackingTouch start,
46716ba89e7f459f49ea85070d4710c1d79d715298George Mount            final OnProgressChanged progressChanged) {
47716ba89e7f459f49ea85070d4710c1d79d715298George Mount        setListener(view, start, null, progressChanged);
48716ba89e7f459f49ea85070d4710c1d79d715298George Mount    }
49716ba89e7f459f49ea85070d4710c1d79d715298George Mount
50716ba89e7f459f49ea85070d4710c1d79d715298George Mount    @BindingAdapter({"android:onStopTrackingTouch", "android:onProgressChanged"})
51716ba89e7f459f49ea85070d4710c1d79d715298George Mount    public static void setListener(SeekBar view, final OnStopTrackingTouch stop,
52716ba89e7f459f49ea85070d4710c1d79d715298George Mount            final OnProgressChanged progressChanged) {
53716ba89e7f459f49ea85070d4710c1d79d715298George Mount        setListener(view, null, stop, progressChanged);
54716ba89e7f459f49ea85070d4710c1d79d715298George Mount    }
55716ba89e7f459f49ea85070d4710c1d79d715298George Mount
56716ba89e7f459f49ea85070d4710c1d79d715298George Mount    @BindingAdapter({"android:onStartTrackingTouch", "android:onStopTrackingTouch", "android:onProgressChanged"})
57716ba89e7f459f49ea85070d4710c1d79d715298George Mount    public static void setListener(SeekBar view, final OnStartTrackingTouch start,
58716ba89e7f459f49ea85070d4710c1d79d715298George Mount            final OnStopTrackingTouch stop, final OnProgressChanged progressChanged) {
59716ba89e7f459f49ea85070d4710c1d79d715298George Mount        if (start == null && stop == null && progressChanged == null) {
60716ba89e7f459f49ea85070d4710c1d79d715298George Mount            view.setOnSeekBarChangeListener(null);
61716ba89e7f459f49ea85070d4710c1d79d715298George Mount        } else {
62716ba89e7f459f49ea85070d4710c1d79d715298George Mount            view.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
63716ba89e7f459f49ea85070d4710c1d79d715298George Mount                @Override
64716ba89e7f459f49ea85070d4710c1d79d715298George Mount                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
65716ba89e7f459f49ea85070d4710c1d79d715298George Mount                    if (progressChanged != null) {
66716ba89e7f459f49ea85070d4710c1d79d715298George Mount                        progressChanged.onProgressChanged(seekBar, progress, fromUser);
67716ba89e7f459f49ea85070d4710c1d79d715298George Mount                    }
68716ba89e7f459f49ea85070d4710c1d79d715298George Mount                }
69716ba89e7f459f49ea85070d4710c1d79d715298George Mount
70716ba89e7f459f49ea85070d4710c1d79d715298George Mount                @Override
71716ba89e7f459f49ea85070d4710c1d79d715298George Mount                public void onStartTrackingTouch(SeekBar seekBar) {
72716ba89e7f459f49ea85070d4710c1d79d715298George Mount                    if (start != null) {
73716ba89e7f459f49ea85070d4710c1d79d715298George Mount                        start.onStartTrackingTouch(seekBar);
74716ba89e7f459f49ea85070d4710c1d79d715298George Mount                    }
75716ba89e7f459f49ea85070d4710c1d79d715298George Mount                }
76716ba89e7f459f49ea85070d4710c1d79d715298George Mount
77716ba89e7f459f49ea85070d4710c1d79d715298George Mount                @Override
78716ba89e7f459f49ea85070d4710c1d79d715298George Mount                public void onStopTrackingTouch(SeekBar seekBar) {
79716ba89e7f459f49ea85070d4710c1d79d715298George Mount                    if (stop != null) {
80716ba89e7f459f49ea85070d4710c1d79d715298George Mount                        stop.onStopTrackingTouch(seekBar);
81716ba89e7f459f49ea85070d4710c1d79d715298George Mount                    }
82716ba89e7f459f49ea85070d4710c1d79d715298George Mount                }
83716ba89e7f459f49ea85070d4710c1d79d715298George Mount            });
84716ba89e7f459f49ea85070d4710c1d79d715298George Mount        }
85716ba89e7f459f49ea85070d4710c1d79d715298George Mount    }
86716ba89e7f459f49ea85070d4710c1d79d715298George Mount
87716ba89e7f459f49ea85070d4710c1d79d715298George Mount    public interface OnStartTrackingTouch {
88716ba89e7f459f49ea85070d4710c1d79d715298George Mount        void onStartTrackingTouch(SeekBar seekBar);
89716ba89e7f459f49ea85070d4710c1d79d715298George Mount    }
90716ba89e7f459f49ea85070d4710c1d79d715298George Mount
91716ba89e7f459f49ea85070d4710c1d79d715298George Mount    public interface OnStopTrackingTouch {
92716ba89e7f459f49ea85070d4710c1d79d715298George Mount        void onStopTrackingTouch(SeekBar seekBar);
93716ba89e7f459f49ea85070d4710c1d79d715298George Mount    }
94716ba89e7f459f49ea85070d4710c1d79d715298George Mount
95716ba89e7f459f49ea85070d4710c1d79d715298George Mount    public interface OnProgressChanged {
96716ba89e7f459f49ea85070d4710c1d79d715298George Mount        void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser);
97716ba89e7f459f49ea85070d4710c1d79d715298George Mount    }
98716ba89e7f459f49ea85070d4710c1d79d715298George Mount}
99