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

Commit f54829a5 authored by Steve Kondik's avatar Steve Kondik
Browse files

Add ACCELEROMETER_ROTATION_MODE.

Configuration value for orientation behavior.
parent de7120cd
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -1338,6 +1338,16 @@ public final class Settings {
         */
        public static final String ACCELEROMETER_ROTATION = "accelerometer_rotation";

        /**
         * Control the type of rotation which can be performed using the accelerometer
         * if ACCELEROMETER_ROTATION is enabled.
         *                  0 = Normal (left only)
         *                  1 = 270 degrees (left/right)
         *                  2 = 360 degrees (full rotation, including inverted)
         * @hide
         */
        public static final String ACCELEROMETER_ROTATION_MODE = "accelerometer_rotation_mode";
        
        /**
         * Whether the audible DTMF tones are played by the dialer when dialing. The value is
         * boolean (1 or 0).
@@ -1487,11 +1497,6 @@ public final class Settings {
            NOTIFICATION_SCREEN_ON
        };

        /**
         * Should 180 degree orientation be enabled. 
         * @hide
         */
        public static final String USE_180_ORIENTATION = "use_180_orientation";
        
        // Settings moved to Settings.Secure

+36 −33
Original line number Diff line number Diff line
@@ -111,23 +111,31 @@ public abstract class WindowOrientationListener {
    
    class SensorEventListenerImpl implements SensorEventListener {
        private static final int _DATA_X = 0;

        private static final int _DATA_Y = 1;

        private static final int _DATA_Z = 2;

        // Angle around x-axis thats considered almost perfect vertical to hold
        // the device
        private static final int PIVOT = 20;

        // Angle around x-asis that's considered almost too vertical. Beyond
        // this angle will not result in any orientation changes. f phone faces uses,
        // this angle will not result in any orientation changes. f phone faces
        // uses,
        // the device is leaning backward.
        private static final int PIVOT_UPPER = 65;

        // Angle about x-axis that's considered negative vertical. Beyond this
        // angle will not result in any orientation changes. If phone faces uses,
        // angle will not result in any orientation changes. If phone faces
        // uses,
        // the device is leaning forward.
        private static final int PIVOT_LOWER = -10;

        // Elanthis rotate code starts
        // Upper threshold limit for switching from portrait to landscape
        private static final int PL_UPPER = 65;

        // Lower threshold limit for switching from landscape to portrait
        private static final int LP_LOWER = 25;

@@ -161,34 +169,27 @@ public abstract class WindowOrientationListener {
                        || (mSensorRotation == Surface.ROTATION_270);

                boolean newrot = false;
                // If the sensor doesn't help you, figure out which way it should be
                if (mSensorRotation == -1)
                {
                    if (orientation <= LP_LOWER)
                    {
                // If the sensor doesn't help you, figure out which way it
                // should be
                if (mSensorRotation == -1) {
                    if (orientation <= LP_LOWER) {
                        newrot = true;
                        landscape = true;
                    }
                    else if (orientation >= PL_UPPER)
                    {
                    } else if (orientation >= PL_UPPER) {
                        newrot = true;
                        landscape = false;
                    }
                }
                else if (landscape)
                } else if (landscape)
                    newrot = (orientation <= LP_LOWER);
                else
                    newrot = orientation >= PL_UPPER;

                if (landscape ^ newrot)
                {
                if (landscape ^ newrot) {
                    if (quadrant == 0 || quadrant == 1)
                        rotation = Surface.ROTATION_270;
                    else
                        rotation = Surface.ROTATION_90;
                    }
                else
                {
                } else {
                    if (quadrant == 0 || quadrant == 3)
                        rotation = Surface.ROTATION_0;
                    else
@@ -198,9 +199,11 @@ public abstract class WindowOrientationListener {
            }
            if (mSensorRotation != rotation) {
                // End Elanthis rotate code
                    if (Surface.ROTATION_180 != rotation || (Surface.ROTATION_180 == rotation && 
                            (Settings.System.getInt(mContext.getContentResolver(), 
                                    Settings.System.USE_180_ORIENTATION, 0) > 0))) {            
                int mode = Settings.System.getInt(mContext.getContentResolver(),
                        Settings.System.ACCELEROMETER_ROTATION_MODE, 0);
                if ((Surface.ROTATION_180 == rotation && mode == 2)
                        || (Surface.ROTATION_270 == rotation && mode > 0)
                        || Surface.ROTATION_90 == rotation || Surface.ROTATION_0 == rotation) {
                    mSensorRotation = rotation;
                    onOrientationChanged(mSensorRotation);
                }