why is Android MotionEvent.getHistoricalX is thowing an exception -
i using gesturedetector.ongesturelistener
in order implement pinch-to-zoom in android. extending textview
class , therefore method settextsize()
implemented. following code onscroll()
.
@override public boolean onscroll(motionevent e1, motionevent e2, float distancex, float distancey) { if(logging) log.v(module_name, "onscroll()"); float x, y; float olddist, newdist; if (e2.getpointercount() == 2 && ((e2.getaction() & motionevent.action_mask) == motionevent.action_move)) { x = e2.gethistoricalx(0, 0) - e2.gethistoricalx(1, 0); y = e2.gethistoricaly(0, 0) - e2.gethistoricaly(1, 0); olddist = floatmath.sqrt(x * x + y * y); if (olddist > 10) { if (logging) log.d(module_name, "starting zoom mode"); x = e2.getx(0) - e2.getx(1); y = e2.gety(0) - e2.gety(1); newdist = floatmath.sqrt(x * x + y * y); if (newdist > 30) { float scalefactor = (newdist > olddist) ? olddist : newdist; float scale = (newdist - olddist) / scalefactor; // callback processed in main thread settextsize(scale * currenttextsize); olddist = newdist; } scrolldetected = true; return true; } } return false; }
my problem occasionally, not always, gethistoricalx()
throws exception. attaching logcat result.
07-31 16:53:30.358: v/zoomtextview(19540): onscroll() 07-31 16:53:30.358: e/inputeventreceiver(19540): exception dispatching input event. 07-31 16:53:30.358: e/messagequeue-jni(19540): exception in messagequeue callback: handlereceivecallback 07-31 16:53:30.358: e/messagequeue-jni(19540): java.lang.illegalargumentexception: historypos out of range 07-31 16:53:30.358: e/messagequeue-jni(19540): @ android.view.motionevent.nativegetaxisvalue(native method) 07-31 16:53:30.358: e/messagequeue-jni(19540): @ android.view.motionevent.gethistoricalx(motionevent.java:2739)
since know there 2 pointers , history @ least size of 0, not clear me how or why exception occurs. can please assist?
i saw this similar question, , of no me.
before using gethistoricalx()
or gethistoricaly()
, should check size gethistorysize()
.
if returns zero, know there no historical events. have process current events, using getx()
, gety()
.
Comments
Post a Comment