Tutorial: Control application UI

In this tutorial you learn how to use conditions to control the application UI. You learn how to control the activation state of Activities that make up the UI by creating popup windows that an application shows only when a condition in a Data Trigger is met. In the Data Trigger you use an Apply Activation Action to activate a specific Activity.

A Data Trigger with an Apply Activation Action keeps an Activity active for as long as the condition in that Data Trigger is met.

You set the condition in a Data Trigger in the form of a binding expression that evaluates to either True or False.

This video shows the result of the tutorial.

../../_images/dt-complete1.gif

This tutorial assumes that you understand the basics of working with the Activity system. The best entry point for that is the Tutorial: Structure application UI.

Assets for the tutorial

The starting point of this tutorial is the <KanziWorkspace>/Tutorials/Data trigger/Start/Tool_project/Data trigger.kzproj Kanzi Studio project. To learn about the content of this project and how to create such a project, see Tutorial: Structure application UI.

You can find the completed tutorial in the <KanziWorkspace>/Tutorials/Data trigger/Completed directory.

The starting point project contains the assets that you need to complete this tutorial:

  • The Prefabs contains the images of UI elements that you use in this tutorial.

    ../../_images/start-prefabs1.png
  • The ActivityProperty.Cluster.MainView property type that you use to control and check the state of the cluster. In Data Triggers you use the value of this property to decide which Activity you want to activate.

    ../../_images/library-mainview.png ../../_images/properties-mainview-property1.png

Create the structure

In this section you create the structure for the popup windows.

To create the structure:

  1. In Kanzi Studio open the <KanziWorkspace>/Tutorials/Data trigger/Start/Tool_project/Data trigger.kzproj Kanzi Studio project.

  2. Create the Activity structure for the popup windows when they are maximized:

    1. In the Prefabs > MaximizedLeft prefab create a Parallel Activity Host named PopupMaximized and drag the MaximizedWidget Activity to the PopupMaximized Activity Host.

      You use a Parallel Activity Host so that you can activate more than one popup window at a time and show the popup windows on top of the currently activated widget.

      ../../_images/prefabs-maximizedleft-pah.png ../../_images/prefabs-maximizedleft-popupmaximized.png
    2. In the Activity Browser below the PopupMaximized Activity Host click add-button to add an Activity, and name it and its prefab PopupIncomingCallMaximized.

      ../../_images/create-incomingcallmaximized.png ../../_images/ab-incomingcallmaximized.png
    3. In the Prefabs drag the PopupIncomingCallMaximizedImage to the PopupIncomingCallMaximized Activity.

      ../../_images/prefabs-popupincomingcall.gif
    4. In the Activity Browser in the PopupIncomingCallMaximized Activity click activate.

      This way you simulate the activation of this Activity so that you can see its content in the Preview.

      ../../_images/ab-activate-popupincomingcallmaximized.png ../../_images/preview-popupincomingcallmaximized.png
    5. In the Prefabs select the MaximizedLeft > PopupMaximized > MaximizedWidget Activity Host and in the Properties drag the Horizontal Padding and Vertical Padding properties to the Prefabs > MaximizedLeft > PopupMaximized Activity Host.

      This way you set the padding for all Activities of the PopupMaximized Activity Host.

      ../../_images/popupmaximized-padding.gif
    6. In the Prefabs select the MaximizedWidget Activity Host and in the Properties remove the Horizontal Padding and Vertical Padding properties.

      ../../_images/prefabs-maximizedwidget1.png ../../_images/properties-maximizedwidget-remove-padding.png ../../_images/preview-popupmaximized-positioned.png
  3. Create the Activity structure for the popups when they are minimized:

    1. In the Prefabs > MinimizedLeft prefab create a Parallel Activity Host named PopupMinimized and drag the MinimizedWidget Activity to the PopupMinimized Activity Host.

      ../../_images/prefabs-minimizedleft-popupminimized.png
    2. In the Activity Browser in the PopupMinimized Activity Host add an Activity and name it and its prefab PopupIncomingCallMinimized.

      ../../_images/create-incomingcallminimized.png ../../_images/ab-incomingcallminimized.png
    3. In the Prefabs drag the PopupIncomingCallMinimizedImage to the PopupIncomingCallMinimized Activity.

      ../../_images/prefabs-popupincomingcallminimized.png
    4. In the Activity Browser in the PopupIncomingCallMinimized Activity click activate.

      This way you simulate the activation of this Activity so that you can see its content in the Preview.

      ../../_images/ab-activate-popupincomingcallminimized.png ../../_images/preview-popupincomingcallminimized.png
    5. In the Prefabs select the MinimizedLeft > PopupMinimized > MinimizedWidget Activity Host and from the Properties drag the Horizontal Padding and Vertical Padding properties to the Prefabs > MinimizedLeft > PopupMinimized Activity Host.

      ../../_images/prefabs-minimizedleft-popupminimized.png ../../_images/properties-popupminimized.png
    6. In the Prefabs select the MinimizedWidget Activity Host and in the Properties remove the Horizontal Padding and Vertical Padding properties.

      ../../_images/prefabs-minimizedwidget1.png ../../_images/properties-minimizedwidget-remove-padding.png ../../_images/preview-popupminimized-positioned.png

