Day 8 – Learning Android Development

Today I focused completely on Java, I looked at the TheNewBoston’s tutorial videos on Java. I felt I needed more background on the language I’m using to create apps so today and for the next 2-3 days I will look at all the beginner tutorial videos. He has around 87 for beginners. After that he has a series on more advanced java but I don’t think I need that right now to develop simple apps.

The videos went of course on the basics, most of them I already knew from before but it’s good to see the good way of writing java. I learned what a scanner was for user input. How to use other classes inside a class. First I thought it could only be done by importing but now I know it can be done by the statement: ” Classname objectname = new Classname(); ”  if your class is in the same source.

I met the while loop for the first time in java, not really that different from python. Conditionals I had already met before during some app development. Something new was how to make a constructor method, it must have the same name as the class and is used to pass a parameter directly when you create an instance.

Lots of other stuff were shown during the 20 first videos that I knew of but did not know how to implement them in Java, so these videos are really helping me a lot.

Day 7 – Learning Android Development

My connection has been fixed so today I was able to resume the TheNewBoston tutorials. Today I learned some new interesting things while working on a second app from the tutorial.

The app consists of a text input box, that when typing certain commands it will do things. For example you can type in WTF and it will print it out below the input box, but with random colors and text sizes,  I got introduced to the Random class in Java to implement this. I also learned about password input type, which can hide what you are writing in the input box like a password. I did that by putting a toggle where ON = hide the input text.

[slideshow]

I learned that a final variable cannot be changed. Also that you cannot compare two strings with “==”, you have to use the  “.contentEquals()” method or a variant thereof. when you use == for strings, you are checking if the memory location of both strings are the same instead of checking to see if they contain the same word.

The tutorial introduced me to a switch statement which i had never heard of before. Now I know it’s a conditional statement and know how to use one. It is replaceable by the traditional” if/else” statement, but the latter is more of a choice, semantically speaking. If this is true, then you do something, if not, then you do something else. While a switch is more of a case e.g.this switch refers to this type of case. At least that’s how I see it, and I’m just a newbie.

I also got introduced to implementing interfaces. I had always seen examples where you extend a class, which means that in your current class you can use methods from another class. When you implement an interface though, you have to use all the methods. An interface is a reference type, like a class is, but can only contain constants, method signatures, and nested types. They don’t have method bodies and cannot be instantiated like a class can, they can only be implemented by classes. The interface I used is View.OnClickListener which is a public static interface.

Day 6 – Learning Android Development

The internet was cut off today for unknown reasons so what I did was use my phone’s 3G network to continue learning, but I didn’t watch video tutorials because that would’ve been a bit expensive. Instead I played around with eclipse and searched a bit on the Java documentation.

I played around with creating an App from scratch again without the help of tutorials. Create new project, create the starting activity class and its layout, and then linking other activities to the starting one. But I had one problem, how could the code for telling the program to sleep for 1.5 seconds be so long? take a look:

Why can’t it be just sleep(1500)? instead of all that?  short answer: you have to.

You must define a new thread. I had never heard of threads before 2-3 days ago when I first linked a new activity to the main one. In python, I would just tell the program sleep(seconds) if i had to wait for something. But the thing is, that would stop execution of code, sleep means the computer isn’t processing anything for that amount of seconds. Threads are awesome, they are threads of execution. The Java virtual machine gives you the ability to have multiple threads of execution running simultaneously. This means you can be running an algorithm that searches for prime numbers and at the same time printing out names of fruit, if you would ever do that.

A new thread is needed in my case because if I tell the current (and single) thread to sleep and then open up a new activity, my previous activity wont show the title. That means my previous activity freezes and doesn’t show anything for those 1.5 seconds. So I need a new thread that will do the waiting and then opening of a new activity, so the old thread can load and run the title.

Day 5 – Learning Android Development

I didn’t do much today. I spent almost the whole day playing skyrim but right now I’ve been able to do some things.

I continued with the video tutorials of TheNewBoston. I created a menu for my app, which uses a special child class of activity called ListActivity. You create an array in order for the activity to show the menu. Then that array gets used by the setListAdapter method from the ListActivity class to provide the cursor for the menu. From there you define inside the method onListItemClick that when you click an item from the menu, it must take you to that activity.

[slideshow]

So I had to change the flow of activities as well. Now the launcher activity or the one that starts is the menu, then you can choose +- 1(or in the future other activities) and the title screen will appear first, followed by the actual activity. since I had to do that, I decided to refactor some class names and xml file names. What followed was a bunch of errors everywhere so I spent quite a while correcting them. But I couldn’t correct a peculiar one, eclipse told me that it couldn’t find R in R.layout. It was constantly trying to import android.R but that was not a class I needed. After a while I figured out that something was wrong in an xml file name I was trying to use for setContentView, I was using upper case which is not possible for xml files. At least I got to know the debugger better.

After that I worked a bit more on xml, discovered how beautiful android:padding and android:weightSum are.

Day 4 – Learning Android Development

Today I did a bit of everything: design, sound and coding. I followed TheNewBoston again, this time videos 11-19. I’m really happy by the way he teaches and I feel I’m learning things at a good pace.

I started out by creating a title design in Photoshop for the app I created yesterday, which i call “+- 1”. Note that most of the code for this app is copied from TheNewBoston’s tutorial, the rest of it is code I’ve added myself or are tweaks from his code. The design is all mine.

Image
Title actitvity
Image
Main Activity

 

 

 

 

 

 

 

 

 

 

The title comes out whenever you start the app (onCreate phase). It lasts 1.5 seconds and then the main activity comes out. You can’t go back to the title activity once you pass it. This is intended as you don’t want the user to go back to the title when he presses the return key. It’s done by putting finish() at the onStop() method, this finishes the class once the activity is not visible.

I redid the layout of the main activity as well as you can see its now a dark grey gradient background and bone colored font. Plus I added sound to the buttons once you press them. For the sound I used Sunvox.

I started on arrays that will make it easier to switch from activities but I will continue on that tomorrow.

The Java is progressing more and more. I haven’t looked at additional resources for it and just by looking at the android tutorials I’ve been able to relate most of it to Python as I learned OOP from there. Creating classes, inheritance, methods, attributes, invoking methods, etc. I’ve been able to handle correctly most of it and I’m getting to know the relatively harder syntax (Python’s syntax is way more simple). But there’s sometimes I don’t get what he’s coding. Maybe I will follow some of his tutorial videos on Java programming.