I m currently writing a service that can read click coordinates via a 
service. 
I m now able to recieve the coordinates and write them to an external file 
but the click is not being passed to the main application even with the use 
of FLAG_NOT_TOUCH_MODAL. This result in total no respond from click while 
the service is running.
 
Code for the service and view is attached. Any guidance is greatly 
appreciated.

**
***

*

** 
**

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
package org.wordpress.android;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.text.SimpleDateFormat;

import android.content.Context;

import android.view.MotionEvent;
import android.view.View;

import android.widget.Toast;

public class HUDView extends View {

	float x, y; // for mouse


	public HUDView(Context context) {
		super(context);
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		x = event.getX();
		y = event.getY();
		SimpleDateFormat s = new SimpleDateFormat("dd/MM/yy-hh:mm:ss:SS");
		String format = s.format(System.currentTimeMillis());

		try {
			ObjectOutputStream oos = new ObjectOutputStream(
					new FileOutputStream(new File("/sdcard/click.txt"), true));

			oos.writeUTF(String.format("%.5f", x) + " "
					+ String.format("%.5f", y) + " " + format + "\n");
			Toast.makeText(getContext(), "x:" + x + " y:" + y, Toast.LENGTH_SHORT).show();
			oos.close();
		} catch (IOException ioe) {

			Toast.makeText(getContext(), "cannot write x:" + x + " y:" + y,Toast.LENGTH_SHORT).show();
		}
		return false;
	}
	


}
package org.wordpress.android;

import android.app.Service;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.IBinder;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

public class ClickService extends Service {
	TextView tv = new TextView(this); 
	//tv.setOnTouchListener(this); 

	HUDView mView;

	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}

	@Override
	public void onCreate() {
		super.onCreate();
		mView = new HUDView(this);
		WindowManager.LayoutParams params = new WindowManager.LayoutParams(
				//WindowManager.LayoutParams.MATCH_PARENT,
				//WindowManager.LayoutParams.MATCH_PARENT,
				WindowManager.LayoutParams.WRAP_CONTENT,
				WindowManager.LayoutParams.WRAP_CONTENT,
				WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
				WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
						| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
						| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
				PixelFormat.TRANSLUCENT);
		WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
		// Add layout to window manager
		//wm.addView(mView, params);
		wm.addView(tv, params);

	}

	@Override
	public void onDestroy() {
		super.onDestroy();
	}
	
	public boolean onTouch(View v, MotionEvent event) { 
	    // TODO Auto-generated method stub 
	    if(v == tv && event.getAction() == MotionEvent.ACTION_OUTSIDE) { 
	         // Do something 
	    }    
	    return false; 
	} 

}

Reply via email to