Notes on The New Boston Tutorials on Android App Development

    These notes are intended to complement the series of 200 YouTube video tutorials given by
    "The New Boston", otherwise known as Travis, covering android app software development
    for Android devices using Java-JDK, Eclipse, ADT, and SDK. I started writing the notes
    so that I could use them later as an index to the tutorials. To that end, I have tried to make
    a reference to android keywords as they crop up and are covered in the tutorials.

    Without wanting to critisise Travis unduly, because I have found (and am still finding) these
    tutorials to be very valuable, there are times when it was not immediately clear to me what
    the aims of some of the tutorials were. There is a lot of presentation of detail, without
    giving an overview of where the tutorials are leading. Here and there I have tried to remedy
    this deficiency. My apologies to Travis and to you, the reader, if you feel that this is
    superfluous.

    With that said, let's get back to the tutorials. I found it useful to download the tutorials
    so that I could then watch them off-line. One can download the tutorials under linux using
    commands of the form:

        youtube-dl "http://www.youtube.com/watch?v=<video-id-code>"

    e.g. the first tutorial can be downloaded thus:

        youtube-dl "http://www.youtube.com/watch?v=SUOWNXGRc6g"

    A list of the first 30 video-id-codes, valid as of Feb 2014, can be found here.
    A list of the remaining 170 codes can be found in the notes to Tutorial 31.

Tutorial 1: Download and Install the Java JDK

    The first 3 tutorials cover the downloading and installation of the required
    software development tools. The first tutorial covers the installation of JDK,
    the Java Development Kit.

    For the record, I started following the tutorials using Ubuntu 12.04 LTS, and have since
    upgraded to Ubuntu 14.04.1 LTS. I downloaded the Android SDK Starter Package, a bundled
    development package from:

       http://developer.android.com/training/

    i.e. not as described in the first 3 tutorials. At the time of writing, I have still not
    completed the course. If I come to regret using this Android Starter Package, I'll modify this
    reference.

Tutorial 2: Installing Eclipse and Setting up the ADT

    The second tutorial covers the installation of the Eclipse IDE (Integrated
    Development Environment). See the notes on Tutorial 1 for an alternative
    installation procedure.

    The tutorial also specifies a workspace for Eclipse. It creates:

          $HOME/Documents/thenewboston/

    I chose instead:

          $HOME/android/workspace/

    Then comes the setup of the ADT (Android Development Tools) plugin for Eclipse.

Tutorial 3: Installing Android SDK and Set up Emulator

    The third tutorial covers the installation of the Android SDK (Software Development
    Kit) and the AVD (Android Virtual Device) Manager. When downloading the SDK, one
    must select which Android version one wishes to develop for. The tutorial selects

         SDK Platform Android 2.2, API 8, revision 2

    so make sure that your kit is set up for this level, or higher. Following this,
    the tutorial covers the setting up of the Android emulator. Travis calls his emulator
    "droidX" with 100 MB SD card. I called mine "virtualTablet".

    See the notes on Tutorial 1 for an alternative installation procedure.

Tutorial 4: Setting up an Android Project

    The first part of the tutorial discusses the setting up of the Eclipse Android
    Preferences. As far as I remember, the Android SDK Starter Package, which
    I installed (see Tutorial 1), did all of that automatically.

    There follows the setting up of a new Android project. Travis called his
    The New Boston. I called mine dm001, with a package name of
    ch.maden.dm001, and Activity Name of StartingPoint.

    Note 1: My version of Eclipse SDK insisted that the activity name started with a
    capital letter. Travis comments on this convention in a later tutorial.

    Note 2: The first time I worked through the tutorials, I called my project
    tnb-dm001. The minus sign led to something having an invalid name at around
    Tutorial 14. I have redone the course using simply dm001. 

    Note 3: During this tutorial, Travis shows how to get back the sub-window
    of the Package Explorer should one have deleted it inadvertently. I could
    not find the button that he used on my version of Eclipse. Instead, I can recover
    it via:
               Window --> Show View --> Package Explorer

