Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

CST2335 Lab 6 CST2335 Lab 6 This assignment relates to the following Course Learning Requirements: · CLR 1: Write a graphical user interface-based program, given design documents. Techniques used will...

1 answer below »

        CST2335 Lab 6
CST2335 Lab 6
This assignment relates to the following Course Learning Requirements:
· CLR 1: Write a graphical user interface-based program, given design documents. Techniques used will be object-oriented programming, structured programming, top-down coding, and event-driven coding.
· CLR 4: Debug program problems using manual and programmatic methods.
· CLR 7: Create GUI programs that support internationalization as well as sustainability.
Objective of this Assignment:
The following is an exercise to help you implement what you have learned in this module. It will allow you to familiarize yourself with the module content as well as practice the skills required to develop software in the Android Studio. The specific goal of this lab is to familiarize yourself with writing files, asynchronous tasks, and network connectivity. You will learn how to connect to a web server, download images and save them to the application’s file directory.
Pre-Assignment Instructions:
1. Review the Module 6 content in Brightspace.
Assignment Tasks:
1. Create a new
anch in Git. Start by selecting the “Git” menu in Android Studio and select “Branches”. In the resulting dialog click “New
anch” and call it “lab_6”. This lab will create a slideshow of random cat pictures for an Android TV.
2. Delete any activities created in previous labs and create a new MainActivity starting from an empty activity.
3. Make sure you have an Android TV set up as an Android Virtual Device for testing in addition to the phone emulators used in previous labs.
4. Add the following to your Android manifest to declare it as supporting TVs:
uses-feature android:name="android.hardware.touchscreen" android:required="false"

uses-feature android:name="android.software.leanback" android:required="true"
You will also need to add an intent filter for your main activity in the manifest, i.e.
intent-filte
intent-filte
5. Update the layout for the MainActivity to look like the following
The layout has a black background, an ImageView with height and width set to match parent, and a ProgressBar at the very bottom with the width also set to match parent.
6. Inside values -> themes -> themes.xml, there will be a reference of an ActionBar theme. Update this to say “NoActionBar” so you don’t have the bar across the top of the TV. i.e.
style name="Theme.AndroidLabs" parent="Theme.MaterialComponents.DayNight.DarkActionBar"
ecomes
style name="Theme.AndroidLabs" parent="Theme.MaterialComponents.DayNight.NoActionBar "
7. Create an inner class in MainActivity called CatImages that extends AsyncTask to download the cat pictures. The class will need a Bitmap variable to store the cu
ent cat picture.
8. Inside the doInBackground of the AsyncTask, use an infinite loop ( while(true) { ) to endlessly cycle through cat pictures. You will need to query https:
cataas.com/cat?json=true to get your random cat picture. Use the “id” in the JSON payload to check if an image file with that name already exists on the device. If it does, you’ll want to set the ImageView to use that local cat image. Otherwise use the “url” in the JSON payload to download the image, save it to the device, and update the ImageView with it.
9. After the cat picture has been downloaded, and is in the ImageView, we need to give the user time to appreciate it. We will also update the ProgressBar so the user knows when the next image will come. Here’s a small snippet that can go in your “doInBackground” to call “onProgressUpdate” to update the progress bar. Feel free to adjust to be faste
slower as you wish.
for (int i = 0; i < 100; i++) {
try {
publishProgress(i);
Thread.sleep(30);
} catch (Exception e) {
e.printStackTrace();
}
}
10. Ensure you implement an onProgressUpdate in your AsyncTask. This will need to do two things:
a. Update the progress bar with the cu
ent status of the time
. If a new cat picture has just been selected, update the ImageView with the new picture.
Hints
· You will not be able to update the ImageView or the progress bar directly from within your doInBackground() method! This method does not run on the UI thread so it can’t make UI updates. Make sure you do updates in a separate method that does run on the UI thread such as onProgressUpdate.
· Make use BitmapFactory to get the Bitmap that you can use for the ImageView. It can either load a file path directory, or an InputStream like the one you get from the URLConnection object in Java.
Here’s a full recording of how the app should function:
Ru
ic
    Criteria
    Points
    The app compiles and runs without crashing
    2
    Cat picture is downloaded and displayed in the ImageView
    3
    The app runs in a loop constantly showing new pictures
    2
    Progress bar on the bottom shows how long is remaining on the cu
ent image
    1
    If the image already exists locally, that will be used instead of downloading the image again.
    2
    Total
    10
Answered 2 days After Feb 20, 2022

Solution

Manikandan answered on Feb 22 2022
106 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Submit New Assignment

Copy and Paste Your Assignment Here