There is no gyroscope to detect device orientation on my device. So I want to rotate screen orientation when user pressing a key such as ALT key or setting "Auto-rotate screen" on in Settings>Display.
1. Modify the label of Auto-rotate screen in strings.xml
--- a/packages/apps/Settings/res/values/strings.xml 2011-07-25 14:17:04.634655000 +0900
+++ b/packages/apps/Settings/res/values/strings.xml 2011-07-25 14:21:31.033813231 +0900
@@ -1161,8 +1161,8 @@
<string name="animations_summary_on">Show animation when opening & closing windows</string>
<!-- Sound & display settings screen, animations option summary text when check box is clear --
<string name="animations_summary_off">Show animation when opening & closing windows</string
- <!-- Sound & display settings screen, accelerometer-based rotation check box label --
- <string name="accelerometer_title">Auto-rotate screen</string
+ <!-- Sound & display settings screen, accelerometer-based rotation check box label // Modified by kangadin --
+ <string name="accelerometer_title">Landscape mode</string>
<!-- Sound & display settings screen, accelerometer-based rotation summary text when check box is selected --
<string name="accelerometer_summary_on">Switch orientation automatically when rotating phone</string
2. Modify setRotation() and setRotationUncheckedLocked() functions in WindowManagerService.java
--- a/frameworks/base/services/java/com/android/server/WindowManagerService.java 2011-07-25 17:53:16.803818344 +0900
+++ b/frameworks/base/services/java/com/android/server/WindowManagerService.java 2011-07-26 10:21:02.353842187 +0900
@@ -4530,8 +4530,9 @@
mLastRotationFlags = animFlags;
}
if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation);
- rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
- mRotation, mDisplayEnabled);
+ // kangadin
+ //rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
+ // mRotation, mDisplayEnabled);
if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation);
changed = mDisplayEnabled && mRotation != rotation;
3. Add key code processing in interceptkeyBeforeDispatching() function in PhoneWindowManager.java
--- a/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java 2011-07-25 17:53:34.203818351 +0900
+++ b/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java 2011-07-26 14:20:40.597822000 +0900
@@ -223,7 +223,7 @@
boolean mScreenOn = false;
boolean mOrientationSensorEnabled = false;
int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
- static final int DEFAULT_ACCELEROMETER_ROTATION = 0;
+ static final int DEFAULT_ACCELEROMETER_ROTATION = 1; // kangadin
int mAccelerometerDefault = DEFAULT_ACCELEROMETER_ROTATION;
boolean mHasSoftInput = false;
@@ -596,6 +596,8 @@
com.android.internal.R.array.config_safeModeDisabledVibePattern);
mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
com.android.internal.R.array.config_safeModeEnabledVibePattern);
+ Settings.System.putInt(mContext.getContentResolver(), // kangadin
+ Settings.System.ACCELEROMETER_ROTATION, DEFAULT_ACCELEROMETER_ROTATION);
}
public void updateSettings() {
@@ -616,7 +618,14 @@
Settings.System.ACCELEROMETER_ROTATION, DEFAULT_ACCELEROMETER_ROTATION);
if (mAccelerometerDefault != accelerometerDefault) {
mAccelerometerDefault = accelerometerDefault;
- updateOrientationListenerLp();
+ //updateOrientationListenerLp(); // kangadin
+ try { // kangadin
+ mWindowManager.setRotation(accelerometerDefault == 0 ?
+ Surface.ROTATION_90 : Surface.ROTATION_0,
+ true, mFancyRotationAnimation);
+ } catch (RemoteException e) {
+ // Ignore
+ }
}
if (mSystemReady) {
int pointerLocation = Settings.System.getInt(resolver,
@@ -1218,6 +1227,15 @@
return true;
}
}
+ } else if (keyCode == KeyEvent.KEYCODE_ALT_LEFT || keyCode == KeyEvent.KEYCODE_ALT_RIGHT) { // kangadin
+ if (down && repeatCount == 0) {
+ // Toggle ACCELEROMETER_ROTATION
+ int ro = Settings.System.getInt(mContext.getContentResolver(),
+ Settings.System.ACCELEROMETER_ROTATION, DEFAULT_ACCELEROMETER_ROTATION);
+ Settings.System.putInt(mContext.getContentResolver(),
+ Settings.System.ACCELEROMETER_ROTATION, ro == 0 ? 1 : 0);
+ }
+ return true;
}
// Shortcuts are invoked through Search+key, so intercept those here
4. Remove android:screenOrientation field in AndroidManifest.xml
packages/apps/Launcher2/AndroidManifest.xml
packages/apps/Contacts/AndroidManifest.xml
packages/apps/Phone/AndroidManifest.xml
packages/apps/Settings/AndroidManifest.xml
packages/apps/VoiceDialer/AndroidManifest.xml
(The End)