SamStenner / WearML

A WearML wrapper for Android to be used with Realwear HMT devices

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WearML Wrapper for Android

A lightweight library that provides programmatic access to WearML funcitonality for Realwear HMT devices.

(Please note this project is not officially associated with Realwear Inc)

Installation

In your project's build.gradle include the following under the repositories section:

maven { url "https://jitpack.io" }

In your app's build.gradle include the following under the dependency section:

implementation 'com.github.SamStenner:WearML:1.0.0'

Code Example

In your activity, include the following line in your OnCreate method:

WearML.init(this)

To register a command use:

WearML.register("Hello World") {
    Log.d("WearML", "Hello World") // Prints: WearML: Hello World
}

To register a command with multiple activation words use:

WearML.register("Hello", "Hi", "Hey", "Howdy") {
    Log.d("WearML", "Hello World") // Prints: WearML: Hello World
}

To access commands within the called functions use:

WearML.register("Hello", "Hi", "Hey", "Howdy") { words ->
    val hey = words[2]
    Log.d("WearML", hey) // Prints: WearML: Hey
}

To maintain a reference to the registered command use:

val helloCommand = WearML.register("Hello World") {
    Log.d("WearML", "Hello World") // Prints: WearML: Hello World
}

To unregister a command use:

WearML.unregister(helloCommand)

To unregister all commands use:

WearML.unregisterAll()

To register a command with extra directives use:

val directives = mutableListOf<WearML.Directives>().apply {
    add(WearML.Directives.NO_GLOBAL_COMMANDS)
    add(WearML.Directives.NO_PTT_HOME)
}

WearML.register("Hello", extraDirectives= directives) {
    Log.d("WearML", "Hello World") // Prints: WearML: Hello World
}

Note: Directives that have an instant effect will be applied immediately, not when the command is invoked. Further information about directives can be found here.

Further information

You can also register commands within a fragment, although it is advised that you unregister those commands when the fragment is destroyed, or else those commands will persist to other fragments.
This would cause your commands to be available in parts of your application that you don't intend, and invoking them could cause a crash. Furthermore, revisitng the fragment would duplicate the command.
It is therefore recommended that you keep a list of registered commands in your fragment, and unregister each command in your fragment's onDestroy method.
If you don't register any commands in your activity and do so exclusively in your fragments, you can use unregisterAll in your onDestroy method as no other commands are at risk of being removed.

About

A WearML wrapper for Android to be used with Realwear HMT devices

License:Apache License 2.0


Languages

Language:Kotlin 100.0%