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:

Smee

Well-Known Member
Licensed User
Longtime User
Oh WOW, just what I have been looking for, Thanks very much for your generous contribution and work. Is the 'Enable Drop' still being planned?
Thanks again
 

Star-Dust

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 ;))
It's very interesting, it resembles the StandOut library. But surely lighter. I'm looking for something like this.

Thank you very much, your projects are always interesting.

Do you have documentation to edit the project and to manage the events?
 

JordiCP

Expert
Licensed User
Longtime User
Is the 'Enable Drop' still being planned?
Sorry, I abandoned my plans to make the "drop" part :(, but shouldn't be too difficult as the source code is there in case someone wants to expand it.

Do you have documentation to edit the project and to manage the events?
It is not a library "per se" but just a working example based on the link of the first post. I will try to take a look a it this week and see if I can "clean"/improve/document something to make it easier to work with.
 

Star-Dust

Expert
Licensed User
Longtime User
If I had a bit of documentation I would try to build a library.

Sorry a question...
BUT if instead of extending an ImageView Object, it extends a Panel object. Can You Build a Flying App?
 
Last edited:

Smee

Well-Known Member
Licensed User
Longtime User
Hey JordiCp, thanks for this code it works perfectly in the demo. When I drop the oservice into a project and just call it with the lines
B4X:
    Starter.MYSERVICE=True
    StartService(oService)
'
the service is called but then hits an error at this line
B4X:
            myChatHead.instance=J.RunMethod("newInstance2",Array(J,id))
The error message I get is

*** Service (oservice) Create ***
** Service (oservice) Start **
Error occurred on line: 129 (oService)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
at aus.anyfcsapp.joe.oservice._init_elements(oservice.java:357)
at aus.anyfcsapp.joe.oservice._service_start(oservice.java:641)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at aus.anyfcsapp.joe.oservice.handleStart(oservice.java:116)
at aus.anyfcsapp.joe.oservice.access$000(oservice.java:19)
at aus.anyfcsapp.joe.oservice$1.run(oservice.java:81)
at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.onStartCommand(ServiceHelper.java:105)
at aus.anyfcsapp.joe.oservice.onStartCommand(oservice.java:79)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2990)
at android.app.ActivityThread.access$2200(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@42a86718 -- permission denied for this window type
at android.view.ViewRootImpl.setView(ViewRootImpl.java:793)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:278)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at aus.anyfcsapp.joe.oservice$CustomImageView.sharedConstructing(oservice.java:721)
at aus.anyfcsapp.joe.oservice$CustomImageView.<init>(oservice.java:689)
at aus.anyfcsapp.joe.oservice.newInstance2(oservice.java:855)
... 30 more

I get the error no mater if i add the line activity.finish or not in the calling of the service

Can you advise of a possible solution?

Thanks again
 

JordiCP

Expert
Licensed User
Longtime User
Did you copy the needed permission to in manifest? (SYSTEM_ALERT_WINDOW)

additionally, in later android versions, a special permission must be granted (manually) so that it can draw on top of other windows. But possibly the crash is due to the reason above.
 

Star-Dust

Expert
Licensed User
Longtime User
A small question in the project is the module called "c". Do you need something?
 
Last edited:

Smee

Well-Known Member
Licensed User
Longtime User
Did you copy the needed permission to in manifest? (SYSTEM_ALERT_WINDOW)

No I did not think to check the manifest. Thank you so much that fixed the problem.
Thanks again, Love your work
 

JordiCP

Expert
Licensed User
Longtime User
A small question in the project is the module called "c". Do you need something?
No, I simply forgot that there, as one day I will forget my head somewhere ;)

(regarding your other question, I just saw now the edit)
BUT if instead of extending an ImageView Object, it extends a Panel object. Can You Build a Flying App?

Not sure if can be done directly with B4A objects, I think not, since they need to be in an activity, but sincerely never tried it. My example is more limited to button/control and some experiments for an app that I started to develop, but is now frozen.

Based on similar principles (I think), but with a more complete implementation, there is also @Informatix's OverlayWindow library
 

Star-Dust

Expert
Licensed User
Longtime User
Last question:p:p : Why did you include these variables in Starter and not Oservice?
B4X:
Dim MYSERVICE As Boolean=False
Dim STICK_TO_BORDER As Boolean
Dim DOUBLETAPBEHAVIOUR As Int
Dim ENABLEDROP As Boolean=False
 

Star-Dust

Expert
Licensed User
Longtime User
I'll look at the Informatrix Library but I like to put my hands in to make something of mine. It is not a computer need, but thirsty to know.;);)
 

JordiCP

Expert
Licensed User
Longtime User
Perhaps they make sense as global behaviour definitions which are not tied to a specific implementation (the one in oService). But don't take anything in my codes too seriously because I can apply other criteria or no criteria at all depending on the day, I am not a "clean" programmer :D
 

JordiCP

Expert
Licensed User
Longtime User
Yes, my code (the b4a adaptation) is free to do what you want. I don't remember if the original code had any type of license, but even if it didn't have any, it is always nice to put a link to the origin.
(Anyway the link in the first post doesn't seem to be active o_O, perhaps it has been moved somewhere else... )
 

Star-Dust

Expert
Licensed User
Longtime User
I do not know how to find it from another side, do you have directions?
I also modify Java, with a lot of effort because I'm 12 years old that I do not write anything in Java
 

Star-Dust

Expert
Licensed User
Longtime User

Smee

Well-Known Member
Licensed User
Longtime User
Hi
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
B4X:
        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
 

Smee

Well-Known Member
Licensed User
Longtime User
Ahhh i worked it out, I forgot to do the event in lowercase :)
 
Top