views:

114

answers:

3

I have a Java Swing application which draws diagrams. It uses Graphics2D calls and awt objects such as Rectangle etc.

At some point I might want to port this to Android. I understand that I can't use Graphics2D on Android, but can I still use the awt Rectangle, Font, Color (etc) classes.

What I want to do is to isolate any code changes between the swing version and the Android version by adding an emulation layer so my Graphics2D calls can be converted to Android drawing calls.

Is this feasible?

Just to be clear, I am not too worried about the Swing UI side of things (the UI is minimal and can be rewritten for Android), I am concerned about the actual drawing code which calls Graphics2D from many places.

A: 

The main problem is that you won't be able do create classes in packages named java.awt. But except that point, basically you can rewrite a library based on awt API.

You can also check awt-android-compat project.

Colin Hebert
Just to clarify, are you saying that I will not be able to use the existing awt classes, even things such as Rectangle? What is the problem?
tomd
awt-android-compat is unfortunately GNU, and mine is a commercial project.
tomd
@tomd: "Just to clarify, are you saying that I will not be able to use the existing awt classes, even things such as Rectangle? What is the problem?" -- they don't exist on Android. However, for utility classes that don't attempt to draw to the screen, you can grab the source for those classes from the Apache Harmony project, refactor them into a new package (e.g., `tomd.awt`), and use them.
CommonsWare
A: 

Thanks for the help.

In my case, I have no immediate need to port to Android, although I probably will at some point. I was just checking if there is anything I need to do now, to save myself doing 10x as much work later on.

If the solution is to create my own copy of awt (which sounds a reasonable idea), I guess the answer is that I don't really need to do anything right now. I can add my own Graphics2D to my awt when I need to port.

tomd