Wiki
Clone wikirobobo-programming / native / touch-library
Using touch library
The touch library provides a interface for using the touch capabilities of the smartphone. The library is composed by one module:
Touch module
This module allows the developer to use touch gestures in a easy way.
The interface of this module is shown below:
public interface ITouchModule extends IModule{ void suscribe(ITouchListener listener); void unsuscribe(ITouchListener listener); boolean feedTouchEvent(MotionEvent event); }
The suscribe()
and unsuscribe()
methods are used to suscribe the different classes implementing
ITouchListener
to the captured touch events.
feedTouchEvent()
must be called in the main activity of the application to pass the
captured touch events to the gesture detector inside the Touch module.
The classes which want to be notified of the touch events must implement the ITouchListener
interface:
public interface ITouchListener { void tap(Integer x, Integer y); void touch(Integer x, Integer y); void fling(TouchGestureDirection dir, double angle, long time, double distance); void caress(TouchGestureDirection dir); }
There are four classes of events fired by the module:
tap()
is called when a single, short tap is made on the screen, whith the position of the
tap as argument.
touch()
is analogous to tap, but only fired when the tap lasts more than 500 ms.
fling()
is called when a fast, swiping motion is detected. The arguments are the direction,
the angle , the time elapsed and the distance of the gesture.
caress()
is called when there is swiping motion over the screen, with the direction of the motion
as argument.
Obtaining the instance of the module
ITouchModule touchModule = roboboManager.getModuleInstance(ITouchModule.class);
Current implementation
AndroidTouchModule
This implementation whas developed using the GestureDetector
class provided by the
Android API.
To use this module on your ROBOBO project it must be declared on the modules.properties
file
of the project as follows:
robobo.module.0 = com.mytechia.robobo.framework.hri.touch.android.AndroidTouchModule
The javadoc documentation of this module can be found here
Updated