Skip to content

Instantly share code, notes, and snippets.

@eyal-lezmy
Last active August 29, 2015 14:04
Show Gist options
  • Save eyal-lezmy/186f676b9ce089cd48a4 to your computer and use it in GitHub Desktop.
Save eyal-lezmy/186f676b9ce089cd48a4 to your computer and use it in GitHub Desktop.
Detect the touch on screen silently
package overlaytouch.eyal.fr.overlaytouch;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.IBinder;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;
/**
* Created by Eyal on 23/07/2014.
*/
public class TouchService extends Service {
TouchView mView;
@Override
public void onCreate() {
super.onCreate();
mView = new TouchView(this);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
1,1,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL|WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.RIGHT | Gravity.TOP;
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(mView, params);
}
public class TouchView extends View {
public TouchView(Context context) {
super(context);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
Log.d("tag", "onTouchEvent" + event.getAction());
return false;
}
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment