I'm trying to get an Android program to recognize a gaming controller for the Ouya. I can make the following code work when it is alone, but I am using a framework that I would like to plug it into. I have tried a few different things (instantiating the class in another one, etc., but so far what I have tried hasn't worked. Can you help me know what to do to make this into its own class and have it take action when someone uses the controller? Thank you!
Here is my code:
import tv.ouya.console.api.OuyaController;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
public class SampleGame extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
OuyaController.init(this);
}
@Override
public boolean onKeyDown(final int keyCode, KeyEvent event){
//Get the player #
int player = OuyaController.getPlayerNumByDeviceId(event.getDeviceId());
boolean handled = false;
//Handle the input
switch(keyCode){
case OuyaController.BUTTON_O:
System.out.println("Button 'O' was pressed.");
//doSomethingWithKey();
handled = true;
break;
case OuyaController.BUTTON_U:
System.out.println("Button 'U' was pressed.");
//doSomethingWithKey();
handled = true;
break;
case OuyaController.BUTTON_Y:
System.out.println("Button 'Y' was pressed.");
//doSomethingWithKey();
handled = true;
break;
case OuyaController.BUTTON_A:
System.out.println("Button 'A' was pressed.");
//doSomethingWithKey();
handled = true;
break;
}
return handled || super.onKeyDown(keyCode, event);
}
}