From c73674788715237fca4463309b1e49c4139fd365 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 28 Jun 2013 20:16:13 +0200 Subject: [PATCH] Added device icons. --- .../controldlna/DeviceArrayAdapter.java | 41 +++++++++++++------ .../nutomic/controldlna/FileArrayAdapter.java | 1 - .../nutomic/controldlna/RemoteImageView.java | 1 + .../controldlna/service/PlayService.java | 1 - 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/com/github/nutomic/controldlna/DeviceArrayAdapter.java b/src/com/github/nutomic/controldlna/DeviceArrayAdapter.java index f281914..c6d0f75 100644 --- a/src/com/github/nutomic/controldlna/DeviceArrayAdapter.java +++ b/src/com/github/nutomic/controldlna/DeviceArrayAdapter.java @@ -27,6 +27,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.github.nutomic.controldlna; +import java.net.URI; +import java.net.URISyntaxException; import java.util.Collection; import org.teleal.cling.model.meta.Device; @@ -68,7 +70,7 @@ public class DeviceArrayAdapter extends ArrayAdapter> * @param deviceType One of RENDERER or SERVER. */ public DeviceArrayAdapter(Activity activity, String deviceType) { - super(activity, android.R.layout.simple_list_item_2); + super(activity, R.layout.list_item); mActivity = activity; mDeviceType = deviceType; } @@ -78,11 +80,26 @@ public class DeviceArrayAdapter extends ArrayAdapter> if (convertView == null) { LayoutInflater inflater = (LayoutInflater) getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - convertView = inflater.inflate(android.R.layout.simple_list_item_1, parent, false); + convertView = inflater.inflate(R.layout.list_item, parent, false); } - TextView tv = (TextView) convertView.findViewById(android.R.id.text1); + TextView tv = (TextView) convertView.findViewById(R.id.title); + RemoteImageView image = + (RemoteImageView) convertView.findViewById(R.id.image); tv.setText(getItem(position).getDetails().getFriendlyName()); + // Loading icons for local devices is not currently implemented. + if (getItem(position) instanceof RemoteDevice && + getItem(position).hasIcons()) { + RemoteDevice device = (RemoteDevice) getItem(position); + URI uri = null; + try { + uri = device.normalizeURI( + getItem(position).getIcons()[0].getUri()).toURI(); + } catch (URISyntaxException e) { + Log.w(TAG, "Failed to get device icon URI", e); + } + image.setImageUri(uri); + } return convertView; } @@ -127,17 +144,13 @@ public class DeviceArrayAdapter extends ArrayAdapter> @Override public void remoteDeviceUpdated(Registry registry, RemoteDevice device) { - if (!device.getType().getType().equals(mDeviceType)) + if (!(device.getType().getType().equals(mDeviceType))) deviceRemoved(device); - mActivity.runOnUiThread(new Runnable() { - - @Override - public void run() { - notifyDataSetChanged(); - } - }); } + /** + * Adds a new device to the list if its type equals mDeviceType. + */ private void deviceAdded(final Device device) { mActivity.runOnUiThread(new Runnable() { @@ -149,12 +162,16 @@ public class DeviceArrayAdapter extends ArrayAdapter> }); } + /** + * Removes the device from the list (if it is an element). + */ private void deviceRemoved(final Device device) { mActivity.runOnUiThread(new Runnable() { @Override public void run() { - remove(device); + if (getPosition(device) != -1) + remove(device); } }); } diff --git a/src/com/github/nutomic/controldlna/FileArrayAdapter.java b/src/com/github/nutomic/controldlna/FileArrayAdapter.java index 5ab7998..fa5215c 100644 --- a/src/com/github/nutomic/controldlna/FileArrayAdapter.java +++ b/src/com/github/nutomic/controldlna/FileArrayAdapter.java @@ -87,7 +87,6 @@ public class FileArrayAdapter extends ArrayAdapter { title.setText(item.getTitle()); artist.setText(""); } - image.setImageDrawable(null); image.setImageUri(item.getFirstPropertyValue( DIDLObject.Property.UPNP.ALBUM_ART_URI.class)); return convertView; diff --git a/src/com/github/nutomic/controldlna/RemoteImageView.java b/src/com/github/nutomic/controldlna/RemoteImageView.java index c860ea6..a4feab1 100644 --- a/src/com/github/nutomic/controldlna/RemoteImageView.java +++ b/src/com/github/nutomic/controldlna/RemoteImageView.java @@ -71,6 +71,7 @@ public class RemoteImageView extends ImageView { } public void setImageUri(URI uri) { + setImageDrawable(null); new LoadImageTask().execute(uri); } diff --git a/src/com/github/nutomic/controldlna/service/PlayService.java b/src/com/github/nutomic/controldlna/service/PlayService.java index 057a89c..79bec20 100644 --- a/src/com/github/nutomic/controldlna/service/PlayService.java +++ b/src/com/github/nutomic/controldlna/service/PlayService.java @@ -140,7 +140,6 @@ public class PlayService extends Service { @Override public IBinder onBind(Intent intent) { - Log.d(TAG, "test2"); return mBinder; }