hoijui / JavaOSC

OSC content format/"protocol" library for JVM languages
http://www.illposed.com/software/javaosc.html
BSD 3-Clause "New" or "Revised" License
156 stars 43 forks source link

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

Closed Burtan closed 4 years ago

Burtan commented 4 years ago

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!

hoijui commented 4 years ago

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?

hoijui commented 4 years ago

@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.

Burtan commented 4 years ago

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)
hoijui commented 4 years ago

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.

Burtan commented 4 years ago

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.

hoijui commented 4 years ago

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

ManuDev9 commented 2 years ago

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