From a2131b1bff238775a9a80d449cf799f9e412c388 Mon Sep 17 00:00:00 2001 From: Vinay Date: Sat, 19 Jul 2014 12:29:50 +0530 Subject: [PATCH 1/3] added getContextMenuInfo method to handle floating context menu --- .../etsy/android/grid/ExtendableListView.java | 45 +++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/com/etsy/android/grid/ExtendableListView.java b/library/src/main/java/com/etsy/android/grid/ExtendableListView.java index 259530f..8f8257b 100644 --- a/library/src/main/java/com/etsy/android/grid/ExtendableListView.java +++ b/library/src/main/java/com/etsy/android/grid/ExtendableListView.java @@ -17,6 +17,8 @@ package com.etsy.android.grid; +import java.util.ArrayList; + import android.content.Context; import android.database.DataSetObserver; import android.graphics.Rect; @@ -28,14 +30,19 @@ import android.support.v4.view.ViewCompat; import android.util.AttributeSet; import android.util.Log; -import android.view.*; +import android.view.ContextMenu.ContextMenuInfo; +import android.view.HapticFeedbackConstants; +import android.view.MotionEvent; +import android.view.VelocityTracker; +import android.view.View; +import android.view.ViewConfiguration; +import android.view.ViewGroup; +import android.view.ViewParent; import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.ListAdapter; import android.widget.Scroller; -import java.util.ArrayList; - /** * An extendable implementation of the Android {@link android.widget.ListView} *

@@ -2910,4 +2917,36 @@ public boolean sameWindow() { return hasWindowFocus() && getWindowAttachCount() == mOriginalAttachCount; } } + + @Override + protected ContextMenuInfo getContextMenuInfo(){ + ContextMenuInfo tmp = super.getContextMenuInfo(); + if(tmp==null){ + final ListAdapter adapter = mAdapter; + final int motionPosition = mPerformClick.mClickMotionPosition; + if (adapter != null && mItemCount > 0 && + motionPosition != INVALID_POSITION && + motionPosition < adapter.getCount()) { + final View view = getChildAt(motionPosition); // a fix by @pboos + + if (view != null) { + final int clickPosition = motionPosition + mFirstPosition; + tmp = new ExtendableListViewContextMenuInfo(view, clickPosition, adapter.getItemId(clickPosition)); + } + } + } + return tmp; + } + + public static class ExtendableListViewContextMenuInfo implements ContextMenuInfo{ + public View targetView; + public int position; + public long id; + + public ExtendableListViewContextMenuInfo(View targetView, int position, long id){ + this.targetView = targetView; + this.position = position; + this.id = id; + } + } } From 4a48544f6fff8c37c7f3897085d3f808f10ef7ed Mon Sep 17 00:00:00 2001 From: Vinay Date: Sat, 19 Jul 2014 12:35:54 +0530 Subject: [PATCH 2/3] renamed static class ExtendableListViewContextMenuInfo name to AdapterContextMenuInfo --- .../main/java/com/etsy/android/grid/ExtendableListView.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/com/etsy/android/grid/ExtendableListView.java b/library/src/main/java/com/etsy/android/grid/ExtendableListView.java index 8f8257b..40355a9 100644 --- a/library/src/main/java/com/etsy/android/grid/ExtendableListView.java +++ b/library/src/main/java/com/etsy/android/grid/ExtendableListView.java @@ -2931,19 +2931,19 @@ protected ContextMenuInfo getContextMenuInfo(){ if (view != null) { final int clickPosition = motionPosition + mFirstPosition; - tmp = new ExtendableListViewContextMenuInfo(view, clickPosition, adapter.getItemId(clickPosition)); + tmp = new AdapterContextMenuInfo(view, clickPosition, adapter.getItemId(clickPosition)); } } } return tmp; } - public static class ExtendableListViewContextMenuInfo implements ContextMenuInfo{ + public static class AdapterContextMenuInfo implements ContextMenuInfo{ public View targetView; public int position; public long id; - public ExtendableListViewContextMenuInfo(View targetView, int position, long id){ + public AdapterContextMenuInfo(View targetView, int position, long id){ this.targetView = targetView; this.position = position; this.id = id; From e521568574ee3724eb0e1f3882fd01313bbf97d5 Mon Sep 17 00:00:00 2001 From: Vinay Date: Sat, 19 Jul 2014 12:45:39 +0530 Subject: [PATCH 3/3] removed unnecessary class written by me --- .../etsy/android/grid/ExtendableListView.java | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/library/src/main/java/com/etsy/android/grid/ExtendableListView.java b/library/src/main/java/com/etsy/android/grid/ExtendableListView.java index 40355a9..7b377cc 100644 --- a/library/src/main/java/com/etsy/android/grid/ExtendableListView.java +++ b/library/src/main/java/com/etsy/android/grid/ExtendableListView.java @@ -2919,9 +2919,9 @@ public boolean sameWindow() { } @Override - protected ContextMenuInfo getContextMenuInfo(){ - ContextMenuInfo tmp = super.getContextMenuInfo(); - if(tmp==null){ + protected ContextMenuInfo getContextMenuInfo(){ // added by v-b-r + ContextMenuInfo menuInfo = super.getContextMenuInfo(); + if(menuInfo==null){ final ListAdapter adapter = mAdapter; final int motionPosition = mPerformClick.mClickMotionPosition; if (adapter != null && mItemCount > 0 && @@ -2931,22 +2931,10 @@ protected ContextMenuInfo getContextMenuInfo(){ if (view != null) { final int clickPosition = motionPosition + mFirstPosition; - tmp = new AdapterContextMenuInfo(view, clickPosition, adapter.getItemId(clickPosition)); + menuInfo = new AdapterContextMenuInfo(view, clickPosition, adapter.getItemId(clickPosition)); } } } - return tmp; - } - - public static class AdapterContextMenuInfo implements ContextMenuInfo{ - public View targetView; - public int position; - public long id; - - public AdapterContextMenuInfo(View targetView, int position, long id){ - this.targetView = targetView; - this.position = position; - this.id = id; - } + return menuInfo; } }