[Android] Audio player: add remove function

Edward Wang git at videolan.org
Thu Jan 23 23:42:01 CET 2014


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Thu Jan 23 17:35:01 2014 -0500| [74cea16084177d7cd750008a1f6ce388db18a723] | committer: Edward Wang

Audio player: add remove function

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

 .../org/videolan/vlc/widget/AudioMiniPlayer.java   |   29 ++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java b/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java
index 3537b0c..1b1997b 100644
--- a/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java
+++ b/vlc-android/src/org/videolan/vlc/widget/AudioMiniPlayer.java
@@ -44,10 +44,17 @@ import android.graphics.BitmapFactory;
 import android.media.AudioManager;
 import android.os.Bundle;
 import android.support.v4.app.Fragment;
+import android.util.Log;
+import android.view.ContextMenu;
 import android.view.LayoutInflater;
+import android.view.MenuInflater;
+import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.ContextMenu.ContextMenuInfo;
 import android.widget.AdapterView;
+import android.widget.AdapterView.AdapterContextMenuInfo;
+import android.widget.AdapterView.OnItemLongClickListener;
 import android.widget.ImageButton;
 import android.widget.ProgressBar;
 import android.widget.SeekBar;
@@ -209,6 +216,7 @@ public class AudioMiniPlayer extends Fragment implements IAudioPlayer {
                 mAudioController.moveItem(positionStart, positionEnd);
             }
         });
+        registerForContextMenu(mSongsList);
 
         getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC);
 
@@ -230,6 +238,27 @@ public class AudioMiniPlayer extends Fragment implements IAudioPlayer {
         super.onStop();
     }
 
+    @Override
+    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
+        MenuInflater menuInflater = getActivity().getMenuInflater();
+        menuInflater.inflate(R.menu.audio_player_mini, menu);
+    }
+
+    @Override
+    public boolean onContextItemSelected(MenuItem item) {
+        AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
+        if(info == null) // info can be null
+            return super.onContextItemSelected(item);
+        int id = item.getItemId();
+
+        if(id == R.id.audio_player_mini_remove) {
+            Log.d(TAG, "Context menu removing " + info.position);
+            mAudioController.remove(info.position);
+            return true;
+        }
+        return super.onContextItemSelected(item);
+    }
+
     /**
      * Show the audio player from an intent
      *



More information about the Android mailing list