LibGDX Android Studio: Download and set up a new LibGDX Project

LibGDX android Setup

Hey fellow developers!

Welcome to the beginning of LibGDX for Android tutorials. In this tutorial, you will learn how to download, setup and create a new LibGDX project in Android Studio.

At the end of this tutorial, you will:

  1. Download LibGDX
  2. Setup LibGDX
  3. Create a new LibGDX project in Android Studio

So lets get Started!


Download LibGDX

First of all, lets download LibGDX. (I am assuming that you already have Android Studio.)

  1. Go to official LibGDX website.
  2. Go to Download
  3. Download (Duh!)
  4. And open the folder

This process is given here

 LibGDX Android Studio - Download

Now, we will setup LibGDX for our project.


Setup LibGDX

Now, we will setup the LibGDX project using the downloaded gdx-setup.java file.

  1. First of all, fill in the basic project information
    1. Run gdx-setup.java
    2. Provide your Project name.
    3. Provide package information according to your settings
    4. Game Class is the java class file name that you will eventually be working with.
    5. Destination is where you will work on your project.
    6. Android SDK is where your Android SDK is installed. Give its path.
  2. Sub-Projects is where you provide the platforms that you wish to support.
    1. Chose Android
      (Only because this is an android based tutorial. But you are not limited to that.)
  3. Extensions is where you tell the setup what extensions to load.
    1. For simplicity, just chose Box2d
      (you can learn more later)
  4. Press Generate
    1. Wait until the download completes.

Here is the screen shot of my completed setup.

This entire process is given below.

 LibGDX Android Studio - Setup

Now, we will open this project in Android Studio


Open in Android Studio

Follow these steps to load the LibGDX project in Android Studio

  1. Open Android Studio
  2. Click Import Project
    • Here is how
  3. Give path to the LibGDX download location (which you provided in setup) and press OK
    • Here is how
  4. Wait till the project is loaded in Android Studio

This entire process is given below:

LibGDX Android Studio - Load project in Android Studio

This is it. You have just loaded LibGDX in Android Studio. Now lets run it in Android Virtual Device 😀


Run LibGDX in Android Virtual Device

Follow these steps to run your new LibGDX project in AVD

  1. Launch your Android Virtual Device (AVD)
  2. Press the Run button in Android Studio
  3. Now, the app will run on your AVD. Done!

This process is given below:

LibGDX Android Studio -Launch app in AVD

This is it. You have just created and run a new LibGDX project in Android Studio.

Lets draw some shapes in the next tutorial.

Return to the LibGDX Tutorials

Creating a new OpenCV project in Android Studio

Return to OpenCV for Android Tutorials List

In this tutorial, we will create a new OpenCV project in Android Studio. Since you have everything downloaded already, we are ready to move on. By the end of this tutorial, you will have a new project set up, which you can use to build your projects upon. So lets do some CV!

Note: This tutorial has been tested on Android Studio 1.5 and 2.0

In short, the steps are, (2) Create simple project. (3) Import OpenCV SDK as a Module in Android Studio. (4) Set OpenCV Version. in Project (5) Fix Library association in project. (6) Done! Now actual OpenCV code can be written in future. The longer and detailed guided tutorial is given below.

  1. I beg you to open Android studio.
  2. Create a new project
    • I named it “OpenCV_Test”. (It could be different in the following GIF)
    • Minimum SDK is “API 19: Android 4.4 (KitKat).
    • Default Activity is “Basic Activity” (easily changeable later on)
    • Activity name is “MainActivity” (i.e. default settings)
    • I have shown the entire process in this GIF.
      Android-Studio-Create-New-Project
    • After pressing Finish, Gradle will perform some processes and eventually, you will be presented with your Android project.
    • Now, we can start importing OpenCV into the project.
  3. Import the OpenCV for Android SDK module in Android Studio.
    • To import the OpenCV SDK as a module in your project, go to File>New>Import Module.
    • Then Give path to your OpenCV as ..\OpenCV-android-sdk\sdk\java
    • You can chose to modify your module’s name.
    • Press Next and Finish the Dialogue.
    • The entire process is given here:
      OpenCV-Android-Import-Module-Android-Studio
    • Note that in the end, there are some errors in the code as well as the console. This is because you need to fix the Version number and link the libraries with your own project. This is shown in the next two steps.
  4. In this step, we will fix the Android Project SDK information in the OpenCV build.gradle file.
    • In project explorer, switch to Project view.
    • Go to OpenCVLibrary300 > build.gradle file and open it.
      • I have updated the contents of the file with the following code
      • Note that the android project’s SDK information can be obtained from the project’s own build.gradle file.
    • Once the Android SDK settings are updated, press “Try Again” button.
    • This entire process is given below:
      OpenCV-Android-Update-DefaultProject-SDK-Information
    • Now. we need to fix library association.
  5. Looking good so far! We now need to make sure that the OpenCV for Android libraries are associated with our Android Studio project. Currently, Android Studio will not recognize the OpenCV code that we type in our files. We fix this as follows.
    • Go to File>Project Structure.
    • When window opens, under Modules, select app.
    • Click Dependencies.
    • Click +.
    • Select Module Dependencies.
    • (In my case) Select :openCVLibrary300.
    • Press Ok and Ok.
    • After a few seconds, the libraries will be associated with your Android project.
    • This entire process is shown here:
      OpenCV-SDK-library-association
    • You can now write more OpenCV code in future in the same project.
  6. We did it! Project is ready for future OpenCV development.

