mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
84 lines
2.5 KiB
TypeScript
84 lines
2.5 KiB
TypeScript
import common = require("./button-common");
|
|
import utils = require("utils/utils")
|
|
import dependencyObservable = require("ui/core/dependency-observable");
|
|
|
|
global.moduleMerge(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(
|
|
<utils.Owned & android.view.View.IOnClickListener>{
|
|
get owner() {
|
|
return that.get();
|
|
},
|
|
|
|
onClick: function(v) {
|
|
if (this.owner) {
|
|
this.owner._emit(common.Button.tapEvent);
|
|
}
|
|
}
|
|
}));
|
|
|
|
this._android.setOnTouchListener(new android.view.View.OnTouchListener(
|
|
<utils.Owned & android.view.View.IOnTouchListener>{
|
|
get owner() {
|
|
return that.get();
|
|
},
|
|
|
|
onTouch: function(v, ev) {
|
|
if (ev.getAction() === 0) { // down
|
|
this.owner._goToVisualState("highlighted");
|
|
}
|
|
else if (ev.getAction() === 1) { // up
|
|
this.owner._goToVisualState("normal");
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
));
|
|
}
|
|
|
|
public _onTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
|
if (this.android) {
|
|
this.android.setText(data.newValue + "");
|
|
}
|
|
}
|
|
|
|
private _transformationMethod;
|
|
public _setFormattedTextPropertyToNative(value) {
|
|
var newText = value ? value._formattedText : null;
|
|
if (this.android) {
|
|
if (newText) {
|
|
if (!this._transformationMethod) {
|
|
this._transformationMethod = this.android.getTransformationMethod();
|
|
}
|
|
this.android.setTransformationMethod(null);
|
|
} else {
|
|
if (this._transformationMethod && !this.android.getTransformationMethod()) {
|
|
this.android.setTransformationMethod(this._transformationMethod);
|
|
}
|
|
}
|
|
|
|
this.android.setText(newText);
|
|
}
|
|
}
|
|
}
|