在调屏的时候有些屏幕触摸是颠倒的,有时颠倒180度等等,linux下我们旋转触摸比较简单,而android则需要修改framework层,下面附方法: 改安卓input event上层, framework/native/services/inputflinger/InputReader.cpp 思路: 添加系统属性(persist.sys.hwrotation),然后根据系统属性对触摸方向进行旋转。 persist.sys.panel.flip 设置触摸的初始方向,当然也可以在设置中添加一个触摸屏旋转选项来方便客户操作,只需修改这个值即可。 diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp index c1a36ff79..851b98027 100644 --- a/services/inputflinger/InputReader.cpp +++ b/services/inputflinger/InputReader.cpp @@ -3814,6 +3814,29 @@ void TouchInputMapper::configureSu**ce(nsecs_t when, bool* outResetNeeded) { bool viewportChanged = mViewport != newViewport; if (viewportChanged) { mViewport = newViewport; + char buffer_orientation[PROP_VALUE_MAX]; + memset(buffer_orientation, 0, sizeof(buffer_orientation)); + property_get("persist.sys.panel.flip", buffer_orientation, "270"); + int cmpRet = atoi(buffer_orientation); + ALOGE("persist.sys.hwrotation~~~~~~~~~~~~~~~~~~~~~~~~~ = %d",cmpRet); + ALOGE("fy-1:mViewport.orientation----------------------- = %d",mViewport.orientation); + if (cmpRet == 0) + { + mViewport.orientation = mViewport.orientation + DISPLAY_ORIENTATION_0; + } + else if(cmpRet == 90) + { + mViewport.orientation = mViewport.orientation + DISPLAY_ORIENTATION_90; + } + else if(cmpRet == 180) + { + mViewport.orientation = mViewport.orientation + DISPLAY_ORIENTATION_180; + } + else if(cmpRet == 270) + { + mViewport.orientation = mViewport.orientation + DISPLAY_ORIENTATION_270; + } + ALOGE("fy-2:mViewport.orientation----------------------- = %d",mViewport.orientation); if (mDeviceMode == DEVICE_MODE_DIRECT || mDeviceMode == DEVICE_MODE_POINTER) { // Convert rotated viewport to natural su**ce coordinates. mViewport.orientation本身也是有一个值,比如APP是竖屏,系统是横屏,打开APP的时候系统会自动旋转为竖屏,此时mViewport.orientation也会跟着变化。 所以mViewport.orientation最后的值为mViewport.orientation + DISPLAY_ORIENTATION_X。 |
|小黑屋|
飞凌嵌入式
( 冀ICP备12004394号-1 )
GMT+8, 2024-9-8 07:24
Powered by Discuz! X3.4
© 2001-2013 Comsenz Inc.