Android启动默认是横屏或者竖屏

来源:互联网 发布:梦幻西游须弥真言数据 编辑:程序博客网 时间:2024/04/17 02:55
Android启动默认是横屏或者竖屏
我们的TV本来是横屏显示,但是有客户竟然要竖屏显示,昨天快下班收到的需求,竟然说7.19就要搞定。思路有2个,一个就是修改LCD的默认输出,但是这个不是我这个水平能轻而易举搞定的。另外一个就是底层应该给上层porting出接口。像这种系统性的接口一般在build.prop里。
找到一个相关度比较大的属性ro.sf.hwrotation=270,和旋转有关的,联想到0,90,180,270.试试吧,将其改为ro.sf.hwrotation=0,测试了一下,OK,满足客户要求了,就早点下班了。

今天来了搜了一下相关的内容,还是发现了不少知识
1. 可以在init.rc里指定系统是横屏还是竖屏
setprop ro.sf.hwrotation 0指定默认输出不旋转(我们默认输出时竖屏)#setprop ro.sf.hwrotation 270指定旋转270度输出

2. 这个指定角度,Android默认只有0度和270度有效,180度无效,如果想使用180度,需要修改源码
修改文件frameworks/base/services/surfaceflinger/SurfaceFlinger.cpp

在方法

void GraphicPlane::setDisplayHardware(DisplayHardware *hw)里加case 180:      displayOrientation = ISurfaceComposer::eOrientation180;     break;

这样子就支持了180度了
3. 还有更详细的 - Android 4.1 默认窗体旋转180度  
1).设置属性值
在system/build.prop文件中加入 ro.sf.hwrotation=180


2).设置窗体默认显示方向
在frameworks/native/services/surfaceflinger/SurfaceFlinger.cpp文件中找到方法
setDisplayHardware
在switch中加入
case 180:     displayOrientation = ISurfaceComposer::eOrientation180;     break;

3).设置窗体动画旋转方向
     a > 在frameworks/base/core/java/android/view/Surface.java 加入方法
/*** @hide*/public static int getDefaultRotation(){return android.os.SystemProperties.getInt("ro.sf.hwrotation", 0);//180}/*** @hide*/  public static int getDefaultRotationIndex(){int rotation = getDefaultRotation();        switch(rotation){        case 0:            return ROTATION_0;        case 90:            return ROTATION_90;        case 180:            return ROTATION_180;        case 270:            return ROTATION_270;        }        return ROTATION_0;    }

b > 在frameworks/base/services/java/com/android/server/vm/ScreenRotationAnimation.java 文件中找到(android4.1) 方法setRotation
或(android4.2)方法setRotationInTransaction 修改 deltaRotation(rotation,Surface.ROTATION_0);
为deltaRotation(rotation,Surface. getDefaultRotationIndex());


4). 修改最近程序视图方向
   在frameworks/base/packages/systemui/src/com/android/systemui/RecentsPanelView.java 文件中修改如下
   private int mThumbnailHeight;//add
   在方法中添加
    
public void updateVoluesFromResources(){       ………………………………………………..       mThumbnailHeight = Math.round(res.getDimension(R.dimen.status_bar_recents_thumbnail_height));//add}

 在方法中添加
private void updateThumbnail(…) {else {Matrix scaleMatrix = new Matrix();float scale = mThumbnailWidth / (float) thumbnail.getWidth();scaleMatrix.postScale(scale, scale);//setScaleh.thumbnailViewImage.setScaleType(ScaleType.MATRIX);h.thumbnailViewImage.setImageMatrix(scaleMatrix);//addif(Surface.getDefaultRotation() > 0){Matrix rotateMatrix = new Matrix();rotateMatrix.setRotate(Surface.getDefaultRotation(),mThumbnailWidth/2,mThumbnailHeight/2);    h.thumbnailViewImage.setImageMatrix(rotateMatrix);}//add end}
5).修改截屏图片方向
  在frameworks/base/pacikages/systemui/src/com/android/systemui/GlobalScreenshot.java 文件中找到takeScreenshot方法
修改 float degrees = getDegreesForRotation(mDisplay.getRotation());

    int rotation = mDisplay.getRotation();    if(Surface.getDefaultRotation() > 0){       rotation = (rotation + Surface.getDefaultRotationIndex())%4;}float degrees = getDegreesForRotation(rotation);
OK 这样就完成屏幕旋转180度