Class VoiceCommandDispatcher.Builder¶
- java.lang.Object
-
- com.iristick.smartglass.core.VoiceCommandDispatcher.Builder
- Enclosing interface:
- VoiceCommandDispatcher
public abstract static class VoiceCommandDispatcher.Builder extends Object
This class allows to construct immutable voice command dispatcher objects.
To obtain a builder instance, use the create()
method.
Builder instances are single-use only. Any attempt to further modify the builder after
build()
has built a voice command dispatcher object will result in an
IllegalStateException
.
Constructor Summary¶
Constructor and Description |
---|
Builder() |
Method Summary¶
Modifier and Type | Method and Description |
---|---|
abstract VoiceCommandDispatcher.Builder |
add(int command,
Runnable callback)
Associate the given
callback with the given command . |
abstract VoiceCommandDispatcher.Builder |
add(String command,
Runnable callback)
Associate the given
callback with the given command . |
abstract VoiceCommandDispatcher |
build()
Builds the voice command dispatcher for all the commands and callbacks accumulated so far.
|
static VoiceCommandDispatcher.Builder |
create()
Creates a new empty builder instance.
|
static VoiceCommandDispatcher.Builder |
create(Context context)
Creates a new empty builder instance.
|
abstract VoiceCommandDispatcher.Builder |
setHandler(Handler handler)
Sets the handler on which callbacks are invoked.
|
Methods inherited from class java.lang.Object¶
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Constructor Detail¶
Builder¶
public Builder()
Method Detail¶
create¶
@NonNull @CheckResult public static VoiceCommandDispatcher.Builder create()
- Returns:
- A new builder instance for building VoiceCommandDispatcher objects.
create¶
@NonNull @CheckResult public static VoiceCommandDispatcher.Builder create(@Nullable Context context)
- Parameters:
context
- Context object. If notnull
, this builder supports theadd(int, Runnable)
convenience method.- Returns:
- A new builder instance for building VoiceGrammar objects.
add¶
@NonNull public abstract VoiceCommandDispatcher.Builder add(@NonNull String command, @NonNull Runnable callback)
callback
with the given command
.
You may call this method multiple times to configure multiple callbacks for the same command. It is also possible to reuse the same callback for multiple commands.
Actions for the same voice command are executed in the order they were added.
- Parameters:
command
- The voice command that triggers the action.callback
- This callback is invoked when the voice command is recognized.- Returns:
- This instance for method chaining.
- Throws:
IllegalStateException
- if a VoiceCommandDispatcher was already built from this builder.
add¶
@NonNull public abstract VoiceCommandDispatcher.Builder add(@StringRes int command, @NonNull Runnable callback)
callback
with the given command
.
You may call this method multiple times to configure multiple callbacks for the same command. It is also possible to reuse the same callback for multiple commands.
Actions for the same voice command are executed in the order they were added.
- Parameters:
command
- The voice command that triggers the action.callback
- This callback is invoked when the voice command is recognized.- Returns:
- This instance for method chaining.
- Throws:
IllegalStateException
- if a VoiceCommandDispatcher was already built from this builder.UnsupportedOperationException
- if the builder was initialized without valid context.- See Also:
create(Context)
setHandler¶
@NonNull public abstract VoiceCommandDispatcher.Builder setHandler(@Nullable Handler handler)
- Parameters:
handler
- Handler on which callbacks are invoked. Ifnull
, callbacks are executed on the main thread.- Returns:
- This instance for method chaining.
- Throws:
IllegalStateException
- if a VoiceCommandDispatcher was already built from this builder.
build¶
@NonNull @CheckResult public abstract VoiceCommandDispatcher build()
- Returns:
- A finished voice command dispatcher.
- Throws:
IllegalStateException
- if no commands have been registered.IllegalStateException
- if a VoiceCommandDispatcher was already built from this builder.- See Also:
Headset.startVoice(VoiceGrammar)