Interface DisplayService

All Known Implementing Classes:
AndroidDisplayService, DesktopDisplayService, DummyDisplayService, IOSDisplayService

public interface DisplayService
With the display service you can query the characteristics of your device's screen. It can return the screen resolution and provides a few utility methods to see if the display is a regular phone, a tablet or a desktop.

Example

 DisplayService.create().ifPresent(service -> {
     Dimension2D resolution = service.getScreenResolution();
      System.out.printf("Screen resolution: %.0fx%.0f", resolution.getWidth(), resolution.getHeight());
  });

Android Configuration: none

iOS Configuration: none

Since:
3.0.0
  • Property Summary

    Properties
    Type
    Property
    Description
    javafx.beans.property.ReadOnlyObjectProperty<DisplayService.Notch>
    Property that contains the position of the notch, if any, and can be used to track changes in its location.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static enum 
    Possible Notch positions
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns an instance of DisplayService.
    javafx.geometry.Dimension2D
    Returns the default screen dimensions of a mobile device, in density independent pixel units.
    javafx.geometry.Dimension2D
    Returns the screen resolution of the device, in pixels.
    float
    Returns the logical density of the display
    boolean
    Indicates if the device has a notch that modifies the display or not.
    boolean
    Returns true if the device is considered a desktop / laptop.
    boolean
    Returns true if the device is considered a phone.
    boolean
    Returns true if the device has a round screen
    boolean
    Returns true if the device is considered a tablet.
    javafx.beans.property.ReadOnlyObjectProperty<DisplayService.Notch>
    Property that contains the position of the notch, if any, and can be used to track changes in its location.
  • Property Details

    • notch

      javafx.beans.property.ReadOnlyObjectProperty<DisplayService.Notch> notchProperty
      Property that contains the position of the notch, if any, and can be used to track changes in its location.
      Since:
      3.8.0
  • Method Details

    • create

      static Optional<DisplayService> create()
      Returns an instance of DisplayService.
      Returns:
      An instance of DisplayService.
    • isPhone

      boolean isPhone()
      Returns true if the device is considered a phone.
      Returns:
      True if the device is considered a phone.
    • isTablet

      boolean isTablet()
      Returns true if the device is considered a tablet.
      Returns:
      True if the device is considered a tablet. Running on Desktop, if the property charm-desktop-form is set to tablet, it will return true. False otherwise
    • isDesktop

      boolean isDesktop()
      Returns true if the device is considered a desktop / laptop.
      Returns:
      True if the device is considered a desktop / laptop.
    • getScreenResolution

      javafx.geometry.Dimension2D getScreenResolution()
      Returns the screen resolution of the device, in pixels.
      Returns:
      The screen resolution of the device.
    • getDefaultDimensions

      javafx.geometry.Dimension2D getDefaultDimensions()
      Returns the default screen dimensions of a mobile device, in density independent pixel units. In case of desktop, it gives the form factor of either a phone or a tablet.
      Returns:
      The screen dimensions of a mobile device, in dp units.
      Since:
      3.7.0
    • getScreenScale

      float getScreenScale()
      Returns the logical density of the display
      Returns:
      the screen scale
      Since:
      3.3.0
    • isScreenRound

      boolean isScreenRound()
      Returns true if the device has a round screen
      Returns:
      true if the device has a round screen
      Since:
      3.3.0
    • hasNotch

      boolean hasNotch()
      Indicates if the device has a notch that modifies the display or not.
      Returns:
      true if the device has a notch, false otherwise
      Since:
      3.8.0
    • notchProperty

      javafx.beans.property.ReadOnlyObjectProperty<DisplayService.Notch> notchProperty()
      Property that contains the position of the notch, if any, and can be used to track changes in its location.
      Since:
      3.8.0