[Android] Audio browser: use a single item type for the AudioBrowserList

Adrien Maglo git at videolan.org
Tue Nov 19 17:32:59 CET 2013


vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Tue Nov 19 17:32:50 2013 +0100| [4f26f46f35955b4d7a056140017f905510fcd74f] | committer: Adrien Maglo

Audio browser: use a single item type for the AudioBrowserList

audio_browser_item_simple has been reworked to host any type of item.
Its configuration is modified pragmatically in the AudioBrowserListAdapter.

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

 .../res/layout/audio_browser_item_simple.xml       |   65 +++++++++++++-------
 vlc-android/res/values/dimens.xml                  |    1 +
 .../vlc/gui/audio/AudioBrowserListAdapter.java     |   30 ++++++---
 3 files changed, 65 insertions(+), 31 deletions(-)

diff --git a/vlc-android/res/layout/audio_browser_item_simple.xml b/vlc-android/res/layout/audio_browser_item_simple.xml
index 75e2118..3dd5e14 100644
--- a/vlc-android/res/layout/audio_browser_item_simple.xml
+++ b/vlc-android/res/layout/audio_browser_item_simple.xml
@@ -1,37 +1,56 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/layout_item"
     android:layout_width="match_parent"
-    android:layout_height="50dp"
+    android:layout_height="wrap_content"
     android:orientation="vertical" >
 
-    <LinearLayout
-        android:id="@+id/layout_item"
+    <RelativeLayout
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:layout_weight="1"
-        android:orientation="horizontal" >
-
-	    <TextView
-	        android:id="@+id/title"
-	        android:layout_width="wrap_content"
-	        android:layout_height="wrap_content"
-	        android:layout_weight="1"
-	        android:layout_marginLeft="10dp"
-	        android:layout_gravity="center_vertical"
-	        android:text="@string/title"
-	        android:textColor="@color/list_title"
-	        android:textSize="20sp" />
-
-         <View
+        android:layout_height="@dimen/audio_browser_item_size" >
+
+        <ImageView
+            android:id="@+id/cover"
+            android:layout_width="@dimen/audio_browser_item_size"
+            android:layout_height="@dimen/audio_browser_item_size"
+            android:layout_gravity="center" />
+
+        <LinearLayout
+            xmlns:android="http://schemas.android.com/apk/res/android"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:layout_toRightOf="@+id/cover"
+            android:gravity="center_vertical"
+            android:orientation="vertical" >
+
+            <TextView
+                android:id="@+id/title"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_gravity="center_vertical"
+                android:text="@string/title"
+                android:textColor="@color/list_title"
+                android:textSize="20sp" />
+
+            <TextView
+                android:id="@+id/subtitle"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="@string/artist"
+                android:textColor="@color/list_subtitle"
+                android:textSize="14sp" />
+        </LinearLayout>
+
+        <View
             android:layout_width="8dp"
             android:layout_height="8dp"
-            android:layout_gravity="bottom"
+            android:layout_alignParentBottom="true"
+            android:layout_alignParentRight="true"
             android:background="@drawable/item_more_triangle" />
-
-    </LinearLayout>
+    </RelativeLayout>
 
     <View
-        android:layout_width="fill_parent"
+        android:layout_width="match_parent"
         android:layout_height="1dip"
         android:background="@color/item_footer" />
 
diff --git a/vlc-android/res/values/dimens.xml b/vlc-android/res/values/dimens.xml
index 94ef587..0055427 100644
--- a/vlc-android/res/values/dimens.xml
+++ b/vlc-android/res/values/dimens.xml
@@ -1,4 +1,5 @@
 <resources>
 	<dimen name="shadow_width">6px</dimen>
 	<dimen name="widget_margin">10dp</dimen>
+    <dimen name="audio_browser_item_size">50dp</dimen>
 </resources>
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
index 607b99e..5973881 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
@@ -34,8 +34,10 @@ import android.graphics.Bitmap;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.LinearLayout;
 import android.widget.ListAdapter;
 import android.widget.ImageView;
+import android.widget.RelativeLayout;
 import android.widget.TextView;
 
 public class AudioBrowserListAdapter implements ListAdapter {
@@ -128,15 +130,12 @@ public class AudioBrowserListAdapter implements ListAdapter {
 
         if (b_createView) {
             LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-            int res = mItemType == ITEM_SIMPLE ? R.layout.audio_browser_item_simple : R.layout.audio_browser_item;
-            v = inflater.inflate(res, parent, false);
+            v = inflater.inflate(R.layout.audio_browser_item_simple, parent, false);
             holder = new ViewHolder();
             holder.layout = v.findViewById(R.id.layout_item);
             holder.title = (TextView) v.findViewById(R.id.title);
-            if (mItemType == ITEM_NORMAL) {
-                holder.cover = (ImageView) v.findViewById(R.id.cover);
-                holder.artist = (TextView) v.findViewById(R.id.artist);
-            }
+            holder.cover = (ImageView) v.findViewById(R.id.cover);
+            holder.subtitle = (TextView) v.findViewById(R.id.subtitle);
             v.setTag(holder);
         } else
             holder = (ViewHolder) v.getTag();
@@ -144,13 +143,28 @@ public class AudioBrowserListAdapter implements ListAdapter {
         ListItem item = getItem(position);
         holder.title.setText(item.mTitle);
 
+        RelativeLayout.LayoutParams paramsCover;
         if (mItemType == ITEM_NORMAL) {
             /*Bitmap cover = AudioUtil.getCover(v.getContext(), media, 64);
             if (cover == null)*/
             Bitmap cover = BitmapCache.GetFromResource(v, R.drawable.icon);
             holder.cover.setImageBitmap(cover);
-            holder.artist.setText(item.mSubTitle);
+            int size = (int) mContext.getResources().getDimension(R.dimen.audio_browser_item_size);
+            paramsCover = new RelativeLayout.LayoutParams(size, size);
+        }
+        else
+            paramsCover = new RelativeLayout.LayoutParams(0, RelativeLayout.LayoutParams.WRAP_CONTENT);
+        holder.cover.setLayoutParams(paramsCover);
+
+        LinearLayout.LayoutParams paramsSubTitle;
+        if (item.mSubTitle == null)
+            paramsSubTitle = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 0);
+        else {
+            paramsSubTitle = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
+                    LinearLayout.LayoutParams.WRAP_CONTENT);
+            holder.subtitle.setText(item.mSubTitle);
         }
+        holder.subtitle.setLayoutParams(paramsSubTitle);
 
         return v;
     }
@@ -188,7 +202,7 @@ public class AudioBrowserListAdapter implements ListAdapter {
         View layout;
         ImageView cover;
         TextView title;
-        TextView artist;
+        TextView subtitle;
         int viewType;
     }
 



More information about the Android mailing list