Time for action – handling accelerometer events
Let's handle accelerometer events in
DroidBlaster
:
- Open
jni/InputHandler.hpp
and add a new methodonAccelerometerEvent()
. Include theandroid/sensor.h
official header for sensors:#ifndef _PACKT_INPUTHANDLER_HPP_ #define _PACKT_INPUTHANDLER_HPP_ #include <android/input.h> #include <android/sensor.h> class InputHandler { public: virtual ~InputHandler() {}; virtual bool onTouchEvent(AInputEvent* pEvent) = 0; virtual bool onKeyboardEvent(AInputEvent* pEvent) = 0; virtual bool onTrackballEvent(AInputEvent* pEvent) = 0; virtual bool onAccelerometerEvent(ASensorEvent* pEvent) = 0; }; #endif
- Create new methods in
jni/EventLoop.hpp
:activateAccelerometer()
anddeactivateAccelerometer()
to enable/disable the ...
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.