1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.systemui.haptics.slider
18 
19 import androidx.annotation.FloatRange
20 
21 /** Listener of events from a slider (such as [android.widget.SeekBar]) */
22 interface SliderStateListener {
23 
24     /** Notification that the handle is acquired by touch */
onHandleAcquiredByTouchnull25     fun onHandleAcquiredByTouch()
26 
27     /** Notification that the handle was released from touch */
28     fun onHandleReleasedFromTouch()
29 
30     /** Notification that the handle reached the lower bookend */
31     fun onLowerBookend()
32 
33     /** Notification that the handle reached the upper bookend */
34     fun onUpperBookend()
35 
36     /**
37      * Notification that the slider reached a certain progress on the slider track.
38      *
39      * This method is called in all intermediate steps of a continuous progress change as the slider
40      * moves through the slider track. A single discrete movement of the handle by an external
41      * button or by a jump on the slider track will not trigger this callback. See
42      * [onSelectAndArrow] and [onProgressJump] for these cases.
43      *
44      * @param[progress] The progress of the slider in the range from 0F to 1F (inclusive).
45      */
46     fun onProgress(@FloatRange(from = 0.0, to = 1.0) progress: Float)
47 
48     /**
49      * Notification that the slider handle jumped to a selected progress on the slider track.
50      *
51      * This method is specific to the case when the handle performed a single jump to a position on
52      * the slider track and reached the corresponding progress. In this case, [onProgress] is not
53      * called and the new progress reached is represented by the [progress] parameter.
54      *
55      * @param[progress] The selected progress on the slider track that the handle jumps to. The
56      *   progress is in the range from 0F to 1F (inclusive).
57      */
58     fun onProgressJump(@FloatRange(from = 0.0, to = 1.0) progress: Float)
59 
60     /**
61      * Notification that the slider handle was moved discretely by one step via a button press.
62      *
63      * @param[progress] The progress of the slider in the range from 0F to 1F (inclusive).
64      */
65     fun onSelectAndArrow(@FloatRange(from = 0.0, to = 1.0) progress: Float)
66 }
67