[Android] FAB button to add a custom directory

Geoffrey Métais git at videolan.org
Tue May 12 14:40:51 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue May 12 13:38:36 2015 +0200| [41e6ece3721a3e157a74ac8f268ec74ca2c7c891] | committer: Geoffrey Métais

FAB button to add a custom directory

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

 vlc-android/res/layout/network_browser.xml         |   14 +++++++--
 .../vlc/gui/browser/StorageBrowserFragment.java    |   32 ++++++++++++++++++--
 2 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/vlc-android/res/layout/network_browser.xml b/vlc-android/res/layout/network_browser.xml
index d96a19d..4329d58 100644
--- a/vlc-android/res/layout/network_browser.xml
+++ b/vlc-android/res/layout/network_browser.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
     <org.videolan.vlc.widget.SwipeRefreshLayout
@@ -24,4 +24,14 @@
     </org.videolan.vlc.widget.SwipeRefreshLayout>
 
     <include layout="@layout/shadow_top"/>
-</FrameLayout>
+
+    <ImageView
+        android:id="@+id/fab_add_custom_dir"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:background="@drawable/ic_fab_shuffle"
+        android:layout_alignParentBottom="true"
+        android:layout_alignParentRight="true"
+        android:visibility="gone"
+        android:layout_margin="16dp"/>
+</RelativeLayout>
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.java
index 9ae5126..060702c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.java
@@ -27,19 +27,22 @@ import android.os.Bundle;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentTransaction;
 import android.text.TextUtils;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
 
 import org.videolan.libvlc.Media;
 import org.videolan.vlc.MediaWrapper;
 import org.videolan.vlc.R;
 import org.videolan.vlc.util.AndroidDevices;
 
-import java.util.ArrayList;
-
-public class StorageBrowserFragment extends FileBrowserFragment {
+public class StorageBrowserFragment extends FileBrowserFragment implements View.OnClickListener {
 
     public static final String KEY_IN_MEDIALIB = "key_in_medialib";
 
     boolean mScannedDirectory = false;
+    ImageView mAddDirectoryFAB;
 
     public StorageBrowserFragment(){
         mHandler = new BrowserFragmentHandler(this);
@@ -63,6 +66,17 @@ public class StorageBrowserFragment extends FileBrowserFragment {
     }
 
     @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+        View v = super.onCreateView(inflater, container, savedInstanceState);
+        if (mRoot) {
+            mAddDirectoryFAB = (ImageView) v.findViewById(R.id.fab_add_custom_dir);
+            mAddDirectoryFAB.setVisibility(View.VISIBLE);
+            mAddDirectoryFAB.setOnClickListener(this);
+        }
+        return v;
+    }
+
+    @Override
     public void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
         outState.putBoolean(KEY_IN_MEDIALIB, mScannedDirectory);
@@ -119,4 +133,16 @@ public class StorageBrowserFragment extends FileBrowserFragment {
         ft.addToBackStack(mMrl);
         ft.commit();
     }
+
+    @Override
+    public void onClick(View v) {
+        if (v.getId() == R.id.fab_add_custom_dir){
+            showAddDirectoryDialog();
+        }
+    }
+
+    @Override
+    protected String getCategoryTitle() {
+        return getString(R.string.directories_summary);
+    }
 }



More information about the Android mailing list