Package org.vaadin.firitin.devicemotion
Class ScreenOrientation
java.lang.Object
org.vaadin.firitin.devicemotion.ScreenOrientation
Helper class to detect screen orientation.
This class uses the Screen Orientation API in the browser to detect the current orientation of the screen.
Useful for adjusting game physics when device is in landscape vs portrait mode.
- Author:
- mstahv
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
cancel()
Stop listening to orientation changes.Get the current screen orientation.getCurrentOrientation
(com.vaadin.flow.component.UI ui) Get the current screen orientation.static ScreenOrientation
listen
(com.vaadin.flow.component.UI ui, ScreenOrientation.OrientationChangeListener listener) Listen to screen orientation changes.static ScreenOrientation
Listen to screen orientation changes.
-
Constructor Details
-
ScreenOrientation
public ScreenOrientation()
-
-
Method Details
-
getCurrentOrientation
Get the current screen orientation.- Returns:
- CompletableFuture with the current orientation info
-
getCurrentOrientation
public static CompletableFuture<ScreenOrientationInfo> getCurrentOrientation(com.vaadin.flow.component.UI ui) Get the current screen orientation.- Parameters:
ui
- the UI context- Returns:
- CompletableFuture with the current orientation info
-
listen
Listen to screen orientation changes.- Parameters:
listener
- the listener to be notified of orientation changes- Returns:
- ScreenOrientation instance that can be used to stop listening
-
listen
public static ScreenOrientation listen(com.vaadin.flow.component.UI ui, ScreenOrientation.OrientationChangeListener listener) Listen to screen orientation changes.- Parameters:
ui
- the UI contextlistener
- the listener to be notified of orientation changes- Returns:
- ScreenOrientation instance that can be used to stop listening
-
cancel
public void cancel()Stop listening to orientation changes.
-