com.octo.android.robospice.spicelist
Class BaseSpiceArrayAdapter<T>

java.lang.Object
  extended by android.widget.BaseAdapter
      extended by android.widget.ArrayAdapter<T>
          extended by com.octo.android.robospice.spicelist.BaseSpiceArrayAdapter<T>
Type Parameters:
T - the type of data displayed by the list.
All Implemented Interfaces:
android.widget.Adapter, android.widget.Filterable, android.widget.ListAdapter, android.widget.SpinnerAdapter
Direct Known Subclasses:
OkHttpSpiceArrayAdapter, SpiceArrayAdapter

public abstract class BaseSpiceArrayAdapter<T>
extends android.widget.ArrayAdapter<T>

An adapter that is optimized for SpiceListView instances. It offers to update ImageViews contained in SpiceListItemView instances with images loaded from the network. All you have to do is to Override #createRequest(Object) to define a bitmapRequest for each object in the list that is associated an image to display. Also please note that in your getView(int, android.view.View, android.view.ViewGroup) method, you must call updateListItemViewAsynchronously(Object, SpiceListItemView) in order for your SpiceListItemView to be updated automagically.

Author:
sni

Nested Class Summary
protected  class BaseSpiceArrayAdapter.ImageRequestListener
           
protected  class BaseSpiceArrayAdapter.ThumbnailAsynTask
           
 
Field Summary
protected  android.graphics.drawable.Drawable defaultDrawable
          The default drawable to display during image loading from the network.
protected  int imageHeight
           
protected  int imageWidth
           
protected  boolean isNetworkFetchingAllowed
          Indicates wether to use the network to update data.
protected  SpiceManager spiceManagerBinary
          A SpiceManager that will be used to fetch binaries.
 
Fields inherited from interface android.widget.Adapter
IGNORE_ITEM_VIEW_TYPE, NO_SELECTION
 
Constructor Summary
  BaseSpiceArrayAdapter(android.content.Context context, SpiceManager spiceManagerBinary)
           
protected BaseSpiceArrayAdapter(android.content.Context context, SpiceManager spiceManagerBinary, List<T> objects)
          Used for testing only.
  BaseSpiceArrayAdapter(android.content.Context context, SpiceManager spiceManagerBinary, T[] objects)
           
 
Method Summary
abstract  IBitmapRequest createRequest(T data, int imageIndex, int requestImageWidth, int requestImageHeight)
           
abstract  SpiceListItemView<T> createView(android.content.Context context, android.view.ViewGroup parent)
           
protected  com.octo.android.robospice.spicelist.BaseSpiceArrayAdapter.BitmapWorkerTask getBitmapWorkerTask(android.widget.ImageView imageView)
           
 android.view.View getView(int position, android.view.View convertView, android.view.ViewGroup parent)
           
protected  void loadBitmapAsynchronously(T octo, android.widget.ImageView thumbImageView, String tempThumbnailImageFileName)
           
 void performBitmapRequestAsync(SpiceListItemView<T> spiceListItemView, T data, int imageIndex)
           
 void setDefaultDrawable(android.graphics.drawable.Drawable defaultDrawable)
           
protected  void updateListItemViewAsynchronously(T data, SpiceListItemView<T> spiceListItemView)
          Updates a SpiceListItemView containing some data.
 
Methods inherited from class android.widget.ArrayAdapter
add, addAll, addAll, clear, createFromResource, getContext, getCount, getDropDownView, getFilter, getItem, getItemId, getPosition, insert, notifyDataSetChanged, remove, setDropDownViewResource, setNotifyOnChange, sort
 
Methods inherited from class android.widget.BaseAdapter
areAllItemsEnabled, getItemViewType, getViewTypeCount, hasStableIds, isEmpty, isEnabled, notifyDataSetInvalidated, registerDataSetObserver, unregisterDataSetObserver
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

imageWidth

protected int imageWidth

imageHeight

protected int imageHeight

isNetworkFetchingAllowed

protected boolean isNetworkFetchingAllowed
Indicates wether to use the network to update data. This is set by the SpiceListView.


spiceManagerBinary

protected SpiceManager spiceManagerBinary
A SpiceManager that will be used to fetch binaries. It's lifecycle has to be managed at the context level (usually fragment or activity).


defaultDrawable

protected android.graphics.drawable.Drawable defaultDrawable
The default drawable to display during image loading from the network.

Constructor Detail

BaseSpiceArrayAdapter

public BaseSpiceArrayAdapter(android.content.Context context,
                             SpiceManager spiceManagerBinary)

BaseSpiceArrayAdapter

public BaseSpiceArrayAdapter(android.content.Context context,
                             SpiceManager spiceManagerBinary,
                             T[] objects)

BaseSpiceArrayAdapter

protected BaseSpiceArrayAdapter(android.content.Context context,
                                SpiceManager spiceManagerBinary,
                                List<T> objects)
Used for testing only.

Method Detail

setDefaultDrawable

public final void setDefaultDrawable(android.graphics.drawable.Drawable defaultDrawable)

updateListItemViewAsynchronously

protected final void updateListItemViewAsynchronously(T data,
                                                      SpiceListItemView<T> spiceListItemView)
Updates a SpiceListItemView containing some data. The method #createRequest(Object) will be applied to data to know which bitmapRequest to execute to get data from network if needed. This method must be called during getView(int, android.view.View, android.view.ViewGroup).

Parameters:
data - the data to update the SpiceListItemView with.
spiceListItemView - the SpiceListItemView that displays an image to represent data.

getView

public android.view.View getView(int position,
                                 android.view.View convertView,
                                 android.view.ViewGroup parent)
Specified by:
getView in interface android.widget.Adapter
Overrides:
getView in class android.widget.ArrayAdapter<T>

performBitmapRequestAsync

public final void performBitmapRequestAsync(SpiceListItemView<T> spiceListItemView,
                                            T data,
                                            int imageIndex)

createView

public abstract SpiceListItemView<T> createView(android.content.Context context,
                                                android.view.ViewGroup parent)

createRequest

public abstract IBitmapRequest createRequest(T data,
                                             int imageIndex,
                                             int requestImageWidth,
                                             int requestImageHeight)

loadBitmapAsynchronously

protected void loadBitmapAsynchronously(T octo,
                                        android.widget.ImageView thumbImageView,
                                        String tempThumbnailImageFileName)

getBitmapWorkerTask

protected final com.octo.android.robospice.spicelist.BaseSpiceArrayAdapter.BitmapWorkerTask getBitmapWorkerTask(android.widget.ImageView imageView)


Copyright © 2012-2014. All Rights Reserved.