Android Question NVIDIA SHIELD! Analog JoyStick Access

bbonilla

Member
Licensed User
Longtime User
Hello Erel

Any news on analog joystick support in B4A. I need to write the control app for android on the Nvidia Shield.
Thank you for the good work.
BB
 

PaulR

Active Member
Licensed User
Longtime User
I don't have any joysticks to test with, but I had a look at this, which looks like it could be implemented with JavaObject in b4a.
B4X:
Sub Globals
     Dim pnl As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
    pnl.Initialize("")
    Dim jo As JavaObject = pnl
    Dim e As Object = jo.CreateEvent("android.view.View.OnGenericMotionListener", _
                     "pnl", False)
    jo.RunMethod("setOnGenericMotionListener", Array(e))
    Activity.AddView(pnl, 0, 0, 100%x, 100%y)
End Sub

Sub pnl_Event(methodName As String, args() As Object) As Boolean
    Dim motionEvent As JavaObject = args(1)
    Dim action As Int = motionEvent.RunMethod("getAction", Array())
    Dim deviceId As Int = motionEvent.RunMethod("getDeviceId", Array())
    Log("action: "&action)
    Log("deviceId: "&deviceId)
    Return True
End Sub
 
Last edited:
Upvote 0

bbonilla

Member
Licensed User
Longtime User

********************************************************************************************
Thank you for your quick response, I'm very new at the B4A so I don't know a lot of things, My strengths are in the ATMEL firmware development.

I copy the your code and I got this error, what I'm missing? Please picture thank you.
P.S I moved the DIM pnl As Panel to the proper section.
 

Attachments

  • Nvidia.jpg
    279.6 KB · Views: 275
Upvote 0

bbonilla

Member
Licensed User
Longtime User
You are missing the JavaObject library. You'll notice when you try to compile the code with this library in place that pnl was declared in the correct place too.

Thank for the LIB, but know I have one more problem. Sorry for my lack of understanding on the subject.
 

Attachments

  • Nvidia2.jpg
    267.9 KB · Views: 254
Upvote 0

PaulR

Active Member
Licensed User
Longtime User
Sorry, that's my fault - the error is because b4a v3.8 has allowed 'Array' to be used as shorthand for 'Array as Object'. So it should be....
B4X:
jo.RunMethod("setOnGenericMotionListener", Array as Object(e))
.... for users of versions <3.8.
 
Upvote 0

bbonilla

Member
Licensed User
Longtime User


Thank you so much for your time, it now compiles, but there are no events being capture by the pnl_OnGenericMotionListener sub.
So there is not much that can be done.
Thank you
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Download the attached jar file and copy it to the additional libraries folder.

Add these lines to the activity:
B4X:
#AdditionalJar: ActivityEx
#Extends: anywheresoftware.b4a.objects.ActivityEx

This will allow you to handle the activity onGenericMotionEvent:
B4X:
Sub Activity_OnGenericMotionEvent(MotionEvent As Object)
   Log(MotionEvent)
End Sub

You can now use JavaObject to access MotionEvent.
 

Attachments

  • ActivityEx.jar
    1 KB · Views: 270
Upvote 0

PaulR

Active Member
Licensed User
Longtime User
I've edited the code in post #2, which now works (at least it is producing action and device ids in Genymotion) - the event sub did not have the correct name so was never called. Sorry about the confusion.
 
Upvote 0

bbonilla

Member
Licensed User
Longtime User


Thank you Erel, I now can log events and I see x and y values, how can I get access to these values.
thank you in advanced.
 
Upvote 0

bbonilla

Member
Licensed User
Longtime User
Thank you Erel, I was able to get the x and y values for only one of the joysticks. But this gives me a good place to start.
 
Upvote 0

bbonilla

Member
Licensed User
Longtime User
No I'm sorry but I had to stop, I was only able to get X&Y for one joystick, and it was taking to long, so I had to stop for now.
Thank you asking.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…