forked from NativeScript/NativeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.android.ts
More file actions
63 lines (49 loc) · 2.29 KB
/
button.android.ts
File metadata and controls
63 lines (49 loc) · 2.29 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
import common = require("ui/button/button-common");
import utils = require("utils/utils");
import trace = require("trace");
// merge the exports of the common file with the exports of this file
declare var exports;
require("utils/module-merge").merge(common, exports);
export class Button extends common.Button {
private _android: android.widget.Button;
private _isPressed: boolean;
constructor() {
super();
this._isPressed = false;
}
get android(): android.widget.Button {
return this._android;
}
public _createUI() {
var that = new WeakRef(this);
this._android = new android.widget.Button(this._context);
this._android.setOnClickListener(new android.view.View.OnClickListener({
get owner() {
return that.get();
},
onClick: function (v) {
if (this.owner) {
this.owner._emit(common.Button.tapEvent);
}
}
}));
}
public onLayout(left: number, top: number, right: number, bottom: number): void {
if (this.android) {
var measuredWidth = this.getMeasuredWidth();
var measuredHeight = this.getMeasuredHeight();
var measureSpecs = this._getCurrentMeasureSpecs();
var widthModeIsNotExact = utils.layout.getMeasureSpecMode(measureSpecs.widthMeasureSpec) !== utils.layout.EXACTLY;
var heightModeIsNotExact = utils.layout.getMeasureSpecMode(measureSpecs.heightMeasureSpec) !== utils.layout.EXACTLY;
var width = right - left;
var height = bottom - top;
if ((Math.abs(measuredWidth - width) > 1 && widthModeIsNotExact) || (Math.abs(measuredHeight - height) > 1 && heightModeIsNotExact)) {
var widthMeasureSpec = utils.layout.makeMeasureSpec(width, utils.layout.EXACTLY);
var heightMeasureSpec = utils.layout.makeMeasureSpec(height, utils.layout.EXACTLY);
trace.write(this + ", measuredSize: (" + measuredWidth + ", " + measuredHeight + ")" + ", remeasure with: (" + width + ", " + height + ")", trace.categories.Layout);
this.android.measure(widthMeasureSpec, heightMeasureSpec);
}
}
super.onLayout(left, top, right, bottom);
}
}