Archive for May, 2008

File Browser

Posted in News on May 15th, 2008 by matt

As a learning exercise, to get used to have a go at putting an android UI together I (matt) have been working on a File Browser.

Here’s a few screen shots of the nearly finished article:

Failed, but hey maybe next time

Posted in News on May 12th, 2008 by matt

No luck in the Android contest, but hey as we only had like 3 weeks to learn the platform and write the application, it wasn’t really unexpected. Congratulations to everyone who did make the top 50.
Looking forward to seeing some of the entries…

Andy Rubin demos android on a 300Mhz touch screen device

Posted in News on May 7th, 2008 by matt

Browsing about and found this http://blip.tv/file/698098/

Dos style file filter

Posted in General Java on May 7th, 2008 by matt

Can’t remember which forum I found this on, but I’m pretty sure it wasn’t licensed, if I am wrong then please contact me.

The following class can be used with ListFiles to filter the files returned using dos style * and ? wildcards.

        public class RegexFilenameFilter implements FilenameFilter {
                String _regex = null; // setting the filter regex to null causes any

                // name to be accepted (same as ".*")
                public RegexFilenameFilter() {
                }

                /**
                 * Set the filter from a wildcard expression as known from the windows
                 * command line ("?" = "any character", "*" = zero or more occurances of
                 * any character")
                 *
                 * @param sWild
                 *            the wildcard pattern
                 *
                 * @return this
                 */

                public RegexFilenameFilter setWildcard(String sWild) {
                        _regex = wildcardToRegex(sWild);
                        Pattern.compile(_regex);
                        return this;
                }

                /**
                 * Set the regular expression of the filter
                 *
                 * @param regex
                 *            the regular expression of the filter
                 *
                 * @return this
                 */

                public RegexFilenameFilter setRegex(String regex)
                                throws java.util.regex.PatternSyntaxException {
                        _regex = regex.toLowerCase();
                        Pattern.compile(_regex); // throw PatternSyntaxException if the
                        // pattern is not valid
                        return this;
                }

                /**
                 * Tests if a specified file should be included in a file list.
                 *
                 * @param dir
                 *            the directory in which the file was found.
                 *
                 * @param name
                 *            the name of the file.
                 *
                 * @return true if and only if the name should be included in the file
                 *         list; false otherwise.
                 */

                public boolean accept(File dir, String name) {
                        boolean bAccept;

                        if (_regex == null)
                                bAccept = true;
                        else
                                bAccept = name.toLowerCase().matches(_regex);

                        return bAccept;
                }

                /**
                 * Converts a windows wildcard pattern to a regex pattern
                 *
                 * @param wild -
                 *            Wildcard patter containing * and ?
                 *
                 * @return - a regex pattern that is equivalent to the windows wildcard
                 *         pattern
                 */

                private String wildcardToRegex(String wild) {
                        if (wild == null)
                                return null;

                        StringBuffer buffer = new StringBuffer();

                        char[] chars = wild.toCharArray();

                        for (int i = 0; i < chars.length; ++i) {
                                if (chars[i] == ‘*’)
                                        buffer.append(".*");
                                else if (chars[i] == ‘?’)
                                        buffer.append(".");
                                else if ("+()^$.{}[]|".indexOf(chars[i]) != -1)
                                        buffer.append(\\).append(chars[i]);
                                else
                                        buffer.append(chars[i]);
                        }

                        return buffer.toString().toLowerCase();
                }
        }
 

create an isntance, call setWidcard, then pass to listFiles.