[Android] Show path from browsers in ActionBar subtitle

Geoffrey Métais git at videolan.org
Wed Apr 27 09:37:48 CEST 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Apr 25 17:29:10 2016 +0200| [f54716b4ad2b5aeeaafe97ace3b8ada4325e5157] | committer: Geoffrey Métais

Show path from browsers in ActionBar subtitle

> https://code.videolan.org/videolan/vlc-android/commit/f54716b4ad2b5aeeaafe97ace3b8ada4325e5157
---

 .../src/org/videolan/vlc/gui/MainActivity.java        |  3 +++
 .../videolan/vlc/gui/browser/BaseBrowserFragment.java | 14 ++++++++++++++
 .../vlc/gui/browser/MediaBrowserFragment.java         | 19 +++++++++++--------
 3 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index b58a524..cfe2889 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -847,6 +847,9 @@ public class MainActivity extends AudioPlayerContainerActivity implements Filter
         if(item == null)
             return false;
 
+        getSupportActionBar().setTitle(null); //clear title
+        getSupportActionBar().setSubtitle(null); //clear subtitle
+
         int id = item.getItemId();
         FragmentManager fm = getSupportFragmentManager();
         Fragment current = fm.findFragmentById(R.id.fragment_placeholder);
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
index 5b69e3d..8a54c50 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -60,7 +60,9 @@ import org.videolan.vlc.interfaces.IRefreshable;
 import org.videolan.vlc.media.MediaDatabase;
 import org.videolan.vlc.media.MediaUtils;
 import org.videolan.vlc.media.MediaWrapper;
+import org.videolan.vlc.util.AndroidDevices;
 import org.videolan.vlc.util.FileUtils;
+import org.videolan.vlc.util.Strings;
 import org.videolan.vlc.util.VLCInstance;
 import org.videolan.vlc.util.WeakHandler;
 
@@ -192,6 +194,18 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
             return mCurrentMedia != null ? mCurrentMedia.getTitle() : mMrl;
     }
 
+    public String getSubTitle(){
+        if (mRoot)
+            return null;
+        String mrl = Strings.removeFileProtocole(mMrl);
+        if (!TextUtils.isEmpty(mrl)) {
+            if (this instanceof FileBrowserFragment && mrl.startsWith(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY))
+                mrl = getString(R.string.internal_memory)+mrl.substring(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY.length());
+            mrl = mrl.replaceAll("://", " ").replaceAll("/", " > ");
+        }
+        return mCurrentMedia != null ? mrl : null;
+    }
+
     @Override
     protected void display() {
         if (!mReadyToDisplay) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.java
index d9990fa..fa49211 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.java
@@ -41,6 +41,16 @@ public abstract class MediaBrowserFragment extends PlaybackServiceFragment {
         mMediaLibrary = MediaLibrary.getInstance();
     }
 
+    public void onStart(){
+        super.onStart();
+        final AppCompatActivity activity = (AppCompatActivity)getActivity();
+        if (activity != null && activity.getSupportActionBar() != null) {
+            activity.getSupportActionBar().setTitle(getTitle());
+            activity.getSupportActionBar().setSubtitle(getSubTitle());
+            getActivity().supportInvalidateOptionsMenu();
+        }
+    }
+
     public void setReadyToDisplay(boolean ready) {
         if (ready && !mReadyToDisplay)
             display();
@@ -51,13 +61,6 @@ public abstract class MediaBrowserFragment extends PlaybackServiceFragment {
     protected abstract void display();
 
     protected abstract String getTitle();
+    protected String getSubTitle() { return null; }
     public abstract void clear();
-    public void onStart(){
-        super.onStart();
-        final AppCompatActivity activity = (AppCompatActivity)getActivity();
-        if (activity != null && activity.getSupportActionBar() != null) {
-            activity.getSupportActionBar().setTitle(getTitle());
-            getActivity().supportInvalidateOptionsMenu();
-        }
-    }
 }



More information about the Android mailing list