Package icyllis.modernui.widget
Class ListPopupWindow
java.lang.Object
icyllis.modernui.widget.ListPopupWindow
- All Implemented Interfaces:
ShowableListMenu
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
FieldsModifier and TypeFieldDescriptionstatic final intThe provided prompt view should appear above list content.static final intThe provided prompt view should appear below list content. -
Constructor Summary
ConstructorsConstructorDescriptionListPopupWindow(Context context) ListPopupWindow(Context context, AttributeSet attrs) ListPopupWindow(Context context, AttributeSet attrs, ResourceId defStyleAttr) ListPopupWindow(Context context, AttributeSet attrs, ResourceId defStyleAttr, ResourceId defStyleRes) -
Method Summary
Modifier and TypeMethodDescriptionvoidClear any current list selection.voiddismiss()Dismiss the popup window.voidRemove 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.intintintlongintintintgetWidth()booleanbooleanisModal()Returns whether the popup window will be modal when shown.booleanbooleanperformItemClick(int position) Perform an item click operation on the specified list adapter position.voidpostShow()Post ashow()call to the UI thread.voidsetAdapter(ListAdapter adapter) Sets the adapter that provides the data and the views to represent the data in this popup window.voidsetAnchorView(View anchor) Sets the popup's anchor view.voidSets a drawable to be the background for the popup window.voidsetContentWidth(int width) Sets the width of the popup window by the size of its content.voidsetDropDownAlwaysVisible(boolean dropDownAlwaysVisible) Sets whether the drop-down should remain visible under certain conditions.voidsetDropDownGravity(int gravity) Set the gravity of the dropdown list.voidsetEpicenterBounds(Rect bounds) Specifies the anchor-relative bounds of the popup's transition epicenter.voidsetForceIgnoreOutsideTouch(boolean forceIgnoreOutsideTouch) Forces outside touches to be ignored.voidsetHeight(int height) Sets the height of the popup window in pixels.voidsetHorizontalOffset(int offset) Set the horizontal offset of this popup from its anchor view in pixels.voidsetListSelector(Drawable selector) Sets a drawable to use as the list item selector.voidsetModal(boolean modal) Set whether this window should be modal when shown.voidSet a listener to receive a callback when the popup is dismissed.voidsetOnItemClickListener(AdapterView.OnItemClickListener clickListener) Sets a listener to receive events when a list item is clicked.voidsetOnItemSelectedListener(AdapterView.OnItemSelectedListener selectedListener) Sets a listener to receive events when a list item is selected.voidsetOverlapAnchor(boolean overlap) voidsetPromptPosition(int position) Set where the optional prompt view should appear.voidsetPromptView(View prompt) Set a view to act as a user prompt for this popup window.voidsetSelection(int position) Set the selected position of the list.voidsetVerticalOffset(int offset) Set the vertical offset of this popup from its anchor view in pixels.voidsetWidth(int width) Sets the width of the popup window in pixels.voidshow()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
-
ListPopupWindow
-
ListPopupWindow
public ListPopupWindow(@NonNull Context context, @Nullable AttributeSet attrs, @Nullable @AttrRes ResourceId defStyleAttr) -
ListPopupWindow
public ListPopupWindow(@NonNull Context context, @Nullable AttributeSet attrs, @Nullable @AttrRes ResourceId defStyleAttr, @Nullable @StyleRes ResourceId defStyleRes)
-
-
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-trueif the popup window should be modal,falseotherwise.
-
isModal
public boolean isModal()Returns whether the popup window will be modal when shown.- Returns:
trueif the popup window will be modal,falseotherwise.
-
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, ornullto 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
nullif 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_PARENTorViewGroup.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:
showin interfaceShowableListMenu
-
dismiss
public void dismiss()Dismiss the popup window.- Specified by:
dismissin 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:
isShowingin interfaceShowableListMenu- Returns:
trueif the popup is currently showing,falseotherwise.
-
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_POSITIONifisShowing()==false. - See Also:
-
getSelectedItemId
public long getSelectedItemId()- Returns:
- The ID of the currently selected item or
AdapterView.INVALID_ROW_IDifisShowing()==false. - See Also:
-
getSelectedView
- Returns:
- The View for the currently selected item or null if
isShowing()==false. - See Also:
-
getListView
- Specified by:
getListViewin interfaceShowableListMenu- Returns:
- The
ListViewdisplayed within the popup window. Only valid whenisShowing()==true.
-
setOverlapAnchor
@Internal public void setOverlapAnchor(boolean overlap)
-