Package 

Class OrientationHelper


  • 
    public class OrientationHelper
    
                        

    Helps with keeping track of both device orientation (which changes when device is rotated) and the display offset (which depends on the activity orientation wrt the device default orientation). Note: any change in the display offset should restart the camera engine, because it reads from the angles container at startup and computes size based on that. This is tricky because activity behavior can differ: - if activity is locked to some orientation, mDisplayOffset won't change, and onConfigurationChanged won't be called. The library will work fine. - if the activity is unlocked and does NOT handle orientation changes with android:configChanges, the actual behavior differs depending on the rotation. - the configuration callback is never called, of course. - for 90°/-90° rotations, the activity is recreated. Sometime you get mDisplayOffset callback before destruction, sometimes you don't - in any case it's going to recreate. - for 180°/-180°, the activity is NOT recreated! But we can rely on mDisplayOffset changing with a 180 delta and restart the engine. - lastly, if the activity is unlocked and DOES handle orientation changes with android:configChanges, as it will often be the case in a modern Compose app, - you always get the mDisplayOffset callback - for 90°/-90° rotations, the view also gets the configuration changed callback. - for 180°/-180°, the view won't get it because configuration only cares about portrait vs. landscape. In practice, since we don't control the activity and we can't easily inspect the configChanges flags at runtime, a good solution is to always restart when the display offset changes. We might do useless restarts in one rare scenario (unlocked, no android:configChanges, 90° rotation, display offset callback received before destruction) but that's acceptable. Tried to avoid that by looking at isChangingConfigurations, but it's always false by the time the display offset callback is invoked.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      public interface OrientationHelper.Callback

      Receives callback about the orientation changes.

    • Method Summary

      Modifier and Type Method Description
      void enable() Enables this listener.
      void disable() Disables this listener.
      int getLastDeviceOrientation() Returns the current device orientation.
      int getLastDisplayOffset() Returns the current display offset.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait