Commit bd0607f8 authored by Ludovic Fauvet's avatar Ludovic Fauvet
Browse files

The audio mini player is now a fragment

parent 902ca9f1
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="0%" android:toXDelta="0%"
android:fromYDelta="100%" android:toYDelta="0%"
android:duration="1000"/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="0%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="100%"
android:duration="1000"/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_node"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
......
......@@ -71,9 +71,8 @@
android:shadowDx="1"
android:shadowDy="1"/>
</RelativeLayout>
<org.videolan.vlc.widget.AudioMiniPlayer
<FrameLayout
android:id="@+id/audio_mini_player"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:visibility="gone" />
android:layout_width="fill_parent"/>
</LinearLayout>
......@@ -51,6 +51,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.View;
......@@ -138,7 +139,12 @@ public class MainActivity extends SherlockFragmentActivity {
showDirectoryView();
// Add mini audio player
mAudioPlayer = (AudioMiniPlayer) findViewById(R.id.audio_mini_player);
mAudioPlayer = new AudioMiniPlayer();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.audio_mini_player, mAudioPlayer);
ft.commit();
mAudioController = AudioServiceController.getInstance();
mAudioPlayer.setAudioPlayerControl(mAudioController);
mAudioPlayer.update();
......@@ -393,12 +399,18 @@ public class MainActivity extends SherlockFragmentActivity {
}*/
public void hideAudioPlayer() {
mAudioPlayer.setVisibility(AudioMiniPlayer.GONE);
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.hide(mAudioPlayer);
ft.commit();
mAudioController.stop();
}
public void showAudioPlayer() {
mAudioPlayer.setVisibility(AudioMiniPlayer.VISIBLE);
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.show(mAudioPlayer);
ft.commit();
}
private void showInfoDialog() {
......@@ -457,11 +469,9 @@ public class MainActivity extends SherlockFragmentActivity {
if (action.equalsIgnoreCase(ACTION_SHOW_PROGRESSBAR)) {
setProgressBarIndeterminateVisibility(Boolean.TRUE);
}
else if (action.equalsIgnoreCase(ACTION_HIDE_PROGRESSBAR)) {
} else if (action.equalsIgnoreCase(ACTION_HIDE_PROGRESSBAR)) {
setProgressBarIndeterminateVisibility(Boolean.FALSE);
}
else if (action.equalsIgnoreCase(ACTION_SHOW_TEXTINFO)) {
} else if (action.equalsIgnoreCase(ACTION_SHOW_TEXTINFO)) {
String info = intent.getStringExtra("info");
int max = intent.getIntExtra("max", 0);
int progress = intent.getIntExtra("progress", 100);
......
......@@ -25,22 +25,28 @@ import org.videolan.vlc.gui.audio.AudioPlayerActivity;
import org.videolan.vlc.interfaces.IAudioPlayer;
import org.videolan.vlc.interfaces.IAudioPlayerControl;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
public class AudioMiniPlayer extends LinearLayout implements IAudioPlayer {
public class AudioMiniPlayer extends Fragment implements IAudioPlayer {
public static final String TAG = "VLC/AudioMiniPlayer";
private IAudioPlayerControl mAudioPlayerControl;
......@@ -75,7 +81,7 @@ public class AudioMiniPlayer extends LinearLayout implements IAudioPlayer {
}
};
public AudioMiniPlayer(Context context, AttributeSet attrs) {
/*public AudioMiniPlayer(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
......@@ -83,56 +89,67 @@ public class AudioMiniPlayer extends LinearLayout implements IAudioPlayer {
public AudioMiniPlayer(Context context) {
super(context);
init();
}
}*/
private void init() {
// get inflater and create the new view
LayoutInflater layoutInflater =
(LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View mMiniPlayerView = layoutInflater.inflate(R.layout.audio_player_mini, this, false);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
lastTitle = "";
}
addView(mMiniPlayerView);
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.audio_player_mini, container, false);
// Initialize the children
mCover = (ImageView) findViewById(R.id.cover);
mTitle = (TextView) findViewById(R.id.title);
mArtist = (TextView) findViewById(R.id.artist);
mPlayPause = (ImageButton) findViewById(R.id.play_pause);
mForward = (ImageButton) findViewById(R.id.forward);
mBackward = (ImageButton) findViewById(R.id.backward);
mCover = (ImageView) v.findViewById(R.id.cover);
mTitle = (TextView) v.findViewById(R.id.title);
mArtist = (TextView) v.findViewById(R.id.artist);
mPlayPause = (ImageButton) v.findViewById(R.id.play_pause);
mForward = (ImageButton) v.findViewById(R.id.forward);
mBackward = (ImageButton) v.findViewById(R.id.backward);
mPlayPause.setOnClickListener(onMediaControlClickListener);
mForward.setOnClickListener(onMediaControlClickListener);
mBackward.setOnClickListener(onMediaControlClickListener);
mSeekbar = (SeekBar) findViewById(R.id.timeline);
lastTitle = "";
mSeekbar = (SeekBar) v.findViewById(R.id.timeline);
this.setOnClickListener(new OnClickListener() {
LinearLayout root = (LinearLayout) v.findViewById(R.id.root_node);
root.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
// Start audio player
Intent intent = new Intent(getContext(),
public void onClick(View v) {
Intent intent = new Intent(getActivity(),
AudioPlayerActivity.class);
getContext().startActivity(intent);
getActivity().startActivity(intent);
}
});
this.setOnLongClickListener(new OnLongClickListener() {
root.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View arg0) {
showContextMenu();
//FIXME getActivity().openContextMenu(getView());
return true;
}
});
return v;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//FIXME registerForContextMenu(getView());
}
@Override
protected void onCreateContextMenu(ContextMenu menu) {
MenuInflater inflater = new MenuInflater(getContext());
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getActivity().getMenuInflater();
inflater.inflate(R.menu.audio_player_mini, menu);
MenuItem hmi = menu.findItem(R.id.hide_mini_player);
MenuItem pp = menu.findItem(R.id.play_pause);
if (mAudioPlayerControl.isPlaying()) {
......@@ -141,8 +158,6 @@ public class AudioMiniPlayer extends LinearLayout implements IAudioPlayer {
} else {
pp.setTitle(R.string.play);
}
super.onCreateContextMenu(menu);
}
public void setAudioPlayerControl(IAudioPlayerControl control) {
......@@ -151,12 +166,19 @@ public class AudioMiniPlayer extends LinearLayout implements IAudioPlayer {
@Override
public void update() {
if (mAudioPlayerControl != null) {
if (mAudioPlayerControl != null && getActivity() != null) {
FragmentManager fm = getActivity().getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
if (mAudioPlayerControl.hasMedia()) {
this.setVisibility(LinearLayout.VISIBLE);
ft.setCustomAnimations(R.anim.anim_enter_bottom, 0);
ft.show(this);
ft.commit();
} else {
this.setVisibility(LinearLayout.GONE);
ft.setCustomAnimations(0, R.anim.anim_leave_bottom);
ft.hide(this);
ft.commit();
return;
}
......
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