diff options
| author | Alan Viverette <alanv@google.com> | 2013-08-27 15:45:16 -0700 |
|---|---|---|
| committer | Alan Viverette <alanv@google.com> | 2013-08-27 15:45:16 -0700 |
| commit | 1955a5b531f03dec90f285b590ef62e3d632783c (patch) | |
| tree | 2cd61fa0e7e19efe392521bba61ceb139311eb27 /core/java/android/widget/PopupMenu.java | |
| parent | 107e2d418b335263da01aaa9bafb69475e79d7f7 (diff) | |
Add public API for obtaining drag-to-open listener
BUG: 10457019
Change-Id: I66485521c54b82033044834e7aab6707a3049e6b
Diffstat (limited to 'core/java/android/widget/PopupMenu.java')
| -rw-r--r-- | core/java/android/widget/PopupMenu.java | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/core/java/android/widget/PopupMenu.java b/core/java/android/widget/PopupMenu.java index 6a6d76766113..e5344c6afbcf 100644 --- a/core/java/android/widget/PopupMenu.java +++ b/core/java/android/widget/PopupMenu.java @@ -26,6 +26,8 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import android.view.View.OnTouchListener; +import android.widget.ListPopupWindow.ForwardingListener; /** * A PopupMenu displays a {@link Menu} in a modal popup window anchored to a {@link View}. @@ -40,6 +42,7 @@ public class PopupMenu implements MenuBuilder.Callback, MenuPresenter.Callback { private MenuPopupHelper mPopup; private OnMenuItemClickListener mMenuItemClickListener; private OnDismissListener mDismissListener; + private OnTouchListener mDragListener; /** * Callback interface used to notify the application that the menu has closed. @@ -71,6 +74,33 @@ public class PopupMenu implements MenuBuilder.Callback, MenuPresenter.Callback { } /** + * Returns an {@link OnTouchListener} that can be added to the anchor view + * to implement drag-to-open behavior. + * <p> + * When the listener is set on a view, touching that view and dragging + * outside of its bounds will open the popup window. Lifting will select the + * currently touched list item. + * <p> + * Example usage: + * <pre>PopupMenu myPopup = new PopupMenu(context, myAnchor); + * myAnchor.setOnTouchListener(myPopup.getDragToOpenListener());</pre> + * + * @return a touch listener that controls drag-to-open behavior + */ + public OnTouchListener getDragToOpenListener() { + if (mDragListener == null) { + mDragListener = new ForwardingListener(mAnchor) { + @Override + public ListPopupWindow getPopup() { + return mPopup.getPopup(); + } + }; + } + + return mDragListener; + } + + /** * @return the {@link Menu} associated with this popup. Populate the returned Menu with * items before calling {@link #show()}. * |
