Android Open Source - android_Findex File Walker






From Project

Back to project page android_Findex.

License

The source code is released under:

Apache License

If you think the Android project android_Findex listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.lithidsw.findex.utils;
//from  w  w w  .  j a  va2  s.c  o  m
import android.content.Context;
import android.content.SharedPreferences;
import android.webkit.MimeTypeMap;

import com.lithidsw.findex.db.DBUtils;
import com.lithidsw.findex.info.FileInfo;

import java.io.File;

public class FileWalker {

    private SharedPreferences mPrefs;
    private DBUtils dbUtils;
    MimeTypeMap map;
    Context mContext;

    public FileWalker(Context context) {
        mContext = context;
        dbUtils = new DBUtils(mContext);
        mPrefs = mContext.getSharedPreferences(C.PREF, Context.MODE_PRIVATE);
    }

    public void walk(File root, String folderName, String storage) {
        File[] list = root.listFiles();
        if (list != null && !isNoMedia(list)) {
            for (File f : list) {
                if (f.isDirectory() && !f.isHidden() && !isNoMediaFolder(f, storage)) {
                    walk(f, f.getName(), storage);
                } else {
                    if (!f.isHidden() && !f.isDirectory()) {
                        if (!dbUtils.isFileExist(f.getAbsolutePath())) {
                            String name = f.getName();
                            map = MimeTypeMap.getSingleton();
                            String ext = MimeTypeMap.getFileExtensionFromUrl(
                                    name.toLowerCase().replace(" ", "")
                            );
                            String type = map.getMimeTypeFromExtension(ext);

                            if (type == null) {
                                type = "*/*";
                            }

                            if (type.contains("video/")) {
                                type = C.TAG_VIDEO;
                            } else if (type.contains("image/")) {
                                type = C.TAG_PICTURES;
                            } else if (type.contains("audio/")) {
                                type = C.TAG_SOUNDS;
                            } else if (type.contains("application/ogg")) {
                                type = C.TAG_SOUNDS;
                            } else {
                                type = C.TAG_DOCUMENTS;
                            }

                            FileInfo fileInfo = new FileInfo();
                            fileInfo.folder = folderName;
                            fileInfo.path = f.getAbsolutePath();
                            fileInfo.name = name;
                            fileInfo.type = type;
                            fileInfo.modified = f.lastModified();
                            fileInfo.size = f.length();
                            fileInfo.storage = storage;
                            dbUtils.write(fileInfo, false);
                        }
                    }
                }
            }
        }
    }

    private boolean isNoMedia(File[] files) {
        for (File file : files) {
            if (file.getName().equalsIgnoreCase(".nomedia")) {
                return true;
            }
        }

        return false;
    }

    private boolean isNoMediaFolder(File file, String storage) {
        boolean isNoMedia = false;
        String[] folders = mPrefs.getString(C.PREF_EXCLUDE_FOLDERS, "").split("::");
        for (String folder : folders) {
            if (folder.length() > 0) {
                isNoMedia = file.getAbsolutePath().contains(folder);
            }

            if (isNoMedia) {
                return true;
            }
        }

        isNoMedia = file.getAbsolutePath().contains(storage + "/Android") ||
                file.getAbsolutePath().contains(storage + "/LOST.DIR") ||
                file.getAbsolutePath().contains(storage + "/data");

        return isNoMedia;

    }

    public void main() {
        StorageOptions.determineStorageOptions(mContext);
        for (String path: StorageOptions.paths) {
            File file = new File(path);
            walk(file, file.getName(), path);
        }
    }
}




Java Source Code List

com.lithidsw.findex.AddTagActivity.java
com.lithidsw.findex.FileInfoActivity.java
com.lithidsw.findex.IntroActivity.java
com.lithidsw.findex.IntroFragment.java
com.lithidsw.findex.MainActivity.java
com.lithidsw.findex.MainFragment.java
com.lithidsw.findex.SettingsActivity.java
com.lithidsw.findex.adapter.DrawerListAdapter.java
com.lithidsw.findex.adapter.FilePageAdapter.java
com.lithidsw.findex.adapter.InfoTagListAdapter.java
com.lithidsw.findex.adapter.StorageListAdapter.java
com.lithidsw.findex.adapter.WidgetListAdapter.java
com.lithidsw.findex.db.DBHelper.java
com.lithidsw.findex.db.DBUtils.java
com.lithidsw.findex.ef.DirectoryAdapter.java
com.lithidsw.findex.ef.DirectoryListActivity.java
com.lithidsw.findex.ef.DirectoryManager.java
com.lithidsw.findex.info.DirPickerInfo.java
com.lithidsw.findex.info.FileInfo.java
com.lithidsw.findex.loader.ImageLoader.java
com.lithidsw.findex.loader.MemoryCache.java
com.lithidsw.findex.receiver.ActionReceiver.java
com.lithidsw.findex.service.IndexService.java
com.lithidsw.findex.utils.C.java
com.lithidsw.findex.utils.DateBuilder.java
com.lithidsw.findex.utils.FileStartActivity.java
com.lithidsw.findex.utils.FileUtils.java
com.lithidsw.findex.utils.FileWalker.java
com.lithidsw.findex.utils.ItemCountLoader.java
com.lithidsw.findex.utils.MrToast.java
com.lithidsw.findex.utils.StorageOptions.java
com.lithidsw.findex.widget.WidgetConfigActivity.java
com.lithidsw.findex.widget.WidgetInfo.java
com.lithidsw.findex.widget.WidgetLoadStub.java
com.lithidsw.findex.widget.WidgetProvider.java
com.lithidsw.findex.widget.WidgetService.java
com.lithidsw.findex.widget.WidgetUtils.java
com.lithidsw.findex.widget.WidgetViews.java