Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.io.FileFilter;

import java.util.Arrays;

import android.support.annotation.NonNull;

public class Main {
    public static Context applicationContext;

    /**
     * Get all temp files.
     *
     * @return The list of existing temp files.
     */
    public static File[] getTempCameraFiles() {
        File tempDir = getTempCameraFolder();

        File[] files = tempDir.listFiles(new FileFilter() {
            @Override
            public boolean accept(@NonNull final File file) {
                return file.isFile();
            }
        });
        if (files == null) {
            files = new File[0];
        }
        Arrays.sort(files);

        return files;
    }

    /**
     * Get the folder where temporary files from the camera are stored.
     *
     * @return The temp folder.
     */
    @NonNull
    public static File getTempCameraFolder() {
        File result = new File(applicationContext.getExternalCacheDir(), "Camera");
        if (!result.exists()) {
            //noinspection ResultOfMethodCallIgnored
            result.mkdirs();
        }
        return result;
    }
}