- 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
PropertiesTypePropertyDescriptionjavafx.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.javafx.beans.property.ReadOnlyObjectProperty<javafx.geometry.Insets>Property that contains the insets of the system bars (typically the status bar at the top and the navigation bar at the bottom). -
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic Optional<DisplayService>create()Returns an instance ofDisplayService.javafx.geometry.Dimension2DReturns the default screen dimensions of a mobile device, in density independent pixel units.javafx.geometry.Dimension2DReturns the screen resolution of the device, in pixels.floatReturns the logical density of the displaybooleanhasNotch()Indicates if the device has a notch that modifies the display or not.booleanReturns true if the device is considered a desktop / laptop.booleanisPhone()Returns true if the device is considered a phone.booleanReturns true if the device has a round screenbooleanisTablet()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.javafx.beans.property.ReadOnlyObjectProperty<javafx.geometry.Insets>Property that contains the insets of the system bars (typically the status bar at the top and the navigation bar at the bottom).
-
Property Details
-
notch
javafx.beans.property.ReadOnlyObjectProperty<DisplayService.Notch> notchPropertyProperty that contains the position of the notch, if any, and can be used to track changes in its location.- Since:
- 3.8.0
-
systemBarsInsets
javafx.beans.property.ReadOnlyObjectProperty<javafx.geometry.Insets> systemBarsInsetsPropertyProperty that contains the insets of the system bars (typically the status bar at the top and the navigation bar at the bottom). These insets can be used to add the necessary padding so the application doesn't get underneath the content shown at the system bars.
-
-
Method Details
-
create
Returns an instance ofDisplayService.- 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-formis set totablet, 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
-
systemBarsInsetsProperty
javafx.beans.property.ReadOnlyObjectProperty<javafx.geometry.Insets> systemBarsInsetsProperty()Property that contains the insets of the system bars (typically the status bar at the top and the navigation bar at the bottom). These insets can be used to add the necessary padding so the application doesn't get underneath the content shown at the system bars.
-