23

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.

tomd
  • 239
  • 1
  • 2
  • 3
  • 1
    Here's a comparison (though it's from 2008, so I'm not sure how much of it is still accurate) of what standard packages Android supports and doesn't support: http://www.zdnet.com/blog/burnette/java-vs-android-apis/504 – Josh1billion Jan 28 '12 at 19:51

2 Answers2

11

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
  • 91,525
  • 15
  • 160
  • 151
  • 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 Oct 09 '10 at 20:50
  • 5
    awt-android-compat is unfortunately GNU, and mine is a commercial project. – tomd Oct 09 '10 at 20:52
  • 2
    @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 Oct 09 '10 at 20:53
1

http://www.apogee.com/ has commercial products which will allow you to run Swing programs on Android. Note that I've never used this product so I can't comment on how good it is.

Noel Grandin
  • 3,143
  • 25
  • 17