Commit 8a13e7e7 authored by Adrien Maglo's avatar Adrien Maglo
Browse files

Audio player: allow to play next and previous songs by sliding the big cover

parent df584592
......@@ -27,7 +27,7 @@
android:gravity="center_vertical"
android:orientation="horizontal" >
<org.videolan.vlc.widget.AudioMediaSwitcher
<org.videolan.vlc.gui.audio.widget.HeaderMediaSwitcher
android:id="@+id/audio_media_switcher"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
......@@ -96,11 +96,11 @@
android:layout_height="fill_parent"
android:background="?attr/background_playlist" />
<org.videolan.vlc.widget.AnimatedCoverView
android:id="@+id/big_cover"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop" />
<org.videolan.vlc.gui.audio.widget.CoverMediaSwitcher
android:id="@+id/cover_media_switcher"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
</ViewSwitcher>
<LinearLayout
......
......@@ -34,13 +34,11 @@ import org.videolan.vlc.Util;
import org.videolan.vlc.gui.CommonDialogs;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.gui.CommonDialogs.MenuType;
import org.videolan.vlc.gui.audio.widget.CoverMediaSwitcher;
import org.videolan.vlc.gui.audio.widget.HeaderMediaSwitcher;
import org.videolan.vlc.interfaces.IAudioPlayer;
import org.videolan.vlc.widget.AnimatedCoverView;
import org.videolan.vlc.widget.AudioMediaSwitcher;
import org.videolan.vlc.widget.AudioMediaSwitcher.AudioMediaSwitcherListener;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.AudioManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
......@@ -67,8 +65,8 @@ public class AudioPlayer extends Fragment implements IAudioPlayer {
public static final String TAG = "VLC/AudioMiniPlayer";
private ProgressBar mProgressBar;
private AudioMediaSwitcher mAudioMediaSwitcher;
private AnimatedCoverView mBigCover;
private HeaderMediaSwitcher mHeaderMediaSwitcher;
private CoverMediaSwitcher mCoverMediaSwitcher;
private TextView mTime;
private TextView mHeaderTime;
private TextView mLength;
......@@ -111,10 +109,11 @@ public class AudioPlayer extends Fragment implements IAudioPlayer {
mProgressBar = (ProgressBar) v.findViewById(R.id.progressBar);
mAudioMediaSwitcher = (AudioMediaSwitcher) v.findViewById(R.id.audio_media_switcher);
mAudioMediaSwitcher.setAudioMediaSwitcherListener(mAudioMediaSwitcherListener);
mHeaderMediaSwitcher = (HeaderMediaSwitcher) v.findViewById(R.id.audio_media_switcher);
mHeaderMediaSwitcher.setAudioMediaSwitcherListener(mHeaderMediaSwitcherListener);
mCoverMediaSwitcher = (CoverMediaSwitcher) v.findViewById(R.id.cover_media_switcher);
mCoverMediaSwitcher.setAudioMediaSwitcherListener(mCoverMediaSwitcherListener);
mBigCover = (AnimatedCoverView) v.findViewById(R.id.big_cover);
mTime = (TextView) v.findViewById(R.id.time);
mHeaderTime = (TextView) v.findViewById(R.id.header_time);
mLength = (TextView) v.findViewById(R.id.length);
......@@ -300,12 +299,8 @@ public class AudioPlayer extends Fragment implements IAudioPlayer {
return;
}
Bitmap cover = mAudioController.getCover();
if (cover == null)
cover = BitmapFactory.decodeResource(getResources(), R.drawable.cone);
mBigCover.setImageBitmap(cover);
mAudioMediaSwitcher.updateMedia();
mHeaderMediaSwitcher.updateMedia();
mCoverMediaSwitcher.updateMedia();
if (mAudioController.isPlaying()) {
mPlayPause.setImageResource(R.drawable.ic_pause);
......@@ -502,7 +497,7 @@ public class AudioPlayer extends Fragment implements IAudioPlayer {
mHeaderTime.setVisibility(TextView.GONE);
}
private final AudioMediaSwitcherListener mAudioMediaSwitcherListener = new AudioMediaSwitcherListener() {
private final AudioMediaSwitcherListener mHeaderMediaSwitcherListener = new AudioMediaSwitcherListener() {
@Override
public void onMediaSwitching() {}
......@@ -525,4 +520,25 @@ public class AudioPlayer extends Fragment implements IAudioPlayer {
restoreHedaderButtonVisibilities();
}
};
private final AudioMediaSwitcherListener mCoverMediaSwitcherListener = new AudioMediaSwitcherListener() {
@Override
public void onMediaSwitching() {}
@Override
public void onMediaSwitched(int position) {
if (position == AudioMediaSwitcherListener.PREVIOUS_MEDIA)
mAudioController.previous();
else if (position == AudioMediaSwitcherListener.NEXT_MEDIA)
mAudioController.next();
}
@Override
public void onTouchDown() {}
@Override
public void onTouchUp() {}
};
}
/*****************************************************************************
* CoverMediaSwitcher.java
*****************************************************************************
* Copyright © 2011-2014 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
package org.videolan.vlc.gui.audio.widget;
import org.videolan.vlc.R;
import org.videolan.vlc.widget.AnimatedCoverView;
import org.videolan.vlc.widget.AudioMediaSwitcher;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.AttributeSet;
import android.view.LayoutInflater;
public class CoverMediaSwitcher extends AudioMediaSwitcher {
public CoverMediaSwitcher(Context context, AttributeSet attrs) {
super(context, attrs);
}
protected void addMediaView(LayoutInflater inflater, String title, String artist, Bitmap cover) {
AnimatedCoverView coverView = new AnimatedCoverView(inflater.getContext(), null);
if (cover == null)
cover = BitmapFactory.decodeResource(getResources(), R.drawable.cone);
coverView.setImageBitmap(cover);
addView(coverView);
}
}
/*****************************************************************************
* HeaderMediaSwitcher.java
*****************************************************************************
* Copyright © 2011-2014 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
package org.videolan.vlc.gui.audio.widget;
import org.videolan.vlc.R;
import org.videolan.vlc.widget.AudioMediaSwitcher;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class HeaderMediaSwitcher extends AudioMediaSwitcher {
public HeaderMediaSwitcher(Context context, AttributeSet attrs) {
super(context, attrs);
}
protected void addMediaView(LayoutInflater inflater, String title, String artist, Bitmap cover) {
View v = inflater.inflate(R.layout.audio_media_switcher_item, this, false);
ImageView coverView = (ImageView) v.findViewById(R.id.cover);
TextView titleView = (TextView) v.findViewById(R.id.title);
TextView artistView = (TextView) v.findViewById(R.id.artist);
if (cover != null) {
coverView.setVisibility(VISIBLE);
coverView.setImageBitmap(cover);
}
titleView.setText(title);
artistView.setText(artist);
addView(v);
}
}
......@@ -21,18 +21,14 @@
package org.videolan.vlc.widget;
import org.videolan.vlc.AudioServiceController;
import org.videolan.vlc.R;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class AudioMediaSwitcher extends FlingViewGroup {
public abstract class AudioMediaSwitcher extends FlingViewGroup {
private AudioMediaSwitcherListener mAudioMediaSwitcherListener;
......@@ -82,23 +78,7 @@ public class AudioMediaSwitcher extends FlingViewGroup {
scrollTo(0);
}
private void addMediaView(LayoutInflater inflater, String title, String artist, Bitmap cover) {
View v = inflater.inflate(R.layout.audio_media_switcher_item, this, false);
ImageView coverView = (ImageView) v.findViewById(R.id.cover);
TextView titleView = (TextView) v.findViewById(R.id.title);
TextView artistView = (TextView) v.findViewById(R.id.artist);
if (cover != null) {
coverView.setVisibility(VISIBLE);
coverView.setImageBitmap(cover);
}
titleView.setText(title);
artistView.setText(artist);
addView(v);
}
protected abstract void addMediaView(LayoutInflater inflater, String title, String artist, Bitmap cover);
private final ViewSwitchListener mViewSwitchListener = new ViewSwitchListener() {
......
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