Tutorial 5: Overview of Project and Adding Folders

    Travis start off by starting the SDK and AVD Manager. On my system, it's
    simply the "Android Virtual Device Manager". The "Android SDK Manager"
    is a separate window. He launches the emulated device created in Tutorial 3.

    Then comes a description of the various components of a project. He also
    creates the extra res folders raw and layout-land. Finally there
    is an important discussion of the "AndroidManifest". The concept of Permissions
    in the manifest is also introduced.

    The project is finally installed in the emulator and run. As one might
    expect, it simply displays the message "Hello World!".

Tutorial 6: Introduction to Layouts in XML

    At the start to Tutorial 6, Travis starts work on res/layout/main.xml. On my system, the
    file in question is called res/layout/activity_starting_point.xml. The tutorial is a
    little confusing because Travis had been playing with this file before starting the tutorial.
    If one uses cut and paste to get the file to look like:

         <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
           android:orientation="vertical"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           >
         <TextView
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:text="@string/hello"
           />
         </LinearLayout>

    one should be able to follow the tutorial. It may also be necessary to edit
    res/values/strings.xml to change <string name="hello_world"> ...
    to <string name="hello"> ...

    Another alternative for layout_width in TextView is wrap_content.

    At the end of the tutorial, after all the playing around, the xml-file looks like:

         <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
           android:orientation="horizontal"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           >
         <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="@string/title"
           />
         <TextView
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:text="Type"
           />
         </LinearLayout>

    and one must add a definition for <string name="title">in strings.xml.

Tutorial 7: Creating A Button in XML and Adding an ID

    The state of the res/layout/activity_starting_point.xml file at the start of this
    tutorial is as it was left at the end of the previous tutorial (see above).

    Tutorial 7 introduces several TextView methods:

           android:textSize=45px   (pixels)
                             =45dp   (density pixels)
           android:layout_gravity="center"
 
      One can also centre thus:
           android:layout_width="fill_parent"
           android:gravity="center"

    Buttons are added to the App. The first one is:
        <Button
          android:layout_width="250dp"
          android:layout_height="wrap_content"
          android:text="Add one"
          android:layout_gravity="center"
          android:textSize="20dp"
        />
    and the second one:
        <Button
          android:layout_width="250dp"
          android:layout_height="wrap_content"
          android:text="Subtract one"
          android:layout_gravity="center"
          android:textSize="20dp"
        />

    To finish, the concept of a reference or id is introduced. The
    TextView is given the id tvDisplay via the statement:

          android:id="@+id/tvDisplay"

    The buttons are similarly given id's of bAdd and bSub.

    The source code of res/layout/activity_starting_point.xml at the end of
    Tutorial 7 can be found here.

Tutorial 8: Setting up Variables and Referencing XML ids

    Tutorial 8 deals with the StartingPoint.java file located in the src
    directory. It describes the adding of variables to the code to reference the
    xml id's defined in Tutorial 7, and shows how they must be initialised when the
    activity is created.

    Note that the addition of variable types such as Button or TextView
    require the addition of extra import commands to get the variable types
    defined.

    The source code of src/ch/maden/dm001/StartingPoint.java at the end of
    Tutorial 8 can be found here.

Tutorial 9: Set up a Button with OnClickListener

    Tutorial 9 continues the development of the StartingPoint.java file started
    in Tutorial 8. It deals with the OnClick setup of the add and sub buttons.
    The code added for each button is of the form:

        buttonName.setOnClickListener (new View.OnClickListener () {
            @Override
            public void onClick (View arg0) {
                // TODO Auto-generated method stub
            }
        });

    The source code of StartingPoint.java at the end of Tutorial 9 can be found here.

Tutorial 10: Using setText method for our button

    Tutorial 10 continues further the development of the StartingPoint.java file.
    It handles the actual OnClick activity of the buttons.

    This is all quite straightforward. For reference, the source code of StartingPoint.java
    at the end of Tutorial 10 can be found here.

    At this point, Android Project dm001 was cloned to create Android Project dm002. 
    As an aside, a step-by-step description of how to clone an Android project can be found
    here.
    Subsequent work is done on dm002. As a result, certain files had minor modifications.
    The new versions of these files are:
        AndroidManifest.xml
        StartingPoint.java
        strings.xml

