[Android] Audio player: control the visibility of the header buttons depending on the position of the sliding panel

Adrien Maglo git at videolan.org
Wed Jan 15 16:53:29 CET 2014


vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Wed Jan 15 16:52:57 2014 +0100| [1768a61f22d6a49c94e194317ea13f06bd0dae93] | committer: Adrien Maglo

Audio player: control the visibility of the header buttons depending on the position of the sliding panel

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

 .../src/org/videolan/vlc/gui/MainActivity.java     |   22 ++++++++++
 .../org/videolan/vlc/widget/AudioMiniPlayer.java   |   43 +++++++++++++++++---
 2 files changed, 59 insertions(+), 6 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 5658039..6446d6c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -178,6 +178,7 @@ public class MainActivity extends SherlockFragmentActivity {
         mMenu.setContent(v_main);
 
         mSlidingPane = (SlidingPaneLayout) v_main.findViewById(R.id.pane);
+        mSlidingPane.setPanelSlideListener(mPanelSlideListener);
 
         View sidebar = LayoutInflater.from(this).inflate(R.layout.sidebar, null);
         final ListView listView = (ListView)sidebar.findViewById(android.R.id.list);
@@ -750,4 +751,25 @@ public class MainActivity extends SherlockFragmentActivity {
     public void hideMiniPlayer() {
         mSlidingPane.openPaneEntirely();
     }
+
+    private final SlidingPaneLayout.PanelSlideListener mPanelSlideListener
+        = new SlidingPaneLayout.PanelSlideListener() {
+
+            @Override
+            public void onPanelSlide(float slideOffset) {}
+
+            @Override
+            public void onPanelOpened() {
+                mAudioPlayer.setHeaderButtonVisibilities(false, false, true);
+            }
+
+            @Override
+            public void onPanelOpenedEntirely() {}
+
+            @Override
+            public void onPanelClosed() {
+                mAudioPlayer.setHeaderButtonVisibilities(true, true, false);
+            }
+
+    };
 }
diff --git a/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java b/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java
index 1171a75..6cb1f8e 100644
--- a/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java
+++ b/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java
@@ -81,6 +81,10 @@ public class AudioMiniPlayer extends Fragment implements IAudioPlayer {
 
     private AudioListAdapter mSongsListAdapter;
 
+    private boolean mAdvFuncVisible;
+    private boolean mPlaylistSwitchVisible;
+    private boolean mHeaderPlayPauseVisible;
+
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -118,6 +122,11 @@ public class AudioMiniPlayer extends Fragment implements IAudioPlayer {
         mSwitcher.setInAnimation(getActivity(), android.R.anim.fade_in);
         mSwitcher.setOutAnimation(getActivity(), android.R.anim.fade_out);
 
+        mAdvFuncVisible = false;
+        mPlaylistSwitchVisible = false;
+        mHeaderPlayPauseVisible = true;
+        restoreHedaderButtonVisibilities();
+
         mTime.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -239,8 +248,6 @@ public class AudioMiniPlayer extends Fragment implements IAudioPlayer {
         mBigCover.setImageBitmap(cover);
 
         mAudioMediaSwitcher.updateMedia();
-        mAdvFunc.setVisibility(ImageButton.VISIBLE);
-        mPlaylistSwitch.setVisibility(ImageButton.VISIBLE);
 
         if (mAudioController.isPlaying()) {
             mPlayPause.setImageResource(R.drawable.ic_pause);
@@ -414,6 +421,32 @@ public class AudioMiniPlayer extends Fragment implements IAudioPlayer {
         activity.hideMiniPlayer();
     }
 
+    /**
+     * Set the visibilities of the player header buttons.
+     * @param advFuncVisible
+     * @param playlistSwitchVisible
+     * @param headerPlayPauseVisible
+     */
+    public void setHeaderButtonVisibilities(boolean advFuncVisible, boolean playlistSwitchVisible,
+                                            boolean headerPlayPauseVisible) {
+        mAdvFuncVisible = advFuncVisible;
+        mPlaylistSwitchVisible = playlistSwitchVisible;
+        mHeaderPlayPauseVisible = headerPlayPauseVisible;
+        restoreHedaderButtonVisibilities();
+    }
+
+    private void restoreHedaderButtonVisibilities() {
+        mAdvFunc.setVisibility(mAdvFuncVisible ? ImageButton.VISIBLE : ImageButton.GONE);
+        mPlaylistSwitch.setVisibility(mPlaylistSwitchVisible ? ImageButton.VISIBLE : ImageButton.GONE);
+        mHeaderPlayPause.setVisibility(mHeaderPlayPauseVisible ? ImageButton.VISIBLE : ImageButton.GONE);
+    }
+
+    private void hideHedaderButtons() {
+        mAdvFunc.setVisibility(ImageButton.GONE);
+        mPlaylistSwitch.setVisibility(ImageButton.GONE);
+        mHeaderPlayPause.setVisibility(ImageButton.GONE);
+    }
+
     private final AudioMediaSwitcherListener mAudioMediaSwitcherListener = new AudioMediaSwitcherListener() {
 
         @Override
@@ -429,14 +462,12 @@ public class AudioMiniPlayer extends Fragment implements IAudioPlayer {
 
         @Override
         public void onTouchDown() {
-            mAdvFunc.setVisibility(ImageButton.GONE);
-            mPlaylistSwitch.setVisibility(ImageButton.GONE);
+            hideHedaderButtons();
         }
 
         @Override
         public void onTouchUp() {
-            mAdvFunc.setVisibility(ImageButton.VISIBLE);
-            mPlaylistSwitch.setVisibility(ImageButton.VISIBLE);
+            restoreHedaderButtonVisibilities();
         }
     };
 }



More information about the Android mailing list