Skip to content

Commit

Permalink
Fix OnLongClickListener triggering OnClickListener #35
Browse files Browse the repository at this point in the history
  • Loading branch information
balysv committed Apr 30, 2015
1 parent 4726256 commit 00f34fa
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ public void setOnClickListener(OnClickListener onClickListener) {
childView.setOnClickListener(onClickListener);
}

@Override
public void setOnLongClickListener(OnLongClickListener onClickListener) {
if (childView == null) {
throw new IllegalStateException("MaterialRippleLayout must have a child view to handle clicks");
}
childView.setOnLongClickListener(onClickListener);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
return !findClickableViewInChild(childView, (int) event.getX(), (int) event.getY());
Expand All @@ -192,7 +200,7 @@ public boolean onTouchEvent(MotionEvent event) {
}

boolean gestureResult = gestureDetector.onTouchEvent(event);
if (gestureResult || mHasPerformedLongPress) {
if (gestureResult || hasPerformedLongPress) {
return true;
} else {
int action = event.getActionMasked();
Expand Down Expand Up @@ -278,11 +286,11 @@ private void cancelPressedEvent() {
}
}

private boolean mHasPerformedLongPress;
private boolean hasPerformedLongPress;
private SimpleOnGestureListener longClickListener = new GestureDetector.SimpleOnGestureListener() {
public void onLongPress(MotionEvent e) {
mHasPerformedLongPress = childView.performLongClick();
if (mHasPerformedLongPress) {
hasPerformedLongPress = childView.performLongClick();
if (hasPerformedLongPress) {
if (rippleHover) {
startRipple(null);
}
Expand All @@ -292,7 +300,7 @@ public void onLongPress(MotionEvent e) {

@Override
public boolean onDown(MotionEvent e) {
mHasPerformedLongPress = false;
hasPerformedLongPress = false;
return super.onDown(e);
}
};
Expand Down Expand Up @@ -627,7 +635,7 @@ private void enableClipPathSupportIfNecessary() {
private class PerformClickEvent implements Runnable {

@Override public void run() {
if (mHasPerformedLongPress) return;
if (hasPerformedLongPress) return;

// if parent is an AdapterView, try to call its ItemClickListener
if (getParent() instanceof AdapterView) {
Expand Down

0 comments on commit 00f34fa

Please sign in to comment.