Example usage for java.io File canExecute

List of usage examples for java.io File canExecute

Introduction

In this page you can find the example usage for java.io File canExecute.

Prototype

public boolean canExecute() 

Source Link

Document

Tests whether the application can execute the file denoted by this abstract pathname.

Usage

From source file:com.atlauncher.data.Settings.java

/**
 * Load the properties from file/* w  w  w .  ja v a  2s . com*/
 */
public void loadProperties() {
    LogManager.debug("Loading properties");
    try {
        this.properties.load(new FileInputStream(propertiesFile));
        this.firstTimeRun = Boolean.parseBoolean(properties.getProperty("firsttimerun", "true"));

        this.hadPasswordDialog = Boolean.parseBoolean(properties.getProperty("hadpassworddialog", "false"));

        this.hideOldJavaWarning = Boolean.parseBoolean(properties.getProperty("hideoldjavawarning", "false"));

        this.hideJava8Warning = Boolean.parseBoolean(properties.getProperty("hidejava8warning", "false"));

        String lang = properties.getProperty("language", "English");
        if (!isLanguageByName(lang)) {
            LogManager.warn("Invalid language " + lang + ". Defaulting to English!");
            lang = "English";
        }

        Language.INSTANCE.load(lang);

        this.forgeLoggingLevel = properties.getProperty("forgelogginglevel", "INFO");
        if (!this.forgeLoggingLevel.equalsIgnoreCase("SEVERE")
                && !this.forgeLoggingLevel.equalsIgnoreCase("WARNING")
                && !this.forgeLoggingLevel.equalsIgnoreCase("INFO")
                && !this.forgeLoggingLevel.equalsIgnoreCase("CONFIG")
                && !this.forgeLoggingLevel.equalsIgnoreCase("FINE")
                && !this.forgeLoggingLevel.equalsIgnoreCase("FINER")
                && !this.forgeLoggingLevel.equalsIgnoreCase("FINEST")) {
            LogManager.warn("Invalid Forge Logging level " + this.forgeLoggingLevel + ". Defaulting to INFO!");
            this.forgeLoggingLevel = "INFO";
        }

        if (Utils.is64Bit()) {
            int halfRam = (Utils.getMaximumRam() / 1000) * 512;
            int defaultRam = (halfRam >= 4096 ? 4096 : halfRam); // Default ram
            this.maximumMemory = Integer.parseInt(properties.getProperty("ram", defaultRam + ""));
            if (this.maximumMemory > Utils.getMaximumRam()) {
                LogManager.warn("Tried to allocate " + this.maximumMemory + "MB of Ram but only "
                        + Utils.getMaximumRam() + "MB is available to use!");
                this.maximumMemory = defaultRam; // User tried to allocate too much ram, set it
                // back to
                // half, capped at 4GB
            }
        } else {
            this.maximumMemory = Integer.parseInt(properties.getProperty("ram", "1024"));
            if (this.maximumMemory > Utils.getMaximumRam()) {
                LogManager.warn("Tried to allocate " + this.maximumMemory + "MB of Maximum Ram but only "
                        + Utils.getMaximumRam() + "MB is available to use!");
                this.maximumMemory = 1024; // User tried to allocate too much ram, set it back
                // to 1GB
            }
        }

        this.initialMemory = Integer.parseInt(properties.getProperty("initialmemory", "256"));
        if (this.initialMemory > Utils.getMaximumRam()) {
            LogManager.warn("Tried to allocate " + this.initialMemory + "MB of Initial Ram but only "
                    + Utils.getMaximumRam() + "MB is available to use!");
            this.initialMemory = 256; // User tried to allocate too much ram, set it back to
            // 256MB
        } else if (this.initialMemory > this.maximumMemory) {
            LogManager.warn("Tried to allocate " + this.initialMemory + "MB of Initial Ram but maximum ram is "
                    + this.maximumMemory + "MB which is less!");
            this.initialMemory = 256; // User tried to allocate too much ram, set it back to 256MB
        }

        // Default PermGen to 256 for 64 bit systems and 128 for 32 bit systems
        this.permGen = Integer.parseInt(properties.getProperty("permGen", (Utils.is64Bit() ? "256" : "128")));

        this.windowWidth = Integer.parseInt(properties.getProperty("windowwidth", "854"));
        if (this.windowWidth > Utils.getMaximumWindowWidth()) {
            LogManager.warn("Tried to set window width to " + this.windowWidth + " pixels but the maximum is "
                    + Utils.getMaximumWindowWidth() + " pixels!");
            this.windowWidth = Utils.getMaximumWindowWidth(); // User tried to make screen size
            // wider than they have
        }

        this.windowHeight = Integer.parseInt(properties.getProperty("windowheight", "480"));
        if (this.windowHeight > Utils.getMaximumWindowHeight()) {
            LogManager.warn("Tried to set window height to " + this.windowHeight + " pixels but the maximum is "
                    + Utils.getMaximumWindowHeight() + " pixels!");
            this.windowHeight = Utils.getMaximumWindowHeight(); // User tried to make screen
            // size wider than they have
        }

        this.usingCustomJavaPath = Boolean.parseBoolean(properties.getProperty("usingcustomjavapath", "false"));

        if (isUsingCustomJavaPath()) {
            this.javaPath = properties.getProperty("javapath", Utils.getJavaHome());
        } else {
            this.javaPath = Utils.getJavaHome();
            if (this.isUsingMacApp()) {
                File oracleJava = new File(
                        "/Library/Internet Plug-Ins/JavaAppletPlugin" + "" + ".plugin/Contents/Home/bin/java");
                if (oracleJava.exists() && oracleJava.canExecute()) {
                    this.setJavaPath("/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home");
                }
            }
        }

        this.javaParamaters = properties.getProperty("javaparameters", "");

        this.maximiseMinecraft = Boolean.parseBoolean(properties.getProperty("maximiseminecraft", "false"));

        this.saveCustomMods = Boolean.parseBoolean(properties.getProperty("savecustommods", "true"));

        this.advancedBackup = Boolean.parseBoolean(properties.getProperty("advancedbackup", "false"));

        this.sortPacksAlphabetically = Boolean
                .parseBoolean(properties.getProperty("sortpacksalphabetically", "false"));

        this.keepLauncherOpen = Boolean.parseBoolean(properties.getProperty("keeplauncheropen", "true"));

        this.enableConsole = Boolean.parseBoolean(properties.getProperty("enableconsole", "true"));

        this.enableTrayIcon = Boolean.parseBoolean(properties.getProperty("enabletrayicon", "true"));

        this.enableLeaderboards = Boolean.parseBoolean(properties.getProperty("enableleaderboards", "false"));

        this.enableLogs = Boolean.parseBoolean(properties.getProperty("enablelogs", "true"));

        this.enableServerChecker = Boolean.parseBoolean(properties.getProperty("enableserverchecker", "false"));

        this.enableOpenEyeReporting = Boolean
                .parseBoolean(properties.getProperty("enableopeneyereporting", "true"));

        this.enableProxy = Boolean.parseBoolean(properties.getProperty("enableproxy", "false"));

        if (this.enableProxy) {
            this.proxyHost = properties.getProperty("proxyhost", null);

            this.proxyPort = Integer.parseInt(properties.getProperty("proxyport", "0"));
            if (this.proxyPort <= 0 || this.proxyPort > 65535) {
                // Proxy port is invalid so disable proxy
                LogManager.warn("Tried to set proxy port to " + this.proxyPort + " which is not a valid port! "
                        + "Proxy support disabled!");
                this.enableProxy = false;
            }

            this.proxyType = properties.getProperty("proxytype", "");
            if (!this.proxyType.equals("SOCKS") && !this.proxyType.equals("HTTP")
                    && !this.proxyType.equals("DIRECT")) {
                // Proxy type is invalid so disable proxy
                LogManager.warn("Tried to set proxy type to " + this.proxyType + " which is not valid! Proxy "
                        + "support disabled!");
                this.enableProxy = false;
            }
        } else {
            this.proxyHost = "";
            this.proxyPort = 0;
            this.proxyType = "";
        }

        this.serverCheckerWait = Integer.parseInt(properties.getProperty("servercheckerwait", "5"));
        if (this.serverCheckerWait < 1 || this.serverCheckerWait > 30) {
            // Server checker wait should be between 1 and 30
            LogManager.warn("Tried to set server checker wait to " + this.serverCheckerWait + " which is not "
                    + "valid! Must be between 1 and 30. Setting back to default of 5!");
            this.serverCheckerWait = 5;
        }

        this.concurrentConnections = Integer.parseInt(properties.getProperty("concurrentconnections", "8"));
        if (this.concurrentConnections < 1) {
            // Concurrent connections should be more than or equal to 1
            LogManager.warn("Tried to set the number of concurrent connections to " + this.concurrentConnections
                    + " which is not valid! Must be 1 or more. Setting back to default of 8!");
            this.concurrentConnections = 8;
        }

        this.daysOfLogsToKeep = Integer.parseInt(properties.getProperty("daysoflogstokeep", "7"));
        if (this.daysOfLogsToKeep < 1 || this.daysOfLogsToKeep > 30) {
            // Days of logs to keep should be 1 or more but less than 30
            LogManager.warn("Tried to set the number of days worth of logs to keep to " + this.daysOfLogsToKeep
                    + " which is not valid! Must be between 1 and 30 inclusive. Setting back to default of 7!");
            this.daysOfLogsToKeep = 7;
        }

        this.theme = properties.getProperty("theme", Constants.LAUNCHER_NAME);

        this.dateFormat = properties.getProperty("dateformat", "dd/M/yyy");
        if (!this.dateFormat.equalsIgnoreCase("dd/M/yyy") && !this.dateFormat.equalsIgnoreCase("M/dd/yyy")
                && !this.dateFormat.equalsIgnoreCase("yyy/M/dd")) {
            LogManager.warn("Tried to set the date format to " + this.dateFormat
                    + " which is not valid! Setting " + "back to default of dd/M/yyy!");
            this.dateFormat = "dd/M/yyy";
        }

        String lastAccountTemp = properties.getProperty("lastaccount", "");
        if (!lastAccountTemp.isEmpty()) {
            if (isAccountByName(lastAccountTemp)) {
                this.account = getAccountByName(lastAccountTemp);
            } else {
                LogManager.warn("The Account " + lastAccountTemp + " is no longer available. Logging out of "
                        + "Account!");
                this.account = null; // Account not found
            }
        }

        this.addedPacks = properties.getProperty("addedpacks", "");
        this.autoBackup = Boolean.parseBoolean(properties.getProperty("autobackup", "false"));
        this.notifyBackup = Boolean.parseBoolean(properties.getProperty("notifybackup", "true"));
        this.dropboxFolderLocation = properties.getProperty("dropboxlocation", "");
    } catch (FileNotFoundException e) {
        logStackTrace(e);
    } catch (IOException e) {
        logStackTrace(e);
    }
    LogManager.debug("Finished loading properties");
}

From source file:com.igniva.filemanager.activities.MainActivity.java

public void refreshDrawer() {
    List<String> val = DataUtils.getStorages();
    if (val == null)
        val = getStorageDirectories();
    ArrayList<Item> list = new ArrayList<>();
    storage_count = 0;/*from   ww w  .ja  v a 2  s.c o m*/
    for (String file : val) {
        File f = new File(file);
        String name;
        Drawable icon1 = ContextCompat.getDrawable(this, R.drawable.ic_sd_storage_white_56dp);
        if ("/storage/emulated/legacy".equals(file) || "/storage/emulated/0".equals(file)) {
            name = getResources().getString(R.string.storage);
        } else if ("/storage/sdcard1".equals(file)) {
            name = getResources().getString(R.string.extstorage);
        } else if ("/".equals(file)) {
            name = getResources().getString(R.string.rootdirectory);
            icon1 = ContextCompat.getDrawable(this, R.drawable.ic_drawer_root_white);
        } else
            name = f.getName();
        if (!f.isDirectory() || f.canExecute()) {
            storage_count++;
            list.add(new EntryItem(name, file, icon1));
        }
    }
    list.add(new SectionItem());
    ArrayList<String[]> Servers = DataUtils.getServers();
    if (Servers != null && Servers.size() > 0) {
        for (String[] file : Servers) {
            list.add(new EntryItem(file[0], file[1],
                    ContextCompat.getDrawable(this, R.drawable.ic_settings_remote_white_48dp)));
        }

        list.add(new SectionItem());
    }
    ArrayList<String[]> accounts = DataUtils.getAccounts();
    if (accounts != null && accounts.size() > 0) {
        Collections.sort(accounts, new BookSorter());
        for (String[] file : accounts) {
            list.add(new EntryItem(file[0], file[1], ContextCompat.getDrawable(this, R.drawable.drive)));
        }

        list.add(new SectionItem());
    }
    ArrayList<String[]> books = DataUtils.getBooks();
    if (books != null && books.size() > 0) {
        Collections.sort(books, new BookSorter());
        for (String[] file : books) {
            list.add(new EntryItem(file[0], file[1], ContextCompat.getDrawable(this, R.drawable.folder_fab)));
        }
        list.add(new SectionItem());
    }
    list.add(new EntryItem(getResources().getString(R.string.quick), "5",
            ContextCompat.getDrawable(this, R.drawable.ic_star_white_18dp)));
    list.add(new EntryItem(getResources().getString(R.string.recent), "6",
            ContextCompat.getDrawable(this, R.drawable.ic_history_white_48dp)));
    list.add(new EntryItem(getResources().getString(R.string.images), "0",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_image)));
    list.add(new EntryItem(getResources().getString(R.string.videos), "1",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_video_am)));
    list.add(new EntryItem(getResources().getString(R.string.audio), "2",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_audio_am)));
    list.add(new EntryItem(getResources().getString(R.string.documents), "3",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_doc_am)));
    list.add(new EntryItem(getResources().getString(R.string.apks), "4",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_apk_grid)));
    DataUtils.setList(list);
    adapter = new DrawerAdapter(con, list, MainActivity.this, Sp);
    mDrawerList.setAdapter(adapter);

}

