public interface AdapterViewProtocol
Generally any subclass should respect the contracts and behaviors of its superclass. Otherwise it becomes impossible to work generically with objects that all claim to share a supertype - you need special cases to perform the same operation 'owned' by the supertype for each sub-type. The 'is - a' relationship is broken.
Android breaks the Liskov substitution principal with ExpandableListView - you can't use getAdapter(), getItemAtPosition(), and other methods common to AdapterViews on an ExpandableListView because an ExpandableListView isn't an adapterView - they just share a lot of code.
This interface exists to work around this wart (which sadly is copied in other projects too) and lets the implementor translate Espresso's needs and manipulations of the AdapterView into calls that make sense for the given subtype and context.
If you have to implement this to talk to widgets your own project defines - I'm sorry.
Modifier and Type | Interface and Description |
---|---|
static class |
AdapterViewProtocol.AdaptedData
A holder that associates a data object from an AdapterView with a token the
AdapterViewProtocol can use to force that data object to be rendered as a child or deeper
descendant of the adapter view.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Iterable<AdapterViewProtocol.AdaptedData> |
getDataInAdapterView(android.widget.AdapterView<? extends android.widget.Adapter> adapterView)
Returns all data this AdapterViewProtocol can find within the given AdapterView.
|
|
getDataRenderedByView(android.widget.AdapterView<? extends android.widget.Adapter> adapterView,
android.view.View descendantView)
Returns the data object this particular view is rendering if possible.
|
boolean |
isDataRenderedWithinAdapterView(android.widget.AdapterView<? extends android.widget.Adapter> adapterView,
AdapterViewProtocol.AdaptedData adaptedData)
Indicates whether or not there now exists a descendant view within adapterView that
is rendering this data.
|
void |
makeDataRenderedWithinAdapterView(android.widget.AdapterView<? extends android.widget.Adapter> adapterView,
AdapterViewProtocol.AdaptedData data)
Requests that a particular piece of data held in this AdapterView is actually rendered by it.
|
java.lang.Iterable<AdapterViewProtocol.AdaptedData> getDataInAdapterView(android.widget.AdapterView<? extends android.widget.Adapter> adapterView)
Any AdaptedData returned by this method can be passed to makeDataRenderedWithinView and the implementation should make the AdapterView bring that data item onto the screen.
adapterView
- the AdapterView we want to interrogate the contents of.Iterable
of AdaptedDatas representing all data the implementation sees in
this viewjava.lang.IllegalArgumentException
- if the implementation doesn't know how to manipulate the given
adapter view.getDataRenderedByView(android.widget.AdapterView<? extends android.widget.Adapter> adapterView, android.view.View descendantView)
Implementations are expected to create a relationship between the data in the AdapterView and the descendant views of the AdapterView that obeys the following conditions:
For example - if a PersonObject is rendered into:
LinearLayout
ImageView picture
TextView firstName
TextView lastName
It would be expected that getDataRenderedByView(adapter, LinearLayout) would return the PersonObject. If it were called instead with the TextView or ImageView it would return Object.absent().
adapterView
- the adapterview hosting the data.descendantView
- a view which is a child, grand-child, or deeper descendant of adapterViewjava.lang.IllegalArgumentException
- if this protocol cannot interrogate this class of adapterViewvoid makeDataRenderedWithinAdapterView(android.widget.AdapterView<? extends android.widget.Adapter> adapterView, AdapterViewProtocol.AdaptedData data)
After calling this method it expected that there will exist some descendant view of adapterView for which calling getDataRenderedByView(adapterView, descView).get() == data.data is true.
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.
adapterView
- the adapterView hosting the data.data
- an AdaptedData instance retrieved by a prior call to getDataInAdapterViewjava.lang.IllegalArgumentException
- if this protocol cannot manipulate adapterView or if data is
not owned by this AdapterViewProtocol.boolean isDataRenderedWithinAdapterView(android.widget.AdapterView<? extends android.widget.Adapter> adapterView, AdapterViewProtocol.AdaptedData adaptedData)
adapterView
- the AdapterView hosting this data.adaptedData
- the data we are checking the display state for.