1 /*
2  * Copyright (C) 2017 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 android.support.animation;
18 
19 /**
20  * <p>FloatValueHolder holds a float value. FloatValueHolder provides a setter and a getter (
21  * i.e. {@link #setValue(float)} and {@link #getValue()}) to access this float value. Animations can
22  * be performed on a FloatValueHolder instance. During each frame of the animation, the
23  * FloatValueHolder will have its value updated via {@link #setValue(float)}. The caller can
24  * obtain the up-to-date animation value via {@link FloatValueHolder#getValue()}.
25  *
26  * <p> Here is an example for creating a {@link FlingAnimation} with a FloatValueHolder:
27  * <pre class="prettyprint">
28  * // Create a fling animation with an initial velocity of 5000 (pixel/s) and an initial position
29  * // of 20f.
30  * FloatValueHolder floatValueHolder = new FloatValueHolder(20f);
31  * FlingAnimation anim = new FlingAnimation(floatValueHolder).setStartVelocity(5000);
32  * anim.start();
33  * </pre>
34  *
35  * @see SpringAnimation#SpringAnimation(FloatValueHolder)
36  * @see FlingAnimation#FlingAnimation(FloatValueHolder)
37  */
38 
39 public final class FloatValueHolder {
40     private float mValue = 0.0f;
41 
42     /**
43      * Constructs a holder for a float value that is initialized to 0.
44      */
FloatValueHolder()45     public FloatValueHolder() {
46     }
47 
48     /**
49      * Constructs a holder for a float value that is initialized to the input value.
50      *
51      * @param value the value to initialize the value held in the FloatValueHolder
52      */
FloatValueHolder(float value)53     public FloatValueHolder(float value) {
54         setValue(value);
55     }
56 
57     /**
58      * Sets the value held in the FloatValueHolder instance.
59      *
60      * @param value float value held in the FloatValueHolder instance
61      */
setValue(float value)62     public void setValue(float value) {
63         mValue = value;
64     }
65 
66     /**
67      * Returns the float value held in the FloatValueHolder instance.
68      *
69      * @return float value held in the FloatValueHolder instance
70      */
getValue()71     public float getValue() {
72         return mValue;
73     }
74 }
75