gesture - difference between click and tap in Android -
the [gesturedetector.ongesturelistener][1] class has method [onsingletapup(motionevent)][2]:
notified when tap occurs motionevent que triggered it.
this method has same onclick's function? can use method implement same behavior want onclick method?
i did tests , seems answer yes, may use onsingletapup instead of onclick. onsingletapup method can differentiate simple click of double or long click. test:
public class mainfragmentscrollercontroller { private mainfragment mfragment; private gesturedetectorcompat mgesturedetector; public mainfragmentscrollercontroller(mainfragment fragment) { mfragment = fragment; mgesturedetector = new gesturedetectorcompat(mfragment.getactivity(), new gesturelistener()); } public void setgesturelistener() { mfragment.myview.setontouchlistener(new ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { boolean gestureresult = mgesturedetector.ontouchevent(event); log.i("gesturelistener", "gestureresult = " + gestureresult); return gestureresult; } }); } public class gesturelistener extends simpleongesturelistener { private final string tag = "gesturelistener"; @override public boolean ondown(motionevent event) { log.d(tag,"ondown: " + event.tostring()); return true; } @override public boolean onfling(motionevent event1, motionevent event2, float velocityx, float velocityy) { log.d(tag, "onfling: " + event1.tostring()+event2.tostring()); return true; } @override public boolean onscroll(motionevent event1, motionevent event2, float distancex, float distancey) { log.d(tag, "onscroll: " + event1.tostring()+event2.tostring()); return true; } @override public boolean onsingletapup(motionevent event) { log.d(tag, "onsingletapup: " + event.tostring()); return true; } @override public void onlongpress(motionevent event) { log.d(tag, "onlongpress: " + event.tostring()); } } }
result simple click:
09-04 14:20:58.040: d/gesturelistener(17689): ondown: motionevent { action=action_down, id[0]=0, x[0]=188.71875, y[0]=26.0625, tooltype[0]=tool_type_finger, buttonstate=0, metastate=0, flags=0x0, edgeflags=0x0, pointercount=1, historysize=0, eventtime=34463725, downtime=34463725, deviceid=1, source=0x1002 } 09-04 14:20:58.040: i/gesturelistener(17689): gestureresult = true 09-04 14:20:58.100: i/gesturelistener(17689): gestureresult = false 09-04 14:20:58.130: d/gesturelistener(17689): onsingletapup: motionevent { action=action_up, id[0]=0, x[0]=188.71875, y[0]=26.0625, tooltype[0]=tool_type_finger, buttonstate=0, metastate=0, flags=0x0, edgeflags=0x0, pointercount=1, historysize=0, eventtime=34463811, downtime=34463725, deviceid=1, source=0x1002 } 09-04 14:20:58.130: i/gesturelistener(17689): gestureresult = true
result long click:
09-04 14:22:12.520: d/gesturelistener(17689): ondown: motionevent { action=action_down, id[0]=0, x[0]=179.22656, y[0]=41.0625, tooltype[0]=tool_type_finger, buttonstate=0, metastate=0, flags=0x0, edgeflags=0x0, pointercount=1, historysize=0, eventtime=34538199, downtime=34538199, deviceid=1, source=0x1002 } 09-04 14:22:12.520: i/gesturelistener(17689): gestureresult = true 09-04 14:22:12.560: i/gesturelistener(17689): gestureresult = false 09-04 14:22:12.930: i/gesturelistener(17689): gestureresult = false 09-04 14:22:12.950: i/gesturelistener(17689): gestureresult = false 09-04 14:22:13.010: i/gesturelistener(17689): gestureresult = false 09-04 14:22:13.100: i/gesturelistener(17689): gestureresult = false 09-04 14:22:13.130: i/gesturelistener(17689): gestureresult = false 09-04 14:22:13.150: i/gesturelistener(17689): gestureresult = false 09-04 14:22:13.180: i/gesturelistener(17689): gestureresult = false 09-04 14:22:13.200: d/gesturelistener(17689): onlongpress: motionevent { action=action_down, id[0]=0, x[0]=179.22656, y[0]=41.0625, tooltype[0]=tool_type_finger, buttonstate=0, metastate=0, flags=0x0, edgeflags=0x0, pointercount=1, historysize=0, eventtime=34538199, downtime=34538199, deviceid=1, source=0x1002 } 09-04 14:22:13.230: i/gesturelistener(17689): gestureresult = false
result fling:
09-04 14:24:09.650: d/gesturelistener(17689): ondown: motionevent { action=action_down, id[0]=0, x[0]=332.15625, y[0]=2.625, tooltype[0]=tool_type_finger, buttonstate=0, metastate=0, flags=0x0, edgeflags=0x0, pointercount=1, historysize=0, eventtime=34655337, downtime=34655337, deviceid=1, source=0x1002 } 09-04 14:24:09.650: i/gesturelistener(17689): gestureresult = true 09-04 14:24:09.690: d/gesturelistener(17689): onscroll: motionevent { action=action_down, id[0]=0, x[0]=332.15625, y[0]=2.625, tooltype[0]=tool_type_finger, buttonstate=0, metastate=0, flags=0x0, edgeflags=0x0, pointercount=1, historysize=0, eventtime=34655337, downtime=34655337, deviceid=1, source=0x1002 }motionevent { action=action_move, id[0]=0, x[0]=331.9604, y[0]=-72.36835, tooltype[0]=tool_type_finger, buttonstate=0, metastate=0, flags=0x0, edgeflags=0x0, pointercount=1, historysize=2, eventtime=34655368, downtime=34655337, deviceid=1, source=0x1002 } 09-04 14:24:09.690: i/gesturelistener(17689): gestureresult = true 09-04 14:24:09.710: d/gesturelistener(17689): onscroll: motionevent { action=action_down, id[0]=0, x[0]=332.15625, y[0]=2.625, tooltype[0]=tool_type_finger, buttonstate=0, metastate=0, flags=0x0, edgeflags=0x0, pointercount=1, historysize=0, eventtime=34655337, downtime=34655337, deviceid=1, source=0x1002 }motionevent { action=action_move, id[0]=0, x[0]=337.91425, y[0]=-124.40411, tooltype[0]=tool_type_finger, buttonstate=0, metastate=0, flags=0x0, edgeflags=0x0, pointercount=1, historysize=2, eventtime=34655385, downtime=34655337, deviceid=1, source=0x1002 } 09-04 14:24:09.710: i/gesturelistener(17689): gestureresult = true 09-04 14:24:09.730: d/gesturelistener(17689): onfling: motionevent { action=action_down, id[0]=0, x[0]=332.15625, y[0]=2.625, tooltype[0]=tool_type_finger, buttonstate=0, metastate=0, flags=0x0, edgeflags=0x0, pointercount=1, historysize=0, eventtime=34655337, downtime=34655337, deviceid=1, source=0x1002 }motionevent { action=action_up, id[0]=0, x[0]=337.91425, y[0]=-124.40411, tooltype[0]=tool_type_finger, buttonstate=0, metastate=0, flags=0x0, edgeflags=0x0, pointercount=1, historysize=0, eventtime=34655414, downtime=34655337, deviceid=1, source=0x1002 } 09-04 14:24:09.730: i/gesturelistener(17689): gestureresult = true
Comments
Post a Comment