1+ import { CheckBoxInterface } from "./checkbox" ;
12import { View } from "ui/core/view" ;
23import { Color } from "color" ;
34import { isAndroid , device } from "platform" ;
45import { Property , PropertyChangeData } from "ui/core/dependency-observable" ;
56import { PropertyMetadata } from "ui/core/proxy" ;
7+ import { Font } from "ui/styling/font" ;
8+ import enums = require( "ui/enums" ) ;
69import style = require( "ui/styling/style" ) ;
710
811declare var android : any ;
912
10- export class CheckBox extends View {
13+ export class CheckBox extends View implements CheckBoxInterface {
1114 private _android : any ; /// android.widget.CheckBox
15+ private _fillColor : string ;
16+ private _checkBoxSize : number ;
1217
1318 public static checkedProperty = new Property (
1419 "checked" ,
@@ -22,6 +27,11 @@ export class CheckBox extends View {
2227 new PropertyMetadata ( false )
2328 ) ;
2429
30+ constructor ( ) {
31+ super ( ) ;
32+
33+ this . _checkBoxSize = 21 ;
34+ }
2535
2636 get android ( ) {
2737 return this . _android ;
@@ -34,17 +44,46 @@ export class CheckBox extends View {
3444 get checked ( ) : boolean {
3545 return this . _getValue ( CheckBox . checkedProperty ) ;
3646 }
47+
3748 set checked ( value : boolean ) {
3849 this . _setValue ( CheckBox . checkedProperty , value ) ;
3950 }
4051
41- get text ( ) : boolean {
52+ get text ( ) : string {
4253 return this . _getValue ( CheckBox . textProperty ) ;
4354 }
44- set text ( value : boolean ) {
55+ set text ( value : string ) {
4556 this . _setValue ( CheckBox . textProperty , value ) ;
4657 }
4758
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+
4887
4988 public _createUI ( ) {
5089
@@ -54,6 +93,12 @@ export class CheckBox extends View {
5493 this . _android . setText ( this . text ) ;
5594 }
5695
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+
57102 var that = new WeakRef ( this ) ;
58103
59104 this . _android . setOnCheckedChangeListener ( new android . widget . CompoundButton . OnCheckedChangeListener ( {
@@ -73,9 +118,6 @@ export class CheckBox extends View {
73118 public toggle ( ) : void {
74119 this . _android . toggle ( ) ;
75120 }
76-
77-
78-
79121}
80122
81123
@@ -107,21 +149,68 @@ function onTextPropertyChanged(data: PropertyChangeData) {
107149
108150
109151export class CheckBoxStyler implements style . Styler {
110- private static setColorProperty ( view : any , newValue : any ) {
152+ private static setColorLabelProperty ( view : any , newValue : any ) {
111153 var cb = < android . widget . CheckBox > view . _nativeView ;
112154 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 ) ;
114185 }
115186 }
116187
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+ }
117195 private static resetColorProperty ( view : View , nativeValue : number ) {
118196 // Do nothing.
119197 }
120198
199+
121200 public static registerHandlers ( ) {
122201 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,
124212 CheckBoxStyler.resetColorProperty), "CheckBox");
213+ */
125214
126215 style . registerHandler ( style . borderWidthProperty , style . ignorePropertyHandler , "CheckBox" ) ;
127216 style . registerHandler ( style . borderColorProperty , style . ignorePropertyHandler , "CheckBox" ) ;
0 commit comments