com.holonplatform.vaadin.device

## Interface DeviceInfo

- All Superinterfaces:
    Serializable, UserAgentInspector

      public interface DeviceInfo
      extends UserAgentInspector

  Provides informations about client device in which application is running
  Since:
    5.0.0
  See Also:
    `UserAgentInspector`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `SESSION_ATTRIBUTE_NAME` Name of the session attribute to cache DeviceInfo instance

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `static DeviceInfo` | `create(String userAgentHeader, String httpAcceptHeader)` Build a DeviceInfo instance using given header values
    `static DeviceInfo` | `create(com.vaadin.server.VaadinRequest request)` Build a DeviceInfo instance using a `VaadinRequest`
    `static Optional<DeviceInfo>` | `ensureInited(com.vaadin.server.VaadinSession session)` Ensure that a `DeviceInfo` is available from given Vaadin `session`.
    `static Optional<DeviceInfo>` | `get()` Get the current DeviceInfo instance, if available.
    `int` | `getScreenHeight()` Get client screen height in pixels
    `int` | `getScreenWidth()` Get client screen width in pixels
    `int` | `getViewPortHeight()` Get application viewport height in pixels
    `int` | `getViewPortWidth()` Get application viewport width in pixels
    `static DeviceInfo` | `require()` Get the current DeviceInfo instance, or throw an `IllegalStateException` if not available.

    - ### Methods inherited from interface com.holonplatform.vaadin.device.UserAgentInspector

      `getAcceptHeader, getUserAgentHeader, isAndroid, isAndroidPhone, isAndroidTablet, isGameConsole, isIOs, isIPad, isIPhone, isIPod, isKindle, isMobile, isNintendo, isPlaystation, isSmartphone, isTablet, isWebKit, isWindowsPhone, isXbox`

- - ### Field Detail

    - #### SESSION_ATTRIBUTE_NAME

          static final String SESSION_ATTRIBUTE_NAME

      Name of the session attribute to cache DeviceInfo instance

  - ### Method Detail

    - #### getScreenWidth

          int getScreenWidth()

      Get client screen width in pixels
      Returns:
        Client screen width, or `-1` if not available at method call time

    - #### getScreenHeight

          int getScreenHeight()

      Get client screen height in pixels
      Returns:
        Client screen height, or `-1` if not available at method call time

    - #### getViewPortWidth

          int getViewPortWidth()

      Get application viewport width in pixels
      Returns:
        Application viewport width, or `-1` if not available at method call time

    - #### getViewPortHeight

          int getViewPortHeight()

      Get application viewport height in pixels
      Returns:
        Application viewport height, or `-1` if not available at method call time

    - #### create

          static DeviceInfo create(String userAgentHeader,
                                   String httpAcceptHeader)

      Build a DeviceInfo instance using given header values
      Specified by:
        `create` in interface `UserAgentInspector`
      Parameters:
        `userAgentHeader` - the User-Agent header
        `httpAcceptHeader` - the Accept header
      Returns:
        The `DeviceInfo`

    - #### create

          static DeviceInfo create(com.vaadin.server.VaadinRequest request)

      Build a DeviceInfo instance using a `VaadinRequest`
      Specified by:
        `create` in interface `UserAgentInspector`
      Parameters:
        `request` - Vaadin request (not null)
      Returns:
        The `DeviceInfo`

    - #### get

          static Optional<DeviceInfo> get()

      Get the current DeviceInfo instance, if available.

      DeviceInfo is created using current `VaadinRequest`, if available. It is cached into `VaadinSession` for further requests.

      Returns:
        Optional DeviceInfo, empty if it cannot be found in session and no current request is available to create a new instance

    - #### require

          static DeviceInfo require()

      Get the current DeviceInfo instance, or throw an `IllegalStateException` if not available.
      Returns:
        The current DeviceInfo instance
      See Also:
        `get()`

    - #### ensureInited

          static Optional<DeviceInfo> ensureInited(com.vaadin.server.VaadinSession session)

      Ensure that a `DeviceInfo` is available from given Vaadin `session`. For successful initialization, a `VaadinService.getCurrentRequest()` must be available.
      Parameters:
        `session` - Vaadin session (not null)
      Returns:
        The session scoped `DeviceInfo` instance, if a request is available

Copyright © 2019 The Holon Platform. All rights reserved.