Home > General > Robot Controll through Android Gesture Movement.

Robot Controll through Android Gesture Movement.

Here I will show you how to control Robot through the Gesture Movement, basically here I’m getting the gesture movement, left right, up, down, based on this value (X and Y direction), I’m passing this value to Controller through mobile bluetooth and based on this command Robot will move left, right, fwd, back.

Gesture detection is one of the great features of all touch based mobile devices. Gestures are patterns drawn by the user on the screen. Simple gestures include tap, scroll, swipe, etc. Complex gestures are more complex patterns drawn on the screen. In Android we can detect simple gestures using GestureDetector class and complex gestures using GestureOverlayView class.

These days, using an Android device is all about high-tech and hassle-free shortcuts. We’ve focused a lot on the voice-oriented side of things — controlling your phone by speaking with Google’s Voice Actions and Vlingo, for example — but talking to your technology isn’t always a practical option.

That’s where the power of Android gestures comes in. With the right set of Android tools, you can open apps, make calls, and even surf the Web by drawing simple lines on your phone’s screen. It’s quick, it’s easy — and it always gets a fun reaction out of non-Android owners in the areaGestureDetector is a class which is used to detect simple gestures like tap, scroll, swipe or fling, etc. This class detects gestures using the supplied MotionEvent class. We use this class along with the onTouchEvent, inside this method we call the GestureDetector.onTouchEvent. GestureDetector identify the gestures or events that occurred and report back to us using GestureDetector.OnGestureListener callback interface. We create an instance of the GestureDetector class by passing Context and GestureDetector.OnGestureListener listener.

Definistion –

The onDown method is called when the user first touch the screen, the MotionEvent parameter represents the event that corresponds to the touch event.

The onLongPress method is called when user touches the screen and holds it for a period of time. The MotionEvent parameter represents the event that corresponds to the touch event.

The onScroll method is called when the user touches the screen and moves to another location on the screen. This method has 4 parameters; first MotionEvent corresponds to the first touch event that occurred, second MotionEvent corresponds to the scroll that occurred, the distanceX parameter represents the scrolled distance along the X axis since the last call to onScroll and the forth parameter distanceY is the distance occurred along Y axis since the last call to onScroll. The third and forth parameters are little bit confusing and are not the distance between MotionEvent 1 and MotionEvent 2.

The onShowPress method is called when the user touches the phone and not moved yet. This event is mostly used for giving visual feedback to the user to show their action.

The onSingleTapUp method is called when a tap occurred, i.e. use taps the screen.

The onFling method is called whenever the user swipes the screen in any direction, i.e. the user touches the screen and immediately moves the finger in any direction. The first parameter is the MotionEvent corresponds to the touch event that started the fling, second parameter is the MotionEvent that corresponds to the movement that triggered the fling, the third one corresponds to the velocity along X axis measured and the forth one corresponds to the velocity along Y axis measured. The use of this gesture depends on application to application. Some application starts the movement of some objects in the screens with velocity based on the X and Y velocity measured and gradually slows down the movement and settled the objects somewhere on the screen. Another use of this method is to move from one page to another within the application.


You should be noticed that the double-tap event is not present in the GestureDetector.onGestureListener callback interface. For some reason this event is reported using another callback interface GestureDetector.onDoubleTapListener. To use this callback interface we have to register for these events using GestureDetector.setOnDoubleTapListener passing the above listener. This interface has the following methods:

Java code :-

package com.sst.robot.movement;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.GestureDetector.OnGestureListener;
import android.widget.LinearLayout;
import android.widget.TextView;
public class ControlRobotwithGestureMovementActivity extends Activity
OnGestureListener {
private LinearLayout main;
private TextView viewA;
private GestureDetector gestureScanner;
public void onCreate(Bundle savedInstanceState) {
gestureScanner = new GestureDetector(this);
main = new LinearLayout(this);
main.setLayoutParams(new LinearLayout.LayoutParams(720, 1120));
viewA = new TextView(this);
viewA.setLayoutParams(new LinearLayout.LayoutParams(720, 1120));
public boolean onTouchEvent(MotionEvent me) {
return gestureScanner.onTouchEvent(me);
public boolean onDown(MotionEvent e)

viewA.setText(“Going ” + “DOWN” + “V”);
return true;
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
viewA.setText(” ” + “FLING” + ” ” + velocityX + ” ” + velocityY);
return true;
public void onLongPress(MotionEvent e) {
viewA.setText(“You Pressed ” + ” LONG” + “-“);
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
viewA.setText(“Its ” + “SCROLLING” + ” ” + distanceX + ” ” + distanceY);
return true;
public void onShowPress(MotionEvent e) {
viewA.setText(“You pressed screen” + “SHOW PRESS”);
public boolean onSingleTapUp(MotionEvent e) {
viewA.setText(“You made ” + “SINGLE TAP “);
return true;
public boolean onDoubleTap(MotionEvent e) {
viewA.setText(“You made ” + “Double TAP “);
return true;



Categories: General
  1. February 20, 2013 at 12:24 am

    how can you connect android device to robot ? bluetooth ?

  2. February 20, 2013 at 5:10 am

    Yes, bluetooth, wifi

    • February 20, 2013 at 6:14 am

      can I see the code for bluetooth, please ? thanks

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: