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
Nested ClassesField Summary
FieldsModifier and TypeFieldDescriptionstatic final IFlashlightDefault instance that always returns unsupported and not Android nor iOS client, and throws IllegalArgumentException when attempting to open a setting.Method Summary
Modifier and TypeMethodDescriptionbooleanaddListener(IFlashlightListener listener) Adds a listener to the flashlight that receives notifications of the flashlight state and return code of operations.booleanGets 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.doubleGets the current flashlight intensity, initially set to 1.0, but also set at the last flashlightswitchOn(double).booleanVerifies if the flashlight has been verified as available by a previous call togetAsyncState().booleanChecks if the flashlight supports intensity levels.booleanVerifies if the flashlight is supported for the client session.booleanGets the flashlight switched on state, initially set tofalse.booleanremoveListener(IFlashlightListener listener) Removes a listener from the flashlight.booleansetIntensity(double intensity) Gets the current flashlight intensity, initially set to 1.0, but also set at the last flashlightswitchOn(double).booleanSwitches off the flashlight.default booleanswitchOn()Switches on the flashlight (with maximum intensity = 1.0, for iOS).booleanswitchOn(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
trueit 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:
trueif intensity is supported, currently only iOS using iiziRun,falseotherwise.
getClientSession
IClientSessionGyro getClientSession()Gets the client session associated with this flashlight instance.- Returns:
- The client session, or
nullif 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:
truefor success,falseiflisteneris 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:
truefor success,falseiflisteneris 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.TRUEif flashlight is switched on,Boolean.FALSEif the flashlight is switched off, ornullif state is undetermined.- See Also:
isAvailable
boolean isAvailable()Verifies if the flashlight has been verified as available by a previous call togetAsyncState().- Returns:
trueif the flashlight has been made available for programmatic use,falseif 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:
trueif changed,falsefor no change.- Throws:
IllegalArgumentException- If theintensityis 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:
trueif the operation is going to issue a later callback using the function registered usingaddListener(IFlashlightListener), orfalseif 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:
trueif the operation is going to issue a later callback using the function registered usingaddListener(IFlashlightListener), orfalseif the flashlight is not present or the client session is disposed of.- Throws:
IllegalArgumentException- If theintensityis not in the range of 0.0 to 1.0.
switchOff
boolean switchOff()Switches off the flashlight.- Returns:
trueif the operation is going to issue a later callback using the function registered usingaddListener(IFlashlightListener), orfalseif the flashlight is not present or the client session is disposed of.