Qt 5 and C++ meet in a graphical user interface!

Section 2 is complete of the “Beginning Qt 5 C++ GUI Development” course! This course is great! I’m really learning a lot from the instructor. Section 2 was sort of a C++ primer, for those who were not familiar with it. As you know, if you’ve been following along here, I already learned C++ in another course. However, in this “primer” of C++, I gained a much deeper understanding of what exactly classes are, how to properly use constructors and all sorts of great stuff!

qt_gui

Check out my “Guess the number” game!

I’m not sure if I think the course is so great because I already know a little about C++, or if it just is that informative, but it seems to me that it moves at a great pace for beginners like myself.

You can check out my completed game, although it’s not much to see yet. The object is to guess the number which is between 1 and 10. You’ll have to import it into Qt-Creator and then compile it. I haven’t started making executables yet.

As an aside, if you are familiar with Android Studio, Qt-Creator is somewhat similar in feel and use. I like how you can right click on an object and add code directly to your cpp files, which is really handy!

Linux – keep it simple.

Having trouble building Bluefruit LE app in Android Studio?

While playing with my Bluefruit Feather, I decided to build the Android app straight from the source code, so I could see the ins and outs of how it works. Unfortunately, when I downloaded the source code and loaded it into Android Studio, I noticed that it didn’t compile the gradle files correctly.

Turns out that they updated the gradle files for Android Studio 3. My Linux distribution was still using Android Studio 2.3.3. That may see pretty out of date, but it went from 2.3 straight to 3.0.

So, I had two choices, update my Android Studio manually, or downgrade the Bluefruit LE app. Fortunately, Github allows you to view a repository at a previous commit level. So, I loaded up the commit just before they updated the gradle files, and downloaded the repository at that state. I figured if you are reading this, you might want that too, so here is a direct link:

https://github.com/adafruit/Bluefruit_LE_Connect_Android/tree/175d517b3e964a2862f311c75bea740075cafe05

bluefruit_le

Downloaded, unzipped, loaded with Android Studio 2.3.3, and ta-da! It worked! I like easy problems. In the future, however, I will need to update my Android Studio anyways, but for now, this gets me where I need to be. Perhaps by the time I need to update, the Linux version I am using will have that package available pre-built.

Linux – keep it simple.

Setting up libGDX for Android Studio on Ubuntu

Every one else is probably brighter than me. However, after reading the instructions over and over again, and then attempting to follow them, it just wasn’t working. All I wanted to do was start a libGDX project in Android Studio. I finally figured out where I went wrong, so here is the step by step for any one else that gets stuck like I did. Please read all the instructions first, because step 5 becomes step 1, but doesn’t make sense unless you read them in this order:

  1. Go to https://libgdx.badlogicgames.com/download.html and click “Download Setup App”.
  2. A jar is downloaded. Don’t try to import it, or something of that nature. Clicking on it is no good either. Simply open a terminal window and cd to the Downloads directory. Once you are there, type: $ java -jar ./gdx-setup.jar
  3. A window will pop up. Fill in the usual blanks to name your app.
  4. For the Android SDK field, open Android Studio, and click File –> Project Structure. That first field is the Android SDK.
  5. For the folder to put the newly created app in, be sure that you choose a folder that is empty, because it will wipe out everything in that folder. So I recommend you make a folder for it first!
  6. Uncheck the things you don’t need, like IOS, HTML, etc, and click generate.
  7. Once it is done, go back to Android Studio, and click File –> open.
  8. Choose the folder you put it in, and Android Studio will recognize the gradle files in it, and open your new app!

Hopefully that makes sense and keeps you from wasting as much time as I did. Most of you are probabl smart enough to know this already!

Linux – keep it simple.

Adding Parse to your App in Android Studio

Parse is a really neat tool for your Android applications, allowing you to have online servers that store game scores, driver id’s, names, logins, you name it! Whatever storage your app needs, you can just about always use parse for the job.

