Skip to content
This repository
Browse code

Fixed issue where back button does not close custom ask dialogs.

  • Loading branch information...
commit 53cedc8914e4b03cd4158ee546fafdb2311c62c4 1 parent bd49e27
James Choi jachoi authored
17 api/dialog/src/main/java/blackberry/ui/dialog/CustomAskAsyncFunction.java
@@ -37,28 +37,25 @@
37 37 public Object execute( Object thiz, Object[] args ) throws Exception {
38 38 String message;
39 39 String[] buttons;
40   - int[] values;
41   - //the default value of the default choice. The developer cannot change it.
  40 + // the default value of the default choice. The developer cannot change it.
42 41 final int defaultChoice = 0;
43   - //callback function
  42 + // callback function
44 43 ScriptableFunction callback = (ScriptableFunction) args[ 2 ];
45   - //the default value of the global status. The developer cannot change it.
46   - final boolean global = false;
  44 + // the default value of the global status. The developer cannot change it.
  45 + final boolean global = false;
47 46 // message
48 47 message = (String) args[ 0 ];
49 48 // choices & values
50 49 Scriptable stringArray = (Scriptable) args[ 1 ];
51 50 int count = stringArray.getElementCount();
52 51 buttons = new String[ count ];
53   - values = new int[ count ];
54 52 for( int i = 0; i < count; i++ ) {
55 53 buttons[ i ] = stringArray.getElement( i ).toString();
56   - values[ i ] = i;
57 54 }
58 55
59   - Runnable dr = DialogRunnableFactory.getCustomAskRunnable(message, buttons, values, defaultChoice, global, callback);
  56 + Runnable dr = DialogRunnableFactory.getCustomAskRunnable( message, buttons, defaultChoice, global, callback );
60 57 // queue
61   - UiApplication.getUiApplication().invokeLater(dr);
  58 + UiApplication.getUiApplication().invokeLater( dr );
62 59 // return value
63 60 return Scriptable.UNDEFINED;
64 61 }
@@ -75,7 +72,7 @@ public Object execute( Object thiz, Object[] args ) throws Exception {
75 72 fs.addParam( Scriptable.class, true );
76 73 // callback
77 74 fs.addParam( ScriptableFunction.class, true );
78   - // filler
  75 + // filler
79 76 fs.addParam( Object.class, false );
80 77 return new FunctionSignature[] { fs };
81 78 }
21 api/dialog/src/main/java/blackberry/ui/dialog/DialogRunnableFactory.java
@@ -82,9 +82,9 @@ public static Runnable getSelectRunnable(boolean allowMultiple, String[] labels,
82 82 * @param callback the callback function
83 83 * @return the Runnable responsible for opening the dialog
84 84 */
85   - public static Runnable getCustomAskRunnable(String message, String[] buttons, int[] values, int defaultChoice, boolean global /* style, false */, ScriptableFunction callback) {
86   - Dialog d = new Dialog( message, buttons, values, defaultChoice, null /* bitmap */, global ? Dialog.GLOBAL_STATUS : 0 /* style */);
87   - return new DialogAsyncRunnable(d, callback);
  85 + public static Runnable getCustomAskRunnable(String message, String[] buttons, int defaultChoice, boolean global /* style, false */, ScriptableFunction callback) {
  86 + Dialog d = new Dialog( message, buttons, null, defaultChoice, null /* bitmap */, global ? Dialog.GLOBAL_STATUS : 0 /* style */);
  87 + return new DialogAsyncRunnable( d, callback );
88 88 }
89 89
90 90 /**
@@ -177,20 +177,19 @@ public void run() {
177 177 _callback = callback;
178 178 }
179 179
180   -
181 180 /**
182 181 * Run the dialog.
183 182 *
184 183 * @see java.lang.Runnable#run()
185 184 */
186   - public void run() {
187   - _dialogValue = new Integer(_dialog.doModal());
188   - //get object's string as all ecma primitives will return a valid string representation of themselves
189   - Object retVal = _dialogValue.toString();
  185 + public void run() {
  186 + _dialogValue = new Integer( _dialog.doModal() );
  187 + // get object's string as all ecma primitives will return a valid string representation of themselves
  188 + Object retVal = _dialogValue.toString();
190 189 try {
191   - _callback.invoke(null, new Object[] { retVal });
192   - } catch (Exception e) {
193   - throw new RuntimeException("Invoke callback failed: " + e.getMessage());
  190 + _callback.invoke( null, new Object[] { retVal } );
  191 + } catch( Exception e ) {
  192 + throw new RuntimeException( "Invoke callback failed: " + e.getMessage() );
194 193 }
195 194 }
196 195 }

1 comment on commit 53cedc8

Sergey Golod

Code review complete.

Please sign in to comment.
Something went wrong with that request. Please try again.