Skip to content
This repository has been archived by the owner on Sep 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #46 from blackberry-webworks/next-back-customAsk
Browse files Browse the repository at this point in the history
Pull Req: Next back custom ask
  • Loading branch information
dmateescu committed Feb 8, 2012
2 parents bd49e27 + 53cedc8 commit e491ea1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down Expand Up @@ -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() );
}
}
}
Expand Down

0 comments on commit e491ea1

Please sign in to comment.