B4A Library ChatHead wrapper + GIF overlay

(2017/07/01)

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



Enjoy!

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

Attachments

  • chatHeadDemo.zip
    122.2 KB · Views: 956
  • GIF_overlay_shared.zip
    160.6 KB · Views: 755
Last edited:

Daniel-White

Active Member
Licensed User
Longtime User
Hi Jordi, I download it, but perhaps, I missing something.


upload_2016-1-5_17-46-42.png
 

JordiCP

Expert
Licensed User
Longtime User
Hi,

I suppose that you need SDK 21 or higher since this method was introduced in that API

But the good news is that this last function ( isMyScreenOn() ) isn't needed in this demo, I simply left it here from another project.

So try to remove the function and see if it works :)
 

JordiCP

Expert
Licensed User
Longtime User
Great! If it works for you can you please tell me phone model/Android version? :)
 

walterf25

Expert
Licensed User
Longtime User
Hi all,

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



Enjoy!

(I am preparing the drop option as in facebook messenger, but will take a while ;))
Impressive, wow, very nice.

Walter
 

walterf25

Expert
Licensed User
Longtime User
Chathead Evolution. Expanding possibilities for a new app. Still a Frankenstein, but it breaths and moves!!!:D

Wow, this is pretty cool Jodi, great work!
 

moster67

Expert
Licensed User
Longtime User
It's really a nice library. Thank you.
I tried your demo-app on my Nexus4 and it works fine. However, when trying it on an Genymotion emulator I got the following error "System.UI has stopped". The error continues to show. The trace is:
B4X:
Process: com.android.systemui, PID: 6287
java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.ColorFilter android.graphics.drawable.Drawable.getColorFilter()' on a null object reference
    at com.android.systemui.statusbar.NotificationTemplateViewWrapper.resolveViews(NotificationTemplateViewWrapper.java:82)
    at com.android.systemui.statusbar.NotificationTemplateViewWrapper.<init>(NotificationTemplateViewWrapper.java:66)
    at com.android.systemui.statusbar.NotificationViewWrapper.wrap(NotificationViewWrapper.java:38)
    at com.android.systemui.statusbar.NotificationContentView.setContractedChild(NotificationContentView.java:125)
    at com.android.systemui.statusbar.BaseStatusBar.inflateViews(BaseStatusBar.java:1389)
    at com.android.systemui.statusbar.BaseStatusBar.inflateViews(BaseStatusBar.java:1288)
    at com.android.systemui.statusbar.BaseStatusBar.createNotificationViews(BaseStatusBar.java:1713)
    at com.android.systemui.statusbar.phone.PhoneStatusBar.addNotification(PhoneStatusBar.java:1326)
    at com.android.systemui.statusbar.BaseStatusBar$5$1.run(BaseStatusBar.java:416)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5254)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Process com.android.systemui has crashed too many times: killing!

I saw that in your other thread (Fly overlay) @Cableguy reported the same error and in this post, you mentioned that you fixed it. I am unsure if you needed to/did fix it also in your library/code you posted here...
If not, I will try to track it down and see if I can find the solution.

Edit: maybe the problem is because it is being run on the Genymotion emulator but in this moment I can only test on one physical device so it is hard to tell.
Edit2: tested it on a Google emulator and it works...( am bit confused)

Thank you.
 
Last edited:

JordiCP

Expert
Licensed User
Longtime User
Hi Moster67,

I think that it could be related, although not sure. The error seems to occur when setting up the notification icon. Try changing the line order where this notification is created, in oService-> Service_Created

B4X:
  '...
  'Notif needed for foreground service
   Snotif.Initialize
   Snotif.Icon="icon"     '<----- MOVE THIS LINE HERE
   Snotif.SetInfo("ChatHead demo", "Press to change settings", Main)
   'Snotif.Icon="icon"     '<----- AND REMOVE IT FROM HERE
   Snotif.Vibrate=False
   Snotif.Sound=False
   Service.StartForeground(1, Snotif)

This happened with only some android version (5.1.1?) and/or a limited number of devices, still don't know why. Changing the line order, worked ok.

Please tell me if this solves your issue and I will upload a version with this modification
 

moster67

Expert
Licensed User
Longtime User
Many thanks! Now it works also on the Genymotion emulator (which is running indeed Lollipop).
 

cambopad

Active Member
Licensed User
Longtime User
Many thanks! Now it works also on the Genymotion emulator (which is running indeed Lollipop).
I tried to combine this with B4A Screen Recorder to allow user to record the screen from overlay button, but I always fail. :( Have you ever tried getting B4A Screen Recorder with this chat head function???
 

peacemaker

Expert
Licensed User
Longtime User
Very good topic !
Some suggestions:

B4X:
Sub action_down(instance As Int)
'Your code here
Log("instance=" & instance)
End Sub

.....
'in Java
processBA.raiseEvent(null, "action_down", index);
 

Carlos marin

Active Member
Licensed User
Longtime User
hola jordi. amigo eres un genio!!!... tengo una pregunta ya que veo que trabajas con esto, es que estoy haciendo un tipo de foro y necesito que cuando mando las cadenas de texto el label y panel se redimensione para mostrarme todo lo escrito. alguna idea?, por ejemplo en visual estudio utilizo el autosize, pero aqui no se como, me puedes dar una idea. muchas gracias.

por cierto ami tambien me corrio sin problemas. tengo un azumi A55T
 

JordiCP

Expert
Licensed User
Longtime User
Hola Carlos! Te envío un correo, pues este post es de un ChatHead pero nada que ver con la pregunta ;)
 

panagiotisden2

Active Member
Licensed User
Longtime User
hello jordi,

is it possible to make something like facebook messenger chat heads?
i want it to expand in full screen and contain a webview,a textbox and some buttons in it, can you help me?

Thank you,
Panos
 

JordiCP

Expert
Licensed User
Longtime User
hello jordi,

is it possible to make something like facebook messenger chat heads?
i want it to expand in full screen and contain a webview,a textbox and some buttons in it, can you help me?

Thank you,
Panos
Hi,

In fact this is just a wrapper-example for the chathead button only. It could be expanded to place whatever you want in it, but I don't think it is necessary. It can be made much simpler.

If you want a whole screen with whatever you want inside it, I would do it in an activity. When you click the button, just launch this activity. And for instance, when you pause the activity, show the button again.
 
Top