COMP3018 Coursework 1- Exercise 1: Fingerpainter Summary In this exercise you are required to build an Android painting application. This is an assessed exercise and will account for 15% of your final module mark. This is an individual coursework, and your submission must be entirely your own work – please pay particular attention to the section of this document regarding plagiarism. This document sets out the requirements of and broad instructions for developing the application. Your application should be submitted no later than: • 3pm on the 6th of November 2020 Submissions should be made electronically via Moodle. Standard penalties of 5% per working day will be applied to late submissions. Your application should be submitted as a .zip or .tar.gz file containing all relevant source code, configuration and related files, and a compiled .apk file – i.e. the contents of the directory containing your Android Studio project after a clean rebuild. Do not submit RAR files. Specification You should create an application to support a simple drawing / painting task, where the user can draw onto a canvas using their finger in a variety of colours and with brushes of different sizes and shapes. The user should either begin with a blank canvas or be able to navigate from an existing image in the device’s Downloads folder that will be loaded by the application. Your application must consist of three Activity components: • An Activity presenting the FingerPainter interface for the user to draw onto • An Activity allowing the user to select the colour with which to draw • An Activity allowing the user to select the shape and size of the drawing brush Furthermore, the application should: • Integrate with other applications to allow the user to draw on existing images as part of the drawing task • Support appropriate lifecycle persistence of Activity UI state A custom painting View is provided that must form the basis of the application. It is left up to you to decide how best to design and implement layouts and other views within these activities. Your application must be written in Java or Kotlin and make use of the Android SDK. There are no requirements to target a specific Android API version, however you can assume that your application will be tested on an emulated device running Android API version 29 (Android 10.0). The compatibility of the UI to portrait/landscape modes and different device resolutions is also part of the assessment criteria. For instance, it is not a good practice if some of the UI components overlap or fall outside the view when the phone is rotated, or the application is running in a device with a different screen resolution. You should consider the following when implementing your application: • Decomposition of the task into discrete Activity components • Appropriate use of Intents, communication between Activities and appreciation of the Activity life-cycle • Appropriate use of Widgets and ViewGroups for layouts that support devices of differing screen sizes and resolutions • Appropriate architectural best practice • Your application is expected to have appropriate comments and variable / class names, so that a reader can easily understand how it works if necessary Assessment Criteria As this is a constrained exercise marks are awarded for achieving specific functionality as follows. For these elements either 0 or full marks are awarded as appropriate. Additional marks are awarded for consideration of good practice. There are no additional marks available for additional functionality in this exercise: Marks Basic Functionality The application has an Activity that allows the user to paint onto a blank canvas 2 The main Activity allows the user to draw with different colours and brush sizes and shapes 1 A second Activity allows the user to select one of at least 5 colours 1 A third Activity allows the user to select the shape and size of the brush 1 The currently chosen colour is passed to and displayed by the colour choosing Activity 1 The current shape and size of the brush are passed to and displayed by the brush choosing Activity 1 The painting Activity maintains colour and brush state throughout its expected lifecycle (e.g. when phone is rotated or when another application is in use, i.e. receiving a phone call) 1 The application can be opened from and displays an image saved elsewhere on the device for painting 1 Best Practice The application demonstrates good architectural design and device portability 6 Total 15 Plagiarism N.B. Use of third party assets (tutorials, images, example code, libraries etc.) MUST be credited and referenced, and you MUST be able to demonstrate that they are available under a license that allows their reuse. Making significant use of tutorial code while referencing it is poor academic practice, and will result in a lower mark that reflects the significance of your own original contribution. Copying code from other students, from previous students, from any other source, or soliciting code from online sources and submitting it as your own is plagiarism and will be penalized as such. FAILING TO ATTRIBUTE a source will result in a mark of zero – and can potentially result in failure of coursework, module or degree. All submissions are checked using both plagiarism detection software and manually for signs of cheating. If you have any doubts, then please ask. Instructions Finger Painting Begin by creating a new application in Android Studio as usual. Add the custom view FingerPainterView to your app project. This class is available on Moodle or at the URL below: https://github.com/mdf/comp3018/blob/main/FingerPainterView/FingerPainterView.java You can either copy the file directly into your project’s source directory (projectname/app/src/main/java/…) or create a new FingerPainterView Java class in your project and copy / paste the code into it, updating the package qualifier accordingly. Add an instance of the FingerPainterView to the layout of your main activity. You can do this either statically through its XML layout resource (Container->view->FingerPainterView or search for FingerPainterView): Or add it to an appropriate ViewGroup programmatically when the activity is created: FingerPainterView myFingerPainterView = new FingerPainterView(this); myFingerPainterView.setId(R.id.myFingerPainterViewId); myFrameLayout.addView(myFingerPainterView); Note in either case the FingerPainterView must have an ID, otherwise the view will not receive the cascaded save state calls (if a view does not have an ID the OS doesn’t know where it should restore the view to on restore). If adding the FingerPainterView programmatically (that is, not via the XML layout but at run- time) you will need to create a static ID resource in res/values/strings.xml and assign it to the view on creation, otherwise the view will not receive cascaded save state calls correctly:
FingerPainter If adding the FingerPainterView via the XML layout you must also remember to specify an ID to the view as using the attributes panel. You should retrieve and maintain a reference to this View in the same way as the other views in lab exercise one (findViewById(…) if you’re instantiating it via the layout resource). You may find it useful to nest the FingerPainterView inside a FrameLayout as in the code above, with its width and height matching that of the parent FrameLayout. FingerPainterView FingerPainterView should automatically create a square paintable canvas that fills the view space that it is given, and responds to touch (“mouse”) events by drawing lines onto its internal bitmap. This bitmap is automatically persisted to a cache file. The class has a few public set / get methods for managing the colour and shape of the brush: public void setColour(int colour) …sets the colour of the brush, where colour is of the form 0xAARRGGBB for setting alpha, red, green and blue values respectively. Alpha should always be 255, i.e. 0xFF. For example, to set the drawing colour to green: myFingerPainterView.setColour(0xFF00FF00); Or: import android.graphics.Color; myFingerPainterView.setColour(Color.GREEN); myFingerPainterView.setColour(Color.parseColor("#FF00FF00")); To set the shape of the brush: public void setBrush(Paint.Cap brush) Where brush is either round or square, defined by the Paint.Cap enum: import android.graphics.Paint; Paint.Cap.ROUND Paint.Cap.SQUARE To set the width of the brush: public void setBrushWidth(int width) Where width is an integer value in pixels. The equivalent get methods allow you to retrieve the current state of these values. They are not persisted by the view between instances. The Task Create two new activities to allow the user to specify the colour, and size and shape of the brush respectively. Open Image Finger Painter Select Colour Select Brush Each of these activities should be passed the current colour and brush size / shape respectively – i.e. the colour selection activity should know and display that the user is currently is painting in red. It is left up to you to create appropriate interfaces to allow the user to select a colour and brush (they need to input either a SQUARE or ROUND brush, and a width in pixels) and return these values to the main activity. Persistence FingerPainterView takes care of persisting its own internal bitmap state if it happens to be destroyed – it saves the current picture to a cache file – however the state of other components, for example the current colour and brush selection are not persisted. You should handle the activity lifecycle for your activities to ensure a coherent user experience if, for example, the device is rotated. Implicit Intent Finally, as in the task diagram above, the user should be able to select an image in another application and choose to open it with your FingerPainter app. To support this our application should respond to implicit Intents that conform to something that we can open – in particular the user attempting to view a file that happens to be an image. Note that you can load files onto the emulator by downloading via the in-emulator web browser, pushing files onto the sd card via the Device File Explorer (View->Tool Windows- >Device File Explorer), or on the command line using adb. Downloaded files are stored in /sdcard/Download/ on the device. zahn:platform-tools pszmdf$ ./adb push cats.jpg /sdcard/Download/cats.jpg cats.jpg: 1 file pushed. 21.6 MB/s (251024 bytes in 0.011s) zahn:platform-tools pszmdf$ The aim here is to, when browsing through their files using the Files application, give the user the option of opening a file in our FingerPainter as opposed to other applications, such as the Picture Viewer. We should do this by registering our application as being able to receive the appropriate intents. Add a second intent-filter to the main activity in the AndroidManifest – so that the application can either be started via the launcher or by an intent sent by another application. This filter should accept intents with an action of android.intent.action.VIEW, category of android.intent.category.DEFAULT, and data of mimeType image/*
android:mimeType="image/*" /> The location of the image to load will be delivered to the main activity via its intent, with the URI of the image being included in the data field of the intent. FingerPainterView will attempt to load an image by URI when called from the onCreate method: myFingerPainter.load(getIntent().getData()); If successful, you can test this by opening an image from the Downloads or Files apps on the device, which should give you the option of your app to open the image with, as well as other installed applications. Notes You can edit FingerPainterView.java as you see fit. FingerPainterView has inherent limitations regarding how it supports resizing. You do not need to fix these. Your application will be tested by pushing the apk contained within your submission onto a device and running it, and as such you should ensure that a) there is an apk included and b) that it works as intended when deployed and run as such. References http://developer.android.com/guide/components/intents-filters.html http://developer.android.com/reference/android/graphics/Color.html http://developer.android.com/reference/android/graphics/Paint.html
欢迎咨询51作业君