Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android4.4如何開機橫屏

android4.4如何開機橫屏

編輯:關於Android編程

軟件環境:android4.4

硬件平台:marvell

之前調試過在android4.0上將屏幕開機旋轉90度,找到了契合點,調整起來還是相對簡單,只需設置一個名稱為ro.sf.hwrotation = 90即可,android的surface系統顯示的時候會讀取該系統屬性的值,從而將顯示界面旋轉,但是android4.4的surfaceflinger機制做了調整,自始至終沒有發現對該屬性的處理判斷,可能有其他的暗門,我暫時沒發現,因此就把4.0判斷屬性的那一套移植了過來,具體改動如下:

--- a/services/surfaceflinger/DisplayDevice.cpp
+++ b/services/surfaceflinger/DisplayDevice.cpp
@@ -384,6 +384,11 @@ status_t DisplayDevice::orientationToTransfrom(
int orientation, int w, int h, Transform* tr)
{
uint32_t flags = 0;
+ char property[PROPERTY_VALUE_MAX];
+ if (property_get("ro.sf.hwrotation", property, NULL) > 0) {
+ if (atoi(property) == 90)
+ orientation = DisplayState::eOrientation90;
+ }
switch (orientation) {
case DisplayState::eOrientationDefault:
flags = Transform::ROT_0;
@@ -411,6 +416,7 @@ void DisplayDevice::setProjection(int orientation,

const int w = mDisplayWidth;
const int h = mDisplayHeight;
+ char property[PROPERTY_VALUE_MAX];

Transform R;
DisplayDevice::orientationToTransfrom(orientation, w, h, &R);
@@ -418,7 +424,12 @@ void DisplayDevice::setProjection(int orientation,
if (!frame.isValid()) {
// the destination frame can be invalid if it has never been set,
// in that case we assume the whole display frame.
- frame = Rect(w, h);www.2cto.com
+ if (property_get("ro.sf.hwrotation", property, NULL) > 0) {
+ if (atoi(property) == 90)
+ frame = Rect(h, w);
+ } else {
+ frame = Rect(w, h);
+ }
}

 

--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -674,6 +674,7 @@ status_t SurfaceFlinger::getDisplayInfo(const sp& display, DisplayInfo*
const HWComposer& hwc(getHwComposer());
float xdpi = hwc.getDpiX(type);
float ydpi = hwc.getDpiY(type);
+ char property[PROPERTY_VALUE_MAX];

// TODO: Not sure if display density should handled by SF any longer
class Density {
@@ -718,8 +719,15 @@ status_t SurfaceFlinger::getDisplayInfo(const sp& display, DisplayInfo*
info->orientation = 0;
}

- info->w = hwc.getWidth(type);
- info->h = hwc.getHeight(type);
+ if (property_get("ro.sf.hwrotation", property, NULL) > 0) {
+ if (atoi(property) == 90) {
+ info->w = hwc.getHeight(type);
+ info->h = hwc.getWidth(type);
+ }
+ } else {
+ info->w = hwc.getWidth(type);
+ info->h = hwc.getHeight(type);
+ }

這兩個文件做完相應的修改之後,問題來了,開機以及後續的一系列顯示確實進入了橫屏模式,但是觸摸屏卻依然沒有旋轉過來,上層對touch點位的處理還是按豎屏模式處理的。。。接著嘗試修改了surface的不少地方企圖扭轉touch點位,均告失敗,最終選擇了一個能解決問題但未必最優的方案,修改Input系統的處理。改動如下:

--- a/services/input/InputReader.cpp
+++ b/services/input/InputReader.cpp
@@ -42,6 +42,7 @@
#include "InputReader.h"

#include
+#include
#include
#include

@@ -2954,6 +2955,12 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
int32_t naturalPhysicalWidth, naturalPhysicalHeight;
int32_t naturalPhysicalLeft, naturalPhysicalTop;
int32_t naturalDeviceWidth, naturalDeviceHeight;
+
+ char property[PROPERTY_VALUE_MAX];
+ if (property_get("ro.sf.hwrotation", property, NULL) > 0) {
+ if (atoi(property) == 90)
+ mViewport.orientation = DISPLAY_ORIENTATION_90;
+ }
switch (mViewport.orientation) {
case DISPLAY_ORIENTATION_90:
naturalLogicalWidth = mViewport.logicalBottom - mViewport.logicalTop;
@@ -4246,6 +4253,11 @@ void TouchInputMapper::cookPointerData() {
// X, Y, and the bounding box for coverage information
// Adjust coords for surface orientation.
float x, y, left, top, right, bottom;
+ char property[PROPERTY_VALUE_MAX];
+ if (property_get("ro.sf.hwrotation", property, NULL) > 0) {
+ if (atoi(property) == 90)
+ mSurfaceOrientation = DISPLAY_ORIENTATION_90;
+ }
switch (mSurfaceOrientation) {
case DISPLAY_ORIENTATION_90:

至此,觸摸屏旋轉成功。

本人是本著遇到問題解決問題的原則,也許4.4有類似4.0的關卡可以一步屬性設置即可,只是本人沒有發現這道關,上述提供的方案僅供參考以及筆者作為記錄之用,穩定性還有待考究,本人未做全面的測試。有問題的同仁可以和我探討,有更好方案的朋友還望不吝賜教。謝謝~~~

 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved