Time for action – handling touch events

Let's intercept touch events in DroidBlaster:

  1. In the same way that we created ActivityHandler to process application events in Chapter 5, Writing a Fully Native Application, create jni/InputHandler.hpp to process input events. The input API is declared in android/input.h. Create onTouchEvent() to handle touch events. These events are packaged in an AInputEvent 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
  2. Modify the jni/EventLoop.hpp header file to include and handle an ...

Get Android NDK Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.