summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Kondik <shade@chemlab.org>2010-03-15 21:49:29 -0400
committerSteve Kondik <shade@chemlab.org>2010-04-11 21:25:32 -0400
commit13c41883789681a6042a8657211ddd0cc94ce973 (patch)
tree1168466c73b027f5691f2697de002da8e34268b5
parent6ce1ade4dc8d37b8ea1d239b4b84d0cf8a13a122 (diff)
downloadandroid_frameworks_base-13c41883789681a6042a8657211ddd0cc94ce973.tar.gz
android_frameworks_base-13c41883789681a6042a8657211ddd0cc94ce973.tar.bz2
android_frameworks_base-13c41883789681a6042a8657211ddd0cc94ce973.zip
Add ACCELEROMETER_ROTATION_MODE.
Configuration value for orientation behavior.
-rw-r--r--core/java/android/provider/Settings.java15
-rwxr-xr-xcore/java/android/view/WindowOrientationListener.java69
2 files changed, 46 insertions, 38 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 3dda0021003..d8c81d9b0d7 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -1279,6 +1279,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).
*/
@@ -1404,11 +1414,6 @@ public final class Settings {
SHOW_WEB_SUGGESTIONS
};
- /**
- * Should 180 degree orientation be enabled.
- * @hide
- */
- public static final String USE_180_ORIENTATION = "use_180_orientation";
// Settings moved to Settings.Secure
diff --git a/core/java/android/view/WindowOrientationListener.java b/core/java/android/view/WindowOrientationListener.java
index f74dae05ecf..2c255e1d53e 100755
--- a/core/java/android/view/WindowOrientationListener.java
+++ b/core/java/android/view/WindowOrientationListener.java
@@ -111,28 +111,36 @@ 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;
private static final float OneEightyOverPi = 57.29577957855f;
-
+
public void onSensorChanged(SensorEvent event) {
float[] values = event.values;
float X = values[_DATA_X];
@@ -146,12 +154,12 @@ public abstract class WindowOrientationListener {
int orientation = 90 - (int) Math.round(angle);
// normalize to 0 - 359 range
orientation %= 360;
- if (orientation < 0)
+ if (orientation < 0)
orientation += 360;
-
+
int quadrant = orientation / 90;
orientation %= 90;
-
+
// If you are in the 2nd or 4th quadrant we should reorient to
// get the mirror of the angle
if (quadrant == 1 || quadrant == 3)
@@ -161,51 +169,46 @@ 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;
+ rotation = Surface.ROTATION_270;
else
rotation = Surface.ROTATION_90;
- }
- else
- {
+ } else {
if (quadrant == 0 || quadrant == 3)
rotation = Surface.ROTATION_0;
else
- rotation = Surface.ROTATION_180;
- }
-
+ rotation = Surface.ROTATION_180;
}
+
+ }
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))) {
- mSensorRotation = rotation;
- onOrientationChanged(mSensorRotation);
- }
+ // End Elanthis rotate code
+ 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);
}
}
+ }
public void onAccuracyChanged(Sensor sensor, int accuracy) {