ItemListController
public
class
ItemListController
extends Object
java.lang.Object | |
↳ | com.google.android.libraries.car.app.testing.model.ItemListController |
A controller that allows testing of an ItemList
.
This controller allows:
- Retrieving all
Item
s in theItemList
. - Retrieving
Item
s by theirtitle
. - Getting the index of the currently selected
Item
. - Selecting a specific
Item
as if the user selected it. - Selecting a
Item
by an index as if the user selected it. - Scrolling the
ItemList
up and down as if the user did so. - Verifying if the
ItemList
is set as selectable. - Getting the no items message set via
ItemList.Builder.setNoItemsMessage(CharSequence)
.
Summary
Public methods | |
---|---|
ItemList
|
get()
Retrieves the |
<T extends ItemController<? extends Item>>
T
|
getItemByTitle(String title, Class<T> itemClass)
Retrieves the first |
List<ItemController<? extends Item>>
|
getItems()
Retrieves all |
String
|
getNoItemsMessage()
Retrieves the |
int
|
getSelectedIndex()
Retrieves index of the currently selected |
static
ItemListController
|
of(ItemList itemList)
Creates an |
void
|
scrollDown()
Performs callbacks as if the user scrolled down the |
void
|
scrollUp()
Performs callbacks as if the user scrolled up the |
void
|
select(Item item)
Performs the expected callback given a user selection on the provided |
void
|
select(int index)
Performs the expected callback given a user selection on the |
Inherited methods | |
---|---|
Public methods
get
public ItemList get ()
Retrieves the ItemList
that this controller is controlling.
Returns | |
---|---|
ItemList |
getItemByTitle
public T getItemByTitle (String title, Class<T> itemClass)
Retrieves the first ItemController
in the list that has the given title as its title,
or null
if none are found.
Parameters | |
---|---|
title |
String |
itemClass |
Class |
Returns | |
---|---|
T |
getItems
public List<ItemController<? extends Item>> getItems ()
Retrieves all ItemController
s in the ItemList
.
Returns | |
---|---|
List<ItemController<? extends Item>> |
getNoItemsMessage
public String getNoItemsMessage ()
Retrieves the noItemsMessage
set via ItemList.Builder.setNoItemsMessage(CharSequence)
, or
null
if it is not present.
The value returned is the CharSequence.toString()
for the text provided.
Returns | |
---|---|
String |
getSelectedIndex
public int getSelectedIndex ()
Retrieves index of the currently selected Item
.
Returns | |
---|---|
int |
of
public static ItemListController of (ItemList itemList)
Creates an ItemListController
to control an ItemList
for testing.
Parameters | |
---|---|
itemList |
ItemList |
Returns | |
---|---|
ItemListController |
scrollDown
public void scrollDown ()
Performs callbacks as if the user scrolled down the ItemList
on the actual car screen.
This will generate a callback to the ItemList.OnItemVisibilityChangedListener
provided via
ItemList.Builder.setOnItemsVisibilityChangeListener(ItemList.OnItemVisibilityChangedListener)
.
If the ItemList
is already scrolled to the bottom, nothing will happen.
For testing purposes, the virtual car screen fits two Item
s per page.
scrollUp
public void scrollUp ()
Performs callbacks as if the user scrolled up the ItemList
on the actual car screen.
This will generate a callback to the ItemList.OnItemVisibilityChangedListener
provided via
ItemList.Builder.setOnItemsVisibilityChangeListener(ItemList.OnItemVisibilityChangedListener)
.
If the ItemList
is already scrolled to the top, nothing will happen.
For testing purposes, the virtual car screen fits two Item
s per page.
select
public void select (Item item)
Performs the expected callback given a user selection on the provided Item
.
This will generate a callback to the ItemList.OnSelectedListener
provided via ItemList.Builder.setSelectable(ItemList.OnSelectedListener)
. *
Parameters | |
---|---|
item |
Item |
Throws | |
---|---|
IllegalArgumentException |
if item is not in the ItemList . |
IllegalStateException |
if the ItemList does not have an ItemList.OnSelectedListener , or is not selectable.
|
select
public void select (int index)
Performs the expected callback given a user selection on the Item
at index
.
This will generate a callback to the ItemList.OnSelectedListener
provided via ItemList.Builder.setSelectable(ItemList.OnSelectedListener)
.
Parameters | |
---|---|
index |
int |
Throws | |
---|---|
IllegalArgumentException |
if no Item exists at index index in the ItemList . |
IllegalStateException |
if the ItemList does not have an ItemList.OnSelectedListener , or is not selectable.
|