1
+ import { CheckBoxInterface } from "./checkbox" ;
1
2
import { View } from "ui/core/view" ;
2
3
import { Color } from "color" ;
3
4
import { isAndroid , device } from "platform" ;
4
5
import { Property , PropertyChangeData } from "ui/core/dependency-observable" ;
5
6
import { PropertyMetadata } from "ui/core/proxy" ;
7
+ import { Font } from "ui/styling/font" ;
8
+ import enums = require( "ui/enums" ) ;
6
9
import style = require( "ui/styling/style" ) ;
7
10
8
11
declare var android : any ;
9
12
10
- export class CheckBox extends View {
13
+ export class CheckBox extends View implements CheckBoxInterface {
11
14
private _android : any ; /// android.widget.CheckBox
15
+ private _fillColor : string ;
16
+ private _checkBoxSize : number ;
12
17
13
18
public static checkedProperty = new Property (
14
19
"checked" ,
@@ -22,6 +27,11 @@ export class CheckBox extends View {
22
27
new PropertyMetadata ( false )
23
28
) ;
24
29
30
+ constructor ( ) {
31
+ super ( ) ;
32
+
33
+ this . _checkBoxSize = 21 ;
34
+ }
25
35
26
36
get android ( ) {
27
37
return this . _android ;
@@ -34,17 +44,46 @@ export class CheckBox extends View {
34
44
get checked ( ) : boolean {
35
45
return this . _getValue ( CheckBox . checkedProperty ) ;
36
46
}
47
+
37
48
set checked ( value : boolean ) {
38
49
this . _setValue ( CheckBox . checkedProperty , value ) ;
39
50
}
40
51
41
- get text ( ) : boolean {
52
+ get text ( ) : string {
42
53
return this . _getValue ( CheckBox . textProperty ) ;
43
54
}
44
- set text ( value : boolean ) {
55
+ set text ( value : string ) {
45
56
this . _setValue ( CheckBox . textProperty , value ) ;
46
57
}
47
58
59
+ get fillColor ( ) : string {
60
+ return this . _fillColor ;
61
+ }
62
+
63
+ set fillColor ( color : string ) {
64
+ this . _fillColor = color ;
65
+
66
+ if ( this . _android )
67
+ this . _android . setButtonTintList ( android . content . res . ColorStateList . valueOf ( new Color ( this . _fillColor ) . android ) ) ;
68
+ }
69
+
70
+ get checkboxSize ( ) {
71
+ return this . _checkBoxSize ;
72
+ }
73
+
74
+ set checkBoxSize ( size : number ) {
75
+ this . _checkBoxSize = size ;
76
+ }
77
+
78
+ //There is no difference between tint and fill on the android widget
79
+ get tintColor ( ) : string {
80
+ return this . fillColor ;
81
+ }
82
+
83
+ set tintColor ( color : string ) {
84
+ this . fillColor = color ;
85
+ }
86
+
48
87
49
88
public _createUI ( ) {
50
89
@@ -54,6 +93,12 @@ export class CheckBox extends View {
54
93
this . _android . setText ( this . text ) ;
55
94
}
56
95
96
+ //Set bound colors
97
+ if ( this . _android ) {
98
+ if ( this . fillColor )
99
+ this . _android . setButtonTintList ( android . content . res . ColorStateList . valueOf ( new Color ( this . _fillColor ) . android ) ) ;
100
+ }
101
+
57
102
var that = new WeakRef ( this ) ;
58
103
59
104
this . _android . setOnCheckedChangeListener ( new android . widget . CompoundButton . OnCheckedChangeListener ( {
@@ -73,9 +118,6 @@ export class CheckBox extends View {
73
118
public toggle ( ) : void {
74
119
this . _android . toggle ( ) ;
75
120
}
76
-
77
-
78
-
79
121
}
80
122
81
123
@@ -107,21 +149,68 @@ function onTextPropertyChanged(data: PropertyChangeData) {
107
149
108
150
109
151
export class CheckBoxStyler implements style . Styler {
110
- private static setColorProperty ( view : any , newValue : any ) {
152
+ private static setColorLabelProperty ( view : any , newValue : any ) {
111
153
var cb = < android . widget . CheckBox > view . _nativeView ;
112
154
if ( cb ) {
113
- ( < any > cb ) . setButtonTintList ( android . content . res . ColorStateList . valueOf ( new Color ( newValue ) . android ) ) ;
155
+ ( < any > cb ) . setTextColor ( new Color ( newValue ) . android ) ;
156
+ }
157
+ }
158
+
159
+ // font
160
+ private static setFontInternalProperty ( view : any , newValue : any , nativeValue ?: any ) {
161
+ var tv = < android . widget . CheckBox > view . _nativeView ;
162
+ var fontValue = < Font > newValue ;
163
+
164
+ var typeface = fontValue . getAndroidTypeface ( ) ;
165
+ if ( typeface ) {
166
+ tv . setTypeface ( typeface ) ;
167
+ }
168
+ else {
169
+ tv . setTypeface ( nativeValue . typeface ) ;
170
+ }
171
+
172
+ if ( fontValue . fontSize ) {
173
+ tv . setTextSize ( fontValue . fontSize ) ;
174
+ }
175
+ else {
176
+ tv . setTextSize ( android . util . TypedValue . COMPLEX_UNIT_PX , nativeValue . size ) ;
177
+ }
178
+ }
179
+
180
+ private static resetFontInternalProperty ( view : any , nativeValue : any ) {
181
+ var tv : android . widget . CheckBox = < android . widget . CheckBox > view . _nativeView ;
182
+ if ( tv && nativeValue ) {
183
+ tv . setTypeface ( nativeValue . typeface ) ;
184
+ tv . setTextSize ( android . util . TypedValue . COMPLEX_UNIT_PX , nativeValue . size ) ;
114
185
}
115
186
}
116
187
188
+ private static getNativeFontInternalValue ( view : any ) : any {
189
+ var tv : android . widget . TextView = < android . widget . CheckBox > view . _nativeView ;
190
+ return {
191
+ typeface : tv . getTypeface ( ) ,
192
+ size : tv . getTextSize ( )
193
+ } ;
194
+ }
117
195
private static resetColorProperty ( view : View , nativeValue : number ) {
118
196
// Do nothing.
119
197
}
120
198
199
+
121
200
public static registerHandlers ( ) {
122
201
style . registerHandler ( style . colorProperty , new style . StylePropertyChangedHandler (
123
- CheckBoxStyler . setColorProperty ,
202
+ CheckBoxStyler . setColorLabelProperty ,
203
+ CheckBoxStyler . resetColorProperty ) , "CheckBox" ) ;
204
+
205
+ style . registerHandler ( style . fontInternalProperty , new style . StylePropertyChangedHandler (
206
+ CheckBoxStyler . setFontInternalProperty ,
207
+ CheckBoxStyler . resetFontInternalProperty ,
208
+ CheckBoxStyler . getNativeFontInternalValue ) , "CheckBox" ) ;
209
+ /*
210
+ style.registerHandler(style.backgroundColorProperty, new style.StylePropertyChangedHandler(
211
+ CheckBoxStyler.setColorLabelProperty,
124
212
CheckBoxStyler.resetColorProperty), "CheckBox");
213
+ */
125
214
126
215
style . registerHandler ( style . borderWidthProperty , style . ignorePropertyHandler , "CheckBox" ) ;
127
216
style . registerHandler ( style . borderColorProperty , style . ignorePropertyHandler , "CheckBox" ) ;
0 commit comments