com.vodafone360.people.service.agent
Class UiAgent

java.lang.Object
  extended by com.vodafone360.people.service.agent.UiAgent

public class UiAgent
extends java.lang.Object

The UiAgent is aware when any "Live" Activities are currently on screen, and contains business logic for sending unsolicited messages to the UI. This is useful for knowing when to send chat messages, presence updates, notifications, error messages, etc to an on screen Activity.


Field Summary
private  boolean mChat
           
private  Context mContext
           
private  Handler mHandler
           
private  long mLocalContactId
           
private  MainApplication mMainApplication
           
private  boolean mNewMessage
           
private  Bundle mUiBundleQueue
           
private  ServiceUiRequest mUiEventQueue
           
static int UI_AGENT_NOTIFICATION_ID
           
 
Constructor Summary
UiAgent(MainApplication mainApplication, Context context)
          Constructor.
 
Method Summary
 long getLocalContactId()
          This method returns the local ID of the contact the HandlerAgent is tracking.
 boolean isSubscribed()
          Returns TRUE if an Activity is currently listening out for unsolicited events (i.e. a "Live" activity is currently on screen).
 boolean isSubscribedWithChat()
          Returns TRUE if an Activity is currently listening out for unsolicited events (i.e. a "Live" activity is currently on screen).
 void sendUnsolicitedUiEvent(ServiceUiRequest uiEvent, Bundle bundle)
          Send an unsolicited UI Event to the UI.
 void subscribe(Handler handler, java.lang.Long localContactId, boolean chat)
          Subscribes a UI Handler to receive unsolicited events.
 void unsubscribe(Handler handler)
          This method ends the UI Handler's subscription.
 void updateChat(long contactId)
          Notifies an on screen Chat capable Activity of a relevant update.
private  void updateChatNotification()
          Update the Notification bar with Chat information directly from the database.
 void updatePresence(long contactId)
          This method is called by the Presence engine to notify a subscribed Activity of updates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UI_AGENT_NOTIFICATION_ID

public static final int UI_AGENT_NOTIFICATION_ID
See Also:
Constant Field Values

mMainApplication

private MainApplication mMainApplication

mUiEventQueue

private ServiceUiRequest mUiEventQueue

mUiBundleQueue

private Bundle mUiBundleQueue

mHandler

private Handler mHandler

mLocalContactId

private long mLocalContactId

mChat

private boolean mChat

mNewMessage

private boolean mNewMessage

mContext

private Context mContext
Constructor Detail

UiAgent

public UiAgent(MainApplication mainApplication,
               Context context)
Constructor.

Method Detail

sendUnsolicitedUiEvent

public void sendUnsolicitedUiEvent(ServiceUiRequest uiEvent,
                                   Bundle bundle)
Send an unsolicited UI Event to the UI. If there are no on screen Activities, then queue the message for later. The queue is of size one, so higher priority messages will simply overwrite older ones.

Parameters:
uiEvent - Event to send.
bundle - Optional Bundle to send to UI, usally set to NULL.
Throws:
java.security.InvalidParameterException - UiEvent is NULL.

subscribe

public void subscribe(Handler handler,
                      java.lang.Long localContactId,
                      boolean chat)
Subscribes a UI Handler to receive unsolicited events.

Parameters:
handler - - UI handler to receive unsolicited events.
localContactId - Provide a local contact ID to receive updates for the given contact only.
localContactId - Set this to -1 to receive updates for every contact.
localContactId - Set this to NULL not to receive contact updates.
chat - - TRUE if the Handler expects chat messages
Throws:
java.lang.NullPointerException - Handler must not be NULL

unsubscribe

public void unsubscribe(Handler handler)
This method ends the UI Handler's subscription. This will have no effect if a different handler is currently subscribed.

Parameters:
handler - - UI handler to no longer receive unsolicited events.
Throws:
java.lang.NullPointerException - Handler must not be NULL

getLocalContactId

public long getLocalContactId()
This method returns the local ID of the contact the HandlerAgent is tracking.

Returns:
LocalContactId of the contact the HandlerAgent is tracking

isSubscribed

public boolean isSubscribed()
Returns TRUE if an Activity is currently listening out for unsolicited events (i.e. a "Live" activity is currently on screen).

Returns:
TRUE if any subscriber is listening the presence state/chat events

isSubscribedWithChat

public boolean isSubscribedWithChat()
Returns TRUE if an Activity is currently listening out for unsolicited events (i.e. a "Live" activity is currently on screen).

Returns:
TRUE if any subscriber is listening the presence chat events

updatePresence

public void updatePresence(long contactId)
This method is called by the Presence engine to notify a subscribed Activity of updates.

Parameters:
contactId - Update an Activity that shows this contact ID only.
contactId - Set this to -1 to send updates relevant to all contacts.

updateChat

public void updateChat(long contactId)
Notifies an on screen Chat capable Activity of a relevant update. If the wrong Activity is on screen, this update will be shown as a Notification.

Parameters:
contactId - Update an Activity that shows Chat information for this localContact ID only.

updateChatNotification

private void updateChatNotification()
Update the Notification bar with Chat information directly from the database.



JavaDoc