android - WebView with swipe Gesture -


i have page first part containing animations. when user swipes, animation goes , webview appears. on swipe up, webview goes , animations again appears. since webview consuming touch, overriding webview touch , passing gesturedetector object. want control switched between webview , gesturedetector. gesturedetector works or webview works doesnt work together. help?

this doing now:

    webview.setontouchlistener(new view.ontouchlistener() {          @override         public boolean ontouch(view v, motionevent event) {             // todo auto-generated method stub              return gesturedetector.ontouchevent(event);             // return false;          }     }); 

the gesture detector handles swiping between animations , webview:

    gesturedetector = new gesturedetector(getactivity(),             new gesturedetector.simpleongesturelistener() {                 /* function pause video on tap */                 @override                 public boolean onsingletapconfirmed(motionevent e) {                     /* on touch event pressed play , pause videoplayer */                     return true;                 }                  /*                  * ondown() has return true fling methof take                  * place                  */                 @override                 public boolean ondown(motionevent e) {                     return true;                 }                  @override                 public boolean onfling(motionevent e1, motionevent e2,                         float velocityx, float velocityy) { 

use gesturedetector custom web view..

webview.setgesturedetector(new gesturedetector(new customegesturedetector()));

gesture detector:

private class customegesturedetector extends simpleongesturelistener {           @override     public boolean onfling(motionevent e1, motionevent e2, float velocityx, float velocityy) {         if(e1 == null || e2 == null) return false;         if(e1.getpointercount() > 1 || e2.getpointercount() > 1) return false;         else {             try { // right left swipe .. go next page                 if(e1.getx() - e2.getx() > 100 && math.abs(velocityx) > 800) {                     //do stuff                     return true;                 } //left right swipe .. go prev page                 else if (e2.getx() - e1.getx() > 100 && math.abs(velocityx) > 800) {                     //do stuff                     return true;                 } //bottom top, go next document                 else if(e1.gety() - e2.gety() > 100 && math.abs(velocityy) > 800                          && webview.getscrolly() >= webview.getscale() * (webview.getcontentheight() - webview.getheight())) {                     //do stuff                     return true;                 } //top bottom, go prev document                 else if (e2.gety() - e1.gety() > 100 && math.abs(velocityy) > 800 ) {                     //do stuff                     return true;                 }              } catch (exception e) { // nothing             }             return false;         }     } } 

custom web view

public final class customwebview extends webview {  private gesturedetector gesturedetector;  /**  * @param context  * @param attrs  * @param defstyle  */ public customwebview(context context) {     super(context); }  /**  * @param context  * @param attrs  * @param defstyle  */ public customwebview(context context, attributeset attrs) {     super(context, attrs); }  /**  * @param context  * @param attrs  * @param defstyle  */ public customwebview(context context, attributeset attrs, int defstyle) {     super(context, attrs, defstyle); }  /*   * @see android.webkit.webview#onscrollchanged(int, int, int, int)  */ @override protected void onscrollchanged(int l, int t, int oldl, int oldt) {     super.onscrollchanged(l, t, oldl, oldt); }  /*   * @see android.webkit.webview#ontouchevent(android.view.motionevent)  */ @override public boolean ontouchevent(motionevent ev) {     return gesturedetector.ontouchevent(ev) || super.ontouchevent(ev); }  public void setgesturedetector(gesturedetector gesturedetector) {     this.gesturedetector = gesturedetector; } } 

Comments