android - Gesture detector steals my singleTap, doesn't send it back to the other views -
i have relativelayout called swipelayout, matches parent, , added gesturedetector on it. have layoutcontainer, contains buttons, slidinguppanellayout , many other. problem need catch swipe right or left, if init gesture detector, catch singletap, means buttons won't work.
this code inside activity:
final gesturedetector gesturedetector = new gesturedetector(psnewjourneyactivity.this, new gesturelistener(psnewjourneyactivity.this, layoutcontainer, new crudstatecallback() { @override public void onresponse(string string) { log.i("","touchdid container ontouch listener called"); } })); swipelayout.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { if (gesturedetector.ontouchevent(event)) { return false; } return true; } }); layoutcontainer.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { log.i("","touchdid container ontouch listener"); return false; } }); as can see: create custom gesture detector, has interface, can return data. have touch listener on swipelayout, call if needed gesture detector. , have touchlistener on layoutcontainer, check if being called.
this gesturelistener:
public class gesturelistener extends gesturedetector.simpleongesturelistener { context context; relativelayout layout; crudstatecallback back; public gesturelistener(context context, relativelayout layout, crudstatecallback back) { this.context = context; this.layout = layout; this.back = back; log.i("","touchdid created"); } @override public boolean onsingletapconfirmed(motionevent event) { // trigger touch event on calendar layout.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { log.i("","touchdid on touch called single tap"); return false; } }); log.i("","touchdid single tap"); layout.ontouchevent(event); return super.onsingletapup(event); } @override public boolean ondoubletap(motionevent e) { log.i("","touchdid double tap"); return super.ondoubletap(e); } @override public boolean onfling(motionevent e1, motionevent e2, float velocityx, float velocityy) { viewconfiguration viewconfiguration = viewconfiguration.get(context); int minswipedistance = viewconfiguration.getscaledpagingtouchslop(); int minswipevelocity = viewconfiguration.getscaledminimumflingvelocity(); int maxswipeoffpath = viewconfiguration.getscaledtouchslop(); log.i("","touchdid fling"); if (math.abs(e1.gety() - e2.gety()) > maxswipeoffpath) { return false; } if (math.abs(velocityx) > minswipevelocity) { // right left swipe if (e1.getx() - e2.getx() > minswipedistance) { log.i("","touchdid left"); } // left right else if (e2.getx() - e1.getx() > minswipedistance) { log.i("","touchdid right"); } log.i("","touchdid onfling"); } return false; } }
now, pass it, layoutcontainer activity, layout. on onsingletapconfirmed layout.ontouchevent(event). shouldn't call ontouchlistener layoutcontainer?
i in adm line of code: log.i("","touchdid single tap"); ontouchlistener never called layoutcontainer. why that?
Comments
Post a Comment