Android Question Touch MotionEvent

Robert Valentino

Well-Known Member
Licensed User
Longtime User
How do I define a MotionEvent so I can reference the individual fields?

I have a Touch Event
B4X:
X_Touch(ViewTag As Object, Action As Int, X As Float, Y As Float, MotionEvent As Object) As Boolean

And I want to determine it the event is a finger touch or a mouse click

Is there a way of mapping the MotionEvent object I am getting?

BobVal
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I guess what I need to do is getActionMasked so I can look for Pointer Up. I know there are values for mouse over touching

B4X:
    View.OnTouchListener touchListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getActionMasked() == MotionEvent.ACTION_UP) {
                onTap(event.getRawX(), event.getRawY());
            }
            return false;
        }


Also found this link
 
Last edited:
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Still trying:
When I log out the MotionEvent as an object I get the following output
B4X:
MotionEvent:MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=1255.9507, y[0]=48.113556, toolType[0]=TOOL_TYPE_MOUSE, buttonState=BUTTON_PRIMARY, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=3996583315, downTime=3996583315, deviceId=22, source=0x2002, displayId=0, eventId=565598001 }

MotionEvent:MotionEvent { action=ACTION_UP, actionButton=0, id[0]=0, x[0]=1255.9507, y[0]=48.113556, toolType[0]=TOOL_TYPE_MOUSE, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=3996583419, downTime=3996583315, deviceId=22, source=0x2002, displayId=0, eventId=352123500 }

So I made a Type structure to try and map over it
B4X:
  Type TMotionEvent(action As String, actionButton As Int, id() As Int, x() As Float, y() As Float, toolType() As String, buttonState As String, classification As String,  _
           metaState As Int, flags As Int, edgeFlags As Int, pointerCount As Int, historySize As Int, eventTime As Long, downTime As Long, deviceId As Int, source As Int,  _                displayId As Int, eventId As Long)

This causes a BIG time crash so that says to m the TMotionEvent is either not defined right ot MotionEvent is maybe a map and I have to ask for the fields???
 
Upvote 0
Top