CS 185C/286 - Lecture 6

Cay S. Horstmann
Lecture 6 Quiz 1
Put your answer into Piazza.
Android 3.0 adds the ability for you to define the on-click behavior for a menu item in XML, using the android:onClick
attribute. The value for the attribute must be the name of a method defined by the activity using the menu. The method must be public and accept a single MenuItem
parameter—when the system calls this method, it passes the menu item selected.
Is this a good idea?
- Yes—then one can just add
android:onClick=onOptionsItemSelected
to each menu item without having to install any listeners.
- Yes—then one can install different listeners for each item without having to have a
switch
statement in the listener.
- No—then one needs to have a different listener for each item.
- No—then one doesn't separate UI layout from behavior.
Lecture 6 Quiz 2
Which of the following “useful methods” are actually useful (i.e. can't be done with the normal java.io.File
API)?
getDir
deleteFile
fileList
- None of them
Today's Lecture/Lab
- The Cinequest Client
- Testing
Cinequest

- San Jose Film Festival
- Every year in the spring in downtown San Jose
- This year: February 26 - March 10, 2013
- Mobile apps developed by SJSU CS Department
- Fall 2008 Blackberry, Fall 2010 Android/iPhone
App Functionality
- List of films and events
- Search by title or show time
- Can make personalized schedule
- Works offline
Android-Specific UI
- Mostly lists
FilmDetail
shows detailed description, director, etc., image(s), show times
- Login
- Save/restore schedule
- Wait dialog
Plain Old Java Code
- Entities (film, schedule, program item, ...)
- XML parsers for these items
- HTML subset → Rich text parser
- Character conversion utilities (HTML entities, Win 1252 code page)
- Composable actions with progress reports
- Simple LRU cache
Platform Abstraction
- Common
Platform
interface for Blackberry (obsolete), Android, Java SE
- Done pre-Android to improve testing
- Anything that's different is abstracted out
- Web connections, XML parsing, logging, sorting (!), serialization
- Should be simplified with the demise of Blackberry
Unit Tests
- Run in Java SE, not on the device
- Covers everything other than the UI
- Uses
JavaSEPlatform
implementation of Platform
interface
- JUnit 4
- Some tests need to be updated every year because the server doesn't keep old data
- More tests wanted
- UI testing wanted
Server Part
- Written in PHP by Lou Bash from Cinequest
- Restful API (before it was fashionable ☺)
- Queries/updates MySQL database
- Query results in XML
- Updates simple HTML POST
- Uses Win 1252 encoding ☹
- Documented here
Reading Before Next Class

- Film, FilmParser, FilmParserTest
- Server Protocol up to (but not including) User Schedules. Also check out the relevant sample queries at the end.
Lab

- Bring your laptop to the lab
- You will work with a buddy
- One of you writes code, the other types up answers
- Switch roles each lab
- Submit lab work to git
Checking Out and Running the App
- Scribe: Inside your
workspace
directory, make a directory lab06
for the report.
- Driver: Outside your
workspace
directory, make a directory lab06
.
- In that directory, run
git clone https://github.com/cayhorstmann/cinequest.git
- Follow these instructions to build the project.
- Target Android 2.2. How did you do that?
- Run the app. What happens?
- What's the first film of March 1?
Running a Test
- Run the
HParserTest
as a unit test. Which unit tests failed?
- That's a problem with these tests. The IDs change from one year to the next. Change the item ID to 1815. Why 1815? I ran this query and spotted ID 1815.
- Now what happens?
Making a Change
- Look at the
ProgramItem
class. Where did you find it?
- Note that it uses a
Vector
to collect the films. (Most program items have one film, but something like “Collected Shorts” has several.) Nowadays, one would use an ArrayList<Film>
, but on the Blackberry there was no ArrayList
. We no longer care about that, so let's make the change. Change Vector
to ArrayList<Film>
and fix any errors in the ProgramItem
class that resulted.
- In the previous step, you changed the public interface of the
ProgramItem
class. To find out who called the getFilms
method (which you changed to return an ArrayList<Film>
), right-click and select References → Workspace. Who called it?
- Fix up all callers. What changes did you make?
- Your program should compile now. What happens when you run
ProgramItemParserTest
?
- Ok, that didn't work. It was an old test. How do you fix the test?
- Nice, but that never tested the
getFilms
method. How can you test it?
Making a Patch