Package com.iizix.device.flash
Interface IFlashlight
- All Known Implementing Classes:
Flash
public interface IFlashlight
The flashlight/torch interface when supported, currently only in iiziRun using Cordova. The flashlight intensity only works under iOS.
See cordova-plugin-flashlight of the implementation in Cordova for more information.
- Author:
- Christopher Mindus
Nested Class Summary
Field Summary
Modifier and TypeFieldDescriptionstatic final IFlashlight
Default instance that always returns unsupported and not Android nor iOS client, and throws IllegalArgumentException when attempting to open a setting.Method Summary
Modifier and TypeMethodDescriptionboolean
addListener
(IFlashlightListener listener) Adds a listener to the flashlight that receives notifications of the flashlight state and return code of operations.boolean
Gets the current availability and state of the flashlight, if successful, it will cause the registered listener(s) to be invoked asynchronously.Gets the client session associated with this flashlight instance.double
Gets the current flashlight intensity, initially set to 1.0, but also set at the last flashlightswitchOn(double)
.boolean
Verifies if the flashlight has been verified as available by a previous call togetAsyncState()
.boolean
Checks if the flashlight supports intensity levels.boolean
Verifies if the flashlight is supported for the client session.boolean
Gets the flashlight switched on state, initially set tofalse
.boolean
removeListener
(IFlashlightListener listener) Removes a listener from the flashlight.boolean
setIntensity
(double intensity) Gets the current flashlight intensity, initially set to 1.0, but also set at the last flashlightswitchOn(double)
.boolean
Switches off the flashlight.default boolean
switchOn()
Switches on the flashlight (with maximum intensity = 1.0, for iOS).boolean
switchOn
(double intensity) Switches on the flashlight with the requested intensity, a value between 0.0 (darkest) and 1.0 (brightest).
Field Details
DEFAULT_IMPL
Default instance that always returns unsupported and not Android nor iOS client, and throws IllegalArgumentException when attempting to open a setting.
Method Details
isSupported
boolean isSupported()Verifies if the flashlight is supported for the client session.- Returns:
- The flashlight support flag. If
true
it only means that the flashlight could potentially be controlled programmatically, not that the user has allowed or enabled access to it.
isIntensitySupported
boolean isIntensitySupported()Checks if the flashlight supports intensity levels.- Returns:
true
if intensity is supported, currently only iOS using iiziRun,false
otherwise.
getClientSession
IClientSessionGyro getClientSession()Gets the client session associated with this flashlight instance.- Returns:
- The client session, or
null
if it is disposed of already. Please note that the client session might be returned as non-null but that it is currently in dispose operation.
addListener
Adds a listener to the flashlight that receives notifications of the flashlight state and return code of operations.- Parameters:
listener
- The listener instance for notifications.- Returns:
true
for success,false
iflistener
is already registered.
removeListener
Removes a listener from the flashlight. When the last listener is removed, the flashlight will automatically be switched off (usingIFlashlight.Operation.SWITCH_OFF
, notIFlashlight.Operation.AUTO_SWITCH_OFF
). This is also valid when the client session is disposed of, but then with the operationIFlashlight.Operation.AUTO_SWITCH_OFF
.- Parameters:
listener
- The listener instance for notifications.- Returns:
true
for success,false
iflistener
is not registered.
getAsyncState
boolean getAsyncState()Gets the current availability and state of the flashlight, if successful, it will cause the registered listener(s) to be invoked asynchronously. The first time this method is invoked for a client session and the iiziRun instance, the user may be asked to allow programmatic operational control of the flashlight. Please note that the flashlight is generally "connected" to the camera, so some devices may use the front camera rather than the back. The user might also be asked to allow camera operational control (instead of just the flashlight).- Returns:
Boolean.TRUE
if flashlight is switched on,Boolean.FALSE
if the flashlight is switched off, ornull
if state is undetermined.- See Also:
isAvailable
boolean isAvailable()Verifies if the flashlight has been verified as available by a previous call togetAsyncState()
.- Returns:
true
if the flashlight has been made available for programmatic use,false
if such a request has been denied by the user or not requested before usinggetAsyncState()
.
isSwitchedOn
boolean isSwitchedOn()Gets the flashlight switched on state, initially set tofalse
.- Returns:
- The flashlight switched on state. Please note that this value may not be accurate if
getAsyncState()
not yet has invoked its listeners, or thatgetAsyncState()
not has been called.
getIntensity
double getIntensity()Gets the current flashlight intensity, initially set to 1.0, but also set at the last flashlightswitchOn(double)
.- Returns:
- The intensity with a value range of 0.0 to 1.0, only working for iOS.
setIntensity
Gets the current flashlight intensity, initially set to 1.0, but also set at the last flashlightswitchOn(double)
.- Returns:
true
if changed,false
for no change.- Throws:
IllegalArgumentException
- If theintensity
is not in the range of 0.0 to 1.0.
switchOn
default boolean switchOn()Switches on the flashlight (with maximum intensity = 1.0, for iOS).- Returns:
true
if the operation is going to issue a later callback using the function registered usingaddListener(IFlashlightListener)
, orfalse
if the flashlight is not present or the client session is disposed of.
switchOn
Switches on the flashlight with the requested intensity, a value between 0.0 (darkest) and 1.0 (brightest). The value is only processed for iOS.- Returns:
true
if the operation is going to issue a later callback using the function registered usingaddListener(IFlashlightListener)
, orfalse
if the flashlight is not present or the client session is disposed of.- Throws:
IllegalArgumentException
- If theintensity
is not in the range of 0.0 to 1.0.
switchOff
boolean switchOff()Switches off the flashlight.- Returns:
true
if the operation is going to issue a later callback using the function registered usingaddListener(IFlashlightListener)
, orfalse
if the flashlight is not present or the client session is disposed of.