@@ -5,22 +5,22 @@ declare const at;
55
66export class AnimatedCircle extends AnimatedCircleCommon {
77 private _android : any ;
8- private _progress : number ;
9- private _animateFrom : number ;
8+ private _progress = 0 ;
9+ private _animateFrom = 0 ;
1010 private _animationDuration = 1000 ;
1111 private _animated : boolean ;
1212 private _maxValue = 100 ;
1313 private _barColor = new Color ( '#3D8FF4' ) ;
14- private _barWidth : number ;
14+ private _barWidth ;
1515 private _rimColor = new Color ( '#FF5722' ) ;
16- private _rimWidth = 5 ;
16+ private _rimWidth ;
1717 private _spinBarColor = new Color ( 'green' ) ;
18- private _startAngle : number ;
18+ private _startAngle : number = 0 ;
1919 private _text = '' ;
2020 private _textColor = new Color ( 'orange' ) ;
2121 private _textSize = 8 ;
22- private _fillColor : Color ;
23- clockwise = true ;
22+ private _fillColor = new Color ( 'transparent' ) ;
23+ private _clockwise = true ;
2424
2525 constructor ( ) {
2626 super ( ) ;
@@ -31,15 +31,22 @@ export class AnimatedCircle extends AnimatedCircleCommon {
3131 }
3232
3333 initNativeView ( ) {
34- this . android . setAutoTextSize ( false ) ;
34+ this . android . setAutoTextSize ( true ) ;
3535 this . android . setBarStrokeCap ( android . graphics . Paint . Cap . ROUND ) ;
3636 this . android . setTextMode ( at . grabner . circleprogress . TextMode . TEXT ) ;
3737 this . android . setShowTextWhileSpinning ( true ) ;
38- this . android . setTextScale ( 1.1 ) ;
39- this . android . setTextSize ( 300 ) ;
4038 this . android . setUnitVisible ( false ) ;
4139 this . android . setOuterContourSize ( 0 ) ;
4240 this . android . setInnerContourSize ( 0 ) ;
41+ this . android . setText ( this . text ) ;
42+ this . android . setValueAnimated ( this . progress ) ;
43+ this . android . setDirection ( this . clockwise ? at . grabner . circleprogress . Direction . CW : at . grabner . circleprogress . Direction . CCW ) ;
44+ this . android . setRimWidth ( this . rimWidth ) ;
45+ this . android . setBarWidth ( this . barWidth ) ;
46+ if ( this . rimWidth ) {
47+ // set rim width to bar width if no bar width provided
48+ this . android . setBarWidth ( this . rimWidth ) ;
49+ }
4350 this . updateAnimatedCircle ( ) ;
4451 }
4552
@@ -61,8 +68,8 @@ export class AnimatedCircle extends AnimatedCircleCommon {
6168 }
6269
6370 set progress ( value : number ) {
64- this . _progress = Number ( value ) ;
65- this . updateAnimatedCircle ( ) ;
71+ this . _progress = value ;
72+ this . android ?. setValueAnimated ( this . _progress ) ;
6673 }
6774
6875 get progress ( ) : number {
@@ -97,8 +104,8 @@ export class AnimatedCircle extends AnimatedCircleCommon {
97104 }
98105
99106 set maxValue ( value : number ) {
100- this . _maxValue = Number ( value ) ;
101- this . updateAnimatedCircle ( ) ;
107+ this . _maxValue = value ;
108+ this . android ?. setMaxValue ( this . maxValue ) ;
102109 }
103110
104111 get maxValue ( ) : number {
@@ -108,9 +115,9 @@ export class AnimatedCircle extends AnimatedCircleCommon {
108115 set rimColor ( value : any ) {
109116 this . _rimColor = value ;
110117 if ( value instanceof Color ) {
111- this . android . setRimColor ( value . argb ) ;
118+ this . android ? .setRimColor ( value . argb ) ;
112119 } else {
113- this . android . setRimColor ( new Color ( value ) . argb ) ;
120+ this . android ? .setRimColor ( new Color ( value ) . argb ) ;
114121 }
115122 }
116123
@@ -124,15 +131,15 @@ export class AnimatedCircle extends AnimatedCircleCommon {
124131 set barColor ( value : Color ) {
125132 this . _barColor = value ;
126133 if ( value instanceof Color ) {
127- this . android . setBarColor ( [ value . argb ] ) ;
134+ this . android ? .setBarColor ( [ value . argb ] ) ;
128135 } else {
129- this . android . setBarColor ( [ new Color ( value ) . argb ] ) ;
136+ this . android ? .setBarColor ( [ new Color ( value ) . argb ] ) ;
130137 }
131138 }
132139
133140 set rimWidth ( value : number ) {
134141 this . _rimWidth = Number ( value ) ;
135- this . updateAnimatedCircle ( ) ;
142+ this . android ?. setRimWidth ( this . _rimWidth ) ;
136143 }
137144
138145 get rimWidth ( ) {
@@ -166,17 +173,24 @@ export class AnimatedCircle extends AnimatedCircleCommon {
166173 }
167174
168175 set startAngle ( value : number ) {
169- this . _startAngle = Number ( value ) ;
170- this . updateAnimatedCircle ( ) ;
176+ this . _startAngle = value ;
177+ this . android ?. setStartAngle ( this . _startAngle ) ;
171178 }
172179
173180 get startAngle ( ) {
174181 return this . _startAngle ;
175182 }
176183
177184 set barWidth ( value : number ) {
178- this . _barWidth = Number ( value ) ;
179- this . updateAnimatedCircle ( ) ;
185+ this . _barWidth = value ;
186+ if ( this . _barWidth ) {
187+ this . android ?. setBarWidth ( this . _barWidth ) ;
188+ } else {
189+ if ( this . _rimWidth ) {
190+ // set rim width to bar width if no bar width provided
191+ this . android ?. setBarWidth ( this . _rimWidth ) ;
192+ }
193+ }
180194 }
181195
182196 get barWidth ( ) {
@@ -185,11 +199,11 @@ export class AnimatedCircle extends AnimatedCircleCommon {
185199
186200 set text ( value : string ) {
187201 this . _text = value ;
188- this . updateAnimatedCircle ( ) ;
202+ this . android ?. setText ( this . _text ) ;
189203 }
190204
191205 get text ( ) {
192- return this . android . getText ( ) ;
206+ return this . _text ;
193207 }
194208
195209 set textColor ( value : string ) {
@@ -206,6 +220,14 @@ export class AnimatedCircle extends AnimatedCircleCommon {
206220 return this . android . getTextSize ( ) ;
207221 }
208222
223+ set clockwise ( value : boolean ) {
224+ this . _clockwise = value ;
225+ this . android ?. setDirection ( value === true ? at . grabner . circleprogress . Direction . CW : at . grabner . circleprogress . Direction . CCW ) ;
226+ }
227+
228+ get clockwise ( ) {
229+ return this . _clockwise ;
230+ }
209231 // CSS Properties
210232
211233 [ rimColorProperty . setNative ] ( value : any ) {
@@ -249,7 +271,6 @@ export class AnimatedCircle extends AnimatedCircleCommon {
249271
250272 private updateAnimatedCircle ( ) : void {
251273 if ( this . android ) {
252- this . android . setText ( this . _text ) ;
253274 if ( this . animated ) {
254275 if ( this . animateFrom ) {
255276 this . android . setValueAnimated ( this . animateFrom , this . progress , this . animationDuration ) ;
@@ -263,24 +284,6 @@ export class AnimatedCircle extends AnimatedCircleCommon {
263284 } else {
264285 this . android . setValue ( this . progress ) ;
265286 }
266- this . android . setMaxValue ( this . maxValue ) ;
267-
268- if ( this . startAngle ) {
269- this . android . setStartAngle ( this . startAngle ) ;
270- }
271- if ( this . barWidth ) {
272- this . android . setBarWidth ( this . barWidth ) ;
273- } else {
274- if ( this . rimWidth ) {
275- // set rim width to bar width if no bar width provided
276- this . android . setBarWidth ( this . rimWidth ) ;
277- }
278- }
279- if ( this . rimWidth ) {
280- this . android . setRimWidth ( this . rimWidth ) ;
281- }
282-
283- this . android . setDirection ( this . clockwise ? at . grabner . circleprogress . Direction . CW : at . grabner . circleprogress . Direction . CCW ) ;
284287 }
285288 }
286289}
0 commit comments