Class ListPopupWindow

java.lang.Object
icyllis.modernui.widget.ListPopupWindow
All Implemented Interfaces:
ShowableListMenu
Direct Known Subclasses:
MenuPopupWindow

public class ListPopupWindow extends Object implements 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 Details

  • Constructor Details

  • Method Details

    • setAdapter

      public void setAdapter(@Nullable ListAdapter adapter)
      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 is POSITION_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 if isDropDownAlwaysVisible() 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

      public void setListSelector(Drawable selector)
      Sets a drawable to use as the list item selector.
      Parameters:
      selector - List selector drawable to use in the popup.
    • getBackground

      @Nullable public Drawable getBackground()
      Returns:
      The background drawable for the popup window.
    • setBackgroundDrawable

      public void setBackgroundDrawable(@Nullable Drawable d)
      Sets a drawable to be the background for the popup window.
      Parameters:
      d - A drawable to set as the background.
    • getAnchorView

      @Nullable public View getAnchorView()
      Returns the view that will be used to anchor this popup.
      Returns:
      The popup's anchor view
    • setAnchorView

      public void setAnchorView(@Nullable View anchor)
      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

      public void setEpicenterBounds(@Nullable Rect bounds)
      Specifies the anchor-relative bounds of the popup's transition epicenter.
      Parameters:
      bounds - anchor-relative bounds, or null to use default epicenter
      See Also:
    • getEpicenterBounds

      @Nullable public Rect 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 be ViewGroup.LayoutParams.MATCH_PARENT or ViewGroup.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 be ViewGroup.LayoutParams.MATCH_PARENT.
      Parameters:
      height - Height of the popup window must be a positive value, ViewGroup.LayoutParams.MATCH_PARENT, or ViewGroup.LayoutParams.WRAP_CONTENT.
      Throws:
      IllegalArgumentException - if height is set to negative value
    • setOnItemClickListener

      public void setOnItemClickListener(@Nullable AdapterView.OnItemClickListener clickListener)
      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

      public void setPromptView(@Nullable View prompt)
      Set a view to act as a user prompt for this popup window. Where the prompt view will appear is controlled by setPromptPosition(int).
      Parameters:
      prompt - View to use as an informational prompt.
    • postShow

      public void postShow()
      Post a show() 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 interface ShowableListMenu
    • dismiss

      public void dismiss()
      Dismiss the popup window.
      Specified by:
      dismiss in interface ShowableListMenu
    • dismissImmediate

      public void dismissImmediate()
      Remove existing exit transition from PopupWindow and force immediate dismissal.
    • setOnDismissListener

      public void setOnDismissListener(@Nullable PopupWindow.OnDismissListener listener)
      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 when isShowing() == true.
      Parameters:
      position - List position to set as selected.
    • clearListSelection

      public void clearListSelection()
      Clear any current list selection. Only valid when isShowing() == true.
    • isShowing

      public boolean isShowing()
      Specified by:
      isShowing in interface ShowableListMenu
      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

      @Nullable public Object 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 if isShowing() == false.
      See Also:
    • getSelectedItemId

      public long getSelectedItemId()
      Returns:
      The ID of the currently selected item or AdapterView.INVALID_ROW_ID if isShowing() == false.
      See Also:
    • getSelectedView

      @Nullable public View getSelectedView()
      Returns:
      The View for the currently selected item or null if isShowing() == false.
      See Also:
    • getListView

      @Nullable public ListView getListView()
      Specified by:
      getListView in interface ShowableListMenu
      Returns:
      The ListView displayed within the popup window. Only valid when isShowing() == true.
    • setOverlapAnchor

      public void setOverlapAnchor(boolean overlap)