From cca9be466e3de0ac5703bd7bfa4b1d9378240541 Mon Sep 17 00:00:00 2001 From: John Reck Date: Fri, 13 Apr 2012 13:40:46 -0700 Subject: Sort files & folders in directory list Change-Id: I2eef1c989150d97266659d615d09edfdad322d2e --- src/com/android/browser/homepages/RequestHandler.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/com/android/browser') diff --git a/src/com/android/browser/homepages/RequestHandler.java b/src/com/android/browser/homepages/RequestHandler.java index b3a03b9..13b52e3 100644 --- a/src/com/android/browser/homepages/RequestHandler.java +++ b/src/com/android/browser/homepages/RequestHandler.java @@ -37,6 +37,8 @@ import java.io.InputStream; import java.io.OutputStream; import java.text.DateFormat; import java.text.DecimalFormat; +import java.util.Arrays; +import java.util.Comparator; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -140,9 +142,20 @@ public class RequestHandler extends Thread { t.write(mOutput); } + private static final Comparator sFileComparator = new Comparator() { + @Override + public int compare(File lhs, File rhs) { + if (lhs.isDirectory() != rhs.isDirectory()) { + return lhs.isDirectory() ? -1 : 1; + } + return lhs.getName().compareTo(rhs.getName()); + } + }; + void writeFolderIndex() throws IOException { File f = new File(mUri.getPath()); final File[] files = f.listFiles(); + Arrays.sort(files, sFileComparator); Template t = Template.getCachedTemplate(mContext, R.raw.folder_view); t.assign("path", mUri.getPath()); t.assign("parent_url", f.getParent() != null ? f.getParent() : f.getPath()); -- cgit v1.1