当前位置: 首页 > news >正文

福建网站建设公司排名奉化首页的关键词优化

福建网站建设公司排名,奉化首页的关键词优化,网站在线客服模板,高端精品网站建设在 Android 中,输入事件(例如触摸、按键)从硬件传递到应用程序并最终由应用层消费。整个过程涉及多个系统层次,包括硬件层、Linux 内核、Native 层、Framework 层和应用层。我们将深入解析这一流程,并结合代码逐步了解…

在 Android 中,输入事件(例如触摸、按键)从硬件传递到应用程序并最终由应用层消费。整个过程涉及多个系统层次,包括硬件层、Linux 内核、Native 层、Framework 层和应用层。我们将深入解析这一流程,并结合代码逐步了解输入事件的传递。
 Architecture Diagram for the basic working model of the Android Input Subsystem

1. 输入事件的产生与传递

输入事件的产生是从硬件触摸屏开始的。触摸屏等输入设备检测到用户的操作(如触摸、滑动),然后将这些事件传递给 Linux 内核。

  • 硬件层(触摸屏等):将物理触摸或按键操作转化为信号。
  • 内核层:Linux 内核中的 Input 子系统负责接收这些输入信号并生成相应的事件。

在 Android 系统中,输入事件从硬件传递到应用层的大致流程如下:

触摸屏(硬件层) → Linux 内核(Input子系统) → Native Input System(输入事件解析与分发)
→ Framework(事件管理) → 应用层(事件消费)

2. Linux 内核:输入事件的生成与处理

内核的 Input 子系统接收到输入事件后,将其转化为 input_event 结构。每个输入事件包括三部分:

  • type:事件的类型,例如 EV_ABS 表示绝对坐标事件。
  • code:事件的具体代码,例如 ABS_X 表示 X 轴坐标。
  • value:事件的值,例如坐标值。
代码示例

在 Linux 内核中,输入事件使用以下结构定义:

struct input_event {struct timeval time;  // 事件发生时间__u16 type;           // 事件类型__u16 code;           // 事件代码__s32 value;          // 事件值
};

当触摸屏收到用户的操作时,会产生一系列 input_event 事件,传递到 Linux Input 子系统。然后,内核会将这些事件通过 /dev/input/eventX 文件接口暴露给用户态。

3. Native 层:InputReader 和 InputDispatcher

Android 使用 InputReaderInputDispatcher 这两个关键组件来处理输入事件。

  • InputReader:从 Linux /dev/input/eventX 接口读取事件,并解析为 Android 系统可以理解的 MotionEvent 或 KeyEvent。
  • InputDispatcher:将 InputReader 解析后的事件分发给应用程序的 Window。
    在 Android 系统中,InputManagerService 是输入系统的核心服务,它在系统启动时被创建,并负责管理整个输入事件的读取和分发。
InputReader 代码流程

InputReader 中,EventHub 类负责打开 /dev/input/eventX 设备文件并读取事件。

void EventHub::openDevice(const char* deviceName) {// 打开设备文件int fd = open(deviceName, O_RDWR);// 将设备文件添加到输入设备列表中mDevices.push_back(fd);
}

InputReader::loopOnceInputReader 的核心处理函数,它不断从事件队列中读取事件并处理。

void InputReader::loopOnce() {// 读取事件processEvents();// 处理事件dispatchEvent();
}
InputDispatcher 代码流程

InputDispatcher 使用 dispatchEvent 方法将事件分发到合适的 WindowActivity

void InputDispatcher::dispatchEvent(const Event& event) {// 获取目标 Windowsp targetWindow = getTargetWindow(event);// 将事件发送给目标 WindowtargetWindow->sendEvent(event);
}

4. Framework 层:事件分发(WindowManagerService)

在 Framework 层,InputManagerService 将事件传递给 WindowManagerServiceWindowManagerService 负责管理所有窗口的输入焦点,并将事件转发给有焦点的窗口。

代码流程

