Individual Assignment 1

From CS1635 Spring 2014
Jump to: navigation, search

Deadline: by 9:00AM on January 21



This warm-up exercise is designed to let you become familiar with the basic workflow and tools for creating an android application. You are expected to practice the following skills in the assignment

  • Create a new android project in the Eclipse environment, test it in the Android emulator, and debug it within the Eclipse IDE.
  • Be familiar with using the user interface descriptive xml and related tools to design simple interfaces.
  • Understand the idea of nested linear layouts and use them to control the look and feel of your application in different screen resolutions.
  • Be familiar with how to change the properties of UI widgets in your Java program. Also be familiar with how to listen for UI events of interest and respond to those events.

You will build a USPS First Class Postage Calculator .

Imagine that you have prepared a birthday gift for a family member, and you'd like to send it via USPS first class mail. You will use the postage calculator you are creating to estimate the actual postage of your gift. Detailed rate information about USPS first class mail can be found from this URL.

You will submit your source code, the executable, and at least one screenshot. It is your responsibility to ensure that the executable has all the resources it needs to execute.

Basic Requirements

  1. Your program needs to accept two types of input, i.e. package type and weight. For the package type, your program needs to support letters, large envelopes and packages (you may ignore the postcard type).
    1. One simple solution is to use a radio box to select package type and use one text field to accept package weight.
  2. Your program needs to handle invalid input and provide proper error messages.
    1. For example, the weight of your package cannot be over 13 oz, the weight of your package cannot be zero or a negative value, and the weight of your package cannot be a non-decimal value.
  3. Provide some textual hints (check the android:hint tag in the UI xml) when the text field is empty. (e.g. valid range: 0 - 13 oz)
  4. You should put text that is used in the widget and static text shown on screen in a separate string resource file, you shouldn't hard code this text in your UI xml file (e.g. main.xml) or in your Java program.
  5. Provide a "Calculate" button to trigger the actual calculation. The "Calculate" button should be disabled if the input is not complete (e.g. the user hasn't entered the package weight yet.
  6. Provide an icon for your application (you can create it in PowerPoint and resize it properly. It doesn't need to be extremely attractive)

Extra Credit

Students will receive up to 10% extra credit for completing the following two features

  1. Provide a second tab, which displays "rules and restrictions" for each package type (e.g. the size limitation of each package type, similar to the contents in the "Rules & Restrictions" tab on USPS. This second tab can include images, but you should avoid horizontal scrolling.
  2. Make sure that your program can handle both the portrait mode and the landscape mode. User input must not be lost when the screen orientation changes.

Grading Criteria

Full credit (20 points) will be given if your application compiles, runs, and contains the functionality as detailed in the instructions.

Up to 5 extra points will be given if you implement additions that make the application more usable or more aesthetically pleasing. (e.g. implementing the extra credits mentioned above)

QuickStart Guide

Creating a new Project

In Eclipse, create a new project with File→New→Project. From within the new project dialog, select Android→Android Project.

Give the project a name, e.g. "PostageCalculator". Check the Android 2.2 SDK version (don't select the Google APIs for now). Scroll down to find the properties for this project. Some suitable options here are:

  • Application Name: Postage Calculator
  • Package Name: edu.pitt.cs1635.yourpittid.prog1
  • Create Activity: PostageCalculator

Click "Next" or "Finish", and you should find your project created in the Package Explorer. Explore the project. Under res→layout you will see the layout xml file as main.xml. This file defines the widgets in the UI. You typically edit this file first to create the widgets you need, and then add code to interact with them in the src directory. Navigate up to the src directory, which will contain a file under the package node. Look inside. It will contain the definition of the new PostageCalculator class with a single "onCreate" method which loads the layout file.

Building and Running

Try building the project with Project→Build Project. Assuming that worked, you can run the project in the emulator. Be patient; it may take some time to initialize the emulator and install your application. You should see a screen that says "Hello World, TipCalculator!". You are off and running. From here you can iterate on your design, gradually adding functionality.


You can use LinearLayout, AbsoluteLayout, or RelativeLayout containers. Droiddraw is a third-part utility that can help you generate layout files. If you use Droiddraw, it will give you an absolutelayout with pixel coordinates for all the widgets. RelativeLayout is the most general, but may be a little more work to get what you want. If you use LinearLayout, you may want to insert some empty FrameLayout objects between your widgets to add extra space. Setting the FrameLayout's height to zero, and using the layout_weight property instead produces the effect of elastic spacing between the widgets.

Some interesting links on layouts, and the options you have with them are:

You can breeze through this assignment even with Linear Layouts, but we recommend that you experiment with various layout schemes once you are done with the basic code. The earlier you do this in the semester, the closer you inch to success in the final project.

Event Listeners

You will want to use several kinds of listeners on your widgets. OnClickListener's are the right option for buttons, RadioButtons have a special listener called OnCheckedChangeListener, and the OnEditorActionListener will allow you to respond to "enter" events on editable text boxes.

There are a total of five different ways to wire up an event listener (below). Please read Five Ways to Wire Up an Event Listener for details, (protected material, By Daniel Fowler, from Chapter 1 of Android Cookbook, OReilly Press)

  • Member Class
  • Interface Type
  • Anonymous Inner Class
  • Implementation in Activity
  • Attribute in View Layout for OnClick Events

Submission Instructions

Create a Wiki Page for this assignment

Begin by creating a new wiki page for this assignment. Go to your user page that you created when you made your account. You can get to it by typing the following URL into your browser (or click your user name located at the top right corner of this wiki after you log in):

Replace FirstName and LastName with your real first and last names. This will take you to the page you created for yourself when you created your wiki account. If you have trouble accessing this page, please check that you created your wiki account properly.

Edit your user page to add a link to a new wiki page for this assignment. The wiki syntax should look like this:

[[IndivisualAssignment1-FirstName_LastName|Individual Assignment 1]]

Again replace FirstName and LastName with your name. Look at my user page for an example. Then click on the link and enter the information about your assignment. You should upload one file (described below) and in the wiki page, describe any extra credit functionality you implemented and want us to review.

Upload Project

  • Your submitted project must include both the full source code as well as the executable of the working application.
  • Create a zip file of your project tree (the top-level folder that includes the Eclipse project. Rename the zip file to (e.g.,
  • Upload the zip file to the IndividualAssignment1-FirstNameLastName page you just created:
    • Create a new file link like this: [[]]
    • Save the page, then click on the File link you just created to upload the zip file.

Add Link to Your Finished Assignment

One you are finished editing the page, add a link to it at the bottom of the page with your full name as the link text. The wiki syntax will look like this: *[[IndividualAssignment1-FirstName_LastName|FirstName LastName]]. Hit the edit button for the last section to see how I created the link for my name.

Links to Finished Assignments

Add your submission below this line: