[Android] Util: add custom directory support

Edward Wang git at videolan.org
Sat Dec 29 19:33:10 CET 2012


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Sat Dec 29 11:32:19 2012 -0500| [96e2158425478339fd043f3c166187cdea656a31] | committer: Edward Wang

Util: add custom directory support

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=96e2158425478339fd043f3c166187cdea656a31
---

 vlc-android/src/org/videolan/vlc/Util.java |   54 ++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/Util.java b/vlc-android/src/org/videolan/vlc/Util.java
index 86dbfd9..2898a5a 100644
--- a/vlc-android/src/org/videolan/vlc/Util.java
+++ b/vlc-android/src/org/videolan/vlc/Util.java
@@ -31,15 +31,18 @@ import java.io.InputStreamReader;
 import java.text.DecimalFormat;
 import java.text.NumberFormat;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Locale;
 import java.util.Properties;
 import java.util.StringTokenizer;
 
 import android.content.Context;
+import android.content.SharedPreferences;
 import android.graphics.Bitmap;
 import android.net.Uri;
 import android.os.Environment;
+import android.preference.PreferenceManager;
 import android.telephony.TelephonyManager;
 import android.util.DisplayMetrics;
 import android.util.TypedValue;
@@ -449,6 +452,57 @@ public class Util {
         return dirs;
     }
 
+    public static String[] getCustomDirectories() {
+        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
+        final String custom_paths = preferences.getString("custom_paths", "");
+        if(custom_paths.equals(""))
+            return new String[0];
+        else
+            return custom_paths.split(":");
+    }
+
+    public static void addCustomDirectory(String path) {
+        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
+
+        ArrayList<String> dirs = new ArrayList<String>(
+                Arrays.asList(getCustomDirectories()));
+        dirs.add(path);
+        StringBuilder builder = new StringBuilder();
+        builder.append(dirs.remove(0));
+        for(String s : dirs) {
+            builder.append(":");
+            builder.append(s);
+        }
+        SharedPreferences.Editor editor = preferences.edit();
+        editor.putString("custom_paths", builder.toString());
+        editor.commit();
+    }
+
+    public static void removeCustomDirectory(String path) {
+        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
+        if(!preferences.getString("custom_paths", "").contains(path))
+            return;
+        ArrayList<String> dirs = new ArrayList<String>(
+                Arrays.asList(preferences.getString("custom_paths", "").split(
+                        ":")));
+        dirs.remove(path);
+        String custom_path;
+        if(dirs.size() > 0) {
+            StringBuilder builder = new StringBuilder();
+            builder.append(dirs.remove(0));
+            for(String s : dirs) {
+                builder.append(":");
+                builder.append(s);
+            }
+            custom_path = builder.toString();
+        } else { // don't do unneeded extra work
+            custom_path = "";
+        }
+        SharedPreferences.Editor editor = preferences.edit();
+        editor.putString("custom_paths", custom_path);
+        editor.commit();
+    }
+
     /**
      * Get the formatted current playback speed in the form of 1.00x
      */



More information about the Android mailing list