SD2550 Application Development Using Java I Unit 2 DISCUSSION 2.1 (2.5 HOURS) Title: SDK Versions Research the various versions of the Android SDK using the ITT Tech Virtual Library and the Internet. Answer the following questions: What are the benefits of using the latest SDK version during development? Choose a feature of the latest version and briefly describe how it could add functionality to an app. How would you perform graceful degradation for the feature you described? Do you think support for legacy versions while creating an app is necessary? Support your answers using examples that state the advantages and disadvantages of supporting legacy or latest SDK versions. Submission Requirements: Submit a Microsoft Word document with the following specifications: Font: Arial; font size: 12; double-spaced Length: 1–2 pages Citation Style: APA 1 SD2550 Application Development Using Java I Unit 2 LAB 2.1 (3.0 HOURS) Assessment Preparation Checklist: To prepare for this assessment: Read Chapter 3, pages 53–72, and Chapter 4, pages 73–88, from your textbook, Android Programming: The Big Nerd Ranch Guide. Chapter 3 readings will help you understand how an activity transitions between four possible states: running, paused, stopped, and destroyed. Readings from Chapter 4 will help you understand how to use the Eclipse debugging tools to find and resolve errors in your code. Go through this module’s lesson that covers the activity’s life cycle and states and the methods you must override to manage the activity's transition between the states. Title: Managing the Activity Life Cycle In this lab, you will examine and respond to the transitions that occur during an activity's life cycle. You will also create a layout to use when the device is in the landscape mode and add code to save and restore the application state. Required Setup and Resources: You will need a virtual computer with Eclipse and the Android SDK installed to complete this lab. You may choose to work on the GeoQuiz project you created in Module 1 Lab 1. If you do not have a working project, you may use the Lab 2.1 starter project. Recommended Procedures Optional Task: Import the Lab2-1 starter project. You can complete this lab either by continuing to work on your Module 1 Lab 1 project or by importing the Lab2-1 starter project. If you choose to work with the starter project, perform the following steps: 1. Launch ITT-Lab in VMware Player. 2. Copy the Lab2.1starter.zip file to ITT-Lab in VMware Player. 3. Extract Lab2.1 starter project to the Android Workplace folder. 4. Launch Eclipse. 5. Click File > Import. 2 SD2550 Application Development Using Java I Unit 2 6. Expand Android and select Existing Android Code into Workspace. 7. Click Next. 8. Browse to select Lab 2.1 starter. 3 SD2550 Application Development Using Java I Unit 2 9. Verify that QuizActivity is selected. 10. Click Finish. Task 1: Log the activity life cycle. 1. Launch Eclipse. 2. Open the QuizActivity.java file in your GeoQuiz project. 3. Add the following constant declaration to the QuizActivity class: private static final String TAG = "QuizActivity"; 4 SD2550 Application Development Using Java I Unit 2 4. Add the following code to the onCreate() method. Place it immediately after the call to the superclass implementation of onCreate(): Log.d(TAG, "onCreate(Bundle called"); 5. Override the onStart() method to write “onStart called” to the log. 6. Override the onPause() method to write “onPause called” to the log. 7. Override the onResume() method to write “onResume called” to the log. 8. Override the onStop() method to write “onStop called” to the log. 9. Override the onDestroy() method to write “onDestroy called” to the log. 10. Save the file. 11. Click Window > Show View > Other. 12. Expand Android and choose LogCat. 13. Run the project in the emulator and watch the messages displayed in the LogCat window. 14. Unlock the device and wait until the application starts. 15. Look for the log entries with a Tag of QuizActivity. 5 SD2550 Application Development Using Java I Unit 2 Question 1: Which methods are called when the application starts? _________________________________________________________________________ 16. Click the Back icon of the device. Look for the log entries with a Tag of QuizActivity. Question 2: Which methods are called? _________________________________________________________________________ 17. Click Apps. 18. Click nnGeoQuiz. Question 3: Which methods are called? ______________________________________________________________________________ 19. Click the Home icon. Question 4: Which methods are called? ______________________________________________________________________________ 20. Click the Recents icon and launch the application. Answer the following question: Question 5: Which methods are called? ______________________________________________________________________________ 21. Click the Next button in your application. 22. Click Home. 23. Click Recent and launch the application. Answer the following question: Question 6: Was the state preserved? ______________________________________________________________________________ 24. Click Back. 25. Launch the application from Apps and answer the following question: Question 7: Which question is displayed? ______________________________________________________________________________ 26. Click the Next button in your application. 27. Press Ctrl + F12. Answer the following questions: Question 8: Which methods are called? ______________________________________________________________________________ Question 9: Was the state preserved? ______________________________________________________________________________ 6 SD2550 Application Development Using Java I Unit 2 28. Close the emulator. Task 2: Add code to manage device rotation. 1. In Package Explorer, right-click res and choose New > Folder. 2. Name the folder layout-land. 3. Click Finish. 4. Copy activity_quiz.xml to the layout-land folder. 7 SD2550 Application Development Using Java I Unit 2 5. Modify the activity_quiz.xml file in the layout-land folder as follows (Refer to Listing 3.4 on page 64 of your textbook if you need help in tweaking the landscape layout of the activity): Replace the LinearLayout root element with a FrameLayout root element. Set layout_gravity of TextView to center_horizontal. Set layout_gravity of LinearLayout that contains the True and False buttons to center_vertical|center_horizontal. Set layout_gravity of the Next button to bottom|right. Set layout_gravity of the Previous button to bottom|left. TIP: If you added a LinearLayout element around the Previous and Next buttons, you will need to remove it to make this layout work. 6. Save the file. 7. Open QuizActivity.java. 8. Declare a private String constant named KEY_INDEX in the QuizActivity class and set its value to “index.” 9. Override the onSaveInstanceState() method of the QuizActivity class as shown: public void onSaveInstanceState(Bundle savedInstanceState) { super.onSaveInstanceState(savedInstanceState); Log.i(TAG, "onSaveInstanceState"); savedInstanceState.putInt(KEY_INDEX, mCurrentIndex); } 10. Add the following code to the onCreate() method immediately before updateQuestion is called: if(savedInstanceState != null) { mCurrentIndex = savedInstanceState.getInt(KEY_INDEX, 0); } 11. Save your file. 12. Run the application in the emulator and test to verify that the test cases shown in the table work correctly. If they do not, use the debugging features you learned about to troubleshoot the cause of the problem. Test Result Start the application. The first question should be displayed. 8 SD2550 Application Development Using Java I Test Result Click Next. The second question should be displayed. Press Ctrl + F12. The screen should rotate. Unit 2 The second question should be displayed. The screen should use the layout you defined for the landscape view. Click Next. The third question should be displayed. Press Ctrl + F12. The screen should rotate. The third question should be displayed. The screen should use the standard layout. Click the Home icon. The app should disappear. Launch the app from The third question should be displayed. Recent. Use the icon, not the emulator button. Note: The Home and Recent buttons on the emulator are not operational. You may use the icons on the device display instead. 13. Take screenshots of your app displayed in both portrait and landscape modes and paste them in your worksheet. Submission Requirements: Compress your Android project folder and responses in a Word document into one zipped folder and submit it to the instructor. Note: Use the following procedure to compress the web pages into one zipped folder: http://windows.microsoft.com/en-US/windows-vista/Compress-and-uncompress-files-zip-files 9 SD2550 Application Development Using Java I Unit 2 Evaluation Criteria: The Lab rubric will be used to evaluate this assessmenthttp://myportal.itttech.edu/employee/dept/curriculum/CRD/Shared Documents/012 - Approved to Post/2. MAR-14/SD2550 OCM resub/ http:/www.content.distance-education.itttech.edu/cliksdmrroot/content_directory/mount1/507393/ITT_Rubrics/Lab_Rubric.xlsx . Your submission will be evaluated against the following criteria using the grading rubric: Does the code meet all functional requirements? Did you provide all requested screenshots in the worksheet? Did you answer all questions? Is the code is readable and documented? 10 SD2550 Application Development Using Java I Unit 2 LAB 2.2 (3.0 HOURS) Assessment Preparation Checklist: To prepare for this assessment: Read Chapter 5, pages 89–112, and Chapter 6, pages 113–123, from your textbook, Android Programming: The Big Nerd Ranch Guide. Chapter 5 readings will guide you on how to set up a second activity and pass data between different activities. Chapter 6 readings will help you locate information about SDK versioning for your project and understand how to write code to manage graceful degradation for legacy devices. Go through this module’s lesson that covers how to add a second activity to the any app. Title: Adding an Activity and Version Compatibility In this activity, you will add a second activity to the GeoQuiz project. You will also explore version compatibility settings that are used to identify the Android versions supported by your app. Required Setup and Resources: You will need a virtual computer with Eclipse and the Android SDK installed to complete this lab. You can complete this lab either by continuing to work on your Module 2 Lab 1 project or by importing the Lab 2.2 starter project. Recommended Procedures Task 1: Add a layout for the second activity. 1. Launch ITT-Lab in VMware Player. 2. Launch Eclipse. 3. If you are planning to use the starter file, import it. 4. Add the following strings to strings.xml. Name Value cheat_button Cheat! warning_text Are you sure you want to do this? show_answer_button Show the answer. judgment_toast Cheating is wrong. 5. Right-click the layout folder and choose New > Other. 11 SD2550 Application Development Using Java I Unit 2 6. Expand Android and choose Android XML Layout File. 7. Click Next. 12 SD2550 Application Development Using Java I Unit 2 8. Name the file activity_cheat and verify that LinearLayout is selected. 9. Click Finish. 13 SD2550 Application Development Using Java I Unit 2 10. Use the following layout diagram to create the layout in the activity_cheat.xml file: 11. Verify that the layout is displayed correctly in Graphical View. Arrange the workspace windows if necessary to allow it to be displayed in its entirety. Take a screenshot and paste it in your worksheet. Task 2: Add a subclass for the activity. 1. Right-click the package and choose New > Class. 2. Name the class CheatActivity and configure it to inherit from Android.app.Activity. 14 SD2550 Application Development Using Java I Unit 2 3. Click Finish. 4. Override the onCreate() method to set the content view to activity_cheat.xml. 5. Save the file and resolve any errors. 6. Open Android.Manifest.xml. 7. Declare the activity by adding the following markup within the <application> element: <activity android:name=".CheatActivity" android:label="@string/app_name" /> Task 3: Add a Cheat! button to QuizActivity. 1. Add a Cheat! button to the default QuizActivity layout. The result should look like this: 2. Add a Cheat! button to the landscape layout. The result should look like this: 15 SD2550 Application Development Using Java I Unit 2 3. Declare a variable for the Cheat! button. 4. Add a listener for the Cheat! button to the QuizActivity class. 5. Add the following code to the listener you created in the previous step: Intent i = new Intent(QuizActivity.this, CheatActivity.class); startActivity(i); 6. Test the application to make sure the Cheat Activity is displayed when you click the Cheat! button. Take a screenshot of the Cheat Activity and paste it in your worksheet. 7. Click the Back icon to verify that the initial screen is displayed. Task 4: Add code to pass data between the activities. 1. Add a constant declaration named EXTRA_ANSWER_IS_TRUE to CheatActivity.java. Set its value to packagename.answer_is_true. 2. Add the following code immediately before the call to startActivity in the Cheat! button’s listener method: boolean answerIsTrue = mQuestionBank[mCurrentIndex].isTrueQuestion(); i.putExtra(CheatActivity.EXTRA_ANSWER_IS_TRUE, answerIsTrue); 3. Add a private boolean variable named mAnswerIsTrue to the CheatActivity class. 4. Add the following statement to the onCreate() method of the CreateActivity class: mAnswerIsTrue = getIntent().getBooleanExtra(EXTRA_ANSWER_IS_TRUE, false); 5. Modify CheckActivity to show whether the answer is true or false in TextView when the user clicks the Show Answer button. 16 SD2550 Application Development Using Java I Unit 2 6. Test your application. Verify the following test cases. Test Case Result Click Cheat. The Cheat Activity is displayed. Click Show Answer. If the answer to the question is true, True will be displayed. If the answer to the question is false, False will be displayed. Click Back The original activity screen should appear. Click Next. A new question should appear. Click Cheat. The Cheat Activity is displayed. Click Show Answer. If the answer to the question is true, True will be displayed. If the answer to the question is false, False will be displayed. Repeat until you have tested a true answer and a false answer. 7. In the QuizActivity class, change the line that calls startActivity() as follows: startActivityForResult(i, 0); 8. Modify the CheatActivity class as follows (HINT: Refer to Listing 5.14 on page 106 of your textbook if you need help in setting a result): Declare a public constant named EXTRA_ANSWER_SHOWN and set it to equal packagename.answer_shown. Create a method named setAnswerShown Result that uses an intent to set the result to the value passed as a boolean parameter. Modify the onCreate() method to ensure that the result is true only if the user clicks Show Answer. 9. Modify the QuizActivity class as follows (HINT: Refer to Listings 5.15 and 5.16 on page 108 and 109 respectively of your textbook if you need help in handling a result): Declare a private boolean variable named mIsCheater. Override the onActivityResult() method as follows: @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { 17 SD2550 Application Development Using Java I Unit 2 if (data==null) { return; } mIsCheater = data.getBooleanExtra(CheatActivity.EXTRA_ANSWER_SHOWN, false); } Modify the checkAnswer() method to display judgment_toast if mIsCheater is true. If mIsCheater is false, the code should display whether the user chose the correct answer. Modify the onCreate() method to set mIsCheater to false. Modify the handlers for the Next and Previous buttons to set mIsCheater to false. 10. Test your application and verify that the following requirements are met: Statement Value User Cheats User Clicks Result True No True Correct! False No False Correct! True No False Incorrect! False No True Incorrect! True Yes True Cheating is wrong. False Yes False Cheating is wrong. True Yes False Cheating is wrong. False Yes True Cheating is wrong. Task 5: Manage versioning and compatibility. 1. Open the Android.xml file. 2. Record the following information in your worksheet: Minimum SDK version: Target SDK version: 3. Right-click the project and choose Properties. Answer the following question: Question 1: What is the build target for the project? ____________________________________________________________________________ 18 SD2550 Application Development Using Java I Unit 2 4. Modify the QuizActivity onCreate() method to display the state you live in as a subtitle. Refer to Listing 6.2, 6.3, and 6.4 on pages 118 and 119 for help on how to add Action Bar Code, check the device’s build version, or give Android Lint a helpful clue. 5. Test your app in your TestDevice emulator to verify that the subtitle is displayed and answer the following question: Question 2: What would happen if you ran the app on a device running Froyo? ____________________________________________________________________________ 6. Compress your project folder and turn it in along with your worksheet. Submission Requirements: Compress your Android project folder, code documentation and responses in a Word document into one zipped folder and submit it to the instructor. Note: Use the following procedure to compress the web pages into one zipped folder: http://windows.microsoft.com/en-US/windows-vista/Compress-and-uncompress-files-zip-files Evaluation Criteria: The Lab rubric will be used to evaluate this. Your submission will be evaluated against the following criteria using the grading rubric: Does the code meet all functional requirements? Did you provide all requested screenshots in the worksheet? Did you answer all questions? Is the code is readable and documented? RESEARCH 2.1 (3.5 HOURS) Assessment Preparation Checklist: To prepare for this assessment: Read Chapter 6, pages 114–115, from your textbook, Android Programming: The Big Nerd Ranch Guide. These readings focus on the various versions of the Android operating systems and their respective market shares. Go through this module’s lesson that gives an overview of the market share of Android. Title: Android Operating System—Versions and Market Shares 19 SD2550 Application Development Using Java I Unit 2 Research the ITT Tech Virtual Library and the Internet for the current penetration of Android operating system versions in the marketplace. In your research, compare the top three versions of Android operating systems. In your comparison, you should cover the following points: Release date API level Linux Kernel Version Market share Distinct features and drawbacks Submission Requirements: Your response should be two- to three-page long. Each page should include a header containing your name and the date. Name the document SD2550_StudentName_Module2_Research.doc, replacing StudentName with your name. Use Arial 12 point as the font and double-line spacing. Cite all references in APA format. Evaluation Criteria: The Research rubric will be used to evaluate this assessment. 20