Create MotionEvent

tpakis

Active Member
Licensed User
Longtime User
I'm trying with reflection library to make a motionevent but without luck. I have this code form stackoverflow on how to simulate a touch event

// Obtain MotionEvent object
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis() + 100;
float x = 0.0f;
float y = 0.0f;
// List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState()
int metaState = 0;
MotionEvent motionEvent = MotionEvent.obtain(
downTime,
eventTime,
MotionEvent.ACTION_UP,
x,
y,
metaState
);

and i want to make get a random x,y motionevent to pass on a panel. I can easily send a detected motion event to any view again with relection but how can i make a new motionevent? Any help??
 

tpakis

Active Member
Licensed User
Longtime User
ok think i got it:
B4X:
uptime = r.RunStaticMethod("android.os.SystemClock", "uptimeMillis", Null, Null)
eltime=uptime+100
motion1=r.RunStaticMethod("android.view.MotionEvent","obtain",Array As Object(uptime,eltime,0,10,10,0),Array As String("java.lang.long","java.lang.long","java.lang.int","java.lang.float","java.lang.float","java.lang.int"))

but when i try to pass it to a panel by:
B4X:
 r.Target=Panel1
  r.RunMethod4("onTouchEvent", Array As Object(motion1), Array As String("android.view.MotionEvent"))

panel touch event doesn't fire... any ideas??
 
Upvote 0

tpakis

Active Member
Licensed User
Longtime User
I'm trying to emulate a user touch.

Inside panel1_touch i have the panel to disapear and a listview bringtofront.

If i call panel1_touch, i can't click anything on the listview only scroll it up or down and then i can click the items (this happens ONLY on android 4+). If the user touches the panel and then panel1_touch gets called, the listview works 100% without any problems :confused::confused::confused:

So i try to make with code the touch on the panel. I know this is not the solution, and i have already found a different approach with that specific app, but now it's also interesting to know how to emulate a touch...:)
 
Upvote 0
Top