Android TIF 为制造商提供了一个标准 API,供他们创建能够控制 Android TV 的输入模块,并让他们可以通过 TV Input(电视输入源)发布的元数据来搜索和推荐直播电视内容。
具体介绍可以参考官文TV Input Framework | Android Open Source Project (google.cn)
对于TIF的按键处理流程,官文中也有介绍,比较简单,如下图所示,当实际遇到问题时就不够用了,所以在这里梳理了一下按键涉及到的code flow。
首先,推荐先阅读Android——按键事件KeyEvent的分发处理流程解析_小欣儿的专栏-CSDN博客_android按键事件分发流程这篇文章,理解一般情况下按键的处理流程。
接下来进入正文,对于TIF框架中,与用户按键交互的时TvView这个class,按键都是通过其中的dispatchKeyEvent()传递给TvInputService.Session的,可以看一下它的注释。
/**
* Displays TV contents. The TvView class provides a high level interface for applications to show
* TV programs from various TV sources that implement {@link TvInputService}. (Note that the list of
* TV inputs available on the system can be obtained by calling
* {@link TvInputManager#getTvInputList() TvInputManager.getTvInputList()}.)
*
* <p>Once the application supplies the URI for a specific TV channel to {@link #tune}
* method, it takes care of underlying service binding (and unbinding if the current TvView is
* already bound to a service) and automatically allocates/deallocates resources needed. In addition
* to a few essential methods to control how the contents are presented, it also provides a way to
* dispatch input events to the connected TvInputService in order to enable custom key actions for
* the TV input.
*/
调用TvView中的dispatchKeyEvent的形式也分几种:
- TvView本身可以获取焦点,则默认自动走Activity:dispatchKeyEvent