This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

UI Annotations

UI Annotations

    Another form of annotation that exists in iiziGo is the UI Annotation. To access any of the UI Component Events in your Java code you must first set the Events property on the component’s Panel. A UI Annotation will be added to your Java class. Then you can set a Java method to respond to any of the familiar UI events by assigning a value to a component’s UI event. A UI Annotation will be added to your Java Method.

    Creating or selecting Java methods through a component’s Events property

    In the following example, we will add a Java method to the UI Event, OnUICreate; our method will lock the mobile device orientation when the Panel is created. A Java method and its annotation are automatically created when adding a method to a UI Event in the Panel’s Property Editor. With the Panel selected in the Property Editor, the Property Editor displays the Events section in which you can choose from the UI Events listed above. By clicking the more button to the right of the OnUICreate property, you can create a new Java method – with the correct annotation – that will be called when your Panel is created. And by doing the same when it is destroyed. Notice that the client session is accessed on the event by a reference to the IIZI Client Gyro.

    Creating classes in the panel’s property editor

    Common UI Events

    OnUICreateOnUIValueChange
    OnUIDestroyOnUIAction
    OnUIConnectOnUISelection
    OnUIBackOnUITextChange
    OnUIFocus
    Creating or selecting Java methods through a component’s Events property

    In the following example, we will add a Java method to the UI Event, OnUICreate; our method will lock the mobile device orientation when the Panel is created. A Java method and its annotation are automatically created when adding a method to a UI Event in the Panel’s Property Editor. With the Panel selected in the Property Editor, the Property Editor displays the Events section in which you can choose from the UI Events listed above. By clicking the more button to the right of the OnUICreate property, you can create a new Java method – with the correct annotation – that will be called when your Panel is created. And by doing the same when it is destroyed. Notice that the client session is accessed on the event by a reference to the IIZI Client Gyro.

    A Java methods for locking screen orientation triggered by the UI events

    /***
    * Auto-generated OnUICreate for panel or its components.
    */
    @OnUICreate(name="nameOfPanel")
    public void onUICreate (UICreateEvent event) {
      ScreenOrientation lockPortrait = ScreenOrientation.portrait;
      event.getClientSessionGyro().setScreenOrientation(lockPortrait);
    }
    /***
    * Auto-generated OnUICreate for panel or its components.
    */
    @OnUIDestroy(name="nameOfPanel")
    public void onUIDestroy (UIDestroyEvent event) {
      virtualSpace.getClientSessionGyro().unlockScreenOrientation();
    }