Tutorial 11: Adding Resources and Setting Background

    For this tutorial one needs an image file in png format, and a sound file in mp3
    or ogg format. To get the image, I simply took a screen-shot, and to make the sound file I
    simply looked for an ogg file on the system disk and made a copy of that.

    The image file should have a lowercase name and be stored in the res/drawable-hdpi/
    directory of our Android project. The sound file should also have a lowercase name. It
    should be stored in the raw directory created in Tutorial 5. I called it dm_splashsound.ogg.
    The project then had to be cleaned via the Project --> Clean... tab to make the new files
    visible to Eclipse.

    During the tutorial, a new xml layout file is created:

                   res/layout/splash.xml

    Having named my png file dm_splash_background.png, the content of the
    splash.xml is:

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:background="@drawable/dm_splash_background"
            >
        </LinearLayout>

Tutorial 12: Setting up an Activity and Using SetContentView

    The tutorial starts by making a new Java class:

         /dm002/src/ch/maden/dm002/Splash.java

    and modifying it to be an activity by adding "extends Activity" to the
    "public class Splash" declaration. This also requires the importation of
    android.app.Activity. Following this, the onCreate method is added,
    and a setContentView of the splash layout is inserted into this. The source
    code of Splash.java can be found here.

Tutorial 13: Introduction to the Android Manifest

    As the title of the tutorial indicates, the subject of interest is the Android
    Manifest. The goal it so get the splash screen to display before the main part
    of the app gets going by adding a second activity.

    The Android Manifest at the start of this tutorial can be found here.

    The Android Manifest at the end of this tutorial can be found here.

Tutorial 14: The Framework of a Thread

    The tutorial enhances the Splash.java activity to get it to sleep for a while and then
    activate the main app. This is done by means of a thread. See Tutorial 12 for the
    code of Splash.java at the start of the tutorial.

    The framework of a thread is defined, and the try/catch/finally construct is introduced.

    The (still incomplete) code of Splash.java at the end of the tutorial can be found here.
    Note the error flag on InterruptedException. This is because the try clause is still empty.

Tutorial 15: How to Start a New Activity via Intent

    In this tutorial the splash activity defined in Splash.java is completed.
    The try/catch/finally construct is filled in with a sleep, an Intent definition,
    and a startActivity.

    The completed version of Splash.java at the end of the tutorial can be found here.

Tutorial 16: Activity Life Cycle

    The splash activity is enhanced to disappear cleanly. An onPause method is added
    which calls finish. The completed version of Splash.java at the end of the tutorial can be
    found here.

Tutorial 17: Adding Music with MediaPlayer

    Sound Pool (SP) and Media Player (MP). SP is used for short clips. MP is used for
    everything else.

    Splash.java gets edited to add MP calls to play raw/dm_splashsound.ogg.

    The source code of Splash.java at the end of Tutorial 17 can be
    found here.

    At this point, Android Project dm002 was cloned to create Android Project dm003. 
    Subsequent work is done on dm003. As a result, certain files had minor modifications.
    The new versions of these files are:
        AndroidManifest.xml
        StartingPoint.java
        Splash.java
        strings.xml

Tutorial 18: Create a List Menu from the ListActivity class

    Here we start to set up an example App with a menu.

    A new class, Menu.java is created and marked as "extends ListActivity".
    It is given 2 Override/Implement methods, an onCreate() and an onListItemClick().
    In addition, a string array classes[] is defined for future use.

    The code of Menu.java at this point can be seen here.

Tutorial 19: Setting up an ArrayAdapter

    This tutorial simply does what the title says. The code of Menu.java at the end of the tutorial
    can be seen here. Essentially a single line has been added to the onCreate() method.

Tutorial 20: Starting an Activity with a Class Object

    Some code is added to the onListItemClick method in Menu.java to start up an
    activity using classes. At the end of the tutorial the code is not yet complete, but can,
    in any case, be seen here.

    Note: there is an error flagged on the Class.forName statement, which should get fixed later.

Tutorial 21: Finishing ListActivity

    In this tutorial, the ListActivity example started in Tutorial 18 is completed. This
    involves edits to 3 files, viz. Menu.java, Splash.java, AndroidManifest.xml. Most of the
    time is spent editing, and discussing the edits to, Menu.java. Much of this is basic programming
    knowledge, so the final version of the Menu.java source code should suffice
    here.

    The AndroidManifest requires the addition of the Menu activity. This is done
    by simply copying and pasting the StartingPoint activity and modifying the
    android:name of the activity and the android:name of the intent filter.
    This should all be quite obvious on looking at the source code of AndroidManifest.xml.

    The change to Splash.java involves simply changing the openStartingPoint intent from
    StartingPoint to Menu.

    The state of the 3 files at the end of the tutorial can be seen here:
        Menu.java
        Splash.java
        AndroidManifest.xml

Tutorial 22: XML: Introducing the EditText Widget

    Create a new layout for illustrating text type operations called text.xml. Insert
    an EditText, a Button, and a TextView widget with appropriate properties.

    At the end of the tutorial the code is not yet complete, but text.xml as it
    stands at this point can be seen here.

Tutorial 23: XML: ToggleButton, WeightSum, and Layout Weight

    A ToggleButton is added to the screen, and the buttons are nested into
    a horizontal LinearLayout to get them to lie on the same line. The widths of the
    buttons are specified via the WeightSum of the LinearLayout being shared between
    the 2 buttons via the Layout Weight values of the buttons. Note that the bigger the
    Layout Weight, the narrower is the button! Both buttons have the layout_width set
    to fill_parent.

    text.xml as it stands at this point can be seen here.

Tutorial 24: XML: Padding and Setting Toggle to On

    The tutorial just demonstrates the effect of padding on the overall LinearLayout
    and the bottom of the ToggleButton. The initial value of the ToggleButton
    is set to On via the android:checked property.

    There shouldn't be any need to show the code at this point.

Tutorial 25: Quick Review by setting up a new Activity

    This tutorial makes quite quick changes to the following 4 files:
        AndroidManifest.xml
        res/layout/text.xml
        src/ch/maden/dm003/TextPlay.java   <-- this is a new file
        src/ch/maden/dm003/Menu.java

    The links show the files at the end of the tutorial. All the actions have
    basically been done before, so they will not be elaborated here, simply stated.

      AndroidManifest.xml: This is extended to refer to the new TextPlay activity.

      text.xml: The changes here are essentially cosmetic. The android:text of the
                bResults button is changed from "Button" to "Try Command", and the id of
                the toggle button is changed from "toggleButton1" to "tbPassword".

      TextPlay.java: This activity is created. In the onCreate method, it sets
                     the view to text.xml and sets up variables for the 4 items on that view.

      Menu.java: The second element of the classes array is changed from "example1" to "TextPlay".
                 Clicking the second entry will now activate the TextPlay activity.

Tutorial 26: If Toggle Button is checked

    This tutorial works on TextPlay.java.

    A setOnClickListener is set up for the toggle button, the concept of final is
    introduced, and the if/else construct is used for the first time.

Tutorial 27: Set the Input Type of an EditText

    This tutorial continues work on TextPlay.java.

    In the if/else construct, the TYPE_TEXT_VARIATION_PASSWORD property of the EditText
    widget gets set using setInputType method of the EditText class.

Tutorial 28: Comparing Strings with else if

    This tutorial continues work on TextPlay.java.

    A setOnClickListener is set up for the bResults button. When the button is clicked,
    the text from the etCommands EditText widget is extracted using the getText method
    and converted to a string using the toString method. This string is then tested with
    a series of if/else if tests. Note that the test has to be done via the
    contentEquals method of the String class rather than by a simple "==" test.

Tutorial 29: Set Gravity within Java

    This tutorial continues work on TextPlay.java. It simply sets the gravity of the
    tvResults TextView widget to left, centre, or right align the displayed text using
    the setGravity method of the TextView class in Java.

Tutorial 30: Setting Colour of a TextView in Java

    This is a simple continuation of the themes covered in Tutorials 25 to
    29 inclusive. It requires no further explanation.

To see the remaining 170 notes, you will require a key.
Please contact David at