CIS 542 - Spring 2012

Lab Assignment #5

March 15, 2012

Due: March 22, 4:30pm

In this assignment, you will check that your Android development environment is correctly set up and then build a simple application that handles button clicks. Once you've done that, you will build a more complex application that implements a typing game.

As always, you may work with one other person on this assignment, but you each must turn in your own homework submission.

Before you begin
This assignment assumes you have correctly set up your Android development environment. Follow the simple set-up tutorial to make sure you can create the "Hello, Android" application before proceeding.

A word about debugging in Android
When you're debugging your Android app, you'll probably be tempted to use trusty ol' System.out.println; it got you this far, right? But you'll notice immediately that the messages you print don't appear in the Android app, nor in the Eclipse console.

Android uses a logging mechanism called LogCat, in which messages are written to a file, along with the time they were written, any associated tags, etc. Instead of System.out.println(message), use Log.v(tag, message), where tag is some meaningful indicator that you can use if you need to filter the log file.

To see the messages that get written to LogCat, go to Window --> Show View --> Other... --> Android --> LogCat in Eclipse, and you'll see it appear at the bottom of the Eclipse window.

For more info, check out the Debugging section of the Android developers guide.

Part 1 (10 points)
In this exercise, you will create an app that shows a button and keeps track of the number of times it is clicked. It is expected that you will finish this during the lab session!

First, create a new Android project called ButtonClicks. Set the Java package to "edu.upenn.cis542".

Then, modify res/layout/main.xml so that the app displays two TextViews (one next to the other) and a Button beneath them. See "XML Layouts" in the developer guide if you need help.

Set the text of the leftmost TextView to "Clicks:". Initialize the other to "0". You can do this right in the main.xml file, or use strings.xml to hold the string constants.

Set the "android:onClick" attribute for the Button to "onButtonClick" in main.xml.

In your Activity class, implement the onButtonClick method so that every time the user clicks the button, the value in the second TextView should increase: "1", then "2", and so on. In order to do this, you must use the Activity's findViewById method to get the appropriate TextView obejct, and then call its setText method to update the text that appears. Note that the setText method expects a String (well, you can pass it an int, but it won't work the way you expect!).

See "Input Events" in the developer guide if you need help.


Part 2 (40 points)
Once you've finished Part 1, you will build a typing game that records how fast a user is able to type a sentence. The application is described here. Make sure you've done Part 1 before attempting to do this part!

Just for fun....
If you develop an Android app in Eclipse and want to install it on an actual device, you can avoid all the messiness of using drivers and cables and just email it to yourself.

In the Eclipse workspace (on disk), you'll find a directory for your project, and in the "bin" directory you will find a file with the extension .apk. If you just email it to yourself, and then check your email from your Android device, you can install it directly. Android will complain that you shouldn't go installing apps that don't come from Android Marketplace, but if you trust yourself, you can go ahead and install it anyway.

If Android complains about your app being of a higher version than your device, I think you can modify the minSdkVersion setting in AndroidManifest.xml and set it to a lower version number.

Academic Honesty
As in the previous lab assignments, you may work with one other student on this assignment (even when you are outside the lab). However, you may not discuss or share solutions with any other students, nor should you be receiving any help from outside sources, including students not taking this course or online resources. If you run into problems, please ask a member of the teaching staff for help. Failure to abide by the academic honesty guidelines will result in a grade of 0 for this assignment.

This assignment is due at 4:30pm on Thursday, March 22. After that, late submissions will be subject to a 10% per day deduction.

All students, regardless of whether they are working alone or with someone else, must submit their solutions individually via Blackboard.

For this particular assignment, please follow these specific instructions:

Failure to properly follow the submission instructions could result in a delay of grading your assignment and/or a lateness penalty, so please be sure to do it correctly!

Updated: Thu Mar 8, 4:39pm