The usual way of getting parse set up in your app used to be downloading the latest parse “starter kit” app. An empty app that has parse libraries and the code needed already built in. But that is a bit of a hassle now, since they have closed down the parse website.

However, as I mentioned before, parse did make all of their material open source as they faded off into the wild blue yonder, but it left newbies like myself struggling to figure out how to implement parse into new apps.

The great news is, you do not need to get a “parse starter kit” or some such app. The pros already had this figured out, but if you are new like me, then here is my take on importing parse into your app in Android Studio (this should work on any Android Studio, but for reference, I used Android Studio 2.3.1).

Step 1. Make a new app, name it whatever you want.

Step 2. From the file menu, click “project structure”.

addparse1

Step 3. In the window that pops up, under Modules, click “app”.

addparse2

Step 4. Click on the “Dependencies” tab.

addparse3

Step 5. Click the green “+” arrow, and choose #1, Library.

addparse4

Step 6. When the Library Dependency window opens, type “parse” and press enter. Now choose the latest “com.parse:parse-android XXXXXXXXXX” version, and press OK.

addparse5

Step 7. You should now be returned to your Dependencies tab, with the parse library added. Press OK to close the window.

addparse6

Step 8. Add these lines to your MainActivity.java file (Or whatever you chose to call the first launched activity) :

// Enable Local Datastore.
Parse.enableLocalDatastore(this);

// Add your initialization code here
Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
        .applicationId("ENTERYOURINFOHERE")
        .clientKey("ENTERYOURINFOHERE")
        .server("https://ENTERYOURINFOHERE/parse/")
        .build()
);

I put that data into the “onCreate” method, so it is called as soon as you launch the app. Now you just have to fill it in with your app id, key, and url for your parse server, and you should be good to go! Then you can start adding your parse commands as usual.

I hope that helps some other parse/app making newbie like myself!

Linux – keep it simple.

 

​A currency converter app.

I never realized just how much goes into an app before trying to learn how to make one work! At the same time, I never realized how simple the individual pieces of the app can be.

 

Here is another app that I made for the course:

 

https://www.mediafire.com/download/npzaxxd0p0qzfw1
What I have been coming to understand is that looking at an app is a lot like building a puzzle. At first, you dump all of the pieces out of the box, and it looks overwhelming! Obviously, the scope of the app is similar to the size of the puzzle. If it has hundreds or thousands of pieces, it just seems impossible to put it together. But, as I learn more about making apps, I have come to realize that it is simpler if you break your puzzle down into groups, and then focus on one piece at a time.

 

For instance, if you sort your puzzle out by edge pieces, and put those together, then you can group center pieces by colors or objects from the box, and by working on just one area or group, you can get it done! You don’t have to figure out every piece at the beginning, you can instead focus on just one set of pieces, and everything will eventually hook together.

 

Similarly, with this currency converter app, I managed (after Googling) to take a number, and multiply it by another number from the user, and present it in a toast, per the instructions. I looked at the numbers, however, and realized that I didn’t want six+ decimal places, just 2. So, one piece at a time, back to Google, and now, praise God, it’s working!

 

You can check out the code here:

 

Here is my ANDROIDMANIFEST.XML

[CODE]

   

       

           

               
               

           

       

   

[/CODE]
Then my MAIN.XML

[CODE]

[/CODE]
Finally, my MAINACTIVITY.JAVA

[CODE]

 package com.mycompany.ustoau;
import android.app.*;

import android.os.*;
import android.app.*;

import android.os.*;

import android.view.*;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.ImageView;

import android.widget.*;

import java.text.DecimalFormat;
public class MainActivity extends Activity 

{

    @Override

    protected void onCreate(Bundle savedInstanceState)

