From 3207eb3e5b09a221a00a8763f86ab7855f72f385 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Mon, 23 Sep 2013 02:40:51 +0200 Subject: [PATCH] Changed packet structure, added missing license text to files. --- AndroidManifest.xml | 2 +- res/layout/list_item.xml | 2 +- .../nutomic/controldlna/LoadImageTask.java | 46 ---------- .../nutomic/controldlna/RemoteImageView.java | 59 ------------- .../nutomic/controldlna/gui/MainActivity.java | 2 +- .../controldlna/gui/RendererFragment.java | 21 ++--- .../controldlna/gui/ServerFragment.java | 4 +- .../{ => upnp}/DeviceListener.java | 29 ++++++- .../{service => upnp}/PlayService.java | 4 +- .../{service => upnp}/PlayServiceBinder.java | 2 +- .../{ => upnp}/UpnpController.java | 29 ++++++- .../controldlna/{ => upnp}/UpnpPlayer.java | 31 ++++++- .../{ => utility}/DeviceArrayAdapter.java | 6 +- .../{ => utility}/FileArrayAdapter.java | 4 +- .../controldlna/utility/LoadImageTask.java | 73 ++++++++++++++++ .../controldlna/utility/RemoteImageView.java | 83 +++++++++++++++++++ 16 files changed, 261 insertions(+), 136 deletions(-) delete mode 100644 src/com/github/nutomic/controldlna/LoadImageTask.java delete mode 100644 src/com/github/nutomic/controldlna/RemoteImageView.java rename src/com/github/nutomic/controldlna/{ => upnp}/DeviceListener.java (61%) rename src/com/github/nutomic/controldlna/{service => upnp}/PlayService.java (99%) rename src/com/github/nutomic/controldlna/{service => upnp}/PlayServiceBinder.java (97%) rename src/com/github/nutomic/controldlna/{ => upnp}/UpnpController.java (67%) rename src/com/github/nutomic/controldlna/{ => upnp}/UpnpPlayer.java (77%) rename src/com/github/nutomic/controldlna/{ => utility}/DeviceArrayAdapter.java (96%) rename src/com/github/nutomic/controldlna/{ => utility}/FileArrayAdapter.java (97%) create mode 100644 src/com/github/nutomic/controldlna/utility/LoadImageTask.java create mode 100644 src/com/github/nutomic/controldlna/utility/RemoteImageView.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index c4de4e7..5f2e919 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -34,7 +34,7 @@ - + diff --git a/res/layout/list_item.xml b/res/layout/list_item.xml index ca312ed..31b64d5 100644 --- a/res/layout/list_item.xml +++ b/res/layout/list_item.xml @@ -4,7 +4,7 @@ android:layout_height="?android:attr/listPreferredItemHeight" android:orientation="horizontal" > - { - - private static final String TAG = "LoadImageTask"; - - @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; - } - -} diff --git a/src/com/github/nutomic/controldlna/RemoteImageView.java b/src/com/github/nutomic/controldlna/RemoteImageView.java deleted file mode 100644 index a85bc8d..0000000 --- a/src/com/github/nutomic/controldlna/RemoteImageView.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.github.nutomic.controldlna; - -import java.net.URI; - -import com.github.nutomic.controldlna.LoadImageTask; - - -import android.content.Context; -import android.graphics.Bitmap; -import android.util.AttributeSet; -import android.widget.ImageView; - -/** - * ImageView that can directly load from a UPNP URI. - * - * @author Felix Ableitner - * - */ -public class RemoteImageView extends ImageView { - - /** - * Assigns the icon as image drawable when it is loaded. - * - * @author Felix - * - */ - private class AssignImageTask extends LoadImageTask { - - @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); - } - - /** - * Sets the URI where the image should be loaded from, loads and assigns it. - */ - public void setImageUri(URI uri) { - setImageDrawable(null); - new AssignImageTask().execute(uri); - } - -} diff --git a/src/com/github/nutomic/controldlna/gui/MainActivity.java b/src/com/github/nutomic/controldlna/gui/MainActivity.java index fa9451e..c96bd2a 100644 --- a/src/com/github/nutomic/controldlna/gui/MainActivity.java +++ b/src/com/github/nutomic/controldlna/gui/MainActivity.java @@ -39,7 +39,7 @@ import android.view.KeyEvent; import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.SherlockFragmentActivity; import com.github.nutomic.controldlna.R; -import com.github.nutomic.controldlna.UpnpPlayer; +import com.github.nutomic.controldlna.upnp.UpnpPlayer; /** * Main activity, with tabs for media servers and media renderers. diff --git a/src/com/github/nutomic/controldlna/gui/RendererFragment.java b/src/com/github/nutomic/controldlna/gui/RendererFragment.java index 48ec2b9..24dd7f7 100644 --- a/src/com/github/nutomic/controldlna/gui/RendererFragment.java +++ b/src/com/github/nutomic/controldlna/gui/RendererFragment.java @@ -27,7 +27,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.github.nutomic.controldlna.gui; -import java.util.List; import java.util.Map; import org.teleal.cling.controlpoint.SubscriptionCallback; @@ -43,7 +42,6 @@ import org.teleal.cling.support.avtransport.lastchange.AVTransportLastChangePars import org.teleal.cling.support.avtransport.lastchange.AVTransportVariable; import org.teleal.cling.support.lastchange.LastChange; import org.teleal.cling.support.model.PositionInfo; -import org.teleal.cling.support.model.item.Item; import android.app.AlertDialog; import android.content.DialogInterface; @@ -65,11 +63,11 @@ import android.widget.ListView; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; -import com.github.nutomic.controldlna.DeviceArrayAdapter; -import com.github.nutomic.controldlna.FileArrayAdapter; import com.github.nutomic.controldlna.R; -import com.github.nutomic.controldlna.UpnpPlayer; import com.github.nutomic.controldlna.gui.MainActivity.OnBackPressedListener; +import com.github.nutomic.controldlna.upnp.UpnpPlayer; +import com.github.nutomic.controldlna.utility.DeviceArrayAdapter; +import com.github.nutomic.controldlna.utility.FileArrayAdapter; /** * Shows a list of media servers, allowing to select one for playback. @@ -179,15 +177,6 @@ public class RendererFragment extends Fragment implements } } - /** - * Sets the new playlist. - */ - public void setPlaylist(List playlist, int start) { - mPlaylistAdapter.clear(); - mPlaylistAdapter.add(playlist); - getPlayer().getPlayService().setPlaylist(playlist, start); - } - /** * Selects a media renderer. */ @@ -266,10 +255,12 @@ public class RendererFragment extends Fragment implements AVTransportVariable.TransportState.class) .getValue()) { case PLAYING: + mPlaying = true; mPlayPause.setImageResource(R.drawable.ic_media_pause); mPlayPause.setContentDescription(getResources(). getString(R.string.pause)); - mPlaying = true; + mPlaylistAdapter.clear(); + mPlaylistAdapter.add(getPlayer().getPlayService().getPlaylist()); pollTimePosition(); enableTrackHighlight(); break; diff --git a/src/com/github/nutomic/controldlna/gui/ServerFragment.java b/src/com/github/nutomic/controldlna/gui/ServerFragment.java index 92477ff..2d4b136 100644 --- a/src/com/github/nutomic/controldlna/gui/ServerFragment.java +++ b/src/com/github/nutomic/controldlna/gui/ServerFragment.java @@ -49,9 +49,9 @@ import android.util.Log; import android.view.View; import android.widget.ListView; -import com.github.nutomic.controldlna.DeviceArrayAdapter; -import com.github.nutomic.controldlna.FileArrayAdapter; import com.github.nutomic.controldlna.gui.MainActivity.OnBackPressedListener; +import com.github.nutomic.controldlna.utility.DeviceArrayAdapter; +import com.github.nutomic.controldlna.utility.FileArrayAdapter; /** * Shows a list of media servers, upon selecting one, allows browsing their diff --git a/src/com/github/nutomic/controldlna/DeviceListener.java b/src/com/github/nutomic/controldlna/upnp/DeviceListener.java similarity index 61% rename from src/com/github/nutomic/controldlna/DeviceListener.java rename to src/com/github/nutomic/controldlna/upnp/DeviceListener.java index f2911c1..89a7f21 100644 --- a/src/com/github/nutomic/controldlna/DeviceListener.java +++ b/src/com/github/nutomic/controldlna/upnp/DeviceListener.java @@ -1,4 +1,31 @@ -package com.github.nutomic.controldlna; +/* +Copyright (c) 2013, Felix Ableitner +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.github.nutomic.controldlna.upnp; import java.util.ArrayList; diff --git a/src/com/github/nutomic/controldlna/service/PlayService.java b/src/com/github/nutomic/controldlna/upnp/PlayService.java similarity index 99% rename from src/com/github/nutomic/controldlna/service/PlayService.java rename to src/com/github/nutomic/controldlna/upnp/PlayService.java index e1a0bc2..fde1685 100644 --- a/src/com/github/nutomic/controldlna/service/PlayService.java +++ b/src/com/github/nutomic/controldlna/upnp/PlayService.java @@ -25,7 +25,7 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.github.nutomic.controldlna.service; +package com.github.nutomic.controldlna.upnp; import java.util.ArrayList; import java.util.List; @@ -69,9 +69,9 @@ import android.support.v4.app.NotificationCompat; import android.util.Log; import android.widget.Toast; -import com.github.nutomic.controldlna.LoadImageTask; import com.github.nutomic.controldlna.R; import com.github.nutomic.controldlna.gui.MainActivity; +import com.github.nutomic.controldlna.utility.LoadImageTask; /** * Background service that handles media playback to a single UPNP media renderer. diff --git a/src/com/github/nutomic/controldlna/service/PlayServiceBinder.java b/src/com/github/nutomic/controldlna/upnp/PlayServiceBinder.java similarity index 97% rename from src/com/github/nutomic/controldlna/service/PlayServiceBinder.java rename to src/com/github/nutomic/controldlna/upnp/PlayServiceBinder.java index 77392a9..76f7090 100644 --- a/src/com/github/nutomic/controldlna/service/PlayServiceBinder.java +++ b/src/com/github/nutomic/controldlna/upnp/PlayServiceBinder.java @@ -25,7 +25,7 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.github.nutomic.controldlna.service; +package com.github.nutomic.controldlna.upnp; import android.os.Binder; diff --git a/src/com/github/nutomic/controldlna/UpnpController.java b/src/com/github/nutomic/controldlna/upnp/UpnpController.java similarity index 67% rename from src/com/github/nutomic/controldlna/UpnpController.java rename to src/com/github/nutomic/controldlna/upnp/UpnpController.java index b80a1d9..ea5a7b8 100644 --- a/src/com/github/nutomic/controldlna/UpnpController.java +++ b/src/com/github/nutomic/controldlna/upnp/UpnpController.java @@ -1,4 +1,31 @@ -package com.github.nutomic.controldlna; +/* +Copyright (c) 2013, Felix Ableitner +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.github.nutomic.controldlna.upnp; import org.teleal.cling.android.AndroidUpnpService; import org.teleal.cling.android.AndroidUpnpServiceImpl; diff --git a/src/com/github/nutomic/controldlna/UpnpPlayer.java b/src/com/github/nutomic/controldlna/upnp/UpnpPlayer.java similarity index 77% rename from src/com/github/nutomic/controldlna/UpnpPlayer.java rename to src/com/github/nutomic/controldlna/upnp/UpnpPlayer.java index 5599206..6ebb8f7 100644 --- a/src/com/github/nutomic/controldlna/UpnpPlayer.java +++ b/src/com/github/nutomic/controldlna/upnp/UpnpPlayer.java @@ -1,4 +1,31 @@ -package com.github.nutomic.controldlna; +/* +Copyright (c) 2013, Felix Ableitner +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.github.nutomic.controldlna.upnp; import org.teleal.cling.model.action.ActionInvocation; import org.teleal.cling.model.message.UpnpResponse; @@ -17,8 +44,6 @@ import android.content.ServiceConnection; import android.os.IBinder; import android.util.Log; -import com.github.nutomic.controldlna.service.PlayService; -import com.github.nutomic.controldlna.service.PlayServiceBinder; /** * Handles connection to PlayService and provides methods related to playback. diff --git a/src/com/github/nutomic/controldlna/DeviceArrayAdapter.java b/src/com/github/nutomic/controldlna/utility/DeviceArrayAdapter.java similarity index 96% rename from src/com/github/nutomic/controldlna/DeviceArrayAdapter.java rename to src/com/github/nutomic/controldlna/utility/DeviceArrayAdapter.java index 7f901dd..ec1425d 100644 --- a/src/com/github/nutomic/controldlna/DeviceArrayAdapter.java +++ b/src/com/github/nutomic/controldlna/utility/DeviceArrayAdapter.java @@ -25,7 +25,7 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.github.nutomic.controldlna; +package com.github.nutomic.controldlna.utility; import java.net.URI; import java.net.URISyntaxException; @@ -42,7 +42,9 @@ import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.TextView; -import com.github.nutomic.controldlna.DeviceListener.DeviceListenerCallback; +import com.github.nutomic.controldlna.R; +import com.github.nutomic.controldlna.upnp.DeviceListener.DeviceListenerCallback; + /** * Displays the devices that are inserted through the RegistryListener (either diff --git a/src/com/github/nutomic/controldlna/FileArrayAdapter.java b/src/com/github/nutomic/controldlna/utility/FileArrayAdapter.java similarity index 97% rename from src/com/github/nutomic/controldlna/FileArrayAdapter.java rename to src/com/github/nutomic/controldlna/utility/FileArrayAdapter.java index 13f5422..08a8066 100644 --- a/src/com/github/nutomic/controldlna/FileArrayAdapter.java +++ b/src/com/github/nutomic/controldlna/utility/FileArrayAdapter.java @@ -25,7 +25,7 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.github.nutomic.controldlna; +package com.github.nutomic.controldlna.utility; import java.util.Comparator; import java.util.List; @@ -42,6 +42,8 @@ import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.TextView; +import com.github.nutomic.controldlna.R; + /** * Allows displaying UPNP media server directory contents in a ListView. * diff --git a/src/com/github/nutomic/controldlna/utility/LoadImageTask.java b/src/com/github/nutomic/controldlna/utility/LoadImageTask.java new file mode 100644 index 0000000..0514b2b --- /dev/null +++ b/src/com/github/nutomic/controldlna/utility/LoadImageTask.java @@ -0,0 +1,73 @@ +/* +Copyright (c) 2013, Felix Ableitner +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.github.nutomic.controldlna.utility; + +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.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.AsyncTask; +import android.util.Log; + +/** + * Handles background task of loading a bitmap by URI. + * + * @author Felix Ableitner + * + */ +public class LoadImageTask extends AsyncTask { + + private static final String TAG = "LoadImageTask"; + + @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; + } + +} diff --git a/src/com/github/nutomic/controldlna/utility/RemoteImageView.java b/src/com/github/nutomic/controldlna/utility/RemoteImageView.java new file mode 100644 index 0000000..4c58eed --- /dev/null +++ b/src/com/github/nutomic/controldlna/utility/RemoteImageView.java @@ -0,0 +1,83 @@ +/* +Copyright (c) 2013, Felix Ableitner +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.github.nutomic.controldlna.utility; + +import java.net.URI; + +import android.content.Context; +import android.graphics.Bitmap; +import android.util.AttributeSet; +import android.widget.ImageView; + +/** + * ImageView that can directly load from a UPNP URI. + * + * @author Felix Ableitner + * + */ +public class RemoteImageView extends ImageView { + + /** + * Assigns the icon as image drawable when it is loaded. + * + * @author Felix + * + */ + private class AssignImageTask extends LoadImageTask { + + @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); + } + + /** + * Sets the URI where the image should be loaded from, loads and assigns it. + */ + public void setImageUri(URI uri) { + setImageDrawable(null); + new AssignImageTask().execute(uri); + } + +}