From source file:com.amaze.filemanager.activities.MainActivity.java

public void refreshDrawer() {
    List<String> val = DataUtils.getStorages();
    if (val == null)
        val = getStorageDirectories();
    ArrayList<Item> list = new ArrayList<>();
    storage_count = 0;//from w w w  .  ja  v a  2 s  . c  o  m
    for (String file : val) {
        File f = new File(file);
        String name;
        Drawable icon1 = ContextCompat.getDrawable(this, R.drawable.ic_sd_storage_white_56dp);
        if ("/storage/emulated/legacy".equals(file) || "/storage/emulated/0".equals(file)) {
            name = getResources().getString(R.string.storage);
        } else if ("/storage/sdcard1".equals(file)) {
            name = getResources().getString(R.string.extstorage);
        } else if ("/".equals(file)) {
            name = getResources().getString(R.string.rootdirectory);
            icon1 = ContextCompat.getDrawable(this, R.drawable.ic_drawer_root_white);
        } else
            name = f.getName();
        if (!f.isDirectory() || f.canExecute()) {
            storage_count++;
            list.add(new EntryItem(name, file, icon1));
        }
    }
    list.add(new SectionItem());
    ArrayList<String[]> Servers = DataUtils.getServers();
    if (Servers != null && Servers.size() > 0) {
        for (String[] file : Servers) {
            list.add(new EntryItem(file[0], file[1],
                    ContextCompat.getDrawable(this, R.drawable.ic_settings_remote_white_48dp)));
        }

        list.add(new SectionItem());
    }
    ArrayList<String[]> accounts = DataUtils.getAccounts();
    if (accounts != null && accounts.size() > 0) {
        for (String[] file : accounts) {
            list.add(new EntryItem(file[0], file[1], ContextCompat.getDrawable(this, R.drawable.drive)));
        }

        list.add(new SectionItem());
    }
    ArrayList<String[]> books = DataUtils.getBooks();
    if (books != null && books.size() > 0) {

        for (String[] file : books) {
            list.add(new EntryItem(file[0], file[1], ContextCompat.getDrawable(this, R.drawable.folder_fab)));
        }
        list.add(new SectionItem());
    }
    list.add(new EntryItem(getResources().getString(R.string.quick), "5",
            ContextCompat.getDrawable(this, R.drawable.ic_star_white_18dp)));
    list.add(new EntryItem(getResources().getString(R.string.recent), "6",
            ContextCompat.getDrawable(this, R.drawable.ic_history_white_48dp)));
    list.add(new EntryItem(getResources().getString(R.string.images), "0",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_image)));
    list.add(new EntryItem(getResources().getString(R.string.videos), "1",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_video_am)));
    list.add(new EntryItem(getResources().getString(R.string.audio), "2",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_audio_am)));
    list.add(new EntryItem(getResources().getString(R.string.documents), "3",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_doc_am)));
    list.add(new EntryItem(getResources().getString(R.string.apks), "4",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_apk_grid)));
    DataUtils.setList(list);
    adapter = new DrawerAdapter(con, list, MainActivity.this, Sp);
    mDrawerList.setAdapter(adapter);

}

From source file:com.filemanager.free.activities.MainActivity.java

public void refreshDrawer() {
    List<String> val = DataUtils.getStorages();
    if (val == null)
        val = getStorageDirectories();
    ArrayList<Item> list = new ArrayList<>();
    storage_count = 0;//  ww w .java  2 s.c  o  m
    for (String file : val) {
        File f = new File(file);
        String name;
        Drawable icon1 = ContextCompat.getDrawable(this, R.drawable.ic_memory_white_24dp);
        if ("/storage/emulated/legacy".equals(file) || "/storage/emulated/0".equals(file)) {
            name = getResources().getString(R.string.storage);
            icon1 = ContextCompat.getDrawable(this, R.drawable.ic_sd_storage_white_24dp);
        } else if ("/storage/sdcard1".equals(file)) {
            name = getResources().getString(R.string.extstorage);
        } else if ("/".equals(file)) {
            name = getResources().getString(R.string.rootdirectory);
            icon1 = ContextCompat.getDrawable(this, R.drawable.ic_security_white_24dp);
        } else
            name = f.getName();
        if (!f.isDirectory() || f.canExecute()) {
            storage_count++;
            list.add(new EntryItem(name, file, icon1));
        }
    }
    list.add(new SectionItem());
    ArrayList<String[]> Servers = DataUtils.getServers();
    if (Servers != null && Servers.size() > 0) {
        for (String[] file : Servers) {
            list.add(new EntryItem(file[0], file[1],
                    ContextCompat.getDrawable(this, R.drawable.ic_settings_remote_white_48dp)));
        }

        list.add(new SectionItem());
    }
    ArrayList<String[]> accounts = DataUtils.getAccounts();
    if (accounts != null && accounts.size() > 0) {
        Collections.sort(accounts, new BookSorter());
        for (String[] file : accounts) {
            list.add(new EntryItem(file[0], file[1], ContextCompat.getDrawable(this, R.drawable.drive)));
        }

        list.add(new SectionItem());
    }
    ArrayList<String[]> books = DataUtils.getBooks();
    if (books != null && books.size() > 0) {
        Collections.sort(books, new BookSorter());
        for (String[] file : books) {
            list.add(new EntryItem(file[0], file[1], ContextCompat.getDrawable(this, R.drawable.folder_fab)));
        }
        list.add(new SectionItem());
    }
    list.add(new EntryItem(getResources().getString(R.string.quick), "5",
            ContextCompat.getDrawable(this, R.drawable.ic_star_white_18dp)));
    list.add(new EntryItem(getResources().getString(R.string.recent), "6",
            ContextCompat.getDrawable(this, R.drawable.ic_history_white_48dp)));
    list.add(new EntryItem(getResources().getString(R.string.images), "0",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_image)));
    list.add(new EntryItem(getResources().getString(R.string.videos), "1",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_video_am)));
    list.add(new EntryItem(getResources().getString(R.string.audio), "2",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_audio_am)));
    list.add(new EntryItem(getResources().getString(R.string.documents), "3",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_doc_am)));
    list.add(new EntryItem(getResources().getString(R.string.apks), "4",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_apk_grid)));
    DataUtils.setList(list);
    adapter = new DrawerAdapter(con, list, MainActivity.this, Sp);
    mDrawerList.setAdapter(adapter);

}

