woo-j / OkapiBarcode

Open-source barcode encoding program written in Java
http://www.okapibarcode.org.uk
Apache License 2.0
318 stars 94 forks source link

Android support #82

Closed TheLastProject closed 6 months ago

TheLastProject commented 3 years ago

Hey devs!

I'd like to try this library on Android because it supports outputting way more barcode formats than zxing support, so I am hoping I can fix https://github.com/TheLastProject/Catima/issues/181 using this library.

I however can't seem to use this library because all the renderers depend on java.awt, which is not supported on Android.

Are there any plans on perhaps supporting Android? I sadly do not think I can help much myself, given I am not very knowledgeable at image drawing, but a renderer that creates an Android Bitmap would most likely be the most convenient way for Android users to be able to use this library too.

gredler commented 3 years ago

This would be an interesting enhancement, but not something that I'm likely to implement myself. It would probably be just another uk.org.okapibarcode.output.SymbolRenderer implementation, similar to uk.org.okapibarcode.output.Java2DRenderer.

I wonder if we start requiring Java 11 or Java 17 in the next few years, whether that closes the door on any Android support in the future?

TheLastProject commented 3 years ago

I understand. Right now Android is supporting partial Java 8 syntax, so it will definitely always be behind in version support: https://developer.android.com/studio/write/java8-support.

So supporting Android will sadly mean having to support lower Java versions for longer, yes.

lT1161558158 commented 2 years ago

not only provide uk.org.okapibarcode.output.SymbolRenderer implementation ,also to provide the Symbol refrence awt class eg java.awt.geom.Ellipse2D and java.awt.geom.Rectangle2D

gredler commented 7 months ago

Just an update: Some work was already done in release 0.4.0 to remove most of the AWT class usage (except in the Java2D renderer). This should go a long way to helping users to more easily incorporate Okapi into Android projects.

kratho commented 6 months ago

You can use the SvgRenderer on Android and convert the svg result to a Bitmap using androidsvg for example.

gredler commented 6 months ago

Thanks for the suggestion, have you used this approach yourself in an application?

The only possible gap I see is that the text element is only partially supported by AndroidSVG, and I'm not sure if all of the text attributes used by Okapi are supported.

kratho commented 6 months ago

Yes i tried this approach and it is working fine!

Regarding the text element: you are right, according to AndroidSvg this might be a limitation. For my use case this is not relevant as i am hiding the human-readable text anyway. But there are multiple other svg to bitmap libraries available which may support this.

gredler commented 6 months ago

Great, thanks for the confirmation! Hopefully it will help others who have similar needs.

One last question, if you don't mind: if you're using Okapi version 0.4.x (with most of the references to the AWT classes removed), did you have to fork and customize Okapi in order to use it on Android? Or did it work out of the box for you? I'm not very familiar with Android development, so I'm not sure how easy or hard it is to use Okapi 0.4.x on Android, or where the remaining roadblocks are (if any).

kratho commented 6 months ago

No i didn't have to fork or customize Okapi in order to use it on Android. This is working out of the box as, in contrary to the Java2D renderer, there are no java.awt references in the SvgRenderer.

gredler commented 6 months ago

That's great to hear! I'll add a blurb to the README with this recommendation for Android developers, close this ticket out, and if anyone runs into more specific Android issues then we can address them in a separate ticket.