Dialog

Your SmartEyeglass app can use dialogs to display text to users. The SmartEyeglassControlUtils class defines different types of dialogs that are convenient for informing your users of choices, events, or warnings.

The basics

To start working with dialogs, set up a project using the SampleDialogExtension; see more about creating SmartEyeglass projects in the How to create your first SmartEyeglass project tutorial. In your class that extends ControlExtension, instantiate SmartEyeglassControlUtils and call methods in the Dialog API.

Dialog types

Choose a dialog type suitable for the app context in which you use it. You can choose one of the predefined types, or define your own custom type.

Dialog with timeout

Dialog with timeouts are useful for notifications that do not require user interaction or approval. This type of dialog only contains text and displays for five seconds. This behavior is modeled on Android Toasts.

Dialog with timeout.

Dialog with timeout.

This dialog closes on its own. When it closes, the onDialogClosed method returns a result code of -1 to your SmartEyeglassEventListener callback, indicating that the dialog was not closed by a button press.

OK dialog

Use this dialog when you need to get acknowledgements from the user. This type of dialog contains text and an “OK” button; it does not have a title line.

Dialog with OK button.

Dialog with OK button.

This dialog does not time out; the user must close it. When it closes, the onDialogClosed method returns a result code of 0 to your SmartEyeglassEventListener callback, indicating that the dialog was closed by the user pressing button 0 (the index of the single button).

Custom dialog

You can define a custom dialog to present choices to the user. This type of dialog contains a title, message text, and one to three buttons, whose labels you define.

You can also define multi-button dialogs to act as menus. For more information, see the code example below.

Dialog with a title, message, and three buttons.

Dialog with a title, message, and three buttons.

A custom dialog does not time out; the user must close it by pressing one of the buttons. When it closes, the onDialogClosed method returns a result code to your SmartEyeglassEventListener callback, indicating which button the user pressed. The code is a 0-based index into the button array that you define.

How to display a dialog

To get started adding dialogs to your app, see the SampleDialogExtension in the SmartEyeglass SDK. This is the basic procedure.

  1. Create a class (such as SampleDialogControl) which extends the ControlExtension class of the SmartExtensionUtils library and instantiates a SmartEyeglassControlUtils member.
    class SampleDialogControl extends ControlExtension {
      	  private final SmartEyeglassControlUtils mSmartEyeglassControlUtils;
    
  2. Create a listener for the SmartEyeglass device, and define a handler for the onDialogClosed event, which returns the result when the dialog closes. For a dialog with several buttons, this handler will execute the chosen action.
    private final SmartEyeglassEventListener mSmartEyeglassEventListener =
    new SmartEyeglassEventListener() {
        @Override
        public void onDialogClosed(int code) {
            mDialogClosed = true;
            //Do something when the dialog closes.
            . . .
    
        }
    };
    
  3. In the constructor method, initialize the SmartEyeglassControlUtils member with your listener, than create the display elements and event handlers.
    SampleDialogControl (final String hostAppPackageName, final Context context) {
        super(context, hostAppPackageName);
        this.mSmartEyeglassControlUtils =
    new SmartEyeglassControlUtils (context, hostAppPackageName,
    	mSmartEyeglassEventListener);
        // Create something
        . . .
    }
    
  4. To show a timeout or OK dialog, call the showDialogMessage() utility method:
    SmartEyeglassControlUtils.showDialogMessage(final String text, final int mode)
    

    The mode is an intent constant for the dialog type.

    • To show a text dialog with a 5-sec timeout, use
      SmartEyeglassControl.Intents.DIALOG_MODE_TIMEOUT.
    • To display a dialog with just the text and OK button, use
      SmartEyeglassControl.Intents.DIALOG_MODE_OK.
    These dialogs have the same text but different modes.

    These dialogs have the same text but different modes.

  5. To create and show a custom dialog, use this form of the showDialogMessage() utility method:
    SmartEyeglassControlUtils.showDialogMessage (final String title,
    final String message,
    final String[] buttons)
    

    A custom dialog with three buttons.

    A custom dialog with three buttons.

    The buttons parameter is a String array of button IDs. Your onDialogClosed handler receives a zero-based index into this array which indicates which button the user pressed to dismiss the dialog.

Learn from the code example

For the full code example of how to define and use dialogs, see the SampleDialogExtension project in the /samples folder of the SmartEyeglass SDK.

Comments 0

Sort by:

Showing 0 of 0 comments. Show all comments