Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Tint Browser for Android
 * 
 * Copyright (C) 2012 - to infinity and beyond J. Devauchelle and contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 3 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;

import android.os.Environment;

public class Main {
    /**
     * Get the list of xml files in the bookmark export folder.
     * @return The list of xml files in the bookmark export folder.
     */
    public static List<String> getExportedBookmarksFileList() {
        List<String> result = new ArrayList<String>();

        File folder = Environment.getExternalStorageDirectory();

        if (folder != null) {

            FileFilter filter = new FileFilter() {

                @Override
                public boolean accept(File pathname) {
                    if ((pathname.isFile()) && (pathname.getPath().toLowerCase(Locale.US).endsWith(".xml")
                            || pathname.getPath().toLowerCase(Locale.US).endsWith(".json"))) {
                        return true;
                    }
                    return false;
                }
            };

            File[] files = folder.listFiles(filter);

            for (File file : files) {
                result.add(file.getName());
            }
        }

        Collections.sort(result, new Comparator<String>() {

            @Override
            public int compare(String arg0, String arg1) {
                return arg1.compareTo(arg0);
            }
        });

        return result;
    }
}