android如何改变系统默认横竖屏方向

来源:互联网 发布:centos7 安装网络配置 编辑:程序博客网 时间:2024/05/01 11:13

在android4.2sdk上,机器默认是横屏,横屏下camera位于机器右上角,安装竖屏APK后,APK旋转180度,需要将camera位置朝下使用。

这一点不符合消费者使用习惯,需要在竖屏APK的情况下,camera位置朝上。 强制改变屏幕启动的方向,我是改的out目录下的build.prop中的ro.sf.hwrotation=90//270,不过这样改,重力感应和camera,开机logo都要翻转方向

由此引出以下开机logo的修改,原生态的logo是ppm格式的,如何修改ppm格式呢,从网上查到的信息是通过代码

具体方法如下

1. pngtopnm logo_linux_clut224.png > logo_linux_clut224.pnm

2. pnmquant 224 logo_linux_clut224.pnm > logo_linux_clut224.pnm

3.pnmtoplainpnm logo_linux_clut224.pnm > logo_linux_clut224.ppm

要删除logo_linux_clut224.c  logo_linux_clut224.o 文件,重新编译内核,

注意编译完内核后,也要将上层编译下在打包,不然第一次烧录和recovery时,logo还会出现原来的现象

以下为转载部分

如何改变android默认的横竖屏,修改源码一个地方就可以了。


[java] view plaincopyprint?
  1. public int rotationForOrientationLw(int orientation, int lastRotation,  
  2.            boolean displayEnabled) {  
  3.   
  4.        if (mPortraitRotation < 0) {  
  5.            // Initialize the rotation angles for each orientation once.  
  6.            Display d = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))  
  7.                    .getDefaultDisplay();  
  8.            if (d.getWidth() > d.getHeight()) {  
  9.                mPortraitRotation = Surface.ROTATION_90;  
  10.                mLandscapeRotation = Surface.ROTATION_0;  
  11.                mUpsideDownRotation = Surface.ROTATION_270;  
  12.                mSeascapeRotation = Surface.ROTATION_180;  
  13.            } else {  
  14.                mPortraitRotation = Surface.ROTATION_0;  
  15.                mLandscapeRotation = Surface.ROTATION_90;  
  16.                mUpsideDownRotation = Surface.ROTATION_180;  
  17.                mSeascapeRotation = Surface.ROTATION_270;  
  18.            }  
  19.        }  
  20.   
  21.     {  
  22.         Log.i(TAG, "MediaPlayer.is not PlayingVideo");  
  23.         synchronized (mLock) {  
  24.             switch (orientation) {  
  25.                 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:  
  26.                     //always return portrait if orientation set to portrait  
  27.                     //return mPortraitRotation;  
  28.                     return mUpsideDownRotation;  
  29.                 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:  
  30.                     //always return landscape if orientation set to landscape  
  31.                     return mLandscapeRotation;  
  32.                 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:  
  33.                     //always return portrait if orientation set to portrait  
  34.                     //return mUpsideDownRotation;  
  35.                     return mPortraitRotation;  
  36.                 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:  
  37.                     //always return seascape if orientation set to reverse landscape  
  38.                     return mSeascapeRotation;  
  39.                 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:  
  40.                     //return either landscape rotation based on the sensor  
  41.                     mOrientationListener.setAllow180Rotation(  
  42.                             isLandscapeOrSeascape(Surface.ROTATION_180));  
  43.                     return getCurrentLandscapeRotation(lastRotation);  
  44.                 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:  
  45.                     mOrientationListener.setAllow180Rotation(  
  46.                             !isLandscapeOrSeascape(Surface.ROTATION_180));  
  47.                     return getCurrentPortraitRotation(lastRotation);  
  48.             }  
  49.   
  50.             mOrientationListener.setAllow180Rotation(  
  51.                    orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR  
  52.                    || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);  
  53.   
  54.             // case for nosensor meaning ignore sensor and consider only lid  
  55.             // or orientation sensor disabled  
  56.             //or case.unspecified   
  57.             if (mLidOpen) {  
  58.                 return mLidOpenRotation;  
  59.             } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) {  
  60.                 return mCarDockRotation;  
  61.             } else if (mDockMode == Intent.EXTRA_DOCK_STATE_DESK && mDeskDockRotation >= 0) {  
  62.                 return mDeskDockRotation;  
  63.             } else {  
  64.                 if (useSensorForOrientationLp(orientation)) {  
  65.                     return mOrientationListener.getCurrentRotation(lastRotation);  
  66.                 }  
  67.                 return Surface.ROTATION_0;  
  68.             }  
  69.         }  
  70. }  
  71.    }  

修改上面倒数一行代码把return Surface.ROTATION_0改为你要的方向,记得这个要和上面的匹配,宽高不同,Surface.ROTATION_0也不同。因为代码开头就有

[java] view plaincopyprint?
  1. if (mPortraitRotation < 0) {  
  2.     // Initialize the rotation angles for each orientation once.  
  3.     Display d = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))  
  4.             .getDefaultDisplay();  
  5.     if (d.getWidth() > d.getHeight()) {  
  6.         mPortraitRotation = Surface.ROTATION_90;  
  7.         mLandscapeRotation = Surface.ROTATION_0;  
  8.         mUpsideDownRotation = Surface.ROTATION_270;  
  9.         mSeascapeRotation = Surface.ROTATION_180;  
  10.     } else {  
  11.         mPortraitRotation = Surface.ROTATION_0;  
  12.         mLandscapeRotation = Surface.ROTATION_90;  
  13.         mUpsideDownRotation = Surface.ROTATION_180;  
  14.         mSeascapeRotation = Surface.ROTATION_270;  
  15.     }  
  16. }  





0 0
原创粉丝点击