This concludes this tutorial. You are now ready to start making your own Android Studio Project that consists of OpenCV SDK features limited only by your imagination. In the next tutorial, I will SHOW CAMERA on android app screen using OpenCV. Make sure that you read it. Do not forget to SHARE this post and write your opinions, ideas and views  in the  COMMENT  section below.

Thanks for reading :). Please like my Facebook page and follow my Twitter for more tutorials.

Return to OpenCV for Android Tutorials List

CodeIgniter 3 – Create your own Hello World with simple form and database!

CodeIgniter 3 Hello World

In the previous tutorial, you you learnt how to remove the “index.php” from URL. Now, we are ready for the “Hello World!” complete with code

GOALS!

In this tutorial, we will learn CodeIgniter 3 MVC by making a Hello World! program, complete with database, introduction to CRUD operations, form, switching pages and code. We will cover a LOT in this tutorial and I am sure you will get a lot of knowledge about CodeIgniter 3. Check the following list to see what you will learn.

  1. Create a database to be used by Model
  2. Connect the database to the web application
  3. Create a custom model:
    • Model will use the Database
    • model will contain a “Hello World!” in a function as a return value for controller to use.
  4. Create two custom views:
    • We will Load views from controller.
    • Pass data to the views using controller.
    • Use data from controller in Views.
    • Make a form which will work along with Controller.
    • Call controller custom function.
    • Pages association (move from page to page)
  5. Create a controller that will:
    • Load the model.
    • Use model function in controller.
    • Receive input from model in controller.
    • Interact with database using model.
    • Pass data to views using data[] array.
    • Create custom controller function.
    • Load views.
    • Load view from a button in another view.
    • Use helper;
    • Use constructor.

As you can see, this is a seriously deep “Hello World!” tutorial. I am sure that you will learn a lot in the end. You will be prepared to learn more without having to worry about learning the basics. Lets get started!

BEGIN!


Creating the Database

1. Create a Database

We will create a database to be used for this tutorial.

  1. In XAMPP, go to localhost/phpmyadmin/
  2. Create a  database called “citutorial
  3. Create a table using this SQL query
  4. Now make a simple “Hello World!” entry in the table so that the table has just a single entry of
    id = 1
    message = Hello World!

Eventually, your table should look like this,

 

2. Connect the Database

Go to the /application/config/database.php and modify the settings for the database citutorial. You need to input the database username, password and database name. By default, the username in XAMPP is “root” and password is empty i.e. “”. And the database name is “citutorial. So the settings are,


Creating the Model

Understanding the Model

We will now understand the model which will retrieve the “Hello World!” message from the database table we created in steps 1 & 2. First, I will show you what method I used and then you will get the entire model code.

For this tutorial, I have first selected the “table” in our database using this line of code.

Then, I provided the criteria to find the “Hello World!” message from the table like this. Note that in the following line of code, “message” is the column name and “Hello World!” is the specific search keyword that is to be matched in order to retrieve the value.

Then, I checked if the query was successful and performed an action on the basis of the success or failure of the query like so.

Note that in the end, I simply returned the result of the query like this.

(Alternative approach)

Now, note that all of this could also have been done using the following model function (which I won’t use).

3. Creating the model

Lets finally create the model file and add the code.

  1. Go to \application\models\1_hello_world\ and create a file called “Helloworld_model.php”.
  2. Double check that the file name starts with a capital letter since it is important in CI3.0+ versions.
  3. Now, open the file and add the following code to it.

This completes the model to be used in this tutorial.  Next, we will prepare our views to receive the input.


 

Creating the Views

For this tutorial, we will make two views.

  1. First view will be used to request a “Hello World!” query.
  2. Second view will be used to show the output (either failure or success)

4.1 Creating a view to request for a “Hello World!” message

This view will show a page which will ask the user to press a button to perform a request. Here are some points to note:

Follow these steps to make the request view..

  1. Go to \application\views\1_hello_world\ and create a file called “request_a_helloworld_message.php”.
  2. Add the following code to it.

4.2 Creating a view to show result

Upon completion of the request, an output message will be generated. This could contain either the “Hello World!” or an error message informing us about the failure to find the “Hello World!” message in database table.

    1. Go to \application\views\1_hello_world\ and create a file called “resultDisplay.php”.
    2. Add the following code to it

 

Creating the Controller

Now comes the really interesting component of CodeIgniter. The Controller! The controller will allow us to perform the following functions of the Hello World! tutorial application.

    1. Load the database to be used by the Model.
    2. Allow switching between two views with a button.
    3. Send data from controller and model to the view.
    4. Loading views.
    5. Calling model functions and passing its result into the view.

Now, lets first understand how I used the controller in this tutorial.

Understanding the Controller

In my controller. I have two functions which are,

    1. index() function which by default loads a request view.
    2. requestModel() function which is called by clicking a button in the “request_a_helloworld_message.php”  view.

 

index()

In this function, I am simply loading a view and passing data to it. The data is passed as an array like this,

The reason I have done it is to show you how it is possible to control the data you wish to show in view from the controller, instead of actually typing it into the view as simple HTML.

When loading views, it is possible to pass data to it. You can even load entire views into variables and pass them into the view.

 

requestModel()

In this function, I am calling a model function and basically passing its result into the view.

I am calling a model and giving it a name of “helloworldmodel” like this,

Afterwards, I have called a model function called “return_helloworld_message()” and stored its output in “$data[‘modelData’]” like this,

Finally, as before, I have loaded a view to show results and passed data to it like this.

 

5. Creating the controller

Now, we will finally create a controller and put the code in it.

  1. Go to \application\controllers\1_hello_world\ and create a Helloworld.php” and make sure that the file name starts with a capital letter
  2. Copy the following code into the Helloworld.php controller.

    Now, you are ready to test the application.

 

Testing the Hello World! application

  1. Go to your browser (chrome in my case) and go to the following address (or the correct address according to your own setup)
    http://localhost/tutorial/1_hello_world/helloworld
  2. You will see the following on the browser
  3. Press the “Submit a Request to model” button and you will go to the following link
    http://localhost/tutorial/1_hello_world/helloworld/requestModel
  4. At this point, you will be seeing this output,
  5. At this point, you can press back to start over.

You can now see that your application can retrieve data from database. This is it! the tutorial is complete!


Conclusion

You have learnt how to create a complete MVC application using CodeIgniter complete with the database. You now have the knowledge required to learn and develop more advanced web applications.

If you found my post helpful or have any questions, please leave a comment. [button link=”https://www.facebook.com/ubaaconsultants” type=”small” newwindow=”yes”] Facebook[/button] [button link=”https://twitter.com/Codeonion” type=”small” newwindow=”yes”] Twitter[/button]

If you think that there is something missing, or you would like me to add something or even, if you wish to request a tutorial, just let me know and I will make a tutorial just for you.

Back to CodeIgniter Tutorials

CodeIgniter 3.0.1 Tutorial 3 – Getting Rid of “index.php” from URL (with download)

In the previous tutorial, you learnt about the purpose of each and every folder in the /application/folder of your web applicaiton.

This is a short tutorial in which you will learn how to get rid of the “index.php” from the URL of your web application using a .htaccess file.


Problem

In a default installation of CodeIgniter 3, the URL looks like this

http://localhost/tutorial/index.php/1_hello_world/helloworld/requestModal

The URL looks bad because of the “index.php”. It is possible to get rid of “index.php” using a simple file in your application’s root.

Solution

The “index.php” can be removed by simply putting a .htaccess  file in the root of your web application. Download the file from GitHub

[button link=”https://github.com/codeonion/CodeIgniter-removing-index.php” type=”big” newwindow=”yes”] DOWNLOAD from Github[/button]

The .htaccess file should contain the following text. The link I have provided from my github repository is ready for you to use.

Now go to the root folder of your CodeIgniter web application and make sure that you put the .htaccess file there.

Now, you can safely change your URLs from

<form method=”post” action=”<?php echo base_url();?>index.php/1_hello_world/helloworld/”>

To

<form method=”post” action=”<?php echo base_url();?>1_hello_world/helloworld/”>

Note that it is still possible to keep using the “index.php” in your URLs and it will show up in URL if you do.

That’s it! You have successfully removed the “need” to have “index.php” in your URLs.


 

If you found my post helpful or have any questions, please leave a comment.

Back to CodeIgniter Tutorials

Codeigniter 2.20 – Sending E-mail using codeigniter

Back to CodeIgniter Tutorials

In CodeIgniter, sending e-mail is a simple process. First the library is loaded. Then the user provides e-mail related data. Finally, the E-mail is sent. Here is how E-mail is sent using a Controller in CodeIgniter

  1. Load the E-mail library of CodeIgniter
  2. Provide set of characters that are to be permitted in the E-mail address.
  3. Initialize the type of e-mail as html (options text or html)
  4. Provide Sender’s E-mail address
  5. Provide Receiver’s E-mail Address
  6. Provide BCC E-mail address
  7. Provide Subject of the E-mail
  8. Provide Body of the E-mail.
  9. Send the E-mail!

Following is the complete code of the above process.

Let me know in comments if there is something that you would like to know. And do like an share.

Back to CodeIgniter Tutorials