    {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

    }

public void convert (View view){

DecimalFormat precision = new DecimalFormat(“0.00”);

EditText usDollar = (EditText) findViewById(R.id.myDollar);

Double valueUs = Double.parseDouble(usDollar.getText().toString());

Double valueAu = 1.35;

Double calculatedValue = valueUs*valueAu;

Toast toast = Toast.makeText(getApplicationContext(), “You have: $” + precision.format(calculatedValue), Toast.LENGTH_LONG);

toast.show();

}

}
[/CODE]


Linux – keep it simple.

The magic button that changes the picture!

​This android developer course is actually pretty fun! There are several hard parts, and a few “scratch my head” moments, but Rob does a great job of explaining what to do.
Here’s my latest creation:
https://www.mediafire.com/download/168pmpux75y8w9u

It is a simple app that changes the picture and gives you a popup (toast) when you click the button.
I am a bit proud of myself on this one, because I went above and beyond the task at hand (changing the picture) but also added the toast (from a previous lesson) and changed the icon (which I posted a “how to” on earlier). The great part is, Rob will teach you some principles, and then give you a related task that he didn’t specifically cover.
In this case, he showed us how to display an image, and then asked us to figure out how to change it. Fortunately, there is Google, or I would not have made it work! After you finish the challenge, you can continue through the video and watch Rob explain it, step by step. It’s funny how things that take me an hour he does in about 3 to 5 minutes!
Here is my ANDROIDMANIFEST.XML

[CODE]

   

       

           

               
               

           

       

   

[/CODE]
Then my MAIN.XML

[CODE]

[/CODE]
Finally, my MAINACTIVITY.JAVA

[CODE]

package com.mycompany.images;
import android.app.*;

import android.os.*;

import android.view.*;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.ImageView;

import android.widget.*;
public class MainActivity extends Activity 

{

Boolean flag=false;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

}
//mess method is declared in XML file

//This function will call when we click on button

//and we have to pass View object in this method

//which will take id of clicked button
public void change(View v)

{

Toast toast = Toast.makeText(getApplicationContext(), “Changing Picture…”, Toast.LENGTH_SHORT);

toast.show();

ImageView iv=(ImageView)findViewById(R.id.mainImageView1);

//use flag to change image

if(flag==false)

{

iv.setImageResource(R.drawable.ic_launcher);

flag=true;

}

else

{

iv.setImageResource(R.drawable.kdf);

flag=false;

}

}

}

[/CODE]
To God be the glory, it even works! Thankfully, there were several helpful finds on stack overflow and other blogs from my Google search. I certainly do not want to take credit for another’s work! I just put all the pieces together.
Another important part of the equation is to put ic_launcher.png and kdf.png (or whatever you name your icons) into the drawable folder in your source.

Linux – keep it simple.

​Changing your Android app icon.

As I continue my studies in Android app making, I was a bit surprised that we had not yet covered how to change your application’s icon. I suppose making the app actually work is the most important part, so I am glad that we are focused on that. However, the first impression of your app to the user is the icon you use.

Within a few minutes on Google, the answer was readily available. Perhaps it is because it is so simple that it was felt to be too simple for the course. Or, since I have not finished the course, perhaps there is a section for that later.
In either event, the answer is simple and I will share it here.
In your app folder is ./src/main/res/drawable-xxhdpi and similar “drawable” folders. These folders contain the icon in different sizes for different screen settings of different phones. In my case, the icon in each folder is called “ic_launcher.png”. The quick and easy way to change the icon for your app is to delete this icon, and replace it with the icon you want to use, and rename that new icon with the same name as the one you deleted.
After a little trial and error, I found that 128×128 icons display great as xxhdpi icons, but your mileage may vary depending on your system. Now just recompile your app and you can praise God that your icon has changed!
Linux – keep it simple.

Making Toast

As I have mentioned previously, I am continuing my studies with an online course from Udemy by Rob Perceval about how to build Android apps. Here is my latest creation:

https://www.mediafire.com/download/1l8ba54llk4c2y4
It’s a simple app, but I am excited because it is the first truely interactive app that I have built. Not only can the user input something, but the user gets a reply from Android!

