159.336 Assignment 2
Due 22nd September 2023
For this assignment you need to write a simple gallery application for Android to view all the photos that are stored on the device.
The gallery must show a scrollable grid of all photos. When you click on a photo it must open in a separate activity which shows only that photo.
Your app must use a GridView or RecyclerView and an Adapter, the Adapter must load photos using a background thread. Use the MediaStore content provider to get a list of all photos ordered by date added with the most recent first, for each photo you will need the id, orientation, width and height. You must use a target API of at least 30. For API level 33 and above you need to get the READ_MEDIA_IMAGES permission, below this you need READ_EXTERNAL_STORAGE permission. To get an InputStream for a photo use:
is=getContentResolver().openInputStream(Uri.withAppendedPath(MediaStore.Images.Media.
EXTERNAL_CONTENT_URI,id)); // id is a string obtained forom the mediastore _ID column
You can use BitmapFactory.decodeStream with inSampleSize Options to load a low resolution image and ThumbnailUtils.extractThumbnail to create a reasonable size thumbnail. You may need to rotate the thumbnail depending on the MediaStore.Images.Media.ORIENTATION.
To speed up loading you may want to use a cache of thumbnails. You are not allowed to use an image library such as Glide, Fresco, Picasso or Photo Picker (submissions using any of these will get 0 marks) but you can use a memory or disk cache as described here:
https://developer.android.com/topic/performance/graphics/cache-bitmap
The single photo activity view should have a higher resolution than the thumbnail. You can optionally add pinch to zoom to the photo viewer and gallery. Make sure your app behaves correctly when the device is rotated and when photos are added or deleted. Make sure your app works with large images, i.e. up to 12MP.
Submit your assignment on Stream. You must submit a zip file containing a clean source tree. To do this, use “File..Export to Zip File...” in Android Studio. Do not use any libraries other than those included in the latest Android SDK. You will lose marks if you submit a zip which was not created by Android Studio or in any other format (such as rar or 7z). Marks will be deducted for zip files which do not build correctly. Do not change the top level gradle build file. There are some example images on Stream, transfer them to the emulator using the Android Studio device explorer. You will need to do a cold boot for them to appear in MediaStore.
This is an individual assignment, you can not work in groups. Marks will be awarded for well written programs. Use comments in your code to document it. Marks will be subtracted for plagiarism, late submission and bad documentation. This assignment is worth 20% of the total marks for the course. M Johnson 2023