android - Why is my SimpleOnGestureListener not functioning? -


i'm using own gesturedetector class detect left|right onfling event. see looks in code nothing happens...?

i need added functionality beyond toggle button opens|closes navigation view in fragments. toggle calls on method in animationlayout class follows:

public void togglesidebar() { if (mcontent.getanimation() != null) { return; }  if (mopened) { /* opened, make close animation */ manimation = new translateanimation(0, -msidebarwidth, 0, 0); manimation.setanimationlistener(mcloselistener); } else { /* not opened, make open animation */ manimation = new translateanimation(0, msidebarwidth, 0, 0); manimation.setanimationlistener(mopenlistener); } manimation.setduration(duration); manimation.setfillafter(true); manimation.setfillenabled(true); mcontent.startanimation(manimation); } 

and...

public void opensidebar()     {     if (!mopened)     {     togglesidebar();     }     }      public void closesidebar()     {     if (mopened)     {     togglesidebar();     }     } 

within main activity onfling() calls on toggle sub:

public static animationlayout mlayout;      // these constants used onfling     private static final int swipe_min_distance = 120;     private static final int swipe_max_off_path = 250;     private static final int swipe_threshold_velocity = 200;     private gesturedetector gesturedetector;  @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);          mlayout = (animationlayout) findviewbyid(r.id.animation_layout);         gesturedetector = new gesturedetector(this.getapplicationcontext(), new mygesturedetector());         // set touch listener main view our custom gesture         // listener         mlayout.setontouchlistener(new view.ontouchlistener() {             public boolean ontouch(view v, motionevent event) {                 if (gesturedetector.ontouchevent(event)) {                     return true;                 }                 return false;             }         });     }       class mygesturedetector extends simpleongesturelistener {         @override         public boolean onfling(motionevent e1, motionevent e2, float velocityx, float velocityy) {              if (math.abs(e1.gety() - e2.gety()) > swipe_max_off_path) {                 return false;             }             // right left swipe             if (e1.getx() - e2.getx() > swipe_min_distance && math.abs(velocityx) > swipe_threshold_velocity) {                 toast.maketext(getapplicationcontext(), "right_left", toast.length_long).show();                 log.i("mygesturedetector", "r2l!");                 mlayout.closesidebar();                 // left right swipe             } else if (e2.getx() - e1.getx() > swipe_min_distance && math.abs(velocityx) > swipe_threshold_velocity) {                 toast.maketext(getapplicationcontext(), "left_right", toast.length_long).show();                 log.i("mygesturedetector", "l2r!");                 mlayout.opensidebar();             }              return false;         }          // return true ondown onfling event register         @override         public boolean ondown(motionevent e) {             return true;         }     } 

this button works fine:

... case r.id.navtogglebtn : {                 mlayout.togglesidebar();             } ... 

i think 1 reason gesture work on onfling condition not satisfied in u r code have implemented 1 ontouchlistener try

yourview.setontouchlistner(onthumbtouch );         ontouchlistener onthumbtouch = new ontouchlistener()         {             float previouspoint = 0 ;             float startpoint=0;             @override             public boolean ontouch(view v, motionevent event)              {                    switch(v.getid())                 {                 case r.id.tvdetailsalaujairiyat: // give r.id.sample ...                 {                     switch(event.getaction())                     {                     case motionevent.action_down:                     {                                   startpoint=event.getx();                         system.out.println("action down,..."+event.getx());                     }                     break;                     case motionevent.action_move:                     {                             }break;                     case motionevent.action_cancel:                     {                                                     previouspoint=event.getx();                         if(previouspoint > startpoint){                             //right side swape                          }else{                         // left side swape                         }                      }break;                      }                     break;                 }                 }                 return true;             }         }; 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -