Author Topic: Source code location to add native HID joystick support?  (Read 13623 times)

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Source code location to add native HID joystick support?
« Reply #15 on: September 27, 2012, 05:16:08 PM »
From what I understand, this just removes Lint errors.  I think as long as you target 12 or higher for the release build (sounds like you're targeting 14?) it will compile just fine.  The 12+ code is excluded at runtime by the conditional checks.  I'm still new to this, but it seems like the standard approach when I looked at examples on the web.
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3496
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Source code location to add native HID joystick support?
« Reply #16 on: September 27, 2012, 05:34:41 PM »
Ok, great.  I'll post a test build for folks to run just to be sure, once I fix a different (unrelated) piece of code that is limiting the app to API 11 right now.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Source code location to add native HID joystick support?
« Reply #17 on: September 27, 2012, 05:37:56 PM »
Hmmm I thought I had this figured out but now I'm not sure after reading this.  If I comment that line out, I get Lint errors all over the place in SDLSurface.java, not just in the new stuff I added.  Some of the calls are using API 5, others API 11, and some of the new stuff I added uses API 12.  Are you explicitly doing run-time hardware checks before calling these methods?

onTouch uses some API 5 methods:
  • MotionEvent.getPointerId
  • MotionEvent.getPointerCount
  • MotionEvent.getX
  • MotionEvent.getY

onKey uses some API 11 methods:
  • ActionBar.hide
  • ActionBar.show
  • ActionBar.isShowing
  • Activity.getActionBar
  • View.setSystemUiVisibility

The native gamepad additions use some API 12 methods:
  • MotionEvent.getAxisValue
  • SurfaceView.setOnGenericMotionListener

Edit: Attached an updated diff file that is more conservative in the lint annotations.
« Last Edit: September 27, 2012, 05:47:37 PM by littleguy »
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3496
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Source code location to add native HID joystick support?
« Reply #18 on: September 27, 2012, 05:47:45 PM »
For the ActionBar stuff, I just put in checks like this:

Code: [Select]
if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB )
That's a good catch on the MotionEvent stuff.  I probably should change the minimum API level to 5 instead of 4.

It's odd you are getting error messages, though.  Generally it will let you build when you have the target API level high enough, but it will crash on the device if you call something that isn't there.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Source code location to add native HID joystick support?
« Reply #19 on: September 27, 2012, 05:51:11 PM »
It's odd you are getting error messages, though.  Generally it will let you build when you have the target API level high enough, but it will crash on the device if you call something that isn't there.
I probably have my Lint settings set conservatively, to error on compile rather than warn.

Edit: Here's the officially sanctioned idiom for supporting multiple platforms.  It recommends that you always target the highest available API for the release build.
« Last Edit: September 27, 2012, 05:56:09 PM by littleguy »
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3496
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Source code location to add native HID joystick support?
« Reply #20 on: September 27, 2012, 05:57:21 PM »
BTW, if it isn't a huge hassle, could you post the diff from the previous SDLSurface.java you had to this one (rather than from the original), since I've already committed the first one?  I can apply the changes by hand if it's too much trouble.

Also, if you'd like write access to the github repository, let me know your username and I can add you.  I don't mind uploading the changes myself, just thought I'd offer in case you are interested.
« Last Edit: September 27, 2012, 06:01:15 PM by Paul »
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Source code location to add native HID joystick support?
« Reply #21 on: September 27, 2012, 06:00:26 PM »
Sorry about that.  It's probably just as easy to do it by hand.  The only changes from the previous are to add/remove the @TargetsAPI annotations.  Just do a text search for "@TargetsAPI" in the latest diff.

Edit: and remove the @TargetsAPI(12) at the class declaration at the top.
« Last Edit: September 27, 2012, 06:02:01 PM by littleguy »
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3496
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Source code location to add native HID joystick support?
« Reply #22 on: September 27, 2012, 06:18:59 PM »
Weird.. when I started playing around with TargetApi, I began getting all kind of API-related errors that weren't there before.  I was able to do all of the changes you had except this one:

Code: [Select]
@@ -393,6 +398,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
                     GameActivityCommon.mSingleton.runOnUiThread(
                         new Runnable()
                         {
+                            @TargetApi(11)
                             public void run()
                             {
                                 if( GameActivityCommon.mSingleton.getActionBar

I went ahead and just left that one out, since that code is already inside a block that will only be run if the device is running Honeycomb or higher, due to this line:

Code: [Select]
            else if( key == KeyEvent.KEYCODE_BACK && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB )
And to shut up the other errors (from the Action Bar stuff), I just added @SuppressLint("NewApi") to the SDLSurface class.  There is definitely something screwy going on with the compiler, since it never had this problem before.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Source code location to add native HID joystick support?
« Reply #23 on: September 27, 2012, 06:53:31 PM »
Yeah, I was noticing the same.  It built out of the box with no problems, then I added my new code, got the Lint errors, then soon all sorts of stuff was giving compile errors where it hadn't before.
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Source code location to add native HID joystick support?
« Reply #24 on: September 28, 2012, 08:45:06 AM »
I forked the latest build on github (username littleguy77) so my inputs should be easier to integrate going forward.

Bear with me, I'm a git noob as well.  Been programming for in C++ for 15 years and C# for the past 6, using Visual Studio and Subversion.  I had a little Java and Eclipse experience going into this, but the Android SDK and Git are brand new.  Thanks for your patience as I have fun learning all this.  ;D
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3496
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Source code location to add native HID joystick support?
« Reply #25 on: September 28, 2012, 08:52:16 AM »
No problem.  I gave you write access to the main repository too, in case you need to use it.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Source code location to add native HID joystick support?
« Reply #26 on: September 28, 2012, 09:00:10 AM »
Thanks a lot ;D

Edit: Started a new branch, deleted my fork.  Better integration now.
« Last Edit: September 28, 2012, 11:32:47 AM by littleguy »
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Source code location to add native HID joystick support?
« Reply #27 on: October 01, 2012, 11:39:14 AM »
Paul - I think I'll try my hand at updating the key/axis mapping GUI over the next week or two.  I'll make a separate branch for this until it stabilizes, then you guys can see what you think.

Question: Is anyone already updating the keymapping UI right now?  I thought I saw a few commits by lioncash recently regarding the "scancode" dialog UI.  Don't want to duplicate efforts...
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3496
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Source code location to add native HID joystick support?
« Reply #28 on: October 01, 2012, 12:01:30 PM »
I haven't started on it, so you are welcome to take it on if you like.  I'm slowly hacking away at getting the overall theme to match and fix the "forgetful checkboxes" bugs, and that will take a while to complete.  I'll just leave the controller section for last so I don't step on your toes.

About the "scancode" dialog UI, lioncash just changed the xml layout on it to simplify the code.  The functionality wasn't changed.  As long as you branch from a commit sometime after that update, you should be good.

If you have any problems let me know.  I'm pretty familiar with that part of the code.
« Last Edit: October 01, 2012, 12:09:45 PM by Paul »
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Source code location to add native HID joystick support?
« Reply #29 on: October 01, 2012, 12:32:22 PM »
Will do.  Thanks much.
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version