mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-18 05:18:39 +08:00
58 lines
1.9 KiB
TypeScript
58 lines
1.9 KiB
TypeScript
import textViewModule = require("ui/text-view");
|
|
import colorModule = require("color");
|
|
import utilsModule = require("utils/utils");
|
|
import enums = require("ui/enums");
|
|
|
|
export function getNativeText(textView: textViewModule.TextView): string {
|
|
return textView.android.getText().toString();
|
|
}
|
|
|
|
export function getNativeEditable(textView: textViewModule.TextView): boolean {
|
|
if (textView.android.getKeyListener()) {
|
|
return true;
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export function getNativeHint(textView: textViewModule.TextView): string {
|
|
return textView.android.getHint();
|
|
}
|
|
|
|
export function getNativeFontSize(textView: textViewModule.TextView): number {
|
|
var density = utilsModule.layout.getDisplayDensity();
|
|
return textView.android.getTextSize() / density;
|
|
}
|
|
|
|
export function getNativeColor(textView: textViewModule.TextView): colorModule.Color {
|
|
return new colorModule.Color(textView.android.getTextColors().getDefaultColor());
|
|
}
|
|
|
|
export function getNativeBackgroundColor(textView: textViewModule.TextView): colorModule.Color {
|
|
return new colorModule.Color((<any>textView.android.getBackground()).backgroundColor);
|
|
}
|
|
|
|
export function getNativeTextAlignment(textView: textViewModule.TextView): string {
|
|
var gravity = textView.android.getGravity();
|
|
|
|
if ((gravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK) === android.view.Gravity.LEFT) {
|
|
return enums.TextAlignment.left;
|
|
}
|
|
|
|
if ((gravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK) === android.view.Gravity.CENTER_HORIZONTAL) {
|
|
return enums.TextAlignment.center;
|
|
}
|
|
|
|
if ((gravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK) === android.view.Gravity.RIGHT) {
|
|
return enums.TextAlignment.right;
|
|
}
|
|
|
|
return "unexpected value";
|
|
}
|
|
|
|
export function typeTextNatively(textView: textViewModule.TextView, text: string): void {
|
|
textView.android.requestFocus();
|
|
textView.android.setText(text);
|
|
textView.android.clearFocus();
|
|
} |