In this programming assignment, you should create an application that allows the user to draw pictures, and share pictures with people from their contacts, via email. You can name the application “Sketcher”. When application begins, the user should be presented with a simple drawing user interface. The user interface should allow the user to select their color, and stroke width, and draw on a canvas below. After drawing a picture, the user should be able to either clear the canvas, or share the picture with someone from their contact list. Take a close look at the animation, demonstrating how the application should work. Take note of a few things in particular:
You are required to use the contacts content provider to display the list of contacts, and to get the email address for a given content in order to setup the intent to send an email. In order to iterate through all of the contacts on an android device, you’ll have to do something along the lines of this:
Cursor cursor = containerActivity.getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (cursor.moveToNext()) {
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
// Do something with the contactId and the name
}
cursor.close();
If you have a particular contact that you want to get an email address for, you can do something like this to get it:
Cursor emails = getActivity().getContentResolver().query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI, null,
ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = " + contactId, null, null);
if (emails.moveToNext()) {
String email = emails.getString(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.ADDRESS));
// Do something with the email address
}
emails.close();
Note that you’ll also have to (A) add the appropriate permission to the manifest file, and (B) go into the settings on the device or emulator, and specifically enable contact permissions for the Sketcher application.
In a previous assignment (CollageCreator), you were tasked with creating an intent to share an image. In this assignment, you are tasked with doing something similar, however, there are some differences:
These two features require setting up an intent in a particular way.
In order to share in image at the path "/A/B/C.png"
to the email "abc@gmail.com"
, you can use the following intent setup:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("vnd.android.cursor.dir/email");
intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "abc@gmail.com" });
Uri uri = FileProvider.getUriForFile(getActivity(),
BuildConfig.APPLICATION_ID + ".provider", new File("/A/B/C.png"));
intent.putExtra(android.content.Intent.EXTRA_STREAM, uri);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
As with the CollageCreator application, you’ll have to set up a provider in your Manifest file. If you’d like, you can copy/paste the provider XML from that application.
Create a Fragment to represent the drawing UI. In the XML, create buttons for color selection, stroke width selection, sharing, and clearing. For now, the share buttons don’t have to do anything. For the canvas to draw on, you can re-use some code form the example shown in class, but you might have to make some changes to the class to get it to behave as you need to for this assignment.
Next, get all of the buttons to work as they should. When one of the color buttons is pressed, the line color for future lines should be changed to that color. When S, M, or L is pressed, the stroke weight should be changed to the corresponding weight for future lines. The clear button should simply wipe the canvas clean. Make sure to test that each button does what it should for the drawing.
When the user presses the share button, there are several things that should happen:
When the user selects a contact from the list, the application should attempt to send am email to that contact with the attached image. You can use the starter code from the sections above to get that working. If the user does not have an email address on file, you can still open the email interface, with no email addresses in the “to” area. If the user has multiple email addresses, just pick any one of them.
For this application, you should target:
This PA is due on Monday, November 9th, 2020, at 7:00pm. You should turn it in on Gradescope. Then, submit the zip file to gradescope. Note that there are not automated tests for this PA, so please ensure that your app works how the specification says it should!