Example usage for android.content Context fileList

List of usage examples for android.content Context fileList

Introduction

In this page you can find the example usage for android.content Context fileList.

Prototype

public abstract String[] fileList();

Source Link

Document

Returns an array of strings naming the private files associated with this Context's application package.

Usage

From source file:Main.java

public static String[] getPuzzleFiles(Context context) {
    String[] files = context.fileList();
    Vector<String> puzzleFiles = new Vector<String>();
    for (String file : files)
        if (file.endsWith(".pfy"))
            puzzleFiles.add(file);/*w  w w. j  a  v  a  2  s .co m*/
    String[] ret = new String[0];
    return puzzleFiles.toArray(ret);
}

From source file:Main.java

/**
 * Delete the wishlist/*from  www. ja v  a2  s.  c  o m*/
 *
 * @param mCtx A context to open the file wish
 */
public static void ResetCards(Context mCtx) {

    String[] files = mCtx.fileList();
    for (String fileName : files) {
        if (fileName.equals(WISHLIST_NAME)) {
            mCtx.deleteFile(fileName);
        }
    }
}

From source file:Main.java

public static boolean isCollectioned(long id, Context context) {
    String name = id + ".txt";
    String[] strings = context.fileList();
    for (String s : strings) {
        if (name.equals(s)) {
            return true;
        }/*from  w ww . j  a  v a2s. c o  m*/
    }
    return false;
}

From source file:Main.java

/**
 * Get a list of all saved characters names.
 *///from   w ww. j av a 2  s.  com
public static List<String> listCharacterFileNames(Context context) {
    List<String> names = new ArrayList<>();

    for (String name : context.fileList()) {
        if (name.startsWith(CORE_PREFIX) || name.startsWith(FAE_PREFIX)) {
            names.add(name);
        }
    }

    return names;
}

From source file:Main.java

/**
 * Get a list of all saved characters names.
 *//*from  ww  w  . j  a  v  a 2s . c  o  m*/
public static List<String> listCharacterNames(Context context) {
    List<String> names = new ArrayList<>();

    for (String name : context.fileList()) {
        if (name.startsWith(CORE_PREFIX)) {
            names.add(name.replace(CORE_PREFIX, ""));
        } else if (name.startsWith(FAE_PREFIX)) {
            names.add(name.replace(FAE_PREFIX, ""));
        }
    }

    return names;
}

From source file:com.jamesgiang.aussnowcam.Utils.java

public static boolean CheckSetting(Context context, String file) {
    String[] filenames = context.fileList();
    for (String name : filenames) {
        if (name.equals(file)) {
            return true;
        }//from   w  ww. java  2 s .  c om
    }
    return false;
}

From source file:net.tawacentral.roger.secrets.FileUtils.java

/**
 * Get all existing restore points, including the restore file on the SD card
 * if it exists.//from   w  w  w  . j  a va2s.  c  o  m
 *
 * @param context Activity context in which the save is called.
 * @return A list of all possible restore points.
 */
public static List<String> getRestorePoints(Context context) {
    String[] filenames = context.fileList();
    ArrayList<String> list = new ArrayList<String>(filenames.length + 1);
    if (restoreFileExist())
        list.add(SECRETS_FILE_NAME_SDCARD);

    for (String filename : filenames) {
        if (filename.startsWith(RP_PREFIX))
            list.add(filename);
    }

    return list;
}

From source file:net.tawacentral.roger.secrets.FileUtils.java

/** Deletes all secrets from the phone.
 * @param context the current context//from ww w  .  ja  v  a2 s . com
 * @return always true
 */
public static boolean deleteSecrets(Context context) {
    Log.d(LOG_TAG, "FileUtils.deleteSecrets");
    synchronized (lock) {
        String filenames[] = context.fileList();
        for (String filename : filenames) {
            context.deleteFile(filename);
        }
    }

    return true;
}

From source file:net.tawacentral.roger.secrets.FileUtils.java

/**
 * Cleanup any residual data files from a previous bad run, if any.  The
 * algorithm is as follows://from www  .jav  a2  s .  c  o  m
 *
 * - delete any file with "new" in the name.  These are possibly partial
 *   writes, so their contents is undefined.
 * - if no secrets file exists, rename the most recent auto restore point
 *   file to secrets.
 * - if too many auto restore point files exist, delete the extra ones.
 *   However, don't delete any auto-backups younger than 48 hours.
 *
 * @param context Activity context in which the save is called.
 */
public static void cleanupDataFiles(Context context) {
    Log.d(LOG_TAG, "FileUtils.cleanupDataFiles");
    synchronized (lock) {
        String[] filenames = context.fileList();
        int oldCount = filenames.length;
        boolean secretsFileExists = context.getFileStreamPath(SECRETS_FILE_NAME).exists();

        // Cleanup any partial saves and find the most recent auto-backup file.
        {
            File mostRecent = null;
            int mostRecentIndex = -1;
            for (int i = 0; i < filenames.length; ++i) {
                String filename = filenames[i];
                if (-1 != filename.indexOf("new")) {
                    context.deleteFile(filename);
                    --oldCount;
                    filenames[i] = null;
                } else if (filename.startsWith(RP_PREFIX)) {
                    if (!secretsFileExists) {
                        File f = context.getFileStreamPath(filename);
                        if (null == mostRecent || f.lastModified() > mostRecent.lastModified()) {
                            mostRecent = f;
                            mostRecentIndex = i;
                        }
                    }
                } else {
                    --oldCount;
                    filenames[i] = null;
                }
            }

            // If we don't have a secrets file but found an auto-backup file,
            // rename the more recent auto-backup to secrets.
            if (null != mostRecent) {
                mostRecent.renameTo(context.getFileStreamPath(SECRETS_FILE_NAME));
                --oldCount;
                filenames[mostRecentIndex] = null;
            }
        }

        // If there are too many old files, delete the oldest extra ones.
        while (oldCount > 10) {
            File oldest = null;
            int oldestIndex = -1;

            for (int i = 0; i < filenames.length; ++i) {
                String filename = filenames[i];
                if (null == filename)
                    continue;

                File f = context.getFileStreamPath(filename);
                if (null == oldest || f.lastModified() < oldest.lastModified()) {
                    oldest = f;
                    oldestIndex = i;
                }
            }

            if (null != oldest) {
                // If the oldest file is not too old, then just break out of the
                // loop.  We don't want to delete any "old" files that are too
                // recent.
                if (!FileUtils.isRestorePointTooOld(oldest))
                    break;

                oldest.delete();
                --oldCount;
                filenames[oldestIndex] = null;
            }
        }
    }
}

From source file:net.phase.wallet.Currency.java

public static Wallet[] getStoredWallets(Context context, WalletActivity activity) throws IOException {
    ArrayList<Wallet> walletsArray = new ArrayList<Wallet>();

    String[] files = context.fileList();

    if (files.length == 0)
        return null;

    for (String filename : files) {
        BufferedReader in = new BufferedReader(new InputStreamReader(context.openFileInput(filename)));
        try {/*from  w  w w .  j  a v  a  2 s  . c  om*/
            walletsArray.add(new Wallet(in, activity));
        } catch (NumberFormatException e) {
        }
        in.close();
    }
    Wallet[] wallets = new Wallet[walletsArray.size()];
    walletsArray.toArray(wallets);
    return wallets;
}