天天看點

android逆時針方向橫屏,android螢幕旋轉在framework中的修改。

平闆電腦一般是預設橫屏, 豎屏的APP程式, 會自動旋轉90°, 由于是順時針轉90°, 需要改為逆時針轉90°; 也就是要把portrait改逆時針轉90°,修改點如下:

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就這麼簡單的一修改,就可以全程豎屏顯示了!