mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
dialogs for android implemented
This commit is contained in:
@ -5,6 +5,11 @@ import promises = require("promises");
|
|||||||
import dialogs = require("ui/dialogs");
|
import dialogs = require("ui/dialogs");
|
||||||
import appmodule = require("application");
|
import appmodule = require("application");
|
||||||
|
|
||||||
|
var STRING = "string",
|
||||||
|
ALERT = "Alert",
|
||||||
|
OK = "OK",
|
||||||
|
CANCEL = "Cancel";
|
||||||
|
|
||||||
function createAlertDialog(options: dialogs.DialogOptions): android.app.AlertDialog.Builder {
|
function createAlertDialog(options: dialogs.DialogOptions): android.app.AlertDialog.Builder {
|
||||||
var alert = new android.app.AlertDialog.Builder(appmodule.android.currentActivity);
|
var alert = new android.app.AlertDialog.Builder(appmodule.android.currentActivity);
|
||||||
alert.setTitle(options.title);
|
alert.setTitle(options.title);
|
||||||
@ -12,19 +17,39 @@ function createAlertDialog(options: dialogs.DialogOptions): android.app.AlertDia
|
|||||||
return alert;
|
return alert;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addOkCancelButtonsToAlertDialog(alert: android.app.AlertDialog.Builder, options: dialogs.ConfirmOptions,
|
||||||
|
okCallback: Function, cancelCallback?: Function): void {
|
||||||
|
alert.setPositiveButton(options.okButtonName, new android.content.DialogInterface.OnClickListener({
|
||||||
|
onClick: function (dialog: android.content.DialogInterface, id: number) {
|
||||||
|
dialog.cancel();
|
||||||
|
okCallback();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
alert.setNegativeButton(options.cancelButtonName, new android.content.DialogInterface.OnClickListener({
|
||||||
|
onClick: function (dialog: android.content.DialogInterface, id: number) {
|
||||||
|
dialog.cancel();
|
||||||
|
if (cancelCallback) {
|
||||||
|
cancelCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
export function alert(arg: any): promises.Promise<void> {
|
export function alert(arg: any): promises.Promise<void> {
|
||||||
var d = promises.defer<void>();
|
var d = promises.defer<void>();
|
||||||
try {
|
try {
|
||||||
var options = typeof arg === "string" ? { message: arg, title: "Alert", buttonName: "OK" } : arg
|
var options = typeof arg === STRING ? { message: arg, title: ALERT, buttonName: OK } : arg
|
||||||
|
|
||||||
var alert = createAlertDialog(options);
|
var alert = createAlertDialog(options);
|
||||||
/*
|
|
||||||
alert.setPositiveButton(options.buttonName, new android.content.DialogInterface.OnClickListener({
|
alert.setPositiveButton(options.buttonName, new android.content.DialogInterface.OnClickListener({
|
||||||
onClick: function (dialog: android.content.DialogInterface, id: number) {
|
onClick: function (dialog: android.content.DialogInterface, id: number) {
|
||||||
dialog.cancel();
|
dialog.cancel();
|
||||||
|
d.resolve();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
*/
|
|
||||||
alert.show();
|
alert.show();
|
||||||
|
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
@ -37,10 +62,12 @@ export function alert(arg: any): promises.Promise<void> {
|
|||||||
export function confirm(arg: any): promises.Promise<boolean> {
|
export function confirm(arg: any): promises.Promise<boolean> {
|
||||||
var d = promises.defer<boolean>();
|
var d = promises.defer<boolean>();
|
||||||
try {
|
try {
|
||||||
var options = typeof arg === "string" ? { message: arg, title: "Alert", okButtonName: "OK", cancelButtonName: "Cancel" } : arg
|
var options = typeof arg === STRING ? { message: arg, title: ALERT, okButtonName: OK, cancelButtonName: CANCEL } : arg
|
||||||
|
|
||||||
var alert = createAlertDialog(options);
|
var alert = createAlertDialog(options);
|
||||||
|
|
||||||
|
addOkCancelButtonsToAlertDialog(alert, options, function () { d.resolve(true); }, function () { d.resolve(false); });
|
||||||
|
|
||||||
alert.show();
|
alert.show();
|
||||||
|
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
@ -53,10 +80,17 @@ export function confirm(arg: any): promises.Promise<boolean> {
|
|||||||
export function prompt(arg: any): promises.Promise<string> {
|
export function prompt(arg: any): promises.Promise<string> {
|
||||||
var d = promises.defer<string>();
|
var d = promises.defer<string>();
|
||||||
try {
|
try {
|
||||||
var options = typeof arg === "string" ? { message: arg, title: "Alert", okButtonName: "OK", cancelButtonName: "Cancel" } : arg
|
var options = typeof arg === STRING ? { message: arg, title: ALERT, okButtonName: OK, cancelButtonName: CANCEL } : arg
|
||||||
|
|
||||||
var alert = createAlertDialog(options);
|
var alert = createAlertDialog(options);
|
||||||
|
|
||||||
|
var input = new android.widget.EditText(appmodule.android.context);
|
||||||
|
input.setText(options.defaultText ? options.defaultText : "");
|
||||||
|
|
||||||
|
alert.setView(input);
|
||||||
|
|
||||||
|
addOkCancelButtonsToAlertDialog(alert, options, function () { d.resolve(input.getText().toString()); });
|
||||||
|
|
||||||
alert.show();
|
alert.show();
|
||||||
|
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
|
Reference in New Issue
Block a user