INFO1-CE9416 Homework

Spring 2015 Section 2 (14 Saturdays)

  1. February 7, 2015: Install Android Studio and Genymotion on your Macintosh or Windows PC. (Mac users must install VirtualBox too.) If you installed Android Studio and Genymotion on a Windows PC, please email me (mark.meretzky@nyu.edu) the differences between the PC and Mac installations. Create a free GitHub account and email me its name. Look here to see your classmates’ GitHub accounts. Study XML. Run Hello and do the exercises, but don’t hand them in. Look at the flowchart diagram of the Activity lifecycle in the documentation for class Activity.

    To try out the Java examples, create the Hello project. It already has a TextView in its activity_main.xml file:

        <TextView
            android:text="@string/hello_world"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
    Give the TextView an id number, as in exercise 9 of Hello.
  2.     <TextView
            android:id="@+id/textView"
            android:text="@string/hello_world"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
    The Hello project also has a method named onCreate in its MainActivity.java file:
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }
    
    Let’s say we wanted to see the output of the Java example For2.java on the screen of the Android emulator. Give onCreate the following extra statements immediately after the setContentView statement. The expression originally written in the parentheses after System.out.println in For2.java should be written in the parentheses after String.valueOf. The + "\n" moves us down to the start of the next line; you can omit it if you don’t want to move down.
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            //Get our hands on the TextView in the activity_main.xml file.
            TextView textView = (TextView)findViewById(R.id.textView);
    
            //Erase the existing text in the TextView, if any.
            textView.setText("");
    
            for (int i = 1; i <= 10; i = i + 1) {
                textView.append(String.valueOf(i) + "\n");
            }
        }
    
  3. February 14, 2015. We saw Java code that wrote its output into a TextView object in an Andoid app; see the above homework for February 7. We saw Java code that got integer input from an EditText object in an Android app; see Bed. We got up to ReturnValue.java in these Java examples. Write an Android app that does input and output, but don’t hand it in. Run it on an Android device as well as on the Genymotion emulator.
  4. February 21, 2015. We did three Java examples: Object, Class, and Subclass. We did several ways of outputting text; do the exercises there, but don’t hand them in. We did two examples of Android listeners: a click listener plugged into a Button, and a key listener plugged into an EditText. Here is the Date.java file we created in class on February 21.
  5. February 28, 2015: we did Programmatically, Japan, and Touch. Write a simple but interesting app and upload it to your GitHub account. Look at your classmates’ apps.
  6. March 7, 2015: we created an options menu using the res/menu/menu_main.xml file of the project and the onCreateOptionsMenu and onOptionsItemSelected methods of class Activity. For example, here is the res/menu/menu_main.xml file containing one <item> element from Hello; see Menu Resource.

    In Touch, the code to create the circle in the center of the big white view is now in exercise #2.

    I updated and debugged Manhattan. It was the same bug that prevented Japan’s drop shadow from working: we have to turn off hardware acceleration in the newer versions of Android.

    On February 28th I asked you to write an app and upload it to your GitHub account. On March 14th, we’ll look at these apps in class. Take a peek at them now.

  7. March 14, 2015. We used a WebView object to draw text and graphics that can be displayed on Android and Apple iOS, and to download files from the Web. Graphics examples: Etch, etc. The three animation examples have been debugged: Animation, ObjectAnimator, and ViewPropertyAnimator. We did gesture recognition: Tap, Fling, Pinch. We uploaded two student apps, CornerDot (with two Spinners) and Touch (with multiple copies of Patton) to GitHub.

    Play with ApiDemos on your simulator, and try to install it on your Android device. Read the source code of ApiDemos on GitHub. For example, the demonstration
    App → Activity → HelloWorld
    is in the files HelloWorld.java, hello_world.xml, and strings.xml. Note that the string resource named hello_world at line 36 of strings.xml. contains the HTML tags <b> (bold) and <i> (italic).

    Is there anything I need to add to the installation instructions for Microsoft Windows 7 or 8 and/or HAXM? Thanks.

    Write another Android app (or work on the one you already have) and upload it to your GitHub account by 9:00 am on March 28th. Look at the other students’ apps. Please email me (mark.meretzky@nyu.edu) your name and the name of your GitHub account if I don’t already have it.

    No class March 21 (Spring Break).

  8. March 28, 2015: up to GridView in the in-class examples. I wrote out the instructions for turning Pong into a two-player game (exercise 6). I added the missing steps in the accelerometer exercise in Pearl. Do Pong and Pearl run more smoothly on your Android device than on your emulator?

    Write and upload to your GitHub account an interesting app that we can look at in-class on April 4th. For example, an app that displays “face up” or “face down” to tell you if the Android device is lying face up or face down. (The app will detect g-forces along the Z axis. You will use the third value in the A HREF = "http://developer.android.com/reference/android/hardware/SensorEvent.html#values">values array. See the comment in the third box in exercise 4c in Pearl.) Or an app that displays a motion picture made of frames as in Phase. How about the 45 frames of the first motion picture, Fred Ott’s Sneeze? Or the Zapruder film, for you assasination buffs? Or an app that’s a two-player game (exercise 6 of Pong)? Or a one-person game? Or something with a Spinner or a ListView? PLay with each other’s apps.

    Read some of the ApiDemos demonstrations: the notorious list of 500 cheeses in ListView (easy reading), and the bouncing balls that squash against the floor in ObjectAnimator (hard reading).

    On March 28, we looked at a project that displayed a menu whose items contained icons for the sun and moon. In the current version of Android, a menu item icon is displayed only when the menu item is displayed in the form of an icon in the action bar. To see both icons in the action bar, change the project’s menu_main.xml file to the following.

    <menu xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        tools:context=".MainActivity" >
    
        <item android:id="@+id/action_settings"
            android:title="@string/action_settings"
            android:icon="@drawable/sunny"
            app:showAsAction="always" />
    
        <item android:id="@+id/exit_the_app"
            android:title="@string/options_exit_text"
            android:icon="@drawable/night"
            app:showAsAction="always" />
    </menu>
    
  9. April 4, 2015. We did the Face accelerometer example, and then did cursor-adapter-adapterview as far as Sqlite. Play with sqlite3. Then use the adb shell command we saw in Cursor to run sqlite3 on your emulator or device. Use adb pull to copy a .db file from your emulator or device to the Desktop of your Mac or PC, and then use sqlite3 to examine that file.

    Review our three examples of dialog boxes:

    1. the one containing an OK button in §2 of Text. The OK button has no listener.
    2. the one containing an EditText in the dialog.xml file and the getDouble method in the MainActivity.java file of Testbed. The EditText has a listener that listens for the ENTER key. The dialog does not have an OK button.
    3. the one containing an OK button in the displayString method in the MainActivity.java file of Testbed. The OK button does have a listener.

    Add a few contacts to your emulator or device if you have not already done so. Then write and upload an app that adds two features to the Sqlite app.

    1. When you append a new row, it should pop up a dialog containing an EditText asking for the name in the new row. EditText will have a listener that listens for the ENTER key and appends the new row. The dialog will not have an OK button.
    2. We already have menu entries in menu_main.xml for “Append a new row” and “Delete all rows”. Add a menu entry for “Update a row”. It will pop up a dialog that asks for the id number of a row and the new name that will go in that row, overwriting the old name.

    I would be delighted if you added even more features, or wrote an additional app involving accelerometers, animation, the beeping sound in the Pong exercise, etc.

    On April 11th, we’ll have brief in-class oral reports on exercises 4 and 5 of Cursor. How can we list the browser bookmarks and browsing history separately? How can we get a list of all the databases created by Android, either in the documentation or via executable code? My thanks to the volunteers.

    I understand that what you want me to create from scratch for you in class on April 11th is an app with a GridView displaying two columns in portrait orientation, three columns in landscape orientation. Each item in the GridView should be a LinearLayout whose orientation is vertical in portrait, horizontal in landscape. Each LinearLayout represents an “offer” and will contain two TextViews named title and description. The text in the TextView should come from a table in an SQLite database file. The database file could be stored inside the app as we did in Cursor. But I understand that you would be delighted if the file was downloaded by the app from a server, such as the Solaris Unix server i5.nyu.edu where this course is hosted.

  10. April 11, 2015: Offer is now debugged. It reads correctly from an SQLite offers.db file in the project’s assets folder, and (in exercise #7) it even reads correctly from an SQLite offers.db that the app downloads from a server while the app is running. For an outline of what went wrong, see the paragraph I added on April 15th to my Stack Overflow post.

    As usual, you should play with and read about the stuff we did in class. In Offer, we saw pairs of .xml resource files for -port and -land, so you should read Android’s documentation about Providing Alternative Resources. And in Cursor and Sqlite, we used the adb shell command to examine the directories and files inside the Android emulator or device, and to run sqlite3 inside the emulator or device. Again, as usual, you should write a simple but interesting app and upload it to your GitHub account.

  11. April 18, 2015: in Weather, we downloaded one record, and then seven records, from a database in a remote server that some else had set up for us. The records were written in JSON format, from which we extracted the information we wanted. In Client, we read and wrote individual records from and to an SQL database that we set up ourseleves on a remote server (the Solaris Unix machine i5.nyu.edu). The server consisted of sqlite3 and a little “glue” program written in the language Perl.
  12. April 25, 2015: we did Rocket (multi-threading), Where (accelerometer), MapView, Map, MediaPlayer, and Service. The current state of our research into a Google Maps marker with a title is in exercise #2 of Map.

    Do exercise #2 of MediaPlayer. You’ll be appalled that the visble behavior (or at least the audible behavior) of the app depends on the vagaries of the Java garbage collector! As usual, write and upload a simple but interesting app. A Scratch demo is coming!

  13. May 2, 2015: Class ActionBarActivity has been deprecated. Your class ActivityMain should now extend AppCompatActivity instead of ActionBarActivity. I’m tempted to say that Oceania is now at war with Eurasia, not Eastasia.

    In Android Studio,
    Tools → Android → SDK Manager
    and download all the new stuff it recommends. When you create a new project, the ActionBarActivity in ActivityMain should now be striken through because it is deprecated. Replace it with AppCompatActivity. As usual, write an app (maybe with a Service playing background music this week?) and upload it to GitHub. Thanks.

  14. May 9, 2015: Location.zip that we created in class today. Map.zip no longer puts the pins in South Carolina.

    I was impressed by the succes of our group effort on May 9th, so I’m going to propose another one for May 16th. I acquired a Samsung Galaxy SII phone (model number SPH-D710, Android version 4.0.4, hardware version D710.10, baseband version S:D710.10 S.FL24), with Google Play services so we could run the MapView in MapView. I see the Play Store icon that looks like a briefcase. But when I connect the phone with a USB cable to my OS X Yosemite 10.10.3 Macintosh, the Mac doesn’t notice the phone. For example, adb devices does not list the phone. Neither does the Mac application “System Information” in the Utilities subfolder of the Applications folder. (I selected Hardware → USB and pulled down File → Refresh Information.) What do I have to do to make the Samsung show up in adb devices?

  15. May 16, 2015: