Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e3d14a68 authored by Saumya Prakash's avatar Saumya Prakash
Browse files

Allow gesture tutorial to work for both orientations for square aspect ratios.

Devices with a square aspect ratio were previously seeing a prompt to rotate the screen for the gesture navigation tutorial. This change enables the tutorial for such devices but will still show the prompt to rotate the device if the aspect ratio would make the tutorial animations look wrong.

Flag: LEGACY ENABLE_NEW_GESTURE_NAV_TUTORIAL ENABLED
Fix: 321650001
Test: Tried gesture tutorial on various devices of different aspect
ratios and ensured that the prompt to rotate the device only shows up on
devices that do not have a square aspect ratio.

Change-Id: I7a6ca40e09a8202a9b54d898e0c68cc142694342
parent e49c26dd
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -54,6 +54,8 @@ public class GestureSandboxActivity extends FragmentActivity {
    static final String KEY_TUTORIAL_TYPE = "tutorial_type";
    static final String KEY_GESTURE_COMPLETE = "gesture_complete";
    static final String KEY_USE_TUTORIAL_MENU = "use_tutorial_menu";
    public static final double SQUARE_ASPECT_RATIO_BOTTOM_BOUND = 0.95;
    public static final double SQUARE_ASPECT_RATIO_UPPER_BOUND = 1.05;

    @Nullable private TutorialType[] mTutorialSteps;
    private GestureSandboxFragment mCurrentFragment;
@@ -159,14 +161,20 @@ public class GestureSandboxActivity extends FragmentActivity {
     * Gesture animations are only in landscape for large screens and portrait for mobile. This
     * method enforces the following flows:
     *     1) phone / two-panel closed -> lock to portrait
     *     2) two-panel open / tablet + portrait -> prompt the user to rotate the screen
     *     3) two-panel open / tablet + landscape -> hide potential rotating prompt
     *     2) Large screen + portrait -> prompt the user to rotate the screen
     *     3) Large screen + landscape -> hide potential rotating prompt
     *     4) Square aspect ratio -> no action taken as the animations will fit both orientations
     */
    private void correctUserOrientation() {
        DeviceProfile deviceProfile = InvariantDeviceProfile.INSTANCE.get(
                getApplicationContext()).getDeviceProfile(this);
        if (deviceProfile.isTablet) {
            boolean showRotationPrompt = getResources().getConfiguration().orientation
            // The tutorial will work in either orientation if the height and width are similar
            boolean isAspectRatioSquare =
                    deviceProfile.aspectRatio > SQUARE_ASPECT_RATIO_BOTTOM_BOUND
                            && deviceProfile.aspectRatio < SQUARE_ASPECT_RATIO_UPPER_BOUND;
            boolean showRotationPrompt = !isAspectRatioSquare
                    && getResources().getConfiguration().orientation
                    == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;

            GestureSandboxFragment recreatedFragment =