Time for action – handling touch events
Let's intercept touch events in DroidBlaster
:
In the same way that we created
ActivityHandler
to process application events in Chapter 5, Writing a Fully Native Application, createjni/InputHandler.hpp
to process input events. The input API is declared inandroid/input.h
. CreateonTouchEvent()
to handle touch events. These events are packaged in anAInputEvent
structure. Other input peripherals will be described later in this chapter:#ifndef _PACKT_INPUTHANDLER_HPP_ #define _PACKT_INPUTHANDLER_HPP_ #include <android/input.h> class InputHandler { public: virtual ~InputHandler() {}; virtual bool onTouchEvent(AInputEvent* pEvent) = 0; }; #endif
Modify the
jni/EventLoop.hpp
header file to include and handle anInputHandler
instance.In a similar way, to activity events, define an internal method
processInputEvent()
, which is triggered by a static callbackcallback_input()
:... #include "ActivityHandler.hpp" #include "InputHandler.hpp" #include...