1
- import { CheckBoxInterface } from "./" ;
2
- import { View } from "ui/core/view" ;
3
- import { Color } from "color" ;
4
- import { isAndroid , device } from "platform" ;
5
- import { Property , PropertyChangeData } from "ui/core/dependency-observable" ;
6
- import { PropertyMetadata } from "ui/core/proxy" ;
7
- import { Font } from "ui/styling/font" ;
1
+ import { CheckBoxInterface } from "./" ;
2
+ import { View } from "ui/core/view" ;
3
+ import { Color } from "color" ;
4
+ import { isAndroid , device } from "platform" ;
5
+ import { Property , PropertyChangeData } from "ui/core/dependency-observable" ;
6
+ import { PropertyMetadata } from "ui/core/proxy" ;
7
+ import { Font } from "ui/styling/font" ;
8
8
import enums = require( "ui/enums" ) ;
9
9
import style = require( "ui/styling/style" ) ;
10
-
10
+ import app = require ( "application" ) ;
11
11
declare var android : any ;
12
12
13
13
export class CheckBox extends View implements CheckBoxInterface {
14
14
private _android : any ; /// android.widget.CheckBox
15
15
private _fillColor : string ;
16
-
16
+ private _checkStyle : string ;
17
+ private _checkPadding : string ;
18
+ private _checkPaddingLeft : string ;
19
+ private _checkPaddingTop : string ;
20
+ private _checkPaddingRight : string ;
21
+ private _checkPaddingBottom : string ;
17
22
public static checkedProperty = new Property (
18
23
"checked" ,
19
24
"CheckBox" ,
@@ -38,6 +43,55 @@ export class CheckBox extends View implements CheckBoxInterface {
38
43
return this . _android ;
39
44
}
40
45
46
+ get checkStyle ( ) {
47
+ return this . _checkStyle ;
48
+ }
49
+
50
+ set checkStyle ( style ) {
51
+ this . _checkStyle = style ;
52
+ }
53
+
54
+ set checkPadding ( padding ) {
55
+ this . _checkPadding = padding ;
56
+ }
57
+
58
+ get checkPadding ( ) {
59
+ return this . _checkPadding ;
60
+ }
61
+
62
+ set checkPaddingLeft ( padding ) {
63
+ this . _checkPaddingLeft = padding ;
64
+ }
65
+
66
+ get checkPaddingLeft ( ) {
67
+ return this . _checkPaddingLeft ;
68
+ }
69
+
70
+
71
+ set checkPaddingTop ( padding ) {
72
+ this . _checkPaddingTop = padding ;
73
+ }
74
+
75
+ get checkPaddingTop ( ) {
76
+ return this . _checkPaddingTop ;
77
+ }
78
+
79
+ set checkPaddingRight ( padding ) {
80
+ this . _checkPaddingRight = padding ;
81
+ }
82
+
83
+ get checkPaddingRight ( ) {
84
+ return this . _checkPaddingRight ;
85
+ }
86
+
87
+ set checkPaddingBottom ( padding ) {
88
+ this . _checkPaddingBottom = padding ;
89
+ }
90
+
91
+ get checkPaddingBottom ( ) {
92
+ return this . _checkPaddingBottom ;
93
+ }
94
+
41
95
get checked ( ) : boolean {
42
96
return this . _getValue ( CheckBox . checkedProperty ) ;
43
97
}
@@ -49,6 +103,7 @@ export class CheckBox extends View implements CheckBoxInterface {
49
103
get text ( ) : string {
50
104
return this . _getValue ( CheckBox . textProperty ) ;
51
105
}
106
+
52
107
set text ( value : string ) {
53
108
this . _setValue ( CheckBox . textProperty , value ) ;
54
109
}
@@ -78,13 +133,51 @@ export class CheckBox extends View implements CheckBoxInterface {
78
133
79
134
this . _android = new android . widget . CheckBox ( this . _context , null ) ;
80
135
136
+ if ( this . checkPaddingLeft ) {
137
+ this . _android . setPadding ( this . checkPaddingLeft , this . _android . getPaddingTop ( ) , this . _android . getPaddingRight ( ) , this . _android . getPaddingBottom ( ) ) ;
138
+ }
139
+
140
+ if ( this . checkPaddingTop ) {
141
+ this . _android . setPadding ( this . _android . getPaddingLeft ( ) , this . checkPaddingTop , this . _android . getPaddingRight ( ) , this . _android . getPaddingBottom ( ) ) ;
142
+ }
143
+
144
+ if ( this . checkPaddingRight ) {
145
+ this . _android . setPadding ( this . _android . getPaddingLeft ( ) , this . _android . getPaddingTop ( ) , this . checkPaddingRight , this . _android . getPaddingBottom ( ) ) ;
146
+ }
147
+
148
+ if ( this . checkPaddingBottom ) {
149
+ this . _android . setPadding ( this . _android . getPaddingLeft ( ) , this . _android . getPaddingTop ( ) , this . _android . getPaddingRight ( ) , this . checkPaddingBottom ) ;
150
+ }
151
+
152
+ if ( this . checkPadding ) {
153
+ let pads = this . checkPadding . toString ( ) . split ( ',' ) ;
154
+ switch ( pads . length ) {
155
+ case 1 :
156
+ this . _android . setPadding ( parseInt ( pads [ 0 ] ) , parseInt ( pads [ 0 ] ) , parseInt ( pads [ 0 ] ) , parseInt ( pads [ 0 ] ) ) ;
157
+ break ;
158
+ case 2 :
159
+ this . _android . setPadding ( parseInt ( pads [ 0 ] ) , parseInt ( pads [ 1 ] ) , parseInt ( pads [ 0 ] ) , parseInt ( pads [ 1 ] ) ) ;
160
+ break ;
161
+ case 3 :
162
+ this . _android . setPadding ( parseInt ( pads [ 0 ] ) , parseInt ( pads [ 1 ] ) , parseInt ( pads [ 2 ] ) , parseInt ( pads [ 1 ] ) ) ;
163
+ break ;
164
+ case 4 :
165
+ this . _android . setPadding ( parseInt ( pads [ 0 ] ) , parseInt ( pads [ 1 ] ) , parseInt ( pads [ 2 ] ) , parseInt ( pads [ 3 ] ) ) ;
166
+ break ;
167
+ }
168
+ }
81
169
if ( this . text ) {
82
170
this . _android . setText ( this . text ) ;
83
171
}
84
172
if ( ! this . style . fontSize ) {
85
173
this . style . fontSize = 15 ;
86
174
}
87
175
176
+ if ( this . _checkStyle ) {
177
+ const drawable = app . android . context . getResources ( ) . getIdentifier ( this . _checkStyle , "drawable" , app . android . context . getPackageName ( ) ) ;
178
+ this . _android . setButtonDrawable ( drawable ) ;
179
+ }
180
+
88
181
89
182
if ( this . _android ) {
90
183
if ( this . fillColor && device . sdkVersion >= "21" ) {
@@ -142,7 +235,6 @@ function onTextPropertyChanged(data: PropertyChangeData) {
142
235
( < PropertyMetadata > CheckBox . textProperty . metadata ) . onSetNativeValue = onTextPropertyChanged ;
143
236
144
237
145
-
146
238
export class CheckBoxStyler implements style . Styler {
147
239
private static setColorLabelProperty ( view : any , newValue : any ) {
148
240
var cb = < android . widget . CheckBox > view . _nativeView ;
@@ -187,6 +279,7 @@ export class CheckBoxStyler implements style.Styler {
187
279
size : tv . getTextSize ( )
188
280
} ;
189
281
}
282
+
190
283
private static resetColorProperty ( view : View , nativeValue : number ) {
191
284
// Do nothing.
192
285
}
0 commit comments