'Background' Gesture Detector

Put your problem here if it does not fit any of the other categories.

'Background' Gesture Detector

Postby schrecklichkeit » Tue Feb 08, 2011 7:52 am

Hi guys, I'm new to Android here.

I've managed to create a GestureDetector on an Activity class, basically it was a cut and paste of this snippet found here, and the code works perfectly.
http://www.androidsnippets.org/snippets/19/index.html

I'm actually trying to create an application that is able to detect all the user's gesture activities (well actually just onSingleTapUp) in the background, meaning without a proper Activity interface.

Can anyone point out a good direction for me to start with? I tried doing up a Service since I didn't want a UI and the code looks like this
Code: Select all
public class GestureService extends Service implements OnGestureListener {
    private GestureDetector gestureScanner;
   
   
   /** Called when the activity is first created. */
    @Override
    public void onCreate() {
        super.onCreate();
       
        gestureScanner = new GestureDetector(this);
        Toast.makeText(this, "onCreate", Toast.LENGTH_SHORT).show();
    }
   
    @Override
   public int onStartCommand(Intent intent, int flags, int startId) {
       Toast.makeText(this, "onStartCommand", Toast.LENGTH_SHORT).show();
       return START_STICKY;
       
    }
   
    public boolean onTouchEvent(MotionEvent me) { 
        return gestureScanner.onTouchEvent(me); 
    } 

   @Override
   public boolean onDown(MotionEvent arg0) {
      // TODO Auto-generated method stub
      Toast.makeText(this, "Down", Toast.LENGTH_SHORT).show();
      return false;
   }

   @Override
   public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
         float velocityY) {
      // TODO Auto-generated method stub
      Toast.makeText(this, "Fling", Toast.LENGTH_SHORT).show();
      return false;
   }

   @Override
   public void onLongPress(MotionEvent e) {
      // TODO Auto-generated method stub
      Toast.makeText(this, "LongPress", Toast.LENGTH_SHORT).show();
   }

   @Override
   public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
         float distanceY) {
      // TODO Auto-generated method stub
      Toast.makeText(this, "Scroll", Toast.LENGTH_SHORT).show();
      return false;
   }

   @Override
   public void onShowPress(MotionEvent e) {
      // TODO Auto-generated method stub
      Toast.makeText(this, "ShowPress", Toast.LENGTH_SHORT).show();
   }

   @Override
   public boolean onSingleTapUp(MotionEvent e) {
      // TODO Auto-generated method stub
      Toast.makeText(this, "SingleTapUp", Toast.LENGTH_SHORT).show();
      return false;
   }

   @Override
   public IBinder onBind(Intent arg0) {
      // TODO Auto-generated method stub
      return null;
   }
}


I've run the Service and verified the OnCreate() and OnStartCommand() methods run. But I am unable to get any of the gesture callbacks, either on the parent app screen or on any other screen. I want it so that it can work on any screen the user is on.. Please help!
schrecklichkeit
Freshman
Freshman
 
Posts: 2
Joined: Tue Feb 08, 2011 7:44 am

Top

Re: 'Background' Gesture Detector

Postby Chitra » Tue Feb 08, 2011 1:31 pm

whr is 'OnSingleTabConfirmed' override method??
Thanks,
Chitra
User avatar
Chitra
Master Developer
Master Developer
 
Posts: 213
Joined: Mon Mar 01, 2010 7:59 am
Location: Bangalore

Re: 'Background' Gesture Detector

Postby schrecklichkeit » Wed Feb 09, 2011 3:51 am

Chitra wrote:whr is 'OnSingleTabConfirmed' override method??


I do not understand what you are asking. Did you mean onSingleTapUp? I've included the Override method in the code I posted.

I have managed to get onSingleTapUp() to fire when the GestureDetector was done inside an Activity. I am trying to change it from an Activity to a Service, and that is when onSingleTapUp() does not happen
schrecklichkeit
Freshman
Freshman
 
Posts: 2
Joined: Tue Feb 08, 2011 7:44 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 16 guests