From source file:com.amaze.filemanager.activities.MainActivity.java

public void updateDrawer() {
    ArrayList<Item> list = new ArrayList<>();
    List<String> val = getStorageDirectories();
    ArrayList<String[]> books = new ArrayList<>();
    ArrayList<String[]> Servers = new ArrayList<>();
    ArrayList<String[]> accounts = new ArrayList<>();
    storage_count = 0;// w  w  w .j  ava 2 s. c  o m
    for (String file : val) {
        File f = new File(file);
        String name;
        Drawable icon1 = ContextCompat.getDrawable(this, R.drawable.ic_sd_storage_white_56dp);
        if ("/storage/emulated/legacy".equals(file) || "/storage/emulated/0".equals(file)) {
            name = getResources().getString(R.string.storage);

        } else if ("/storage/sdcard1".equals(file)) {
            name = getResources().getString(R.string.extstorage);
        } else if ("/".equals(file)) {
            name = getResources().getString(R.string.rootdirectory);
            icon1 = ContextCompat.getDrawable(this, R.drawable.ic_drawer_root_white);
        } else
            name = f.getName();
        if (!f.isDirectory() || f.canExecute()) {
            storage_count++;
            list.add(new EntryItem(name, file, icon1));
        }
    }
    DataUtils.setStorages(val);
    list.add(new SectionItem());
    try {
        for (String[] file : grid.readTableSecondary(DataUtils.SMB))
            Servers.add(file);
        DataUtils.setServers(Servers);
        if (Servers.size() > 0) {
            Collections.sort(Servers, new BookSorter());
            for (String[] file : Servers)
                list.add(new EntryItem(file[0], file[1],
                        ContextCompat.getDrawable(this, R.drawable.ic_settings_remote_white_48dp)));
            list.add(new SectionItem());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        for (String[] file : grid.readTableSecondary(DataUtils.DRIVE)) {
            accounts.add(file);
        }
        DataUtils.setAccounts(accounts);
        if (accounts.size() > 0) {
            Collections.sort(accounts, new BookSorter());
            for (String[] file : accounts)
                list.add(new EntryItem(file[0], file[1], ContextCompat.getDrawable(this, R.drawable.drive)));
            list.add(new SectionItem());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        for (String[] file : grid.readTableSecondary(DataUtils.BOOKS)) {
            books.add(file);
        }
        DataUtils.setBooks(books);
        if (books.size() > 0) {
            Collections.sort(books, new BookSorter());
            for (String[] file : books)
                list.add(new EntryItem(file[0], file[1],
                        ContextCompat.getDrawable(this, R.drawable.folder_fab)));
            list.add(new SectionItem());
        }
    } catch (Exception e) {

    }
    list.add(new EntryItem(getResources().getString(R.string.quick), "5",
            ContextCompat.getDrawable(this, R.drawable.ic_star_white_18dp)));
    list.add(new EntryItem(getResources().getString(R.string.recent), "6",
            ContextCompat.getDrawable(this, R.drawable.ic_history_white_48dp)));
    list.add(new EntryItem(getResources().getString(R.string.images), "0",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_image)));
    list.add(new EntryItem(getResources().getString(R.string.videos), "1",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_video_am)));
    list.add(new EntryItem(getResources().getString(R.string.audio), "2",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_audio_am)));
    list.add(new EntryItem(getResources().getString(R.string.documents), "3",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_doc_am)));
    list.add(new EntryItem(getResources().getString(R.string.apks), "4",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_apk_grid)));
    DataUtils.setList(list);
    adapter = new DrawerAdapter(this, list, MainActivity.this, Sp);
    mDrawerList.setAdapter(adapter);
}

