Most visited

Recently visited

ExploreByTouchHelper

public abstract class ExploreByTouchHelper
extends AccessibilityDelegateCompat

java.lang.Object
   ↳ android.support.v4.view.AccessibilityDelegateCompat
     ↳ android.support.v4.widget.ExploreByTouchHelper


ExploreByTouchHelper是一个工具类,用于在自定义View实现可访问性支持,该自定义View代表View类逻辑项目的集合。 它扩展了AccessibilityNodeProviderCompat并简化了为辅助功能服务提供信息和管理辅助功能的许多方面。 该类当前不支持逻辑项目的层次结构。

客户应该重写此类上的抽象方法,并使用 setAccessibilityDelegate(View, AccessibilityDelegateCompat)将其附加到主机视图中:

 class MyCustomView extends View {
     private MyVirtualViewHelper mVirtualViewHelper;

     public MyCustomView(Context context, ...) {
         ...
         mVirtualViewHelper = new MyVirtualViewHelper(this);
         ViewCompat.setAccessibilityDelegate(this, mVirtualViewHelper);
     }

     @Override
     public boolean dispatchHoverEvent(MotionEvent event) {
       return mHelper.dispatchHoverEvent(this, event)
           || super.dispatchHoverEvent(event);
     }

     @Override
     public boolean dispatchKeyEvent(KeyEvent event) {
       return mHelper.dispatchKeyEvent(event)
           || super.dispatchKeyEvent(event);
     }

     @Override
     public boolean onFocusChanged(boolean gainFocus, int direction,
         Rect previouslyFocusedRect) {
       super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
       mHelper.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
     }
 }
 mAccessHelper = new MyExploreByTouchHelper(someView);
 ViewCompat.setAccessibilityDelegate(someView, mAccessHelper);
 

Summary

Constants

int HOST_ID

主机视图节点的虚拟节点标识符值。

int INVALID_ID

无效节点的虚拟节点标识符值。

Public constructors

ExploreByTouchHelper(View host)

构造一个新的帮助器,可以为指定的主机视图公开虚拟视图层次结构。

Public methods

final boolean clearKeyboardFocusForVirtualView(int virtualViewId)

尝试从虚拟视图中清除键盘焦点。

final boolean dispatchHoverEvent(MotionEvent event)

代表悬停主机视图中的事件。

final boolean dispatchKeyEvent(KeyEvent event)

从主机视图中委派关键事件。

final int getAccessibilityFocusedVirtualViewId()
AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View host)

获取用于管理以此视图为根的虚拟视图层次结构的提供者,并将其报告给探索窗口内容的 AccessibilityService

int getFocusedVirtualView()

此方法已弃用。 使用getAccessibilityFocusedVirtualViewId()

final int getKeyboardFocusedVirtualViewId()
final void invalidateRoot()

通知辅助功能框架父视图的属性已更改。

final void invalidateVirtualView(int virtualViewId)

通知可访问性框架,特定项目的属性已更改。

final void invalidateVirtualView(int virtualViewId, int changeTypes)

通知可访问性框架,特定项目的属性已更改。

final void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect)

代表关注主机视图中的更改。

void onInitializeAccessibilityEvent(View host, AccessibilityEvent event)

使用有关作为事件源的主机View的信息初始化 AccessibilityEvent

void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info)

使用有关主机视图的信息初始化 AccessibilityNodeInfoCompat

final boolean requestKeyboardFocusForVirtualView(int virtualViewId)

尝试将键盘焦点置于虚拟视图。

final boolean sendEventForVirtualView(int virtualViewId, int eventType)

使用有关项目的信息填充指定类型的事件,并尝试通过视图层次结构发送它。

Protected methods

abstract int getVirtualViewAt(float x, float y)

提供视图相对坐标和逻辑项目之间的映射。

abstract void getVisibleVirtualViews(List<Integer> virtualViewIds)

用视图的可见项填充列表。

abstract boolean onPerformActionForVirtualView(int virtualViewId, int action, Bundle arguments)

对与虚拟视图标识符关联的项目执行指定的辅助功能操作。

void onPopulateEventForHost(AccessibilityEvent event)

用关于主机视图的信息填充 AccessibilityEvent

void onPopulateEventForVirtualView(int virtualViewId, AccessibilityEvent event)

用指定项目的信息填充 AccessibilityEvent

void onPopulateNodeForHost(AccessibilityNodeInfoCompat node)

用关于主机视图的信息填充 AccessibilityNodeInfoCompat

abstract void onPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfoCompat node)

用关于指定项目的信息填充 AccessibilityNodeInfoCompat

void onVirtualViewKeyboardFocusChanged(int virtualViewId, boolean hasFocus)

当虚拟视图的焦点状态改变时调用。

Inherited methods

From class android.support.v4.view.AccessibilityDelegateCompat
From class java.lang.Object

Constants

HOST_ID

int HOST_ID

主机视图节点的虚拟节点标识符值。

常量值:-1(0xffffffff)

INVALID_ID

int INVALID_ID

无效节点的虚拟节点标识符值。

常量值:-2147483648(0x80000000)

Public constructors

ExploreByTouchHelper

ExploreByTouchHelper (View host)

构造一个新的帮助器,可以为指定的主机视图公开虚拟视图层次结构。

Parameters
host View: view whose virtual view hierarchy is exposed by this helper

Public methods

clearKeyboardFocusForVirtualView

boolean clearKeyboardFocusForVirtualView (int virtualViewId)

尝试从虚拟视图中清除键盘焦点。

Parameters
virtualViewId int: the identifier of the virtual view from which to clear keyboard focus
Returns
boolean whether this virtual view actually cleared keyboard focus

dispatchHoverEvent

boolean dispatchHoverEvent (MotionEvent event)

代表悬停主机视图中的事件。

当启用了触摸浏览功能时,将鼠标悬停 MotionEvent s到虚拟视图层次结构。

应通过覆盖主机视图的 dispatchHoverEvent(MotionEvent)方法调用此方法:

@Override
 public boolean dispatchHoverEvent(MotionEvent event) {
   return mHelper.dispatchHoverEvent(this, event)
       || super.dispatchHoverEvent(event);
 }
 

Parameters
event MotionEvent: The hover event to dispatch to the virtual view hierarchy.
Returns
boolean Whether the hover event was handled.

dispatchKeyEvent

boolean dispatchKeyEvent (KeyEvent event)

从主机视图中委派关键事件。

应通过覆盖主机视图的 dispatchKeyEvent(KeyEvent)方法调用此方法:

@Override
 public boolean dispatchKeyEvent(KeyEvent event) {
   return mHelper.dispatchKeyEvent(event)
       || super.dispatchKeyEvent(event);
 }
 

Parameters
event KeyEvent
Returns
boolean

getAccessibilityFocusedVirtualViewId

int getAccessibilityFocusedVirtualViewId ()

Returns
int the identifier of the virtual view that has accessibility focus or INVALID_ID if no virtual view has accessibility focus

getAccessibilityNodeProvider

AccessibilityNodeProviderCompat getAccessibilityNodeProvider (View host)

获取用于管理以此视图为根的虚拟视图层次结构的提供程序,并报告给探索窗口内容的 AccessibilityService

对于未设置可访问性委托的情况,默认实现的行为为 ViewCompat#getAccessibilityNodeProvider(View)

Parameters
host View
Returns
AccessibilityNodeProviderCompat The provider.

getFocusedVirtualView

int getFocusedVirtualView ()

此方法已弃用。
使用getAccessibilityFocusedVirtualViewId()

返回当前可访问性焦点项目的虚拟视图ID。

Returns
int the identifier of the virtual view that has accessibility focus or INVALID_ID if no virtual view has accessibility focus

getKeyboardFocusedVirtualViewId

int getKeyboardFocusedVirtualViewId ()

Returns
int the identifier of the virtual view that has keyboard focus or INVALID_ID if no virtual view has keyboard focus

invalidateRoot

void invalidateRoot ()

通知辅助功能框架父视图的属性已更改。

添加或删除父视图中的项目后,您 必须调用此方法。

invalidateVirtualView

void invalidateVirtualView (int virtualViewId)

通知可访问性框架,特定项目的属性已更改。

必须在更改 onPopulateNodeForVirtualView(int, AccessibilityNodeInfoCompat)设置的任何属性后调用此方法。

Parameters
virtualViewId int: the virtual view id to invalidate, or HOST_ID to invalidate the root view

也可以看看:

invalidateVirtualView

void invalidateVirtualView (int virtualViewId, 
                int changeTypes)

通知可访问性框架,特定项目的属性已更改。

更改 onPopulateNodeForVirtualView(int, AccessibilityNodeInfoCompat)设置的任何属性后, 必须调用此方法。

Parameters
virtualViewId int: the virtual view id to invalidate, or HOST_ID to invalidate the root view
changeTypes int: the bit mask of change types. May be 0 for the default (undefined) change type or one or more of:

onFocusChanged

void onFocusChanged (boolean gainFocus, 
                int direction, 
                Rect previouslyFocusedRect)

代表关注主机视图中的更改。

应通过覆盖主机视图的 onFocusChanged(boolean, int, Rect)方法调用此方法:

@Override
 public boolean onFocusChanged(boolean gainFocus, int direction,
     Rect previouslyFocusedRect) {
   super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
   mHelper.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
 }
 

Parameters
gainFocus boolean
direction int
previouslyFocusedRect Rect

onInitializeAccessibilityEvent

void onInitializeAccessibilityEvent (View host, 
                AccessibilityEvent event)

使用有关作为事件源的主机View的信息初始化 AccessibilityEvent

对于未设置可访问性委托的情况,默认实现的行为为 ViewCompat#onInitalizeAccessibilityEvent(View v, AccessibilityEvent event)

Parameters
host View: The View hosting the delegate.
event AccessibilityEvent: The event to initialize.

onInitializeAccessibilityNodeInfo

void onInitializeAccessibilityNodeInfo (View host, 
                AccessibilityNodeInfoCompat info)

使用有关主机视图的信息初始化 AccessibilityNodeInfoCompat

对于没有设置可访问性委托的情况,默认实现的行为为 ViewCompat#onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfoCompat)

Parameters
host View: The View hosting the delegate.
info AccessibilityNodeInfoCompat: The instance to initialize.

requestKeyboardFocusForVirtualView

boolean requestKeyboardFocusForVirtualView (int virtualViewId)

尝试将键盘焦点置于虚拟视图。

Parameters
virtualViewId int: the identifier of the virtual view on which to place keyboard focus
Returns
boolean whether this virtual view actually took keyboard focus

sendEventForVirtualView

boolean sendEventForVirtualView (int virtualViewId, 
                int eventType)

使用有关项目的信息填充指定类型的事件,并尝试通过视图层次结构发送它。

在执行通常触发辅助功能事件的用户操作(例如单击某个项目)后,应该调用此方法。

public void performItemClick(T item) {
   ...
   sendEventForVirtualViewId(item.id, AccessibilityEvent.TYPE_VIEW_CLICKED);
 }
 

Parameters
virtualViewId int: the identifier of the virtual view for which to send an event
eventType int: the type of event to send
Returns
boolean true if the event was sent successfully, false otherwise

Protected methods

getVirtualViewAt

int getVirtualViewAt (float x, 
                float y)

提供视图相对坐标和逻辑项目之间的映射。

Parameters
x float: The view-relative x coordinate
y float: The view-relative y coordinate
Returns
int virtual view identifier for the logical item under coordinates (x,y) or HOST_ID if there is no item at the given coordinates

getVisibleVirtualViews

void getVisibleVirtualViews (List<Integer> virtualViewIds)

用视图的可见项填充列表。 virtualViewIds的项目virtualViewIds规定了辅助焦点遍历的顺序。

Parameters
virtualViewIds List: The list to populate with visible items

onPerformActionForVirtualView

boolean onPerformActionForVirtualView (int virtualViewId, 
                int action, 
                Bundle arguments)

对与虚拟视图标识符关联的项目执行指定的辅助功能操作。 有关更多信息,请参阅performAction(int, Bundle)

实现 必须处理在 onPopulateNodeForVirtualView(int, AccessibilityNodeInfoCompat)手动添加的任何操作。

辅助类自动处理由 ACTION_ACCESSIBILITY_FOCUSACTION_CLEAR_ACCESSIBILITY_FOCUS操作产生的焦点管理。

Parameters
virtualViewId int: The virtual view identifier of the item on which to perform the action
action int: The accessibility action to perform
arguments Bundle: (Optional) A bundle with additional arguments, or null
Returns
boolean true if the action was performed

onPopulateEventForHost

void onPopulateEventForHost (AccessibilityEvent event)

用关于主机视图的信息填充 AccessibilityEvent

默认实现是无操作。

Parameters
event AccessibilityEvent: the event to populate with information about the host view

onPopulateEventForVirtualView

void onPopulateEventForVirtualView (int virtualViewId, 
                AccessibilityEvent event)

用关于指定项目的信息填充 AccessibilityEvent

辅助类根据 onPopulateNodeForVirtualView(int, AccessibilityNodeInfoCompat)设置的值自动填充以下字段,但实现可以选择覆盖它们:

以下必填字段由帮助类自动填充,并且可能不会被覆盖:

Parameters
virtualViewId int: The virtual view id for the item for which to populate the event
event AccessibilityEvent: The event to populate

onPopulateNodeForHost

void onPopulateNodeForHost (AccessibilityNodeInfoCompat node)

用关于主机视图的信息填充 AccessibilityNodeInfoCompat

默认实现是无操作。

Parameters
node AccessibilityNodeInfoCompat: the node to populate with information about the host view

onPopulateNodeForVirtualView

void onPopulateNodeForVirtualView (int virtualViewId, 
                AccessibilityNodeInfoCompat node)

用关于指定项目的信息填充 AccessibilityNodeInfoCompat

实现 必须填充以下必填字段:

辅助类自动使用默认值填充以下字段,但实现可以选择性地覆盖它们:

以下必填字段由帮助类自动填充,并且可能不会被覆盖:

此外,辅助类自动加入适当的处理键盘焦点和无障碍重点管理ACTION_FOCUSACTION_CLEAR_FOCUSACTION_ACCESSIBILITY_FOCUS ,或ACTION_CLEAR_ACCESSIBILITY_FOCUS行动。 实现绝不能手动添加这些操作。

辅助类还会自动修改父级和屏幕相对边界,以反映其父级中可见项的部分。

Parameters
virtualViewId int: The virtual view identifier of the item for which to populate the node
node AccessibilityNodeInfoCompat: The node to populate

onVirtualViewKeyboardFocusChanged

void onVirtualViewKeyboardFocusChanged (int virtualViewId, 
                boolean hasFocus)

当虚拟视图的焦点状态改变时调用。

Parameters
virtualViewId int: the virtual view identifier
hasFocus boolean: true if the view has focus, false otherwise

Hooray!