[Android] Show 'sdcard' instead of the user's ID in the file browsers
Ludovic Fauvet
git at videolan.org
Mon Nov 26 15:23:53 CET 2012
vlc-ports/android | branch: master | Ludovic Fauvet <etix at videolan.org> | Mon Nov 26 15:03:08 2012 +0100| [02178a469626a1ee1a3da85a424c651fbc53fbb9] | committer: Ludovic Fauvet
Show 'sdcard' instead of the user's ID in the file browsers
Since Android 4.2 the support for multi-user accounts was added and uses
a separated storage space for each user represented by an ID
(/storage/emulated/<user-id>) that is visible in the file browsers.
Instead of showing this nonsensical number, and since we're unable to
get the current user name (thanks to the protected state of the
UserManager class), this commit replaces it by 'sdcard' to mimic the old
behavior.
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=02178a469626a1ee1a3da85a424c651fbc53fbb9
---
vlc-android/res/values/strings.xml | 1 +
.../src/org/videolan/vlc/gui/BrowserAdapter.java | 14 ++++++++++-
.../src/org/videolan/vlc/gui/DirectoryAdapter.java | 25 ++++++++++++++++++--
3 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 9ffa19f..1f69ecd 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -123,6 +123,7 @@
<string name="load_1_period" translatable="false">.</string>
<string name="load_2_period" translatable="false">..</string>
<string name="load_3_period" translatable="false">...</string>
+ <string name="sdcard">sdcard</string>
<!-- About -->
<string name="app_name_full">VLC for Android™</string>
diff --git a/vlc-android/src/org/videolan/vlc/gui/BrowserAdapter.java b/vlc-android/src/org/videolan/vlc/gui/BrowserAdapter.java
index 84a9103..79c398b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/BrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/BrowserAdapter.java
@@ -27,8 +27,10 @@ import java.util.List;
import org.videolan.vlc.DatabaseManager;
import org.videolan.vlc.R;
import org.videolan.vlc.Util;
+import org.videolan.vlc.VLCApplication;
import android.content.Context;
+import android.os.Environment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -76,7 +78,7 @@ public class BrowserAdapter extends ArrayAdapter<File>
if (item != null && item.getName() != null) {
Util.setItemBackground(holder.layout, position);
- holder.text.setText(item.getName());
+ holder.text.setText(getVisibleName(item));
holder.check.setOnCheckedChangeListener(null);
holder.check.setTag(item);
holder.check.setEnabled(true);
@@ -134,6 +136,16 @@ public class BrowserAdapter extends ArrayAdapter<File>
file2.getName().toUpperCase());
}
+ private String getVisibleName(File file) {
+ if (android.os.Build.VERSION.SDK_INT >= 17) {
+ // Show "sdcard" for the user's folder when running in multi-user
+ if (file.getAbsolutePath().equals(Environment.getExternalStorageDirectory().getPath())) {
+ return VLCApplication.getAppContext().getString(R.string.sdcard);
+ }
+ }
+ return file.getName();
+ }
+
static class ViewHolder {
View layout;
CheckBox check;
diff --git a/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java b/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
index 5f1cb6d..b6eb2cc 100644
--- a/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
@@ -34,6 +34,7 @@ import org.videolan.vlc.Util;
import org.videolan.vlc.VLCApplication;
import android.content.Context;
+import android.os.Environment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -55,10 +56,16 @@ public class DirectoryAdapter extends BaseAdapter {
public class Node implements Comparable<DirectoryAdapter.Node> {
public ArrayList<DirectoryAdapter.Node> children;
String name;
+ String visibleName;
public Boolean isFile;
public Node(String _name) {
+ this(_name, null);
+ }
+
+ public Node(String _name, String _visibleName) {
this.name = _name;
+ this.visibleName = _visibleName;
this.children = new ArrayList<DirectoryAdapter.Node>();
this.isFile = false;
}
@@ -103,6 +110,10 @@ public class DirectoryAdapter extends BaseAdapter {
return c;
}
+ public String getVisibleName() {
+ return (this.visibleName != null) ? this.visibleName : this.name;
+ }
+
@Override
public int compareTo(Node arg0) {
if(this.isFile && !(arg0.isFile))
@@ -127,7 +138,7 @@ public class DirectoryAdapter extends BaseAdapter {
String storages[] = Util.getStorageDirectories();
for (String storage : storages) {
File f = new File(storage);
- DirectoryAdapter.Node child = new DirectoryAdapter.Node(f.getName());
+ DirectoryAdapter.Node child = new DirectoryAdapter.Node(f.getName(), getVisibleName(f));
child.isFile = false;
this.populateNode(child, storage);
n.children.add(child);
@@ -260,7 +271,7 @@ public class DirectoryAdapter extends BaseAdapter {
holder.title.setText(m.getTitle());
holderText = m.getArtist() + " - " + m.getAlbum();
} else
- holder.title.setText(selectedNode.name);
+ holder.title.setText(selectedNode.getVisibleName());
if(selectedNode.name == "..")
holderText = context.getString(R.string.parent_folder);
@@ -384,4 +395,14 @@ public class DirectoryAdapter extends BaseAdapter {
}
return Util.stripTrailingSlash(path);
}
+
+ private String getVisibleName(File file) {
+ if (android.os.Build.VERSION.SDK_INT >= 17) {
+ // Show "sdcard" for the user's folder when running in multi-user
+ if (file.getAbsolutePath().equals(Environment.getExternalStorageDirectory().getPath())) {
+ return VLCApplication.getAppContext().getString(R.string.sdcard);
+ }
+ }
+ return file.getName();
+ }
}
More information about the Android
mailing list