Skip to content

Commit 8691c1f

Browse files
committed
TLIB.05-Exercise-DrawEmojiOverFaces
1 parent 2a064f8 commit 8691c1f

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

app/src/main/java/com/example/android/emojify/Emojifier.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class Emojifier {
4141
*/
4242
static void detectFaces(Context context, Bitmap picture) {
4343

44+
// TODO (3): Change the name of the detectFaces() method to detectFacesAndOverlayEmoji() and the return type from void to Bitmap
45+
4446
// Create the face detector, disable tracking and enable classifications
4547
FaceDetector detector = new FaceDetector.Builder(context)
4648
.setTrackingEnabled(false)
@@ -56,6 +58,7 @@ static void detectFaces(Context context, Bitmap picture) {
5658
// Log the number of faces
5759
Log.d(LOG_TAG, "detectFaces: number of faces = " + faces.size());
5860

61+
// TODO (7): Create a variable called resultBitmap and initialize it to the original picture bitmap passed into the detectFacesAndOverlayEmoji() method
5962
// If there are no faces detected, show a Toast message
6063
if(faces.size() == 0) {
6164
Toast.makeText(context, R.string.no_faces_message, Toast.LENGTH_SHORT).show();
@@ -67,12 +70,17 @@ static void detectFaces(Context context, Bitmap picture) {
6770
// Get the appropriate emoji for each face
6871
whichEmoji(face);
6972

73+
// TODO (4): Create a variable called emojiBitmap to hold the appropriate Emoji bitmap and remove the call to whichEmoji()
74+
// TODO (5): Create a switch statement on the result of the whichEmoji() call, and assign the proper emoji bitmap to the variable you created
75+
// TODO (8): Call addBitmapToFace(), passing in the resultBitmap, the emojiBitmap and the Face object, and assigning the result to resultBitmap
76+
7077
}
7178
}
7279

7380

7481
// Release the detector
7582
detector.release();
83+
// TODO (9): Return the resultBitmap
7684
}
7785

7886

@@ -85,6 +93,7 @@ static void detectFaces(Context context, Bitmap picture) {
8593

8694
private static void whichEmoji(Face face) {
8795

96+
// TODO (1): Change the return type of the whichEmoji() method from void to Emoji.
8897
// Log all the probabilities
8998
Log.d(LOG_TAG, "whichEmoji: smilingProb = " + face.getIsSmilingProbability());
9099
Log.d(LOG_TAG, "whichEmoji: leftEyeOpenProb = "
@@ -126,8 +135,11 @@ private static void whichEmoji(Face face) {
126135

127136
// Log the chosen Emoji
128137
Log.d(LOG_TAG, "whichEmoji: " + emoji.name());
138+
139+
// TODO (2): Have the method return the selected Emoji type.
129140
}
130-
141+
142+
// TODO (6) Create a method called addBitmapToFace() which takes the background bitmap, the Emoji bitmap, and a Face object as arguments and returns the combined bitmap with the Emoji over the face.
131143
// Enum for all possible Emojis
132144
private enum Emoji {
133145
SMILE,

app/src/main/java/com/example/android/emojify/MainActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ private void processAndSetImage() {
183183

184184
// Detect the faces
185185
Emojifier.detectFaces(this, mResultsBitmap);
186+
// TODO (10): Change the method call from detectFaces() to detectFacesAndOverlayEmoji() and assign the result to mResultsBitmap.
186187

187188
// Set the new bitmap to the ImageView
188189
mImageView.setImageBitmap(mResultsBitmap);

0 commit comments

Comments
 (0)