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

Commit 8401308c authored by Vinit Nayak's avatar Vinit Nayak
Browse files

Don't rely on nav mode change listener for oriented state

When nav mode state changes, launcher gets
re-instantiated, which means the listener for
nav mode changes often gets destroyed before it
even gets fired. Rely on the initial setup to
set the correct nav mode.

The other bug with relying
on the initial value was that we were initially
getting the old nav mode when initFlags was called
from the ctor, but then the correct updated nav
mode when called from initListeners(). The first
call would enable rotation but then the second
call wasn't disabling it. Now we toggled based on
nav mode each time.

Another bug fix in RecentsView was not calling
update when launcher rotation is enabled. That was
added when previously we were using HOME_ROTATED
and PORTRAIT as different PagedViewHandlers to
differentiate when launcher rotation was enabled.
HOME_ROTATED is now removed, so we no longer need
to change the internal state of RecentsOrientedState.

Fixes: 159176222
Change-Id: I2a37880ce3cf835ca5b9b165ce3840537facee6c
parent 832aa03a
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -1053,8 +1053,7 @@ public abstract class RecentsView<T extends BaseActivity> extends PagedView impl

    private void animateRecentsRotationInPlace(int newRotation) {
        if (mOrientationState.canLauncherRotate()) {
            // Update the rotation but let system take care of the rotation animation
            setLayoutRotation(newRotation, mOrientationState.getDisplayRotation());
            // Let system take care of the rotation
            return;
        }
        AnimatorSet pa = setRecentsChangedOrientation(true);
+3 −26
Original line number Diff line number Diff line
@@ -116,9 +116,6 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
            MASK_MULTIPLE_ORIENTATION_SUPPORTED_BY_DEVICE | FLAG_SYSTEM_ROTATION_ALLOWED
                    | FLAG_ROTATION_WATCHER_SUPPORTED | FLAG_ROTATION_WATCHER_ENABLED;

    private SysUINavigationMode.NavigationModeChangeListener mNavModeChangeListener =
            newMode -> setFlag(FLAG_ROTATION_WATCHER_SUPPORTED, newMode != TWO_BUTTONS);

    private final Context mContext;
    private final ContentResolver mContentResolver;
    private final SharedPreferences mSharedPrefs;
@@ -268,10 +265,9 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre

    private void initFlags() {
        SysUINavigationMode.Mode currentMode = SysUINavigationMode.getMode(mContext);
        if (mOrientationListener.canDetectOrientation() &&
                currentMode != TWO_BUTTONS) {
            mFlags |= FLAG_ROTATION_WATCHER_SUPPORTED;
        }
        boolean rotationWatcherSupported = mOrientationListener.canDetectOrientation() &&
                currentMode != TWO_BUTTONS;
        setFlag(FLAG_ROTATION_WATCHER_SUPPORTED, rotationWatcherSupported);

        // initialize external flags
        updateAutoRotateSetting();
@@ -288,9 +284,6 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
            mContentResolver.registerContentObserver(
                    Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION),
                    false, mSystemAutoRotateObserver);
            SysUINavigationMode.Mode currentMode =
                    SysUINavigationMode.INSTANCE.get(mContext)
                            .addModeChangeListener(mNavModeChangeListener);
        }
        initFlags();
    }
@@ -302,8 +295,6 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
        if (isMultipleOrientationSupportedByDevice()) {
            mSharedPrefs.unregisterOnSharedPreferenceChangeListener(this);
            mContentResolver.unregisterContentObserver(mSystemAutoRotateObserver);
            SysUINavigationMode.INSTANCE.get(mContext)
                    .removeModeChangeListener(mNavModeChangeListener);
        }
        setRotationWatcherEnabled(false);
    }
@@ -349,20 +340,6 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
        setFlag(FLAG_ROTATION_WATCHER_ENABLED, isEnabled);
    }

    public int getTouchRotationDegrees() {
        switch (mTouchRotation) {
            case ROTATION_90:
                return 90;
            case ROTATION_180:
                return 180;
            case ROTATION_270:
                return 270;
            case ROTATION_0:
            default:
                return 0;
        }
    }

    /**
     * Returns the scale and pivot so that the provided taskRect can fit the provided full size
     */