[Android] Highlight current audio media

Sébastien Toque git at videolan.org
Fri Mar 2 20:12:53 CET 2012


android | branch: master | Sébastien Toque <xilasz at gmail.com> | Fri Mar  2 20:09:20 2012 +0100| [19ccff83fcf50721e3ed2fdc6e20b344e8e7113e] | committer: Sébastien Toque

Highlight current audio media

> http://git.videolan.org/gitweb.cgi/android.git/?a=commit;h=19ccff83fcf50721e3ed2fdc6e20b344e8e7113e
---

 vlc-android/src/org/videolan/vlc/AudioService.java |    6 ++++++
 .../org/videolan/vlc/AudioServiceController.java   |    9 +++++++++
 .../videolan/vlc/gui/audio/AudioListActivity.java  |   11 ++++++++++-
 .../vlc/gui/audio/AudioSongsListAdapter.java       |    8 ++++++++
 .../org/videolan/vlc/interfaces/IAudioService.aidl |    1 +
 5 files changed, 34 insertions(+), 1 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index b40f4ca..233c276 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -506,6 +506,12 @@ public class AudioService extends Service {
             return medias;
         }
 
+        public String getItem() {
+            return mCurrentMedia != null
+                    ? mCurrentMedia.getPath()
+                    : null;
+        }
+
         @Override
         public void next() throws RemoteException {
             AudioService.this.next();
diff --git a/vlc-android/src/org/videolan/vlc/AudioServiceController.java b/vlc-android/src/org/videolan/vlc/AudioServiceController.java
index 59245f8..2f2df4f 100644
--- a/vlc-android/src/org/videolan/vlc/AudioServiceController.java
+++ b/vlc-android/src/org/videolan/vlc/AudioServiceController.java
@@ -90,6 +90,15 @@ public class AudioServiceController implements IAudioPlayerControl {
         return new ArrayList<String>();
     }
 
+    public String getItem() {
+        try {
+            return mAudioServiceBinder.getItem();
+        } catch (RemoteException e) {
+            Log.e(TAG, "remote procedure call failed: getItem()");
+        }
+        return null;
+    }
+
     /**
      * Bind to audio service if it is running
      */
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioListActivity.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioListActivity.java
index caaa2b0..dd3d926 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioListActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioListActivity.java
@@ -190,10 +190,13 @@ public class AudioListActivity extends ListActivity {
         int mode = getIntent().getIntExtra(EXTRA_MODE, 0);
         List<Media> audioList;
         List<String> itemList;
+        String currentItem = null;
+        int currentIndex = -1;
 
         if (name == null || mode == 0) {
             mTitle.setText(R.string.songs);
             itemList = AudioServiceController.getInstance().getItems();
+            currentItem = AudioServiceController.getInstance().getItem();
             audioList = MediaLibrary.getInstance(this).getMediaItems(itemList);
         }
         else {
@@ -214,9 +217,15 @@ public class AudioListActivity extends ListActivity {
         if (mSortReverse) {
             Collections.reverse(audioList);
         }
+
         for (int i = 0; i < audioList.size(); i++) {
-            mSongsAdapter.add(audioList.get(i));
+            Media media = audioList.get(i);
+            if (currentItem != null && currentItem.equals(media.getPath()))
+                currentIndex = i;
+            mSongsAdapter.add(media);
         }
+        mSongsAdapter.setCurrentIndex(currentIndex);
+        getListView().setSelection(currentIndex);
 
         mSongsAdapter.notifyDataSetChanged();
     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioSongsListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioSongsListAdapter.java
index 3ee16b4..b9d2c4a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioSongsListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioSongsListAdapter.java
@@ -27,6 +27,7 @@ import org.videolan.vlc.Media;
 import org.videolan.vlc.R;
 
 import android.content.Context;
+import android.graphics.Color;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -36,10 +37,12 @@ import android.widget.TextView;
 public class AudioSongsListAdapter extends ArrayAdapter<Media> {
 
     private ArrayList<Media> mMediaList;
+    private int mCurrentIndex;
 
     public AudioSongsListAdapter(Context context, int textViewResourceId) {
         super(context, textViewResourceId);
         mMediaList = new ArrayList<Media>();
+        mCurrentIndex = -1;
     }
 
     @Override
@@ -54,6 +57,10 @@ public class AudioSongsListAdapter extends ArrayAdapter<Media> {
         super.clear();
     }
 
+    public void setCurrentIndex(int currentIndex) {
+        mCurrentIndex = currentIndex;
+    }
+
     @Override
     public View getView(int position, View convertView, ViewGroup parent) {
         ViewHolder holder;
@@ -70,6 +77,7 @@ public class AudioSongsListAdapter extends ArrayAdapter<Media> {
 
         Media media = getItem(position);
         holder.title.setText(media.getTitle());
+        holder.title.setTextColor(mCurrentIndex == position ? Color.RED : Color.WHITE);
         holder.artist.setText(media.getArtist() + " - " + media.getAlbum());
         return v;
     }
diff --git a/vlc-android/src/org/videolan/vlc/interfaces/IAudioService.aidl b/vlc-android/src/org/videolan/vlc/interfaces/IAudioService.aidl
index 73b7c7e..eab36df 100644
--- a/vlc-android/src/org/videolan/vlc/interfaces/IAudioService.aidl
+++ b/vlc-android/src/org/videolan/vlc/interfaces/IAudioService.aidl
@@ -33,6 +33,7 @@ interface IAudioService {
     void load(in List<String> mediaPathList, int position);
     void append(in List<String> mediaPathList);
     List<String> getItems();
+    String getItem();
     boolean isPlaying();
     boolean isShuffling();
     int getRepeatType();



More information about the Android mailing list