Kaydet (Commit) bc7300a7 authored tarafından Siqi Liu's avatar Siqi Liu

formatting for consistancy across Java code

Change-Id: I4d53376ea1b5ffa158cbb3412353c3cf5ba860d5
üst 620e40b3
...@@ -139,11 +139,13 @@ public class LibreOfficeMainActivity extends ActionBarActivity { ...@@ -139,11 +139,13 @@ public class LibreOfficeMainActivity extends ActionBarActivity {
if (getIntent().getData().getScheme().equals(ContentResolver.SCHEME_CONTENT)) { if (getIntent().getData().getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
if (copyFileToTemp() && mTempFile != null) { if (copyFileToTemp() && mTempFile != null) {
mInputFile = mTempFile.getPath(); mInputFile = mTempFile.getPath();
Log.d(LOGTAG, "SCHEME_CONTENT: getPath(): " + getIntent().getData().getPath());
} else { } else {
// TODO: can't open the file // TODO: can't open the file
} }
} else if (getIntent().getData().getScheme().equals(ContentResolver.SCHEME_FILE)) { } else if (getIntent().getData().getScheme().equals(ContentResolver.SCHEME_FILE)) {
mInputFile = getIntent().getData().getPath(); mInputFile = getIntent().getData().getPath();
Log.d(LOGTAG, "SCHEME_FILE: getPath(): " + getIntent().getData().getPath());
} }
} else { } else {
mInputFile = DEFAULT_DOC_PATH; mInputFile = DEFAULT_DOC_PATH;
......
...@@ -42,7 +42,7 @@ public class FileUtilities { ...@@ -42,7 +42,7 @@ public class FileUtilities {
/** Smallest Files First */ /** Smallest Files First */
static final int SORT_SMALLEST = 5; static final int SORT_SMALLEST = 5;
private static final Map<String,Integer> mExtnMap = new HashMap<String,Integer>(); private static final Map<String, Integer> mExtnMap = new HashMap<String, Integer>();
private static final Map<String, String> extensionToMimeTypeMap = new HashMap<String, String>(); private static final Map<String, String> extensionToMimeTypeMap = new HashMap<String, String>();
static { static {
// Please keep this in sync with AndroidManifest.xml // Please keep this in sync with AndroidManifest.xml
...@@ -117,8 +117,7 @@ public class FileUtilities { ...@@ -117,8 +117,7 @@ public class FileUtilities {
extensionToMimeTypeMap.put("oth", "application/vnd.oasis.opendocument.text-web"); extensionToMimeTypeMap.put("oth", "application/vnd.oasis.opendocument.text-web");
} }
private static final String getExtension(String filename) private static final String getExtension(String filename) {
{
if (filename == null) if (filename == null)
return ""; return "";
int nExt = filename.lastIndexOf('.'); int nExt = filename.lastIndexOf('.');
...@@ -127,26 +126,23 @@ public class FileUtilities { ...@@ -127,26 +126,23 @@ public class FileUtilities {
return filename.substring(nExt); return filename.substring(nExt);
} }
private static final int lookupExtension(String filename) private static final int lookupExtension(String filename) {
{ String extn = getExtension(filename);
String extn = getExtension (filename);
if (!mExtnMap.containsKey(extn)) if (!mExtnMap.containsKey(extn))
return UNKNOWN; return UNKNOWN;
return mExtnMap.get (extn); return mExtnMap.get(extn);
} }
static int getType(String filename) static int getType(String filename) {
{
int type = lookupExtension (filename); int type = lookupExtension (filename);
android.util.Log.d("debug", "extn : " + filename + " -> " + type); Log.d("debug", "extn : " + filename + " -> " + type);
return type; return type;
} }
static String getMimeType(String filename) static String getMimeType(String filename) {
{
String extension = MimeTypeMap.getFileExtensionFromUrl(filename); String extension = MimeTypeMap.getFileExtensionFromUrl(filename);
String mime = extensionToMimeTypeMap.get(extension); String mime = extensionToMimeTypeMap.get(extension);
if(mime == null) { if (mime == null) {
//fallback to Android's MimeTypeMap //fallback to Android's MimeTypeMap
mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension( mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
extension); extension);
...@@ -155,100 +151,96 @@ public class FileUtilities { ...@@ -155,100 +151,96 @@ public class FileUtilities {
} }
// Filter by mode, and/or in future by filename/wildcard // Filter by mode, and/or in future by filename/wildcard
static private boolean doAccept(String filename, int byMode, String byFilename) static private boolean doAccept(String filename, int byMode, String byFilename) {
{ Log.d("debug", "doAccept : " + filename + " mode " + byMode + " byFilename " + byFilename);
android.util.Log.d("debug", "doAccept : " + filename + " mode " + byMode + " byFilename " + byFilename); if (filename == null)
if (filename == null)
return false;
if (byMode == ALL && byFilename == "") {
if( filename.startsWith(".")) {//ignore hidden files
return false; return false;
if (byMode == ALL && byFilename == "") {
if (filename.startsWith(".")) {//ignore hidden files
return false;
}
return true;
}
// check extension
if (byMode != ALL) {
if (mExtnMap.get (getExtension (filename)) != byMode)
return false;
}
if (byFilename != "") {
// FIXME return false on a non-match
} }
return true; return true;
} }
// check extension
if (byMode != ALL) {
if (mExtnMap.get (getExtension (filename)) != byMode)
return false;
}
if (byFilename != "") {
// FIXME return false on a non-match
}
return true;
}
static FileFilter getFileFilter(final int mode) static FileFilter getFileFilter(final int mode) {
{ return new FileFilter() {
return new FileFilter() { public boolean accept(File pathname) {
public boolean accept(File pathname) { if (pathname.isDirectory())
if (pathname.isDirectory()) return true;
return true; if (lookupExtension(pathname.getName()) == UNKNOWN)
if( lookupExtension(pathname.getName()) == UNKNOWN) return false;
return false; return doAccept(pathname.getName(), mode, "");
return doAccept(pathname.getName(), mode, ""); }
} };
};
} }
static FilenameFilter getFilenameFilter(final int mode) static FilenameFilter getFilenameFilter(final int mode) {
{
return new FilenameFilter() { return new FilenameFilter() {
public boolean accept(File dir, String filename) { public boolean accept(File dir, String filename) {
if( new File( dir , filename ).isDirectory() ) if (new File(dir , filename).isDirectory())
return true; return true;
return doAccept(filename, mode, ""); return doAccept(filename, mode, "");
} }
}; };
} }
static void sortFiles(File[] files , int sortMode) static void sortFiles(File[] files, int sortMode) {
{
// Should really change all this to a switch statement... // Should really change all this to a switch statement...
if( sortMode == SORT_AZ ){ if (sortMode == SORT_AZ) {
Arrays.sort( files , new Comparator<File>() { Arrays.sort(files , new Comparator<File>() {
public int compare(File lhs, File rhs) { public int compare(File lhs, File rhs) {
return lhs.getName().compareTo( rhs.getName() ); return lhs.getName().compareTo(rhs.getName());
} }
}); });
return; return;
} }
if( sortMode == SORT_ZA ){ if (sortMode == SORT_ZA) {
Arrays.sort( files , new Comparator<File>() { Arrays.sort(files , new Comparator<File>() {
public int compare(File lhs, File rhs) { public int compare(File lhs, File rhs) {
return rhs.getName().compareTo( lhs.getName() ); return rhs.getName().compareTo(lhs.getName());
} }
}); });
return; return;
} }
if( sortMode == SORT_OLDEST ){ if (sortMode == SORT_OLDEST) {
Arrays.sort( files , new Comparator<File>() { Arrays.sort(files , new Comparator<File>() {
public int compare(File lhs, File rhs) { public int compare(File lhs, File rhs) {
return Long.valueOf( lhs.lastModified() ).compareTo( rhs.lastModified() ); return Long.valueOf(lhs.lastModified()).compareTo(rhs.lastModified());
} }
}); });
return; return;
} }
if( sortMode == SORT_NEWEST ){ if (sortMode == SORT_NEWEST) {
Arrays.sort( files , new Comparator<File>() { Arrays.sort(files , new Comparator<File>() {
public int compare(File lhs, File rhs) { public int compare(File lhs, File rhs) {
return Long.valueOf( rhs.lastModified() ).compareTo( lhs.lastModified() ); return Long.valueOf(rhs.lastModified()).compareTo(lhs.lastModified());
} }
}); });
return; return;
} }
if( sortMode == SORT_LARGEST ){ if (sortMode == SORT_LARGEST) {
Arrays.sort( files , new Comparator<File>() { Arrays.sort(files , new Comparator<File>() {
public int compare(File lhs, File rhs) { public int compare(File lhs, File rhs) {
return Long.valueOf( rhs.length() ).compareTo( lhs.length() ); return Long.valueOf(rhs.length()).compareTo(lhs.length());
} }
}); });
return; return;
} }
if( sortMode == SORT_SMALLEST ){ if (sortMode == SORT_SMALLEST) {
Arrays.sort( files , new Comparator<File>() { Arrays.sort(files , new Comparator<File>() {
public int compare(File lhs, File rhs) { public int compare(File lhs, File rhs) {
return Long.valueOf( lhs.length() ).compareTo( rhs.length() ); return Long.valueOf(lhs.length()).compareTo(rhs.length());
} }
}); });
return; return;
...@@ -256,33 +248,31 @@ public class FileUtilities { ...@@ -256,33 +248,31 @@ public class FileUtilities {
return; return;
} }
static boolean isHidden( File file ){ static boolean isHidden(File file) {
if( file.getName().startsWith(".") ) if (file.getName().startsWith("."))
return true; return true;
return false; return false;
} }
static boolean isThumbnail( File file ){ static boolean isThumbnail(File file) {
if( isHidden(file) && file.getName().endsWith(".png") ) if (isHidden(file) && file.getName().endsWith(".png"))
return true; return true;
return false; return false;
} }
static boolean hasThumbnail(File file) static boolean hasThumbnail(File file) {
{
String filename = file.getName(); String filename = file.getName();
if( lookupExtension( filename ) == DOC ) // only do this for docs for now if (lookupExtension(filename) == DOC) // only do this for docs for now
{ {
// Will need another method to check if Thumb is up-to-date - or extend this one? // Will need another method to check if Thumb is up-to-date - or extend this one?
if( new File( file.getParent() , getThumbnailName( file ) ).isFile() ) if (new File(file.getParent() , getThumbnailName(file)).isFile())
return true; return true;
return false; // If it's a document with no thumb return false; // If it's a document with no thumb
} }
return true; return true;
} }
static String getThumbnailName( File file ) static String getThumbnailName(File file) {
{
return "." + file.getName().split("[.]")[0] + ".png" ; return "." + file.getName().split("[.]")[0] + ".png" ;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment