3、\frameworks\base\services\java\com\android\server\WindowManagerService.java 中
public boolean
setRotationUncheckedLocked(int rotation, int animFlags) // 函数用来最终设置屏方向。
二、
calculateNewRotation()函数
private void calculateNewRotation(float orientation, float tiltAngle)
{
if (localLOGV) Log.i(TAG, orientation + ", " + tiltAngle + ", " + mRotation);
// final boolean allow180Rotation = mAllow180Rotation;
final boolean allow180Rotation = true;
int thresholdRanges[][] = allow180Rotation ? THRESHOLDS_WITH_180[mRotation] : THRESHOLDS[mRotation];
//判断支持哪种旋转模式 THRESHOLDS_WITH_180 或 THRESHOLDS
int row = -1;
for (int i = 0; i < thresholdRanges.length; i++)
{
if
(orientation >= thresholdRanges[i][0] && orientation < thresholdRanges[i][1])
{
//判断旋转地范围
row = i;
break;
}
}
if (row == -1) return; // no matching transition
int rotation = allow180Rotation ? ROTATE_TO_WITH_180[mRotation][row] : ROTATE_TO[mRotation][row];
//根据mRotation、row判断旋转方向,也就是要转向的那个方向
//此时mRotation对应你当前屏幕方向,
rotation 是你马上要转向的那个方向
if (tiltAngle > MAX_TRANSITION_TILT[rotation])
{
// tilted too far flat to go to this rotation
return;
}
if (localLOGV) Log.i(TAG, "orientation " + orientation + " gives new rotation = " + rotation);
mRotation = rotation;
//此时
mRotation 对应你要转向的方向了
mOrientationListener.onOrientationChanged(INTERNAL_TO_SURFACE_ROTATION[mRotation]);
//
将mRotation传递到WindowManagerService.java中做屏幕的旋转
}
三、
修改备忘
路径:frameworks\base\core\java\android\view\WindowOrientationListener.java
/*default
private static final int[][] ROTATE_TO_WITH_180 = new int[][] {
{ROTATION_90, ROTATION_180, ROTATION_270},
{ROTATION_0, ROTATION_180, ROTATION_90, ROTATION_0},
{ROTATION_0, ROTATION_270, ROTATION_180, ROTATION_0},
{ROTATION_0, ROTATION_90, ROTATION_270, ROTATION_0},
};
*/
private static final int[][] ROTATE_TO_WITH_180 = new int[][] {
{ROTATION_90, ROTATION_180, ROTATION_270},
{ROTATION_0, ROTATION_180, ROTATION_270, ROTATION_0},
{ROTATION_0, ROTATION_90, ROTATION_180, ROTATION_0},
{ROTATION_0, ROTATION_90, ROTATION_270, ROTATION_0},
};