Game Development Reference
In-Depth Information
case 3:
DialogTool.showNavMethodDialog(this);
return true;
case 6:
// Exit
DoomTools.hardExit(0);
return true;
}
return false;
}
Key and Touch Event Handlers
Key and touch handlers can be overridden to process key and touch events. Doom handles
key and touch events as follows (see Listing 5-5):
keyCode is first translated to an ASCII key symbol by calling
int sym = DoomTools.keyCodeToKeySym(keyCode) .
The ASCII symbol is then sent to the DSO through the native interface
The Android
class Natives.keyEvent(EVENT_TYPE, SYMBOL) where the event type
must be either Natives.EV_KEYUP or Natives.EV_KEYDOWN . Note that any
errors in the native side (such as a missing symbol or invalid signature)
will throw an UnsatisfiedLinkError .
Listing 5-5. Key and Touch Handlers
public boolean onKeyUp(int keyCode, KeyEvent event) {
//
if (keyCode == KeyEvent.KEYCODE_MENU) {
return false;
}
int sym = DoomTools.keyCodeToKeySym(keyCode);
try {
Natives.keyEvent(Natives.EV_KEYUP, sym);
} catch (UnsatisfiedLinkError e) {
// Should not happen
Log.e(TAG, e.toString());
}
return false;
}
 
Search WWH ::




Custom Search