Search in sources :

Example 1 with XmlRes

use of android.support.annotation.XmlRes in project robotcode by OutoftheBoxFTC.

the class RobotConfigFileManager method getXMLFiles.

/**
 * Gets the list of files from the Configuration File directory, and populates the global list
 * used by the fileSpinner. Note that this should only ever be executed on the robot controller,
 * not the driver station, as the robot controller is the authoritative source of configurations.
 */
public ArrayList<RobotConfigFile> getXMLFiles() {
    File robotDir = AppUtil.CONFIG_FILES_DIR;
    File[] configFiles = robotDir.listFiles();
    ArrayList<RobotConfigFile> fileList = new ArrayList<RobotConfigFile>();
    for (File f : configFiles) {
        if (f.isFile()) {
            String name = f.getName();
            Pattern pattern = Pattern.compile("(?i).xml");
            if (pattern.matcher(name).find()) {
                String nameNoExt = stripFileNameExtension(name);
                fileList.add(new RobotConfigFile(this, nameNoExt));
            }
        }
    }
    /*
         * Pull the cached list of filtered resources
         */
    for (@XmlRes int id : getXmlResourceIds()) {
        /**
         * With file-based configurations, the name of the configuration always
         * matches the name of the file in which the XML is stored. And by default,
         * the same is similarly true of resource-based configurations. Unfortunately,
         * however, resource names have significant syntax restrictions on them. To
         * work around this limitation, the name of a resource-based configuration
         * may optionally be taken from the "name" attribute of the root element.
         */
        XmlResourceParser xpp = resources.getXml(id);
        String name = RobotConfigResFilter.getRootAttribute(xpp, RobotConfigResFilter.robotConfigRootTag, "name", resources.getResourceEntryName(id));
        // Avoid duplicate names
        RobotConfigFile configFile = new RobotConfigFile(name, id);
        if (!configFile.containedIn(fileList)) {
            fileList.add(configFile);
        }
    }
    return fileList;
}
Also used : Pattern(java.util.regex.Pattern) XmlResourceParser(android.content.res.XmlResourceParser) XmlRes(android.support.annotation.XmlRes) ArrayList(java.util.ArrayList) File(java.io.File)

Example 2 with XmlRes

use of android.support.annotation.XmlRes in project robotcode by OutoftheBoxFTC.

the class RobotConfigFileManager method getXMLTemplates.

public ArrayList<RobotConfigFile> getXMLTemplates() {
    ArrayList<RobotConfigFile> templateList = new ArrayList<RobotConfigFile>();
    for (@XmlRes int id : getXmlResourceTemplateIds()) {
        /**
         *  @see #getXMLFiles()
         */
        XmlResourceParser xpp = resources.getXml(id);
        String name = RobotConfigResFilter.getRootAttribute(xpp, RobotConfigResFilter.robotConfigRootTag, "name", resources.getResourceEntryName(id));
        // Avoid duplicate names
        RobotConfigFile configFile = new RobotConfigFile(name, id);
        if (!configFile.containedIn(templateList)) {
            templateList.add(configFile);
        }
    }
    return templateList;
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) XmlRes(android.support.annotation.XmlRes) ArrayList(java.util.ArrayList)

Aggregations

XmlResourceParser (android.content.res.XmlResourceParser)2 XmlRes (android.support.annotation.XmlRes)2 ArrayList (java.util.ArrayList)2 File (java.io.File)1 Pattern (java.util.regex.Pattern)1