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

时间:2025-01-31 08:29:28
Android启动默认是横屏或者竖屏
我们的TV本来是横屏显示,但是有客户竟然要竖屏显示,昨天快下班收到的需求,竟然说7.19就要搞定。思路有2个,一个就是修改LCD的默认输出,但是这个不是我这个水平能轻而易举搞定的。另外一个就是底层应该给上层porting出接口。像这种系统性的接口一般在里。
找到一个相关度比较大的属性=270,和旋转有关的,联想到0,90,180,270.试试吧,将其改为=0,测试了一下,OK,满足客户要求了,就早点下班了。

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

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

在方法

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

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


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

3).设置窗体动画旋转方向
     a > 在frameworks/base/core/java/android/view/ 加入方法
/**
			* @hide
			*/
			public static int getDefaultRotation(){
				return ("", 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/ 文件中找到(android4.1) 方法setRotation
或(android4.2)方法setRotationInTransaction 修改 deltaRotation(rotation,Surface.ROTATION_0);
为deltaRotation(rotation,Surface. getDefaultRotationIndex());


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

 在方法中添加
private void updateThumbnail(…) {
		
		else {
			Matrix scaleMatrix = new Matrix();
			float scale = mThumbnailWidth / (float) ();
			(scale, scale);//setScale
			();
			(scaleMatrix);
			//add
			if(() > 0){
			Matrix rotateMatrix = new Matrix();
			((),mThumbnailWidth/2,mThumbnailHeight/2);
			    (rotateMatrix);
			}
			//add end
		}
5).修改截屏图片方向
  在frameworks/base/pacikages/systemui/src/com/android/systemui/ 文件中找到takeScreenshot方法
修改 float degrees = getDegreesForRotation(());

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