From 53cedc8914e4b03cd4158ee546fafdb2311c62c4 Mon Sep 17 00:00:00 2001 From: James Choi Date: Mon, 6 Feb 2012 14:44:57 -0500 Subject: [PATCH] Fixed issue where back button does not close custom ask dialogs. --- .../ui/dialog/CustomAskAsyncFunction.java | 17 +++++++-------- .../ui/dialog/DialogRunnableFactory.java | 21 +++++++++---------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/api/dialog/src/main/java/blackberry/ui/dialog/CustomAskAsyncFunction.java b/api/dialog/src/main/java/blackberry/ui/dialog/CustomAskAsyncFunction.java index bd6031a..e5e8a5b 100644 --- a/api/dialog/src/main/java/blackberry/ui/dialog/CustomAskAsyncFunction.java +++ b/api/dialog/src/main/java/blackberry/ui/dialog/CustomAskAsyncFunction.java @@ -37,28 +37,25 @@ public class CustomAskAsyncFunction extends ScriptableFunctionBase { public Object execute( Object thiz, Object[] args ) throws Exception { String message; String[] buttons; - int[] values; - //the default value of the default choice. The developer cannot change it. + // the default value of the default choice. The developer cannot change it. final int defaultChoice = 0; - //callback function + // callback function ScriptableFunction callback = (ScriptableFunction) args[ 2 ]; - //the default value of the global status. The developer cannot change it. - final boolean global = false; + // the default value of the global status. The developer cannot change it. + final boolean global = false; // message message = (String) args[ 0 ]; // choices & values Scriptable stringArray = (Scriptable) args[ 1 ]; int count = stringArray.getElementCount(); buttons = new String[ count ]; - values = new int[ count ]; for( int i = 0; i < count; i++ ) { buttons[ i ] = stringArray.getElement( i ).toString(); - values[ i ] = i; } - Runnable dr = DialogRunnableFactory.getCustomAskRunnable(message, buttons, values, defaultChoice, global, callback); + Runnable dr = DialogRunnableFactory.getCustomAskRunnable( message, buttons, defaultChoice, global, callback ); // queue - UiApplication.getUiApplication().invokeLater(dr); + UiApplication.getUiApplication().invokeLater( dr ); // return value return Scriptable.UNDEFINED; } @@ -75,7 +72,7 @@ protected FunctionSignature[] getFunctionSignatures() { fs.addParam( Scriptable.class, true ); // callback fs.addParam( ScriptableFunction.class, true ); - // filler + // filler fs.addParam( Object.class, false ); return new FunctionSignature[] { fs }; } diff --git a/api/dialog/src/main/java/blackberry/ui/dialog/DialogRunnableFactory.java b/api/dialog/src/main/java/blackberry/ui/dialog/DialogRunnableFactory.java index 1772ad1..5ff06a3 100644 --- a/api/dialog/src/main/java/blackberry/ui/dialog/DialogRunnableFactory.java +++ b/api/dialog/src/main/java/blackberry/ui/dialog/DialogRunnableFactory.java @@ -82,9 +82,9 @@ public static Runnable getSelectRunnable(boolean allowMultiple, String[] labels, * @param callback the callback function * @return the Runnable responsible for opening the dialog */ - public static Runnable getCustomAskRunnable(String message, String[] buttons, int[] values, int defaultChoice, boolean global /* style, false */, ScriptableFunction callback) { - Dialog d = new Dialog( message, buttons, values, defaultChoice, null /* bitmap */, global ? Dialog.GLOBAL_STATUS : 0 /* style */); - return new DialogAsyncRunnable(d, callback); + public static Runnable getCustomAskRunnable(String message, String[] buttons, int defaultChoice, boolean global /* style, false */, ScriptableFunction callback) { + Dialog d = new Dialog( message, buttons, null, defaultChoice, null /* bitmap */, global ? Dialog.GLOBAL_STATUS : 0 /* style */); + return new DialogAsyncRunnable( d, callback ); } /** @@ -177,20 +177,19 @@ private static class DialogAsyncRunnable implements Runnable { _callback = callback; } - /** * Run the dialog. * * @see java.lang.Runnable#run() */ - public void run() { - _dialogValue = new Integer(_dialog.doModal()); - //get object's string as all ecma primitives will return a valid string representation of themselves - Object retVal = _dialogValue.toString(); + public void run() { + _dialogValue = new Integer( _dialog.doModal() ); + // get object's string as all ecma primitives will return a valid string representation of themselves + Object retVal = _dialogValue.toString(); try { - _callback.invoke(null, new Object[] { retVal }); - } catch (Exception e) { - throw new RuntimeException("Invoke callback failed: " + e.getMessage()); + _callback.invoke( null, new Object[] { retVal } ); + } catch( Exception e ) { + throw new RuntimeException( "Invoke callback failed: " + e.getMessage() ); } } }