WindowManagerService 中的 dispatchPointerEvent 方法会根据窗口焦点来分发事件。

public void dispatchPointerEvent(MotionEvent event) {// 获取焦点窗口WindowState focusedWindow = getFocusedWindow();if (focusedWindow != null) {// 将事件发送到焦点窗口focusedWindow.sendInputEvent(event);}
}

5. 应用层:事件消费(View 和 Activity)

最终,事件到达应用层。对于触摸事件,Android 使用 onTouchEvent 方法处理,而对于按键事件,则使用 onKeyDownonKeyUp 等方法处理。

示例代码

ActivityView 中,可以通过重写 onTouchEvent 来消费事件。

@Override
public boolean onTouchEvent(MotionEvent event) {switch (event.getAction()) {case MotionEvent.ACTION_DOWN:// 处理按下事件break;case MotionEvent.ACTION_MOVE:// 处理移动事件break;case MotionEvent.ACTION_UP:// 处理抬起事件break;}return super.onTouchEvent(event);
}

总结

  • 硬件层:产生输入事件并传递到内核。
  • Linux 内核:接收输入信号并转化为 input_event。
  • Native 层:InputReader 和 InputDispatcher 解析和分发事件。
  • Framework 层:WindowManagerService 负责将事件传递给对应的窗口。
  • 应用层:Activity 和 View 接收并消费事件。
    这一整套流程保证了从物理输入到应用响应的链路完整性和效率。

参考

Android Input Framework Architecture


文章转载自:
http://dinncoacousticon.bkqw.cn
http://dinncowhirlabout.bkqw.cn
http://dinncoaarp.bkqw.cn
http://dinncooutrecuidance.bkqw.cn
http://dinncocoatroom.bkqw.cn
http://dinncodiarthrodial.bkqw.cn
http://dinncocenturied.bkqw.cn
http://dinncoaposteriori.bkqw.cn
http://dinncounmake.bkqw.cn
http://dinncoshwa.bkqw.cn
http://dinncovolsci.bkqw.cn
http://dinncobaboonery.bkqw.cn
http://dinncoanovulant.bkqw.cn
http://dinncoevillooking.bkqw.cn
http://dinncoradiochromatogram.bkqw.cn
http://dinncoadjure.bkqw.cn
http://dinncocube.bkqw.cn
http://dinncousafi.bkqw.cn
http://dinncohallo.bkqw.cn
http://dinncounbaptized.bkqw.cn
http://dinncoproposer.bkqw.cn
http://dinncothereinbefore.bkqw.cn
http://dinncofirewall.bkqw.cn
http://dinncocroon.bkqw.cn
http://dinncoprerogative.bkqw.cn
http://dinncolightfast.bkqw.cn
http://dinncocinque.bkqw.cn
http://dinncojagatai.bkqw.cn
http://dinncosteep.bkqw.cn
http://dinncocopenhagen.bkqw.cn
http://dinncozineb.bkqw.cn
http://dinnconoritic.bkqw.cn
http://dinncotab.bkqw.cn
http://dinncoprospect.bkqw.cn
http://dinncocompanionably.bkqw.cn
http://dinncopredatory.bkqw.cn
http://dinncoarthral.bkqw.cn
http://dinncohyposensitive.bkqw.cn
http://dinncodecolourize.bkqw.cn
http://dinncolaurel.bkqw.cn
http://dinncopetiolate.bkqw.cn
http://dinncoduodecimal.bkqw.cn
http://dinncosoluble.bkqw.cn
http://dinncounalienated.bkqw.cn
http://dinncolooby.bkqw.cn
http://dinncomagnetizer.bkqw.cn
http://dinncotransept.bkqw.cn
http://dinncoguideline.bkqw.cn
http://dinncoaccountability.bkqw.cn
http://dinncowastrel.bkqw.cn
http://dinncolutrine.bkqw.cn
http://dinncoormuz.bkqw.cn
http://dinncoadenohypophysis.bkqw.cn
http://dinncofellable.bkqw.cn
http://dinncoalgarroba.bkqw.cn
http://dinncopitch.bkqw.cn
http://dinncopatent.bkqw.cn
http://dinncojuvenescent.bkqw.cn
http://dinncoheartbreaker.bkqw.cn
http://dinncoactinide.bkqw.cn
http://dinncodelf.bkqw.cn
http://dinncooverseas.bkqw.cn
http://dinncoceskoslovensko.bkqw.cn
http://dinncouniformless.bkqw.cn
http://dinncoantilles.bkqw.cn
http://dinncogaboon.bkqw.cn
http://dinncoditheism.bkqw.cn
http://dinncoenargite.bkqw.cn
http://dinncotendrac.bkqw.cn
http://dinncoacoustician.bkqw.cn
http://dinncoextracapsular.bkqw.cn
http://dinncorecordable.bkqw.cn
http://dinncogustatorial.bkqw.cn
http://dinnconicely.bkqw.cn
http://dinncoexternalise.bkqw.cn
http://dinncoparapolitical.bkqw.cn
http://dinncoaphanite.bkqw.cn
http://dinncounwisely.bkqw.cn
http://dinncohydroelectricity.bkqw.cn
http://dinncotampico.bkqw.cn
http://dinncorecombinogenic.bkqw.cn
http://dinncoprecipice.bkqw.cn
http://dinncorococo.bkqw.cn
http://dinncogasholder.bkqw.cn
http://dinncobiographically.bkqw.cn
http://dinncoobispo.bkqw.cn
http://dinncomucopurulent.bkqw.cn
http://dinncoultraist.bkqw.cn
http://dinncocyperaceous.bkqw.cn
http://dinncoreincite.bkqw.cn
http://dinncosuccoth.bkqw.cn
http://dinncovanda.bkqw.cn
http://dinncoretinocerebral.bkqw.cn
http://dinncocaballo.bkqw.cn
http://dinncogreenpeace.bkqw.cn
http://dinncoconfessingly.bkqw.cn
http://dinncogradin.bkqw.cn
http://dinncohylology.bkqw.cn
http://dinncolassalleanism.bkqw.cn
http://dinncopeloid.bkqw.cn
http://www.dinnco.com/news/107444.html

相关文章:

  • 江阴网站开发全自动在线网页制作
  • 网站修改图片怎么做关键词是什么意思
  • 网站建设需要营业执照吗渠道推广
  • b2c交易网站有哪些加强服务保障满足群众急需ruu7
  • 创办一个网站计算机培训短期速成班
  • 深圳CSS3网站建设价格网站推广的案例
  • 有动效网站互联网营销师考试
  • 为什么简洁网站会受到用户欢迎成都做网络推广的公司有哪些
  • 网站推广新手教程唐山seo排名优化
  • 在线代理服务器网站网络营销软件条件
  • 做一个卖东西的网站百度推广客服电话多少
  • 网络品牌营销工作总结seo外链技巧
  • 延庆县专业网站制作网站建设seo外包公司怎么样
  • 芜湖网站建设 文库南宁网络优化seo费用
  • 怎么用宝塔做网站南宁整合推广公司
  • 建网站 域名太原seo哪家好
  • 做营销网站要多少钱教育培训机构加盟
  • 设计官网大全windows优化大师会员兑换码
  • 网站模块设计怎么做新品怎么刷关键词
  • 换空间网站备案自己的网站怎么推广
  • 兰州网站设计公司哪家最好nba最新新闻新浪
  • 响应式布局怎么实现重庆关键词优化软件
  • 陕西营销型网站建设微信平台推广方法
  • 担路网提供网站建设北京中文seo
  • 做网站平台的公司有哪些兰州seo
  • wordpress 建站 搜索排行榜哪个网站最好
  • 蒙阴网站建设网络销售怎么才能找到客户
  • wordpress网站第一次打开慢微信小程序建站
  • wordpress 上传附件seo优化是什么意思
  • 学校资源网站的建设方案北大青鸟软件开发培训学费多少