Wednesday, December 16, 2015

libGDX Android Text Input

libGDX has its ups and its downs. It isn't perfect by any means, but I still believe it has a ton of potential especially with RoboVM at its side which makes it work wonderfully with iOS and still keeps it working great for Android and Desktop. I love the make it once, run it everywhere aspect that it provides. Also the same reason I love Java.

However the problem I was facing today was dealing with Android text input. I am amid creating my own library add-on for libGDX that provides a lot of the same GUI menu like items provided with Android, however they are directly for libGDX and use within games and game menus. I have been working on Buttons, Layouts, Text Inputs, Labels, Custom Widgets, Loading Bars, you name it. However when it came to text input from the soft-keyboard provided in Android, there were bugs that were all dependent on device, or if they weren't using Google keyboard. For a game that is supposed to run flawlessly on any device on which it can be installed, this wouldn't cut it. So I did a bit of popping around on the internet and came up with this way of creating a popup for Android that would take input.


Input.TextInputListener inputListener = new Input.TextInputListener() {
    @Override
    public void input(String input) {
        text = input;
    }

    @Override
    public void canceled() {

    }
};
             
Gdx.input.getTextInput(inputListener,  hint, text, "");

This worked excellently. It gave me a little popup that allowed for me to input text, then it would make the text in the widget, which I call EditText after Android EditText widget, change to be whatever I put in the popup. Everything was great. Just one problem. The popup looked almost 'prehistoric' or at least it was Android Froyo styling. Not exactly my taste. I like Lollipop much better, but I also supported back to Android Jelly Bean. So I did the next best thing.

In my Android part of the project I went into styles.xml and changed one part so that the android Dialog would look how I wanted it to.


Before:
<resources>
    <style name="GdxTheme" parent="android:Theme">
 <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:colorBackgroundCacheHint">@null</item>
        <item name="android:windowAnimationStyle">@android:style/Animation</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowFullscreen">true</item>
    </style>
</resources>


After:
<resources>
    <style name="GdxTheme" parent="android:Theme.DeviceDefault">
 <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:colorBackgroundCacheHint">@null</item>
        <item name="android:windowAnimationStyle">@android:style/Animation</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowFullscreen">true</item>
    </style>
</resources>


Changing the parent of GdxTheme from android:Theme to android:Theme.DeviceDefault will make it so that the popup matches whatever OS you're running, be it KitKat, JellyBean, or Marshmallow.

That's all for today. Hope this helps anyone else struggling with this problem.

Wednesday, July 29, 2015

First Internship

I finally turned 18 and I'm out in the world, I landed my first internship, and let's just say that has been quite the experience.
A few things I've learned.
I already grew to love Android studio after a struggle to switch from Eclipse with Android Developer Tools. But it was well worth the switch, my productivity doubled, I felt more comfortable in the environment and everything went much better with different themes and a newer fresher more modern look.
The switch to Android studio happened back in January, but getting used to the IntelliJ platform was definitely useful in my first week as I was put to work using a framework I'd never even heard of.
My first project was on a framework called Spring Boot. It took me quite a few days to get used to Spring Boot and how it all connected, there's a lot being done in the background and I wasn't quite used to the way it used annotations yet. It's an amazing framework with lots of potential and lots of quick development. I learned an important lesson with that, you don't need to understand completely how something works, just understand that it does work and go with it.