160 likes | 296 Views
Cosc 5/4755. Blackberry dialogs. Dialogs. Dialogs can range from information with an OK button (like in bb helloworld example) To very complex. Status message. A built method is a the Status Subclass of PopupScreen that we see later in the lecture Code:
E N D
Cosc 5/4755 Blackberry dialogs
Dialogs • Dialogs can range from information with an OK button (like in bb helloworld example) • To very complex
Status message. • A built method is a the Status • Subclass of PopupScreen that we see later in the lecture • Code: • Status.show(“This is a status message.”); • You can also choose you own Bitmap and as well time • show(String message, int time) • show(String message, Bitmap bitmap, int time)
Dialog class • The Dialog class also provides a simple method to display information • Dialog.alert(“Goodbye!”); • For predefined dialog use • Dialog.alert(String) or Dialog.inform(String) • Dialog.ask(int), which has a return value.
Dialog.ask • Dialog.ask(int) and Dialog.ask(int, String) • Use Dialog. Constants to change the dialog prefined set • D_DELETE • Standard delete confirmation dialog. • D_OK • Standard OK dialog. • D_OK_CANCEL • Standard OK/Cancel confirmation dialog. • D_SAVE • Standard save prompt dialog. • D_YES_NO • Standard Yes/No confirmation dialog. • Intval = Dialog.ask(Dialog.D_YES_NO, “Exit?”);
Dialog.ask (2) • Return values • Dialog.CANCEL, DELETE, DISCARD, NO, OK, SAVE, YES • Note: CANCEL and NO have the same Behaviour
Custom Dialogs • To create custom dialogs • Use the constructor • Dialog(String message, Object[] choices, int[] values, intdefaultChoice, Bitmap bitmap) • Add a listener and use the show() method. • Example: String choices[] = { "Next Level", "Quit" }; intvalues[] = { 1, 2, Dialog.CANCEL }; Dialog d = new Dialog("Winner!", choices, values, 1, null); • values will be the value that is returned for the choice picked. d.setDialogClosedListener(new myDialoglistener() ); d.show();
Custom Dialogs (2) • Listener then looks something like this: class myDialoglistener implements DialogClosedListener { public void dialogClosed(Dialog dialog, int choice) { if (choice == 1) { //next level ; } else if (choice == 2) { //quit close(); } else if (choice == Dialog.CANCEL){ //The dialog box was canceled, no value selected close(); } } }
Custom Dialogs and Threads • If you launch a Dialog from a separate thread, then you will need to get an Event lock to allow it to display • Otherwise, the app will likely crash. synchronized (UiApplication.getEventLock()) { d.show(); }
PopupScreen • Screen providing features for building dialog and status screens. • Dialog is a subclass • And PopupScreen is sublcass of screen. So most of the methods of screen are avialable to use. • Add Fields to the layout managers in the constructor
PopupScreen (2) • When we are ready to display the Popup use • UiApplication.getUiApplication().pushModalScreen( myPopupScreen); • This pushes on the screen stack and Model screen. • The code the pushed the screen is stopped and waits for the PopupScreen to finish. • So we can then capture the information from the PopupScreen without the need for a listner.
Custom Spinner Popup • The constructor creates the fields for the label and TextSpinnerBoxField • OS v5+ required here. • Add a couple of methods so we can retrieve the data • getChoice() • Which returns the value from the spinner • isSet() return true if the value is set
Custom Spinner Popup (2) • Since we only have one field, we can also override the invokeActionmethod. • When a value for the spinner is selected, then invokeAction will be call. • invokeAction will set the value and then close the window. • Take a look at the code associated with this lecture for more detail.
Settings screen • Using the PopupScreen we can create a custom settings screen as a dialog box. • The code itself is very simple • Create all the fields • a booleanisset variable • And listener for the buttons • The buttons close the screen. A note, these fields and layouts are using Blackberry’s custom fields from the webcast. See the handouts for the entire custom field slides and code.
Settings screen (2) • Like spinner popup • The main code pushModalScreen and retrieves the values once the screen closes. • Again, take a look at the code associated with this lecture for more detail.
Q A &