B4A Library ChatHead wrapper + GIF overlay


Based on this wrapper, I also built some strange things on it, with different purposes. I am not working on most of them anymore, so I decided to share.

This one is funny. Similar to the video but with added elements
It combines several overlay elements and brings them into life simulating GIF animation (based on some previously converted GIF files to PNG) and sequencing them with a timer. In this version there are some xmas stars, a Santa and a spider skull

I publish it here since the thread already exists and is related to it... As always, perhaps the code style is not the best in the world to learn from, but I have tried to comment a bit and delete unneeded things so that it will be more easy to follow.

Important: in most recent android versions, you must grant directly to the app the permission to show elements on top of others (it is not enough with the declared manifest permissions). So, if nothing appears on your screen you should check it.

Hope you enjoy it :)

I'm happy to share this chatHead wrapper made with B4A and Inline Java. :) The original project is taken from here . I wrapped and modified it "a bit" for my purposes.

These views are not "normal" views in the sense that they don't need to be in an activity, but are added diectly to the WindowManager.
This allows for special uses, such as pop-up notifications which the user can interact with or simply discard. But also special care must be taken.

The attached zip is itself a small demo. All the "important" things are in the inline Java part in "oService", and how are they created and destroyed. The rest is just for the demo itself

Possibly many things can be improved, such as adding animations (I think in this case they are a bit tricky and still struggling with them)

Important: These views are not automatically destroyed when you destroy your app. Please pay attention at Service_Destroy

Also: the sound example in Files folder is from http://www.freesfx.co.uk/. It is free, but if you use it, they need to be mentioned


(I am preparing the drop option as in facebook messenger, but will take a while ;))


  • chatHeadDemo.zip
    122.2 KB · Views: 620
  • GIF_overlay_shared.zip
    160.6 KB · Views: 440
Last edited:

Johan Hormaza

Well-Known Member
Licensed User
I have modified the java code to accept a single tap and it works fine. However I am trying to add a long click event that does not work. the code is as follows
        public void onLongPress(MotionEvent e) {      
            processBA.raiseEvent(null, "onLong_Press", index);

Could you shed any light why this would not work? I have tried it both inside the public class GestureListener extends and outside of it. I do not get any errors thrown but it just does not respond
Many thanks for any help
Hello, To do it with just one click, what would the java code be like, since you have it with LonCklick.
Thank you!


Licensed User
Longtime User
Great code.
Any suggestion of a text popup menu sample after clicking over the head ?
Or simpler just open an activity ?


Licensed User
My library also works on Android 8.1 and does not need to be re-compiled because it already provides all the news on permiss-request.
Then using the same code the library checks the SDK version and if less than 26 does not ask for permissions, instead if it is equal to or higher than SDK 26 it asks for permissions.

but I had suggested the code you will find in the examples to open a menu after clicking the Head (floating button).
So look more at the example that the library and can help you for what you want to do
Last edited:

Jarek I&Q

Licensed User
OK, I made it.
I don't know if I did it right, but the button is motionless now, just like I wanted it to.

I commented on that in the Java code:
case MotionEvent.ACTION_MOVE: 

Ibrahim Saleh

Licensed User
Longtime User
Im getting this error when trying to compile project
B4A Version: 10.0
Java Version: 8
Parsing code. (0.02s)
Building folders structure. (0.02s)
Compiling code. (0.07s)
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
(Android Support Library)
Generating R file. (0.00s)
Compiling generated Java code. Error
javac 1.8.0_271
src\com\hover\bubble\oservice. java:856: error: cannot find symbol
location: class LayoutParams
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error


Well-Known Member
Licensed User
Longtime User
Try changing targetSDK version to 28 or higher in the manifest file.

Which Android SDK version are you using?
Last edited:

Johan Hormaza

Well-Known Member
Licensed User
What will this error be?
** Activity (main) Pause, UserClosed = true **
*** Service (oservice) Create ***
** Service (oservice) Start **
Error occurred on line: 198 (oService)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
at com.twouchapps.fun.xmas.oservice._init_elements(oservice.java:370)
at com.twouchapps.fun.xmas.oservice._service_start(oservice.java:964)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at com.twouchapps.fun.xmas.oservice.handleStart(oservice.java:112)
at com.twouchapps.fun.xmas.oservice.access$000(oservice.java:20)
at com.twouchapps.fun.xmas.oservice$1.run(oservice.java:83)
at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.onStartCommand(ServiceHelper.java:237)
at com.twouchapps.fun.xmas.oservice.onStartCommand(oservice.java:81)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3738)
at android.app.ActivityThread.access$1700(ActivityThread.java:201)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1711)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6864)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@a3fbbf5 -- permission denied for window type 2002
at android.view.ViewRootImpl.setView(ViewRootImpl.java:861)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:356)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:94)
at com.twouchapps.fun.xmas.oservice$CustomImageView.sharedConstructing(oservice.java:1038)
at com.twouchapps.fun.xmas.oservice$CustomImageView.<init>(oservice.java:1007)
at com.twouchapps.fun.xmas.oservice.myInstance2(oservice.java:1180)
... 25 more

** Service (oservice) Destroy **
** Service (starter) Destroy (ignored)**


Well-Known Member
Licensed User
Longtime User
Ok, Taking your modified project as reference, I only had to change the TYPE_PHONE --> TYPE_APPLICATION_OVERLAY to make it work :)
Also changed the Activity buttons background, otherwise the text was not seen

Santa is back!!!


  • GIF_overlay_updated.zip
    168.4 KB · Views: 100