Repository navigation
Expand file tree
/
Copy pathswitch.android.ts
More file actions
91 lines (71 loc) · 3.31 KB
/
Copy pathswitch.android.ts
File metadata and controls
91 lines (71 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import common = require("./switch-common");
import dependencyObservable = require("ui/core/dependency-observable");
import proxy = require("ui/core/proxy");
import utils = require("utils/utils")
import style = require("ui/styling/style");
import view = require("ui/core/view");
function onCheckedPropertyChanged(data: dependencyObservable.PropertyChangeData) {
var swtch = <Switch>data.object;
if (!swtch.android) {
return;
}
swtch.android.setChecked(data.newValue);
}
// register the setNativeValue callbacks
(<proxy.PropertyMetadata>common.Switch.checkedProperty.metadata).onSetNativeValue = onCheckedPropertyChanged;
global.moduleMerge(common, exports);
export class Switch extends common.Switch {
private _android: android.widget.Switch;
get android(): android.widget.Switch {
return this._android;
}
public _createUI() {
this._android = new android.widget.Switch(this._context);
var that = new WeakRef(this);
this._android.setOnCheckedChangeListener(new android.widget.CompoundButton.OnCheckedChangeListener(<utils.Owned & android.widget.CompoundButton.IOnCheckedChangeListener>{
get owner() {
return that.get();
},
onCheckedChanged: function (sender, isChecked) {
if (this.owner) {
this.owner._onPropertyChangedFromNative(common.Switch.checkedProperty, isChecked);
}
}
}));
}
}
export class SwitchStyler implements style.Styler {
private static setColorProperty(view: view.View, newValue: any) {
var sw = <android.widget.Switch>view._nativeView;
var drawable = <android.graphics.drawable.StateListDrawable>sw.getThumbDrawable();
if (drawable) {
drawable.setColorFilter(newValue, android.graphics.PorterDuff.Mode.SRC_IN);
}
}
private static resetColorProperty(view: view.View, nativeValue: number) {
// Do nothing.
}
private static setBackgroundAndBorderProperty(view: view.View, newValue: any) {
var sw = <android.widget.Switch>view._nativeView;
var drawable = <android.graphics.drawable.StateListDrawable>sw.getTrackDrawable();
if (drawable) {
drawable.setColorFilter(newValue, android.graphics.PorterDuff.Mode.SRC_IN);
}
}
private static resetBackgroundAndBorderProperty(view: view.View, nativeValue: number) {
// Do nothing.
}
public static registerHandlers() {
style.registerHandler(style.colorProperty, new style.StylePropertyChangedHandler(
SwitchStyler.setColorProperty,
SwitchStyler.resetColorProperty), "Switch");
style.registerHandler(style.backgroundColorProperty, new style.StylePropertyChangedHandler(
SwitchStyler.setBackgroundAndBorderProperty,
SwitchStyler.resetBackgroundAndBorderProperty), "Switch");
style.registerHandler(style.borderWidthProperty, style.ignorePropertyHandler, "Switch");
style.registerHandler(style.borderColorProperty, style.ignorePropertyHandler, "Switch");
style.registerHandler(style.borderRadiusProperty, style.ignorePropertyHandler, "Switch");
style.registerHandler(style.backgroundInternalProperty, style.ignorePropertyHandler, "Switch");
}
}
SwitchStyler.registerHandlers();