@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
      // get the saved file name
      Preferences.loadSettings(AddReportActivity.this);
      photoName = Preferences.fileName;
      if (requestCode == REQUEST_CODE_CAMERA) {

        Uri uri = PhotoUtils.getPhotoUri(photoName, this);
        Bitmap bitmap = PhotoUtils.getCameraPhoto(this, uri);
        PhotoUtils.savePhoto(this, bitmap, photoName);
        log(String.format("REQUEST_CODE_CAMERA %dx%d", bitmap.getWidth(), bitmap.getHeight()));

      } else if (requestCode == REQUEST_CODE_IMAGE) {

        Bitmap bitmap = PhotoUtils.getGalleryPhoto(this, data.getData());
        PhotoUtils.savePhoto(this, bitmap, photoName);
        log(String.format("REQUEST_CODE_IMAGE %dx%d", bitmap.getWidth(), bitmap.getHeight()));
      }

      if (id > 0) {
        addPhotoToReport();
      } else {
        pendingPhoto.refresh();
      }
    }
  }
  /** Delete any existing photo in the pending folder */
  private void deleteExistingPhoto() {
    File[] pendingPhotos = PhotoUtils.getPendingPhotos(this);
    if (pendingPhotos != null && pendingPhotos.length > 0) {
      for (File file : pendingPhotos) {
        if (file.exists()) {

          file.delete();
        }
      }
    }
  }
  /**
   * Post to local database
   *
   * @author henryaddo
   */
  private boolean addReport() {
    log("Adding new reports");
    File[] pendingPhotos = PhotoUtils.getPendingPhotos(this);

    Report report = new Report();

    report.setTitle(view.mIncidentTitle.getText().toString());
    report.setDescription(view.mIncidentDesc.getText().toString());
    report.setLatitude(view.mLatitude.getText().toString());
    report.setLongitude(view.mLongitude.getText().toString());
    report.setLocationName(view.mIncidentLocation.getText().toString());
    report.setReportDate(mDateToSubmit);
    report.setMode(String.valueOf(0));
    report.setVerified(String.valueOf(0));
    report.setPending(1);

    if (id == 0) {
      // Add a new pending report
      if (model.addPendingReport(
          report, mVectorCategories, pendingPhotos, view.mNews.getText().toString())) {
        // move saved photos
        log("Moving photos to fetched folder");
        ImageManager.movePendingPhotos(this);
        id = report.getDbId();
      } else {
        return false;
      }
    } else {
      // Update exisiting report
      List<Photo> photos = new ArrayList<Photo>();
      for (int i = 0; i < pendingPhoto.getCount(); i++) {
        photos.add(pendingPhoto.getItem(i));
      }
      if (model.updatePendingReport(
          id, report, mVectorCategories, photos, view.mNews.getText().toString())) {
        // move saved photos
        log("Moving photos to fetched folder");
        ImageManager.movePendingPhotos(this);
      } else {
        return false;
      }
    }
    if (mSendOpenGeoSms) {
      mOgsDao.addReport(id);
    } else {
      mOgsDao.deleteReport(id);
    }
    return true;
  }
 /** Set photo to be attached to an existing report */
 private void addPhotoToReport() {
   File[] pendingPhotos = PhotoUtils.getPendingPhotos(this);
   if (pendingPhotos != null && pendingPhotos.length > 0) {
     int id = 0;
     for (File file : pendingPhotos) {
       if (file.exists()) {
         id += 1;
         Photo photo = new Photo();
         photo.setDbId(id);
         photo.setPhoto("pending/" + file.getName());
         pendingPhoto.addItem(photo);
       }
     }
   }
 }