Class IristickApp¶
- java.lang.Object
-
- com.iristick.smartglass.support.app.IristickApp
public class IristickApp extends Object
The support library must be initialized by calling the init(Application)
static method
in the Application.onCreate()
method of the application subclass. This should be done
before any other method of this class is used.
All activities should wrap their context with wrapContext(Context)
. This can be done
by including the following code in all activities (or once in a base Activity
subclass
that is inherited by all other activities):
protected void attachBaseContext(Context newBase) { super.attachBaseContext(IristickApp.wrapContext(newBase)); }
Activities that do not want the main screen to be cloned to the heads-up display, but instead
manage the heads-up display and touchpad interaction themselves, shall implement the
HudActivity
interface.
Long-running components that are not linked to an activity lifecycle, such as services, that
want to be notified of headset (dis)connections, can register a IristickConnection
or
IristickConnection2
listener with the registerConnectionListener(com.iristick.smartglass.core.IristickConnection, android.os.Handler)
method.
It is strongly recommended not to use IristickManager.bind(com.iristick.smartglass.core.IristickConnection, android.content.Context, android.os.Handler)
when using the app
support library to preserve resources.
Method Summary¶
Modifier and Type | Method and Description |
---|---|
static IristickBinding |
getBinding()
Get the Iristick service binding object.
|
static Headset |
getHeadset()
Get the connected Iristick headset.
|
static int |
getInteractionMode()
Get the current interaction mode of the attached headset.
|
static PocketUnit |
getPocketUnit()
Get the connected Iristick pocket unit.
|
static void |
init(Application application)
Initialize the Iristick app support library with the default configuration.
|
static void |
init(Application application,
IristickConfiguration configuration)
Initialize the Iristick app support library with custom configuration.
|
static boolean |
isInitialized()
Check whether the Iristick app support library has been initialized.
|
static void |
registerConnectionListener(IristickConnection listener,
Handler handler)
Register a listener that gets notified of headset connections and disconnections.
|
static void |
setInteractionRules(List<InteractionRule> rules)
Configure interaction behavior when using Iristick smart glasses to navigate through views.
|
static void |
startVoice(VoiceGrammar grammar)
Starts listening for voice commands for the given grammar.
|
static void |
stopVoice(VoiceGrammar grammar)
Stop listening for voice commands for the given grammar.
|
static void |
unregisterConnectionListener(IristickConnection listener)
Unregisters a connection listener.
|
static Context |
wrapContext(Context base)
Adapt base context according to the currently attached headset and interaction mode.
|
Methods inherited from class java.lang.Object¶
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Method Detail¶
init¶
public static void init(@NonNull Application application)
This method (or a variant) must be called from Application.onCreate()
.
- Parameters:
application
- The Android application instance.
init¶
public static void init(@NonNull Application application, @NonNull IristickConfiguration configuration)
This method (or a variant) must be called from Application.onCreate()
.
- Parameters:
application
- The Android application instance.configuration
- The custom library configuration.
isInitialized¶
@CheckResult public static boolean isInitialized()
- Returns:
true
if the Iristick app support library has been initialized,false
otherwise.- See Also:
init(Application)
,init(Application, IristickConfiguration)
getBinding¶
@CheckResult @Nullable public static IristickBinding getBinding()
- Returns:
- The Iristick service binding object or
null
if the service is not initialized. - Throws:
IllegalStateException
- ifinit(android.app.Application)
has not been called.
getPocketUnit¶
@CheckResult @Nullable public static PocketUnit getPocketUnit()
- Returns:
- The connected pocket unit or
null
if no pocket unit is attached. - Throws:
IllegalStateException
- ifinit(android.app.Application)
has not been called.
getHeadset¶
@CheckResult @Nullable public static Headset getHeadset()
- Returns:
- The connected headset or
null
if no headset attached. - Throws:
IllegalStateException
- ifinit(android.app.Application)
has not been called.
getInteractionMode¶
@CheckResult public static int getInteractionMode()
Headset.INTERACTION_MODE_PHONE
will be returned.- Returns:
- The current interaction mode.
- Throws:
IllegalStateException
- ifinit(android.app.Application)
has not been called.- See Also:
Headset.INTERACTION_MODE_PHONE
,Headset.INTERACTION_MODE_HUD
wrapContext¶
@CheckResult @NonNull public static Context wrapContext(@NonNull Context base)
This method should be used in the
attachBaseContext()
method
of all Activities
.
- Parameters:
base
- Base context.- Returns:
- The adapted context.
- Throws:
IllegalStateException
- ifinit(android.app.Application)
has not been called.
registerConnectionListener¶
public static void registerConnectionListener(@NonNull IristickConnection listener, @Nullable Handler handler)
Register a listener that gets notified of headset connections and disconnections.
The semantics are similar to calling
IristickManager.bind(IristickConnection, Context, Handler)
, but the internal
connection to the Iristick Services is reused instead of creating a new one.
Hence, registering a listener through this method is strongly recommended over making
a new binding when using the app support library.
If headsets and/or pocket units are already connected prior to calling this function, the
IristickConnection.onHeadsetConnected(Headset)
and/or
IristickConnection2.onPocketUnitConnected(PocketUnit)
methods will be called for
each of them.
If a subclass of IristickConnection2
is given, extra callbacks will be enabled.
New applications are recommended to always extend the IristickConnection2
abstract
class rather than implementing the IristickConnection
interface directly.
- Parameters:
listener
- Receives information as headsets are (dis)connected. This must be a validIristickConnection
object; it must not be null.handler
- Handler from which to call callbacks. If null, the main application thread will be used.- Throws:
IllegalStateException
- ifinit(android.app.Application)
has not been called.- See Also:
unregisterConnectionListener(IristickConnection)
unregisterConnectionListener¶
public static void unregisterConnectionListener(@NonNull IristickConnection listener)
Unregisters a connection listener.
If headsets are still connected when calling this function, the
IristickConnection.onHeadsetDisconnected(Headset)
method will be called for
each of them on the given connection.
- Parameters:
listener
- The listener to unregister.- Throws:
IllegalStateException
- ifinit(android.app.Application)
has not been called.
setInteractionRules¶
public static void setInteractionRules(@Nullable List<InteractionRule> rules)
- Parameters:
rules
- Interaction rules to set ornull
to clear all rules.- Throws:
IllegalStateException
- ifinit(android.app.Application)
has not been called.
startVoice¶
public static void startVoice(@NonNull VoiceGrammar grammar)
The grammar is automatically used with connected headsets until the grammar is removed
with stopVoice(com.iristick.smartglass.core.VoiceGrammar)
or until the grammar is released
.
This operation is a no-op if the grammar is already in use for voice recognition.
Warning
Do not mix calls to
startVoice(com.iristick.smartglass.core.VoiceGrammar)
/stopVoice(com.iristick.smartglass.core.VoiceGrammar)
with the similar methods defined
by Headset
.
- Parameters:
grammar
- The grammar for the voice recognition engine to recognize.- Throws:
NullPointerException
- ifgrammar
isnull
.
stopVoice¶
public static void stopVoice(@NonNull VoiceGrammar grammar)
Warning
Do not mix calls to
startVoice(com.iristick.smartglass.core.VoiceGrammar)
/stopVoice(com.iristick.smartglass.core.VoiceGrammar)
with the similar methods defined
by Headset
.
- Parameters:
grammar
- The grammar to stop listening for.