From source file:com.filemanager.free.activities.MainActivity.java

public void updateDrawer() {
    ArrayList<Item> list = new ArrayList<>();
    List<String> val = getStorageDirectories();
    ArrayList<String[]> books = new ArrayList<>();
    ArrayList<String[]> Servers = new ArrayList<>();
    ArrayList<String[]> accounts = new ArrayList<>();
    storage_count = 0;//from www.  j av a2  s.  c o  m
    for (String file : val) {
        File f = new File(file);
        String name;
        Drawable icon1 = ContextCompat.getDrawable(this, R.drawable.ic_sd_storage_white_24dp);
        if ("/storage/emulated/legacy".equals(file) || "/storage/emulated/0".equals(file)) {
            name = getResources().getString(R.string.storage);
            icon1 = ContextCompat.getDrawable(this, R.drawable.ic_memory_white_24dp);
        } else if ("/storage/sdcard1".equals(file)) {
            name = getResources().getString(R.string.extstorage);
        } else if ("/".equals(file)) {
            name = getResources().getString(R.string.rootdirectory);
            icon1 = ContextCompat.getDrawable(this, R.drawable.ic_security_white_24dp);
        } else
            name = f.getName();
        if (!f.isDirectory() || f.canExecute()) {
            storage_count++;
            list.add(new EntryItem(name, file, icon1));
        }
    }
    DataUtils.setStorages(val);
    list.add(new SectionItem());
    try {
        for (String[] file : grid.readTableSecondary(DataUtils.SMB))
            Servers.add(file);
        DataUtils.setServers(Servers);
        if (Servers.size() > 0) {
            Collections.sort(Servers, new BookSorter());
            for (String[] file : Servers)
                list.add(new EntryItem(file[0], file[1],
                        ContextCompat.getDrawable(this, R.drawable.ic_settings_remote_white_48dp)));
            list.add(new SectionItem());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        for (String[] file : grid.readTableSecondary(DataUtils.DRIVE)) {
            accounts.add(file);
        }
        DataUtils.setAccounts(accounts);
        if (accounts.size() > 0) {
            Collections.sort(accounts, new BookSorter());
            for (String[] file : accounts)
                list.add(new EntryItem(file[0], file[1], ContextCompat.getDrawable(this, R.drawable.drive)));
            list.add(new SectionItem());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        for (String[] file : grid.readTableSecondary(DataUtils.BOOKS)) {
            books.add(file);
        }
        DataUtils.setBooks(books);
        if (books.size() > 0) {
            Collections.sort(books, new BookSorter());
            for (String[] file : books)
                list.add(new EntryItem(file[0], file[1],
                        ContextCompat.getDrawable(this, R.drawable.folder_fab)));
            list.add(new SectionItem());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    list.add(new EntryItem(getResources().getString(R.string.quick), "5",
            ContextCompat.getDrawable(this, R.drawable.ic_star_white_18dp)));
    list.add(new EntryItem(getResources().getString(R.string.recent), "6",
            ContextCompat.getDrawable(this, R.drawable.ic_history_white_48dp)));
    list.add(new EntryItem(getResources().getString(R.string.images), "0",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_image)));
    list.add(new EntryItem(getResources().getString(R.string.videos), "1",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_video_am)));
    list.add(new EntryItem(getResources().getString(R.string.audio), "2",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_audio_am)));
    list.add(new EntryItem(getResources().getString(R.string.documents), "3",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_doc_am)));
    list.add(new EntryItem(getResources().getString(R.string.apks), "4",
            ContextCompat.getDrawable(this, R.drawable.ic_doc_apk_grid)));
    DataUtils.setList(list);
    adapter = new DrawerAdapter(con, list, MainActivity.this, Sp);
    mDrawerList.setAdapter(adapter);
}

From source file:com.amaze.carbonfilemanager.activities.MainActivity.java

