Log is never logging ACTION_UP or ACTION_MOVE(which i removed from the code example for shortening)
Here is my shorten version of the code:
public class ProfileBadgeView extends LinearLayout {
Activity act;
public ProfileBadgeView(Context context) {
super(context);
}
public ProfileBadgeView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public ProfileBadgeView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public void initView(Activity act) {
//..init
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
logIntercept("ACTION DOWN");
} else if (ev.getAction() == MotionEvent.ACTION_UP) {
logIntercept("ACTION_UP");
}
return false;
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
return true;
}
private void logIntercept(Object obj) {
Log.i(this.getClass().getSimpleName() + " INTERCEPT :", obj.toString());
}
}
Your onInterceptTouchEvent
method is not called after ACTION_DOWN
event because you return true
in onTouchEvent
method. So all the other events are sent in onTouchEvent
and not in onInterceptTouchEvent
any more:
Using this function takes some care, as it has a fairly complicated interaction with View.onTouchEvent(MotionEvent), and using it requires implementing that method as well as this one in the correct way. Events will be received in the following order:
You will receive the down event here. The down event will be handled either by a child of this view group, or given to your own onTouchEvent() method to handle; this means you should implement onTouchEvent() to return true, so you will continue to see the rest of the gesture (instead of looking for a parent view to handle it). Also, by returning true from onTouchEvent(), you will not receive any following events in onInterceptTouchEvent() and all touch processing must happen in onTouchEvent() like normal.
http://developer.android.com/reference/android/view/ViewGroup.html#onInterceptTouchEvent(android.view.MotionEvent)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With