Skip to content

Instantly share code, notes, and snippets.

@fdoyle
Created April 16, 2014 20:57
Show Gist options
  • Save fdoyle/10932323 to your computer and use it in GitHub Desktop.
Save fdoyle/10932323 to your computer and use it in GitHub Desktop.
package crub.the.flub
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ListView;
/**
* Created by fdoyle on 3/19/14.
*/
public class FancyListView extends ListView {
View ignoreView;
public FancyListView(Context context) {
super(context);
}
public FancyListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FancyListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public void setIgnoreView(View v) {
ignoreView = v;
}
int[] screenPosition = new int[2];
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if(ignoreView != null && ev.getAction() == MotionEvent.ACTION_DOWN) {
ignoreView.getLocationInWindow(screenPosition);
if (ev.getRawX() > screenPosition[0] &&
ev.getRawX() < screenPosition[0] + ignoreView.getWidth() &&
ev.getRawY() > screenPosition[1] &&
ev.getRawY() < screenPosition[1] + ignoreView.getHeight()) {
return false;
}
}
return super.onInterceptTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
if(ignoreView != null && ev.getAction() == MotionEvent.ACTION_DOWN) {
ignoreView.getLocationInWindow(screenPosition);
if (ev.getRawX() > screenPosition[0] &&
ev.getRawX() < screenPosition[0] + ignoreView.getWidth() &&
ev.getRawY() > screenPosition[1] &&
ev.getRawY() < screenPosition[1] + ignoreView.getHeight()) {
return false;
}
}
return super.onTouchEvent(ev);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment