Skip to content

3.1 Events

This Core Library provides several events that are triggered by the NIMMSTA Smart Watch. In this section, we will describe the most important ones.

Scan Event

The most important event for a barcode scanner is the ScanEvent. The ScanEvent provides the barcode that was scanned.

In a future release, we will also provide information about the barcode type to the user. This can be currently tested as pre-release. Please ask one of the developers about this.

Note

If you want to learn more about barcode encodings, have a look at the section under "Advanced Topics".

class ExampleEventHandler: NIMMSTAEventHandler {

    override fun didScanBarcode(
        device: NIMMSTADevice,
        barcode: Barcode,
        event: ScanEvent
    ) {
        // handle the scanned barcode
    }
}
class ExampleEventHandler implements NIMMSTAEventHandler {

    @Override
    public void didScanBarcode(
        @NotNull NIMMSTADevice nimmstaDevice,
        @NotNull Barcode barcode,
        @NotNull ScanEvent scanEvent
    ) {
        // handle the scanned barcode
    }
}

Button Click Event

A ButtonClickEvent is fired once a Button was clicked.

The sender of the event will be the button object.

Note

The name of the button in this example corresponds to the attribute "name" of the button in the layout.

class ExampleEventHandler: NIMMSTAEventHandler {

    override fun didClickButton(
        device: NIMMSTADevice,
        sender: Button?,
        event: ButtonClickEvent
    ) {
        if (sender?.name == "next_task") {
            // go to next task
        }
    }
}
class ExampleEventHandler implements NIMMSTAEventHandler {

    @Override
    public void didClickButton(
        @NotNull NIMMSTADevice nimmstaDevice,
        @Nullable Button button,
        @NotNull ButtonClickEvent buttonClickEvent
    ) {
        if (button != null) {
            if (Objects.equals(button.getName(), "next_task")) {
                // go to next task
            }
        }
    }
}

Touch Event

A TouchEvent represents a single tap on the screen of the NIMMSTA Smart Watch. At the moment, every touch leads to a TouchEvent.

class ExampleEventHandler: NIMMSTAEventHandler {

    override fun didTouch(
        device: NIMMSTADevice,
        x: Int,
        y: Int,
        screen: Int,
        event: TouchEvent
    ) {
        // handle touch
    }
}
class ExampleEventHandler implements NIMMSTAEventHandler {

    @Override
    public void didTouch(
        @NotNull NIMMSTADevice nimmstaDevice,
        double x,
        double y,
        int screen,
        @NotNull TouchEvent touchEvent
    ) {
        // handle touch
    }
}

Battery Level Changed Event

A Battery Level Changed Event is fired if the battery level of the scanner changes.

class ExampleEventHandler: NIMMSTAEventHandler {

    override fun batteryLevelChanged(
        device: NIMMSTADevice,
        newBatteryLevel: Int
    ) {
        // handle new battery level
    }
}
class ExampleEventHandler implements NIMMSTAEventHandler {

    @Override
    public void batteryLevelChanged(
        NIMMSTADevice nimmstaDevice,
        int newBatteryLevel
    ) {
        // handle new battery level
    }
}

Start Charging Event

A Start Charging Event is fired if the device is placed on the charging pad and starts charging.

class ExampleEventHandler: NIMMSTAEventHandler {

    override fun didStartCharging(device: NIMMSTADevice) {
        // handle start charging
    }
}
class ExampleEventHandler implements NIMMSTAEventHandler {

    @Override
    public void didStartCharging(
        @NotNull NIMMSTADevice nimmstaDevice
    ) {
        // handle start charging
    }
}

Stop Charging Event

A Stop Charging Event is fired if the device is removed from the charging pad and stops charging.

class ExampleEventHandler: NIMMSTAEventHandler {

    override fun didStopCharging(device: NIMMSTADevice) {
        // handle stop charging
    }
}
class ExampleEventHandler implements NIMMSTAEventHandler {

    @Override
    public void didStopCharging(
        @NotNull NIMMSTADevice nimmstaDevice
    ) {
        // handle stop charging
    }
}

Trigger Event

A Trigger Event is fired if the trigger is pressed on the device. The trigger is the button which is usually used to trigger a scan.

class ExampleEventHandler: NIMMSTAEventHandler {

    override fun didReceiveEvent(device: NIMMSTADevice) {
        when (event) {
            is TriggerEvent -> {
                // handle trigger event
            }
        }
    }
}
class ExampleEventHandler implements NIMMSTAEventHandler {

    @Override
    public void didReceiveEvent(@NotNull NIMMSTADevice nimmstaDevice, @NotNull Event event) {
        if (event instanceof TriggerEvent) {
            // handle trigger event
        }
    }
}

Double Trigger Event

A Double Trigger Event is fired if the trigger is pressed twice on the device in quick succession. The trigger is the button which is usually used to trigger a scan.

Note

Before receiving a Double Trigger Event, you will always receive a Trigger Event.

class ExampleEventHandler: NIMMSTAEventHandler {

    override fun didReceiveEvent(device: NIMMSTADevice) {
        when (event) {
            is DoubleTriggerEvent -> {
                // handle double trigger event
            }
        }
    }
}
class ExampleEventHandler implements NIMMSTAEventHandler {

    @Override
    public void didReceiveEvent(@NotNull NIMMSTADevice nimmstaDevice, @NotNull Event event) {
        if (event instanceof DoubleTriggerEvent) {
            // handle double trigger event
        }
    }
}

Triple Trigger Event

A Triple Trigger Event is fired if the trigger is pressed three times on the device in quick succession. The trigger is the button which is usually used to trigger a scan.

Note

Before receiving a Triple Trigger Event, you will always receive first a Trigger Event and then a Double Trigger Event.

class ExampleEventHandler: NIMMSTAEventHandler {

    override fun didReceiveEvent(device: NIMMSTADevice) {
        when (event) {
            is TripleTriggerEvent -> {
                // handle triple trigger event
            }
        }
    }
}
class ExampleEventHandler implements NIMMSTAEventHandler {

    @Override
    public void didReceiveEvent(@NotNull NIMMSTADevice nimmstaDevice, @NotNull Event event) {
        if (event instanceof TripleTriggerEvent) {
            // handle triple trigger event
        }
    }
}

Handling all Events

One possibility to handle all events is to use the didReceiveEvent method. There you can get all kinds of available events in one central method:

class ExampleEventHandler: NIMMSTAEventHandler {

    override fun didReceiveEvent(device: NIMMSTADevice, event: Event) {
        when(event) {
            is BatterySOCChangedEvent -> {

            }
            is TouchEvent -> {

            }
            is ChargingEvent -> {

            }
            is ButtonClickEvent -> {

            }
        }
    }
}
class ExampleEventHandler implements NIMMSTAEventHandler {
    /* ... */

    @Override
    public void didReceiveEvent(
        @NotNull NIMMSTADevice nimmstaDevice,
        @NotNull Event event
    ) {
        if (event instanceof BatterySOCChangedEvent) {

        } else if (event instanceof TouchEvent) {

        } else if (event instanceof ChargingEvent) {

        } else if (event instanceof ButtonClickEvent) {

        }
    }

    /* ... */
}