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 Classes
    Modifier and Type
    Interface
    Description
    static enum 
    The asynchronous operations.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static 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 Type
    Method
    Description
    boolean
    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 flashlight switchOn(double).
    boolean
    Verifies if the flashlight has been verified as available by a previous call to getAsyncState().
    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 to false.
    boolean
    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 flashlight switchOn(double).
    boolean
    Switches off the flashlight.
    default boolean
    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

      static final IFlashlight 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

      boolean addListener(IFlashlightListener listener)
      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 if listener is already registered.
    • removeListener

      boolean removeListener(IFlashlightListener listener)
      Removes a listener from the flashlight. When the last listener is removed, the flashlight will automatically be switched off (using IFlashlight.Operation.SWITCH_OFF, not IFlashlight.Operation.AUTO_SWITCH_OFF). This is also valid when the client session is disposed of, but then with the operation IFlashlight.Operation.AUTO_SWITCH_OFF.
      Parameters:
      listener - The listener instance for notifications.
      Returns:
      true for success, false if listener 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, or null if state is undetermined.
      See Also:
    • isAvailable

      boolean isAvailable()
      Verifies if the flashlight has been verified as available by a previous call to getAsyncState().
      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 using getAsyncState().
    • isSwitchedOn

      boolean isSwitchedOn()
      Gets the flashlight switched on state, initially set to false.
      Returns:
      The flashlight switched on state. Please note that this value may not be accurate if getAsyncState() not yet has invoked its listeners, or that getAsyncState() not has been called.
    • getIntensity

      double getIntensity()
      Gets the current flashlight intensity, initially set to 1.0, but also set at the last flashlight switchOn(double).
      Returns:
      The intensity with a value range of 0.0 to 1.0, only working for iOS.
    • setIntensity

      boolean setIntensity(double intensity) throws IllegalArgumentException
      Gets the current flashlight intensity, initially set to 1.0, but also set at the last flashlight switchOn(double).
      Returns:
      true if changed, false for no change.
      Throws:
      IllegalArgumentException - If the intensity 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 using addListener(IFlashlightListener), or false if the flashlight is not present or the client session is disposed of.
    • switchOn

      boolean switchOn(double intensity) throws IllegalArgumentException
      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 using addListener(IFlashlightListener), or false if the flashlight is not present or the client session is disposed of.
      Throws:
      IllegalArgumentException - If the intensity 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 using addListener(IFlashlightListener), or false if the flashlight is not present or the client session is disposed of.