Porting AWT graphics code to Android
Asked Answered
C

3

12

We would like to use some of our existing Java AWT graphics code on the Android platform. As far as I can tell, Android does not include any of the AWT classes -- no Graphics2D, Path2D, FontMetrics, etc.

What is the best approach to port our drawing code to Android? Ideally, we would like to modify our code base to target both Android and generic Java.

Contextual answered 25/4, 2011 at 21:42 Comment(3)
Check out the awt-android-compat project: code.google.com/p/awt-android-compat . There hasn't been much activity lately, unfortunately, so it's still in a very early stage. Seems there are some references to AWT in Android's internal code, but utilizing it directly appears impossible. Perhaps it could be useful in making contributions to the awt-android-compat project? I'm not sure. grepcode.com/file/repository.grepcode.com/java/ext/…Twentieth
awt android compatibility : dead, too many issues.Isometropia
Here is a wrapper I made for the Graphics apis, its not fully complete but has a lot of functionality. pastebin.com/b5TFWSqQShaman
H
9

The android platform supports a small subset of awt. By small, I mean it supports awt fonts. Going from java swing (are you really just using awt as a standalone UI?) to Android is going to be a shock to the system. One defines Android's UI in XML resource files, and those resources are loaded into Activity classes which represents a logical unit of the application. Canvas' replace Graphics2D objects, and they have somewhat different functionality.The Android UI system seeks to avoid absolute positioning, which is common in java UI's. And there is so much more to consider for Android, like varying screen sizes and differences in resolution. Neither of which were much of a issue for Java SE. To answer your question: you have your work cut out for you and you will have to start much of your coding from scratch.

I'm not sure what 'drawing code' means, but in my case, I have a large amount of animation code that is displayed via awt shapes. This is reproducable on android as there are graphics.drawable.shapes objects, and one can display primitive shapes by doing something like canvas.drawCircle(x,y,z,h) (remind you of something?). But when I ported it, it was difficulty and felt like I was cortorting the android to do something it really didn't want to, and wasn't intended to do. It's hard to answer your question exactly given the vagueness of it.

Honig answered 25/4, 2011 at 23:54 Comment(1)
You wrote "The Android UI system seeks to avoid absolute positioning, which is common in java UI's". I think the positioning is same on both systems. Can you explain where I'm wrong? Background infos:I have the a similar issue. Should I implement some of the java.awt code that are used only for structuring and not for drawing. e.g. like awt.Rectangle2D? Or should I completeley refactor the application in android. If I must refactor, I think it would be to much effort. On the other hand, I don't realy know what are the consequences if I try to simulate java.awt.Tumble
L
3

I don't think you can port AWT to Android. I mean, it's Java SE vs a subset of it (or an updated Java ME with steroids, as you prefer).

There are though, some UI classes for Java ME that work perfectly on Android. Personally I like LWUIT but it's not the only one.

Licking answered 25/4, 2011 at 21:47 Comment(0)
I
3

appengine-awt is a pure java implementation of the java.awt and javax.imageio packages for use in the Google AppEngine environment.

https://github.com/witwall/appengine-awt

SwingWT is a 100% pure Java library which aims to be a free implementation of Swing and AWT. Unlike Swing, it drives native peer widgets for your platform from SWT.

https://github.com/witwall/SwingWT

Incorporate answered 13/3, 2019 at 20:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.