-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.android.js
70 lines (59 loc) · 2.09 KB
/
index.android.js
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
var application = require("application");
var result;
exports.show = function (options) {
return new Promise(function (resolve, reject) {
try {
if (options) {
var alert = new android.app.AlertDialog.Builder(application.android.currentContext);
if (options.message) {
alert.setMessage(options.message);
}
if (options.title) {
alert.setTitle(options.title);
}
if (options.nativeView instanceof android.view.View) {
alert.setView(options.nativeView);
}
if (options.cancelButtonText) {
alert.setNegativeButton(options.cancelButtonText, new android.content.DialogInterface.OnClickListener({
onClick: function (dialog, id) {
dialog.cancel();
resolve(false);
}
}));
}
if (options.neutralButtonText) {
alert.setNeutralButton(options.neutralButtonText, new android.content.DialogInterface.OnClickListener({
onClick: function (dialog, id) {
dialog.cancel();
resolve(undefined);
}
}));
}
if (options.okButtonText) {
alert.setPositiveButton(options.okButtonText, new android.content.DialogInterface.OnClickListener({
onClick: function (dialog, id) {
dialog.cancel();
resolve(true);
}
}));
}
result = {};
result.resolve = resolve,
result.dialog = alert.show();
}
} catch (ex) {
reject(ex);
}
});
}
exports.close = function () {
if(result){
if(result.dialog instanceof android.app.AlertDialog){
result.dialog.cancel();
}
if(result.resolve instanceof Function){
result.resolve(true);
}
}
}