Class DeviceOrientationDelegate

java.lang.Object
com.jwplayer.pub.api.fullscreen.delegates.DeviceOrientationDelegate
All Implemented Interfaces:
androidx.lifecycle.LifecycleEventObserver, androidx.lifecycle.LifecycleObserver

public class DeviceOrientationDelegate extends Object implements androidx.lifecycle.LifecycleEventObserver
Responsible for changing the device orientation during fullscreen and listening to changes in device orientation to enter or exit fullscreen.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
    Used to store whether fullscreen can be exited by rotation.
  • Constructor Summary

    Constructors
    Constructor
    Description
    DeviceOrientationDelegate(android.app.Activity activity, androidx.lifecycle.Lifecycle lifecycle, android.os.Handler handler)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    doRotation(boolean fullscreen, boolean allowFullscreenPortrait)
    Force the screen orientation to change.
    protected void
    Starts a orientation event listener.
    boolean
    Whether the current or a very recent device orientation change was performed by the user, as opposed to requested by this delegate.
    void
    onAllowFullscreenPortrait(boolean allowFullscreenPortrait)
     
    void
    onAllowRotationChanged(boolean allowRotation)
     
    void
    onStateChanged(androidx.lifecycle.LifecycleOwner source, androidx.lifecycle.Lifecycle.Event event)
     
    void
    Detaches this delegate from the process: unregisters the configuration-change callback, stops the orientation sensor listener, and drops any pending orientation restore.
    void
    setFullscreen(boolean fullscreen)
     
    protected long
    The clock used for rotation-attribution bookkeeping.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • mAllowRotation

      protected boolean mAllowRotation
      Used to store whether fullscreen can be exited by rotation.
  • Constructor Details

    • DeviceOrientationDelegate

      public DeviceOrientationDelegate(android.app.Activity activity, androidx.lifecycle.Lifecycle lifecycle, android.os.Handler handler)
  • Method Details

    • setFullscreen

      public void setFullscreen(boolean fullscreen)
    • isUserRotationInProgress

      public boolean isUserRotationInProgress()
      Whether the current or a very recent device orientation change was performed by the user, as opposed to requested by this delegate. Queried while a fullscreen exit is being processed: a host reacting to rotation calls JWPlayer.setFullscreen(false, ...) from Activity.onConfigurationChanged, within the same main-thread dispatch as the configuration change itself.
      Returns:
      true when an orientation change not requested by this delegate is being dispatched or completed within the last USER_ROTATION_ATTRIBUTION_WINDOW_MS.
    • release

      public void release()
      Detaches this delegate from the process: unregisters the configuration-change callback, stops the orientation sensor listener, and drops any pending orientation restore. Safe to call more than once. Runs on the host lifecycle's ON_DESTROY, and is also invoked by the SDK when the player owning this delegate is destroyed independently of its Activity (for example a player recycled out of a feed) — the configuration-change callback lives on the application context and would otherwise outlive, and leak, the player and its Activity.
    • uptimeMillis

      protected long uptimeMillis()
      The clock used for rotation-attribution bookkeeping. Overridable so tests can control time; SystemClock is not usable in local unit tests.
    • onStateChanged

      public void onStateChanged(@NonNull androidx.lifecycle.LifecycleOwner source, @NonNull androidx.lifecycle.Lifecycle.Event event)
      Specified by:
      onStateChanged in interface androidx.lifecycle.LifecycleEventObserver
    • onAllowRotationChanged

      public void onAllowRotationChanged(boolean allowRotation)
    • doRotation

      protected void doRotation(boolean fullscreen, boolean allowFullscreenPortrait)
      Force the screen orientation to change.

      Default behavior is to force LANDSCAPE/REVERSE_LANDSCAPE when fullscreen == true and PORTRAIT when fullscreen == false.

      Parameters:
      fullscreen - True when entering fullscreen.
    • doRotationListener

      protected void doRotationListener()
      Starts a orientation event listener.
    • onAllowFullscreenPortrait

      public void onAllowFullscreenPortrait(boolean allowFullscreenPortrait)