Android 设置20点触摸

Android 设置20点触摸

文章目录

一、前言

增加Android触摸点,一般是在商显的Android大屏上有一定的需求,在普通的Android设备基本不用。

首先,Android系统默认最多支持16点触摸。

如果要增加有效触摸点,需要更新对应的触摸框驱动ko文件;

还要再framework中进行代码适配。

关于触摸框点数增加的文章,网上也有不少,但是CSDN上基本都是要会员才能看,这里给大家介绍一下。

二、适配修改

1、修改触摸驱动文件

ko位置:

复制代码
device/ko/touch/xxx.ko

ko 文件是驱动层结合触摸框硬件提供的,未进行过具体修改,不过多描述。

2、修改framework代码文件

framework中的需要适配的代码:

(1)开放触摸点数为20点,修改的文件包含:
复制代码
release/frameworks/base/core/java/android/view/MotionEvent.java
release/frameworks/native/include/android/input.h
release/frameworks/native/include/input/Input.h
release/frameworks/native/include/input/InputEventLabels.h

修改的代码,不就是Android 系统中的按键相关代码吗。

(2)具体修改

其实改的代码也不多,也比较容易理解,具体修改入下:

有+号的行,就是代码增加的意思。

复制代码
diff --git a/release/frameworks/base/core/java/android/view/MotionEvent.java b/release/frameworks/base/core/java/android/view/MotionEvent.java


+++ b/release/frameworks/base/core/java/android/view/MotionEvent.java
@@ -1229,6 +1229,10 @@ public final class MotionEvent extends InputEvent implements Parcelable {
      * @see InputDevice#getMotionRange
      */
     public static final int AXIS_GENERIC_16 = 47;
+    public static final int AXIS_GENERIC_17 = 48;
+    public static final int AXIS_GENERIC_18 = 49;
+    public static final int AXIS_GENERIC_19 = 50;
+    public static final int AXIS_GENERIC_20 = 51;
 
     // NOTE: If you add a new axis here you must also add it to:
     //  native/include/android/input.h
@@ -1283,6 +1287,10 @@ public final class MotionEvent extends InputEvent implements Parcelable {
         names.append(AXIS_GENERIC_14, "AXIS_GENERIC_14");
         names.append(AXIS_GENERIC_15, "AXIS_GENERIC_15");
         names.append(AXIS_GENERIC_16, "AXIS_GENERIC_16");
+        names.append(AXIS_GENERIC_17, "AXIS_GENERIC_17");
+        names.append(AXIS_GENERIC_18, "AXIS_GENERIC_18");
+        names.append(AXIS_GENERIC_19, "AXIS_GENERIC_19");
+        names.append(AXIS_GENERIC_20, "AXIS_GENERIC_20");
     }
 
     /**
diff --git a/release/frameworks/native/include/android/input.h b/release/frameworks/native/include/android/input.h


+++ b/release/frameworks/native/include/android/input.h
@@ -747,6 +747,10 @@ enum {
      * The interpretation of a generic axis is device-specific.
      */
     AMOTION_EVENT_AXIS_GENERIC_16 = 47,
+    AMOTION_EVENT_AXIS_GENERIC_17 = 48,
+    AMOTION_EVENT_AXIS_GENERIC_18 = 49,
+    AMOTION_EVENT_AXIS_GENERIC_19 = 50,
+    AMOTION_EVENT_AXIS_GENERIC_20 = 51,
 
     // NOTE: If you add a new axis here you must also add it to several other files.
     //       Refer to frameworks/base/core/java/android/view/MotionEvent.java for the full list.
diff --git a/release/frameworks/native/include/input/Input.h b/release/frameworks/native/include/input/Input.h


+++ b/release/frameworks/native/include/input/Input.h
@@ -122,7 +122,7 @@ enum {
  * (We want at least 10 but some touch controllers obstensibly configured for 10 pointers
  * will occasionally emit 11.  There is not much harm making this constant bigger.)
  */
-#define MAX_POINTERS 16
+#define MAX_POINTERS 20
 
 /*
  * Maximum number of samples supported per motion event.
diff --git a/release/frameworks/native/include/input/InputEventLabels.h b/release/frameworks/native/include/input/InputEventLabels.h
old mode 100644
new mode 100755

+++ b/release/frameworks/native/include/input/InputEventLabels.h
@@ -372,6 +372,10 @@ static const InputEventLabel AXES[] = {
     DEFINE_AXIS(GENERIC_14),
     DEFINE_AXIS(GENERIC_15),
     DEFINE_AXIS(GENERIC_16),
+    DEFINE_AXIS(GENERIC_17),
+    DEFINE_AXIS(GENERIC_18),
+    DEFINE_AXIS(GENERIC_19),
+    DEFINE_AXIS(GENERIC_20),
 
     // NOTE: If you add a new axis here you must also add it to several other files.
     //       Refer to frameworks/base/core/java/android/view/MotionEvent.java for the full list.
diff --git a/version.h b/version.h

(END)

随着cpu越来越高效,现在商显(白板应用)要求触摸点数也是越来多,有的设备要求32点或者更多。

无论修改多少点基本上修改上面对应的文件即可。

相关推荐
alexhilton20 小时前
面向开发者的系统设计:像建筑师一样思考
android·kotlin·android jetpack
CYRUS_STUDIO1 天前
用 Frida 控制 Android 线程:kill 命令、挂起与恢复全解析
android·linux·逆向
CYRUS_STUDIO1 天前
Frida 实战:Android JNI 数组 (jobjectArray) 操作全流程解析
android·逆向
用户091 天前
Gradle Cache Entries 深度探索
android·java·kotlin
循环不息优化不止1 天前
安卓 View 绘制机制深度解析
android
叽哥1 天前
Kotlin学习第 9 课:Kotlin 实战应用:从案例到项目
android·java·kotlin
雨白2 天前
Java 线程通信基础:interrupt、wait 和 notifyAll 详解
android·java
诺诺Okami2 天前
Android Framework-Launcher-UI和组件
android
潘潘潘2 天前
Android线程间通信机制Handler介绍
android
潘潘潘2 天前
Android动态链接库So的加载
android