Skip to content

Commit 2c31fe3

Browse files
committed
TLIB.07-Solution-AddTimber
1 parent 73021e0 commit 2c31fe3

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ dependencies {
2929
compile 'com.google.android.gms:play-services-vision:10.2.0'
3030
compile 'com.jakewharton:butterknife:8.4.0'
3131
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
32-
// TODO (1): Add Timber dependency
32+
compile 'com.jakewharton.timber:timber:4.5.0'
3333
testCompile 'junit:junit:4.12'
3434
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,17 @@
2020
import android.graphics.Bitmap;
2121
import android.graphics.BitmapFactory;
2222
import android.graphics.Canvas;
23-
import android.util.Log;
2423
import android.util.SparseArray;
2524
import android.widget.Toast;
2625

2726
import com.google.android.gms.vision.Frame;
2827
import com.google.android.gms.vision.face.Face;
2928
import com.google.android.gms.vision.face.FaceDetector;
3029

30+
import timber.log.Timber;
31+
3132
class Emojifier {
3233

33-
// TODO (3): Change all Log statements to Timber logs and remove the LOG_TAG variable
34-
private static final String LOG_TAG = Emojifier.class.getSimpleName();
3534

3635
private static final float EMOJI_SCALE_FACTOR = .9f;
3736
private static final double SMILING_PROB_THRESHOLD = .15;
@@ -59,7 +58,7 @@ static Bitmap detectFacesandOverlayEmoji(Context context, Bitmap picture) {
5958
SparseArray<Face> faces = detector.detect(frame);
6059

6160
// Log the number of faces
62-
Log.d(LOG_TAG, "detectFaces: number of faces = " + faces.size());
61+
Timber.d("detectFaces: number of faces = " + faces.size());
6362

6463
// Initialize result bitmap to original picture
6564
Bitmap resultBitmap = picture;
@@ -134,10 +133,10 @@ static Bitmap detectFacesandOverlayEmoji(Context context, Bitmap picture) {
134133

135134
private static Emoji whichEmoji(Face face) {
136135
// Log all the probabilities
137-
Log.d(LOG_TAG, "whichEmoji: smilingProb = " + face.getIsSmilingProbability());
138-
Log.d(LOG_TAG, "whichEmoji: leftEyeOpenProb = "
136+
Timber.d("whichEmoji: smilingProb = " + face.getIsSmilingProbability());
137+
Timber.d("whichEmoji: leftEyeOpenProb = "
139138
+ face.getIsLeftEyeOpenProbability());
140-
Log.d(LOG_TAG, "whichEmoji: rightEyeOpenProb = "
139+
Timber.d("whichEmoji: rightEyeOpenProb = "
141140
+ face.getIsRightEyeOpenProbability());
142141

143142

@@ -173,8 +172,9 @@ private static Emoji whichEmoji(Face face) {
173172

174173

175174
// Log the chosen Emoji
176-
Log.d(LOG_TAG, "whichEmoji: " + emoji.name());
177-
175+
Timber.d("whichEmoji: " + emoji.name());
176+
177+
// return the chosen Emoji
178178
return emoji;
179179
}
180180

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import butterknife.BindView;
4343
import butterknife.ButterKnife;
4444
import butterknife.OnClick;
45+
import timber.log.Timber;
4546

4647
public class MainActivity extends AppCompatActivity {
4748

@@ -73,7 +74,8 @@ protected void onCreate(Bundle savedInstanceState) {
7374
// Bind the views
7475
ButterKnife.bind(this);
7576

76-
// TODO (2): Set up Timber
77+
// Set up Timber
78+
Timber.plant(new Timber.DebugTree());
7779
}
7880

7981
/**
@@ -181,7 +183,7 @@ private void processAndSetImage() {
181183

182184
// Resample the saved image to fit the ImageView
183185
mResultsBitmap = BitmapUtils.resamplePic(this, mTempPhotoPath);
184-
186+
185187

186188
// Detect the faces and overlay the appropriate emoji
187189
mResultsBitmap = Emojifier.detectFacesandOverlayEmoji(this, mResultsBitmap);
@@ -191,7 +193,6 @@ private void processAndSetImage() {
191193
}
192194

193195

194-
195196
/**
196197
* OnClick method for the save button.
197198
*/

0 commit comments

Comments
 (0)