[Android] show covers in audio lists

Sébastien Toque git at videolan.org
Mon Oct 8 23:18:21 CEST 2012


vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Fri Oct  5 12:54:05 2012 +0200| [2f7ab538c11f507ebb12543b2ac2cc209068956b] | committer: Sébastien Toque

show covers in audio lists

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

 vlc-android/res/layout/audio_browser_item.xml      |   55 ++++++++++++--------
 vlc-android/res/layout/audio_browser_playlist.xml  |    6 +++
 .../res/layout/audio_browser_playlist_child.xml    |    6 +++
 .../videolan/vlc/gui/audio/AudioListAdapter.java   |    8 +++
 .../vlc/gui/audio/AudioPlaylistAdapter.java        |   14 ++++-
 5 files changed, 67 insertions(+), 22 deletions(-)

diff --git a/vlc-android/res/layout/audio_browser_item.xml b/vlc-android/res/layout/audio_browser_item.xml
index 7f3edab..1c607f8 100644
--- a/vlc-android/res/layout/audio_browser_item.xml
+++ b/vlc-android/res/layout/audio_browser_item.xml
@@ -3,29 +3,42 @@
     android:id="@+id/layout_item"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
-    android:gravity="center_vertical"
-    android:orientation="vertical" >
+    android:orientation="horizontal" >
 
-    <TextView
-        android:id="@+id/title"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_marginLeft="5dip"
-        android:layout_marginRight="5dip"
-        android:layout_marginTop="5dip"
-        android:text="@string/title"
-        android:textColor="@color/list_title"
-        android:textSize="20dip" />
+    <ImageView
+        android:id="@+id/cover"
+        android:layout_width="50dp"
+        android:layout_height="50dp"
+        android:layout_gravity="center" />
 
-    <TextView
-        android:id="@+id/artist"
-        android:layout_width="wrap_content"
+    <LinearLayout
+        android:layout_width="0dip"
         android:layout_height="wrap_content"
-        android:layout_marginLeft="5dip"
-        android:layout_marginRight="5dip"
-        android:layout_marginBottom="5dip"
-        android:text="@string/artist"
-        android:textColor="@color/list_subtitle"
-        android:textSize="14dip" />
+        android:layout_weight="1"
+        android:gravity="center_vertical"
+        android:orientation="vertical" >
+
+        <TextView
+            android:id="@+id/title"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginLeft="5dip"
+            android:layout_marginRight="5dip"
+            android:layout_marginTop="5dip"
+            android:text="@string/title"
+            android:textColor="@color/list_title"
+            android:textSize="20dip" />
+
+        <TextView
+            android:id="@+id/artist"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginBottom="5dip"
+            android:layout_marginLeft="5dip"
+            android:layout_marginRight="5dip"
+            android:text="@string/artist"
+            android:textColor="@color/list_subtitle"
+            android:textSize="14dip" />
+    </LinearLayout>
 
 </LinearLayout>
\ No newline at end of file
diff --git a/vlc-android/res/layout/audio_browser_playlist.xml b/vlc-android/res/layout/audio_browser_playlist.xml
index bf898da..9940626 100644
--- a/vlc-android/res/layout/audio_browser_playlist.xml
+++ b/vlc-android/res/layout/audio_browser_playlist.xml
@@ -5,6 +5,12 @@
     android:layout_height="wrap_content"
     android:orientation="horizontal" >
 
+    <ImageView
+        android:id="@+id/cover"
+        android:layout_width="50dp"
+        android:layout_height="50dp"
+        android:layout_gravity="center" />
+
     <LinearLayout
         android:layout_width="0dip"
         android:layout_height="wrap_content"
diff --git a/vlc-android/res/layout/audio_browser_playlist_child.xml b/vlc-android/res/layout/audio_browser_playlist_child.xml
index 768f379..42bbb58 100644
--- a/vlc-android/res/layout/audio_browser_playlist_child.xml
+++ b/vlc-android/res/layout/audio_browser_playlist_child.xml
@@ -11,6 +11,12 @@
         android:layout_marginLeft="5dip"
         android:background="@color/orange" />
 
+    <ImageView
+        android:id="@+id/cover"
+        android:layout_width="50dp"
+        android:layout_height="50dp"
+        android:layout_gravity="center" />
+
     <LinearLayout
         android:layout_width="0dip"
         android:layout_height="wrap_content"
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioListAdapter.java
index 968f5aa..e373710 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioListAdapter.java
@@ -29,10 +29,12 @@ import org.videolan.vlc.Util;
 
 import android.content.Context;
 import android.content.res.ColorStateList;
+import android.graphics.Bitmap;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.ArrayAdapter;
+import android.widget.ImageView;
 import android.widget.TextView;
 
 public class AudioListAdapter extends ArrayAdapter<Media> {
@@ -77,6 +79,7 @@ public class AudioListAdapter extends ArrayAdapter<Media> {
             v = inflater.inflate(R.layout.audio_browser_item, parent, false);
             holder = new ViewHolder();
             holder.layout = (View) v.findViewById(R.id.layout_item);
+            holder.cover = (ImageView) v.findViewById(R.id.cover);
             holder.title = (TextView) v.findViewById(R.id.title);
             holder.artist = (TextView) v.findViewById(R.id.artist);
             v.setTag(holder);
@@ -84,6 +87,10 @@ public class AudioListAdapter extends ArrayAdapter<Media> {
             holder = (ViewHolder) v.getTag();
 
         Media media = getItem(position);
+
+        Bitmap cover = AudioUtil.getCover(v.getContext(), media, 64);
+        holder.cover.setImageBitmap(cover);
+
         Util.setItemBackground(holder.layout, position);
         holder.title.setText(media.getTitle());
         ColorStateList titleColor = v.getResources().getColorStateList(mCurrentIndex == position
@@ -111,6 +118,7 @@ public class AudioListAdapter extends ArrayAdapter<Media> {
 
     static class ViewHolder {
         View layout;
+        ImageView cover;
         TextView title;
         TextView artist;
     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistAdapter.java
index 0bc1d90..16f1833 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistAdapter.java
@@ -30,6 +30,7 @@ import org.videolan.vlc.Util;
 
 import android.content.Context;
 import android.content.res.Resources;
+import android.graphics.Bitmap;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -152,6 +153,7 @@ public class AudioPlaylistAdapter extends BaseExpandableListAdapter {
             v = mInflater.inflate(R.layout.audio_browser_playlist, parent, false);
             holder = new GroupViewHolder();
             holder.layout = (View) v.findViewById(R.id.layout_item);
+            holder.cover = (ImageView) v.findViewById(R.id.cover);
             holder.title = (TextView) v.findViewById(R.id.title);
             holder.text = (TextView) v.findViewById(R.id.text);
             holder.more = (ImageView) v.findViewById(R.id.more);
@@ -161,9 +163,13 @@ public class AudioPlaylistAdapter extends BaseExpandableListAdapter {
 
         String name = mTitles.get(groupPosition);
         int count = mSubTitles.get(name).size();
-        int countMedia = mGroups.get(name).get(null).size();
+        ArrayList<Media> list = mGroups.get(name).get(null);
+        int countMedia = list.size();
         Resources res = mContext.getResources();
 
+        Bitmap cover = AudioUtil.getCover(v.getContext(), list.get(0), 64);
+        holder.cover.setImageBitmap(cover);
+
         Util.setItemBackground(holder.layout, groupPosition);
         holder.title.setText(name);
         if (count > 2)
@@ -189,6 +195,7 @@ public class AudioPlaylistAdapter extends BaseExpandableListAdapter {
             v = mInflater.inflate(R.layout.audio_browser_playlist_child, parent, false);
             holder = new ChildViewHolder();
             holder.layout = (View) v.findViewById(R.id.layout_item);
+            holder.cover = (ImageView) v.findViewById(R.id.cover);
             holder.title = (TextView) v.findViewById(R.id.title);
             holder.text = (TextView) v.findViewById(R.id.text);
             v.setTag(holder);
@@ -201,6 +208,9 @@ public class AudioPlaylistAdapter extends BaseExpandableListAdapter {
         int count = list.size();
         Resources res = mContext.getResources();
 
+        Bitmap cover = AudioUtil.getCover(v.getContext(), list.get(0), 64);
+        holder.cover.setImageBitmap(cover);
+
         Util.setItemBackground(holder.layout, childPosition);
         if (name != null)
             holder.title.setText(name);
@@ -213,6 +223,7 @@ public class AudioPlaylistAdapter extends BaseExpandableListAdapter {
 
     static class GroupViewHolder {
         View layout;
+        ImageView cover;
         TextView title;
         TextView text;
         ImageView more;
@@ -220,6 +231,7 @@ public class AudioPlaylistAdapter extends BaseExpandableListAdapter {
 
     static class ChildViewHolder {
         View layout;
+        ImageView cover;
         TextView title;
         TextView text;
     }



More information about the Android mailing list