The course is really fun and, for the most part, intuitive. The course is designed around using Android Studio, but I have also been using AIDE, the Android equivalent.


It is a little less intuitive than using Android Studio, but it is still a great tool with auto complete and error checking. Not to mention, when I click run, to test my app, it builds the app and installs it on my phone! No emulator needed, and you know exactly what your app will look like when you hold it in your hands.

It is also great for working on the go. It even has a visual editor for layout designing.

Linux – keep it simple.

Setting up Android Studio on a Debian Jessie HP Compaq 6715b AMD Turion X2 Processor

Setting up Android Studio on a HP Compaq 6715b AMD Turion X2 processor was far from simple. I followed numerous guides online, read dozens of articles on Stack Overflow, and yet, I was still stuck. Until I finally got it going (Praise God!). So, what made it so difficult? Well, let me tell you:

It all started when I bought a technical book from Amazon for kindle. Somehow, that book got me a reference to a course on Udemy called “The Complete Android Developer Course” By Rob Percival. Normally, the course was $200 plus, but for some reason it was on sale for a mere $17! The course said that it was designed for what I call “zero to hero” students, or those who knew little to nothing about the subject to train them to know enough to be dangerous, er, uh, useful. Needless to say, I purchased the online course.

In the course, which is a bit older now, Rob is using Android Studio 1.1 and suggests that students could use newer versions, but that they could also use AS 1.1 if they want everything to look and act the exact same way as in the course material. So, I downloaded AS 1.1. There were so many problems getting that to run, that I will not even discuss those here, for fear of nightmarish flashbacks.

So, I downloaded the latest version for Linux, 2.2. It launched first try. I followed instructions from a blog here:

http://ridz1ba.blogspot.com/2015/07/how-to-install-oracle-java-and-android.html

Which worked to get Android Studio to start. However, after following along through the course, it was time to launch my first app, which did not launch. Instead I received the following error:

[CODE]
glxinfo
libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast
X Error of failed request: BadValue (integer parameter out of range for operation)
Major opcode of failed request: 155 (GLX)
Minor opcode of failed request: 24 (X_GLXCreateNewContext)
Value in failed request: 0x0
Serial number of failed request: 38
Current serial number in output stream: 39
[/CODE]

This lead me on a painful search, from which I would like to save you similar users from doing and afflicting yourselves with. Here was what I did in the end:

I thought that for my model/make of processor, I could not use the x86 version of the emulator, so, when I set up a new device, or create a new virtual device, I needed to click on the “other” tab and choose an arm variant. This did not solve the issue, the same error happened when trying to launch my app.

Then I realized that I needed to install more dependencies. I used aptitude search and found that I also needed to install these:

[CODE]$ sudo apt-get install libgl1-mesa-swrast-dev libgl1-mesa-dev -y [/CODE]

Then, when I pressed launch, the android phone would appear, but it stayed blank. Finally, I found taht I had a graphics issue, which I could resolve by creating a new virtual device, and choosing “advanced features”. In those features is the option to use software graphics instead of hardware graphics. After selecting that, launching my app made the phone appear, AND it began to boot.

Now I can boot using the arm version or the x86 version. However, in the arm version, it is so slow that it is practically unusable. In the x86 version, it is also very slow, but usable, and I receive these errors:

[CODE]
WARNING: The Mesa software renderer is deprecated. Use Swiftshader (-gpu swiftshader) for software rendering.
emulator: WARNING: Host CPU is missing the following feature(s) required for x86 emulation: SSSE3
Hardware-accelerated emulation may not work properly!
[/CODE]

The first start up took a while, but now, when I make changes to my app, from pressing launch to actually seeing my app on screen takes 2:27 (m:ss), which is a bit slow, but reasonable on an older laptop. Hopefully, this will help others trying to use Android Studio on older laptops running Debian 8 with a Turion X2 processor.

Linux – keep it simple.