How to listen in background for touch events ...

SagePourpre

Member
Licensed User
Longtime User
Hi everyone,

I was wondering if someone had an idea of how to proceed to listen
for touch events transparently, as like many app launchers are doing.

Example :
(blue line are normally invisible and are actually the reactive area of the app which will triggers the layout activity when touched.)
Pie Control
EwnwdTy.png


I figured that I need to create a service that would listen for touch
events in defined area and launch the wanted activity (the current launcher).

My question, i suppose, is: How do I listen "silently" (as I want the
launcher being accessible from any apps) to listen for touch events.

I've been through the 10 first pages of the user examples and looked for
some hours on the forums without finding a propper method to do that.
Anybody could enlighten me on the matter ?

Meanwhile, I'll continue to look out and post my findings
so hopefully it can helps others too (provided that I find something more
on it.
 

SagePourpre

Member
Licensed User
Longtime User
Thanks.
I stopped looking into the service part and found other topics discussing a similar issue.

basic4android-updates-questions/17297-transparent-activity-floating-widget-type-thing.html

By looking at the permissions of all that kind of app launcher, I found out that they all have a "Draw over other apps" permission.
I'll continue to look in that direction to see what comes out.

edit #1:
the "Draw over apps" permission can be obtained by adding
B4X:
AddPermission(android.permission.SYSTEM_ALERT_WINDOW)
in the manifest editor. I just need now to actually use that permission.
 
Last edited:
Upvote 0

bitstra

Member
Licensed User
Longtime User
Yes, I'm on the same stage. But underlaying apps don't get Touchevents if my app with this permission (android.permission.SYSTEM_ALERT_WINDOW) is active.

I'm experimenting now with Window.Flags:

B4X:
(with binded Reflection Lib...)
Dim r As Reflector

r.Target = r.GetActivity
r.Target = r.RunMethod("getWindow")
r.RunMethod2("addFlags", 2003, "java.lang.int") 'TYPE_SYSTEM_ALERT
r.Target = r.GetActivity
r.Target = r.RunMethod("getWindow")
r.RunMethod2("addFlags", 8, "java.lang.int") 'FLAG_NOT_FOCUSABLE
r.Target = r.GetActivity
r.Target = r.RunMethod("getWindow")
r.RunMethod2("addFlags", 32, "java.lang.int") 'FLAG_NOT_TOUCH_MODAL
r.Target = r.GetActivity
r.Target = r.RunMethod("getWindow")
r.RunMethod2("addFlags", 262144, "java.lang.int") 'FLAG_WATCH_OUTSIDE_TOUCH
r.Target = r.GetActivity
r.Target = Activity.Background
r.RunMethod2("setAlpha", 128, "java.lang.int")

but no success atm!

I think we have to switch between
r.RunMethod2("addFlags", 2003, "java.lang.int") 'TYPE_SYSTEM_ALERT
and
r.RunMethod2("addFlags", 2006, "java.lang.int") 'TYPE_SYSTEM_OVERLAY
or
r.RunMethod2("addFlags", 2008, "java.lang.int") 'TYPE_SYSTEM_DIALOG
or so...

playing around with flags, to find something out...

because:
flag 2003 effects black background to my sample app and my panel IS NOT move-/touchable, but touchevents ARE RECOGNISED by underlaying apps.
flag 2008 effects background transparent to my sample app and panel IS move-/touchable, but touchevents ARE NOT RECOGNISED by underlaying apps.
 
Last edited:
Upvote 0

SagePourpre

Member
Licensed User
Longtime User
Thanks for your input. I was not yet familiar with the Addflags and the reflector library.

After some more seach, I feel that the

StandOut library is my best way to get to something...

However, the library would need to be translated for b4a...
I'm reading the library tutorial right now and I'll see if I can achieve something.
 
Upvote 0
Top