Use conditions to control the activation state of Activities

In this section you learn how to use a Data Trigger with an Apply Activation Action to control the activation state of an Activity when a condition in that Data Trigger is met.

To use conditions to control the activation state of Activities:

  1. Create a property type that you use to set the state of an Activity:

    1. In the Library > Property Types > ActivityProperty press Alt and right-click, select Property Type, and in the New Property Type window set:

      • Name to ActivityProperty.IncomingCall

      • Category to Controller Properties

      • Data Type to Boolean

      ../../_images/library-incomingcall.png ../../_images/incomingcall-property.png
    2. In the Node Tree select the Cluster node and in the Properties add the Controller Properties > ActivityProperty.IncomingCall property.

      You add the ActivityProperty.IncomingCall property to the Cluster Activity Host because you want to control the activation state of the IncomingCall Activities from this node.

      ../../_images/node-tree-root-pah1.png ../../_images/properties-cluster1.png
  2. Create a Data Trigger that controls the activation state of an Activity based on a condition:

    1. In the Node Tree select the Cluster node, in the Node Components press Alt and right-click Triggers, select Data Trigger, and name it PopupIncomingCallMaximized.

      ../../_images/apply-activation-create-data-trigger1.png ../../_images/node-components-popupincomingcallmaximized.png
    2. In the Data Trigger in the Condition Expression click expression-open, select the Properties window, drag the ActivityProperty.Cluster.MainView and ActivityProperty.IncomingCall properties to the Expression field, and edit the expression to

      {@./ActivityProperty.Cluster.MainView}==0 && {@./ActivityProperty.IncomingCall}==true
      

      A condition expression in a Data Trigger must evaluate to either True or False.

      Click Save.

      This way you set the Data Trigger to keep an Apply Action in that Data Trigger applied only when the ActivityProperty.Cluster.MainView is set to Drive (enumeration value 0) and the ActivityProperty.IncomingCall is enabled (Boolean value True). You add an Apply Activation Action in the next step.

      ../../_images/expression-mainview-incomingcall.png
  3. Create an Apply Activation Action that activates and deactivates an Activity:

    1. In the PopupIncomingCallMaximized Data Trigger press Alt and right-click Actions, and select Apply Activation Action.

      ../../_images/popupincomingcallmaximized-create-apply-activation-action.png ../../_images/popupincomingcallmaximized-apply-activation-action.png
    2. In the Activity Browser right-click the PopupIncomingCallMaximized Activity and select Copy Activation path.

      ../../_images/popupincomingcallmaximized-copy-activation-path.png
    3. In the Node Components in the Apply Activation Action set:

      • Activity Host Path to < Relative > and .

      • Activity Activation Path paste the path that you copied from the Activity Browser and from the beginning of the path remove Cluster/

      The path to the Activity that you set in the Activity Activation Path property is relative to the Activity Host node that you set in the Activity Host Path property.

      The Data Trigger and Apply Activation Action keep this Activity active for as long as the condition in the Data Trigger is met.

      The Activity Browser indicates that an Activity Host has a Data Trigger with the data-trigger icon.

      ../../_images/popupincomingcallmaximized-dt-set.png ../../_images/ab-cluster-w-dt.png
  4. Set the Cluster Activity Host to activate the PopupIncomingCallMinimized Activity when the Cluster is in Browse mode and the ActivityProperty.IncomingCall is enabled:

    1. In the Node Components right-click the PopupIncomingCallMaximized Data Trigger, select Duplicate, and rename the Data Trigger to PopupIncomingCallMinimized.

      ../../_images/popupincomingcallmaximized-duplicate.png ../../_images/popupincomingcallminimized-dt.png
    2. In the Condition Expression edit the expression to

      {@./ActivityProperty.Cluster.MainView}==1 && {@./ActivityProperty.IncomingCall}==true
      

      Click Apply.

      ../../_images/popupincomingcallminimized-expression.png
    3. In the Activity Browser right-click the PopupIncomingCallMinimized Activity, select Copy Activation path, in the PopupIncomingCallMinimized Data Trigger Apply Activation Action paste the path, and from the beginning of the path remove Cluster/.

      ../../_images/popupincomingcallminimized-copy-activation-path.png ../../_images/popupincomingcallminimized-dt-set.png

Tip

During the application development, use these Data Trigger tools in the Activity Browser side panel:

Tool

Description

../../_images/show-data-trigger-icon.png

Shows where a Data Trigger is and where the source and target Activity nodes of that Data Trigger are.

../../_images/apply-data-trigger-icon.png

Simulates the state when you apply a Data Trigger.

This enables you to see the state of your application when the conditions for a Data Trigger are met without having to change the property values in your application.

../../_images/data-trigger-node-components-icon.png

Shows a Data Trigger in the Node Components window.

../../_images/ab-helpers.png

Now when you select in the Activity Browser the Cluster node you can in the side panel switch between the Drive and Browse modes, and use the IncomingCall property to control in both modes whether the Cluster shows the notification for an incoming call.

../../_images/popupincomingcallmaximized.gif

Create additional popup windows

To create popup windows for a new message notification and control that notification with a Data Trigger, repeat the procedures above with these differences:

  1. In the Activity Browser add these Activities:

    • In the PopupMaximized add an Activity named PopupNewMessageMaximized whose prefab uses the PopupNewMessageMaximizedImage.

      ../../_images/ab-popupnewmessagemaximized.png
    • In the PopupMinimized add an Activity named PopupNewMessageMinimized whose prefab uses the PopupNewMessageMinimizedImage.

      ../../_images/ab-popupnewmessageminimized.png
    ../../_images/prefabs-popupnewmessage.png
  2. To control the activation state, create a controller Boolean property type called ActivityProperty.NewMessage and add it to the Cluster Activity Host.

    ../../_images/properties-newmessage.png ../../_images/properties-newmessage-bool.png ../../_images/node-tree-root-pah1.png ../../_images/properties-cluster-newmessage.png
  3. In the Cluster Activity Host in the Node Components duplicate the PopupIncomingCallMaximized Data Trigger, rename it to PopupNewMessageMaximized and set:

    • Expression to

      {@./ActivityProperty.Cluster.MainView}==0 && {@./ActivityProperty.NewMessage}==true
      

      Click Apply.

    • In the Apply Activation Action the Activity Activation Path property to the activation path of the PopupNewMessageMaximized Activity.

    ../../_images/node-components-popupnewmessagemaximized.png
  4. In the Cluster Activity Host in the Node Components duplicate the PopupNewMessageMaximized Data Trigger, rename it to PopupNewMessageMinimized and set:

    • Condition Expression to

      {@./ActivityProperty.Cluster.MainView}==1 && {@./ActivityProperty.NewMessage}==true
      

      Click Apply.

    • In the Apply Activation Action the Activity Activation Path property to the activation path of the PopupNewMessageMinimized Activity.

    ../../_images/node-components-popupnewmessageminimized.png

See also

To learn more about the Activity system, see Activities.