hoijui / JavaOSC

OSC content format/"protocol" library for JVM languages

Home Page:http://www.illposed.com/software/javaosc.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ColorArgumentHandler uses java.awt.color and does not work on Android

Burtan opened this issue · comments

Hi,
with 0.5 ColorArgumentHandler was added. However it relies on java.awt.color and e.g. crashes on android. Some server configuration might also not contain the desktop java classes. Could we change that?
Thanks!

good point, thanks!
I am unsure of how to solve it though.
I would like java,awt.Color used on an Desktop JRE,
android.graphics.Color on Androd,
and some other solution on headless systems.
That is not really possible in one "binary" (JAR) file though, so I guess I will go with an approach that uses java.awt.Color if available, and a custom class if not.

Any ideas?

@Burtan please try the latest commit and tell me if it works for you on android and if the solution is ok for you.

There is a new class OSCColor now, which works quite similarly like java.awt.Color, and can be converted to and from it. It is now used instead of java.awt.Color, though the later should still be accepted for serialization, but when parsing (listening to OSC), OSCColor will be returned now.

I'm using gradle maven to build the app, can I use single commits? I don't know how though :D.
However, I found a workaround at least for me.
Kotlin code:

val serializer = OSCSerializerFactory.createDefaultFactory()
serializer.unregisterArgumentHandler(serializer.argumentHandlers.single { it is ColorArgumentHandler })
OSCPortOut(serializer, socket)

ahh, thanks for the workaround, looks good for such!
I just released a snapshot release on the maven repo, so you can try this change with version 0.7-SNAPSHOT.

Sorry for the late reply. I tried the new solution and it would work, but the usage of java.awt.color in LibraryInfo.java is crashing.

This should be fixed in master and the latest 0.7-SNAPSHOT release.
thanks to Burtan for the fix!

Hello my friends,
this is a Java workaround from the application perspective. No need to pick weird snapshots:

            OSCSerializerAndParserBuilder serializer = new OSCSerializerAndParserBuilder();
            serializer.setUsingDefaultHandlers(false);
            List<ArgumentHandler> defaultParserTypes = Activator.createSerializerTypes();
            defaultParserTypes.remove(16);
            char typeChar = 'a';
            for (ArgumentHandler argumentHandler:defaultParserTypes) {
                serializer.registerArgumentHandler(argumentHandler, typeChar);
                typeChar++;
            }
            mOscPortOut = new OSCPortOut(serializer,
                    new InetSocketAddress(AppData.getOscRemoteAddress(), AppData.getOscPortOutNumber()));

Enjoy