Package icyllis.modernui.widget

# 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:
  - `Spinner`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `POSITION_PROMPT_ABOVE`
  The provided prompt view should appear above list content.
  `static final int`
  `POSITION_PROMPT_BELOW`
  The provided prompt view should appear below list content.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ListPopupWindow(Context context)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `clearListSelection()`
  Clear any current list selection.
  `void`
  `dismiss()`
  Dismiss the popup window.
  `void`
  `dismissImmediate()`
  Remove existing exit transition from PopupWindow and force immediate dismissal.
  `View`
  `getAnchorView()`
  Returns the view that will be used to anchor this popup.
  `Drawable`
  `getBackground()`
  `Rect`
  `getEpicenterBounds()`
  Returns bounds which are used as a popup's epicenter of the enter and exit transitions.
  `int`
  `getHeight()`
  `int`
  `getHorizontalOffset()`
  `ListView`
  `getListView()`
  `int`
  `getPromptPosition()`
  `Object`
  `getSelectedItem()`
  `long`
  `getSelectedItemId()`
  `int`
  `getSelectedItemPosition()`
  `View`
  `getSelectedView()`
  `int`
  `getVerticalOffset()`
  `int`
  `getWidth()`
  `boolean`
  `isDropDownAlwaysVisible()`
  `boolean`
  `isModal()`
  Returns whether the popup window will be modal when shown.
  `boolean`
  `isShowing()`
  `boolean`
  `performItemClick(int position)`
  Perform an item click operation on the specified list adapter position.
  `void`
  `postShow()`
  Post a `show()` 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`
  `setBackgroundDrawable(Drawable d)`
  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`
  `setOnDismissListener(PopupWindow.OnDismissListener listener)`
  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.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### POSITION_PROMPT_ABOVE

    public static final int POSITION_PROMPT_ABOVE
    The provided prompt view should appear above list content.
    See Also:
      - `setPromptPosition(int)`
      - `getPromptPosition()`
      - `setPromptView(View)`
      - Constant Field Values

  - ### POSITION_PROMPT_BELOW

    public static final int POSITION_PROMPT_BELOW
    The provided prompt view should appear below list content.
    See Also:
      - `setPromptPosition(int)`
      - `getPromptPosition()`
      - `setPromptView(View)`
      - Constant Field Values

- ## Constructor Details

  - ### ListPopupWindow

    public ListPopupWindow(@NonNull Context context)

- ## 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:
      - `POSITION_PROMPT_ABOVE`
      - `POSITION_PROMPT_BELOW`

  - ### getPromptPosition

    public int getPromptPosition()
    Returns:
      Where the optional prompt view should appear.
    See Also:
      - `POSITION_PROMPT_ABOVE`
      - `POSITION_PROMPT_BELOW`

  - ### 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()`

  - ### 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:
      - `setEpicenterBounds(Rect)`

  - ### 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:
      - `AdapterView.setOnItemClickListener(AdapterView.OnItemClickListener)`

  - ### 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:
      - `AdapterView.setOnItemSelectedListener(AdapterView.OnItemSelectedListener)`

  - ### 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:
      - `AdapterView.getSelectedItemPosition()`

  - ### getSelectedItemId

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

  - ### getSelectedView

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

  - ### 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)