public void refreshDrawer() {

    ArrayList<Item> sectionItems = new ArrayList<>();
    ArrayList<String> storageDirectories = getStorageDirectories();
    ArrayList<String[]> books = new ArrayList<>();
    ArrayList<String[]> servers = new ArrayList<>();
    storage_count = 0;//from www . j  a  va  2s.c  o m
    for (String file : storageDirectories) {
        File f = new File(file);
        String name;
        Drawable icon1 = ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_sd_storage_white_56dp);
        if ("/storage/emulated/legacy".equals(file) || "/storage/emulated/0".equals(file)) {
            name = getResources().getString(R.string.storage);
        } else if ("/storage/sdcard1".equals(file)) {
            name = getResources().getString(R.string.extstorage);
        } else if ("/".equals(file)) {
            name = getResources().getString(R.string.rootdirectory);
            icon1 = ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_drawer_root_white);
        } else if (file.contains(OTGUtil.PREFIX_OTG)) {
            name = "OTG";
            icon1 = ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_usb_white_48dp);
        } else
            name = f.getName();
        if (!f.isDirectory() || f.canExecute()) {
            storage_count++;
            sectionItems.add(new EntryItem(name, file, icon1));
        }
    }
    dataUtils.setStorages(storageDirectories);
    sectionItems.add(new SectionItem());
    try {
        for (String[] file : grid.readTableSecondary(DataUtils.SMB))
            servers.add(file);
        dataUtils.setServers(servers);
        if (servers.size() > 0) {
            Collections.sort(servers, new BookSorter());
            for (String[] file : servers)
                sectionItems.add(new EntryItem(file[0], file[1], ContextCompat.getDrawable(MainActivity.this,
                        R.drawable.ic_settings_remote_white_48dp)));
            sectionItems.add(new SectionItem());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    ArrayList<String[]> accountAuthenticationList = new ArrayList<>();

    if (CloudSheetFragment.isCloudProviderAvailable(MainActivity.this)) {

        for (CloudStorage cloudStorage : dataUtils.getAccounts()) {

            if (cloudStorage instanceof Dropbox) {

                sectionItems.add(new EntryItem(CloudHandler.CLOUD_NAME_DROPBOX,
                        CloudHandler.CLOUD_PREFIX_DROPBOX + "/",
                        ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_dropbox_white_24dp)));

                accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_DROPBOX,
                        CloudHandler.CLOUD_PREFIX_DROPBOX + "/", });
            } else if (cloudStorage instanceof Box) {

                sectionItems.add(new EntryItem(CloudHandler.CLOUD_NAME_BOX, CloudHandler.CLOUD_PREFIX_BOX + "/",
                        ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_box_white_24dp)));

                accountAuthenticationList.add(
                        new String[] { CloudHandler.CLOUD_NAME_BOX, CloudHandler.CLOUD_PREFIX_BOX + "/", });
            } else if (cloudStorage instanceof OneDrive) {

                sectionItems.add(new EntryItem(CloudHandler.CLOUD_NAME_ONE_DRIVE,
                        CloudHandler.CLOUD_PREFIX_ONE_DRIVE + "/",
                        ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_onedrive_white_24dp)));

                accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_ONE_DRIVE,
                        CloudHandler.CLOUD_PREFIX_ONE_DRIVE + "/", });
            } else if (cloudStorage instanceof GoogleDrive) {

                sectionItems.add(new EntryItem(CloudHandler.CLOUD_NAME_GOOGLE_DRIVE,
                        CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE + "/",
                        ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_google_drive_white_24dp)));

                accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_GOOGLE_DRIVE,
                        CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE + "/", });
            }
        }
        Collections.sort(accountAuthenticationList, new BookSorter());

        if (accountAuthenticationList.size() != 0)
            sectionItems.add(new SectionItem());
    }

    if (!sharedPref.contains(FoldersPref.KEY)) {
        for (String[] file : grid.readTableSecondary(DataUtils.BOOKS)) {
            books.add(file);
        }
    } else {
        ArrayList<FoldersPref.Shortcut> booksPref = FoldersPref.castStringListToTrioList(
                TinyDB.getList(sharedPref, String.class, FoldersPref.KEY, new ArrayList<String>()));

        for (FoldersPref.Shortcut t : booksPref) {
            if (t.enabled) {
                books.add(new String[] { t.name, t.directory });
            }
        }
    }
    dataUtils.setBooks(books);
    if (sharedPref.getBoolean(PREFERENCE_SHOW_SIDEBAR_FOLDERS, true)) {
        if (books.size() > 0) {
            if (!sharedPref.contains(FoldersPref.KEY)) {
                Collections.sort(books, new BookSorter());
            }

            for (String[] file : books) {
                sectionItems.add(new EntryItem(file[0], file[1],
                        ContextCompat.getDrawable(MainActivity.this, R.drawable.folder_fab)));
            }
            sectionItems.add(new SectionItem());
        }
    }

    Boolean[] quickAccessPref = TinyDB.getBooleanArray(sharedPref, QuickAccessPref.KEY,
            QuickAccessPref.DEFAULT);

    if (sharedPref.getBoolean(PREFERENCE_SHOW_SIDEBAR_QUICKACCESSES, true)) {
        if (quickAccessPref[0])
            sectionItems.add(new EntryItem(getResources().getString(R.string.quick), "5",
                    ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_star_white_18dp)));
        if (quickAccessPref[1])
            sectionItems.add(new EntryItem(getResources().getString(R.string.recent), "6",
                    ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_history_white_48dp)));
        if (quickAccessPref[2])
            sectionItems.add(new EntryItem(getResources().getString(R.string.images), "0",
                    ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_doc_image)));
        if (quickAccessPref[3])
            sectionItems.add(new EntryItem(getResources().getString(R.string.videos), "1",
                    ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_doc_video_am)));
        if (quickAccessPref[4])
            sectionItems.add(new EntryItem(getResources().getString(R.string.audio), "2",
                    ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_doc_audio_am)));
        if (quickAccessPref[5])
            sectionItems.add(new EntryItem(getResources().getString(R.string.documents), "3",
                    ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_doc_doc_am)));
        if (quickAccessPref[6])
            sectionItems.add(new EntryItem(getResources().getString(R.string.apks), "4",
                    ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_doc_apk_grid)));
    } else {
        sectionItems.remove(sectionItems.size() - 1); //Deletes last divider
    }

    dataUtils.setList(sectionItems);

    adapter = new DrawerAdapter(MainActivity.this, MainActivity.this, sectionItems, MainActivity.this,
            sharedPref);
    mDrawerList.setAdapter(adapter);
}

