Tuesday, May 28, 2013

Android 1: Lesson 4: Java Language

Lesson 4: Java Language
INTRODUCTION
In this lesson you will be learning how to understand and use Java and how it will make your app work

LESSON OBJECTIVES
By the end of this lesson, you will be able to:
1. Learning how to connected your 'main_activity.xml' to your Java
2. Understanding what each piece of code does in Java

LEARNING SEQUENCE

Required Reading
Read the following:
Introduction To Development Environment
·        Eclipse
·        Android
·        Activity-Google site
Resources
View the following: 
1.      Eclipse
2.      Android Development
Assignments 

  1. Java is a complicated language, but it is very efficient when used correctly
  2. First we’ll start with creating a new class in the 'src' folder, open the 'src' folder and you should see the package: 'com.example.(name of your app)', and inside that you'll see the 'MainActivity.java' class. Double click on the class and it will open
  3. Here, you'll see (from the top down) the package name. 3 imports. a public class. and 2 overrides
  4. The imports are what make Java efficient and fast. Java has a massive library of different things it can do, but only if you import it to the app so it knows how
  5. The android 'import android.os.bundle' is what allows it to work in the android API
  6. 'import android.os.Activity' is where all the actual java happens.
  7. 'public class' means that it is open to the users, and the class defines a variable within the class
  8. inside the 'public class' are the overrides. One of them has 'protected void' and the other has 'public boolean'
  9. protected means that it can be accessed by the other classes that get related to it
  10. boolean, inside the other override, is a primitive type of object, using less memory (RAM) to run than the more complicated Boolean, with a captial B. Java is very fragile when it comes to capitalization.
  11. onCreate is what actually runs when the app opens. Java runs in a very specific way. It first scans your code for the onCreate method, than runs from there, as seen on the Google website about Activities http://developer.android.com/reference/android/app/Activity.html
  12. Right now, the Java isn't doing anything with your app and doesn't have the following pieces of code, but you will be adding them next lesson. You have to assign each thing in the interface to a piece of code in Java
  13. For the TextView, it will be assigned the title of 'display', which allows it to get changed and altered by different pieces of Java
  14. You then can assign the buttons to individual pieces of code, cause you don't want them doing the same thing. Making one of the buttons 'add' and the other 'sub'
  15. 'int' tells the Java what it's going to be doing. if you assign 'counter' to the 'int', then the Java will know what you're doing and that it will be adding or subtracting one from the display

Android 1: Lesson 3: Starting a New project and Understanding XML layout

Lesson 3: Starting a New Project and Understanding XML Layout
INTRODUCTION
In this lesson you will be testing what each piece of code does, and how it works. You'll be changing certain parts of the code to see how it comes out in the 'Graphic Layout' of Eclipse.

LESSON OBJECTIVES
By the end of this lesson, you will be able to:
1. Learning how to 'Clean' your project
2. Understand TextView and Button code
3. Seeing what each piece of code actually does
LEARNING SEQUENCE

Required Reading
Read the following:
Introduction To Development Environment
·        Eclipse
·        Android
·        Considerations for beginning programming.
Resources
View the following: 
1.      Eclipse
2.      Android Development
Assignments 

  1. During this video, we’ll be showing you what each piece of code does in the ‘activity_main.xml’ and how to clean your project
  2. First we’ll start with how to clean the project. Cleaning your project is when Eclipse scans your app of any false errors, and cleans it.
  3. When you open your app, or you are sure you don't have any errors in the code, you should clean the app.
  4. Go to PROJECT>CLEAN. Then the Clean menu will pop up. You can either clean all of your projects, or chose to clean only one of the projects. Cleaning all of them takes longer, so check the ‘Clean selected projects below’ and click only your project. This scans the whole app and gets rid of the errors that don’t actually exist, and leaves you with only the true errors
  5. The rest of the errors you can change by checking the coding with the video, and hovering your mouse over the error and seeing what Eclipse suggests to fix it.
  6. Next you will change what each piece of code does. Let’s start with ‘orientation’. This determines if it goes vertical or horizontal. Change the word vertical to horizontal, and open up the ‘graphic layout’ at the bottom left of the XML document.
  7. You’ll now see that the app Layout hasn't changed, but the TextView and the Buttons have shifted to a horizontal view
  8. Now the 'android:layout_width/height' coding. This piece of code determines how much space each piece of code takes up, as described in the last lesson
  9. Changing the code here, you will not see a physical change except that the TextView and Buttons will shift around slightly in the graphic layout
  10. The 'android:text' describes what the TextView and Button say on them. the 'android:textSize' will change how big the text will be.
  11. You can change the 'android:textSize' from dp to xp or sp. Which are all different text sizes. 
  12. xp being the default for most devices, and will keep the text at a permanent size not matter the screen size. sp is another ratio, much like dp
  13. Changing the 'android:layout_gravity' will move around the pieces of the app. You can change it from 'center', to the 'right', and to the 'left'
  14. 'android:id' will not give you anything special in your app, changing this will not be shown in the graphic layout of Eclipse. The id refers to the identification of the app in the java.