Package icyllis.modernui.widget
Class ListPopupWindow
java.lang.Object
icyllis.modernui.widget.ListPopupWindow
- All Implemented Interfaces:
ShowableListMenu
- Direct Known Subclasses:
MenuPopupWindow
A ListPopupWindow anchors itself to a host view and displays a
list of choices.
ListPopupWindow contains a number of tricky behaviors surrounding positioning, scrolling parents to fit the dropdown, interacting sanely with the IME if present, and others.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The provided prompt view should appear above list content.static final int
The provided prompt view should appear below list content. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Clear any current list selection.void
dismiss()
Dismiss the popup window.void
Remove existing exit transition from PopupWindow and force immediate dismissal.Returns the view that will be used to anchor this popup.Returns bounds which are used as a popup's epicenter of the enter and exit transitions.int
int
int
long
int
int
int
getWidth()
boolean
boolean
isModal()
Returns whether the popup window will be modal when shown.boolean
boolean
performItemClick
(int position) Perform an item click operation on the specified list adapter position.void
postShow()
Post ashow()
call to the UI thread.void
setAdapter
(ListAdapter adapter) Sets the adapter that provides the data and the views to represent the data in this popup window.void
setAnchorView
(View anchor) Sets the popup's anchor view.void
Sets a drawable to be the background for the popup window.void
setContentWidth
(int width) Sets the width of the popup window by the size of its content.void
setDropDownAlwaysVisible
(boolean dropDownAlwaysVisible) Sets whether the drop-down should remain visible under certain conditions.void
setDropDownGravity
(int gravity) Set the gravity of the dropdown list.void
setEpicenterBounds
(Rect bounds) Specifies the anchor-relative bounds of the popup's transition epicenter.void
setForceIgnoreOutsideTouch
(boolean forceIgnoreOutsideTouch) Forces outside touches to be ignored.void
setHeight
(int height) Sets the height of the popup window in pixels.void
setHorizontalOffset
(int offset) Set the horizontal offset of this popup from its anchor view in pixels.void
setListSelector
(Drawable selector) Sets a drawable to use as the list item selector.void
setModal
(boolean modal) Set whether this window should be modal when shown.void
Set a listener to receive a callback when the popup is dismissed.void
setOnItemClickListener
(AdapterView.OnItemClickListener clickListener) Sets a listener to receive events when a list item is clicked.void
setOnItemSelectedListener
(AdapterView.OnItemSelectedListener selectedListener) Sets a listener to receive events when a list item is selected.void
setOverlapAnchor
(boolean overlap) void
setPromptPosition
(int position) Set where the optional prompt view should appear.void
setPromptView
(View prompt) Set a view to act as a user prompt for this popup window.void
setSelection
(int position) Set the selected position of the list.void
setVerticalOffset
(int offset) Set the vertical offset of this popup from its anchor view in pixels.void
setWidth
(int width) Sets the width of the popup window in pixels.void
show()
Show the popup list.
-
Field Details
-
POSITION_PROMPT_ABOVE
public static final int POSITION_PROMPT_ABOVEThe provided prompt view should appear above list content.- See Also:
-
POSITION_PROMPT_BELOW
public static final int POSITION_PROMPT_BELOWThe provided prompt view should appear below list content.- See Also:
-
-
Constructor Details
-
ListPopupWindow
-
-
Method Details
-
setAdapter
Sets the adapter that provides the data and the views to represent the data in this popup window.- Parameters:
adapter
- The adapter to use to create this window's content.
-
setPromptPosition
public void setPromptPosition(int position) Set where the optional prompt view should appear. The default isPOSITION_PROMPT_ABOVE
.- Parameters:
position
- A position constant declaring where the prompt should be displayed.- See Also:
-
getPromptPosition
public int getPromptPosition()- Returns:
- Where the optional prompt view should appear.
- See Also:
-
setModal
public void setModal(boolean modal) Set whether this window should be modal when shown.If a popup window is modal, it will receive all touch and key input. If the user touches outside the popup window's content area the popup window will be dismissed.
- Parameters:
modal
-true
if the popup window should be modal,false
otherwise.
-
isModal
public boolean isModal()Returns whether the popup window will be modal when shown.- Returns:
true
if the popup window will be modal,false
otherwise.
-
setForceIgnoreOutsideTouch
public void setForceIgnoreOutsideTouch(boolean forceIgnoreOutsideTouch) Forces outside touches to be ignored. Normally ifisDropDownAlwaysVisible()
is false, we allow outside touch to dismiss the dropdown. If this is set to true, then we ignore outside touch even when the drop down is not set to always visible. -
setDropDownAlwaysVisible
public void setDropDownAlwaysVisible(boolean dropDownAlwaysVisible) Sets whether the drop-down should remain visible under certain conditions.The drop-down will occupy the entire screen below
getAnchorView()
regardless of the size or content of the list.getBackground()
will fill any space that is not used by the list.- Parameters:
dropDownAlwaysVisible
- Whether to keep the drop-down visible.
-
isDropDownAlwaysVisible
public boolean isDropDownAlwaysVisible()- Returns:
- Whether the drop-down is visible under special conditions.
-
setListSelector
Sets a drawable to use as the list item selector.- Parameters:
selector
- List selector drawable to use in the popup.
-
getBackground
- Returns:
- The background drawable for the popup window.
-
setBackgroundDrawable
Sets a drawable to be the background for the popup window.- Parameters:
d
- A drawable to set as the background.
-
getAnchorView
Returns the view that will be used to anchor this popup.- Returns:
- The popup's anchor view
-
setAnchorView
Sets the popup's anchor view. This popup will always be positioned relative to the anchor view when shown.- Parameters:
anchor
- The view to use as an anchor.
-
getHorizontalOffset
public int getHorizontalOffset()- Returns:
- The horizontal offset of the popup from its anchor in pixels.
-
setHorizontalOffset
public void setHorizontalOffset(int offset) Set the horizontal offset of this popup from its anchor view in pixels.- Parameters:
offset
- The horizontal offset of the popup from its anchor.
-
getVerticalOffset
public int getVerticalOffset()- Returns:
- The vertical offset of the popup from its anchor in pixels.
-
setVerticalOffset
public void setVerticalOffset(int offset) Set the vertical offset of this popup from its anchor view in pixels.- Parameters:
offset
- The vertical offset of the popup from its anchor.
-
setEpicenterBounds
Specifies the anchor-relative bounds of the popup's transition epicenter.- Parameters:
bounds
- anchor-relative bounds, ornull
to use default epicenter- See Also:
-
getEpicenterBounds
Returns bounds which are used as a popup's epicenter of the enter and exit transitions.- Returns:
- bounds relative to anchor view, or
null
if not set - See Also:
-
setDropDownGravity
public void setDropDownGravity(int gravity) Set the gravity of the dropdown list. This is commonly used to set gravity to START or END for alignment with the anchor.- Parameters:
gravity
- Gravity value to use
-
getWidth
public int getWidth()- Returns:
- The width of the popup window in pixels.
-
setWidth
public void setWidth(int width) Sets the width of the popup window in pixels. Can also beViewGroup.LayoutParams.MATCH_PARENT
orViewGroup.LayoutParams.WRAP_CONTENT
.- Parameters:
width
- Width of the popup window.
-
setContentWidth
public void setContentWidth(int width) Sets the width of the popup window by the size of its content. The final width may be larger to accommodate styled window dressing.- Parameters:
width
- Desired width of content in pixels.
-
getHeight
public int getHeight()- Returns:
- The height of the popup window in pixels.
-
setHeight
public void setHeight(int height) Sets the height of the popup window in pixels. Can also beViewGroup.LayoutParams.MATCH_PARENT
.- Parameters:
height
- Height of the popup window must be a positive value,ViewGroup.LayoutParams.MATCH_PARENT
, orViewGroup.LayoutParams.WRAP_CONTENT
.- Throws:
IllegalArgumentException
- if height is set to negative value
-
setOnItemClickListener
Sets a listener to receive events when a list item is clicked.- Parameters:
clickListener
- Listener to register- See Also:
-
setOnItemSelectedListener
public void setOnItemSelectedListener(@Nullable AdapterView.OnItemSelectedListener selectedListener) Sets a listener to receive events when a list item is selected.- Parameters:
selectedListener
- Listener to register.- See Also:
-
setPromptView
Set a view to act as a user prompt for this popup window. Where the prompt view will appear is controlled bysetPromptPosition(int)
.- Parameters:
prompt
- View to use as an informational prompt.
-
postShow
public void postShow()Post ashow()
call to the UI thread. -
show
public void show()Show the popup list. If the list is already showing, this method will recalculate the popup's size and position.- Specified by:
show
in interfaceShowableListMenu
-
dismiss
public void dismiss()Dismiss the popup window.- Specified by:
dismiss
in interfaceShowableListMenu
-
dismissImmediate
public void dismissImmediate()Remove existing exit transition from PopupWindow and force immediate dismissal. -
setOnDismissListener
Set a listener to receive a callback when the popup is dismissed.- Parameters:
listener
- Listener that will be notified when the popup is dismissed.
-
setSelection
public void setSelection(int position) Set the selected position of the list. Only valid whenisShowing()
==true
.- Parameters:
position
- List position to set as selected.
-
clearListSelection
public void clearListSelection()Clear any current list selection. Only valid whenisShowing()
==true
. -
isShowing
public boolean isShowing()- Specified by:
isShowing
in interfaceShowableListMenu
- Returns:
true
if the popup is currently showing,false
otherwise.
-
performItemClick
public boolean performItemClick(int position) Perform an item click operation on the specified list adapter position.- Parameters:
position
- Adapter position for performing the click- Returns:
- true if the click action could be performed, false if not. (e.g. if the popup was not showing, this method would return false.)
-
getSelectedItem
- Returns:
- The currently selected item or null if the popup is not showing.
-
getSelectedItemPosition
public int getSelectedItemPosition()- Returns:
- The position of the currently selected item or
AdapterView.INVALID_POSITION
ifisShowing()
==false
. - See Also:
-
getSelectedItemId
public long getSelectedItemId()- Returns:
- The ID of the currently selected item or
AdapterView.INVALID_ROW_ID
ifisShowing()
==false
. - See Also:
-
getSelectedView
- Returns:
- The View for the currently selected item or null if
isShowing()
==false
. - See Also:
-
getListView
- Specified by:
getListView
in interfaceShowableListMenu
- Returns:
- The
ListView
displayed within the popup window. Only valid whenisShowing()
==true
.
-
setOverlapAnchor
public void setOverlapAnchor(boolean overlap)
-