Class EnvProps

  • All Implemented Interfaces:
    EventListener, IGProp<GProp<?>[]>, IPropCnr, java.lang.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 Detail

      • clientEnv

        protected StringMapProp clientEnv
        The client environment properties.
      • geoProps

        protected GeoProps geoProps
        The Geolocation properties.
      • serverEnv

        protected StringMapProp serverEnv
        The server environment properties.
    • Constructor Detail

      • EnvProps

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

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

      • addPredefinedProps

        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

        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
      • getServerEnv

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

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

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

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

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

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

        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

        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

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

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

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

        public <TYPE> TYPE getCachedValue​(java.lang.String name,
                                          java.lang.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

        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

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

        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:
        java.lang.IllegalStateException - If not called from the framework.
      • onRemoteEvent

        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

        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

        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:
        java.lang.NullPointerException - If the listener is null.
      • removeScreenSizeListener

        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

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

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

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

        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:
        java.lang.NullPointerException - If the listener is null.
      • removeScreenOrientationListener

        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

        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.
      • setScreenOrientation

        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:
        java.lang.IllegalArgumentException - If orientation is ScreenOrientation.unknown.
      • unlockScreenOrientation

        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

        public java.lang.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

        public java.lang.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

        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

        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:
        java.lang.NullPointerException - If the listener is null.
      • removeStatusBarTapListener

        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.