com.vodafone360.people.engine.content
Class ThumbnailHandler

java.lang.Object
  extended by com.vodafone360.people.engine.content.ThumbnailHandler
All Implemented Interfaces:
TransferListener

public class ThumbnailHandler
extends java.lang.Object
implements TransferListener

ThumbnailHandler is a handler for contents. The ContentEngine uses handlers to handle transfers of ContentObjects. The handler implements the TransferListener interface and registers itself in the ContentObjects before sending them to the ContentEngine. The ContentEngine calls the TransferListener on a ContentObject after a transfer completes. The ThumbnailHandler handles the fetching of thumbnails for contacts, saving them and refreshing the list.


Field Summary
private static int MAX_QUALITY
          Used only for jpeg but mandatory for some calls.
private static int MAX_THUMBS_FETCHED_PER_PAGE
          Number of thumbnails to fetch in a single RPG request batch.
private  java.util.List<Contact> mContactsQueue
          Queue with contacts to fetch thumbnails for.
private  java.util.List<ContentObject> mContentObjects
          List with ContentObjects.
private static ThumbnailHandler mThumbnailHandlerInstance
          instance of ThumbnailHandler.
 
Constructor Summary
private ThumbnailHandler()
          Private constructor.
 
Method Summary
 void downloadContactThumbnails(java.util.List<Contact> contactList)
          Puts the contactlist in to a queue and starts downloading the thumbnails for them.
private  void downloadThumbnails()
          Download the next bunch of contacts from the queue.
static ThumbnailHandler getInstance()
          Factory method for creating and getting singleton instance of this handler.
private  DatabaseHelper.ThumbnailInfo getThumbnailForContact(java.util.List<DatabaseHelper.ThumbnailInfo> thumbnailInfoList, Contact contact)
          Returns a ThumbanailInfo for a given Contact from a list of ThumbnailInfos.
 void transferComplete(ContentObject content)
          Called by ContentEngine when a Transfer is done.
 void transferError(ContentObject content, java.lang.RuntimeException exc)
          Called when there was an error transfering a ContentObject.
 void uploadServerThumbnails()
          Dummy method to replace the dummy processor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mThumbnailHandlerInstance

private static ThumbnailHandler mThumbnailHandlerInstance
instance of ThumbnailHandler. Used for singleton.


MAX_THUMBS_FETCHED_PER_PAGE

private static final int MAX_THUMBS_FETCHED_PER_PAGE
Number of thumbnails to fetch in a single RPG request batch.

See Also:
Constant Field Values

MAX_QUALITY

private static final int MAX_QUALITY
Used only for jpeg but mandatory for some calls.

See Also:
Constant Field Values

mContactsQueue

private java.util.List<Contact> mContactsQueue
Queue with contacts to fetch thumbnails for. The contacts are queued here when the downloadContactThumbnails is called and are then fetched batch for batch. The variable MAX_THUMBS_FETCHED_PER_PAGE defines how much are processed at one time


mContentObjects

private java.util.List<ContentObject> mContentObjects
List with ContentObjects. Every time a ContentObjects is created for downloading it is puted in this list. Every time it is processed, it will be removed. When the list is empty, the next batch of Contacts is processed.

Constructor Detail

ThumbnailHandler

private ThumbnailHandler()
Private constructor. The singleton method has to be used to obtain an instance.

Method Detail

getInstance

public static ThumbnailHandler getInstance()
Factory method for creating and getting singleton instance of this handler.

Returns:
Instance of Thumbnailhandler

transferComplete

public final void transferComplete(ContentObject content)
Called by ContentEngine when a Transfer is done. It saves the thumbnail to file, links it to the contact and refreshes the view.

Specified by:
transferComplete in interface TransferListener
Parameters:
content - Transfered ContentObject containing the Thumbnail

transferError

public final void transferError(ContentObject content,
                                java.lang.RuntimeException exc)
Called when there was an error transfering a ContentObject. It can happen when a timeout occurs, the URL is not valid, the server is not responding and so on.

Specified by:
transferError in interface TransferListener
Parameters:
content - The failing ContentObject
exc - RuntimeException explaining what happened

getThumbnailForContact

private DatabaseHelper.ThumbnailInfo getThumbnailForContact(java.util.List<DatabaseHelper.ThumbnailInfo> thumbnailInfoList,
                                                            Contact contact)
Returns a ThumbanailInfo for a given Contact from a list of ThumbnailInfos. When we fetch ThumbnailInfos for a big group of Contacts we will get an List with available ThumbnailInfos. Because not every Contact has a thumbnail mostly this List will be smaller then the given list of contacts. This method is then called to determine matching ThumbnailInfo for a Contact.

Parameters:
thumbnailInfoList - List with all available Thumbnails
contact - A Contact object for which the ThumbnailInfo is to be searched for
Returns:
Matching ThumbnailInfo for the given Contact

downloadContactThumbnails

public final void downloadContactThumbnails(java.util.List<Contact> contactList)
Puts the contactlist in to a queue and starts downloading the thumbnails for them.

Parameters:
contactList - List of contacts to download the thumbnails for

downloadThumbnails

private void downloadThumbnails()
Download the next bunch of contacts from the queue. The method uses the ContentEngine to download the thumbnails and sets this class as a handler


uploadServerThumbnails

public void uploadServerThumbnails()
Dummy method to replace the dummy processor.



JavaDoc