1- package com.github.mikephil.charting.animation ;
1+ package com.github.mikephil.charting.animation
22
3- import android.animation.ObjectAnimator;
4- import android.animation.ValueAnimator.AnimatorUpdateListener;
5- import androidx.annotation.RequiresApi;
6-
7- import com.github.mikephil.charting.animation.Easing.EasingFunction;
3+ import android.animation.ObjectAnimator
4+ import android.animation.ValueAnimator.AnimatorUpdateListener
5+ import com.github.mikephil.charting.animation.Easing.EasingFunction
86
97/* *
108 * Object responsible for all animations in the Chart. Animations require API level 11.
119 *
1210 * @author Philipp Jahoda
1311 * @author Mick Ashton
1412 */
15- public class ChartAnimator {
16-
17- /* * object that is updated upon animation update */
18- private AnimatorUpdateListener mListener;
13+ open class ChartAnimator {
14+ /* * object that is updated upon animation update */
15+ private var mListener: AnimatorUpdateListener ? = null
1916
20- /* * The phase of drawn values on the y-axis. 0 - 1 */
21- @SuppressWarnings(" WeakerAccess" )
22- protected float mPhaseY = 1f ;
17+ /* * The phase of drawn values on the y-axis. 0 - 1 */
18+ protected var mPhaseY: Float = 1f
2319
24- /* * The phase of drawn values on the x-axis. 0 - 1 */
25- @SuppressWarnings(" WeakerAccess" )
26- protected float mPhaseX = 1f ;
20+ /* * The phase of drawn values on the x-axis. 0 - 1 */
21+ protected var mPhaseX: Float = 1f
2722
28- public ChartAnimator () { }
23+ constructor ()
2924
30- @RequiresApi(11 )
31- public ChartAnimator (AnimatorUpdateListener listener) {
32- mListener = listener;
25+ constructor (listener: AnimatorUpdateListener ? ) {
26+ mListener = listener
3327 }
3428
35- @RequiresApi(11 )
36- private ObjectAnimator xAnimator(int duration, EasingFunction easing) {
29+ private fun xAnimator (duration : Int , easing : EasingFunction ? ): ObjectAnimator {
30+ val animatorX = ObjectAnimator .ofFloat(this , " phaseX" , 0f , 1f )
31+ animatorX.interpolator = easing
32+ animatorX.setDuration(duration.toLong())
3733
38- ObjectAnimator animatorX = ObjectAnimator .ofFloat(this , " phaseX" , 0f , 1f );
39- animatorX.setInterpolator(easing);
40- animatorX.setDuration(duration);
41-
42- return animatorX;
34+ return animatorX
4335 }
4436
45- @RequiresApi(11 )
46- private ObjectAnimator yAnimator(int duration, EasingFunction easing) {
47-
48- ObjectAnimator animatorY = ObjectAnimator .ofFloat(this , " phaseY" , 0f , 1f );
49- animatorY.setInterpolator(easing);
50- animatorY.setDuration(duration);
37+ private fun yAnimator (duration : Int , easing : EasingFunction ? ): ObjectAnimator {
38+ val animatorY = ObjectAnimator .ofFloat(this , " phaseY" , 0f , 1f )
39+ animatorY.interpolator = easing
40+ animatorY.setDuration(duration.toLong())
5141
52- return animatorY;
42+ return animatorY
5343 }
5444
5545 /* *
5646 * Animates values along the X axis, in a linear fashion.
5747 *
5848 * @param durationMillis animation duration
5949 */
60- @RequiresApi(11 )
61- public void animateX(int durationMillis) {
62- animateX(durationMillis, Easing .Linear );
50+ fun animateX (durationMillis : Int ) {
51+ animateX(durationMillis, Easing .Linear )
6352 }
6453
6554 /* *
@@ -68,12 +57,10 @@ public class ChartAnimator {
6857 * @param durationMillis animation duration
6958 * @param easing EasingFunction
7059 */
71- @RequiresApi(11 )
72- public void animateX(int durationMillis, EasingFunction easing) {
73-
74- ObjectAnimator animatorX = xAnimator(durationMillis, easing);
75- animatorX.addUpdateListener(mListener);
76- animatorX.start();
60+ fun animateX (durationMillis : Int , easing : EasingFunction ? ) {
61+ val animatorX = xAnimator(durationMillis, easing)
62+ animatorX.addUpdateListener(mListener)
63+ animatorX.start()
7764 }
7865
7966 /* *
@@ -82,9 +69,8 @@ public class ChartAnimator {
8269 * @param durationMillisX animation duration along the X axis
8370 * @param durationMillisY animation duration along the Y axis
8471 */
85- @RequiresApi(11 )
86- public void animateXY(int durationMillisX, int durationMillisY) {
87- animateXY(durationMillisX, durationMillisY, Easing .Linear , Easing .Linear );
72+ fun animateXY (durationMillisX : Int , durationMillisY : Int ) {
73+ animateXY(durationMillisX, durationMillisY, Easing .Linear , Easing .Linear )
8874 }
8975
9076 /* *
@@ -94,20 +80,18 @@ public class ChartAnimator {
9480 * @param durationMillisY animation duration along the Y axis
9581 * @param easing EasingFunction for both axes
9682 */
97- @RequiresApi(11 )
98- public void animateXY(int durationMillisX, int durationMillisY, EasingFunction easing) {
99-
100- ObjectAnimator xAnimator = xAnimator(durationMillisX, easing);
101- ObjectAnimator yAnimator = yAnimator(durationMillisY, easing);
83+ fun animateXY (durationMillisX : Int , durationMillisY : Int , easing : EasingFunction ? ) {
84+ val xAnimator = xAnimator(durationMillisX, easing)
85+ val yAnimator = yAnimator(durationMillisY, easing)
10286
10387 if (durationMillisX > durationMillisY) {
104- xAnimator.addUpdateListener(mListener);
88+ xAnimator.addUpdateListener(mListener)
10589 } else {
106- yAnimator.addUpdateListener(mListener);
90+ yAnimator.addUpdateListener(mListener)
10791 }
10892
109- xAnimator.start();
110- yAnimator.start();
93+ xAnimator.start()
94+ yAnimator.start()
11195 }
11296
11397 /* *
@@ -118,31 +102,30 @@ public class ChartAnimator {
118102 * @param easingX EasingFunction for the X axis
119103 * @param easingY EasingFunction for the Y axis
120104 */
121- @RequiresApi( 11 )
122- public void animateXY(int durationMillisX, int durationMillisY, EasingFunction easingX,
123- EasingFunction easingY) {
124-
125- ObjectAnimator xAnimator = xAnimator(durationMillisX, easingX);
126- ObjectAnimator yAnimator = yAnimator(durationMillisY, easingY);
105+ fun animateXY (
106+ durationMillisX : Int , durationMillisY : Int , easingX : EasingFunction ? ,
107+ easingY : EasingFunction ?
108+ ) {
109+ val xAnimator = xAnimator(durationMillisX, easingX)
110+ val yAnimator = yAnimator(durationMillisY, easingY)
127111
128112 if (durationMillisX > durationMillisY) {
129- xAnimator.addUpdateListener(mListener);
113+ xAnimator.addUpdateListener(mListener)
130114 } else {
131- yAnimator.addUpdateListener(mListener);
115+ yAnimator.addUpdateListener(mListener)
132116 }
133117
134- xAnimator.start();
135- yAnimator.start();
118+ xAnimator.start()
119+ yAnimator.start()
136120 }
137121
138122 /* *
139123 * Animates values along the Y axis, in a linear fashion.
140124 *
141125 * @param durationMillis animation duration
142126 */
143- @RequiresApi(11 )
144- public void animateY(int durationMillis) {
145- animateY(durationMillis, Easing .Linear );
127+ fun animateY (durationMillis : Int ) {
128+ animateY(durationMillis, Easing .Linear )
146129 }
147130
148131 /* *
@@ -151,57 +134,53 @@ public class ChartAnimator {
151134 * @param durationMillis animation duration
152135 * @param easing EasingFunction
153136 */
154- @RequiresApi(11 )
155- public void animateY(int durationMillis, EasingFunction easing) {
156-
157- ObjectAnimator animatorY = yAnimator(durationMillis, easing);
158- animatorY.addUpdateListener(mListener);
159- animatorY.start();
160- }
161-
162- /* *
163- * Gets the Y axis phase of the animation.
164- *
165- * @return float value of {@link #mPhaseY}
166- */
167- public float getPhaseY() {
168- return mPhaseY;
137+ fun animateY (durationMillis : Int , easing : EasingFunction ? ) {
138+ val animatorY = yAnimator(durationMillis, easing)
139+ animatorY.addUpdateListener(mListener)
140+ animatorY.start()
169141 }
170142
171- /* *
172- * Sets the Y axis phase of the animation.
173- *
174- * @param phase float value between 0 - 1
175- */
176- public void setPhaseY(float phase) {
177- if (phase > 1f ) {
178- phase = 1f ;
179- } else if (phase < 0f ) {
180- phase = 0f ;
143+ var phaseY: Float
144+ /* *
145+ * Gets the Y axis phase of the animation.
146+ *
147+ * @return float value of [.mPhaseY]
148+ */
149+ get() = mPhaseY
150+ /* *
151+ * Sets the Y axis phase of the animation.
152+ *
153+ * @param phase float value between 0 - 1
154+ */
155+ set(phase) {
156+ var phase = phase
157+ if (phase > 1f ) {
158+ phase = 1f
159+ } else if (phase < 0f ) {
160+ phase = 0f
161+ }
162+ mPhaseY = phase
181163 }
182- mPhaseY = phase;
183- }
184164
185- /* *
186- * Gets the X axis phase of the animation.
187- *
188- * @return float value of {@link #mPhaseX}
189- */
190- public float getPhaseX() {
191- return mPhaseX;
192- }
193-
194- /* *
195- * Sets the X axis phase of the animation.
196- *
197- * @param phase float value between 0 - 1
198- */
199- public void setPhaseX(float phase) {
200- if (phase > 1f ) {
201- phase = 1f ;
202- } else if (phase < 0f ) {
203- phase = 0f ;
165+ var phaseX: Float
166+ /* *
167+ * Gets the X axis phase of the animation.
168+ *
169+ * @return float value of [.mPhaseX]
170+ */
171+ get() = mPhaseX
172+ /* *
173+ * Sets the X axis phase of the animation.
174+ *
175+ * @param phase float value between 0 - 1
176+ */
177+ set(phase) {
178+ var phase = phase
179+ if (phase > 1f ) {
180+ phase = 1f
181+ } else if (phase < 0f ) {
182+ phase = 0f
183+ }
184+ mPhaseX = phase
204185 }
205- mPhaseX = phase;
206- }
207186}
0 commit comments