Added album art to files.
This commit is contained in:
parent
3e674cd55f
commit
58009016f3
4 changed files with 125 additions and 4 deletions
39
res/layout/list_item.xml
Normal file
39
res/layout/list_item.xml
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="?android:attr/listPreferredItemHeight"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<com.github.nutomic.controldlna.RemoteImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="?android:attr/listPreferredItemHeight"
|
||||
android:layout_height="?android:attr/listPreferredItemHeight"
|
||||
android:layout_margin="4dip"
|
||||
android:contentDescription="@string/album_art" />
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginTop="4dip" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:lines="1"
|
||||
android:ellipsize="end" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/subtitle"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:lines="1"
|
||||
android:ellipsize="end" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -10,5 +10,6 @@
|
|||
<string name="previous">Previous</string>
|
||||
<string name="next">Next</string>
|
||||
<string name="select_renderer">Please select a renderer</string>
|
||||
<string name="album_art">Album Art</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -45,7 +45,7 @@ import android.widget.TextView;
|
|||
public class FileArrayAdapter extends ArrayAdapter<DIDLObject> {
|
||||
|
||||
public FileArrayAdapter(Context context) {
|
||||
super(context, android.R.layout.simple_list_item_1);
|
||||
super(context, R.layout.list_item);
|
||||
sort(new Comparator<DIDLObject>() {
|
||||
|
||||
@Override
|
||||
|
@ -70,11 +70,12 @@ public class FileArrayAdapter extends ArrayAdapter<DIDLObject> {
|
|||
if (convertView == null) {
|
||||
LayoutInflater inflater = (LayoutInflater) getContext()
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
convertView = inflater.inflate(android.R.layout.simple_list_item_2, parent, false);
|
||||
convertView = inflater.inflate(R.layout.list_item, parent, false);
|
||||
}
|
||||
DIDLObject item = getItem(position);
|
||||
TextView title = (TextView) convertView.findViewById(android.R.id.text1);
|
||||
TextView artist = (TextView) convertView.findViewById(android.R.id.text2);
|
||||
TextView title = (TextView) convertView.findViewById(R.id.title);
|
||||
TextView artist = (TextView) convertView.findViewById(R.id.subtitle);
|
||||
RemoteImageView image = (RemoteImageView) convertView.findViewById(R.id.image);
|
||||
MusicTrack track;
|
||||
if (item instanceof MusicTrack) {
|
||||
track = (MusicTrack) item;
|
||||
|
@ -86,6 +87,9 @@ public class FileArrayAdapter extends ArrayAdapter<DIDLObject> {
|
|||
title.setText(item.getTitle());
|
||||
artist.setText("");
|
||||
}
|
||||
image.setImageDrawable(null);
|
||||
image.setImageUri(item.getFirstPropertyValue(
|
||||
DIDLObject.Property.UPNP.ALBUM_ART_URI.class));
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
|
77
src/com/github/nutomic/controldlna/RemoteImageView.java
Normal file
77
src/com/github/nutomic/controldlna/RemoteImageView.java
Normal file
|
@ -0,0 +1,77 @@
|
|||
package com.github.nutomic.controldlna;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.widget.ImageView;
|
||||
|
||||
/**
|
||||
* ImageView that can directly load from a UPNP URI.
|
||||
*
|
||||
* @author Felix
|
||||
*
|
||||
*/
|
||||
public class RemoteImageView extends ImageView {
|
||||
|
||||
private static final String TAG = "RemoteImageView";
|
||||
|
||||
private class LoadImageTask extends AsyncTask<URI, Void, Bitmap> {
|
||||
|
||||
@Override
|
||||
protected Bitmap doInBackground(URI... uri) {
|
||||
if (uri[0] == null)
|
||||
return null;
|
||||
|
||||
Bitmap bm = null;
|
||||
try {
|
||||
URLConnection conn = new URL(uri[0].toString())
|
||||
.openConnection();
|
||||
conn.connect();
|
||||
InputStream is = conn.getInputStream();
|
||||
BufferedInputStream bis = new BufferedInputStream(is);
|
||||
bm = BitmapFactory.decodeStream(bis);
|
||||
bis.close();
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, "Failed to load artwork image", e);
|
||||
}
|
||||
return bm;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Bitmap bm) {
|
||||
if (bm != null)
|
||||
setImageBitmap(bm);
|
||||
else
|
||||
setImageDrawable(null);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public RemoteImageView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public RemoteImageView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public RemoteImageView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
public void setImageUri(URI uri) {
|
||||
new LoadImageTask().execute(uri);
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue