Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added AdapterContextMenuInfo for floating context menu support #125

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}
* <p/>
Expand Down Expand Up @@ -2910,4 +2917,24 @@ public boolean sameWindow() {
return hasWindowFocus() && getWindowAttachCount() == mOriginalAttachCount;
}
}

@Override
protected ContextMenuInfo getContextMenuInfo(){ // added by v-b-r
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Floating context menu with StaggeredGridView, menuInfo was null previously, I've added necessary method to get menuInfo properly. I've have not gone through full code, this method might need a review.

ContextMenuInfo menuInfo = super.getContextMenuInfo();
if(menuInfo==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;
menuInfo = new AdapterContextMenuInfo(view, clickPosition, adapter.getItemId(clickPosition));
}
}
}
return menuInfo;
}
}