content: package com.albinmathew.samples.photocrop;
  
  import android.content.Intent;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.Button;
  import android.widget.ImageView;
  import android.widget.Toast;
  
  
  /**
   * @author albin
   * @date 23/6/15
   */
  public class ImageViewActivity extends AppCompatActivity implements PicModeSelectDialogFragment.IPicModeSelectListener {
  
      public static final String TAG = "ImageViewActivity";
      public static final String TEMP_PHOTO_FILE_NAME = "temp_photo.jpg";
      public static final int REQUEST_CODE_UPDATE_PIC = 0x1;
  
      private Button mBtnUpdatePic;
      private ImageView mImageView;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_image_view);
          mBtnUpdatePic = (Button) findViewById(R.id.btnUpdatePic);
          mImageView = (ImageView) findViewById(R.id.iv_user_pic);
          mBtnUpdatePic.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  showAddProfilePicDialog();
              }
          });
      }
  
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent result) {
          if (requestCode == REQUEST_CODE_UPDATE_PIC) {
              if (resultCode == RESULT_OK) {
                  String imagePath = result.getStringExtra(Constants.IntentExtras.IMAGE_PATH);
                  showCroppedImage(imagePath);
              } else if (resultCode == RESULT_CANCELED) {
  
              } else {
                  String errorMsg = result.getStringExtra(ImageCropActivity.ERROR_MSG);
                  Toast.makeText(this, errorMsg, Toast.LENGTH_LONG).show();
              }
          }
      }
  
      private void showCroppedImage(String mImagePath) {
          if (mImagePath != null) {
              Bitmap myBitmap = BitmapFactory.decodeFile(mImagePath);
              mImageView.setImageBitmap(myBitmap);
          }
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          switch (item.getItemId()) {
              case android.R.id.home:
                  super.onBackPressed();
                  return true;
              default:
                  return super.onOptionsItemSelected(item);
          }
      }
  
      private void showAddProfilePicDialog() {
          PicModeSelectDialogFragment dialogFragment = new PicModeSelectDialogFragment();
          dialogFragment.setiPicModeSelectListener(this);
          dialogFragment.show(getFragmentManager(), "picModeSelector");
      }
  
      private void actionProfilePic(String action) {
          Intent intent = new Intent(this, ImageCropActivity.class);
          intent.putExtra("ACTION", action);
          startActivityForResult(intent, REQUEST_CODE_UPDATE_PIC);
      }
  
  
      @Override
      public void onPicModeSelected(String mode) {
          String action = mode.equalsIgnoreCase(Constants.PicModes.CAMERA) ? Constants.IntentExtras.ACTION_CAMERA : Constants.IntentExtras.ACTION_GALLERY;
          actionProfilePic(action);
      }
  }
  