[Android] blacklist alarms/notifications/ ringtones folders + use an HashSet for extensions
Sébastien Toque
git at videolan.org
Tue Apr 3 20:34:49 CEST 2012
android | branch: master | Sébastien Toque <xilasz at gmail.com> | Mon Apr 2 19:16:06 2012 +0200| [3ddc2f0f7803cf634cd3c82732e2542316e35159] | committer: Sébastien Toque
blacklist alarms/notifications/ringtones folders + use an HashSet for extensions
> http://git.videolan.org/gitweb.cgi/android.git/?a=commit;h=3ddc2f0f7803cf634cd3c82732e2542316e35159
---
vlc-android/src/org/videolan/vlc/Media.java | 52 ++++++++++++++------
vlc-android/src/org/videolan/vlc/MediaLibrary.java | 8 +--
.../src/org/videolan/vlc/gui/BrowserActivity.java | 3 +-
3 files changed, 41 insertions(+), 22 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/Media.java b/vlc-android/src/org/videolan/vlc/Media.java
index 659a8f7..db238ae 100644
--- a/vlc-android/src/org/videolan/vlc/Media.java
+++ b/vlc-android/src/org/videolan/vlc/Media.java
@@ -23,6 +23,7 @@ package org.videolan.vlc;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.HashSet;
import android.content.Context;
import android.graphics.Bitmap;
@@ -32,17 +33,39 @@ public class Media implements Comparable<Media> {
public final static String TAG = "VLC/MediaItem";
- public final static String[] EXTENTIONS = {
- ".3g2", ".3gp", ".3gp2", ".3gpp", ".amv", ".asf", ".avi", ".divx", ".dv", "f4v",
- ".flv", ".gxf", ".iso", ".m1v", ".m2v", ".m2t", ".m2ts", ".m4v", ".mkv", ".mov", ".mp2",
- ".mp2v", ".mp4", ".mp4v", ".mpa", ".mpe", ".mpeg", ".mpeg1", ".mpeg2", ".mpeg4", ".mpg",
- ".mpv2", ".mts", ".mxf", ".nsv", ".nuv", ".ogg", ".ogm", ".ogv", ".ogx", ".ps", ".rec",
- ".rm", ".rmvb", ".tod", ".ts", ".tts", ".vob", ".vro", ".webm", ".wmv",
-
- ".a52", ".aac", ".ac3", ".adt", ".adts", ".aif", ".aifc", ".aiff", ".amr", ".aob", ".ape",
- ".awb", ".cda", ".dts", ".flac", ".it", ".m4a", ".m4p", ".mid", ".mka", ".mlp", ".mod",
- ".mp1", ".mp2", ".mp3", ".mpc", ".oga", ".ogg", ".oma", ".rmi", ".s3m", ".spx", ".tta",
- ".voc", ".vqf", ".w64", ".wav", ".wma", ".wv", ".xa", ".xm" };
+ public final static HashSet<String> EXTENTIONS;
+ public final static HashSet<String> FOLDER_BLACKLIST;
+
+ static {
+ String[] extensions = {
+ ".3g2", ".3gp", ".3gp2", ".3gpp", ".amv", ".asf", ".avi", ".divx", ".dv", "f4v",
+ ".flv", ".gxf", ".iso", ".m1v", ".m2v", ".m2t", ".m2ts", ".m4v", ".mkv", ".mov", ".mp2",
+ ".mp2v", ".mp4", ".mp4v", ".mpa", ".mpe", ".mpeg", ".mpeg1", ".mpeg2", ".mpeg4", ".mpg",
+ ".mpv2", ".mts", ".mxf", ".nsv", ".nuv", ".ogg", ".ogm", ".ogv", ".ogx", ".ps", ".rec",
+ ".rm", ".rmvb", ".tod", ".ts", ".tts", ".vob", ".vro", ".webm", ".wmv",
+
+ ".a52", ".aac", ".ac3", ".adt", ".adts", ".aif", ".aifc", ".aiff", ".amr", ".aob", ".ape",
+ ".awb", ".cda", ".dts", ".flac", ".it", ".m4a", ".m4p", ".mid", ".mka", ".mlp", ".mod",
+ ".mp1", ".mp2", ".mp3", ".mpc", ".oga", ".ogg", ".oma", ".rmi", ".s3m", ".spx", ".tta",
+ ".voc", ".vqf", ".w64", ".wav", ".wma", ".wv", ".xa", ".xm" };
+ String[] folder_blacklist = {
+ "/sdcard/alarms",
+ "/sdcard/notifications",
+ "/sdcard/ringtones",
+ "/sdcard/media/alarms",
+ "/sdcard/media/notifications",
+ "/sdcard/media/ringtones",
+ "/sdcard/media/audio/alarms",
+ "/sdcard/media/audio/notifications",
+ "/sdcard/media/audio/ringtones" };
+
+ EXTENTIONS = new HashSet<String>();
+ for (String item : extensions)
+ EXTENTIONS.add(item);
+ FOLDER_BLACKLIST = new HashSet<String>();
+ for (String item : folder_blacklist)
+ FOLDER_BLACKLIST.add(item);
+ }
public final static int TYPE_ALL = -1;
public final static int TYPE_VIDEO = 0;
@@ -85,14 +108,13 @@ public class Media implements Comparable<Media> {
URL urlobj = new URL(MRL);
mFilename = urlobj.getFile().substring(urlobj.getFile().lastIndexOf('/') + 1);
/* empty filenames are awkward */
- if(mFilename.equals("")) {
+ if (mFilename.equals("")) {
mFilename = urlobj.getHost();
}
} catch (MalformedURLException e1) {
mFilename = "";
}
-
LibVLC mLibVlc = null;
try {
mLibVlc = LibVLC.getInstance();
@@ -124,7 +146,7 @@ public class Media implements Comparable<Media> {
e.printStackTrace();
}
- if(addToDb) {
+ if (addToDb) {
// Add this item to database
DatabaseManager db = DatabaseManager.getInstance(context);
db.addMedia(this);
@@ -215,7 +237,7 @@ public class Media implements Comparable<Media> {
}
public String getTitle() {
- if(mTitle != null)
+ if (mTitle != null)
return mTitle;
else
return mFilename;
diff --git a/vlc-android/src/org/videolan/vlc/MediaLibrary.java b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
index 10f8972..ce2784b 100644
--- a/vlc-android/src/org/videolan/vlc/MediaLibrary.java
+++ b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
@@ -24,7 +24,6 @@ import java.io.File;
import java.io.FileFilter;
import java.lang.Thread.State;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -270,20 +269,17 @@ public class MediaLibrary {
*/
private class MediaItemFilter implements FileFilter {
- // FIXME: save extensions in external database
- private String[] extensions = Media.EXTENTIONS;
-
public boolean accept(File f) {
boolean accepted = false;
if (!f.isHidden()) {
- if (f.isDirectory()) {
+ if (f.isDirectory() && !Media.FOLDER_BLACKLIST.contains(f.getPath().toLowerCase())) {
accepted = true;
} else {
String fileName = f.getName().toLowerCase();
int dotIndex = fileName.lastIndexOf(".");
if (dotIndex != -1) {
String fileExt = fileName.substring(dotIndex);
- accepted = Arrays.asList(extensions).contains(fileExt);
+ accepted = Media.EXTENTIONS.contains(fileExt);
}
}
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/BrowserActivity.java b/vlc-android/src/org/videolan/vlc/gui/BrowserActivity.java
index 9700134..8a74d5a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/BrowserActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/BrowserActivity.java
@@ -24,6 +24,7 @@ import java.io.File;
import java.io.FileFilter;
import java.util.Stack;
+import org.videolan.vlc.Media;
import org.videolan.vlc.MediaLibrary;
import org.videolan.vlc.R;
import org.videolan.vlc.Util;
@@ -141,7 +142,7 @@ public class BrowserActivity extends ListActivity {
private class DirFilter implements FileFilter {
public boolean accept(File f) {
- return f.isDirectory() && !f.isHidden();
+ return f.isDirectory() && !f.isHidden() && !Media.FOLDER_BLACKLIST.contains(f.getPath().toLowerCase());
}
}
More information about the Android
mailing list