Loading core/java/android/view/WindowOrientationListener.java +28 −15 Original line number Diff line number Diff line Loading @@ -106,7 +106,7 @@ public abstract class WindowOrientationListener { 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 = 30; 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, // the device is leaning backward. Loading @@ -114,22 +114,26 @@ public abstract class WindowOrientationListener { // Angle about x-axis that's considered negative vertical. Beyond this // angle will not result in any orientation changes. If phone faces uses, // the device is leaning forward. private static final int PIVOT_LOWER = 0; private static final int PIVOT_LOWER = -10; // Upper threshold limit for switching from portrait to landscape private static final int PL_UPPER = 280; private static final int PL_UPPER = 285; // Lower threshold limit for switching from landscape to portrait private static final int LP_LOWER = 320; // Lower threshold limt for switching from portrait to landscape private static final int PL_LOWER = 240; private static final int PL_LOWER = 265; // Upper threshold limit for switching from landscape to portrait private static final int LP_UPPER = 360; private static final int LP_UPPER = 355; // Internal value used for calculating linear variant private static final float PL_LINEAR_FACTOR = ((float)(PL_UPPER-PL_LOWER))/((float)(PIVOT_UPPER-PIVOT_LOWER)); private static final float PL_LF_UPPER = ((float)(PL_UPPER-PL_LOWER))/((float)(PIVOT_UPPER-PIVOT)); private static final float PL_LF_LOWER = ((float)(PL_UPPER-PL_LOWER))/((float)(PIVOT-PIVOT_LOWER)); // Internal value used for calculating linear variant private static final float LP_LINEAR_FACTOR = ((float)(LP_UPPER - LP_LOWER))/((float)(PIVOT_UPPER-PIVOT_LOWER)); private static final float LP_LF_UPPER = ((float)(LP_UPPER - LP_LOWER))/((float)(PIVOT_UPPER-PIVOT)); private static final float LP_LF_LOWER = ((float)(LP_UPPER - LP_LOWER))/((float)(PIVOT-PIVOT_LOWER)); public void onSensorChanged(SensorEvent event) { float[] values = event.values; Loading @@ -138,7 +142,7 @@ public abstract class WindowOrientationListener { float Z = values[_DATA_Z]; float OneEightyOverPi = 57.29577957855f; float gravity = (float) Math.sqrt(X*X+Y*Y+Z*Z); float zyangle = Math.abs((float)Math.asin(Z/gravity)*OneEightyOverPi); float zyangle = (float)Math.asin(Z/gravity)*OneEightyOverPi; int rotation = mSensorRotation; if ((zyangle <= PIVOT_UPPER) && (zyangle >= PIVOT_LOWER)) { // Check orientation only if the phone is flat enough Loading @@ -152,20 +156,29 @@ public abstract class WindowOrientationListener { while (orientation < 0) { orientation += 360; } float delta = (float)Math.abs(zyangle - PIVOT); float delta = zyangle - PIVOT; if (((orientation >= 0) && (orientation <= LP_UPPER)) || (orientation >= PL_LOWER)) { float threshold; if (mSensorRotation == Surface.ROTATION_90) { threshold = LP_LOWER + (LP_LINEAR_FACTOR * delta) ; if (delta < 0) { // delta is negative threshold = LP_LOWER - (LP_LF_LOWER * delta); //threshold = LP_LOWER + (LP_LF_LOWER * delta); } else { threshold = LP_LOWER + (LP_LF_UPPER * delta); } } else { threshold = PL_UPPER - (PL_LINEAR_FACTOR * delta); if (delta < 0) { //delta is negative threshold = PL_UPPER+(PL_LF_LOWER * delta); } else { threshold = PL_UPPER-(PL_LF_UPPER * delta); } } rotation = (orientation >= PL_LOWER && orientation <= threshold) ? Surface.ROTATION_90 : Surface.ROTATION_0; } } if (rotation != mSensorRotation) { mSensorRotation = rotation; Loading Loading
core/java/android/view/WindowOrientationListener.java +28 −15 Original line number Diff line number Diff line Loading @@ -106,7 +106,7 @@ public abstract class WindowOrientationListener { 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 = 30; 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, // the device is leaning backward. Loading @@ -114,22 +114,26 @@ public abstract class WindowOrientationListener { // Angle about x-axis that's considered negative vertical. Beyond this // angle will not result in any orientation changes. If phone faces uses, // the device is leaning forward. private static final int PIVOT_LOWER = 0; private static final int PIVOT_LOWER = -10; // Upper threshold limit for switching from portrait to landscape private static final int PL_UPPER = 280; private static final int PL_UPPER = 285; // Lower threshold limit for switching from landscape to portrait private static final int LP_LOWER = 320; // Lower threshold limt for switching from portrait to landscape private static final int PL_LOWER = 240; private static final int PL_LOWER = 265; // Upper threshold limit for switching from landscape to portrait private static final int LP_UPPER = 360; private static final int LP_UPPER = 355; // Internal value used for calculating linear variant private static final float PL_LINEAR_FACTOR = ((float)(PL_UPPER-PL_LOWER))/((float)(PIVOT_UPPER-PIVOT_LOWER)); private static final float PL_LF_UPPER = ((float)(PL_UPPER-PL_LOWER))/((float)(PIVOT_UPPER-PIVOT)); private static final float PL_LF_LOWER = ((float)(PL_UPPER-PL_LOWER))/((float)(PIVOT-PIVOT_LOWER)); // Internal value used for calculating linear variant private static final float LP_LINEAR_FACTOR = ((float)(LP_UPPER - LP_LOWER))/((float)(PIVOT_UPPER-PIVOT_LOWER)); private static final float LP_LF_UPPER = ((float)(LP_UPPER - LP_LOWER))/((float)(PIVOT_UPPER-PIVOT)); private static final float LP_LF_LOWER = ((float)(LP_UPPER - LP_LOWER))/((float)(PIVOT-PIVOT_LOWER)); public void onSensorChanged(SensorEvent event) { float[] values = event.values; Loading @@ -138,7 +142,7 @@ public abstract class WindowOrientationListener { float Z = values[_DATA_Z]; float OneEightyOverPi = 57.29577957855f; float gravity = (float) Math.sqrt(X*X+Y*Y+Z*Z); float zyangle = Math.abs((float)Math.asin(Z/gravity)*OneEightyOverPi); float zyangle = (float)Math.asin(Z/gravity)*OneEightyOverPi; int rotation = mSensorRotation; if ((zyangle <= PIVOT_UPPER) && (zyangle >= PIVOT_LOWER)) { // Check orientation only if the phone is flat enough Loading @@ -152,20 +156,29 @@ public abstract class WindowOrientationListener { while (orientation < 0) { orientation += 360; } float delta = (float)Math.abs(zyangle - PIVOT); float delta = zyangle - PIVOT; if (((orientation >= 0) && (orientation <= LP_UPPER)) || (orientation >= PL_LOWER)) { float threshold; if (mSensorRotation == Surface.ROTATION_90) { threshold = LP_LOWER + (LP_LINEAR_FACTOR * delta) ; if (delta < 0) { // delta is negative threshold = LP_LOWER - (LP_LF_LOWER * delta); //threshold = LP_LOWER + (LP_LF_LOWER * delta); } else { threshold = LP_LOWER + (LP_LF_UPPER * delta); } } else { threshold = PL_UPPER - (PL_LINEAR_FACTOR * delta); if (delta < 0) { //delta is negative threshold = PL_UPPER+(PL_LF_LOWER * delta); } else { threshold = PL_UPPER-(PL_LF_UPPER * delta); } } rotation = (orientation >= PL_LOWER && orientation <= threshold) ? Surface.ROTATION_90 : Surface.ROTATION_0; } } if (rotation != mSensorRotation) { mSensorRotation = rotation; Loading