From 1ea6e5897e58cbbd5874915405cf82d95792af88 Mon Sep 17 00:00:00 2001 From: Nathanael Anderson Date: Tue, 10 Nov 2015 21:34:31 -0600 Subject: [PATCH 1/5] This will now allow the dialog to call the resolve function when canceled by clicking outside of the dialog. --- ui/dialogs/dialogs.android.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/ui/dialogs/dialogs.android.ts b/ui/dialogs/dialogs.android.ts index ef3dfcad4..a00082707 100644 --- a/ui/dialogs/dialogs.android.ts +++ b/ui/dialogs/dialogs.android.ts @@ -13,6 +13,9 @@ function createAlertDialog(options?: dialogs.DialogOptions): android.app.AlertDi var alert = new android.app.AlertDialog.Builder(appmodule.android.foregroundActivity); alert.setTitle(options && types.isString(options.title) ? options.title : ""); alert.setMessage(options && types.isString(options.message) ? options.message : ""); + if (options && (options.cancelable === false || options.cancelable === 0)) { + alert.setCancelable(false); + } return alert; } @@ -72,6 +75,11 @@ function addButtonsToAlertDialog(alert: android.app.AlertDialog.Builder, options } })); } + alert.setOnDismissListener(new android.content.DialogInterface.OnDismissListener({ + onDismiss: function() { + callback(false); + } + })); } export function alert(arg: any): Promise { @@ -87,6 +95,11 @@ export function alert(arg: any): Promise { resolve(); } })); + alert.setOnDismissListener(new android.content.DialogInterface.OnDismissListener({ + onDismiss: function() { + resolve(); + } + })); showDialog(alert); @@ -262,6 +275,9 @@ export function action(arg: any): Promise { var alert = new android.app.AlertDialog.Builder(activity); var message = options && types.isString(options.message) ? options.message : ""; var title = options && types.isString(options.title) ? options.title : ""; + if (options && (options.cancelable === false || options.cancelable === 0)) { + alert.setCancelable(false); + } if (title) { alert.setTitle(title); @@ -289,6 +305,17 @@ export function action(arg: any): Promise { } })); } + + alert.setOnDismissListener(new android.content.DialogInterface.OnDismissListener({ + onDismiss: function() { + if (types.isString(options.cancelButtonText)) { + resolve(options.cancelButtonText); + } else { + resolve(""); + } + } + })); + showDialog(alert); } catch (ex) { From 73f179d3b6cf5c4b7df2cc88d4a13688cf9f8348 Mon Sep 17 00:00:00 2001 From: Nathanael Anderson Date: Thu, 12 Nov 2015 16:51:47 -0600 Subject: [PATCH 2/5] Added the cancelable to the dialogs.d.ts --- ui/dialogs/dialogs.d.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ui/dialogs/dialogs.d.ts b/ui/dialogs/dialogs.d.ts index 8114eb669..7db01cdc8 100644 --- a/ui/dialogs/dialogs.d.ts +++ b/ui/dialogs/dialogs.d.ts @@ -120,6 +120,12 @@ declare module "ui/dialogs" { * Gets or sets the dialog message. */ message?: string; + + /** + * Sets if the Android dialog can be canceled via clicking outside of it + * defaults to true. + */ + cancelable?: boolean; } /** From bc7fd76498f097d2da4ff4b1ae82c33b60ebfae8 Mon Sep 17 00:00:00 2001 From: Nathanael Anderson Date: Thu, 12 Nov 2015 16:56:10 -0600 Subject: [PATCH 3/5] Eliminte that 0 check on this; as this should only be a boolean value. --- ui/dialogs/dialogs.android.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/dialogs/dialogs.android.ts b/ui/dialogs/dialogs.android.ts index a00082707..3040a1090 100644 --- a/ui/dialogs/dialogs.android.ts +++ b/ui/dialogs/dialogs.android.ts @@ -13,7 +13,7 @@ function createAlertDialog(options?: dialogs.DialogOptions): android.app.AlertDi var alert = new android.app.AlertDialog.Builder(appmodule.android.foregroundActivity); alert.setTitle(options && types.isString(options.title) ? options.title : ""); alert.setMessage(options && types.isString(options.message) ? options.message : ""); - if (options && (options.cancelable === false || options.cancelable === 0)) { + if (options && options.cancelable === false) { alert.setCancelable(false); } return alert; From 84d79b44dc791153669abc4b666d332f5596849c Mon Sep 17 00:00:00 2001 From: Nathanael Anderson Date: Fri, 13 Nov 2015 13:18:36 -0600 Subject: [PATCH 4/5] Update the dialogs.d.ts so that everything can use the cancelable. ;-) --- ui/dialogs/dialogs.d.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/ui/dialogs/dialogs.d.ts b/ui/dialogs/dialogs.d.ts index 7db01cdc8..d134fc707 100644 --- a/ui/dialogs/dialogs.d.ts +++ b/ui/dialogs/dialogs.d.ts @@ -81,11 +81,21 @@ declare module "ui/dialogs" { * @param options The options for the dialog box. */ export function action(options: ActionOptions): Promise; + + /** + * Provides options for the dialog. + */ + export interface CancelableOptions { + /** + * [Android only] Gets or sets if the dialog can be canceled by taping outside of the dialog. + */ + cancelable?: boolean; + } /** * Provides options for the dialog. */ - export interface ActionOptions { + export interface ActionOptions extends CancelableOptions { /** * Gets or sets the dialog title. */ @@ -110,7 +120,7 @@ declare module "ui/dialogs" { /** * Provides options for the dialog. */ - export interface DialogOptions { + export interface DialogOptions extends CancelableOptions { /** * Gets or sets the dialog title. */ @@ -120,12 +130,7 @@ declare module "ui/dialogs" { * Gets or sets the dialog message. */ message?: string; - - /** - * Sets if the Android dialog can be canceled via clicking outside of it - * defaults to true. - */ - cancelable?: boolean; + } /** From 77f3008c5cf693d4b25b11996af0fe5208ad5cb6 Mon Sep 17 00:00:00 2001 From: Nathanael Anderson Date: Mon, 16 Nov 2015 14:19:54 -0600 Subject: [PATCH 5/5] Fix the final === 0 removal. --- ui/dialogs/dialogs.android.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/dialogs/dialogs.android.ts b/ui/dialogs/dialogs.android.ts index 3040a1090..067d0f70c 100644 --- a/ui/dialogs/dialogs.android.ts +++ b/ui/dialogs/dialogs.android.ts @@ -275,7 +275,7 @@ export function action(arg: any): Promise { var alert = new android.app.AlertDialog.Builder(activity); var message = options && types.isString(options.message) ? options.message : ""; var title = options && types.isString(options.title) ? options.title : ""; - if (options && (options.cancelable === false || options.cancelable === 0)) { + if (options && options.cancelable === false) { alert.setCancelable(false); }