1 / 16

Cosc 5/4755

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:

marva
Download Presentation

Cosc 5/4755

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Cosc 5/4755 Blackberry dialogs

  2. Dialogs • Dialogs can range from information with an OK button (like in bb helloworld example) • To very complex

  3. 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)

  4. 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.

  5. 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?”);

  6. Dialog.ask (2) • Return values • Dialog.CANCEL, DELETE, DISCARD, NO, OK, SAVE, YES • Note: CANCEL and NO have the same Behaviour

  7. 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();

  8. 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(); } } }

  9. 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(); }

  10. 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

  11. 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.

  12. 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

  13. 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.

  14. 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.

  15. 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.

  16. Q A &

More Related