From source file:hd3gtv.mydmam.useraction.fileoperation.CopyMove.java

private void copyFile(File source_file, File destination_file) throws IOException {
    if (destination_file.exists()) {
        Log2Dump dump = new Log2Dump();
        dump.add("source_file", source_file);
        dump.add("destination_file", destination_file);
        dump.add("delete_after_copy", delete_after_copy);

        if (fileexistspolicy == FileExistsPolicy.IGNORE) {
            Log2.log.debug("Destination file exists, ignore copy/move", dump);
            return;
        } else if (fileexistspolicy == FileExistsPolicy.OVERWRITE) {
            Log2.log.debug("Destination file exists, overwrite it", dump);
            FileUtils.forceDelete(destination_file);
        } else if (fileexistspolicy == FileExistsPolicy.RENAME) {
            // destination_file
            int cursor = 1;
            int dot_pos;
            StringBuilder sb;/*ww  w  . j  a v  a2 s . c  o  m*/
            while (destination_file.exists()) {
                sb = new StringBuilder();
                sb.append(destination_file.getParent());
                sb.append(File.separator);
                dot_pos = destination_file.getName().lastIndexOf(".");
                if (dot_pos > 0) {
                    sb.append(destination_file.getName().substring(0, dot_pos));
                    sb.append(" (");
                    sb.append(cursor);
                    sb.append(")");
                    sb.append(
                            destination_file.getName().substring(dot_pos, destination_file.getName().length()));
                } else {
                    sb.append(destination_file.getName());
                    sb.append(" (");
                    sb.append(cursor);
                    sb.append(")");
                }
                destination_file = new File(sb.toString());
                cursor++;
            }
            dump.add("new destination file name", destination_file);
            Log2.log.debug("Destination file exists, change destionation name", dump);
        }
    }
    /**
     * Imported from org.apache.commons.io.FileUtils
     * Licensed to the Apache Software Foundation,
     * http://www.apache.org/licenses/LICENSE-2.0
     */
    FileInputStream fis = null;
    FileOutputStream fos = null;
    FileChannel input = null;
    FileChannel output = null;
    try {
        fis = new FileInputStream(source_file);
        fos = new FileOutputStream(destination_file);
        input = fis.getChannel();
        output = fos.getChannel();
        long size = input.size();
        long pos = 0;
        long count = 0;
        while (pos < size) {
            count = (size - pos) > FIFTY_MB ? FIFTY_MB : (size - pos);
            pos += output.transferFrom(input, pos, count);

            if (progression != null) {
                actual_progress_value = (int) ((pos + progress_copy) / (1024 * 1024));
                if (actual_progress_value > last_progress_value) {
                    last_progress_value = actual_progress_value;
                    progression.updateProgress(actual_progress_value, progress_size);
                }
            }
        }
    } finally {
        IOUtils.closeQuietly(output);
        IOUtils.closeQuietly(fos);
        IOUtils.closeQuietly(input);
        IOUtils.closeQuietly(fis);
    }

    if (source_file.length() != destination_file.length()) {
        throw new IOException(
                "Failed to copy full contents from '" + source_file + "' to '" + destination_file + "'");
    }
    if (destination_file.setExecutable(source_file.canExecute()) == false) {
        Log2.log.error("Can't set Executable status to dest file", new IOException(destination_file.getPath()));
    }
    if (destination_file.setLastModified(source_file.lastModified()) == false) {
        Log2.log.error("Can't set LastModified status to dest file",
                new IOException(destination_file.getPath()));
    }
}