Added device icons.
This commit is contained in:
parent
49614a9051
commit
c736747887
4 changed files with 30 additions and 14 deletions
|
@ -27,6 +27,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
package com.github.nutomic.controldlna;
|
package com.github.nutomic.controldlna;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.teleal.cling.model.meta.Device;
|
import org.teleal.cling.model.meta.Device;
|
||||||
|
@ -68,7 +70,7 @@ public class DeviceArrayAdapter extends ArrayAdapter<Device<?, ?, ?>>
|
||||||
* @param deviceType One of RENDERER or SERVER.
|
* @param deviceType One of RENDERER or SERVER.
|
||||||
*/
|
*/
|
||||||
public DeviceArrayAdapter(Activity activity, String deviceType) {
|
public DeviceArrayAdapter(Activity activity, String deviceType) {
|
||||||
super(activity, android.R.layout.simple_list_item_2);
|
super(activity, R.layout.list_item);
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
mDeviceType = deviceType;
|
mDeviceType = deviceType;
|
||||||
}
|
}
|
||||||
|
@ -78,11 +80,26 @@ public class DeviceArrayAdapter extends ArrayAdapter<Device<?, ?, ?>>
|
||||||
if (convertView == null) {
|
if (convertView == null) {
|
||||||
LayoutInflater inflater = (LayoutInflater) getContext()
|
LayoutInflater inflater = (LayoutInflater) getContext()
|
||||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
.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());
|
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;
|
return convertView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,17 +144,13 @@ public class DeviceArrayAdapter extends ArrayAdapter<Device<?, ?, ?>>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remoteDeviceUpdated(Registry registry, RemoteDevice device) {
|
public void remoteDeviceUpdated(Registry registry, RemoteDevice device) {
|
||||||
if (!device.getType().getType().equals(mDeviceType))
|
if (!(device.getType().getType().equals(mDeviceType)))
|
||||||
deviceRemoved(device);
|
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) {
|
private void deviceAdded(final Device<?, ?, ?> device) {
|
||||||
mActivity.runOnUiThread(new Runnable() {
|
mActivity.runOnUiThread(new Runnable() {
|
||||||
|
|
||||||
|
@ -149,12 +162,16 @@ public class DeviceArrayAdapter extends ArrayAdapter<Device<?, ?, ?>>
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the device from the list (if it is an element).
|
||||||
|
*/
|
||||||
private void deviceRemoved(final Device<?, ?, ?> device) {
|
private void deviceRemoved(final Device<?, ?, ?> device) {
|
||||||
mActivity.runOnUiThread(new Runnable() {
|
mActivity.runOnUiThread(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
remove(device);
|
if (getPosition(device) != -1)
|
||||||
|
remove(device);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,6 @@ public class FileArrayAdapter extends ArrayAdapter<DIDLObject> {
|
||||||
title.setText(item.getTitle());
|
title.setText(item.getTitle());
|
||||||
artist.setText("");
|
artist.setText("");
|
||||||
}
|
}
|
||||||
image.setImageDrawable(null);
|
|
||||||
image.setImageUri(item.getFirstPropertyValue(
|
image.setImageUri(item.getFirstPropertyValue(
|
||||||
DIDLObject.Property.UPNP.ALBUM_ART_URI.class));
|
DIDLObject.Property.UPNP.ALBUM_ART_URI.class));
|
||||||
return convertView;
|
return convertView;
|
||||||
|
|
|
@ -71,6 +71,7 @@ public class RemoteImageView extends ImageView {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setImageUri(URI uri) {
|
public void setImageUri(URI uri) {
|
||||||
|
setImageDrawable(null);
|
||||||
new LoadImageTask().execute(uri);
|
new LoadImageTask().execute(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -140,7 +140,6 @@ public class PlayService extends Service {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
Log.d(TAG, "test2");
|
|
||||||
return mBinder;
|
return mBinder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue