Individual Assignment 1

From CS1635 Spring 2016
Jump to: navigation, search

Deadline: by 9:00AM on January 26


Overview

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 (choose API 16, Android 4.1 Jelly Bean, and "Empty Activity", i.e. the second option in the "Add an Activity to Mobile" Tab) in the Android Studio environment, test it in the Android emulator, and debug it within the Android Studio.
  • 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.
  • Additional instructions on using Android Studio can be found here.

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 (you may also choose to use a drop down list) 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 Android Studio, create a new project with File→New→New→Project. From within the new project dialog.

Give the project a name, e.g. "PostageCalculator". Enter "yourpittid.cs1635.cs.pitt.edu" as the company domain. In the next tab, check "Phone and tablet", choose API 16:Android 4.1 (Jelly Bean) as the min 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
  • Company Name: yourpittid.cs1635.cs.pitt.edu


Click "Next" or "Finish", and you should find your project created in the Package Explorer. Explore the project. Under app→res→layout you will see the layout xml file as activity_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 java directory, which will contain a file MainActivity.java under the package node. Look inside. It will contain the definition of the new MainActivity 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 an empty screen. You are off and running. From here you can iterate on your design, gradually adding functionality.

Layout

You can use LinearLayout, AbsoluteLayout, or RelativeLayout containers. The built-in layout editor in Android Studio is a good choice. You may notice that it could be faster to directly edit the layout xml in text format in the layout editor and then check the visual outcome from the preview window, rather than directly drag and drop the widgets to the activity. 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):

http://mips.lrdc.pitt.edu/cs1635-spring16/User:FirstName_LastName

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 apk1-firstname-lastname.zip (e.g., apk1-jingtao-wang.zip)
  • Upload the zip file to the IndividualAssignment1-FirstNameLastName page you just created:
    • Create a new file link like this: [[File:apk1-firstname-lastname.zip]]
    • 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: