Class EnvProps

All Implemented Interfaces:
EventListener, IGProp<GProp<?>[]>, IPropCnr, Cloneable

public class EnvProps extends PropCnr
This client property is a container that holds everything a client/server needs in order to establish communication with the other party, and information about themselves (such as environment).

The property also handles the capabilities of the client.

The environment has at least the following properties:

  • $client - StringMapProp
  • $server - StringMapProp
  • $geo - GeoProps
  • ...other capabilities such as Speech...
Author:
Christopher Mindus
  • Field Details Link icon

    • clientEnv Link icon

      protected StringMapProp clientEnv
      The client environment properties.
    • geoProps Link icon

      protected GeoProps geoProps
      The Geolocation properties.
    • serverEnv Link icon

      protected StringMapProp serverEnv
      The server environment properties.
  • Constructor Details Link icon

    • EnvProps Link icon

      protected EnvProps()
      Creates the environment properties without a name.
    • EnvProps Link icon

      public EnvProps(Atom atom)
      Creates the environment properties with a name.
      Parameters:
      atom - The atom name.
  • Method Details Link icon

    • getClientSessionGyro Link icon

      public IClientSessionGyro getClientSessionGyro()
      Gets the client session gyro instance.
      Specified by:
      getClientSessionGyro in interface IGProp<GProp<?>[]>
      Overrides:
      getClientSessionGyro in class GProp<GProp<?>[]>
      Returns:
      The instance, or null if not found.
    • shouldSerializeToXML Link icon

      protected boolean shouldSerializeToXML(int programType)
      The EnvProps are never written to XML.
      Overrides:
      shouldSerializeToXML in class GProp<GProp<?>[]>
      Parameters:
      programType - From PropFactory.getProgramType(): 0=PropFactory.CLIENT, 1=PropFactory.SERVER or 2=PropFactory.EDITOR.
      Returns:
      true (default if not VOLATILE) to save to XML, false to avoid writing the property to XML.
    • addPredefinedProps Link icon

      protected void addPredefinedProps() throws PropException
      Adds the predefined properties for this container. This method is called once just after construction of the property container.

      Properties added:

        - client environment  StringMapProp  Atom.A_CLIENT
        - server environment  StringMapProp  Atom.A_SERVER
       

      Overrides:
      addPredefinedProps in class PropCnr
      Throws:
      PropException - for property exceptions.
    • getPredefinedProps Link icon

      protected void getPredefinedProps()
      Gets potential references to predefined properties for this container. This method is called once just after cloning of the property container.

      The method should get reference to using the getProp(...) methods. This allows the subclass to be able to retrieve the new instances to the properties created during addPredefinedProps() if stored in instance variables.

      Overrides:
      getPredefinedProps in class PropCnr
    • clone Link icon

      public EnvProps clone()
      Clones the environment properties.
      Overrides:
      clone in class PropCnr
    • getServerEnv Link icon

      public StringMapProp getServerEnv()
      Gets the server environment properties.
      Returns:
      StringMapProp for the server environment.
    • getClientEnv Link icon

      public StringMapProp getClientEnv()
      Gets the client environment properties.
      Returns:
      StringMapProp for the client environment.
    • iiziRunPresent Link icon

      public boolean iiziRunPresent()
      Checks if iiziRun is present.
      Returns:
      true if present, false otherwise.
    • getGeolocation Link icon

      public GeoProps getGeolocation()
      Gets the Geolocation properties.
    • getSpeechSynthesis Link icon

      public SpeechSynthesisProp getSpeechSynthesis()
      Gets the speech synthesis instance.
      Returns:
      The instance, or null if not supported.
    • getSpeechRecognition Link icon

      public SpeechRecognitionProp getSpeechRecognition()
      Gets the speech recognition instance.
      Returns:
      The instance, or null if not supported.
    • getLocale Link icon

      public LocaleInfo getLocale()
      Gets the client local info class instance.
      Returns:
      The client locale info class instance when the client environment has been set, otherwise the default client locale info instance specified for the server.
    • setLocale Link icon

      public LocaleInfo setLocale(LocaleInfo locale) throws PropTypeException
      Changes or sets the LocaleInfo for the environment. This method is intended to be used to change the language setting of a client session.

      Note that this change does not fire any refresh to the client property tree, use the IClientSessionGyro.setLocale(LocaleInfo) instead.

      Parameters:
      locale - localeInfo The locale information to use.
      Returns:
      The old LocaleInfo, or null if not set.
      Throws:
      PropTypeException - If the property is read-only.
    • getDPR Link icon

      public double getDPR()
      The device pixel ratio of the client.
      Returns:
      The Device Pixel Ratio, or 1.0 if not found.
    • getLanguageCode Link icon

      public String getLanguageCode()
      Gets the language code to use.
      Returns:
      The language code, or null for default (not defined by the client).
    • setCachedValue Link icon

      public void setCachedValue(String name, Object value)
      Sets a cached property by name. This is set for this instance only.
      Parameters:
      name - The name.
      value - An object.
    • getCachedValue Link icon

      public <TYPE> TYPE getCachedValue(String name, Class<TYPE> valueClass)
      Gets a cached property of a certain type.
      Parameters:
      name - The name.
      valueClass - The value class to retrieve.
      Returns:
      The cached value, or null if not found or class mismatch.
    • hasClientCapabilities Link icon

      public boolean hasClientCapabilities(EnvProps.ClientCapability capability)
      Checks if a client has the specified capabilities. It is important to use the appropriate EnvProps instance, i.e. the client session EnvProps and not e.g. the server's.
      Parameters:
      capability - The capability to query.
      Returns:
      true for support, false when client doesn't have the capability.
    • getParsedUserAgent Link icon

      public ua_parser.Client getParsedUserAgent() throws Exception
      Gets the parsed user agent instance.
      Returns:
      The parsed user agent for the client, a cached value (i.e. parsed once only).
      Throws:
      Exception - An exception due to failure in performing the test, with a message why it failed.
    • getDeviceDetectionFromUserAgent Link icon

      public io.github.mngsk.devicedetector.Detection getDeviceDetectionFromUserAgent() throws Exception
      Gets the cached device detection instance based on the parsed user agent.
      Returns:
      The cached device detection instance based on the parsed user agent (i.e. parsed once only).
      Throws:
      Exception - An exception due to failure in performing the test, with a message why it failed.
    • registerSession Link icon

      public IRemoteSessionControl registerSession(IClientSessionGyro clientGyro, IRemoteSessionControlListener listener)
      Assigns the application session control listener.

      This method is only intended for the framework and will throw an error if called.

      Parameters:
      clientGyro - The client gyro instance.
      listener - The control listener.
      Throws:
      IllegalStateException - If not called from the framework.
    • onRemoteEvent Link icon

      public void onRemoteEvent(RemoteEvent event)
      Called when a remote property event should be processed by this property.

      A subclass can override this method to perform appropriate processing and is not required to call super.onRemoteEvent(e).

      The onRemoteEvent is NOT called when in a proxied property container, but rather the normal onEventSelf method.

      Specified by:
      onRemoteEvent in interface IGProp<GProp<?>[]>
      Overrides:
      onRemoteEvent in class GProp<GProp<?>[]>
      Parameters:
      event - The remote event.
    • onEventSelf Link icon

      public void onEventSelf(GEvent event)
      Called when a property event is send to this property.

      A subclass can override this method to perform appropriate processing and is not required to call super.onEventSelf(e).

      Specified by:
      onEventSelf in interface IGProp<GProp<?>[]>
      Overrides:
      onEventSelf in class GProp<GProp<?>[]>
      Parameters:
      event - The property event.
    • addScreenSizeListener Link icon

      public boolean addScreenSizeListener(IScreenSizeListener listener)
      Adds a screen size listener for the client session. Calling this method multiple times with the same listener will have no effect (but to return false).
      Parameters:
      listener - The listener to add.
      Returns:
      true if the listener was added, false otherwise.
      Throws:
      NullPointerException - If the listener is null.
    • removeScreenSizeListener Link icon

      public boolean removeScreenSizeListener(IScreenSizeListener listener)
      Removes a screen size listener for the client session.
      Parameters:
      listener - The listener to remove.
      Returns:
      true if listener is successfully removed, false otherwise.
    • getScreenWidth Link icon

      public int getScreenWidth()
      Gets the current screen width.
      Returns:
      The current screen width, or zero if not initialized.
    • getScreenHeight Link icon

      public int getScreenHeight()
      Gets the current screen height.
      Returns:
      The current screen height, or zero if not initialized.
    • getScreenSize Link icon

      public Size getScreenSize()
      Gets the current screen size.
      Returns:
      The current screen size, or zero width and/or height if not initialized.
    • addScreenOrientationListener Link icon

      public boolean addScreenOrientationListener(IScreenOrientationListener listener)
      Adds a screen orientation listener for the client session. Calling this method multiple times with the same listener will have no effect (but to return false).
      Parameters:
      listener - The listener to add.
      Returns:
      true if the listener was added, false otherwise.
      Throws:
      NullPointerException - If the listener is null.
    • removeScreenOrientationListener Link icon

      public boolean removeScreenOrientationListener(IScreenOrientationListener listener)
      Removes a screen orientation listener for the client session.
      Parameters:
      listener - The listener to remove.
      Returns:
      true if listener is successfully removed, false otherwise.
    • isScreenOrientationLockSupported Link icon

      public boolean isScreenOrientationLockSupported()
      Checks if screen orientation locking is supported or not.
      Returns:
      true if the functions to lock or unlock screen orientation are supported, false otherwise.
    • getScreenOrientation Link icon

      public ScreenOrientation getScreenOrientation()
      Gets the current screen orientation.
      Returns:
      The orientation, ScreenOrientation.unknown if not supported.
    • setScreenOrientation Link icon

      public boolean setScreenOrientation(ScreenOrientation orientation)
      Locks the screen orientation.

      Note that there may be a delay in the orientation change after calling this method. This could be due to slow client connection, disconnected client or just due to device lag.

      Parameters:
      orientation - The orientation.
      Returns:
      true for success, false for not supported.
      Throws:
      IllegalArgumentException - If orientation is ScreenOrientation.unknown.
    • unlockScreenOrientation Link icon

      public boolean unlockScreenOrientation()
      Unlocks the screen orientation.

      Note that there may be a delay in the orientation change after calling this method. This could be due to slow client connection, disconnected client or just due to device lag.

      Returns:
      true for success, false for not supported.
    • getDeviceUUID Link icon

      public String getDeviceUUID()
      Gets the device UUID.
      Returns:
      The device's UUID if iiziRun is used and has been initialized, unknown otherwise. It is always "browser" for browsers.
    • getDeviceUUID Link icon

      public String getDeviceUUID(boolean mustBeValid)
      Gets the device UUID.
      Parameters:
      mustBeValid - Flag requiring device UUID to be from a valid device, otherwise null is returned. When flag is false,
      Returns:
      The device's UUID if iiziRun is used and has been initialized, when mustBeValid is false unknown otherwise. It is always "browser" for browsers when mustBeValid is false. When mustBeValid is true, null is returned.
    • configureStatusBar Link icon

      public boolean configureStatusBar(StatusBarConfig config)
      Sets the client sessions status bar to the configuration specified.

      Note: this only works on devices using iiziRun.

      Parameters:
      config - The configuration.
      Returns:
      true for ch
    • addStatusBarTapListener Link icon

      public boolean addStatusBarTapListener(IStatusBarTapListener listener)
      Adds a status bar tap listener for the client session. Calling this method multiple times with the same listener will have no effect (but to return false).

      Status bar tap events are only fired for devices using iiziRun with status bars available, using iOS devices.

      Parameters:
      listener - The listener to add.
      Returns:
      true if the listener was added, false otherwise.
      Throws:
      NullPointerException - If the listener is null.
    • removeStatusBarTapListener Link icon

      public boolean removeStatusBarTapListener(IStatusBarTapListener listener)
      Removes a status bar tap listener for the client session.
      Parameters:
      listener - The listener to remove.
      Returns:
      true if listener is successfully removed, false otherwise.