全部博文(61)
分类: Java
2014-04-15 14:38:15
原文地址:android屏幕旋转在framework中的修改。 作者:zou_12345
PhoneWindowManager.java(\\192.168.1.4\opt\android_froyo_smdk\frameworks\policies\base\phone\com\android\internal\policy\impl)
public int rotationForOrientationLw(int orientation, int lastRotation,
boolean displayEnabled) {
if (mPortraitRotation < 0) {
// Initialize the rotation angles for each orientation once.
Display d =((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay();
if (d.getWidth() > d.getHeight()) {
mPortraitRotation = Surface.ROTATION_270;//Surface.ROTATION_90;
mLandscapeRotation =Surface.ROTATION_0;
} else {
mPortraitRotation =Surface.ROTATION_0;
mLandscapeRotation = Surface.ROTATION_270;//Surface.ROTATION_90;
}
}
一下是参考文章------------------------------------------------------------------------------------------------------
本行实现以后才发现,google在1.5到2.2这个过程中改进了很多,1.5修改竖屏比较麻烦,而2.2是相当的容易!
其实基本上google将之前版本的默认为竖屏的做法进行了改进,不需要再花费更多力气在屏幕的默认横竖切换上面。1.还是kernel竖屏,可以显示到屏幕出现"A N D R O I D"字样
启动参数里加入fbcon=rotate:1 (0:正常屏; 1:顺时钟转90度; 2:转180度; 3:顺时钟转270度;)
最后生成的autoconf.h里有类似项:
#define CONFIG_CMDLINE "console=ttySAC0,115200 fbcon=rotate:1"此项的解析在$(kernel)/drivers/video/console/fbcon.c
static int __init fb_console_setup(char *this_opt);
只是去初始化变量initial_rotation,然后initial_rotation会传递给其他需要的结构。
要选上:Device Drivers -> Graphics support -> Console display driver
support ->Framebuffer Console support -> Framebuffer Console
Rotation
注意:参考$(kernel)/documentation/fb/fbcon.txt2.android OS旋转屏幕
froyo中已经相当容易,仅修改一处:
frameworks/base/libs/surfaceflinger/SurfaceFlinger.cpp
void GraphicPlane::setDisplayHardware(DisplayHardware *hw)
{
mHw = hw; // initialize the display orientation transform.
// it's a constant that should come from the display driver.
// int displayOrientation = ISurfaceComposer::eOrientationDefault;
int displayOrientation = ISurfaceComposer::eOrientation90; //jeff.
。。。
}
或者只在init.rc中增加一项:
setprop ro.sf.hwrotation 90就这么简单的一修改,就可以全程竖屏显示了!