Android Example JME Project

Hope it helps :slight_smile:

It would be nice if any of the Android/JME experts could review this project.

Do you like the way I did the lemur buttons?
It does seem to work, but maybe there’s a better way? (By better, I mean simpler :slight_smile:

Any comments would be appreciated!

1 Like

Congratulations! The android part looks good, but I think you had better to follow clean code methodologies and utilize more design patterns on the go.

Good examples:

  • A method/function should never exceed 10 lines.
  • A method/function has only one function represented by its name.
  • Use BaseAppStates and Controls instead of mashing everything into your Main class.
  • I think it would be better to merge the utilities module into the core module.
  • As for lemur, I use lemur for some game gui components on my desktop that I haven’t ported it yet and I use android native ui plugin (I built) especially for Android (platform specific plugin), so I will leave this for others to decide.

One other clean code violation is you have copied jme android harness with the same name, though I know the package is different, but you should avoid these duplicates anyway on your code, if you have to use AppCompatActivity then use JmeSurfaceView with an AppCompatActivity, and I am planning to build a new Activity harness by the way…

EDIT:
On Buttons.java I noticed you are using a lot of anonymous classes to implement command-states or observers for button actions, try not to utilize a lot of the anonymous classes, they are vague, non-clean and hide the truth of a lot of things, it is better you create useable implementations (classes that implement the interface and provide abstract actions as far as you can).

Hey @Pavl_G, thanks for the review! Seems I have been exposed as a C code hacker, who didn’t like C++, and now hacks in Java. And quite correctly too ! How I miss struct’s :wink:

I’ll try to tidy up the code structure, but I wasn’t really aiming for a model project, just ‘something’ that worked on Android. Perhaps I should aim higher.

Having separate gradle sub-projects, one for app, one for Desktop, and one for the ‘core’ was something I really liked in Ialon. Having the same project that runs on windows and Android was genius I thought.

The subproject ‘Utilities’ came from an existing project I already had. As for AppCompatActivity, that may be a leftover cut-and-paste. Hopefully I don’t I need it and can remove it.

For the splash screen, is there a simple way to get it appear immediately the app is run? Android does display the project icon on a plain background by default, but it would be nicer to have something more interesting to look at while the app starts.

1 Like

Yeah, that is why I don’t like C++ that much :-), may be because people have ruined it with unclean architectures, idk, but there is always a room for improvements on any language, I am trying also the clean code methodology on C and GNU/Linux.

JmeSurfaceView provides a delay attachment facility (that doesn’t delay the update() by the way), you can utilize it and add an android native component (CardView for example) with a timer, this is an example:

For the splash screen, is there a simple way to get it appear immediately the app is run? Android does display the project icon on a plain background by default, but it would be nicer to have something more interesting to look at while the app starts.

No unfortunately not. I tried to do this in Ialon but it is a “feature” of Android 12 to always display the app icon while starting the app, until the app gains control.

One other clean code violation is you have copied jme android harness with the same name, though I know the package is different, but you should avoid these duplicates anyway on your code

I also did that in Ialon do explicitly show that the class was a patch of the original, and thus should not contain project specific code and should disappear in the future.

I guess the goal is similar here ?

Simply, you shouldn’t have code duplicates with just one thing changed, it’s highly confusing on the long run, it’s all about maintainability, you can take Mythruna as an example, Complex but Simple if you followed the clean code methodologies.

As for the current state of the AndroidHarness, i am building a new CompatHarness API, it is currently in the development phase, it may be included on jme-3.7 and it utilizes a JmeSurfaceView with a support for lifecycle tracking (command-states).

For now, you can use a JmeSurfaceView on an AppCompatActivity.

The stock splash screen API shipped with the android SDK is another topic.

But you can do a splash screen using JmeSurfaceView :wink:.

But you can do a splash screen using JmeSurfaceView :wink:

Since @tharg2 is writing about the project icon that displays at the start, I guess it is about the Android 12 specific behavior…
Once your app is started, you can of course display anything you want, including a splashscreen

1 Like

Does jmesurfaceView works well with API 32-33 ? mine game is not loading its reverting back to old activity/fragment from which GameplayActivity is launched. Has anyone tested on api32-33 ?

1 Like

Please open another thread and ask your question providing how did you use JmeSurfaceView (through java or xml or both), your code and the logcat errors or exceptions thrown on the runtime, however JmeSurfaceView should work fine on new android apis.