/**
  * Upload site picture
  *
  * @param context
  * @param site
  * @param fullPicture
  * @param thumb
  */
 public static void uploadSitePicture(
     final Context context,
     final ProjectSiteDTO site,
     final File fullPicture,
     final File thumb,
     Location location) {
   Log.w(LOG, "**** uploadSitePicture .........");
   final PhotoUploadDTO dto = getObject(context, fullPicture, thumb, location);
   dto.setProjectID(site.getProjectID());
   dto.setProjectSiteID(site.getProjectSiteID());
   dto.setPictureType(PhotoUploadDTO.SITE_IMAGE);
   dto.setAccuracy(location.getAccuracy());
   addPhotoToCache(context, dto);
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image);
    ctx = getApplicationContext();
    if (savedInstanceState != null) {
      index = savedInstanceState.getInt("index");
      projectSite = (ProjectSiteDTO) savedInstanceState.getSerializable("projectSite");
      project = (ProjectDTO) savedInstanceState.getSerializable("project");
    } else {
      project = (ProjectDTO) getIntent().getSerializableExtra("project");
      projectSite = (ProjectSiteDTO) getIntent().getSerializableExtra("projectSite");
      index = getIntent().getIntExtra("index", 0);
    }
    setFields();
    txtNumber.setText("" + (index + 1));

    photoCache = new PhotoCache();
    StringBuilder sb = new StringBuilder();
    sb.append(Statics.IMAGE_URL);
    if (projectSite != null) {
      photoCache.setPhotoUploadList(projectSite.getPhotoUploadList());
      PhotoUploadDTO dto = photoCache.getPhotoUploadList().get(index);
      sb.append(dto.getUri());
      txtTitle.setText(projectSite.getProjectName());
      txtSubTitle.setText(projectSite.getProjectSiteName());
      txtDate.setText(sdf.format(dto.getDateTaken()));
    }
    if (project != null) {
      photoCache.setPhotoUploadList(project.getPhotoUploadList());
      PhotoUploadDTO dto = photoCache.getPhotoUploadList().get(index);
      sb.append(dto.getUri());
      txtTitle.setText(project.getProjectName());
      txtDate.setText(sdf.format(dto.getDateTaken()));
      txtSubTitle.setVisibility(View.GONE);
    }
    url = sb.toString();
    Picasso.with(ctx).load(url).into(imageView);

    Util.animateScaleY(imageView, 200);
    setHeader();
  }
  public void setLocation(Location location) {
    if (projectSite == null) return;
    this.location = location;
    txtLat.setText("" + location.getLatitude());
    txtLng.setText("" + location.getLongitude());
    txtAccuracy.setText("" + location.getAccuracy());

    if (location.getAccuracy() == seekBar.getProgress()
        || location.getAccuracy() < seekBar.getProgress()) {
      listener.onEndScanRequested();
      isScanning = false;
      stopRotatingLogo();
      chronometer.stop();
      resetLogo();
      btnScan.setText(ctx.getString(R.string.start_scan));
      btnSave.setVisibility(View.VISIBLE);
      projectSite.setLatitude(location.getLatitude());
      projectSite.setLongitude(location.getLongitude());
      projectSite.setAccuracy(location.getAccuracy());
      Util.expand(btnSave, 200, null);
      Log.d(LOG, "----------- onEndScanRequested - stopped scanning");
    }
    Util.flashSeveralTimes(hero, 300, 1, null);
  }
  private void sendGPSData() {

    RequestDTO w = new RequestDTO(RequestDTO.UPDATE_PROJECT_SITE);
    ProjectSiteDTO site = new ProjectSiteDTO();
    site.setProjectSiteID(projectSite.getProjectSiteID());
    site.setLatitude(location.getLatitude());
    site.setLongitude(location.getLongitude());
    site.setAccuracy(location.getAccuracy());
    w.setProjectSite(site);

    rotateLogo();
    WebSocketUtil.sendRequest(
        ctx,
        Statics.COMPANY_ENDPOINT,
        w,
        new WebSocketUtil.WebSocketListener() {
          @Override
          public void onMessage(final ResponseDTO response) {
            getActivity()
                .runOnUiThread(
                    new Runnable() {
                      @Override
                      public void run() {
                        stopRotatingLogo();
                        if (!ErrorUtil.checkServerError(ctx, response)) {
                          return;
                        }
                        Log.w(LOG, "++++++++++++ project site location updated");
                      }
                    });
          }

          @Override
          public void onClose() {}

          @Override
          public void onError(final String message) {
            Log.e(LOG, "---- ERROR websocket - " + message);
            getActivity()
                .runOnUiThread(
                    new Runnable() {
                      @Override
                      public void run() {
                        Util.showErrorToast(ctx, message);
                      }
                    });
          }
        });
  }
 public void setProjectSite(ProjectSiteDTO projectSite) {
   this.projectSite = projectSite;
   if (projectSite != null) txtName.setText(projectSite.getProjectSiteName());
 }