This lab will require students to complete an Android flashcard application. The Android app will require the Flashcard information to be represented in a .txt file where the appropriate information gets read / parsed into the app and allows the user to answer them. At the end of answering all questions, the app provides general statistics based on the questions answered, including percentage correct and time statistics.
Unfortunately for ICS 45J, the focus is on Java programming and not Android-‐specifics. Therefore, I will provide a template of the application (and all of the necessary .java and asset files) for you. I
don’t expect students to know the android-‐specific related code, but for those who are interested in android development, feel free to peruse through it and piece it together. J
Setting up the Android Development Environment
I will provide a list of steps to install Android in your current development environment (i.e. JDK 8 with Eclipse). The main concern I have (which I talked about in class) is compatibility issues – I can only imagine the various operating system versions, hardware, configuration, etc. the class has on their personal computers. Please setup up your environment EARLY so we can try and help you if you run into any problems. There is not much we can do if you have installation issues a couple of days before the lab is due, and I would like to know of any issues students have earlier rather than
later.
The following instructions are for getting Android setup for Windows and Mac operating systems:
Installing Android Development Tools (ADT)
-‐ In Eclipse, go to “Help” -‐> “Install New Software”.
-‐ In the “Work with:” bar, enter https://dl-‐ssl.google.com/android/eclipse .
-‐ Click Add (give it a name (if you want) in order to help you remember what this is for.
-‐ Check “Developer Tools”, agree to the terms, and install.
-‐ Restart Eclipse and install the new Android SDK (latest available version). o For the target location, put it anywhere (I prefer my home folder for Mac or C:\ for
Windows). o Continue installation, accept license. o Continue installing any necessary dependent packages.
-‐ Once done, an Android SDK Manager should be available to you in Eclipse. Go to “Window”-‐>
“Android SDK Manager”.
-‐ Select Android 6.0 and Tools -‐> Android SDK Build-‐tools (all).
-‐ Click install packages and accept Android SDK License.
-‐ … wait a while … make a sandwich …
-‐ When everything is done, you should be able to use the Android Library in all its glory!
To run the application, you can either use your own device or an emulator. Since everyone in the class may not have an actual device, I’ll step through the process of installing the emulator.
Installing Intel’s Hardware Acceleration Manager (HAXM)
-‐ Go to “Window” -‐> “Android SDK Manager”.
-‐ Install Extras / Intel x86 Emulator Accelerator (HAXM Installer)
-‐ You will probably have to find the HAXM Installer and execute it.
o On my Windows, the installer was located in:
C:\extras\intel\Hardware_Accelerated_Execution_Manager\ o On my Mac, the installer was located in:
[home]/android-‐sdks/extras/intel/Hardware_Accelerated_Execution_Manager/ o In any case, you can search your File System for “haxm” to find where the installer is located.
-‐ See: http://stackoverflow.com/questions/1554099/why-‐is-‐the-‐android-‐emulator-‐so-‐slow-‐ how-‐can-‐we-‐speed-‐up-‐the-‐android-‐emulator and/or
-‐ http://stackoverflow.com/questions/29136173/emulator-‐error-‐x86-‐emulation-‐currently-‐ requires-‐hardware-‐acceleration for additional details and possible troubleshooting steps you can take if problems are encountered.
Creating a Virtual Device
At this point, you should be able to configure a virtual device to run your android applications.
-‐ Restart Eclipse, go to “Window” -‐> “Android Virtual Device Manager”.
-‐ Click “Create”.
-‐ Select the following when configuring your device: o AVD Name is required (you can provide any) o Device: Nexus 7 (you can experiment with different devices...) o Target: Android 6.0 API Level 23 o Skin selection is required (you can select no skin) o CPU/ABI Intel Atom x86 o Memory Options: RAM: 1024 o Internal Storage: 200 MiB
Quickly Test Things Out
-‐ In Eclipse, Go to “File” -‐> “New” -‐> “Project” -‐> “Android Application Project”.
-‐ Create an application named “HelloWorld”.
-‐ Continue with the default settings and select finish.
-‐ Right-‐click the Project in the package explorer, select “Run As” -‐> “Android Application”.
-‐ You should see the emulator run the “HelloWorld” Android Application.
Importing and Working with the Android App for this Lab.
-‐ Create a new Android Application Project (“File” -‐> “New” -‐> “Project” -‐> “Android
Application Project”).
-‐ Create an application named “Lab4”.
-‐ Unselect “Create Custom Launcher Icon” and “Create Activity”. Click Finish.
-‐ Download Lab4.zip from: http://www.ics.uci.edu/~rkwang/Fall_2015_ICS45J/LabManual/Lab4/Lab4.zip
-‐ Unzip the file and copy the contents into your Project directory in your workspace (in your
File System).
-‐ Replace all existing files with the files in Lab4.zip. o Note: You may get an error about project compliance settings. Allow eclipse to fix the problem for you and change the project compliance to 1.7. o You can manually change / check your compliance level by right-‐clicking the project in the package explorer, select “Build Path” -‐> “Configure Build Path” -‐> “Java
Compiler” -‐> “Compiler Compliance Level”. o Set your Compiler Compliance Level to 1.7.
-‐ The project will not run in the current state. I expect students to fill in the methods and classes in: o FlashcardManager.java o Card.java o MultipleChoiceAnswer.java o ShortAnswer.java o TruthAnswer.java
-‐ When you think your implementation is complete and want to run the application o Right-‐click the Project in the package explorer, select “Run As”-‐>”Android
Application” o Your Virtual Device should load and the android application should appear.
Overview
Your job is to complete the unimplemented components in the Application. There are three types of questions this application will support: True/False, Short Answer, and Multiple Choice questions.
The breakdown of the different components you are responsible for completing are:
-‐ cards.txt o Each line in this input file represents a card that your application will use.
Depending on the type of question, the following is a breakdown for the possible formats:
§ [question];[difficulty];[question type];[answer type];[answer];[case sensitive flag (if applicable)] o question – the question to be displayed to the user.
o difficulty – the difficulty of the question from 1 – 3 (you may assume all questions have a difficulty of 1).
o question type – the subject of the question (can be anything such as “Inheritance”,
“Casting”, “File IO”, etc.) o answer type
§ If the type of answer to the question is True / False, then this field will be
“TF”.
§ If the type of answer to the question is Short Answer, then this field will be
“SA”.
§ If the type of answer to the question is Multiple Choice, then this field will o answer be “MC”.
§ The answer to a TF question will either be “true” or “false”
§ The answer to a SA question will be a String representing the answer
§ The answer to a MC question will be a list of choices presented to the user, where each choice is separated by a comma (‘,’). The first option presented in this list is always the correct answer.
o case sensitive flag
§ This only applies to SA questions.
§ If the answer should be case sensitive, the flag is set to “true”.
§ If the answer shouldn’t be case sensitive, the flag is set to “false”.
o You may assume that the cards.txt file is always in the correct format and do not need to provide error checking.
-‐ FlashcardManager.java o This class is responsible for reading and creating flashcards in your app. For this lab, there are two ways cards can be created:
§ Reading a “cards.txt” file within your project (located in your “assets” folder).
§ Reading a “cards.txt” file from the web.
• This can be done by starting the app, clicking on “Options”, and entering the Uniform Resource Locator (URL) of cards.txt. I am providing a sample here: http://www.ics.uci.edu/~rkwang/cards.txt
§ In both methods, an ArrayList<Card> is returned with the constructed cards created from each line in cards.txt.
-‐ Cards.java o This class represents a flashcard that your application will present to the user. o All cards consist of a String representing the actual question and a question type (i.e. the subject of the question such as "Inheritance", "Exceptions", "Loops", etc). o Each card has an Answer object associated with it and a difficulty level (between 1 -‐
3) that is defined in the cards.txt file. For this lab, you can assume all Cards have a difficulty level of 1. o The cardFactory(String[] args) is responsible for taking a String array with individual components of the card read from cards.txt and constructs an appropriate Card object.
-‐ Answer.java o This file is an Interface that all types of Answers will implement. The methods in the
Interface are:
§ boolean equals(Answer answer) – Takes in an answer object and returns true if answer has the correct answer, returns false otherwise.
§ boolean checkAnswer(String answer) – Checks the String answer and returns true if the answer is the correct answer, returns false otherwise.
§ String toString() – Returns a String representing the correct answer.
-‐ MultipleChoiceAnswer.java o Implements the Interface Answer. o Represents a multiple choice answer for a Card. o The fields for this class are the String representing the correct answer and a String array representing all the answers presented to the user. o You can assume that the first item in this String array will always be the correct answer.
-‐ ShortAnswer.java o Implements the Interface Answer. o Represents a short answer for a Card. o The fields for this class are the String representing the correct answer and a boolean flag representing if the answer is case-‐sensitive or not. If it is case-‐sensitive then the flag is true, otherwise the flag is false.
-‐ TruthAnswer.java o Implements the Interface Answer. o Represents a True/False answer for a Card. o The fields for this class is a boolean value representing the correct answer.
Once you’re done implementing the application, you can create your own flashcards by replacing the
questions in cards.txt. I’ll be happy if students can use this and helps in studying for finals J .