AdapterViewProtocol

public interface AdapterViewProtocol

android.support.test.espresso.action.AdapterViewProtocol


与AdapterViews交互的间接可悲的必要层。

一般来说,任何子类都应该尊重其超类的契约和行为。 否则就不可能一般地处理所有声称共享一个超类型的对象 - 你需要特殊情况来为每个子类型执行超类型“拥有”的相同操作。 '是 - 一个'关系被打破。

Android使用ExpandableListView打破Liskov替换原则 - 您无法使用getAdapter(),getItemAtPosition()和其他在ExpandableListView上适用于AdapterView的方法,因为ExpandableListView不是adapterView - 它们只是共享大量代码。

这个接口的存在是为了解决这个问题(可悲的是也在其他项目中复制),并让实现者将Espresso的需求和AdapterView的操作转化为对给定子类型和上下文有意义的调用。

如果您必须实现这个功能才能与您自己的项目定义的小部件对话 - 我很抱歉。

Summary

Nested classes

class AdapterViewProtocol.AdaptedData

一个持有者,将AdapterView中的数据对象与AdapterViewProtocol可以用来强制该数据对象渲染为适配器视图的子代或更深层后代的标记相关联。

interface AdapterViewProtocol.DataFunction

执行getData()时应用的自定义函数。

Public methods

abstract Iterable<AdapterViewProtocol.AdaptedData> getDataInAdapterView(AdapterView<? extends Adapter> adapterView)

返回AdapterViewProtocol在给定AdapterView中可以找到的所有数据。

abstract Optional<AdapterViewProtocol.AdaptedData> getDataRenderedByView(AdapterView<? extends Adapter> adapterView, View descendantView)

如果可能,则返回此特定视图正在呈现的数据对象。

abstract boolean isDataRenderedWithinAdapterView(AdapterView<? extends Adapter> adapterView, AdapterViewProtocol.AdaptedData adaptedData)

指示adapterView中是否存在呈现此数据的后代视图。

abstract void makeDataRenderedWithinAdapterView(AdapterView<? extends Adapter> adapterView, AdapterViewProtocol.AdaptedData data)

请求在此AdapterView中保存的特定数据片段实际上由其呈现。

Public methods

getDataInAdapterView

Iterable<AdapterViewProtocol.AdaptedData> getDataInAdapterView (AdapterView<? extends Adapter> adapterView)

返回AdapterViewProtocol在给定AdapterView中可以找到的所有数据。

此方法返回的任何AdaptedData都可以传递给makeDataRenderedWithinView,并且实现应该使AdapterView将该数据项引入屏幕。

Parameters
adapterView AdapterView: the AdapterView we want to interrogate the contents of.
Returns
Iterable<AdapterViewProtocol.AdaptedData> an Iterable of AdaptedDatas representing all data the implementation sees in this view
Throws
IllegalArgumentException if the implementation doesn't know how to manipulate the given adapter view.

getDataRenderedByView

Optional<AdapterViewProtocol.AdaptedData> getDataRenderedByView (AdapterView<? extends Adapter> adapterView, 
                View descendantView)

如果可能,则返回此特定视图正在呈现的数据对象。

预计实现将在AdapterView中的数据与遵循以下条件的AdapterView的后代视图之间建立关系:

例如 - 如果PersonObject被渲染到:

LinearLayout ImageView picture TextView firstName TextView lastName

预计getDataRenderedByView(适配器,LinearLayout)将返回PersonObject。 如果使用TextView或ImageView调用它,它将返回Object.absent()。

Parameters
adapterView AdapterView: the adapterview hosting the data.
descendantView View: a view which is a child, grand-child, or deeper descendant of adapterView
Returns
Optional<AdapterViewProtocol.AdaptedData> an optional data object the descendant view is rendering.
Throws
IllegalArgumentException if this protocol cannot interrogate this class of adapterView

isDataRenderedWithinAdapterView

boolean isDataRenderedWithinAdapterView (AdapterView<? extends Adapter> adapterView, 
                AdapterViewProtocol.AdaptedData adaptedData)

指示adapterView中是否存在呈现此数据的后代视图。

Parameters
adapterView AdapterView: the AdapterView hosting this data.
adaptedData AdapterViewProtocol.AdaptedData: the data we are checking the display state for.
Returns
boolean true if the data is rendered by a view in the adapterView, false otherwise.

makeDataRenderedWithinAdapterView

void makeDataRenderedWithinAdapterView (AdapterView<? extends Adapter> adapterView, 
                AdapterViewProtocol.AdaptedData data)

请求在此AdapterView中保存的特定数据片段实际上由其呈现。

调用此方法后,它预期会存在调用getDataRenderedByView(adapterView,descView).get()== data.data的adapterView的某些后代视图。

Note: this need not happen immediately. EG: an implementor handling ListView may call listView.smoothScrollToPosition(data.opaqueToken) - which kicks off an animated scroll over the list to the given position. The animation may be in progress after this call returns. The only guarantee is that eventually - with no further interaction necessary - this data item will be rendered as a child or deeper descendant of this AdapterView.

Parameters
adapterView AdapterView: the adapterView hosting the data.
data AdapterViewProtocol.AdaptedData: an AdaptedData instance retrieved by a prior call to getDataInAdapterView
Throws
IllegalArgumentException if this protocol cannot manipulate adapterView or if data is not owned by this AdapterViewProtocol.