I am currently immersed in Android development and have recently encountered difficulties. I would like to create an overlay application that lies on top of all other applications. He should listen to three fingers, while all other touch events should be handled by the OS (for example, the base application).
Is it possible?
I already figured out that I need to add LayoutParam TYPE_PHONE instead of SYSTEM_ALERT, since the latter will consume all touch events. So my class is as follows:
package [...] public class Overlay extends Service { private TView mView; private ThreeFingerSwipeDetector detector = new ThreeFingerSwipeDetector() { @Override public void onThreeFingerTap() { Toast.makeText(getBaseContext(), "Three Fingers recognized.", Toast.LENGTH_SHORT).show(); } }; @Override public IBinder onBind(Intent intent) { return null; } @Override public void onCreate() { super.onCreate(); Toast.makeText(getBaseContext(), "Launched! :-)", Toast.LENGTH_SHORT).show(); mView = new TView(this); WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
The detector will correctly recognize three fingers, but my application in its current state will block all other user interactions with the main user interface until I kill the application.
Is there any system call that can be called using MotionEvent as a parameter, where is my TODO annotation now? Or do I want something that is simply impossible?
Best wishes and thank you!
Edit : The ThreeFingerSwipeDetector class looks like this:
[Import, ...] public abstract class ThreeFingerSwipeDetector { public boolean onTouchEvent(MotionEvent event) { int t = event.getActionMasked(); switch(event.getActionMasked()) { case MotionEvent.ACTION_POINTER_DOWN: if(event.getPointerCount() == 3) onThreeFingerTap(); return true; case MotionEvent.ACTION_DOWN: if(event.getPointerCount() == 3) { onThreeFingerTap(); return true; } } return false; } public abstract void onThreeFingerTap(); }
In fact, it is still not recognizing wipes, but at the moment it checks only three fingers. In any case, the logic there should be the same.