Search in sources :

Example 1 with ZipTask

use of com.peterlaurence.trekadvisor.util.ZipTask in project TrekAdvisor by peterLaurence.

the class Map method zip.

/**
 * Archives the map. <p>
 * Creates a zip file named with this {@link Map} name and the date. This file is placed in the
 * parent folder of the {@link Map}.
 *
 * @param listener The {@link com.peterlaurence.trekadvisor.util.ZipTask.ZipProgressionListener}.
 */
public void zip(ZipTask.ZipProgressionListener listener) {
    /* Generate an output zip file named with the map name and the date */
    Date date = new Date();
    DateFormat dateFormat = new SimpleDateFormat("dd\\MM\\yyyy-HH:mm:ss", Locale.ENGLISH);
    String zipFileName = getName() + "-" + dateFormat.format(date) + ".zip";
    /* By default and for instance, the archive is placed in the parent folder of the map */
    File zipDirectory = mConfigFile.getParentFile().getParentFile();
    File outputFile = new File(zipDirectory, zipFileName);
    try {
        if (!outputFile.createNewFile()) {
            listener.onZipError();
        }
    } catch (IOException e) {
        Log.e(TAG, Tools.stackTraceToString(e));
        listener.onZipError();
    }
    ZipTask zipTask = new ZipTask(mConfigFile.getParentFile(), outputFile, listener);
    zipTask.execute();
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ZipTask(com.peterlaurence.trekadvisor.util.ZipTask) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Date(java.util.Date)

Aggregations

ZipTask (com.peterlaurence.trekadvisor.util.ZipTask)1 File (java.io.File)1 IOException (java.io.IOException)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1