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

Commit 94c9a245 authored by Sven Dawitz's avatar Sven Dawitz Committed by Steve Kondik
Browse files

Added option for 180 degree rotation.

This patch enables the rotation to 180 degrees.
Inspired by a patch for cm61, where you could
toggle 90/180/270 degrees rotation.
Since WindowOrientationListener.java got completly
changed, i couldnt port that patch, but had
to implement it in a different way.

Change-Id: If3c7240ac72c8a7ebec02582fbaa3ef4933d52d9
parent 804d785b
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -1725,6 +1725,14 @@ public final class Settings {
         */
        public static final String ACCELEROMETER_ROTATION = "accelerometer_rotation";

         /**
         * Control weather 180 degree rotation should be included if
         * ACCELEROMETER_ROTATION is enabled. If 0 no 180 degree rotation will be
         * executed, if 1 the 180 degree rotation is executed when ACCELEROMETER_ROTATION is true.
         * @hide
         */
        public static final String ACCELEROMETER_ROTATE_180 = "accelerometer_rotate_180";

        /**
         * Specifies the number of recent apps to show (8, 12, 16)
         * @hide
@@ -2346,6 +2354,7 @@ public final class Settings {
            TIME_12_24,
            DATE_FORMAT,
            ACCELEROMETER_ROTATION,
            ACCELEROMETER_ROTATE_180,
            DTMF_TONE_WHEN_DIALING,
            DTMF_TONE_TYPE_WHEN_DIALING,
            EMERGENCY_TONE,
+10 −8
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.provider.Settings;
import android.util.Config;
import android.util.Log;

@@ -39,6 +40,7 @@ public abstract class WindowOrientationListener {
    private static final String TAG = "WindowOrientationListener";
    private static final boolean DEBUG = false;
    private static final boolean localLOGV = DEBUG || Config.DEBUG;
    private static Context mContext;
    private SensorManager mSensorManager;
    private boolean mEnabled = false;
    private int mRate;
@@ -69,6 +71,7 @@ public abstract class WindowOrientationListener {
     */
    private WindowOrientationListener(Context context, int rate) {
        mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
        mContext = context;
        mRate = rate;
        mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        if (mSensor != null) {
@@ -267,8 +270,6 @@ public abstract class WindowOrientationListener {
        private static final float ACCELERATING_LOWPASS_ALPHA =
            computeLowpassAlpha(ACCELERATING_TIME_CONSTANT_MS);

        private boolean mAllow180Rotation = false;

        private WindowOrientationListener mOrientationListener;
        private int mRotation = ROTATION_0; // Current orientation state
        private float mTiltAngle = 0; // low-pass filtered
@@ -291,7 +292,7 @@ public abstract class WindowOrientationListener {
        }

        void setAllow180Rotation(boolean allowed) {
            mAllow180Rotation = allowed;
            // deprecated since ACCELEROMETER_ROTATE_180 in Settings is added
        }

        int getCurrentRotation(int lastRotation) {
@@ -304,7 +305,8 @@ public abstract class WindowOrientationListener {

        private void calculateNewRotation(float orientation, float tiltAngle) {
            if (localLOGV) Log.i(TAG, orientation + ", " + tiltAngle + ", " + mRotation);
            final boolean allow180Rotation = mAllow180Rotation;
            boolean allow180Rotation = (Settings.System.getInt(mContext.getContentResolver(),
                Settings.System.ACCELEROMETER_ROTATE_180, 0) != 0);
            int thresholdRanges[][] = allow180Rotation
                    ? THRESHOLDS_WITH_180[mRotation] : THRESHOLDS[mRotation];
            int row = -1;