Commit 1768a61f authored by Adrien Maglo's avatar Adrien Maglo

Audio player: control the visibility of the header buttons depending on the...

Audio player: control the visibility of the header buttons depending on the position of the sliding panel
parent cfeac8cc
......@@ -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);
}
};
}
......@@ -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();
}
};
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment