Running Lemur on Android (using Groovy)

Hello PSpeed,

I can’t compile groovy on android

Are there any new styles available or a fix yet?

Something about gradle?

Groovy in Lemur is only used for the style language. You could work around it by manually defining your styles in Java code. It will be a lot more verbose but structurally equivalent.

I don’t know enough about Android to know how to get Groovy to work there but it sounds like it’s a device-specific issue maybe?

Well not really, it just looks like the groovy-all.jar wont compile to android unless it has a gradle wrapper or something. I tried a bunch of things but not much luck. I tried to get the plugins but my default proxy is not working for some reason. Is netbeens plugin offline?

Gradle is a build tool… so I’m not sure how it fits here. Maybe there is a gradle plugin that is wrapping/conberying the groovy-all to run on android?

I’m kind of out of my element here as I’ve never done android development. It’s possible to use Lemur without groovy as its an optional component… you just can’t use the style language or default glass style in that case.

Erm, how do I use glass style without groovy?

Doing this:

    GuiGlobals.initialize(this);         
    BaseStyles.loadGlassStyle();       
    GuiGlobals.getInstance().getStyles().setDefaultStyle("glass");
    stateManager.attach(new MouseAppState(this)); 
    
    // Create a simple container for our elements
    Container myWindow = new Container();
    guiNode.attachChild(myWindow);

    // Put it somewhere that we will see it.
    // Note: Lemur GUI elements grow down from the upper left corner.
    myWindow.setLocalTranslation(300, 300, 0);

    // Add some elements
    myWindow.addChild(new Label("Hello, World."));
    Button clickMe = myWindow.addChild(new Button("Click Me"));
    clickMe.addClickCommands(new Command<Button>() {
            @Override
            public void execute( Button source ) {
                System.out.println("The world is yours.");
            }
        });

I get:

SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.RuntimeException: Groovy scripting engine not available.
at com.simsilica.lemur.style.StyleLoader.<init>(StyleLoader.java:75)
at com.simsilica.lemur.style.StyleLoader.<init>(StyleLoader.java:62)
at com.simsilica.lemur.style.BaseStyles.loadStyleResources(BaseStyles.java:72)
at com.simsilica.lemur.style.BaseStyles.loadGlassStyle(BaseStyles.java:62)
at mygame.Main.simpleInitApp(Main.java:48)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:220)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:211)
at java.lang.Thread.run(Thread.java:745)

Default style:

You can’t use that. Take that out and you won’t need groovy.

But you will have to define your own style in Java code. If you look at this documentation:

You can see how to setup styles in Java code. If you scroll a little above you can see what that example would have looked like in the styling language.

So, if you want to use Lemur without groovy AND still want to use the glass styling, you would have to similarly transform the glass style file to Java code.

Non-trivial to be sure… but you also really only need to redo the bits you use.

Still, might be easier just to figure out how to get groovy working on android, I don’t know. Maybe someone else with more Android experience can comment.

1 Like

Yeah, will wait for that I thinks. Thanks pspeed

Hey Paul, still no answers yet. Do you know anyone who could help?

Sorry… I’m android-ignorant at this point.

Lol, when you said non-trivial it frightened me but now I know you just use that word as you would the word “easy” correct?

I managed to get a new style working. Do you have any idea how I can change the yellow color I get on button mouse-over ?

Edit:

Found it. Here is a way to make a few of the elements work (just button and container for now):

Make a new class:

package mygame;

import com.jme3.asset.AssetManager;
import com.jme3.math.ColorRGBA;
import com.simsilica.lemur.GuiGlobals;
import com.simsilica.lemur.component.*;
import com.simsilica.lemur.style.*;


/**
 *
 * @author Ghost
 */
public class LemurStyle {

    public static void InitLemurStyle(AssetManager assetManager){

    Styles styles = GuiGlobals.getInstance().getStyles();

    Attributes attrs;   

    attrs = styles.getSelector("glass");
    attrs.set("fontSize", 20);
    
    QuadBackgroundComponent bg = new QuadBackgroundComponent(new ColorRGBA(0.207f, 0.518f, 0.89f, 0.5f));
    
    attrs = styles.getSelector("button", "glass");
    attrs.set("color", new ColorRGBA(0.5f, 0.75f, 0.75f, 0.85f));
    attrs.set("highlightColor", new ColorRGBA(1, 1, 1, 1));
    attrs.set("background", bg);

    attrs = styles.getSelector("container", "glass");
    attrs.set("color", new ColorRGBA(0.4f, 0.75f, 0.75f, 0.85f));        
    attrs.set("background", bg);        
    
    /*BitmapFont font = assetManager.loadFont("myFont.fnt");
    attrs = styles.getSelector("slider", "button", "glass");
    attrs.set("fontSize", 10);
    attrs.set("font", font);*/
}
}   

And then call this to init in main (+usage example):

@Override
public void simpleInitApp() {
    
    GuiGlobals.initialize(this); //this           
    LemurStyle.InitLemurStyle(assetManager);     
    GuiGlobals.getInstance().getStyles().setDefaultStyle("glass");
    stateManager.attach(new MouseAppState(this)); 
    
    // Create a simple container for our elements
    Container myWindow = new Container();
    guiNode.attachChild(myWindow);

    // Put it somewhere that we will see it.
    // Note: Lemur GUI elements grow down from the upper left corner.
    myWindow.setLocalTranslation(300, 300, 0);

    // Add some elements
    myWindow.addChild(new Label("Hello, World."));
    Button clickMe = myWindow.addChild(new Button("Click Me"));
    clickMe.addClickCommands(new Command<Button>() {
            @Override
            public void execute( Button source ) {
                System.out.println("The world is yours.");
            }
        });
}

Means not trivial. Trivial would be a one line change. It’s a many line translation (as you’ve discovered). It’s not hard. It’s even straight forward… but it’s non-trivial. :slight_smile:

Everything in the groovy-based style file pretty much has a 1:1 mapping to Java code. It’s just a lot more verbose.

1 Like

And I guess I recognize that some people use the phrase “non-trivial” in an exaggerated form of “super hard”… much like when I say “copious spare time” I’m being pretty facetious.

As a software contractor, I once told an Army col. that a software enhancement would be “trivial”. When I didn’t have it done the next day, he beat me over the head with that word at least 10 times over as many weeks. “Trivial” has almost a PTSD effect on me now and I treat it’s use quite literally. :slight_smile:

1 Like