Class ScreenOrientation

java.lang.Object
org.vaadin.firitin.devicemotion.ScreenOrientation

public class ScreenOrientation extends Object
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
  • Constructor Details

    • ScreenOrientation

      public ScreenOrientation()
  • Method Details

    • getCurrentOrientation

      public static CompletableFuture<ScreenOrientationInfo> 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 context
      listener - 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.