コード例 #1
0
  private void renameFile(File oldFile, PictureFile pictureFile, String newGeoname) {

    pictureFile.setGeo_name(newGeoname);

    Double lat = pictureFile.getLat();
    Double lon = pictureFile.getLon();
    String geoname = newGeoname;
    Long time = pictureFile.getTime();

    String oldPath = pictureFile.getFull_path_on_device();
    int indexForSlash = oldPath.lastIndexOf("/");
    String parentPath = oldPath.substring(0, indexForSlash + 1);
    String timestamp = StorageHelper.formatTimeForFilename(time);
    String location = StorageHelper.formatLatLonGeoname(lat, lon, geoname);
    String username = daoHelper.getUserName();
    String newName = StorageHelper.formatFilename(username, location, timestamp);
    String newPath = parentPath + newName;

    pictureFile.setFilename(newName);
    pictureFile.setFull_path_on_device(newPath);

    File newFile = new File(newPath);
    oldFile.renameTo(newFile);

    Log.w(LOG_TAG, "Renamed " + oldPath + " to " + newPath);

    daoHelper.pictureFileDao.update(pictureFile);
    daoHelper.onPictureFilesUpdated();
  }