Class ScreenUtils

java.lang.Object
com.castlabs.android.utils.ScreenUtils

public class ScreenUtils extends Object
Utility class that provides helper methods around the device screen
Since:
3.0.0
  • Method Details

    • getScreenSize

      public static Point getScreenSize(@NonNull Context context)
      Deprecated.
      Returns the dimensions of the device screen in pixel. Please note that this method ignores the current orientation of the device.
      Parameters:
      context - The context
      Returns:
      Point that holds the width and height of the screen in pixel
    • getWindowSize

      @NonNull public static Point getWindowSize(@NonNull Context context)
      Returns the best available playback size in pixels for track-selection decisions.

      If the provided context is a UI context, this method prefers window bounds (WindowManager.getCurrentWindowMetrics() on API 30+) so multi-window playback uses the actual window size. If a window-specific size is not available, it falls back to the current display mode size for the resolved display.

      For non-visual contexts, this method avoids direct visual-service access through Context.WINDOW_SERVICE and resolves the display via getDisplay(Context).

      Parameters:
      context - Any context (UI or non-UI)
      Returns:
      A Point with width/height in pixels, or (Integer.MAX_VALUE, Integer.MAX_VALUE) when no display can be resolved
    • getDisplay

      @Nullable public static Display getDisplay(@NonNull Context context)
      Resolves a display for the given context without requiring a UI context.

      The default display is preferred; if unavailable, the first available display from DisplayManager.getDisplays() is returned.

      Parameters:
      context - Any context
      Returns:
      The resolved Display, or null if no display is available