3939import java .io .File ;
4040import java .io .IOException ;
4141
42+ import butterknife .BindView ;
43+ import butterknife .ButterKnife ;
44+ import butterknife .OnClick ;
45+
4246public class MainActivity extends AppCompatActivity {
4347
44- // TODO (2): Replace all View declarations with Butterknife annotations
4548
4649 private static final int REQUEST_IMAGE_CAPTURE = 1 ;
4750 private static final int REQUEST_STORAGE_PERMISSION = 1 ;
4851
4952 private static final String FILE_PROVIDER_AUTHORITY = "com.example.android.fileprovider" ;
5053
51- private ImageView mImageView ;
54+ @ BindView ( R . id . image_view ) ImageView mImageView ;
5255
53- private Button mEmojifyButton ;
54- private FloatingActionButton mShareFab ;
55- private FloatingActionButton mSaveFab ;
56- private FloatingActionButton mClearFab ;
56+ @ BindView ( R . id . emojify_button ) Button mEmojifyButton ;
57+ @ BindView ( R . id . share_button ) FloatingActionButton mShareFab ;
58+ @ BindView ( R . id . save_button ) FloatingActionButton mSaveFab ;
59+ @ BindView ( R . id . clear_button ) FloatingActionButton mClearFab ;
5760
58- private TextView mTitleTextView ;
61+ @ BindView ( R . id . title_text_view ) TextView mTitleTextView ;
5962
6063 private String mTempPhotoPath ;
6164
@@ -67,22 +70,15 @@ protected void onCreate(Bundle savedInstanceState) {
6770 super .onCreate (savedInstanceState );
6871 setContentView (R .layout .activity_main );
6972
70- // TODO (3): Replace the findViewById calls with the Butterknife data binding
7173 // Bind the views
72- mImageView = (ImageView ) findViewById (R .id .image_view );
73- mEmojifyButton = (Button ) findViewById (R .id .emojify_button );
74- mShareFab = (FloatingActionButton ) findViewById (R .id .share_button );
75- mSaveFab = (FloatingActionButton ) findViewById (R .id .save_button );
76- mClearFab = (FloatingActionButton ) findViewById (R .id .clear_button );
77- mTitleTextView = (TextView ) findViewById (R .id .title_text_view );
74+ ButterKnife .bind (this );
7875 }
7976
8077 /**
8178 * OnClick method for "Emojify Me!" Button. Launches the camera app.
82- *
83- * @param view The emojify me button.
8479 */
85- public void emojifyMe (View view ) {
80+ @ OnClick (R .id .emojify_button )
81+ public void emojifyMe () {
8682 // Check for the external storage permission
8783 if (ContextCompat .checkSelfPermission (this ,
8884 Manifest .permission .WRITE_EXTERNAL_STORAGE )
@@ -193,13 +189,12 @@ private void processAndSetImage() {
193189 }
194190
195191
196- // TODO (4): Replace OnClick methods with Butterknife annotations for OnClicks
192+
197193 /**
198194 * OnClick method for the save button.
199- *
200- * @param view The save button.
201195 */
202- public void saveMe (View view ) {
196+ @ OnClick (R .id .save_button )
197+ public void saveMe () {
203198 // Delete the temporary image file
204199 BitmapUtils .deleteImageFile (this , mTempPhotoPath );
205200
@@ -209,10 +204,9 @@ public void saveMe(View view) {
209204
210205 /**
211206 * OnClick method for the share button, saves and shares the new bitmap.
212- *
213- * @param view The share button.
214207 */
215- public void shareMe (View view ) {
208+ @ OnClick (R .id .share_button )
209+ public void shareMe () {
216210 // Delete the temporary image file
217211 BitmapUtils .deleteImageFile (this , mTempPhotoPath );
218212
@@ -225,10 +219,9 @@ public void shareMe(View view) {
225219
226220 /**
227221 * OnClick for the clear button, resets the app to original state.
228- *
229- * @param view The clear button.
230222 */
231- public void clearImage (View view ) {
223+ @ OnClick (R .id .clear_button )
224+ public void clearImage () {
232225 // Clear the image and toggle the view visibility
233226 mImageView .setImageResource (0 );
234227 mEmojifyButton .setVisibility (View .VISIBLE );
0 commit comments