Android4.0強制橫屏豎屏

來源:互聯網
上載者:User

標籤:android   blog   http   io   ar   os   使用   sp   java   

Android的啟動預設是橫屏或者豎屏
我們的TV本來是橫屏顯示,但是有客戶竟然要豎屏顯示,昨天快下班收到的需求,竟然說7.19就要搞定。思路有2個,一個就是修改LCD的預設輸出,但是這個不是我這個水平能輕而易舉搞定的。另外一個就是底層應該給上層porting出介面。像這種系統性的介面一般在build.prop裡。
找到一個相關度比較大的屬性ro.sf.hwrotation=270,和旋轉有關的,聯想到0,90,180,270.試試吧,將其改為ro.sf.hwrotation=0,測試了一下,OK,滿足客戶要求了,就早點下班了。
/ device/samsung/smdk4x12/system.prop(ro.sf.hwrotation )
今天來了搜了一下相關的內容,還是發現了不少知識
1,可以在init.rc裡指定系統是橫屏還是豎屏

[普通]  鑒於普通副本

  1. 對應setProp ro.sf.hwrotation 0指定預設輸出不旋轉(我們預設輸出時豎屏)  

  2.         #對應setProp ro.sf.hwrotation 270指定旋轉270度輸出  


2。這個指定角度,Android預設只有0度和270度有效,180度無效,如果想使用180度,需要修改源碼
修改檔案的架構/基地/服務/的surfaceflinger / SurfaceFlinger.cpp

在方法

[CPP]  鑒於普通副本

  1. 無效 GraphicPlane :: setDisplayHardware(DisplayHardware * HW)裡加  

  2.                         案例 180:  

  3.                     displayOrientation = ISurfaceComposer :: eOrientation180;  

  4.                     打破;  

 

這樣子就支援了180度了
3,還有更詳細的 - 安卓4.1預設表單旋轉180度  
1)設定屬性值
在系統/ build.prop檔案中加入ro.sf.hwrotation = 180


2)設定表單預設顯示方向
在架構/本地/服務/的surfaceflinger / SurfaceFlinger.cpp檔案中找到方法
setDisplayHardware
在交換器中加入

[CPP]  鑒於普通副本

  1. 案例 180:  

  2.             displayOrientation = ISurfaceComposer :: eOrientation180;  

  3.             打破;  


3)。設定表單動畫旋轉方向
     一>在架構/底座/核心/ JAVA /機器人/視圖/ Surface.java加入方法

[CPP]  鑒於普通副本

  1. / ** 

  2.             * @隱藏 

  3.             * /  

  4.             公用 靜態 詮釋 getDefaultRotation(){  

  5.                 返回 android.os.SystemProperties.getInt(“ro.sf.hwrotation” ,0); / / 180  

  6.             }  

  7.   

  8.   

  9.             / ** 

  10.             * @隱藏 

  11.             * /    

  12.             公用 靜態 詮釋 getDefaultRotationIndex(){  

  13.                 整型 旋轉= getDefaultRotation();  

  14.         開關(旋轉){  

  15.         情況下 0:  

  16.             返回 ROTATION_0;  

  17.         案例 90:  

  18.             返回 ROTATION_90;  

  19.         案例 180:  

  20.             返回 ROTATION_180;  

  21.         案例 270:  

  22.             返回 ROTATION_270;  

  23.         }  

  24.         返回 ROTATION_0;  

  25.     }  


B>在架構/基地/服務/ JAVA / COM /機器人/伺服器/ VM / ScreenRotationAnimation.java檔案中找到(android4.1)方法setRotation
或(android4.2)方法setRotationInTransaction修改deltaRotation(旋轉,Surface.ROTATION_0);
為deltaRotation(旋轉,表面getDefaultRotationIndex());


4)修改最近程式視圖方向
   在架構/底座/包/ systemui / SRC / COM /機器人/ systemui / RecentsPanelView.java檔案中修改如下
   私人詮釋mThumbnailHeight ;/ /加
   在方法中添加
    

[CPP]  鑒於普通副本

  1. 公用 無效 updateVoluesFromResources(){  

  2.            ........................................................  

  3.            mThumbnailHeight = Math.round(res.getDimension(R.dimen.status_bar_recents_thumbnail_height)); / /添加  

  4.         }  


 在方法中添加

[Java]中 查看純副本

  1. 私人 無效 updateThumbnail(...){  

  2.           

  3.         否則 {  

  4.             矩陣scaleMatrix =  新的 矩陣();  

  5.             浮 規模= mThumbnailWidth /(浮動)thumbnail.getWidth();  

  6.             scaleMatrix.postScale(刻度,刻度); / / setScale  

  7.             h.thumbnailViewImage.setScaleType(ScaleType.MATRIX);  

  8.             h.thumbnailViewImage.setImageMatrix(scaleMatrix);  

  9.             / /添加  

  10.             如果(Surface.getDefaultRotation()>  0 ){  

  11.             矩陣rotateMatrix =  新的 矩陣();  

  12.             rotateMatrix.setRotate(Surface.getDefaultRotation(),mThumbnailWidth / 2 ,mThumbnailHeight / 2 );  

  13.                 h.thumbnailViewImage.setImageMatrix(rotateMatrix);  

  14.             }  

  15.             / /添加結束  

  16.         }  

5)。修改截屏圖片方向
  在架構/底座/ pacikages / systemui / SRC / COM /機器人/ systemui / GlobalScreenshot.java檔案中找到takeScreenshot方法
修改浮度= getDegreesForRotation(mDisplay.getRotation());

[Java]中 查看純副本

  1.   整型 旋轉= mDisplay.getRotation();  

  2.   如果(Surface.getDefaultRotation()>  0 ){  

  3.      =旋轉(旋轉+ Surface.getDefaultRotationIndex())%4 ;  

  4. }  

  5. 浮 度= getDegreesForRotation(旋轉);  

確定這樣就完成旋轉螢幕180度

Android4.0強制橫屏豎屏

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.