summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api/current.txt2
-rw-r--r--core/java/android/widget/ListPopupWindow.java27
-rw-r--r--core/java/android/widget/PopupMenu.java30
3 files changed, 59 insertions, 0 deletions
diff --git a/api/current.txt b/api/current.txt
index e7278086167a..4b4ecb0356dc 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -31354,6 +31354,7 @@ package android.widget {
ctor public ListPopupWindow(android.content.Context, android.util.AttributeSet, int);
ctor public ListPopupWindow(android.content.Context, android.util.AttributeSet, int, int);
method public void clearListSelection();
+ method public android.view.View.OnTouchListener createDragToOpenListener(android.view.View);
method public void dismiss();
method public android.view.View getAnchorView();
method public int getAnimationStyle();
@@ -31565,6 +31566,7 @@ package android.widget {
public class PopupMenu {
ctor public PopupMenu(android.content.Context, android.view.View);
method public void dismiss();
+ method public android.view.View.OnTouchListener getDragToOpenListener();
method public android.view.Menu getMenu();
method public android.view.MenuInflater getMenuInflater();
method public void inflate(int);
diff --git a/core/java/android/widget/ListPopupWindow.java b/core/java/android/widget/ListPopupWindow.java
index 626238746223..f2da765745fc 100644
--- a/core/java/android/widget/ListPopupWindow.java
+++ b/core/java/android/widget/ListPopupWindow.java
@@ -965,6 +965,33 @@ public class ListPopupWindow {
}
/**
+ * Returns an {@link OnTouchListener} that can be added to the source view
+ * to implement drag-to-open behavior. Generally, the source view should be
+ * the same view that was passed to {@link #setAnchorView}.
+ * <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>ListPopupWindow myPopup = new ListPopupWindow(context);
+ * myPopup.setAnchor(myAnchor);
+ * OnTouchListener dragListener = myPopup.createDragToOpenListener(myAnchor);
+ * myAnchor.setOnTouchListener(dragListener);</pre>
+ *
+ * @param src the view on which the resulting listener will be set
+ * @return a touch listener that controls drag-to-open behavior
+ */
+ public OnTouchListener createDragToOpenListener(View src) {
+ return new ForwardingListener(src) {
+ @Override
+ public ListPopupWindow getPopup() {
+ return ListPopupWindow.this;
+ }
+ };
+ }
+
+ /**
* <p>Builds the popup window's content and returns the height the popup
* should have. Returns -1 when the content already exists.</p>
*
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()}.
*