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


    http://blog.csdn.net/abc19842008/article/details/7543559

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


    [java] view plaincopy
    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 plaincopy
    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. }  


    调试android记录 —— 屏幕改为竖屏


    http://hi.baidu.com/jsxhxcq/item/960ca20607ed24e1359902d2

     在调试android时,项目需要将屏幕竖屏,而且没有传感器。

    按照网上的要求 在 build/target/product/core.mk 中

    PRODUCT_POLICY := android.policy_phone   //mid 改为phone

     但是改完没有任何反应。随就追踪下去

    1. 系统启动后 执行 performEnableScreen()

    performEnableScreen() -->     mPolicy.enableScreenAfterBoot();->

    windowmanagerservice.java
        public void enableScreenAfterBoot() {
            synchronized(mWindowMap) {
                if (mSystemBooted) {
                    return;
                }
                mSystemBooted = true;
            }
    2. 在其函数中调用updateRotation();

    public void enableScreenAfterBoot() {
            readLidState();
            updateRotation(Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
        }

     

     void updateRotation(int animFlags) {
            mPowerManager.setKeyboardVisibility(mLidOpen);
            int rotation = Surface.ROTATION_0;  

            if (mLidOpen) {
                rotation = mLidOpenRotation;
            } else if (mDockState == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) {
                rotation = mCarDockRotation;
            } else if (mDockState == Intent.EXTRA_DOCK_STATE_DESK && mDeskDockRotation >= 0) {
                rotation = mDeskDockRotation;
            }
            //if lid is closed orientation will be portrait
            try {
                //set orientation on WindowManager
                mWindowManager.setRotation(rotation, true,
                        mFancyRotationAnimation | animFlags);
            } catch (RemoteException e) {
                // Ignore
            }
        }

    3. setRotation()函数在 windowmanagerservices.java  中

        static final boolean DEBUG_ORIENTATION = true; //打开调试信息

    设置旋转函数, 下面调用关系 

    setRotation()  - > setRotationUnchecked()   - >  setRotationUncheckedLocked()->   rotationForOrientationLw()

    if (useSensorForOrientationLp(orientation)) {
                        // If the user has enabled auto rotation by default, do it.
                        int curRotation = mOrientationListener.getCurrentRotation();
                        return curRotation >= 0 ? curRotation : lastRotation;
                    }


    让所有应用都横屏显示

    http://blog.csdn.net/knock/article/details/7629585

    1. frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java  
    2.   
    3.     public int rotationForOrientationLw(int orientation, int lastRotation,  
    4.             boolean displayEnabled) {  
    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_0;  //jeff. ROTATION_90;  
    10.                 mLandscapeRotation = Surface.ROTATION_0;  
    11.                 mUpsideDownRotation = Surface.ROTATION_90;  //jeff. 270;  
    12.                 mSeascapeRotation = Surface.ROTATION_180;  
    13.             }  



    android屏幕旋转在framework中的修改

    http://blog.csdn.net/xulinguestc/article/details/6435957

     在framework中修改,可以随意修改屏幕0°指向的方向,其实也是framework层做的映射。 修改HAL层来修改屏幕0°指向的方向应该也是可以的,还没有试过, 估计会复杂点,应该要修改触摸屏的坐标, 触摸键值映射表, 比较麻烦,其实没什么必要,修改framework层就可以搞定了。

     

    平板电脑一般是默认横屏, 竖屏的APP程序, 会自动旋转90°, 由于是顺时针转90°, 需要改为逆时针转90°; 也就是要把portrait改逆时针转90°,这样就和手机一致,兼容很多gsensor游戏, 修改点如下:

    1. PhoneWindowManager.java(//192.168.1.4/opt/android_froyo_smdk/frameworks/policies/base/phone/com/android/internal/policy/impl)  
    2.   
    3.   
    4. public int rotationForOrientationLw(int orientation, int lastRotation,  
    5.   
    6.   
    7. boolean displayEnabled) {  
    8.   
    9.    
    10.   
    11.   
    12. if (mPortraitRotation < 0) {  
    13.   
    14.   
    15. // Initialize the rotation angles for each orientation once.  
    16.   
    17.   
    18. Display d =((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))  
    19.   
    20.   
    21. .getDefaultDisplay();  
    22.   
    23.   
    24. if (d.getWidth() > d.getHeight()) {  
    25.   
    26.   
    27. mPortraitRotation = Surface.ROTATION_270;//Surface.ROTATION_90;  
    28.   
    29.   
    30. mLandscapeRotation =Surface.ROTATION_0;  
    31.   
    32.   
    33. else {  
    34.   
    35.   
    36. mPortraitRotation =Surface.ROTATION_0;  
    37.   
    38.   
    39. mLandscapeRotation = Surface.ROTATION_270;//Surface.ROTATION_90;  
    40.   
    41.   
    42. }  
    43.   
    44.   
    45. }  

    以下是参考文章------------------------------------------------------------------------------------------------------

    本行实现以后才发现,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就这么简单的一修改,就可以全程竖屏显示了!

  • 相关阅读:
    Centos7下部署两套python版本并存环境的操作记录
    JSON格式化输出和解析工具
    利用阿里云的源yum方式安装Mongodb
    Ansible配置及常用模块总结
    VMware/KVM/OpenStack虚拟化之网络模式总结
    Mac下通过VMware Fusion安装centos虚拟机操作记录
    Supervisor (进程管理利器) 使用说明
    zabbix中配置当memory剩余不足20%时触发报警
    分布式监控系统Zabbix-3.0.3--短信报警设置
    linux下用户操作记录审计环境的部署记录
  • 原文地址:https://www.cnblogs.com/liulaolaiu/p/11744540.html
Copyright © 2020-2023  润新知