Using an XBOX 360 Controller on Android

I’ve been working on a few Android games in my spare time. With the rollout of Honeycomb to my Logitech Revue, I’ve been able to finally test these games on it. One of the things I noticed was that the Revue has USB Host support and (wired) Xbox 360 controllers are simply plug and play. Using them is quite simple as well; the button presses are mostly mapped to the key event. The left and right triggers, right directional stick, and analog inputs are not mapped through this method however. The left analog stick and directional pads have their inputs mapped to direction buttons.

[sourcecode language=”java”]
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch(keyCode) {
case KeyEvent.KEYCODE_BUTTON_L1:
case KeyEvent.KEYCODE_BUTTON_R1:
case KeyEvent.KEYCODE_DPAD_UP:
case KeyEvent.KEYCODE_BUTTON_MODE://Big button in the middle
return super.onKeyDown(keyCode, keyEvent);

Of special note, KeyEvent.KEYCODE_BUTTON_B goes back and KeyEvent.KEYCODE_BUTTON_START pulls up home bar in the default implementation. Also, the “A” button has special behaviors which I don’t fully understand.

For the analog controls however, we must override the method onGenericMotionEvent as follows:

[sourcecode language=”java”]
public boolean onGenericMotionEvent(MotionEvent event) {

Log.d("Right Trigger Value", event.getAxisValue(MotionEvent.AXIS_RTRIGGER) + "");
Log.d("Left Trigger Value", event.getAxisValue(MotionEvent.AXIS_LTRIGGER) + "");

Log.d("Left Stick X", event.getX() + "");
Log.d("Left Stick Y", event.getY() + "");

Log.d("Right Stick Y", event.getAxisValue(MotionEvent.AXIS_RZ) + "");
Log.d("Right Stick X", event.getAxisValue(MotionEvent.AXIS_Z) + "");

return super.onGenericMotionEvent(event);

Google Dart Lightning Talk

A few months ago I gave a talk about Google Dart. Here is the presentation.

[gview file=”” force=”1″]

Getting Started Writing Groovy Tests With Maven and Netbeans

Lately I’ve been trying my hand at non Java languages on the JVM. Since Groovy is quite popular and a well supported language, I was giving it a go. Maven and Netbeans are my preferred project and IDE systems, and I had used GMaven at work so I knew it COULD be done. As a good TDD Developer I decided my first task would be to write a failing unit test and thus began my troubles.

GMaven works by generating Java stubs which are then compiled. This way the IDE has excellent intellisense, static analysis, and other goodies when you use the Groovy code in Java. This has the side effect of requiring a clean and build for every change. The extra step ends up really slowing down my rhythm and I tried to avoid it. Browsing around, it seemed like the groovy-eclipse-compiler plugin would help here. After setting that up, however, my trivial unit test always passed when it should have failed. Eventually I gave up and went back to GMaven.

The GMaven plugin has a project archetype. (mvn archetype:generate -DarchetypeGroupId=org.codehaus.gmaven.archetypes -DarchetypeArtifactId=gmaven-archetype-basic for the lazy), but the default implementation has busted unit tests. I had to remove the import statements from the examples before I could run them. Finally I was given my red bar and could begin coding in earnest.

Overall, this has been far more work than I had hoped. It seems like the GMaven project is thinking about merging with the eclipse compiler project. They hope to solve the stub issue this way, but that seems to be a ways off.