compiling
------------------------------
Haxe files that get converted to java are in
java-src/
The compiled java files get put into
src/java/src
To compile, move the files, package and run it (for android)
compile com.gigglingcorpse.test.haxejavatoast.MyActivity application.nmml
from the project directory. (Sorry about the long package name.)
There may be pathing issues. I have haxe-byte's location in my path, and HAXE_LIBRARY_PATH set
application.nmml
-------------------------------
In application.nmml, I specify a java entry. Its path is set to where the java code is output.
I also specify
This copies the contents of assets/res into bin/android/bin/res, which is pretty special. It usually contains resources for your APK.
Here, it just contains the application's layout.
assets/res/layout/main.xml
I also overwrite NME's default MainActivity.java with my own. This file is not generated.
The actual file is just at
MainActivity.java
And is very simple.
the haxe that gets compiled to java
----------------------------------------
I defined some files for android classes that I wanted to include. They are externs, and contain only the bare minimum that I required.
In some cases, they are outright lies.
I have defined android.app.Activity to extend android.content.Context.
In fact, android.app.Activity extends android.view.ContextThemeWrapper.. and so it continues down until it gets to android.content.Context.
I needed it to eventually extend android.content.Context and am lazy, so that was that.
R.
----------------------------------------
The way android handles resource files is a little strange. You can access them through the R object.
http://developer.android.com/reference/android/R.html
I define the layout with XML
assets/res/layout/main.xml
java-sr/r
And in the HaXe code do things like
setContentView(r.Layout.main);
btnToast = cast( findViewById(r.Id.btnToast), Button );
The case is different than it would be normally, because Layout and Id are now classes, and r is the package.
It is converted for java
@:native("R.layout")
This is kind of messy, but could probably be automated without too much effort
I wonder if an R class at package ; with entries that are dynamic objects would map better.
To see if i could do it, the onClick for the button is defined in
assets/res/layout/main.xml
That should be it!