/** Save the camera file URI if we have taken a picture */
 @Override
 protected void onSaveInstanceState(Bundle outState) {
   super.onSaveInstanceState(outState);
   if (cameraFileUri != null && !cameraFileUri.equals(""))
     outState.putString(Constants.IMAGE_URI_KEY, cameraFileUri.toString());
   outState.putBoolean(Constants.FROM_GALLERY_KEY, fromGallery);
 }
  /* Sets up the User Interface */
  protected void setupUI() {
    super.setupUI();
    // If we have GPS disabled then ask to activate it
    if (!myApplication.isGPSEnabled())
      AlertBuilder.buildGPSAlertMessage(SelectImageActivity.this, true).show();
    captureImageButton = (Button) findViewById(R.id.capture_image_button);
    selectImageFromGalleryButton = (Button) findViewById(R.id.select_image_from_gallery_button);

    previewImageView = (ImageView) findViewById(R.id.preview_image);
    previewTextView = (TextView) findViewById(R.id.preview_text);

    // goes to the description activity
    nextButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            if (cameraFileUri != null) {
              // save the image URI to the submissionEventBuilder
              submissionEventBuilder.setImagePath(cameraFileUri);
              submissionEventBuilder.setFromGallery(fromGallery);
              // start description activity
              startActivity(new Intent(SelectImageActivity.this, DescriptionActivity.class));
              //					Toast.makeText(SelectImageActivity.this, getString(R.string.saving_image),
              // Toast.LENGTH_LONG).show();
            } else
              Toast.makeText(
                      SelectImageActivity.this,
                      getString(R.string.please_select_a_image),
                      Toast.LENGTH_LONG)
                  .show();
          }
        });
    captureImageButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            startActivityForResult(
                new Intent(SelectImageActivity.this, TakePictureActivity.class),
                Constants.REQUEST_CODE_TAKE_PICTURE);
          }
        });
    selectImageFromGalleryButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            // open gallery
            // dealt with at onActivityResult()
            retrieveImageFromGallery();
          }
        });
    backButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            onBackPressed();
          }
        });
  }
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.select_image_layout);
   setupUI();
   loadState(savedInstanceState);
   // starts a new submission event
   submissionEventBuilder.startNewSubmissionEvent();
 }
 @Override
 public void onBackPressed() {
   if (cameraFileUri != null) {
     String imagePath = cameraFileUri.toString();
     // delete image
     if (imagePath != null && !imagePath.equals("")) {
       myApplication.deleteImage(imagePath);
     }
   }
   super.onBackPressed();
 }
 @Override
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   // Coming from capturing an image from native activity
   if (requestCode == Constants.REQUEST_CODE_TAKE_PICTURE && resultCode == Activity.RESULT_OK) {
     if (data == null || data.getData() == null) {
       // Picture has been taken natively, get the path from activity
       cameraFileUri = Uri.parse(data.getStringExtra(Constants.IMAGE_URI_KEY));
       setPreviewImageOn(cameraFileUri);
       fromGallery = false;
     }
   }
   // Coming from gallery
   if (requestCode == Constants.REQUEST_CODE_GALLERY && resultCode == Activity.RESULT_OK) {
     if (data != null) {
       cameraFileUri = data.getData();
       setPreviewImageOn(cameraFileUri);
       fromGallery = true;
     }
   }
   Log.i(toString(), "cameraFileUri : " + cameraFileUri);
 }