Skip to content

Level Control

RealWearDevBot edited this page Aug 28, 2020 · 1 revision

Description

Level Control is a stylized RealWear control that allows the user to chose a value from a short list of values displayed in a level scale. There is a title view at the top which informs the user of what voice command to use, and a series of numbers below which indicate the different levels available for selection.

Example

https://github.com/realwear/UXLibrary-Example/blob/master/app/src/main/java/com/realwear/uxlibrary_example/levelcontrolexample/LevelControlExampleActivity.kt

Usage

Level Control can be created in an XML layout file or programmatically.

<com.realwear.ux.view.LevelControl
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

or

val levelControl = LevelControl(context)

The following parameters can be set to configure the level control component:

  • min: the minimum level number.
  • max: the maximum level number.
  • value: the currently selected level number.
  • positiveVoiceCommand: the voice command to be used for positive integer levels. The string format must take an integer value (%d).
  • negativeVoiceCommand: the voice command to be used for negative integer levels. The string format must take an integer value (%d).
  • zeroVoiceCommand: the voice command to be used for level 0. The string format must take an integer value (%d).
  • title: the title of the level control and also the hint given to the user about what voice command to use. Ex) “Set Volume” as the title for level control with voice commands “Set Volume 1”, “Set Volume 2”, etc.
<com.realwear.ux.view.LevelControl
    app:level_command_negative="Level Minus %d"
    app:level_command_positive="Level %d"
    app:level_command_zero="Level %d"
    app:max="3"
    app:min="-2"
    app:title="Level"
    app:value="0" />

or

level_control.min = 10
level_control.max = 20
level_control.value = 15
level_control.positiveVoiceCommand = "Level %d"
level_control.negativeVoiceCommand = "Level Minus %d"
level_control.zeroVoiceCommand = "Level %d"
level_control.title = "Level"

An OnLevelChangedListener can be set on this component that will listen for any changes to the selected level. The callback, onLevelChanged(), can be overridden by the user to determine what behavior to implement when a level is changed. The callback supplies the new selected level integer as a parameter.

level_control.onLevelChangedListener = object : OnLevelChangedListener {
    override fun onLevelChanged(newLevel: Int) {
        Log.i(TAG, "New level: $newLevel")
    }
}

Clone this wiki locally